@openchamber/web 1.11.5 → 1.11.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{MarkdownRendererImpl-C3-ZpwEx.js → MarkdownRendererImpl-COdbjw73.js} +3 -3
- package/dist/assets/{MultiRunWindow-BDfPzMDy.js → MultiRunWindow-BKSHxjMq.js} +1 -1
- package/dist/assets/{OnboardingScreen-DGgh4IXB.js → OnboardingScreen-Chjg337p.js} +1 -1
- package/dist/assets/{SettingsWindow-B8QKr5dB.js → SettingsWindow-C0lRRW8M.js} +1 -1
- package/dist/assets/{TerminalView-D7IIkSGJ.js → TerminalView-Bvil3j1u.js} +4 -4
- package/dist/assets/es-BZIAUghG.js +15 -0
- package/dist/assets/index-UcCH2KN9.css +1 -0
- package/dist/assets/ko-DU9l-zox.js +15 -0
- package/dist/assets/{main-VVcyjpiF.js → main-Blhx9Fp5.js} +2 -2
- package/dist/assets/main-d2-dY4er.js +232 -0
- package/dist/assets/miniChat-CJ7-rZFl.js +2 -0
- package/dist/assets/{modelPrefsAutoSave-Ctdc3cCY.js → modelPrefsAutoSave-DRJSYigo.js} +96 -96
- package/dist/assets/{pl-C577DpsX.js → pl-CdqzokG-.js} +1 -1
- package/dist/assets/pt-BR-Bknbr_Y3.js +15 -0
- package/dist/assets/{renderElectronMiniChatApp-CsddCM3q.js → renderElectronMiniChatApp-BxZRI73j.js} +2 -2
- package/dist/assets/uk-Be4E8ZNO.js +15 -0
- package/dist/assets/zh-CN-qpPiaZMg.js +15 -0
- package/dist/index.html +3 -3
- package/dist/mini-chat.html +3 -3
- package/package.json +1 -1
- package/server/index.js +2 -0
- package/server/lib/cloudflare-tunnel.js +3 -5
- package/server/lib/ngrok-tunnel.js +209 -0
- package/server/lib/opencode/core-routes.js +1 -0
- package/server/lib/opencode/feature-routes-runtime.js +35 -0
- package/server/lib/opencode/index.js +19 -0
- package/server/lib/opencode/npm-registry.js +157 -0
- package/server/lib/opencode/npm-registry.test.js +179 -0
- package/server/lib/opencode/plugin-routes.js +373 -0
- package/server/lib/opencode/plugin-routes.test.js +384 -0
- package/server/lib/opencode/plugin-spec.js +107 -0
- package/server/lib/opencode/plugin-spec.test.js +154 -0
- package/server/lib/opencode/plugins.js +393 -0
- package/server/lib/opencode/plugins.test.js +176 -0
- package/server/lib/opencode/settings-helpers.js +3 -0
- package/server/lib/opencode/settings-helpers.test.js +11 -0
- package/server/lib/tunnels/DOCUMENTATION.md +1 -0
- package/server/lib/tunnels/providers/ngrok.js +117 -0
- package/server/lib/tunnels/types.js +2 -0
- package/dist/assets/es-dIVpApmS.js +0 -15
- package/dist/assets/index-Bk9IWJe1.css +0 -1
- package/dist/assets/ko-Cqf3E9-d.js +0 -15
- package/dist/assets/main-D45l3Dxw.js +0 -232
- package/dist/assets/miniChat-a9w7WM0c.js +0 -2
- package/dist/assets/pt-BR-BeeF6VlK.js +0 -15
- package/dist/assets/uk-CZ7XVz_D.js +0 -15
- package/dist/assets/zh-CN-BMSSqdyO.js +0 -15
- /package/dist/assets/{index-DHluop4D.js → index-B9LvUHdG.js} +0 -0
|
@@ -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-Ctdc3cCY.js","assets/index-DHluop4D.js","assets/index-Bk9IWJe1.css","assets/TerminalView-D7IIkSGJ.js","assets/SettingsWindow-B8QKr5dB.js","assets/MultiRunWindow-BDfPzMDy.js","assets/OnboardingScreen-DGgh4IXB.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{c as ot,R as o,u as eo,a as oi,j as s,b as Ml,C as El,P as to,S as dl,d as Zg,D as ul,e as so,f as no,g as rr,i as Si,r as _e,k as ex,l as tx,p as ho,m as Rl,n as sx,o as nx,q as rx,_ as Dr,s as Bf,v as Jc,t as qa,w as Vf,x as Go,W as ax,y as ix,V as ox,F as lx,z as cx,A as er,E as dx,B as $n,G as ux,H as ki,I as pu,J as mx,K as px,L as Ql,M as fx,N as hx,O as gx,Q as fu,T as ml,U as hu,X as xx,Y as zf,Z as Uf,$ as bx,a0 as gu,a1 as yx,a2 as vx,a3 as wx,a4 as jx,a5 as Nx,a6 as xu,a7 as pt,a8 as ko,a9 as Sx,aa as kx,ab as Cx,ac as Ix,ad as Px,ae as Ax,af as Dx,ag as Tx,ah as Mx,ai as Ex,aj as Rx,ak as Fx,al as bu,am as yu,an as vu,ao as Ox}from"./vendor-.bun-Bum-iBXX.js";import{a as Lx,b as $x,f as _x}from"./index-DHluop4D.js";import{u as ut,a as Re,b as an,c as ye,I as D,d as Ss,i as mn,g as nr,e as Cr,s as Jl,r as Xl,f as Zl,h as Cs,o as nn,j as Ks,T as kt,k as Ct,l as It,m as Va,n as sa,p as wu,D as Ot,q as Bx,t as pl,v as Rn,w as G,x as Is,y as Xn,z as Ps,A as As,B as Wf,C as ju,E as Vx,F as zx,G as Nu,H as Ux,J as Wx,K as Kx,L as Hx,M as Bn,N as Cn,O as Zn,P as Xc,Q as xr,R as Kf,S as Gx,U as yt,V as $t,W as qx,X as Hf,Y as Oa,Z as Td,_ as Hn,$ as Md,a0 as Gf,a1 as Yx,a2 as Su,a3 as Qx,a4 as Jx,a5 as qf,a6 as Xx,a7 as Zx,a8 as Yf,a9 as Ed,aa as fl,ab as eb,ac as Fl,ad as Zr,ae as Rd,af as qo,ag as tb,ah as sb,ai as en,aj as Qf,ak as Jf,al as Xf,am as Br,an as fi,ao as nb,ap as Zf,aq as gs,ar as fs,as as ve,at as ms,au as ps,av as za,aw as rb,ax as ab,ay as Co,az as kn,aA as eh,aB as th,aC as Ol,aD as ib,aE as sh,aF as ku,aG as Cu,aH as jn,aI as Bt,aJ as xs,aK as ob,aL as lb,aM as cb,aN as db,aO as ub,aP as mb,aQ as pb,aR as ws,aS as Gs,aT as fb,aU as hb,aV as Ns,aW as gb,aX as xb,aY as bb,aZ as yb,a_ as Pr,a$ as go,b0 as vb,b1 as Hs,b2 as Ll,b3 as ai,b4 as hi,b5 as gi,b6 as Iu,b7 as xi,b8 as wb,b9 as is,ba as os,bb as us,bc as ls,bd as Mt,be as jb,bf as ha,bg as Nb,bh as ra,bi as Fd,bj as $l,bk as Sb,bl as Od,bm as kb,bn as Cb,bo as Ld,bp as Ib,bq as Qs,br as xo,bs as Ar,bt as Pb,bu as Ab,bv as ec,bw as _l,bx as $d,by as _d,bz as Bl,bA as On,bB as Bd,bC as Ua,bD as hl,bE as gl,bF as bi,bG as nh,bH as Db,bI as vr,bJ as Tb,bK as xl,bL as Mb,bM as Pu,bN as Eb,bO as Gi,bP as Vl,bQ as rh,bR as Rb,bS as Fb,bT as bo,bU as Ob,bV as Vd,bW as Lb,bX as ii,bY as ro,bZ as ah,b_ as yi,b$ as ih,c0 as $b,c1 as _b,c2 as zd,c3 as ma,c4 as li,c5 as La,c6 as zl,c7 as yo,c8 as vo,c9 as Zc,ca as oh,cb as Ud,cc as lh,cd as ao,ce as Bb,cf as Vb,cg as zb,ch as Ub,ci as Wb,cj as ci,ck as tc,cl as Au,cm as Kb,cn as Hb,co as Gb,cp as qb,cq as Ul,cr as ti,cs as sc,ct as Yb,cu as Du,cv as ta,cw as Qb,cx as Tu,cy as Mu,cz as Eu,cA as Ru,cB as Yo,cC as Fu,cD as Jb,cE as nc,cF as Xb,cG as Zb,cH as ey,cI as ty,cJ as sy,cK as ny,cL as ry,cM as rc,cN as Ou,cO as ay,cP as iy,cQ as oy,cR as ly,cS as cy,cT as ac,cU as dy,cV as Lu,cW as Ui,cX as uy,cY as ch,cZ as my,c_ as si,c$ as py,d0 as $u,d1 as fy,d2 as dh,d3 as Io,d4 as qi,d5 as hy,d6 as uh,d7 as gy,d8 as xy,d9 as _u,da as Bu,db as mh,dc as ph,dd as ic,de as Po,df as by,dg as yy,dh as vy,di as wy,dj as fh,dk as hh,dl as gh,dm as ed,dn as Wd,dp as jy,dq as bs,dr as io,ds as vi,dt as di,du as Vu,dv as Yn,dw as Ny,dx as Yi,dy as Sy,dz as xh,dA as ky,dB as Cy,dC as td,dD as Iy,dE as zu,dF as Py,dG as Ay,dH as Dy,dI as Kd,dJ as bh,dK as Ty,dL as My,dM as Ey,dN as Ry,dO as Uu,dP as Fy,dQ as Oy,dR as Ly,dS as $y,dT as oc,dU as _y,dV as By,dW as Vy,dX as zy,dY as Uy,dZ as Wy,d_ as Ky,d$ as Hy,e0 as Gy,e1 as qy,e2 as Yy,e3 as Qy,e4 as Wu,e5 as Jy,e6 as Xy,e7 as yh,e8 as Zy,e9 as ev,ea as tv,eb as sv,ec as aa,ed as nv,ee as Ku,ef as rv,eg as Qo,eh as Jo,ei as av,ej as iv,ek as ov,el as lv,em as cv,en as Hu,eo as dv,ep as Gu,eq as uv,er as mv,es as pv,et as qu,eu as Yu,ev as Qu,ew as fv,ex as vh,ey as wh,ez as hv,eA as gv,eB as xv,eC as bv,eD as yv,eE as vv,eF as wv,eG as jv,eH as Nv,eI as Sv,eJ as kv}from"./modelPrefsAutoSave-Ctdc3cCY.js";const Cv=({transform:t})=>({...t,y:0}),Iv=t=>{const e=ot.c(18),{id:n,children:r,className:a}=t;let i;e[0]!==n?(i={id:n},e[0]=n,e[1]=i):i=e[1];const{attributes:l,listeners:c,setNodeRef:d,transform:p,transition:m,isDragging:u}=Ml(i);let f;e[2]!==p?(f=El.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 g=u&&"opacity-50";let v;e[7]!==a||e[8]!==g?(v=ye("h-full rounded-md",a,g),e[7]=a,e[8]=g,e[9]=v):v=e[9];let x;return e[10]!==l||e[11]!==r||e[12]!==n||e[13]!==c||e[14]!==d||e[15]!==b||e[16]!==v?(x=s.jsx("div",{ref:d,"data-sortable-tab-id":n,style:b,className:v,...l,...c,children:r}),e[10]=l,e[11]=r,e[12]=n,e[13]=c,e[14]=d,e[15]=b,e[16]=v,e[17]=x):x=e[17],x},Pv=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 l;return e[2]!==r||e[3]!==n||e[4]!==i?(l=s.jsx("div",{className:i,"data-sortable-tab-id":n,children:r}),e[2]=r,e[3]=n,e[4]=i,e[5]=l):l=e[5],l},Vr=t=>{const e=ot.c(121),{items:n,activeId:r,onSelect:a,onClose:i,onReorder:l,layoutMode:c,variant:d,activePillInsetClassName:p,activePillButtonClassName:m,inactiveTabsIconOnly:u,iconOnlyActiveTab:f,animateActivePill:b,activePillLowercase:g,className:v}=t,x=c===void 0?"scrollable":c,h=d===void 0?"default":d,j=u===void 0?!1:u,y=f===void 0?!1:f,C=g===void 0?!0:g,{t:k}=ut(),w=Re(Av),{isTablet:S}=an(),I=w||S,T=o.useRef(null);let P;e[0]===Symbol.for("react.memo_cache_sentinel")?(P={left:!1,right:!1},e[0]=P):P=e[0];const[A,N]=o.useState(P);let E;e[1]!==n?(E=n.map(Dv),e[1]=n,e[2]=E):E=e[2];const M=E,O=x==="scrollable",V=h==="default",B=h==="active-pill",$=h==="animated",F=B||$,_=V,q=F||_,L=B&&O,Y=F,Z=b??$,ae=typeof l=="function",re=ae?Iv:Pv;let me;e[3]===Symbol.for("react.memo_cache_sentinel")?(me=new Map,e[3]=me):me=e[3];const fe=o.useRef(me),[H,K]=o.useState(null);let Q;e[4]===Symbol.for("react.memo_cache_sentinel")?(Q={activationConstraint:{distance:8}},e[4]=Q):Q=e[4];const W=eo(oi(to,Q)),de=Tv;let be;e[5]===Symbol.for("react.memo_cache_sentinel")?(be=(Je,ce)=>{if(ce){fe.current.set(Je,ce);return}fe.current.delete(Je)},e[5]=be):be=e[5];const we=be;let te;e[6]!==r||e[7]!==q?(te=()=>{if(!q||!r){K(Mv);return}const Je=T.current,ce=fe.current.get(r);if(!Je||!ce){K(Ev);return}let We=0,Le=0,Ge=ce;for(;Ge&&Ge!==Je;)We=We+Ge.offsetLeft,Le=Le+Ge.offsetTop,Ge=Ge.offsetParent;const at={left:We,top:Le,width:ce.offsetWidth,height:ce.offsetHeight};K(He=>de(He,at)?He:at)},e[6]=r,e[7]=q,e[8]=te):te=e[8];const ge=te;let ue;e[9]!==O?(ue=()=>{if(!O){N({left:!1,right:!1});return}const Je=T.current;if(!Je){N({left:!1,right:!1});return}N({left:Je.scrollLeft>2,right:Je.scrollLeft+Je.clientWidth<Je.scrollWidth-2})},e[9]=O,e[10]=ue):ue=e[10];const xe=ue;let ne;e[11]!==O||e[12]!==xe?(ne=()=>{if(!O){N({left:!1,right:!1});return}const Je=T.current;if(!Je)return;xe(),Je.addEventListener("scroll",xe,{passive:!0});const ce=new ResizeObserver(xe);return ce.observe(Je),()=>{Je.removeEventListener("scroll",xe),ce.disconnect()}},e[11]=O,e[12]=xe,e[13]=ne):ne=e[13];let pe;e[14]!==O||e[15]!==n.length||e[16]!==xe?(pe=[O,n.length,xe],e[14]=O,e[15]=n.length,e[16]=xe,e[17]=pe):pe=e[17],o.useEffect(ne,pe);let J;e[18]!==r||e[19]!==ge||e[20]!==q?(J=()=>{if(!q){K(null);return}ge();const Je=T.current;if(!Je)return;const ce=new ResizeObserver(ge);if(ce.observe(Je),r){const We=fe.current.get(r);We&&ce.observe(We)}return()=>{ce.disconnect()}},e[18]=r,e[19]=ge,e[20]=q,e[21]=J):J=e[21];let Se;e[22]!==r||e[23]!==n.length||e[24]!==ge||e[25]!==q?(Se=[r,n.length,ge,q],e[22]=r,e[23]=n.length,e[24]=ge,e[25]=q,e[26]=Se):Se=e[26],o.useEffect(J,Se);let he;e[27]!==ge?(he=()=>{ge()},e[27]=ge,e[28]=he):he=e[28],o.useLayoutEffect(he);let Ie;e[29]!==r||e[30]!==O||e[31]!==xe?(Ie=()=>{if(!O||!r)return;const Je=T.current;if(!Je)return;const ce=window.requestAnimationFrame(()=>{const We=typeof window.CSS?.escape=="function"?window.CSS.escape(r):r.replace(/"/g,'\\"'),Le=Je.querySelector(`[data-sortable-tab-id="${We}"]`);Le&&(Le.scrollIntoView({block:"nearest",inline:"nearest"}),xe())});return()=>{window.cancelAnimationFrame(ce)}},e[29]=r,e[30]=O,e[31]=xe,e[32]=Ie):Ie=e[32];let Pe;e[33]!==r||e[34]!==O||e[35]!==n.length||e[36]!==xe?(Pe=[r,O,n.length,xe],e[33]=r,e[34]=O,e[35]=n.length,e[36]=xe,e[37]=Pe):Pe=e[37],o.useEffect(Ie,Pe);let Ce;e[38]!==l?(Ce=Je=>{if(!l)return;const{active:ce,over:We}=Je;!We||ce.id===We.id||l(String(ce.id),String(We.id))},e[38]=l,e[39]=Ce):Ce=e[39];const X=Ce;let ie;e[40]!==v?(ie=ye("relative flex h-full min-w-0 flex-1",v),e[40]=v,e[41]=ie):ie=e[41];let Ne;e[42]!==O||e[43]!==A||e[44]!==F?(Ne=O&&A.left?s.jsx("div",{className:ye("pointer-events-none absolute inset-y-0 left-0 z-20 bg-gradient-to-r to-transparent",F?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,e[42]=O,e[43]=A,e[44]=F,e[45]=Ne):Ne=e[45];let oe;e[46]!==O||e[47]!==A||e[48]!==F?(oe=O&&A.right?s.jsx("div",{className:ye("pointer-events-none absolute inset-y-0 right-0 z-20 bg-gradient-to-l to-transparent",F?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,e[46]=O,e[47]=A,e[48]=F,e[49]=oe):oe=e[49];const ke=F?"items-center overflow-x-hidden overflow-y-hidden":"items-stretch",Te=F&&"@container/pill-tabs",Be=F&&"pill-tabs__track",je=F&&(p??"gap-0.5 py-0.5"),ee=_&&"items-center overflow-y-hidden",R=Y&&"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=O?"overflow-x-auto scrollbar-none":"overflow-x-hidden";let le;e[50]!==ke||e[51]!==Te||e[52]!==Be||e[53]!==je||e[54]!==ee||e[55]!==R||e[56]!==U?(le=ye("relative flex h-full min-w-0 flex-1",ke,Te,Be,je,ee,R,U),e[50]=ke,e[51]=Te,e[52]=Be,e[53]=je,e[54]=ee,e[55]=R,e[56]=U,e[57]=le):le=e[57];let Me;e[58]!==O?(Me=O?{scrollbarWidth:"none",msOverflowStyle:"none"}:void 0,e[58]=O,e[59]=Me):Me=e[59];let Oe;e[60]!==k?(Oe=k("sortableTabsStrip.aria.tabs"),e[60]=k,e[61]=Oe):Oe=e[61];let Ae;e[62]!==H||e[63]!==Z||e[64]!==F?(Ae=F&&H?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(${H.left}px, ${H.top}px, 0)`,width:`${H.width}px`,height:`${H.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]=H,e[63]=Z,e[64]=F,e[65]=Ae):Ae=e[65];let z;e[66]!==H||e[67]!==_?(z=_&&H?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(${H.left}px, 0, 0)`,width:`${H.width}px`},"aria-hidden":!0}):null,e[66]=H,e[67]=_,e[68]=z):z=e[68];let De;if(e[69]!==re||e[70]!==r||e[71]!==m||e[72]!==C||e[73]!==I||e[74]!==y||e[75]!==j||e[76]!==B||e[77]!==w||e[78]!==O||e[79]!==n||e[80]!==i||e[81]!==a||e[82]!==L||e[83]!==F){let Je;e[85]!==re||e[86]!==r||e[87]!==m||e[88]!==C||e[89]!==I||e[90]!==y||e[91]!==j||e[92]!==B||e[93]!==w||e[94]!==O||e[95]!==i||e[96]!==a||e[97]!==L||e[98]!==F?(Je=ce=>{const We=ce.id===r,Le=j&&F&&!We&&!!ce.icon,Ge=!Le,at=!!ce.icon&&(!y||We),He=j&&F&&We&&!O&&!L,ze=ce.closable!==!1&&!!i,et=ze&&!!ce.icon,gt=O||L?void 0:F?He?"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",Pt=ze?ht=>{ht.button===1&&(ht.preventDefault(),ht.stopPropagation(),i?.(ce.id))}:void 0,Nt=ze?Rv:void 0;return s.jsx(re,{id:ce.id,className:gt,children:s.jsxs("div",{ref:ht=>we(ce.id,ht),onAuxClick:Pt,onMouseDown:Nt,className:ye("group flex h-full min-w-0 flex-nowrap items-center",O||L?"shrink-0":F?"w-full":"w-full min-w-0",F?"relative z-10 bg-transparent":We?"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":We,"aria-label":Le?ce.title??ce.label:void 0,onClick:()=>a(ce.id),className:ye(F?"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",F&&C?"lowercase":null,F&&(Le?"gap-0":"gap-1.5"),F?L?"shrink-0 whitespace-nowrap px-3 text-center":O?"max-w-56 shrink-0 px-3 text-center":Le?"px-2 !min-w-0 text-center":He?"shrink-0 whitespace-nowrap px-3 text-center":"px-3 text-center":O?"max-w-56 justify-start truncate px-3 text-left":"w-full justify-center truncate px-3 text-center",F?m??(B?w?"h-[38px]":"h-[31px]":"h-7"):null,F?We?"text-foreground":"text-muted-foreground hover:text-foreground":null,F?"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:ce.title??ce.label,children:F?s.jsxs(s.Fragment,{children:[at?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",et&&(I?"opacity-0":"group-hover:opacity-0")),children:ce.icon}),et?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:Fv,onClick:ht=>{ht.stopPropagation(),i?.(ce.id)},"aria-label":ce.closeLabel??`Close ${ce.label} tab`,title:ce.closeLabel??`Close ${ce.label} tab`,children:s.jsx(D,{name:"close",className:"h-3.5 w-3.5"})}):null]}):null,Ge?s.jsx("span",{className:"animated-tabs__label truncate",children:ce.label}):null]}):s.jsxs("span",{className:ye("flex min-w-0 flex-nowrap items-center gap-1.5",!O&&"justify-center"),children:[at?s.jsxs("span",{className:ye("relative flex h-4 w-4 shrink-0 items-center justify-center transition-colors duration-200 ease-out",We?"text-[var(--primary-base)]":"text-muted-foreground"),children:[s.jsx("span",{className:ye("flex items-center justify-center transition-opacity",et&&(I?"opacity-0":"group-hover:opacity-0")),children:ce.icon}),et?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:Ov,onClick:ht=>{ht.stopPropagation(),i?.(ce.id)},"aria-label":ce.closeLabel??`Close ${ce.label} tab`,title:ce.closeLabel??`Close ${ce.label} tab`,children:s.jsx(D,{name:"close",className:"h-3.5 w-3.5"})}):null]}):null,s.jsx("span",{className:"truncate leading-[1.2]",children:ce.label})]})}),ze&&!et?s.jsx("button",{type:"button",onPointerDown:Lv,onClick:ht=>{ht.stopPropagation(),i?.(ce.id)},className:ye("relative z-20 inline-flex !min-h-0 !min-w-0 items-center justify-center transition-opacity",F?"-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",F?We?"text-muted-foreground hover:bg-transparent hover:text-foreground":"text-muted-foreground opacity-0 hover:bg-transparent hover:text-foreground group-hover:opacity-100":We?"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":ce.closeLabel??`Close ${ce.label} tab`,title:ce.closeLabel??`Close ${ce.label} tab`,children:s.jsx(D,{name:"close",className:"h-3 w-3"})}):null]})},ce.id)},e[85]=re,e[86]=r,e[87]=m,e[88]=C,e[89]=I,e[90]=y,e[91]=j,e[92]=B,e[93]=w,e[94]=O,e[95]=i,e[96]=a,e[97]=L,e[98]=F,e[99]=Je):Je=e[99],De=n.map(Je),e[69]=re,e[70]=r,e[71]=m,e[72]=C,e[73]=I,e[74]=y,e[75]=j,e[76]=B,e[77]=w,e[78]=O,e[79]=n,e[80]=i,e[81]=a,e[82]=L,e[83]=F,e[84]=De}else De=e[84];let Xe;e[100]!==le||e[101]!==Me||e[102]!==Oe||e[103]!==Ae||e[104]!==z||e[105]!==De?(Xe=s.jsxs("div",{ref:T,className:le,style:Me,role:"tablist","aria-label":Oe,children:[Ae,z,De]}),e[100]=le,e[101]=Me,e[102]=Oe,e[103]=Ae,e[104]=z,e[105]=De,e[106]=Xe):Xe=e[106];let st;e[107]!==ie||e[108]!==Ne||e[109]!==oe||e[110]!==Xe?(st=s.jsxs("div",{className:ie,children:[Ne,oe,Xe]}),e[107]=ie,e[108]=Ne,e[109]=oe,e[110]=Xe,e[111]=st):st=e[111];const tt=st;if(!ae)return tt;let Ue;e[112]===Symbol.for("react.memo_cache_sentinel")?(Ue=[Cv],e[112]=Ue):Ue=e[112];let it;e[113]!==M||e[114]!==tt?(it=s.jsx(dl,{items:M,strategy:Zg,children:tt}),e[113]=M,e[114]=tt,e[115]=it):it=e[115];let Ye;e[116]===Symbol.for("react.memo_cache_sentinel")?(Ye=s.jsx(ul,{dropAnimation:null}),e[116]=Ye):Ye=e[116];let rt;return e[117]!==X||e[118]!==W||e[119]!==it?(rt=s.jsxs(so,{sensors:W,collisionDetection:no,onDragEnd:X,modifiers:Ue,children:[it,Ye]}),e[117]=X,e[118]=W,e[119]=it,e[120]=rt):rt=e[120],rt};function Av(t){return t.isMobile}function Dv(t){return t.id}function Tv(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 Mv(t){return t===null?t:null}function Ev(t){return t===null?t:null}function Rv(t){t.button===1&&t.preventDefault()}function Fv(t){t.stopPropagation()}function Ov(t){t.stopPropagation()}function Lv(t){t.stopPropagation()}function Ju(t){const e=ot.c(14);let n,r,a,i;e[0]!==t?({size:a,className:n,style:i,...r}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=a,e[4]=i):(n=e[1],r=e[2],a=e[3],i=e[4]);const l=typeof a=="number"?`${a}px`:a,c=typeof a=="number"?`${a}px`:a;let d;e[5]!==i||e[6]!==l||e[7]!==c?(d={width:l,height:c,...i},e[5]=i,e[6]=l,e[7]=c,e[8]=d):d=e[8];let 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 Wr=[{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"}];Wr.reduce((t,e)=>(t[e.id]=e,t),{});const $v=t=>typeof t!="number"||!Number.isFinite(t)?null:Math.max(0,Math.min(100,Math.round(t))),_v=t=>typeof t!="number"||!Number.isFinite(t)?"-":`${Math.round(t)}%`,oo=(t,e)=>t??_v(e),Hd=(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??""}},jh=t=>t===null?"safe":t>=80?"critical":t>=50?"warn":"safe",Gd=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,Bv=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},lo=(t,e,n,r)=>{let a=n;if(a===null&&r&&(a=Bv(r)),t===null||e===null||a===null||a<=0)return null;const i=Date.now(),l=Math.max(0,(e-i)/1e3),c=Math.max(0,Math.min(a,a-l)),d=Math.max(0,Math.min(1,c/a)),p=t/100,m=t>=100&&l>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,g=b?86400:3600,v=b?"d":"h",x=a/g,h=Math.max(c/g,x*.01),j=t/h,y=Number.isFinite(j)?`${Math.min(999.9,Math.max(0,j)).toFixed(1)}%/${v}`:"-",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:l,isExhausted:m,elapsedSeconds:c,totalSeconds:a,status:f,paceRateText:y,predictText:C,dailyAllocationPercent:k}},Vv=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)"}},Xu=t=>{const e=Math.max(0,Math.floor(t)),n=Math.floor(e/60),r=Math.floor(n/60),a=Math.floor(r/24),i=r%24,l=n%60;return a>0?`${a}d ${i}h`:r>0?`${r}h`:n===0?"<1m":`${l}m`},ea=t=>Math.min(100,Math.max(0,t*100));function bl(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 zv=[{id:"gemini-auth",label:"Gemini",matcher:t=>t.startsWith("gemini/"),order:1},{id:"antigravity-auth",label:"Antigravity",matcher:t=>t.startsWith("antigravity/"),order:2}],Nh={google:zv};function Sh(t,e){const n=Nh[e]??[];for(const r of n)if(r.matcher(t))return r;return null}function kh(t){return Nh[t]??[]}function Ch(t){return[...t].sort((e,n)=>e.order-n.order)}function Uv(t,e){const n=new Map;for(const r of Object.keys(t)){const i=Sh(r,e)?.id??null;n.has(i)||n.set(i,[]),n.get(i).push(r)}return n}function Wv(t,e,n){const r=new Map;for(const a of t){const i=e(a),c=Sh(i,n)?.id??null;r.has(c)||r.set(c,[]),r.get(c).push(a)}return r}function Kv(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 qd=6e4,Zu=t=>{const e=Wr.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))):qd,a=t?.usageDisplayMode==="remaining"?"remaining":"usage",i=Array.isArray(t?.usageDropdownProviders)?t?.usageDropdownProviders:null,l=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:l,selectedModels:c,expandedFamilies:p}},Hv=async()=>{const t=nr()?.settings;if(t)try{const n=(await t.load())?.settings;return Zu(n??null)}catch{}if(!mn()){const e=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(e.ok){const n=await e.json().catch(()=>null);return Zu(n)}}return{autoRefresh:!1,refreshIntervalMs:qd,displayMode:"usage",dropdownProviderIds:Wr.map(e=>e.id),selectedModels:{},expandedFamilies:{}}},Es=rr()(Si((t,e)=>({results:[],selectedProviderId:null,isLoading:!1,isFetchingProvider:{},lastUpdated:null,error:null,autoRefresh:!1,refreshIntervalMs:qd,displayMode:"usage",dropdownProviderIds:Wr.map(n=>n.id),selectedModels:{},expandedFamilies:{},loadSettings:async()=>{try{const n=await Hv();t(n)}catch(n){console.warn("Failed to load usage settings:",n)}},fetchAllQuotas:async()=>{t({isLoading:!0,error:null});const n=Wr.map(r=>r.id);try{await Promise.all(n.map(r=>e().fetchProviderQuota(r))),t({isLoading:!1,lastUpdated:Date.now()})}catch(r){const a=r instanceof Error?r.message:"Failed to fetch quotas";t({isLoading:!1,error:a})}},fetchProviderQuota:async n=>{t(r=>({isFetchingProvider:{...r.isFetchingProvider,[n]:!0}}));try{const r=await fetch(`/api/quota/${encodeURIComponent(n)}`),a=await r.json().catch(()=>null);if(!r.ok)throw new Error(a?.error||"Failed to fetch quota");const i=a;t(l=>{const c=l.results.filter(d=>d.providerId!==n);return c.push(i),{results:c,error:null}})}catch(r){const a=r instanceof Error?r.message:"Failed to fetch quota",i={providerId:n,providerName:n,ok:!1,configured:!1,error:a,usage:null,fetchedAt:Date.now()};t(l=>{const c=l.results.filter(d=>d.providerId!==n);return c.push(i),{results:c,error:a}})}finally{t(r=>({isFetchingProvider:{...r.isFetchingProvider,[n]:!1}}))}},setSelectedProvider:n=>t({selectedProviderId:n}),setAutoRefresh:n=>t({autoRefresh:n}),setRefreshInterval:n=>{const r=Math.max(3e4,Math.min(3e5,Math.round(n)));t({refreshIntervalMs:r})},setDisplayMode:n=>t({displayMode:n}),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}})),Ss({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}}}),Ss({usageExpandedFamilies:e().expandedFamilies})},applyDefaultSelections:(n,r)=>{if((e().selectedModels[n]?.length??0)>0)return;const i=Kv(n,r);i.length!==0&&(t(l=>({selectedModels:{...l.selectedModels,[n]:i}})),Ss({usageSelectedModels:e().selectedModels}))}}),{name:"quota-store"})),Ih=()=>{const t=ot.c(5),e=Es(Gv),n=Es(qv),r=Es(Yv);let a,i;t[0]!==e||t[1]!==r||t[2]!==n?(a=()=>{if(!e)return;const l=window.setInterval(()=>{r()},n);return()=>window.clearInterval(l)},i=[e,n,r],t[0]=e,t[1]=r,t[2]=n,t[3]=a,t[4]=i):(a=t[3],i=t[4]),o.useEffect(a,i)};function Gv(t){return t.autoRefresh}function qv(t){return t.refreshIntervalMs}function Yv(t){return t.fetchAllQuotas}const yl=_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 l;n[5]===Symbol.for("react.memo_cache_sentinel")?(l={width:"36px",height:"20px",minWidth:"36px",minHeight:"20px"},n[5]=l):l=n[5];let c;n[6]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(ex,{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(tx,{className:i,style:l,...a,ref:e,children:c}),n[7]=a,n[8]=e,n[9]=i,n[10]=d):d=n[10],d});yl.displayName="Switch";const Ao=()=>{try{const e=Cs.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const n=nn.getDirectory();if(n?.trim())return n.trim()}catch(t){console.warn("[McpConfigStore] Error resolving config directory:",t)}return null},em=t=>t?Object.entries(t).map(([e,n])=>({key:e,value:n})):[],tm=t=>{const e=t.filter(n=>n.key.trim());if(e.length!==0)return Object.fromEntries(e.map(n=>[n.key.trim(),n.value]))},Do=t=>typeof t!="string"?void 0:t.trim()||void 0,lc=800,Qv=5e3,Jv="__default__",sd=new Map,cc=new Map,Ph=t=>t?.trim()||Jv,dc=t=>{sd.delete(Ph(t))},co=rr()(Si(ho((t,e)=>({mcpServers:[],selectedMcpName:null,isLoading:!1,mcpDraft:null,setSelectedMcp:n=>t({selectedMcpName:n}),setMcpDraft:n=>t({mcpDraft:n}),loadMcpConfigs:async n=>{const r=Ao(),a=Ph(r),i=Date.now(),l=sd.get(a)??0,c=e().mcpServers.length>0;if(!n?.force&&c&&i-l<Qv)return!0;const d=cc.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}),sd.set(a,Date.now()),!0}catch(m){return console.error("[McpConfigStore] Failed to load MCP configs:",m),t({isLoading:!1}),!1}})();cc.set(a,p);try{return await p}finally{cc.delete(a)}},createMcp:async n=>{Jl("Creating MCP server configuration…");let r=!1;try{const a=sm(n),i=Ao(),l=i?`?directory=${encodeURIComponent(i)}`:"",c=await fetch(`/api/config/mcp/${encodeURIComponent(n.name)}${l}`,{method:"POST",headers:{"Content-Type":"application/json",...i?{"x-opencode-directory":i}:{}},body:JSON.stringify(a)}),d=await c.json().catch(()=>null);if(!c.ok)throw new Error(d?.error||"Failed to create MCP server");return dc(i),d?.requiresReload?(r=!0,await Xl({message:d.message,delayMs:d.reloadDelayMs??lc,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||Zl()}},updateMcp:async(n,r)=>{Jl("Updating MCP server configuration…");let a=!1;try{const i=sm(r),l=Ao(),c=l?`?directory=${encodeURIComponent(l)}`:"",d=await fetch(`/api/config/mcp/${encodeURIComponent(n)}${c}`,{method:"PATCH",headers:{"Content-Type":"application/json",...l?{"x-opencode-directory":l}:{}},body:JSON.stringify(i)}),p=await d.json().catch(()=>null);if(!d.ok)throw new Error(p?.error||"Failed to update MCP server");return dc(l),p?.requiresReload?(a=!0,await Xl({message:p.message,delayMs:p.reloadDelayMs??lc,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||Zl()}},deleteMcp:async n=>{Jl("Deleting MCP server configuration…");let r=!1;try{const a=Ao(),i=a?`?directory=${encodeURIComponent(a)}`:"",l=await fetch(`/api/config/mcp/${encodeURIComponent(n)}${i}`,{method:"DELETE",headers:a?{"x-opencode-directory":a}:void 0}),c=await l.json().catch(()=>null);if(!l.ok)throw new Error(c?.error||"Failed to delete MCP server");return dc(a),c?.requiresReload&&(r=!0,await Xl({message:c.message,delayMs:c.reloadDelayMs??lc,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||Zl()}},getMcpByName:n=>e().mcpServers.find(r=>r.name===n)}),{name:"mcp-config-store",storage:Rl(()=>Cr()),partialize:t=>({selectedMcpName:t.selectedMcpName})}),{name:"mcp-config-store"}));function sm(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=tm(t.environment)??{}),t.headers!==void 0&&(e.headers=tm(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:Do(t.oauthClientId),clientSecret:Do(t.oauthClientSecret),scope:Do(t.oauthScope),redirectUri:Do(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 Xv={},Zv={},Xr=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},Za=t=>Xr(t)??"__global__",Na=t=>{const e=Xr(t);return e?nn.getScopedApiClient(e):nn.getApiClient()},Sn=rr()(Si((t,e)=>({byDirectory:{},diagnosticsByDirectory:{},loadingKeys:{},lastErrorKeys:{},getStatusForDirectory:n=>{const r=Za(n??Ks.getState().currentDirectory);return e().byDirectory[r]??Xv},getDiagnosticForDirectory:n=>{const r=Za(n??Ks.getState().currentDirectory);return e().diagnosticsByDirectory[r]??Zv},getErrorForDirectory:n=>{const r=Za(n??Ks.getState().currentDirectory);return e().lastErrorKeys[r]??null},refresh:async n=>{const r=Xr(n?.directory??Ks.getState().currentDirectory),a=Za(r);n?.silent||t(i=>({loadingKeys:{...i.loadingKeys,[a]:!0},lastErrorKeys:{...i.lastErrorKeys,[a]:null}}));try{const c=(await Na(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 l=i instanceof Error?i.message:"Failed to load MCP status";t(c=>({loadingKeys:{...c.loadingKeys,[a]:!1},lastErrorKeys:{...c.lastErrorKeys,[a]:l}}))}},connect:async(n,r)=>{const a=Xr(r??Ks.getState().currentDirectory),i=Za(a),l=Na(a);try{await l.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=Xr(r??Ks.getState().currentDirectory);await Na(a).mcp.disconnect({name:n},{throwOnError:!0}),await e().refresh({directory:a,silent:!0})},startAuth:async(n,r)=>{const a=Xr(r??Ks.getState().currentDirectory),c=(await Na(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=Xr(a??Ks.getState().currentDirectory);await Na(i).mcp.auth.callback({name:n,code:r},{throwOnError:!0}),await e().refresh({directory:i,silent:!0})},clearAuth:async(n,r)=>{const a=Xr(r??Ks.getState().currentDirectory);await Na(a).mcp.auth.remove({name:n},{throwOnError:!0}),await e().refresh({directory:a,silent:!0})},testConnection:async(n,r)=>{const a=Xr(r??Ks.getState().currentDirectory),i=Za(a),l=Na(a),d=e().getStatusForDirectory(a)[n]?.status==="connected";let p,m;try{await l.mcp.connect({name:n},{throwOnError:!0})}catch(b){p=b instanceof Error?b.message:"Connection failed",t(g=>({diagnosticsByDirectory:{...g.diagnosticsByDirectory,[i]:{...g.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 l.mcp.disconnect({name:n},{throwOnError:!0})}catch(b){m=`Connection test succeeded, but cleanup disconnect failed: ${b instanceof Error?b.message:"Disconnect failed"}`}await e().refresh({directory:a,silent:!0})}return{status:f??e().getStatusForDirectory(a)[n],error:p,warning:m}}}))),e1=(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}},t1=t=>{switch(t?.status){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"default"}},Ah=({active:t,className:e})=>{const{t:n}=ut(),a=Ks(h=>h.currentDirectory)??null,i=Sn(h=>h.getStatusForDirectory(a)),l=Sn(h=>h.refresh),c=Sn(h=>h.connect),d=Sn(h=>h.disconnect),p=co(h=>h.mcpServers),m=co(h=>h.loadMcpConfigs),[u,f]=o.useState(!1),[b,g]=o.useState(null);o.useEffect(()=>{l({directory:a,silent:!0})},[l,a]),o.useEffect(()=>{m({force:!0})},[m]),o.useEffect(()=>{t&&Promise.all([l({directory:a,silent:!0}),m({force:!0})])},[t,l,a,m]);const v=o.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,y)=>j.localeCompare(y))},[p,i]),x=o.useCallback(h=>{if(h?.preventDefault(),u)return;f(!0);const j=new Promise(y=>setTimeout(y,500));Promise.all([l({directory:a}),j]).finally(()=>{f(!1)})},[u,l,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:x,"aria-label":n("mcpDropdown.actions.refreshAria"),children:s.jsx(D,{name:"refresh",className:ye("h-4 w-4",u&&"animate-spin")})})]})}),s.jsxs("div",{className:"max-h-64 overflow-y-auto py-2",children:[v.map(h=>{const j=i[h],y=t1(j),C=j?.status==="connected",k=b===h,w=e1(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",y==="success"&&"bg-status-success",y==="error"&&"bg-status-error",y==="warning"&&"bg-status-warning",y==="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(yl,{checked:C,disabled:k,className:"data-[checked]:bg-status-info",onCheckedChange:async S=>{g(h);try{S?await c(h,a):await d(h,a)}finally{g(null)}}})]},h)}),v.length===0&&s.jsx("div",{className:"px-4 py-5 typography-ui-label text-muted-foreground text-center",children:n("mcpDropdown.empty.configureInConfig")})]})]})},uo=t=>{const e=ot.c(20),{percent:n,tonePercent:r,className:a,expectedMarkerPercent:i}=t;let l;e[0]!==n?(l=$v(n)??0,e[0]=n,e[1]=l):l=e[1];const c=l,d=r??n;let p;e[2]!==d?(p=jh(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 g;e[6]!==a?(g=ye("relative h-2.5 rounded-full bg-[var(--interactive-border)] overflow-hidden",a),e[6]=a,e[7]=g):g=e[7];const v=`${c}%`;let x;e[8]!==b||e[9]!==v?(x={...b,width:v},e[8]=b,e[9]=v,e[10]=x):x=e[10];let h;e[11]!==c||e[12]!==x?(h=s.jsx("div",{className:"h-full transition-all duration-300",style:x,role:"progressbar","aria-valuenow":c,"aria-valuemin":0,"aria-valuemax":100}),e[11]=c,e[12]=x,e[13]=h):h=e[13];let j;e[14]!==u?(j=u!=null&&u>0&&u<100&&s.jsx("div",{className:"absolute top-0 h-full w-0.5 bg-foreground",style:{left:`${u}%`},title:`Expected usage if spread evenly: ${Math.round(u)}% of quota`,"aria-hidden":"true"}),e[14]=u,e[15]=j):j=e[15];let y;return e[16]!==g||e[17]!==h||e[18]!==j?(y=s.jsxs("div",{className:g,children:[h,j]}),e[16]=g,e[17]=h,e[18]=j,e[19]=y):y=e[19],y},mo=t=>{const e=ot.c(67),{paceInfo:n,className:r,compact:a}=t,i=a===void 0?!1:a,{t:l}=ut();let c;e[0]!==n.status?(c=Vv(n.status),e[0]=n.status,e[1]=c):c=e[1];const d=c;let p;e:{switch(n.status){case"on-track":{let S;e[2]!==l?(S=l("settings.usage.pace.status.onTrack"),e[2]=l,e[3]=S):S=e[3],p=S;break e}case"slightly-fast":{let S;e[4]!==l?(S=l("settings.usage.pace.status.slightlyFast"),e[4]=l,e[5]=S):S=e[5],p=S;break e}case"too-fast":{let S;e[6]!==l?(S=l("settings.usage.pace.status.tooFast"),e[6]=l,e[7]=S):S=e[7],p=S;break e}case"exhausted":{let S;e[8]!==l?(S=l("settings.usage.pace.status.usedUp"),e[8]=l,e[9]=S):S=e[9],p=S;break e}}p=void 0}const m=p;let u;e[10]!==n.predictText||e[11]!==l?(u=l("settings.usage.pace.predictionTooltip",{prediction:n.predictText}),e[10]=n.predictText,e[11]=l,e[12]=u):u=e[12];const f=u;if(i){let S;e[13]!==r?(S=ye("flex items-center gap-1.5",r),e[13]=r,e[14]=S):S=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 A=n.isExhausted?void 0:f;let N;e[22]!==n.isExhausted||e[23]!==n.predictText||e[24]!==n.remainingSeconds||e[25]!==l?(N=n.isExhausted?s.jsx(s.Fragment,{children:l("settings.usage.pace.wait",{duration:Xu(n.remainingSeconds)})}):s.jsx(s.Fragment,{children:l("settings.usage.pace.prediction",{prediction:n.predictText})}),e[22]=n.isExhausted,e[23]=n.predictText,e[24]=n.remainingSeconds,e[25]=l,e[26]=N):N=e[26];let E;e[27]!==N||e[28]!==P||e[29]!==A?(E=s.jsx("span",{className:"typography-micro tabular-nums",style:P,title:A,children:N}),e[27]=N,e[28]=P,e[29]=A,e[30]=E):E=e[30];let M;return e[31]!==E||e[32]!==S||e[33]!==T?(M=s.jsxs("div",{className:S,children:[T,E]}),e[31]=E,e[32]=S,e[33]=T,e[34]=M):M=e[34],M}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 g;e[37]!==n.isExhausted||e[38]!==n.paceRateText||e[39]!==l?(g=!n.isExhausted&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:l("settings.usage.pace.rate",{rate:n.paceRateText})}),e[37]=n.isExhausted,e[38]=n.paceRateText,e[39]=l,e[40]=g):g=e[40];let v;e[41]!==g?(v=s.jsx("div",{className:"flex items-center gap-1.5",children:g}),e[41]=g,e[42]=v):v=e[42];let x;e[43]!==d?(x={color:d},e[43]=d,e[44]=x):x=e[44];let h;e[45]!==n.isExhausted||e[46]!==n.predictText||e[47]!==n.remainingSeconds||e[48]!==f||e[49]!==m||e[50]!==l?(h=n.isExhausted?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"font-medium",children:m}),s.jsx("span",{className:"text-muted-foreground",children:l("settings.usage.pace.waitSeparator")}),s.jsx("span",{className:"font-medium",children:Xu(n.remainingSeconds)})]}):s.jsxs("span",{title:f,children:[s.jsx("span",{className:"text-muted-foreground",children:l("settings.usage.pace.predictionLabel")}),s.jsx("span",{className:"font-medium",children:n.predictText})]}),e[45]=n.isExhausted,e[46]=n.predictText,e[47]=n.remainingSeconds,e[48]=f,e[49]=m,e[50]=l,e[51]=h):h=e[51];let j;e[52]!==x||e[53]!==h?(j=s.jsx("span",{className:"typography-micro tabular-nums",style:x,children:h}),e[52]=x,e[53]=h,e[54]=j):j=e[54];let y;e[55]!==d?(y={backgroundColor:d},e[55]=d,e[56]=y):y=e[56];let C;e[57]!==m||e[58]!==y?(C=s.jsx("div",{className:"h-2 w-2 rounded-full flex-shrink-0",style:y,title:m}),e[57]=m,e[58]=y,e[59]=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]!==v?(w=s.jsxs("div",{className:b,children:[v,k]}),e[63]=k,e[64]=b,e[65]=v,e[66]=w):w=e[66],w},br=sx,Tr=t=>{const e=ot.c(14);let n,r,a,i;e[0]!==t?({className:a,asChild:n,children:r,...i}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=a,e[4]=i):(n=e[1],r=e[2],a=e[3],i=e[4]);let l;e[5]!==n||e[6]!==r?(l=n&&_e.isValidElement(r)?{render:r}:{children:r},e[5]=n,e[6]=r,e[7]=l):l=e[7];const c=l;let d;e[8]!==a?(d=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(nx,{className:d,...i,...c}),e[10]=i,e[11]=c,e[12]=d,e[13]=p):p=e[13],p},yr=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(rx,{className:a,...r}),e[5]=r,e[6]=a,e[7]=i):i=e[7],i},pa=[{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"}],nd="finder",rd=new Set(["finder","terminal"]),ad=t=>t?pa.find(e=>e.id===t)??null:null,uc=()=>pa.filter(t=>rd.has(t.id)).map(t=>({...t})),s1=()=>{if(typeof window>"u")return nd;const t=window.localStorage.getItem("openInAppId");return t&&ad(t)?t:nd};let mc=!1,ei=!1,la=!1,ca=0,Qi=null;const nm=()=>{Qi&&(clearTimeout(Qi),Qi=null)},$r=rr()((t,e)=>({selectedAppId:s1(),availableApps:uc(),hasLoadedApps:!1,isCacheStale:!1,isScanning:!1,initialize:()=>{if(mc||typeof window>"u")return;mc=!0;const n=(d,p=!0)=>{if(!Array.isArray(d)||d.length===0){t({availableApps:uc(),hasLoadedApps:p});return}const m=new Set(d.map(g=>g.name)),u=new Map(d.map(g=>[g.name,g.iconDataUrl??void 0])),b=pa.filter(g=>m.has(g.appName)||rd.has(g.id)).map(g=>({...g,iconDataUrl:u.get(g.appName)}));t({availableApps:b,hasLoadedApps:!0})},r=async d=>{if(!Va()||!sa()||ei||e().hasLoadedApps&&!d)return;const m=pa.map(u=>u.appName);nm(),ei=!0,la=!1,t({isScanning:!0});try{const{apps:u,success:f,hasCache:b,isCacheStale:g}=await wu(m,d),v=f&&!b&&u.length===0&&ca<3;if(t({isCacheStale:b?g:!1}),n(u,f?!v:!1),f){if(v){const h=[800,1600,3200][ca]??3200;ca+=1,la=!0,Qi=setTimeout(()=>{r()},h);return}ca=0,la=!1;return}if(ca<3){const h=[1e3,3e3,7e3][ca]??7e3;ca+=1,la=!0,Qi=setTimeout(()=>{r()},h)}}finally{ei=!1,la||t({isScanning:!1})}};r();const a=d=>{const p=d.detail,m=p&&typeof p.openInAppId=="string"&&p.openInAppId.length>0&&ad(p.openInAppId)?p.openInAppId:null;m&&(window.localStorage.setItem("openInAppId",m),t({selectedAppId:m}))},i=()=>{r()},l=d=>{const p=d.detail;Array.isArray(p)&&(ca=3,la=!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",l),window.__openchamberAppReady&&r(),window.setTimeout(()=>{e().hasLoadedApps||r()},5e3)},loadInstalledApps:async n=>{if(mc||e().initialize(),!Va()||!sa()||ei||e().hasLoadedApps&&!n)return;const a=pa.map(i=>i.appName);nm(),n&&t({hasLoadedApps:!1}),ei=!0,la=!1,t({isScanning:!0});try{const{apps:i,hasCache:l,isCacheStale:c}=await wu(a,n),d=new Set(i.map(f=>f.name)),p=new Map(i.map(f=>[f.name,f.iconDataUrl??void 0])),u=pa.filter(f=>d.has(f.appName)||rd.has(f.id)).map(f=>({...f,iconDataUrl:p.get(f.appName)}));t({availableApps:u.length>0?u:uc(),hasLoadedApps:u.length>0,isCacheStale:l?c:!1})}finally{ei=!1,la||t({isScanning:!1})}},selectApp:async n=>{ad(n)&&(t({selectedAppId:n}),typeof window<"u"&&window.localStorage.setItem("openInAppId",n),await Ss({openInAppId:n}))}})),n1="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",r1="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",pc=t=>({...t,fallbackIconDataUrl:t.id==="finder"?n1:t.id==="terminal"?r1:void 0}),rm=t=>{const e=ot.c(8),{label:n,iconDataUrl:r,fallbackIconDataUrl:a}=t,[i,l]=o.useState(!1);let c;e[0]!==n?(c=n.trim().slice(0,1).toUpperCase()||"?",e[0]=n,e[1]=c):c=e[1];const d=c,p=r||a;if(p&&!i){let f;e[2]===Symbol.for("react.memo_cache_sentinel")?(f=()=>l(!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},a1=t=>{const e=ot.c(75),{directory:n,className:r}=t,{t:a}=ut(),i=$r(i1),l=$r(o1),c=$r(l1),d=$r(c1),p=$r(d1),m=$r(u1),u=$r(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]),o.useEffect(f,b);const g=Va()&&sa();let v;e:{let H;e[3]!==l||e[4]!==i?(H=l.find(W=>W.id===i)??l.find(p1)??l[0]??pa[0],e[3]=l,e[4]=i,e[5]=H):H=e[5];const K=H;if(K){let W;e[6]!==K?(W=pc(K),e[6]=K,e[7]=W):W=e[7],v=W;break e}let Q;e[8]===Symbol.for("react.memo_cache_sentinel")?(Q=pc(pa[0]),e[8]=Q):Q=e[8],v=Q}const x=v;if(!g||!n||l.length===0)return null;let h;e[9]!==n?(h=async H=>{await Bx(n,H.id,H.appName)||await pl(n,H.appName)},e[9]=n,e[10]=h):h=e[10];const j=h;let y;e[11]!==j||e[12]!==u?(y=async H=>{await u(H.id),await j(H)},e[11]=j,e[12]=u,e[13]=y):y=e[13];const C=y;let k;e[14]!==n||e[15]!==a?(k=async()=>{(await Rn(n)).ok&&G.success(a("openInApp.toast.pathCopied"))},e[14]=n,e[15]=a,e[16]=k):k=e[16];const w=k;let S;e[17]!==r?(S=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]=S):S=e[18];let I;e[19]!==j||e[20]!==x?(I=()=>{j(x)},e[19]=j,e[20]=x,e[21]=I):I=e[21];const 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 A;e[24]!==x.label||e[25]!==a?(A=a("openInApp.actions.openInAria",{app:x.label}),e[24]=x.label,e[25]=a,e[26]=A):A=e[26];let N;e[27]!==x.fallbackIconDataUrl||e[28]!==x.iconDataUrl||e[29]!==x.label?(N=s.jsx(rm,{label:x.label,iconDataUrl:x.iconDataUrl,fallbackIconDataUrl:x.fallbackIconDataUrl}),e[27]=x.fallbackIconDataUrl,e[28]=x.iconDataUrl,e[29]=x.label,e[30]=N):N=e[30];let E;e[31]!==P||e[32]!==A||e[33]!==N||e[34]!==I?(E=s.jsx("button",{type:"button",onClick:I,className:P,"aria-label":A,children:N}),e[31]=P,e[32]=A,e[33]=N,e[34]=I,e[35]=E):E=e[35];let M;e[36]===Symbol.for("react.memo_cache_sentinel")?(M=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]=M):M=e[36];let O;e[37]!==a?(O=a("openInApp.actions.chooseAppAria"),e[37]=a,e[38]=O):O=e[38];let V;e[39]===Symbol.for("react.memo_cache_sentinel")?(V=s.jsx(D,{name:"arrow-down-s",className:"h-4 w-4"}),e[39]=V):V=e[39];let B;e[40]!==O?(B=s.jsx(Is,{asChild:!0,children:s.jsx("button",{type:"button",className:M,"aria-label":O,children:V})}),e[40]=O,e[41]=B):B=e[41];let $;e[42]!==w?($=()=>{w()},e[42]=w,e[43]=$):$=e[43];let F;e[44]===Symbol.for("react.memo_cache_sentinel")?(F=s.jsx(D,{name:"file-copy",className:"h-4 w-4"}),e[44]=F):F=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(Ot,{className:"flex items-center gap-2",onClick:$,children:[F,q]}),e[49]=$,e[50]=q,e[51]=L):L=e[51];let Y;e[52]===Symbol.for("react.memo_cache_sentinel")?(Y=s.jsx(Xn,{}),e[52]=Y):Y=e[52];let Z;if(e[53]!==l||e[54]!==C||e[55]!==x.id){let H;e[57]!==C||e[58]!==x.id?(H=K=>{const Q=pc(K);return s.jsxs(Ot,{className:"flex items-center gap-2",onClick:()=>{C(K)},children:[s.jsx(rm,{label:K.label,iconDataUrl:K.iconDataUrl,fallbackIconDataUrl:Q.fallbackIconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:K.label}),x.id===K.id?s.jsx(D,{name:"check",className:"ml-auto h-4 w-4 text-primary"}):null]},K.id)},e[57]=C,e[58]=x.id,e[59]=H):H=e[59],Z=l.map(H),e[53]=l,e[54]=C,e[55]=x.id,e[56]=Z}else Z=e[56];let ae;e[60]!==c||e[61]!==m||e[62]!==a?(ae=c?s.jsxs(Ot,{className:"flex items-center gap-2",onClick:()=>{m(!0)},children:[s.jsx(D,{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]=ae):ae=e[63];let re;e[64]!==L||e[65]!==Z||e[66]!==ae?(re=s.jsxs(Ps,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[L,Y,Z,ae]}),e[64]=L,e[65]=Z,e[66]=ae,e[67]=re):re=e[67];let me;e[68]!==B||e[69]!==re?(me=s.jsxs(As,{children:[B,re]}),e[68]=B,e[69]=re,e[70]=me):me=e[70];let fe;return e[71]!==E||e[72]!==me||e[73]!==S?(fe=s.jsxs("div",{className:S,children:[E,me]}),e[71]=E,e[72]=me,e[73]=S,e[74]=fe):fe=e[74],fe};function i1(t){return t.selectedAppId}function o1(t){return t.availableApps}function l1(t){return t.isCacheStale}function c1(t){return t.isScanning}function d1(t){return t.initialize}function u1(t){return t.loadInstalledApps}function m1(t){return t.selectApp}function p1(t){return t.id===nd}const f1=1e6,h1="terminal-store";let am=!1;const fc=t=>typeof t=="object"&&t!==null,g1=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 hc=(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}),gc=t=>({tabs:[t],activeTabId:t.id}),Or=(t,e)=>t.tabs.findIndex(n=>n.id===e),on=rr()(Si(ho((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),l=`tab-${a.nextTabId}`,c=hc(l,"Terminal");return i.set(r,gc(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(l=>l.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 l=new Map(i.sessions),c=l.get(r),d=i.nextTabId+1,m=`Terminal ${(c?.tabs.length??0)+1}`,u=hc(a,m);return c?l.set(r,{...c,tabs:[...c.tabs,u]}):l.set(r,gc(u)),{sessions:l,nextTabId:d}}),a},setActiveTab:(n,r)=>{const a=Wn(n);t(i=>{const l=new Map(i.sessions),c=l.get(a);return!c||c.activeTabId===r||Or(c,r)<0?i:(l.set(a,{...c,activeTabId:r}),{sessions:l})})},setTabLabel:(n,r,a)=>{const i=Wn(n),l=a.trim();l&&t(c=>{const d=new Map(c.sessions),p=d.get(i);if(!p)return c;const m=Or(p,r);if(m<0||p.tabs[m]?.label===l)return c;const u=[...p.tabs];return u[m]={...u[m],label:l},d.set(i,{...p,tabs:u}),{sessions:d}})},setTabIconKey:(n,r,a)=>{const i=Wn(n);t(l=>{const c=new Map(l.sessions),d=c.get(i);if(!d)return l;const p=Or(d,r);if(p<0)return l;const m=a?.trim()||null;if(d.tabs[p]?.iconKey===m)return l;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 Lx(c)}catch{}t(d=>{const p=new Map(d.sessions),m=p.get(a);if(!m)return d;const u=Or(m,r);if(u<0)return d;const f=m.tabs.filter(x=>x.id!==r),b=Object.fromEntries(Object.entries(d.projectActionRuns).filter(([,x])=>!(x.directory===a&&x.tabId===r))),g=Object.keys(b).length!==Object.keys(d.projectActionRuns).length;if(f.length===0){const x=`tab-${d.nextTabId}`,h=hc(x,"Terminal");return p.set(a,gc(h)),{sessions:p,nextTabId:d.nextTabId+1,...g?{projectActionRuns:b}:{}}}let v=m.activeTabId;return m.activeTabId===r&&(v=f[Math.min(u,f.length-1)]?.id??f[0]?.id??null),p.set(a,{...m,tabs:f,activeTabId:v}),{sessions:p,...g?{projectActionRuns:b}:{}}})},setTabSessionId:(n,r,a)=>{const i=Wn(n);t(l=>{const c=new Map(l.sessions),d=c.get(i);if(!d)return l;const p=Or(d,r);if(p<0)return l;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}:{}},g=[...d.tabs];return g[p]=b,c.set(i,{...d,tabs:g}),{sessions:c}})},setTabLifecycle:(n,r,a)=>{const i=Wn(n);t(l=>{const c=new Map(l.sessions),d=c.get(i);if(!d)return l;const p=Or(d,r);if(p<0)return l;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(l=>{const c=new Map(l.sessions),d=c.get(i);if(!d)return l;const p=Or(d,r);if(p<0)return l;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(l=>{const c=new Map(l.sessions),d=c.get(i);if(!d)return l;const p=Or(d,r);if(p<0)return l;const m=d.tabs[p],u=l.nextChunkId,f={id:u,data:a},b=[...m.bufferChunks,f];let g=m.bufferLength+a.length;for(;g>f1&&b.length>1;){const x=b.shift();if(!x)break;g-=x.data.length}const v=[...d.tabs];return v[p]={...m,bufferChunks:b,bufferLength:g},c.set(i,{...d,tabs:v}),{sessions:c,nextChunkId:u+1}})},setTabPreviewUrl:(n,r,a,i={})=>{const l=Wn(n);t(c=>{const d=new Map(c.sessions),p=d.get(l);if(!p)return c;const m=Or(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 g=[...p.tabs];return g[m]={...u,previewUrl:a,previewAutoOpened:f,previewUrlLocked:b},d.set(l,{...p,tabs:g}),{sessions:d}})},markPreviewAutoOpened:(n,r)=>{const a=Wn(n);t(i=>{const l=new Map(i.sessions),c=l.get(a);if(!c)return i;const d=Or(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},l.set(a,{...c,tabs:m}),{sessions:l}})},setProjectActionRun:n=>{t(r=>{const a=r.projectActionRuns[n.key];return a&&a.directory===n.directory&&a.actionId===n.actionId&&a.tabId===n.tabId&&a.sessionId===n.sessionId&&a.status===n.status?r:{projectActionRuns:{...r.projectActionRuns,[n.key]:n}}})},updateProjectActionRunStatus:(n,r)=>{t(a=>{const i=a.projectActionRuns[n];return!i||i.status===r?a:{projectActionRuns:{...a.projectActionRuns,[n]:{...i,status:r}}}})},removeProjectActionRun:n=>{t(r=>{if(!r.projectActionRuns[n])return r;const a={...r.projectActionRuns};return delete a[n],{projectActionRuns:a}})},clearBuffer:(n,r)=>{const a=Wn(n);t(i=>{const l=new Map(i.sessions),c=l.get(a);if(!c)return i;const d=Or(c,r);if(d<0)return i;const p=[...c.tabs];return p[d]={...p[d],bufferChunks:[],bufferLength:0},l.set(a,{...c,tabs:p}),{sessions:l}})},removeDirectory:n=>{const r=Wn(n);t(a=>{const i=new Map(a.sessions);i.delete(r);const l=Object.fromEntries(Object.entries(a.projectActionRuns).filter(([,c])=>c.directory!==r));return{sessions:i,projectActionRuns:l}})},clearAll:()=>{t({sessions:new Map,projectActionRuns:{},nextChunkId:1,nextTabId:1})}}),{name:h1,storage:Rl(()=>Wf()),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(!fc(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"||!fc(p))continue;const m=Array.isArray(p.tabs)?p.tabs:[],u=[];for(const g of m){if(!fc(g))continue;const v=typeof g.id=="string"?g.id:null;if(!v)continue;const x=g1(v);x!==null&&(a=Math.max(a,x));const h=typeof g.terminalSessionId=="string"||g.terminalSessionId===null?g.terminalSessionId:null,j=g.lifecycle,y=j==="idle"||j==="running"||j==="exited"?j:h?"running":"idle";u.push({id:v,label:typeof g.label=="string"?g.label:"Terminal",iconKey:typeof g.iconKey=="string"?g.iconKey:null,terminalSessionId:h,lifecycle:y,createdAt:typeof g.createdAt=="number"?g.createdAt:Date.now(),bufferChunks:[],bufferLength:0,isConnecting:!1,previewUrl:null,previewAutoOpened:!1,previewUrlLocked:!1})}if(u.length===0)continue;const f=typeof p.activeTabId=="string"?p.activeTabId:null,b=f?u.some(g=>g.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,l=Math.max(e.nextTabId,i,a+1);return{...e,sessions:r,nextChunkId:1,nextTabId:l,hasHydrated:!0}}})));if(typeof window<"u"&&!am){am=!0;const t=on.persist,e=()=>{on.getState().hasHydrated||on.setState({hasHydrated:!0})};t?.hasHydrated?.()?e():t?.onFinishHydration?t.onFinishHydration(e):e()}const im=(t,e)=>e.updatedAtMs-t.updatedAtMs,Xs=rr((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([Wx(),Nu()]),a={};for(const i of r.sort(im))a[i.id]=i;e().listenerReady||await Kx(i=>{t(l=>({statusesById:{...l.statusesById,[i.id]:i}}))}),t({instances:n.instances,statusesById:a,isLoading:!1,initialized:!0,listenerReady:!0})}catch(n){t({isLoading:!1,error:n instanceof Error?n.message:String(n)})}}},loadImports:async()=>{if(!e().isImportsLoading){t({isImportsLoading:!0,error:null});try{const n=await Ux();t({importCandidates:n,isImportsLoading:!1})}catch(n){t({isImportsLoading:!1,error:n instanceof Error?n.message:String(n)})}}},refreshStatuses:async()=>{try{const n=await Nu(),r={};for(const a of n.sort(im))r[a.id]=a;t({statusesById:r})}catch(n){t({error:n instanceof Error?n.message:String(n)})}},setInstances:async n=>{t({isSaving:!0,error:null});try{await zx({instances:n}),t({instances:n,isSaving:!1}),await e().refreshStatuses()}catch(r){throw t({isSaving:!1,error:r instanceof Error?r.message:String(r)}),r}},upsertInstance:async n=>{const r=e().instances,a=r.some(i=>i.id===n.id)?r.map(i=>i.id===n.id?n:i):[n,...r];await e().setInstances(a)},createFromCommand:async(n,r,a)=>{const i=Hx(n,r);a&&a.trim()&&(i.nickname=a.trim()),await e().upsertInstance(i)},removeInstance:async n=>{await ju(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 Vx(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 ju(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})})),Dh=[{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"}],Xo=Object.fromEntries(Dh.map(t=>[t.key,t.Icon])),id="openchamber:project-actions-updated",Th=t=>{const e=(t||"").trim().replace(/\\/g,"/");return e?e==="/"?"/":e.length>1?e.replace(/\/+$/,""):e:""},da=(t,e)=>`${Th(t)}::${e}`,x1=t=>{const e=t.trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},om=t=>{if(typeof t!="number"||!Number.isFinite(t))return null;const e=Math.round(t);return e<1||e>65535?null:e},b1=(t,e)=>{if(!e.enabled||e.type!=="local")return null;const n=om(e.localPort),r=om(e.remotePort);if(!n||!r)return null;const a=x1(e.localHost||t.localForward.bindHost||"127.0.0.1"),i=(e.remoteHost||"127.0.0.1").trim(),l=(t.nickname||t.id||"instance").trim();return{id:`${t.id}::${e.id}`,label:`${l} - ${a}:${n} -> ${i}:${r}`,url:`http://${a}:${n}`}},Mh=t=>{const e=[];for(const n of t)if(!(!n?.id||!Array.isArray(n.portForwards)))for(const r of n.portForwards){const a=b1(n,r);a&&e.push(a)}return e},y1=(t,e)=>{const n=(t||"").trim();return n&&Mh(e).find(i=>i.id===n)?.url||null},v1=[{pattern:/^dev(:.*)?$/i},{pattern:/^start(:.*)?$/i},{pattern:/^preview(:.*)?$/i},{pattern:/^serve(:.*)?$/i},{pattern:/^develop(:.*)?$/i}],w1=["dev","start","preview","serve"];async function j1(t,e,n){if(!t)return null;const r=k1(e);if(r)return{command:r.command,label:r.name||"Start Preview",actionId:r.id};if(n){const a=C1(n);if(a){const i=await I1(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 N1(t)){const a=await S1(),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 N1(t){const e=`${t}/index.html`,n=await vl(e);return typeof n=="string"&&n.trim().length>0}async function S1(){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 k1(t){for(const e of t){const n=`${e.name} ${e.command}`.toLowerCase();if(w1.some(a=>n.includes(a)))return e}return null}function C1(t){for(const{pattern:e}of v1)for(const n of Object.keys(t))if(e.test(n))return n;return null}async function I1(t){const e=await vl(`${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 vl(`${t}/${r}`);if(typeof i=="string"&&i.trim().length>0)return a}return"npm"}async function vl(t){const e=nr()?.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 P1(t){try{const e=await vl(`${t}/package.json`);return e==null?null:JSON.parse(e).scripts||null}catch{return null}}const A1=t=>new Promise(e=>{window.setTimeout(e,t)}),D1="\x1B",T1=new RegExp(`${D1}\\[[0-9;?]*[ -/]*[@-~]`,"g"),M1=/https?:\/\/[^\s<>'"`]+/gi,ur="__openchamber_auto_discover_preview__",E1=15e3,R1=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},F1=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}},O1=t=>{const n=t.replace(T1,"").match(M1);if(!n||n.length===0)return null;const r=n.map(i=>i.replace(/[),.;]+$/,"")).filter(Boolean);if(r.length===0)return null;const a=[];for(const i of r)try{const l=new URL(i);l.port&&l.port.length>0&&a.push({raw:i,parsed:l})}catch{}if(a.length>0){const i=l=>{const{parsed:c}=l,d=c.hostname.toLowerCase(),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 g=0;return p&&(g+=50),f&&(g+=30),g-=Math.min(u*5,20),b&&(g-=10),g};return a.sort((l,c)=>i(c)-i(l)),a[0]?.parsed.origin??a[0]?.raw??null}return r[0]??null},lm=({projectRef:t,directory:e,className:n,compact:r=!1,allowMobile:a=!1})=>{const{t:i}=ut(),{terminal:l,runtime:c}=Bn(),{isMobile:d}=an(),p=o.useMemo(()=>Cn(),[]),m=Xs(oe=>oe.instances),u=Xs(oe=>oe.load),f=Re(oe=>oe.setBottomTerminalOpen),b=Re(oe=>oe.setActiveMainTab),g=Re(oe=>oe.setSettingsPage),v=Re(oe=>oe.setSettingsDialogOpen),x=Re(oe=>oe.setSettingsProjectsSelectedId),h=Re(oe=>oe.openContextPreview),j=on(oe=>oe.sessions),y=on(oe=>oe.ensureDirectory),C=on(oe=>oe.setTabLabel),k=on(oe=>oe.setTabIconKey),w=on(oe=>oe.setActiveTab),S=on(oe=>oe.setConnecting),I=on(oe=>oe.setTabSessionId),T=on(oe=>oe.setTabPreviewUrl),P=on(oe=>oe.projectActionRuns),A=on(oe=>oe.setProjectActionRun),N=on(oe=>oe.updateProjectActionRunStatus),E=on(oe=>oe.removeProjectActionRun),[M,O]=o.useState([]),[V,B]=o.useState(null),[$,F]=o.useState(!1),_=o.useRef({}),q=o.useRef({}),L=o.useRef({}),Y=o.useRef({}),Z=o.useRef(0),ae=t?.id??null,re=t?.path??"",me=o.useMemo(()=>ae?{id:ae,path:re}:null,[ae,re]);o.useEffect(()=>{p&&u().catch(()=>{})},[p,u]);const fe=o.useCallback(async oe=>{await Zn(oe)},[]),H=o.useCallback(async()=>{if(!me)return;const oe=Z.current+1;Z.current=oe,F(!0);try{const ke=await Xc(me);if(Z.current!==oe)return;const Te=ke.actions;O(Te),B(Be=>Be===ur||Be&&Te.some(je=>je.id===Be)?Be:null)}catch{if(Z.current!==oe)return}finally{Z.current===oe&&F(!1)}},[me]),K=o.useMemo(()=>Th(e||me?.path||""),[e,me?.path]),Q=o.useMemo(()=>V?M.find(oe=>oe.id===V)??null:null,[M,V]),W=o.useMemo(()=>({id:ur,name:i("projectActions.actions.autoDiscover"),command:"",icon:"search",autoOpenUrl:!0}),[i]),de=!d,be=o.useMemo(()=>de?[W,...M]:M,[M,W,de]);o.useEffect(()=>{H()},[H]),o.useEffect(()=>{if(typeof window>"u")return;const oe=ke=>{const Te=ke.detail;ae&&(Te?.projectId&&Te.projectId!==ae||H())};return window.addEventListener(id,oe),()=>{window.removeEventListener(id,oe)}},[H,ae]),o.useEffect(()=>{V&&(V===ur&&de||M.some(oe=>oe.id===V)||B(null))},[M,de,V]),o.useEffect(()=>{for(const[oe,ke]of Object.entries(P)){const Be=j.get(ke.directory)?.tabs.find(je=>je.id===ke.tabId);(!Be||Be.terminalSessionId!==ke.sessionId)&&E(oe)}},[P,E,j]),o.useEffect(()=>{for(const[oe,ke]of Object.entries(P)){const Te=q.current[oe]??{lastSeenChunkId:null,openedUrl:!1,tail:"",openInPreview:!1};q.current[oe]=Te;const Be=be.find(Ae=>Ae.id===ke.actionId);if(!Be)continue;const ee=j.get(ke.directory)?.tabs.find(Ae=>Ae.id===ke.tabId);if(!ee||!Array.isArray(ee.bufferChunks)||ee.bufferChunks.length===0)continue;const R=ee.bufferChunks.filter(Ae=>Te.lastSeenChunkId===null?!0:Ae.id>Te.lastSeenChunkId);if(R.length===0)continue;const U=R.map(Ae=>Ae.data).join(""),le=`${Te.tail}${U}`,Me=!Te.openedUrl&&Be.autoOpenUrl===!0?O1(le):null,Oe=R[R.length-1]?.id??Te.lastSeenChunkId;if(Te.lastSeenChunkId=Oe,Te.tail=le.slice(-512),Me)if(Te.openedUrl=!0,Te.openInPreview){const Ae=P[oe];Ae&&(T(Ae.directory,Ae.tabId,Me,{locked:!1,autoOpened:!1}),Ae.status==="waiting-for-preview"&&N(oe,"running"),window.clearTimeout(Y.current[oe]),delete Y.current[oe],h(Ae.directory,Me))}else fe(Me),G.success(i("projectActions.toast.openedUrlFromOutput"));q.current[oe]=Te}for(const oe of Object.keys(q.current))P[oe]||(delete q.current[oe],window.clearTimeout(Y.current[oe]),delete Y.current[oe])},[be,h,fe,P,T,i,j,N]);const we=o.useCallback(async(oe,ke={})=>{if(!K)throw new Error(i("projectActions.error.noActiveDirectory"));const Te=da(K,oe.id);y(K);const Be=on.getState(),je=Be.getDirectoryState(K);let ee=_.current[Te]||null;const R=ee?!!je?.tabs.some(Me=>Me.id===ee):!1;(!ee||!R)&&(ee=Be.createTab(K),_.current[Te]=ee),C(K,ee,`Action: ${oe.name}`),k(K,ee,oe.icon||"play"),ke.revealTerminal!==!1&&(w(K,ee),f(!0),b("terminal"));const le=on.getState().getDirectoryState(K)?.tabs.find(Me=>Me.id===ee);return{key:Te,tabId:ee,sessionId:le?.terminalSessionId??null}},[y,K,b,w,f,k,C,i]),te=o.useCallback(async oe=>{if(c.isVSCode||!a&&d)return;if(!K){G.error(i("projectActions.error.noActiveDirectoryForAction"));return}const ke=da(K,oe.id),Te=P[ke];if(!(Te&&Te.status==="running"))try{const Be=oe.id===ur?await(async()=>{const[Xe,st]=await Promise.all([Xc({id:me?.id??"",path:K}),P1(K)]),tt=await j1(K,Xe.actions,st);if(!tt)throw new Error(i("contextPanel.preview.noDevServer"));return{id:ur,name:i("projectActions.actions.autoDiscover"),command:tt.command,icon:"search",autoOpenUrl:!0,openUrl:tt.previewUrlHint||""}})():oe,je=Be.autoOpenUrl===!0&&(Be.openUrl||"").trim().length>0,{key:ee,tabId:R,sessionId:U}=await we(Be,{revealTerminal:!je&&oe.id!==ur});let le=U,Me=!1;if(!le){S(K,R,!0);try{le=(await l.createSession({cwd:K})).sessionId,Me=!0,I(K,R,le)}finally{S(K,R,!1)}}if(!le)throw new Error(i("projectActions.error.failedToCreateTerminalSession"));Me&&await A1(350),Be.id===ur&&(L.current[ee]?.(),S(K,R,!0),L.current[ee]=$x(le,Xe=>{Xe.type==="data"&&typeof Xe.data=="string"&&Xe.data.length>0&&on.getState().appendToBuffer(K,R,Xe.data),Xe.type==="exit"&&(on.getState().setTabLifecycle(K,R,"exited"),on.getState().setConnecting(K,R,!1),on.getState().removeProjectActionRun(ee),delete q.current[ee],L.current[ee]?.(),delete L.current[ee],window.clearTimeout(Y.current[ee]),delete Y.current[ee])},()=>{on.getState().setConnecting(K,R,!1)},{maxRetries:60,initialRetryDelay:250,maxRetryDelay:2e3,connectionTimeout:5e3}));const Oe=Be.autoOpenUrl===!0&&p&&(Be.desktopOpenSshForward||"").trim().length>0,Ae=Be.autoOpenUrl?F1(Be.openUrl):null,z=Be.autoOpenUrl&&p?y1(Be.desktopOpenSshForward,m):null;A({key:ee,directory:K,actionId:Be.id,tabId:R,sessionId:le,status:Be.id===ur&&!Ae?"waiting-for-preview":"running"}),window.clearTimeout(Y.current[ee]),delete Y.current[ee],Be.id===ur&&!Ae&&(Y.current[ee]=window.setTimeout(()=>{on.getState().updateProjectActionRunStatus(ee,"running"),delete Y.current[ee]},E1)),z?(T(K,R,null,{locked:!0}),fe(z),G.success(i("projectActions.toast.openedForwardedUrl"))):Ae?(T(K,R,Ae,{locked:!0,autoOpened:!0}),h(K,Ae),G.success(i("projectActions.toast.openedActionUrl"))):je?(T(K,R,null,{locked:!0}),G.error(i("projectActions.error.invalidCustomUrlFormat"))):Oe?(T(K,R,null,{locked:!0}),G.error(i("projectActions.error.selectedDesktopSshForwardUnavailable"))):T(K,R,null,{locked:!1,autoOpened:!1}),q.current[ee]={lastSeenChunkId:null,openedUrl:!!z||!!Ae||je,tail:"",openInPreview:Be.id===ur};const De=R1(Be.command.trim().replace(/\r\n|\r/g,`
|
|
3
|
-
`));await l.sendInput(le,`${De}\r`)}catch(Be){E(ke),delete q.current[ke],L.current[ke]?.(),delete L.current[ke],window.clearTimeout(Y.current[ke]),delete Y.current[ke],G.error(Be instanceof Error?Be.message:i("projectActions.error.failedToRunAction"))}},[m,we,a,d,p,K,fe,h,P,c.isVSCode,E,S,A,T,I,me?.id,i,l]),ge=o.useCallback(async oe=>{const ke=da(K,oe.id),Te=P[ke];if(!Te)return;N(ke,"stopping");try{await l.sendInput(Te.sessionId,"")}catch{}if(await new Promise(ee=>{window.setTimeout(ee,1e3)}),on.getState().getDirectoryState(Te.directory)?.tabs.find(ee=>ee.id===Te.tabId)?.terminalSessionId===Te.sessionId){if(typeof l.forceKill=="function")try{await l.forceKill({sessionId:Te.sessionId})}catch{}else try{await l.close(Te.sessionId)}catch{}I(Te.directory,Te.tabId,null)}E(ke),delete q.current[ke],L.current[ke]?.(),delete L.current[ke],window.clearTimeout(Y.current[ke]),delete Y.current[ke]},[K,P,E,I,l,N]),ue=o.useCallback(()=>{const oe=Q??be[0];if(!oe)return;const ke=da(K,oe.id),Te=P[ke];if(Te?.status!=="stopping"){if(Te){ge(oe);return}te(oe)}},[be,K,te,P,Q,ge]),xe=o.useCallback((oe,ke=!1)=>{if(B(oe.id),!ke){te(oe);return}const Te=da(K,oe.id),Be=P[Te];if(Be?.status!=="stopping"){if(Be){ge(oe);return}te(oe)}},[K,te,P,ge]),ne=o.useCallback(()=>{me?.id&&(x(me.id),g("projects"),v(!0))},[v,g,x,me?.id]);if(c.isVSCode||!a&&d||!me||!K)return null;const pe=Q??be[0]??null;if(!pe)return null;const J=pe.icon||"play",Se=pe.id===ur?"search":Xo[J]||"play",he=da(K,pe.id),Ie=P[he],Pe=Ie?.status==="stopping",Ce=Ie?.status==="waiting-for-preview",X=Ie?j.get(Ie.directory)?.tabs.find(oe=>oe.id===Ie.tabId)?.previewUrl??null:null,ie=!!(Ie&&X),Ne=()=>{!Ie||!X||h(Ie.directory,X)};return r?s.jsxs("div",{className:"inline-flex items-center",children:[s.jsx("button",{type:"button",disabled:$||Pe,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:ue,"aria-label":Ie?i("projectActions.actions.stopNamedAria",{name:pe.name}):i("projectActions.actions.runNamedAria",{name:pe.name}),children:Pe||Ce?s.jsx(D,{name:"loader-4",className:"h-5 w-5 animate-spin text-[var(--status-warning)]"}):Ie?s.jsx(D,{name:"stop",className:"h-5 w-5 text-[var(--status-warning)]"}):s.jsx(D,{name:Se,className:"h-5 w-5"})}),ie?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:Ne,children:s.jsx(D,{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(D,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})}),s.jsxs(Ps,{align:"end",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs(Ot,{className:"flex items-center gap-2",onClick:ne,children:[s.jsx(D,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("projectActions.actions.addNewAction")})]}),s.jsx(Xn,{}),be.map(oe=>{const ke=oe.icon||"play",Te=oe.id===ur?"search":Xo[ke]||"play",Be=da(K,oe.id),je=P[Be],ee=!!je,R=je?.status==="stopping";return s.jsxs(Ot,{className:"flex items-center gap-2",onClick:()=>{xe(oe,!0)},children:[s.jsx(D,{name:Te,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:oe.name}),R||je?.status==="waiting-for-preview"?s.jsx(D,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):ee?s.jsx(D,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},oe.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:ue,disabled:$||Pe,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":Ie?i("projectActions.actions.stopNamedAria",{name:pe.name}):i("projectActions.actions.runNamedAria",{name:pe.name}),children:s.jsx("span",{className:"inline-flex h-4 w-4 shrink-0 items-center justify-center",children:Pe||Ce?s.jsx(D,{name:"loader-4",className:"h-4 w-4 animate-spin text-[var(--status-warning)]"}):Ie?s.jsx(D,{name:"stop",className:"h-4 w-4 text-[var(--status-warning)]"}):s.jsx(D,{name:Se,className:"h-4 w-4"})})}),ie?s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Ne,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(D,{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(D,{name:"arrow-down-s",className:"h-4 w-4"})})}),s.jsxs(Ps,{align:"start",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs(Ot,{className:"flex items-center gap-2",onClick:ne,children:[s.jsx(D,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("projectActions.actions.addNewAction")})]}),s.jsx(Xn,{}),be.map(oe=>{const ke=oe.icon||"play",Te=oe.id===ur?"search":Xo[ke]||"play",Be=da(K,oe.id),je=P[Be],ee=!!je,R=je?.status==="stopping";return s.jsxs(Ot,{className:"flex items-center gap-2",onClick:()=>{xe(oe,!0)},children:[s.jsx(D,{name:Te,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:oe.name}),R||je?.status==="waiting-for-preview"?s.jsx(D,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):ee?s.jsx(D,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},oe.id)})]})]})]})},Wl="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",L1="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",Ei=o.memo(function(e){const n=ot.c(13),{visible:r,title:a,ariaLabel:i,onClick:l,className:c,Icon:d,iconClassName:p}=e;if(!(r===void 0?!0:r))return null;const u=c??Wl,f=p??"h-[18px] w-[18px]";let b;n[0]!==d||n[1]!==f?(b=s.jsx(D,{name:d,className:f}),n[0]=d,n[1]=f,n[2]=b):b=n[2];let g;n[3]!==i||n[4]!==l||n[5]!==u||n[6]!==b?(g=s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:l,"aria-label":i,className:u,children:b})}),n[3]=i,n[4]=l,n[5]=u,n[6]=b,n[7]=g):g=n[7];let v;n[8]!==a?(v=s.jsx(It,{children:s.jsx("p",{children:a})}),n[8]=a,n[9]=v):v=n[9];let x;return n[10]!==g||n[11]!==v?(x=s.jsxs(kt,{children:[g,v]}),n[10]=g,n[11]=v,n[12]=x):x=n[12],x}),$1=o.memo(function(e){const n=ot.c(42),{isMobile:r,githubAuthStatus:a,githubAccounts:i,githubAvatarUrl:l,githubLogin:c,isSwitchingGitHubAccount:d,handleGitHubAccountSwitch:p}=e,{t:m}=ut();if(!a?.connected||r)return null;if(i.length>1){let g;n[0]===Symbol.for("react.memo_cache_sentinel")?(g=ye(Wl,"h-7 w-7 overflow-hidden rounded-full border border-border/60 bg-muted/80 p-0"),n[0]=g):g=n[0];let v;n[1]!==c||n[2]!==m?(v=c?m("header.github.connectedWithLogin",{login:c}):m("header.github.connected"),n[1]=c,n[2]=m,n[3]=v):v=n[3];let x;n[4]!==l||n[5]!==c||n[6]!==m?(x=l?s.jsx("img",{src:l,alt:c?m("header.github.avatarWithLogin",{login:c}):m("header.github.avatar"),className:"h-full w-full object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx(D,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"}),n[4]=l,n[5]=c,n[6]=m,n[7]=x):x=n[7];let h;n[8]!==d||n[9]!==v||n[10]!==x?(h=s.jsx(Is,{asChild:!0,children:s.jsx("button",{type:"button",className:g,title:v,disabled:d,children:x})}),n[8]=d,n[9]=v,n[10]=x,n[11]=h):h=n[11];let j;n[12]!==m?(j=m("header.github.accountsTitle"),n[12]=m,n[13]=j):j=n[13];let y;n[14]!==j?(y=s.jsx(Kf,{className:"typography-ui-header font-semibold text-foreground",children:j}),n[14]=j,n[15]=y):y=n[15];let C;n[16]===Symbol.for("react.memo_cache_sentinel")?(C=s.jsx(Xn,{}),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,A=!!T.current;return s.jsxs(Ot,{className:"gap-2",disabled:A||d,onSelect:()=>{A||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(D,{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]}),A?s.jsx(D,{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]!==y||n[27]!==k?(w=s.jsxs(Ps,{align:"end",className:"w-64",children:[y,C,k]}),n[26]=y,n[27]=k,n[28]=w):w=n[28];let S;return n[29]!==h||n[30]!==w?(S=s.jsxs(As,{children:[h,w]}),n[29]=h,n[30]=w,n[31]=S):S=n[31],S}let u;n[32]!==c||n[33]!==m?(u=c?m("header.github.connectedWithLogin",{login:c}):m("header.github.connected"),n[32]=c,n[33]=m,n[34]=u):u=n[34];let f;n[35]!==l||n[36]!==c||n[37]!==m?(f=l?s.jsx("img",{src:l,alt:c?m("header.github.avatarWithLogin",{login:c}):m("header.github.avatar"),className:"h-full w-full object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx(D,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"}),n[35]=l,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}),_1=o.memo(function(e){const n=ot.c(76),{isDesktopApp:r,currentInstanceLabel:a,compactCurrentInstanceLabel:i,isDesktopServicesOpen:l,setIsDesktopServicesOpen:c,refreshCurrentInstanceLabel:d,desktopServicesTab:p,setDesktopServicesTab:m,quotaResultsLength:u,fetchAllQuotas:f,servicesTabItems:b,quotaLastUpdated:g,quotaDisplayMode:v,quotaDisplayTabItems:x,handleDisplayModeChange:h,handleUsageRefresh:j,isQuotaLoading:y,isUsageRefreshSpinning:C,hasRateLimits:k,rateLimitGroups:w,expandedFamilies:S,toggleFamilyExpanded:I,shortcutLabel:T,showDevShutdown:P,isDevShutdownInFlight:A,onDevShutdown:N}=e,{t:E}=ut();let M;n[0]!==p||n[1]!==f||n[2]!==u||n[3]!==d||n[4]!==c?(M=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]=M):M=n[5];let O;n[6]!==a||n[7]!==r||n[8]!==E?(O=r?E("header.services.openWithCurrent",{current:a}):E("header.services.open"),n[6]=a,n[7]=r,n[8]=E,n[9]=O):O=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(Wl,V),n[10]=V,n[11]=B):B=n[11];let $;n[12]===Symbol.for("react.memo_cache_sentinel")?($=s.jsx(D,{name:"stack",className:"h-[18px] w-[18px]"}),n[12]=$):$=n[12];let F;n[13]!==i||n[14]!==r?(F=r?s.jsx("span",{className:"truncate typography-ui-label font-medium text-foreground",children:i}):null,n[13]=i,n[14]=r,n[15]=F):F=n[15];let _;n[16]!==O||n[17]!==B||n[18]!==F?(_=s.jsx(Ct,{asChild:!0,children:s.jsx(Is,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":O,className:B,children:[$,F]})})}),n[16]=O,n[17]=B,n[18]=F,n[19]=_):_=n[19];let q;n[20]!==a||n[21]!==r||n[22]!==T||n[23]!==E?(q=r?E("header.services.tooltip.currentInstanceWithShortcuts",{current:a,toggle:T("toggle_services_menu"),nextTab:T("cycle_services_tab")}):E("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]=E,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 Y;n[27]!==_||n[28]!==L?(Y=s.jsxs(kt,{children:[_,L]}),n[27]=_,n[28]=L,n[29]=Y):Y=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 ae;n[34]!==p||n[35]!==b||n[36]!==Z?(ae=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(Vr,{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]=ae):ae=n[37];let re;n[38]!==p||n[39]!==r||n[40]!==l||n[41]!==c?(re=r&&p==="instance"?s.jsx(Gx,{embedded:!0,open:l&&p==="instance",onOpenChange:z1,onHostSwitched:()=>c(!1)}):null,n[38]=p,n[39]=r,n[40]=l,n[41]=c,n[42]=re):re=n[42];let me;n[43]!==p||n[44]!==l?(me=p==="mcp"?s.jsx(Ah,{active:l&&p==="mcp"}):null,n[43]=p,n[44]=l,n[45]=me):me=n[45];let fe;n[46]!==p||n[47]!==S||n[48]!==h||n[49]!==j||n[50]!==k||n[51]!==y||n[52]!==C||n[53]!==v||n[54]!==x||n[55]!==g||n[56]!==w||n[57]!==E||n[58]!==I?(fe=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:E("header.services.rateLimits")}),s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:Eh(g)})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("div",{className:"h-7 w-[10.5rem]",children:s.jsx(Vr,{items:x,activeId:v,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:y||C,"aria-label":E("header.services.refreshRateLimitsAria"),children:s.jsx(D,{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:E("header.services.noRateLimits")})}),s.jsx("div",{className:"py-2",children:w.map((W,de)=>{const be=S[W.providerId]??[];return s.jsxs(o.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(xr,{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??E("header.services.noRateLimitsReported")})}):s.jsxs("div",{className:"space-y-3 px-4 pb-2",children:[W.entries.map(we=>{const[te,ge]=we,ue=v==="remaining"?ge.remainingPercent:ge.usedPercent,xe=lo(ge.usedPercent,ge.resetAt,ge.windowSeconds,te),ne=xe?.dailyAllocationPercent!=null?v==="remaining"?100-ea(xe.elapsedRatio):ea(xe.elapsedRatio):null,pe=oo(ge.valueLabel,ue),J=Hd(ge.resetAt,ge.resetAfterFormatted??ge.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:Gd(te)}),J?s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:J}):null]}),s.jsx("span",{className:"typography-ui-label tabular-nums text-foreground",children:pe==="-"?"":pe})]}),s.jsx(uo,{percent:ue,tonePercent:ge.usedPercent,className:"h-1.5",expectedMarkerPercent:ne}),xe?s.jsx(mo,{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(we=>{const te=we.familyId??"other",ge=be.includes(te);return s.jsxs(br,{open:ge,onOpenChange:()=>I(W.providerId,te),children:[s.jsxs(Tr,{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:we.familyLabel}),ge?s.jsx(D,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(D,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsx(yr,{children:s.jsx("div",{className:"space-y-2.5 pb-1 pl-1 pt-1",children:we.models.map(ue=>{const[xe,ne]=ue,pe=v==="remaining"?ne.remainingPercent:ne.usedPercent,J=lo(ne.usedPercent,ne.resetAt,ne.windowSeconds),Se=J?.dailyAllocationPercent!=null?v==="remaining"?100-ea(J.elapsedRatio):ea(J.elapsedRatio):null,he=oo(ne.valueLabel,pe);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:bl(xe)}),s.jsx("span",{className:"typography-ui-label tabular-nums text-foreground",children:he==="-"?"":he})]}),s.jsx(uo,{percent:pe,tonePercent:ne.usedPercent,className:"h-1.5",expectedMarkerPercent:Se}),J?s.jsx(mo,{paceInfo:J,compact:!0}):null]},`${W.providerId}-${xe}`)})})})]},te)})}):null]})]},W.providerId)})})]}):null,n[46]=p,n[47]=S,n[48]=h,n[49]=j,n[50]=k,n[51]=y,n[52]=C,n[53]=v,n[54]=x,n[55]=g,n[56]=w,n[57]=E,n[58]=I,n[59]=fe):fe=n[59];let H;n[60]!==A||n[61]!==N||n[62]!==P||n[63]!==E?(H=P?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"mx-4 my-2 border-t border-[var(--interactive-border)]"}),s.jsx("div",{className:"px-2 pb-2",children:s.jsx(Ot,{disabled:A,onSelect:()=>{N()},children:E("header.services.shutdownDev")})})]}):null,n[60]=A,n[61]=N,n[62]=P,n[63]=E,n[64]=H):H=n[64];let K;n[65]!==ae||n[66]!==re||n[67]!==me||n[68]!==fe||n[69]!==H?(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:[ae,re,me,fe,H]}),n[65]=ae,n[66]=re,n[67]=me,n[68]=fe,n[69]=H,n[70]=K):K=n[70];let Q;return n[71]!==l||n[72]!==M||n[73]!==Y||n[74]!==K?(Q=s.jsxs(As,{open:l,onOpenChange:M,children:[Y,K]}),n[71]=l,n[72]=M,n[73]=Y,n[74]=K,n[75]=Q):Q=n[75],Q}),B1=(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??""),V1=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},Eh=t=>{if(!t)return"-";try{return new Date(t).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"})}catch{return"-"}},mr=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},To=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,cm=({onToggleLeftDrawer:t,onToggleRightDrawer:e,leftDrawerOpen:n,rightDrawerOpen:r})=>{const{t:a}=ut(),i=Re(Ve=>Ve.setSessionSwitcherOpen),l=Re(Ve=>Ve.toggleSidebar),c=Re(Ve=>Ve.toggleBottomTerminal),d=Re(Ve=>Ve.toggleRightSidebar),p=Re(Ve=>Ve.openContextOverview),m=Re(Ve=>Ve.openContextPlan),u=Re(Ve=>Ve.openContextBrowser),f=Re(Ve=>Ve.closeContextPanel),b=Re(Ve=>Ve.contextPanelByDirectory),g=Re(Ve=>Ve.activeMainTab),v=Re(Ve=>Ve.setActiveMainTab),x=Re(Ve=>Ve.shortcutOverrides),h=yt(Ve=>Ve.getCurrentModel),j=Bn(),[y,C]=o.useState(!1),k=$t(Ve=>Ve.getContextUsage),w=$t(Ve=>!!Ve.newSessionDraft?.open),S=$t(Ve=>Ve.currentSessionId),I=qx(S??""),T=Hf(S??null),P=Oa(Ve=>Ve.activeSessions),A=Td(),N=Cs(Ve=>Ve.activeProjectId?Ve.projects.find(Dt=>Dt.id===Ve.activeProjectId)??null:null),E=o.useMemo(()=>{if(!N)return null;const Ve=N.label?.trim();if(Ve)return Ve;const Dt=N.path.split(/[\\/]/).filter(Boolean);return Dt[Dt.length-1]??null},[N]),M=Es(Ve=>Ve.results),O=Es(Ve=>Ve.fetchAllQuotas),V=Es(Ve=>Ve.isLoading),B=Es(Ve=>Ve.lastUpdated),$=Es(Ve=>Ve.displayMode),F=Es(Ve=>Ve.dropdownProviderIds),_=Es(Ve=>Ve.loadSettings),q=Es(Ve=>Ve.setDisplayMode),{isMobile:L}=an(),Y=Hn(Ve=>Ve.status),Z=Hn(Ve=>Ve.setStatus),ae=o.useRef(null),[re,me]=o.useState(()=>typeof window>"u"?!1:Cn()),fe=o.useMemo(()=>Md(),[]),H=Gf(),[K,Q]=o.useState(!1),W=o.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),de=o.useMemo(()=>{if(typeof window>"u")return null;const Ve=window.__OPENCHAMBER_MACOS_MAJOR__;if(typeof Ve=="number"&&Number.isFinite(Ve)&&Ve>0)return Ve;if(typeof navigator>"u")return null;const Dt=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!Dt)return null;const Gt=Number.parseInt(Dt[1],10),as=Number.parseInt(Dt[2],10);return Number.isNaN(Gt)?null:Gt===10?as:Gt},[]);_e.useEffect(()=>{typeof window>"u"||me(Cn())},[]);const be=h(),we=be&&typeof be.limit=="object"&&be.limit!==null?be.limit:null,te=we&&typeof we.context=="number"?we.context:0,ge=we&&typeof we.output=="number"?we.output:0,ue=k(te,ge),[xe,ne]=o.useState(null),pe=!S||I;_e.useEffect(()=>{if(!S){ne(Ve=>Ve===null?Ve:null);return}if(ue&&ue.totalTokens>0){ne(Ve=>B1(Ve,ue)?Ve:ue);return}pe&&ne(Ve=>Ve===null?Ve:null)},[ue,S,pe]);const J=Re(Ve=>Ve.isSessionSwitcherOpen),Se=Y?.connected?Y.user?.avatarUrl??null:null,he=Y?.connected?Y.user?.login??null:null,Ie=Y?.accounts??[],[Pe,Ce]=o.useState(!1),[X,ie]=o.useState(!1),[Ne,oe]=o.useState(!1),[ke,Te]=o.useState(!1),[Be,je]=o.useState("Local"),ee=o.useMemo(()=>V1(Be),[Be]),[R,U]=o.useState(re?"instance":"usage"),[le,Me]=o.useState("usage");_e.useEffect(()=>{!re&&R==="instance"&&U("usage")},[R,re]);const Oe=o.useMemo(()=>mn(),[]),Ae=!Oe&&g==="chat"&&!!xe&&xe.totalTokens>0,z=xe&&xe.contextLimit>0?Math.min(999,xe.totalTokens/xe.contextLimit*100):0,De=o.useCallback(async()=>{if(!(typeof window>"u"||!re))try{const Ve=await Yx(),Dt=window.location.href,Gt=window.__OPENCHAMBER_LOCAL_ORIGIN__||window.location.origin;if(Su(Dt,Gt)){je("Local");return}const as=Ve.hosts.find(_s=>Su(Dt,_s.url));if(as?.label?.trim()){je(Qx(as.label.trim()));return}je("Instance")}catch{je("Local")}},[re]);_e.useEffect(()=>{De()},[De]),Ih();const Xe=Es(Ve=>Ve.selectedModels),st=Es(Ve=>Ve.expandedFamilies),tt=Es(Ve=>Ve.toggleFamilyExpanded),Ue=o.useMemo(()=>{const Ve=[];for(const Dt of Wr){if(!F.includes(Dt.id))continue;const Gt=M.find(Zs=>Zs.providerId===Dt.id),as=Gt?.usage?.windows??{},_s=Gt?.usage?.models,qs=Object.entries(as),Ws={providerId:Dt.id,providerName:Dt.name,entries:qs,error:Gt&&!Gt.ok&&Gt.configured?Gt.error:void 0};if(_s&&Object.keys(_s).length>0){const Zs=Xe[Dt.id]??[],tn=Zs.length>0,or=Uv(_s,Dt.id),tr=kh(Dt.id),Kr=Ch(tr);Ws.modelFamilies=[];for(const cn of Kr){const pn=or.get(cn.id)??[];if(pn.length===0)continue;const yn=tn?pn.filter(wr=>Zs.includes(wr)):pn;if(yn.length===0)continue;const Nn=[];for(const wr of yn){const vn=_s[wr];if(vn?.windows){const Ur=Object.entries(vn.windows);Ur.length>0&&Nn.push([wr,Ur[0][1]])}}Nn.length>0&&Ws.modelFamilies.push({familyId:cn.id,familyLabel:cn.label,models:Nn})}const zr=or.get(null)??[],In=tn?zr.filter(cn=>Zs.includes(cn)):zr;if(In.length>0){const cn=[];for(const pn of In){const yn=_s[pn];if(yn?.windows){const Nn=Object.entries(yn.windows);Nn.length>0&&cn.push([pn,Nn[0][1]])}}cn.length>0&&Ws.modelFamilies.push({familyId:null,familyLabel:a("header.services.modelFamily.other"),models:cn})}}(qs.length>0||Ws.modelFamilies&&Ws.modelFamilies.length>0||Ws.error)&&Ve.push(Ws)}return Ve},[F,M,Xe,a]),it=Ue.length>0;o.useEffect(()=>{_()},[_]);const Ye=o.useCallback(async Ve=>{q(Ve);try{await Ss({usageDisplayMode:Ve})}catch(Dt){console.warn("Failed to update usage display mode:",Dt)}},[q]),rt=o.useCallback(()=>{if(ke)return;Te(!0);const Ve=new Promise(Dt=>setTimeout(Dt,500));Promise.all([O(),Ve]).finally(()=>{Te(!1)})},[O,ke]),Je=o.useMemo(()=>S?A.find(Ve=>Ve.id===S)??P.find(Ve=>Ve.id===S)??T??Jx().find(Ve=>Ve.id===S)??null:null,[S,T,P,A]),ce=o.useRef(null),[We,Le]=o.useState(0);o.useEffect(()=>{if(!S){ce.current&&(ce.current=null,Le(as=>as+1));return}if(Je){ce.current={sessionId:S,session:Je,expiresAt:Date.now()+2e3};return}const Ve=ce.current;if(!Ve||Ve.sessionId!==S)return;const Dt=Ve.expiresAt-Date.now();if(Dt<=0){ce.current=null,Le(as=>as+1);return}const Gt=window.setTimeout(()=>{ce.current?.sessionId===S&&(ce.current=null),Le(as=>as+1)},Dt);return()=>{window.clearTimeout(Gt)}},[S,Je]);const Ge=(()=>{if(Je)return Je;if(!S)return null;const Ve=ce.current;return Ve&&Ve.sessionId===S&&Ve.expiresAt>Date.now()?Ve.session:null})(),at=$t(Ve=>S?Ve.worktreeMetadata.get(S)?.path??"":""),He=$t(Ve=>S?Ve.worktreeMetadata.get(S)?.branch?.trim()??null:null),ze=qf(Ve=>S?Ve.getAttachment(S):void 0),et=o.useMemo(()=>ze?Xx(ze):null,[ze]),gt=o.useMemo(()=>ze?ze.legacy?"legacy":ze.degraded?"degraded":ze.worktreeStatus==="missing"?"missing":ze.worktreeStatus==="invalid"?"invalid":ze.attentionReason?"attention":null:null,[ze]),Pt=o.useMemo(()=>mr(at||""),[at]),Nt=o.useMemo(()=>{const Ve=typeof Ge?.directory=="string"?Ge.directory:"";return mr(Ve||"")},[Ge?.directory]),ht=$t(Ve=>Ve.newSessionDraft?.open?mr(Ve.newSessionDraft.bootstrapPendingDirectory??Ve.newSessionDraft.directoryOverride??""):""),wt=o.useMemo(()=>Pt||Nt||ht,[ht,Nt,Pt]),es=$t(Ve=>{const Dt=mr(Pt||Nt||"");if(!Dt)return null;for(const Gt of Ve.availableWorktreesByProject.values()){const _s=Gt.find(qs=>mr(qs.path)===Dt)?.branch?.trim();if(_s)return _s}return null}),Jt=Zx(wt||null)||He||es,mt=o.useMemo(()=>{if(!S)return E??"OpenChamber";const Ve=Ge?.title?.trim();return Ve&&Ve.length>0?Ve:"Untitled Session"},[E,Ge?.title,S]),Lt=o.useMemo(()=>Yf(Ge?.summary),[Ge?.summary]),ts=o.useMemo(()=>Lt||{additions:0,deletions:0},[Lt]),js=ts.additions>0||ts.deletions>0,ds=o.useMemo(()=>mr(wt||N?.path||""),[N?.path,wt]),hs=o.useMemo(()=>N?{id:N.id,path:N.path}:null,[N]),Ut=o.useRef(null);o.useEffect(()=>{!hs||!ds||(Ut.current={projectRef:hs,directory:ds})},[ds,hs]);const Qe=o.useMemo(()=>hs&&ds?{projectRef:hs,directory:ds}:Ut.current,[ds,hs]),At=Ed(Ve=>Ve.planModeEnabled),Ht=$t(Ve=>Ve.isSessionPlanAvailable),jt=At&&S?Ht(S):!1,Zt=jt,rs=o.useRef("");o.useEffect(()=>{if(!At){Re.getState().activeMainTab==="plan"&&Re.getState().setActiveMainTab("chat");return}if(!S)return;const Ve=`${S||"none"}:${Nt||"none"}:${Ge?.time?.created||0}:${Ge?.slug||"none"}`;rs.current!==Ve&&(rs.current=Ve),!jt&&Re.getState().activeMainTab==="plan"&&Re.getState().setActiveMainTab("chat")},[At,jt,Ge?.slug,Ge?.time?.created,S,Nt]);const Ds=o.useCallback(async Ve=>{if(!(!Ve||Pe)){Ce(!0);try{const Dt=j.github?await j.github.authActivate(Ve):await(async()=>{const Gt=await fetch("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:Ve})}),as=await Gt.json().catch(()=>null);if(!Gt.ok||!as)throw new Error(as?.error||Gt.statusText);return as})();Z(Dt)}catch(Dt){console.error("Failed to switch GitHub account:",Dt)}finally{Ce(!1)}}},[Pe,j.github,Z]),ns=o.useCallback(()=>{if(typeof document>"u")return;const Ve=document.activeElement;if(!Ve)return;const Dt=Ve.tagName;(Dt==="INPUT"||Dt==="TEXTAREA"||Dt==="SELECT"||Ve.isContentEditable)&&Ve.blur()},[]),zs=o.useCallback(()=>{if(L){ns(),i(!J);return}l()},[ns,L,J,i,l]),$s=o.useCallback(()=>{fl("desktop_open_draft_mini_chat_window",{directory:mr(wt||N?.path||""),projectId:N?.id??null}).catch(Ve=>{console.warn("[header] failed to open draft mini chat window",Ve)})},[N?.id,N?.path,wt]),gn=o.useCallback(()=>{if(w){$s();return}S&&fl("desktop_open_session_mini_chat_window",{sessionId:S,directory:mr(wt||N?.path||"")}).catch(Ve=>{console.warn("[header] failed to open session mini chat window",Ve)})},[N?.path,S,$s,w,wt]),rn=o.useCallback(()=>{const Ve=mr(wt||"");if(!Ve)return;const Dt=b[Ve];if(To(Dt)==="context"){f(Ve);return}p(Ve)},[f,b,p,wt]),Wt=o.useMemo(()=>{const Ve=mr(wt||"");if(!Ve)return!1;const Dt=b[Ve];return To(Dt)==="context"},[b,wt]),Kt=o.useCallback(()=>{const Ve=mr(wt||"");if(!Ve)return;const Dt=b[Ve];if(To(Dt)==="plan"){f(Ve);return}m(Ve)},[f,b,m,wt]),se=o.useCallback(()=>{const Ve=mr(wt||"");Ve&&u(Ve)},[u,wt]),bt=o.useMemo(()=>{const Ve=mr(wt||"");if(!Ve)return!1;const Dt=b[Ve];return To(Dt)==="plan"},[b,wt]),_t=Wl,lt=L1,ss=o.useMemo(()=>X?"services":n?"sessions":r?"git":g,[g,X,n,r]),cs=o.useCallback(()=>{ie(!1),n&&t&&t(),r&&e&&e(),!t&&J&&i(!1)},[J,n,t,e,r,i]),Ke=o.useCallback(()=>{n||ie(!1),t?.()},[n,t]),xt=o.useCallback(()=>{r||ie(!1),e?.()},[e,r]),Tt=o.useMemo(()=>re&&W&&!K||H?"pl-[5.5rem]":"pl-3",[re,K,W,H]);_e.useEffect(()=>{if(!re||!W){Q(!1);return}let Ve=!1,Dt=null;const Gt=async()=>{try{const{getCurrentWindow:_s}=await Dr(async()=>{const{getCurrentWindow:Zs}=await import("./vendor-.bun-Bum-iBXX.js").then(tn=>tn.bP);return{getCurrentWindow:Zs}},__vite__mapDeps([0,1])),Ws=await _s().isFullscreen();Ve||Q(Ws)}catch{Ve||Q(!1)}},as=async()=>{try{const{getCurrentWindow:_s}=await Dr(async()=>{const{getCurrentWindow:Ws}=await import("./vendor-.bun-Bum-iBXX.js").then(Zs=>Zs.bP);return{getCurrentWindow:Ws}},__vite__mapDeps([0,1]));Dt=await _s().onResized(()=>{Gt()})}catch{}};return Gt(),as(),()=>{Ve=!0,Dt&&Dt()}},[re,W]);const Et=o.useMemo(()=>!re||!W||de===null?"":de>=26?"h-12":de<=15?"h-14":"",[re,W,de]),Qt=o.useMemo(()=>{if(!(re||Oe))return{paddingLeft:H?"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))"}},[re,H,Oe]),Rt=o.useCallback(()=>{if(typeof document>"u")return;const Ve=ae.current?.getBoundingClientRect().height;Ve&&document.documentElement.style.setProperty("--oc-header-height",`${Ve}px`)},[]);_e.useEffect(()=>{if(typeof window>"u")return;Rt();const Ve=ae.current;if(!Ve||typeof ResizeObserver>"u")return()=>{};let Dt=0;const Gt=()=>{Dt||(Dt=requestAnimationFrame(()=>{Dt=0,Rt()}))},as=new ResizeObserver(Gt);return as.observe(Ve),window.addEventListener("resize",Gt),window.addEventListener("orientationchange",Gt),()=>{Dt&&cancelAnimationFrame(Dt),as.disconnect(),window.removeEventListener("resize",Gt),window.removeEventListener("orientationchange",Gt)}},[Rt]),_e.useEffect(()=>{Rt()},[Rt,L,Et]);const Os=o.useCallback(async Ve=>{const Dt=Ve.target;Dt.closest(".app-region-no-drag")||Dt.closest("button, a, input, select, textarea")||Ve.button===0&&re&&await eb()},[re]),Ts=o.useMemo(()=>{if(L){const Ve=[{id:"chat",label:a("layout.mainTab.chat"),icon:"chat-4"}];return Zt&&Ve.push({id:"plan",label:a("layout.mainTab.plan"),icon:"file-text"}),Ve.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"}),Ve}return[]},[L,Zt,a]),ks=o.useCallback(Ve=>Fl(Zr(Ve,x)),[x]);_e.useEffect(()=>{!L&&(g==="git"||g==="terminal"||g==="diff"||g==="files"||g==="context")&&v("chat")},[g,L,v]);const Bs=o.useMemo(()=>{const Ve=[];return re&&Ve.push({value:"instance",label:a("layout.services.instance"),icon:"server"}),Ve.push({value:"usage",label:a("layout.services.usage"),icon:"timer"},{value:"mcp",label:"MCP",icon:"plug-2"}),Ve},[re,a]),ys=o.useMemo(()=>Bs.map(Ve=>({id:Ve.value,label:Ve.label,icon:s.jsx(D,{name:Ve.icon,className:"h-3.5 w-3.5"})})),[Bs]),Gn=o.useMemo(()=>{if(typeof window>"u"||re||Oe)return!1;const Ve=window.location.hostname;return Ve==="localhost"||Ve==="127.0.0.1"||Ve==="::1"},[re,Oe]),xn=o.useCallback(async()=>{if(y)return;C(!0),oe(!1);const Ve=[];let Dt=!1;try{try{for(const[,Gt]of on.getState().sessions.entries())for(const as of Gt.tabs)as.previewUrl&&Ve.push(as.previewUrl)}catch{}try{await _x({})}catch{}try{(await fetch("/api/system/dev-shutdown",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({previewUrls:Ve})})).ok?Dt=!0:Dt=(await fetch("/api/system/shutdown",{method:"POST"})).ok}catch{}}finally{Dt||C(!1)}},[y,oe]),ln=o.useMemo(()=>[{value:"usage",label:a("header.services.used")},{value:"remaining",label:a("header.services.remaining")}],[a]),ar=o.useMemo(()=>ln.map(Ve=>({id:Ve.value,label:Ve.label})),[ln]),Us=o.useMemo(()=>[{id:"usage",label:a("layout.services.usage"),icon:s.jsx(D,{name:"timer",className:"h-3.5 w-3.5"})},{id:"mcp",label:"MCP",icon:s.jsx(D,{name:"command",className:"h-3.5 w-3.5"})}],[a]);_e.useEffect(()=>{const Ve=Dt=>{if(Rd(Dt)&&!Dt.shiftKey&&!Dt.altKey){const Gt=parseInt(Dt.key,10);Gt>=1&&Gt<=Ts.length&&(Dt.preventDefault(),L&&(ns(),cs()),v(Ts[Gt-1].id))}};return window.addEventListener("keydown",Ve),()=>window.removeEventListener("keydown",Ve)},[ns,cs,L,v,Ts]),_e.useEffect(()=>{const Ve=Dt=>{const Gt=Zr("toggle_services_menu",x);if(qo(Dt,Gt)){Dt.preventDefault(),Ne?oe(!1):(oe(!0),De(),R==="usage"&&M.length===0&&O());return}const as=Zr("cycle_services_tab",x);if(qo(Dt,as)){Dt.preventDefault();const qs=Bs.map(or=>or.value);if(qs.length===0)return;const Ws=qs.indexOf(R),Zs=Ws===-1?0:(Ws+1)%qs.length,tn=qs[Zs];U(tn),oe(!0),De(),tn==="usage"&&M.length===0&&O();return}const _s=Zr("toggle_context_plan",x);qo(Dt,_s)&&(Dt.preventDefault(),Kt())};return window.addEventListener("keydown",Ve),()=>window.removeEventListener("keydown",Ve)},[x,Ne,R,Bs,M.length,O,De,Kt]);const bn=Ve=>{const Dt=g===Ve.id,Gt=Ve.icon==="diff",as=Gt?null:Ve.icon,_s=Ve.id==="chat",qs=Zs=>Gt?s.jsx(Ju,{size:Zs}):as?s.jsx(D,{name:as,className:`h-${Zs/4} w-${Zs/4}`}):null,Ws=s.jsxs("button",{type:"button",onClick:()=>v(Ve.id),className:ye("relative flex h-8 items-center gap-2 px-3 rounded-lg typography-ui-label font-medium transition-colors",Dt?"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",_s&&!L&&"min-w-[100px] justify-center"),"aria-label":Ve.label,"aria-selected":Dt,role:"tab",children:[L?qs(20):s.jsxs(s.Fragment,{children:[qs(16),s.jsx("span",{className:"header-tab-label",children:Ve.label})]}),Ve.badge!==void 0&&Ve.badge>0&&s.jsx("span",{className:"header-tab-badge typography-micro text-status-info font-medium",children:Ve.badge})]});return s.jsx(o.Fragment,{children:Ws},Ve.id)},ir=s.jsxs(s.Fragment,{children:[Zt&&s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":a("header.actions.openPlanAria"),onClick:Kt,className:ye(_t,bt&&"bg-[var(--interactive-hover)]"),children:s.jsx(D,{name:"file-text",className:"h-[18px] w-[18px]"})})}),s.jsx(It,{children:s.jsx("p",{children:a("header.actions.planWithShortcut",{shortcut:ks("toggle_context_plan")})})})]}),s.jsx(a1,{directory:ds,className:"mr-1"}),s.jsx(_1,{isDesktopApp:re,currentInstanceLabel:Be,compactCurrentInstanceLabel:ee,isDesktopServicesOpen:Ne,setIsDesktopServicesOpen:oe,refreshCurrentInstanceLabel:De,desktopServicesTab:R,setDesktopServicesTab:U,quotaResultsLength:M.length,fetchAllQuotas:O,servicesTabItems:ys,quotaLastUpdated:B,quotaDisplayMode:$,quotaDisplayTabItems:ar,handleDisplayModeChange:Ye,handleUsageRefresh:rt,isQuotaLoading:V,isUsageRefreshSpinning:ke,hasRateLimits:it,rateLimitGroups:Ue,expandedFamilies:st,toggleFamilyExpanded:tt,shortcutLabel:ks,showDevShutdown:Gn,isDevShutdownInFlight:y,onDevShutdown:xn}),s.jsx(Ei,{title:a("header.actions.terminalPanelWithShortcut",{shortcut:ks("toggle_terminal")}),ariaLabel:a("header.actions.toggleTerminalPanelAria"),onClick:c,Icon:"terminal-box"}),fe?s.jsx(Ei,{title:a("contextPanel.browser.open"),ariaLabel:a("contextPanel.browser.open"),onClick:se,Icon:"global"}):null,s.jsx(Ei,{title:a("header.actions.rightSidebarWithShortcut",{shortcut:ks("toggle_right_sidebar")}),ariaLabel:a("header.actions.toggleRightSidebarAria"),onClick:d,Icon:"layout-right"}),s.jsx($1,{isMobile:L,githubAuthStatus:Y,githubAccounts:Ie,githubAvatarUrl:Se,githubLogin:he,isSwitchingGitHubAccount:Pe,handleGitHubAccountSwitch:Ds})]}),Vn=fe&&(w||!!S),Mr=()=>s.jsxs("div",{onMouseDown:Os,className:ye("app-region-drag relative flex h-12 select-none items-center pr-3",Tt,Et),style:Qt,role:"tablist","aria-label":a("header.navigation.mainAria"),children:[s.jsx(Ei,{title:a("header.actions.openSessionsWithShortcut",{shortcut:ks("toggle_sidebar")}),ariaLabel:a("header.actions.openSessionsAria"),onClick:zs,className:`${_t} shrink-0`,Icon:"layout-left"}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center pl-3",children:[Qe&&s.jsx(lm,{projectRef:Qe.projectRef,directory:Qe.directory,className:"mr-2"}),s.jsx(tb,{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"):mt}),E||Jt||!w&&(js||gt)?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:[E?s.jsx("span",{className:"truncate",children:E}):null,Jt?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(D,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:Jt})]}):null,!w&&js?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:["+",ts.additions]}),s.jsx("span",{className:"text-muted-foreground/60",children:"/"}),s.jsxs("span",{className:"text-status-error/65",children:["-",ts.deletions]})]}):null,!w&>?s.jsxs("span",{className:ye("inline-flex min-w-0 items-center gap-0.5",gt==="attention"||gt==="invalid"||gt==="missing"?"text-status-warning":"text-muted-foreground/60"),children:[s.jsx(D,{name:"alert",className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:et})]}):null]}):null]})}),Ts.length>0&&s.jsx("div",{className:"flex items-center gap-1 rounded-lg bg-[var(--surface-muted)]/50 p-1",children:Ts.map(Ve=>bn(Ve))}),s.jsx("div",{className:"flex-1"}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Ae&&xe?s.jsx(sb,{totalTokens:xe.totalTokens,percentage:z,colorPercentage:xe.percentage,contextLimit:xe.contextLimit,outputLimit:xe.outputLimit??0,size:"compact",hideIcon:!0,showPercentIcon:!0,onClick:rn,pressed:Wt,className:Vn?"":"mr-3.5",valueClassName:"typography-ui-label font-medium leading-none text-foreground",percentIconClassName:"h-5 w-5"}):null,s.jsx(Ei,{visible:Vn,title:a(w?"header.actions.newMiniChat":"header.actions.openSessionMiniChat"),ariaLabel:a(w?"header.actions.newMiniChatAria":"header.actions.openSessionMiniChatAria"),onClick:gn,className:ye(_t,Ae?"mr-3.5":"mr-1"),Icon:"picture-in-picture-2"}),ir]})]})]}),Ls=()=>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:Ke,className:ye(lt,ss==="sessions"&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":a(n?"header.actions.closeSessionsAria":"header.actions.openSessionsAria"),children:s.jsx(D,{name:"layout-left",className:"h-5 w-5"})}):J?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(D,{name:"arrow-left-s",className:"h-5 w-5"})}):s.jsx("button",{type:"button",onClick:zs,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(D,{name:"play-list-add",className:"h-5 w-5"})}),!t&&J&&s.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:a("header.sessions.title")})]}),(!J||!!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:Ts.map(Ve=>{const Dt=g===Ve.id,Gt=Ve.icon==="diff",as=Gt?null:Ve.icon;return s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>{L&&(ns(),cs()),v(Ve.id)},"aria-label":Ve.label,"aria-selected":Dt,role:"tab",className:ye(lt,"relative rounded-lg",ss===Ve.id&&"bg-interactive-selection text-interactive-selection-foreground"),children:[Gt?s.jsx(Ju,{className:"h-5 w-5"}):as?s.jsx(D,{name:as,className:"h-5 w-5"}):null,Ve.badge!==void 0&&Ve.badge>0&&s.jsx("span",{className:"absolute -top-1 -right-1 text-[10px] font-semibold text-primary",children:Ve.badge}),Ve.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:Ve.label})})]},Ve.id)})})})})}),s.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[Qe&&s.jsx(lm,{projectRef:Qe.projectRef,directory:Qe.directory,compact:!0,allowMobile:!0,className:"h-9"}),s.jsxs(As,{open:X,onOpenChange:Ve=>{Ve&&(n&&t&&t(),r&&e&&e()),ie(Ve),Ve&&M.length===0&&O()},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(lt,ss==="services"&&"bg-interactive-selection text-interactive-selection-foreground"),children:s.jsx(D,{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(Vr,{items:Us,activeId:le,onSelect:Ve=>{const Dt=Ve;Me(Dt),Dt==="usage"&&M.length===0&&O()},layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",activePillButtonClassName:"h-8",className:"h-full"})}),s.jsx("button",{type:"button",onClick:()=>ie(!1),className:"inline-flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover","aria-label":a("header.services.closeAria"),children:s.jsx(D,{name:"close",className:"h-5 w-5"})})]})}),le==="mcp"&&s.jsx(Ah,{active:X&&le==="mcp"}),le==="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:Eh(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:()=>Ye("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:()=>Ye("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:rt,disabled:V||ke,"aria-label":a("header.services.refreshRateLimitsAria"),children:s.jsx(D,{name:"refresh",className:ye("h-4 w-4",ke&&"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:Ue.map((Ve,Dt)=>s.jsxs(o.Fragment,{children:[Dt>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(xr,{providerId:Ve.providerId,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:Ve.providerName})]}),Ve.entries.length===0&&(!Ve.modelFamilies||Ve.modelFamilies.length===0)?s.jsx("div",{className:"px-4 pb-2",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:Ve.error??a("header.services.noRateLimitsReported")})}):s.jsxs("div",{className:"space-y-3 px-4 pb-2",children:[Ve.entries.map(([Gt,as])=>{const _s=$==="remaining"?as.remainingPercent:as.usedPercent,qs=lo(as.usedPercent,as.resetAt,as.windowSeconds,Gt),Ws=qs?.dailyAllocationPercent!=null?$==="remaining"?100-ea(qs.elapsedRatio):ea(qs.elapsedRatio):null,Zs=oo(as.valueLabel,_s),tn=Hd(as.resetAt,as.resetAfterFormatted??as.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:Gd(Gt)}),tn?s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:tn}):null]}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:Zs==="-"?"":Zs})]}),s.jsx(uo,{percent:_s,tonePercent:as.usedPercent,className:"h-1.5",expectedMarkerPercent:Ws}),qs?s.jsx(mo,{paceInfo:qs,compact:!0}):null]},`${Ve.providerId}-${Gt}`)}),Ve.modelFamilies&&Ve.modelFamilies.length>0&&s.jsx("div",{className:"space-y-0.5",children:Ve.modelFamilies.map(Gt=>{const _s=(st[Ve.providerId]??[]).includes(Gt.familyId??"other");return s.jsxs(br,{open:_s,onOpenChange:()=>tt(Ve.providerId,Gt.familyId??"other"),children:[s.jsxs(Tr,{className:"flex w-full items-center justify-between rounded-md px-1 py-1.5 text-left hover:bg-[var(--interactive-hover)]/50 transition-colors",children:[s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:Gt.familyLabel}),_s?s.jsx(D,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(D,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsx(yr,{children:s.jsx("div",{className:"space-y-2.5 pb-1 pl-1 pt-1",children:Gt.models.map(([qs,Ws])=>{const Zs=$==="remaining"?Ws.remainingPercent:Ws.usedPercent,tn=lo(Ws.usedPercent,Ws.resetAt,Ws.windowSeconds),or=tn?.dailyAllocationPercent!=null?$==="remaining"?100-ea(tn.elapsedRatio):ea(tn.elapsedRatio):null,tr=oo(Ws.valueLabel,Zs);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:bl(qs)}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:tr==="-"?"":tr})]}),s.jsx(uo,{percent:Zs,tonePercent:Ws.usedPercent,className:"h-1.5",expectedMarkerPercent:or}),tn?s.jsx(mo,{paceInfo:tn,compact:!0}):null]},`${Ve.providerId}-${qs}`)})})})]},Gt.familyId??"other")})})]})]},Ve.providerId))})]})]})})]}),e?s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:xt,className:ye(lt,"relative",ss==="git"&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":r?"Close git sidebar":"Open git sidebar",children:s.jsx(D,{name:"layout-right",className:"h-5 w-5"})})}),s.jsx(It,{children:s.jsx("p",{children:r?"Close git sidebar":"Open git sidebar"})})]}):null]})]})]}),Rs=ye("header-safe-area relative z-10",L?"border-b border-border/50 bg-background":"bg-sidebar");return s.jsx("header",{ref:ae,className:Rs,style:{"--padding-scale":"1"},children:L?Ls():Mr()})};function z1(){}const dm=180,um=640,U1=110,W1=t=>{const e=ot.c(44),{isOpen:n,isMobile:r,children:a}=t,{t:i}=ut(),l=Re(K1),c=Re(H1),d=Re(G1),p=Re(q1),[m,u]=o.useState(null),[f,b]=o.useState(!1),g=o.useRef(null),v=o.useRef(0),x=o.useRef(l||300),h=Math.min(um,Math.max(dm,l||300));let j,y;e[0]!==n?(j=()=>{n||(u(null),b(!1))},y=[n],e[0]=n,e[1]=j,e[2]=y):(j=e[1],y=e[2]),o.useEffect(j,y);let C,k;e[3]!==c||e[4]!==r||e[5]!==n?(C=()=>{if(r||!n||!c)return;const Z=()=>{const me=g.current?.parentElement?.getBoundingClientRect().height;if(!me||me<=0)return;const fe=Math.max(0,Math.round(me));u(H=>H===fe?H:fe)};Z();const ae=g.current?.parentElement;if(!ae)return;const re=new ResizeObserver(Z);return re.observe(ae),()=>{re.disconnect()}},k=[c,r,n],e[3]=c,e[4]=r,e[5]=n,e[6]=C,e[7]=k):(C=e[6],k=e[7]),o.useEffect(C,k);let w,S;if(e[8]!==c||e[9]!==r||e[10]!==f||e[11]!==d||e[12]!==p?(w=()=>{if(r||!f||c)return;const Z=re=>{const me=v.current-re.clientY,fe=Math.min(um,Math.max(dm,x.current+me));d(fe)},ae=()=>{b(!1),Re.getState().bottomTerminalHeight<=U1&&p(!1)};return window.addEventListener("pointermove",Z),window.addEventListener("pointerup",ae,{once:!0}),()=>{window.removeEventListener("pointermove",Z),window.removeEventListener("pointerup",ae)}},S=[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]=S):(w=e[13],S=e[14]),o.useEffect(w,S),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),v.current=Z.clientY,x.current=I,Z.preventDefault())},e[15]=I,e[16]=c,e[17]=n,e[18]=P):P=e[18];const A=P,N=T?"absolute inset-x-0 bottom-0 z-40":"relative",E=f?"transition-none":"transition-[height] duration-300 ease-in-out",M=(!n||T)&&"border-t-0";let O;e[19]!==M||e[20]!==N||e[21]!==E?(O=ye("flex overflow-hidden border-t border-border bg-sidebar",N,E,M),e[19]=M,e[20]=N,e[21]=E,e[22]=O):O=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]!==A||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:A,role:"separator","aria-orientation":"horizontal","aria-label":i("terminalView.bottomDock.resizeAria")}),e[26]=A,e[27]=c,e[28]=n,e[29]=f,e[30]=i,e[31]=$):$=e[31];const F=!n&&"pointer-events-none select-none opacity-0";let _;e[32]!==F?(_=ye("relative z-10 flex h-full min-h-0 w-full flex-col transition-opacity duration-300 ease-in-out",F),e[32]=F,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 Y;return e[38]!==O||e[39]!==V||e[40]!==B||e[41]!==$||e[42]!==L?(Y=s.jsxs("section",{ref:g,className:O,style:V,"aria-hidden":B,children:[$,L]}),e[38]=O,e[39]=V,e[40]=B,e[41]=$,e[42]=L,e[43]=Y):Y=e[43],Y};function K1(t){return t.bottomTerminalHeight}function H1(t){return t.isBottomTerminalExpanded}function G1(t){return t.setBottomTerminalHeight}function q1(t){return t.setBottomTerminalOpen}const od=280,mm=280,pm=500,Y1=({isOpen:t,isMobile:e,children:n,className:r})=>{const{t:a}=ut(),i=Re(w=>w.sidebarWidth),l=Re(w=>w.setSidebarWidth),[c,d]=o.useState(!1),p=o.useRef(0),m=o.useRef(i||od),u=o.useRef(null),f=o.useRef(null),b=o.useRef(null),g=o.useCallback(w=>Math.min(pm,Math.max(mm,w)),[]),v=o.useCallback(w=>{const S=b.current;S&&(S.style.width=`${w}px`,S.style.minWidth=`${w}px`,S.style.maxWidth=`${w}px`,S.style.setProperty("--oc-left-sidebar-width",`${w}px`))},[]);if(o.useEffect(()=>{e&&c&&d(!1)},[e,c]),o.useEffect(()=>{c||(u.current=null,f.current=null)},[c]),e)return null;const x=Math.min(pm,Math.max(mm,i||od)),h=t?x: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,v(h),w.preventDefault()}},y=w=>{if(e||!c||f.current!==w.pointerId)return;const S=w.clientX-p.current,I=g(m.current+S);u.current!==I&&(u.current=I,v(I))},C=w=>{if(f.current!==w.pointerId||e)return;try{w.currentTarget.releasePointerCapture(w.pointerId)}catch{}const S=g(u.current??h);f.current=null,u.current=null,d(!1),l(S)},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:x}px`,overflowX:"clip",transitionProperty:c?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!t||h===0,children:[t&&s.jsx("div",{className: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:y,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})})})]})},ld=420,fm=360,hm=860,Q1=({isOpen:t,children:e,className:n})=>{const{t:r}=ut(),a=Re(k=>k.rightSidebarWidth),i=Re(k=>k.setRightSidebarWidth),[l,c]=o.useState(!1),d=o.useRef(0),p=o.useRef(a||ld),m=o.useRef(null),u=o.useRef(null),f=o.useRef(null),b=o.useCallback(k=>Math.min(hm,Math.max(fm,k)),[]),g=o.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`))},[]),v=Math.min(hm,Math.max(fm,a||ld)),x=t?v:0,h=k=>{if(t){try{k.currentTarget.setPointerCapture(k.pointerId)}catch{}u.current=k.pointerId,c(!0),d.current=k.clientX,p.current=x,m.current=x,g(x),k.preventDefault()}},j=k=>{if(!l||u.current!==k.pointerId)return;const w=d.current-k.clientX,S=b(p.current+w);m.current!==S&&(m.current=S,g(S))},y=k=>{if(u.current!==k.pointerId)return;try{k.currentTarget.releasePointerCapture(k.pointerId)}catch{}const w=b(m.current??x);u.current=null,m.current=null,c(!1),i(w)};o.useEffect(()=>{l||(m.current=null,u.current=null)},[l]);const C=l?m.current??x:x;return s.jsxs("aside",{ref: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":`${l?C:v}px`,overflowX:"clip",transitionProperty:l?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!t||x===0,children:[t&&s.jsx("div",{className:ye("absolute left-0 top-0 z-20 h-full w-[3px] cursor-col-resize hover:bg-[var(--interactive-border)]/80 transition-colors",l&&"bg-[var(--interactive-border)]"),onPointerDown:h,onPointerMove:j,onPointerUp:y,onPointerCancel:y,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",l&&"pointer-events-none",!t&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-right-sidebar-width)"},"aria-hidden":!t,children:t?e:null})]})},wo=t=>{const e=ot.c(128),{providerId:n,modelId:r,onChange:a,className:i,allowedProviderIds:l,placeholder:c}=t,{t:d}=ut(),{isReady:p,isUnavailable:m}=Qf(),u=yt(J1),f=yt(X1),b=Re(Z1),g=Re(ew),v=Re(tw),x=Re(sw),h=Re(nw),{favoriteModelsList:j,recentModelsList:y}=Jf(),{isMobile:C}=an(),k=b||C,[w,S]=o.useState(!1),[I,T]=o.useState(!1),[P,A]=o.useState("");let N;e[0]===Symbol.for("react.memo_cache_sentinel")?(N=()=>{S(!1),T(!1),A("")},e[0]=N):N=e[0];const E=N;let M;e[1]!==h||e[2]!==a?(M=ke=>{a(ke.providerID,ke.modelID),h(ke.providerID,ke.modelID),E()},e[1]=h,e[2]=a,e[3]=M):M=e[3];const O=M;let V;e[4]!==a?(V=()=>{a("",""),E()},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 F;e[8]!==d?(F=d("settings.agents.modelSelector.state.noModelsFound"),e[8]=d,e[9]=F):F=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 Y;e[16]!==c||e[17]!==d?(Y=c||d("settings.agents.modelSelector.notSelected"),e[16]=c,e[17]=d,e[18]=Y):Y=e[18];let Z;e[19]!==d?(Z=d("settings.agents.modelSelector.actions.favorite"),e[19]=d,e[20]=Z):Z=e[20];let ae;e[21]!==d?(ae=d("settings.agents.modelSelector.actions.unfavorite"),e[21]=d,e[22]=ae):ae=e[22];let re;e[23]!==d?(re=d("chat.modelControls.capabilities"),e[23]=d,e[24]=re):re=e[24];let me;e[25]!==d?(me=d("chat.modelControls.capability.toolCalling"),e[25]=d,e[26]=me):me=e[26];let fe;e[27]!==d?(fe=d("chat.modelControls.capability.reasoning"),e[27]=d,e[28]=fe):fe=e[28];let H;e[29]!==d?(H=d("chat.modelControls.input"),e[29]=d,e[30]=H):H=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]!==ae||e[37]!==re||e[38]!==me||e[39]!==fe||e[40]!==H||e[41]!==K||e[42]!==Q||e[43]!==$||e[44]!==F||e[45]!==_||e[46]!==q||e[47]!==L||e[48]!==Y?(W={searchPlaceholder:$,noResults:F,favorites:_,recent:q,keyboardHint:L,notSelected:Y,favorite:Z,unfavorite:ae,capabilities:re,capabilityToolCalling:me,capabilityReasoning:fe,input:H,output:K,costPerMillion:Q},e[35]=Z,e[36]=ae,e[37]=re,e[38]=me,e[39]=fe,e[40]=H,e[41]=K,e[42]=Q,e[43]=$,e[44]=F,e[45]=_,e[46]=q,e[47]=L,e[48]=Y,e[49]=W):W=e[49];const de=W;let be;e[50]!==r||e[51]!==n?(be=n&&r?{providerID:n,modelID:r}:null,e[50]=r,e[51]=n,e[52]=be):be=e[52];const we=be;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 ge=te,ue=k?w:I;let xe;e[58]!==x?(xe=ke=>x(ke.providerID,ke.modelID),e[58]=x,e[59]=xe):xe=e[59];let ne;e[60]!==v?(ne=ke=>v(ke.providerID,ke.modelID),e[60]=v,e[61]=ne):ne=e[61];let pe;e[62]!==l||e[63]!==j||e[64]!==O||e[65]!==B||e[66]!==g||e[67]!==de||e[68]!==f||e[69]!==u||e[70]!==y||e[71]!==P||e[72]!==we||e[73]!==ue||e[74]!==xe||e[75]!==ne?(pe=s.jsx(Xf,{providers:u,favoriteModels:j,recentModels:y,modelsMetadata:f,searchQuery:P,onSearchQueryChange:A,onSelect:O,labels:de,selectedModel:we,hiddenModels:g,allowedProviderIds:l,includeNotSelected:!0,onSelectNone:B,onEscape:E,tooltipsEnabled:ue,isFavorite:xe,onToggleFavorite:ne}),e[62]=l,e[63]=j,e[64]=O,e[65]=B,e[66]=g,e[67]=de,e[68]=f,e[69]=u,e[70]=y,e[71]=P,e[72]=we,e[73]=ue,e[74]=xe,e[75]=ne,e[76]=pe):pe=e[76];const J=pe;if(k){let ke;e[77]!==p?(ke=p?()=>S(!0):void 0,e[77]=p,e[78]=ke):ke=e[78];const Te=!p,Be=!p&&"opacity-60 cursor-not-allowed";let je;e[79]!==i||e[80]!==Be?(je=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",Be,i),e[79]=i,e[80]=Be,e[81]=je):je=e[81];let ee;e[82]!==p||e[83]!==m||e[84]!==n||e[85]!==d?(ee=p?n?s.jsx(xr,{providerId:n,className:"h-3.5 w-3.5 flex-shrink-0"}):s.jsx(D,{name:"pencil-ai",className:"h-3 w-3 text-muted-foreground"}):s.jsxs(s.Fragment,{children:[s.jsx(D,{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 R;e[87]!==p||e[88]!==ge?(R=p?s.jsx("span",{className:"typography-meta font-medium text-foreground truncate",children:ge}):null,e[87]=p,e[88]=ge,e[89]=R):R=e[89];let U;e[90]!==ee||e[91]!==R?(U=s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[ee,R]}),e[90]=ee,e[91]=R,e[92]=U):U=e[92];let le;e[93]===Symbol.for("react.memo_cache_sentinel")?(le=s.jsx(D,{name:"arrow-down-s",className:"h-3 w-3 flex-shrink-0 text-muted-foreground"}),e[93]=le):le=e[93];let Me;e[94]!==ke||e[95]!==Te||e[96]!==je||e[97]!==U?(Me=s.jsxs("button",{type:"button",onClick:ke,disabled:Te,className:je,children:[U,le]}),e[94]=ke,e[95]=Te,e[96]=je,e[97]=U,e[98]=Me):Me=e[98];let Oe;e[99]!==d?(Oe=d("settings.agents.modelSelector.title"),e[99]=d,e[100]=Oe):Oe=e[100];let Ae;e[101]!==w||e[102]!==J||e[103]!==Oe?(Ae=s.jsx(Br,{open:w,onClose:E,title:Oe,children:J}),e[101]=w,e[102]=J,e[103]=Oe,e[104]=Ae):Ae=e[104];let z;return e[105]!==Me||e[106]!==Ae?(z=s.jsxs(s.Fragment,{children:[Me,Ae]}),e[105]=Me,e[106]=Ae,e[107]=z):z=e[107],z}const Se=p&&I,he=p?T:void 0,Ie=!p&&"opacity-60 cursor-not-allowed";let Pe;e[108]!==i||e[109]!==Ie?(Pe=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",Ie,i),e[108]=i,e[109]=Ie,e[110]=Pe):Pe=e[110];let Ce;e[111]!==p||e[112]!==m||e[113]!==n||e[114]!==d||e[115]!==ge?(Ce=p?s.jsxs(s.Fragment,{children:[n?s.jsx(xr,{providerId:n,className:"h-3.5 w-3.5 flex-shrink-0"}):s.jsx(D,{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:ge})]}):s.jsxs(s.Fragment,{children:[s.jsx(D,{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]=ge,e[116]=Ce):Ce=e[116];let X;e[117]===Symbol.for("react.memo_cache_sentinel")?(X=s.jsx(D,{name:"arrow-down-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/50"}),e[117]=X):X=e[117];let ie;e[118]!==Pe||e[119]!==Ce?(ie=s.jsx(Is,{asChild:!0,children:s.jsxs("div",{className:Pe,children:[Ce,X]})}),e[118]=Pe,e[119]=Ce,e[120]=ie):ie=e[120];let Ne;e[121]!==J?(Ne=s.jsx(Ps,{className:"w-[min(380px,calc(100vw-2rem))] p-0 flex flex-col",align:"start",children:J}),e[121]=J,e[122]=Ne):Ne=e[122];let oe;return e[123]!==Se||e[124]!==he||e[125]!==ie||e[126]!==Ne?(oe=s.jsxs(As,{open:Se,onOpenChange:he,children:[ie,Ne]}),e[123]=Se,e[124]=he,e[125]=ie,e[126]=Ne,e[127]=oe):oe=e[127],oe};function J1(t){return t.providers}function X1(t){return t.modelsMetadata}function Z1(t){return t.isMobile}function ew(t){return t.hiddenModels}function tw(t){return t.toggleFavoriteModel}function sw(t){return t.isFavoriteModel}function nw(t){return t.addRecentModel}const Kl=t=>{const e=ot.c(34),{agentName:n,onChange:r,className:a,filter:i}=t,{t:l}=ut(),{isReady:c,isUnavailable:d}=Qf(),p=yt(rw),m=fi(aw),u=fi(iw),f=yt(ow);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 g=b;let v;if(e[2]!==i||e[3]!==g){const B=nb(g);v=i?B.filter(i):B,e[2]=i,e[3]=g,e[4]=v}else v=e[4];const x=v,h=Re(lw),{isMobile:j}=an(),y=h||j,[C,k]=o.useState(!1);let w,S;e[5]!==u||e[6]!==f||e[7]!==g.length?(w=()=>{g.length>0||(f(),u())},S=[g.length,f,u],e[5]=u,e[6]=f,e[7]=g.length,e[8]=w,e[9]=S):(w=e[8],S=e[9]),o.useEffect(w,S);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 A=P;let N;e[13]!==n||e[14]!==x||e[15]!==A||e[16]!==y||e[17]!==C||e[18]!==l?(N=()=>y?s.jsx(Br,{open:C,onClose:T,title:l("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:()=>{A(""),T()},children:[s.jsx("span",{className:ye("typography-meta",n?"text-muted-foreground":"font-medium"),children:l("settings.commands.agentSelector.notSelected")}),!n&&s.jsx("div",{className:"h-2 w-2 rounded-full bg-primary"})]}),x.map(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:()=>{A(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]=x,e[15]=A,e[16]=y,e[17]=C,e[18]=l,e[19]=N):N=e[19];const E=N;let M;e[20]!==n||e[21]!==x||e[22]!==a||e[23]!==A||e[24]!==y||e[25]!==c||e[26]!==d||e[27]!==l?(M=y?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(D,{name:"robot-2",className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"typography-meta font-medium text-foreground",children:n||l("settings.commands.agentSelector.selectAgentPlaceholder")})]}):s.jsxs(s.Fragment,{children:[s.jsx(D,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:l(d?"common.unavailable":"common.loading")})]})}),s.jsx(D,{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(D,{name:"robot-2",className:"h-3 w-3 flex-shrink-0 text-muted-foreground"}),s.jsx("span",{className:"typography-micro font-medium whitespace-nowrap",children:n||l("settings.commands.agentSelector.notSelected")}),s.jsx(D,{name:"arrow-down-s",className:"h-3 w-3 flex-shrink-0 text-muted-foreground"})]})}),s.jsxs(Ps,{className:"max-w-[300px]",children:[s.jsx(Ot,{className:"typography-meta",onSelect:()=>A(""),children:s.jsx("span",{className:"text-muted-foreground",children:l("settings.commands.agentSelector.notSelected")})}),x.map(B=>s.jsx(Ot,{className:"typography-meta",onSelect:()=>A(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(D,{name:"loader-4",className:"h-3 w-3 animate-spin text-muted-foreground flex-shrink-0"}),s.jsx("span",{className:"typography-micro font-medium whitespace-nowrap text-muted-foreground",children:l(d?"common.unavailable":"common.loading")})]}),e[20]=n,e[21]=x,e[22]=a,e[23]=A,e[24]=y,e[25]=c,e[26]=d,e[27]=l,e[28]=M):M=e[28];let O;e[29]!==E?(O=E(),e[29]=E,e[30]=O):O=e[30];let V;return e[31]!==M||e[32]!==O?(V=s.jsxs(s.Fragment,{children:[M,O]}),e[31]=M,e[32]=O,e[33]=V):V=e[33],V};function rw(t){return t.agents}function aw(t){return t.agents}function iw(t){return t.loadAgents}function ow(t){return t.loadAgents}function lw(t){return t.isMobile}const gm=t=>({providerID:t.providerID,modelID:t.modelID,variant:t.variant,agent:t.agent}),cw=t=>{const e=ot.c(38),{value:n,options:r,disabled:a,onChange:i}=t,{t:l}=ut();let c;e[0]!==l||e[1]!==n?(c=n||l("rightSidebar.contextNotesTodo.sendDialog.variant.default"),e[0]=l,e[1]=n,e[2]=c):c=e[2];const d=c,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(D,{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 g=b;if(a)return g;let v;e[11]!==g?(v=s.jsx(Is,{asChild:!0,children:g}),e[11]=g,e[12]=v):v=e[12];let x;e[13]!==i?(x=()=>i(""),e[13]=i,e[14]=x):x=e[14];const h=!n&&"text-primary";let j;e[15]!==h?(j=ye("font-medium",h),e[15]=h,e[16]=j):j=e[16];let y;e[17]!==l?(y=l("rightSidebar.contextNotesTodo.sendDialog.variant.default"),e[17]=l,e[18]=y):y=e[18];let C;e[19]!==j||e[20]!==y?(C=s.jsx("span",{className:j,children:y}),e[19]=j,e[20]=y,e[21]=C):C=e[21];let k;e[22]!==C||e[23]!==x?(k=s.jsx(Ot,{className:"typography-meta",onSelect:x,children:C}),e[22]=C,e[23]=x,e[24]=k):k=e[24];let w;if(e[25]!==i||e[26]!==r||e[27]!==n){let T;e[29]!==i||e[30]!==n?(T=P=>s.jsx(Ot,{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 S;e[32]!==k||e[33]!==w?(S=s.jsxs(Ps,{align:"start",className:"max-w-[220px]",children:[k,w]}),e[32]=k,e[33]=w,e[34]=S):S=e[34];let I;return e[35]!==S||e[36]!==v?(I=s.jsxs(As,{children:[v,S]}),e[35]=S,e[36]=v,e[37]=I):I=e[37],I};function Rh(t){const e=ot.c(99),{t:n}=ut(),{open:r,onOpenChange:a,target:i,projectDirectory:l,submitting:c,onConfirm:d}=t,p=c===void 0?!1:c,m=yt(yw),u=yt(bw),f=fi(xw),b=yt(gw),g=yt(hw),v=yt(fw),x=yt(pw),h=yt(mw);let j;e[0]!==h||e[1]!==v||e[2]!==g||e[3]!==x?(j=()=>gm({providerID:g,modelID:v,variant:x,agent:h}),e[0]=h,e[1]=v,e[2]=g,e[3]=x,e[4]=j):j=e[4];const[y,C]=o.useState(j);let k,w;e[5]!==f||e[6]!==u||e[7]!==m||e[8]!==r||e[9]!==l?(k=()=>{r&&(m({directory:l}),u({directory:l}),f())},w=[r,m,u,f,l],e[5]=f,e[6]=u,e[7]=m,e[8]=r,e[9]=l,e[10]=k,e[11]=w):(k=e[10],w=e[11]),o.useEffect(k,w);let S,I;e[12]!==h||e[13]!==v||e[14]!==g||e[15]!==x||e[16]!==r?(S=()=>{r&&C(gm({providerID:g,modelID:v,variant:x,agent:h}))},I=[r,g,v,x,h],e[12]=h,e[13]=v,e[14]=g,e[15]=x,e[16]=r,e[17]=S,e[18]=I):(S=e[17],I=e[18]),o.useEffect(S,I);let T,P;e[19]!==y.modelID||e[20]!==y.providerID||e[21]!==r||e[22]!==b?(T=()=>{if(!r||b.length===0)return;const Pe=b.find(Ne=>Ne.id===y.providerID)??b[0],Ce=Array.isArray(Pe?.models)?Pe.models:[],X=Ce.some(Ne=>Ne.id===y.modelID),ie=Ce[0]?.id??"";Pe?.id===y.providerID&&X||C(Ne=>({...Ne,providerID:Pe?.id??"",modelID:X?Ne.modelID:ie,variant:""}))},P=[r,b,y.providerID,y.modelID],e[19]=y.modelID,e[20]=y.providerID,e[21]=r,e[22]=b,e[23]=T,e[24]=P):(T=e[23],P=e[24]),o.useEffect(T,P);const A=uw;let N;if(e[25]!==y.modelID||e[26]!==y.providerID||e[27]!==b){let Pe;e[29]!==y.providerID?(Pe=X=>X.id===y.providerID,e[29]=y.providerID,e[30]=Pe):Pe=e[30],N=b.find(Pe)?.models?.find(X=>X.id===y.modelID),e[25]=y.modelID,e[26]=y.providerID,e[27]=b,e[28]=N}else N=e[28];const E=N;let M;e[31]!==E?(M=E?.variants?Object.keys(E.variants):[],e[31]=E,e[32]=M):M=e[32];const O=M,V=O.length>0;let B,$;e[33]!==y.variant||e[34]!==V?(B=()=>{V||!y.variant||C(dw)},$=[V,y.variant],e[33]=y.variant,e[34]=V,e[35]=B,e[36]=$):(B=e[35],$=e[36]),o.useEffect(B,$);let F;e[37]!==y.modelID||e[38]!==y.providerID?(F=y.providerID.trim().length>0&&y.modelID.trim().length>0,e[37]=y.modelID,e[38]=y.providerID,e[39]=F):F=e[39];const _=F;let q;e[40]!==_||e[41]!==y||e[42]!==d||e[43]!==p?(q=()=>{!_||p||d(y)},e[40]=_,e[41]=y,e[42]=d,e[43]=p,e[44]=q):q=e[44];const L=q;let Y,Z;e[45]!==L||e[46]!==r?(Y=()=>{if(!r)return;const Pe=Ce=>{(Ce.metaKey||Ce.ctrlKey)&&Ce.key==="Enter"&&(Ce.preventDefault(),L())};return window.addEventListener("keydown",Pe),()=>window.removeEventListener("keydown",Pe)},Z=[r,L],e[45]=L,e[46]=r,e[47]=Y,e[48]=Z):(Y=e[47],Z=e[48]),o.useEffect(Y,Z);let ae;e[49]!==n||e[50]!==i?(ae=n(i==="worktree"?"rightSidebar.contextNotesTodo.sendDialog.title.newWorktree":"rightSidebar.contextNotesTodo.sendDialog.title.newSession"),e[49]=n,e[50]=i,e[51]=ae):ae=e[51];const re=ae;let me;e[52]!==a||e[53]!==p?(me=Pe=>{p||a(Pe)},e[52]=a,e[53]=p,e[54]=me):me=e[54];let fe;e[55]!==re?(fe=s.jsx(gs,{children:s.jsx(fs,{children:re})}),e[55]=re,e[56]=fe):fe=e[56];let H;e[57]===Symbol.for("react.memo_cache_sentinel")?(H=(Pe,Ce)=>{C(X=>({...X,providerID:Pe,modelID:Ce,variant:""}))},e[57]=H):H=e[57];let K;e[58]!==y.modelID||e[59]!==y.providerID?(K=s.jsx(wo,{providerId:y.providerID,modelId:y.modelID,onChange:H}),e[58]=y.modelID,e[59]=y.providerID,e[60]=K):K=e[60];const Q=!V;let W;e[61]===Symbol.for("react.memo_cache_sentinel")?(W=Pe=>C(Ce=>({...Ce,variant:Pe})),e[61]=W):W=e[61];let de;e[62]!==y.variant||e[63]!==Q||e[64]!==O?(de=s.jsx(cw,{value:y.variant,options:O,disabled:Q,onChange:W}),e[62]=y.variant,e[63]=Q,e[64]=O,e[65]=de):de=e[65];let be;e[66]===Symbol.for("react.memo_cache_sentinel")?(be=Pe=>C(Ce=>({...Ce,agent:Pe})),e[66]=be):be=e[66];let we;e[67]!==y.agent?(we=s.jsx(Kl,{agentName:y.agent,filter:A,onChange:be}),e[67]=y.agent,e[68]=we):we=e[68];let te;e[69]!==K||e[70]!==de||e[71]!==we?(te=s.jsxs("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-2",children:[K,de,we]}),e[69]=K,e[70]=de,e[71]=we,e[72]=te):te=e[72];let ge;e[73]!==a?(ge=()=>a(!1),e[73]=a,e[74]=ge):ge=e[74];let ue;e[75]!==n?(ue=n("rightSidebar.contextNotesTodo.sendDialog.actions.cancel"),e[75]=n,e[76]=ue):ue=e[76];let xe;e[77]!==p||e[78]!==ge||e[79]!==ue?(xe=s.jsx(ve,{variant:"ghost",size:"sm",onClick:ge,disabled:p,children:ue}),e[77]=p,e[78]=ge,e[79]=ue,e[80]=xe):xe=e[80];const ne=!_||p;let pe;e[81]!==p||e[82]!==n?(pe=n(p?"rightSidebar.contextNotesTodo.sendDialog.actions.sending":"rightSidebar.contextNotesTodo.sendDialog.actions.send"),e[81]=p,e[82]=n,e[83]=pe):pe=e[83];let J;e[84]!==L||e[85]!==ne||e[86]!==pe?(J=s.jsx(ve,{size:"sm",onClick:L,disabled:ne,children:pe}),e[84]=L,e[85]=ne,e[86]=pe,e[87]=J):J=e[87];let Se;e[88]!==xe||e[89]!==J?(Se=s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[xe,J]}),e[88]=xe,e[89]=J,e[90]=Se):Se=e[90];let he;e[91]!==fe||e[92]!==te||e[93]!==Se?(he=s.jsxs(ms,{className:"max-w-lg",children:[fe,te,Se]}),e[91]=fe,e[92]=te,e[93]=Se,e[94]=he):he=e[94];let Ie;return e[95]!==r||e[96]!==me||e[97]!==he?(Ie=s.jsx(ps,{open:r,onOpenChange:me,children:he}),e[95]=r,e[96]=me,e[97]=he,e[98]=Ie):Ie=e[98],Ie}function dw(t){return{...t,variant:""}}function uw(t){return Zf(t.mode)}function mw(t){return t.currentAgentName||""}function pw(t){return t.currentVariant||""}function fw(t){return t.currentModelId}function hw(t){return t.currentProviderId}function gw(t){return t.providers}function xw(t){return t.loadAgents}function bw(t){return t.loadAgents}function yw(t){return t.loadProviders}const cd=5,Fh=15,Zo=t=>{const e=Math.sqrt(t/100),n=12*e,r=24*e;return Math.ceil(n+r+1)},vw=(t,e)=>{const n=Zo(e);return Math.max(n*cd,Math.min(n*Fh,n*t))},ww=async(t,e)=>{const n=await ob(t.path);return{...t,title:n?.title||t.path.split("/").pop()||e}},jw=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`todo_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,Nw=t=>{const e=ot.c(20),{id:n,children:r}=t;let a;e[0]!==n?(a={id:n},e[0]=n,e[1]=a):a=e[1];const{attributes:i,listeners:l,setNodeRef:c,setActivatorNodeRef:d,transform:p,transition:m,isDragging:u}=Ml(a);let f;e[2]!==p?(f=El.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 g=u&&"opacity-60";let v;e[7]!==g?(v=ye(g),e[7]=g,e[8]=v):v=e[8];let x;e[9]!==i||e[10]!==r||e[11]!==u||e[12]!==l||e[13]!==d?(x=r({attributes:i,listeners:l,setActivatorNodeRef:d,isDragging:u}),e[9]=i,e[10]=r,e[11]=u,e[12]=l,e[13]=d,e[14]=x):x=e[14];let h;return e[15]!==c||e[16]!==b||e[17]!==v||e[18]!==x?(h=s.jsx("li",{ref:c,style:b,className:v,children:x}),e[15]=c,e[16]=b,e[17]=v,e[18]=x,e[19]=h):h=e[19],h},Sw=({projectRef:t,projectLabel:e,canCreateWorktree:n=!1,onActionComplete:r,className:a})=>{const{t:i}=ut(),[l,c]=o.useState(!1),[d,p]=o.useState(""),[m,u]=o.useState([]),[f,b]=o.useState(""),[g,v]=o.useState(null),[x,h]=o.useState(()=>new Set),[j,y]=o.useState([]),[C,k]=o.useState(null),[w,S]=o.useState(!1),[I,T]=o.useState(0),P=o.useRef(!1),A=o.useRef(""),N=Re(R=>R.todoPanelHeight),E=Re(R=>R.setTodoPanelHeight),M=Re(R=>R.notesPanelHeight),O=Re(R=>R.setNotesPanelHeight),[V,B]=o.useState(!1),$=o.useRef(0),F=o.useRef(N),_=$t(R=>R.currentSessionId),q=$t(R=>R.createSession),L=$t(R=>R.initializeNewOpenChamberSession),Y=$t(R=>R.sendMessage),Z=$t(R=>R.setCurrentSession),ae=za(R=>R.setPendingInputText),re=Ks(R=>R.currentDirectory),me=Re(R=>R.openContextPanelTab),fe=Re(R=>R.setActiveMainTab),H=Re(R=>R.setSessionSwitcherOpen),K=Re(R=>R.padding),Q=o.useCallback(async(R,U)=>{if(!t)return!1;const le=await rb(t,{notes:R,todos:U});return le||G.error(i("rightSidebar.contextNotesTodo.toast.saveNotesFailed")),le},[t,i]);o.useEffect(()=>{if(!t){p(""),u([]),y([]),b(""),h(new Set);return}let R=!1;return c(!0),(async()=>{try{const U=await ab(t),le=await Promise.all(U.plans.map(Me=>ww(Me,i("rightSidebar.contextNotesTodo.plan.defaultTitle"))));if(R)return;p(U.notes),u(U.todos),y(le),A.current=U.notes,P.current=!0,b(""),h(new Set)}catch{R||(G.error(i("rightSidebar.contextNotesTodo.toast.loadNotesFailed")),p(""),u([]),y([]),A.current="",P.current=!0)}finally{R||c(!1)}})(),()=>{R=!0}},[I,t,i]),o.useEffect(()=>{if(!t)return;const R=U=>{const le=U.detail;le?.projectId&&le.projectId!==t.id||T(Me=>Me+1)};return window.addEventListener("openchamber:project-plan-saved",R),window.addEventListener("openchamber:project-notes-updated",R),()=>{window.removeEventListener("openchamber:project-plan-saved",R),window.removeEventListener("openchamber:project-notes-updated",R)}},[t]),o.useEffect(()=>{if(m.length<7)return;const R=vw(m.length,K),U=Zo(K)*cd;(N<U||N>R)&&E(R)},[m.length,K,N,E]),o.useEffect(()=>{if(!V)return;const R=le=>{const Me=le.clientY-$.current,Oe=Math.min(Zo(K)*Fh,Math.max(Zo(K)*cd,F.current+Me));E(Oe)},U=()=>{B(!1)};return window.addEventListener("pointermove",R),window.addEventListener("pointerup",U,{once:!0}),window.addEventListener("pointercancel",U,{once:!0}),()=>{window.removeEventListener("pointermove",R),window.removeEventListener("pointerup",U),window.removeEventListener("pointercancel",U)}},[V,K,E]);const W=o.useCallback(R=>{B(!0),$.current=R.clientY,F.current=N,R.preventDefault()},[N]),de=o.useCallback(()=>{A.current=d,Q(d,m)},[d,Q,m]);o.useEffect(()=>{if(!t||!P.current||d===A.current)return;const R=window.setTimeout(()=>{A.current=d,Q(d,m)},400);return()=>{window.clearTimeout(R)}},[d,Q,t,m]);const be=o.useCallback(()=>{const R=f.trim();if(!R)return;const U=[...m,{id:jw(),text:R.slice(0,Co),completed:!1,createdAt:Date.now()}];u(U),b(""),Q(d,U)},[f,d,Q,m]),we=o.useCallback(R=>{h(U=>{const le=new Set(U);return le.has(R)?le.delete(R):le.add(R),le})},[]),te=o.useCallback((R,U)=>{const le=m.map(Me=>Me.id===R?{...Me,completed:U}:Me);u(le),Q(d,le)},[d,Q,m]),ge=o.useCallback(R=>{const U=m.filter(le=>le.id!==R);u(U),Q(d,U)},[d,Q,m]),ue=o.useCallback(()=>{const R=m.filter(U=>!U.completed);R.length!==m.length&&(u(R),Q(d,R))},[d,Q,m]),xe=o.useCallback(R=>{const{active:U,over:le}=R;if(!le||U.id===le.id)return;const Me=m.findIndex(z=>z.id===U.id),Oe=m.findIndex(z=>z.id===le.id);if(Me===-1||Oe===-1)return;const Ae=Bf(m,Me,Oe);u(Ae),Q(d,Ae)},[d,Q,m]),ne=eo(oi(to,{activationConstraint:{distance:8}})),pe=f.slice(0,Co),J=m.reduce((R,U)=>R+(U.completed?1:0),0),Se=o.useCallback(()=>{fe("chat"),H(!1)},[fe,H]),he=o.useCallback((R,U)=>{!t||g||k({kind:"session",todoId:R,todoText:U})},[t,g]),Ie=o.useCallback(R=>{if(!_){G.error(i("rightSidebar.contextNotesTodo.toast.noActiveSession"));return}Se();const U=`\`\`\`md
|
|
4
|
-
${R}
|
|
5
|
-
\`\`\``;ae(U,"append"),G.success(i("rightSidebar.contextNotesTodo.toast.sentToCurrentSession")),r?.()},[_,r,Se,ae,i]),Pe=o.useCallback((R,U)=>{if(!(!t||g)){if(!n){G.error(i("rightSidebar.contextNotesTodo.toast.worktreeRequiresGitRepo"));return}k({kind:"worktree",todoId:R,todoText:U})}},[n,t,g,i]),Ce=o.useCallback(async R=>{if(!t||!C)return;const U=await kn("plan.todo.visible",{todo_text:C.todoText}),Me=[{synthetic:!0,text:await kn("plan.todo.instructions",{todo_text:C.todoText})}];S(!0),v(C.todoId);try{Se();let Oe=null,Ae=t.path;if(C.kind==="worktree"){if(!n){G.error(i("rightSidebar.contextNotesTodo.toast.worktreeRequiresGitRepo"));return}const De=await eh(t.path,th());if(!De?.id)return;Oe=De.id,Ae=null}else{const De=await q(void 0,t.path,null);if(!De?.id){G.error(i("rightSidebar.contextNotesTodo.toast.createSessionFailed"));return}Oe=De.id,Ae=De.directory??t.path,L(De.id,yt.getState().agents??[])}if(!Oe)return;const z=Ol.getState();z.saveSessionModelSelection(Oe,R.providerID,R.modelID),R.agent.trim()&&(z.saveSessionAgentSelection(Oe,R.agent),z.saveAgentModelForSession(Oe,R.agent,R.providerID,R.modelID),z.saveAgentModelVariantForSession(Oe,R.agent,R.providerID,R.modelID,R.variant||void 0)),Z(Oe,Ae),await Y(U,R.providerID,R.modelID,R.agent.trim()||void 0,void 0,void 0,Me,R.variant||void 0),G.success(C.kind==="worktree"?i("rightSidebar.contextNotesTodo.toast.sentToNewWorktreeSession"):i("rightSidebar.contextNotesTodo.toast.sentToNewSession")),k(null),r?.()}catch(Oe){const Ae=Oe instanceof Error?Oe.message:void 0;G.error(i("rightSidebar.contextNotesTodo.toast.sendTodoFailed"),Ae?{description:Ae}:void 0)}finally{S(!1),v(null)}},[n,q,L,r,C,t,Se,Y,Z,i]),X=o.useRef(null),[ie,Ne]=o.useState(!1),[oe,ke]=o.useState(null),Te=o.useCallback(async R=>{if(!(!t||oe)){ke(R);try{if(!await ib(t,R)){G.error(i("rightSidebar.contextNotesTodo.toast.deletePlanFailed"));return}y(le=>le.filter(Me=>Me.id!==R)),window.dispatchEvent(new CustomEvent("openchamber:project-plan-saved",{detail:{projectId:t.id}}))}finally{ke(null)}}},[oe,t,i]),Be=o.useCallback(async()=>{if(!t||ie)return;const R=await sh({defaultPath:t.path,filters:[{name:"Plan files",extensions:["md","markdown","txt"]},{name:"All files",extensions:["*"]}]});if(R.success&&R.path){Ne(!0);try{const U=new URLSearchParams({path:R.path,allowOutsideWorkspace:"true"}),le=await fetch(`/api/fs/read?${U.toString()}`,{cache:"no-store"});if(!le.ok){G.error(i("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"));return}const Me=await le.text();if(!Me.trim()){G.error(i("rightSidebar.contextNotesTodo.toast.planFileEmpty"));return}const Oe=R.path.split("/").pop()?.replace(/\.(md|markdown|txt)$/i,"").trim()||"";if(!await ku(t,Me,Oe)){G.error(i("rightSidebar.contextNotesTodo.toast.importPlanFailed"));return}window.dispatchEvent(new CustomEvent("openchamber:project-plan-saved",{detail:{projectId:t.id}})),G.success(i("rightSidebar.contextNotesTodo.toast.planImported"))}catch(U){const le=U instanceof Error?U.message:void 0;G.error(i("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"),le?{description:le}:void 0)}finally{Ne(!1)}}else R.error==="Native file picker not available"&&X.current?.click()},[ie,t,i]),je=o.useCallback(async R=>{if(!(!t||!R)){Ne(!0);try{const U=await R.text();if(!U.trim()){G.error(i("rightSidebar.contextNotesTodo.toast.planFileEmpty"));return}const le=R.name.replace(/\.(md|markdown|txt)$/i,"").trim();if(!await ku(t,U,le)){G.error(i("rightSidebar.contextNotesTodo.toast.importPlanFailed"));return}window.dispatchEvent(new CustomEvent("openchamber:project-plan-saved",{detail:{projectId:t.id}})),G.success(i("rightSidebar.contextNotesTodo.toast.planImported"))}catch(U){const le=U instanceof Error?U.message:void 0;G.error(i("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"),le?{description:le}:void 0)}finally{Ne(!1)}}},[t,i]),ee=o.useCallback(R=>{const U=t?.path?.trim(),le=re?.trim()||U;le&&me(le,{mode:"plan",targetPath:R.path,dedupeKey:R.path,label:R.title})},[re,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,"/",Cu]})]}),s.jsx(jn,{value:d,onChange:R=>p(R.target.value.slice(0,Cu)),onBlur:de,placeholder:i("rightSidebar.contextNotesTodo.notes.placeholder"),resizedHeight:M,onResizeHeightChange:O,useScrollShadow:!0,scrollShadowSize:56,disabled:l})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-label font-semibold text-foreground",children:i("rightSidebar.contextNotesTodo.todo.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:m.length===1?i("rightSidebar.contextNotesTodo.todo.itemsSingle",{count:m.length}):i("rightSidebar.contextNotesTodo.todo.itemsPlural",{count:m.length})}),s.jsx("button",{type:"button",onClick:ue,disabled:l||J===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:[pe.length,"/",Co]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Bt,{value:pe,onChange:R=>b(R.target.value.slice(0,Co)),onKeyDown:R=>{R.key==="Enter"&&(R.preventDefault(),be())},placeholder:i("rightSidebar.contextNotesTodo.todo.inputPlaceholder"),disabled:l,className:"h-8"}),s.jsx("button",{type:"button",onClick:be,disabled:l||pe.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(D,{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:`${N}px`,maxHeight:`${N}px`},children:m.length===0?s.jsx("p",{className:"px-3 py-3 typography-meta text-muted-foreground",children:i("rightSidebar.contextNotesTodo.todo.empty")}):s.jsx(so,{sensors:ne,collisionDetection:no,onDragEnd:xe,children:s.jsx(dl,{items:m.map(R=>R.id),strategy:Jc,children:s.jsx("ul",{className:"divide-y divide-border/50",children:m.map(R=>{const U=x.has(R.id);return s.jsx(Nw,{id:R.id,children:le=>s.jsxs("div",{className:"flex items-start gap-1.5 px-2.5 py-1.5",children:[s.jsx("button",{type:"button",ref:le.setActivatorNodeRef,...le.attributes,...le.listeners,onClick:Me=>{Me.preventDefault(),Me.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:R.text}),title:i("rightSidebar.contextNotesTodo.todo.actions.reorder",{text:R.text}),children:s.jsx(D,{name:"draggable",className:"h-3.5 w-3.5"})}),s.jsx("div",{className:"flex h-6 items-center",children:s.jsx(xs,{checked:R.completed,onChange:Me=>te(R.id,Me),ariaLabel:i("rightSidebar.contextNotesTodo.todo.actions.markComplete",{text:R.text})})}),s.jsx("button",{type:"button",onClick:()=>we(R.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",R.completed&&"text-muted-foreground line-through"),title:U?void 0:R.text,"aria-label":U?i("rightSidebar.contextNotesTodo.todo.actions.collapse",{text:R.text}):i("rightSidebar.contextNotesTodo.todo.actions.expand",{text:R.text}),children:R.text}),s.jsxs("div",{className:"flex h-6 items-center gap-0.5",children:[s.jsx("button",{type:"button",onClick:()=>ge(R.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:R.text}),title:i("rightSidebar.contextNotesTodo.todo.actions.delete",{text:R.text}),children:s.jsx(D,{name:"delete-bin",className:"h-3.5 w-3.5"})}),s.jsxs(As,{children:[s.jsx(Is,{asChild:!0,children:s.jsx("button",{type:"button",disabled:g===R.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:R.text}),title:i("rightSidebar.contextNotesTodo.todo.actions.send",{text:R.text}),children:s.jsx(D,{name:"send-plane",className:"h-3.5 w-3.5"})})}),s.jsxs(Ps,{align:"end",className:"w-56",children:[s.jsx(Ot,{onClick:()=>Ie(R.text),children:i("rightSidebar.contextNotesTodo.todo.sendMenu.currentSession")}),s.jsx(Ot,{onClick:()=>he(R.id,R.text),children:i("rightSidebar.contextNotesTodo.todo.sendMenu.newSession")}),s.jsx(Ot,{onClick:()=>{Pe(R.id,R.text)},disabled:!n,children:i("rightSidebar.contextNotesTodo.todo.sendMenu.newWorktreeSession")})]})]})]})]})},R.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:R=>{const U=R.target.files?.[0]??null;je(U),R.currentTarget.value=""}}),s.jsx("button",{type:"button",onClick:Be,disabled:!t||ie,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(D,{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(R=>s.jsxs("li",{className:"flex items-center gap-1.5 px-2.5 py-1.5",children:[s.jsxs("button",{type:"button",onClick:()=>ee(R),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:R.title}),s.jsx("span",{className:"flex-shrink-0 typography-micro text-muted-foreground",children:new Date(R.createdAt).toLocaleDateString()})]}),s.jsx("button",{type:"button",onClick:()=>{Te(R.id)},disabled:oe===R.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:R.title}),children:s.jsx(D,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},R.id))})})]}),s.jsx(Rh,{open:C!==null,onOpenChange:R=>{!R&&!w&&k(null)},target:C?.kind??"session",projectDirectory:t?.path??null,submitting:w,onConfirm:Ce})]}):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")})})},Oh=12,kw=[{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"}],Cw=t=>{const e=ot.c(18),{isActive:n,burstKey:r,className:a,durationMs:i,bursts:l,onComplete:c}=t,d=r===void 0?0:r,p=i===void 0?900:i,m=l===void 0?kw:l,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 g;e[4]===Symbol.for("react.memo_cache_sentinel")?(g=Array.from({length:Oh},Iw),e[4]=g):g=e[4];const v=g;if(!n)return null;let x;e[5]!==a?(x=ye("fireworks-overlay pointer-events-none",a),e[5]=a,e[6]=x):x=e[6];let h;if(e[7]!==d||e[8]!==m||e[9]!==p){let y;e[11]!==d||e[12]!==p?(y=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:v.map((w,S)=>{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}-${S}-${d}`)})},`${C.id}-${d}`)},e[11]=d,e[12]=p,e[13]=y):y=e[13],h=m.map(y),e[7]=d,e[8]=m,e[9]=p,e[10]=h}else h=e[10];let j;return e[14]!==d||e[15]!==x||e[16]!==h?(j=s.jsx("div",{className:x,"aria-hidden":"true","data-burst-key":d,children:h}),e[14]=d,e[15]=x,e[16]=h,e[17]=j):j=e[17],j};function Iw(t,e){const n=Math.PI*2*e/Oh;return{x:Math.cos(n),y:Math.sin(n),delay:e*18}}const Pw=t=>{const e=ot.c(13);let n;e[0]!==t?(n={},e[0]=t,e[1]=n):n=e[1];const{durationMs:r}=n,a=r===void 0?3400:r;let i;e[2]===Symbol.for("react.memo_cache_sentinel")?(i={isActive:!1,cycle:0},e[2]=i):i=e[2];const[l,c]=_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(Aw)},e[4]=u):u=e[4];const f=u;let b;e[5]!==a?(b=()=>{m(),c(Dw),d.current=window.setTimeout(()=>{c(Tw),d.current=null},a)},e[5]=a,e[6]=b):b=e[6];const g=b;let v,x;e[7]===Symbol.for("react.memo_cache_sentinel")?(v=()=>()=>m(),x=[m],e[7]=v,e[8]=x):(v=e[7],x=e[8]),_e.useEffect(v,x);let h;return e[9]!==l.cycle||e[10]!==l.isActive||e[11]!==g?(h={isActive:l.isActive,burstKey:l.cycle,triggerFireworks:g,dismissFireworks:f},e[9]=l.cycle,e[10]=l.isActive,e[11]=g,e[12]=h):h=e[12],h};function Aw(t){return t.isActive?{...t,isActive:!1}:t}function Dw(t){return{isActive:!0,cycle:t.cycle+1}}function Tw(t){return t.isActive?{...t,isActive:!1}:t}const Lh=o.createContext(void 0),Mw=t=>{const e=ot.c(10),{children:n}=t,{isActive:r,burstKey:a,triggerFireworks:i,dismissFireworks:l}=Pw();let c;e[0]!==l||e[1]!==i?(c={triggerFireworks:i,dismissFireworks:l},e[0]=l,e[1]=i,e[2]=c):c=e[2];const d=c;let p;e[3]!==a||e[4]!==r?(p=s.jsx(Cw,{isActive:r,burstKey:a}),e[3]=a,e[4]=r,e[5]=p):p=e[5];let m;return e[6]!==n||e[7]!==p||e[8]!==d?(m=s.jsxs(Lh.Provider,{value:d,children:[n,p]}),e[6]=n,e[7]=p,e[8]=d,e[9]=m):m=e[9],m},Ew=()=>{const t=o.useContext(Lh);if(!t)throw new Error("useFireworksCelebration must be used within FireworksProvider");return t},Qn=rr()(Si(ho((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 pb();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 mb();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 ub();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=nr()?.settings;if(a)try{const l=(await a.load())?.settings||{};r=n(l.defaultGitIdentityId)}catch{}}if(r===null)try{const a=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(a.ok){const i=await a.json().catch(()=>null);r=n(i?.defaultGitIdentityId)}}catch{}return t({defaultGitIdentityId:r}),!0}catch(r){return console.error("Failed to load default git identity setting:",r),!1}},setDefaultGitIdentityId:async n=>{try{const r=typeof n=="string"?n.trim():"",a=r.length>0?r:"";return await Ss({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 db(r),await e().loadProfiles(),!0}catch(r){return console.error("Failed to create git identity profile:",r),!1}},updateProfile:async(n,r)=>{try{const a=e().profiles.find(l=>l.id===n);if(!a)throw new Error("Profile not found");const i={...a,...r};return await cb(n,i),await e().loadProfiles(),!0}catch(a){return console.error("Failed to update git identity profile:",a),!1}},deleteProfile:async n=>{try{return await lb(n),e().selectedProfileId===n&&t({selectedProfileId:null}),await e().loadProfiles(),!0}catch(r){return console.error("Failed to delete git identity profile:",r),!1}},getProfileById:n=>{const{profiles:r,globalIdentity:a}=e();return n==="global"?a||void 0:r.find(i=>i.id===n)},getUnimportedCredentials:()=>{const{profiles:n,discoveredCredentials:r}=e();return r.filter(a=>!n.some(i=>i.authType==="token"&&i.host===a.host))}}),{name:"git-identities-store",storage:Rl(()=>Cr()),partialize:t=>({selectedProfileId:t.selectedProfileId})}),{name:"git-identities-store"}));typeof window<"u"&&(window.__zustand_git_identities_store__=Qn);function Wa(t){const e=ot.c(12);let n,r,a;e[0]!==t?({className:n,style:a,...r}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=a):(n=e[1],r=e[2],a=e[3]);let i;e[4]!==a?(i={color:"var(--surface-elevated-foreground)",...a},e[4]=a,e[5]=i):i=e[5];let l;e[6]!==n?(l=ye("flex h-full w-full flex-col overflow-hidden rounded-xl",n),e[6]=n,e[7]=l):l=e[7];let c;return e[8]!==r||e[9]!==i||e[10]!==l?(c=s.jsx(qa,{"data-slot":"command",style:i,className:l,...r}),e[8]=r,e[9]=i,e[10]=l,e[11]=c):c=e[11],c}const ga=_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(D,{name:"search",className:"size-4 shrink-0 opacity-50"}),n[3]=i):i=n[3];let l;n[4]!==r?(l=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]=l):l=n[5];let c;return n[6]!==a||n[7]!==e||n[8]!==l?(c=s.jsxs("div",{"data-slot":"command-input-wrapper",className:"flex h-8 items-center gap-2 border-b px-3",children:[i,s.jsx(qa.Input,{ref:e,"data-slot":"command-input",className:l,...a})]}),n[6]=a,n[7]=e,n[8]=l,n[9]=c):c=n[9],c});ga.displayName="CommandInput";function Ka(t){const e=ot.c(14);let n,r,a,i,l;e[0]!==t?({className:r,children:n,scrollbarClassName:l,disableHorizontal:a,...i}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=a,e[4]=i,e[5]=l):(n=e[1],r=e[2],a=e[3],i=e[4],l=e[5]);let c;e[6]!==r?(c=ye("scroll-py-1 overflow-x-hidden h-full min-h-0",r),e[6]=r,e[7]=c):c=e[7];const d=l??"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",p=a??!0;let m;return e[8]!==n||e[9]!==i||e[10]!==c||e[11]!==d||e[12]!==p?(m=s.jsx(ws,{as:qa.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 Ha(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(qa.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 Ln(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(qa.Group,{"data-slot":"command-group",className:a,...r}),e[5]=r,e[6]=a,e[7]=i):i=e[7],i}function Ra(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(qa.Separator,{"data-slot":"command-separator",className:a,...r}),e[5]=r,e[6]=a,e[7]=i):i=e[7],i}function An(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(qa.Item,{"data-slot":"command-item",className:a,...r}),e[5]=r,e[6]=a,e[7]=i):i=e[7],i}function Rw(t){const e=ot.c(12);let n,r,a,i;if(e[0]!==t){const{className:c,...d}=t,p=Ow,m=typeof d.children=="string"?d.children:"",u=m?m.split("+").map(Fw).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 l;return e[7]!==n||e[8]!==r||e[9]!==a||e[10]!==i?(l=s.jsx("span",{"data-slot":n,className:r,...a,children:i}),e[7]=n,e[8]=r,e[9]=a,e[10]=i,e[11]=l):l=e[11],l}function Fw(t){return t.trim()}function Ow(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(D,{name:"command",className:"size-3.5"}):e==="shift"||e==="⇧"?s.jsx(D,{name:"arrow-up",className:"size-3.5"}):s.jsx("span",{className:"text-xs font-medium",children:t})}const dd=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},Lw=t=>{const e=dd(t);if(!e)return null;const r=e.indexOf("/.git/worktrees/");return r>0&&e.slice(0,r)||null};function $w(t,e,n){const r=ot.c(5),[a,i]=o.useState();let l,c;return r[0]!==n||r[1]!==t||r[2]!==e?(l=()=>{if(e){i(void 0);return}if(!t){i(void 0);return}i(void 0);let d=!1;return(async()=>{const[p,m]=await Promise.all([Gs("git rev-parse --absolute-git-dir",t),Gs("git rev-parse --show-toplevel",t)]);if(d||!p.success||!m.success)return;const u=dd((p.stdout||"").trim()),f=Lw(u);if(!f)return;const b=dd((m.stdout||"").trim());if(!b||b===f)return;const g=n||"",v=b.split("/").filter(Boolean).pop()||b;i({source:"sdk",path:b,projectDirectory:f,branch:g,label:g||v,name:v,worktreeRoot:b,worktreeStatus:"ready",headState:g?"branch":"unborn",worktreeSource:"existing"})})(),()=>{d=!0}},c=[t,e,n],r[0]=n,r[1]=t,r[2]=e,r[3]=l,r[4]=c):(l=r[3],c=r[4]),o.useEffect(l,c),e??a}const Jn=t=>{const e=t.trim();return e?`'${e.replace(/'/g,"'\\''")}'`:"''"},wi=t=>(t||"").split(/\r?\n/).map(e=>e.trim()).filter(Boolean),na=t=>!!t.success,Hl=t=>(t.stdout||"").trim(),$a=t=>(t.stderr||"").trim();async function _w(t){const n=((await Gs("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 Bw(t){const e=`refs/heads/${t.targetBranch}`,n=new Set(t.excludePaths),a=(await _w(t.repoRoot)).filter(l=>l.branchRef===e).map(l=>l.path).filter(l=>l&&!n.has(l)),i=[];for(const l of a){const c=await Gs("git status --porcelain",l);Hl(c)||i.push(l)}return i}async function $h(t,e){for(const n of e)await Gs("git reset --hard",n).catch(()=>{})}async function Vw(t,e){const n=e.trim();if(!n||n==="HEAD")return"HEAD";const r=await Gs(`git show-ref --verify --quiet ${Jn(`refs/heads/${n}`)}`,t);if(na(r))return n;if(n.startsWith("remotes/")){const l=n.slice(8).split("/"),c=l[0]||"origin",d=l.slice(1).join("/");if(d)return await Gs(`git branch --track ${Jn(d)} ${Jn(`${c}/${d}`)}`,t),d}const a=await Gs(`git show-ref --verify --quiet ${Jn(`refs/remotes/origin/${n}`)}`,t);return na(a)&&await Gs(`git branch --track ${Jn(n)} ${Jn(`origin/${n}`)}`,t),n}async function Ri(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 Vw(e,r),i=await Gs(`git cherry ${Jn(a)} ${Jn(n)}`,e),l=wi(i.stdout),c=new Set;for(const u of l){const f=u.match(/^\+\s+([0-9a-f]{7,40})\b/i);f&&c.add(f[1])}const d=await Gs(`git rev-list --reverse ${Jn(`${a}..${n}`)}`,e),m=wi(d.stdout).filter(u=>c.has(u));return{repoRoot:e,sourceBranch:n,targetBranch:a,commits:m}}async function zw(t,e){const n=await Gs('mkdir -p "$HOME/.config/openchamber/tmp"',t);if(!na(n))throw new Error($a(n)||"Failed to create temp directory parent");const r=await Gs('mktemp -d "$HOME/.config/openchamber/tmp/oc-integrate-XXXXXX"',t),a=Hl(r);if(!a)throw new Error($a(r)||"Failed to create temp directory");const i=await Gs(`git worktree add --force ${Jn(a)} ${Jn(e)}`,t);if(!na(i))throw new Error($a(i)||"Failed to create temp worktree");return a}async function wl(t,e){await Gs(`git worktree remove --force ${Jn(e)}`,t).catch(()=>{}),await Gs("git worktree prune",t).catch(()=>{})}async function Uw(t){const e=await Gs("git rev-parse --abbrev-ref --symbolic-full-name @{u}",t),n=Hl(e);if(!n)return;await Gs("git fetch",t);const r=await Gs(`git merge --ff-only ${Jn(n)}`,t);if(!na(r))throw new Error($a(r)||"Fast-forward failed")}async function jl(t){const e=await Gs("git status --porcelain",t),n=await Gs("git diff --name-only --diff-filter=U",t),r=await Gs("git diff",t),a=await Gs("git show --no-patch --pretty=fuller CHERRY_PICK_HEAD",t),i=await Gs("git show CHERRY_PICK_HEAD",t);return{statusPorcelain:e.stdout||"",unmergedFiles:wi(n.stdout),diff:r.stdout||r.stderr||"",currentPatchMeta:a.stdout||a.stderr||"",currentPatch:i.stdout||i.stderr||""}}async function Ww(t){return jl(t)}async function Kw(t){const e=await Gs("git rev-parse --verify --quiet CHERRY_PICK_HEAD",t);return na(e)}async function Hw(t){if(t.commits.length===0)return{kind:"noop",reason:"No commits to move"};const e=await zw(t.repoRoot,t.targetBranch);let n=[];try{await Uw(e);const r=await Gs("git status --porcelain",e);if(Hl(r))throw new Error("Target branch has local changes; abort integration and retry");const a=await Bw({repoRoot:t.repoRoot,targetBranch:t.targetBranch,excludePaths:[e]}).catch(()=>[]);for(n=[...t.commits];n.length>0;){const i=n[0],l=await Gs(`git cherry-pick ${Jn(i)}`,e);if(na(l)){n.shift();continue}const c=await Gs("git diff --name-only --diff-filter=U",e);if(wi(c.stdout).length>0){const p=await jl(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($a(l)||"Cherry-pick failed")}return await wl(t.repoRoot,e),await $h(t.repoRoot,a).catch(()=>{}),{kind:"success",moved:t.commits.length}}catch(r){throw await wl(t.repoRoot,e).catch(()=>{}),r}}async function Gw(t){await Gs("git cherry-pick --abort",t.tempWorktreePath).catch(()=>{}),await wl(t.repoRoot,t.tempWorktreePath)}async function qw(t){const e=await Gs("git cherry-pick --continue",t.tempWorktreePath);if(!na(e)){const i=await Gs("git diff --name-only --diff-filter=U",t.tempWorktreePath);if(wi(i.stdout).length>0){const c=await jl(t.tempWorktreePath);return{kind:"conflict",state:t,details:c}}throw new Error($a(e)||"Cherry-pick continue failed")}const n=t.tempWorktreePath,r=[...t.remainingCommits];r.length>0&&r[0]===t.currentCommit&&r.shift();const a=[...r];for(;a.length>0;){const i=a[0],l=await Gs(`git cherry-pick ${Jn(i)}`,n);if(na(l)){a.shift();continue}const c=await Gs("git diff --name-only --diff-filter=U",n);if(wi(c.stdout).length>0){const p=await jl(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($a(l)||"Cherry-pick failed")}return await wl(t.repoRoot,t.tempWorktreePath),await $h(t.repoRoot,t.cleanTargetWorktrees).catch(()=>{}),{kind:"success",moved:t.remainingCommits.length}}const Yw=({repoRoot:t,sourceBranch:e,worktreeMetadata:n,localBranches:r,defaultTargetBranch:a,refreshKey:i,onRefresh:l})=>{const{t:c}=ut(),d=$t(F=>F.currentSessionId),p=Re(F=>F.setActiveMainTab),[m,u]=_e.useState(!1),f=_e.useRef(null),[b,g]=_e.useState(a);_e.useEffect(()=>{g(a)},[a]),_e.useEffect(()=>{if(m){const F=setTimeout(()=>{f.current?.focus()},0);return()=>clearTimeout(F)}},[m]);const v=!!(t&&e&&b&&b!=="HEAD"&&e!==b),[x,h]=_e.useState({kind:"idle"}),[j,y]=_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 F=window.localStorage.getItem(w);if(!F)return;let _=!1;try{const q=JSON.parse(F);if(!q?.tempWorktreePath||q.repoRoot!==t){window.localStorage.removeItem(w);return}(async()=>{const L=await Kw(q.tempWorktreePath).catch(()=>!1);if(_)return;if(!L){window.localStorage.removeItem(w);return}const Y=await Ww(q.tempWorktreePath).catch(()=>null);_||Y&&h({kind:"conflict",state:q,details:Y})})()}catch{window.localStorage.removeItem(w)}return()=>{_=!0}},[w,t]),_e.useEffect(()=>{if(!v){h({kind:"idle"});return}let F=!1;return h({kind:"loading"}),(async()=>{try{const _=await Ri({repoRoot:t,sourceBranch:e,targetBranch:b});if(F)return;if(h({kind:"ready",plan:_}),_.commits.length>0){const Y=_.commits.slice(-50).reverse().map(me=>JSON.stringify(me)).join(" "),ae=((await Gs(`git show -s --format=%H%x09%h%x09%s ${Y}`,t)).stdout||"").split(/\r?\n/).filter(Boolean),re=[];for(const me of ae){const[fe,H,K]=me.split(" ");!fe||!H||re.push({sha:fe,short:H,subject:K||""})}F||(k(re),y(!1))}else F||(k([]),y(!1))}catch{F||h({kind:"idle"})}})(),()=>{F=!0}},[v,t,e,b,i]);const S=_e.useCallback(F=>{d&&$t.getState().setWorktreeMetadata(d,{...n,createdFromBranch:F})},[d,n]),I=$t(F=>F.openNewSessionDraft),T=_e.useCallback(async F=>{const _=await kn("git.integrate.cherrypick.resolve.visible",{current_commit:F.state.currentCommit,target_branch:F.state.targetBranch}),q=await kn("git.integrate.cherrypick.resolve.instructions",{repo_root:F.state.repoRoot,temp_worktree_path:F.state.tempWorktreePath,source_branch:F.state.sourceBranch,target_branch:F.state.targetBranch,current_commit:F.state.currentCommit}),L=`Cherry-pick conflict context (JSON)
|
|
6
|
-
${JSON.stringify({repoRoot:F.state.repoRoot,tempWorktreePath:F.state.tempWorktreePath,sourceBranch:F.state.sourceBranch,targetBranch:F.state.targetBranch,currentCommit:F.state.currentCommit,remainingCommits:F.state.remainingCommits,statusPorcelain:F.details.statusPorcelain,unmergedFiles:F.details.unmergedFiles,currentPatchMeta:F.details.currentPatchMeta,currentPatch:F.details.currentPatch,diff:F.details.diff},null,2)}`;return{visibleText:_,instructionsText:q,payloadText:L}},[]),P=za(F=>F.setPendingInputText),A=za(F=>F.setPendingSyntheticParts),N=_e.useCallback(async(F,_)=>{const q=await T(F);if(_){I({directoryOverride:F.state.tempWorktreePath,initialPrompt:q.visibleText,syntheticParts:[{text:q.instructionsText,synthetic:!0},{text:q.payloadText,synthetic:!0}]}),p("chat");return}if(!d){G.error(c("gitView.integrate.noActiveSession"),{description:c("gitView.integrate.noActiveSessionDescription")});return}P(q.visibleText,"replace"),A([{text:q.instructionsText,synthetic:!0},{text:q.payloadText,synthetic:!0}]),p("chat")},[d,p,T,I,P,A,c]),E=_e.useCallback(async()=>{if(x.kind==="ready"){if(x.plan.commits.length===0){G.message(c("gitView.integrate.noCommitsToMoveToast"));return}h({kind:"running",plan:x.plan});try{const F=await Hw(x.plan);if(F.kind==="success"){G.success(c("gitView.integrate.commitsMovedToast"),{description:F.moved===1?c("gitView.integrate.commitsMovedDescriptionSingle",{count:F.moved,branch:x.plan.targetBranch}):c("gitView.integrate.commitsMovedDescriptionPlural",{count:F.moved,branch:x.plan.targetBranch})});const _=await Ri(x.plan);h({kind:"ready",plan:_}),l?.();return}F.kind==="conflict"&&(G.error(c("gitView.integrate.cherryPickConflictToast"),{description:c("gitView.integrate.cherryPickConflictDescription")}),h({kind:"conflict",state:F.state,details:F.details}),w&&typeof window<"u"&&window.localStorage.setItem(w,JSON.stringify(F.state)))}catch(F){const _=F instanceof Error?F.message:String(F);G.error(c("gitView.integrate.failedToMoveToast"),{description:_});const q=await Ri({repoRoot:t,sourceBranch:e,targetBranch:b}).catch(()=>null);h(q?{kind:"ready",plan:q}:{kind:"idle"})}}},[x,l,t,e,b,w,c]),M=_e.useCallback(async()=>{if(x.kind==="conflict")try{await Gw(x.state),G.message(c("gitView.integrate.cherryPickAbortedToast")),w&&typeof window<"u"&&window.localStorage.removeItem(w)}finally{const F=await Ri({repoRoot:t,sourceBranch:e,targetBranch:b}).catch(()=>null);h(F?{kind:"ready",plan:F}:{kind:"idle"})}},[x,t,e,b,w,c]),O=_e.useCallback(async()=>{if(x.kind==="conflict")try{const F=await qw(x.state);if(F.kind==="success"){G.success(c("gitView.integrate.cherryPickFinishedToast"));const _=await Ri({repoRoot:t,sourceBranch:e,targetBranch:b}).catch(()=>null);h(_?{kind:"ready",plan:_}:{kind:"idle"}),w&&typeof window<"u"&&window.localStorage.removeItem(w),l?.();return}F.kind==="conflict"&&(h({kind:"conflict",state:F.state,details:F.details}),w&&typeof window<"u"&&window.localStorage.setItem(w,JSON.stringify(F.state)))}catch(F){const _=F instanceof Error?F.message:String(F);G.error(c("gitView.integrate.cherryPickContinueFailedToast"),{description:_})}},[x,t,e,b,l,w,c]);return!t||!e?null:s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[s.jsxs("div",{className:"px-0 py-3 border-b border-border/40 flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(D,{name:"split-cells-horizontal",className:"size-4 text-muted-foreground"}),s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground truncate",children:c("gitView.integrate.title")}),x.kind==="ready"&&x.plan.commits.length>0?s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:c("gitView.integrate.toMoveCount",{count:x.plan.commits.length})}):null]}),s.jsx("div",{className:"flex items-center gap-2",children:x.kind==="loading"||x.kind==="running"?s.jsx(D,{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(ve,{variant:"outline",size:"sm",className:"gap-1.5",children:[c("gitView.integrate.target"),s.jsx("span",{className:"max-w-[160px] truncate font-mono text-xs text-muted-foreground",children:b}),s.jsx(D,{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(Wa,{className:"h-full min-h-0",children:[s.jsx(ga,{ref:f,placeholder:c("gitView.branch.searchPlaceholder"),onKeyDown:F=>F.stopPropagation()}),s.jsxs(Ka,{className:"h-full min-h-0",scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[s.jsx(Ha,{children:c("gitView.branch.empty")}),s.jsx(Ln,{heading:c("gitView.branch.localBranches"),children:r.map(F=>s.jsx(An,{value:F,onSelect:()=>{g(F),S(F),u(!1)},children:F},F))})]})]})})]}),x.kind==="ready"?s.jsx(ve,{size:"sm",onClick:()=>{E()},disabled:!v||x.plan.commits.length===0,children:c("gitView.integrate.move")}):x.kind==="loading"?s.jsx(ve,{size:"sm",variant:"outline",disabled:!0,children:c("gitView.integrate.checking")}):x.kind==="running"?s.jsx(ve,{size:"sm",variant:"outline",disabled:!0,children:c("gitView.integrate.moving")}):null]}),x.kind==="ready"&&x.plan.commits.length===0&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:c("gitView.integrate.noCommitsToMove")}),x.kind==="ready"&&x.plan.commits.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"typography-meta text-foreground",children:[c("gitView.integrate.commitsToMove"),s.jsxs("span",{className:"text-muted-foreground",children:[" (",x.plan.commits.length,")"]})]}),C.length>0&&x.plan.commits.length>5&&s.jsx("button",{type:"button",onClick:()=>y(F=>!F),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(F=>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:F.short}),s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:F.subject||F.sha})]},F.sha)),C.length===0&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:c("gitView.integrate.previewUnavailable")}),x.plan.commits.length>C.length&&s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:c("gitView.integrate.showingFirstCommits",{count:C.length})})]})]}),x.kind==="conflict"&&s.jsxs("div",{className:"rounded-md border border-border/60 bg-background/60 p-3 space-y-2",children:[s.jsx("div",{className:"typography-meta text-foreground",children:c("gitView.integrate.conflictsInFiles",{count:x.details.unmergedFiles.length})}),s.jsxs("div",{className:"typography-micro text-muted-foreground/80",children:[c("gitView.integrate.currentCommit"),": ",s.jsx("span",{className:"font-mono",children:x.state.currentCommit.slice(0,7)})]}),s.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[x.details.unmergedFiles.slice(0,6).map(F=>s.jsx("span",{className:"font-mono text-xs px-2 py-0.5 rounded bg-muted/40 text-muted-foreground",children:F},F)),x.details.unmergedFiles.length>6&&s.jsx("span",{className:"text-xs text-muted-foreground",children:c("gitView.integrate.moreFiles",{count:x.details.unmergedFiles.length-6})})]}),s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsx(ve,{size:"sm",variant:"ghost",className:"typography-meta",onClick:()=>{M()},children:c("gitView.operation.abort")}),s.jsxs(ve,{size:"sm",variant:"secondary",className:"typography-meta gap-1",disabled:!d,onClick:()=>{N({state:x.state,details:x.details},!1)},children:[s.jsx(D,{name:"sparkling",className:"size-3.5"}),c("gitView.integrate.currentSession")]}),s.jsxs(ve,{size:"sm",variant:"secondary",className:"typography-meta gap-1",onClick:()=>{N({state:x.state,details:x.details},!0)},children:[s.jsx(D,{name:"sparkling",className:"size-3.5"}),c("gitView.integrate.newSession")]}),s.jsx(ve,{size:"sm",className:"typography-meta",onClick:()=>{O()},children:c("gitView.operation.continue")})]})]})]})]})},Qw=t=>t.trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._/-]/g,"-").replace(/-+/g,"-").replace(/\/{2,}/g,"/").replace(/\/-+/g,"/").replace(/-+\//g,"/").replace(/^[-/]+/,"").replace(/[-/]+$/,""),Jw=({currentBranch:t,localBranches:e,remoteBranches:n,branchInfo:r,onCheckout:a,onCreate:i,remotes:l=[],disabled:c=!1})=>{const{t:d}=ut(),[p,m]=o.useState(!1),[u,f]=o.useState(""),[b,g]=o.useState(!1),[v,x]=o.useState(!1),[h,j]=o.useState(""),[y,C]=o.useState(!1),k=o.useRef(null),w=o.useCallback(B=>{B.stopPropagation()},[]),S=l.length>1,I=o.useMemo(()=>Qw(h),[h]),T=o.useMemo(()=>{const B=u.toLowerCase();return B?e.filter($=>$.toLowerCase().includes(B)):e},[u,e]),P=o.useMemo(()=>{const B=u.toLowerCase();return B?n.filter($=>$.toLowerCase().includes(B)):n},[u,n]),A=B=>{if(B===t){m(!1);return}a(B),m(!1),f("")},N=()=>{g(!0),setTimeout(()=>k.current?.focus(),50)},E=async()=>{if(!(!I||y)){if(S){x(!0);return}C(!0);try{await i(I,l[0]),j(""),g(!1),m(!1)}finally{C(!1)}}},M=async B=>{if(!(!I||y)){C(!0);try{await i(I,B),j(""),g(!1),x(!1),m(!1)}finally{C(!1)}}},O=()=>{x(!1)},V=()=>{j(""),g(!1),x(!1)};return o.useEffect(()=>{p||(f(""),g(!1),x(!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(ve,{variant:"ghost",size:"sm",className:"h-8 min-w-0 max-w-full justify-start gap-1.5 px-2 py-1",disabled:c,children:[s.jsx(D,{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(D,{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(Wa,{className:"h-full min-h-0",children:[s.jsx(ga,{placeholder:d("gitView.branch.searchPlaceholder"),value:u,onValueChange:f,onKeyDown:w}),s.jsxs(Ka,{scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[s.jsx(Ha,{children:d("gitView.branch.empty")}),s.jsx(Ln,{children:v?s.jsxs("div",{className:"px-2 py-1.5",children:[s.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[s.jsx("button",{type:"button",onClick:O,disabled:y,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:s.jsx(D,{name:"arrow-left",className:"size-4"})}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[d("gitView.branch.pushToPrefix")," ",s.jsx("span",{className:"text-foreground font-medium",children:I})," ",d("gitView.branch.pushToSuffix")]})]}),s.jsx("div",{className:"flex flex-col gap-1",children:l.map(B=>s.jsxs("button",{type:"button",onClick:()=>M(B),disabled:y,className:"flex flex-col items-start gap-0.5 px-2 py-1.5 rounded-md text-left hover:bg-accent disabled:opacity-50",children:[s.jsxs("span",{className:"typography-ui-label text-foreground",children:[y?s.jsx(D,{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(),E()):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:E,disabled:!I||y,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:y?s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(D,{name:"add",className:"size-4"})}),s.jsx("button",{type:"button",onClick:V,disabled:y,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:s.jsx(D,{name:"close",className:"size-4"})})]}):s.jsxs(An,{onSelect:N,children:[s.jsx(D,{name:"add",className:"size-4"}),s.jsx("span",{children:d("gitView.branch.create")})]})}),s.jsx(Ra,{}),s.jsxs(Ln,{heading:d("gitView.branch.localBranches"),children:[T.map(B=>s.jsxs(An,{onSelect:()=>A(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(An,{disabled:!0,className:"justify-center",children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:d("gitView.branch.noLocalBranches")})})]}),s.jsx(Ra,{}),s.jsxs(Ln,{heading:d("gitView.branch.remoteBranches"),children:[P.map(B=>s.jsx(An,{onSelect:()=>A(B),children:s.jsx("span",{className:"typography-ui-label text-foreground",children:B})},`remote-${B}`)),P.length===0&&s.jsx(An,{disabled:!0,className:"justify-center",children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:d("gitView.branch.noRemoteBranches")})})]})]})]})})]})},Xw=t=>t.trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._/-]/g,"-").replace(/-+/g,"-").replace(/\/{2,}/g,"/").replace(/\/-+/g,"/").replace(/-+\//g,"/").replace(/^[-/]+/,"").replace(/[-/]+$/,""),Zw=({currentBranch:t,onRename:e,showEditButton:n=!0})=>{const{t:r}=ut(),[a,i]=o.useState(!1),[l,c]=o.useState(t||""),[d,p]=o.useState(!1),m=o.useRef(null),u=()=>{!t||!e||(c(t),i(!0),setTimeout(()=>m.current?.focus(),0))},f=async()=>{if(!t||!e||!l.trim())return;const v=Xw(l);if(v===t){i(!1);return}p(!0);try{await e(t,v),i(!1),c("")}finally{p(!1)}},b=()=>{i(!1),c("")},g=v=>{v.key==="Enter"?(v.preventDefault(),f()):v.key==="Escape"&&(v.preventDefault(),b())};return a?s.jsx("div",{className:"flex items-center gap-2 rounded-md bg-primary/12 px-2 py-1 h-8",children:s.jsxs("form",{className:"flex w-full items-center gap-2",onSubmit:v=>{v.preventDefault(),f()},children:[s.jsx(D,{name:"git-branch",className:"size-4 text-primary"}),s.jsx("input",{ref:m,value:l,onChange:v=>c(v.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",placeholder:r("gitView.branch.namePlaceholder"),onKeyDown:g,autoFocus:!0}),s.jsx("button",{type:"submit",disabled:d,"aria-label":r(d?"gitView.branch.renameSaving":"gitView.branch.renameSave"),title:r(d?"gitView.branch.renameSaving":"gitView.branch.renameSave"),className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:d?s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(D,{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(D,{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(D,{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(ve,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 shrink-0",onClick:u,title:r("gitView.branch.renameTitle"),children:s.jsx(D,{name:"edit",className:"size-4"})})]})]})},ej=t=>{const e=ot.c(41),{syncAction:n,remotes:r,onFetch:a,onSync:i,onRemoveRemote:l,disabled:c,removingRemoteName:d,aheadCount:p,behindCount:m,trackingRemoteName:u,hasUncommittedChanges:f}=t,b=r===void 0?[]:r,g=d===void 0?null:d,v=p===void 0?0:p,x=m===void 0?0:m,h=f===void 0?!1:f,{t:j}=ut(),y=o.useRef(!1),C=!!g,k=b.find(ue=>ue.name===u)??b[0],w=x>0&&h,S=c||n!==null||C||!k||w,I=c||n!==null||C||b.length===0,T=v>0||x>0;let P;e[0]!==j?(P=j("gitView.sync.sync"),e[0]=j,e[1]=P):P=e[1];const A=x>0?`↓${x}`:null,N=v>0?`↑${v}`:null;let E;e[2]!==P||e[3]!==A||e[4]!==N?(E=[P,A,N].filter(Boolean),e[2]=P,e[3]=A,e[4]=N,e[5]=E):E=e[5];const M=E.join(" "),O=w?j("gitView.sync.commitOrStashTooltip"):k?T?j("gitView.sync.syncChangesTooltip",{ahead:v,behind:x}):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 F;e[7]!==j?(F=j("gitView.sync.syncChanges"),e[7]=j,e[8]=F):F=e[8];let _;e[9]!==n?(_=n==="sync"?s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(D,{name:"refresh",className:"size-4"}),e[9]=n,e[10]=_):_=e[10];let q;e[11]!==M?(q=s.jsx("span",{className:"whitespace-nowrap tabular-nums",children:M}),e[11]=M,e[12]=q):q=e[12];let L;e[13]!==V||e[14]!==S||e[15]!==F||e[16]!==_||e[17]!==q?(L=s.jsx(Ct,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:V,disabled:S,className:$,"aria-label":F,children:[_,q]})}),e[13]=V,e[14]=S,e[15]=F,e[16]=_,e[17]=q,e[18]=L):L=e[18];let Y;e[19]!==O?(Y=s.jsx(It,{sideOffset:8,children:O}),e[19]=O,e[20]=Y):Y=e[20];let Z;e[21]!==L||e[22]!==Y?(Z=s.jsxs(kt,{children:[L,Y]}),e[21]=L,e[22]=Y,e[23]=Z):Z=e[23];const ae=As;let re;e[24]===Symbol.for("react.memo_cache_sentinel")?(re=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]=re):re=e[24];let me;e[25]!==j?(me=j("gitView.sync.moreActionsAria"),e[25]=j,e[26]=me):me=e[26];let fe;e[27]===Symbol.for("react.memo_cache_sentinel")?(fe=s.jsx(D,{name:"arrow-down-s",className:"size-4"}),e[27]=fe):fe=e[27];let H;e[28]!==I||e[29]!==me?(H=s.jsx(Is,{asChild:!0,children:s.jsx("button",{type:"button",className:re,disabled:I,"aria-label":me,children:fe})}),e[28]=I,e[29]=me,e[30]=H):H=e[30];const K=Ps,Q="start",W=-40,de="w-[min(360px,calc(100vw-2rem))] max-h-[320px] overflow-y-auto",be=b.map(ue=>s.jsx(Ot,{onSelect:xe=>{if(y.current){xe.preventDefault(),y.current=!1;return}a(ue)},children:s.jsxs("div",{className:"flex w-full items-center gap-2",children:[s.jsx(D,{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:ue.name})}),s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:ue.fetchUrl})]})}),l&&ue.name!==u?s.jsx(ve,{type:"button",variant:"destructive",size:"xs",className:"h-6 w-6 px-0",disabled:n!==null||C,onPointerDown:xe=>{y.current=!0,xe.preventDefault(),xe.stopPropagation()},onClick:xe=>{y.current=!0,xe.preventDefault(),xe.stopPropagation(),l(ue)},"aria-label":j("gitView.header.removeRemoteAria",{name:ue.name}),title:j("gitView.header.removeRemoteTitle",{name:ue.name}),children:g===ue.name?s.jsx(D,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(D,{name:"close",className:"size-3.5"})}):null]})},ue.name));let we;e[31]!==K||e[32]!==be?(we=s.jsx(K,{align:Q,alignOffset:W,className:de,children:be}),e[31]=K,e[32]=be,e[33]=we):we=e[33];let te;e[34]!==ae||e[35]!==H||e[36]!==we?(te=s.jsxs(ae,{children:[H,we]}),e[34]=ae,e[35]=H,e[36]=we,e[37]=te):te=e[37];let ge;return e[38]!==Z||e[39]!==te?(ge=s.jsxs("div",{className:B,children:[Z,te]}),e[38]=Z,e[39]=te,e[40]=ge):ge=e[40],ge},tj={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart",user:"user-3"},sj={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)",success:"var(--status-success)",info:"var(--status-info)",warning:"var(--status-warning)"};function _h(t){return t&&sj[t]||"var(--primary)"}const xm=t=>{const e=ot.c(8),{icon:n,className:r,colorToken:a}=t,i=tj[n??"branch"]??"user-3";let l;e[0]!==a?(l=_h(a),e[0]=a,e[1]=l):l=e[1];let c;e[2]!==l?(c={color:l},e[2]=l,e[3]=c):c=e[3];let d;return e[4]!==r||e[5]!==i||e[6]!==c?(d=s.jsx(D,{name:i,className:r,style:c}),e[4]=r,e[5]=i,e[6]=c,e[7]=d):d=e[7],d},Bh=t=>{const e=ot.c(35),{activeProfile:n,identities:r,onSelect:a,isApplying:i,iconOnly:l}=t,c=l===void 0?!1:l,{t:d}=ut(),p=i||r.length===0,m=n?.color;let u;e[0]!==m?(u=_h(m),e[0]=m,e[1]=u):u=e[1];let f;e[2]!==u?(f={color:u},e[2]=u,e[3]=f):f=e[3];let b;e[4]!==n?.color||e[5]!==n?.icon||e[6]!==i?(b=i?s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(xm,{icon:n?.icon,colorToken:n?.color,className:"size-4"}),e[4]=n?.color,e[5]=n?.icon,e[6]=i,e[7]=b):b=e[7];let g;e[8]!==n?.name||e[9]!==c||e[10]!==d?(g=!c&&s.jsx("span",{className:"git-identity-label min-w-0 flex-1 truncate text-left",children:n?.name||d("gitView.header.noIdentity")}),e[8]=n?.name,e[9]=c,e[10]=d,e[11]=g):g=e[11];let v;e[12]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx(D,{name:"arrow-down-s",className:"size-4 opacity-60"}),e[12]=v):v=e[12];let x;e[13]!==p||e[14]!==f||e[15]!==b||e[16]!==g?(x=s.jsx(Ct,{asChild:!0,children:s.jsx(Is,{asChild:!0,children:s.jsxs(ve,{variant:"ghost",size:"sm",className:"h-8 min-w-0 max-w-[15rem] justify-start gap-1.5 px-2 py-1 typography-ui-label",style:f,disabled:p,children:[b,g,v]})})}),e[13]=p,e[14]=f,e[15]=b,e[16]=g,e[17]=x):x=e[17];let h;e[18]!==d?(h=d("gitView.header.identityTooltip"),e[18]=d,e[19]=h):h=e[19];let j;e[20]!==h?(j=s.jsx(It,{sideOffset:8,children:h}),e[20]=h,e[21]=j):j=e[21];let y;e[22]!==j||e[23]!==x?(y=s.jsxs(kt,{children:[x,j]}),e[22]=j,e[23]=x,e[24]=y):y=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(S=>{const I=n?.id===S.id;return s.jsx(Ot,{onSelect:()=>a(S),children:s.jsxs("span",{className:"flex items-center gap-2",children:[s.jsx(xm,{icon:S.icon,colorToken:S.color,className:"size-4"}),s.jsxs("span",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:S.name}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:S.userEmail})]}),I?s.jsx(D,{name:"check",className:"ml-auto size-4 text-foreground"}):null]})},S.id)}),e[25]=n?.id,e[26]=r,e[27]=a,e[28]=d,e[29]=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]!==y||e[33]!==k?(w=s.jsxs(As,{children:[y,k]}),e[32]=y,e[33]=k,e[34]=w):w=e[34],w},nj=t=>{const e=ot.c(49),{status:n,localBranches:r,remoteBranches:a,branchInfo:i,syncAction:l,remotes:c,onFetch:d,onSync:p,onRemoveRemote:m,removingRemoteName:u,onCheckoutBranch:f,onCreateBranch:b,onRenameBranch:g,activeIdentityProfile:v,availableIdentities:x,onSelectIdentity:h,isApplyingIdentity:j,isWorktreeMode:y,onOpenHistory:C,onOpenStashes:k,actionTabItems:w,activeActionTab:S,onSelectActionTab:I}=t,{t:T}=ut();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(ve,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0","aria-label":T("gitView.history.title"),children:s.jsx(D,{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(Ot,{onSelect:C,children:[s.jsx(D,{name:"history",className:"size-4"}),T("gitView.history.title")]}):null,k?s.jsxs(Ot,{onSelect:k,children:[s.jsx(D,{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 A;e[4]!==P?(A=s.jsx("div",{className:"flex items-center gap-1 shrink-0",children:P}),e[4]=P,e[5]=A):A=e[5];const N=A,E=!n;let M;e[6]!==n.tracking?(M=n.tracking?.split("/")[0],e[6]=n.tracking,e[7]=M):M=e[7];const O=(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]!==l||e[16]!==E||e[17]!==M||e[18]!==O?(V=s.jsx(ej,{syncAction:l,remotes:c,onFetch:d,onSync:p,onRemoveRemote:m,removingRemoteName:u,disabled:E,iconOnly:!0,aheadCount:n.ahead,behindCount:n.behind,trackingRemoteName:M,hasUncommittedChanges:O}),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]=l,e[16]=E,e[17]=M,e[18]=O,e[19]=V):V=e[19];const B=V;let $;e[20]!==v||e[21]!==x||e[22]!==j||e[23]!==h?($=s.jsx(Bh,{activeProfile:v,identities:x,onSelect:h,isApplying:j,iconOnly:!0}),e[20]=v,e[21]=x,e[22]=j,e[23]=h,e[24]=$):$=e[24];const F=$;let _;e[25]!==i||e[26]!==y||e[27]!==r||e[28]!==f||e[29]!==b||e[30]!==g||e[31]!==a||e[32]!==c||e[33]!==n.current?(_=s.jsx("div",{className:"min-w-0 flex-1",children:y?s.jsx(Zw,{currentBranch:n.current,onRename:g}):s.jsx(Jw,{currentBranch:n.current,localBranches:r,remoteBranches:a,branchInfo:i,onCheckout:f,onCreate:b,remotes:c})}),e[25]=i,e[26]=y,e[27]=r,e[28]=f,e[29]=b,e[30]=g,e[31]=a,e[32]=c,e[33]=n.current,e[34]=_):_=e[34];let q;e[35]!==F||e[36]!==N?(q=s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[N,F]}),e[35]=F,e[36]=N,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 Y;e[41]!==w||e[42]!==S||e[43]!==I||e[44]!==B?(Y=w&&S&&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(Vr,{items:w,activeId:S,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]=S,e[43]=I,e[44]=B,e[45]=Y):Y=e[45];let Z;return e[46]!==L||e[47]!==Y?(Z=s.jsxs("header",{className:"@container/git-header px-3 py-2 bg-transparent",children:[L,Y]}),e[46]=L,e[47]=Y,e[48]=Z):Z=e[48],Z},rj=({open:t,onOpenChange:e,directory:n,hasUncommittedChanges:r,hasStagedChanges:a=!1,uncommittedFileCount:i,onChanged:l})=>{const{t:c}=ut(),[d,p]=o.useState([]),[m,u]=o.useState(!1),[f,b]=o.useState(""),[g,v]=o.useState(""),[x,h]=o.useState(null),[j,y]=o.useState({}),C=o.useCallback(async()=>{if(n){u(!0);try{const P=await fb(n);p(P.stashes),y({})}catch(P){G.error(P instanceof Error?P.message:c("gitView.stashes.toast.loadFailed"))}finally{u(!1)}}},[n,c]);o.useEffect(()=>{t&&C()},[C,t]),o.useEffect(()=>{if(!t||!n||d.length===0)return;let P=!1;const A=d.map(N=>N.ref);return hb(n,A).then(N=>{P||y(N.counts)}).catch(()=>{}),()=>{P=!0}},[n,t,d]);const k=o.useMemo(()=>{const P=f.trim().toLowerCase();return P?d.filter(A=>`${A.ref} ${A.message} ${A.relativeTime}`.toLowerCase().includes(P)):d},[f,d]),w=o.useCallback(async P=>{await C(),await l?.(P)},[C,l]),S=async()=>{if(!(!n||x)){h("create");try{const P=await gb(n,{message:g.trim()||void 0});P.created?(G.success(c("gitView.stashes.toast.created")),v("")):G.info(c("gitView.stashes.toast.noChanges")),await w({affectsIndex:!!(P.created&&a)})}catch(P){G.error(P instanceof Error?P.message:c("gitView.stashes.toast.createFailed"))}finally{h(null)}}},I=async(P,A)=>{if(!(!n||x)&&!(A==="drop"&&!window.confirm(c("gitView.stashes.confirm.drop",{ref:P.ref})))){h(`${A}:${P.ref}`);try{A==="apply"&&await xb(n,{ref:P.ref}),A==="pop"&&await bb(n,{ref:P.ref}),A==="drop"&&await yb(n,{ref:P.ref});const N=A==="apply"?"gitView.stashes.toast.applySuccess":A==="pop"?"gitView.stashes.toast.popSuccess":"gitView.stashes.toast.dropSuccess";G.success(c(N)),await w({affectsIndex:A!=="drop"})}catch(N){const E=A==="apply"?"gitView.stashes.toast.applyFailed":A==="pop"?"gitView.stashes.toast.popFailed":"gitView.stashes.toast.dropFailed";G.error(N instanceof Error?N.message:c(E)),await w({affectsIndex:A!=="drop"})}finally{h(null)}}},T=x!==null;return s.jsx(ps,{open:t,onOpenChange:e,children:s.jsxs(ms,{className:"max-w-2xl max-h-[70vh] flex flex-col",children:[s.jsxs(gs,{children:[s.jsxs(fs,{className:"flex items-center gap-2",children:[s.jsx(D,{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(Bt,{value:g,onChange:P=>v(P.target.value),placeholder:c("gitView.stashes.messagePlaceholder"),disabled:T||!r,className:"flex-1"}),s.jsxs(ve,{onClick:S,disabled:!r||T||!n,children:[x==="create"?s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(D,{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(D,{name:"search",className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),s.jsx(Bt,{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(D,{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,A)=>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:A===0&&!f.trim()?c("gitView.stashes.latestLabel"):c("gitView.stashes.itemNumber",{number:A+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(xc,{label:c("gitView.stashes.actions.apply"),loading:x===`apply:${P.ref}`,onClick:()=>I(P,"apply"),disabled:T,children:s.jsx(D,{name:"inbox-unarchive",className:"size-4"})}),s.jsx(xc,{label:c("gitView.stashes.actions.pop"),loading:x===`pop:${P.ref}`,onClick:()=>I(P,"pop"),disabled:T,children:s.jsx(D,{name:"inbox-unarchive-fill",className:"size-4"})}),s.jsx(xc,{label:c("gitView.stashes.actions.drop"),loading:x===`drop:${P.ref}`,onClick:()=>I(P,"drop"),disabled:T,destructive:!0,children:s.jsx(D,{name:"delete-bin",className:"size-4"})})]})]},P.ref))})]})})},xc=t=>{const e=ot.c(17),{label:n,loading:r,disabled:a,destructive:i,onClick:l,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(D,{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]!==l||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:l,disabled:a,children:u})}),e[5]=a,e[6]=n,e[7]=l,e[8]=d,e[9]=m,e[10]=u,e[11]=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 g;return e[14]!==f||e[15]!==b?(g=s.jsxs(kt,{children:[f,b]}),e[14]=f,e[15]=b,e[16]=g):g=e[16],g},Vh={"?":{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"}},aj=Vh.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 oj(t){const e=ij(t);return Vh[e]??aj}const lj=o.memo(function(e){const n=ot.c(58),{file:r,actionLabel:a,actionSymbol:i,onAction:l,onViewDiff:c,onRevert:d,isReverting:p,stats:m,rowPaddingClassName:u,indentPx:f,actionAtStart:b,showRevert:g}=e,v=f===void 0?0:f,x=b===void 0?!1:b,h=g===void 0?!0:g;let j;n[0]!==r?(j=oj(r),n[0]=r,n[1]=j):j=n[1];const y=j,{t:C}=ut(),k=y.description,w=m?.insertions??0,S=m?.deletions??0;let I;n[2]!==l||n[3]!==c?(I=W=>{W.key===" "?(W.preventDefault(),l()):W.key==="Enter"&&(W.preventDefault(),c())},n[2]=l,n[3]=c,n[4]=I):I=n[4];const T=I;let P;n[5]!==l?(P=W=>{W.preventDefault(),W.stopPropagation(),l()},n[5]=l,n[6]=P):P=n[6];const A=P;let N;n[7]!==d?(N=W=>{W.preventDefault(),W.stopPropagation(),d()},n[7]=d,n[8]=N):N=n[8];const E=N;let M;n[9]!==a||n[10]!==i||n[11]!==A?(M=s.jsx("button",{type:"button",onClick:A,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]=A,n[12]=M):M=n[12];const O=M,V=`group flex items-center gap-2 py-1.5 hover:bg-sidebar/40 cursor-pointer ${u??"px-3"}`;let B;n[13]!==v?(B=v>0?{paddingLeft:`${v}px`}:void 0,n[13]=v,n[14]=B):B=n[14];const $=x?O:null;let F;n[15]!==y.color?(F={color:y.color},n[15]=y.color,n[16]=F):F=n[16];let _;n[17]!==y.code||n[18]!==k||n[19]!==F?(_=s.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:F,title:k,"aria-label":k,children:y.code}),n[17]=y.code,n[18]=k,n[19]=F,n[20]=_):_=n[20];let q;n[21]!==r.path?(q=s.jsx(Pr,{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),be=r.path.slice(W);let we;n[26]===Symbol.for("react.memo_cache_sentinel")?(we={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},n[26]=we):we=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 ge=s.jsx("span",{className:"text-foreground",children:be.slice(1)});let ue;n[28]!==ge?(ue=s.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[te,ge]}),n[28]=ge,n[29]=ue):ue=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:we,children:de}),ue]})}n[23]=r.path,n[24]=L}else L=n[24];let Y;n[30]===Symbol.for("react.memo_cache_sentinel")?(Y={color:"var(--status-success)"},n[30]=Y):Y=n[30];let Z;n[31]!==w?(Z=s.jsxs("span",{style:Y,children:["+",w]}),n[31]=w,n[32]=Z):Z=n[32];let ae,re;n[33]===Symbol.for("react.memo_cache_sentinel")?(ae=s.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),re={color:"var(--status-error)"},n[33]=ae,n[34]=re):(ae=n[33],re=n[34]);let me;n[35]!==S?(me=s.jsxs("span",{style:re,children:["-",S]}),n[35]=S,n[36]=me):me=n[36];let fe;n[37]!==Z||n[38]!==me?(fe=s.jsxs("span",{className:"shrink-0 typography-micro",children:[Z,ae,me]}),n[37]=Z,n[38]=me,n[39]=fe):fe=n[39];let H;n[40]!==r.path||n[41]!==E||n[42]!==p||n[43]!==h||n[44]!==C?(H=h?s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:E,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(D,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(D,{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]=E,n[42]=p,n[43]=h,n[44]=C,n[45]=H):H=n[45];const K=x?null:O;let Q;return n[46]!==T||n[47]!==c||n[48]!==B||n[49]!==$||n[50]!==_||n[51]!==q||n[52]!==L||n[53]!==fe||n[54]!==H||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,fe,H,K]}),n[46]=T,n[47]=c,n[48]=B,n[49]=$,n[50]=_,n[51]=q,n[52]=L,n[53]=fe,n[54]=H,n[55]=K,n[56]=V,n[57]=Q):Q=n[57],Q}),bm=14,zh=t=>t.replace(/\\/g,"/").replace(/^\/+/,"").trim(),ym=(t,e)=>({id:`dir:${t}`,path:t,name:e,children:new Map,directFiles:[],files:[]}),cj=t=>{const e=ym("","");for(const n of t){const r=zh(n.path);if(!r)continue;const i=r.split("/").filter(Boolean).slice(0,-1);let l=e;if(l.files.push(n),i.length>0){let c="";for(const d of i){c=c?`${c}/${d}`:d;const p=l.children.get(d);if(p){p.files.push(n),l=p;continue}const m=ym(c,d);m.files.push(n),l.children.set(d,m),l=m}}l.directFiles.push(n)}return e},dj=(t,e)=>{const n=[],r=(a,i)=>{const l=Array.from(a.children.values()).sort((d,p)=>d.path.localeCompare(p.path));for(const d of l)n.push({key:d.id,kind:"directory",depth:i,directory:d}),e.has(d.path)&&r(d,i+1);const c=[...a.directFiles].sort((d,p)=>d.path.localeCompare(p.path));for(const d of c)n.push({key:`file:${zh(d.path)}`,kind:"file",depth:i,file:d})};return r(t,0),n},uj=1e3,mj=34,pj=30,Mo="pl-0 pr-2",bc=(t,e)=>`${t} ${e}`,fj=({groups:t,diffStats:e,revertingPaths:n,isRevertingAll:r=!1,onVisiblePathsChange:a,onRevertAll:i})=>{const{t:l}=ut(),c=o.useRef(null),p=Re($=>$.gitChangesViewMode)==="tree",m=o.useMemo(()=>t.filter($=>$.entries.length>0),[t]),[u,f]=o.useState(new Set),[b,g]=o.useState(new Set),[v,x]=o.useState(!1),h=o.useMemo(()=>m.map($=>cj($.entries)),[m]),j=o.useMemo(()=>{const $=[];return m.forEach((F,_)=>{Array.from(h[_]?.children.values()??[]).forEach(q=>{$.push(bc(F.id,q.path))})}),$},[h,m]);o.useEffect(()=>{p&&g($=>{const F=new Set,_=new Set(j);return $.forEach(q=>{(q.slice(q.indexOf(" ")+1).includes("/")||_.has(q))&&F.add(q)}),j.forEach(q=>F.add(q)),F})},[p,j]);const y=o.useMemo(()=>{const $=[];return m.forEach((F,_)=>{if($.push({type:"header",key:`header:${F.id}`,groupIndex:_}),!u.has(F.id)){if(p){const q=new Set;b.forEach(Y=>{Y.startsWith(`${F.id} `)&&q.add(Y.slice(F.id.length+1))}),dj(h[_],q).forEach(Y=>{Y.kind==="file"?$.push({type:"file",key:`${F.id}:${Y.key}`,groupIndex:_,file:Y.file,depth:Y.depth}):$.push({type:"directory",key:`${F.id}:${Y.key}`,groupIndex:_,directory:Y.directory,depth:Y.depth})});return}F.entries.forEach(q=>{$.push({type:"file",key:`${F.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=y.length,k=C>=uj,w=Vf({count:C,getScrollElement:()=>c.current,estimateSize:()=>mj,overscan:12,enabled:k});o.useEffect(()=>{if(!k)return;const $=c.current;if(!$)return;const F=new ResizeObserver(()=>w.measure());return F.observe($),()=>F.disconnect()},[k,w]);const S=w.getTotalSize(),I=o.useMemo(()=>k&&S>=0?w.getVirtualItems():[],[k,w,S]);o.useEffect(()=>{if(!a)return;const $=F=>F&&F.type==="file"?F.file.path:null;if(C===0){a([]);return}if(!k){const F=[];for(const _ of y)if(_.type==="file"&&(F.push(_.file.path),F.length>=pj))break;a(F);return}a(I.map(F=>$(y[F.index])).filter(F=>!!F))},[a,C,y,k,I]);const T=o.useCallback($=>{f(F=>{const _=new Set(F);return _.has($)?_.delete($):_.add($),_})},[]),P=o.useCallback(($,F)=>{g(_=>{const q=new Set(_),L=bc($,F);return q.has(L)?q.delete(L):q.add(L),q})},[]),A=o.useMemo(()=>{const $=new Set;return m.forEach(F=>F.entries.forEach(_=>$.add(_.path))),Array.from($)},[m]),N=A.length,E=o.useCallback(async()=>{!i||r||A.length===0||(await i(A),x(!1))},[A,r,i]),M=o.useCallback(($,F)=>{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",Mo,!F&&"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(D,{name:"arrow-down-s",className:ye("size-3.5 shrink-0 text-muted-foreground transition-transform",_&&"-rotate-90")})]})]})},[u,T]),O=o.useCallback(($,F,_)=>{const q=b.has(bc($.id,F.path));return s.jsxs("div",{className:ye("group flex items-center gap-2 py-1.5 hover:bg-sidebar/40",Mo),style:{paddingLeft:`${_*bm}px`},children:[s.jsxs("button",{type:"button",onClick:()=>P($.id,F.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?l("gitView.changes.collapseDirectoryAria",{path:F.path}):l("gitView.changes.expandDirectoryAria",{path:F.path}),children:[q?s.jsx(D,{name:"folder-open-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):s.jsx(D,{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:F.path,children:F.name}),s.jsx("span",{className:"ml-auto shrink-0 typography-micro text-muted-foreground",children:F.files.length})]}),s.jsx("button",{type:"button",onClick:()=>$.onActionAll(F.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":l($.actionSymbol==="+"?"gitView.changes.stageDirectoryAria":"gitView.changes.unstageDirectoryAria",{path:F.path}),title:l($.actionSymbol==="+"?"gitView.changes.stageDirectoryAria":"gitView.changes.unstageDirectoryAria",{path:F.path}),children:$.actionSymbol})]})},[b,l,P]),V=o.useCallback(($,F)=>{if($.type==="revert-all")return s.jsx("div",{className:ye("flex justify-end py-2",Mo),children:s.jsxs(ve,{variant:"ghost",size:"sm",onClick:()=>x(!0),disabled:r,className:"gap-1.5 text-[var(--status-error)] hover:bg-[var(--status-error)]/10 hover:text-[var(--status-error)]",children:[s.jsx(D,{name:"arrow-go-back",className:"size-3.5"}),l("gitView.changes.revertAll")]})});const _=m[$.groupIndex];if(!_)return null;if($.type==="header")return M(_,F);if($.type==="directory")return O(_,$.directory,$.depth);const q=$.file;return s.jsx(lj,{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:Mo,indentPx:$.depth*bm,actionAtStart:!p,showRevert:_.showRevertActions!==!1})},[e,r,p,O,M,n,l,m]),B=o.useCallback($=>{const F=y[$],_=y[$-1];return!F||!_||F.type!=="file"&&F.type!=="directory"||_.type!=="file"&&_.type!=="directory"?!1:_.groupIndex===F.groupIndex},[y]);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(go,{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 F=y[$.index];return F?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(F,$.index===0)},F.key):null})}):s.jsx("div",{role:"list","aria-label":l("gitView.changes.changedFilesAria"),children:y.map(($,F)=>s.jsx("div",{className:ye("relative",B(F)&&"before:pointer-events-none before:absolute before:left-0 before:right-2 before:top-0 before:border-t before:border-border/60"),children:V($,F===0)},$.key))})}),s.jsx(vb,{containerRef:c,disableHorizontal:!0})]}),s.jsx(ps,{open:v,onOpenChange:$=>{!r&&!$&&x(!1)},children:s.jsxs(ms,{className:"max-w-md",children:[s.jsxs(gs,{children:[s.jsx(fs,{children:l("gitView.changes.revertAllDialogTitle")}),s.jsx(Ns,{children:N===1?l("gitView.changes.revertAllDescriptionSingle",{count:N}):l("gitView.changes.revertAllDescriptionPlural",{count:N})})]}),s.jsxs(Hs,{children:[s.jsx(ve,{variant:"outline",size:"sm",onClick:()=>x(!1),disabled:r,children:l("gitView.common.cancel")}),s.jsx(ve,{variant:"destructive",size:"sm",onClick:()=>{E()},disabled:r,children:l(r?"gitView.changes.reverting":"gitView.changes.revertAll")})]})]})})]})},yc=38,Eo=200,hj=t=>{const e=ot.c(20),{value:n,onChange:r,placeholder:a,disabled:i,hasTouchInput:l,isMobile:c}=t,d=i===void 0?!1:i,p=l===void 0?!1:l,m=c===void 0?!1:c,{t:u}=ut(),f=o.useRef(null),b=Re(gj);let g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g=()=>{const T=f.current;if(!T)return;const P=document.activeElement===T,A=()=>{T.style.height=`${yc}px`;const E=T.scrollHeight,M=Math.min(Math.max(E,yc),Eo);T.style.height=`${M}px`,T.style.overflowY=E>Eo?"auto":"hidden",E>Eo&&!P&&(T.scrollTop=T.scrollHeight)};A();const N=window.requestAnimationFrame(A);return()=>{window.cancelAnimationFrame(N)}},e[0]=g):g=e[0];let v;e[1]!==n?(v=[n],e[1]=n,e[2]=v):v=e[2],o.useLayoutEffect(g,v);let x;e[3]!==r?(x=T=>r(T.target.value),e[3]=r,e[4]=x):x=e[4];let h;e[5]!==a||e[6]!==u?(h=a??u("gitView.commit.messagePlaceholder"),e[5]=a,e[6]=u,e[7]=h):h=e[7];const j=p?"on":"off",y=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 S;e[10]===Symbol.for("react.memo_cache_sentinel")?(S={minHeight:yc,maxHeight:Eo},e[10]=S):S=e[10];let I;return e[11]!==d||e[12]!==C||e[13]!==w||e[14]!==x||e[15]!==h||e[16]!==j||e[17]!==y||e[18]!==n?(I=s.jsx("textarea",{ref:f,value:n,onChange:x,placeholder:h,rows:1,disabled:d,autoCorrect:j,autoCapitalize:y,spellCheck:C,className:w,style:S}),e[11]=d,e[12]=C,e[13]=w,e[14]=x,e[15]=h,e[16]=j,e[17]=y,e[18]=n,e[19]=I):I=e[19],I};function gj(t){return t.inputSpellcheckEnabled}const xj=t=>{const e=ot.c(30),{highlights:n,onInsert:r}=t,{t:a}=ut();if(n.length===0)return null;let i;e[0]!==n||e[1]!==r?(i=()=>{r(n)},e[0]=n,e[1]=r,e[2]=i):i=e[2];const l=i;let c;e[3]!==a?(c=a("gitView.commit.aiHighlights.title"),e[3]=a,e[4]=c):c=e[4];let d;e[5]!==c?(d=s.jsx("p",{className:"typography-micro text-muted-foreground",children:c}),e[5]=c,e[6]=d):d=e[6];let 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(D,{name:"arrow-down",className:"size-4"}),e[9]=m):m=e[9];let u;e[10]!==l||e[11]!==p?(u=s.jsx(Ct,{asChild:!0,children:s.jsx(ve,{variant:"ghost",size:"icon",className:"size-6",onClick:l,"aria-label":p,children:m})}),e[10]=l,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 g;e[17]!==u||e[18]!==b?(g=s.jsxs(kt,{children:[u,b]}),e[17]=u,e[18]=b,e[19]=g):g=e[19];let v;e[20]!==d||e[21]!==g?(v=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[d,g]}),e[20]=d,e[21]=g,e[22]=v):v=e[22];let x;e[23]!==n?(x=n.map(bj),e[23]=n,e[24]=x):x=e[24];let h;e[25]!==x?(h=s.jsx("ul",{className:"space-y-1",children:x}),e[25]=x,e[26]=h):h=e[26];let j;return e[27]!==v||e[28]!==h?(j=s.jsxs("div",{className:"space-y-2 rounded-xl border border-border/60 bg-transparent px-3 py-2",children:[v,h]}),e[27]=v,e[28]=h,e[29]=j):j=e[29],j};function bj(t,e){return s.jsx("li",{className:"typography-meta text-foreground",children:t},`${t}-${e}`)}const yj=t=>{const e=ot.c(75),{stagedCount:n,commitMessage:r,onCommitMessageChange:a,generatedHighlights:i,onInsertHighlights:l,onGenerateMessage:c,isGeneratingMessage:d,onCommit:p,onCommitAndPush:m,commitAction:u,hasPendingIndexMutation:f,gitmojiEnabled:b,onOpenGitmojiPicker:g}=t,v=f===void 0?!1:f,{t:x}=ut(),h=n>0;let j;e[0]!==u||e[1]!==r||e[2]!==v||e[3]!==h?(j=r.trim()&&h&&u===null&&!v,e[0]=u,e[1]=r,e[2]=v,e[3]=h,e[4]=j):j=e[4];const y=j,{isMobile:C,hasTouchInput:k}=an();let w;e[5]!==x?(w=x("gitView.commit.title"),e[5]=x,e[6]=w):w=e[6];let S;e[7]!==w?(S=s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:w}),e[7]=w,e[8]=S):S=e[8];let I;e[9]!==h||e[10]!==x?(I=h?null:s.jsx("span",{className:"min-w-0 truncate typography-meta text-muted-foreground",children:x("gitView.commit.stageFilesHint")}),e[9]=h,e[10]=x,e[11]=I):I=e[11];let T;e[12]!==S||e[13]!==I?(T=s.jsxs("div",{className:"flex w-full items-baseline gap-2 px-0 pt-2 pb-1",children:[S,I]}),e[12]=S,e[13]=I,e[14]=T):T=e[14];let P;e[15]!==i||e[16]!==l?(P=s.jsx(xj,{highlights:i,onInsert:l}),e[15]=i,e[16]=l,e[17]=P):P=e[17];let A;e[18]!==x?(A=x("gitView.commit.messagePlaceholder"),e[18]=x,e[19]=A):A=e[19];const N=u!==null;let E;e[20]!==r||e[21]!==k||e[22]!==C||e[23]!==a||e[24]!==A||e[25]!==N?(E=s.jsx(hj,{value:r,onChange:a,placeholder:A,disabled:N,hasTouchInput:k,isMobile:C}),e[20]=r,e[21]=k,e[22]=C,e[23]=a,e[24]=A,e[25]=N,e[26]=E):E=e[26];let M;e[27]!==b||e[28]!==g||e[29]!==x?(M=b&&s.jsxs(ve,{variant:"outline",size:"sm",onClick:g,className:"w-fit",type:"button",children:[s.jsx(D,{name:"emotion-happy",className:"size-4"}),x("gitView.commit.addGitmoji")]}),e[27]=b,e[28]=g,e[29]=x,e[30]=M):M=e[30];const O=d||u!==null||v||n===0;let V;e[31]!==x?(V=x("gitView.commit.generateAria"),e[31]=x,e[32]=V):V=e[32];let B;e[33]!==d?(B=d?s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(D,{name:"ai-generate-2",className:"size-4 text-primary"}),e[33]=d,e[34]=B):B=e[34];let $;e[35]!==x?($=x("gitView.commit.generate"),e[35]=x,e[36]=$):$=e[36];let F;e[37]!==$?(F=s.jsx("span",{className:"commit-actions__label",children:$}),e[37]=$,e[38]=F):F=e[38];let _;e[39]!==c||e[40]!==O||e[41]!==V||e[42]!==B||e[43]!==F?(_=s.jsxs(ve,{variant:"outline",size:"sm",onClick:c,disabled:O,type:"button","aria-label":V,className:"commit-actions__btn",children:[B,F]}),e[39]=c,e[40]=O,e[41]=V,e[42]=B,e[43]=F,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=!y||d;let Y;e[46]!==x?(Y=x("gitView.commit.commitAria"),e[46]=x,e[47]=Y):Y=e[47];let Z;e[48]!==u||e[49]!==x?(Z=u==="commit"?s.jsxs(s.Fragment,{children:[s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"commit-actions__label",children:x("gitView.commit.committing")})]}):s.jsxs(s.Fragment,{children:[s.jsx(D,{name:"git-commit",className:"size-4"}),s.jsx("span",{className:"commit-actions__label",children:x("gitView.commit.commit")})]}),e[48]=u,e[49]=x,e[50]=Z):Z=e[50];let ae;e[51]!==p||e[52]!==L||e[53]!==Y||e[54]!==Z?(ae=s.jsx(ve,{size:"sm",variant:"outline",onClick:p,disabled:L,className:"commit-actions__btn whitespace-nowrap","aria-label":Y,children:Z}),e[51]=p,e[52]=L,e[53]=Y,e[54]=Z,e[55]=ae):ae=e[55];let re;e[56]!==y||e[57]!==u||e[58]!==d||e[59]!==C||e[60]!==m||e[61]!==x?(re=C?s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(ve,{variant:"default",size:"sm",onClick:()=>m(),disabled:!y||d,className:"h-7 w-7 p-0","aria-label":x("gitView.commit.pushAria"),children:u==="commitAndPush"?s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(D,{name:"arrow-up",className:"size-3.5"})})}),s.jsx(It,{side:"top",children:s.jsx("p",{children:x("gitView.commit.push")})})]}):s.jsx(ve,{size:"sm",variant:"default",onClick:()=>m(),disabled:!y||d,className:"commit-actions__btn","aria-label":x("gitView.commit.pushAria"),children:u==="commitAndPush"?s.jsxs(s.Fragment,{children:[s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"commit-actions__label commit-actions__label--push",children:x("gitView.commit.pushing")})]}):s.jsxs(s.Fragment,{children:[s.jsx(D,{name:"arrow-up",className:"size-3.5"}),s.jsx("span",{className:"commit-actions__label commit-actions__label--push",children:x("gitView.commit.push")})]})}),e[56]=y,e[57]=u,e[58]=d,e[59]=C,e[60]=m,e[61]=x,e[62]=re):re=e[62];let me;e[63]!==_||e[64]!==ae||e[65]!==re?(me=s.jsxs("div",{className:"@container/commit-actions flex items-center gap-2 min-w-0",children:[_,q,ae,re]}),e[63]=_,e[64]=ae,e[65]=re,e[66]=me):me=e[66];let fe;e[67]!==E||e[68]!==M||e[69]!==me||e[70]!==P?(fe=s.jsxs("div",{className:"flex flex-col gap-3 px-0 pt-1 pb-3",children:[P,E,M,me]}),e[67]=E,e[68]=M,e[69]=me,e[70]=P,e[71]=fe):fe=e[71];let H;return e[72]!==fe||e[73]!==T?(H=s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[T,fe]}),e[72]=fe,e[73]=T,e[74]=H):H=e[74],H},vj=t=>{const e=ot.c(16),{onOpenStashes:n}=t,{t:r}=ut();let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=s.jsx(D,{name:"git-commit",className:"size-10 text-muted-foreground/70 mb-4"}),e[0]=a):a=e[0];let i;e[1]!==r?(i=r("gitView.empty.cleanTitle"),e[1]=r,e[2]=i):i=e[2];let l;e[3]!==i?(l=s.jsx("p",{className:"typography-ui-label font-semibold text-foreground mb-1",children:i}),e[3]=i,e[4]=l):l=e[4];let c;e[5]!==r?(c=r("gitView.empty.cleanDescription"),e[5]=r,e[6]=c):c=e[6];let d;e[7]!==c?(d=s.jsx("p",{className:"typography-meta text-muted-foreground mb-4",children:c}),e[7]=c,e[8]=d):d=e[8];let p;e[9]!==n||e[10]!==r?(p=n?s.jsxs(ve,{type:"button",variant:"outline",size:"sm",onClick:n,className:"gap-1.5",children:[s.jsx(D,{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]!==l||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,l,d,p]}),e[12]=l,e[13]=d,e[14]=p,e[15]=m):m=e[15],m};function Uh(t){const e=ot.c(63),{draft:n,onEdit:r,onDelete:a,className:i,maxWidth:l}=t,{t:c}=ut(),p=Ll()?.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 g=b;let v;e[2]!==i?(v=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]=v):v=e[3];const x=p?.colors?.surface?.elevated,h=p?.colors?.interactive?.border,j=l?`${Math.max(200,Math.floor(l))}px`:void 0;let y;e[4]!==x||e[5]!==h||e[6]!==j?(y={backgroundColor:x,borderColor:h,maxWidth:j},e[4]=x,e[5]=h,e[6]=j,e[7]=y):y=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 S;e[15]!==w?(S=s.jsx("span",{children:w}),e[15]=w,e[16]=S):S=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]!==S||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,S,I]}),e[19]=S,e[20]=I,e[21]=C,e[22]=T):T=e[22];const P=m||!g,A=!m&&g&&"line-clamp-3";let N;e[23]!==A?(N=ye("text-sm whitespace-pre-wrap break-words leading-relaxed",A),e[23]=A,e[24]=N):N=e[24];let E;e[25]!==f||e[26]!==N?(E=s.jsx("div",{className:N,children:f}),e[25]=f,e[26]=N,e[27]=E):E=e[27];let M;e[28]!==g||e[29]!==m||e[30]!==c?(M=g&&s.jsx(Tr,{asChild:!0,children:s.jsx(ve,{variant:"ghost",size:"sm",className:"h-6 px-0 mt-1 text-xs text-muted-foreground hover:text-foreground w-full justify-start",children:m?s.jsxs(s.Fragment,{children:[s.jsx(D,{name:"arrow-up-s",className:"size-3 mr-1"}),c("inlineComment.actions.showLess")]}):s.jsxs(s.Fragment,{children:[s.jsx(D,{name:"arrow-down-s",className:"size-3 mr-1"}),c("inlineComment.actions.showMore")]})})}),e[28]=g,e[29]=m,e[30]=c,e[31]=M):M=e[31];let O;e[32]===Symbol.for("react.memo_cache_sentinel")?(O=s.jsx(yr,{}),e[32]=O):O=e[32];let V;e[33]!==P||e[34]!==E||e[35]!==M?(V=s.jsxs(br,{open:P,onOpenChange:u,children:[E,M,O]}),e[33]=P,e[34]=E,e[35]=M,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(ve,{variant:"ghost",size:"icon",className:"h-6 w-6 -mr-1 text-muted-foreground hover:text-foreground",children:s.jsx(D,{name:"more",className:"size-4"})})}),e[40]=$):$=e[40];let F;e[41]===Symbol.for("react.memo_cache_sentinel")?(F=s.jsx(D,{name:"edit",className:"size-4 mr-2"}),e[41]=F):F=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(Ot,{onClick:r,children:[F,_]}),e[44]=r,e[45]=_,e[46]=q):q=e[46];let L;e[47]===Symbol.for("react.memo_cache_sentinel")?(L=s.jsx(D,{name:"delete-bin",className:"size-4 mr-2"}),e[47]=L):L=e[47];let Y;e[48]!==c?(Y=c("inlineComment.actions.deleteComment"),e[48]=c,e[49]=Y):Y=e[49];let Z;e[50]!==a||e[51]!==Y?(Z=s.jsxs(Ot,{onClick:a,className:"text-destructive",children:[L,Y]}),e[50]=a,e[51]=Y,e[52]=Z):Z=e[52];let ae;e[53]!==q||e[54]!==Z?(ae=s.jsxs(As,{children:[$,s.jsxs(Ps,{align:"end",children:[q,Z]})]}),e[53]=q,e[54]=Z,e[55]=ae):ae=e[55];let re;e[56]!==B||e[57]!==ae?(re=s.jsxs("div",{className:"flex items-start justify-between gap-2 p-3",children:[B,ae]}),e[56]=B,e[57]=ae,e[58]=re):re=e[58];let me;return e[59]!==v||e[60]!==re||e[61]!==y?(me=s.jsx("div",{className:v,style:y,"data-comment-card":"true",children:re}),e[59]=v,e[60]=re,e[61]=y,e[62]=me):me=e[62],me}function Nl(t){const e=ot.c(57),{initialText:n,onSave:r,onCancel:a,fileLabel:i,lineRange:l,isEditing:c,className:d,maxWidth:p}=t,m=n===void 0?"":n,u=c===void 0?!1:c,{t:f}=ut(),g=Ll()?.currentTheme,{isMobile:v}=an(),[x,h]=o.useState(m),j=_e.useRef(null),y=_e.useRef(l);let C,k;e[0]!==l?(C=()=>{l&&(y.current=l)},k=[l],e[0]=l,e[1]=C,e[2]=k):(C=e[1],k=e[2]),_e.useEffect(C,k);const w=Ij,S=w(l);let I,T;e[3]!==v?(I=()=>{const xe=j.current;if(!xe)return;const ne=xe.closest(".overlay-scrollbar-container"),pe=ne?.scrollTop??window.scrollY,J=ne?.scrollLeft??window.scrollX;if(v){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(()=>{ne?(ne.scrollTop=pe,ne.scrollLeft=J):window.scrollTo({top:pe,left:J})})},T=[v],e[3]=v,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]!==x?(P=xe=>{(xe.metaKey||xe.ctrlKey)&&xe.key==="Enter"?(xe.preventDefault(),x.trim()&&r(x,w(y.current))):xe.key==="Escape"&&(xe.preventDefault(),a())},e[6]=a,e[7]=r,e[8]=x,e[9]=P):P=e[9];const A=P;let N;e[10]!==r||e[11]!==x?(N=xe=>{xe.stopPropagation(),x.trim()&&r(x,w(y.current))},e[10]=r,e[11]=x,e[12]=N):N=e[12];const E=N;let M;e[13]!==d?(M=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]=M):M=e[14];const O=g?.colors?.surface?.elevated,V=g?.colors?.interactive?.border,B=p?`${Math.max(200,Math.floor(p))}px`:void 0;let $;e[15]!==O||e[16]!==V||e[17]!==B?($={backgroundColor:O,borderColor:V,maxWidth:B},e[15]=O,e[16]=V,e[17]=B,e[18]=$):$=e[18];const F="true",_=Cj,q=kj,L="p-3",Y=(i||l)&&s.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground mb-2",children:[i&&s.jsx("span",{className:"truncate max-w-[200px]",children:i}),i&&l&&s.jsx("span",{children:"•"}),S&&s.jsx("span",{children:f("inlineComment.range.lines",{start:S.start,end:S.end})})]});let Z;e[19]===Symbol.for("react.memo_cache_sentinel")?(Z=xe=>h(xe.target.value),e[19]=Z):Z=e[19];let ae;e[20]!==f?(ae=f("inlineComment.input.placeholder"),e[20]=f,e[21]=ae):ae=e[21];let re;e[22]!==A||e[23]!==ae||e[24]!==x?(re=s.jsx(jn,{simple:!0,ref:j,value:x,onChange:Z,onKeyDown:A,placeholder:ae,outerClassName:"rounded-[var(--radius-xl)] bg-[var(--surface-subtle)] ring-1 ring-inset ring-border/60 focus-within:ring-2 focus-within:ring-[var(--interactive-focus-ring)]",className:"min-h-[80px] px-3 py-2.5 text-sm resize-y"}),e[22]=A,e[23]=ae,e[24]=x,e[25]=re):re=e[25];let me;e[26]!==f?(me=f("inlineComment.actions.cancel"),e[26]=f,e[27]=me):me=e[27];let fe;e[28]!==a||e[29]!==me?(fe=s.jsx(ve,{variant:"ghost",size:"sm",onClick:a,onPointerDown:Sj,onTouchStart:Nj,className:"h-8 text-muted-foreground hover:text-foreground",children:me}),e[28]=a,e[29]=me,e[30]=fe):fe=e[30];let H;e[31]!==x?(H=x.trim(),e[31]=x,e[32]=H):H=e[32];const K=!H,Q=g?.colors?.status?.success,W=g?.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 be;e[36]!==u||e[37]!==f?(be=f(u?"inlineComment.actions.save":"inlineComment.actions.comment"),e[36]=u,e[37]=f,e[38]=be):be=e[38];let we;e[39]!==E||e[40]!==K||e[41]!==de||e[42]!==be?(we=s.jsx(ve,{size:"sm",onClick:E,onPointerDown:jj,onTouchStart:wj,disabled:K,className:"h-8 min-w-[80px]",style:de,children:be}),e[39]=E,e[40]=K,e[41]=de,e[42]=be,e[43]=we):we=e[43];let te;e[44]!==fe||e[45]!==we?(te=s.jsxs("div",{className:"flex items-center justify-end gap-2 mt-3",children:[fe,we]}),e[44]=fe,e[45]=we,e[46]=te):te=e[46];let ge;e[47]!==Y||e[48]!==re||e[49]!==te?(ge=s.jsxs("div",{className:L,children:[Y,re,te]}),e[47]=Y,e[48]=re,e[49]=te,e[50]=ge):ge=e[50];let ue;return e[51]!==$||e[52]!==_||e[53]!==q||e[54]!==ge||e[55]!==M?(ue=s.jsx("div",{className:M,style:$,"data-comment-input":F,onPointerDown:_,onTouchStart:q,children:ge}),e[51]=$,e[52]=_,e[53]=q,e[54]=ge,e[55]=M,e[56]=ue):ue=e[56],ue}function wj(t){return t.stopPropagation()}function jj(t){return t.stopPropagation()}function Nj(t){return t.stopPropagation()}function Sj(t){return t.stopPropagation()}function kj(t){return t.stopPropagation()}function Cj(t){return t.stopPropagation()}function Ij(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 Pj=t=>{const e=Math.min(t.startLine,t.endLine),n=Math.max(t.startLine,t.endLine);return{...t,startLine:e,endLine:n}},Sl=t=>{const e=Math.min(t.start,t.end),n=Math.max(t.start,t.end);return{...t,start:e,end:n}};function Yd(t){const e=ot.c(40),{t:n}=ut(),{source:r,fileLabel:a,language:i,getCodeForRange:l,toStoreRange:c,fromDraftRange:d}=t,p=$t(Rj),m=$t(Ej),u=ai(Mj),f=ai(Tj),b=ai(Dj),g=ai(Aj),[v,x]=o.useState(null),[h,j]=o.useState(""),[y,C]=o.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 F;e[1]!==g||e[2]!==k?(F=g[k]??[],e[1]=g,e[2]=k,e[3]=F):F=e[3];const _=F;let q;if(e[4]!==a||e[5]!==_||e[6]!==r){let L;e[8]!==a||e[9]!==r?(L=Y=>Y.source===r&&Y.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 S=w;let I;e[11]===Symbol.for("react.memo_cache_sentinel")?(I=()=>{x(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 A=P;let N;e[13]!==d?(N=F=>{const _=Sl(d(F));x(_),j(F.text),C(F.id)},e[13]=d,e[14]=N):N=e[14];const E=N;let M;e[15]!==y||e[16]!==b?(M=F=>{b(F.sessionKey,F.id),y===F.id&&T()},e[15]=y,e[16]=b,e[17]=M):M=e[17];const O=M;let V;e[18]!==u||e[19]!==y||e[20]!==a||e[21]!==l||e[22]!==i||e[23]!==v||e[24]!==k||e[25]!==r||e[26]!==n||e[27]!==c||e[28]!==f?(V=(F,_)=>{const q=_??v,L=F.trim();if(!q||!L||!a)return;if(!k){G.error(n("inlineComment.toast.selectSessionToSave"));return}const Y=Sl(q),Z=Pj(c(Y)),ae=l(Y);y?f(k,y,{fileLabel:a,startLine:Z.startLine,endLine:Z.endLine,side:Z.side,code:ae,language:i,text:L}):u({sessionKey:k,source:r,fileLabel:a,startLine:Z.startLine,endLine:Z.endLine,side:Z.side,code:ae,language:i,text:L}),T()},e[18]=u,e[19]=y,e[20]=a,e[21]=l,e[22]=i,e[23]=v,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]!==O||e[32]!==S||e[33]!==y||e[34]!==d||e[35]!==B||e[36]!==v||e[37]!==k||e[38]!==E?($={sessionKey:k,drafts:S,selection:v,setSelection:x,commentText:h,setCommentText:j,editingDraftId:y,setEditingDraftId:C,reset:T,cancel:A,startEdit:E,deleteDraft:O,saveComment:B,fromDraftRange:d},e[30]=h,e[31]=O,e[32]=S,e[33]=y,e[34]=d,e[35]=B,e[36]=v,e[37]=k,e[38]=E,e[39]=$):$=e[39],$}function Aj(t){return t.drafts}function Dj(t){return t.removeDraft}function Tj(t){return t.updateDraft}function Mj(t){return t.addDraft}function Ej(t){return t.newSessionDraft?.open}function Rj(t){return t.currentSessionId}function Wh(t){const{drafts:e,editingDraftId:n,commentText:r,selection:a,isDragging:i,fileLabel:l,newWidgetId:c,mapDraftToRange:d,onSave:p,onCancel:m,onEdit:u,onDelete:f}=t,b=[];for(const g of e){const v=d(g);if(g.id===n){b.push({afterLine:v.end,id:`edit-${g.id}`,content:s.jsx(Nl,{initialText:r,fileLabel:l,lineRange:v,isEditing:!0,onSave:p,onCancel:m},`edit-${g.id}`)});continue}b.push({afterLine:v.end,id:`card-${g.id}`,content:s.jsx(Uh,{draft:g,onEdit:()=>u(g),onDelete:()=>f(g)},`card-${g.id}`)})}if(a&&!n&&!i){const g={...a,start:Math.min(a.start,a.end),end:Math.max(a.start,a.end)};b.push({afterLine:g.end,id:c,content:s.jsx(Nl,{initialText:r,fileLabel:l,lineRange:g,isEditing:!1,onSave:p,onCancel:m},c)})}return b}const el=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}`},Fj=t=>{const{drafts:e,editingDraftId:n,selection:r}=t,a=[];for(const i of e){if(!Number.isFinite(i.endLine))continue;const l=Math.max(1,Math.floor(i.endLine)),c=i.side==="original"?"deletions":"additions";a.push({lineNumber:l,side:c,metadata:{type:i.id===n?"edit":"saved",draft:i}})}return r&&!n&&a.push({lineNumber:Math.max(r.start,r.end),side:r.side??"additions",metadata:{type:"new",selection:r}}),a};function Oj(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 vm(t){if(!(!t||t<=0))return Math.max(200,Math.floor(t))}function Lj(t){const{diffRootRef:e,drafts:n,selection:r,editingDraftId:a,commentText:i,fileLabel:l,onSave:c,onCancel:d,onEdit:p,onDelete:m}=t,[u,f]=o.useState(0),[b,g]=o.useState(null),v=o.useMemo(()=>!r||a?null:el({type:"new",selection:r}),[a,r]),x=o.useMemo(()=>{const y=n.map(C=>el({type:C.id===a?"edit":"saved",draft:C}));return v&&y.push(v),y},[n,a,v]),h=o.useCallback(y=>{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="${y}"]`);if(w instanceof HTMLElement)return w;const S=k.shadowRoot;return S?S.querySelector(`[data-annotation-id="${y}"]`):null},[e]);o.useEffect(()=>{if(x.length===0)return;let y=!1,C=0;const k=12,w=()=>{y||x.every(I=>!!h(I))||C>=k||(C+=1,requestAnimationFrame(()=>{y||(f(I=>I+1),w())}))};return w(),()=>{y=!0}},[x,h]),o.useEffect(()=>{const y=e.current;if(!y)return;const C=()=>{const w=getComputedStyle(y),S=Oj(w.getPropertyValue("--oc-context-panel-width")),I=y.getBoundingClientRect(),T=S??I.width;g(T>0?T:null)};C();const k=new ResizeObserver(()=>{C()});return k.observe(y),window.addEventListener("resize",C),()=>{k.disconnect(),window.removeEventListener("resize",C)}},[e]);const j=o.useCallback(y=>{const k=e.current?.getBoundingClientRect(),w=y.closest("[data-annotation-content]"),S=w instanceof HTMLElement?w.getBoundingClientRect():y.getBoundingClientRect(),I=[S.width];k&&I.push(k.right-S.left);const T=I.filter(P=>Number.isFinite(P)&&P>0);return T.length>0?vm(Math.min(...T)):vm(b)},[e,b]);return s.jsxs(s.Fragment,{children:[n.map(y=>{const C=el({type:y.id===a?"edit":"saved",draft:y}),k=h(C);if(!k)return null;const w=j(k);return y.id===a?Go.createPortal(s.jsx(Nl,{initialText:i,fileLabel:l,lineRange:{start:y.startLine,end:y.endLine,side:y.side==="original"?"deletions":"additions"},isEditing:!0,onSave:c,onCancel:d,maxWidth:w}),k,`draft-edit-${y.id}`):Go.createPortal(s.jsx(Uh,{draft:y,onEdit:()=>p(y),onDelete:()=>m(y),maxWidth:w}),k,`draft-card-${y.id}`)}),r&&!a&&v&&(()=>{const y=h(v);if(!y)return null;const C=j(y);return Go.createPortal(s.jsx(Nl,{initialText:i,fileLabel:l,lineRange:r,isEditing:!1,onSave:c,onCancel:d,maxWidth:C}),y,v)})()]})}function $j(){return new Worker(ax,{type:"module"})}const _j=["typescript","javascript","tsx","jsx","json","markdown"],ud={unified:{poolSize:1,totalASTLRUCacheSize:24,lineDiffType:"none"},split:{poolSize:2,totalASTLRUCacheSize:56,lineDiffType:"word-alt"}};let wm,jm;const Nm=t=>{const e=ud[t],n=new ix({workerFactory:$j,poolSize:e.poolSize,totalASTLRUCacheSize:e.totalASTLRUCacheSize},{theme:{light:"pierre-light",dark:"pierre-dark"},langs:_j,lineDiffType:e.lineDiffType,preferredHighlighter:"shiki-wasm"});return n.initialize(),n},Bj=t=>{if(!(typeof window>"u"))return t==="split"?(jm??=Nm("split"),jm):(wm??=Nm("unified"),wm)},Vj=t=>{const e=ot.c(7),{children:n,renderTheme:r}=t,a=md("unified"),i=md("split");let l,c;e[0]!==r||e[1]!==i||e[2]!==a?(l=()=>{a&&a.setRenderOptions({theme:r,lineDiffType:ud.unified.lineDiffType}),i&&i.setRenderOptions({theme:r,lineDiffType:ud.split.lineDiffType})},c=[r,i,a],e[0]=r,e[1]=i,e[2]=a,e[3]=l,e[4]=c):(l=e[3],c=e[4]),_e.useEffect(l,c);let d;return e[5]!==n?(d=s.jsx(s.Fragment,{children:n}),e[5]=n,e[6]=d):d=e[6],d},zj=t=>{const e=ot.c(11),{children:n}=t,r=Ll();let a,i;if(e[0]!==r?.availableThemes||e[1]!==r?.darkThemeId||e[2]!==r?.lightThemeId){const p=hi(!1),m=hi(!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,gi(i),gi(a),e[0]=r?.availableThemes,e[1]=r?.darkThemeId,e[2]=r?.lightThemeId,e[3]=a,e[4]=i}else a=e[3],i=e[4];let l;e[5]!==a.metadata.id||e[6]!==i.metadata.id?(l={light:i.metadata.id,dark:a.metadata.id},e[5]=a.metadata.id,e[6]=i.metadata.id,e[7]=l):l=e[7];const c=l;let d;return e[8]!==n||e[9]!==c?(d=s.jsx(Vj,{renderTheme:c,children:n}),e[8]=n,e[9]=c,e[10]=d):d=e[10],d},md=t=>{const e=ot.c(2),n=t===void 0?"unified":t;let r;return e[0]!==n?(r=Bj(n),e[0]=n,e[1]=r):r=e[1],r},Uj=5e5,Wj=`
|
|
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 Kj(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 Sm(t){const e=t.length>400?`${t.slice(0,200)}${t.slice(-200)}`:t;return`${t.length}:${Kj(e)}`}const Hj=(t,e,n)=>{const i=(n.side==="deletions"?t:e).split(`
|
|
37
|
-
`),l=Math.min(n.start,n.end),c=Math.max(n.start,n.end),d=Math.max(1,l),p=Math.min(i.length,c);return d>p?"":i.slice(d-1,p).join(`
|
|
38
|
-
`)},Gj=(t,e)=>t===e?!0:!t||!e?!1:t.start===e.start&&t.end===e.end&&t.side===e.side,Ro=new WeakMap,qj={lineHeight:24,hunkSeparatorHeight:24,fileGap:0};function Yj(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 Qj(t){if(typeof document>"u")return null;const e=Yj(t);let n=Ro.get(e.key);if(!n){const a=new cx;a.setup(e.root,e.content),n={virtualizer:a,refs:0},Ro.set(e.key,n)}n.refs+=1;let r=!1;return{virtualizer:n.virtualizer,release:()=>{if(r)return;r=!0;const a=Ro.get(e.key);a&&(a.refs-=1,!(a.refs>0)&&(a.virtualizer.cleanUp(),Ro.delete(e.key)))}}}const Qd=({original:t,modified:e,language:n,fileName:r,renderSideBySide:a,wrapLines:i,layout:l="fill"})=>{const c=Ll(),d=c?.currentTheme.metadata.variant==="dark",p=c?.availableThemes.find(Q=>Q.metadata.id===c.lightThemeId)??hi(!1),m=c?.availableThemes.find(Q=>Q.metadata.id===c.darkThemeId)??hi(!0),{isMobile:u}=an(),f=Yd({source:"diff",fileLabel:r||"unknown",language:n,getCodeForRange:Q=>Hj(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:g,setSelection:v,commentText:x,setCommentText:h,editingDraftId:j,saveComment:y,cancel:C,startEdit:k,deleteDraft:w}=f,S=_e.useRef(null),I=_e.useRef(null),T=_e.useRef(!1),P=_e.useRef(null);_e.useEffect(()=>{S.current=g},[g]),_e.useEffect(()=>{I.current=j},[j]);const A=_e.useCallback(Q=>{if(T.current)return;const W=S.current;if(u&&W&&Q&&Q.side===W.side){const de=Math.min(W.start,Q.start),be=Math.max(W.end,Q.end);v({...Q,start:de,end:be})}else v(Q);Q&&(I.current||h(""))},[u,h,v]),N=_e.useCallback(()=>{C()},[C]),E=_e.useCallback(Q=>{const W=document.createElement("div");W.style.position="relative";const de=el(Q.metadata);return W.dataset.annotationId=de,W.dataset.annotationSide=Q.side,W.dataset.annotationLine=String(Q.lineNumber),W},[]),M=_e.useCallback((Q,W)=>{y(Q,W??g??void 0)},[y,g]),O=_e.useCallback(Q=>{v(Q);const W=_.current;if(W)try{T.current=!0,W.setSelectedLines(Q),P.current=Q}catch{}finally{T.current=!1}},[v]),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 be=Q.closest("[data-line-type]");if(be instanceof HTMLElement){const we=be.getBoundingClientRect(),te=Q.getBoundingClientRect(),ge=we.left+we.width/2;return te.left+te.width/2<ge?"deletions":"additions"}return"additions"},[]);gi(p),gi(m);const B=`${p.metadata.id}:${m.metadata.id}:${d?"dark":"light"}`,$=_e.useRef(null),F=_e.useRef(null),_=_e.useRef(null),q=_e.useRef(null),[,L]=o.useReducer(Q=>Q+1,0),Y=md(a?"split":"unified"),Z=_e.useMemo(()=>Iu(p),[p]),ae=_e.useMemo(()=>Iu(m),[m]);o.useLayoutEffect(()=>{const Q=$.current;if(!Q)return;const W=Q.querySelector("diffs-container");if(!W)return;const de=d?ae:Z,be=(Ie,Pe)=>Ie.colors?.[Pe],we=be(Z,"terminal.ansiGreen"),te=be(Z,"terminal.ansiRed"),ge=be(Z,"terminal.ansiBlue"),ue=be(ae,"terminal.ansiGreen"),xe=be(ae,"terminal.ansiRed"),ne=be(ae,"terminal.ansiBlue");W.style.setProperty("--shiki-light",Z.fg),W.style.setProperty("--shiki-light-bg",Z.bg),we&&W.style.setProperty("--shiki-light-addition-color",we),te&&W.style.setProperty("--shiki-light-deletion-color",te),ge&&W.style.setProperty("--shiki-light-modified-color",ge),W.style.setProperty("--shiki-dark",ae.fg),W.style.setProperty("--shiki-dark-bg",ae.bg),ue&&W.style.setProperty("--shiki-dark-addition-color",ue),xe&&W.style.setProperty("--shiki-dark-deletion-color",xe),ne&&W.style.setProperty("--shiki-dark-modified-color",ne),W.style.setProperty("--diffs-bg",de.bg),W.style.setProperty("--diffs-fg",de.fg);const pe=d?ue:we,J=d?xe:te,Se=d?ne:ge;pe&&W.style.setProperty("--diffs-addition-color-override",pe),J&&W.style.setProperty("--diffs-deletion-color-override",J),Se&&W.style.setProperty("--diffs-modified-color-override",Se);const he=W.shadowRoot?.querySelector("pre");he&&(he.style.setProperty("--shiki-light",Z.fg),he.style.setProperty("--shiki-light-bg",Z.bg),we&&he.style.setProperty("--shiki-light-addition-color",we),te&&he.style.setProperty("--shiki-light-deletion-color",te),ge&&he.style.setProperty("--shiki-light-modified-color",ge),he.style.setProperty("--shiki-dark",ae.fg),he.style.setProperty("--shiki-dark-bg",ae.bg),ue&&he.style.setProperty("--shiki-dark-addition-color",ue),xe&&he.style.setProperty("--shiki-dark-deletion-color",xe),ne&&he.style.setProperty("--shiki-dark-modified-color",ne),he.style.setProperty("--diffs-bg",de.bg),he.style.setProperty("--diffs-fg",de.fg),pe&&he.style.setProperty("--diffs-addition-color-override",pe),J&&he.style.setProperty("--diffs-deletion-color-override",J),Se&&he.style.setProperty("--diffs-modified-color-override",Se))},[ae,B,d,Z]);const re=_e.useMemo(()=>Math.max(t.length,e.length)>Uj,[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:re?0:1e3,maxLineLengthForHighlighting:re?1:1e3,expansionLineCount:20,overflow:i?"wrap":"scroll",disableFileHeader:!0,enableLineSelection:!0,enableHoverUtility:!1,onLineSelected:A,unsafeCSS:Wj,renderAnnotation:E}),[m.metadata.id,d,re,p.metadata.id,a,i,A,E]),fe=_e.useMemo(()=>Fj({drafts:b,editingDraftId:j,selection:g}),[j,b,g]),H=_e.useRef(fe);if(_e.useEffect(()=>{H.current=fe},[fe]),_e.useEffect(()=>{if(typeof window>"u")return;const Q=F.current;if(!Q||!Y)return;_.current?.cleanUp(),_.current=null,q.current?.release(),q.current=null,Q.innerHTML="";const W=Qj(Q);q.current=W;const de=W?new ox(me,W.virtualizer,qj,Y):new lx(me,Y);_.current=de,P.current=null;const be={name:r||"",contents:t,lang:n,cacheKey:`old:${B}:${r}:${Sm(t)}`},we={name:r||"",contents:e,lang:n,cacheKey:`new:${B}:${r}:${Sm(e)}`};return de.render({oldFile:be,newFile:we,lineAnnotations:H.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,Y]),_e.useEffect(()=>{const Q=_.current;if(Q){try{Q.setLineAnnotations(fe)}catch(W){console.error("Failed to apply diff line annotations",W);try{Q.setLineAnnotations([])}catch{}}requestAnimationFrame(()=>{if(_.current===Q){try{Q.rerender()}catch{}L()}})}},[fe]),_e.useEffect(()=>{const Q=_.current;if(!Q||g!==null)return;const W=P.current;if(!Gj(g,W))try{T.current=!0,Q.setSelectedLines(g),P.current=g}catch{}finally{T.current=!1}},[g]),_e.useEffect(()=>{const Q=F.current;if(!Q)return;let W=null,de=()=>{};const be=()=>{const te=Q.querySelector("diffs-container")?.shadowRoot;if(!te){W=requestAnimationFrame(be);return}const ge=ue=>{if(!(ue instanceof MouseEvent)||ue.button!==0||!(ue.target instanceof Element))return;const xe=ue.target.closest("[data-column-number]");if(!(xe instanceof HTMLElement))return;const ne=xe.getAttribute("data-column-number"),pe=ne?parseInt(ne,10):NaN;if(Number.isNaN(pe))return;const J=V(xe);A({start:pe,end:pe,side:J}),ue.preventDefault(),ue.stopPropagation()};te.addEventListener("click",ge,!0),de=()=>{te.removeEventListener("click",ge,!0)}};return be(),()=>{W!==null&&cancelAnimationFrame(W),de()}},[B,r,A,V]),_e.useEffect(()=>{const Q=F.current;if(!Q)return;let W=null,de=null;const we=setTimeout(()=>{const te=Q.querySelector("diffs-container");if(!(te instanceof HTMLElement))return;const ge=te.shadowRoot;W=new MutationObserver(()=>{de&&cancelAnimationFrame(de),de=requestAnimationFrame(()=>{L(),de=null})}),W.observe(te,{childList:!0,subtree:!0}),ge&&W.observe(ge,{childList:!0,subtree:!0})},100);return()=>{clearTimeout(we),de&&cancelAnimationFrame(de),W?.disconnect()}},[B,r]),typeof window>"u")return null;const K=s.jsx(Lj,{diffRootRef:$,drafts:b,selection:g,editingDraftId:j,commentText:x,fileLabel:r?.split("/").pop()??"",onSave:M,onCancel:N,onEdit:Q=>{O({start:Q.startLine,end:Q.endLine,side:Q.side==="original"?"deletions":"additions"}),k(Q)},onDelete:w});return l==="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(ws,{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:F,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:F,className:"w-full"})}),K]})},km=15e3,Cm=500,Im=12,Pm=8*1024*1024,Am=t=>typeof t=="string"?0:(t.original?.length??0)+(t.modified?.length??0),Dm=t=>{if(t.size<=Im){let a=0;for(const i of t.values())a+=Am(i);if(a<=Pm)return t}const e=Array.from(t.entries()).reverse(),n=new Map;let r=0;for(const[a,i]of e){if(n.size>=Im)continue;const l=Am(i);r+l>Pm&&n.size>0||(n.set(a,i),r+=l)}return new Map(Array.from(n.entries()).reverse())};function Tm(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 Jj(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 Xj=o.memo(t=>{const e=ot.c(71),{entry:n,isExpanded:r,onToggle:a,files:i,isLoadingFiles:l,onCopyHash:c,directory:d}=t,{t:p}=ut();let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m=new Set,e[0]=m):m=e[0];const[u,f]=o.useState(m);let b;e[1]===Symbol.for("react.memo_cache_sentinel")?(b=new Map,e[1]=b):b=e[1];const[g,v]=o.useState(b);let x;e[2]===Symbol.for("react.memo_cache_sentinel")?(x=new Set,e[2]=x):x=e[2];const[h,j]=o.useState(x);let y;e[3]!==d||e[4]!==n.hash?(y=async Q=>{const W=Q.path;if(!d){v(de=>new Map(de).set(W,"error"));return}v(de=>Dm(new Map(de).set(W,"loading")));try{const de=wb(d,n.hash,Q.path,!1),be=new Promise(Zj),we=await Promise.race([de,be]);v(te=>Dm(new Map(te).set(W,we)))}catch{v(de=>new Map(de).set(W,"error"))}},e[3]=d,e[4]=n.hash,e[5]=y):y=e[5];const C=y;let k;e[6]!==g||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 ge=new Set(te);return ge.has(W)?ge.delete(W):ge.add(W),ge});return}const de=g.get(W);if(u.has(W)&&de&&de!=="error"){f(te=>{const ge=new Set(te);return ge.delete(W),ge});return}f(te=>{const ge=new Set(te);return ge.add(W),ge}),!(de&&de!=="error"||Q.insertions+Q.deletions>Cm&&!h.has(W))&&await C(Q)},e[6]=g,e[7]=h,e[8]=C,e[9]=u,e[10]=k):k=e[10];const w=k,S=r?"bg-sidebar/90":"hover:bg-sidebar/40";let I;e[11]!==S?(I=ye("w-full flex items-start gap-3 px-3 py-2 text-left transition-colors",S),e[11]=S,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 A;e[16]!==n.author_name?(A=s.jsx("span",{className:"truncate min-w-[3ch]",title:n.author_name,children:n.author_name}),e[16]=n.author_name,e[17]=A):A=e[17];let N;e[18]===Symbol.for("react.memo_cache_sentinel")?(N=s.jsx("span",{className:"shrink-0",children:"·"}),e[18]=N):N=e[18];let E;e[19]!==n.date?(E=Tm(n.date),e[19]=n.date,e[20]=E):E=e[20];let M;e[21]!==n.date?(M=Tm(n.date),e[21]=n.date,e[22]=M):M=e[22];let O;e[23]!==E||e[24]!==M?(O=s.jsx("span",{className:"truncate min-w-0",title:E,children:M}),e[23]=E,e[24]=M,e[25]=O):O=e[25];let V;e[26]!==A||e[27]!==O?(V=s.jsxs("div",{className:"flex items-center gap-1 min-w-0 truncate",children:[A,N,O]}),e[26]=A,e[27]=O,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 F;e[32]!==$?(F=s.jsx("code",{className:"shrink-0 font-mono",children:$}),e[32]=$,e[33]=F):F=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(D,{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(ve,{variant:"ghost",size:"sm",className:"h-5 px-1 shrink-0",onClick:_,children:q})}),e[38]=_,e[39]=L):L=e[39];let Y;e[40]!==p?(Y=p("gitView.history.copySha"),e[40]=p,e[41]=Y):Y=e[41];let Z;e[42]!==Y?(Z=s.jsx(It,{sideOffset:8,children:Y}),e[42]=Y,e[43]=Z):Z=e[43];let ae;e[44]!==L||e[45]!==Z?(ae=s.jsxs(kt,{children:[L,Z]}),e[44]=L,e[45]=Z,e[46]=ae):ae=e[46];let re;e[47]!==V||e[48]!==F||e[49]!==ae?(re=s.jsxs("div",{className:"flex items-center gap-1 typography-meta text-muted-foreground",children:[V,B,F,ae]}),e[47]=V,e[48]=F,e[49]=ae,e[50]=re):re=e[50];let me;e[51]!==re||e[52]!==P?(me=s.jsxs("div",{className:"min-w-0 flex-1",children:[P,re]}),e[51]=re,e[52]=P,e[53]=me):me=e[53];let fe;e[54]!==a||e[55]!==me||e[56]!==I?(fe=s.jsxs("button",{type:"button",onClick:a,className:I,children:[T,me]}),e[54]=a,e[55]=me,e[56]=I,e[57]=fe):fe=e[57];let H;e[58]!==g||e[59]!==i||e[60]!==h||e[61]!==r||e[62]!==l||e[63]!==C||e[64]!==u||e[65]!==p||e[66]!==w?(H=r&&s.jsx("div",{className:"px-3 pb-2 pl-8 border-t border-border/40",children:l?s.jsxs("div",{className:"flex items-center gap-2 py-2",children:[s.jsx(D,{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",Jj(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(D,{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>Cm)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(ve,{type:"button",variant:"ghost",size:"xs",className:"h-6 px-0 text-primary hover:bg-transparent hover:underline",onClick:()=>{j(be=>new Set(be).add(Q.path)),C(Q)},children:p("gitView.history.renderDiffAnyway")})]});const de=g.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(Qd,{original:de.original,modified:de.modified,language:xi(Q.path)||"",fileName:Q.path,renderSideBySide:!1,layout:"inline"})})()})]},Q.path))})}),e[58]=g,e[59]=i,e[60]=h,e[61]=r,e[62]=l,e[63]=C,e[64]=u,e[65]=p,e[66]=w,e[67]=H):H=e[67];let K;return e[68]!==fe||e[69]!==H?(K=s.jsxs("li",{children:[fe,H]}),e[68]=fe,e[69]=H,e[70]=K):K=e[70],K});function Zj(t,e){setTimeout(()=>e(new Error(`Timed out after ${km}ms`)),km)}const e0=[{labelKey:"gitView.history.logSize25",value:25},{labelKey:"gitView.history.logSize50",value:50},{labelKey:"gitView.history.logSize100",value:100}],t0=t=>{const e=ot.c(56),{log:n,isLogLoading:r,logMaxCount:a,onLogMaxCountChange:i,expandedCommitHashes:l,onToggleCommit:c,commitFilesMap:d,loadingCommitHashes:p,onCopyHash:m,directory:u,showHeader:f,contentMaxHeightClassName:b,branchDivider:g}=t,v=f===void 0?!0:f,x=b===void 0?"max-h-[50vh]":b,h=g===void 0?null:g,{t:j}=ut(),[y,C]=o.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,S=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]!==x||e[8]!==u||e[9]!==l||e[10]!==k||e[11]!==S||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(D,{name:"arrow-down-s",className:"size-3.5"}):s.jsx(D,{name:"arrow-up",className:"size-3.5"}),e[19]=h?.direction,e[20]=q):q=e[20];const L=q;let Y;e[21]!==d||e[22]!==u||e[23]!==l||e[24]!==p||e[25]!==m||e[26]!==c?(Y=ae=>s.jsx("ul",{className:"divide-y divide-border/60",children:ae.map(re=>s.jsx(Xj,{entry:re,isExpanded:l.has(re.hash),onToggle:()=>c(re.hash),files:d.get(re.hash)??[],isLoadingFiles:p.has(re.hash),onCopyHash:m,directory:u},re.hash))}),e[21]=d,e[22]=u,e[23]=l,e[24]=p,e[25]=m,e[26]=c,e[27]=Y):Y=e[27];const Z=Y;P=s.jsx(ws,{outerClassName:`min-h-0 ${x}`,className:"h-full w-full",children:n.all.length===0?s.jsx("div",{className:"flex h-full items-center justify-center p-4",children:s.jsx("p",{className:"typography-ui-label text-muted-foreground",children:j("gitView.history.noCommits")})}):S&&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]=x,e[8]=u,e[9]=l,e[10]=k,e[11]=S,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 A=P;if(!v){if(S){let q;return e[28]!==A?(q=s.jsx("section",{className:"h-full min-h-0",children:A}),e[28]=A,e[29]=q):q=e[29],q}let _;return e[30]!==A?(_=s.jsx("section",{className:"h-full min-h-0 rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:A}),e[30]=A,e[31]=_):_=e[31],_}let N;e[32]!==j?(N=j("gitView.history.title"),e[32]=j,e[33]=N):N=e[33];let E;e[34]!==N?(E=s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:N}),e[34]=N,e[35]=E):E=e[35];let M;e[36]!==r||e[37]!==y||e[38]!==a||e[39]!==i||e[40]!==j?(M=y&&s.jsx("div",{onClick:s0,onPointerDown:n0,children:s.jsxs(is,{value:String(a),onValueChange:_=>i(Number(_)),disabled:r,children:[s.jsx(os,{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(us,{placeholder:j("gitView.history.commitsPlaceholder")})}),s.jsx(ls,{children:e0.map(_=>s.jsx(Mt,{value:String(_.value),children:j(_.labelKey)},_.value))})]})}),e[36]=r,e[37]=y,e[38]=a,e[39]=i,e[40]=j,e[41]=M):M=e[41];let O;e[42]!==y?(O=y?s.jsx(D,{name:"arrow-up-s",className:"size-4 text-muted-foreground"}):s.jsx(D,{name:"arrow-down-s",className:"size-4 text-muted-foreground"}),e[42]=y,e[43]=O):O=e[43];let V;e[44]!==M||e[45]!==O?(V=s.jsxs("div",{className:"flex items-center gap-2",children:[M,O]}),e[44]=M,e[45]=O,e[46]=V):V=e[46];let B;e[47]!==V||e[48]!==E?(B=s.jsxs(Tr,{className:"flex w-full items-center justify-between px-3 h-10 hover:bg-transparent",children:[E,V]}),e[47]=V,e[48]=E,e[49]=B):B=e[49];let $;e[50]!==A?($=s.jsx(yr,{children:A}),e[50]=A,e[51]=$):$=e[51];let F;return e[52]!==y||e[53]!==B||e[54]!==$?(F=s.jsxs(br,{open:y,onOpenChange:C,className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[B,$]}),e[52]=y,e[53]=B,e[54]=$,e[55]=F):F=e[55],F};function s0(t){return t.stopPropagation()}function n0(t){return t.stopPropagation()}const r0=9e4,a0=15e3,i0=5*6e4,o0=[2e3,5e3],l0=6e4,c0=2*6e4,d0=5*6e4,u0=720*6e4,m0="openchamber.github-pr-status",p0=t=>t==="closed"||t==="merged",f0=t=>{const e=t?.checks;return e?e.state==="pending"||e.pending>0:!1},Ji=(t,e,n)=>`${t}::${e}`,Fo=new Map,Oo=new Map,Fi=new Set,Mm=new Map,Wi=()=>({status:null,isLoading:!1,error:null,isInitialStatusResolved:!1,lastRefreshAt:0,lastDiscoveryPollAt:0,watchers:0,params:null,identity:null,resolvedRemoteName:null}),kl=t=>t?.params?.directory&&t.params.branch?{directory:t.params.directory,branch:t.params.branch,remoteName:t.params.remoteName??t.resolvedRemoteName??t.identity?.remoteName??null}:!t?.identity?.directory||!t.identity.branch?null:t.identity,Jd=t=>{const e=kl(t);return!e?.directory||!e.branch?null:`${e.directory}::${e.branch}`},Kh=(t,e)=>Object.entries(t).filter(([,n])=>Jd(n)===e).map(([n])=>n),h0=(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}}},Lo=t=>!t?.params?.canShow||!t.params.github?.prStatus?null:{...t.params,remoteName:t.params.remoteName??t.resolvedRemoteName??t.identity?.remoteName??null},g0=(t,e,n)=>{const r=Kh(t,e),a=r.map(d=>Lo(t[d])).filter(d=>!!d);if(a.length===0)return null;const i=Lo(t[n]);if(i&&Jd(t[n])===e)return i;const l=r.map(d=>t[d]).find(d=>!!(d?.resolvedRemoteName&&Lo(d)));if(l)return Lo(l);const c=a.find(d=>!!d.remoteName);return c||(a[0]??null)},x0=t=>({status:t.status,isInitialStatusResolved:t.isInitialStatusResolved,lastRefreshAt:t.lastRefreshAt,lastDiscoveryPollAt:t.lastDiscoveryPollAt,identity:kl(t),resolvedRemoteName:t.resolvedRemoteName??t.status?.resolvedRemoteName??null}),b0=t=>({...Wi(),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}),gr=rr()(ho((t,e)=>({entries:{},activeRequestCount:0,totalRequestCount:0,ensureEntry:n=>{t(r=>r.entries[n]?r:{entries:{...r.entries,[n]:Wi()}})},setParams:(n,r)=>{t(a=>{const i=a.entries[n]??Wi();return{entries:{...a.entries,[n]:h0(i,r)}}})},startWatching:n=>{if(t(i=>{const l=i.entries[n]??Wi();return{entries:{...i.entries,[n]:{...l,watchers:l.watchers+1}}}}),Fo.has(n))return;const r=i=>{const l=window.setTimeout(()=>{if(typeof document<"u"&&document.visibilityState!=="visible")return;const d=e().entries[n];!d||d.watchers<=0||d.status?.pr||e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0})},i),c=Oo.get(n)??[];c.push(l),Oo.set(n,c)};e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0}),o0.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(p0(i.status?.pr?.state))return;const c=Date.now()-i.lastRefreshAt,d=f0(i.status)?l0:i.status?.checks&&i.status.checks.state!=="pending"?d0:c0;c<d||e().refresh(n,{force:!0,onlyExistingPr:!0,silent:!0,markInitialResolved:!0})},a0);Fo.set(n,a)},stopWatching:n=>{t(l=>{const c=l.entries[n];if(!c)return l;const d=Math.max(0,c.watchers-1);return{entries:{...l.entries,[n]:{...c,watchers:d}}}});const r=e().entries[n];if(r&&r.watchers>0)return;const a=Fo.get(n);typeof a=="number"&&window.clearInterval(a),Fo.delete(n);const i=Oo.get(n);i&&i.length>0&&i.forEach(l=>{window.clearTimeout(l)}),Oo.delete(n)},refresh:async(n,r)=>{const a=e(),i=a.entries[n],l=Jd(i);if(!i||!l)return;const c=Kh(a.entries,l),d=c.some(u=>!!a.entries[u]?.status?.pr);if(r?.onlyExistingPr&&!d)return;const p=Mm.get(l)??0;if(!r?.force&&Date.now()-p<r0||Fi.has(l))return;const m=g0(a.entries,l,n);if(m){if(Fi.add(l),Mm.set(l,Date.now()),t(u=>{const f={...u.entries};return c.forEach(b=>{const g=f[b];g&&(f[b]={...g,lastRefreshAt:Date.now(),isLoading:r?.silent?g.isLoading:!0,error:null})}),{entries:f}}),m.githubAuthChecked&&m.githubConnected===!1){t(u=>{const f={...u.entries};return c.forEach(b=>{const g=f[b];g&&(f[b]={...g,status:{connected:!1},error:null,isLoading:r?.silent?g.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?g.isInitialStatusResolved:!0})}),{entries:f}}),Fi.delete(l);return}if(!m.github?.prStatus){t(u=>{const f={...u.entries};return c.forEach(b=>{const g=f[b];g&&(f[b]={...g,status:null,error:"GitHub runtime API unavailable",isLoading:r?.silent?g.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?g.isInitialStatusResolved:!0})}),{entries:f}}),Fi.delete(l);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(g=>{const v=b[g];if(!v)return;const x=v.status?.pr,h=u.pr,y=!!(h&&x&&h.number===x.number&&(!h.body||!h.body.trim())&&typeof x.body=="string"&&x.body.trim().length>0)&&h&&x?.body?{...u,pr:{...h,body:x.body}}:u,C=y.resolvedRemoteName??v.resolvedRemoteName??m.remoteName??null,k=kl(v)??{directory:m.directory,branch:m.branch,remoteName:m.remoteName??null};b[g]={...v,status:y,error:null,isLoading:r?.silent?v.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?v.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 g={...b.entries};return c.forEach(v=>{const x=g[v];x&&(g[v]={...x,error:f||"Failed to load PR status",isLoading:r?.silent?x.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?x.isInitialStatusResolved:!0})}),{entries:g}})}finally{Fi.delete(l),t(u=>({...u,activeRequestCount:Math.max(0,u.activeRequestCount-1)}))}}},refreshTargets:async(n,r)=>{const a=Array.from(new Set(n.map(i=>{const l=i.directory.trim(),c=i.branch.trim();return!l||!c?null:Ji(l,c,i.remoteName??null)}).filter(i=>!!i)));await Promise.all(a.map(i=>e().refresh(i,r)))},updateStatus:(n,r)=>{t(a=>{const i=a.entries[n]??Wi();return{entries:{...a.entries,[n]:{...i,status:r(i.status)}}}})}}),{name:m0,storage:Rl(()=>Cr()),partialize:t=>({entries:Object.fromEntries(Object.entries(t.entries).filter(([,e])=>{const n=kl(e);if(!n?.directory||!n.branch)return!1;const r=Math.max(e.lastRefreshAt,e.lastDiscoveryPollAt);return r===0||Date.now()-r<u0}).map(([e,n])=>[e,x0(n)]))}),merge:(t,e)=>{const n=t?.entries??{};return{...e,entries:Object.fromEntries(Object.entries(n).map(([a,i])=>[a,b0(i)]))}}})),y0=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"},v0=t=>{const e=y0(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}},w0=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 vc=new Map,Em=new Map;const j0=t=>{const e=ot.c(2);let n;return e[0]!==t?(n=r=>{const a=new Map,i=new Map;for(const l of t){const c=r.entries[l];if(!c)continue;const d=v0(c);if(!d)continue;const p=w0(d);a.set(l,p),i.set(l,d)}if(a.size===vc.size){let l=!0;for(const[c,d]of a)if(vc.get(c)!==d){l=!1;break}if(l)return Em}return vc=a,Em=i,i},e[0]=t,e[1]=n):n=e[1],gr(n)},N0=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"}},S0=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"},k0=[2e3,5e3],Rm=t=>t.replace(/^refs\/heads\//,"").replace(/[-_]+/g," ").replace(/\s+/g," ").trim().replace(/\b\w/g,e=>e.toUpperCase()),ua=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):""},C0=(t,e)=>{const n=ua(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},I0=(t,e)=>`${t}::${e}`,Xd=t=>{const e=String(t||"").trim();if(!e)return"";const n=e.indexOf("/");return n<=0?"":e.slice(0,n).trim()},wc=(t,e)=>{if(t.length===0)return null;const n=String(e.selectedRemoteName||"").trim();if(n){const i=t.find(l=>l.name===n);if(i)return i}const r=Xd(e.trackingBranch);if(r){const i=r==="origin"?t.find(c=>c.name==="upstream"):null;if(i)return i;const l=t.find(c=>c.name===r);if(l)return l}const a=t.find(i=>i.name==="origin");return a||(t[0]??null)},P0=t=>t.startsWith("pr-"),A0=(t,e)=>{const n=Xd(e),r=new Map(t.map(l=>[l.name,l])),a=[],i=l=>{l&&(a.some(c=>c.name===l.name)||a.push(l))};return n&&i(r.get(n)),i(r.get("upstream")),i(r.get("origin")),t.filter(l=>!P0(l.name)).forEach(l=>i(l)),t.forEach(l=>i(l)),a},jc=new Map,Nc=Zn;function D0(t,e){const[n,r]=o.useState(null),[a,i]=o.useState([]),l=o.useRef(null);return o.useEffect(()=>{r(null),i([])},[t]),o.useEffect(()=>{if(!t||!e?.repoUpstream||l.current===t)return;l.current=t;let c=!1;return(async()=>{try{const d=await e.repoUpstream(t);if(c||!d?.isFork||!d.upstream||(r(d.upstream),!e.repoBranches))return;try{const p=await e.repoBranches(d.upstream.owner,d.upstream.repo);c||i(p)}catch{}}catch{}})(),()=>{c=!0}},[t,e]),{detectedUpstream:n,upstreamBranches:a}}const T0=({directory:t,branch:e,baseBranch:n,trackingBranch:r,remotes:a=[],remoteBranches:i=[],onGeneratedDescription:l})=>{const{t:c}=ut(),{github:d}=Bn(),p=Hn(Ke=>Ke.status),m=Hn(Ke=>Ke.hasChecked),u=Re(Ke=>Ke.setSettingsDialogOpen),f=Re(Ke=>Ke.setSettingsPage),b=Re(Ke=>Ke.setActiveMainTab),g=$t(Ke=>Ke.currentSessionId),{isMobile:v,hasTouchInput:x}=an(),h=o.useCallback(()=>{f("github"),u(!0)},[u,f]),j=o.useMemo(()=>I0(t,e),[t,e]),y=o.useMemo(()=>jc.get(j)??null,[j]),C=gr(Ke=>Ke.ensureEntry),k=gr(Ke=>Ke.setParams),w=gr(Ke=>Ke.startWatching),S=gr(Ke=>Ke.stopWatching),I=gr(Ke=>Ke.refresh),T=gr(Ke=>Ke.updateStatus),[P,A]=o.useState(()=>y?.title??Rm(e)),[N,E]=o.useState(()=>y?.body??""),[M,O]=o.useState(()=>y?.draft??!1),[V,B]=o.useState(()=>y?.additionalContext??""),[$,F]=o.useState(()=>{const Ke=typeof y?.targetBaseBranch=="string"?ua(y.targetBaseBranch):"";return Ke||ua(n)}),[_,q]=o.useState("squash"),[L,Y]=o.useState(!1),[Z,ae]=o.useState(!1),[re,me]=o.useState(!1),[fe,H]=o.useState(!1),[K,Q]=o.useState(!1),[W,de]=o.useState(!1),[be,we]=o.useState(null),[te,ge]=o.useState(""),[ue,xe]=o.useState(""),[ne,pe]=o.useState(!1),[J,Se]=o.useState(!1),[he,Ie]=o.useState(()=>wc(a,{selectedRemoteName:y?.selectedRemoteName,trackingBranch:r})),[Pe,Ce]=o.useState(!1),{detectedUpstream:X,upstreamBranches:ie}=D0(t,d);o.useEffect(()=>{Ce(!1)},[t]);const Ne=a.some(Ke=>Ke.name==="upstream"),ke=!!(t&&e&&n&&(e!==n||(Ne||X!==null))),Te=o.useMemo(()=>Ji(t,e),[t,e]),Be=gr(Ke=>Ke.entries[Te]),je=Be?.isLoading??!1,ee=Be?.status??null,R=Be?.error??null,U=Be?.isInitialStatusResolved??!1,le=o.useMemo(()=>{const Ke=Pe?null:he?.name?.trim()||null,xt=new Set;for(const Qt of i){const Rt=C0(Qt,Ke);!Rt||Rt==="HEAD"||xt.add(Rt)}if(Pe)for(const Qt of ie)Qt&&Qt!=="HEAD"&&xt.add(Qt);const Tt=ua(n);Tt&&Tt!=="HEAD"&&xt.add(Tt);const Et=ua($);return Et&&Et!=="HEAD"&&xt.add(Et),Array.from(xt).sort((Qt,Rt)=>Qt.localeCompare(Rt))},[n,i,he?.name,$,ie,Pe]);o.useEffect(()=>{if(a.length===0){he&&Ie(null);return}(!he||!a.some(Ke=>Ke.name===he.name))&&Ie(wc(a,{selectedRemoteName:y?.selectedRemoteName,trackingBranch:r}))},[y?.selectedRemoteName,a,he,r]),o.useEffect(()=>{const Ke=ua(n);if(!$&&Ke){F(Ke);return}if(le.length!==0&&!le.includes($)){const xt=le.includes(Ke)?Ke:le[0];xt&&F(xt)}},[le,n,$]);const[Me,Oe]=o.useState(!1),[Ae,z]=o.useState(null),[De,Xe]=o.useState(!1),[st,tt]=o.useState(new Set),[Ue,it]=o.useState(!1),[Ye,rt]=o.useState(null),[Je,ce]=o.useState(!1),We=o.useRef(new Set),Le=o.useRef(null),Ge=o.useRef(!1),at=o.useRef(new Set),He=o.useRef([]);o.useEffect(()=>{X&&!Ne&&Ce(!0)},[X,Ne]),o.useEffect(()=>{Pe&&X?.defaultBranch&&F(X.defaultBranch)},[Pe,X?.defaultBranch]);const ze=ee?.pr??null,et=ze?`${t}#${ze.number}`:null,gt=!!(et&&be===et);o.useEffect(()=>{if(!d?.prContext||!ze||typeof ze.body=="string"&&ze.body.length>0)return;const Ke=`${t}#${ze.number}`;if(We.current.has(Ke))return;We.current.add(Ke),we(Ke);let xt=!1;return d.prContext(t,ze.number,{includeDiff:!1,includeCheckDetails:!1}).then(Tt=>{if(xt)return;const Et=Tt?.pr;Et&&T(Te,Qt=>!Qt?.pr||Qt.pr.number!==ze.number?Qt:{...Qt,pr:{...Qt.pr,body:Et.body||""}})}).catch(()=>{}).finally(()=>{xt||we(Tt=>Tt===Ke?null:Tt)}),()=>{xt=!0}},[t,d,ze,Te,T]),o.useEffect(()=>{if(!ze){de(!1),ge(""),xe(""),Le.current=null;return}const Ke=Le.current!==null&&Le.current!==ze.number;Ke&&de(!1),(!W||Ke)&&(ge(ze.title||""),xe(ze.body||"")),Le.current=ze.number},[W,ze]);const Pt=o.useCallback(async()=>{if(!d?.prContext){G.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(ze){Oe(!0),tt(new Set),Xe(!0);try{const Ke=await d.prContext(t,ze.number,{includeDiff:!1,includeCheckDetails:!0});z(Ke)}catch(Ke){const xt=Ke instanceof Error?Ke.message:String(Ke);G.error(c("gitView.pr.toast.loadCheckDetailsFailed"),{description:xt})}finally{Xe(!1)}}},[t,d,ze,c]),Nt=o.useCallback(async()=>{if(!d?.prContext){G.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(ze){it(!0),ce(!0);try{const Ke=await d.prContext(t,ze.number,{includeDiff:!1,includeCheckDetails:!1});rt(Ke)}catch(Ke){const xt=Ke instanceof Error?Ke.message:String(Ke);G.error(c("gitView.pr.toast.loadCommentsFailed"),{description:xt})}finally{ce(!1)}}},[t,d,ze,c]),ht=o.useCallback(Ke=>{if(!Ke)return"";const xt=Date.parse(Ke);return Number.isFinite(xt)?new Date(xt).toLocaleString():Ke},[]),wt=o.useMemo(()=>{const Ke=p?.user?.login;return typeof Ke=="string"?Ke.trim():""},[p]),es=o.useMemo(()=>"[&_a[href*='oc-self-mention=1']]:!text-[var(--primary-base)] [&_a[href*='oc-self-mention=1']]:font-semibold [&_a[href*='oc-self-mention=1']]:!no-underline [&_a[href*='oc-self-mention=1']:hover]:!text-[var(--primary-hover)]",[]),Vt=o.useCallback(Ke=>{const xt=wt.toLowerCase(),Tt=/(^|[^\w`])@([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,38}))/g;return Ke.replace(Tt,(Et,Qt,Rt)=>{const Os=`@${Rt}`,Ts=Rt.toLowerCase();return`${Qt}[${Os}](https://github.com/${Ts}${xt&&Ts===xt?"?oc-self-mention=1":""})`})},[wt]),Jt=o.useMemo(()=>{const Ke=(Ye?.issueComments??[]).map(Et=>({id:`issue-${Et.id}`,body:Et.body||"",authorName:Et.author?.name||Et.author?.login||c("gitView.pr.comments.unknownAuthor"),authorLogin:Et.author?.login||null,avatarUrl:Et.author?.avatarUrl||null,createdAt:Et.createdAt,context:c("gitView.pr.comments.generalContext"),path:null,line:null})),xt=(Ye?.reviewComments??[]).map(Et=>({id:`review-${Et.id}`,body:Et.body||"",authorName:Et.author?.name||Et.author?.login||c("gitView.pr.comments.unknownAuthor"),authorLogin:Et.author?.login||null,avatarUrl:Et.author?.avatarUrl||null,createdAt:Et.createdAt,context:c("gitView.pr.comments.reviewContext"),path:Et.path||null,line:Et.line??null})),Tt=[...Ke,...xt];return Tt.sort((Et,Qt)=>{const Rt=Et.createdAt?Date.parse(Et.createdAt):0,Os=Qt.createdAt?Date.parse(Qt.createdAt):0,Ts=Number.isFinite(Rt)?Rt:0,ks=Number.isFinite(Os)?Os:0;return Ts-ks}),Tt},[Ye,c]),mt=o.useCallback(()=>{if(!g)return G.error(c("gitView.pr.toast.noActiveSession"),{description:c("gitView.pr.toast.noActiveSessionDescription")}),null;const{currentProviderId:Ke,currentModelId:xt,currentAgentName:Tt,currentVariant:Et}=yt.getState(),Qt=Ol.getState().lastUsedProvider,Rt=Ke||Qt?.providerID,Os=xt||Qt?.modelID;return!Rt||!Os?(G.error(c("gitView.pr.toast.noModelSelected")),null):{sessionId:g,providerID:Rt,modelID:Os,currentAgentName:Tt??null,currentVariant:Et??null}},[g,c]),Lt=o.useCallback((Ke,xt,Tt,Et)=>{$t.getState().sendMessage(xt,Ke.providerID,Ke.modelID,Ke.currentAgentName??void 0,void 0,void 0,[{text:Tt,synthetic:!0},{text:Et,synthetic:!0}],Ke.currentVariant??void 0).catch(Qt=>{const Rt=Qt instanceof Error?Qt.message:String(Qt);G.error(c("gitView.pr.toast.sendMessageFailed"),{description:Rt})})},[c]),ts=o.useCallback(Ke=>{const xt=Ke.status||"unknown",Tt=Ke.conclusion??void 0,Et=Tt?`${xt} / ${Tt}`:xt,Qt=Ke.app?.name||Ke.app?.slug;return s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-start justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label text-foreground truncate",children:Ke.name}),s.jsx("div",{className:"typography-micro text-muted-foreground truncate",children:Qt?`${Qt} · ${Et}`:Et})]}),Ke.detailsUrl?s.jsx(ve,{variant:"outline",size:"sm",asChild:!0,className:"flex-shrink-0",children:s.jsxs("a",{href:Ke.detailsUrl,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(D,{name:"external-link",className:"size-4"}),"Open"]})}):null]}),Ke.output?.title?s.jsx("div",{className:"typography-micro text-foreground",children:Ke.output.title}):null,Ke.output?.summary?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap",children:Ke.output.summary}):null,Ke.output?.text?s.jsx("div",{className:"rounded border border-border/40 bg-transparent px-2 py-2 typography-micro text-muted-foreground whitespace-pre-wrap max-h-48 overflow-y-auto",children:Ke.output.text}):null,Array.isArray(Ke.annotations)&&Ke.annotations.length>0?s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"typography-micro text-muted-foreground",children:["Failed annotations",Ke.annotations.length>20?` (showing 20/${Ke.annotations.length})`:""]}),s.jsx("div",{className:"space-y-1",children:Ke.annotations.slice(0,20).map((Rt,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:[Rt.title||Rt.level||"Issue",Rt.path?` · ${Rt.path}`:"",typeof Rt.startLine=="number"?`:${Rt.startLine}`:"",typeof Rt.endLine=="number"&&Rt.endLine!==Rt.startLine?`-${Rt.endLine}`:""]}),s.jsx("div",{className:"typography-micro text-foreground whitespace-pre-wrap mt-1",children:Rt.message}),Rt.rawDetails?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap mt-1",children:Rt.rawDetails}):null]},`${Rt.path||"file"}:${Rt.startLine||Os}:${Os}`))})]}):null,Ke.job?.steps&&Ke.job.steps.length>0?s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.checks.steps")}),s.jsx("div",{className:"space-y-1",children:Ke.job.steps.map((Rt,Os)=>{const Ts=(Rt.conclusion||"").toLowerCase(),ks=Ts&&!["success","neutral","skipped"].includes(Ts),Bs=`${Ke.id??"run"}:${Ke.job?.jobId??"job"}:${Rt.number??Os}:${Rt.name}`,ys=st.has(Bs);return ks?s.jsxs(br,{open:ys,children:[s.jsxs("button",{type:"button",onClick:()=>{tt(Gn=>{const xn=new Set(Gn);return xn.has(Bs)?xn.delete(Bs):xn.add(Bs),xn})},className:"typography-micro flex w-full items-center gap-2 rounded px-2 py-1 text-left "+(ks?"bg-destructive/10 text-destructive":"text-muted-foreground"),children:[ys?s.jsx(D,{name:"arrow-down-s",className:"size-4"}):s.jsx(D,{name:"arrow-right-s",className:"size-4"}),s.jsx("span",{className:"truncate",children:Rt.name}),Rt.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:Rt.conclusion}):null]}),s.jsx(yr,{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 Rt.number=="number"?s.jsxs("div",{children:[c("gitView.pr.checks.stepLabel"),": ",Rt.number]}):null,Rt.status?s.jsxs("div",{children:[c("gitView.pr.checks.statusLabel"),": ",Rt.status]}):null,Rt.conclusion?s.jsxs("div",{children:[c("gitView.pr.checks.conclusionLabel"),": ",Rt.conclusion]}):null,Rt.startedAt?s.jsxs("div",{children:[c("gitView.pr.checks.startedLabel"),": ",ht(Rt.startedAt)]}):null,Rt.completedAt?s.jsxs("div",{children:[c("gitView.pr.checks.completedLabel"),": ",ht(Rt.completedAt)]}):null]})})]},Bs):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:Rt.name}),Rt.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:Rt.conclusion}):null]},Bs)})})]}):null]})},[st,ht,c]),js=o.useCallback(async()=>{if(b("chat"),!d?.prContext){G.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!ze)return;const Ke=mt();if(Ke)try{const xt=await d.prContext(t,ze.number,{includeDiff:!1,includeCheckDetails:!0}),Et=(xt.checkRuns??[]).filter(ks=>{const Bs=typeof ks.conclusion=="string"?ks.conclusion.toLowerCase():"";return Bs?!["success","neutral","skipped"].includes(Bs):!1});if(Et.length===0){G.message(c("gitView.pr.toast.noFailedChecks"));return}const Qt=await kn("github.pr.checks.review.visible"),Rt=await kn("github.pr.checks.review.instructions"),Os=Et.flatMap(ks=>(Array.isArray(ks.annotations)?ks.annotations:[]).map(ys=>({run:ks.name,level:ys.level,title:ys.title,path:ys.path,startLine:ys.startLine,endLine:ys.endLine,message:ys.message,rawDetails:ys.rawDetails}))),Ts=`GitHub PR failed checks (JSON)
|
|
39
|
-
${JSON.stringify({repo:xt.repo??null,pr:xt.pr??null,failedChecks:Et,failedAnnotations:Os},null,2)}`;Lt(Ke,Qt,Rt,Ts)}catch(xt){const Tt=xt instanceof Error?xt.message:String(xt);G.error(c("gitView.pr.toast.loadChecksFailed"),{description:Tt})}},[t,Lt,d,ze,mt,b,c]),ds=o.useCallback(async()=>{if(b("chat"),!d?.prContext){G.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!ze)return;const Ke=mt();if(Ke)try{const xt=await d.prContext(t,ze.number,{includeDiff:!1,includeCheckDetails:!1}),Tt=xt.issueComments??[],Et=xt.reviewComments??[];if(Tt.length+Et.length===0){G.message(c("gitView.pr.toast.noPrComments"));return}const Rt=await kn("github.pr.comments.review.visible"),Os=await kn("github.pr.comments.review.instructions"),Ts=`GitHub PR comments (JSON)
|
|
40
|
-
${JSON.stringify({repo:xt.repo??null,pr:xt.pr??null,issueComments:Tt,reviewComments:Et},null,2)}`;Lt(Ke,Rt,Os,Ts)}catch(xt){const Tt=xt instanceof Error?xt.message:String(xt);G.error(c("gitView.pr.toast.loadPrCommentsFailed"),{description:Tt})}},[t,Lt,d,ze,mt,b,c]),hs=o.useCallback(async Ke=>{it(!1),b("chat");const xt=mt();if(!xt)return;const Tt=await kn("github.pr.comment.single.visible"),Et=await kn("github.pr.comment.single.instructions"),Qt=`GitHub PR comment (JSON)
|
|
41
|
-
${JSON.stringify({repo:Ye?.repo??null,pr:Ye?.pr??ze??null,comment:Ke},null,2)}`;Lt(xt,Tt,Et,Qt)},[Ye,Lt,ze,mt,b]),Ut=o.useCallback(async Ke=>{await I(Te,Ke)},[Te,I]),Qe=o.useCallback(()=>{He.current.forEach(Ke=>{window.clearTimeout(Ke)}),He.current=k0.map(Ke=>window.setTimeout(()=>{Ut({force:!0,silent:!0,markInitialResolved:!0})},Ke))},[Ut]);o.useEffect(()=>{if(!d?.prStatus||!ke||a.length<=1||Ge.current||ee?.pr)return;const Ke=`${j}::${he?.name??""}`;if(at.current.has(Ke))return;at.current.add(Ke);const xt=A0(a,r).filter(Qt=>Qt.name!==he?.name);if(xt.length===0)return;let Tt=!1;return(async()=>{for(const Qt of xt){if(Tt)return;try{if(!(await d.prStatus(t,e,Qt.name))?.pr)continue;if(Tt)return;Ie(Os=>Os?.name===Qt.name?Os:Qt);return}catch{}}})(),()=>{Tt=!0}},[e,ke,t,d,a,he?.name,j,ee?.pr,r]),o.useEffect(()=>{C(Te),k(Te,{directory:t,branch:e,remoteName:he?.name??null,canShow:ke,github:d,githubAuthChecked:m,githubConnected:p?.connected??null})},[e,ke,t,C,d,m,p?.connected,Te,he?.name,k]),o.useEffect(()=>(w(Te),()=>{S(Te)}),[Te,w,S]),o.useEffect(()=>{const Ke=jc.get(j)??null;A(Ke?.title??Rm(e)),E(Ke?.body??""),O(Ke?.draft??!1),F(Ke?.targetBaseBranch?ua(Ke.targetBaseBranch):ua(n));const xt=wc(a,{selectedRemoteName:Ke?.selectedRemoteName,trackingBranch:r});Ie(Tt=>Tt?.name===xt?.name?Tt:xt)},[n,e,a,j,r]),o.useEffect(()=>{Ut({markInitialResolved:!0})},[Te,Ut]),o.useEffect(()=>{!ke||!he?.name||Ut({force:!0,silent:!0,markInitialResolved:!0})},[ke,Ut,he?.name]),o.useEffect(()=>{const Ke=ee?.resolvedRemoteName?.trim();if(!Ke||Ge.current)return;const xt=a.find(Tt=>Tt.name===Ke);xt&&Ie(Tt=>Tt?.name===xt.name?Tt:xt)},[a,ee?.resolvedRemoteName]),o.useEffect(()=>{const Ke=ee?.pr?.state==="closed"||ee?.pr?.state==="merged",xt=Be?.lastRefreshAt??0,Tt=Date.now()-xt>6e4,Et=!Ke&&Tt,Qt=()=>{Et&&Ut({force:!0,silent:!0})},Rt=()=>{document.visibilityState==="visible"&&Et&&Ut({force:!0,silent:!0})};return window.addEventListener("focus",Qt),document.addEventListener("visibilitychange",Rt),()=>{window.removeEventListener("focus",Qt),document.removeEventListener("visibilitychange",Rt)}},[Ut,ee?.pr?.state,Be?.lastRefreshAt]),o.useEffect(()=>{m&&p?.connected===!1&&Ut({force:!0,silent:!0,markInitialResolved:!0})},[m,p,Ut]),o.useEffect(()=>{!t||!e||jc.set(j,{title:P,body:N,draft:M,additionalContext:V,targetBaseBranch:$,selectedRemoteName:he?.name})},[j,P,N,M,V,$,he?.name,t,e]),o.useEffect(()=>{const Ke=He.current;return()=>{Ke.forEach(xt=>{window.clearTimeout(xt)}),He.current=[]}},[]);const At=o.useCallback(async()=>{if(!L&&t){Y(!0);try{const xt={base:Pe&&X?.defaultBranchSha?X.defaultBranchSha:$,head:e};V&&(xt.context=V);const Tt=await jb(t,xt);Tt.title?.trim()&&A(Tt.title.trim()),Tt.body?.trim()&&E(Tt.body.trim()),l?.()}catch(Ke){const xt=Ke instanceof Error?Ke.message:String(Ke);G.error(c("gitView.pr.toast.generateDescriptionFailed"),{description:xt})}finally{Y(!1)}}},[V,e,X?.defaultBranchSha,t,L,l,$,c,Pe]),Ht=o.useCallback(async()=>{if(!d?.prCreate){G.error(c("gitView.pr.toast.githubApiUnavailable"));return}const Ke=P.trim();if(!Ke){G.error(c("gitView.pr.toast.titleRequired"));return}const xt=$.trim();if(!xt){G.error(c("gitView.pr.toast.baseBranchRequired"));return}if(!Pe&&xt===e){G.error(c("gitView.pr.toast.baseMustDifferFromHead"));return}ae(!0);try{const Tt=Xd(r),Et=Pe&&X,Qt=await d.prCreate({directory:t,title:Ke,head:e,base:xt,...N.trim()?{body:N}:{},draft:M,...Et?{targetRepo:{owner:X.owner,repo:X.repo},headRemote:"origin"}:{...he?{remote:he.name}:{},...Tt&&Tt!==he?.name?{headRemote:Tt}:{}}});G.success(c("gitView.pr.toast.prCreated")),T(Te,Rt=>Rt&&{...Rt,pr:Qt}),await Ut({force:!0}),Qe()}catch(Tt){const Et=Tt instanceof Error?Tt.message:String(Tt);G.error(c("gitView.pr.toast.createPrFailed"),{description:Et})}finally{ae(!1)}},[N,e,X,t,M,d,Te,Ut,Qe,he,$,P,r,T,Pe,c]),jt=o.useCallback(async Ke=>{if(!d?.prMerge){G.error(c("gitView.pr.toast.githubApiUnavailable"));return}H(!0);try{const xt=await d.prMerge({directory:t,number:Ke.number,method:_});xt.merged?G.success(c("gitView.pr.toast.prMerged")):G.message(c("gitView.pr.toast.prNotMerged"),{description:xt.message||c("gitView.pr.notMergeable")}),await Ut({force:!0}),Qe()}catch(xt){const Tt=xt instanceof Error?xt.message:String(xt);G.error(c("gitView.pr.toast.mergeFailed"),{description:Tt}),Ke.url&&Nc(Ke.url)}finally{H(!1)}},[t,d,_,Ut,Qe,c]),Zt=o.useCallback(async Ke=>{if(!d?.prReady){G.error(c("gitView.pr.toast.githubApiUnavailable"));return}Q(!0);try{await d.prReady({directory:t,number:Ke.number}),G.success(c("gitView.pr.toast.markedReady")),await Ut({force:!0}),Qe()}catch(xt){const Tt=xt instanceof Error?xt.message:String(xt);G.error(c("gitView.pr.toast.markReadyFailed"),{description:Tt}),Ke.url&&Nc(Ke.url)}finally{Q(!1)}},[t,d,Ut,Qe,c]),rs=o.useCallback(async Ke=>{if(!d?.prUpdate){G.error(c("gitView.pr.toast.githubApiUnavailable"));return}const xt=te.trim();if(!xt){G.error(c("gitView.pr.toast.titleRequired"));return}me(!0);try{const Tt=await d.prUpdate({directory:t,number:Ke.number,title:xt,body:ue});T(Te,Et=>Et&&{...Et,pr:{...Et.pr??Ke,...Tt}}),de(!1),G.success(c("gitView.pr.toast.prUpdated")),await Ut({force:!0}),Qe()}catch(Tt){const Et=Tt instanceof Error?Tt.message:String(Tt);G.error(c("gitView.pr.toast.updatePrFailed"),{description:Et})}finally{me(!1)}},[t,ue,te,d,Te,Ut,Qe,T,c]);if(!ke)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 Ds=ee?.repo?.url||null,ns=Pe&&X?.url?X.url:Ds,zs=ee?.checks??null,$s=!!ee?.canMerge,gn=!!ee?.connected,rn=m&&ee?.connected===!1,Wt=S0(ee),Kt=Wt?`var(--pr-${Wt})`:"var(--status-info)",se=Wt==="draft"?"git-pr-draft":Wt==="merged"?"git-merge":Wt==="closed"?"git-close-pull-request":"git-pull-request",bt=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(" · "):"",_t=zs?zs.total>0?`${zs.success}/${zs.total} ${c("gitView.pr.checks.label")}`:`${zs.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:()=>{Nc(ze.url)},"aria-label":c("gitView.pr.actions.openOnGitHubAria"),children:s.jsx(D,{name:se,className:"size-4 shrink-0",style:{color:Kt}})})}),s.jsx(It,{children:s.jsx("p",{children:c("gitView.pr.actions.openOnGitHub")})})]}):s.jsx(D,{name:se,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:[je?s.jsx(D,{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:je,onClick:()=>{Ut({force:!0})},"aria-label":c("gitView.pr.actions.refreshAria"),children:s.jsx(D,{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:Kt},children:bt}),zs?s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx("span",{className:`h-2 w-2 rounded-full ${N0(zs.state)}`}),_t]}):null,r&&he&&r.split("/")[0]!==he.name?s.jsxs("span",{className:"min-w-0 truncate",children:[r.split("/")[0]," → ",he.name]}):null]}):null]}),s.jsxs("div",{className:"flex flex-col gap-3 py-3",children:[rn?s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-meta text-muted-foreground",children:c("gitView.pr.githubNotConnected")}),s.jsx(ve,{variant:"outline",size:"sm",onClick:h,className:"w-fit",children:c("gitView.pr.actions.openSettings")})]}):null,R?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:R}),ns?s.jsx(ve,{variant:"outline",size:"sm",asChild:!0,className:"w-fit",children:s.jsxs("a",{href:ns,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(D,{name:"external-link",className:"size-4"}),"Open Repo"]})}):null]}):null,!ze&&!U&&!R&&!rn?s.jsxs("div",{className:"flex items-center gap-2 typography-micro text-muted-foreground",children:[s.jsx(D,{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(Bt,{value:te,onChange:Ke=>ge(Ke.target.value),placeholder:c("gitView.pr.placeholder.title"),autoCorrect:x?"on":"off",autoCapitalize:x?"sentences":"off",spellCheck:x}),s.jsx(jn,{value:ue,onChange:Ke=>xe(Ke.target.value),className:"min-h-[120px] bg-background/80",placeholder:c("gitView.pr.placeholder.description"),autoCorrect:x?"on":"off",autoCapitalize:x?"sentences":"off",spellCheck:x})]}):s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"typography-markdown text-xl font-semibold text-foreground break-words leading-snug",children:ze.title}),ze.body?.trim()?s.jsx(ha,{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(gt?"gitView.pr.loadingDescription":"gitView.pr.noDescription")})]}),$s&&ze.draft?s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.draftMustBeReady")}):null,$s?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(ve,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>{de(!1),ge(ze.title||""),xe(ze.body||"")},disabled:re,"aria-label":c("gitView.pr.actions.cancelEditingAria"),children:s.jsx(D,{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(ve,{size:"sm",className:"h-7 w-7 px-0",onClick:()=>rs(ze),disabled:re||!te.trim(),"aria-label":c("gitView.pr.actions.savePrAria"),children:re?s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(D,{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(ve,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>de(!0),"aria-label":c("gitView.pr.actions.editPrAria"),children:s.jsx(D,{name:"edit",className:"size-4"})})}),s.jsx(It,{children:s.jsx("p",{children:c("gitView.pr.actions.editPr")})})]}):null,zs?s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(ve,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:Pt,disabled:De,"aria-label":c("gitView.pr.actions.openChecksAria"),children:De?s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(D,{name:"information",className:"size-4"})})}),s.jsx(It,{children:s.jsx("p",{children:c("gitView.pr.actions.openChecks")})})]}):null,zs?.failure?s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(ve,{variant:"outline",size:"sm",className:"h-7 w-7 px-0 border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",onClick:js,"aria-label":c("gitView.pr.actions.resolveFailedChecksAria"),children:s.jsx(D,{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(ve,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:Nt,"aria-label":c("gitView.pr.actions.openCommentsAria"),children:s.jsx(D,{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(ve,{variant:"outline",size:"sm",className:"h-7 w-7 px-0 border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",onClick:ds,"aria-label":c("gitView.pr.actions.shareCommentsAria"),children:s.jsx(D,{name:"ai-generate-2",className:"size-4"})})}),s.jsx(It,{children:s.jsx("p",{children:c("gitView.pr.actions.shareComments")})})]}),$s&&ze.draft&&ze.state==="open"?s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(ve,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>Zt(ze),disabled:K||fe||re||W,"aria-label":c("gitView.pr.actions.markReadyAria"),children:K?s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(D,{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:$s?s.jsxs(s.Fragment,{children:[s.jsxs(is,{value:_,onValueChange:Ke=>q(Ke),disabled:fe||ze.state!=="open",children:[s.jsx(os,{size:"lg",className:"h-7 w-auto min-w-0",children:s.jsx(us,{})}),s.jsxs(ls,{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(ve,{size:"sm",className:"h-7 w-7 px-0",onClick:()=>jt(ze),disabled:fe||K||ze.state!=="open"||ze.draft||re||W,"aria-label":c("gitView.pr.actions.mergePrAria"),children:fe?s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(D,{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:["(",Pe&&X?"upstream":"remote",")"]})]})]}),ns?s.jsx(ve,{variant:"outline",size:"sm",asChild:!0,children:s.jsxs("a",{href:ns,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(D,{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(Bt,{value:P,onChange:Ke=>A(Ke.target.value),placeholder:c("gitView.pr.placeholder.title"),autoCorrect:x?"on":"off",autoCapitalize:x?"sentences":"off",spellCheck:x})]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.field.baseBranch")}),le.length>0?s.jsxs(is,{value:$,onValueChange:F,children:[s.jsx(os,{className:"h-9",children:s.jsx(us,{placeholder:c("gitView.pr.placeholder.selectBaseBranch")})}),s.jsx(ls,{children:le.map(Ke=>s.jsx(Mt,{value:Ke,children:Ke},Ke))})]}):s.jsx(Bt,{value:$,onChange:Ke=>F(Ke.target.value),placeholder:c("gitView.pr.placeholder.main")})]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.field.description")}),s.jsx(jn,{value:N,onChange:Ke=>E(Ke.target.value),className:"min-h-[110px]",placeholder:c("gitView.pr.placeholder.whatChanged"),autoCorrect:x?"on":"off",autoCapitalize:x?"sentences":"off",spellCheck:x})]}),s.jsxs("div",{className:"flex items-center gap-2 cursor-pointer",role:"button",tabIndex:0,"aria-pressed":M,onClick:()=>O(Ke=>!Ke),onKeyDown:Ke=>{(Ke.key===" "||Ke.key==="Enter")&&(Ke.preventDefault(),O(xt=>!xt))},children:[s.jsx(xs,{size:"sm",checked:M,onChange:Ke=>O(Ke),ariaLabel:c("gitView.pr.actions.toggleDraftAria")}),s.jsx("span",{className:"typography-ui-label text-foreground select-none",children:c("gitView.pr.field.draft")})]}),v?s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.additionalContext.optional")}),s.jsx(ve,{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(br,{open:ne,onOpenChange:pe,children:[s.jsxs(Tr,{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:ne?c("gitView.pr.actions.hide"):V.trim()?c("gitView.pr.actions.edit"):c("gitView.pr.actions.add")})]}),s.jsx(yr,{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(jn,{value:V,onChange:Ke=>B(Ke.target.value),className:"min-h-[100px] bg-transparent",placeholder:c("gitView.pr.placeholder.additionalContext")}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.additionalContext.hint")})]})})]}),s.jsx(Br,{open:J,onClose:()=>Se(!1),title:c("gitView.pr.additionalContext.title"),footer:s.jsx(ve,{size:"sm",onClick:()=>Se(!1),className:"w-full",children:c("gitView.common.done")}),children:s.jsxs("div",{className:"space-y-3",children:[s.jsx(jn,{value:V,onChange:Ke=>B(Ke.target.value),className:"min-h-[200px] bg-transparent",placeholder:c("gitView.pr.placeholder.additionalContext"),autoFocus:!0}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.additionalContext.hint")})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(ve,{variant:"outline",size:"sm",onClick:At,disabled:L||Z,children:[L?s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(D,{name:"ai-generate-2",className:"size-4 text-primary"}),c("gitView.commit.generate")]}),s.jsx("div",{className:"flex-1"}),s.jsxs(ve,{size:"sm",className:"min-w-[7.5rem] justify-center gap-2",onClick:Ht,disabled:Z||!gn||!$.trim()||!Pe&&$.trim()===e,children:[s.jsx("span",{className:"inline-flex size-4 items-center justify-center",children:Z?s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(D,{name:"git-pull-request",className:"size-4"})}),s.jsx("span",{children:c("gitView.pr.actions.createPr")})]})]})]})]}),s.jsx(ps,{open:Me,onOpenChange:Oe,children:s.jsxs(ms,{className:"max-w-2xl max-h-[70vh] flex flex-col min-h-0",children:[s.jsxs(gs,{children:[s.jsxs(fs,{className:"flex items-center gap-2",children:[s.jsx(D,{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(D,{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(Ae?.checkRuns)&&Ae?.checkRuns.length>0?Ae.checkRuns.map((Ke,xt)=>{const Tt=`${Ke.id??"run"}:${Ke.job?.jobId??"job"}:${Ke.name}:${xt}`;return s.jsx("div",{className:"p-1",children:ts(Ke)},Tt)}):s.jsx("div",{className:"text-center text-muted-foreground py-8",children:c("gitView.pr.checkDetails.empty")})})]})]})}),s.jsx(ps,{open:Ue,onOpenChange:it,children:s.jsxs(ms,{className:"max-w-2xl max-h-[82vh] min-h-[38rem] flex flex-col gap-2",children:[s.jsx(gs,{children:s.jsxs(fs,{className:"flex items-center gap-2",children:[s.jsx(D,{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(go,{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(D,{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:Jt.length>0?s.jsx("div",{className:"relative pl-3",children:s.jsx("div",{children:Jt.map((Ke,xt)=>{const Tt=(Ke.authorName||"?").charAt(0).toUpperCase(),Et=xt===Jt.length-1;return s.jsxs("div",{className:"relative pl-10 pb-5 last:pb-0",children:[Et?null:s.jsx("div",{className:"absolute left-4 top-[2.375rem] bottom-[0.375rem] w-px bg-border/60"}),s.jsx("div",{className:"absolute left-0 top-0 z-10 flex size-8 items-center justify-center overflow-hidden rounded-full border border-border/60 bg-surface-elevated text-xs text-muted-foreground",children:Ke.avatarUrl?s.jsx("img",{src:Ke.avatarUrl,alt:Ke.authorName,className:"h-full w-full object-cover"}):s.jsx("span",{children:Tt})}),s.jsxs("div",{className:"rounded-lg bg-surface-elevated px-3 pt-0 pb-3 space-y-2",children:[s.jsxs("div",{className:"flex flex-col items-start gap-1 typography-micro text-muted-foreground sm:flex-row sm:flex-wrap sm:items-center sm:gap-x-1 sm:gap-y-1",children:[s.jsxs("span",{className:"text-foreground whitespace-nowrap",children:[Ke.authorName,Ke.authorLogin&&Ke.authorLogin!==Ke.authorName?` · @${Ke.authorLogin}`:""]}),Ke.createdAt?s.jsx("span",{className:"whitespace-nowrap",children:ht(Ke.createdAt)}):null,s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsxs(ve,{variant:"ghost",size:"sm",className:"h-6 px-0 has-[>svg]:px-0 sm:px-2 sm:has-[>svg]:px-2.5 text-[var(--status-success)] hover:bg-[var(--status-success-background)] hover:text-[var(--status-success)] justify-start",onClick:()=>{hs(Ke)},"aria-label":c("gitView.pr.actions.sendCommentToAgentAria"),children:[s.jsx(D,{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:[Ke.context,Ke.path?` · ${Ke.path}`:"",Ke.line?`:${Ke.line}`:""]}),s.jsx(ha,{content:Vt(Ke.body),className:["typography-markdown-body text-foreground break-words [&_a]:no-underline [&_a:hover]:no-underline",es].filter(Boolean).join(" ")})]})]},Ke.id)})})}):s.jsx("div",{className:"text-center text-muted-foreground py-8",children:c("gitView.pr.comments.empty")})})]})]})})]})},M0=t=>{const e=ot.c(150),{open:n,onOpenChange:r,conflictFiles:a,directory:i,operation:l,onAbort:c,onClearState:d}=t;let p;e[0]!==a?(p=a===void 0?[]:a,e[0]=a,e[1]=p):p=e[1];const m=p,{t:u}=ut(),f=$t(E0),b=$t(R0),g=za(F0),v=za(O0),x=Re(L0),[h,j]=o.useState(!1),[y,C]=o.useState(null),[k,w]=o.useState(null);let S,I;e[2]!==i||e[3]!==n||e[4]!==u?(S=()=>{!n||!i||(j(!0),w(null),C(null),Nb(i).then(Ce=>{C(Ce)}).catch(Ce=>{const X=Ce instanceof Error?Ce.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]=S,e[6]=I):(S=e[5],I=e[6]),o.useEffect(S,I);let T;e[7]!==y||e[8]!==i||e[9]!==l?(T=async()=>{if(!y)return null;const Ce=l==="merge"?"merge":"rebase",X=y.headInfo||(l==="merge"?"MERGE_HEAD":"REBASE_HEAD"),ie=l==="merge"?"git commit --no-edit":"git rebase --continue",Ne=await kn("git.conflict.resolve.visible",{operation_label:Ce,head_ref:X}),oe=await kn("git.conflict.resolve.instructions",{operation_label:Ce,directory:i,operation:l,head_info:y.headInfo||"N/A",continue_cmd:ie}),ke=`${Ce} conflict context (JSON)
|
|
42
|
-
${JSON.stringify({directory:i,operation:y.operation,headInfo:y.headInfo,statusPorcelain:y.statusPorcelain,unmergedFiles:y.unmergedFiles,diff:y.diff},null,2)}`;return{visibleText:Ne,instructionsText:oe,payloadText:ke}},e[7]=y,e[8]=i,e[9]=l,e[10]=T):T=e[10];const P=T;let A;e[11]!==c||e[12]!==r?(A=()=>{c(),r(!1)},e[11]=c,e[12]=r,e[13]=A):A=e[13];const N=A;let E;e[14]!==d||e[15]!==r?(E=()=>{d?.(),r(!1)},e[14]=d,e[15]=r,e[16]=E):E=e[16];const M=E;let O;e[17]!==P||e[18]!==b||e[19]!==d||e[20]!==r||e[21]!==x||e[22]!==g||e[23]!==v||e[24]!==u?(O=async()=>{const Ce=await P();if(!Ce){G.error(u("gitView.conflict.noDetailsAvailable"));return}if(!b){G.error(u("gitView.conflict.noActiveSession"),{description:u("gitView.conflict.noActiveSessionDescription")});return}g(Ce.visibleText,"replace"),v([{text:Ce.instructionsText,synthetic:!0},{text:Ce.payloadText,synthetic:!0}]),x("chat"),d?.(),r(!1)},e[17]=P,e[18]=b,e[19]=d,e[20]=r,e[21]=x,e[22]=g,e[23]=v,e[24]=u,e[25]=O):O=e[25];const V=O;let B;e[26]!==P||e[27]!==i||e[28]!==d||e[29]!==r||e[30]!==f||e[31]!==x||e[32]!==u?(B=async()=>{const Ce=await P();if(!Ce){G.error(u("gitView.conflict.noDetailsAvailable"));return}f({directoryOverride:i,initialPrompt:Ce.visibleText,syntheticParts:[{text:Ce.instructionsText,synthetic:!0},{text:Ce.payloadText,synthetic:!0}]}),x("chat"),d?.(),r(!1)},e[26]=P,e[27]=i,e[28]=d,e[29]=r,e[30]=f,e[31]=x,e[32]=u,e[33]=B):B=e[33];const $=B;let F,_,q,L,Y,Z,ae,re,me,fe,H,K,Q,W,de,be,we,te,ge,ue,xe,ne;if(e[34]!==y||e[35]!==m||e[36]!==b||e[37]!==N||e[38]!==M||e[39]!==V||e[40]!==$||e[41]!==h||e[42]!==k||e[43]!==r||e[44]!==n||e[45]!==l||e[46]!==u){const Ce=u(l==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),X=y?.unmergedFiles||m;q=ps,xe=n,ne=r,_=ms,ue="max-w-md w-[calc(100vw-2rem)]",W="flex flex-col gap-4 overflow-hidden";let ie;e[69]===Symbol.for("react.memo_cache_sentinel")?(ie=s.jsx(D,{name:"alert",className:"size-5 shrink-0 text-[var(--status-warning)]"}),e[69]=ie):ie=e[69];const Ne=s.jsxs("div",{className:"flex items-center gap-2",children:[ie,s.jsx(fs,{children:u("gitView.conflict.detectedTitle",{operation:Ce})})]});let oe;e[70]!==l||e[71]!==u?(oe=u("gitView.conflict.detectedDescription",{operation:l}),e[70]=l,e[71]=u,e[72]=oe):oe=e[72];let ke;e[73]!==oe?(ke=s.jsx(Ns,{children:oe}),e[73]=oe,e[74]=ke):ke=e[74],e[75]!==Ne||e[76]!==ke?(de=s.jsxs(gs,{children:[Ne,ke]}),e[75]=Ne,e[76]=ke,e[77]=de):de=e[77],e[78]!==h||e[79]!==u?(be=h&&s.jsxs("div",{className:"flex items-center justify-center gap-2 py-4 text-muted-foreground",children:[s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"typography-meta",children:u("gitView.conflict.loading")})]}),e[78]=h,e[79]=u,e[80]=be):be=e[80],e[81]!==k||e[82]!==u?(we=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]=we):we=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($0)})})]}),e[84]=X,e[85]=u,e[86]=te):te=e[86],e[87]!==y||e[88]!==u?(ge=y?.headInfo&&s.jsxs("div",{className:"space-y-1 overflow-hidden",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:u("gitView.conflict.headInfo")}),s.jsx("div",{className:"typography-micro text-foreground font-mono bg-[var(--surface-elevated)] rounded-lg p-3 max-h-24 overflow-y-auto break-words whitespace-pre-wrap",children:y.headInfo})]}),e[87]=y,e[88]=u,e[89]=ge):ge=e[89],H="flex flex-col gap-2 pt-2";let Te;e[90]!==$?(Te=()=>{$()},e[90]=$,e[91]=Te):Te=e[91];const Be=h||!y;let je;e[92]!==h?(je=h?s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(D,{name:"add",className:"size-4"}),e[92]=h,e[93]=je):je=e[93];let ee;e[94]!==u?(ee=u("gitView.conflict.resolveNewSession"),e[94]=u,e[95]=ee):ee=e[95],e[96]!==Te||e[97]!==Be||e[98]!==je||e[99]!==ee?(K=s.jsxs(ve,{variant:"default",onClick:Te,disabled:Be,className:"w-full gap-2",children:[je,ee]}),e[96]=Te,e[97]=Be,e[98]=je,e[99]=ee,e[100]=K):K=e[100];let R;e[101]!==V?(R=()=>{V()},e[101]=V,e[102]=R):R=e[102];const U=h||!y||!b;let le;e[103]!==h?(le=h?s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(D,{name:"chat-1",className:"size-4"}),e[103]=h,e[104]=le):le=e[104];let Me;e[105]!==u?(Me=u("gitView.conflict.resolveCurrentSession"),e[105]=u,e[106]=Me):Me=e[106],e[107]!==R||e[108]!==U||e[109]!==le||e[110]!==Me?(Q=s.jsxs(ve,{variant:"outline",onClick:R,disabled:U,className:"w-full gap-2",children:[le,Me]}),e[107]=R,e[108]=U,e[109]=le,e[110]=Me,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]!==M||e[115]!==Oe?(fe=s.jsx(ve,{variant:"ghost",size:"sm",onClick:M,className:"flex-1",children:Oe}),e[114]=M,e[115]=Oe,e[116]=fe):fe=e[116],F=ve,L="destructive",Y="sm",Z=N,ae="flex-1",re=u("gitView.conflict.abortOperation",{operation:Ce}),e[34]=y,e[35]=m,e[36]=b,e[37]=N,e[38]=M,e[39]=V,e[40]=$,e[41]=h,e[42]=k,e[43]=r,e[44]=n,e[45]=l,e[46]=u,e[47]=F,e[48]=_,e[49]=q,e[50]=L,e[51]=Y,e[52]=Z,e[53]=ae,e[54]=re,e[55]=me,e[56]=fe,e[57]=H,e[58]=K,e[59]=Q,e[60]=W,e[61]=de,e[62]=be,e[63]=we,e[64]=te,e[65]=ge,e[66]=ue,e[67]=xe,e[68]=ne}else F=e[47],_=e[48],q=e[49],L=e[50],Y=e[51],Z=e[52],ae=e[53],re=e[54],me=e[55],fe=e[56],H=e[57],K=e[58],Q=e[59],W=e[60],de=e[61],be=e[62],we=e[63],te=e[64],ge=e[65],ue=e[66],xe=e[67],ne=e[68];let pe;e[117]!==F||e[118]!==L||e[119]!==Y||e[120]!==Z||e[121]!==ae||e[122]!==re?(pe=s.jsx(F,{variant:L,size:Y,onClick:Z,className:ae,children:re}),e[117]=F,e[118]=L,e[119]=Y,e[120]=Z,e[121]=ae,e[122]=re,e[123]=pe):pe=e[123];let J;e[124]!==me||e[125]!==fe||e[126]!==pe?(J=s.jsxs("div",{className:me,children:[fe,pe]}),e[124]=me,e[125]=fe,e[126]=pe,e[127]=J):J=e[127];let Se;e[128]!==H||e[129]!==K||e[130]!==Q||e[131]!==J?(Se=s.jsxs("div",{className:H,children:[K,Q,J]}),e[128]=H,e[129]=K,e[130]=Q,e[131]=J,e[132]=Se):Se=e[132];let he;e[133]!==W||e[134]!==de||e[135]!==be||e[136]!==we||e[137]!==te||e[138]!==ge||e[139]!==Se?(he=s.jsxs("div",{className:W,children:[de,be,we,te,ge,Se]}),e[133]=W,e[134]=de,e[135]=be,e[136]=we,e[137]=te,e[138]=ge,e[139]=Se,e[140]=he):he=e[140];let Ie;e[141]!==_||e[142]!==ue||e[143]!==he?(Ie=s.jsx(_,{className:ue,children:he}),e[141]=_,e[142]=ue,e[143]=he,e[144]=Ie):Ie=e[144];let Pe;return e[145]!==q||e[146]!==xe||e[147]!==ne||e[148]!==Ie?(Pe=s.jsx(q,{open:xe,onOpenChange:ne,children:Ie}),e[145]=q,e[146]=xe,e[147]=ne,e[148]=Ie,e[149]=Pe):Pe=e[149],Pe};function E0(t){return t.openNewSessionDraft}function R0(t){return t.currentSessionId}function F0(t){return t.setPendingInputText}function O0(t){return t.setPendingSyntheticParts}function L0(t){return t.setActiveMainTab}function $0(t){return s.jsx("li",{className:"typography-micro text-foreground font-mono truncate block",title:t,children:t},t)}const _0=({open:t,onOpenChange:e,operation:n,targetBranch:r,onConfirm:a})=>{const{t:i}=ut(),[l,c]=o.useState(!0),[d,p]=o.useState(!1),m=i(n==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),u=async()=>{p(!0);try{await a(l),e(!1)}catch(b){const g=b instanceof Error?b.message:`Failed to ${n}`;G.error(g)}finally{p(!1)}},f=()=>{d||e(!1)};return s.jsx(ps,{open:t,onOpenChange:d?void 0:e,children:s.jsxs(ms,{className:"max-w-md",children:[s.jsxs(gs,{children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(D,{name:"alert",className:"size-5 text-[var(--status-warning)]"}),s.jsx(fs,{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})]}),l&&s.jsx("li",{children:i("gitView.stash.stepRestore")})]})]}),s.jsxs("div",{className:"flex items-center gap-2 py-2",children:[s.jsx(xs,{checked:l,onChange:c,disabled:d,ariaLabel:i("gitView.stash.restoreAria")}),s.jsx("span",{className:"typography-ui-label text-foreground cursor-pointer select-none",onClick:()=>!d&&c(!l),children:i("gitView.stash.restoreAfterOperation",{operation:n})})]}),s.jsxs(Hs,{className:"gap-2",children:[s.jsx(ve,{variant:"ghost",size:"sm",onClick:f,disabled:d,children:i("gitView.common.cancel")}),s.jsx(ve,{variant:"default",size:"sm",onClick:u,disabled:d,className:"gap-1.5",children:d?s.jsxs(s.Fragment,{children:[s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}),i("gitView.common.processing")]}):i("gitView.stash.confirmButton",{operation:m})})]})]})})},B0=({mergeInProgress:t,rebaseInProgress:e,onContinue:n,onAbort:r,onResolveWithAI:a,hasUnresolvedConflicts:i=!1,isLoading:l=!1})=>{const{t:c}=ut(),[d,p]=o.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)}},g=async()=>{p("abort");try{await r()}finally{p(null)}},v=d!==null,x=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(D,{name:h,className:"size-4 text-[var(--status-warning)] shrink-0"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:"typography-label text-[var(--status-warning)]",children:c("gitView.operation.inProgressTitle",{operation:x})}),j&&s.jsx("p",{className:"typography-micro text-muted-foreground truncate",children:j})]})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i&&a&&s.jsxs(ve,{variant:"outline",size:"sm",onClick:a,disabled:v||l,className:"gap-1.5",children:[s.jsx(D,{name:"sparkling",className:"size-4"}),c("gitView.operation.resolveWithAi")]}),d!=="continue"&&s.jsxs(ve,{variant:"ghost",size:"sm",onClick:g,disabled:v||l,className:"gap-1.5",children:[d==="abort"?s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(D,{name:"close",className:"size-4"}),c("gitView.operation.abort")]}),!i&&s.jsxs(ve,{variant:"default",size:"sm",onClick:b,disabled:v||l,className:"gap-1.5",children:[d==="continue"?s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(D,{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")})]})})},V0=t=>{const e=ot.c(104),{currentBranch:n,localBranches:r,remoteBranches:a,onMerge:i,onRebase:l,disabled:c,isOperating:d,operationLogs:p,onOperationComplete:m,mode:u,defaultTargetBranch:f}=t,b=c===void 0?!1:c,g=d===void 0?!1:d,v=p===void 0?[]:p,x=u===void 0?"dialog":u,{t:h}=ut(),[j,y]=o.useState(!1),[C,k]=o.useState("merge"),[w,S]=o.useState(null),[I,T]=o.useState(!1),[P,A]=o.useState(""),N=o.useRef(null),E=o.useRef(null),M=b||g,O=n||h("gitView.branch.currentBranchFallback"),V=v.length>0&&v.every(z0),B=v.some(U0);let $;e[0]===Symbol.for("react.memo_cache_sentinel")?($=()=>{E.current&&(E.current.scrollTop=E.current.scrollHeight)},e[0]=$):$=e[0],o.useEffect($,[v]);let F;if(e[1]!==P||e[2]!==n||e[3]!==r||e[4]!==a){e:{const R=P.toLowerCase();let U;e[6]!==a?(U=new Set(a.map(W0).filter(Boolean)),e[6]=a,e[7]=U):U=e[7];const le=U;let Me;e[8]!==n||e[9]!==le?(Me=Ae=>Ae!==n&&!le.has(Ae),e[8]=n,e[9]=le,e[10]=Me):Me=e[10];const Oe=r.filter(Me);if(!R){F=Oe;break e}F=Oe.filter(Ae=>Ae.toLowerCase().includes(R))}e[1]=P,e[2]=n,e[3]=r,e[4]=a,e[5]=F}else F=e[5];const _=F;let q;if(e[11]!==P||e[12]!==a){e:{const R=P.toLowerCase();if(!R){q=a;break e}q=a.filter(U=>U.toLowerCase().includes(R))}e[11]=P,e[12]=a,e[13]=q}else q=e[13];const L=q;let Y;e[14]!==f||e[15]!==r||e[16]!==a?(Y=()=>f&&(a.includes(f)||r.includes(f))?f:null,e[14]=f,e[15]=r,e[16]=a,e[17]=Y):Y=e[17];const Z=Y;let ae;e[18]!==Z||e[19]!==y?(ae=()=>{y(!0),S(Z()),k("merge"),A("")},e[18]=Z,e[19]=y,e[20]=ae):ae=e[20];const re=ae;let me;e[21]===Symbol.for("react.memo_cache_sentinel")?(me=R=>{S(R),T(!1),A("")},e[21]=me):me=e[21];const fe=me;let H;e[22]!==i||e[23]!==l||e[24]!==C||e[25]!==w?(H=()=>{w&&(C==="merge"?i(w):l(w))},e[22]=i,e[23]=l,e[24]=C,e[25]=w,e[26]=H):H=e[26];const K=H;let Q;e[27]!==g||e[28]!==y?(Q=()=>{g||(S(null),k("merge"),A(""),y(!1))},e[27]=g,e[28]=y,e[29]=Q):Q=e[29];const W=Q,de=()=>{g&&!V||(V&&m?.(),S(null),k("merge"),A(""),y(!1))};let be,we;e[30]!==I?(be=()=>{I||A("")},we=[I],e[30]=I,e[31]=be,e[32]=we):(be=e[31],we=e[32]),o.useEffect(be,we);let te,ge;e[33]!==x||e[34]!==Z||e[35]!==w?(te=()=>{x!=="inline"||w||S(Z())},ge=[x,Z,w],e[33]=x,e[34]=Z,e[35]=w,e[36]=te,e[37]=ge):(te=e[36],ge=e[37]),o.useEffect(te,ge);const ne=g?s.jsxs("div",{className:"space-y-3",children:[s.jsx("div",{ref:E,className:"rounded-lg border border-border bg-muted/30 p-3 max-h-48 overflow-y-auto",children:s.jsx("div",{className:"space-y-2",children:v.map(K0)})}),V?x==="dialog"?s.jsx(Hs,{children:s.jsx(ve,{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(ve,{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(D,{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(D,{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:O}):h("gitView.branch.branchToRebaseOnto")}),s.jsxs(As,{open:I,onOpenChange:T,modal:!1,children:[s.jsx(Is,{asChild:!0,children:s.jsxs(ve,{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(D,{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(Wa,{className:"h-full min-h-0",children:[s.jsx(ga,{ref:N,placeholder:h("gitView.branch.searchPlaceholder"),value:P,onValueChange:A,onKeyDown:H0}),s.jsxs(Ka,{className:"h-full min-h-0",disableHorizontal:!0,children:[s.jsx(Ha,{children:h("gitView.branch.empty")}),_.length>0&&s.jsx(Ln,{heading:h("gitView.branch.localBranches"),children:_.map(R=>s.jsx(An,{onSelect:()=>fe(R),children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:R})},`local-${R}`))}),_.length>0&&L.length>0?s.jsx(Ra,{}):null,L.length>0&&s.jsx(Ln,{heading:h("gitView.branch.remoteBranches"),children:L.map(R=>s.jsx(An,{onSelect:()=>fe(R),children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:R})},`remote-${R}`))})]})]})})]})]}),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:O})]}):s.jsxs(s.Fragment,{children:[h("gitView.branch.summaryRebasePrefix")," ",s.jsx("span",{className:"font-mono text-foreground",children:O})," ",h("gitView.branch.summaryRebaseInfix")," ",s.jsx("span",{className:"font-mono text-foreground",children:w})]})})}):null,x==="dialog"?s.jsxs(Hs,{className:"gap-2 pt-1",children:[s.jsx(ve,{variant:"ghost",size:"sm",onClick:W,children:h("gitView.common.cancel")}),s.jsx(ve,{variant:"default",size:"sm",onClick:K,disabled:!w,className:"gap-1.5",children:C==="merge"?s.jsxs(s.Fragment,{children:[s.jsx(D,{name:"git-merge",className:"size-4"}),h("gitView.operation.merge")]}):s.jsxs(s.Fragment,{children:[s.jsx(D,{name:"git-branch",className:"size-4"}),h("gitView.operation.rebase")]})})]}):s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsx(ve,{variant:"destructive",size:"sm",onClick:W,disabled:M,children:h("gitView.common.reset")}),s.jsx("div",{className:"flex-1"}),s.jsx(ve,{variant:"default",size:"sm",onClick:K,disabled:M||!w,children:h(C==="merge"?"gitView.operation.merge":"gitView.operation.rebase")})]})]});if(x==="inline"){let R;e[38]!==h?(R=h("gitView.branch.updateTitle"),e[38]=h,e[39]=R):R=e[39];let U;e[40]!==R?(U=s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:R}),e[40]=R,e[41]=U):U=e[41];let le;e[42]!==h?(le=h("gitView.branch.updateDescriptionPrefix"),e[42]=h,e[43]=le):le=e[43];let Me;e[44]!==O?(Me=s.jsx("span",{className:"font-mono text-foreground",children:O}),e[44]=O,e[45]=Me):Me=e[45];let Oe;e[46]!==le||e[47]!==Me?(Oe=s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[le," ",Me,"."]}),e[46]=le,e[47]=Me,e[48]=Oe):Oe=e[48];let Ae;e[49]!==U||e[50]!==Oe?(Ae=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]=Ae):Ae=e[51];let z;e[52]!==ne?(z=s.jsx("div",{className:"pt-3",children:ne}),e[52]=ne,e[53]=z):z=e[53];let De;return e[54]!==Ae||e[55]!==z?(De=s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[Ae,z]}),e[54]=Ae,e[55]=z,e[56]=De):De=e[56],De}let pe;e[57]!==g?(pe=g?s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(D,{name:"git-merge",className:"size-4"}),e[57]=g,e[58]=pe):pe=e[58];let J;e[59]!==h?(J=h("gitView.branch.mergeRebase"),e[59]=h,e[60]=J):J=e[60];let Se;e[61]!==J?(Se=s.jsx("span",{children:J}),e[61]=J,e[62]=Se):Se=e[62];let he;e[63]!==re||e[64]!==M||e[65]!==pe||e[66]!==Se?(he=s.jsx(Ct,{asChild:!0,children:s.jsxs(ve,{variant:"outline",size:"sm",className:"gap-1.5",onClick:re,disabled:M,children:[pe,Se]})}),e[63]=re,e[64]=M,e[65]=pe,e[66]=Se,e[67]=he):he=e[67];let Ie;e[68]!==h?(Ie=h("gitView.branch.mergeRebaseTooltip"),e[68]=h,e[69]=Ie):Ie=e[69];let Pe;e[70]!==Ie?(Pe=s.jsx(It,{sideOffset:8,children:Ie}),e[70]=Ie,e[71]=Pe):Pe=e[71];let Ce;e[72]!==he||e[73]!==Pe?(Ce=s.jsxs(kt,{children:[he,Pe]}),e[72]=he,e[73]=Pe,e[74]=Ce):Ce=e[74];let X;e[75]!==de||e[76]!==y?(X=R=>{R?y(!0):de()},e[75]=de,e[76]=y,e[77]=X):X=e[77];let ie;e[78]!==h?(ie=h("gitView.branch.updateTitle"),e[78]=h,e[79]=ie):ie=e[79];let Ne;e[80]!==ie?(Ne=s.jsx(fs,{children:ie}),e[80]=ie,e[81]=Ne):Ne=e[81];let oe;e[82]!==B||e[83]!==g||e[84]!==C||e[85]!==V||e[86]!==h||e[87]!==O?(oe=g?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:O}),"."]}),e[82]=B,e[83]=g,e[84]=C,e[85]=V,e[86]=h,e[87]=O,e[88]=oe):oe=e[88];let ke;e[89]!==oe?(ke=s.jsx(Ns,{children:oe}),e[89]=oe,e[90]=ke):ke=e[90];let Te;e[91]!==Ne||e[92]!==ke?(Te=s.jsxs(gs,{children:[Ne,ke]}),e[91]=Ne,e[92]=ke,e[93]=Te):Te=e[93];let Be;e[94]!==ne||e[95]!==Te?(Be=s.jsxs(ms,{className:"max-w-md",children:[Te,ne]}),e[94]=ne,e[95]=Te,e[96]=Be):Be=e[96];let je;e[97]!==j||e[98]!==X||e[99]!==Be?(je=s.jsx(ps,{open:j,onOpenChange:X,children:Be}),e[97]=j,e[98]=X,e[99]=Be,e[100]=je):je=e[100];let ee;return e[101]!==Ce||e[102]!==je?(ee=s.jsxs(s.Fragment,{children:[Ce,je]}),e[101]=Ce,e[102]=je,e[103]=ee):ee=e[103],ee};function z0(t){return t.status==="done"||t.status==="error"}function U0(t){return t.status==="error"}function W0(t){return t.slice(t.indexOf("/")+1)}function K0(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(D,{name:"loader-4",className:"size-3.5 animate-spin text-primary"}),t.status==="done"&&s.jsx(D,{name:"check",className:"size-3.5 text-success"}),t.status==="error"&&s.jsx(D,{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 H0(t){return t.stopPropagation()}const G0=({runMutation:t,onMutationComplete:e,onMutationError:n,onPathsComplete:r,scheduleFlush:a})=>{const i=[];let l=!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(l)return;const d=i.shift();if(!d)return;l=!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),l=!1,i.length>0&&a()}})()},clear:()=>{i.length=0},size:()=>i.length,isRunning:()=>l}},Fm="oc.git.actionTab",q0=15e3,Y0=t=>t==="commit"||t==="branch"||t==="pr",Hh="gitmojiCache",Q0=1e3*60*60*24*7,Gh="1",J0=40,X0=20,Z0="https://raw.githubusercontent.com/carloscuesta/gitmoji/master/packages/gitmojis/src/gitmojis.json",Om={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:"},qh=t=>{if(!t||typeof t!="object")return!1;const e=t;return typeof e.emoji=="string"&&typeof e.code=="string"&&typeof e.description=="string"},eN=()=>{if(typeof window>"u")return null;try{const t=localStorage.getItem(Hh);if(!t)return null;const e=JSON.parse(t);return!e||e.version!==Gh||typeof e.fetchedAt!="number"||!Array.isArray(e.gitmojis)?null:{gitmojis:e.gitmojis.filter(qh),fetchedAt:e.fetchedAt,version:e.version}}catch{return null}},tN=t=>{if(!(typeof window>"u"))try{const e={gitmojis:t,fetchedAt:Date.now(),version:Gh};localStorage.setItem(Hh,JSON.stringify(e))}catch{return}},sN=t=>Date.now()-t.fetchedAt<Q0,nN=(t,e)=>{const n=t.toLowerCase(),r=/^([a-z]+)(?:\(.*\))?!?:/,a=n.match(r);if(a){const c=a[1],d=Om[c];if(d)return e.find(p=>p.code===d)||null}const i=n.split(" ")[0],l=Om[i];return l&&e.find(c=>c.code===l)||null},Lm=new Map,Qr=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),$m=t=>{const e=t.index?.trim();return!!(e&&e!=="?")},rN=t=>{const e=t.working_dir?.trim(),n=t.index?.trim();return!!(e||n==="?")},Yh=()=>{const{t}=ut(),{git:e}=Bn(),n=ra(),[r,a]=o.useState(null),[i,l]=o.useState(!1),c=$t(Fe=>Fe.currentSessionId),d=$t(Fe=>Fe.newSessionDraft),p=$t(Fe=>Fe.setDraftBootstrapPendingDirectory),m=$t(Fe=>Fe.worktreeMetadata),u=$t(Fe=>Fe.availableWorktrees),f=Qr(n),b=o.useMemo(()=>{if(!f)return;const Fe=u.find(qe=>Qr(qe.path)===f);if(Fe)return Fe;for(const qe of m.values())if(Qr(qe.path)===f)return qe},[u,f,m]),g=o.useMemo(()=>{if(c)return m.get(c)??b;if(d?.open)return b},[c,b,d?.open,m]),{profiles:v,globalIdentity:x,defaultGitIdentityId:h,loadProfiles:j,loadGlobalIdentity:y,loadDefaultGitIdentityId:C}=Qn(er(Fe=>({profiles:Fe.profiles,globalIdentity:Fe.globalIdentity,defaultGitIdentityId:Fe.defaultGitIdentityId,loadProfiles:Fe.loadProfiles,loadGlobalIdentity:Fe.loadGlobalIdentity,loadDefaultGitIdentityId:Fe.loadDefaultGitIdentityId}))),k=Fd(n??null),w=$l(n??null),S=qf(Fe=>c?Fe.getAttachment(c):void 0),I=S?Sb(S):[],T=S&&!S.degraded&&!S.legacy?S.worktreeRoot??void 0:void 0,P=$w(n,g,w?.current??void 0),A=Od(n??null),N=kb(n??null),E=Cb(n??null),M=Ld(n??null),O=Ib(n??null),V=Qs(Fe=>Fe.setActiveDirectory),B=Qs(Fe=>Fe.fetchAll),$=Qs(Fe=>Fe.ensureAll),F=Qs(Fe=>Fe.fetchStatus),_=Qs(Fe=>Fe.fetchBranches),q=Qs(Fe=>Fe.fetchLog),L=Qs(Fe=>Fe.fetchIdentity),Y=Qs(Fe=>Fe.prefetchDiffs),Z=Qs(Fe=>Fe.setLogMaxCount),ae=Qs(Fe=>Fe.moveStatusPathsOptimistically),re=Qs(Fe=>Fe.restoreStatus),me=Qs(Fe=>Fe.bumpIndexRevision),fe=Re(Fe=>Fe.isMobile),H=Re(Fe=>Fe.openContextDiff),K=Re(Fe=>Fe.navigateToDiff),Q=Re(Fe=>Fe.setRightSidebarOpen),W=o.useRef(null),de=o.useRef(null),be=o.useRef(null),we=o.useRef(null),te=o.useCallback(()=>{de.current!==null&&(window.clearTimeout(de.current),de.current=null)},[]),ge=o.useCallback(Fe=>{te(),de.current=window.setTimeout(()=>{de.current=null,Qr(Fe)===Qr(n)&&F(Fe,e,{silent:!0})},q0)},[te,n,F,e]);o.useEffect(()=>te,[te]);const ue=o.useCallback(()=>{be.current!==null&&(window.clearTimeout(be.current),be.current=null)},[]),xe=o.useCallback(()=>{be.current===null&&(be.current=window.setTimeout(()=>{be.current=null,we.current?.()},0))},[]),ne=o.useCallback(async(Fe,qe,Ze)=>{if(qe==="stage"){if(e.stageGitFiles){await e.stageGitFiles(Fe,Ze);return}await Promise.all(Ze.map(dt=>e.stageGitFile(Fe,dt)));return}if(e.unstageGitFiles){await e.unstageGitFiles(Fe,Ze);return}await Promise.all(Ze.map(dt=>e.unstageGitFile(Fe,dt)))},[e]),pe=o.useMemo(()=>G0({runMutation:({directory:Fe,direction:qe,paths:Ze})=>ne(Fe,qe,Ze),onMutationComplete:({directory:Fe})=>{me(Fe),ge(Fe)},onMutationError:({directory:Fe,direction:qe,rollback:Ze},dt)=>{Ze?.(),me(Fe),ge(Fe);const Ft=t(qe==="stage"?"gitView.toast.stageFileFailed":"gitView.toast.unstageFileFailed");G.error(dt instanceof Error?dt.message:Ft)},onPathsComplete:Fe=>{Le(qe=>{const Ze=new Set(qe);return Fe.forEach(dt=>Ze.delete(dt)),Ze})},scheduleFlush:xe}),[me,ne,xe,ge,t]);o.useEffect(()=>(we.current=pe.flush,()=>{we.current=null}),[pe]),o.useEffect(()=>()=>pe.clear(),[pe]),o.useEffect(()=>ue,[ue]),o.useEffect(()=>{if(!n){a(null),l(!1);return}let Fe=!1,qe=null;const Ze=async()=>{try{const dt=await Ab(n);if(Fe)return;a(dt.status),dt.status==="pending"&&(qe=window.setTimeout(()=>{Ze()},500))}catch{Fe||a(null)}};return Ze(),()=>{Fe=!0,qe!==null&&window.clearTimeout(qe)}},[n]),o.useEffect(()=>{const Fe=W.current;W.current=r,!(!n||!e)&&(Fe==="pending"&&r==="ready"&&(l(!0),B(n,e).finally(()=>{window.setTimeout(()=>{l(!1)},1200)})),r==="failed"&&(p(null),l(!1)))},[n,B,e,p,r]);const J=Qr(d?.bootstrapPendingDirectory??null),Se=!!(n&&J&&J===Qr(n)),Ie=!!(n&&(r==="pending"||Se))||i,Pe=o.useMemo(()=>n?Lm.get(n)??null:null,[n]),Ce=yt(Fe=>Fe.settingsGitmojiEnabled),[X,ie]=o.useState(null);o.useEffect(()=>{const Fe=T||P?.projectDirectory;if(!Fe){ie(null);return}let qe=!1;return xo(Fe).then(Ze=>{if(qe)return;const dt=Ze.trim();ie(dt&&dt!=="HEAD"?dt:null)}).catch(()=>{qe||ie(null)}),()=>{qe=!0}},[T,P?.projectDirectory]);const[Ne,oe]=o.useState(Pe?.commitMessage??""),[ke,Te]=o.useState([]),[Be,je]=o.useState(!1),ee=o.useRef(null),[R,U]=o.useState(null),[le,Me]=o.useState(!1),[Oe,Ae]=o.useState(null),[z,De]=o.useState(25),[Xe,st]=o.useState(!1),{triggerFireworks:tt}=Ew(),Ue=o.useRef(new Map),it=o.useRef(0),Ye=o.useCallback(()=>{it.current+=1,st(!0)},[]),rt=o.useCallback(()=>{it.current=Math.max(0,it.current-1),it.current===0&&st(!1)},[]),[Je,ce]=o.useState(new Set),[We,Le]=o.useState(new Set),[Ge,at]=o.useState(!1),[He,ze]=o.useState(0),[et,gt]=o.useState(!1),[Pt,Nt]=o.useState(Pe?.generatedHighlights??[]),ht=We.size>0||pe.size()>0||pe.isRunning(),wt=o.useCallback(()=>{const Fe=ee.current;Fe&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{Fe.scrollTo({top:Fe.scrollHeight,behavior:"smooth"})})})},[]),es=T||P?.projectDirectory||null,Vt=w?.current||null,Jt=o.useMemo(()=>{const Fe=w?.tracking;return Fe?Fe.startsWith("origin/"):!0},[w?.tracking]),mt=o.useMemo(()=>{const Fe=P?.createdFromBranch,qe=typeof Fe=="string"?Fe.trim():"",Ze=typeof w?.current=="string"?w.current.trim():"",dt=typeof X=="string"?X.trim():"";return qe?qe===Ze&&qe.startsWith("opencode/")&&dt.length>0&&dt!==qe?dt:qe:dt||Ze||"HEAD"},[P?.createdFromBranch,w,X]),Lt=o.useCallback(()=>{Nt([])},[]),[ts,js]=o.useState(new Set),[ds,hs]=o.useState(new Map),[Ut,Qe]=o.useState(new Set),[At,Ht]=o.useState(null),[jt,Zt]=o.useState(null),[rs,Ds]=o.useState([]),[ns,zs]=o.useState(""),[$s,gn]=o.useState(!1),rn=o.useMemo(()=>[{id:"commit",label:t("gitView.tabs.commit"),icon:s.jsx(D,{name:"git-commit",className:"h-3.5 w-3.5"})},{id:"branch",label:t("gitView.tabs.update"),icon:s.jsx(D,{name:"git-merge",className:"h-3.5 w-3.5"})},{id:"pr",label:t("gitView.tabs.pr"),icon:s.jsx(D,{name:"git-pull-request",className:"h-3.5 w-3.5"})}],[t]),[Wt,Kt]=o.useState(()=>{if(typeof window>"u")return"commit";const Fe=window.localStorage.getItem(Fm);return Fe==="worktree"?"branch":Y0(Fe)?Fe:"commit"}),[se,bt]=o.useState([]),[_t,lt]=o.useState(null),[ss,cs]=o.useState(null),[Ke,xt]=o.useState([]),[Tt,Et]=o.useState(!1),[Qt,Rt]=o.useState([]),[Os,Ts]=o.useState("merge"),ks=o.useMemo(()=>c?`openchamber.conflict:${c}`:null,[c]),Bs=o.useCallback((Fe,qe,Ze)=>{if(!ks||typeof window>"u")return;const dt={directory:Fe,conflictFiles:qe,operation:Ze};window.localStorage.setItem(ks,JSON.stringify(dt))},[ks]),ys=o.useCallback(()=>{!ks||typeof window>"u"||window.localStorage.removeItem(ks)},[ks]);o.useEffect(()=>{typeof window>"u"||window.localStorage.setItem(Fm,Wt)},[Wt]),o.useEffect(()=>{if(!ks||typeof window>"u"||!n)return;const Fe=window.localStorage.getItem(ks);if(Fe)try{const qe=JSON.parse(Fe);if(qe.directory!==n){window.localStorage.removeItem(ks);return}Rt(qe.conflictFiles??[]),Ts(qe.operation??"merge"),Et(!0)}catch{window.localStorage.removeItem(ks)}},[ks,n]);const[Gn,xn]=o.useState(!1),[ln,ar]=o.useState("merge"),[Us,bn]=o.useState(""),ir=o.useCallback(Fe=>{Rn(Fe).then(qe=>{if(qe.ok){G.success(t("gitView.toast.commitHashCopied"));return}G.error(t("gitView.toast.copyFailed"))})},[t]),Vn=o.useCallback(Fe=>{js(qe=>{const Ze=new Set(qe);return Ze.has(Fe)?Ze.delete(Fe):Ze.add(Fe),Ze})},[]);o.useEffect(()=>{if(!n||!e)return;const Fe=Array.from(ts).filter(qe=>!ds.has(qe)&&!Ut.has(qe));if(Fe.length!==0){Qe(qe=>{const Ze=new Set(qe);for(const dt of Fe)Ze.add(dt);return Ze});for(const qe of Fe)e.getCommitFiles(n,qe).then(Ze=>{hs(dt=>new Map(dt).set(qe,Ze.files))}).catch(Ze=>{console.error("Failed to fetch commit files:",Ze),hs(dt=>new Map(dt).set(qe,[]))}).finally(()=>{Qe(Ze=>{const dt=new Set(Ze);return dt.delete(qe),dt})})}},[ts,n,e,ds,Ut]),o.useEffect(()=>{n&&Lm.set(n,{directory:n,commitMessage:Ne,generatedHighlights:Pt})},[Ne,n,Pt]),o.useEffect(()=>{j(),y(),C()},[j,y,C]),o.useEffect(()=>{if(!n||!e?.getRemoteUrl){Zt(null);return}e.getRemoteUrl(n).then(Zt).catch(()=>Zt(null))},[n,e]);const Mr=o.useCallback(async()=>{if(!n||!e?.getRemotes){bt([]);return}try{const Fe=await e.getRemotes(n);bt(Fe)}catch{bt([])}},[n,e]);o.useEffect(()=>{Mr()},[Mr]),o.useEffect(()=>{if(!Ce){Ds([]);return}let Fe=!1;const qe=eN();return qe&&(Ds(qe.gitmojis),sN(qe))?()=>{Fe=!0}:((async()=>{try{const dt=await fetch(Z0);if(!dt.ok)throw new Error(`Failed to load gitmojis: ${dt.statusText}`);const Ft=await dt.json(),zt=Array.isArray(Ft.gitmojis)?Ft.gitmojis.filter(qh):[];Fe||(Ds(zt),tN(zt))}catch(dt){Fe||console.warn("Failed to load gitmoji list:",dt)}})(),()=>{Fe=!0})},[Ce]),o.useEffect(()=>{n&&(V(n),$(n,e))},[n,V,$,e]),o.useEffect(()=>{if(n)return Ar.onGitRefreshHint(Fe=>{Qr(Fe.directory)===Qr(n)&&F(n,e)})},[n,F,e]);const Ls=o.useCallback(async(Fe=!0)=>{if(n)try{await Promise.all([F(n,e),_(n,e)])}catch(qe){if(Fe){const Ze=qe instanceof Error?qe.message:t("gitView.toast.refreshRepositoryFailed");G.error(Ze)}}},[n,e,F,_,t]),Rs=o.useCallback(async()=>{n&&await q(n,e,z)},[n,e,q,z]),Ve=o.useCallback(async()=>{n&&await L(n,e)},[n,e,L]);o.useEffect(()=>{if(!n||!e?.hasLocalIdentity||k!==!0)return;const Fe=typeof h=="string"?h.trim():"";if(!Fe||Fe==="global"||Ue.current.get(n)===Fe)return;let Ze=!1;return(async()=>{try{const Ft=await e.hasLocalIdentity?.(n);if(Ze||Ft===!0)return;Ye(),await e.setGitIdentity(n,Fe),Ue.current.set(n,Fe),await Ve()}catch(Ft){console.warn("Failed to auto-apply default git identity:",Ft)}finally{Ze||rt()}})(),()=>{Ze=!0}},[Ye,n,h,rt,e,k,Ve]);const Dt=o.useMemo(()=>{if(!w)return[];const Fe=w.files??[],qe=new Map;for(const Ze of Fe)qe.set(Ze.path,Ze);return Array.from(qe.values()).sort((Ze,dt)=>Ze.path.localeCompare(dt.path))},[w]),Gt=o.useMemo(()=>Dt.filter($m),[Dt]),as=o.useMemo(()=>Dt.filter(rN),[Dt]);o.useEffect(()=>{if(!n||Dt.length===0)return;const Fe=[],qe=new Set,Ze=Ft=>{!Ft||qe.has(Ft)||(qe.add(Ft),Fe.push(Ft))};if(Gt.forEach(Ft=>Ze(Ft.path)),ke.forEach(Ze),Dt.slice(0,X0).forEach(Ft=>Ze(Ft.path)),Fe.length===0)return;const dt=window.setTimeout(()=>{Y(n,e,Fe,{maxFiles:J0})},120);return()=>{window.clearTimeout(dt)}},[Dt,n,e,Y,Gt,ke]);const _s=async(Fe,qe)=>{if(n){U(Fe);try{const Ze=dt=>{const Ft=`${dt.name}/`,zt=w?.tracking?.startsWith(Ft)?w.tracking.slice(Ft.length):void 0;return{remote:dt.name,branch:zt,rebase:!0}};if(Fe==="fetch"){if(!qe)throw new Error("No remote available for fetch");await e.gitFetch(n,{remote:qe.name}),G.success(t("gitView.toast.fetchedFromRemote",{name:qe.name}))}else if(Fe==="pull"){if(!qe)throw new Error("No remote available for pull");const dt=await e.gitPull(n,Ze(qe));G.success(dt.files.length===1?t("gitView.toast.pulledFilesSingle",{count:dt.files.length,name:qe.name}):t("gitView.toast.pulledFilesPlural",{count:dt.files.length,name:qe.name}))}else if(Fe==="push")await e.gitPush(n),G.success(t("gitView.toast.pushedToUpstream"));else if(Fe==="sync"){if(!qe)throw new Error("No remote available for sync");let dt=0,Ft=!1;await e.gitFetch(n,{remote:qe.name});const zt=await e.getGitStatus(n);if((zt.behind??0)>0){if((zt.files?.length??0)>0){G.error(t("gitView.toast.commitOrStashBeforeSync"));return}dt=(await e.gitPull(n,Ze(qe))).files.length}((await e.getGitStatus(n)).ahead??0)>0&&(await e.gitPush(n),Ft=!0),dt>0&&Ft?G.success(dt===1?t("gitView.toast.syncedPulledSingleAndPushed",{count:dt,name:qe.name}):t("gitView.toast.syncedPulledPluralAndPushed",{count:dt,name:qe.name})):dt>0?G.success(dt===1?t("gitView.toast.pulledFilesSingle",{count:dt,name:qe.name}):t("gitView.toast.pulledFilesPlural",{count:dt,name:qe.name})):Ft?G.success(t("gitView.toast.pushedToUpstream")):G.success(t("gitView.toast.alreadyUpToDate"))}await Ls(!1),await Rs()}catch(Ze){const dt=Ze instanceof Error?Ze.message:t("gitView.toast.syncActionFailed",{action:Fe==="sync"?t("gitView.sync.syncChanges"):Fe==="pull"?t("gitView.sync.pull"):Fe});G.error(dt)}finally{U(null)}}},qs=o.useCallback(async Fe=>{if(!n)return;const qe=Fe.name.trim();if(!qe){G.error(t("gitView.toast.remoteNameRequired"));return}if(qe==="origin"){G.error(t("gitView.toast.cannotRemoveOriginRemote"));return}lt(qe);try{await e.removeRemote(n,{remote:qe}),G.success(t("gitView.toast.removedRemote",{name:qe})),await Promise.all([Ls(!1),Mr()])}catch(Ze){const dt=Ze instanceof Error?Ze.message:`Failed to remove ${qe}`;G.error(dt)}finally{lt(null)}},[n,e,Mr,Ls,t]),Ws=async(Fe={})=>{if(!n)return;if(!Ne.trim()){G.error(t("gitView.toast.enterCommitMessage"));return}const qe=Gt.map(dt=>dt.path).sort();if(qe.length===0){G.error(t("gitView.toast.stageFileToCommit"));return}const Ze=Fe.pushAfter?"commitAndPush":"commit";Ae(Ze);try{if(await e.createGitCommit(n,Ne.trim(),{files:qe,stageFiles:[]}),me(n),G.success(t("gitView.toast.commitCreated")),oe(""),Lt(),await Ls(),Fe.pushAfter){U("sync");const dt=w?.tracking?.split("/")[0],Ft=pn.find(wa=>wa.name===dt)??pn[0];if(!Ft)throw new Error("No remote available for sync");const zt=`${Ft.name}/`,Vs=w?.tracking?.startsWith(zt)?w.tracking.slice(zt.length):void 0;let Fs=0,Pn=!1;await e.gitFetch(n,{remote:Ft.name}),((await e.getGitStatus(n)).behind??0)>0&&(Fs=(await e.gitPull(n,{remote:Ft.name,branch:Vs,rebase:!0})).files.length),((await e.getGitStatus(n)).ahead??0)>0&&(await e.gitPush(n),Pn=!0),Fs>0&&Pn?G.success(Fs===1?t("gitView.toast.syncedPulledSingleAndPushed",{count:Fs,name:Ft.name}):t("gitView.toast.syncedPulledPluralAndPushed",{count:Fs,name:Ft.name})):Fs>0?G.success(Fs===1?t("gitView.toast.pulledFilesSingle",{count:Fs,name:Ft.name}):t("gitView.toast.pulledFilesPlural",{count:Fs,name:Ft.name})):Pn?G.success(t("gitView.toast.pushedToUpstream")):G.success(t("gitView.toast.alreadyUpToDate")),tt(),await Ls(!1)}else await Ls(!1);await Rs(),ze(dt=>dt+1)}catch(dt){const Ft=dt instanceof Error?dt.message:t("gitView.toast.createCommitFailed");G.error(Ft)}finally{Ae(null),Fe.pushAfter&&U(null)}},Zs=o.useCallback(async()=>{if(!n)return;const Fe=Gt.map(qe=>qe.path).sort();if(Fe.length===0){G.error(t("gitView.toast.stageFileToDescribe"));return}console.error("[git-generation][browser] generate button clicked",{directory:n,selectedFiles:Fe.length}),gt(!0);try{const{message:qe}=await Pb(n,Fe),Ze=qe.subject?.trim()??"",dt=Array.isArray(qe.highlights)?qe.highlights:[];if(Ze){let Ft=Ze;if(Ce&&rs.length>0){const zt=nN(Ze,rs);if(zt){const{code:Vs,emoji:Fs}=zt;!Ze.startsWith(Vs)&&!Ze.startsWith(Fs)&&(Ft=`${Vs} ${Ze}`)}}oe(Ft)}Nt(dt),wt()}catch(qe){console.error("[git-generation][browser] GitView generate handler failed",{message:qe instanceof Error?qe.message:String(qe),error:qe});const Ze=qe instanceof Error?qe.message:t("gitView.toast.generateCommitMessageFailed");G.error(Ze)}finally{gt(!1)}},[n,Gt,Ce,rs,wt,t]),tn=Fe=>Fe.reason==="attention"?`${Fe.attentionReason} in progress`:Fe.reason==="missing"?"worktree is missing":"worktree is invalid",or=async(Fe,qe)=>{if(!n||!w)return;const Ze=ec(S);if(Ze.length>0){G.error(t("gitView.toast.cannotCreateBranch",{reason:tn(Ze[0])}));return}const dt=w.current??null,Ft=qe?.name??"origin";try{await e.createBranch(n,Fe,dt??"HEAD"),G.success(t("gitView.toast.createdBranch",{name:Fe})),await e.checkoutBranch(n,Fe);let zt=!1;try{await e.gitPush(n,{remote:Ft,branch:Fe,options:["--set-upstream"]}),zt=!0}catch(Vs){const Fs=Vs instanceof Error?Vs.message:`Unable to push new branch to ${Ft}.`;G.warning(t("gitView.toast.branchCreatedLocally"),{description:s.jsxs("span",{className:"text-foreground/80 dark:text-foreground/70",children:["Upstream setup failed: ",Fs]})})}await Ls(),await Rs(),zt&&G.success(t("gitView.toast.upstreamSet",{branch:Fe,remote:Ft}))}catch(zt){const Vs=zt instanceof Error?zt.message:t("gitView.toast.createBranchFailed");throw G.error(Vs),zt}},tr=async(Fe,qe)=>{if(!n)return;const Ze=ec(S);if(Ze.length>0){G.error(t("gitView.toast.cannotRenameBranch",{reason:tn(Ze[0])}));return}try{await e.renameBranch(n,Fe,qe),G.success(t("gitView.toast.renamedBranch",{oldName:Fe,newName:qe})),await Ls(),await Rs()}catch(dt){const Ft=dt instanceof Error?dt.message:t("gitView.toast.renameBranchFailed",{oldName:Fe,newName:qe});G.error(Ft)}},Kr=async Fe=>{if(!n)return;const qe=ec(S);if(qe.length>0){G.error(t("gitView.toast.cannotCheckout",{reason:tn(qe[0])}));return}const Ze=Fe.replace(/^remotes\//,"");if(w?.current!==Ze)try{await e.checkoutBranch(n,Ze),G.success(t("gitView.toast.checkedOut",{name:Ze})),await Ls(),await Rs()}catch(dt){const Ft=dt instanceof Error?dt.message:t("gitView.toast.checkoutFailed",{name:Ze});G.error(Ft)}},zr=async Fe=>{if(n){Ye();try{await e.setGitIdentity(n,Fe.id),G.success(t("gitView.toast.appliedIdentity",{name:Fe.name})),await Ve()}catch(qe){const Ze=qe instanceof Error?qe.message:t("gitView.toast.applyIdentityFailed");G.error(Ze)}finally{rt()}}},In=o.useMemo(()=>A?.all?A.all.filter(Fe=>!Fe.startsWith("remotes/")).sort():[],[A]),cn=o.useMemo(()=>A?.all?A.all.filter(Fe=>Fe.startsWith("remotes/")).map(Fe=>Fe.replace(/^remotes\//,"")).sort():[],[A]),pn=o.useMemo(()=>{if(se.length>0)return se;const Fe=new Set,qe=w?.tracking?.trim();qe&&qe.includes("/")&&Fe.add(qe.split("/")[0]);for(const Ze of cn){const dt=Ze.indexOf("/");dt>0&&Fe.add(Ze.slice(0,dt))}return Fe.size===0&&jt&&Fe.add("origin"),Array.from(Fe).map(Ze=>({name:Ze,fetchUrl:jt??"",pushUrl:jt??""}))},[se,cn,jt,w?.tracking]),yn=o.useMemo(()=>{const Fe=new Set(pn.map(Ft=>Ft.name)),qe=Ft=>{if(!Ft)return"";let zt=Ft.trim();if(!zt||zt==="HEAD")return"";if(In.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 Vs=zt.indexOf("/");if(Vs>0){const Fs=zt.slice(0,Vs);if(Fe.has(Fs)){const Pn=zt.slice(Vs+1).trim();Pn&&(zt=Pn)}}return zt},Ze=qe(typeof P?.createdFromBranch=="string"?P.createdFromBranch:"");if(Ze)return Ze;const dt=qe(typeof X=="string"?X:"");return dt||(In.includes("main")?"main":In.includes("master")?"master":In.includes("develop")?"develop":"main")},[pn,In,X,P?.createdFromBranch]),Nn=o.useMemo(()=>pn.map(Ze=>Ze.name).map(Ze=>`${Ze}/${yn}`).find(Ze=>cn.includes(Ze))??yn,[yn,pn,cn]),wr=o.useMemo(()=>{const Fe=new Map;x&&Fe.set(x.id,x);let qe=null;if(jt)try{let Ze=jt.trim();Ze.startsWith("git@")&&(Ze=`https://${Ze.slice(4).replace(":","/")}`),Ze.endsWith(".git")&&(Ze=Ze.slice(0,-4));const dt=new URL(Ze);qe=dt.hostname+dt.pathname}catch{}for(const Ze of v){if(Ze.authType!=="token"){Fe.set(Ze.id,Ze);continue}const dt=Ze.host;if(!dt){Fe.set(Ze.id,Ze);continue}if(!dt.includes("/")){Fe.set(Ze.id,Ze);continue}qe&&qe===dt&&Fe.set(Ze.id,Ze)}return Array.from(Fe.values())},[v,x,jt]),vn=o.useMemo(()=>{if(E?.userName&&E?.userEmail){const Fe=v.find(qe=>qe.userName===E.userName&&qe.userEmail===E.userEmail);return Fe||(x&&x.userName===E.userName&&x.userEmail===E.userEmail?x:{id:"local-config",name:E.userName,userName:E.userName,userEmail:E.userEmail,sshKey:E.sshCommand?.replace("ssh -i ","")??null,color:"info",icon:"user"})}return x??null},[E,v,x]),Ur=Gt.length,lr=M||R!==null||Oe!==null,zn=w?.current??null,Ya=!!(P&&es&&Vt&&Jt),xa=!!(n&&zn),ba=!!zn,dn=Ya&&es&&Vt&&P?{repoRoot:es,sourceBranch:Vt,worktreeMetadata:P}:null,jr=o.useMemo(()=>!xa||!n||!zn?null:{directory:n,branch:zn},[xa,zn,n]);o.useEffect(()=>{if(!n||!e||!N?.all?.length||!zn||!yn||zn===yn){Ht(null);return}let Fe=!1;return(async()=>{try{const Ze=await e.getGitLog(n,{from:yn,to:"HEAD",maxCount:z});if(Fe)return;const dt=new Set((Ze?.all??[]).map(zt=>zt.hash).filter(zt=>typeof zt=="string"&&zt.length>0));if(dt.size===0){Ht(null);return}const Ft=N.all.findIndex(zt=>!dt.has(zt.hash));if(Ft===0){Ht(null);return}if(Ft===-1){Ht({insertBeforeIndex:N.all.length,branchName:zn,direction:"up"});return}Ht({insertBeforeIndex:Ft,branchName:zn,direction:"up"})}catch{Fe||Ht(null)}})(),()=>{Fe=!0}},[yn,zn,n,e,N,z]);const un=o.useCallback((Fe,qe)=>{if(!n||Fe.length===0)return;const Ze=Array.from(new Set(Fe));Le(Ft=>{const zt=new Set(Ft);return Ze.forEach(Vs=>zt.add(Vs)),zt});const dt=ae(n,Ze,qe);pe.enqueue({directory:n,direction:qe,paths:new Set(Ze),rollback:()=>re(n,dt)}),xe()},[n,pe,ae,re,xe]),cr=o.useCallback(async Fe=>{if(n){ce(qe=>{const Ze=new Set(qe);return Ze.add(Fe),Ze});try{await e.revertGitFile(n,Fe,{scope:"working"}),G.success(t("gitView.toast.revertedFile",{path:Fe})),await Ls(!1)}catch(qe){const Ze=qe instanceof Error?qe.message:t("gitView.toast.revertFailed");G.error(Ze)}finally{ce(qe=>{const Ze=new Set(qe);return Ze.delete(Fe),Ze})}}},[n,Ls,e,t]),Hr=o.useCallback(async Fe=>{if(!n||Fe.length===0||Ge)return;const qe=Array.from(new Set(Fe)),Ze=new Set(Gt.map(zt=>zt.path)),dt=qe.some(zt=>Ze.has(zt));at(!0),ce(zt=>{const Vs=new Set(zt);return qe.forEach(Fs=>Vs.add(Fs)),Vs});const Ft=[];try{if(await Promise.all(qe.map(async zt=>{try{await e.revertGitFile(n,zt)}catch(Vs){Ft.push({path:zt,message:Vs instanceof Error?Vs.message:t("gitView.toast.revertFailed")})}})),dt&&Ft.length<qe.length&&me(n),await Ls(!1),Ft.length===0)G.success(qe.length===1?t("gitView.toast.revertedFilesSingle",{count:qe.length}):t("gitView.toast.revertedFilesPlural",{count:qe.length}));else if(Ft.length===qe.length)G.error(Ft[0]?.message||t("gitView.toast.revertFailed"));else{const zt=qe.length-Ft.length;G.warning(zt===1?t("gitView.toast.revertedSomeSingle",{success:zt,failed:Ft.length}):t("gitView.toast.revertedSomePlural",{success:zt,failed:Ft.length}))}}finally{ce(zt=>{const Vs=new Set(zt);return qe.forEach(Fs=>Vs.delete(Fs)),Vs}),at(!1)}},[me,n,e,Ge,Ls,Gt,t]),ia=o.useCallback((Fe,qe)=>{if(n&&!fe){H(n,Fe,qe);return}K(Fe,qe),fe&&Q(!1)},[n,fe,K,H,Q]),Nr=o.useCallback(()=>Me(!0),[]),Qa=o.useMemo(()=>{const Fe=[];return Gt.length>0&&Fe.push({id:"staged",title:t("gitView.changes.stagedTitle"),entries:Gt,actionSymbol:"-",actionAllLabel:t("gitView.changes.unstageAllAria"),getActionLabel:qe=>t("gitView.changes.unstageFileAria",{path:qe}),onActionFile:qe=>{un([qe],"unstage")},onActionAll:qe=>{un(qe,"unstage")},onViewDiff:qe=>ia(qe,!0),onRevertFile:cr,showRevertActions:!1,accent:!0}),as.length>0&&Fe.push({id:"unstaged",title:t("gitView.changes.title"),entries:as,actionSymbol:"+",actionAllLabel:t("gitView.changes.stageAllAria"),getActionLabel:qe=>t("gitView.changes.stageFileAria",{path:qe}),onActionFile:qe=>{un([qe],"stage")},onActionAll:qe=>{un(qe,"stage")},onViewDiff:qe=>ia(qe,!1),onRevertFile:cr}),Fe},[cr,ia,un,Gt,t,as]),wn=o.useCallback(Fe=>{if(Fe.length===0)return;const qe=Fe.map(Ze=>Ze.trim()).filter(Boolean);if(qe.length===0){Lt();return}oe(Ze=>{const dt=Ze.trim(),Ft=dt.length>0?`
|
|
43
|
-
|
|
44
|
-
`:"";return`${dt}${Ft}${qe.join(`
|
|
45
|
-
`)}`.trim()}),Lt()},[Lt]),Ii=o.useCallback((Fe,qe)=>{const Ze=qe||Fe;oe(dt=>{const Ft=dt.trimStart();return Ft.startsWith(Fe)||qe&&Ft.startsWith(qe)?dt:`${Ze.endsWith(" ")?Ze:`${Ze} `}${dt}`.trimStart()}),zs(""),je(!1)},[]),No=o.useCallback(Fe=>{De(Fe),n&&(Z(n,Fe),q(n,e,Fe))},[n,Z,q,e]),oa=o.useCallback(Fe=>{const qe=Fe instanceof Error?Fe.message.toLowerCase():"";return qe.includes("uncommitted changes")||qe.includes("local changes")||qe.includes("your local changes would be overwritten")||qe.includes("please commit your changes or stash them")||qe.includes("cannot rebase: you have unstaged changes")||qe.includes("error: cannot pull with rebase")},[]),dr=o.useCallback((Fe,qe)=>{xt(Ze=>[...Ze,{message:Fe,status:qe,timestamp:Date.now()}])},[]),Dn=o.useCallback((Fe,qe)=>{xt(Ze=>{if(Ze.length===0)return Ze;const dt=[...Ze];return dt[dt.length-1]={...dt[dt.length-1],status:Fe,...qe?{message:qe}:{}},dt})},[]),Er=o.useCallback(()=>{xt([])},[]),Ja=o.useCallback(()=>{xt([]),cs(null)},[]),Gr=o.useCallback(Fe=>{const qe=Fe.trim(),Ze=new Set(pn.map(Ft=>Ft.name)),dt=qe.indexOf("/");if(dt>0){const Ft=qe.slice(0,dt),zt=qe.slice(dt+1);if(Ze.has(Ft)&&zt)return{branch:qe,remote:Ft,remoteBranch:zt}}for(const Ft of pn){const zt=`${Ft.name}/${qe}`;if(cn.includes(zt))return{branch:zt,remote:Ft.name,remoteBranch:qe}}return{branch:qe,remote:null,remoteBranch:null}},[pn,cn]),Xa=o.useCallback(async Fe=>{if(!n)return;cs("merge"),Er();const qe=w?.current,Ze=Gr(Fe);try{Ze.remote&&Ze.remoteBranch&&(dr(`Fetching ${Ze.remote}/${Ze.remoteBranch}...`,"running"),await e.gitFetch(n,{remote:Ze.remote,branch:Ze.remoteBranch}),Dn("done",`Fetched ${Ze.remote}/${Ze.remoteBranch}`)),dr(`Merging ${Ze.branch} into ${qe}...`,"running");const dt=await e.merge(n,{branch:Ze.branch});dt.conflict?(Dn("error","Merge conflicts detected"),Rt(dt.conflictFiles??[]),Ts("merge"),Et(!0),Bs(n,dt.conflictFiles??[],"merge")):(Dn("done",`Merged ${Ze.branch} into ${qe}`),ys(),dr("Refreshing repository status...","running"),await Ls(),await Rs(),Dn("done","Repository status updated"))}catch(dt){if(oa(dt))Dn("error","Uncommitted changes detected"),ar("merge"),bn(Ze.branch),xn(!0);else{const Ft=dt instanceof Error?dt.message:`Failed to merge ${Ze.branch}`;Dn("error",Ft)}}},[n,e,w,Gr,Ls,Rs,oa,Bs,ys,dr,Dn,Er]),Tn=o.useCallback(async Fe=>{if(!n)return;cs("rebase"),Er();const qe=w?.current,Ze=Gr(Fe);try{Ze.remote&&Ze.remoteBranch&&(dr(`Fetching ${Ze.remote}/${Ze.remoteBranch}...`,"running"),await e.gitFetch(n,{remote:Ze.remote,branch:Ze.remoteBranch}),Dn("done",`Fetched ${Ze.remote}/${Ze.remoteBranch}`)),dr(`Rebasing ${qe} onto ${Ze.branch}...`,"running");const dt=await e.rebase(n,{onto:Ze.branch});dt.conflict?(Dn("error","Rebase conflicts detected"),Rt(dt.conflictFiles??[]),Ts("rebase"),Et(!0),Bs(n,dt.conflictFiles??[],"rebase")):(Dn("done",`Rebased ${qe} onto ${Ze.branch}`),ys(),dr("Refreshing repository status...","running"),await Ls(),await Rs(),Dn("done","Repository status updated"))}catch(dt){if(oa(dt))Dn("error","Uncommitted changes detected"),ar("rebase"),bn(Ze.branch),xn(!0);else{const Ft=dt instanceof Error?dt.message:`Failed to rebase onto ${Ze.branch}`;Dn("error",Ft)}}},[n,e,w,Gr,Ls,Rs,oa,Bs,ys,dr,Dn,Er]),Rr=o.useCallback(async()=>{if(n)try{Os==="merge"?(await e.abortMerge(n),G.success(t("gitView.toast.mergeAborted"))):(await e.abortRebase(n),G.success(t("gitView.toast.rebaseAborted"))),ys(),await Ls(),await Rs()}catch(Fe){const qe=Fe instanceof Error?Fe.message:`Failed to abort ${Os}`;G.error(qe)}},[n,e,Os,Ls,Rs,ys,t]),qr=o.useMemo(()=>w?.files?w.files.some(Fe=>Fe.index==="U"||Fe.working_dir==="U"||Fe.index==="A"&&Fe.working_dir==="A"||Fe.index==="D"&&Fe.working_dir==="D"):!1,[w?.files]),Ys=o.useCallback(async()=>{if(n)try{const Fe=!!w?.mergeInProgress?.head,qe=!!(w?.rebaseInProgress?.headName||w?.rebaseInProgress?.onto);if(Fe){const Ze=await e.continueMerge(n);Ze.conflict?(Rt(Ze.conflictFiles??[]),Ts("merge"),Et(!0),Bs(n,Ze.conflictFiles??[],"merge"),G.error(t("gitView.toast.mergeConflictsDetected"))):(ys(),G.success(t("gitView.toast.mergeCompleted")),await Ls(),await Rs())}else if(qe){const Ze=await e.continueRebase(n);Ze.conflict?(Rt(Ze.conflictFiles??[]),Ts("rebase"),Et(!0),Bs(n,Ze.conflictFiles??[],"rebase"),G.error(t("gitView.toast.rebaseConflictsDetected"))):(ys(),G.success(t("gitView.toast.rebaseStepCompleted")),await Ls(),await Rs())}}catch(Fe){const qe=Fe instanceof Error?Fe.message:t("gitView.toast.continueOperationFailed");G.error(qe)}},[n,e,w,Ls,Rs,Bs,ys,t]),Fr=o.useCallback(async()=>{if(n)try{!!w?.mergeInProgress?.head?(await e.abortMerge(n),G.success(t("gitView.toast.mergeAborted"))):(await e.abortRebase(n),G.success(t("gitView.toast.rebaseAborted"))),ys(),await Ls(),await Rs()}catch(Fe){const qe=Fe instanceof Error?Fe.message:t("gitView.toast.abortOperationFailed");G.error(qe)}},[n,e,w,Ls,Rs,ys,t]),ya=o.useCallback(()=>{if(!n)return;const qe=!!w?.mergeInProgress?.head?"merge":"rebase",Ze=w?.files?.filter(dt=>dt.index==="U"||dt.working_dir==="U").map(dt=>dt.path)??[];Ze.length>0&&Rt(Ze),Ts(qe),Et(!0)},[n,w]),Pi=o.useCallback(async Fe=>{if(!n)return;const qe=w?.current,Ze=ln,dt=Us,Ft=(w?.files??[]).some($m);try{await e.stash(n,{message:`Auto-stash before ${Ze} with ${dt}`,includeUntracked:!0}),Ft&&me(n)}catch(Fs){const Pn=Fs instanceof Error?Fs.message:"Failed to stash changes";G.error(Pn);return}let zt=!1,Vs=!1;try{if(Ze==="merge"){const Fs=await e.merge(n,{branch:dt});Fs.conflict?(Vs=!0,Rt(Fs.conflictFiles??[]),Ts("merge"),Et(!0)):(zt=!0,G.success(t("gitView.toast.mergedIntoBranch",{branch:dt,currentBranch:qe||""})))}else{const Fs=await e.rebase(n,{onto:dt});Fs.conflict?(Vs=!0,Rt(Fs.conflictFiles??[]),Ts("rebase"),Et(!0)):(zt=!0,G.success(t("gitView.toast.rebasedOntoBranch",{currentBranch:qe||"",branch:dt})))}if(Fe&&zt)try{await e.stashPop(n),me(n),G.success(t("gitView.toast.stashedRestored"))}catch(Fs){const Pn=Fs instanceof Error?Fs.message:t("gitView.toast.restoreStashFailed");G.error(Pn)}else Fe&&Vs&&G.info(t("gitView.toast.restoreStashManually"));await Ls(),await Rs()}catch(Fs){if(Fe)try{await e.stashPop(n),me(n)}catch{}throw Fs}},[me,n,e,w,ln,Us,Ls,Rs,t]);return n?M&&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(D,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"typography-ui-label",children:t("gitView.loading.checkingRepository")})]})}):k===!1?Ie?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-4 text-center",children:[s.jsx(D,{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(D,{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(nj,{status:w,localBranches:In,remoteBranches:cn,branchInfo:A?.branches,syncAction:R,remotes:pn,onFetch:Fe=>_s("fetch",Fe),onSync:Fe=>_s("sync",Fe),onRemoveRemote:qs,removingRemoteName:_t,onCheckoutBranch:Kr,onCreateBranch:or,onRenameBranch:tr,activeIdentityProfile:vn,availableIdentities:wr,onSelectIdentity:zr,isApplyingIdentity:Xe,isWorktreeMode:!!P,onOpenHistory:()=>gn(!0),onOpenStashes:Nr,actionTabItems:rn,activeActionTab:Wt,onSelectActionTab:Fe=>Kt(Fe)}),n&&(w?.mergeInProgress?.head||w?.rebaseInProgress?.headName||w?.rebaseInProgress?.onto)&&s.jsx(B0,{mergeInProgress:w?.mergeInProgress,rebaseInProgress:w?.rebaseInProgress,onContinue:Ys,onAbort:Fr,onResolveWithAI:ya,hasUnresolvedConflicts:qr,isLoading:M}),s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:s.jsx("div",{className:"h-full min-h-0 flex flex-col",children:s.jsx("div",{className:ye("min-w-0 min-h-0 h-full flex flex-col","bg-sidebar"),children:s.jsxs(ws,{as:go,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:(Dt?.length??0)>0?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:s.jsx(fj,{groups:Qa,diffStats:w?.diffStats,revertingPaths:Je,isRevertingAll:Ge,onVisiblePathsChange:Te,onRevertAll:Hr})}),s.jsx(yj,{stagedCount:Ur,commitMessage:Ne,onCommitMessageChange:oe,generatedHighlights:Pt,onInsertHighlights:wn,onGenerateMessage:Zs,isGeneratingMessage:et,onCommit:()=>Ws({pushAfter:!1}),onCommitAndPush:()=>Ws({pushAfter:!0}),commitAction:Oe,hasPendingIndexMutation:ht,gitmojiEnabled:Ce,onOpenGitmojiPicker:()=>je(!0)})]}):s.jsx(vj,{onOpenStashes:()=>Me(!0)})}):null,Wt==="branch"?s.jsx("div",{className:"space-y-4",children:ba?s.jsxs(s.Fragment,{children:[s.jsx(V0,{mode:"inline",currentBranch:w?.current,localBranches:In,remoteBranches:cn,defaultTargetBranch:Nn,onMerge:Xa,onRebase:Tn,disabled:lr,isOperating:ss!==null,operationLogs:Ke,onOperationComplete:Ja}),dn?s.jsx(Yw,{repoRoot:dn.repoRoot,sourceBranch:dn.sourceBranch,worktreeMetadata:dn.worktreeMetadata,localBranches:In,defaultTargetBranch:mt,refreshKey:He,onRefresh:()=>{n&&(F(n,e),_(n,e),q(n,e,z))}},dn.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:jr?s.jsx(T0,{directory:jr.directory,branch:jr.branch,baseBranch:yn,trackingBranch:w?.tracking??void 0,remotes:se,remoteBranches:cn,onGeneratedDescription:wt}):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(ps,{open:$s,onOpenChange:gn,children:s.jsxs(ms,{className:"max-w-5xl h-[90vh] max-h-[90vh] flex flex-col overflow-hidden",children:[s.jsxs(gs,{children:[s.jsx(fs,{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(t0,{log:N,isLogLoading:O,logMaxCount:z,onLogMaxCountChange:No,expandedCommitHashes:ts,onToggleCommit:Vn,commitFilesMap:ds,loadingCommitHashes:Ut,onCopyHash:ir,directory:n??void 0,showHeader:!1,contentMaxHeightClassName:"h-full max-h-none",branchDivider:At})})]})}),s.jsx(rj,{open:le,onOpenChange:Me,directory:n,hasUncommittedChanges:(w?.files?.length??0)>0,hasStagedChanges:Gt.length>0,uncommittedFileCount:w?.files?.length??0,onChanged:async Fe=>{n&&Fe?.affectsIndex&&me(n),await Ls(!1),await Rs()}}),s.jsx(ps,{open:Be,onOpenChange:je,children:s.jsxs(ms,{className:"max-w-md p-0 overflow-hidden",children:[s.jsx(gs,{className:"px-4 pt-4",children:s.jsx(fs,{children:t("gitView.gitmoji.title")})}),s.jsxs(Wa,{className:"h-[420px]",children:[s.jsx(ga,{placeholder:t("gitView.gitmoji.searchPlaceholder"),value:ns,onValueChange:zs}),s.jsxs(Ka,{children:[s.jsx(Ha,{children:t("gitView.gitmoji.empty")}),s.jsx(Ln,{children:(rs.length===0?[]:rs.filter(Fe=>{const qe=ns.trim().toLowerCase();return qe?Fe.emoji.includes(qe)||Fe.code.toLowerCase().includes(qe)||Fe.description.toLowerCase().includes(qe):!0})).map(Fe=>s.jsxs(An,{onSelect:()=>Ii(Fe.emoji,Fe.code),children:[s.jsx("span",{className:"text-lg",children:Fe.emoji}),s.jsx("span",{className:"typography-ui-label text-foreground",children:Fe.code}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:Fe.description})]},Fe.code))})]})]})]})}),n&&s.jsx(M0,{open:Tt,onOpenChange:Et,conflictFiles:Qt,directory:n,operation:Os,onAbort:Rr,onClearState:ys}),s.jsx(_0,{open:Gn,onOpenChange:xn,operation:ln,targetBranch:Us,onConfirm:Pi})]}):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")})})},aN=Object.freeze(Object.defineProperty({__proto__:null,GitView:Yh},Symbol.toStringTag,{value:"Module"})),pd=5e3,iN=(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},oN=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"},lN=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()},Zd=async(t,e)=>{try{const n=await lN(t,e);return iN(n,pd)>pd?{ok:!1,reason:"too-large"}:{ok:!0}}catch(n){return{ok:!1,reason:oN(n)}}},eu=t=>t==="too-large"?`File is too large to open (>${pd.toLocaleString()} lines)`:t==="missing"?"File not found":"Failed to open file",cN=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},Qh=(t,e)=>{const n=Kn(e),r=Kn(t).replace(/\/+$/,"");return n===r?".":!r||!n.startsWith(`${r}/`)?n:n.slice(r.length+1)},dN=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),uN=new Set(["node_modules"]),mN=t=>uN.has(t),pN=t=>{const e=Kn(t);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},Jh=(t,e)=>s.jsx(Pr,{filePath:t,extension:e}),fN=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},hN=t=>{const e=ot.c(63),{node:n,root:r,isExpanded:a,isActive:i,status:l,badge:c,permissions:d,downloadFile:p,contextMenuPath:m,setContextMenuPath:u,onSelect:f,onToggle:b,onRevealPath:g,onOpenDialog:v}=t,{t:x}=ut(),h=n.type==="directory",{canRename:j,canCreateFile:y,canCreateFolder:C,canDelete:k,canReveal:w}=d;let S;e[0]!==y||e[1]!==C||e[2]!==k||e[3]!==j||e[4]!==w||e[5]!==n.path||e[6]!==u?(S=Z=>{!j&&!y&&!C&&!k&&!w||(Z?.preventDefault(),u(n.path))},e[0]=y,e[1]=C,e[2]=k,e[3]=j,e[4]=w,e[5]=n.path,e[6]=u,e[7]=S):S=e[7];const I=S;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 A;e[13]!==n.path||e[14]!==u?(A=Z=>{Z.stopPropagation(),u(n.path)},e[13]=n.path,e[14]=u,e[15]=A):A=e[15];const N=A;let E;e[16]!==n.path||e[17]!==r?(E=Z=>{const ae=Qh(r,n.path);!ae||ae==="."||(Z.dataTransfer.setData("application/x-openchamber-file-path",ae),Z.dataTransfer.effectAllowed="copy")},e[16]=n.path,e[17]=r,e[18]=E):E=e[18];const M=E,O=i?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let V;e[19]!==O?(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",O,"cursor-grab active:cursor-grabbing"),e[19]=O,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(D,{name:"folder-open-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):s.jsx(D,{name:"folder-3-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):Jh(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 F;e[29]!==h||e[30]!==l?(F=!h&&l&&s.jsx(fN,{status:l}),e[29]=h,e[30]=l,e[31]=F):F=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]!==M||e[37]!==P||e[38]!==_||e[39]!==V||e[40]!==B||e[41]!==$||e[42]!==F?(q=s.jsxs("button",{type:"button",onClick:P,onContextMenu:I,draggable:!0,onDragStart:M,className:V,children:[B,$,F,_]}),e[35]=I,e[36]=M,e[37]=P,e[38]=_,e[39]=V,e[40]=B,e[41]=$,e[42]=F,e[43]=q):q=e[43];let L;e[44]!==y||e[45]!==C||e[46]!==k||e[47]!==j||e[48]!==w||e[49]!==m||e[50]!==p||e[51]!==N||e[52]!==h||e[53]!==n||e[54]!==v||e[55]!==g||e[56]!==u||e[57]!==x?(L=(j||y||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(ve,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:N,title:x("sidebarFilesTree.actions.fileMenuTitle"),"aria-label":x("sidebarFilesTree.actions.fileMenuTitle"),children:s.jsx(D,{name:"more-2-fill",className:"h-4 w-4"})})})})}),s.jsx(It,{side:"bottom",sideOffset:6,children:x("sidebarFilesTree.actions.fileMenuTitle")})]}),s.jsxs(Ps,{align:"end",side:"bottom",onCloseAutoFocus:()=>u(null),children:[j&&s.jsxs(Ot,{onClick:Z=>{Z.stopPropagation(),v("rename",n)},children:[s.jsx(D,{name:"edit",className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.rename")]}),s.jsxs(Ot,{onClick:Z=>{Z.stopPropagation(),Rn(n.path).then(ae=>{if(ae.ok){G.success(x("sidebarFilesTree.toast.pathCopied"));return}G.error(x("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(D,{name:"file-copy",className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.copyPath")]}),!h&&p&&s.jsxs(Ot,{onClick:Z=>{Z.stopPropagation(),p(n.path)},children:[s.jsx(D,{name:"download",className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.save")]}),w&&s.jsxs(Ot,{onClick:Z=>{Z.stopPropagation(),g(n.path)},children:[s.jsx(D,{name:"folder-received",className:"mr-2 h-4 w-4"})," ",x(Bd())]}),h&&(y||C)&&s.jsxs(s.Fragment,{children:[s.jsx(Xn,{}),y&&s.jsxs(Ot,{onClick:Z=>{Z.stopPropagation(),v("createFile",n)},children:[s.jsx(D,{name:"file-add",className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.newFile")]}),C&&s.jsxs(Ot,{onClick:Z=>{Z.stopPropagation(),v("createFolder",n)},children:[s.jsx(D,{name:"folder-add",className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.newFolder")]})]}),k&&s.jsxs(s.Fragment,{children:[s.jsx(Xn,{}),s.jsxs(Ot,{onClick:Z=>{Z.stopPropagation(),v("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(D,{name:"delete-bin",className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.delete")]})]})]})]})}),e[44]=y,e[45]=C,e[46]=k,e[47]=j,e[48]=w,e[49]=m,e[50]=p,e[51]=N,e[52]=h,e[53]=n,e[54]=v,e[55]=g,e[56]=u,e[57]=x,e[58]=L):L=e[58];let Y;return e[59]!==I||e[60]!==q||e[61]!==L?(Y=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]=Y):Y=e[62],Y},gN=()=>{const t=ot.c(250),{t:e}=ut(),{files:n,runtime:r}=Bn(),a=ra()??"";let i;t[0]!==a?(i=Kn(a.trim()),t[0]=a,t[1]=i):i=t[1];const l=i,c=_l(),d=$d(),p=_d(xN),m=Re(bN),u=$l(a),[f,b]=o.useState(""),g=Bl(f,200),v=o.useRef(null);let x;t[2]===Symbol.for("react.memo_cache_sentinel")?(x=[],t[2]=x):x=t[2];const[h,j]=o.useState(x),[y,C]=o.useState(!1);let k;t[3]===Symbol.for("react.memo_cache_sentinel")?(k={},t[3]=k):k=t[3];const[w,S]=o.useState(k);let I;t[4]===Symbol.for("react.memo_cache_sentinel")?(I=new Set,t[4]=I):I=t[4];const T=o.useRef(I);let P;t[5]===Symbol.for("react.memo_cache_sentinel")?(P=new Set,t[5]=P):P=t[5];const A=o.useRef(P);let N;t[6]===Symbol.for("react.memo_cache_sentinel")?(N=[],t[6]=N):N=t[6];const E=N;let M;t[7]===Symbol.for("react.memo_cache_sentinel")?(M=[],t[7]=M):M=t[7];const O=M;let V;t[8]!==l?(V=Wt=>l?Wt.byRoot[l]?.expandedPaths??E:E,t[8]=l,t[9]=V):V=t[9];const B=On(V);let $;t[10]!==l?($=Wt=>l?Wt.byRoot[l]?.selectedPath??null:null,t[10]=l,t[11]=$):$=t[11];const F=On($),_=On(yN),q=On(vN),L=On(wN),Y=On(jN);let Z;t[12]!==l?(Z=Wt=>l?Wt.contextPanelByDirectory[l]?.tabs??O:O,t[12]=l,t[13]=Z):Z=t[13];const ae=Re(Z);let re;t[14]!==ae?(re=new Set(ae.map(NN).filter(SN).map(kN)),t[14]=ae,t[15]=re):re=t[15];const me=re,[fe,H]=o.useState(null),[K,Q]=o.useState(null),[W,de]=o.useState(null),[be,we]=o.useState(""),[te,ge]=o.useState(!1),ue=!!n.writeFile,xe=!!n.createDirectory,ne=!!n.rename,pe=!!n.delete,J=!!n.revealPath;let Se;t[16]!==ue||t[17]!==xe||t[18]!==pe||t[19]!==ne||t[20]!==J?(Se={canRename:ne,canCreateFile:ue,canCreateFolder:xe,canDelete:pe,canReveal:J},t[16]=ue,t[17]=xe,t[18]=pe,t[19]=ne,t[20]=J,t[21]=Se):Se=t[21];const he=Se;let Ie;t[22]!==n||t[23]!==e?(Ie=Wt=>{n.revealPath&&n.revealPath(Wt).catch(()=>{G.error(e("sidebarFilesTree.toast.revealFailed"))})},t[22]=n,t[23]=e,t[24]=Ie):Ie=t[24];const Pe=Ie;let Ce;t[25]===Symbol.for("react.memo_cache_sentinel")?(Ce=(Wt,Kt)=>{Q(Wt),de(Kt),we(Wt==="rename"&&Kt.name||""),ge(!1)},t[25]=Ce):Ce=t[25];const X=Ce;let ie;t[26]!==d||t[27]!==c?(ie=(Wt,Kt)=>{const se=Kt.filter(CN).filter(bt=>c||!bt.name.startsWith(".")).filter(bt=>d||!mN(bt.name)).map(bt=>{const _t=bt.name,lt=Kn(bt.path||""),ss=lt?dN(lt)?lt:Kn(`${Wt}/${lt}`):Kn(`${Wt}/${_t}`),cs=bt.isDirectory?"directory":"file",Ke=cs==="file"&&_t.includes(".")?_t.split(".").pop()?.toLowerCase():void 0;return{name:_t,path:ss,type:cs,extension:Ke}});return cN(se)},t[26]=d,t[27]=c,t[28]=ie):ie=t[28];const Ne=ie;let oe;t[29]!==n||t[30]!==Ne||t[31]!==r.isDesktop||t[32]!==d?(oe=async Wt=>{const Kt=Kn(Wt.trim());if(!Kt||T.current.has(Kt)||A.current.has(Kt))return;A.current=new Set(A.current),A.current.add(Kt);const se=!d;await(r.isDesktop?n.listDirectory(Kt,{respectGitignore:se}).then(PN):nn.listLocalDirectory(Kt,{respectGitignore:se}).then(DN)).then(_t=>{const lt=Ne(Kt,_t);T.current=new Set(T.current),T.current.add(Kt),S(ss=>({...ss,[Kt]:lt}))}).catch(()=>{S(_t=>({..._t,[Kt]:_t[Kt]??[]}))}).finally(()=>{A.current=new Set(A.current),A.current.delete(Kt)})},t[29]=n,t[30]=Ne,t[31]=r.isDesktop,t[32]=d,t[33]=oe):oe=t[33];const ke=oe;let Te;t[34]!==ke||t[35]!==l?(Te=async()=>{l&&(T.current=new Set,A.current=new Set,S(TN),await ke(l))},t[34]=ke,t[35]=l,t[36]=Te):Te=t[36];const Be=Te;let je;t[37]!==ke||t[38]!==Be?(je=async Wt=>{if(!Wt){await Be();return}const Kt=Kn(Wt);T.current=new Set(T.current),T.current.delete(Kt),A.current=new Set(A.current),A.current.delete(Kt),await ke(Kt)},t[37]=ke,t[38]=Be,t[39]=je):je=t[39];const ee=je;let R;t[40]!==ke||t[41]!==l?(R=()=>{l&&(T.current=new Set,A.current=new Set,S(MN),ke(l))},t[40]=ke,t[41]=l,t[42]=R):R=t[42];let U;t[43]!==ke||t[44]!==l||t[45]!==d||t[46]!==c?(U=[ke,l,c,d],t[43]=ke,t[44]=l,t[45]=d,t[46]=c,t[47]=U):U=t[47],o.useEffect(R,U);let le,Me;t[48]!==B||t[49]!==ke||t[50]!==l?(le=()=>{if(!l||B.length===0)return;const Wt=B.map(EN).filter(se=>!!se&&se!==l&&se.startsWith(`${l}/`)&&!T.current.has(se)&&!A.current.has(se)).sort(RN);if(Wt.length===0)return;let Kt=!1;return(async()=>{for(let se=0;se<Wt.length&&!Kt;se=se+3,se){const bt=Wt.slice(se,se+3);await Promise.all(bt.map(_t=>ke(_t)))}})(),()=>{Kt=!0}},Me=[B,ke,l],t[48]=B,t[49]=ke,t[50]=l,t[51]=le,t[52]=Me):(le=t[51],Me=t[52]),o.useEffect(le,Me);let Oe,Ae;t[53]!==a||t[54]!==g||t[55]!==p||t[56]!==d||t[57]!==c?(Oe=()=>{if(!a){j([]),C(!1);return}const Wt=g.trim();if(!Wt){j([]),C(!1);return}let Kt=!1;return C(!0),p(a,Wt,150,{includeHidden:c,respectGitignore:!d,type:"file"}).then(se=>{if(Kt)return;const _t=se.filter(lt=>d||!pN(lt.path)).map(FN);j(_t)}).catch(()=>{Kt||j([])}).finally(()=>{Kt||C(!1)}),()=>{Kt=!0}},Ae=[a,g,p,c,d],t[53]=a,t[54]=g,t[55]=p,t[56]=d,t[57]=c,t[58]=Oe,t[59]=Ae):(Oe=t[58],Ae=t[59]),o.useEffect(Oe,Ae);let z;t[60]!==u||t[61]!==me||t[62]!==l?(z=Wt=>{if(me.has(Wt))return"open";if(u?.files){const Kt=Wt.startsWith(l+"/")?Wt.slice(l.length+1):Wt,se=u.files.find(bt=>bt.path===Kt);if(se){if(se.index==="A"||se.working_dir==="?")return"git-added";if(se.index==="D")return"git-deleted";if(se.index==="M"||se.working_dir==="M")return"git-modified"}}return null},t[60]=u,t[61]=me,t[62]=l,t[63]=z):z=t[63];const De=z;let Xe;t[64]!==u||t[65]!==l?(Xe=Wt=>{if(!u?.files)return null;const Kt=Wt.startsWith(l+"/")?Wt.slice(l.length+1):Wt,se=Kt?`${Kt}/`:"";let bt=0,_t=0;for(const lt of u.files)lt.path.startsWith(se)&&((lt.index==="M"||lt.working_dir==="M")&&bt++,(lt.index==="A"||lt.working_dir==="?")&&_t++);return bt+_t>0?{modified:bt,added:_t}:null},t[64]=u,t[65]=l,t[66]=Xe):Xe=t[66];const st=Xe;let tt;t[67]!==q||t[68]!==n||t[69]!==m||t[70]!==l||t[71]!==_?(tt=async Wt=>{if(!l)return;const Kt=await Zd(n,Wt.path);if(!Kt.ok){G.error(eu(Kt.reason));return}_(l,Wt.path),q(l,Wt.path),m(l,Wt.path)},t[67]=q,t[68]=n,t[69]=m,t[70]=l,t[71]=_,t[72]=tt):tt=t[72];const Ue=tt;let it;t[73]!==ke||t[74]!==l||t[75]!==Y?(it=async Wt=>{const Kt=Kn(Wt);l&&(Y(l,Kt),T.current.has(Kt)||await ke(Kt))},t[73]=ke,t[74]=l,t[75]=Y,t[76]=it):it=t[76];const Ye=it;let rt;t[77]!==K||t[78]!==W||t[79]!==be||t[80]!==n||t[81]!==ee||t[82]!==L||t[83]!==l||t[84]!==F||t[85]!==_||t[86]!==e?(rt=async Wt=>{if(Wt?.preventDefault(),!W||!K)return;ge(!0);const Kt=()=>ge(!1),se=()=>Q(null);if(K==="createFile"){if(!be.trim()){G.error(e("sidebarFilesTree.toast.filenameRequired")),Kt();return}if(!n.writeFile){G.error(e("sidebarFilesTree.toast.writeNotSupported")),Kt();return}const bt=W.path,_t=bt?`${bt}/`:"",lt=Kn(`${_t}${be.trim()}`);await n.writeFile(lt,"").then(async ss=>{ss.success&&(G.success(e("sidebarFilesTree.toast.fileCreated")),await ee(bt)),se()}).catch(()=>G.error(e("sidebarFilesTree.toast.operationFailed"))).finally(Kt);return}if(K==="createFolder"){if(!be.trim()){G.error(e("sidebarFilesTree.toast.folderNameRequired")),Kt();return}const bt=W.path,_t=bt?`${bt}/`:"",lt=Kn(`${_t}${be.trim()}`);await n.createDirectory(lt).then(async ss=>{ss.success&&(G.success(e("sidebarFilesTree.toast.folderCreated")),await ee(bt)),se()}).catch(()=>G.error(e("sidebarFilesTree.toast.operationFailed"))).finally(Kt);return}if(K==="rename"){if(!be.trim()){G.error(e("sidebarFilesTree.toast.nameRequired")),Kt();return}if(!n.rename){G.error(e("sidebarFilesTree.toast.renameNotSupported")),Kt();return}const bt=W.path,_t=bt.split("/").slice(0,-1).join("/"),lt=_t?`${_t}/`:"",ss=Kn(`${lt}${be.trim()}`);await n.rename(bt,ss).then(async cs=>{cs.success&&(G.success(e("sidebarFilesTree.toast.renamedSuccessfully")),await ee(_t),l&&L(l,bt),(F===bt||F&&F.startsWith(`${bt}/`))&&_(l,null)),se()}).catch(()=>G.error(e("sidebarFilesTree.toast.operationFailed"))).finally(Kt);return}if(K==="delete"){if(!n.delete){G.error(e("sidebarFilesTree.toast.deleteNotSupported")),Kt();return}const bt=W.path,_t=bt.split("/").slice(0,-1).join("/");await n.delete(bt).then(async lt=>{lt.success&&(G.success(e("sidebarFilesTree.toast.deletedSuccessfully")),await ee(_t),l&&L(l,bt),(F===bt||F&&F.startsWith(bt+"/"))&&_(l,null)),se()}).catch(()=>G.error(e("sidebarFilesTree.toast.operationFailed"))).finally(Kt);return}Kt()},t[77]=K,t[78]=W,t[79]=be,t[80]=n,t[81]=ee,t[82]=L,t[83]=l,t[84]=F,t[85]=_,t[86]=e,t[87]=rt):rt=t[87];const Je=rt;let ce,We,Le,Ge,at,He,ze;if(t[88]!==ue||t[89]!==xe||t[90]!==w||t[91]!==fe||t[92]!==a||t[93]!==B||t[94]!==he||t[95]!==n.downloadFile||t[96]!==De||t[97]!==st||t[98]!==Ue||t[99]!==Pe||t[100]!==Be||t[101]!==l||t[102]!==f||t[103]!==h||t[104]!==y||t[105]!==F||t[106]!==e||t[107]!==Ye){let Wt=function(ys,Gn){const xn=w[ys]??[];return xn.map((ln,ar)=>{const Us=ln.type==="directory",bn=Us&&B.includes(ln.path),ir=F===ln.path,Vn=ar===xn.length-1;return s.jsxs("li",{className:"relative",children:[Gn>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),Vn&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-sidebar/50"})]}),s.jsx(hN,{node:ln,root:l,isExpanded:bn,isActive:ir,status:Us?void 0:De(ln.path),badge:Us?st(ln.path):void 0,permissions:he,downloadFile:n.downloadFile,contextMenuPath:fe,setContextMenuPath:H,onSelect:Ue,onToggle:Ye,onRevealPath:Pe,onOpenDialog:X}),Us&&bn&&s.jsx("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:Wt(ln.path,Gn+1)})]},ln.path)})};const Kt=!!(l&&w[l]);He="flex h-full min-h-0 flex-col overflow-hidden bg-sidebar";let se;t[115]===Symbol.for("react.memo_cache_sentinel")?(se=s.jsx(D,{name:"search",className:"pointer-events-none absolute left-2 top-2 h-4 w-4 text-muted-foreground"}),t[115]=se):se=t[115];let bt;t[116]===Symbol.for("react.memo_cache_sentinel")?(bt=ys=>b(ys.target.value),t[116]=bt):bt=t[116];let _t;t[117]!==e?(_t=e("sidebarFilesTree.search.placeholder"),t[117]=e,t[118]=_t):_t=t[118];let lt;t[119]!==f||t[120]!==_t?(lt=s.jsx(Bt,{ref:v,value:f,onChange:bt,placeholder:_t,className:"h-8 pl-8 pr-8 typography-meta"}),t[119]=f,t[120]=_t,t[121]=lt):lt=t[121];let ss;t[122]!==f||t[123]!==e?(ss=f.trim().length>0?s.jsx("button",{type:"button","aria-label":e("sidebarFilesTree.search.clearAria"),className:"absolute right-2 top-2 inline-flex h-4 w-4 items-center justify-center text-muted-foreground hover:text-foreground",onClick:()=>{b(""),v.current?.focus()},children:s.jsx(D,{name:"close",className:"h-4 w-4"})}):null,t[122]=f,t[123]=e,t[124]=ss):ss=t[124];let cs;t[125]!==lt||t[126]!==ss?(cs=s.jsxs("div",{className:"relative min-w-0 flex-1",children:[se,lt,ss]}),t[125]=lt,t[126]=ss,t[127]=cs):cs=t[127];let Ke;t[128]!==ue||t[129]!==a||t[130]!==e?(Ke=ue&&s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(ve,{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(D,{name:"file-add",className:"h-4 w-4"})})})}),s.jsx(It,{side:"bottom",sideOffset:6,children:e("sidebarFilesTree.actions.newFileTitle")})]}),t[128]=ue,t[129]=a,t[130]=e,t[131]=Ke):Ke=t[131];let xt;t[132]!==xe||t[133]!==a||t[134]!==e?(xt=xe&&s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(ve,{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(D,{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]=xt):xt=t[135];let Tt;t[136]!==Be?(Tt=()=>{Be()},t[136]=Be,t[137]=Tt):Tt=t[137];let Et;t[138]!==e?(Et=e("sidebarFilesTree.actions.refreshTitle"),t[138]=e,t[139]=Et):Et=t[139];let Qt;t[140]!==e?(Qt=e("sidebarFilesTree.actions.refreshTitle"),t[140]=e,t[141]=Qt):Qt=t[141];let Rt;t[142]===Symbol.for("react.memo_cache_sentinel")?(Rt=s.jsx(D,{name:"refresh",className:"h-4 w-4"}),t[142]=Rt):Rt=t[142];let Os;t[143]!==Tt||t[144]!==Et||t[145]!==Qt?(Os=s.jsx(Ct,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(ve,{variant:"ghost",size:"sm",onClick:Tt,className:"h-8 w-8 p-0 flex-shrink-0",title:Et,"aria-label":Qt,children:Rt})})}),t[143]=Tt,t[144]=Et,t[145]=Qt,t[146]=Os):Os=t[146];let Ts;t[147]!==e?(Ts=e("sidebarFilesTree.actions.refreshTitle"),t[147]=e,t[148]=Ts):Ts=t[148];let ks;t[149]!==Ts?(ks=s.jsx(It,{side:"bottom",sideOffset:6,children:Ts}),t[149]=Ts,t[150]=ks):ks=t[150];let Bs;t[151]!==Os||t[152]!==ks?(Bs=s.jsxs(kt,{children:[Os,ks]}),t[151]=Os,t[152]=ks,t[153]=Bs):Bs=t[153],t[154]!==cs||t[155]!==Ke||t[156]!==xt||t[157]!==Bs?(ze=s.jsxs("div",{className:"flex items-center gap-2 border-b border-border/40 px-3 py-2",children:[cs,Ke,xt,Bs]}),t[154]=cs,t[155]=Ke,t[156]=xt,t[157]=Bs,t[158]=ze):ze=t[158],ce=ws,Ge="flex-1 min-h-0",at="p-2",We="flex flex-col",Le=y?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(D,{name:"loader-4",className:"h-4 w-4 animate-spin"}),e("sidebarFilesTree.state.searching")]}):h.length>0?h.map(ys=>{const Gn=F===ys.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>Ue(ys),draggable:!0,onDragStart:xn=>{const ln=ys.relativePath||Qh(l??"",ys.path);!ln||ln==="."||(xn.dataTransfer.setData("application/x-openchamber-file-path",ln),xn.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",Gn?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),title:ys.path,children:[Jh(ys.path,ys.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},children:ys.relativePath??ys.path})]})},ys.path)}):Kt&&l?Wt(l,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:e("sidebarFilesTree.state.loading")}),t[88]=ue,t[89]=xe,t[90]=w,t[91]=fe,t[92]=a,t[93]=B,t[94]=he,t[95]=n.downloadFile,t[96]=De,t[97]=st,t[98]=Ue,t[99]=Pe,t[100]=Be,t[101]=l,t[102]=f,t[103]=h,t[104]=y,t[105]=F,t[106]=e,t[107]=Ye,t[108]=ce,t[109]=We,t[110]=Le,t[111]=Ge,t[112]=at,t[113]=He,t[114]=ze}else ce=t[108],We=t[109],Le=t[110],Ge=t[111],at=t[112],He=t[113],ze=t[114];let et;t[159]!==We||t[160]!==Le?(et=s.jsx("ul",{className:We,children:Le}),t[159]=We,t[160]=Le,t[161]=et):et=t[161];let gt;t[162]!==ce||t[163]!==Ge||t[164]!==at||t[165]!==et?(gt=s.jsx(ce,{outerClassName:Ge,className:at,children:et}),t[162]=ce,t[163]=Ge,t[164]=at,t[165]=et,t[166]=gt):gt=t[166];const Pt=!!K;let Nt;t[167]===Symbol.for("react.memo_cache_sentinel")?(Nt=Wt=>!Wt&&Q(null),t[167]=Nt):Nt=t[167];let ht;t[168]!==K||t[169]!==e?(ht=K==="createFile"&&e("sidebarFilesTree.dialog.createFile.title"),t[168]=K,t[169]=e,t[170]=ht):ht=t[170];let wt;t[171]!==K||t[172]!==e?(wt=K==="createFolder"&&e("sidebarFilesTree.dialog.createFolder.title"),t[171]=K,t[172]=e,t[173]=wt):wt=t[173];let es;t[174]!==K||t[175]!==e?(es=K==="rename"&&e("sidebarFilesTree.dialog.rename.title"),t[174]=K,t[175]=e,t[176]=es):es=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 Jt;t[180]!==ht||t[181]!==wt||t[182]!==es||t[183]!==Vt?(Jt=s.jsxs(fs,{children:[ht,wt,es,Vt]}),t[180]=ht,t[181]=wt,t[182]=es,t[183]=Vt,t[184]=Jt):Jt=t[184];let mt;t[185]!==K||t[186]!==W?.path||t[187]!==e?(mt=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]=mt):mt=t[188];let Lt;t[189]!==K||t[190]!==W?.path||t[191]!==e?(Lt=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]=Lt):Lt=t[192];let ts;t[193]!==K||t[194]!==W?.name||t[195]!==e?(ts=K==="rename"&&e("sidebarFilesTree.dialog.rename.description",{name:W?.name??""}),t[193]=K,t[194]=W?.name,t[195]=e,t[196]=ts):ts=t[196];let js;t[197]!==K||t[198]!==W?.name||t[199]!==e?(js=K==="delete"&&e("sidebarFilesTree.dialog.delete.description",{name:W?.name??""}),t[197]=K,t[198]=W?.name,t[199]=e,t[200]=js):js=t[200];let ds;t[201]!==mt||t[202]!==Lt||t[203]!==ts||t[204]!==js?(ds=s.jsxs(Ns,{children:[mt,Lt,ts,js]}),t[201]=mt,t[202]=Lt,t[203]=ts,t[204]=js,t[205]=ds):ds=t[205];let hs;t[206]!==Jt||t[207]!==ds?(hs=s.jsxs(gs,{children:[Jt,ds]}),t[206]=Jt,t[207]=ds,t[208]=hs):hs=t[208];let Ut;t[209]!==K||t[210]!==be||t[211]!==Je||t[212]!==e?(Ut=K!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(Bt,{value:be,onChange:Wt=>we(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]=be,t[211]=Je,t[212]=e,t[213]=Ut):Ut=t[213];let Qe;t[214]===Symbol.for("react.memo_cache_sentinel")?(Qe=()=>Q(null),t[214]=Qe):Qe=t[214];let At;t[215]!==e?(At=e("sidebarFilesTree.dialog.cancel"),t[215]=e,t[216]=At):At=t[216];let Ht;t[217]!==te||t[218]!==At?(Ht=s.jsx(ve,{variant:"outline",onClick:Qe,disabled:te,children:At}),t[217]=te,t[218]=At,t[219]=Ht):Ht=t[219];const jt=K==="delete"?"destructive":"default";let Zt;t[220]!==Je?(Zt=()=>{Je()},t[220]=Je,t[221]=Zt):Zt=t[221];let rs;t[222]!==K||t[223]!==be||t[224]!==te?(rs=te||K!=="delete"&&!be.trim(),t[222]=K,t[223]=be,t[224]=te,t[225]=rs):rs=t[225];let Ds;t[226]!==K||t[227]!==te||t[228]!==e?(Ds=te?s.jsx(D,{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]=Ds):Ds=t[229];let ns;t[230]!==jt||t[231]!==Zt||t[232]!==rs||t[233]!==Ds?(ns=s.jsx(ve,{variant:jt,onClick:Zt,disabled:rs,children:Ds}),t[230]=jt,t[231]=Zt,t[232]=rs,t[233]=Ds,t[234]=ns):ns=t[234];let zs;t[235]!==Ht||t[236]!==ns?(zs=s.jsxs(Hs,{children:[Ht,ns]}),t[235]=Ht,t[236]=ns,t[237]=zs):zs=t[237];let $s;t[238]!==hs||t[239]!==Ut||t[240]!==zs?($s=s.jsxs(ms,{children:[hs,Ut,zs]}),t[238]=hs,t[239]=Ut,t[240]=zs,t[241]=$s):$s=t[241];let gn;t[242]!==Pt||t[243]!==$s?(gn=s.jsx(ps,{open:Pt,onOpenChange:Nt,children:$s}),t[242]=Pt,t[243]=$s,t[244]=gn):gn=t[244];let rn;return t[245]!==He||t[246]!==ze||t[247]!==gt||t[248]!==gn?(rn=s.jsxs("section",{className:He,children:[ze,gt,gn]}),t[245]=He,t[246]=ze,t[247]=gt,t[248]=gn,t[249]=rn):rn=t[249],rn};function xN(t){return t.searchFiles}function bN(t){return t.openContextFile}function yN(t){return t.setSelectedPath}function vN(t){return t.addOpenPath}function wN(t){return t.removeOpenPathsByPrefix}function jN(t){return t.toggleExpandedPath}function NN(t){return t.mode==="file"?t.targetPath:null}function SN(t){return typeof t=="string"&&t.length>0}function kN(t){return Kn(t)}function CN(t){return t&&typeof t.name=="string"&&t.name.length>0}function IN(t){return{name:t.name,path:t.path,isDirectory:t.isDirectory}}function PN(t){return t.entries.map(IN)}function AN(t){return{name:t.name,path:t.path,isDirectory:t.isDirectory}}function DN(t){return t.map(AN)}function TN(t){return Object.keys(t).length===0?t:{}}function MN(t){return Object.keys(t).length===0?t:{}}function EN(t){return Kn(t)}function RN(t,e){return t.split("/").length-e.split("/").length}function FN(t){return{name:t.name,path:Kn(t.path),type:"file",extension:t.extension,relativePath:t.relativePath}}function ON(t,e){const n=ot.c(6),{git:r}=Bn(),a=Qs(LN);let i,l;n[0]!==t||n[1]!==a||n[2]!==r||n[3]!==e?(i=()=>{if(!t||!r||!e)return;a(t,r);const c=setInterval(()=>{typeof document<"u"&&document.hidden||a(t,r)},1e4);return()=>clearInterval(c)},l=[t,r,e,a],n[0]=t,n[1]=a,n[2]=r,n[3]=e,n[4]=i,n[5]=l):(i=n[4],l=n[5]),o.useEffect(i,l)}function LN(t){return t.ensureStatus}const Xh=()=>{const t=ot.c(17),e=Cs(_N),n=Cs(BN),r=Ks(VN),a=Qs(zN);let i;e:{if(e){let g;t[0]!==e||t[1]!==n?(g=n.find(v=>v.id===e)??n[0]??null,t[0]=e,t[1]=n,t[2]=g):g=t[2],i=g;break e}i=n[0]??null}const l=i;let c;e:{if(!l){c=null;break e}let g;t[3]!==l.id||t[4]!==l.path?(g={id:l.id,path:l.path},t[3]=l.id,t[4]=l.path,t[5]=g):g=t[5],c=g}const d=c;let p;e:{if(!l){p=null;break e}let g;t[6]!==l.label||t[7]!==l.path||t[8]!==r?(g=l.label?.trim()||Ua(l.path,r)||l.path,t[6]=l.label,t[7]=l.path,t[8]=r,t[9]=g):g=t[9],p=g}const m=p;let u;e:{if(!l){u=!1;break e}let g;t[10]!==l.path||t[11]!==a?(g=a.get(l.path)?.isGitRepo,t[10]=l.path,t[11]=a,t[12]=g):g=t[12],u=g===!0}const 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(Sw,{projectRef:d,projectLabel:m,canCreateWorktree:f})}),t[13]=f,t[14]=m,t[15]=d,t[16]=b):b=t[16],b},$N=()=>{const t=ot.c(38),{t:e}=ut(),n=Re(UN),r=Re(WN),a=Re(KN),i=ra();ON(i,a);let l;t[0]!==e?(l=e("layout.rightSidebar.git"),t[0]=e,t[1]=l):l=t[1];let c;t[2]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(D,{name:"git-branch",className:"h-3.5 w-3.5"}),t[2]=c):c=t[2];let d;t[3]!==l?(d={id:"git",label:l,icon:c},t[3]=l,t[4]=d):d=t[4];let 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(D,{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(D,{name:"file-list-2",className:"h-3.5 w-3.5"}),t[12]=b):b=t[12];let g;t[13]!==f?(g={id:"context",label:f,icon:b},t[13]=f,t[14]=g):g=t[14];let v;t[15]!==d||t[16]!==u||t[17]!==g?(v=[d,u,g],t[15]=d,t[16]=u,t[17]=g,t[18]=v):v=t[18];const x=v;let h;t[19]!==r?(h=I=>r(I),t[19]=r,t[20]=h):h=t[20];let j;t[21]!==n||t[22]!==h||t[23]!==x?(j=s.jsx("div",{className:"h-9 bg-sidebar pt-1 px-2",children:s.jsx(Vr,{items:x,activeId:n,onSelect:h,layoutMode:"fit",variant:"active-pill",className:"h-full"})}),t[21]=n,t[22]=h,t[23]=x,t[24]=j):j=t[24];let y;t[25]!==n?(y=n==="git"&&s.jsx(Yh,{}),t[25]=n,t[26]=y):y=t[26];let C;t[27]!==n?(C=n==="files"&&s.jsx(gN,{}),t[27]=n,t[28]=C):C=t[28];let k;t[29]!==n?(k=n==="context"&&s.jsx(Xh,{}),t[29]=n,t[30]=k):k=t[30];let w;t[31]!==y||t[32]!==C||t[33]!==k?(w=s.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden",children:[y,C,k]}),t[31]=y,t[32]=C,t[33]=k,t[34]=w):w=t[34];let S;return t[35]!==j||t[36]!==w?(S=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]=S):S=t[37],S};function _N(t){return t.activeProjectId}function BN(t){return t.projects}function VN(t){return t.homeDirectory}function zN(t){return t.directories}function UN(t){return t.rightSidebarTab}function WN(t){return t.setRightSidebarTab}function KN(t){return t.isRightSidebarOpen}const HN=1100,fd=15e3,_m=500,GN=t=>t<=6?t:t<=12?6:t<=25?4:2,Zh=o.memo(()=>{const t=ot.c(4),{t:e}=ut();let n;t[0]!==e?(n=e("diffView.binary.unavailable"),t[0]=e,t[1]=n):n=t[1];let r;return t[2]!==n?(r=s.jsx("div",{className:"rounded-lg border border-border/60 bg-background px-3 py-2",children:s.jsx("div",{className:"typography-meta text-muted-foreground",children:n})}),t[2]=n,t[3]=r):r=t[3],r}),eg={"?":{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"}},qN=eg.M,tl=[{value:"single",labelKey:"diffView.mode.single.label",descriptionKey:"diffView.mode.single.description"},{value:"stacked",labelKey:"diffView.mode.stacked.label",descriptionKey:"diffView.mode.stacked.description"}],YN=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"},tg=t=>{const e=YN(t);return eg[e]??qN},QN=t=>{const{index:e,working_dir:n}=t;return e==="A"||n==="A"||e==="?"||n==="?"},JN=t=>{const e=t.index?.trim();return!!(e&&e!=="?")},XN=t=>!!t.working_dir?.trim()||t.index==="?",ZN=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),e2=(t,e)=>{const n=t.replace(/\\/g,"/").replace(/\/+$/g,""),r=e.replace(/\\/g,"/");if(ZN(r))return r;const a=r.replace(/^\/+/,"");return n?`${n}/${a}`:a},Bm=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),Vm=(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},t2=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},Cl=(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=o.memo(t=>{const e=ot.c(29),{changedFiles:n,selectedFile:r,selectedFileEntry:a,onSelectFile:i,isMobile:l,showModeSelector:c,mode:d,onModeChange:p}=t,m=c===void 0?!1:c,{t:u}=ut();let f;e[0]!==l?(f=S=>{if(!l)return S;const I=S.lastIndexOf("/");return I>=0?S.slice(I+1):S},e[0]=l,e[1]=f):f=e[1];const b=f;if(n.length===0)return null;let g;e[2]!==b||e[3]!==a||e[4]!==u?(g=a?s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[s.jsx(Pr,{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)}),Cl(a.insertions,a.deletions)]}):s.jsx("span",{className:"text-muted-foreground",children:u("diffView.selector.selectFile")}),e[2]=b,e[3]=a,e[4]=u,e[5]=g):g=e[5];let v;e[6]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx(D,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[6]=v):v=e[6];let x;e[7]!==g?(x=s.jsx(Is,{asChild:!0,children:s.jsxs("button",{className:"flex h-7 items-center gap-2 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground outline-none hover:bg-interactive-hover hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring",children:[g,v]})}),e[7]=g,e[8]=x):x=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(Kf,{className:"typography-meta text-muted-foreground",children:u("diffView.selector.viewMode")}),s.jsx(hl,{value:d,onValueChange:S=>p(S),children:tl.map(S=>s.jsx(gl,{value:S.value,className:"items-center",children:s.jsx("span",{className:"typography-meta text-foreground",children:u(S.labelKey)})},S.value))}),s.jsx(Xn,{})]}):null,e[9]=d,e[10]=p,e[11]=m,e[12]=u,e[13]=h):h=e[13];const j=r??"";let y;if(e[14]!==n||e[15]!==b){let S;e[17]!==b?(S=I=>s.jsx(gl,{value:I.path,children:s.jsxs("div",{className:"flex w-full min-w-0 items-center gap-3",children:[s.jsx(Pr,{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:Cl(I.insertions,I.deletions)})]})},I.path),e[17]=b,e[18]=S):S=e[18],y=n.map(S),e[14]=n,e[15]=b,e[16]=y}else y=e[16];let C;e[19]!==i||e[20]!==j||e[21]!==y?(C=s.jsx(hl,{value:j,onValueChange:i,children:y}),e[19]=i,e[20]=j,e[21]=y,e[22]=C):C=e[22];let k;e[23]!==h||e[24]!==C?(k=s.jsxs(Ps,{className:"max-h-[70vh] min-w-[320px] overflow-y-auto",children:[h,C]}),e[23]=h,e[24]=C,e[25]=k):k=e[25];let w;return e[26]!==k||e[27]!==x?(w=s.jsxs(As,{children:[x,k]}),e[26]=k,e[27]=x,e[28]=w):w=e[28],w}),n2=o.memo(t=>{const e=ot.c(31),{mode:n,onModeChange:r}=t,{t:a}=ut();let i,l,c,d,p,m;if(e[0]!==n||e[1]!==a){const y=tl.find(C=>C.value===n)??tl[0];l=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(y.labelKey),e[0]=n,e[1]=a,e[2]=i,e[3]=l,e[4]=c,e[5]=d,e[6]=p,e[7]=m}else i=e[2],l=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(D,{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 g;e[15]!==i||e[16]!==m||e[17]!==b?(g=s.jsx(i,{asChild:m,children:b}),e[15]=i,e[16]=m,e[17]=b,e[18]=g):g=e[18];let v;e[19]!==r?(v=y=>r(y),e[19]=r,e[20]=v):v=e[20];let x;e[21]!==a?(x=tl.map(y=>s.jsx(gl,{value:y.value,children:s.jsx("span",{className:"typography-meta text-foreground",children:a(y.labelKey)})},y.value)),e[21]=a,e[22]=x):x=e[22];let h;e[23]!==n||e[24]!==x||e[25]!==v?(h=s.jsx(Ps,{className:"min-w-[140px]",children:s.jsx(hl,{value:n,onValueChange:v,children:x})}),e[23]=n,e[24]=x,e[25]=v,e[26]=h):h=e[26];let j;return e[27]!==l||e[28]!==h||e[29]!==g?(j=s.jsxs(l,{children:[g,h]}),e[27]=l,e[28]=h,e[29]=g,e[30]=j):j=e[30],j}),r2=o.memo(t=>{const e=ot.c(11),{changedFiles:n,selectedFile:r,onSelectFile:a}=t,{t:i}=ut();if(n.length===0)return null;let l;if(e[0]!==n||e[1]!==a||e[2]!==r||e[3]!==i){let d;e[5]!==a||e[6]!==r||e[7]!==i?(d=p=>{const m=tg(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(Pr,{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}),Cl(p.insertions,p.deletions)]})},p.path)},e[5]=a,e[6]=r,e[7]=i,e[8]=d):d=e[8],l=n.map(d),e[0]=n,e[1]=a,e[2]=r,e[3]=i,e[4]=l}else l=e[4];let c;return e[9]!==l?(c=s.jsx(ws,{outerClassName:"flex-1 min-h-0",className:"px-2 py-2",children:s.jsx("ul",{className:"flex flex-col gap-1",children:l})}),e[9]=l,e[10]=c):c=e[10],c}),a2=o.memo(t=>{const e=ot.c(21),{filePath:n,diff:r,isVisible:a,renderSideBySide:i}=t,{t:l}=ut(),c=r.original.length>0,d=r.modified.length>0;if(!a){let v;return e[0]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx("div",{className:"absolute inset-0 hidden"}),e[0]=v):v=e[0],v}const p=i?"flex flex-row gap-6 items-start justify-center h-full":"flex flex-col gap-4 items-center",m=i?"flex flex-col items-center gap-2 flex-1 min-w-0 h-full":"flex flex-col items-center gap-2";let u;e[1]===Symbol.for("react.memo_cache_sentinel")?(u={contain:"size layout"},e[1]=u):u=e[1];let f;e[2]!==r.original||e[3]!==n||e[4]!==c||e[5]!==m||e[6]!==i||e[7]!==l?(f=c&&s.jsxs("div",{className:m,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:l("diffView.image.original")}),s.jsx("img",{src:r.original,alt:l("diffView.image.originalAlt",{path:n}),className:i?"max-w-full max-h-[calc(100%-2rem)] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[2]=r.original,e[3]=n,e[4]=c,e[5]=m,e[6]=i,e[7]=l,e[8]=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]!==l?(b=d&&s.jsxs("div",{className:m,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:l(c?"diffView.image.modified":"diffView.image.new")}),s.jsx("img",{src:r.modified,alt:l("diffView.image.modifiedAlt",{path:n}),className:i?"max-w-full max-h-[calc(100%-2rem)] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[9]=r.modified,e[10]=n,e[11]=d,e[12]=c,e[13]=m,e[14]=i,e[15]=l,e[16]=b):b=e[16];let g;return e[17]!==p||e[18]!==f||e[19]!==b?(g=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]=g):g=e[20],g}),i2=o.memo(t=>{const e=ot.c(20),{filePath:n,diff:r,renderSideBySide:a}=t,{t:i}=ut(),l=r.original.length>0,c=r.modified.length>0,d=a?"flex flex-row gap-6 items-start justify-center":"flex flex-col gap-4 items-center",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]!==l||e[4]!==p||e[5]!==a||e[6]!==i?(u=l&&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]=l,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]!==l||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(l?"diffView.image.modified":"diffView.image.new")}),s.jsx("img",{src:r.modified,alt:i("diffView.image.modifiedAlt",{path:n}),className:a?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[8]=r.modified,e[9]=n,e[10]=c,e[11]=l,e[12]=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}),o2=o.memo(t=>{const e=ot.c(15),{filePath:n,diff:r,renderSideBySide:a,wrapLines:i}=t;let l;e[0]!==n?(l=xi(n)||"text",e[0]=n,e[1]=l):l=e[1];const c=l;if(r.isBinary){let m;return e[2]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(Zh,{}),e[2]=m):m=e[2],m}if(bi(n)){let m;return e[3]!==r||e[4]!==n||e[5]!==a?(m=s.jsx(i2,{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(Qd,{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}),l2=o.memo(t=>{const e=ot.c(15),{filePath:n,diff:r,isVisible:a,renderSideBySide:i,wrapLines:l}=t;let c;e[0]!==n?(c=xi(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(Zh,{}),e[2]=m):m=e[2],m}if(!a)return null;if(bi(n)){let m;return e[3]!==r||e[4]!==n||e[5]!==a||e[6]!==i?(m=s.jsx(a2,{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]!==l?(p=s.jsx(ws,{outerClassName:"absolute inset-0",disableHorizontal:!1,observeMutations:!1,preventOverscroll:!0,"data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:s.jsx(Qd,{original:r.original,modified:r.modified,language:d,fileName:n,renderSideBySide:i,wrapLines:l,layout:"inline"})}),e[8]=r.modified,e[9]=r.original,e[10]=n,e[11]=d,e[12]=i,e[13]=l,e[14]=p):p=e[14],p}),c2=o.memo(t=>{const e=ot.c(129),{directory:n,file:r,layout:a,wrapLines:i,scrollRootRef:l,isSelected:c,onSelect:d,registerSectionRef:p,defaultCollapsed:m,expandRequestPath:u,expandRequestNonce:f,showOpenInEditorAction:b,isOpeningInEditor:g,onOpenInEditor:v,staged:x,stagedRevision:h}=t,j=m===void 0?!1:m,y=u===void 0?null:u,C=f===void 0?0:f,k=b===void 0?!1:b,w=g===void 0?!1:g,S=x===void 0?!1:x,I=h===void 0?0:h,{t:T}=ut(),{git:P}=Bn();let A;e[0]!==n||e[1]!==r.path?(A=Ge=>Ge.directories.get(n)?.diffCache.get(r.path)??null,e[0]=n,e[1]=r.path,e[2]=A):A=e[2];const N=Qs(A),E=Qs(u2),M=Re(m2),[O,V]=o.useState(!j),[B,$]=o.useState(!1),[F,_]=o.useState(0),[q,L]=o.useState(null),[Y,Z]=o.useState(!1),[ae,re]=o.useState(!1),[me,fe]=o.useState(null),H=o.useRef(null),K=o.useRef(null);let Q;e[3]!==r?(Q=tg(r),e[3]=r,e[4]=Q):Q=e[4];const W=Q,de=a==="side-by-side";let be;e:{if(S){be=me;break e}if(!N){be=null;break e}let Ge;e[5]!==N.isBinary||e[6]!==N.modified||e[7]!==N.original?(Ge={original:N.original,modified:N.modified,isBinary:N.isBinary},e[5]=N.isBinary,e[6]=N.modified,e[7]=N.original,e[8]=Ge):Ge=e[8],be=Ge}const we=be;let te;e[9]!==r.path||e[10]!==p?(te=Ge=>{K.current=Ge,p(r.path,Ge)},e[9]=r.path,e[10]=p,e[11]=te):te=e[11];const ge=te;let ue;e[12]===Symbol.for("react.memo_cache_sentinel")?(ue=Ge=>{V(Ge),Ge&&$(!0)},e[12]=ue):ue=e[12];const xe=ue;let ne;e[13]!==r.path||e[14]!==d?(ne=()=>{d(r.path)},e[13]=r.path,e[14]=d,e[15]=ne):ne=e[15];const pe=ne;let J,Se;e[16]!==B||e[17]!==O||e[18]!==l?(J=()=>{if(!O||B)return;const Ge=K.current;if(!Ge)return;if(!l.current||typeof IntersectionObserver>"u"){$(!0);return}const at=new IntersectionObserver(He=>{He.some(p2)&&($(!0),at.disconnect())},{root:l.current,rootMargin:"200px 0px",threshold:.1});return at.observe(Ge),()=>at.disconnect()},Se=[B,O,l],e[16]=B,e[17]=O,e[18]=l,e[19]=J,e[20]=Se):(J=e[19],Se=e[20]),o.useEffect(J,Se);let he,Ie;e[21]!==C||e[22]!==y||e[23]!==r.path?(he=()=>{C<=0||y!==r.path||(V(!0),$(!0))},Ie=[C,y,r.path],e[21]=C,e[22]=y,e[23]=r.path,e[24]=he,e[25]=Ie):(he=e[24],Ie=e[25]),o.useEffect(he,Ie);let Pe;e[26]!==S?(Pe=()=>{S&&(fe(null),L(null),H.current=null)},e[26]=S,e[27]=Pe):Pe=e[27];let Ce;e[28]!==S||e[29]!==I?(Ce=[S,I],e[28]=S,e[29]=I,e[30]=Ce):Ce=e[30],o.useEffect(Pe,Ce);let X,ie;e[31]!==we||e[32]!==F||e[33]!==n||e[34]!==r.path||e[35]!==P||e[36]!==B||e[37]!==O||e[38]!==E||e[39]!==S||e[40]!==I?(X=()=>{if(!O||!B)return;if(!n||we){H.current=null,Z(!1);return}const Ge=`${n}::${r.path}::${S?`staged:${I}`:"unstaged"}::${F}`;if(H.current===Ge)return;H.current=Ge,L(null),Z(!0);let at=!1;const He=P.getGitFileDiff(n,{path:r.path,staged:S}),ze=new Promise(f2);return Promise.race([He,ze]).then(et=>{if(at)return;const gt={original:et.original??"",modified:et.modified??"",isBinary:et.isBinary};S?fe(gt):E(n,r.path,gt),Z(!1)}).catch(et=>{if(at)return;const gt=et instanceof Error?et.message:String(et);L(gt),Z(!1)}),()=>{at=!0,H.current===Ge&&(H.current=null)}},ie=[n,we,F,r.path,P,B,O,E,S,I],e[31]=we,e[32]=F,e[33]=n,e[34]=r.path,e[35]=P,e[36]=B,e[37]=O,e[38]=E,e[39]=S,e[40]=I,e[41]=X,e[42]=ie):(X=e[41],ie=e[42]),o.useEffect(X,ie);let Ne;e[43]!==pe||e[44]!==O?(Ne=()=>{xe(!O),pe()},e[43]=pe,e[44]=O,e[45]=Ne):Ne=e[45];const oe=Ne,ke=O?"rounded-b-none":"rounded-b-xl",Te=c?"ring-1 ring-inset ring-[var(--interactive-selection)]":null;let Be;e[46]!==ke||e[47]!==Te?(Be=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",ke,"text-muted-foreground hover:text-foreground",Te),e[46]=ke,e[47]=Te,e[48]=Be):Be=e[48];let je;e[49]===Symbol.for("react.memo_cache_sentinel")?(je=s.jsx("div",{className:"absolute inset-0 pointer-events-none group-hover/header:bg-interactive-hover"}),e[49]=je):je=e[49];let ee;e[50]!==O?(ee=s.jsx("span",{className:"flex size-5 items-center justify-center opacity-70 group-hover/header:opacity-100",children:O?s.jsx(D,{name:"arrow-down-s",className:"size-4"}):s.jsx(D,{name:"arrow-right-s",className:"size-4"})}),e[50]=O,e[51]=ee):ee=e[51];let R;e[52]!==W.color?(R={color:W.color},e[52]=W.color,e[53]=R):R=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 le;e[57]!==W.descriptionKey||e[58]!==T?(le=T(W.descriptionKey),e[57]=W.descriptionKey,e[58]=T,e[59]=le):le=e[59];let Me;e[60]!==W.code||e[61]!==R||e[62]!==U||e[63]!==le?(Me=s.jsx("span",{className:"typography-micro font-semibold leading-none w-4 text-center uppercase",style:R,title:U,"aria-label":le,children:W.code}),e[60]=W.code,e[61]=R,e[62]=U,e[63]=le,e[64]=Me):Me=e[64];const Oe=r.path;let Ae;e[65]!==r.path?(Ae=s.jsx(Pr,{filePath:r.path,className:"h-3.5 w-3.5 flex-shrink-0 align-middle"}),e[65]=r.path,e[66]=Ae):Ae=e[66];let z;if(e[67]!==r.path){e:{const Ge=r.path.lastIndexOf("/");if(Ge===-1){let ht;e[69]===Symbol.for("react.memo_cache_sentinel")?(ht={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},e[69]=ht):ht=e[69],z=s.jsx("span",{className:"block min-w-0 truncate typography-ui-label text-foreground",style:ht,children:r.path});break e}const at=r.path.slice(0,Ge),He=r.path.slice(Ge+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 et;e[71]!==at?(et=s.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:ze,children:at}),e[71]=at,e[72]=et):et=e[72];let gt;e[73]===Symbol.for("react.memo_cache_sentinel")?(gt=s.jsx("span",{className:"text-muted-foreground",children:"/"}),e[73]=gt):gt=e[73];let Pt;e[74]!==He?(Pt=s.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[gt,s.jsx("span",{className:"text-foreground",children:He})]}),e[74]=He,e[75]=Pt):Pt=e[75];let Nt;e[76]!==et||e[77]!==Pt?(Nt=s.jsxs("span",{className:"flex min-w-0 items-baseline overflow-hidden",children:[et,Pt]}),e[76]=et,e[77]=Pt,e[78]=Nt):Nt=e[78],z=Nt}e[67]=r.path,e[68]=z}else z=e[68];let De;e[79]!==Ae||e[80]!==z?(De=s.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[Ae,z]}),e[79]=Ae,e[80]=z,e[81]=De):De=e[81];let Xe;e[82]!==r.path||e[83]!==De?(Xe=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]=Xe):Xe=e[84];let st;e[85]!==ee||e[86]!==Me||e[87]!==Xe?(st=s.jsxs("div",{className:"relative flex min-w-0 flex-1 items-center gap-2",children:[ee,Me,Xe]}),e[85]=ee,e[86]=Me,e[87]=Xe,e[88]=st):st=e[88];let tt;e[89]!==r.deletions||e[90]!==r.insertions?(tt=Cl(r.insertions,r.deletions),e[89]=r.deletions,e[90]=r.insertions,e[91]=tt):tt=e[91];let Ue;e[92]!==we||e[93]!==r.path||e[94]!==w||e[95]!==v||e[96]!==k||e[97]!==T?(Ue=k&&v?s.jsx(ve,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",title:T("diffView.actions.openFileInEditorAtChange"),onClick:Ge=>{Ge.stopPropagation(),v(r.path,we)},disabled:w,children:w?s.jsx(D,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(D,{name:"edit",className:"size-3.5"})}):null,e[92]=we,e[93]=r.path,e[94]=w,e[95]=v,e[96]=k,e[97]=T,e[98]=Ue):Ue=e[98];const it=de?"side-by-side":"unified";let Ye;e[99]!==r.path||e[100]!==M?(Ye=Ge=>{const at=Ge==="side-by-side"?"side-by-side":"inline";M(r.path,at)},e[99]=r.path,e[100]=M,e[101]=Ye):Ye=e[101];let rt;e[102]!==it||e[103]!==Ye?(rt=s.jsx(nh,{mode:it,onModeChange:Ye,className:"opacity-70"}),e[102]=it,e[103]=Ye,e[104]=rt):rt=e[104];let Je;e[105]!==tt||e[106]!==Ue||e[107]!==rt?(Je=s.jsxs("div",{className:"relative flex items-center gap-2",children:[tt,Ue,rt]}),e[105]=tt,e[106]=Ue,e[107]=rt,e[108]=Je):Je=e[108];let ce;e[109]!==oe||e[110]!==Be||e[111]!==st||e[112]!==Je?(ce=s.jsx("div",{className:"sticky top-0 z-10 bg-background",children:s.jsxs("button",{type:"button",onClick:oe,className:Be,children:[je,st,Je]})}),e[109]=oe,e[110]=Be,e[111]=st,e[112]=Je,e[113]=ce):ce=e[113];let We;e[114]!==we||e[115]!==q||e[116]!==r.deletions||e[117]!==r.insertions||e[118]!==r.path||e[119]!==ae||e[120]!==O||e[121]!==Y||e[122]!==de||e[123]!==i?(We=O&&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:()=>_(h2),children:"Retry"})]}):null,Y&&!we&&!q?s.jsxs("div",{className:"flex items-center justify-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}),"Loading diff…"]}):null,we&&!ae&&r.insertions+r.deletions>_m?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:()=>re(!0),children:"Render anyway"})]}):null,we&&(ae||r.insertions+r.deletions<=_m)?s.jsx(o2,{filePath:r.path,diff:we,renderSideBySide:de,wrapLines:i}):null]}),e[114]=we,e[115]=q,e[116]=r.deletions,e[117]=r.insertions,e[118]=r.path,e[119]=ae,e[120]=O,e[121]=Y,e[122]=de,e[123]=i,e[124]=We):We=e[124];let Le;return e[125]!==ge||e[126]!==ce||e[127]!==We?(Le=s.jsxs("div",{ref:ge,className:"scroll-mt-4",children:[ce,We]}),e[125]=ge,e[126]=ce,e[127]=We,e[128]=Le):Le=e[128],Le}),sg=({hideStackedFileSidebar:t=!1,stackedDefaultCollapsedAll:e=!1,hideFileSelector:n=!1,pinSelectedFileHeaderToTopOnNavigate:r=!1,showOpenInEditorAction:a=!1,diffScope:i="all",targetFilePath:l=null})=>{const{t:c}=ut(),{git:d,files:p}=Bn(),m=ra(),{screenWidth:u,isMobile:f}=an(),b=Fd(m??null),g=$l(m??null),v=Ld(m??null),x=Qs(Ue=>Ue.setActiveDirectory),h=Qs(Ue=>Ue.ensureStatus),j=Qs(Ue=>Ue.fetchStatus),y=Qs(Ue=>Ue.setDiff),C=Qs(o.useCallback(Ue=>m?Ue.directories.get(m)?.indexRevision??0:0,[m])),[k,w]=o.useState(null),[S,I]=o.useState(!1),[T,P]=o.useState(null),[A,N]=o.useState(null),[E,M]=o.useState(0),[O,V]=o.useState(null),[B,$]=o.useState(0),[F,_]=o.useState(null),q=o.useRef(null),L=Re(Ue=>Ue.pendingDiffFile),Y=Re(Ue=>Ue.pendingDiffStaged),Z=Re(Ue=>Ue.setPendingDiffFile),ae=Re(Ue=>Ue.diffLayoutPreference),re=Re(Ue=>Ue.diffFileLayout),me=Re(Ue=>Ue.setDiffFileLayout),fe=Re(Ue=>Ue.diffWrapLines),H=Re(Ue=>Ue.setDiffWrapLines),K=Re(Ue=>Ue.diffViewMode),Q=Re(Ue=>Ue.setDiffViewMode),W=Re(Ue=>Ue.openContextFileAtLine),de=fe,be=i==="staged"?!0:i==="working"?!1:null,we=be??S,te=K==="stacked",ge=f||u<=768,ue=!t&&!ge&&u>=1024,xe=o.useRef(null),ne=o.useRef(new Map),pe=o.useRef(null),J=o.useRef(null),Se=o.useRef(!1);o.useEffect(()=>{if(!r||!te||!O)return;const Ue=xe.current;if(!Ue)return;let it=null,Ye=!1,rt=0;const Je=Date.now()+1200;let ce=0;const We=()=>{Ye||(Ye=!0,V(null))},Le=()=>{We()},Ge=()=>{if(ce>0){ce-=1;return}We()};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}),Ue.addEventListener("scroll",Ge,{passive:!0});const at=()=>{if(Ye||Date.now()>Je){We();return}const He=xe.current,ze=ne.current.get(O);if(!He||!ze){We();return}const et=He.getBoundingClientRect(),Pt=ze.getBoundingClientRect().top-et.top;if(Math.abs(Pt)<=1){if(rt+=1,rt>=2){We();return}}else{rt=0;const Nt=Math.max(0,He.scrollHeight-He.clientHeight),ht=Math.min(Nt,Math.max(0,He.scrollTop+Pt));if(Math.abs(ht-He.scrollTop)<=.5){We();return}ce+=1,He.scrollTop=ht}it=window.requestAnimationFrame(at)};return it=window.requestAnimationFrame(at),()=>{Ye=!0,it!==null&&window.cancelAnimationFrame(it),window.removeEventListener("wheel",Le,!0),window.removeEventListener("touchstart",Le,!0),window.removeEventListener("pointerdown",Le,!0),window.removeEventListener("keydown",Le,!0),Ue.removeEventListener("scroll",Ge)}},[te,r,O]);const he=o.useMemo(()=>{if(!g?.files)return[];const Ue=g.diffStats??{},it=i==="staged"?JN:i==="working"?XN:()=>!0;return g.files.filter(it).map(Ye=>({...Ye,insertions:Ue[Ye.path]?.insertions??0,deletions:Ue[Ye.path]?.deletions??0,isNew:QN(Ye)})).sort((Ye,rt)=>Ye.path.localeCompare(rt.path))},[i,g]),Ie=o.useMemo(()=>k?he.find(Ue=>Ue.path===k)??null:null,[he,k]),Pe=o.useCallback(Ue=>{const it=re[Ue.path];if(it)return it;if(ae==="inline")return"inline";if(ae==="side-by-side")return"side-by-side";const Ye=u<HN;return Ue.isNew||Ye?"inline":"side-by-side"},[re,ae,u]),Ce=o.useMemo(()=>Ie?Pe(Ie):null,[Pe,Ie]);o.useEffect(()=>{m&&(x(m),h(m,d))},[m,x,h,d]),o.useEffect(()=>{if(m)return Ar.onGitRefreshHint(Ue=>{Bm(Ue.directory)===Bm(m)&&j(m,d)})},[m,j,d]),o.useEffect(()=>{i==="all"&&L&&(w(L),I(Y),P(null),Z(null),te&&(Se.current=!0,pe.current=L,N(L),M(Ue=>Ue+1)))},[i,te,L,Y,Z]),o.useEffect(()=>{if(i==="all")return;const Ue=l?.trim();Ue&&(w(Ue),I(i==="staged"),P(null),te&&(Se.current=!0,pe.current=Ue,N(Ue),M(it=>it+1)))},[i,te,l]),o.useEffect(()=>{we&&(P(null),_(null),q.current=null)},[we,C]),o.useEffect(()=>{!k&&!L&&he.length>0&&w(he[0].path)},[he,k,L]),o.useEffect(()=>{k&&he.length>0&&(he.some(it=>it.path===k)||w(he[0]?.path??null))},[he,k]);const X=o.useCallback((Ue,it)=>{const Ye=ne.current;it?Ye.set(Ue,it):Ye.delete(Ue)},[]),ie=o.useCallback(Ue=>{const it=ne.current.get(Ue),Ye=xe.current;if(!it||!Ye)return{ok:!1,aligned:!1,didMove:!1,atScrollLimit:!1,delta:0};const rt=Ye.getBoundingClientRect(),ce=it.getBoundingClientRect().top-rt.top,We=Math.max(0,Ye.scrollHeight-Ye.clientHeight),Le=Ye.scrollTop+ce,Ge=Math.min(We,Math.max(0,Le)),at=Math.abs(Ge-Ye.scrollTop)>.5;Ye.scrollTop=Ge;const He=Math.abs(ce)<=1,ze=Ge<=.5||Ge>=We-.5;return{ok:!0,aligned:He,didMove:at,atScrollLimit:ze,delta:ce}},[]);o.useEffect(()=>{if(!te){pe.current=null,Se.current=!1,J.current!==null&&(window.cancelAnimationFrame(J.current),J.current=null);return}if(!pe.current)return;let it=0;const Ye=120;let rt=!1,Je=0,ce=!1,We=0;const Le=Date.now()+2e3,Ge=()=>{ce||(ce=!0,window.removeEventListener("wheel",He,!0),window.removeEventListener("touchstart",He,!0),window.removeEventListener("pointerdown",He,!0),window.removeEventListener("keydown",He,!0),et?.removeEventListener("scroll",ze))},at=()=>{rt||(rt=!0,Ge(),pe.current=null,Se.current=!1,J.current!==null&&(window.cancelAnimationFrame(J.current),J.current=null))},He=()=>{at()},ze=()=>{if(Je>0){Je-=1;return}at()},et=xe.current;window.addEventListener("wheel",He,{passive:!0,capture:!0}),window.addEventListener("touchstart",He,{passive:!0,capture:!0}),window.addEventListener("pointerdown",He,{capture:!0}),window.addEventListener("keydown",He,{capture:!0}),et?.addEventListener("scroll",ze,{passive:!0});const gt=()=>{if(Date.now()>Le){at(),J.current=null;return}if(rt){J.current=null;return}const Pt=pe.current;if(!Pt){at(),J.current=null;return}Je+=1;const Nt=ie(Pt);if(!Nt.ok){Je=Math.max(0,Je-1),it+=1,it<Ye?J.current=window.requestAnimationFrame(gt):(at(),J.current=null);return}if(!Nt.aligned){if(it+=1,Nt.didMove){if(We=0,it<Ye){J.current=window.requestAnimationFrame(gt);return}}else if(We+=1,We<6&&(Nt.atScrollLimit||Math.abs(Nt.delta)>1)){J.current=window.requestAnimationFrame(gt);return}}r&&Se.current&&V(Pt),at()};return J.current=window.requestAnimationFrame(gt),()=>{rt=!0,Ge(),J.current!==null&&(window.cancelAnimationFrame(J.current),J.current=null)}},[te,r,ie,k,E]);const Ne=o.useCallback(Ue=>{w(Ue),I(!1),P(null)},[]),oe=o.useCallback(Ue=>{if(J.current!==null&&(window.cancelAnimationFrame(J.current),J.current=null),pe.current=null,w(Ue),I(!1),P(null),!te){Se.current=!1;return}Se.current=!0,pe.current=Ue,ie(Ue)},[te,ie]),ke=o.useCallback(Ue=>{Q(Ue),Ue==="stacked"&&k&&(ie(k).aligned||(pe.current=k))},[ie,k,Q]),Te=o.useCallback(Ue=>{const it=Ue==="side-by-side"?"side-by-side":"inline";if(te){he.forEach(Ye=>{me(Ye.path,it)});return}Ie&&me(Ie.path,it)},[he,te,Ie,me]),Be=(Ce??"side-by-side")==="side-by-side",je=!n&&(!te||!ue),ee=Qs(o.useCallback(Ue=>!m||!k||we?null:Ue.directories.get(m)?.diffCache.get(k)??null,[we,m,k])),R=o.useMemo(()=>we?T:ee?{original:ee.original,modified:ee.modified,isBinary:ee.isBinary}:null,[we,ee,T]),[U,le]=o.useState(null),Me=o.useCallback(async(Ue,it)=>{if(!(!m||!Ue)){le(Ue);try{let Ye=null;if(it&&!it.isBinary&&!bi(Ue)&&(Ye=Vm(it.original,it.modified)),Ye===null)try{const Le=await d.getGitDiff(m,{path:Ue,staged:we,contextLines:3});Ye=t2(Le.diff)}catch{Ye=null}let rt=it;if(Ye===null||!rt){const Le=await d.getGitFileDiff(m,{path:Ue,staged:we});rt={original:Le.original??"",modified:Le.modified??"",isBinary:Le.isBinary},we||y(m,Ue,rt)}const Je=Ye??(rt.isBinary||bi(Ue)?1:Vm(rt.original,rt.modified)),ce=e2(m,Ue),We=await Zd(p,ce);if(!We.ok){G.error(eu(We.reason));return}W(m,ce,Je,1)}finally{le(Ye=>Ye===Ue?null:Ye)}}},[we,m,p,d,W,y]),Oe=o.useCallback(async()=>{k&&await Me(k,R)},[Me,R,k]),Ae=!!(k&&U===k),z=we?!!T:!!ee,De=!te&&!!k&&!z;o.useEffect(()=>{if(te)return;if(_(null),!m||!k){q.current=null;return}if(we?T:ee){q.current=null;return}const Ue=`${m}::${k}::${we?`staged:${C}`:"unstaged"}::${B}`;if(q.current===Ue)return;q.current=Ue;let it=!1;const Ye=d.getGitFileDiff(m,{path:k,staged:we}),rt=fd,Je=new Promise((ce,We)=>{setTimeout(()=>We(new Error(`Timed out after ${rt}ms`)),rt)});return Promise.race([Ye,Je]).then(ce=>{if(it)return;const We={original:ce.original??"",modified:ce.modified??"",isBinary:ce.isBinary};we?P(We):y(m,k,We)}).catch(ce=>{if(it)return;const We=ce instanceof Error?ce.message:String(ce);_(We)}),()=>{it=!0,q.current===Ue&&(q.current=null)}},[we,m,C,te,k,ee,T,d,y,B]);const Xe=()=>!m||!k||!R?null:s.jsx(l2,{filePath:k,diff:R,isVisible:!0,renderSideBySide:Be,wrapLines:de},k),st=()=>{if(!m)return null;const Ue=GN(he.length),it=Ye=>be!==null?be:S&&Ye===k;return s.jsxs("div",{className:"flex flex-1 min-h-0 h-full gap-3 px-3 pb-3 pt-2",children:[ue&&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:he.length})]}),s.jsx(r2,{changedFiles:he,selectedFile:k,onSelectFile:oe})]}),s.jsx(ws,{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:he.map((Ye,rt)=>s.jsx(c2,{directory:m,file:Ye,layout:Pe(Ye),wrapLines:de,scrollRootRef:xe,isSelected:Ye.path===k,onSelect:Ne,registerSectionRef:X,defaultCollapsed:e?!0:rt>=Ue,expandRequestPath:A,expandRequestNonce:E,showOpenInEditorAction:a,isOpeningInEditor:U===Ye.path,onOpenInEditor:(Je,ce)=>{Me(Je,ce)},staged:it(Ye.path),stagedRevision:C},`${it(Ye.path)?"staged":"unstaged"}:${Ye.path}`))})})]})},tt=()=>m?v&&!g?s.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[s.jsx(D,{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")}):he.length===0?s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:c("diffView.state.cleanWorkingTree")}):te?st():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:[Xe(),De&&!z&&s.jsx("div",{className:"absolute inset-0 flex items-center justify-center gap-2 text-sm text-muted-foreground",children:F?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:F}),s.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>{_(null),$(Ue=>Ue+1)},children:c("diffView.actions.retry")})]}):s.jsxs(s.Fragment,{children:[s.jsx(D,{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(D,{name:"git-commit",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:v&&!g?c("diffView.state.loadingChanges"):he.length===1?c("diffView.summary.changedFilesSingle",{count:he.length}):c("diffView.summary.changedFilesPlural",{count:he.length})})]}),!ge&&s.jsx(n2,{mode:K,onModeChange:ke}),je&&s.jsx(s2,{changedFiles:he,selectedFile:k,selectedFileEntry:Ie,onSelectFile:oe,isMobile:ge,showModeSelector:ge,mode:K,onModeChange:ke}),s.jsx("div",{className:"flex-1"}),Ie&&s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>H(!fe),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(D,{name:"text-wrap",className:"size-4"})}),a&&Ie&&!te&&s.jsx(ve,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",onClick:()=>{Oe()},disabled:Ae,title:c("diffView.actions.openFileAtFirstChangedLine"),children:Ae?s.jsx(D,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(D,{name:"edit",className:"size-3.5"})}),Ie&&Ce&&s.jsx(nh,{mode:Ce==="side-by-side"?"side-by-side":"unified",onModeChange:Te})]}),tt()]})},d2=()=>{const t=ot.c(6),{git:e}=Bn(),n=ra(),r=Qs(g2),a=Qs(x2),i=Db(n??null);let l,c;return t[0]!==n||t[1]!==a||t[2]!==e||t[3]!==r?(l=()=>{n&&(r(n),a(n,e))},c=[n,r,a,e],t[0]=n,t[1]=a,t[2]=e,t[3]=r,t[4]=l,t[5]=c):(l=t[4],c=t[5]),o.useEffect(l,c),i};function u2(t){return t.setDiff}function m2(t){return t.setDiffFileLayout}function p2(t){return t.isIntersecting}function f2(t,e){setTimeout(()=>e(new Error(`Timed out after ${fd}ms`)),fd)}function h2(t){return t+1}function g2(t){return t.setActiveDirectory}function x2(t){return t.ensureStatus}const b2=Object.freeze(Object.defineProperty({__proto__:null,DiffView:sg,useDiffFileCount:d2},Symbol.toStringTag,{value:"Module"})),y2={next:"Next match",prev:"Previous match",select:"Select all matches",replace:"Replace",replaceAll:"Replace all",close:"Close"},v2={case:"Match case",re:"Regular expression",word:"Match whole word"};function w2(t){const e=t.querySelector(".cm-search");if(e){for(const[n,r]of Object.entries(y2)){const a=e.querySelector(`button[name="${n}"]`);a&&!a.title&&(a.title=r)}for(const[n,r]of Object.entries(v2)){const i=e.querySelector(`input[name="${n}"]`)?.parentElement;i&&!i.title&&(i.title=r)}}}const Sc=new WeakMap;function j2(t,e){const n=ml(t.state);if(!n.valid)return Sc.delete(t),0;const r=Sc.get(t);if(!e&&r?.doc===t.state.doc&&r.query.eq(n))return r.total;const a=n.getCursor(t.state);let i=0;for(let l=a.next();!l.done;l=a.next())i+=1;return Sc.set(t,{query:n,doc:t.state.doc,total:i}),i}function N2(t){const e=ml(t.state);if(!e.valid)return 0;const n=t.state.selection.main,r=e.getCursor(t.state);let a=0,i=0;for(let l=r.next();!l.done;l=r.next()){const c=l.value;if(a+=1,i===0&&(i=a),n.from===c.from&&n.to===c.to||n.from<c.to&&n.to>c.from||c.from>=n.head)return a}return i}function zm(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=j2(e,n),l=i===0?0:N2(e);a.textContent=i===0?"":`${l}/${i}`}const Um=new ki,Wm=new ki,Km=new ki,Hm=new ki,Gm=new ki,qm=new ki,Ym=t=>t,kc=yx,S2=vx,k2=wx;class C2 extends jx{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 Qm=(t,e)=>!t||t.length===0?[]:bx.define({create(n){const r=new zf,a=[...t].sort((i,l)=>i.afterLine-l.afterLine);for(const i of a){const l=n.doc.lines;if(i.afterLine>l)continue;const c=n.doc.line(i.afterLine);r.add(c.to,c.to,Uf.widget({widget:new C2(i.id,e),block:!0,side:1}))}return r.finish()},update(n,r){return n.map(r.changes)},provide:n=>$n.decorations.from(n)}),Jm=t=>{if(!t)return[];const e=Math.max(1,t.start),n=Math.max(e,t.end);return xx.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 zf;for(let i=e;i<=n&&i<=r.state.doc.lines;i+=1){const l=r.state.doc.line(i);a.add(l.from,l.from,Uf.line({class:"oc-cm-selected-line"}))}return a.finish()}},{decorations:r=>r.decorations})};function po({value:t,onChange:e,extensions:n,className:r,readOnly:a,lineNumbersConfig:i,highlightLines:l,onViewReady:c,onViewDestroy:d,blockWidgets:p,enableSearch:m,searchOpen:u,onSearchOpenChange:f}){const b=o.useRef(null),g=o.useRef(null),v=o.useRef(t),x=o.useRef(e),h=o.useRef(c),j=o.useRef(d),y=o.useRef(f),C=o.useRef(p),k=o.useRef(new Map),[w,S]=o.useState([]),I=o.useCallback(P=>{const A=(P??[]).map(N=>{const E=k.current.get(N.id);return E?{id:N.id,content:N.content,container:E}:null}).filter(N=>N!==null);S(N=>N.length===A.length&&N.every((E,M)=>{const O=A[M];return E.id===O.id&&E.content===O.content&&E.container===O.container})?N:A)},[]),T=o.useCallback(P=>{const A=b.current,N=P??g.current;if(!A||!N)return;const E=N.dom.querySelector(".cm-gutters"),M=E instanceof HTMLElement?E.getBoundingClientRect().width:0;A.style.setProperty("--oc-editor-gutter-width",`${M}px`)},[]);return o.useEffect(()=>{v.current=t},[t]),o.useEffect(()=>{x.current=e},[e]),o.useEffect(()=>{h.current=c,j.current=d},[c,d]),o.useEffect(()=>{y.current=f},[f]),o.useEffect(()=>{C.current=p,I(p)},[p,I]),o.useEffect(()=>{if(!b.current)return;const P=(()=>{if(typeof document>"u")return null;const N=document.querySelector('meta[name="csp-nonce"]')?.getAttribute("content");if(N)return N;const E=window.__OPENCHAMBER_CSP_NONCE__;return typeof E=="string"&&E.length>0?E:null})(),A=dx.create({doc:v.current,extensions:[...P?[$n.cspNonce.of(P)]:[],ux({fixed:!0}),Um.of(pu(i)),mx(),px.of(" "),Ql.of([fx,...hx,...gx]),$n.updateListener.of(N=>{T(N.view),(N.viewportChanged||N.geometryChanged)&&I(C.current);const E=fu(N.startState),M=fu(N.state);E!==M&&y.current?.(M);const O=!ml(N.startState).eq(ml(N.state));if(M&&(E!==M||O||N.docChanged||N.selectionSet)&&zm(N.view.dom,N.view,E!==M||O||N.docChanged),!N.docChanged)return;const V=N.state.doc.toString();v.current=V,x.current(V),I(C.current)}),Wm.of($n.editable.of(!a)),Km.of(n??[]),Hm.of(Jm(l)),Gm.of(Qm(p,k.current)),qm.of(m?[hu({top:!0}),Ql.of(Ym(gu))]:[])]});return g.current=new $n({state:A,parent:b.current}),kc(g.current,g.current.state.doc.length,200),g.current.requestMeasure(),requestAnimationFrame(()=>{T(g.current),I(C.current)}),g.current&&h.current?.(g.current),()=>{j.current?.(),g.current?.destroy(),g.current=null,S([])}},[C,T,I]),o.useEffect(()=>{const P=g.current;P&&(P.dispatch({effects:[Um.reconfigure(pu(i)),Wm.reconfigure($n.editable.of(!a)),Km.reconfigure(n??[]),Hm.reconfigure(Jm(l)),Gm.reconfigure(Qm(p,k.current)),qm.reconfigure(m?[hu({top:!0}),Ql.of(Ym(gu))]:[])]}),kc(P,P.state.doc.length,200),P.requestMeasure(),requestAnimationFrame(()=>{T(P),I(C.current)}))},[n,l,i,a,p,m,T,I]),o.useEffect(()=>{const P=g.current;!P||m===!1||(u?(S2(P),requestAnimationFrame(()=>{w2(P.dom),zm(P.dom,P,!0)})):k2(P))},[u,m]),o.useEffect(()=>{const P=g.current;if(!P)return;const A=P.state.doc.toString();A!==t&&(P.dispatch({changes:{from:0,to:A.length,insert:t}}),kc(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=>Go.createPortal(P.content,P.container,P.id))]})}const I2=(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)},Xm=(t,e)=>{const n=t.state.doc.lineAt(e.main.head);return{lineNumber:n.number,character:e.main.head-n.from+1,selection:e}},Zm=(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:Nx.cursor(i),effects:$n.scrollIntoView(i,{y:"center"})})};function P2({open:t,onOpenChange:e,view:n,variant:r="overlay"}){const{t:a}=ut(),[i,l]=o.useState(""),c=o.useRef(null),d=o.useRef(!1),p=o.useRef(null),m=o.useRef(null),u=o.useMemo(()=>I2(i,n),[i,n]);o.useEffect(()=>{!t||!n||(d.current=!1,c.current=Xm(n,n.state.selection),l(""))},[t,n]),o.useEffect(()=>{t&&window.requestAnimationFrame(()=>{m.current?.focus(),m.current?.select()})},[t]),o.useEffect(()=>{if(!(!t||!n||!c.current)){if(u===null){const{selection:x}=c.current;n.dispatch({selection:x,effects:$n.scrollIntoView(x.main.from,{y:"center"})});return}Zm(n,u,c.current.character)}},[u,t,n]);const f=o.useCallback(()=>{if(!n||d.current||!c.current)return;const{selection:x}=c.current;n.dispatch({selection:x,effects:$n.scrollIntoView(x.main.from,{y:"center"})})},[n]),b=o.useCallback(x=>{x||f(),e(x)},[e,f]),g=o.useCallback(()=>{!n||u===null||!c.current||(d.current=!0,Zm(n,u,c.current.character),e(!1),n.focus())},[u,e,n]);o.useEffect(()=>{if(!t)return;const x=j=>{const y=p.current,C=j.target;!y||!(C instanceof Node)||y.contains(C)||b(!1)},h=j=>{j.key==="Escape"&&(j.preventDefault(),b(!1))};return document.addEventListener("pointerdown",x,!0),document.addEventListener("keydown",h,!0),()=>{document.removeEventListener("pointerdown",x,!0),document.removeEventListener("keydown",h,!0)}},[b,t,r]);const v=o.useMemo(()=>{if(!n)return a("goToLineDialog.helper.editorUnavailable");if(u===null){const x=c.current??Xm(n,n.state.selection);return a("goToLineDialog.helper.currentLineRange",{current:x.lineNumber,max:n.state.doc.lines})}return a("goToLineDialog.helper.goToLine",{line:u})},[u,a,n]);return r==="inline"?t?s.jsxs("div",{ref:p,className:"ml-1 flex h-6 items-center gap-1",children:[s.jsx(Bt,{ref:m,type:"number",min:1,step:1,inputMode:"numeric",value:i,onChange:x=>l(x.target.value),onKeyDown:x=>{x.key==="Enter"&&(x.preventDefault(),g())},placeholder:a("goToLineDialog.field.linePlaceholderShort"),className:"h-6 w-20 rounded-md border-border/70 bg-transparent px-2 typography-meta"}),s.jsx(ve,{variant:"outline",size:"xs",onClick:g,disabled:!n||u===null,className:"h-6 px-2",children:a("goToLineDialog.actions.go")})]}):null:s.jsx("div",{ref: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(Bt,{ref:m,type:"number",min:1,step:1,inputMode:"numeric",value:i,onChange:x=>l(x.target.value),onKeyDown:x=>{x.key==="Enter"&&(x.preventDefault(),g())},placeholder:a("goToLineDialog.field.linePlaceholder"),className:"h-8 w-full rounded-md border-border/70 bg-background/60 typography-ui-label"}),s.jsx("div",{className:"mt-2 rounded-md bg-primary/15 px-3 py-1.5 typography-ui-label text-foreground/95",children:v})]})})}const Il=t=>{const e=ot.c(11),{currentMode:n,onToggle:r}=t,a=n==="preview",i=a?"Switch to edit mode":"Switch to preview mode",l=a?"Edit":"Preview";let c;e[0]!==a?(c=a?s.jsx(D,{name:"eye",className:"size-4","aria-hidden":"true"}):s.jsx(D,{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(ve,{variant:"ghost",size:"sm",onClick:r,"aria-label":i,className:"h-5 w-5 p-0",children:c})}),e[2]=i,e[3]=r,e[4]=c,e[5]=d):d=e[5];let p;e[6]!==l?(p=s.jsx(It,{sideOffset:8,children:l}),e[6]=l,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 fo(t){const e=t.metadata.variant==="dark",n=t.config?.fonts?.mono||"monospace",r=t.colors.syntax.highlights||{},a=t.colors.syntax.tokens||{},i=$n.theme({"&":{backgroundColor:"var(--background)",color:t.colors.syntax.base.foreground,fontSize:"var(--text-code)",lineHeight:"1.5rem",position:"relative"},".cm-scroller":{fontFamily:n,backgroundColor:"var(--background)"},".cm-comment":{color:t.colors.syntax.base.comment},".cm-keyword":{color:t.colors.syntax.base.keyword},".cm-string":{color:t.colors.syntax.base.string},".cm-string-2":{color:a.stringEscape||t.colors.syntax.base.string},".cm-number":{color:t.colors.syntax.base.number},".cm-operator":{color:t.colors.syntax.base.operator},".cm-punctuation":{color:a.punctuation||t.colors.syntax.base.comment},".cm-atom":{color:a.boolean||t.colors.syntax.base.number},".cm-builtin":{color:a.functionCall||t.colors.syntax.base.function},".cm-def":{color:a.variableGlobal||t.colors.syntax.base.variable},".cm-attribute":{color:a.variableOther||a.variableProperty||t.colors.syntax.base.operator},".cm-meta":{color:t.colors.syntax.base.comment},".cm-property":{color:a.variableProperty||t.colors.syntax.base.keyword},".cm-variable":{color:t.colors.syntax.base.variable},".cm-variable-2":{color:a.variableOther||t.colors.syntax.base.function},".cm-variable-3":{color:a.variableGlobal||t.colors.syntax.base.type},".cm-tag":{color:a.tag||t.colors.syntax.base.keyword},".cm-link":{color:a.url||t.colors.syntax.base.keyword,textDecoration:"underline"},".cm-content":{caretColor:t.colors.interactive.cursor},".cm-cursor, .cm-dropCursor":{borderLeftColor:t.colors.interactive.cursor},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, ::selection":{backgroundColor:t.colors.interactive.selection},".cm-gutters":{backgroundColor:"var(--background)",color:r.lineNumber||t.colors.syntax.base.comment,borderRight:`1px solid ${t.colors.interactive.border}`,position:"sticky",paddingRight:"8px",left:0,zIndex:2,boxShadow:"0 0 0 var(--background)"},".cm-gutter":{backgroundColor:"var(--background)"},".cm-gutterElement":{backgroundColor:"var(--background)"},".cm-lineNumbers":{backgroundColor:"var(--background)"},".cm-lineNumbers .cm-gutterElement":{paddingLeft:"8px",paddingRight:"8px",minWidth:"42px"},".cm-activeLineGutter":{color:r.lineNumberActive||t.colors.syntax.base.foreground},".cm-activeLine":{backgroundColor:t.colors.surface.overlay},".cm-panels":{backgroundColor:"transparent",color:t.colors.surface.foreground,position:"absolute",top:"0",right:"0",left:"auto",width:"auto",zIndex:10,pointerEvents:"none"},".cm-panels-top":{borderBottom:"none",position:"absolute",top:"6px",right:"14px",left:"auto",width:"auto"},".cm-panel.cm-search":{pointerEvents:"auto",padding:"4px",backgroundColor:`color-mix(in srgb, ${t.colors.surface.elevated} 85%, transparent)`,border:`1px solid ${t.colors.interactive.border}`,borderRadius:"10px",boxShadow:`0 2px 8px color-mix(in srgb, ${t.colors.surface.background} 60%, transparent)`,width:"auto",minWidth:"360px",maxWidth:"480px"},".cm-search":{display:"flex",flexWrap:"wrap",alignItems:"center",gap:"0",width:"100%",color:t.colors.surface.foreground,fontFamily:"inherit",fontSize:"13px",lineHeight:"1"},".cm-search br":{display:"none"},".cm-search .cm-textfield":{appearance:"none",height:"26px",margin:0,padding:"0 8px",borderRadius:"6px !important",border:`1px solid ${t.colors.interactive.border}`,backgroundColor:t.colors.surface.background,color:t.colors.surface.foreground,fontFamily:"inherit",fontSize:"12px",lineHeight:"1",outline:"none",transition:"border-color 150ms ease"},".cm-search .cm-textfield::placeholder":{color:t.colors.surface.mutedForeground,opacity:1},".cm-search .cm-textfield:focus":{borderColor:t.colors.primary.base},'.cm-search .cm-textfield[name="search"]':{order:1,flex:"1 1 120px",maxWidth:"calc(100% - 142px)",minWidth:"100px"},".cm-search label":{order:2,display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:0,marginLeft:"1px",padding:0,borderRadius:"4px",border:"1px solid transparent",backgroundColor:"transparent",color:"transparent",cursor:"pointer",userSelect:"none",fontSize:"1px",lineHeight:"0",overflow:"hidden",position:"relative",transition:"background-color 120ms ease, border-color 120ms ease"},".cm-search label:hover":{backgroundColor:t.colors.interactive.hover},'.cm-search label:has(input[type="checkbox"]:checked)':{backgroundColor:t.colors.interactive.hover,borderColor:t.colors.interactive.border},'.cm-search [type="checkbox"]':{appearance:"none",WebkitAppearance:"none",width:"0",height:"0",margin:"0",padding:"0",border:"none",position:"absolute",opacity:"0",pointerEvents:"none"},".cm-search label::after":{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",fontSize:"13px",fontWeight:"600",lineHeight:"1",fontFamily:"inherit",color:t.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search label:hover::after":{color:t.colors.surface.foreground},'.cm-search label:has(input[type="checkbox"]:checked)::after':{color:t.colors.surface.foreground},'.cm-search label:has(input[name="case"])::after':{content:'"Aa"',fontSize:"12px",letterSpacing:"-0.5px"},'.cm-search label:has(input[name="re"])::after':{content:'".*"',fontSize:"13px",fontFamily:"monospace"},'.cm-search label:has(input[name="word"])::after':{content:'"ab"',fontSize:"12px",textDecoration:"underline",textUnderlineOffset:"2px"},".cm-search .cm-search-message":{order:3,color:t.colors.surface.mutedForeground,backgroundColor:"transparent",border:"none",borderRadius:"0",padding:"0 6px",fontSize:"11px",whiteSpace:"nowrap",lineHeight:"26px"},".cm-search .cm-button":{appearance:"none",WebkitAppearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:0,marginLeft:"1px",padding:0,borderRadius:"4px",border:"none",backgroundColor:"transparent",backgroundImage:"none",color:"transparent",cursor:"pointer",fontSize:"1px",fontWeight:"400",lineHeight:"0",overflow:"hidden",position:"relative",boxShadow:"none",transition:"background-color 120ms ease"},".cm-search .cm-button::after":{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",fontSize:"15px",lineHeight:"1",color:t.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search .cm-button:hover":{backgroundColor:t.colors.interactive.hover},".cm-search .cm-button:hover::after":{color:t.colors.surface.foreground},".cm-search .cm-button:active":{backgroundColor:t.colors.interactive.active},".cm-search .cm-button:focus-visible":{outline:"none",boxShadow:`0 0 0 1px ${t.colors.interactive.focusRing}`},".cm-search .cm-button:disabled":{opacity:.4,cursor:"default",pointerEvents:"none"},'.cm-search .cm-button[name="prev"]':{order:21,marginTop:"2px"},'.cm-search .cm-button[name="prev"]::after':{content:'"↑"'},'.cm-search .cm-button[name="next"]':{order:22,marginTop:"2px"},'.cm-search .cm-button[name="next"]::after':{content:'"↓"'},'.cm-search .cm-button[name="select"]':{order:23,marginTop:"2px"},'.cm-search .cm-button[name="select"]::after':{content:'"≡"',fontSize:"17px"},'.cm-panel.cm-search button[name="close"]':{order:5,appearance:"none",WebkitAppearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:"0 0 0 auto",padding:"0",borderRadius:"4px",border:"none",backgroundColor:"transparent",backgroundImage:"none",color:t.colors.surface.mutedForeground,cursor:"pointer",fontSize:"16px",lineHeight:"1",boxShadow:"none",position:"relative",overflow:"visible",transition:"background-color 120ms ease, color 120ms ease"},'.cm-panel.cm-search button[name="close"]:hover':{backgroundColor:t.colors.interactive.hover,color:t.colors.surface.foreground},'.cm-search .cm-button[name="replace"]':{order:24,marginTop:"2px"},'.cm-search .cm-button[name="replace"]::after':{content:'"⇄"'},'.cm-search .cm-button[name="replaceAll"], .cm-search .cm-button[name="replace-all"]':{order:25,marginTop:"2px"},'.cm-search .cm-button[name="replaceAll"]::after, .cm-search .cm-button[name="replace-all"]::after':{content:'"⇉"'},'.cm-search .cm-textfield[name="replace"]':{order:20,flex:"1 1 100%",maxWidth:"calc(100% - 142px)",minWidth:"80px",marginTop:"2px"},".cm-searchMatch":{backgroundColor:t.colors.status.infoBackground,boxShadow:`inset 0 0 0 1px ${t.colors.status.infoBorder}`,borderRadius:"2px"},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:t.colors.interactive.selection,color:t.colors.interactive.selectionForeground,boxShadow:`inset 0 0 0 1px ${t.colors.interactive.borderFocus}`},"&.cm-focused":{outline:"none"}},{dark:e}),l=xu.define([{tag:[pt.comment,pt.docComment,pt.meta,pt.documentMeta],class:"cm-comment"},{tag:[pt.keyword,pt.controlKeyword,pt.moduleKeyword,pt.definitionKeyword,pt.modifier],class:"cm-keyword"},{tag:[pt.operatorKeyword,pt.operator,pt.derefOperator,pt.updateOperator,pt.definitionOperator,pt.typeOperator,pt.controlOperator,pt.logicOperator,pt.bitwiseOperator,pt.arithmeticOperator,pt.compareOperator],class:"cm-operator"},{tag:[pt.punctuation,pt.separator,pt.bracket,pt.paren,pt.brace,pt.squareBracket,pt.angleBracket],class:"cm-punctuation"},{tag:[pt.string,pt.regexp,pt.attributeValue,pt.special(pt.string),pt.monospace],class:"cm-string"},{tag:pt.escape,class:"cm-string-2"},{tag:[pt.number,pt.bool,pt.atom,pt.null,pt.self],class:"cm-number"},{tag:[pt.function(pt.variableName),pt.function(pt.definition(pt.variableName)),pt.function(pt.propertyName),pt.standard(pt.variableName),pt.special(pt.variableName)],class:"cm-builtin"},{tag:pt.definition(pt.variableName),class:"cm-def"},{tag:[pt.variableName,pt.local(pt.variableName),pt.constant(pt.variableName),pt.literal],class:"cm-variable"},{tag:pt.propertyName,class:"cm-property"},{tag:pt.attributeName,class:"cm-attribute"},{tag:[pt.className,pt.typeName,pt.namespace],class:"cm-variable-3"},{tag:[pt.tagName,pt.labelName,pt.annotation,pt.macroName],class:"cm-tag"},{tag:pt.link,class:"cm-link"},{tag:[pt.heading,pt.heading1,pt.heading2,pt.heading3,pt.heading4,pt.heading5,pt.heading6],class:"cm-keyword"}]),c=xu.define([{tag:[pt.comment,pt.docComment,pt.meta,pt.documentMeta],color:t.colors.syntax.base.comment},{tag:[pt.keyword,pt.controlKeyword,pt.moduleKeyword,pt.definitionKeyword,pt.modifier],color:t.colors.syntax.base.keyword},{tag:[pt.operatorKeyword,pt.operator,pt.derefOperator,pt.updateOperator,pt.definitionOperator,pt.typeOperator,pt.controlOperator,pt.logicOperator,pt.bitwiseOperator,pt.arithmeticOperator,pt.compareOperator],color:t.colors.syntax.base.operator},{tag:[pt.string,pt.regexp,pt.attributeValue,pt.special(pt.string),pt.monospace],color:t.colors.syntax.base.string},{tag:pt.escape,color:a.stringEscape||t.colors.syntax.base.string},{tag:[pt.number,pt.bool,pt.atom,pt.null,pt.self],color:t.colors.syntax.base.number},{tag:[pt.function(pt.variableName),pt.function(pt.definition(pt.variableName)),pt.function(pt.propertyName),pt.standard(pt.variableName),pt.special(pt.variableName)],color:t.colors.syntax.base.function},{tag:pt.definition(pt.variableName),color:a.variableGlobal||t.colors.syntax.base.variable},{tag:[pt.variableName,pt.local(pt.variableName),pt.constant(pt.variableName),pt.literal],color:t.colors.syntax.base.variable},{tag:pt.propertyName,color:a.variableProperty||t.colors.syntax.base.variable},{tag:pt.attributeName,color:a.variableOther||t.colors.syntax.base.variable},{tag:[pt.className,pt.typeName,pt.namespace],color:t.colors.syntax.base.type},{tag:[pt.tagName,pt.labelName,pt.annotation,pt.macroName],color:a.tag||t.colors.syntax.base.keyword},{tag:pt.link,color:a.url||t.colors.syntax.base.function,textDecoration:"underline"},{tag:[pt.punctuation,pt.separator,pt.bracket,pt.paren,pt.brace,pt.squareBracket,pt.angleBracket],color:a.punctuation||t.colors.syntax.base.comment}]);return[i,ko(Sx,{fallback:!0}),ko(kx),ko(l),ko(c)]}const A2=t=>{const e=hn(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},D2=t=>{const e=ot.c(8),{label:n,iconDataUrl:r}=t,[a,i]=o.useState(!1);let l;e[0]!==n?(l=n.trim().slice(0,1).toUpperCase()||"?",e[0]=n,e[1]=l):l=e[1];const c=l;if(r&&!a){let m;e[2]===Symbol.for("react.memo_cache_sentinel")?(m=()=>i(!0),e[2]=m):m=e[2];let u;return e[3]!==r?(u=s.jsx("img",{src:r,alt:"",className:"size-4 rounded-sm",onError:m}),e[3]=r,e[4]=u):u=e[4],u}let d;e[5]===Symbol.for("react.memo_cache_sentinel")?(d=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},T2=t=>t.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),hn=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},M2=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),ep=t=>/^[A-Za-z]:\//.test(t)?t.toLowerCase():t,Pl=(t,e)=>{const n=hn(e),r=hn(t);if(!n||!r)return!1;const a=ep(n),i=ep(r);return i===a||i.startsWith(`${a}/`)},tp=(t,e)=>{const n=hn(e),r=hn(t);if(!Pl(r,n))return[];const i=r.slice(n.length).replace(/^\//,"").split("/"),l=[];let c=n;for(let d=0;d<i.length-1;d++)c=c?`${c}/${i[d]}`:i[d],l.push(c);return l},hd=(t,e)=>{if(!e)return"";const n=hn(e);if(!t||!Pl(n,t))return n;const r=n.slice(t.length);return r.startsWith("/")?r.slice(1):r},E2=new Set(["node_modules"]),R2=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},sp=t=>{const e=ot.c(11),{name:n}=t,r=o.useRef(null),a=o.useRef(null),[i,l]=o.useState(!1);let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=()=>{const f=r.current,b=a.current;if(!f||!b)return;const g=()=>{l(b.scrollWidth>f.clientWidth+1)};g();const v=new ResizeObserver(g);return v.observe(f),v.observe(b),()=>{v.disconnect()}},e[0]=c):c=e[0];let d;e[1]!==n?(d=[n],e[1]=n,e[2]=d):d=e[2],o.useLayoutEffect(c,d);let 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},F2=t=>E2.has(t),O2=t=>{const e=hn(t);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},L2=t=>{const n=(t instanceof Error?t.message:String(t??"")).toLowerCase();return n.includes("is a directory")||n.includes("eisdir")},np=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")},Oi=2e5,ng="openchamber:files:auto-save-enabled",$2=()=>{if(typeof window>"u")return!0;try{return window.localStorage.getItem(ng)!=="false"}catch{return!0}},rg=(t,e)=>s.jsx(Pr,{filePath:t,extension:e}),_2=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="md"||e==="markdown"},B2=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="json"||e==="jsonc"||e==="json5"||e==="geojson"},Cc=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="html"||e==="htm"},V2=t=>{const e=ot.c(62),{node:n,root:r,isExpanded:a,isActive:i,isMobile:l,alwaysShowActions:c,status:d,badge:p,permissions:m,downloadFile:u,contextMenuPath:f,setContextMenuPath:b,onSelect:g,onToggle:v,onRevealPath:x,onOpenDialog:h}=t,{t:j}=ut(),y=n.type==="directory",{canRename:C,canCreateFile:k,canCreateFolder:w,canDelete:S,canReveal:I}=m;let T;e[0]!==k||e[1]!==w||e[2]!==S||e[3]!==C||e[4]!==I||e[5]!==n.path||e[6]!==b?(T=re=>{!C&&!k&&!w&&!S&&!I||(re?.preventDefault(),b(n.path))},e[0]=k,e[1]=w,e[2]=S,e[3]=C,e[4]=I,e[5]=n.path,e[6]=b,e[7]=T):T=e[7];const P=T;let A;e[8]!==y||e[9]!==n||e[10]!==g||e[11]!==v?(A=()=>{y?v(n.path):g(n)},e[8]=y,e[9]=n,e[10]=g,e[11]=v,e[12]=A):A=e[12];const N=A;let E;e[13]!==n.path||e[14]!==b?(E=re=>{re.stopPropagation(),b(n.path)},e[13]=n.path,e[14]=b,e[15]=E):E=e[15];const M=E,O=l?void 0:P,V=l?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 F;e[18]!==y||e[19]!==a||e[20]!==n.extension||e[21]!==n.path?(F=y?a?s.jsx(D,{name:"folder-open-fill",className:"size-4 flex-shrink-0 text-primary/60"}):s.jsx(D,{name:"folder-3-fill",className:"size-4 flex-shrink-0 text-primary/60"}):rg(n.path,n.extension),e[18]=y,e[19]=a,e[20]=n.extension,e[21]=n.path,e[22]=F):F=e[22];let _;e[23]!==n.name||e[24]!==n.path?(_=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:n.path,children:n.name}),e[23]=n.name,e[24]=n.path,e[25]=_):_=e[25];let q;e[26]!==y||e[27]!==d?(q=!y&&d&&s.jsx(R2,{status:d}),e[26]=y,e[27]=d,e[28]=q):q=e[28];let L;e[29]!==p||e[30]!==y?(L=y&&p&&s.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[p.modified>0&&s.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",p.modified]}),p.added>0&&s.jsxs("span",{className:"text-[var(--status-success)]",children:["+",p.added]})]}),e[29]=p,e[30]=y,e[31]=L):L=e[31];let Y;e[32]!==N||e[33]!==q||e[34]!==L||e[35]!==V||e[36]!==$||e[37]!==F||e[38]!==_?(Y=s.jsxs("button",{type:"button",onClick:N,onContextMenu:V,className:$,children:[F,_,q,L]}),e[32]=N,e[33]=q,e[34]=L,e[35]=V,e[36]=$,e[37]=F,e[38]=_,e[39]=Y):Y=e[39];let Z;e[40]!==c||e[41]!==k||e[42]!==w||e[43]!==S||e[44]!==C||e[45]!==I||e[46]!==f||e[47]!==u||e[48]!==M||e[49]!==y||e[50]!==l||e[51]!==n||e[52]!==h||e[53]!==x||e[54]!==r||e[55]!==b||e[56]!==j?(Z=(C||k||w||S||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:re=>b(re?n.path:null),children:[s.jsx(Is,{asChild:!0,children:s.jsx(ve,{variant:"ghost",size:"icon",className:"size-6",onClick:M,children:s.jsx(D,{name:"more-2-fill",className:"size-4"})})}),s.jsxs(Ps,{align:"end",side:"bottom",onCloseAutoFocus:()=>b(null),children:[C&&s.jsxs(Ot,{onClick:re=>{re.stopPropagation(),h("rename",n)},children:[s.jsx(D,{name:"edit",className:"mr-2 size-4"})," ",j("sidebarFilesTree.menu.rename")]}),s.jsxs(Ot,{onClick:re=>{re.stopPropagation(),Rn(n.path).then(me=>{if(me.ok){G.success(j("sidebarFilesTree.toast.pathCopied"));return}G.error(j("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(D,{name:"file-copy",className:"mr-2 size-4"})," ",j("sidebarFilesTree.menu.copyPath")]}),s.jsxs(Ot,{onClick:re=>{re.stopPropagation();const me=hd(r,n.path)||n.path;Rn(me).then(fe=>{if(fe.ok){G.success(j("filesView.toast.relativePathCopied"));return}G.error(j("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(D,{name:"file-copy-2",className:"mr-2 size-4"})," ",j("filesView.tree.menu.copyRelativePath")]}),!y&&u&&s.jsxs(Ot,{onClick:re=>{re.stopPropagation(),u(n.path)},children:[s.jsx(D,{name:"download",className:"mr-2 size-4"})," ",j("sidebarFilesTree.menu.save")]}),I&&s.jsxs(Ot,{onClick:re=>{re.stopPropagation(),x(n.path)},children:[s.jsx(D,{name:"folder-received",className:"mr-2 size-4"})," ",j(Bd())]}),y&&(k||w)&&s.jsxs(s.Fragment,{children:[s.jsx(Xn,{}),k&&s.jsxs(Ot,{onClick:re=>{re.stopPropagation(),h("createFile",n)},children:[s.jsx(D,{name:"file-add",className:"mr-2 size-4"})," ",j("sidebarFilesTree.menu.newFile")]}),w&&s.jsxs(Ot,{onClick:re=>{re.stopPropagation(),h("createFolder",n)},children:[s.jsx(D,{name:"folder-add",className:"mr-2 size-4"})," ",j("sidebarFilesTree.menu.newFolder")]})]}),S&&s.jsxs(s.Fragment,{children:[s.jsx(Xn,{}),s.jsxs(Ot,{onClick:re=>{re.stopPropagation(),h("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(D,{name:"delete-bin",className:"mr-2 size-4"})," ",j("sidebarFilesTree.menu.delete")]})]})]})]})}),e[40]=c,e[41]=k,e[42]=w,e[43]=S,e[44]=C,e[45]=I,e[46]=f,e[47]=u,e[48]=M,e[49]=y,e[50]=l,e[51]=n,e[52]=h,e[53]=x,e[54]=r,e[55]=b,e[56]=j,e[57]=Z):Z=e[57];let ae;return e[58]!==Y||e[59]!==Z||e[60]!==O?(ae=s.jsxs("div",{className:"group relative flex items-center",onContextMenu:O,children:[Y,Z]}),e[58]=Y,e[59]=Z,e[60]=O,e[61]=ae):ae=e[61],ae},z2=t=>{const e=ot.c(83),{activeDialog:n,dialogData:r,dialogInputValue:a,onDialogInputChange:i,isDialogSubmitting:l,onDialogSubmit:c,onClose:d,inputRef:p}=t,{t:m}=ut(),u=!!n;let f;e[0]!==d?(f=F=>!F&&d(),e[0]=d,e[1]=f):f=e[1];let b;e[2]!==n||e[3]!==m?(b=n==="createFile"&&m("filesView.dialog.createFile.title"),e[2]=n,e[3]=m,e[4]=b):b=e[4];let g;e[5]!==n||e[6]!==m?(g=n==="createFolder"&&m("filesView.dialog.createFolder.title"),e[5]=n,e[6]=m,e[7]=g):g=e[7];let v;e[8]!==n||e[9]!==m?(v=n==="rename"&&m("filesView.dialog.rename.title"),e[8]=n,e[9]=m,e[10]=v):v=e[10];let x;e[11]!==n||e[12]!==m?(x=n==="delete"&&m("filesView.dialog.delete.title"),e[11]=n,e[12]=m,e[13]=x):x=e[13];let h;e[14]!==b||e[15]!==g||e[16]!==v||e[17]!==x?(h=s.jsxs(fs,{children:[b,g,v,x]}),e[14]=b,e[15]=g,e[16]=v,e[17]=x,e[18]=h):h=e[18];let j;e[19]!==n||e[20]!==r?.path||e[21]!==m?(j=n==="createFile"&&m("filesView.dialog.createFile.description",{path:r?.path??m("filesView.dialog.rootFallback")}),e[19]=n,e[20]=r?.path,e[21]=m,e[22]=j):j=e[22];let y;e[23]!==n||e[24]!==r?.path||e[25]!==m?(y=n==="createFolder"&&m("filesView.dialog.createFolder.description",{path:r?.path??m("filesView.dialog.rootFallback")}),e[23]=n,e[24]=r?.path,e[25]=m,e[26]=y):y=e[26];let 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]!==y?(w=s.jsxs(Ns,{children:[j,y,C,k]}),e[35]=C,e[36]=k,e[37]=j,e[38]=y,e[39]=w):w=e[39];let S;e[40]!==w||e[41]!==h?(S=s.jsxs(gs,{children:[h,w]}),e[40]=w,e[41]=h,e[42]=S):S=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(Bt,{value:a,onChange:F=>i(F.target.value),placeholder:m(n==="rename"?"filesView.dialog.rename.placeholder":"filesView.dialog.namePlaceholder"),onKeyDown:F=>{F.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]!==l||e[53]!==d||e[54]!==T?(P=s.jsx(ve,{variant:"outline",onClick:d,disabled:l,children:T}),e[52]=l,e[53]=d,e[54]=T,e[55]=P):P=e[55];const A=n==="delete"?"destructive":"default";let N;e[56]!==c?(N=()=>{c()},e[56]=c,e[57]=N):N=e[57];let E;e[58]!==n||e[59]!==a||e[60]!==l?(E=l||n!=="delete"&&!a.trim(),e[58]=n,e[59]=a,e[60]=l,e[61]=E):E=e[61];let M;e[62]!==n||e[63]!==l||e[64]!==m?(M=l?s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):m(n==="delete"?"filesView.dialog.delete.confirm":"filesView.dialog.confirm"),e[62]=n,e[63]=l,e[64]=m,e[65]=M):M=e[65];let O;e[66]!==A||e[67]!==N||e[68]!==E||e[69]!==M?(O=s.jsx(ve,{variant:A,onClick:N,disabled:E,children:M}),e[66]=A,e[67]=N,e[68]=E,e[69]=M,e[70]=O):O=e[70];let V;e[71]!==P||e[72]!==O?(V=s.jsxs(Hs,{children:[P,O]}),e[71]=P,e[72]=O,e[73]=V):V=e[73];let B;e[74]!==p||e[75]!==S||e[76]!==I||e[77]!==V?(B=s.jsxs(ms,{initialFocus:p,children:[S,I,V]}),e[74]=p,e[75]=S,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(ps,{open:u,onOpenChange:f,children:B}),e[79]=u,e[80]=f,e[81]=B,e[82]=$):$=e[82],$},ag=({mode:t="full"})=>{const{t:e}=ut(),{files:n,runtime:r}=Bn(),{currentTheme:a,availableThemes:i,lightThemeId:l,darkThemeId:c}=vr(),{isMobile:d,isTablet:p,screenWidth:m}=an(),u=d||p,f=_l(),b=$d(),g=ra()??"",v=hn(g.trim()),x=d||t!=="editor-only",h=t==="editor-only"&&!d,j=_d(Ee=>Ee.searchFiles),y=$l(g),[C,k]=o.useState(""),w=Bl(C,200),S=o.useRef(null),[I,T]=o.useState(!1),[P,A]=o.useState(!0),[N,E]=o.useState(!1),[M,O]=o.useState(!1),[V,B]=o.useState(!1),$=o.useRef(null),F=o.useRef(0),_=o.useCallback(Ee=>{F.current=Math.max(0,F.current+(Ee?1:-1))},[]),q=o.useCallback(Ee=>Ee instanceof Element?Ee.closest('[data-slot="dropdown-menu-content"], [data-slot="dropdown-menu-item"]')!==null:!1,[]);o.useEffect(()=>{if(!V)return;const Ee=nt=>{F.current>0||q(nt.target)||$.current&&!$.current.contains(nt.target)&&B(!1)};return document.addEventListener("mousedown",Ee),()=>document.removeEventListener("mousedown",Ee)},[q,V]);const[L,Y]=o.useState("edit"),[Z,ae]=o.useState("edit"),[re,me]=o.useState("tree"),[fe,H]=o.useState("edit"),K=o.useRef({}),Q=o.useRef({}),W=o.useRef({}),de=o.useMemo(()=>i.find(Ee=>Ee.metadata.id===l)??hi(!1),[i,l]),be=o.useMemo(()=>i.find(Ee=>Ee.metadata.id===c)??hi(!0),[i,c]);o.useEffect(()=>{gi(de),gi(be)},[de,be]);const we=o.useMemo(()=>[],[]),te=On(Ee=>v?Ee.byRoot[v]?.openPaths??we:we),ge=On(Ee=>v?Ee.byRoot[v]?.selectedPath??null:null),ue=On(Ee=>v?Ee.byRoot[v]?.expandedPaths??we:we),xe=On(Ee=>Ee.addOpenPath),ne=On(Ee=>Ee.removeOpenPath),pe=On(Ee=>Ee.removeOpenPathsByPrefix),J=On(Ee=>Ee.setSelectedPath),Se=On(Ee=>Ee.toggleExpandedPath),he=On(Ee=>Ee.expandPaths),Ie=o.useCallback(Ee=>{const nt=hn(Ee),ct=nt.split("/"),vt=ct[ct.length-1]||nt,qt=vt.includes(".")?vt.split(".").pop()?.toLowerCase():void 0;return{name:vt,path:nt,type:"file",extension:qt}},[]),Pe=o.useMemo(()=>te.map(Ie),[te,Ie]),Ce=o.useMemo(()=>ge??te[0]??null,[te,ge]),X=o.useMemo(()=>Ce?Ie(Ce):null,[Ce,Ie]),ie=X?.path??"",Ne=!!(v&&ie&&!Pl(ie,v)),oe=o.useMemo(()=>({allowOutsideWorkspace:t==="editor-only"&&Ne}),[t,Ne]),ke=o.useRef(null),[Te,Be]=o.useState({left:!1,right:!1}),je=o.useCallback(()=>{const Ee=ke.current;Ee&&Be({left:Ee.scrollLeft>2,right:Ee.scrollLeft+Ee.clientWidth<Ee.scrollWidth-2})},[]),ee=o.useRef(je);ee.current=je,o.useEffect(()=>{const Ee=ke.current;if(!Ee)return;const nt=()=>ee.current();nt(),Ee.addEventListener("scroll",nt,{passive:!0});const ct=new ResizeObserver(nt);return ct.observe(Ee),()=>{Ee.removeEventListener("scroll",nt),ct.disconnect()}},[Pe.length]);const[R,U]=o.useState({}),le=o.useRef(new Set),Me=o.useRef(new Set),Oe=o.useRef(new Map),Ae=o.useRef(0),[z,De]=o.useState([]),[Xe,st]=o.useState(!1),[tt,Ue]=o.useState(""),[it,Ye]=o.useState(!1),[rt,Je]=o.useState(null),[ce,We]=o.useState(""),[Le,Ge]=o.useState(null),[at,He]=o.useState(""),[ze,et]=o.useState(!1),gt=o.useRef(null),Pt=o.useRef(null),Nt=o.useRef(null),ht=o.useRef(0),[wt,es]=o.useState("idle"),[Vt,Jt]=o.useState($2),[mt,Lt]=o.useState(!1),ts=o.useRef(null),js=o.useRef(null),ds=o.useRef(null),hs=o.useRef(!1),Ut=o.useRef(null),Qe=o.useRef(null),At=o.useRef(null),Ht=o.useRef(null),[jt,Zt]=o.useState(0),rs=o.useRef(null),Ds=o.useRef({key:"",attempts:0});o.useEffect(()=>()=>{rs.current!==null&&typeof window<"u"&&(window.cancelAnimationFrame(rs.current),rs.current=null)},[]);const[ns,zs]=o.useState(null),[$s,gn]=o.useState(null),[rn,Wt]=o.useState(""),[Kt,se]=o.useState(!1),[bt,_t]=o.useState(null),[lt,ss]=o.useState(!1),[cs,Ke]=o.useState(!1),[xt,Tt]=o.useState(!1),Et=!!n.writeFile,Qt=!!n.createDirectory,Rt=!!n.rename,Os=!!n.delete,Ts=!!n.revealPath,ks=$r(Ee=>Ee.availableApps),Bs=$r(Ee=>Ee.isCacheStale),ys=$r(Ee=>Ee.initialize),Gn=$r(Ee=>Ee.loadInstalledApps);o.useEffect(()=>{ys()},[ys]);const xn=o.useCallback(Ee=>{n.revealPath&&n.revealPath(Ee).catch(()=>{G.error(e("sidebarFilesTree.toast.revealFailed"))})},[n,e]),ln=o.useCallback(async Ee=>{if(!X?.path||await Tb(X.path,Ee.id,Ee.appName)||await pl(X.path,Ee.appName))return;const vt=A2(X.path)||v;vt&&await pl(vt,Ee.appName)||G.error(e("filesView.toast.openInAppFailed",{app:Ee.appName}))},[v,X?.path,e]),ar=o.useCallback((Ee,nt)=>{zs(Ee),gn(nt),Wt(Ee==="rename"&&nt.name||""),se(!1)},[]),[Us,bn]=o.useState(null),ir=o.useRef(!1),Vn=o.useRef(null),[Mr,Ls]=o.useState(!1),Rs=Re(Ee=>Ee.setMainTabGuard),Ve=Re(Ee=>Ee.pendingFileNavigation),Dt=Re(Ee=>Ee.setPendingFileNavigation),Gt=Re(Ee=>Ee.pendingFileFocusPath),as=Re(Ee=>Ee.setPendingFileFocusPath),_s=Re(Ee=>Ee.shortcutOverrides),qs=yt(Ee=>Ee.settingsDefaultFileViewerPreview);o.useEffect(()=>{const Ee=()=>{ir.current=!1,Vn.current=null,Ls(!1)};return document.addEventListener("mouseup",Ee),()=>document.removeEventListener("mouseup",Ee)},[]),o.useEffect(()=>()=>{Ut.current!==null&&window.clearTimeout(Ut.current),Qe.current!==null&&window.clearTimeout(Qe.current)},[]);const Ws=o.useCallback((Ee,nt)=>{const ct=Ee.split(`
|
|
48
|
-
`),vt=Math.max(1,nt.start),qt=Math.min(ct.length,nt.end);return vt>qt?"":ct.slice(vt-1,qt).join(`
|
|
49
|
-
`)},[]),Zs=Yd({source:"file",fileLabel:X?.path??null,language:X?.path&&xi(X.path)||"text",getCodeForRange:Ee=>Ws(tt,Sl(Ee)),toStoreRange:Ee=>({startLine:Ee.start,endLine:Ee.end}),fromDraftRange:Ee=>({start:Ee.startLine,end:Ee.endLine})}),{drafts:tn,commentText:or,editingDraftId:tr,setSelection:Kr,saveComment:zr,cancel:In,reset:cn,startEdit:pn,deleteDraft:yn}=Zs;o.useEffect(()=>{bn(null),cn(),Rs(null),He(""),et(!1)},[X?.path,cn,Rs]),o.useEffect(()=>{Kr(Us)},[Us,Kr]),o.useEffect(()=>{if(!Us&&!tr)return;const Ee=ct=>{const vt=ct.target;vt.closest('[data-comment-input="true"]')||vt.closest('[data-comment-card="true"]')||vt.closest(".cm-gutterElement")||vt.closest("[data-sonner-toast]")||vt.closest("[data-sonner-toaster]")||(bn(null),In())},nt=setTimeout(()=>{document.addEventListener("click",Ee)},100);return()=>{clearTimeout(nt),document.removeEventListener("click",Ee)}},[In,tr,Us]);const Nn=o.useCallback((Ee,nt)=>{const ct=nt??Us??void 0;nt&&bn(nt),zr(Ee,ct),bn(null)},[Us,zr]),wr=o.useCallback((Ee,nt)=>{const ct=[];for(const vt of nt){if(!(vt&&typeof vt.name=="string"&&vt.name.length>0)||!f&&vt.name.startsWith(".")||!b&&F2(vt.name))continue;const qt=vt.name,Xt=hn(vt.path||""),Ms=Xt?M2(Xt)?Xt:hn(`${Ee}/${Xt}`):hn(`${Ee}/${qt}`),Js=vt.isDirectory?"directory":"file",Un=Js==="file"&&qt.includes(".")?qt.split(".").pop()?.toLowerCase():void 0;ct.push({name:qt,path:Ms,type:Js,extension:Un})}return T2(ct)},[b,f]),vn=o.useCallback(async Ee=>{const nt=hn(Ee.trim());if(!nt||le.current.has(nt)||Me.current.has(nt))return;Me.current=new Set(Me.current),Me.current.add(nt);const ct=Ae.current+1;Ae.current=ct,Oe.current=new Map(Oe.current),Oe.current.set(nt,ct);const vt=()=>Oe.current.get(nt)===ct,qt=!b;await(r.isDesktop?n.listDirectory(nt,{respectGitignore:qt}).then(Ms=>Ms.entries.map(Js=>({name:Js.name,path:Js.path,isDirectory:Js.isDirectory}))):nn.listLocalDirectory(nt,{respectGitignore:qt}).then(Ms=>Ms.map(Js=>({name:Js.name,path:Js.path,isDirectory:Js.isDirectory})))).then(Ms=>{if(!vt())return;const Js=wr(nt,Ms);le.current=new Set(le.current),le.current.add(nt),U(Un=>({...Un,[nt]:Js}))}).catch(()=>{vt()&&U(Ms=>({...Ms,[nt]:Ms[nt]??[]}))}).finally(()=>{vt()&&(Oe.current=new Map(Oe.current),Oe.current.delete(nt),Me.current=new Set(Me.current),Me.current.delete(nt))})},[n,wr,r.isDesktop,b]),Ur=o.useCallback(async()=>{v&&(le.current=new Set,Me.current=new Set,Oe.current=new Map,U(Ee=>Object.keys(Ee).length===0?Ee:{}),await vn(v))},[vn,v]),lr=o.useCallback(async Ee=>{if(!Ee){await Ur();return}const nt=hn(Ee);le.current=new Set(le.current),le.current.delete(nt),Me.current=new Set(Me.current),Me.current.delete(nt),await vn(nt)},[vn,Ur]),zn=o.useRef(""),Ya=o.useRef("");o.useEffect(()=>{if(!v)return;const Ee=`${v}|h${f?"1":"0"}|g${b?"1":"0"}`,nt=zn.current!==v,ct=Ya.current!==Ee;!nt&&!ct||(nt&&(zn.current=v,Ue(""),Je(null),We(""),Ge(null),T(!1)),ct&&(Ya.current=Ee,le.current=new Set,Me.current=new Set,Oe.current=new Map,U(vt=>Object.keys(vt).length===0?vt:{}),vn(v)))},[vn,v,b,f]),o.useEffect(()=>{if(!n.listDirectory)return;const Ee=()=>{if(!document.hidden&&ue.length>0)for(const nt of ue)lr(nt)};return document.addEventListener("visibilitychange",Ee),()=>document.removeEventListener("visibilitychange",Ee)},[ue,n.listDirectory,lr]),o.useEffect(()=>{if(!n.listDirectory||ue.length===0)return;const Ee=setInterval(()=>{if(!document.hidden)for(const nt of ue)lr(nt)},8e3);return()=>clearInterval(Ee)},[ue,n.listDirectory,lr]);const xa=o.useCallback(async Ee=>{if(Ee?.preventDefault(),!$s||!ns)return;se(!0);const nt=()=>{zs(null)},ct=qt=>{G.error(qt)},vt=()=>{se(!1)};if(ns==="createFile"){if(!rn.trim()){ct(e("sidebarFilesTree.toast.filenameRequired")),vt();return}if(!n.writeFile){ct(e("sidebarFilesTree.toast.writeNotSupported")),vt();return}const qt=$s.path,Xt=qt?`${qt}/`:"",Ms=hn(`${Xt}${rn.trim()}`);await n.writeFile(Ms,"").then(async Js=>{Js.success&&(G.success(e("sidebarFilesTree.toast.fileCreated")),await lr(qt)),nt()}).catch(()=>ct(e("sidebarFilesTree.toast.operationFailed"))).finally(vt);return}if(ns==="createFolder"){if(!rn.trim()){ct(e("sidebarFilesTree.toast.folderNameRequired")),vt();return}const qt=$s.path,Xt=qt?`${qt}/`:"",Ms=hn(`${Xt}${rn.trim()}`);await n.createDirectory(Ms).then(async Js=>{Js.success&&(G.success(e("sidebarFilesTree.toast.folderCreated")),await lr(qt)),nt()}).catch(()=>ct(e("sidebarFilesTree.toast.operationFailed"))).finally(vt);return}if(ns==="rename"){if(!rn.trim()){ct(e("sidebarFilesTree.toast.nameRequired")),vt();return}if(!n.rename){ct(e("sidebarFilesTree.toast.renameNotSupported")),vt();return}const qt=$s.path,Xt=qt.split("/").slice(0,-1).join("/"),Ms=Xt?`${Xt}/`:"",Js=hn(`${Ms}${rn.trim()}`);await n.rename(qt,Js).then(async Un=>{Un.success&&(G.success(e("sidebarFilesTree.toast.renamedSuccessfully")),await lr(Xt),v&&pe(v,qt),(X?.path===qt||X?.path.startsWith(`${qt}/`))&&(v&&J(v,null),Ue(""),Je(null),We(""),Ge(null),d&&T(!1))),nt()}).catch(()=>ct(e("sidebarFilesTree.toast.operationFailed"))).finally(vt);return}if(ns==="delete"){if(!n.delete){ct(e("sidebarFilesTree.toast.deleteNotSupported")),vt();return}const qt=$s.path,Xt=qt.split("/").slice(0,-1).join("/");await n.delete(qt).then(async Ms=>{Ms.success&&(G.success(e("sidebarFilesTree.toast.deletedSuccessfully")),await lr(Xt),v&&pe(v,qt),(X?.path===qt||X?.path.startsWith(`${qt}/`))&&(v&&J(v,null),Ue(""),Je(null),We(""),Ge(null),d&&T(!1))),nt()}).catch(()=>ct(e("sidebarFilesTree.toast.operationFailed"))).finally(vt);return}vt()},[ns,$s,rn,n,lr,d,pe,v,X?.path,J,e]);o.useEffect(()=>{if(!g){De([]),st(!1);return}const Ee=w.trim();if(!Ee){De([]),st(!1);return}let nt=!1;return st(!0),j(g,Ee,150,{includeHidden:f,respectGitignore:!b,type:"file"}).then(ct=>{if(nt)return;const qt=ct.filter(Xt=>b||!O2(Xt.path)).map(Xt=>({name:Xt.name,path:hn(Xt.path),type:"file",extension:Xt.extension,relativePath:Xt.relativePath}));De(qt)}).catch(()=>{nt||De([])}).finally(()=>{nt||st(!1)}),()=>{nt=!0}},[g,w,j,f,b]);const ba=o.useCallback(async(Ee,nt)=>{if(n.readFile)return(await n.readFile(Ee,nt)).content??"";const ct=new URLSearchParams({path:Ee});nt?.allowOutsideWorkspace&&ct.set("allowOutsideWorkspace","true"),nt?.optional&&ct.set("optional","true");const vt=await fetch(`/api/fs/read?${ct.toString()}`,{cache:nt?.optional?"no-store":"default"});if(!vt.ok){const qt=await vt.json().catch(()=>({error:vt.statusText}));throw new Error(qt.error||e("filesView.error.readFileFailed"))}return vt.text()},[n,e]),dn=o.useCallback(async(Ee,nt)=>{if(n.statFile){const ct=await n.statFile(Ee,nt);return{path:ct.path,size:ct.size,mtimeMs:ct.mtimeMs}}return null},[n]);o.useEffect(()=>{if(!v||!n.statFile||te.length===0)return;let Ee=!1;const nt=[...te];return Promise.all(nt.map(async ct=>{try{const vt=await n.statFile?.(ct);!Ee&&vt&&!vt.isFile&&pe(v,ct)}catch(vt){!Ee&&np(vt)&&pe(v,ct)}})),()=>{Ee=!0}},[n,te,pe,v]);const jr=o.useMemo(()=>tt.length>Oi?`${tt.slice(0,Oi)}
|
|
50
|
-
|
|
51
|
-
… truncated …`:tt,[tt]),un=at!==jr,cr=o.useCallback(async()=>{if(!X||!n.writeFile)return G.error(e("filesView.toast.savingNotSupported")),!1;if(!un)return!0;et(!0);try{return(await n.writeFile(X.path,at))?.success?(Ue(at),dn(X.path).then(nt=>{nt&&(Nt.current=nt)}).catch(()=>{}),!0):(G.error(e("filesView.toast.writeFileFailed")),!1)}catch(Ee){return G.error(Ee instanceof Error?Ee.message:e("filesView.toast.saveFailed")),!1}finally{et(!1)}},[at,n,un,dn,X,e]);o.useEffect(()=>{if(!un){Rs(null);return}const Ee=nt=>hs.current?(hs.current=!1,!0):(Lt(!0),js.current=nt,!1);return Rs(Ee),()=>{Re.getState().mainTabGuard===Ee&&Rs(null)}},[un,Rs]),o.useEffect(()=>{try{window.localStorage.setItem(ng,Vt?"true":"false")}catch{}},[Vt]),o.useEffect(()=>{Vt||(es("idle"),Pt.current&&(clearTimeout(Pt.current),Pt.current=null))},[Vt]);const Hr=1500;o.useEffect(()=>{const Ee=!!(X&&n.writeFile);if(!(!Vt||!un||!Ee||ze))return Pt.current=setTimeout(()=>{cr().then(nt=>{nt&&(es("saved"),setTimeout(()=>es("idle"),2e3))})},Hr),()=>{Pt.current&&(clearTimeout(Pt.current),Pt.current=null)}},[Vt,at,un,X,n.writeFile,ze,cr]),o.useEffect(()=>{es("idle")},[X?.path]),o.useEffect(()=>{const Ee=nt=>{Rd(nt)&&(nt.key.toLowerCase()==="s"?(nt.preventDefault(),Pt.current&&(clearTimeout(Pt.current),Pt.current=null),ze||cr().then(ct=>{ct&&(es("saved"),setTimeout(()=>es("idle"),2e3))})):nt.key.toLowerCase()==="f"&&(nt.preventDefault(),O(!0)))};return window.addEventListener("keydown",Ee),()=>window.removeEventListener("keydown",Ee)},[ze,cr]);const ia=o.useCallback(async Ee=>{const nt=ht.current+1;ht.current=nt;const ct=()=>{if(!v)return!1;const Ms=On.getState().byRoot[v],Js=Ms?.selectedPath??Ms?.openPaths[0]??null;return ht.current===nt&&Js===Ee.path};Je(null),We(""),Ge(null);const vt=bi(Ee.path),qt=Ee.path.toLowerCase().endsWith(".svg");if(d&&T(!0),r.isDesktop&&vt&&!qt){Ue(""),He(""),Ye(!0);return}if(!r.isDesktop&&vt&&!qt){Ue(""),He(""),Ge(Ee.path),Ye(!1);return}Ye(!0);const Xt={allowOutsideWorkspace:t==="editor-only"&&!!v&&!Pl(Ee.path,v)};await ba(Ee.path,Xt).then(Ms=>{ct()&&(Ue(Ms),He(Ms.length>Oi?`${Ms.slice(0,Oi)}
|
|
52
|
-
|
|
53
|
-
… truncated …`:Ms),Ge(Ee.path),dn(Ee.path,Xt).then(Js=>{Js&&ct()&&(Nt.current=Js)}).catch(()=>{}))}).catch(Ms=>{if(ct()){if(L2(Ms)){if(Ye(!1),v&&J(v,null),Je(null),Ue(""),He(""),Ge(null),Nt.current=null,C.trim().length>0&&k(""),d&&T(!1),v){const Un=[...tp(Ee.path,v),Ee.path];Un.length>0&&he(v,Un);for(const So of Un)le.current.has(So)||vn(So)}return}if(np(Ms)){v&&pe(v,Ee.path),Ue(""),He(""),Je(null),Nt.current=null,d&&T(!1);return}Ue(""),He(""),Je(Ms instanceof Error?Ms.message:e("filesView.error.readFileFailed")),Nt.current=null}}).finally(()=>{ct()&&Ye(!1)})},[he,d,vn,t,ba,dn,pe,v,r.isDesktop,C,J,e]),Nr=o.useCallback(async(Ee,nt)=>{if(!v)return;const ct=tp(Ee,v),vt=nt?[...ct,Ee]:ct;vt.length>0&&he(v,vt);const qt=vt.map(Xt=>{if(!le.current.has(Xt))return vn(Xt)}).filter(Boolean);await Promise.all(qt)},[he,vn,v]),Qa=o.useCallback((Ee,nt)=>{const ct=nt.findIndex(vt=>vt.path===Ee);return ct===-1||nt.length<=1?null:nt[ct+1]??nt[ct-1]??null},[]),wn=o.useCallback(async Ee=>{if(hs.current)hs.current=!1;else if(un){Lt(!0),ts.current=Ee;return}v&&(J(v,Ee.path),xe(v,Ee.path),Nr(Ee.path,!1)),Je(null),We(""),Ue(""),He(""),Ge(null),d&&T(!0)},[xe,Nr,un,d,v,J]);o.useEffect(()=>{X?.path&&Nr(X.path,!1)},[Nr,X?.path]),o.useEffect(()=>{if(!X){ht.current+=1,Ye(!1);return}Le!==X.path&&ia(X)},[ia,Le,X]);const Ii=o.useRef(un);Ii.current=un,o.useEffect(()=>{if(!X?.path||Le!==X.path)return;let Ee=!1;const nt=window.setInterval(()=>{document.hidden||dn(X.path,oe).then(ct=>{if(Ee||!ct)return;const vt=Nt.current;if(!vt||vt.path!==X.path){Nt.current=ct;return}const qt=ct.mtimeMs!==void 0&&vt.mtimeMs!==void 0&&ct.mtimeMs!==vt.mtimeMs,Xt=ct.size!==vt.size;!qt&&!Xt||Ii.current||(Nt.current=ct,Ge(null))}).catch(()=>{})},2e3);return()=>{Ee=!0,window.clearInterval(nt)}},[Le,dn,X?.path,oe]);const No=o.useCallback(()=>{const Ee=ts.current,nt=js.current,ct=ds.current;if(ts.current=null,js.current=null,ds.current=null,hs.current=!0,Lt(!1),He(jr),ct){v&&ne(v,ct),X?.path===ct&&(Ee?wn(Ee):(v&&J(v,null),Ue(""),Je(null),We(""),Ge(null),d&&T(!1)));return}if(Ee){wn(Ee);return}nt&&(Rs(null),Re.getState().setActiveMainTab(nt))},[jr,wn,d,ne,v,X?.path,Rs,J]),oa=o.useCallback(async()=>{const Ee=ts.current,nt=js.current,ct=ds.current;if(!await cr()){hs.current=!1;return}if(ts.current=null,js.current=null,ds.current=null,hs.current=!0,Lt(!1),ct){v&&ne(v,ct),X?.path===ct&&(Ee?await wn(Ee):(v&&J(v,null),Ue(""),Je(null),We(""),Ge(null),d&&T(!1)));return}if(Ee){await wn(Ee);return}nt&&(Rs(null),Re.getState().setActiveMainTab(nt))},[wn,d,ne,v,cr,X?.path,Rs,J]),dr=o.useCallback(Ee=>{const nt=X?.path===Ee,ct=Qa(Ee,Pe);if(nt&&un){Lt(!0),ts.current=ct,ds.current=Ee;return}if(v&&ne(v,Ee),!!nt){if(ct){wn(ct);return}v&&J(v,null),Ue(""),Je(null),We(""),Ge(null),d&&T(!1)}},[Qa,wn,un,d,Pe,ne,v,X?.path,J]),Dn=o.useCallback(Ee=>{if(te.includes(Ee))return"open";if(y?.files){const nt=Ee.startsWith(v+"/")?Ee.slice(v.length+1):Ee,ct=y.files.find(vt=>vt.path===nt);if(ct){if(ct.index==="A"||ct.working_dir==="?")return"git-added";if(ct.index==="D")return"git-deleted";if(ct.index==="M"||ct.working_dir==="M")return"git-modified"}}return null},[te,y,v]),Er=o.useCallback(Ee=>{if(!y?.files)return null;const nt=Ee.startsWith(v+"/")?Ee.slice(v.length+1):Ee,ct=nt?`${nt}/`:"";let vt=0,qt=0;for(const Xt of y.files)Xt.path.startsWith(ct)&&((Xt.index==="M"||Xt.working_dir==="M")&&vt++,(Xt.index==="A"||Xt.working_dir==="?")&&qt++);return vt+qt>0?{modified:vt,added:qt}:null},[y,v]),Ja=o.useCallback(async Ee=>{const nt=hn(Ee);v&&(Se(v,nt),le.current.has(nt)||await vn(nt))},[vn,v,Se]),Gr=o.useMemo(()=>({canRename:Rt,canCreateFile:Et,canCreateFolder:Qt,canDelete:Os,canReveal:Ts}),[Rt,Et,Qt,Os,Ts]);function Xa(Ee,nt){const ct=R[Ee]??[];return ct.map((vt,qt)=>{const Xt=vt.type==="directory",Ms=Xt&&ue.includes(vt.path),Js=X?.path===vt.path,Un=qt===ct.length-1;return s.jsxs("li",{className:"relative",children:[nt>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(V2,{node:vt,root:v,isExpanded:Ms,isActive:Js,isMobile:d,alwaysShowActions:u,status:Xt?void 0:Dn(vt.path),badge:Xt?Er(vt.path):void 0,permissions:Gr,downloadFile:n.downloadFile,contextMenuPath:bt,setContextMenuPath:_t,onSelect:wn,onToggle:Ja,onRevealPath:xn,onOpenDialog:ar}),Xt&&Ms&&s.jsx("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:Xa(vt.path,nt+1)})]},vt.path)})}const Tn=!!(X?.path&&bi(X.path)),Rr=!!(X?.path&&X.path.toLowerCase().endsWith(".svg")),qr=o.useMemo(()=>hn(Ve?.path??""),[Ve?.path]),Ys=!!(Ve&&qr&&ie&&ie===qr&&!it&&!rt&&!Tn),Fr=o.useMemo(()=>hd(v,ie),[ie,v]),ya=!!(X&&(!Tn||Rr)&&tt.length>0),Pi=!!(X&&Fr.length>0),Fe=!!(X&&!Ne&&!Tn&&n.writeFile&&tt.length<=Oi),qe=!!(X?.path&&_2(X.path)),Ze=!!(X?.path&&B2(X.path)),dt=!!(X?.path&&Cc(X.path)),zt=!!(X&&!Tn)&&!qe&&!(dt&&fe==="preview"),Vs=o.useMemo(()=>ie?xl(ie):null,[ie]),[Fs,Pn]=o.useState(null);o.useEffect(()=>{let Ee=!1;const nt=X?.path;if(!nt||Vs){Pn(null);return}return Pn(null),Mb(nt).then(ct=>{Ee||Pn(ct)}),()=>{Ee=!0}},[X?.path,Vs]),o.useEffect(()=>{!Fe&&L==="edit"&&Y("view")},[Fe,L]);const va="openchamber:files:md-viewer-mode",Ai="openchamber:files:html-viewer-mode",wa="openchamber:files:json-viewer-mode";o.useEffect(()=>{const Ee=X?.path;if(!Ee)return;const nt=qs?"view":"edit";Y(K.current[Ee]??nt);let ct=qs?"preview":"edit";try{const Xt=localStorage.getItem(va);(Xt==="preview"||Xt==="edit")&&(ct=Xt)}catch{}ae(Q.current[Ee]??ct);let vt=qs?"preview":"edit";try{const Xt=localStorage.getItem(Ai);(Xt==="preview"||Xt==="edit")&&(vt=Xt)}catch{}H(W.current[Ee]??vt);let qt=qs?"tree":"text";try{const Xt=localStorage.getItem(wa);(Xt==="tree"||Xt==="text")&&(qt=Xt)}catch{}me(qt)},[X?.path,qs]);const $e=o.useCallback(Ee=>{const nt=X?.path;nt&&(K.current[nt]=Ee),Y(Ee)},[X?.path]),St=o.useCallback(Ee=>{const nt=X?.path;nt&&(Q.current[nt]=Ee),ae(Ee);try{localStorage.setItem(va,Ee)}catch{}},[X?.path]),ft=o.useCallback(()=>Z,[Z]),Yt=o.useCallback(Ee=>{me(Ee);try{localStorage.setItem(wa,Ee)}catch{}},[]),vs=o.useCallback(Ee=>{const nt=X?.path;nt&&(W.current[nt]=Ee),H(Ee);try{localStorage.setItem(Ai,Ee)}catch{}},[X?.path]),sn=o.useCallback(()=>fe,[fe]);o.useEffect(()=>{if(!Ve||!v)return;const Ee=()=>{typeof window>"u"||rs.current===null&&(rs.current=window.requestAnimationFrame(()=>{rs.current=null,Zt(Yr=>Yr+1)}))},nt=(Yr,ja)=>{if(Yr.state.doc.length!==ja.length)return!1;if(ja.length===0)return!0;const Yl=Math.min(128,ja.length);if(Yr.state.sliceDoc(0,Yl)!==ja.slice(0,Yl))return!1;const mu=Math.max(0,ja.length-Yl);return Yr.state.sliceDoc(mu,ja.length)===ja.slice(mu)},ct=hn(Ve.path);if(!ct){Dt(null),Ds.current={key:"",attempts:0};return}const vt=`${ct}:${Ve.line}:${Ve.column??1}`;if(Ds.current.key!==vt&&(Ds.current={key:vt,attempts:0}),X?.path!==ct){if(mt)return;wn(Ie(ct));return}if(it||Le!==ct)return;if(rt||Tn){Dt(null),Ds.current={key:"",attempts:0};return}if(!Fe)return;if(L!=="edit"){Y("edit");return}const qt=At.current;if(!qt){Ee();return}if(!nt(qt,at)){Ee();return}const Xt=Math.max(1,Math.min(Ve.line,qt.state.doc.lines)),Ms=qt.state.doc.line(Xt),Js=Math.max(1,Ve.column||1),Un=Math.max(0,Ms.to-Ms.from),So=Math.min(Un,Js-1),Mi=Ms.from+So;if(!(qt.state.selection.main.head===Mi)||Ds.current.attempts===0){Ds.current.attempts+=1,qt.dispatch({selection:{anchor:Mi},effects:$n.scrollIntoView(Mi,{y:"center"})}),qt.focus(),Ee();return}typeof window<"u"&&window.requestAnimationFrame(()=>{const Yr=At.current;Yr&&(Yr.dispatch({selection:{anchor:Mi},effects:$n.scrollIntoView(Mi,{y:"center"})}),Yr.focus())}),Dt(null),Ds.current={key:"",attempts:0}},[Fe,mt,at,jt,rt,it,Tn,Le,wn,Ve,v,X?.path,Dt,L,Ie]),o.useEffect(()=>{if(!Gt||!v)return;const Ee=hn(Gt);if(!Ee){as(null);return}if(X?.path!==Ee){if(mt)return;wn(Ie(Ee));return}if(!(it||Le!==Ee||rt||Tn)){if(Fe&&L==="edit"){const nt=At.current;if(!nt)return;nt.focus()}as(null)}},[Fe,mt,rt,it,wn,Tn,Le,Gt,v,X?.path,as,L,Ie]);const fn=o.useCallback(Ee=>{if(!d||!Ee||!Ee.hasFocus||typeof window>"u")return;const nt=window.visualViewport;if(!nt)return;const ct=document.documentElement.clientHeight||window.innerHeight;if(Math.max(0,ct-(nt.offsetTop+nt.height))<=0)return;const qt=Ee.state.selection.main.head,Xt=Ee.coordsAtPos(qt);if(!Xt)return;const Ms=Math.round(nt.offsetTop+nt.height),Un=Xt.bottom+20-Ms;Un<=0||(Ee.scrollDOM.scrollTop+=Un)},[d]);o.useEffect(()=>{if(!d||typeof window>"u")return;const Ee=()=>{window.requestAnimationFrame(()=>{fn(At.current)})},nt=window.visualViewport;return nt?.addEventListener("resize",Ee),nt?.addEventListener("scroll",Ee,{passive:!0}),document.addEventListener("selectionchange",Ee),()=>{nt?.removeEventListener("resize",Ee),nt?.removeEventListener("scroll",Ee),document.removeEventListener("selectionchange",Ee)}},[d,fn]),o.useEffect(()=>{if(!Fe||L!=="edit"||d)return;const Ee=Zr("open_go_to_line",_s),nt=ct=>{const vt=ct.target;if(vt?.closest('[role="dialog"]'))return;const qt=!!vt?.closest(".cm-editor");vt?.closest('input, textarea, [contenteditable="true"], [role="textbox"]')&&!qt||!document.activeElement?.closest(".cm-editor")||qo(ct,Ee)&&(ct.preventDefault(),Tt(!0))};return window.addEventListener("keydown",nt),()=>window.removeEventListener("keydown",nt)},[Fe,d,_s,L]);const Sr=o.useMemo(()=>{if(!X?.path)return[fo(a)];const Ee=[fo(a)],nt=Vs??Fs;return nt&&Ee.push(nt),P&&Ee.push($n.lineWrapping),d&&Ee.push($n.updateListener.of(ct=>{ct.view.hasFocus&&(ct.selectionSet||ct.focusChanged||ct.viewportChanged||ct.geometryChanged)&&window.requestAnimationFrame(()=>{fn(ct.view)})})),Ee},[a,X?.path,Vs,Fs,P,d,fn]),sr=o.useMemo(()=>({light:de.metadata.id,dark:be.metadata.id}),[de.metadata.id,be.metadata.id]),Mn=X?.path&&Tn?r.isDesktop?Rr?`data:${Pu(X.path)};utf8,${encodeURIComponent(tt)}`:ce:Rr?`data:${Pu(X.path)};utf8,${encodeURIComponent(tt)}`:`/api/fs/raw?${new URLSearchParams({path:X.path,...oe.allowOutsideWorkspace?{allowOutsideWorkspace:"true"}:{}}).toString()}`:"";o.useEffect(()=>{let Ee=!1;return(async()=>{if(!r.isDesktop||!X?.path||!Tn||Rr){We("");return}Je(null),await(n.readFileBinary?n.readFileBinary(X.path,oe).then(vt=>vt.dataUrl):Promise.resolve(Ix(X.path,"asset"))).then(vt=>{Ee||(We(vt),Ge(X.path))}).catch(vt=>{Ee||(We(""),Je(vt instanceof Error?vt.message:e("filesView.error.readFileFailed")),Ge(null))}).finally(()=>{Ee||Ye(!1)})})(),()=>{Ee=!0}},[n,Tn,Rr,r.isDesktop,X?.path,oe,e]);const En=o.useCallback(()=>zs(null),[]),Di=o.useMemo(()=>Wh({drafts:tn,editingDraftId:tr,commentText:or,selection:Us,isDragging:Mr,fileLabel:X?.path??"",newWidgetId:"files-new-comment-input",mapDraftToRange:Ee=>({start:Ee.startLine,end:Ee.endLine}),onSave:Nn,onCancel:()=>{bn(null),In()},onEdit:Ee=>{pn(Ee),bn({start:Ee.startLine,end:Ee.endLine})},onDelete:yn}),[In,or,yn,tr,tn,Nn,Mr,Us,X?.path,pn]),Ti=o.useCallback((Ee,nt)=>s.jsx("div",{className:"h-full",children:s.jsx(Cx,{file:{name:Ee.name,contents:nt,lang:xi(Ee.path)||void 0},options:{disableFileHeader:!0,overflow:P?"wrap":"scroll",theme:sr,themeType:a.metadata.variant==="dark"?"dark":"light"},className:"block h-full w-full",style:{height:"100%"}})}),[a.metadata.variant,sr,P]),du=({exitFullscreenOnly:Ee=!1}={})=>{if(!X)return null;const nt=(ct,vt)=>s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:vt})}),s.jsx(It,{side:"bottom",sideOffset:6,children:ct})]});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:[Fe&&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(D,{name:"loader-4",className:"size-3.5 animate-spin"}),e("filesView.editor.saving")]}):Vt&&wt==="saved"&&!un?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-[color:var(--status-success)] typography-meta",children:[s.jsx(D,{name:"check",className:"size-3.5"}),e("filesView.editor.saved")]}):un?nt(e(Vt?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:`${Gi()}+S`}),s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>{cr()},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:`${Gi()}+S`}),"aria-label":e("filesView.editor.saveAria",{shortcut:`${Gi()}+S`}),children:s.jsx(D,{name:"save-3",className:"size-4"})})):null,nt(e(Vt?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>Jt(ct=>!ct),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(D,{name:"file-check-fill",className:"size-4"}):s.jsx(D,{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(ve,{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(D,{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:[ks.map(ct=>s.jsxs(Ot,{className:"flex items-center gap-2",onClick:()=>{ln(ct)},children:[s.jsx(D2,{label:ct.label,iconDataUrl:ct.iconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:ct.label})]},ct.id)),Bs?s.jsxs(Ot,{className:"flex items-center gap-2",onClick:()=>{Gn(!0)},children:[s.jsx(D,{name:"refresh",className:"size-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:e("filesView.editor.refreshApps")})]}):null]})]}),!Tn&&s.jsxs(s.Fragment,{children:[nt(e(P?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>A(!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(D,{name:"text-wrap",className:"size-4"})})),L==="edit"&&s.jsxs(s.Fragment,{children:[nt(e("filesView.editor.findInFile"),s.jsx(ve,{variant:"ghost",size:"sm",onClick:ct=>{O(!M),ct.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(D,{name:"search",className:"size-4"})})),nt(e("filesView.editor.goToLine"),s.jsx(ve,{variant:"ghost",size:"sm",onClick:ct=>{Tt(vt=>!vt),ct.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(D,{name:"menu-fold-2",className:"size-4"})})),s.jsx(P2,{open:xt,onOpenChange:Tt,view:At.current,variant:"inline"})]})]}),zt&&Fe&&!Ze&&!dt&&s.jsx(Il,{currentMode:L==="view"?"preview":"edit",onToggle:()=>{$e(L==="view"?"edit":"view")}}),(qe||Cc(X?.path??""))&&s.jsx(Il,{currentMode:qe?ft():sn(),onToggle:()=>{Cc(X?.path??"")?vs(sn()==="preview"?"edit":"preview"):St(ft()==="preview"?"edit":"preview")}}),Ze&&nt(e(re==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>Yt(re==="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(re==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),children:re==="tree"?s.jsx(D,{name:"code-sslash",className:"size-4"}):s.jsx(D,{name:"node-tree",className:"size-4"})})),ya&&nt(e("filesView.editor.copyFileContents"),s.jsx(ve,{variant:"ghost",size:"sm",onClick:async()=>{(await Rn(tt)).ok?(ss(!0),Ut.current!==null&&window.clearTimeout(Ut.current),Ut.current=window.setTimeout(()=>{ss(!1)},1200)):G.error(e("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.copyFileContents"),"aria-label":e("filesView.editor.copyFileContents"),children:lt?s.jsx(D,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(D,{name:"clipboard",className:"size-4"})})),Pi&&nt(e("filesView.editor.copyFilePathTitle",{path:Fr}),s.jsx(ve,{variant:"ghost",size:"sm",onClick:async()=>{(await Rn(Fr)).ok?(Ke(!0),Qe.current!==null&&window.clearTimeout(Qe.current),Qe.current=window.setTimeout(()=>{Ke(!1)},1200)):G.error(e("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.copyFilePathTitle",{path:Fr}),"aria-label":e("filesView.editor.copyFilePathTitle",{path:Fr}),children:cs?s.jsx(D,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(D,{name:"file-copy-2",className:"size-4"})})),n.downloadFile&&nt(e("filesView.editor.saveFile"),s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>{const ct=n.downloadFile;ct&&ct(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(D,{name:"download",className:"size-4"})})),Ee?nt(e("filesView.editor.exitFullscreen"),s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>E(!1),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.exitFullscreen"),"aria-label":e("filesView.editor.exitFullscreen"),children:s.jsx(D,{name:"fullscreen-exit",className:"size-4"})})):!d&&t==="full"&&nt(e(N?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>E(!N),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e(N?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),"aria-label":e(N?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),children:N?s.jsx(D,{name:"fullscreen-exit",className:"size-4"}):s.jsx(D,{name:"fullscreen",className:"size-4"})}))]})},ql=s.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden",children:[s.jsx(ps,{open:mt,onOpenChange:Ee=>{Ee||Lt(!0)},children:s.jsxs(ms,{showCloseButton:!1,className:"max-w-md",children:[s.jsxs(gs,{children:[s.jsx(fs,{children:e("filesView.unsaved.title")}),s.jsx(Ns,{children:e("filesView.unsaved.description")})]}),s.jsxs(Hs,{children:[s.jsx(ve,{variant:"outline",onClick:()=>{oa()},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(ve,{variant:"destructive",onClick:No,children:e("filesView.unsaved.discard")})]})]})}),s.jsx("div",{className:ye("flex flex-col flex-shrink-0",x&&"border-b border-border/40"),children:x?s.jsxs("div",{className:"flex min-w-0 items-center px-3 py-1.5",children:[d&&I&&s.jsx("button",{type:"button",onClick:()=>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(D,{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(Pr,{filePath:X.path,extension:X.extension,className:"size-3.5 flex-shrink-0"}),s.jsx(sp,{name:X.name}),s.jsx(D,{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:Pe.map(Ee=>{const nt=X?.path===Ee.path;return s.jsxs(Ot,{onSelect:ct=>{if(ct.target.closest("[data-close-open-file]")){ct.preventDefault();return}nt||wn(Ee)},className:ye("flex min-w-0 items-center justify-between gap-2 overflow-hidden",nt&&"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(Pr,{filePath:Ee.path,extension:Ee.extension,className:"size-3.5 flex-shrink-0"}),s.jsx(sp,{name:Ee.name})]}),s.jsx("button",{type:"button","data-close-open-file":!0,onPointerDown:ct=>{ct.preventDefault(),ct.stopPropagation()},onClick:ct=>{ct.preventDefault(),ct.stopPropagation(),dr(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(D,{name:"close",className:"size-3.5"})})]},Ee.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")}):Pe.length>0?s.jsxs("div",{className:"relative min-w-0 flex-1",children:[Te.left&&s.jsx("div",{className:"pointer-events-none absolute left-0 top-0 bottom-0 w-6 z-10 bg-gradient-to-r from-background to-transparent"}),Te.right&&s.jsx("div",{className:"pointer-events-none absolute right-0 top-0 bottom-0 w-6 z-10 bg-gradient-to-l from-background to-transparent"}),s.jsx("div",{ref:ke,className:"flex min-w-0 items-center gap-1 overflow-x-auto scrollbar-none",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:Pe.map(Ee=>{const nt=X?.path===Ee.path;return s.jsxs("div",{title:hd(v,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",nt?"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(Pr,{filePath:Ee.path,extension:Ee.extension,className:"size-3.5 flex-shrink-0"}),s.jsx("button",{type:"button",onClick:()=>{nt||wn(Ee)},className:"max-w-[12rem] truncate text-left",children:Ee.name}),s.jsx("button",{type:"button",onClick:ct=>{ct.stopPropagation(),dr(Ee.path)},className:ye("rounded-sm p-0.5 text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]",!nt&&!u&&"opacity-0 group-hover:opacity-100"),"aria-label":e("filesView.editor.closeFileAria",{name:Ee.name}),children:s.jsx(D,{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&&!M&&s.jsx("div",{ref:$,className:"absolute right-3 top-3 z-30",onMouseEnter:()=>B(!0),onMouseLeave:()=>{F.current>0||B(!1)},children:V?du():s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(ve,{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(D,{name:"more-2-fill",className:"size-4"})})})}),s.jsx(It,{side:"bottom",sideOffset:6,children:e("filesView.editor.controlsTitle")})]})}),s.jsx(ws,{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(D,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.loading")]}):rt?s.jsx("div",{className:"p-3 typography-ui text-[color:var(--status-error)]",children:rt}):Tn?s.jsx("div",{className:"flex h-full items-center justify-center p-3",children:s.jsx("img",{src:Mn,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&&Ze&&re==="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(Eb,{jsonString:tt,maxHeight:"100%",initiallyExpandedDepth:2})})}):X&&qe&&ft()==="preview"?s.jsxs("div",{className:"h-full overflow-auto p-3",children:[tt.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(tt.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(ha,{content:tt,className:"typography-markdown-body",stripFrontmatter:!0})})]}):X&&dt&&fe==="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 tt;const nt=`<base href="${r.isDesktop,Ee}">`;return tt.replace(/<head([^>]*)>/i,`<head$1>${nt}`)})(),className:"w-full h-full border-none",sandbox:"allow-scripts allow-same-origin allow-forms",title:e("filesView.editor.htmlPreviewTitle")})}):X&&zt&&L==="view"?Ti(X,at):s.jsxs("div",{className:ye("relative h-full",Ys&&"overflow-hidden"),ref:Ht,children:[s.jsx("div",{className:ye("h-full",Ys&&"invisible"),children:s.jsx(po,{value:at,onChange:He,readOnly:!Fe,extensions:Sr,className:"h-full",blockWidgets:Di,onViewReady:Ee=>{At.current=Ee,Zt(nt=>nt+1),window.requestAnimationFrame(()=>{fn(Ee)})},onViewDestroy:()=>{At.current&&(At.current=null),Zt(Ee=>Ee+1)},enableSearch:!0,searchOpen:M,onSearchOpenChange:O,highlightLines:Us?{start:Math.min(Us.start,Us.end),end:Math.max(Us.start,Us.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(Ee,nt,ct)=>{if(!(ct instanceof MouseEvent)||ct.button!==0)return!1;ct.preventDefault();const vt=Ee.state.doc.lineAt(nt.from).number;if(d&&Us&&!ct.shiftKey){const qt=Math.min(Us.start,Us.end,vt),Xt=Math.max(Us.start,Us.end,vt);return bn({start:qt,end:Xt}),ir.current=!1,Vn.current=null,Ls(!1),!0}if(ir.current=!0,Vn.current=vt,Ls(!0),Us&&ct.shiftKey){const qt=Math.min(Us.start,vt),Xt=Math.max(Us.end,vt);bn({start:qt,end:Xt})}else bn({start:vt,end:vt});return!0},mouseover:(Ee,nt,ct)=>{if(!(ct instanceof MouseEvent)||ct.buttons!==1||!ir.current||Vn.current===null)return!1;const vt=Ee.state.doc.lineAt(nt.from).number,qt=Math.min(Vn.current,vt),Xt=Math.max(Vn.current,vt);return bn({start:qt,end:Xt}),Ls(!0),!1},mouseup:()=>(ir.current=!1,Vn.current=null,Ls(!1),!1)}}})}),Ys&&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(D,{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")})})]})]}),Jg=!!(v&&R[v]),uu=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(D,{name:"search",className:"pointer-events-none absolute left-2 top-2 size-4 text-muted-foreground"}),s.jsx(Bt,{ref:S,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(""),S.current?.focus()},children:s.jsx(D,{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(ve,{variant:"ghost",size:"sm",onClick:()=>ar("createFile",{path:g,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFileTitle"),"aria-label":e("filesView.tree.actions.newFileTitle"),children:s.jsx(D,{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(ve,{variant:"ghost",size:"sm",onClick:()=>ar("createFolder",{path:g,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFolderTitle"),"aria-label":e("filesView.tree.actions.newFolderTitle"),children:s.jsx(D,{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(ve,{variant:"ghost",size:"sm",onClick:()=>{Ur()},className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.refreshTitle"),"aria-label":e("filesView.tree.actions.refreshTitle"),children:s.jsx(D,{name:"refresh",className:"size-4"})})})}),s.jsx(It,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.refreshTitle")})]})]})}),s.jsx(ws,{outerClassName:"flex-1 min-h-0",className:ye("py-2",d?"px-3":"px-2"),children:s.jsx("ul",{className:"flex flex-col",children:Xe?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.tree.search.searching")]}):z.length>0?z.map(Ee=>{const nt=X?.path===Ee.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>{wn(Ee)},className:ye("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors",nt?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),children:[rg(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)}):Jg?Xa(v,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:e("filesView.state.loading")})})})]}),Xg=t==="full"&&N&&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:du({exitFullscreenOnly:!0})}),s.jsx(ws,{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(D,{name:"loader-4",className:"size-4 animate-spin"}),"Loading…"]}):rt?s.jsx("div",{className:"p-4 typography-ui text-[color:var(--status-error)]",children:rt}):Tn?s.jsx("div",{className:"flex h-full items-center justify-center p-4",children:s.jsx("img",{src:Mn,alt:X.name,className:"max-w-full max-h-full object-contain rounded-md border border-border/30 bg-primary/10"})}):qe&&ft()==="preview"?s.jsxs("div",{className:"h-full overflow-auto p-4",children:[tt.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(tt.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(ha,{content:tt,className:"typography-markdown-body",stripFrontmatter:!0})})]}):zt&&L==="view"?Ti(X,at):s.jsxs("div",{className:ye("relative h-full",Ys&&"overflow-hidden"),children:[s.jsx("div",{className:ye("h-full",Ys&&"invisible"),children:s.jsx(po,{value:at,onChange:He,readOnly:!Fe,extensions:Sr,className:"h-full",onViewReady:Ee=>{At.current=Ee,window.requestAnimationFrame(()=>{fn(Ee)})},onViewDestroy:()=>{At.current&&(At.current=null)}})}),Ys&&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(D,{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(z2,{activeDialog:ns,dialogData:$s,dialogInputValue:rn,onDialogInputChange:Wt,isDialogSubmitting:Kt,onDialogSubmit:xa,onClose:En,inputRef:gt}),Xg,d?I?ql:uu: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:ql})}):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:uu}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden rounded-xl border border-border/60 bg-background",children:ql})]})]})},U2=Object.freeze(Object.defineProperty({__proto__:null,FilesView:ag},Symbol.toStringTag,{value:"Module"})),_r=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},Ic=(t,e)=>{const n=_r(t),r=e.replace(/\\/g,"/").replace(/^\/+/,"").replace(/\/+$/,"");return!n||n==="/"?`/${r}`:`${n}/${r}`},W2=(t,e,n)=>Ic(Ic(Ic(t,".opencode"),"plans"),`${e}-${n}.md`),K2=(t,e)=>`~/.opencode/plans/${t}-${e}.md`,H2=(t,e)=>{const n=t.trim();return n.startsWith("~")?n==="~"?e||n:(n.startsWith("~/")||n.startsWith("~\\"))&&e?`${e}${n.slice(1)}`:n:n},G2=(t,e)=>{const n=_r(e.currentDirectory),r=_r(e.homeDirectory),a=_r(t);return n&&a.startsWith(n+"/")?a.slice(n.length+1):r&&a===r?"~":r&&a.startsWith(r+"/")?`~${a.slice(r.length)}`:a},q2=(t,e,n)=>{const r=_r(t.trim());if(!r)return null;const a=n?e.find(l=>l.id===n)??null:null;if(a?.path){const l=_r(a.path);if(r===l||r.startsWith(`${l}/`))return{id:a.id,path:a.path}}const i=e.filter(l=>{const c=_r(l.path);return r===c||r.startsWith(`${c}/`)}).sort((l,c)=>_r(c.path).length-_r(l.path).length)[0];return i?{id:i.id,path:i.path}:null},ig=({targetPath:t=null})=>{const{t:e}=ut(),n=$t(ee=>ee.currentSessionId),r=$t(ee=>ee.createSession),a=$t(ee=>ee.initializeNewOpenChamberSession),i=$t(ee=>ee.sendMessage),l=$t(ee=>ee.setCurrentSession),c=Vl(),d=Ks(ee=>ee.homeDirectory),p=Ed(ee=>ee.planModeEnabled),m=Cs(ee=>ee.projects),u=Cs(ee=>ee.activeProjectId),f=Qs(ee=>ee.directories),b=ra()??"",g=Re(ee=>ee.setActiveMainTab),v=Re(ee=>ee.setSessionSwitcherOpen),x=Bn(),{isMobile:h}=an(),{currentTheme:j}=vr();o.useMemo(()=>rh(j),[j]);const y=o.useMemo(()=>n?c.find(ee=>ee.id===n)??null:null,[n,c]),C=o.useMemo(()=>{const ee=typeof y?.directory=="string"?y.directory:"";return _r(ee||"")},[y?.directory]),k=o.useMemo(()=>_r(b||C),[b,C]),w=o.useMemo(()=>q2(k,m,u),[u,k,m]),S=o.useMemo(()=>w?f.get(w.path)?.isGitRepo===!0:!1,[w,f]),[I,T]=o.useState(null),[P,A]=o.useState(!1),[N,E]=o.useState(null),M=o.useMemo(()=>!N||!C||!d?N:G2(N,{currentDirectory:C,homeDirectory:d}),[N,C,d]),[O,V]=o.useState(""),[B,$]=o.useState(null),F=o.useMemo(()=>M&&M.split("/").pop()||e("planView.file.defaultName"),[M,e]),_=o.useMemo(()=>O.trim()&&Rb(O).title||e("planView.title.default"),[O,e]),q=o.useMemo(()=>_.trim()||e("planView.title.default"),[_,e]),[L,Y]=o.useState(!1),[Z,ae]=o.useState(!1),[re,me]=o.useState("edit"),fe=o.useRef(null),[H,K]=o.useState(null),Q=o.useRef(null),W=o.useRef(null),de="openchamber:plan:md-viewer-mode";o.useEffect(()=>{try{const ee=localStorage.getItem(de);if(!ee)return;const R=JSON.parse(ee);(R==="preview"||R==="edit")&&me(R)}catch{}},[]);const be=o.useCallback(ee=>{me(ee);try{localStorage.setItem(de,JSON.stringify(ee))}catch{}},[]),we=o.useRef(!1),te=o.useRef(null),[ge,ue]=o.useState(!1);o.useEffect(()=>{const ee=()=>{we.current=!1,te.current=null,ue(!1)};return document.addEventListener("mouseup",ee),()=>document.removeEventListener("mouseup",ee)},[]);const xe=o.useCallback((ee,R)=>{const U=ee.split(`
|
|
54
|
-
`),le=Math.max(1,R.start),Me=Math.min(U.length,R.end);return le>Me?"":U.slice(le-1,Me).join(`
|
|
55
|
-
`)},[]),ne=Yd({source:"plan",fileLabel:F,language:N&&xi(N)||"markdown",getCodeForRange:ee=>xe(O,Sl(ee)),toStoreRange:ee=>({startLine:ee.start,endLine:ee.end}),fromDraftRange:ee=>({start:ee.startLine,end:ee.endLine})}),{drafts:pe,commentText:J,editingDraftId:Se,setSelection:he,saveComment:Ie,cancel:Pe,reset:Ce,startEdit:X,deleteDraft:ie}=ne;o.useEffect(()=>{K(null),Ce()},[O,Ce]),o.useEffect(()=>{he(H)},[H,he]);const Ne=o.useCallback(()=>{K(null),Pe()},[Pe]),oe=o.useCallback((ee,R)=>{R&&K(R),Ie(ee,R??H??void 0),K(null)},[H,Ie]);o.useEffect(()=>{if(!H)return;const ee=U=>{const le=U.target;le.closest('[data-comment-card="true"]')||le.closest('[data-comment-input="true"]')||le.closest(".oc-block-widget")||le.closest(".cm-gutterElement")||le.closest("[data-sonner-toast]")||le.closest("[data-sonner-toaster]")||(K(null),Pe())},R=window.setTimeout(()=>{document.addEventListener("click",ee)},100);return()=>{window.clearTimeout(R),document.removeEventListener("click",ee)}},[Pe,Se,h,H]);const ke=o.useMemo(()=>{const ee=[fo(j)],R=xl(N||"plan.md");return R&&ee.push(R),ee.push($n.lineWrapping),ee},[j,N]);o.useEffect(()=>{if(!p&&!t){E(null),V(""),Y(!1);return}let ee=!1;const R=async le=>{if(x.files?.readFile)return(await x.files.readFile(le))?.content??"";const Me=nr()?.files;if(Me?.readFile)return(await Me.readFile(le,{optional:!0}))?.content??"";const Oe=await fetch(`/api/fs/read?path=${encodeURIComponent(le)}&optional=true`,{cache:"no-store"});if(!Oe.ok)throw new Error(`Failed to read plan file (${Oe.status})`);return Oe.text()};return(async()=>{if(E(null),V(""),$(null),t){Y(!0);try{const le=await R(t);if(ee)return;E(t),V(le)}catch{if(ee)return;E(null),V("")}finally{ee||Y(!1)}return}if(!y?.slug||!y?.time?.created||!C){E(null),V("");return}Y(!0);try{const le=W2(C,y.time.created,y.slug),Me=H2(K2(y.time.created,y.slug),d||null);let Oe=null,Ae=null;try{Ae=await R(le),Oe=le}catch{}if(!Oe)try{Ae=await R(Me),Oe=Me}catch{}if(ee)return;if(!Oe||Ae===null){E(null),V("");return}E(Oe),V(Ae)}catch{if(ee)return;E(null),V("")}finally{ee||Y(!1)}})(),()=>{ee=!0}},[d,p,x.files,C,y?.slug,y?.time?.created,t]),o.useEffect(()=>{if(!N){$(null);return}const ee=window.setTimeout(async()=>{$(null);try{if(x.files?.writeFile){if(!(await x.files.writeFile(N,O))?.success)throw new Error(e("planView.error.writeFailed"))}else{const R=await fetch("/api/fs/write",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:N,content:O})});if(!R.ok)throw new Error(e("planView.error.writePlanFileFailed",{status:R.status}))}}catch(R){$(R instanceof Error?R.message:e("planView.error.saveFailed"))}},350);return()=>{window.clearTimeout(ee)}},[O,N,x.files,e]),o.useEffect(()=>()=>{fe.current!==null&&window.clearTimeout(fe.current)},[]);const Te=o.useCallback(()=>{g("chat"),v(!1)},[g,v]),Be=o.useCallback(async ee=>{if(!w||!I)return;const R=await kn(I.action==="improve"?"plan.improve.visible":"plan.implement.visible",{plan_title:q}),le=[{synthetic:!0,text:await kn(I.action==="improve"?"plan.improve.instructions":"plan.implement.instructions",{plan_title:q,plan_path:N??""})}];A(!0);try{Te();let Me=null,Oe=w.path;if(I.target==="worktree"){if(!S)return;const z=await eh(w.path,th());if(!z?.id)return;Me=z.id,Oe=null}else{const z=await r(void 0,w.path,null);if(!z?.id)return;Me=z.id,Oe=z.directory??w.path,a(z.id,yt.getState().agents??[])}if(!Me)return;const Ae=Ol.getState();Ae.saveSessionModelSelection(Me,ee.providerID,ee.modelID),ee.agent.trim()&&(Ae.saveSessionAgentSelection(Me,ee.agent),Ae.saveAgentModelForSession(Me,ee.agent,ee.providerID,ee.modelID),Ae.saveAgentModelVariantForSession(Me,ee.agent,ee.providerID,ee.modelID,ee.variant||void 0)),l(Me,Oe),await i(R,ee.providerID,ee.modelID,ee.agent.trim()||void 0,void 0,void 0,le,ee.variant||void 0),T(null)}finally{A(!1)}},[S,r,w,a,I,N,Te,i,q,l]),je=o.useMemo(()=>Wh({drafts:pe,editingDraftId:Se,commentText:J,selection:H,isDragging:ge,fileLabel:F,newWidgetId:"plan-new-comment-input",mapDraftToRange:ee=>({start:ee.startLine,end:ee.endLine}),onSave:oe,onCancel:Ne,onEdit:ee=>{X(ee),K({start:ee.startLine,end:ee.endLine})},onDelete:ie}),[J,ie,Se,Ne,oe,ge,H,pe,F,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]}),N?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(ve,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0","aria-label":e("planView.actions.improvePlanAria"),disabled:!O.trim(),children:s.jsx(D,{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(Ot,{onClick:()=>T({action:"improve",target:"session"}),children:e("planView.actions.sendToNewSession")}),s.jsx(Ot,{onClick:()=>T({action:"improve",target:"worktree"}),disabled:!S,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(ve,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0","aria-label":e("planView.actions.implementPlanAria"),disabled:!O.trim(),children:s.jsx(D,{name:"code-ai",className:"size-4"})})})}),s.jsx(It,{sideOffset:8,children:e("planView.actions.implement")})]}),s.jsxs(Ps,{align:"end",children:[s.jsx(Ot,{onClick:()=>T({action:"implement",target:"session"}),children:e("planView.actions.sendToNewSession")}),s.jsx(Ot,{onClick:()=>T({action:"implement",target:"worktree"}),disabled:!S,children:e("planView.actions.sendToNewWorktreeSession")})]})]}),s.jsx(Il,{currentMode:re,onToggle:()=>be(re==="preview"?"edit":"preview")}),s.jsx(ve,{variant:"ghost",size:"sm",onClick:async()=>{(await Rn(O)).ok&&(ae(!0),fe.current!==null&&window.clearTimeout(fe.current),fe.current=window.setTimeout(()=>{ae(!1)},1200))},className:"h-5 w-5 p-0",title:e("planView.actions.copyPlanContents"),"aria-label":e("planView.actions.copyPlanContents"),children:Z?s.jsx(D,{name:"check",className:"h-4 w-4 text-[color:var(--status-success)]"}):s.jsx(D,{name:"clipboard",className:"h-4 w-4"})})]}):null]}),s.jsx(Rh,{open:I!==null,onOpenChange:ee=>{!ee&&!P&&T(null)},target:I?.target??"session",projectDirectory:w?.path??null,submitting:P,onConfirm:Be}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 relative",children:s.jsx(ws,{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:re==="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(ha,{content:O,className:"typography-markdown-body"})})}):s.jsx("div",{className:"relative h-full",ref:W,children:s.jsx(po,{value:O,onChange:V,readOnly:!1,className:"h-full",extensions:ke,onViewReady:ee=>{Q.current=ee},onViewDestroy:()=>{Q.current=null},blockWidgets:je,highlightLines:H?{start:Math.min(H.start,H.end),end:Math.max(H.start,H.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(ee,R,U)=>{if(!(U instanceof MouseEvent)||U.button!==0)return!1;U.preventDefault();const le=ee.state.doc.lineAt(R.from).number;if(h&&H&&!U.shiftKey){const Me=Math.min(H.start,H.end,le),Oe=Math.max(H.start,H.end,le);return K({start:Me,end:Oe}),we.current=!1,te.current=null,ue(!1),!0}if(we.current=!0,te.current=le,ue(!0),H&&U.shiftKey){const Me=Math.min(H.start,le),Oe=Math.max(H.end,le);K({start:Me,end:Oe})}else K({start:le,end:le});return!0},mouseover:(ee,R,U)=>{if(!(U instanceof MouseEvent)||U.buttons!==1||!we.current||te.current===null)return!1;const le=ee.state.doc.lineAt(R.from).number,Me=Math.min(te.current,le),Oe=Math.max(te.current,le);return K({start:Me,end:Oe}),ue(!0),!1},mouseup:()=>(we.current=!1,te.current=null,ue(!1),!1)}}})})})})})})]})},Y2=Object.freeze(Object.defineProperty({__proto__:null,PlanView:ig},Symbol.toStringTag,{value:"Module"})),gd={input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:0},sl={user:0,assistant:0,tool:0,other:0},Aa=t=>typeof t!="number"||!Number.isFinite(t)||t<0?0:t,rp=t=>{const e=t.info.tokens,n=e!==void 0?e:t.parts.find(p=>p.tokens!==void 0)?.tokens;if(typeof n=="number")return{...gd,total:Aa(n)};if(!n||typeof n!="object")return gd;const r=n,a=Aa(r.input),i=Aa(r.output),l=Aa(r.reasoning),c=Aa(r.cache?.read),d=Aa(r.cache?.write);return{input:a,output:i,reasoning:l,cacheRead:c,cacheWrite:d,total:a+i+l+c+d}},Q2=(...t)=>{for(const e of t)if(typeof e=="string"&&e.trim().length>0)return e;return""},pr=t=>typeof t=="string"?t.length:typeof t=="number"||typeof t=="boolean"?String(t).length:Array.isArray(t)?t.reduce((e,n)=>e+pr(n),0):t&&typeof t=="object"?Object.values(t).reduce((e,n)=>e+pr(n),0):0,J2=(t,e)=>{const n=t,r=typeof n.type=="string"?n.type:"";if(r==="reasoning")return{...sl,assistant:pr(n.text)+pr(n.content)};const a=Q2(n.text,n.content,n.value,n.source?.value,n.source?.text?.value);return r==="tool"||e==="tool"?{user:0,assistant:0,tool:pr(n.input)+pr(n.output)+pr(n.error)+pr(n.call?.input)+pr(n.call?.output)+pr(n.call?.error)+pr(n.raw)+Math.round(pr(n.metadata)*.25)+Math.round(pr(n.state)*.1),other:0}:e==="user"?{user:a.length,assistant:0,tool:0,other:0}:e==="assistant"?{user:0,assistant:a.length,tool:0,other:0}:{user:0,assistant:0,tool:0,other:a.length}},ap=(t,e)=>({user:t.user+e.user,assistant:t.assistant+e.assistant,tool:t.tool+e.tool,other:t.other+e.other}),X2=t=>{const e=bo(t.info);return e.isUser?"user":e.role==="assistant"?"assistant":e.role==="tool"?"tool":"other"},Z2=(t,e)=>{if(t.length===0)return{...sl};const n=t.reduce((r,a)=>{const i=X2(a);let l={...sl};for(const c of a.parts)l=ap(l,J2(c,i));return ap(r,l)},{...sl});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)}},ni=t=>t.toLocaleString(),eS=t=>!Number.isFinite(t)||t<=0?"$0.00":t<.01?`$${t.toFixed(4)}`:`$${t.toFixed(2)}`,tS=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"}),nS=t=>t&&`${t[0].toUpperCase()}${t.slice(1)}`,rS=(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}},aS=()=>{const t=ot.c(199),{t:e}=ut(),{currentTheme:n}=vr();let r;t[0]!==n?(r=rh(n),t[0]=n,t[1]=r):r=t[1];const a=r;let i;t[2]===Symbol.for("react.memo_cache_sentinel")?(i={},t[2]=i):i=t[2];const[l,c]=o.useState(i),[d,p]=o.useState(null),m=o.useRef(null),u=$t(iS),f=Vl(),b=Fb(u??""),g=yt(oS);let v;t[3]===Symbol.for("react.memo_cache_sentinel")?(v=()=>{m.current!==null&&(window.clearTimeout(m.current),m.current=null),c(lS),p(null)},t[3]=v):v=t[3];let x;t[4]!==u?(x=[u],t[4]=u,t[5]=x):x=t[5],o.useEffect(v,x);let h,j;t[6]===Symbol.for("react.memo_cache_sentinel")?(h=()=>()=>{m.current!==null&&(window.clearTimeout(m.current),m.current=null)},j=[],t[6]=h,t[7]=j):(h=t[6],j=t[7]),o.useEffect(h,j);let y;t[8]===Symbol.for("react.memo_cache_sentinel")?(y=async(ht,wt)=>{(await Rn(wt)).ok?(p(ht),m.current!==null&&window.clearTimeout(m.current),m.current=window.setTimeout(()=>{p(Vt=>Vt===ht?null:Vt),m.current=null},2e3)):p(null)},t[8]=y):y=t[8];const C=y;let k;t[9]!==u||t[10]!==f?(k=u?f.find(ht=>ht.id===u)??null:null,t[9]=u,t[10]=f,t[11]=k):k=t[11];const w=k;let S,I,T,P,A;if(t[12]!==g||t[13]!==b){S=b.filter(cS);let ht;t[19]!==b?(ht=b.filter(dS),t[19]=b,t[20]=ht):ht=t[20],A=ht;let wt=null;for(let Vt=S.length-1;Vt>=0;Vt=Vt-1,Vt){const Jt=S[Vt];if(rp(Jt).total>0){wt=Jt;break}}T=wt?rp(wt):gd,P=S.reduce(uS,0);const es=wt?.info??null;I=rS(g,es?.providerID||"",es?.modelID||""),t[12]=g,t[13]=b,t[14]=S,t[15]=I,t[16]=T,t[17]=P,t[18]=A}else S=t[14],I=t[15],T=t[16],P=t[17],A=t[18];const N=I,E=N.contextLimit,M=E&&E>0?Math.min(999,T.total/E*100):0;let O;if(t[21]!==b){const ht=[...b].reverse().find(mS)?.info?.system||"";O=Z2(b,ht),t[21]=b,t[22]=O}else O=t[22];const V=O,B=V.user,$=V.assistant,F=V.tool,_=Math.max(0,T.input-B-$-F),q=B+$+F+_,L=b[0]?.info?.time?.created,Y=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 ae=w?.time?.created??L??null,re=Y??w?.time?.created??null;let me;t[26]!==$||t[27]!==_||t[28]!==F||t[29]!==B?(me={user:B,assistant:$,tool:F,other:_},t[26]=$,t[27]=_,t[28]=F,t[29]=B,t[30]=me):me=t[30];let fe;t[31]!==S.length||t[32]!==q||t[33]!==E||t[34]!==N||t[35]!==b.length||t[36]!==Z||t[37]!==ae||t[38]!==re||t[39]!==me||t[40]!==T||t[41]!==P||t[42]!==M||t[43]!==A.length?(fe={sessionTitle:Z,messagesCount:b.length,userMessagesCount:A.length,assistantMessagesCount:S.length,createdAt:ae,lastActivityAt:re,providerModel:N,tokenBreakdown:T,usagePercent:M,totalAssistantCost:P,contextLimit:E,breakdown:me,breakdownTotal:q},t[31]=S.length,t[32]=q,t[33]=E,t[34]=N,t[35]=b.length,t[36]=Z,t[37]=ae,t[38]=re,t[39]=me,t[40]=T,t[41]=P,t[42]=M,t[43]=A.length,t[44]=fe):fe=t[44];const H=fe;if(!u){let ht;t[45]!==e?(ht=e("contextSidebar.empty.openSession"),t[45]=e,t[46]=ht):ht=t[46];let wt;return t[47]!==ht?(wt=s.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center typography-ui-label text-muted-foreground",children:ht}),t[47]=ht,t[48]=wt):wt=t[48],wt}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]!==H.breakdown.user?(Q={key:"user",label:K,value:H.breakdown.user,color:"var(--status-success)"},t[51]=K,t[52]=H.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]!==H.breakdown.assistant?(de={key:"assistant",label:W,value:H.breakdown.assistant,color:"var(--primary-base)"},t[56]=W,t[57]=H.breakdown.assistant,t[58]=de):de=t[58];let be;t[59]!==e?(be=e("contextSidebar.breakdown.toolCalls"),t[59]=e,t[60]=be):be=t[60];let we;t[61]!==be||t[62]!==H.breakdown.tool?(we={key:"tool",label:be,value:H.breakdown.tool,color:"var(--status-warning)"},t[61]=be,t[62]=H.breakdown.tool,t[63]=we):we=t[63];let te;t[64]!==e?(te=e("contextSidebar.breakdown.other"),t[64]=e,t[65]=te):te=t[65];let ge;t[66]!==te||t[67]!==H.breakdown.other?(ge={key:"other",label:te,value:H.breakdown.other,color:"var(--surface-muted-foreground)"},t[66]=te,t[67]=H.breakdown.other,t[68]=ge):ge=t[68];let ue;t[69]!==Q||t[70]!==de||t[71]!==we||t[72]!==ge?(ue=[Q,de,we,ge],t[69]=Q,t[70]=de,t[71]=we,t[72]=ge,t[73]=ue):ue=t[73];const xe=ue;let ne;t[74]!==H.sessionTitle?(ne=s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:H.sessionTitle}),t[74]=H.sessionTitle,t[75]=ne):ne=t[75];let pe;t[76]!==H.providerModel.modelName||t[77]!==H.providerModel.providerName?(pe=s.jsxs("span",{children:[H.providerModel.providerName," / ",H.providerModel.modelName]}),t[76]=H.providerModel.modelName,t[77]=H.providerModel.providerName,t[78]=pe):pe=t[78];let J;t[79]!==H.createdAt?(J=H.createdAt&&s.jsxs(s.Fragment,{children:[s.jsx("span",{children:"·"}),s.jsx("span",{children:tS(H.createdAt)})]}),t[79]=H.createdAt,t[80]=J):J=t[80];let Se;t[81]!==pe||t[82]!==J?(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:[pe,J]}),t[81]=pe,t[82]=J,t[83]=Se):Se=t[83];let he;t[84]!==ne||t[85]!==Se?(he=s.jsxs("div",{className:"mb-6",children:[ne,Se]}),t[84]=ne,t[85]=Se,t[86]=he):he=t[86];let Ie;t[87]!==e?(Ie=e("contextSidebar.section.context"),t[87]=e,t[88]=Ie):Ie=t[88];let Pe;t[89]!==Ie?(Pe=s.jsx("span",{className:"typography-micro text-muted-foreground",children:Ie}),t[89]=Ie,t[90]=Pe):Pe=t[90];let Ce;t[91]!==H.tokenBreakdown.total?(Ce=ni(H.tokenBreakdown.total),t[91]=H.tokenBreakdown.total,t[92]=Ce):Ce=t[92];let X;t[93]!==H.contextLimit?(X=H.contextLimit?` / ${ni(H.contextLimit)}`:"",t[93]=H.contextLimit,t[94]=X):X=t[94];let ie;t[95]!==Ce||t[96]!==X?(ie=s.jsxs("span",{className:"typography-micro tabular-nums text-muted-foreground/70",children:[Ce,X]}),t[95]=Ce,t[96]=X,t[97]=ie):ie=t[97];let Ne;t[98]!==Pe||t[99]!==ie?(Ne=s.jsxs("div",{className:"flex items-baseline justify-between",children:[Pe,ie]}),t[98]=Pe,t[99]=ie,t[100]=Ne):Ne=t[100];let oe;t[101]!==H.usagePercent?(oe=H.usagePercent>0&&s.jsx("div",{className:"rounded-full transition-all duration-300",style:{width:`${Math.max(.5,H.usagePercent)}%`,backgroundColor:H.usagePercent>80?"var(--status-warning)":"var(--primary-base)"}}),t[101]=H.usagePercent,t[102]=oe):oe=t[102];let ke;t[103]!==oe?(ke=s.jsx("div",{className:"mt-2.5 flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:oe}),t[103]=oe,t[104]=ke):ke=t[104];let Te;t[105]!==e||t[106]!==H.usagePercent?(Te=e("contextSidebar.context.percentUsed",{percent:H.usagePercent.toFixed(1)}),t[105]=e,t[106]=H.usagePercent,t[107]=Te):Te=t[107];let Be;t[108]!==Te?(Be=s.jsx("div",{className:"mt-1.5 typography-micro font-medium tabular-nums text-foreground/80",children:Te}),t[108]=Te,t[109]=Be):Be=t[109];let je;t[110]!==Ne||t[111]!==ke||t[112]!==Be?(je=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[Ne,ke,Be]}),t[110]=Ne,t[111]=ke,t[112]=Be,t[113]=je):je=t[113];let ee;t[114]!==e?(ee=e("contextSidebar.stats.messages"),t[114]=e,t[115]=ee):ee=t[115];let R;t[116]!==H.messagesCount?(R=ni(H.messagesCount),t[116]=H.messagesCount,t[117]=R):R=t[117];let U;t[118]!==ee||t[119]!==R?(U={label:ee,value:R},t[118]=ee,t[119]=R,t[120]=U):U=t[120];let le;t[121]!==e?(le=e("contextSidebar.stats.user"),t[121]=e,t[122]=le):le=t[122];let Me;t[123]!==H.userMessagesCount?(Me=ni(H.userMessagesCount),t[123]=H.userMessagesCount,t[124]=Me):Me=t[124];let Oe;t[125]!==le||t[126]!==Me?(Oe={label:le,value:Me},t[125]=le,t[126]=Me,t[127]=Oe):Oe=t[127];let Ae;t[128]!==e?(Ae=e("contextSidebar.stats.assistant"),t[128]=e,t[129]=Ae):Ae=t[129];let z;t[130]!==H.assistantMessagesCount?(z=ni(H.assistantMessagesCount),t[130]=H.assistantMessagesCount,t[131]=z):z=t[131];let De;t[132]!==Ae||t[133]!==z?(De={label:Ae,value:z},t[132]=Ae,t[133]=z,t[134]=De):De=t[134];let Xe;t[135]!==e?(Xe=e("contextSidebar.stats.cost"),t[135]=e,t[136]=Xe):Xe=t[136];let st;t[137]!==H.totalAssistantCost?(st=eS(H.totalAssistantCost),t[137]=H.totalAssistantCost,t[138]=st):st=t[138];let tt;t[139]!==Xe||t[140]!==st?(tt={label:Xe,value:st},t[139]=Xe,t[140]=st,t[141]=tt):tt=t[141];let Ue;t[142]!==U||t[143]!==Oe||t[144]!==De||t[145]!==tt?(Ue=[U,Oe,De,tt],t[142]=U,t[143]=Oe,t[144]=De,t[145]=tt,t[146]=Ue):Ue=t[146];const it=Ue;let Ye;t[147]!==it?(Ye=s.jsx("div",{className:"mb-5 grid grid-cols-2 gap-2",children:it.map(pS)}),t[147]=it,t[148]=Ye):Ye=t[148];let rt;t[149]!==e?(rt=e("contextSidebar.section.lastAssistantMessage"),t[149]=e,t[150]=rt):rt=t[150];let Je;t[151]!==rt?(Je=s.jsx("div",{className:"typography-micro text-muted-foreground",children:rt}),t[151]=rt,t[152]=Je):Je=t[152];let ce;t[153]!==e||t[154]!==H.tokenBreakdown.cacheRead||t[155]!==H.tokenBreakdown.cacheWrite||t[156]!==H.tokenBreakdown.input||t[157]!==H.tokenBreakdown.output||t[158]!==H.tokenBreakdown.reasoning?(ce=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:H.tokenBreakdown.input},{label:e("contextSidebar.tokens.output"),value:H.tokenBreakdown.output},{label:e("contextSidebar.tokens.reasoning"),value:H.tokenBreakdown.reasoning},{label:e("contextSidebar.tokens.cacheRead"),value:H.tokenBreakdown.cacheRead},{label:e("contextSidebar.tokens.cacheWrite"),value:H.tokenBreakdown.cacheWrite}].map(fS)}),t[153]=e,t[154]=H.tokenBreakdown.cacheRead,t[155]=H.tokenBreakdown.cacheWrite,t[156]=H.tokenBreakdown.input,t[157]=H.tokenBreakdown.output,t[158]=H.tokenBreakdown.reasoning,t[159]=ce):ce=t[159];let We;t[160]!==Je||t[161]!==ce?(We=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[Je,ce]}),t[160]=Je,t[161]=ce,t[162]=We):We=t[162];let Le;t[163]!==xe||t[164]!==H.breakdownTotal?(Le=s.jsx("div",{className:"flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:xe.map(ht=>ht.value<=0||H.breakdownTotal<=0?null:s.jsx("div",{style:{width:`${ht.value/H.breakdownTotal*100}%`,backgroundColor:ht.color}},ht.key))}),t[163]=xe,t[164]=H.breakdownTotal,t[165]=Le):Le=t[165];let Ge;t[166]!==xe||t[167]!==H.breakdownTotal?(Ge=s.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-x-4 gap-y-1",children:xe.map(ht=>{const wt=H.breakdownTotal>0?ht.value/H.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:ht.color}}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70",children:[ht.label," ",s.jsxs("span",{className:"tabular-nums",children:[wt.toFixed(0),"%"]})]})]},ht.key)})}),t[166]=xe,t[167]=H.breakdownTotal,t[168]=Ge):Ge=t[168];let at;t[169]!==Le||t[170]!==Ge?(at=s.jsxs("div",{className:"mb-6",children:[Le,Ge]}),t[169]=Le,t[170]=Ge,t[171]=at):at=t[171];let He;t[172]!==e?(He=e("contextSidebar.section.rawMessages"),t[172]=e,t[173]=He):He=t[173];let ze;t[174]!==He?(ze=s.jsx("div",{className:"typography-micro text-muted-foreground",children:He}),t[174]=He,t[175]=ze):ze=t[175];let et;if(t[176]!==d||t[177]!==l||t[178]!==b||t[179]!==a||t[180]!==e){let ht;t[182]!==d||t[183]!==l||t[184]!==a||t[185]!==e?(ht=wt=>{const es=bo(wt.info).role,Vt=l[wt.info.id]===!0,Jt=d===wt.info.id,mt=wt.info.time?.created??null,Lt=Vt?JSON.stringify({info:wt.info,parts:wt.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(ts=>({...ts,[wt.info.id]:ts[wt.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:nS(es)}),s.jsx("span",{className:"min-w-0 truncate typography-micro text-muted-foreground",children:wt.info.id})]}),s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:sS(mt)})]})}),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:ts=>{ts.stopPropagation(),C(wt.info.id,Lt)},"aria-label":e(Jt?"contextSidebar.actions.copied":"contextSidebar.actions.copyJson"),title:e(Jt?"contextSidebar.actions.copied":"contextSidebar.actions.copy"),children:Jt?s.jsx(D,{name:"check",className:"size-3.5"}):s.jsx(D,{name:"file-copy",className:"size-3.5"})})}),s.jsx(Px,{language:"json",style:a,PreTag:"div",customStyle:{margin:0,padding:"0.75rem",background:"transparent",fontSize:"var(--text-micro)",lineHeight:"1.35"},codeTagProps:{style:{whiteSpace:"pre-wrap",wordBreak:"break-word",overflowWrap:"break-word"}},wrapLongLines:!0,children:Lt})]})})]},wt.info.id)},t[182]=d,t[183]=l,t[184]=a,t[185]=e,t[186]=ht):ht=t[186],et=[...b].reverse().map(ht),t[176]=d,t[177]=l,t[178]=b,t[179]=a,t[180]=e,t[181]=et}else et=t[181];let gt;t[187]!==et?(gt=s.jsx("div",{className:"mt-2.5 space-y-1",children:et}),t[187]=et,t[188]=gt):gt=t[188];let Pt;t[189]!==ze||t[190]!==gt?(Pt=s.jsxs("div",{children:[ze,gt]}),t[189]=ze,t[190]=gt,t[191]=Pt):Pt=t[191];let Nt;return t[192]!==he||t[193]!==je||t[194]!==Ye||t[195]!==We||t[196]!==at||t[197]!==Pt?(Nt=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:[he,je,Ye,We,at,Pt]})}),t[192]=he,t[193]=je,t[194]=Ye,t[195]=We,t[196]=at,t[197]=Pt,t[198]=Nt):Nt=t[198],Nt};function iS(t){return t.currentSessionId}function oS(t){return t.providers}function lS(t){return Object.keys(t).length>0?{}:t}function cS(t){return bo(t.info).role==="assistant"}function dS(t){return bo(t.info).isUser}function uS(t,e){const n=Aa(e.info.cost);return t+n}function mS(t){return bo(t.info).isUser&&typeof t.info.system=="string"}function pS(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 fS(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:ni(t.value)})]},t.label)}const hS=360,gS=1400,og=600,xS=24,ip=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",xd=t=>{if(!t||typeof t!="object")return!1;const e=t,n=e.bounds;return typeof e.tag=="string"&&typeof e.selector=="string"&&typeof e.path=="string"&&!!n&&typeof n?.x=="number"&&typeof n?.y=="number"&&typeof n?.width=="number"&&typeof n?.height=="number"},lg=({pageUrl:t,viewport:e,devicePixelRatio:n,target:r,screenshotAttached:a,intro:i})=>{const l=r.text.trim(),c=Object.entries(r.attributes).map(([b,g])=>`${b}="${g}"`).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}`,l?`Text: ${l}`: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
|
-
`)},yS=async(t,e)=>{const n=typeof window<"u"?window.__TAURI__:void 0;if(typeof n?.core?.invoke=="function")try{const r=t.getBoundingClientRect(),a=await n.core.invoke("desktop_capture_page_rect",{x:r.left,y:r.top,width:r.width,height:r.height}),i=new Image;await new Promise((v,x)=>{i.onload=()=>v(),i.onerror=()=>x(new Error("Failed to load desktop preview screenshot")),i.src=`data:${a.mime};base64,${a.base64}`});const l=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/l),m=document.createElement("canvas");m.width=Math.floor(l*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,l,c);const f=l/Math.max(1,r.width),b=c/Math.max(1,r.height);u.fillStyle="rgba(37, 99, 235, 0.28)",u.strokeStyle="rgb(37, 99, 235)",u.lineWidth=Math.max(2,2*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 g=await new Promise(v=>m.toBlob(v,"image/jpeg",.82));return g?new File([g],`preview-annotation-${Date.now()}.jpg`,{type:"image/jpeg"}):null}catch(r){return console.warn("[preview] failed to capture annotation screenshot:",r),null}return null},vS=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},op=t=>Number.isFinite(t)?Math.min(gS,Math.max(hS,Math.round(t))):og,wS=(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},jS=(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"),NS=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},SS=(t,e)=>{if(t.label)return t.label;if(t.mode==="file")return NS(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"):jS(t.mode,e)},kS=t=>{if(t.mode==="file")return t.targetPath?s.jsx(Pr,{filePath:t.targetPath,className:"h-3.5 w-3.5"}):void 0;if(t.mode==="diff")return s.jsx(D,{name:"arrow-left-right",className:"h-3.5 w-3.5"});if(t.mode==="plan")return s.jsx(D,{name:"file-text",className:"h-3.5 w-3.5"});if(t.mode==="context")return s.jsx(D,{name:"donut-chart-fill",className:"h-3.5 w-3.5"});if(t.mode==="chat")return s.jsx(D,{name:"chat-4",className:"h-3.5 w-3.5"});if(t.mode==="preview")return s.jsx(D,{name:"global",className:"h-3.5 w-3.5 text-[var(--status-info)]"});if(t.mode==="browser")return s.jsx(D,{name:"global",className:"h-3.5 w-3.5"})},CS=t=>!t||!t.startsWith("session:")?null:t.slice(8).trim()||null,IS=`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
|
-
});`,Pc=`(() => {
|
|
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
|
-
})()`,Ac=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"}},PS=async(t,e,n,r,a,i)=>{if(!t)return null;try{const l=new Image;await new Promise((x,h)=>{l.onload=()=>x(),l.onerror=()=>h(new Error("Failed to load desktop browser screenshot")),l.src=`data:image/jpeg;base64,${t}`});const c=Math.max(1,l.naturalWidth||e),d=Math.max(1,l.naturalHeight||n),m=Math.min(1,1200/c),u=document.createElement("canvas");u.width=Math.floor(c*m),u.height=Math.floor(d*m);const f=u.getContext("2d");if(!f)return null;f.scale(m,m),f.drawImage(l,0,0,c,d);const b=c/Math.max(1,r||c),g=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*g,i.bounds.width*b,i.bounds.height*g),f.strokeRect(i.bounds.x*b,i.bounds.y*g,i.bounds.width*b,i.bounds.height*g);const v=await new Promise(x=>u.toBlob(x,"image/jpeg",.82));return v?new File([v],`browser-annotation-${Date.now()}.jpg`,{type:"image/jpeg"}):null}catch{return null}},AS=(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()},DS=(t,e)=>t.length<=e?t:`${t.slice(0,e-3)}...`,Ta=new Map,TS=3e4,MS=t=>{const e=Ta.get(t);return e?e.expiresAt-Date.now()<=TS?(Ta.delete(t),null):e:null},ES=({rawUrl:t,onNavigate:e})=>{const{t:n}=ut(),{currentTheme:r}=vr(),[a,i]=o.useReducer(te=>te+1,0),[l,c]=o.useReducer(te=>te+1,0),[d,p]=o.useState({status:"idle"}),m=o.useRef(null),u=o.useRef(1),[f,b]=o.useState(!1),[g,v]=o.useState(!1),[x,h]=o.useState("all"),[j,y]=o.useState([]),[C,k]=o.useState(!1),[w,S]=o.useState(null),I=$t(te=>te.currentSessionId),T=$t(te=>te.newSessionDraft?.open),P=ai(te=>te.addDraft),A=za(te=>te.addAttachedFile);let N=null;try{N=t?new URL(t):null}catch{N=null}const E=N?N.hostname==="localhost"||N.hostname==="127.0.0.1"||N.hostname==="::1"||N.hostname==="[::1]"||N.hostname==="0.0.0.0":!1,M=N?N.hostname==="0.0.0.0"?new URL(N.toString().replace("0.0.0.0","127.0.0.1")):N:null,O=M?M.toString():"",V=r.metadata.variant;o.useEffect(()=>{if(!O||!E){p({status:"idle"});return}const te=MS(O);if(te){p({status:"ready",proxyBasePath:te.proxyBasePath,expiresAt:te.expiresAt});return}let ge=!1;return p({status:"loading"}),(async()=>{try{const ue=await fetch("/api/preview/targets",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({url:O})});if(!ue.ok){Ta.delete(O);const J=await ue.json().catch(()=>({})),Se=typeof J?.error=="string"?J.error:`HTTP ${ue.status}`;ge||p({status:"error",message:Se});return}const xe=await ue.json(),ne=typeof xe.proxyBasePath=="string"?xe.proxyBasePath:"",pe=typeof xe.expiresAt=="number"?xe.expiresAt:0;if(!ne){Ta.delete(O),ge||p({status:"error",message:n("contextPanel.preview.proxyError")});return}Ta.set(O,{proxyBasePath:ne,expiresAt:pe}),ge||p({status:"ready",proxyBasePath:ne,expiresAt:pe})}catch(ue){if(Ta.delete(O),!ge){const xe=ue instanceof Error?ue.message:String(ue);p({status:"error",message:xe})}}})(),()=>{ge=!0}},[E,l,n,O]);const B=M&&(M.protocol==="http:"||M.protocol==="https:")?M.toString():"",$=E&&d.status==="ready"&&M?(()=>{const te=M.pathname||"/",ge=new URLSearchParams(M.search);ge.set("ocPreview",String(a));const ue=ge.toString(),xe=M.hash||"";return`${d.proxyBasePath}${te}${ue?`?${ue}`:""}${xe}`})():"",F=E?$:B,_=F||B,q=E&&(d.status==="loading"||d.status==="idle"),L=E&&d.status==="error",Y=o.useCallback(te=>{const ge=I??(T?"draft":null);if(!ge){G.error(n("contextPanel.preview.inspect.attachNoSession"));return}const ue=t||F||"",xe=typeof window<"u"?{width:window.innerWidth,height:window.innerHeight}:{width:0,height:0},ne=typeof window<"u"?window.devicePixelRatio:1;(async()=>{let pe=!1;try{const J=m.current,Se=J?await yS(J,te):null;Se&&(await A(Se),pe=!0)}catch{pe=!1}P({sessionKey:ge,source:"preview-annotation",fileLabel:ue||"preview",startLine:1,endLine:1,code:lg({pageUrl:ue,viewport:xe,devicePixelRatio:ne,target:te,screenshotAttached:pe,intro:n("contextPanel.preview.inspect.attachAnnotation")}),language:"markdown",text:""}),G.success(n("contextPanel.preview.inspect.attached"))})()},[A,P,I,F,T,t,n]);o.useEffect(()=>{b(!1),y([]),v(!1),h("all"),k(!1),S(null),u.current=1},[F]),o.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]),o.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]),o.useEffect(()=>{if(!C||typeof window>"u")return;const te=ge=>{ge.key==="Escape"&&(ge.preventDefault(),ge.stopImmediatePropagation(),k(!1))};return window.addEventListener("keydown",te,!0),()=>window.removeEventListener("keydown",te,!0)},[C]),o.useEffect(()=>{if(!E||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)}},ge=xe=>{const ne=u.current;u.current+=1,y(pe=>{const J=[...pe,{...xe,id:ne}];return J.length>ip?J.slice(J.length-ip):J})},ue=xe=>{if(xe.source!==m.current?.contentWindow)return;const ne=xe.data;if(!(!ne||ne.source!=="openchamber-preview-bridge"||ne.version!==1)){if(ne.type==="ready"){b(!0);return}if(ne.type==="console"){const pe=ne.level==="error"||ne.level==="warn"||ne.level==="info"||ne.level==="debug"?ne.level:"log",J=Array.isArray(ne.args)?ne.args.map(te).filter(Boolean):[];ge({level:pe,message:J.join(" "),ts:typeof ne.ts=="number"?ne.ts:Date.now()});return}if(ne.type==="runtime-error"){const pe=te(ne.filename),J=typeof ne.line=="number"?ne.line:null,Se=typeof ne.column=="number"?ne.column:null,he=pe?`${pe}${J!==null?`:${J}${Se!==null?`:${Se}`:""}`:""}`:"",Ie=te(ne.stack);ge({level:"runtime",message:te(ne.message)||n("contextPanel.preview.console.runtimeError"),details:[he,Ie].filter(Boolean).join(`
|
|
148
|
-
`),ts:typeof ne.ts=="number"?ne.ts:Date.now()});return}if(ne.type==="resource-error"){const pe=te(ne.tag)||"resource",J=te(ne.url);ge({level:"resource",message:J?`${pe}: ${J}`:pe,details:te(ne.outerHTML),ts:typeof ne.ts=="number"?ne.ts:Date.now()});return}if(ne.type==="hover"){S(xd(ne.target)?ne.target:null);return}if(ne.type==="select"&&xd(ne.target)){S(ne.target),k(!1),Y(ne.target);return}if(ne.type==="navigate-preview"){const pe=typeof ne.url=="string"?ne.url:"",J=ne.navigation==="external"?"external":"proxy";if(pe&&J==="external"){Zn(pe);return}pe&&e(pe)}}};return window.addEventListener("message",ue),()=>{window.removeEventListener("message",ue)}},[Y,E,e,n]);const Z=j.filter(te=>te.level==="error"||te.level==="runtime"||te.level==="resource").length,ae=j.filter(te=>bS(te,x)),re=o.useCallback(()=>{const te=[`Preview URL: ${t||F||""}`,`Events: ${j.length}`,""].join(`
|
|
149
|
-
`),ge=j.map(ue=>{const xe=new Date(ue.ts).toISOString(),ne=ue.details?`
|
|
150
|
-
${ue.details}`:"";return`[${xe}] [${ue.level}] ${ue.message}${ne}`}).join(`
|
|
151
|
-
`);Rn(`${te}${ge}`).then(ue=>{ue.ok?G.success(n("contextPanel.preview.console.copied")):G.error(n("contextPanel.preview.console.copyFailed"))})},[j,F,t,n]),me=o.useCallback(()=>{const te=I??(T?"draft":null);if(!te){G.error(n("contextPanel.preview.console.attachNoSession"));return}const ge=[`Preview URL: ${t||F||""}`,`Events: ${j.length}`,""].join(`
|
|
152
|
-
`),ue=j.map(xe=>{const ne=new Date(xe.ts).toISOString(),pe=xe.details?`
|
|
153
|
-
${xe.details}`:"";return`[${ne}] [${xe.level}] ${xe.message}${pe}`}).join(`
|
|
154
|
-
`);P({sessionKey:te,source:"preview-console",fileLabel:t||F||"preview",startLine:1,endLine:Math.max(1,j.length),code:`${ge}${ue}`,language:"text",text:n("contextPanel.preview.console.attachAnnotation")}),G.success(n("contextPanel.preview.console.attached"))},[P,j,I,F,T,t,n]),[fe,H]=o.useState("unknown"),K=o.useRef(0),Q=o.useRef(0),W=15e3;o.useEffect(()=>{if(!$){H("unknown"),K.current=0,Q.current=0;return}let te=!1;return K.current||(K.current=Date.now(),Q.current=0),H("unknown"),(async()=>{const ue=await(async()=>{try{return await fetch($,{method:"GET",credentials:"include",cache:"no-store",redirect:"manual"})}catch{return null}})();if(te)return;if(!ue){H("unreachable");return}if(ue.status===403||ue.status===404){Ta.delete(O),p({status:"loading"}),c();return}if(ue.status!==502){H("reachable");return}const xe=K.current||Date.now();if(Date.now()-xe<W){H("starting"),Q.current+=1;const pe=Q.current,J=Math.min(2e3,250*Math.pow(2,Math.min(4,pe)));setTimeout(()=>{te||i()},J).unref?.();return}H("unreachable")})(),()=>{te=!0}},[$,a,O]);const de=E&&d.status==="ready"&&(fe==="unknown"||fe==="starting"),be=E&&d.status==="ready"&&fe==="unreachable",we=o.useCallback(te=>{if(!E||d.status!=="ready"||typeof window>"u")return;const ge=te.currentTarget.contentWindow;if(ge)try{const ue=ge.location;if(ue.origin!==window.location.origin||ue.pathname.startsWith(d.proxyBasePath))return;const xe=`${d.proxyBasePath}${ue.pathname}${ue.search}${ue.hash}`;ge.location.replace(xe)}catch{}},[E,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(ve,{type:"button",size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>i(),title:n("contextPanel.preview.actions.reload"),"aria-label":n("contextPanel.preview.actions.reload"),disabled:!F,children:s.jsx(D,{name:"refresh",className:"h-3.5 w-3.5"})}),s.jsx(ve,{type:"button",size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{B&&Zn(B)},title:n("contextPanel.preview.actions.openExternal"),"aria-label":n("contextPanel.preview.actions.openExternal"),disabled:!B,children:s.jsx(D,{name:"external-link",className:"h-3.5 w-3.5"})}),E?s.jsx(ve,{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(D,{name:"cursor",className:"h-3.5 w-3.5"})}):null,E?s.jsxs(ve,{type:"button",size:"sm",variant:g?"secondary":"ghost",className:"h-7 gap-1 px-2",onClick:()=>v(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(D,{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")})]}):be?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center text-sm text-muted-foreground",children:[s.jsx("div",{children:n("contextPanel.preview.upstreamUnreachable")}),s.jsx("div",{className:"text-xs opacity-70",children:n("contextPanel.preview.upstreamUnreachableHint")}),s.jsx(ve,{type:"button",size:"sm",variant:"outline",onClick:()=>i(),children:n("contextPanel.preview.actions.retry")})]}):F&&(!E||fe==="reachable")?s.jsxs("div",{className:"relative h-full w-full",children:[s.jsx("iframe",{ref:m,src:F,title:n("contextPanel.preview.iframeTitle"),className:"h-full w-full border-0",style:{colorScheme:V},onLoad:we,sandbox:E?"allow-scripts allow-same-origin allow-forms allow-popups allow-downloads":"allow-scripts allow-forms"},`${F}:${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")}),g?s.jsxs("div",{className:"absolute inset-x-3 bottom-3 z-10 max-h-[45%] overflow-hidden rounded-xl border border-border/70 bg-[var(--surface-elevated)] shadow-lg",children:[s.jsxs("div",{className:"flex items-center justify-between border-b border-border/50 px-3 py-2",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:n("contextPanel.preview.console.title")}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(ve,{type:"button",size:"xs",variant:"ghost",onClick:me,disabled:j.length===0,children:n("contextPanel.preview.console.attach")}),s.jsx(ve,{type:"button",size:"xs",variant:"ghost",onClick:re,disabled:j.length===0,children:n("contextPanel.preview.console.copy")}),s.jsx(ve,{type:"button",size:"xs",variant:"ghost",onClick:()=>y([]),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(ve,{type:"button",size:"xs",variant:x===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")}):ae.length===0?s.jsx("div",{className:"px-2 py-3 text-muted-foreground",children:n("contextPanel.preview.console.noFilteredEvents")}):ae.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]})]})},RS=({initialUrl:t,directory:e,tabID:n})=>{const{t:r}=ut(),a=o.useRef(null),i=Re(T=>T.setContextPanelTabTargetPath),l=Ac(t),c=l!=="about:blank"?l:"",[d,p]=o.useState(c),[m,u]=o.useState(c),[f,b]=o.useState(!1),[g,v]=o.useState(!0),x=o.useRef(null),h=g,j=o.useCallback(T=>{!T||T==="about:blank"||!e||!n||i(e,n,T)},[e,n,i]),y=$t(T=>T.currentSessionId),C=$t(T=>T.newSessionDraft?.open),k=ai(T=>T.addDraft),w=za(T=>T.addAttachedFile);o.useEffect(()=>{const T=a.current;if(!T)return;const P=()=>{try{const O=T.getURL();O&&O!=="about:blank"&&(u(O),p(O),j(O))}catch{}},A=O=>{const V=O.detail;typeof V?.url=="string"&&V.url&&(u(V.url),p(V.url),j(V.url))},N=()=>{x.current&&clearTimeout(x.current),x.current=setTimeout(()=>v(!0),200)},E=()=>{x.current&&clearTimeout(x.current),v(!1),P()},M=O=>{const V=O.detail;if(V?.disposition==="new-window"||V?.disposition==="foreground-tab"||V?.disposition==="background-tab"){O.preventDefault();const B=a.current;typeof B?.loadURL=="function"&&V.url&&B.loadURL(V.url)}};T.addEventListener("did-navigate",A),T.addEventListener("did-navigate-in-page",A),T.addEventListener("did-start-loading",N),T.addEventListener("did-stop-loading",E),T.addEventListener("new-window",M);try{T.isLoading()||(v(!1),P())}catch{}return()=>{x.current&&clearTimeout(x.current),T.removeEventListener("did-navigate",A),T.removeEventListener("did-navigate-in-page",A),T.removeEventListener("did-start-loading",N),T.removeEventListener("did-stop-loading",E),T.removeEventListener("new-window",M)}},[j]),o.useEffect(()=>{const T=setTimeout(()=>v(!1),3e4);return()=>clearTimeout(T)},[]),o.useEffect(()=>{if(!f)return;const T=P=>{if(P.key!=="Escape")return;P.preventDefault(),P.stopImmediatePropagation(),b(!1);const A=a.current;try{A?.executeJavaScript?.(Pc).catch(()=>{})}catch{}};return window.addEventListener("keydown",T,!0),()=>window.removeEventListener("keydown",T,!0)},[f]),o.useEffect(()=>{const T=a.current;return()=>{try{const P=T?.getURL?.();P&&P!=="about:blank"&&i(e,n,P)}catch{}try{T?.executeJavaScript?.(Pc).catch(()=>{})}catch{}}},[e,n,i]);const S=o.useCallback(T=>{const P=a.current;if(typeof P?.loadURL!="function")return;const A=Ac(T);try{P.loadURL(A)}catch{}},[]),I=o.useCallback(()=>{const T=a.current;if(T){if(f){b(!1);try{T.executeJavaScript?.(Pc).catch(()=>{})}catch{}return}b(!0),T.executeJavaScript?.(IS,!0).then(async P=>{if(b(!1),!P||!xd(P))return;const A=y??(C?"draft":null);if(!A){G.error(r("contextPanel.preview.inspect.attachNoSession"));return}const N=typeof T.getWebContentsId=="function"?T.getWebContentsId():null;if(N==null)return;const E=await Ob("desktop_browser_capture_page",{webContentsId:N}),M=await T.executeJavaScript?.("({ width: window.innerWidth, height: window.innerHeight })",!0).catch(()=>null),O=Number.isFinite(M?.width)?M.width:E.width,V=Number.isFinite(M?.height)?M.height:E.height,B=await PS(E.base64,E.width,E.height,O,V,P),$=!!B;B&&await w(B),k({sessionKey:A,source:"preview-annotation",fileLabel:m||"browser",startLine:1,endLine:1,code:lg({pageUrl:m,viewport:{width:O,height:V},devicePixelRatio:window.devicePixelRatio||1,target:P,screenshotAttached:$,intro:r("contextPanel.preview.inspect.attachAnnotationWithScreenshot")}),language:"markdown",text:""}),G.success(r("contextPanel.preview.inspect.attached"))}).catch(()=>b(!1))}},[w,k,y,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(ve,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{a.current?.goBack?.()}catch{}},children:s.jsx(D,{name:"arrow-left",className:"h-3.5 w-3.5"})}),s.jsx(ve,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{a.current?.goForward?.()}catch{}},children:s.jsx(D,{name:"arrow-right",className:"h-3.5 w-3.5"})}),s.jsx(ve,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{a.current?.reload?.()}catch{}},children:s.jsx(D,{name:"refresh",className:"h-3.5 w-3.5"})}),s.jsx("form",{className:"min-w-0 flex-1",onSubmit:T=>{T.preventDefault(),S(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(ve,{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(D,{name:"cursor",className:"h-3.5 w-3.5"})}),s.jsx(ve,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{Zn(m)},children:s.jsx(D,{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:Ac(t),partition:"persist:openchamber-browser",style:{width:"100%",height:"100%",border:"none"}}),(!m||m==="about:blank")&&!g?s.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-6 bg-background p-6 text-center",children:[s.jsx(Vd,{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]})]})},FS=()=>{const{t}=ut(),e=ra()??"",n=o.useMemo(()=>vS(e),[e]),r=Re(W=>n?W.contextPanelByDirectory[n]:void 0),a=Re(W=>W.closeContextPanel),i=Re(W=>W.closeContextPanelTab),l=Re(W=>W.toggleContextPanelExpanded),c=Re(W=>W.setContextPanelWidth),d=Re(W=>W.setActiveContextPanelTab),p=Re(W=>W.reorderContextPanelTabs),m=On(W=>W.setSelectedPath),u=Re(W=>W.openContextPreview),{themeMode:f,lightThemeId:b,darkThemeId:g,currentTheme:v}=vr(),x=o.useMemo(()=>r?.tabs??[],[r?.tabs]),h=x.find(W=>W.id===r?.activeTabId)??x[x.length-1]??null,j=!!(r?.isOpen&&h),y=!!(j&&r?.expanded),C=op(r?.width??og),[k,w]=o.useState(!1),S=o.useRef(0),I=o.useRef(C),T=o.useRef(null),P=o.useRef(null),A=o.useRef(null),N=o.useRef(new Map),E=o.useRef(!1);o.useEffect(()=>{if(!j||E.current){E.current=j;return}const W=window.requestAnimationFrame(()=>{A.current?.focus({preventScroll:!0})});return E.current=!0,()=>window.cancelAnimationFrame(W)},[j]);const M=o.useCallback(W=>{const de=A.current;de&&de.style.setProperty("--oc-context-panel-width",`${W}px`)},[]),O=o.useCallback(W=>{if(!(!j||y||!n)){try{W.currentTarget.setPointerCapture(W.pointerId)}catch{}P.current=W.pointerId,w(!0),S.current=W.clientX,I.current=C,T.current=C,M(C),W.preventDefault()}},[M,n,y,j,C]),V=o.useCallback(W=>{if(!k||P.current!==W.pointerId)return;const de=S.current-W.clientX,be=op(I.current+de);T.current!==be&&(T.current=be,M(be))},[M,k]),B=o.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]);o.useEffect(()=>{k||(T.current=null)},[k]);const $=o.useCallback(()=>{n&&a(n)},[a,n]),F=o.useCallback(()=>{n&&l(n)},[n,l]),_=o.useCallback(W=>{W.key==="Escape"&&(W.preventDefault(),W.stopPropagation(),$())},[$]);o.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=o.useCallback(()=>{if(typeof window>"u")return;const W={themeMode:f,lightThemeId:b,darkThemeId:g,currentTheme:v};for(const de of N.current.values()){const be=de.contentWindow;if(!be)continue;const we=be.__openchamberApplyThemeSync;if(typeof we=="function")try{we(W);continue}catch{}be.postMessage({type:"openchamber:theme-sync",payload:W},window.location.origin)}},[v,g,b,f]),Y=o.useCallback(()=>{if(!(typeof window>"u"))for(const[W,de]of N.current.entries()){const be=de.contentWindow;if(!be)continue;const we={visible:q===W},te=be.__openchamberSetEmbeddedVisibility;if(typeof te=="function")try{te(we);continue}catch{}be.postMessage({type:"openchamber:embedded-visibility",payload:we},window.location.origin)}},[q]);o.useLayoutEffect(()=>{x.some(de=>de.mode==="chat")&&(L(),Y())},[g,b,Y,L,x,f]);const Z=o.useMemo(()=>x.map(W=>{const de=SS(W,t),be=DS(de,xS),we=wS(W.targetPath,e);return{id:W.id,label:be,icon:kS(W),title:we?`${de}: ${we}`:de,closeLabel:t("contextPanel.tab.closeTabAria",{label:be})}}),[e,t,x]),ae=h?.mode==="diff"?s.jsx(sg,{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(aS,{}):h?.mode==="plan"?s.jsx(ig,{targetPath:h.targetPath}):h?.mode==="preview"?s.jsx(ES,{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(D,{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")})]}),re=o.useMemo(()=>x.filter(W=>W.mode==="chat"),[x]),me=o.useMemo(()=>x.filter(W=>W.mode==="browser"),[x]),fe=o.useMemo(()=>x.some(W=>W.mode==="file"),[x]),H=h?.mode==="file",K=s.jsxs("header",{className:"flex h-10 items-stretch border-b border-transparent",children:[s.jsx(Vr,{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(ve,{type:"button",variant:"ghost",size:"sm",onClick:F,className:"h-7 w-7 p-0",title:t(y?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),"aria-label":t(y?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),children:y?s.jsx(D,{name:"fullscreen-exit",className:"h-3.5 w-3.5"}):s.jsx(D,{name:"fullscreen",className:"h-3.5 w-3.5"})}),s.jsx(ve,{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(D,{name:"close",className:"h-3.5 w-3.5"})})]})]});if(!j)return null;const Q=y?{"--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:A,"data-context-panel":"true",tabIndex:-1,className:ye("flex min-h-0 flex-col overflow-hidden bg-background",!y&&"border-l border-border/40",y?"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:[!y&&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:O,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:[fe?s.jsx("div",{className:ye("absolute inset-0",H?"block":"hidden"),children:s.jsx(ag,{mode:"editor-only"})}):null,re.map(W=>{const de=CS(W.dedupeKey);if(!de)return null;const be=AS(de,n||null,W.readOnly);return be?s.jsx("iframe",{ref:we=>{if(!we){N.current.delete(W.id);return}N.current.set(W.id,we)},src:be,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(),Y()}},W.id):null}),me.map(W=>s.jsx("div",{className:ye("absolute inset-0",h?.mode!=="browser"&&"hidden"),children:s.jsx(RS,{initialUrl:W.targetPath??"",directory:n,tabID:W.id})},W.id)),h?.mode!=="chat"&&!H&&h?.mode!=="browser"?ae:null]})]})},tu=[{slug:"home",title:"Settings",group:"general",kind:"single",description:"Search and jump to common pages.",keywords:["search","settings"]},{slug:"projects",title:"Projects",group:"projects",kind:"split",keywords:["project","projects","worktree","worktrees","repo","repository","directory"]},{slug:"remote-instances",title:"Remote Instances",group:"projects",kind:"split",keywords:["ssh","remote","instances","tunnels","forwarding","connection"],isAvailable:t=>t.isDesktop&&!t.isWeb&&!t.isVSCode},{slug:"providers",title:"Providers",group:"opencode",kind:"split",keywords:["provider","providers","models","model","api key","api keys","openai","anthropic","ollama","credentials"]},{slug:"usage",title:"Usage",group:"usage",kind:"split",keywords:["quota","billing","tokens","usage","limits"]},{slug:"agents",title:"Agents",group:"opencode",kind:"split",keywords:["agent","agents","prompts","tools","permissions"]},{slug:"behavior",title:"Behavior",group:"opencode",kind:"single",keywords:["behavior","agents.md","system prompt","global rules","instructions","override"]},{slug:"commands",title:"Commands",group:"opencode",kind:"split",keywords:["command","commands","slash","macros","automation"]},{slug:"mcp",title:"MCP",group:"opencode",kind:"split",keywords:["mcp","model context protocol","servers","tools","remote","stdio"]},{slug:"skills.installed",title:"Skills",group:"skills",kind:"split",keywords:["skill","skills","instructions","install","catalog"]},{slug:"skills.catalog",title:"Skills Catalog",group:"skills",kind:"single",keywords:["install","catalog","external","repository","skills catalog"]},{slug:"git",title:"Git",group:"git",kind:"single",keywords:["git","github","identity","identities","ssh","profiles","credentials","keys","commit","gitmoji","oauth","prs","issues"],isAvailable:t=>!t.isVSCode},{slug:"appearance",title:"Appearance",group:"appearance",kind:"single",keywords:["theme","font","spacing","padding","corner radius","radius","input bar","keyboard","viewport","mobile","terminal","pwa","install name","app shortcuts"]},{slug:"chat",title:"Chat",group:"general",kind:"single",keywords:["tools","diff","reasoning","dotfiles","draft","queue","output","copy","image","split messages","message actions"]},{slug:"shortcuts",title:"Shortcuts",group:"general",kind:"single",keywords:["keyboard","hotkeys","shortcuts","bindings"],isAvailable:t=>!t.isVSCode},{slug:"sessions",title:"Sessions",group:"general",kind:"single",keywords:["defaults","default agent","default model","retention","memory","limits","zen"]},{slug:"magic-prompts",title:"Magic Prompts",group:"general",kind:"split",keywords:["prompts","templates","git","github","review","commit","pull request"],isAvailable:t=>!t.isVSCode},{slug:"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}],OS={sessions:"sessions",agents:"agents",commands:"commands",mcp:"mcp",skills:"skills.installed",providers:"providers",usage:"usage","git-identities":"git",settings:"home"};function Ki(t){const e=t.trim().toLowerCase();return tu.find(n=>n.slug===e)??null}function su(t){const e=(t??"").trim().toLowerCase();if(!e)return"home";const n=OS[e];if(n)return n;const r=Ki(e);return r?r.slug:"home"}const cg=t=>t.replace(/[-_]/g," ").replace(/\b\w/g,e=>e.toUpperCase()),jo=t=>{const e=ot.c(39),{className:n}=t,{t:r}=ut(),a=Cs(LS),i=Cs($S),l=Cs(_S),c=mn();let d;e[0]!==a?(d=[...a].sort(BS),e[0]=a,e[1]=d):d=e[1];const p=d;let m;e:{if(p.length===0){m=null;break e}let M;e[2]!==i||e[3]!==p?(M=p.find(O=>O.id===i)??p[0],e[2]=i,e[3]=p,e[4]=M):M=e[4],m=M}const u=m;if(c||p.length===0)return null;let f;e[5]!==u||e[6]!==r?(f=u?.label&&u.label.trim().length>0?u.label:u?.path.split("/").filter(Boolean).pop()||u?.path||r("settings.shared.projectSelector.fallbackProject"),e[5]=u,e[6]=r,e[7]=f):f=e[7];const b=f;let g;e[8]!==b?(g=cg(b),e[8]=b,e[9]=g):g=e[9];const v=g;let x;e[10]!==n?(x=ye(n),e[10]=n,e[11]=x):x=e[11];let h;e[12]!==r?(h=r("settings.shared.projectSelector.switchProjectAria"),e[12]=r,e[13]=h):h=e[13];let j;e[14]!==r?(j=r("settings.shared.projectSelector.switchProjectTitle"),e[14]=r,e[15]=j):j=e[15];let y,C;e[16]===Symbol.for("react.memo_cache_sentinel")?(y=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(D,{name:"folder",className:"h-4 w-4 opacity-70"}),e[16]=y,e[17]=C):(y=e[16],C=e[17]);let k;e[18]!==v?(k=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium",children:v}),e[18]=v,e[19]=k):k=e[19];let w;e[20]===Symbol.for("react.memo_cache_sentinel")?(w=s.jsx(D,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[20]=w):w=e[20];let S;e[21]!==k||e[22]!==h||e[23]!==j?(S=s.jsx(Is,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":h,title:j,className:y,children:[C,k,w]})}),e[21]=k,e[22]=h,e[23]=j,e[24]=S):S=e[24];const I=u?.id??"";let T;e[25]!==l?(T=M=>{M&&l(M)},e[25]=l,e[26]=T):T=e[26];let P;e[27]!==p?(P=p.map(VS),e[27]=p,e[28]=P):P=e[28];let A;e[29]!==I||e[30]!==T||e[31]!==P?(A=s.jsx(Ps,{align:"start",className:"w-auto",children:s.jsx(hl,{value:I,onValueChange:T,children:P})}),e[29]=I,e[30]=T,e[31]=P,e[32]=A):A=e[32];let N;e[33]!==S||e[34]!==A?(N=s.jsxs(As,{children:[S,A]}),e[33]=S,e[34]=A,e[35]=N):N=e[35];let E;return e[36]!==N||e[37]!==x?(E=s.jsx("div",{className:x,children:N}),e[36]=N,e[37]=x,e[38]=E):E=e[38],E};function LS(t){return t.projects}function $S(t){return t.activeProjectId}function _S(t){return t.setActiveProject}function BS(t,e){return(t.label||t.path).localeCompare(e.label||e.path)}function VS(t){const e=t.label?.trim()?t.label.trim():t.path.split("/").filter(Boolean).pop()||t.path,n=cg(e);return s.jsx(gl,{value:t.id,children:s.jsx("span",{className:"min-w-0 truncate typography-ui",children:n})},t.id)}function zS(t,e){return`opencode:sidebar-group:${t}:${e}`}const bd=t=>{const e=ot.c(33),{label:n,count:r,storageKey:a,defaultExpanded:i,children:l}=t,c=i===void 0?!0:i;let d;e[0]!==n||e[1]!==a?(d=zS(a,n),e[0]=n,e[1]=a,e[2]=d):d=e[2];const p=d,m=o.useId();let u;e[3]!==c||e[4]!==p?(u=()=>{try{const A=localStorage.getItem(p);if(A!==null)return A==="true"}catch{}return c},e[3]=c,e[4]=p,e[5]=u):u=e[5];const[f,b]=_e.useState(u);let g,v;e[6]!==f||e[7]!==p?(g=()=>{try{localStorage.setItem(p,String(f))}catch{}},v=[p,f],e[6]=f,e[7]=p,e[8]=g,e[9]=v):(g=e[8],v=e[9]),_e.useEffect(g,v);let x;e[10]===Symbol.for("react.memo_cache_sentinel")?(x=()=>b(US),e[10]=x):x=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 y;e[12]!==j?(y=ye("h-3.5 w-3.5 flex-shrink-0 transition-transform duration-200",j),e[12]=j,e[13]=y):y=e[13];let C;e[14]!==y?(C=s.jsx(D,{name:"arrow-down-s",className:y}),e[14]=y,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 S;e[20]!==m||e[21]!==f||e[22]!==C||e[23]!==k||e[24]!==w?(S=s.jsxs("button",{type:"button",onClick:x,"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]=S):S=e[25];const I=!f;let T;e[26]!==l||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:l}),e[26]=l,e[27]=m,e[28]=I,e[29]=T):T=e[29];let P;return e[30]!==S||e[31]!==T?(P=s.jsxs("div",{children:[S,T]}),e[30]=S,e[31]=T,e[32]=P):P=e[32],P};function US(t){return!t}const WS=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},KS=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())},lp=t=>{const e=KS(WS(t));if(e.length===0)return;const n={};for(const a of e)a.permission&&((n[a.permission]||={})[a.pattern]=a.action);const r={};for(const[a,i]of Object.entries(n)){const l=Object.keys(i);if(l.length===1&&l[0]==="*"){r[a]=i["*"];continue}r[a]=i}return Object.keys(r).length>0?r:void 0},HS=({onItemSelect:t})=>{const{t:e}=ut(),[n,r]=o.useState(null),[a,i]=o.useState(""),[l,c]=o.useState(null),[d,p]=o.useState(null),[m,u]=o.useState(!1),[f,b]=o.useState(null),{selectedAgentName:g,agents:v,setSelectedAgent:x,setAgentDraft:h,createAgent:j,deleteAgent:y,loadAgents:C}=fi(er(_=>({selectedAgentName:_.selectedAgentName,agents:_.agents,setSelectedAgent:_.setSelectedAgent,setAgentDraft:_.setAgentDraft,createAgent:_.createAgent,deleteAgent:_.deleteAgent,loadAgents:_.loadAgents})));o.useEffect(()=>{C()},[C]);const k="bg-background",w=()=>{const _="new-agent";let q=_,L=1;for(;v.some(Y=>Y.name===q);)q=`${_}-${L}`,L++;h({name:q,scope:"user"}),x(q),t?.()},S=async _=>{if(ii(_)){G.error(e("settings.agents.sidebar.toast.builtInCannotDelete"));return}c(_),p("delete")},I=async _=>{ii(_)&&(c(_),p("reset"))},T=()=>{c(null),p(null)},P=async()=>{if(!l||!d)return;u(!0),await y(l.name)?(d==="delete"?G.success(e("settings.agents.sidebar.toast.agentDeleted",{name:l.name})):G.success(e("settings.agents.sidebar.toast.agentReset",{name:l.name})),T()):d==="delete"?G.error(e("settings.agents.sidebar.toast.deleteFailed")):G.error(e("settings.agents.sidebar.toast.resetFailed")),u(!1)},A=_=>{const q=_.name;let L=1,Y=`${q}-copy`;for(;v.some(me=>me.name===Y);)L++,Y=`${q}-copy-${L}`;const Z=_,ae=_.model?.providerID&&_.model?.modelID?`${_.model.providerID}/${_.model.modelID}`:null,re=_;h({name:Y,scope:Z.scope||"user",description:_.description,model:ae,temperature:_.temperature,top_p:_.topP,prompt:_.prompt,mode:_.mode,permission:lp(_.permission),disable:re.disable}),x(Y)},N=_=>{i(_.name),r(_)},E=async()=>{if(!n)return;const _=a.trim().replace(/\s+/g,"-");if(!_){G.error(e("settings.agents.sidebar.toast.agentNameRequired"));return}if(_===n.name){r(null);return}if(v.some(Z=>Z.name===_)){G.error(e("settings.agents.sidebar.toast.agentExists"));return}const q=n.model?.providerID&&n.model?.modelID?`${n.model.providerID}/${n.model.modelID}`:null,L=n;await j({name:_,description:n.description,model:q,temperature:n.temperature,top_p:n.topP,prompt:n.prompt,mode:n.mode,permission:lp(n.permission),disable:L.disable,scope:L.scope})?await y(n.name)?(G.success(`Agent renamed to "${_}"`),x(_)):G.error(e("settings.agents.sidebar.toast.removeOldAfterRenameFailed")):G.error(e("settings.agents.sidebar.toast.renameFailed")),r(null)},M=_=>{switch(_){case"primary":return s.jsx(D,{name:"ai-agent",className:"h-3 w-3 text-primary"});case"all":return s.jsx(D,{name:"ai-agent-fill",className:"h-3 w-3 text-primary"});case"subagent":return s.jsx(D,{name:"robot",className:"h-3 w-3 text-primary"});default:return null}},O=v.filter(_=>!Lb(_)),V=O.filter(ii),B=O.filter(_=>!ii(_)),{groupedCustomAgents:$,ungroupedCustomAgents:F}=_e.useMemo(()=>{const _={},q=[];for(const Y of B){const Z=Y;Z.group?(_[Z.group]||(_[Z.group]=[]),_[Z.group].push(Y)):q.push(Y)}return{groupedCustomAgents:Object.keys(_).sort((Y,Z)=>Y.localeCompare(Z)).map(Y=>({name:Y,agents:_[Y]})),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(jo,{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:O.length})}),s.jsx(ve,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:w,children:s.jsx(D,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(ws,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:O.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(D,{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(Dc,{agent:_,isSelected:g===_.name,onSelect:()=>{x(_.name),t?.()},onReset:()=>I(_),onDuplicate:()=>A(_),getAgentModeIcon:M,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(bd,{label:_,count:q.length,storageKey:"agents",children:q.map(L=>s.jsx(Dc,{agent:L,isSelected:g===L.name,onSelect:()=>{x(L.name),t?.()},onRename:()=>N(L),onDelete:()=>S(L),onDuplicate:()=>A(L),getAgentModeIcon:M,isMenuOpen:f===L.name,onMenuOpenChange:Y=>b(Y?L.name:null)},L.name))},_)),F.map(_=>s.jsx(Dc,{agent:_,isSelected:g===_.name,onSelect:()=>{x(_.name),t?.()},onRename:()=>N(_),onDelete:()=>S(_),onDuplicate:()=>A(_),getAgentModeIcon:M,isMenuOpen:f===_.name,onMenuOpenChange:q=>b(q?_.name:null)},_.name))]})]})}),s.jsx(ps,{open:l!==null&&d!==null,onOpenChange:_=>{!_&&!m&&T()},children:s.jsxs(ms,{className:"max-w-md",children:[s.jsxs(gs,{children:[s.jsx(fs,{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:l?.name??""}):e("settings.agents.sidebar.dialog.resetDescription",{name:l?.name??""})})]}),s.jsxs(Hs,{children:[s.jsx(ve,{size:"sm",variant:"ghost",onClick:T,disabled:m,children:e("settings.common.actions.cancel")}),s.jsx(ve,{size:"sm",onClick:P,disabled:m,children:e(d==="delete"?"settings.common.actions.delete":"settings.common.actions.reset")})]})]})}),s.jsx(ps,{open:n!==null,onOpenChange:_=>!_&&r(null),children:s.jsxs(ms,{children:[s.jsxs(gs,{children:[s.jsx(fs,{children:e("settings.agents.sidebar.renameDialog.title")}),s.jsx(Ns,{children:e("settings.agents.sidebar.renameDialog.description",{name:n?.name??""})})]}),s.jsx(Bt,{value:a,onChange:_=>i(_.target.value),placeholder:e("settings.agents.sidebar.renameDialog.placeholder"),className:"text-foreground placeholder:text-muted-foreground",onKeyDown:_=>{_.key==="Enter"&&E()}}),s.jsxs(Hs,{children:[s.jsx(ve,{size:"sm",variant:"ghost",onClick:()=>r(null),children:e("settings.common.actions.cancel")}),s.jsx(ve,{size:"sm",onClick:E,children:e("settings.common.actions.rename")})]})]})})]})},Dc=t=>{const e=ot.c(58),{agent:n,isSelected:r,onSelect:a,onDelete:i,onReset:l,onRename:c,onDuplicate:d,getAgentModeIcon:p,isMenuOpen:m,onMenuOpenChange:u}=t,{t:f}=ut(),b=n;let g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g=ro(),e[0]=g):g=e[0];const v=g,x=r?"bg-interactive-selection":"hover:bg-interactive-hover";let h;e[1]!==x?(h=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]=h):h=e[2];let j;e[3]!==u?(j=v?void 0:q=>{q.preventDefault(),u(!0)},e[3]=u,e[4]=j):j=e[4];let y;e[5]!==n.name?(y=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n.name}),e[5]=n.name,e[6]=y):y=e[6];let 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||ii(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:ii(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]!==y||e[15]!==C||e[16]!==k?(w=s.jsxs("div",{className:"flex items-center gap-1.5",children:[y,C,k]}),e[14]=y,e[15]=C,e[16]=k,e[17]=w):w=e[17];let S;e[18]!==n.description?(S=n.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n.description}),e[18]=n.description,e[19]=S):S=e[19];let I;e[20]!==a||e[21]!==w||e[22]!==S?(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,S]}),e[20]=a,e[21]=w,e[22]=S,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(ve,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(D,{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(Ot,{onClick:q=>{q.stopPropagation(),c()},children:[s.jsx(D,{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 A;e[28]!==d?(A=q=>{q.stopPropagation(),d()},e[28]=d,e[29]=A):A=e[29];let N;e[30]===Symbol.for("react.memo_cache_sentinel")?(N=s.jsx(D,{name:"file-copy",className:"h-4 w-4 mr-px"}),e[30]=N):N=e[30];let E;e[31]!==f?(E=f("settings.common.actions.duplicate"),e[31]=f,e[32]=E):E=e[32];let M;e[33]!==A||e[34]!==E?(M=s.jsxs(Ot,{onClick:A,children:[N,E]}),e[33]=A,e[34]=E,e[35]=M):M=e[35];let O;e[36]!==l||e[37]!==f?(O=l&&s.jsxs(Ot,{onClick:q=>{q.stopPropagation(),l()},children:[s.jsx(D,{name:"restart",className:"h-4 w-4 mr-px"}),f("settings.common.actions.reset")]}),e[36]=l,e[37]=f,e[38]=O):O=e[38];let V;e[39]!==i||e[40]!==f?(V=i&&s.jsxs(Ot,{onClick:q=>{q.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[s.jsx(D,{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]!==M||e[44]!==O||e[45]!==V?(B=s.jsxs(Ps,{align:"end",className:"w-fit min-w-20",children:[P,M,O,V]}),e[42]=P,e[43]=M,e[44]=O,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 F;e[51]!==I||e[52]!==$?(F=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[I,$]}),e[51]=I,e[52]=$,e[53]=F):F=e[53];let _;return e[54]!==F||e[55]!==h||e[56]!==j?(_=s.jsx("div",{className:h,onContextMenu:j,children:F}),e[54]=F,e[55]=h,e[56]=j,e[57]=_):_=e[57],_};function cp(t,e,n){return Math.min(n,Math.max(e,t))}function GS(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 dp(t,e){const n=GS(e);return n<=0?t:Number(t.toFixed(n))}const _n=_e.forwardRef((t,e)=>{const n=ot.c(125);let r,a,i,l,c,d,p,m,u,f,b,g,v;n[0]!==t?({value:v,onValueChange:p,min:u,max:f,step:b,className:r,containerClassName:a,onBlur:c,disabled:i,fallbackValue:l,onClear:d,emptyLabel:g,...m}=t,n[0]=t,n[1]=r,n[2]=a,n[3]=i,n[4]=l,n[5]=c,n[6]=d,n[7]=p,n[8]=m,n[9]=u,n[10]=f,n[11]=b,n[12]=g,n[13]=v):(r=n[1],a=n[2],i=n[3],l=n[4],c=n[5],d=n[6],p=n[7],m=n[8],u=n[9],f=n[10],b=n[11],g=n[12],v=n[13]);const x=u===void 0?-1/0:u,h=f===void 0?1/0:f,j=b===void 0?1:b,y=g===void 0?"—":g,{t:C}=ut();let k;n[14]!==v?(k=()=>v===void 0?"":String(v),n[14]=v,n[15]=k):k=n[15];const[w,S]=_e.useState(k),{isMobile:I}=an(),T=_e.useRef(!1),P=_e.useRef(null);let A;n[16]===Symbol.for("react.memo_cache_sentinel")?(A=()=>{if(typeof document>"u"||typeof window>"u")return;P.current?.();const Ce=Ne=>{Ne.preventDefault(),Ne.stopPropagation(),Ne.stopImmediatePropagation?.(),P.current?.()},X=window.setTimeout(()=>{P.current?.()},700),ie=()=>{window.clearTimeout(X),document.removeEventListener("click",Ce,!0),P.current=null};P.current=ie,document.addEventListener("click",Ce,!0)},n[16]=A):A=n[16];const N=A;let E,M;n[17]===Symbol.for("react.memo_cache_sentinel")?(E=()=>()=>{P.current?.()},M=[],n[17]=E,n[18]=M):(E=n[17],M=n[18]),_e.useEffect(E,M);let O,V;n[19]!==v?(V=()=>{S(v===void 0?"":String(v))},O=[v],n[19]=v,n[20]=O,n[21]=V):(O=n[20],V=n[21]),_e.useEffect(V,O);let B;e:{if(v!==void 0){B=v;break e}if(l!==void 0){B=l;break e}if(Number.isFinite(x)){B=x;break e}B=0}const $=B;let F;n[22]!==h||n[23]!==x||n[24]!==p||n[25]!==j?(F=Ce=>{const X=cp(Ce,x,h);p(dp(X,j))},n[22]=h,n[23]=x,n[24]=p,n[25]=j,n[26]=F):F=n[26];const _=F;let q;n[27]!==_||n[28]!==d?(q=Ce=>{const X=Ce.target.value;if(S(X),X.trim()===""){d?.();return}const ie=Number(X);Number.isFinite(ie)&&_(ie)},n[27]=_,n[28]=d,n[29]=q):q=n[29];const L=q;let Y;n[30]!==w||n[31]!==h||n[32]!==x||n[33]!==c||n[34]!==d||n[35]!==p||n[36]!==j||n[37]!==v?(Y=Ce=>{if(w.trim()===""){d||S(v===void 0?"":String(v)),c?.(Ce);return}const X=Number(w);if(!Number.isFinite(X))S(v===void 0?"":String(v));else{const ie=cp(X,x,h),Ne=dp(ie,j);Ne!==v&&p(Ne),S(String(Ne))}c?.(Ce)},n[30]=w,n[31]=h,n[32]=x,n[33]=c,n[34]=d,n[35]=p,n[36]=j,n[37]=v,n[38]=Y):Y=n[38];const Z=Y,ae=!!(i||$>=h),re=!!(i||$<=x);let me;n[39]!==$||n[40]!==_||n[41]!==re||n[42]!==j?(me=()=>{re||_($-j)},n[39]=$,n[40]=_,n[41]=re,n[42]=j,n[43]=me):me=n[43];const fe=me;let H;n[44]!==$||n[45]!==_||n[46]!==ae||n[47]!==j?(H=()=>{ae||_($+j)},n[44]=$,n[45]=_,n[46]=ae,n[47]=j,n[48]=H):H=n[48];const K=H;let Q;if(n[49]!==r||n[50]!==a||n[51]!==re||n[52]!==w||n[53]!==y||n[54]!==fe||n[55]!==K||n[56]!==ae||n[57]!==I||n[58]!==C||n[59]!==v){Q=Symbol.for("react.early_return_sentinel");e:{const Ce=ie=>Ne=>{Ne.preventDefault(),Ne.stopPropagation(),T.current=!0,N(),ie()},X=ie=>Ne=>{if(T.current){T.current=!1,Ne.preventDefault(),Ne.stopPropagation();return}ie()};if(I){let ie;n[61]!==a?(ie=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]=ie):ie=n[62];let Ne;n[63]!==C?(Ne=C("numberInput.actions.decreaseAria"),n[63]=C,n[64]=Ne):Ne=n[64];const oe=Ce(fe),ke=X(fe),Te=!re&&"active:bg-interactive-hover";let Be;n[65]!==Te?(Be=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",Te),n[65]=Te,n[66]=Be):Be=n[66];let je;n[67]===Symbol.for("react.memo_cache_sentinel")?(je=s.jsx(D,{name:"subtract",className:"block h-4 w-4"}),n[67]=je):je=n[67];const ee=s.jsx("button",{type:"button","aria-label":Ne,disabled:re,onTouchStart:oe,onClick:ke,className:Be,children:je});let R;n[68]!==r?(R=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]=R):R=n[69];const U=v===void 0?y:w;let le;n[70]!==R||n[71]!==U?(le=s.jsx("div",{className:R,"aria-live":"polite",children:U}),n[70]=R,n[71]=U,n[72]=le):le=n[72];let Me;n[73]!==C?(Me=C("numberInput.actions.increaseAria"),n[73]=C,n[74]=Me):Me=n[74];const Oe=Ce(K),Ae=X(K),z=!ae&&"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 Xe;n[77]===Symbol.for("react.memo_cache_sentinel")?(Xe=s.jsx(D,{name:"add",className:"block h-4 w-4"}),n[77]=Xe):Xe=n[77];const st=s.jsx("button",{type:"button","aria-label":Me,disabled:ae,onTouchStart:Oe,onClick:Ae,className:De,children:Xe});let tt;n[78]!==ie||n[79]!==ee||n[80]!==le||n[81]!==st?(tt=s.jsxs("div",{className:ie,children:[ee,le,st]}),n[78]=ie,n[79]=ee,n[80]=le,n[81]=st,n[82]=tt):tt=n[82],Q=tt;break e}}n[49]=r,n[50]=a,n[51]=re,n[52]=w,n[53]=y,n[54]=fe,n[55]=K,n[56]=ae,n[57]=I,n[58]=C,n[59]=v,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 be;n[87]!==$||n[88]!==_||n[89]!==j?(be=()=>_($-j),n[87]=$,n[88]=_,n[89]=j,n[90]=be):be=n[90];let we,te;n[91]===Symbol.for("react.memo_cache_sentinel")?(we=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(D,{name:"subtract",className:"block h-3.5 w-3.5"}),n[91]=we,n[92]=te):(we=n[91],te=n[92]);let ge;n[93]!==re||n[94]!==de||n[95]!==be?(ge=s.jsx("button",{type:"button","aria-label":de,disabled:re,onClick:be,className:we,children:te}),n[93]=re,n[94]=de,n[95]=be,n[96]=ge):ge=n[96];const ue=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 ne;n[99]!==i||n[100]!==w||n[101]!==Z||n[102]!==L||n[103]!==m||n[104]!==e||n[105]!==ue||n[106]!==xe?(ne=s.jsx("input",{...m,ref:e,type:"text",inputMode:ue,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]=ue,n[106]=xe,n[107]=ne):ne=n[107];let pe;n[108]!==C?(pe=C("numberInput.actions.increaseAria"),n[108]=C,n[109]=pe):pe=n[109];let J;n[110]!==$||n[111]!==_||n[112]!==j?(J=()=>_($+j),n[110]=$,n[111]=_,n[112]=j,n[113]=J):J=n[113];let Se,he;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"),he=s.jsx(D,{name:"add",className:"block h-3.5 w-3.5"}),n[114]=Se,n[115]=he):(Se=n[114],he=n[115]);let Ie;n[116]!==ae||n[117]!==pe||n[118]!==J?(Ie=s.jsx("button",{type:"button","aria-label":pe,disabled:ae,onClick:J,className:Se,children:he}),n[116]=ae,n[117]=pe,n[118]=J,n[119]=Ie):Ie=n[119];let Pe;return n[120]!==W||n[121]!==ge||n[122]!==ne||n[123]!==Ie?(Pe=s.jsxs("div",{className:W,children:[ge,ne,Ie]}),n[120]=W,n[121]=ge,n[122]=ne,n[123]=Ie,n[124]=Pe):Pe=n[124],Pe});_n.displayName="NumberInput";const up=["*","read","edit","glob","grep","list","bash","task","skill","lsp","todoread","todowrite","webfetch","websearch","codesearch","external_directory","doom_loop","question","plan_enter","plan_exit"],nl=t=>t==="allow"||t==="ask"||t==="deny",Ma=(t,e)=>`${t}::${e}`,Ga=t=>{const e=new Map;for(const n of t)!n.permission||n.permission==="invalid"||n.pattern&&nl(n.action)&&e.set(Ma(n.permission,n.pattern),{permission:n.permission,pattern:n.pattern,action:n.action});return Array.from(e.values())},$o=t=>{const e=new Map;for(const n of Ga(t))e.set(Ma(n.permission,n.pattern),n);return e},mp=t=>[...t].sort((e,n)=>{const r=e.permission.localeCompare(n.permission);return r!==0?r:e.pattern.localeCompare(n.pattern)}),qS=(t,e)=>{const n=mp(Ga(t)),r=mp(Ga(e));return n.length!==r.length?!1:n.every((a,i)=>{const l=r[i];return a.permission===l.permission&&a.pattern===l.pattern&&a.action===l.action})},YS=t=>t.find(n=>n.permission==="*"&&n.pattern==="*")?.action??"allow",QS=(t,e)=>Ga(t).filter(n=>!(n.permission==="*"&&n.pattern==="*")).filter(n=>n.pattern!=="*"||n.action!==e),JS=t=>{if(nl(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(nl(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))nl(i)&&e.push({permission:n,pattern:a,action:i})}return e},XS=(t,e)=>{const n=Ga(e),r={};for(const i of n)(r[i.permission]||={})[i.pattern]=i.action;const a={"*":t};for(const[i,l]of Object.entries(r))if(i!=="*"){if(Object.keys(l).length===1&&l["*"]){a[i]=l["*"];continue}a[i]=l}return a},ZS=()=>{const{t}=ut(),{isMobile:e}=an(),{selectedAgentName:n,getAgentByName:r,createAgent:a,updateAgent:i,agents:l,agentDraft:c,setAgentDraft:d}=fi(er(ie=>({selectedAgentName:ie.selectedAgentName,getAgentByName:ie.getAgentByName,createAgent:ie.createAgent,updateAgent:ie.updateAgent,agents:ie.agents,agentDraft:ie.agentDraft,setAgentDraft:ie.setAgentDraft}))),p=n?r(n):null,m=!!(c&&c.name===n&&!p),[u,f]=o.useState(""),[b,g]=o.useState("user"),[v,x]=o.useState(""),[h,j]=o.useState("subagent"),[y,C]=o.useState(""),[k,w]=o.useState(void 0),[S,I]=o.useState(void 0),[T,P]=o.useState(""),[A,N]=o.useState("allow"),[E,M]=o.useState([]),[O,V]=o.useState([]),[B,$]=o.useState(""),[F,_]=o.useState("*"),[q,L]=o.useState(!1),[Y,Z]=o.useState(!1),ae=o.useRef(null),re=Ks(ie=>ie.currentDirectory??null),[me,fe]=o.useState([]),H=ah(ie=>ie.permission);o.useEffect(()=>{let ie=!1;return(async()=>{const oe=await nn.listToolIds({directory:re});if(ie)return;const ke=new Set(["write","patch","multiedit"]),Te=oe.map(Be=>typeof Be=="string"?Be.trim():"").filter(Boolean).filter(Be=>Be!=="*").filter(Be=>Be!=="invalid").filter(Be=>!ke.has(Be));fe(Array.from(new Set(Te)).sort((Be,je)=>Be.localeCompare(je)))})(),()=>{ie=!0}},[re]);const K=o.useMemo(()=>{const ie=new Set;for(const Ne of l){const oe=Ga(Array.isArray(Ne.permission)?Ne.permission:[]);for(const ke of oe)ke.permission&&ke.permission!=="*"&&ke.permission!=="invalid"&&ie.add(ke.permission)}for(const Ne of Object.values(H))for(const oe of Ne){const ke=oe.permission?.trim();ke&&ke!=="invalid"&&ie.add(ke)}for(const Ne of me)ie.add(Ne);return Array.from(ie).sort((Ne,oe)=>Ne.localeCompare(oe))},[l,H,me]),Q=o.useMemo(()=>$o(E),[E]),W=o.useMemo(()=>$o(O),[O]),de=o.useCallback(ie=>W.get(Ma(ie,"*"))?.action,[W]),be=o.useCallback(ie=>O.filter(Ne=>Ne.permission===ie&&Ne.pattern!=="*").sort((Ne,oe)=>Ne.pattern.localeCompare(oe.pattern)),[O]),we=o.useMemo(()=>{const ie=new Set;for(const Ne of up)ie.add(Ne);for(const Ne of K)ie.add(Ne);return Array.from(ie).sort((Ne,oe)=>Ne.localeCompare(oe))},[K]),te=o.useCallback(ie=>{const Ne=ie==="*"?A:de(ie)??A,oe=be(ie),ke=!1,Te=oe.reduce((je,ee)=>(je[ee.action]=(je[ee.action]??0)+1,je),{allow:0,ask:0,deny:0}),Be=["allow","ask","deny"].filter(je=>Te[je]>0).map(je=>`${Te[je]} ${je}`).join(", ");return{defaultAction:Ne,patternRulesCount:oe.length,patternSummary:Be,hasDefaultHint:ke}},[be,de,A]),ge=o.useCallback(ie=>t(ie==="allow"?"settings.common.permission.allow":ie==="deny"?"settings.common.permission.deny":"settings.common.permission.ask"),[t]),ue=o.useCallback(ie=>ie==="global"?t("settings.common.scope.global"):ge(ie),[ge,t]),xe=o.useMemo(()=>{const ie=new Set;for(const Ne of up)ie.add(Ne);for(const Ne of K)ie.add(Ne);return Array.from(ie).sort((Ne,oe)=>Ne.localeCompare(oe))},[K]),ne=o.useCallback((ie,Ne,oe)=>{V(ke=>{const Te=$o(ke);return Te.set(Ma(ie,Ne),{permission:ie,pattern:Ne,action:oe}),Array.from(Te.values())})},[]),pe=o.useCallback((ie,Ne)=>{V(oe=>{const ke=$o(oe);return ke.delete(Ma(ie,Ne)),Array.from(ke.values())})},[]),J=o.useCallback((ie,Ne)=>{const oe=Q.get(Ma(ie,Ne));if(oe){ne(ie,Ne,oe.action);return}pe(ie,Ne)},[Q,pe,ne]),Se=o.useCallback((ie,Ne,oe)=>{ne(ie,Ne,oe)},[ne]),he=o.useCallback(ie=>{N(ie),V(Ne=>Ne.filter(oe=>!(oe.pattern==="*"&&oe.action===ie)))},[]),Ie=o.useCallback(ie=>{const Ne=B.trim();if(!Ne){G.error(t("settings.agents.page.toast.permissionNameRequired"));return}const oe=F.trim()||"*";if(Ne==="*"&&oe==="*"){he(ie),$(""),_("*");return}oe==="*"&&Ne!=="*"&&ie===A?pe(Ne,"*"):ne(Ne,oe,ie),$(""),_("*")},[A,B,F,pe,he,t,ne]),Pe=o.useCallback(ie=>ie==="*"?t("settings.agents.page.permissions.defaultLabel"):ie==="webfetch"?"WebFetch":ie==="websearch"?"WebSearch":ie==="codesearch"?"CodeSearch":ie==="doom_loop"?"Doom Loop":ie==="external_directory"?"External Directory":ie==="todowrite"?"TodoWrite":ie==="todoread"?"TodoRead":ie.split(/[_-]+/g).filter(Boolean).map(Ne=>Ne.charAt(0).toUpperCase()+Ne.slice(1)).join(" "),[t]);o.useEffect(()=>{$(""),_("*");const ie=Ne=>{const oe=Ga(Ne),ke=YS(oe),Te=QS(oe,ke);return N(ke),M(Te),V(Te),{global:ke,rules:Te}};if(m&&c){const Ne=c.name||"",oe=c.scope||"user",ke=c.description||"",Te=c.mode||"subagent",Be=c.model||"",je=c.temperature,ee=c.top_p,R=c.prompt||"";f(Ne),g(oe),x(ke),j(Te),C(Be),w(je),I(ee),P(R);const U=JS(c.permission),le=ie(U);ae.current={draftName:Ne,draftScope:oe,description:ke,mode:Te,model:Be,temperature:je,topP:ee,prompt:R,globalPermission:le.global,permissionRules:le.rules};return}if(p&&n===p.name){const Ne=p.description||"",oe=p.mode||"subagent",ke=p.model?.providerID&&p.model?.modelID?`${p.model.providerID}/${p.model.modelID}`:"",Te=p.temperature,Be=p.topP,je=p.prompt||"";x(Ne),j(oe),C(ke),w(Te),I(Be),P(je);const ee=ie(Array.isArray(p.permission)?p.permission:[]);ae.current={draftName:"",draftScope:"user",description:Ne,mode:oe,model:ke,temperature:Te,topP:Be,prompt:je,globalPermission:ee.global,permissionRules:ee.rules}}},[c,m,p,n]);const Ce=o.useMemo(()=>{const ie=ae.current;return ie?!!(m&&(u!==ie.draftName||b!==ie.draftScope)||v!==ie.description||h!==ie.mode||y!==ie.model||k!==ie.temperature||S!==ie.topP||T!==ie.prompt||A!==ie.globalPermission||!qS(O,ie.permissionRules)):!1},[v,u,b,A,m,h,y,O,T,k,S]),X=async()=>{const ie=m?u.trim().replace(/\s+/g,"-"):n?.trim();if(!ie){G.error(t("settings.agents.sidebar.toast.agentNameRequired"));return}if(m&&l.some(Ne=>Ne.name===ie)){G.error(t("settings.agents.sidebar.toast.agentExists"));return}Z(!0);try{const Ne=y.trim(),oe=XS(A,O),ke={name:ie,description:v.trim()||void 0,mode:h,model:Ne===""?null:Ne,temperature:k,top_p:S,prompt:T.trim()||void 0,permission:oe,scope:m?b:void 0};let Te;m?(Te=await a(ke),Te&&d(null)):Te=await i(ie,ke),Te?G.success(t(m?"settings.agents.page.toast.created":"settings.agents.page.toast.updated")):G.error(t(m?"settings.agents.page.toast.createFailed":"settings.agents.page.toast.updateFailed"))}catch(Ne){console.error("Error saving agent:",Ne);const oe=Ne instanceof Error&&Ne.message?Ne.message:t("settings.agents.page.toast.saveUnexpectedError");G.error(oe)}finally{Z(!1)}};return n?s.jsx(ws,{outerClassName:"h-full",className:"w-full",children:s.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[s.jsx("div",{className:"mb-4 flex items-center justify-between gap-4",children:s.jsxs("div",{className:"min-w-0",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:m?t("settings.agents.page.title.new"):n}),s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:t(m?"settings.agents.page.subtitle.new":"settings.agents.page.subtitle.edit")})]})}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.agents.page.section.identityRole")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[m&&s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.agents.page.field.agentName")})}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:[s.jsxs("div",{className:"flex items-center",children:[s.jsx("span",{className:"typography-ui-label text-muted-foreground mr-1",children:"@"}),s.jsx(Bt,{value:u,onChange:ie=>f(ie.target.value),placeholder:t("settings.agents.page.field.agentNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(is,{value:b,onValueChange:ie=>g(ie),children:[s.jsx(os,{className:"w-fit min-w-[100px]",children:s.jsx(us,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(ls,{align:"end",children:[s.jsx(Mt,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(D,{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(D,{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(jn,{value:v,onChange:ie=>x(ie.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(D,{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(ve,{variant:"chip",size:"xs","aria-pressed":h==="primary",onClick:()=>j("primary"),className:"!font-normal",children:t("settings.agents.page.mode.primary")}),s.jsx(ve,{variant:"chip",size:"xs","aria-pressed":h==="subagent",onClick:()=>j("subagent"),className:"!font-normal",children:t("settings.agents.page.mode.subagent")}),s.jsx(ve,{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(wo,{providerId:yi(y)?.providerId??"",modelId:yi(y)?.modelId??"",onChange:(ie,Ne)=>{C(ie&&Ne?`${ie}/${Ne}`:"")}})})]}),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(D,{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(ve,{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(D,{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(D,{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:S,fallbackValue:.9,onValueChange:I,onClear:()=>I(void 0),min:0,max:1,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),S!==void 0&&s.jsx(ve,{size:"sm",type:"button",variant:"ghost",onClick:()=>I(void 0),className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":t("settings.agents.page.field.clearTopPAria"),title:t("settings.common.actions.clear"),children:s.jsx(D,{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(jn,{value:T,onChange:ie=>P(ie.target.value),placeholder:t("settings.agents.page.field.systemPromptPlaceholder"),rows:8,className:"w-full font-mono typography-meta min-h-[120px] max-h-[60vh] bg-transparent resize-y"})})]}),s.jsxs("div",{className:"mb-2",children:[s.jsxs("div",{className:"mb-1 px-1 flex items-center justify-between gap-4",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.agents.page.section.toolPermissions")}),s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>L(ie=>!ie),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(is,{value:A,onValueChange:ie=>he(ie),children:[s.jsx(os,{className:"w-[100px]",children:s.jsx(us,{children:ge(A)})}),s.jsxs(ls,{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:we.filter(ie=>ie!=="*").map(ie=>{const Ne=Pe(ie),{defaultAction:oe,patternRulesCount:ke}=te(ie),Te=de(ie),Be=Te??"global",je=be(ie),ee=["allow","ask","deny"].filter(R=>R!==A);return s.jsxs("div",{className:"border-t border-[var(--surface-subtle)] pt-2",children:[s.jsxs("div",{className:"flex items-center justify-between py-1",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:Ne}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono",children:ie})]}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:ke>0?t("settings.agents.page.permissions.globalSummary",{summary:oe}):oe})]}),s.jsxs("div",{className:"space-y-1 pl-2 mt-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 py-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:t("settings.agents.page.permissions.pattern")}),s.jsx("span",{className:"typography-micro font-mono text-foreground bg-[var(--surface-muted)] px-1 rounded",children:"*"}),Te&&s.jsx(ve,{size:"sm",variant:"ghost",onClick:()=>J(ie,"*"),className:"px-1.5 py-0 h-5",children:s.jsx(D,{name:"subtract",className:"h-3.5 w-3.5 text-muted-foreground hover:text-foreground"})})]}),s.jsxs(is,{value:Be,onValueChange:R=>{if(R==="global"){pe(ie,"*");return}ne(ie,"*",R)},children:[s.jsx(os,{className:"w-[90px]",children:s.jsx(us,{children:ue(Be)})}),s.jsxs(ls,{children:[s.jsx(Mt,{value:"global",children:t("settings.common.scope.global")}),ee.map(R=>s.jsx(Mt,{value:R,className:"capitalize",children:ge(R)},R))]})]})]}),je.map(R=>{const U=Ma(R.permission,R.pattern),le=Q.get(U),Me=!le,Oe=!!(le&&le.action!==R.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:R.pattern}),Me&&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")}),(Me||Oe)&&s.jsx(ve,{size:"sm",variant:"ghost",onClick:()=>Me?pe(R.permission,R.pattern):J(R.permission,R.pattern),className:"px-1.5 py-0 h-5",children:s.jsx(D,{name:"subtract",className:"h-3.5 w-3.5 text-muted-foreground hover:text-foreground"})})]}),s.jsxs(is,{value:R.action,onValueChange:Ae=>Se(R.permission,R.pattern,Ae),children:[s.jsx(os,{className:"w-[90px]",children:s.jsx(us,{children:ge(R.action)})}),s.jsxs(ls,{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)})]})]},ie)})}),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(is,{value:B,onValueChange:$,children:[s.jsx(os,{className:"w-full sm:w-[160px]",children:B?s.jsx("span",{className:"truncate",children:Pe(B)}):s.jsx("span",{className:"text-muted-foreground",children:t("settings.agents.page.permissions.permissionPlaceholder")})}),s.jsx(ls,{children:xe.map(ie=>s.jsx(Mt,{value:ie,children:s.jsx("div",{className:"flex items-center justify-between gap-2 w-full",children:s.jsx("span",{children:Pe(ie)})})},ie))})]}),s.jsx(Bt,{value:F,onChange:ie=>_(ie.target.value),placeholder:t("settings.agents.page.permissions.patternPlaceholder"),className:"h-7 flex-1 font-mono text-xs"}),s.jsxs("div",{className:"flex gap-1",children:[s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ie("allow"),children:t("settings.common.permission.allow")}),s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ie("ask"),children:t("settings.common.permission.ask")}),s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ie("deny"),children:t("settings.common.permission.deny")})]})]})]})]}):s.jsx("section",{className:"px-2 pb-2 pt-0 space-y-0",children:we.map((ie,Ne)=>{const{defaultAction:oe,patternRulesCount:ke,patternSummary:Te,hasDefaultHint:Be}=te(ie),je=Pe(ie),ee=Be?`${oe} (env blocked)`:oe;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",Ne>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:je}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono hidden sm:inline-block",children:ie})]}),s.jsxs("div",{className:"flex items-center gap-3",children:[ke>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}),ke>0&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:t("settings.agents.page.permissions.rulesSummary",{summary:Te})})]})]},ie)})})]}),s.jsx("div",{className:"px-2 py-1",children:s.jsx(ve,{onClick:X,disabled:Y||!Ce,size:"xs",className:"!font-normal",children:t(Y?"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(D,{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")})]})})},ek="~/.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},tk=t=>t.length>0&&!t.endsWith(`
|
|
155
|
-
`)?`${t}
|
|
156
|
-
`:t,_o={prompt:"",responseStyleEnabled:!1,responseStylePreset:"concise",responseStyleCustomInstructions:""},sk=(t,e)=>t==="custom"?e:_b(t),nk=t=>t==="custom"?"custom":ih(t)?t:"concise",pp={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"},fp=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))},rk=()=>{const{t}=ut(),[e,n]=o.useState(""),[r,a]=o.useState(_o.responseStyleEnabled),[i,l]=o.useState(_o.responseStylePreset),[c,d]=o.useState(_o.responseStyleCustomInstructions),[p,m]=o.useState(!0),[u,f]=o.useState(!1),[b,g]=o.useState(""),v=o.useRef(null);o.useEffect(()=>{const y=new AbortController;return(async()=>{try{const[k,w]=await Promise.all([fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},signal:y.signal}),fetch("/api/behavior/agents-md",{method:"GET",headers:{Accept:"application/json"},signal:y.signal})]);let S=_o;if(k.ok){const I=await k.json();S={...S,responseStyleEnabled:I.responseStyleEnabled===!0,responseStylePreset:nk(I.responseStylePreset),responseStyleCustomInstructions:typeof I.responseStyleCustomInstructions=="string"?I.responseStyleCustomInstructions:""},typeof I.globalBehaviorPrompt=="string"&&(S={...S,prompt:I.globalBehaviorPrompt})}if(!S.prompt.trim()&&w.ok){const I=await w.json();typeof I.content=="string"&&(S={...S,prompt:I.content})}n(S.prompt),a(S.responseStyleEnabled),l(S.responseStylePreset),d(S.responseStyleCustomInstructions),g(S.prompt),v.current={enabled:S.responseStyleEnabled,preset:S.responseStylePreset,custom:S.responseStyleCustomInstructions}}catch(k){k.name!=="AbortError"&&console.warn("Failed to load behavior settings:",k)}finally{m(!1)}})(),()=>y.abort()},[]),o.useEffect(()=>{if(p)return;const y=v.current;if(y&&y.enabled===r&&y.preset===i&&y.custom===c)return;const C={enabled:r,preset:i,custom:c},k=setTimeout(async()=>{try{await fp({responseStyleEnabled:C.enabled,responseStylePreset:C.preset,responseStyleCustomInstructions:C.custom},t("settings.behavior.page.toast.saveFailed")),v.current=C}catch(w){const S=w instanceof Error?w.message:t("settings.behavior.page.toast.saveFailed");G.error(S)}},400);return()=>clearTimeout(k)},[r,i,c,p,t]);const x=sk(i,c),h=e!==b,j=async()=>{f(!0);try{const y=tk(e),C=await fetch("/api/behavior/agents-md",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({content:y})});if(!C.ok)throw new Error(await dg(C,t("settings.behavior.page.toast.saveFailed")));await fp({globalBehaviorPrompt:y},t("settings.behavior.page.toast.saveFailed")),n(y),g(y),G.success(t("settings.behavior.page.toast.saved"))}catch(y){console.error("Failed to save behavior:",y);const C=y instanceof Error?y.message:t("settings.behavior.page.toast.saveFailed");G.error(C)}finally{f(!1)}};return s.jsx(ws,{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(D,{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:ek})})]})})]})]})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsx(jn,{value:e,onChange:y=>n(y.target.value),placeholder:t("settings.behavior.page.field.systemPromptPlaceholder"),rows:12,disabled:p,outerClassName:"min-h-[160px] max-h-[70vh]",className:"w-full font-mono typography-meta bg-transparent"}),s.jsx(ve,{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(D,{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(xs,{checked:r,onChange:a,disabled:p,ariaLabel:t("settings.behavior.page.responseStyle.enableAria")}),t("settings.behavior.page.responseStyle.enable")]}),s.jsxs(is,{value:i,onValueChange:y=>l(y),disabled:p||!r,children:[s.jsx(os,{className:"w-full sm:w-56",size:"lg",children:s.jsx(us,{children:y=>y==="custom"?t("settings.behavior.page.responseStyle.option.custom"):ih(y)?t(pp[y]):null})}),s.jsxs(ls,{children:[$b.map(y=>s.jsx(Mt,{value:y,children:t(pp[y])},y)),s.jsx(Mt,{value:"custom",children:t("settings.behavior.page.responseStyle.option.custom")})]})]}),s.jsx(jn,{value:x,onChange:y=>d(y.target.value),placeholder:t("settings.behavior.page.responseStyle.customPlaceholder"),rows:5,disabled:p||!r||i!=="custom",outerClassName:"min-h-[120px]",className:"w-full font-mono typography-meta bg-transparent"})]})]})]})})},ak=t=>{const e=ot.c(169),{onItemSelect:n}=t,{t:r}=ut(),[a,i]=o.useState(null),[l,c]=o.useState(""),[d,p]=o.useState(null),[m,u]=o.useState(null),[f,b]=o.useState(!1),[g,v]=o.useState(null),{selectedCommandName:x,commands:h,setSelectedCommand:j,setCommandDraft:y,createCommand:C,deleteCommand:k,loadCommands:w}=zd(er(ik)),S=ma(ok),I=ma(lk);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]),o.useEffect(T,P);let A;e[4]!==S?(A=new Set(S.map(ck)),e[4]=S,e[5]=A):A=e[5];const N=A;let E;if(e[6]!==h||e[7]!==N){let Le;e[9]!==N?(Le=Ge=>!N.has(Ge.name),e[9]=N,e[10]=Le):Le=e[10],E=h.filter(Le),e[6]=h,e[7]=N,e[8]=E}else E=e[8];const M=E;let O,V;e[11]!==x||e[12]!==j||e[13]!==N?(O=()=>{x&&N.has(x)&&j(null)},V=[x,j,N],e[11]=x,e[12]=j,e[13]=N,e[14]=O,e[15]=V):(O=e[14],V=e[15]),o.useEffect(O,V);let B;e[16]!==h||e[17]!==n||e[18]!==y||e[19]!==j?(B=()=>{let Le="new-command",Ge=1;for(;h.some(at=>at.name===Le);)Le=`new-command-${Ge}`,Ge++;y({name:Le,scope:"user"}),j(Le),n?.()},e[16]=h,e[17]=n,e[18]=y,e[19]=j,e[20]=B):B=e[20];const $=B;let F;e[21]!==r?(F=async Le=>{if(li(Le)){G.error(r("settings.commands.sidebar.toast.builtInCannotDelete"));return}p(Le),u("delete")},e[21]=r,e[22]=F):F=e[22];const _=F;let q;e[23]===Symbol.for("react.memo_cache_sentinel")?(q=async Le=>{li(Le)&&(p(Le),u("reset"))},e[23]=q):q=e[23];const L=q;let Y;e[24]===Symbol.for("react.memo_cache_sentinel")?(Y=()=>{p(null),u(null)},e[24]=Y):Y=e[24];const Z=Y;let ae;e[25]!==d||e[26]!==m||e[27]!==k||e[28]!==r?(ae=async()=>{if(!d||!m)return;b(!0),await k(d.name)?(m==="delete"?G.success(r("settings.commands.sidebar.toast.commandDeleted",{name:d.name})):G.success(r("settings.commands.sidebar.toast.commandReset",{name:d.name})),Z()):m==="delete"?G.error(r("settings.commands.sidebar.toast.deleteFailed")):G.error(r("settings.commands.sidebar.toast.resetFailed")),b(!1)},e[25]=d,e[26]=m,e[27]=k,e[28]=r,e[29]=ae):ae=e[29];const re=ae;let me;e[30]!==h||e[31]!==y||e[32]!==j?(me=Le=>{const Ge=Le.name;let at=1,He=`${Ge}-copy`;for(;h.some(ze=>ze.name===He);)at++,He=`${Ge}-copy-${at}`;y({name:He,scope:Le.scope||"user",description:Le.description,template:Le.template,agent:Le.agent,model:Le.model}),j(He)},e[30]=h,e[31]=y,e[32]=j,e[33]=me):me=e[33];const fe=me;let H;e[34]===Symbol.for("react.memo_cache_sentinel")?(H=Le=>{c(Le.name),i(Le)},e[34]=H):H=e[34];const K=H;let Q;e[35]!==h||e[36]!==C||e[37]!==k||e[38]!==a||e[39]!==l||e[40]!==j||e[41]!==r?(Q=async()=>{if(!a)return;const Le=l.trim().replace(/\s+/g,"-");if(!Le){G.error(r("settings.commands.sidebar.toast.commandNameRequired"));return}if(Le===a.name){i(null);return}if(h.some(at=>at.name===Le)){G.error(r("settings.commands.sidebar.toast.commandExists"));return}await C({name:Le,description:a.description,template:a.template,agent:a.agent,model:a.model})?await k(a.name)?(G.success(`Command renamed to "${Le}"`),j(Le)):G.error(r("settings.commands.sidebar.toast.removeOldAfterRenameFailed")):G.error(r("settings.commands.sidebar.toast.renameFailed")),i(null)},e[35]=h,e[36]=C,e[37]=k,e[38]=a,e[39]=l,e[40]=j,e[41]=r,e[42]=Q):Q=e[42];const W=Q;let de,be,we,te,ge,ue;if(e[43]!==M||e[44]!==$||e[45]!==_||e[46]!==fe||e[47]!==n||e[48]!==g||e[49]!==x||e[50]!==j||e[51]!==r){const Le=M.filter(li),Ge=M.filter(dk);e[58]===Symbol.for("react.memo_cache_sentinel")?(ge=ye("flex h-full flex-col","bg-background"),e[58]=ge):ge=e[58];let at;e[59]!==r?(at=r("settings.commands.sidebar.title"),e[59]=r,e[60]=at):at=e[60];let He;e[61]!==at?(He=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:at}),e[61]=at,e[62]=He):He=e[62];let ze;e[63]===Symbol.for("react.memo_cache_sentinel")?(ze=s.jsx(jo,{className:"mb-3"}),e[63]=ze):ze=e[63];let et;e[64]!==M.length||e[65]!==r?(et=r("settings.commands.sidebar.total",{count:M.length}),e[64]=M.length,e[65]=r,e[66]=et):et=e[66];let gt;e[67]!==et?(gt=s.jsx("span",{className:"typography-meta text-muted-foreground",children:et}),e[67]=et,e[68]=gt):gt=e[68];let Pt;e[69]===Symbol.for("react.memo_cache_sentinel")?(Pt=s.jsx(D,{name:"add",className:"h-3.5 w-3.5"}),e[69]=Pt):Pt=e[69];let Nt;e[70]!==$?(Nt=s.jsx(ve,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:$,children:Pt}),e[70]=$,e[71]=Nt):Nt=e[71];let ht;e[72]!==gt||e[73]!==Nt?(ht=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[gt,Nt]}),e[72]=gt,e[73]=Nt,e[74]=ht):ht=e[74],e[75]!==He||e[76]!==ht?(ue=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[He,ze,ht]}),e[75]=He,e[76]=ht,e[77]=ue):ue=e[77],de=ws,be="flex-1 min-h-0",we="space-y-1 px-3 py-2",te=M.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(D,{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:[Le.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")}),[...Le].sort(uk).map(wt=>s.jsx(hp,{command:wt,isSelected:x===wt.name,onSelect:()=>{j(wt.name),n?.()},onReset:()=>L(wt),onDuplicate:()=>fe(wt),isMenuOpen:g===wt.name,onMenuOpenChange:es=>v(es?wt.name:null)},wt.name))]}),Ge.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")}),[...Ge].sort(mk).map(wt=>s.jsx(hp,{command:wt,isSelected:x===wt.name,onSelect:()=>{j(wt.name),n?.()},onRename:()=>K(wt),onDelete:()=>_(wt),onDuplicate:()=>fe(wt),isMenuOpen:g===wt.name,onMenuOpenChange:es=>v(es?wt.name:null)},wt.name))]})]}),e[43]=M,e[44]=$,e[45]=_,e[46]=fe,e[47]=n,e[48]=g,e[49]=x,e[50]=j,e[51]=r,e[52]=de,e[53]=be,e[54]=we,e[55]=te,e[56]=ge,e[57]=ue}else de=e[52],be=e[53],we=e[54],te=e[55],ge=e[56],ue=e[57];let xe;e[78]!==de||e[79]!==be||e[80]!==we||e[81]!==te?(xe=s.jsx(de,{outerClassName:be,className:we,children:te}),e[78]=de,e[79]=be,e[80]=we,e[81]=te,e[82]=xe):xe=e[82];const ne=d!==null&&m!==null;let pe;e[83]!==f?(pe=Le=>{!Le&&!f&&Z()},e[83]=f,e[84]=pe):pe=e[84];let J;e[85]!==m||e[86]!==r?(J=r(m==="delete"?"settings.commands.sidebar.dialog.deleteTitle":"settings.commands.sidebar.dialog.resetTitle"),e[85]=m,e[86]=r,e[87]=J):J=e[87];let Se;e[88]!==J?(Se=s.jsx(fs,{children:J}),e[88]=J,e[89]=Se):Se=e[89];let he;e[90]!==d?.name||e[91]!==m||e[92]!==r?(he=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]=he):he=e[93];let Ie;e[94]!==he?(Ie=s.jsx(Ns,{children:he}),e[94]=he,e[95]=Ie):Ie=e[95];let Pe;e[96]!==Se||e[97]!==Ie?(Pe=s.jsxs(gs,{children:[Se,Ie]}),e[96]=Se,e[97]=Ie,e[98]=Pe):Pe=e[98];let Ce;e[99]!==r?(Ce=r("settings.common.actions.cancel"),e[99]=r,e[100]=Ce):Ce=e[100];let X;e[101]!==f||e[102]!==Ce?(X=s.jsx(ve,{size:"sm",variant:"ghost",onClick:Z,disabled:f,children:Ce}),e[101]=f,e[102]=Ce,e[103]=X):X=e[103];let ie;e[104]!==m||e[105]!==r?(ie=r(m==="delete"?"settings.common.actions.delete":"settings.common.actions.reset"),e[104]=m,e[105]=r,e[106]=ie):ie=e[106];let Ne;e[107]!==re||e[108]!==f||e[109]!==ie?(Ne=s.jsx(ve,{size:"sm",onClick:re,disabled:f,children:ie}),e[107]=re,e[108]=f,e[109]=ie,e[110]=Ne):Ne=e[110];let oe;e[111]!==X||e[112]!==Ne?(oe=s.jsxs(Hs,{children:[X,Ne]}),e[111]=X,e[112]=Ne,e[113]=oe):oe=e[113];let ke;e[114]!==Pe||e[115]!==oe?(ke=s.jsxs(ms,{className:"max-w-md",children:[Pe,oe]}),e[114]=Pe,e[115]=oe,e[116]=ke):ke=e[116];let Te;e[117]!==ne||e[118]!==pe||e[119]!==ke?(Te=s.jsx(ps,{open:ne,onOpenChange:pe,children:ke}),e[117]=ne,e[118]=pe,e[119]=ke,e[120]=Te):Te=e[120];const Be=a!==null;let je;e[121]===Symbol.for("react.memo_cache_sentinel")?(je=Le=>!Le&&i(null),e[121]=je):je=e[121];let ee;e[122]!==r?(ee=r("settings.commands.sidebar.renameDialog.title"),e[122]=r,e[123]=ee):ee=e[123];let R;e[124]!==ee?(R=s.jsx(fs,{children:ee}),e[124]=ee,e[125]=R):R=e[125];const U=a?.name??"";let le;e[126]!==r||e[127]!==U?(le=r("settings.commands.sidebar.renameDialog.description",{name:U}),e[126]=r,e[127]=U,e[128]=le):le=e[128];let Me;e[129]!==le?(Me=s.jsx(Ns,{children:le}),e[129]=le,e[130]=Me):Me=e[130];let Oe;e[131]!==R||e[132]!==Me?(Oe=s.jsxs(gs,{children:[R,Me]}),e[131]=R,e[132]=Me,e[133]=Oe):Oe=e[133];let Ae;e[134]===Symbol.for("react.memo_cache_sentinel")?(Ae=Le=>c(Le.target.value),e[134]=Ae):Ae=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=Le=>{Le.key==="Enter"&&W()},e[137]=W,e[138]=De):De=e[138];let Xe;e[139]!==l||e[140]!==z||e[141]!==De?(Xe=s.jsx(Bt,{value:l,onChange:Ae,placeholder:z,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:De}),e[139]=l,e[140]=z,e[141]=De,e[142]=Xe):Xe=e[142];let st;e[143]===Symbol.for("react.memo_cache_sentinel")?(st=()=>i(null),e[143]=st):st=e[143];let tt;e[144]!==r?(tt=r("settings.common.actions.cancel"),e[144]=r,e[145]=tt):tt=e[145];let Ue;e[146]!==tt?(Ue=s.jsx(ve,{size:"sm",variant:"ghost",onClick:st,children:tt}),e[146]=tt,e[147]=Ue):Ue=e[147];let it;e[148]!==r?(it=r("settings.common.actions.rename"),e[148]=r,e[149]=it):it=e[149];let Ye;e[150]!==W||e[151]!==it?(Ye=s.jsx(ve,{size:"sm",onClick:W,children:it}),e[150]=W,e[151]=it,e[152]=Ye):Ye=e[152];let rt;e[153]!==Ue||e[154]!==Ye?(rt=s.jsxs(Hs,{children:[Ue,Ye]}),e[153]=Ue,e[154]=Ye,e[155]=rt):rt=e[155];let Je;e[156]!==Oe||e[157]!==Xe||e[158]!==rt?(Je=s.jsxs(ms,{children:[Oe,Xe,rt]}),e[156]=Oe,e[157]=Xe,e[158]=rt,e[159]=Je):Je=e[159];let ce;e[160]!==Be||e[161]!==Je?(ce=s.jsx(ps,{open:Be,onOpenChange:je,children:Je}),e[160]=Be,e[161]=Je,e[162]=ce):ce=e[162];let We;return e[163]!==ge||e[164]!==ue||e[165]!==xe||e[166]!==Te||e[167]!==ce?(We=s.jsxs("div",{className:ge,children:[ue,xe,Te,ce]}),e[163]=ge,e[164]=ue,e[165]=xe,e[166]=Te,e[167]=ce,e[168]=We):We=e[168],We},hp=t=>{const e=ot.c(53),{command:n,isSelected:r,onSelect:a,onDelete:i,onReset:l,onRename:c,onDuplicate:d,isMenuOpen:p,onMenuOpenChange:m}=t,{t:u}=ut();let f;e[0]===Symbol.for("react.memo_cache_sentinel")?(f=ro(),e[0]=f):f=e[0];const b=f,g=r?"bg-interactive-selection":"hover:bg-interactive-hover";let v;e[1]!==g?(v=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]=v):v=e[2];let x;e[3]!==m?(x=b?void 0:$=>{$.preventDefault(),m(!0)},e[3]=m,e[4]=x):x=e[4];let h;e[5]!==n.name?(h=s.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["/",n.name]}),e[5]=n.name,e[6]=h):h=e[6];let j;e[7]!==n||e[8]!==u?(j=(n.scope||li(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:li(n)?u("settings.agents.sidebar.badge.system"):n.scope}),e[7]=n,e[8]=u,e[9]=j):j=e[9];let y;e[10]!==h||e[11]!==j?(y=s.jsxs("div",{className:"flex items-center gap-2",children:[h,j]}),e[10]=h,e[11]=j,e[12]=y):y=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]!==y||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:[y,C]}),e[15]=a,e[16]=y,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(ve,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(D,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[19]=w):w=e[19];let S;e[20]!==c||e[21]!==u?(S=c&&s.jsxs(Ot,{onClick:$=>{$.stopPropagation(),c()},children:[s.jsx(D,{name:"edit",className:"h-4 w-4 mr-px"}),u("settings.common.actions.rename")]}),e[20]=c,e[21]=u,e[22]=S):S=e[22];let 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(D,{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 A;e[28]!==I||e[29]!==P?(A=s.jsxs(Ot,{onClick:I,children:[T,P]}),e[28]=I,e[29]=P,e[30]=A):A=e[30];let N;e[31]!==l||e[32]!==u?(N=l&&s.jsxs(Ot,{onClick:$=>{$.stopPropagation(),l()},children:[s.jsx(D,{name:"restart",className:"h-4 w-4 mr-px"}),u("settings.common.actions.reset")]}),e[31]=l,e[32]=u,e[33]=N):N=e[33];let E;e[34]!==i||e[35]!==u?(E=i&&s.jsxs(Ot,{onClick:$=>{$.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[s.jsx(D,{name:"delete-bin",className:"h-4 w-4 mr-px"}),u("settings.common.actions.delete")]}),e[34]=i,e[35]=u,e[36]=E):E=e[36];let M;e[37]!==S||e[38]!==A||e[39]!==N||e[40]!==E?(M=s.jsxs(Ps,{align:"end",className:"w-fit min-w-20",children:[S,A,N,E]}),e[37]=S,e[38]=A,e[39]=N,e[40]=E,e[41]=M):M=e[41];let O;e[42]!==p||e[43]!==m||e[44]!==M?(O=s.jsxs(As,{open:p,onOpenChange:m,children:[w,M]}),e[42]=p,e[43]=m,e[44]=M,e[45]=O):O=e[45];let V;e[46]!==O||e[47]!==k?(V=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[k,O]}),e[46]=O,e[47]=k,e[48]=V):V=e[48];let B;return e[49]!==V||e[50]!==v||e[51]!==x?(B=s.jsx("div",{className:v,onContextMenu:x,children:V}),e[49]=V,e[50]=v,e[51]=x,e[52]=B):B=e[52],B};function ik(t){return{selectedCommandName:t.selectedCommandName,commands:t.commands,setSelectedCommand:t.setSelectedCommand,setCommandDraft:t.setCommandDraft,createCommand:t.createCommand,deleteCommand:t.deleteCommand,loadCommands:t.loadCommands}}function ok(t){return t.skills}function lk(t){return t.loadSkills}function ck(t){return t.name}function dk(t){return!li(t)}function uk(t,e){return t.name.localeCompare(e.name)}function mk(t,e){return t.name.localeCompare(e.name)}const pk=()=>{const{t}=ut(),{selectedCommandName:e,getCommandByName:n,createCommand:r,updateCommand:a,commands:i,commandDraft:l,setCommandDraft:c}=zd(er(A=>({selectedCommandName:A.selectedCommandName,getCommandByName:A.getCommandByName,createCommand:A.createCommand,updateCommand:A.updateCommand,commands:A.commands,commandDraft:A.commandDraft,setCommandDraft:A.setCommandDraft}))),d=e?n(e):null,p=!!(l&&l.name===e&&!d),[m,u]=o.useState(""),[f,b]=o.useState("user"),[g,v]=o.useState(""),[x,h]=o.useState(""),[j,y]=o.useState(""),[C,k]=o.useState(""),[w,S]=o.useState(!1),I=o.useRef(null);o.useEffect(()=>{if(p&&l){const A=l.name||"",N=l.scope||"user",E=l.description||"",M=l.agent||"",O=l.model||"",V=l.template||"";u(A),b(N),v(E),h(M),y(O),k(V),I.current={draftName:A,draftScope:N,description:E,agent:M,model:O,template:V}}else if(d){const A=d.description||"",N=d.agent||"",E=d.model||"",M=d.template||"";v(A),h(N),y(E),k(M),I.current={draftName:"",draftScope:"user",description:A,agent:N,model:E,template:M}}},[d,p,e,i,l]);const T=o.useMemo(()=>{const A=I.current;return A?!!(p&&(m!==A.draftName||f!==A.draftScope)||g!==A.description||x!==A.agent||j!==A.model||C!==A.template):!1},[x,g,m,f,p,j,C]),P=async()=>{const A=p?m.trim().replace(/\s+/g,"-"):e?.trim();if(!A){G.error(t("settings.commands.sidebar.toast.commandNameRequired"));return}if(!C.trim()){G.error(t("settings.commands.page.toast.templateRequired"));return}if(p&&i.some(N=>N.name===A)){G.error(t("settings.commands.sidebar.toast.commandExists"));return}S(!0);try{const N=x.trim(),E=j.trim(),M=C.trim(),O={name:A,description:g.trim()||void 0,agent:N===""?null:N,model:E===""?null:E,template:M,scope:p?f:void 0};let V;p?(V=await r(O),V&&c(null)):V=await a(A,O),V?G.success(t(p?"settings.commands.page.toast.created":"settings.commands.page.toast.updated")):G.error(t(p?"settings.commands.page.toast.createFailed":"settings.commands.page.toast.updateFailed"))}catch(N){console.error("Error saving command:",N),G.error(t("settings.commands.page.toast.saveUnexpectedError"))}finally{S(!1)}};return e?s.jsx(ws,{outerClassName:"h-full",className:"w-full",children:s.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[s.jsx("div",{className:"mb-4 flex items-center justify-between gap-4",children:s.jsxs("div",{className:"min-w-0",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:p?t("settings.commands.page.title.new"):`/${e}`}),s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:t(p?"settings.commands.page.subtitle.new":"settings.commands.page.subtitle.edit")})]})}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.commands.page.section.identity")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[p&&s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.commands.page.field.commandName")})}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:[s.jsxs("div",{className:"flex items-center",children:[s.jsx("span",{className:"typography-ui-label text-muted-foreground mr-1",children:"/"}),s.jsx(Bt,{value:m,onChange:A=>u(A.target.value),placeholder:t("settings.commands.page.field.commandNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(is,{value:f,onValueChange:A=>b(A),children:[s.jsx(os,{className:"w-fit min-w-[100px]",children:s.jsx(us,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(ls,{align:"end",children:[s.jsx(Mt,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(D,{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(D,{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(jn,{value:g,onChange:A=>v(A.target.value),placeholder:t("settings.commands.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})})]})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.commands.page.section.executionContext")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.commands.page.field.overrideAgent")})}),s.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:s.jsx(Kl,{agentName:x,onChange:A=>h(A)})})]}),s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.agents.page.field.overrideModel")})}),s.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:s.jsx(wo,{providerId:yi(j)?.providerId??"",modelId:yi(j)?.modelId??"",onChange:(A,N)=>{y(A&&N?`${A}/${N}`:"")}})})]})]})]}),s.jsxs("div",{className:"mb-2",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.commands.page.section.template")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsx(jn,{value:C,onChange:A=>k(A.target.value),placeholder:t("settings.commands.page.field.templatePlaceholder"),rows:12,className:"w-full font-mono typography-meta min-h-[160px] max-h-[60vh] bg-transparent resize-y"})}),s.jsx("div",{className:"mt-2 px-2",children:s.jsxs("p",{className:"typography-meta text-muted-foreground",children:[s.jsx("code",{className:"text-foreground",children:"$ARGUMENTS"})," ",t("settings.commands.page.templateHint.userInput")," ·"," ",s.jsx("code",{className:"text-foreground",children:"!`cmd`"})," ",t("settings.commands.page.templateHint.shellOutput")," ·"," ",s.jsx("code",{className:"text-foreground",children:"@file"})," ",t("settings.commands.page.templateHint.fileContents")]})})]}),s.jsx("div",{className:"px-2 py-1",children:s.jsx(ve,{onClick: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(D,{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")})]})})},gp=t=>{switch(t){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"idle"}},xp=t=>{const e=ot.c(5),{tone:n,enabled:r}=t;if(!r){let l;return e[0]===Symbol.for("react.memo_cache_sentinel")?(l=s.jsx("span",{className:"inline-block h-2 w-2 rounded-full bg-muted-foreground/30 flex-shrink-0"}),e[0]=l):l=e[0],l}let a;e[1]!==n?(a=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},fk=t=>{const e=ot.c(116),{onItemSelect:n}=t,{t:r}=ut(),{mcpServers:a,selectedMcpName:i,setSelectedMcp:l,setMcpDraft:c,loadMcpConfigs:d,deleteMcp:p}=co(er(hk)),m=Ks(gk);let u;e[0]!==m?(u=ee=>ee.getStatusForDirectory(m??null),e[0]=m,e[1]=u):u=e[1];const f=Sn(u),b=Sn(xk),g=Sn(bk),[v,x]=o.useState(null),[h,j]=o.useState(!1),[y,C]=o.useState(null),[k,w]=o.useState(!1);let S;e[2]!==a?(S=a.filter(yk),e[2]=a,e[3]=S):S=e[3];const I=S;let T;e[4]!==a?(T=a.filter(vk),e[4]=a,e[5]=T):T=e[5];const P=T;let A,N;e[6]!==d?(A=()=>{d()},N=[d],e[6]=d,e[7]=A,e[8]=N):(A=e[7],N=e[8]),o.useEffect(A,N);let E;e[9]!==m||e[10]!==g||e[11]!==k||e[12]!==b?(E=()=>{if(k)return;w(!0);const ee=new Promise(wk);Promise.all([b({directory:m,silent:!0}),ee]).then(()=>{const R=g(m);R&&G.error(R)}).finally(()=>{w(!1)})},e[9]=m,e[10]=g,e[11]=k,e[12]=b,e[13]=E):E=e[13];const M=E;let O;e[14]!==a||e[15]!==n||e[16]!==c||e[17]!==l?(O=()=>{let ee="new-mcp-server",R=1;for(;a.some(le=>le.name===ee);)ee=`new-mcp-server-${R}`,R++;c({name:ee,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),l(ee),n?.()},e[14]=a,e[15]=n,e[16]=c,e[17]=l,e[18]=O):O=e[18];const V=O;let B;e[19]!==p||e[20]!==v||e[21]!==r?(B=async()=>{if(!v)return;j(!0);const ee=await p(v.name);ee.ok?ee.reloadFailed?G.warning(ee.message||`MCP server "${v.name}" deleted, but OpenCode reload failed`,{description:ee.warning||r("settings.mcp.sidebar.toast.refreshListIfStale")}):G.success(ee.message||r("settings.mcp.sidebar.toast.serverDeleted",{name:v.name})):G.error(r("settings.mcp.sidebar.toast.deleteFailed")),x(null),j(!1)},e[19]=p,e[20]=v,e[21]=r,e[22]=B):B=e[22];const $=B;let F;e[23]===Symbol.for("react.memo_cache_sentinel")?(F=ye("flex h-full flex-col","bg-background"),e[23]=F):F=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 Y;e[30]!==r?(Y=r("settings.mcp.sidebar.actions.refreshStatusTitle"),e[30]=r,e[31]=Y):Y=e[31];const Z=k&&"animate-spin";let ae;e[32]!==Z?(ae=ye("h-4 w-4",Z),e[32]=Z,e[33]=ae):ae=e[33];let re;e[34]!==ae?(re=s.jsx(D,{name:"refresh",className:ae}),e[34]=ae,e[35]=re):re=e[35];let me;e[36]!==M||e[37]!==k||e[38]!==L||e[39]!==Y||e[40]!==re?(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:M,"aria-label":L,title:Y,children:re}),e[36]=M,e[37]=k,e[38]=L,e[39]=Y,e[40]=re,e[41]=me):me=e[41];let fe;e[42]!==q||e[43]!==me?(fe=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[q,me]}),e[42]=q,e[43]=me,e[44]=fe):fe=e[44];let H;e[45]===Symbol.for("react.memo_cache_sentinel")?(H=s.jsx(jo,{className:"mb-3"}),e[45]=H):H=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(D,{name:"add",className:"h-3.5 w-3.5"}),e[53]=de):de=e[53];let be;e[54]!==V||e[55]!==W?(be=s.jsx(ve,{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]=be):be=e[56];let we;e[57]!==Q||e[58]!==be?(we=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Q,be]}),e[57]=Q,e[58]=be,e[59]=we):we=e[59];let te;e[60]!==fe||e[61]!==we?(te=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[fe,H,we]}),e[60]=fe,e[61]=we,e[62]=te):te=e[62];let ge;e[63]!==a.length||e[64]!==f||e[65]!==n||e[66]!==y||e[67]!==I||e[68]!==i||e[69]!==c||e[70]!==l||e[71]!==r||e[72]!==P?(ge=s.jsx(ws,{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(D,{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 R=f[ee.name],U=gp(R?.status),le=i===ee.name,Me=ro();return s.jsxs("div",{className:ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",le?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:Me?void 0:Oe=>{Oe.preventDefault(),C(ee.name)},children:[s.jsxs("button",{onClick:()=>{l(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(xp,{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(D,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(D,{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:y===ee.name,onOpenChange:Oe=>C(Oe?ee.name:null),children:[s.jsx(Is,{asChild:!0,children:s.jsx(ve,{size:"xs",variant:"ghost",className:"flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(D,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Ps,{align:"end",className:"w-fit min-w-20",children:s.jsxs(Ot,{onClick:Oe=>{Oe.stopPropagation(),x(ee)},className:"text-destructive focus:text-destructive",children:[s.jsx(D,{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 R=f[ee.name],U=gp(R?.status),le=i===ee.name,Me=ro();return s.jsxs("div",{className:ye("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",le?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:Me?void 0:Oe=>{Oe.preventDefault(),C(ee.name)},children:[s.jsxs("button",{onClick:()=>{l(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(xp,{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(D,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(D,{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:y===ee.name,onOpenChange:Oe=>C(Oe?ee.name:null),children:[s.jsx(Is,{asChild:!0,children:s.jsx(ve,{size:"xs",variant:"ghost",className:"flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(D,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Ps,{align:"end",className:"w-fit min-w-20",children:s.jsxs(Ot,{onClick:Oe=>{Oe.stopPropagation(),x(ee)},className:"text-destructive focus:text-destructive",children:[s.jsx(D,{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]=y,e[67]=I,e[68]=i,e[69]=c,e[70]=l,e[71]=r,e[72]=P,e[73]=ge):ge=e[73];const ue=v!==null;let xe;e[74]!==h?(xe=ee=>{!ee&&!h&&x(null)},e[74]=h,e[75]=xe):xe=e[75];let ne;e[76]!==r?(ne=r("settings.mcp.sidebar.deleteDialog.title"),e[76]=r,e[77]=ne):ne=e[77];let pe;e[78]!==ne?(pe=s.jsx(fs,{children:ne}),e[78]=ne,e[79]=pe):pe=e[79];const J=v?.name||"";let Se;e[80]!==r||e[81]!==J?(Se=r("settings.mcp.sidebar.deleteDialog.descriptionPrefix",{name:J}),e[80]=r,e[81]=J,e[82]=Se):Se=e[82];let he;e[83]===Symbol.for("react.memo_cache_sentinel")?(he=s.jsx("code",{className:"text-foreground",children:"opencode.json"}),e[83]=he):he=e[83];let Ie;e[84]!==Se?(Ie=s.jsxs(Ns,{children:[Se," ",he,"."]}),e[84]=Se,e[85]=Ie):Ie=e[85];let Pe;e[86]!==pe||e[87]!==Ie?(Pe=s.jsxs(gs,{children:[pe,Ie]}),e[86]=pe,e[87]=Ie,e[88]=Pe):Pe=e[88];let Ce;e[89]===Symbol.for("react.memo_cache_sentinel")?(Ce=()=>x(null),e[89]=Ce):Ce=e[89];let X;e[90]!==r?(X=r("settings.common.actions.cancel"),e[90]=r,e[91]=X):X=e[91];let ie;e[92]!==h||e[93]!==X?(ie=s.jsx(ve,{size:"sm",variant:"ghost",onClick:Ce,disabled:h,children:X}),e[92]=h,e[93]=X,e[94]=ie):ie=e[94];let Ne;e[95]!==h||e[96]!==r?(Ne=r(h?"settings.mcp.sidebar.actions.deleting":"settings.common.actions.delete"),e[95]=h,e[96]=r,e[97]=Ne):Ne=e[97];let oe;e[98]!==$||e[99]!==h||e[100]!==Ne?(oe=s.jsx(ve,{size:"sm",onClick:$,disabled:h,children:Ne}),e[98]=$,e[99]=h,e[100]=Ne,e[101]=oe):oe=e[101];let ke;e[102]!==ie||e[103]!==oe?(ke=s.jsxs(Hs,{children:[ie,oe]}),e[102]=ie,e[103]=oe,e[104]=ke):ke=e[104];let Te;e[105]!==Pe||e[106]!==ke?(Te=s.jsxs(ms,{className:"max-w-md",children:[Pe,ke]}),e[105]=Pe,e[106]=ke,e[107]=Te):Te=e[107];let Be;e[108]!==ue||e[109]!==xe||e[110]!==Te?(Be=s.jsx(ps,{open:ue,onOpenChange:xe,children:Te}),e[108]=ue,e[109]=xe,e[110]=Te,e[111]=Be):Be=e[111];let je;return e[112]!==te||e[113]!==ge||e[114]!==Be?(je=s.jsxs("div",{className:F,children:[te,ge,Be]}),e[112]=te,e[113]=ge,e[114]=Be,e[115]=je):je=e[115],je};function hk(t){return{mcpServers:t.mcpServers,selectedMcpName:t.selectedMcpName,setSelectedMcp:t.setSelectedMcp,setMcpDraft:t.setMcpDraft,loadMcpConfigs:t.loadMcpConfigs,deleteMcp:t.deleteMcp}}function gk(t){return t.currentDirectory}function xk(t){return t.refresh}function bk(t){return t.getErrorForDirectory}function yk(t){return t.scope==="project"}function vk(t){return t.scope!=="project"}function wk(t){return setTimeout(t,500)}function fa(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Li(t){return Array.isArray(t)&&t.every(e=>typeof e=="string")}function Sa(t,e){return e!==void 0?{ok:!1,error:t,parsed:e}:{ok:!1,error:t}}function Tc(t,e,n){const r=jk(n),a=typeof n.url=="string"?n.url.trim():"",i=bp(n,"env","environment"),l=bp(n,"headers"),c=Nk(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=Sk(n),b=kk(n);return{ok:!0,name:t,type:e,command:r,url:a,environment:i,headers:l,oauthEnabled:c,oauthClientId:d,oauthClientSecret:p,oauthScope:m,oauthRedirectUri:u,timeout:f,enabled:b}}function jk(t){const e=t.command,n=t.args;if(Li(e)&&Li(n))return[...e,...n];if(Li(e))return e;if(typeof e=="string"&&e.trim()){const r=e.trim().split(/\s+/);return Li(n)?[...r,...n]:r}return Li(n)?n:[]}function bp(t,...e){for(const n of e){const r=t[n];if(!fa(r))continue;const a=Object.entries(r).filter(([i,l])=>i&&typeof l=="string");if(a.length>0)return a.map(([i,l])=>({key:i,value:String(l)}))}return[]}function Nk(t){if(t.oauth===!1||t.oauth===null||t.oauth===void 0||!fa(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 Sk(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 kk(t){return"disabled"in t&&t.disabled===!0?!1:"enabled"in t?!!t.enabled:!0}function Ck(t){const e=t.mcpServers;if(fa(e)){const r=Object.keys(e);if(r.length===1){const a=r[0],i=e[a];if(fa(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"&&fa(a)});if(n.length===1){const r=n[0],a=t[r];if(ug(a))return{name:r,entry:a}}return null}function ug(t){return t.type==="local"||t.type==="remote"||Array.isArray(t.command)||typeof t.url=="string"||Array.isArray(t.args)}function Ik(t,e){let n;try{const l=t.trim();if(!l)return Sa("No JSON content provided");n=JSON.parse(l)}catch(l){return Sa(l instanceof Error?`Invalid JSON: ${l.message}`:"Invalid JSON")}if(!fa(n))return Sa("Expected a JSON object, not an array or primitive");const r=n,a=r.mcpServers;if(fa(a)){const l=Object.keys(a);if(l.length===0)return Sa("mcpServers object is empty",n);if(l.length>1)return Sa("Paste one server at a time. Found "+l.length+" servers in mcpServers",n);const c=l[0],d=a[c];return fa(d)?Tc(c,Mc(d),d):Sa("Server entry is not a valid object",n)}const i=Ck(r);if(i)return Tc(i.name,Mc(i.entry),i.entry);if(ug(r)){const l=Mc(r),c=typeof r.name=="string"&&r.name.trim()?r.name.trim():e?.fallbackName;return Tc(c,l,r)}return Sa("No recognizable MCP server configuration found in JSON",n)}function Mc(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 Pk(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 mg="/mcp/oauth/callback",Ak=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}},pg=t=>{const e=Dk(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}},nu=t=>{const e=t.get("state");return typeof e!="string"?null:e.trim()||null},Dk=t=>{if(typeof t!="string"||!t.trim())return null;const e=Ak(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 Tk(t){const e=[];let n="",r=!1,a=!1;for(let i=0;i<t.length;i++){const l=t[i];if(l==="'"&&!a){r=!r;continue}if(l==='"'&&!r){a=!a;continue}if((l===" "||l===" ")&&!r&&!a){n&&(e.push(n),n="");continue}n+=l}return n&&e.push(n),e}function Mk(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:pg(n.searchParams),stateKey:nu(n.searchParams)}}catch{}return{code:e,context:null,stateKey:null}}const Ek=({value:t,onChange:e,pasteCommandTitle:n,pasteCommandLabel:r,pasteSuccess:a,clipboardReadFailed:i,preview:l})=>{const[c,d]=o.useState(()=>t.join(`
|
|
157
|
-
`)),p=o.useRef(t);o.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(g=>g.trim().length>0);e(b)},u=async()=>{try{const b=(await navigator.clipboard.readText()).trim(),g=b.includes(`
|
|
160
|
-
`)?b.split(`
|
|
161
|
-
`).filter(v=>v.trim()):Tk(b);d(g.join(`
|
|
162
|
-
`)),e(g),G.success(a(g.length))}catch{G.error(i)}};return s.jsxs("div",{className:"space-y-2","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",children:[s.jsx("div",{className:"flex items-center justify-end gap-2",children:s.jsxs(ve,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:u,type:"button",title:n,children:[s.jsx(D,{name:"clipboard",className:"h-3 w-3"}),r]})}),s.jsx(jn,{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:l(t.length)}),s.jsx("div",{className:"mt-1 rounded-md bg-[var(--surface-elevated)] px-3 py-2 overflow-x-auto",children:s.jsx("code",{className:"typography-micro text-foreground/80 whitespace-pre",children:t.map((f,b)=>s.jsxs("span",{className:"block",children:[s.jsxs("span",{className:"text-muted-foreground select-none mr-2",children:["[",b,"]"]}),f]},b))})})]})]})},Rk=t=>t.toUpperCase().replace(/[^A-Z0-9_]/g,"_"),yp=({value:t,onChange:e,keyTransform:n=Rk,keyPlaceholder:r="API_KEY",keyInputClassName:a="w-36 shrink-0 font-mono typography-meta uppercase",pasteLabel:i="Paste .env",pasteTitle:l="Paste KEY=VALUE lines from clipboard",noPairsFoundError:c,importSuccess:d,clipboardReadFailed:p,keyLabel:m,valueLabel:u,valuePlaceholder:f,hideValueTitle:b,showValueTitle:g,addVariable:v,plainTextWarning:x,removeVariableAria:h})=>{const[j,y]=o.useState(new Set),C=()=>e([...t,{key:"",value:""}]),k=P=>{e(t.filter((A,N)=>N!==P)),y(A=>{const N=new Set(A);return N.delete(P),N})},w=(P,A,N)=>{const E=[...t];E[P]={...E[P],[A]:N},e(E)},S=P=>{y(A=>{const N=new Set(A);return N.has(P)?N.delete(P):N.add(P),N})},I=async()=>{try{const P=await navigator.clipboard.readText(),A=[];for(const E of P.split(`
|
|
168
|
-
`)){const M=E.trim();if(!M||M.startsWith("#"))continue;const O=M.indexOf("=");if(O===-1)continue;const V=M.slice(0,O).trim();let B=M.slice(O+1).trim();(B.startsWith('"')&&B.endsWith('"')||B.startsWith("'")&&B.endsWith("'"))&&(B=B.slice(1,-1)),V&&A.push({key:V,value:B})}if(A.length===0){G.error(c);return}const N=[...t];for(const E of A){const M=N.findIndex(O=>O.key===E.key);M!==-1?N[M]=E:N.push(E)}e(N),G.success(d(A.length))}catch{G.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(ve,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:I,type:"button",title:l,children:[s.jsx(D,{name:"clipboard",className:"h-3 w-3"}),i]})]}),s.jsx("div",{className:"space-y-1.5",children:t.map((P,A)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Bt,{value:P.key,onChange:N=>w(A,"key",n(N.target.value)),placeholder:r,className:a,"data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),s.jsxs("div",{className:"relative flex-1 flex items-center",children:[s.jsx(Bt,{type:j.has(A)?"text":"password",value:P.value,onChange:N=>w(A,"value",N.target.value),placeholder:f,className:"font-mono typography-meta pr-8 w-full",autoComplete:"new-password","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),s.jsx("button",{type:"button",onClick:()=>S(A),className:"absolute right-2 text-muted-foreground/60 hover:text-muted-foreground",title:j.has(A)?b:g,children:j.has(A)?s.jsx(D,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(D,{name:"eye",className:"h-3.5 w-3.5"})})]}),s.jsx(ve,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 shrink-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>k(A),"aria-label":h,children:s.jsx(D,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},A))}),s.jsxs(ve,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:C,type:"button",children:[s.jsx(D,{name:"add",className:"h-3.5 w-3.5"}),v]}),T&&s.jsx("p",{className:"typography-micro text-muted-foreground/60",children:x})]})},vp=t=>{const e=ot.c(14),{status:n,enabled:r,getStatusLabel:a,variant:i}=t,l=i===void 0?"compact":i;if(!r||!n)return null;let c,d;if(e[0]!==a||e[1]!==n||e[2]!==l){d=Symbol.for("react.early_return_sentinel");e:{const 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(l==="pill"){const b=ye("typography-micro font-medium rounded-full px-2 py-0.5",f.text,f.bg);let g;e[5]!==a||e[6]!==n?(g=a(n),e[5]=a,e[6]=n,e[7]=g):g=e[7],d=s.jsxs("span",{className:b,children:["● ",g]});break e}c=ye("typography-micro font-medium",f.text)}e[0]=a,e[1]=n,e[2]=l,e[3]=c,e[4]=d}else c=e[3],d=e[4];if(d!==Symbol.for("react.early_return_sentinel"))return d;let 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},Fk=(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")}},Ok=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)]"}},Lk=(t,e,n,r)=>!!(t==="failed"||t==="needs_auth"||t==="needs_client_registration"||e||n||r),wp=(t,e)=>{if(typeof window>"u")return null;const n=new URL(mg,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()},$k=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")}},_k=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},$i=async t=>{typeof t!="string"||!t.trim()||await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(t.trim())}`,{method:"DELETE"}).catch(()=>{})},Ec=(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},Bk=(t,e)=>{const n=typeof e=="string"&&e.trim()?e.trim():"__global__";return`${t??"__none__"}::${n}`},Vk=()=>{const{t}=ut(),e=o.useCallback((Qe,At)=>t(Qe,At),[t]),{selectedMcpName:n,mcpServers:r,mcpDraft:a,setMcpDraft:i,setSelectedMcp:l,getMcpByName:c,createMcp:d,updateMcp:p,deleteMcp:m}=co(er(Qe=>({selectedMcpName:Qe.selectedMcpName,mcpServers:Qe.mcpServers,mcpDraft:Qe.mcpDraft,setMcpDraft:Qe.setMcpDraft,setSelectedMcp:Qe.setSelectedMcp,getMcpByName:Qe.getMcpByName,createMcp:Qe.createMcp,updateMcp:Qe.updateMcp,deleteMcp:Qe.deleteMcp}))),u=Ks(Qe=>Qe.currentDirectory),f=o.useMemo(()=>mn(),[]),b=Sn(Qe=>Qe.getStatusForDirectory(u??null)),g=Sn(Qe=>Qe.getDiagnosticForDirectory(u??null)),v=Sn(Qe=>Qe.refresh),x=Sn(Qe=>Qe.connect),h=Sn(Qe=>Qe.disconnect),j=Sn(Qe=>Qe.startAuth),y=Sn(Qe=>Qe.completeAuth),C=Sn(Qe=>Qe.clearAuth),k=Sn(Qe=>Qe.testConnection),w=n?c(n):null,S=!!(a&&a.name===n&&!w),[I,T]=o.useState(""),[P,A]=o.useState("user"),[N,E]=o.useState("local"),[M,O]=o.useState([]),[V,B]=o.useState(""),[$,F]=o.useState([]),[_,q]=o.useState([]),[L,Y]=o.useState(!0),[Z,ae]=o.useState(""),[re,me]=o.useState(""),[fe,H]=o.useState(""),[K,Q]=o.useState(""),[W,de]=o.useState(""),[be,we]=o.useState(!0),[te,ge]=o.useState(!1),[ue,xe]=o.useState(!1),[ne,pe]=o.useState(!1),[J,Se]=o.useState(!1),[he,Ie]=o.useState(!1),[Pe,Ce]=o.useState(!1),[X,ie]=o.useState(!1),[Ne,oe]=o.useState(!1),[ke,Te]=o.useState(null),[Be,je]=o.useState(null),[ee,R]=o.useState(""),[U,le]=o.useState(!1),Me=o.useRef(0),Oe=o.useRef(!1),[Ae,z]=o.useState(!1),[De,Xe]=o.useState(!1),[st,tt]=o.useState(""),[Ue,it]=o.useState(null),Ye=o.useMemo(()=>Bk(n,u),[u,n]),rt=o.useRef(Ye),Je=o.useRef(null),ce=o.useCallback(()=>{Te(null),je(null),R(""),le(!1),Me.current=0,oe(!1),Ie(!1),Ce(!1),Oe.current=!1},[]),We=o.useCallback(()=>{tt(""),it(null),Xe(!0)},[]),Le=o.useCallback(async()=>{try{const Qe=await navigator.clipboard.readText();tt(Qe),it(null)}catch{G.error(t("settings.mcp.page.toast.clipboardReadFailed"))}},[t]),Ge=o.useCallback(()=>{const Qe=Ik(st,{fallbackName:I});if(!Qe.ok){it(Qe.error);return}const Ht=Pk(Qe,{name:I,scope:P,type:N,command:M,url:V,environment:$,headers:_,oauthEnabled:L,oauthClientId:Z,oauthClientSecret:re,oauthScope:fe,oauthRedirectUri:K,timeout:W,enabled:be},{isNewServer:S});T(Ht.name),E(Ht.type),O(Ht.command??[]),B(Ht.url??""),F(Ht.environment??[]),q(Ht.headers??[]),Y(Ht.oauthEnabled??!1),ae(Ht.oauthClientId??""),me(Ht.oauthClientSecret??""),H(Ht.oauthScope??""),Q(Ht.oauthRedirectUri??""),de(Ht.timeout??""),we(Ht.enabled??!0),Xe(!1),tt(""),it(null),G.success(t("settings.mcp.page.toast.configImported"))},[st,I,P,N,M,V,$,_,L,Z,re,fe,K,W,be,S,t]);o.useEffect(()=>{if(S&&a){T(a.name),A(a.scope||"user"),E(a.type),O(a.command),B(a.url),F(a.environment),q(a.headers),Y(a.oauthEnabled),ae(a.oauthClientId),me(a.oauthClientSecret),H(a.oauthScope),Q(a.oauthRedirectUri),de(a.timeout),we(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){A(w.scope==="project"?"project":"user");const Qe=em(w.environment),At=w.type==="remote"?w:null,Ht=em(At?.headers),jt=At?.oauth,Zt=jt&&typeof jt=="object"?jt:null,rs=jt!==!1,Ds=w.type,ns=Ds==="local"?w.command??[]:[],zs=Ds==="remote"?w.url??"":"",$s=typeof At?.timeout=="number"&&Number.isFinite(At.timeout)?String(At.timeout):"";E(Ds),O(ns),B(zs),F(Qe),q(Ht),Y(rs),ae(rs?Zt?.clientId??"":""),me(rs?Zt?.clientSecret??"":""),H(rs?Zt?.scope??"":""),Q(rs?Zt?.redirectUri??"":""),de($s),we(w.enabled),z(!1),Je.current={mcpType:Ds,command:ns,url:zs,envEntries:Qe,headerEntries:Ht,oauthEnabled:rs,oauthClientId:rs?Zt?.clientId??"":"",oauthClientSecret:rs?Zt?.clientSecret??"":"",oauthScope:rs?Zt?.scope??"":"",oauthRedirectUri:rs?Zt?.redirectUri??"":"",timeout:$s,enabled:w.enabled}}},[w,S,a]);const at=o.useMemo(()=>{const Qe=Je.current;return Qe?N!==Qe.mcpType||be!==Qe.enabled||JSON.stringify(M)!==JSON.stringify(Qe.command)||V!==Qe.url||JSON.stringify($)!==JSON.stringify(Qe.envEntries)||JSON.stringify(_)!==JSON.stringify(Qe.headerEntries)||L!==Qe.oauthEnabled||Z!==Qe.oauthClientId||re!==Qe.oauthClientSecret||fe!==Qe.oauthScope||K!==Qe.oauthRedirectUri||W!==Qe.timeout:!1},[N,M,V,$,_,L,Z,re,fe,K,W,be]),He=async()=>{const Qe=S?I.trim():n??"";if(!Qe){G.error(t("settings.mcp.page.toast.nameRequired"));return}if(S&&r.some(Ht=>Ht.name===Qe)){G.error(t("settings.mcp.page.toast.serverNameExists"));return}if(N==="local"&&M.filter(Boolean).length===0){G.error(t("settings.mcp.page.toast.localCommandRequired"));return}if(N==="remote"&&!V.trim()){G.error(t("settings.mcp.page.toast.remoteUrlRequired"));return}const At={name:Qe,scope:P,type:N,command:M,url:V,environment:$,headers:_,oauthEnabled:L,oauthClientId:Z,oauthClientSecret:re,oauthScope:fe,oauthRedirectUri:K,timeout:W,enabled:be};ge(!0);try{const Ht=S?await d(At):await p(Qe,At);Ht.ok?(await $i(Be),ce(),S&&(i(null),l(Qe)),await v({directory:u,silent:!0}),Ht.reloadFailed?G.warning(Ht.message||t(S?"settings.mcp.page.toast.serverCreatedReloadFailed":"settings.mcp.page.toast.savedReloadFailed"),{description:Ht.warning||t("settings.mcp.page.toast.retryRefreshHint")}):G.success(Ht.message||t(S?"settings.mcp.page.toast.serverCreatedReloading":"settings.mcp.page.toast.savedReloading"))):G.error(t("settings.mcp.page.toast.saveFailed"))}catch(Ht){G.error(Ht instanceof Error?Ht.message:t("settings.mcp.page.toast.unexpectedError"))}finally{ge(!1)}},ze=async()=>{if(!n)return;pe(!0);const Qe=await m(n);Qe.ok?(await $i(Be),ce(),Qe.reloadFailed?G.warning(Qe.message||t("settings.mcp.page.toast.serverDeletedReloadFailed",{name:n}),{description:Qe.warning||t("settings.mcp.page.toast.refreshListIfStale")}):G.success(Qe.message||t("settings.mcp.page.toast.serverDeleted",{name:n})),xe(!1)):G.error(t("settings.mcp.page.toast.deleteFailed")),pe(!1)},et=async()=>{if(n){Se(!0);try{if(b[n]?.status==="connected")await h(n,u),G.success(t("settings.mcp.page.toast.disconnected"));else{await x(n,u),await v({directory:u,silent:!0});const At=Sn.getState().getStatusForDirectory(u??null)[n];At?.status==="connected"?G.success(t("settings.mcp.page.toast.connected")):At?.status==="needs_auth"?G.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):At?.status==="needs_client_registration"?G.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):At?.status==="failed"?G.error(At.error||t("settings.mcp.page.toast.connectionFailed")):G.message(t("settings.mcp.page.toast.connectionAttemptFinished"));return}await v({directory:u,silent:!0})}catch(Qe){G.error(Qe instanceof Error?Qe.message:t("settings.mcp.page.toast.connectionFailed"))}finally{Se(!1)}}},gt=o.useCallback(()=>S?(G.error(t("settings.mcp.page.toast.createServerBeforeLiveActions")),!1):at?(G.error(t("settings.mcp.page.toast.saveBeforeLiveActions")),!1):!0,[at,S,t]),Pt=o.useCallback(async(Qe=!1)=>{try{await v({directory:u,silent:Qe})}catch(At){Qe||G.error(At instanceof Error?At.message:t("settings.mcp.page.toast.refreshStatusFailed"))}},[u,v,t]);o.useEffect(()=>{Pt(!0)},[Pt]),o.useEffect(()=>{rt.current=Ye,Se(!1),ie(!1),ce()},[ce,Ye]);const Nt=o.useCallback(async()=>{if(!n||N!=="remote"||!gt())return;Ie(!0);const Qe=Ye;let At=null;try{const Ht=Sn.getState().getStatusForDirectory(u??null)[n]?.status;Oe.current=Ht==="needs_auth"||Ht==="needs_client_registration";const jt=wp(n,u);if(!jt)throw new Error(t("settings.mcp.page.toast.oauthRedirectUrlBuildFailed"));if(!K.trim()&&!f){const ns=await p(n,{oauthEnabled:L,oauthClientId:Z,oauthClientSecret:re,oauthScope:fe,oauthRedirectUri:jt});if(!ns.ok)throw new Error(t("settings.mcp.page.toast.oauthBrowserCallbackSaveFailed"));if(ns.reloadFailed)throw new Error(ns.warning||ns.message||t("settings.mcp.page.toast.openCodeReloadFailedAfterCallbackSave"));if(rt.current!==Qe)return;Q(jt),Je.current=Je.current?{...Je.current,oauthRedirectUri:jt}:Je.current}const Zt=await j(n,u),rs=nu(new URL(Zt).searchParams);if(rs&&(At=rs,await $k({state:rs,name:n,directory:u})),rt.current!==Qe)return;Te(Zt),je(rs??null),le(!0),Me.current=0;const Ds=await Zn(Zt);if(rt.current!==Qe)return;Ds?G.message(t(f?"settings.mcp.page.toast.completeAuthorizationInBrowserWithPaste":"settings.mcp.page.toast.completeAuthorizationInBrowser")):G.error(t("settings.mcp.page.toast.openAuthorizationUrlFailed"))}catch(Ht){await $i(At),rt.current===Qe&&G.error(Ec(Ht,t("settings.mcp.page.toast.authorizationStartFailed"),e))}finally{rt.current===Qe&&Ie(!1)}},[u,f,N,Z,re,L,K,fe,gt,Ye,n,j,t,e,p]),ht=o.useCallback(async()=>{if(!n||!gt())return;Ce(!0);const Qe=Ye;try{if(await C(n,u),rt.current!==Qe)return;Te(null),je(null),R(""),le(!1),Me.current=0,await $i(Be),G.success(t("settings.mcp.page.toast.savedAuthorizationRemoved"))}catch(At){rt.current===Qe&&G.error(Ec(At,t("settings.mcp.page.toast.clearAuthorizationFailed"),e))}finally{rt.current===Qe&&Ce(!1)}},[Be,C,u,gt,Ye,n,t,e]),wt=o.useCallback(async()=>{if(!ke)return;if((await Rn(ke)).ok){G.success(t("settings.mcp.page.toast.authorizationUrlCopied"));return}G.error(t("settings.mcp.page.toast.authorizationUrlCopyFailed"))},[ke,t]),es=o.useCallback(async()=>{const Qe=Mk(ee);if(!Qe.code){G.error(t("settings.mcp.page.toast.pasteCallbackOrCodeFirst"));return}const At=Qe.stateKey?await _k(Qe.stateKey):null,Ht=Qe.context??At,jt=Ht?.name??n,Zt=Ht?.directory??u;if(!jt){G.error(t("settings.mcp.page.toast.missingServerDetails"));return}if(!Ht&&!gt())return;oe(!0);const rs=Ye;try{if(await y(jt,Qe.code,Zt),await $i(Qe.stateKey??Be),rt.current!==rs)return;R(""),Te(null),je(null),le(!1),Me.current=0,G.success(jt===n?t("settings.mcp.page.toast.authorizationCompleted"):t("settings.mcp.page.toast.authorizationCompletedFor",{name:jt}))}catch(Ds){rt.current===rs&&G.error(Ec(Ds,t("settings.mcp.page.toast.authorizationCompleteFailed"),e))}finally{rt.current===rs&&oe(!1)}},[ee,Be,y,u,gt,Ye,n,t,e]),Vt=o.useCallback(async()=>{if(!(!n||!gt())){if(!be){G.error(t("settings.mcp.page.toast.enableServerBeforeTest"));return}ie(!0);try{const Qe=await k(n,u),At=Qe.status?.status;Qe.warning?G.warning(Qe.warning):At==="connected"?G.success(t("settings.mcp.page.toast.connectionTestSucceeded")):At==="needs_auth"?G.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):At==="needs_client_registration"?G.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):At==="failed"?G.error(Qe.status?.error||Qe.error||t("settings.mcp.page.toast.connectionTestFailed")):Qe.error?G.error(Qe.error):G.message(t("settings.mcp.page.toast.connectionTestFinished"))}catch(Qe){G.error(Qe instanceof Error?Qe.message:t("settings.mcp.page.toast.connectionTestFailed"))}finally{ie(!1)}}},[u,be,gt,n,t,k]);if(o.useEffect(()=>{if(!U||!n)return;const Qe=window.setInterval(()=>{(async()=>{Me.current+=1,await v({directory:u,silent:!0});const At=Sn.getState().getStatusForDirectory(u??null)[n];if(At){if(Oe.current&&At.status!=="needs_auth"&&At.status!=="needs_client_registration"){le(!1),Me.current=0,Oe.current=!1,Te(null),R(""),At.status==="connected"&&G.success(t("settings.mcp.page.toast.authorizationCompleted"));return}if(!Oe.current&&At.status==="failed"){le(!1),Me.current=0,Oe.current=!1,G.error(At.error||t("settings.mcp.page.toast.authorizationFailed"));return}Me.current>=30&&(le(!1),Me.current=0,Oe.current=!1,G.message(t("settings.mcp.page.toast.authorizationStillInProgress")))}})()},2e3);return()=>{window.clearInterval(Qe)}},[u,U,v,n,t]),!n)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(D,{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 Jt=b[n],mt=n?g[n]:void 0,Lt=Jt??mt,ts=Jt?.status==="connected",js=Jt?.status==="needs_auth"||Jt?.status==="needs_client_registration",ds=f?null:wp(n,u),hs=Fk(Lt?.status,e,Lt&&"error"in Lt?Lt.error:void 0),Ut=Qe=>{switch(Qe){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 Qe}};return s.jsxs(ws,{outerClassName:"h-full",className:"w-full",children:[s.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[s.jsx("div",{className:"mb-4",children:s.jsxs("div",{className:"min-w-0",children:[S?s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:t("settings.mcp.page.header.newServer")}):s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:n}),s.jsx(vp,{status:Lt?.status,enabled:be,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:S?t("settings.mcp.page.header.configureNewServer"):t("settings.mcp.page.header.transport",{type:t(N==="local"?"settings.mcp.page.transport.local":"settings.mcp.page.transport.remote")})}),!S&&s.jsxs(s.Fragment,{children:[s.jsx(ve,{variant:ts?"outline":"default",size:"xs",className:"!font-normal",onClick:et,disabled:J||!be,children:t(J?"settings.mcp.page.actions.working":ts?"settings.mcp.page.actions.disconnect":"settings.mcp.page.actions.connect")}),N==="remote"&&s.jsxs(s.Fragment,{children:[s.jsx(ve,{variant:js?"default":"outline",size:"xs",className:"!font-normal",onClick:()=>{Nt()},disabled:he||!be,children:t(he?"settings.mcp.page.actions.starting":js?"settings.mcp.page.actions.authorize":"settings.mcp.page.actions.reauthorize")}),s.jsx(ve,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{ht()},disabled:Pe||!be,children:t(Pe?"settings.mcp.page.actions.clearing":"settings.mcp.page.actions.clearAuth")})]}),ts&&s.jsx(ve,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{Vt()},disabled:X||!be,children:t(X?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.test")})]})]})]})}),!S&&Lk(Lt?.status,ke,js,U)&&s.jsx("div",{className:"mb-6 px-2",children:s.jsxs("div",{className:ye("rounded-lg border p-3",Ok(Lt?.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(vp,{status:Lt?.status,enabled:be,getStatusLabel:Ut})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:hs}),s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:P==="project"?t("settings.mcp.page.status.projectScopedTo",{directory:u??t("settings.mcp.page.status.activeProject")}):t("settings.mcp.page.status.userScoped")})]}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:!ts&&s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Vt()},disabled:X||!be,children:t(X?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.testConnection")})}),ke&&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:ke}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Zn(ke)},children:[s.jsx(D,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.openInBrowser")]}),s.jsxs(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{wt()},children:[s.jsx(D,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.copyLink")]})]})]})}),N==="remote"&&(js||U||ke)&&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(jn,{value:ee,onChange:Qe=>R(Qe.target.value),placeholder:t("settings.mcp.page.auth.callbackInputPlaceholder"),rows:3,className:"font-mono typography-meta resize-y","data-bwignore":"true","data-1p-ignore":"true",spellCheck:!1}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{es()},disabled:Ne,children:t(Ne?"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:[S&&s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.mcp.page.server.name")})}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:[s.jsx(Bt,{value:I,onChange:Qe=>T(Qe.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(is,{value:P,onValueChange:Qe=>A(Qe),children:[s.jsx(os,{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(D,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(D,{name:"folder",className:"h-3.5 w-3.5"})}),s.jsxs(ls,{align:"end",children:[s.jsx(Mt,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(D,{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(D,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]})]}),S&&s.jsx("div",{className:"py-1.5",children:s.jsxs(ve,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:We,type:"button",title:t("settings.mcp.page.server.importJsonTitle"),children:[s.jsx(D,{name:"file-code",className:"h-3.5 w-3.5"}),t("settings.mcp.page.server.importJson")]})}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":be,onClick:()=>we(!be),onKeyDown:Qe=>{(Qe.key===" "||Qe.key==="Enter")&&(Qe.preventDefault(),we(!be))},children:[s.jsx(xs,{checked:be,onChange:we,ariaLabel:t("settings.mcp.page.server.enableAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.mcp.page.server.enable")})]}),s.jsx("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:s.jsxs("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.mcp.page.server.transportMode")}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[s.jsx(ve,{variant:"chip",size:"xs","aria-pressed":N==="local",onClick:()=>E("local"),className:"!font-normal",children:t("settings.mcp.page.transport.local")}),s.jsx(ve,{variant:"chip",size:"xs","aria-pressed":N==="remote",onClick:()=>E("remote"),className:"!font-normal",children:t("settings.mcp.page.transport.remote")})]})]})})]})]}),s.jsxs("div",{className:"mb-6",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t(N==="local"?"settings.mcp.page.connection.command":"settings.mcp.page.connection.serverUrl")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:N==="local"?s.jsx(Ek,{value:M,onChange:O,pasteCommandTitle:t("settings.mcp.page.connection.pasteCommandTitle"),pasteCommandLabel:t("settings.mcp.page.connection.pasteCommand"),pasteSuccess:Qe=>t("settings.mcp.page.toast.pastedArgumentsCount",{count:Qe}),clipboardReadFailed:t("settings.mcp.page.toast.clipboardReadFailed"),preview:Qe=>t("settings.mcp.page.connection.previewArgs",{count:Qe})}):s.jsx(Bt,{value:V,onChange:Qe=>B(Qe.target.value),placeholder:t("settings.mcp.page.connection.serverUrlPlaceholder"),className:"font-mono typography-meta"})})]}),N==="remote"&&s.jsxs("div",{className:"mb-6",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.mcp.page.advanced.title")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsxs(br,{open:Ae,onOpenChange:z,children:[s.jsxs(Tr,{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`:"",")"]})]}),Ae?s.jsx(D,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(D,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(yr,{className:"pt-2",children:s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.mcp.page.advanced.timeoutMs")})}),s.jsx("div",{className:"flex items-center gap-2",children:s.jsx(Bt,{type:"number",min:"1",step:"1",value:W,onChange:Qe=>de(Qe.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(yp,{value:_,onChange:q,keyTransform:Qe=>Qe.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:Qe=>t("settings.mcp.page.toast.importedVariablesCount",{count:Qe}),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:()=>Y(!L),onKeyDown:Qe=>{(Qe.key===" "||Qe.key==="Enter")&&(Qe.preventDefault(),Y(!L))},children:[s.jsx(xs,{checked:L,onChange:Y,ariaLabel:t("settings.mcp.page.advanced.oauthAutoDetectionAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.mcp.page.advanced.oauthAutoDetection")})]}),s.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[s.jsx(Bt,{value:Z,onChange:Qe=>ae(Qe.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(Bt,{value:re,onChange:Qe=>me(Qe.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(Bt,{value:fe,onChange:Qe=>H(Qe.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(Bt,{value:K,onChange:Qe=>Q(Qe.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")}),ds&&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:ds})]})]})]})})]})})]}),s.jsxs("div",{className:"mb-2",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("h3",{className:"typography-ui-header font-medium text-foreground",children:[t("settings.mcp.page.env.title"),$.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",$.length,")"]})]})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:$.length===0?s.jsxs(ve,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:()=>F([{key:"",value:""}]),children:[s.jsx(D,{name:"add",className:"h-3.5 w-3.5"}),t("settings.mcp.page.env.addEnvironmentVariable")]}):s.jsx(yp,{value:$,onChange:F,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:Qe=>t("settings.mcp.page.toast.importedVariablesCount",{count:Qe}),clipboardReadFailed:t("settings.mcp.page.toast.clipboardReadFailed"),keyLabel:t("settings.mcp.page.env.key"),valueLabel:t("settings.mcp.page.env.value"),valuePlaceholder:t("settings.mcp.page.env.valuePlaceholder"),hideValueTitle:t("settings.mcp.page.env.hide"),showValueTitle:t("settings.mcp.page.env.show"),addVariable:t("settings.mcp.page.env.addVariable"),plainTextWarning:t("settings.mcp.page.env.plainTextWarning"),removeVariableAria:t("settings.mcp.page.env.removeVariableAria")})})]}),s.jsxs("div",{className:"flex items-center gap-2 px-2 py-1",children:[s.jsx(ve,{onClick:He,disabled:te||!at&&!S,size:"xs",className:"!font-normal",children:t(te?"settings.common.actions.saving":S?"settings.common.actions.create":"settings.common.actions.saveChanges")}),!S&&s.jsx(ve,{variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>xe(!0),children:t("settings.common.actions.delete")})]})]}),s.jsx(ps,{open:De,onOpenChange:Qe=>{Qe||(Xe(!1),tt(""),it(null))},children:s.jsxs(ms,{className:"max-w-md",children:[s.jsxs(gs,{children:[s.jsx(fs,{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(jn,{value:st,onChange:Qe=>{tt(Qe.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"}),Ue&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:Ue}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:s.jsxs(ve,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:Le,type:"button",children:[s.jsx(D,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.importDialog.pasteFromClipboard")]})})]}),s.jsxs(Hs,{children:[s.jsx(ve,{variant:"outline",onClick:()=>{Xe(!1),tt(""),it(null)},className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(ve,{onClick:Ge,disabled:!st.trim(),size:"sm",children:t("settings.common.actions.import")})]})]})}),s.jsx(ps,{open:ue,onOpenChange:Qe=>{!Qe&&!ne&&xe(!1)},children:s.jsxs(ms,{className:"max-w-md",children:[s.jsxs(gs,{children:[s.jsx(fs,{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(Hs,{children:[s.jsx(ve,{variant:"outline",onClick:()=>xe(!1),disabled:ne,className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(ve,{variant:"destructive",size:"sm",onClick:ze,disabled:ne,children:t(ne?"settings.mcp.page.actions.deleting":"settings.common.actions.delete")})]})]})})]})},zk="<built-in>",ri=t=>t?.path===zk,Uk=t=>{const e=ot.c(150),{onItemSelect:n}=t,{t:r}=ut(),[a,i]=o.useState(null),[l,c]=o.useState(""),[d,p]=o.useState(null),[m,u]=o.useState(!1),[f,b]=o.useState(null),{selectedSkillName:g,skills:v,setSelectedSkill:x,setSkillDraft:h,createSkill:j,deleteSkill:y,getSkillDetail:C}=ma(er(Wk));let k;e[0]!==n||e[1]!==x||e[2]!==h||e[3]!==v?(k=()=>{let Le="new-skill",Ge=1;for(;v.some(at=>at.name===Le);)Le=`new-skill-${Ge}`,Ge++;h({name:Le,scope:"user",source:"opencode",description:""}),x(Le),n?.()},e[0]=n,e[1]=x,e[2]=h,e[3]=v,e[4]=k):k=e[4];const w=k;let S;e[5]===Symbol.for("react.memo_cache_sentinel")?(S=async Le=>{ri(Le)||p(Le)},e[5]=S):S=e[5];const I=S;let T;e[6]!==d||e[7]!==y||e[8]!==r?(T=async()=>{if(!d)return;if(ri(d)){p(null);return}u(!0),await y(d.name)?(G.success(r("settings.skills.sidebar.toast.skillDeleted",{name:d.name})),p(null)):G.error(r("settings.skills.sidebar.toast.deleteSkillFailed")),u(!1)},e[6]=d,e[7]=y,e[8]=r,e[9]=T):T=e[9];const P=T;let A;e[10]!==C||e[11]!==x||e[12]!==h||e[13]!==v||e[14]!==r?(A=async Le=>{if(ri(Le))return;const Ge=Le.name;let at=1,He=`${Ge}-copy`;for(;v.some(et=>et.name===He);)at++,He=`${Ge}-copy-${at}`;const ze=await C(Le.name);if(!ze){G.error(r("settings.skills.sidebar.toast.duplicateLoadFailed"));return}h({name:He,scope:Le.scope||"user",source:Le.source||"opencode",description:(ze.sources.md.fields.includes("description"),""),instructions:""}),x(He)},e[10]=C,e[11]=x,e[12]=h,e[13]=v,e[14]=r,e[15]=A):A=e[15];const N=A;let E;e[16]===Symbol.for("react.memo_cache_sentinel")?(E=Le=>{ri(Le)||(c(Le.name),i(Le))},e[16]=E):E=e[16];const M=E;let O;e[17]!==j||e[18]!==y||e[19]!==C||e[20]!==a||e[21]!==l||e[22]!==x||e[23]!==v||e[24]!==r?(O=async()=>{if(!a)return;if(ri(a)){i(null);return}const Le=l.trim().replace(/\s+/g,"-").toLowerCase();if(!Le){G.error(r("settings.skills.page.toast.skillNameRequired"));return}if(Le===a.name){i(null);return}if(v.some(He=>He.name===Le)){G.error(r("settings.skills.page.toast.skillExists"));return}if(!await C(a.name)){G.error(r("settings.skills.sidebar.toast.renameLoadFailed")),i(null);return}await j({name:Le,description:"Renamed skill",scope:a.scope,source:a.source})?await y(a.name)?(G.success(`Skill renamed to "${Le}"`),x(Le)):G.error(r("settings.skills.sidebar.toast.removeOldAfterRenameFailed")):G.error(r("settings.skills.sidebar.toast.renameFailed")),i(null)},e[17]=j,e[18]=y,e[19]=C,e[20]=a,e[21]=l,e[22]=x,e[23]=v,e[24]=r,e[25]=O):O=e[25];const V=O;let B;e[26]!==v?(B=v.filter(Kk),e[26]=v,e[27]=B):B=e[27];const $=B;let F;e[28]!==v?(F=v.filter(Hk),e[28]=v,e[29]=F):F=e[29];const _=F;let q;e[30]===Symbol.for("react.memo_cache_sentinel")?(q=function(Ge){const at={},He=[];for(const et of Ge)et.group?(at[et.group]||(at[et.group]=[]),at[et.group].push(et)):He.push(et);const ze=Object.keys(at).sort(Gk).map(et=>({name:et,skills:[...at[et]].sort(qk)}));return He.sort(Yk),{sortedGroups:ze,ungrouped:He}},e[30]=q):q=e[30];const L=q;let Y;e[31]!==$?(Y=L($),e[31]=$,e[32]=Y):Y=e[32];const Z=Y;let ae;e[33]!==_?(ae=L(_),e[33]=_,e[34]=ae):ae=e[34];const re=ae;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 fe;e[36]!==r?(fe=r("settings.skills.sidebar.title"),e[36]=r,e[37]=fe):fe=e[37];let H;e[38]!==fe?(H=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:fe}),e[38]=fe,e[39]=H):H=e[39];let K;e[40]===Symbol.for("react.memo_cache_sentinel")?(K=s.jsx(jo,{className:"mb-3"}),e[40]=K):K=e[40];let Q;e[41]!==v.length||e[42]!==r?(Q=r("settings.skills.sidebar.total",{count:v.length}),e[41]=v.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(D,{name:"add",className:"h-3.5 w-3.5"}),e[46]=de):de=e[46];let be;e[47]!==w?(be=s.jsx(ve,{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]=be):be=e[48];let we;e[49]!==W||e[50]!==be?(we=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[W,be]}),e[49]=W,e[50]=be,e[51]=we):we=e[51];let te;e[52]!==H||e[53]!==we?(te=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[H,K,we]}),e[52]=H,e[53]=we,e[54]=te):te=e[54];let ge;e[55]!==Z||e[56]!==re||e[57]!==N||e[58]!==n||e[59]!==f||e[60]!==$||e[61]!==g||e[62]!==x||e[63]!==v.length||e[64]!==r||e[65]!==_?(ge=s.jsx(ws,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:v.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(D,{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(Le=>{const{name:Ge,skills:at}=Le;return s.jsx(bd,{label:Ge,count:at.length,storageKey:"project-skills",children:at.map(He=>s.jsx(Bo,{skill:He,isSelected:g===He.name,onSelect:()=>{x(He.name),n?.()},onRename:()=>M(He),onDelete:()=>I(He),onDuplicate:()=>N(He),isMenuOpen:f===He.name,onMenuOpenChange:ze=>b(ze?He.name:null)},He.name))},Ge)}),Z.ungrouped.map(Le=>s.jsx(Bo,{skill:Le,isSelected:g===Le.name,onSelect:()=>{x(Le.name),n?.()},onRename:()=>M(Le),onDelete:()=>I(Le),onDuplicate:()=>N(Le),isMenuOpen:f===Le.name,onMenuOpenChange:Ge=>b(Ge?Le.name:null)},Le.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")}),re.sortedGroups.map(Le=>{const{name:Ge,skills:at}=Le;return s.jsx(bd,{label:Ge,count:at.length,storageKey:"user-skills",children:at.map(He=>s.jsx(Bo,{skill:He,isSelected:g===He.name,onSelect:()=>{x(He.name),n?.()},onRename:()=>M(He),onDelete:()=>I(He),onDuplicate:()=>N(He),isMenuOpen:f===He.name,onMenuOpenChange:ze=>b(ze?He.name:null)},He.name))},Ge)}),re.ungrouped.map(Le=>s.jsx(Bo,{skill:Le,isSelected:g===Le.name,onSelect:()=>{x(Le.name),n?.()},onRename:()=>M(Le),onDelete:()=>I(Le),onDuplicate:()=>N(Le),isMenuOpen:f===Le.name,onMenuOpenChange:Ge=>b(Ge?Le.name:null)},Le.name))]})]})}),e[55]=Z,e[56]=re,e[57]=N,e[58]=n,e[59]=f,e[60]=$,e[61]=g,e[62]=x,e[63]=v.length,e[64]=r,e[65]=_,e[66]=ge):ge=e[66];const ue=d!==null;let xe;e[67]!==m?(xe=Le=>{!Le&&!m&&p(null)},e[67]=m,e[68]=xe):xe=e[68];let ne;e[69]!==r?(ne=r("settings.skills.sidebar.deleteDialog.title"),e[69]=r,e[70]=ne):ne=e[70];let pe;e[71]!==ne?(pe=s.jsx(fs,{children:ne}),e[71]=ne,e[72]=pe):pe=e[72];const J=d?.name??"";let Se;e[73]!==r||e[74]!==J?(Se=r("settings.skills.sidebar.deleteDialog.description",{name:J}),e[73]=r,e[74]=J,e[75]=Se):Se=e[75];let he;e[76]!==Se?(he=s.jsx(Ns,{children:Se}),e[76]=Se,e[77]=he):he=e[77];let Ie;e[78]!==pe||e[79]!==he?(Ie=s.jsxs(gs,{children:[pe,he]}),e[78]=pe,e[79]=he,e[80]=Ie):Ie=e[80];let Pe;e[81]===Symbol.for("react.memo_cache_sentinel")?(Pe=()=>p(null),e[81]=Pe):Pe=e[81];let Ce;e[82]!==r?(Ce=r("settings.common.actions.cancel"),e[82]=r,e[83]=Ce):Ce=e[83];let X;e[84]!==m||e[85]!==Ce?(X=s.jsx(ve,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:Pe,disabled:m,children:Ce}),e[84]=m,e[85]=Ce,e[86]=X):X=e[86];let ie;e[87]!==r?(ie=r("settings.common.actions.delete"),e[87]=r,e[88]=ie):ie=e[88];let Ne;e[89]!==P||e[90]!==m||e[91]!==ie?(Ne=s.jsx(ve,{size:"sm",onClick:P,disabled:m,children:ie}),e[89]=P,e[90]=m,e[91]=ie,e[92]=Ne):Ne=e[92];let oe;e[93]!==X||e[94]!==Ne?(oe=s.jsxs(Hs,{children:[X,Ne]}),e[93]=X,e[94]=Ne,e[95]=oe):oe=e[95];let ke;e[96]!==Ie||e[97]!==oe?(ke=s.jsxs(ms,{className:"max-w-md",children:[Ie,oe]}),e[96]=Ie,e[97]=oe,e[98]=ke):ke=e[98];let Te;e[99]!==ue||e[100]!==xe||e[101]!==ke?(Te=s.jsx(ps,{open:ue,onOpenChange:xe,children:ke}),e[99]=ue,e[100]=xe,e[101]=ke,e[102]=Te):Te=e[102];const Be=a!==null;let je;e[103]===Symbol.for("react.memo_cache_sentinel")?(je=Le=>!Le&&i(null),e[103]=je):je=e[103];let ee;e[104]!==r?(ee=r("settings.skills.sidebar.renameDialog.title"),e[104]=r,e[105]=ee):ee=e[105];let R;e[106]!==ee?(R=s.jsx(fs,{children:ee}),e[106]=ee,e[107]=R):R=e[107];const U=a?.name??"";let le;e[108]!==r||e[109]!==U?(le=r("settings.skills.sidebar.renameDialog.description",{name:U}),e[108]=r,e[109]=U,e[110]=le):le=e[110];let Me;e[111]!==le?(Me=s.jsx(Ns,{children:le}),e[111]=le,e[112]=Me):Me=e[112];let Oe;e[113]!==R||e[114]!==Me?(Oe=s.jsxs(gs,{children:[R,Me]}),e[113]=R,e[114]=Me,e[115]=Oe):Oe=e[115];let Ae;e[116]===Symbol.for("react.memo_cache_sentinel")?(Ae=Le=>c(Le.target.value),e[116]=Ae):Ae=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=Le=>{Le.key==="Enter"&&V()},e[119]=V,e[120]=De):De=e[120];let Xe;e[121]!==l||e[122]!==z||e[123]!==De?(Xe=s.jsx(Bt,{value:l,onChange:Ae,placeholder:z,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:De}),e[121]=l,e[122]=z,e[123]=De,e[124]=Xe):Xe=e[124];let st;e[125]===Symbol.for("react.memo_cache_sentinel")?(st=()=>i(null),e[125]=st):st=e[125];let tt;e[126]!==r?(tt=r("settings.common.actions.cancel"),e[126]=r,e[127]=tt):tt=e[127];let Ue;e[128]!==tt?(Ue=s.jsx(ve,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:st,children:tt}),e[128]=tt,e[129]=Ue):Ue=e[129];let it;e[130]!==r?(it=r("settings.common.actions.rename"),e[130]=r,e[131]=it):it=e[131];let Ye;e[132]!==V||e[133]!==it?(Ye=s.jsx(ve,{size:"sm",onClick:V,children:it}),e[132]=V,e[133]=it,e[134]=Ye):Ye=e[134];let rt;e[135]!==Ue||e[136]!==Ye?(rt=s.jsxs(Hs,{children:[Ue,Ye]}),e[135]=Ue,e[136]=Ye,e[137]=rt):rt=e[137];let Je;e[138]!==Oe||e[139]!==Xe||e[140]!==rt?(Je=s.jsxs(ms,{children:[Oe,Xe,rt]}),e[138]=Oe,e[139]=Xe,e[140]=rt,e[141]=Je):Je=e[141];let ce;e[142]!==Be||e[143]!==Je?(ce=s.jsx(ps,{open:Be,onOpenChange:je,children:Je}),e[142]=Be,e[143]=Je,e[144]=ce):ce=e[144];let We;return e[145]!==te||e[146]!==ge||e[147]!==Te||e[148]!==ce?(We=s.jsxs("div",{className:me,children:[te,ge,Te,ce]}),e[145]=te,e[146]=ge,e[147]=Te,e[148]=ce,e[149]=We):We=e[149],We},Bo=t=>{const e=ot.c(38),{skill:n,isSelected:r,onSelect:a,onDelete:i,onRename:l,onDuplicate:c,isMenuOpen:d,onMenuOpenChange:p}=t,{t:m}=ut();let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u=ro(),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 g=b;let v;e[4]!==n?(v=ri(n),e[4]=n,e[5]=v):v=e[5];const x=v,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 y;e[8]!==p?(y=f?void 0:N=>{N.preventDefault(),p(!0)},e[8]=p,e[9]=y):y=e[9];let C;e[10]!==n.name?(C=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n.name}),e[10]=n.name,e[11]=C):C=e[11];let k;e[12]!==n.scope?(k=s.jsx("span",{className:"typography-micro text-muted-foreground bg-[var(--surface-muted)] px-1 rounded flex-shrink-0 leading-none pb-px border border-[var(--interactive-border)]/50",children:n.scope}),e[12]=n.scope,e[13]=k):k=e[13];let w;e[14]!==g?(w=s.jsx("span",{className:"typography-micro text-muted-foreground bg-[var(--surface-muted)] px-1 rounded flex-shrink-0 leading-none pb-px border border-[var(--interactive-border)]/50",children:g}),e[14]=g,e[15]=w):w=e[15];let S;e[16]!==C||e[17]!==k||e[18]!==w?(S=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]=S):S=e[19];let I;e[20]!==a||e[21]!==S?(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:S}),e[20]=a,e[21]=S,e[22]=I):I=e[22];let T;e[23]!==x||e[24]!==d||e[25]!==i||e[26]!==c||e[27]!==p||e[28]!==l||e[29]!==m?(T=x?null:s.jsxs(As,{open:d,onOpenChange:p,children:[s.jsx(Is,{asChild:!0,children:s.jsx(ve,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(D,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsxs(Ps,{align:"end",className:"w-fit min-w-20",children:[s.jsxs(Ot,{onClick:N=>{N.stopPropagation(),l()},children:[s.jsx(D,{name:"edit",className:"h-4 w-4 mr-px"}),m("settings.common.actions.rename")]}),s.jsxs(Ot,{onClick:N=>{N.stopPropagation(),c()},children:[s.jsx(D,{name:"file-copy",className:"h-4 w-4 mr-px"}),m("settings.common.actions.duplicate")]}),s.jsxs(Ot,{onClick:N=>{N.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[s.jsx(D,{name:"delete-bin",className:"h-4 w-4 mr-px"}),m("settings.common.actions.delete")]})]})]}),e[23]=x,e[24]=d,e[25]=i,e[26]=c,e[27]=p,e[28]=l,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 A;return e[34]!==P||e[35]!==j||e[36]!==y?(A=s.jsx("div",{className:j,onContextMenu:y,children:P}),e[34]=P,e[35]=j,e[36]=y,e[37]=A):A=e[37],A};function Wk(t){return{selectedSkillName:t.selectedSkillName,skills:t.skills,setSelectedSkill:t.setSelectedSkill,setSkillDraft:t.setSkillDraft,createSkill:t.createSkill,deleteSkill:t.deleteSkill,getSkillDetail:t.getSkillDetail}}function Kk(t){return t.scope==="project"}function Hk(t){return t.scope==="user"}function Gk(t,e){return t.localeCompare(e)}function qk(t,e){return t.name.localeCompare(e.name)}function Yk(t,e){return t.name.localeCompare(e.name)}const Qk=()=>`custom:${Date.now()}-${Math.random().toString(16).slice(2)}`,Jk=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},Xk=async()=>{try{const t=nr()?.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}},Zk=t=>{const e=ot.c(158),{open:n,onOpenChange:r}=t,{t:a}=ut(),i=La(e3),l=La(t3),c=La(s3),d=Qn(n3),p=Qn(r3),[m,u]=o.useState(""),[f,b]=o.useState(""),[g,v]=o.useState("");let x;e[0]===Symbol.for("react.memo_cache_sentinel")?(x=[],e[0]=x):x=e[0];const[h,j]=o.useState(x),[y,C]=o.useState(null),[k,w]=o.useState(!1);let S;e[1]===Symbol.for("react.memo_cache_sentinel")?(S=[],e[1]=S):S=e[1];const[I,T]=o.useState(S),[P,A]=o.useState(null),N=o.useRef(0);let E;e[2]===Symbol.for("react.memo_cache_sentinel")?(E=ce=>{N.current=N.current+1,w(!1),C(null),ce?.clearIdentity&&(T([]),A(null))},e[2]=E):E=e[2];const M=E;let O,V;e[3]!==p||e[4]!==n?(O=()=>{n&&(N.current=N.current+1,u(""),b(""),v(""),C(null),w(!1),T([]),A(null),p(),(async()=>{const ce=await Xk(),We=Array.isArray(ce?.skillCatalogs)?ce?.skillCatalogs:[];j(We||[])})())},V=[n,p],e[3]=p,e[4]=n,e[5]=O,e[6]=V):(O=e[5],V=e[6]),o.useEffect(O,V);let B;e[7]!==f?(B=f.trim(),e[7]=f,e[8]=B):B=e[8];const $=B;let F;e[9]!==g?(F=g.trim(),e[9]=g,e[10]=F):F=e[10];const _=F;let q;if(e[11]!==h||e[12]!==$||e[13]!==_){let ce;e[15]!==$||e[16]!==_?(ce=We=>{const Le=(We.source||"").trim(),Ge=(We.subpath||"").trim();return Le===$&&Ge===_},e[15]=$,e[16]=_,e[17]=ce):ce=e[17],q=h.some(ce),e[11]=h,e[12]=$,e[13]=_,e[14]=q}else q=e[14];const L=q;let Y;e[18]!==d||e[19]!==P||e[20]!==m||e[21]!==i||e[22]!==f||e[23]!==g||e[24]!==a?(Y=async()=>{const ce=f.trim();if(!ce){G.error(a("settings.skills.catalog.add.toast.repositoryRequired"));return}m.trim()||u(Jk(ce)),w(!1),C(null);const We=N.current+1;N.current=We;const Le=await i({source:ce,subpath:g.trim()||void 0,gitIdentityId:P||void 0});if(N.current!==We)return;if(!Le.ok){if(Le.error?.kind==="authRequired"){if(mn()){G.error(a("settings.skills.catalog.shared.toast.privateRepoNotSupportedVsCode"));return}const at=Le.error.identities||[];if(T(at),!P&&at.length>0){const He=d&&d!=="global"&&at.some(ze=>ze.id===d)?d:at[0].id;A(He)}G.error(a("settings.skills.catalog.add.toast.authenticationRequiredScan"));return}G.error(Le.error?.message||a("settings.skills.catalog.add.toast.scanFailed"));return}const Ge=Le.items?.length||0;if(C(Ge),Ge===0){G.error(a("settings.skills.catalog.add.toast.noSkillsFound")),w(!1);return}T([]),w(!0),G.success(a("settings.skills.catalog.shared.toast.foundSkills",{count:Ge}))},e[18]=d,e[19]=P,e[20]=m,e[21]=i,e[22]=f,e[23]=g,e[24]=a,e[25]=Y):Y=e[25];const Z=Y;let ae;e[26]!==h||e[27]!==P||e[28]!==L||e[29]!==m||e[30]!==l||e[31]!==r||e[32]!==k||e[33]!==f||e[34]!==g||e[35]!==a?(ae=async()=>{const ce=m.trim(),We=f.trim(),Le=g.trim();if(!ce){G.error(a("settings.skills.catalog.add.toast.catalogNameRequired"));return}if(!We){G.error(a("settings.skills.catalog.add.toast.repositoryRequired"));return}if(!k){G.error(a("settings.skills.catalog.add.toast.scanBeforeAdd"));return}if(L){G.error(a("settings.skills.catalog.add.toast.catalogAlreadyExists"));return}const Ge={id:Qk(),label:ce,source:We,...Le?{subpath:Le}:{},...P?{gitIdentityId:P}:{}},at=[...h,Ge];try{await Ss({skillCatalogs:at}),j(at),G.success(a("settings.skills.catalog.add.toast.catalogAdded")),await l({refresh:!0}),r(!1)}catch(He){const ze=He;G.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]=l,e[31]=r,e[32]=k,e[33]=f,e[34]=g,e[35]=a,e[36]=ae):ae=e[36];const re=ae;let me;e[37]!==a?(me=a("settings.skills.catalog.add.title"),e[37]=a,e[38]=me):me=e[38];let fe;e[39]!==me?(fe=s.jsx(fs,{children:me}),e[39]=me,e[40]=fe):fe=e[40];let H;e[41]!==a?(H=a("settings.skills.catalog.add.descriptionPrefix"),e[41]=a,e[42]=H):H=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]!==H||e[47]!==Q?(W=s.jsxs(Ns,{children:[H," ",K,Q]}),e[46]=H,e[47]=Q,e[48]=W):W=e[48];let de;e[49]!==fe||e[50]!==W?(de=s.jsxs(gs,{children:[fe,W]}),e[49]=fe,e[50]=W,e[51]=de):de=e[51];let be;e[52]!==a?(be=a("settings.skills.catalog.add.field.catalogName"),e[52]=a,e[53]=be):be=e[53];let we;e[54]!==be?(we=s.jsx("label",{className:"typography-ui-label text-foreground",children:be}),e[54]=be,e[55]=we):we=e[55];let te;e[56]===Symbol.for("react.memo_cache_sentinel")?(te=ce=>u(ce.target.value),e[56]=te):te=e[56];let ge;e[57]!==a?(ge=a("settings.skills.catalog.add.field.catalogNamePlaceholder"),e[57]=a,e[58]=ge):ge=e[58];let ue;e[59]!==m||e[60]!==ge?(ue=s.jsx(Bt,{value:m,onChange:te,placeholder:ge}),e[59]=m,e[60]=ge,e[61]=ue):ue=e[61];let xe;e[62]!==we||e[63]!==ue?(xe=s.jsxs("div",{className:"space-y-2",children:[we,ue]}),e[62]=we,e[63]=ue,e[64]=xe):xe=e[64];let ne;e[65]!==a?(ne=a("settings.skills.catalog.add.field.repository"),e[65]=a,e[66]=ne):ne=e[66];let pe;e[67]!==ne?(pe=s.jsx("label",{className:"typography-ui-label text-foreground",children:ne}),e[67]=ne,e[68]=pe):pe=e[68];let J;e[69]===Symbol.for("react.memo_cache_sentinel")?(J=ce=>{b(ce.target.value),M({clearIdentity:!0})},e[69]=J):J=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 he;e[72]!==f||e[73]!==Se?(he=s.jsx(Bt,{value:f,onChange:J,placeholder:Se}),e[72]=f,e[73]=Se,e[74]=he):he=e[74];let Ie;e[75]!==a?(Ie=a("settings.skills.catalog.add.field.repositoryHint"),e[75]=a,e[76]=Ie):Ie=e[76];let Pe;e[77]!==Ie?(Pe=s.jsx("p",{className:"typography-micro text-muted-foreground",children:Ie}),e[77]=Ie,e[78]=Pe):Pe=e[78];let Ce;e[79]!==pe||e[80]!==he||e[81]!==Pe?(Ce=s.jsxs("div",{className:"space-y-2",children:[pe,he,Pe]}),e[79]=pe,e[80]=he,e[81]=Pe,e[82]=Ce):Ce=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 ie;e[85]!==X?(ie=s.jsx("label",{className:"typography-ui-label text-foreground",children:X}),e[85]=X,e[86]=ie):ie=e[86];let Ne;e[87]===Symbol.for("react.memo_cache_sentinel")?(Ne=ce=>{v(ce.target.value),M({clearIdentity:!0})},e[87]=Ne):Ne=e[87];let oe;e[88]!==a?(oe=a("settings.skills.catalog.shared.field.subpathPlaceholder"),e[88]=a,e[89]=oe):oe=e[89];let ke;e[90]!==g||e[91]!==oe?(ke=s.jsx(Bt,{value:g,onChange:Ne,placeholder:oe}),e[90]=g,e[91]=oe,e[92]=ke):ke=e[92];let Te;e[93]!==ie||e[94]!==ke?(Te=s.jsxs("div",{className:"space-y-2",children:[ie,ke]}),e[93]=ie,e[94]=ke,e[95]=Te):Te=e[95];let Be;e[96]!==P||e[97]!==I||e[98]!==a?(Be=I.length>0&&!mn()?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(is,{value:P||"",onValueChange:ce=>{A(ce),M()},children:[s.jsx(os,{className:"w-fit",children:s.jsx("span",{children:I.find(ce=>ce.id===P)?.name||a("settings.skills.catalog.shared.auth.chooseIdentity")})}),s.jsx(ls,{align:"start",children:I.map(a3)})]}),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]=Be):Be=e[99];let je;e[100]!==y||e[101]!==a?(je=y!==null?s.jsx("div",{className:"typography-meta text-muted-foreground",children:a("settings.skills.catalog.add.scanResult",{count:y})}):null,e[100]=y,e[101]=a,e[102]=je):je=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 R;e[106]!==xe||e[107]!==Ce||e[108]!==Te||e[109]!==Be||e[110]!==je||e[111]!==ee?(R=s.jsxs("div",{className:"space-y-4",children:[xe,Ce,Te,Be,je,ee]}),e[106]=xe,e[107]=Ce,e[108]=Te,e[109]=Be,e[110]=je,e[111]=ee,e[112]=R):R=e[112];let U;e[113]!==r?(U=()=>r(!1),e[113]=r,e[114]=U):U=e[114];let le;e[115]!==a?(le=a("settings.common.actions.cancel"),e[115]=a,e[116]=le):le=e[116];let Me;e[117]!==U||e[118]!==le?(Me=s.jsx(ve,{size:"sm",variant:"ghost",onClick:U,children:le}),e[117]=U,e[118]=le,e[119]=Me):Me=e[119];let Oe;e[120]!==Z?(Oe=()=>{Z()},e[120]=Z,e[121]=Oe):Oe=e[121];let Ae;e[122]!==c||e[123]!==f?(Ae=c||!f.trim(),e[122]=c,e[123]=f,e[124]=Ae):Ae=e[124];let z;e[125]===Symbol.for("react.memo_cache_sentinel")?(z=s.jsx(D,{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 Xe;e[129]!==Oe||e[130]!==Ae||e[131]!==De?(Xe=s.jsxs(ve,{size:"sm",className:"gap-2",variant:"ghost",onClick:Oe,disabled:Ae,children:[z,De]}),e[129]=Oe,e[130]=Ae,e[131]=De,e[132]=Xe):Xe=e[132];let st;e[133]!==re?(st=()=>{re()},e[133]=re,e[134]=st):st=e[134];let tt;e[135]!==L||e[136]!==m||e[137]!==k||e[138]!==f?(tt=!k||L||!m.trim()||!f.trim(),e[135]=L,e[136]=m,e[137]=k,e[138]=f,e[139]=tt):tt=e[139];let Ue;e[140]!==a?(Ue=a("settings.skills.catalog.add.actions.addCatalog"),e[140]=a,e[141]=Ue):Ue=e[141];let it;e[142]!==st||e[143]!==tt||e[144]!==Ue?(it=s.jsx(ve,{size:"sm",onClick:st,disabled:tt,children:Ue}),e[142]=st,e[143]=tt,e[144]=Ue,e[145]=it):it=e[145];let Ye;e[146]!==Me||e[147]!==Xe||e[148]!==it?(Ye=s.jsxs(Hs,{children:[Me,Xe,it]}),e[146]=Me,e[147]=Xe,e[148]=it,e[149]=Ye):Ye=e[149];let rt;e[150]!==de||e[151]!==R||e[152]!==Ye?(rt=s.jsxs(ms,{className:"max-w-xl",children:[de,R,Ye]}),e[150]=de,e[151]=R,e[152]=Ye,e[153]=rt):rt=e[153];let Je;return e[154]!==r||e[155]!==n||e[156]!==rt?(Je=s.jsx(ps,{open:n,onOpenChange:r,children:rt}),e[154]=r,e[155]=n,e[156]=rt,e[157]=Je):Je=e[157],Je};function e3(t){return t.scanRepo}function t3(t){return t.loadCatalog}function s3(t){return t.isScanning}function n3(t){return t.defaultGitIdentityId}function r3(t){return t.loadDefaultGitIdentityId}function a3(t){return s.jsx(Mt,{value:t.id,children:t.name},t.id)}const i3=t=>{const e=ot.c(85),{open:n,onOpenChange:r,conflicts:a,onConfirm:i}=t,{t:l}=ut();let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c={},e[0]=c):c=e[0];const[d,p]=o.useState(c);let m,u;e[1]!==a||e[2]!==n?(m=()=>{if(!n)return;const fe={};for(const H of a)fe[H.skillName]="skip";p(fe)},u=[n,a],e[1]=a,e[2]=n,e[3]=m,e[4]=u):(m=e[3],u=e[4]),o.useEffect(m,u);let f;e[5]!==a?(f=fe=>{const H={};for(const K of a)H[K.skillName]=fe;p(H)},e[5]=a,e[6]=f):f=e[6];const b=f;let g;e[7]!==a||e[8]!==d?(g=a.length>0&&a.every(fe=>d[fe.skillName]),e[7]=a,e[8]=d,e[9]=g):g=e[9];const v=g;let x;e[10]!==l?(x=l("settings.skills.catalog.conflicts.title"),e[10]=l,e[11]=x):x=e[11];let h;e[12]!==x?(h=s.jsx(fs,{children:x}),e[12]=x,e[13]=h):h=e[13];let j;e[14]!==l?(j=l("settings.skills.catalog.conflicts.description"),e[14]=l,e[15]=j):j=e[15];let y;e[16]!==j?(y=s.jsx(Ns,{children:j}),e[16]=j,e[17]=y):y=e[17];let C;e[18]!==h||e[19]!==y?(C=s.jsxs(gs,{children:[h,y]}),e[18]=h,e[19]=y,e[20]=C):C=e[20];let k;e[21]!==a.length||e[22]!==l?(k=l("settings.skills.catalog.conflicts.count",{count:a.length}),e[21]=a.length,e[22]=l,e[23]=k):k=e[23];let w;e[24]!==k?(w=s.jsx("span",{className:"typography-meta text-muted-foreground",children:k}),e[24]=k,e[25]=w):w=e[25];let S;e[26]!==b?(S=()=>b("skip"),e[26]=b,e[27]=S):S=e[27];let I;e[28]!==l?(I=l("settings.skills.catalog.conflicts.actions.skipAll"),e[28]=l,e[29]=I):I=e[29];let T;e[30]!==S||e[31]!==I?(T=s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:S,children:I}),e[30]=S,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 A;e[35]!==l?(A=l("settings.skills.catalog.conflicts.actions.overwriteAll"),e[35]=l,e[36]=A):A=e[36];let N;e[37]!==P||e[38]!==A?(N=s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:P,children:A}),e[37]=P,e[38]=A,e[39]=N):N=e[39];let E;e[40]!==T||e[41]!==N?(E=s.jsxs("div",{className:"flex items-center gap-2",children:[T,N]}),e[40]=T,e[41]=N,e[42]=E):E=e[42];let M;e[43]!==w||e[44]!==E?(M=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[w,E]}),e[43]=w,e[44]=E,e[45]=M):M=e[45];let O;if(e[46]!==a||e[47]!==d||e[48]!==l){let fe;e[50]!==d||e[51]!==l?(fe=H=>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:H.skillName}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("settings.skills.catalog.conflicts.installedIn",{scope:H.scope==="project"?l("settings.skills.catalog.conflicts.scope.project"):l("settings.skills.catalog.conflicts.scope.user"),source:H.source==="agents"?l("settings.skills.catalog.conflicts.source.agents"):l("settings.skills.catalog.conflicts.source.opencode")})})]}),s.jsxs(is,{value:d[H.skillName]||"skip",onValueChange:K=>p(Q=>({...Q,[H.skillName]:K})),children:[s.jsx(os,{className:"w-fit",children:s.jsx("span",{className:"capitalize",children:(d[H.skillName]||"skip")==="overwrite"?l("settings.skills.catalog.conflicts.decision.overwrite"):l("settings.skills.catalog.conflicts.decision.skip")})}),s.jsxs(ls,{align:"end",children:[s.jsx(Mt,{value:"skip",className:"pr-2 [&>span:first-child]:hidden",children:l("settings.skills.catalog.conflicts.decision.skip")}),s.jsx(Mt,{value:"overwrite",className:"pr-2 [&>span:first-child]:hidden",children:l("settings.skills.catalog.conflicts.decision.overwrite")})]})]})]},H.skillName),e[50]=d,e[51]=l,e[52]=fe):fe=e[52],O=a.map(fe),e[46]=a,e[47]=d,e[48]=l,e[49]=O}else O=e[49];let V;e[53]!==O?(V=s.jsx("div",{className:"space-y-2",children:O}),e[53]=O,e[54]=V):V=e[54];let B;e[55]!==M||e[56]!==V?(B=s.jsxs("div",{className:"space-y-3",children:[M,V]}),e[55]=M,e[56]=V,e[57]=B):B=e[57];let $;e[58]!==r?($=()=>r(!1),e[58]=r,e[59]=$):$=e[59];let F;e[60]!==l?(F=l("settings.common.actions.cancel"),e[60]=l,e[61]=F):F=e[61];let _;e[62]!==$||e[63]!==F?(_=s.jsx(ve,{size:"sm",variant:"ghost",onClick:$,children:F}),e[62]=$,e[63]=F,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=!v;let Y;e[68]!==l?(Y=l("settings.skills.catalog.conflicts.actions.continue"),e[68]=l,e[69]=Y):Y=e[69];let Z;e[70]!==q||e[71]!==L||e[72]!==Y?(Z=s.jsx(ve,{size:"sm",onClick:q,disabled:L,children:Y}),e[70]=q,e[71]=L,e[72]=Y,e[73]=Z):Z=e[73];let ae;e[74]!==_||e[75]!==Z?(ae=s.jsxs(Hs,{children:[_,Z]}),e[74]=_,e[75]=Z,e[76]=ae):ae=e[76];let re;e[77]!==C||e[78]!==B||e[79]!==ae?(re=s.jsxs(ms,{className:"max-w-2xl",children:[C,B,ae]}),e[77]=C,e[78]=B,e[79]=ae,e[80]=re):re=e[80];let me;return e[81]!==r||e[82]!==n||e[83]!==re?(me=s.jsx(ps,{open:n,onOpenChange:r,children:re}),e[81]=r,e[82]=n,e[83]=re,e[84]=me):me=e[84],me},ru=[{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 Xi(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 fg(t){if(t==="user-claude")return{scope:"user",source:"claude"};if(t==="project-claude")return{scope:"project",source:"claude"};const e=ru.find(n=>n.value===t);return e?{scope:e.scope,source:e.source}:{scope:"user",source:"opencode"}}const o3=t=>{const e=ot.c(124),{open:n,onOpenChange:r,item:a}=t,{t:i}=ut(),l=La(l3),c=La(c3),[d,p]=o.useState("user"),[m,u]=o.useState("opencode"),f=Cs(d3),b=Cs(u3),[g,v]=o.useState(null),[x,h]=o.useState(!1);let j;e[0]===Symbol.for("react.memo_cache_sentinel")?(j=[],e[0]=j):j=e[0];const[y,C]=o.useState(j),[k,w]=o.useState(null);let S,I;e[1]!==b||e[2]!==n?(S=()=>{n&&(p("user"),u("opencode"),v(b),h(!1),C([]),w(null))},I=[n,b],e[1]=b,e[2]=n,e[3]=S,e[4]=I):(S=e[3],I=e[4]),o.useEffect(S,I);let T;e[5]!==i?(T=je=>{switch(je){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 A;e[7]!==i?(A=je=>{switch(je){case"project-opencode":return i("settings.skills.location.option.projectOpencode.description");case"user-agents":return i("settings.skills.location.option.userAgents.description");case"project-agents":return i("settings.skills.location.option.projectAgents.description");default:return i("settings.skills.location.option.userOpencode.description")}},e[7]=i,e[8]=A):A=e[8];const N=A;let E;e:{if(f.length===0){E=null;break e}if(g&&f.some(je=>je.id===g)){E=g;break e}if(b&&f.some(je=>je.id===b)){E=b;break e}E=f[0]?.id??null}const M=E;let O;e:{if(d!=="project"){O=null;break e}const je=M;if(!je){O=null;break e}let ee;if(e[9]!==je||e[10]!==f){let U;e[12]!==je?(U=le=>le.id===je,e[12]=je,e[13]=U):U=e[13],ee=f.find(U),e[9]=je,e[10]=f,e[11]=ee}else ee=e[11];O=ee?.path??null}const V=O;let B;e[14]!==l||e[15]!==a||e[16]!==r||e[17]!==i?(B=async je=>{const ee={skillDir:je.skillDir};a?.clawdhub&&(ee.clawdhub={slug:a.clawdhub.slug,version:a.clawdhub.version});const R=await l({source:je.source,subpath:je.subpath,gitIdentityId:a?.gitIdentityId,scope:je.scope,targetSource:je.targetSource,selections:[ee],conflictPolicy:"prompt",conflictDecisions:je.conflictDecisions},{directory:je.directoryOverride??null});if(R.ok){G.success(i("settings.skills.catalog.installSkill.toast.installed")),r(!1);return}if(R.error?.kind==="conflicts"){w({source:je.source,subpath:je.subpath,scope:je.scope,targetSource:je.targetSource,skillDir:je.skillDir,directoryOverride:je.directoryOverride??null}),C(R.error.conflicts),h(!0);return}if(R.error?.kind==="authRequired"){G.error(R.error.message||i("settings.skills.catalog.installSkill.toast.authRequired"));return}G.error(R.error?.message||i("settings.skills.catalog.installSkill.toast.installFailed"))},e[14]=l,e[15]=a,e[16]=r,e[17]=i,e[18]=B):B=e[18];const $=B;if(!a)return null;let F;e[19]!==i?(F=i("settings.skills.catalog.installSkill.title"),e[19]=i,e[20]=F):F=e[20];let _;e[21]!==F?(_=s.jsx(fs,{children:F}),e[21]=F,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 Y;e[27]!==i?(Y=i("settings.skills.catalog.installSkill.descriptionSuffix"),e[27]=i,e[28]=Y):Y=e[28];let Z;e[29]!==q||e[30]!==L||e[31]!==Y?(Z=s.jsxs(Ns,{children:[q," ",L," ",Y]}),e[29]=q,e[30]=L,e[31]=Y,e[32]=Z):Z=e[32];let ae;e[33]!==_||e[34]!==Z?(ae=s.jsxs(gs,{children:[_,Z]}),e[33]=_,e[34]=Z,e[35]=ae):ae=e[35];let re;e[36]!==i?(re=i("settings.skills.catalog.installSkill.field.destination"),e[36]=i,e[37]=re):re=e[37];let me;e[38]!==re?(me=s.jsx("span",{className:"typography-ui-label text-foreground",children:re}),e[38]=re,e[39]=me):me=e[39];let fe;e[40]!==d||e[41]!==m?(fe=Xi(d,m),e[40]=d,e[41]=m,e[42]=fe):fe=e[42];let H;e[43]===Symbol.for("react.memo_cache_sentinel")?(H=je=>{const ee=fg(je);p(ee.scope),u(ee.source==="agents"?"agents":"opencode")},e[43]=H):H=e[43];let K;e[44]!==d?(K=d==="user"?s.jsx(D,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(D,{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(D,{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(Xi(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 be;e[54]!==K||e[55]!==Q||e[56]!==de?(be=s.jsxs(os,{className:"w-fit gap-1.5",children:[K,Q,de]}),e[54]=K,e[55]=Q,e[56]=de,e[57]=be):be=e[57];let we;e[58]!==N||e[59]!==P?(we=ru.map(je=>s.jsx(Mt,{value:je.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:[je.scope==="user"?s.jsx(D,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(D,{name:"folder",className:"h-3.5 w-3.5"}),je.source==="agents"?s.jsx(D,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:P(je.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-5",children:N(je.value)})]})},je.value)),e[58]=N,e[59]=P,e[60]=we):we=e[60];let te;e[61]!==we?(te=s.jsx(ls,{align:"start",children:we}),e[61]=we,e[62]=te):te=e[62];let ge;e[63]!==fe||e[64]!==be||e[65]!==te?(ge=s.jsxs(is,{value:fe,onValueChange:H,children:[be,te]}),e[63]=fe,e[64]=be,e[65]=te,e[66]=ge):ge=e[66];let ue;e[67]!==me||e[68]!==ge?(ue=s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[me,ge]}),e[67]=me,e[68]=ge,e[69]=ue):ue=e[69];let xe;e[70]!==f||e[71]!==M||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(is,{value:M??"",onValueChange:je=>v(je),disabled:f.length===1,children:[s.jsx(os,{className:"w-fit",children:s.jsx(us,{placeholder:i("settings.skills.catalog.installSkill.field.chooseProjectPlaceholder")})}),s.jsx(ls,{align:"start",children:f.map(m3)})]})]}),e[70]=f,e[71]=M,e[72]=d,e[73]=i,e[74]=xe):xe=e[74];let ne;e[75]!==a.warnings?(ne=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]=ne):ne=e[76];let pe;e[77]!==ue||e[78]!==xe||e[79]!==ne?(pe=s.jsxs("div",{className:"mt-2 space-y-3",children:[ue,xe,ne]}),e[77]=ue,e[78]=xe,e[79]=ne,e[80]=pe):pe=e[80];let J;e[81]!==r?(J=()=>r(!1),e[81]=r,e[82]=J):J=e[82];let Se;e[83]!==i?(Se=i("settings.common.actions.cancel"),e[83]=i,e[84]=Se):Se=e[84];let he;e[85]!==J||e[86]!==Se?(he=s.jsx(ve,{size:"sm",variant:"ghost",onClick:J,children:Se}),e[85]=J,e[86]=Se,e[87]=he):he=e[87];const Ie=c||!a.installable||d==="project"&&!V;let Pe;e[88]!==V||e[89]!==$||e[90]!==a.repoSource||e[91]!==a.repoSubpath||e[92]!==a.skillDir||e[93]!==d||e[94]!==m?(Pe=()=>{$({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]=Pe):Pe=e[95];let Ce;e[96]!==c||e[97]!==i?(Ce=i(c?"settings.skills.catalog.installSkill.actions.installing":"settings.skills.catalog.installSkill.actions.install"),e[96]=c,e[97]=i,e[98]=Ce):Ce=e[98];let X;e[99]!==Ie||e[100]!==Pe||e[101]!==Ce?(X=s.jsx(ve,{size:"sm",disabled:Ie,onClick:Pe,children:Ce}),e[99]=Ie,e[100]=Pe,e[101]=Ce,e[102]=X):X=e[102];let ie;e[103]!==he||e[104]!==X?(ie=s.jsxs(Hs,{children:[he,X]}),e[103]=he,e[104]=X,e[105]=ie):ie=e[105];let Ne;e[106]!==ae||e[107]!==pe||e[108]!==ie?(Ne=s.jsxs(ms,{className:"max-w-md",children:[ae,pe,ie]}),e[106]=ae,e[107]=pe,e[108]=ie,e[109]=Ne):Ne=e[109];let oe;e[110]!==r||e[111]!==n||e[112]!==Ne?(oe=s.jsx(ps,{open:n,onOpenChange:r,children:Ne}),e[110]=r,e[111]=n,e[112]=Ne,e[113]=oe):oe=e[113];let ke;e[114]!==k||e[115]!==$?(ke=je=>{k&&($({source:k.source,subpath:k.subpath,scope:k.scope,targetSource:k.targetSource,skillDir:k.skillDir,conflictDecisions:je,directoryOverride:k.directoryOverride??null}),h(!1))},e[114]=k,e[115]=$,e[116]=ke):ke=e[116];let Te;e[117]!==y||e[118]!==x||e[119]!==ke?(Te=s.jsx(i3,{open:x,onOpenChange:h,conflicts:y,onConfirm:ke}),e[117]=y,e[118]=x,e[119]=ke,e[120]=Te):Te=e[120];let Be;return e[121]!==oe||e[122]!==Te?(Be=s.jsxs(s.Fragment,{children:[oe,Te]}),e[121]=oe,e[122]=Te,e[123]=Be):Be=e[123],Be};function l3(t){return t.installSkills}function c3(t){return t.isInstalling}function d3(t){return t.projects}function u3(t){return t.activeProjectId}function m3(t){return s.jsx(Mt,{value:t.id,children:t.label||t.path},t.id)}const p3=async()=>{try{const t=nr()?.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}},f3=({mode:t,onModeChange:e,showModeTabs:n=!0})=>{const{t:r}=ut(),{sources:a,itemsBySource:i,selectedSourceId:l,setSelectedSource:c,loadCatalog:d,loadSource:p,loadMoreClawdHub:m,isLoadingCatalog:u,isLoadingSource:f,isLoadingMore:b,loadedSourceIds:g,clawdhubHasMoreBySource:v,lastCatalogError:x}=La(er(_=>({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]=o.useState(""),[y,C]=o.useState(!1),[k,w]=o.useState(!1),[S,I]=o.useState(null),[T,P]=o.useState(!1),[A,N]=o.useState(!1);o.useEffect(()=>{d()},[d]),o.useEffect(()=>{l&&(g[l]||p(l))},[l,g,p]);const E=o.useMemo(()=>l?i[l]||[]:[],[i,l]),M=o.useMemo(()=>{const _=h.trim().toLowerCase();return _?E.filter(q=>{const L=q.skillName.toLowerCase(),Y=(q.description||"").toLowerCase(),Z=(q.frontmatterName||"").toLowerCase();return L.includes(_)||Y.includes(_)||Z.includes(_)}):E},[E,h]),O=o.useMemo(()=>a.find(_=>_.id===l)||null,[a,l]),V=!!(l&&l.startsWith("custom:")),B=O?.source==="clawdhub:registry"||O?.sourceType==="clawdhub",$=!!(l&&(v[l]??!0)),F=async()=>{if(!(!l||!V)){P(!0);try{const _=await p3(),L=(Array.isArray(_?.skillCatalogs)?_?.skillCatalogs:[]).filter(Y=>Y.id!==l);await Ss({skillCatalogs:L}),await d({refresh:!0}),N(!1)}finally{P(!1)}}};return s.jsx(ws,{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(Vr,{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(is,{value:l||"",onValueChange:_=>c(_),children:[s.jsx(os,{className:"w-fit",children:s.jsx(us,{placeholder:r("settings.skills.catalog.page.field.selectSourcePlaceholder"),children:O?.label})}),s.jsx(ls,{align:"start",children:a.map(_=>s.jsx(Mt,{value:_.id,children:_.label},_.id))})]}),s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>{l?p(l,{refresh:!0}):d({refresh:!0})},disabled:u||f,title:r("settings.skills.catalog.page.actions.refreshTitle"),children:s.jsx(D,{name:"refresh",className:ye("h-3.5 w-3.5",(u||f)&&"animate-spin")})}),V&&s.jsx(ve,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0 text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>N(!0),disabled:T,title:r("settings.skills.catalog.page.actions.removeCatalogTitle"),children:s.jsx(D,{name:"delete-bin",className:"h-3.5 w-3.5"})}),s.jsxs(ve,{size:"xs",className:"!font-normal gap-1",onClick:()=>C(!0),children:[s.jsx(D,{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(D,{name:"search",className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Bt,{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:M.length})})]})]})]}),x&&s.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-4 py-3",children:[s.jsx("div",{className:"typography-ui-label font-medium text-[var(--status-error)]",children:r("settings.skills.catalog.page.error.catalogTitle")}),s.jsx("div",{className:"typography-meta text-[var(--status-error)]/80 mt-1",children:x.message})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("section",{className:"px-2 pb-2 pt-0",children:M.length===0&&!f?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-body",children:r("settings.skills.catalog.page.empty.noSkillsTitle")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:r("settings.skills.catalog.page.empty.noSkillsDescription")})]}):f?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx(D,{name:"refresh",className:"mx-auto mb-3 h-5 w-5 animate-spin opacity-50"}),s.jsx("p",{className:"typography-meta",children:r("settings.skills.catalog.page.loading.skills")})]}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:M.map(_=>{const q=_.installed?.isInstalled,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(D,{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(D,{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(ve,{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&&M.length>0&&s.jsx("div",{className:"flex justify-center mt-2 px-2",children:s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{m()},disabled:b,children:r(b?"settings.skills.catalog.page.loading.more":"settings.skills.catalog.page.actions.loadMoreSkills")})})]}),s.jsx(Zk,{open:y,onOpenChange:C}),s.jsx(o3,{open:k,onOpenChange:w,item:S}),s.jsx(ps,{open:A,onOpenChange:_=>{T||N(_)},children:s.jsxs(ms,{className:"max-w-md",children:[s.jsxs(gs,{children:[s.jsx(fs,{children:r("settings.skills.catalog.page.removeDialog.title")}),s.jsx(Ns,{children:r("settings.skills.catalog.page.removeDialog.description")})]}),s.jsxs(Hs,{children:[s.jsx(ve,{size:"sm",variant:"ghost",onClick:()=>N(!1),disabled:T,children:r("settings.common.actions.cancel")}),s.jsx(ve,{size:"sm",variant:"destructive",onClick:()=>{F()},disabled:T,children:r("settings.skills.catalog.page.actions.removeCatalog")})]})]})})]})})},h3=()=>{const t=ot.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(f3,{mode:"external",onModeChange:w3,showModeTabs:!1}),t[0]=e):e=t[0],e},g3="SKILL.md",x3="h-[clamp(320px,58dvh,680px)] min-h-[260px] max-h-[calc(100dvh-220px)]",rl=(t,e)=>{const n=Ax({description:t}).trimEnd(),r=e.trimStart();return`---
|
|
176
|
-
${n}
|
|
177
|
-
---${r?`
|
|
178
|
-
|
|
179
|
-
${r}`:`
|
|
180
|
-
`}`},b3=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),hg=t=>{const e=t.match(/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)([\s\S]*)$/);if(!e)return{description:null,instructions:t};let n=null;try{const r=Dx(e[1]);if(b3(r)){const a=r.description;typeof a=="string"&&(n=a)}}catch{n=null}return{description:n,instructions:e[2].replace(/^\r?\n/,"")}},y3=(t,e)=>{const n=hg(t);return rl(e,n.instructions)},v3=()=>{const{t}=ut(),{currentTheme:e}=vr(),{selectedSkillName:n,getSkillByName:r,getSkillDetail:a,createSkill:i,updateSkill:l,skills:c,skillDraft:d,setSkillDraft:p,setSelectedSkill:m}=ma(er(je=>({selectedSkillName:je.selectedSkillName,getSkillByName:je.getSkillByName,getSkillDetail:je.getSkillDetail,createSkill:je.createSkill,updateSkill:je.updateSkill,skills:je.skills,skillDraft:je.skillDraft,setSkillDraft:je.setSkillDraft,setSelectedSkill:je.setSelectedSkill}))),u=n?r(n):null,f=!!(d&&d.name===n&&!u),b=!!(n&&!u&&!d),g=u?.path==="<built-in>";o.useEffect(()=>{b&&m(null)},[b,m]);const[v,x]=o.useState(""),[h,j]=o.useState("user"),[y,C]=o.useState("opencode"),[k,w]=o.useState(""),[S,I]=o.useState(""),[T,P]=o.useState(()=>rl("","")),[A,N]=o.useState("edit"),[E,M]=o.useState([]),[O,V]=o.useState([]),[B,$]=o.useState(!1),[F,_]=o.useState(!1),[q,L]=o.useState(""),[Y,Z]=o.useState(""),[ae,re]=o.useState(!1),[me,fe]=o.useState(""),[H,K]=o.useState(""),[Q,W]=o.useState(null),[de,be]=o.useState(!1),[we,te]=o.useState(""),[ge,ue]=o.useState(null),[xe,ne]=o.useState(!1),pe=f?v.trim()!==""||k.trim()!==""||S.trim()!==""||O.length>0:k!==q||S!==Y,J=Q?H!==we:me.trim()!=="",Se=o.useCallback(je=>{switch(je){case"project-opencode":return t("settings.skills.location.option.projectOpencode.label");case"user-claude":return t("settings.skills.location.option.userClaude.label");case"project-claude":return t("settings.skills.location.option.projectClaude.label");case"user-agents":return t("settings.skills.location.option.userAgents.label");case"project-agents":return t("settings.skills.location.option.projectAgents.label");default:return t("settings.skills.location.option.userOpencode.label")}},[t]),he=o.useCallback(je=>{switch(je){case"project-opencode":return t("settings.skills.location.option.projectOpencode.description");case"user-claude":return t("settings.skills.location.option.userClaude.description");case"project-claude":return t("settings.skills.location.option.projectClaude.description");case"user-agents":return t("settings.skills.location.option.userAgents.description");case"project-agents":return t("settings.skills.location.option.projectAgents.description");default:return t("settings.skills.location.option.userOpencode.description")}},[t]);o.useEffect(()=>{(async()=>{if(f&&d){const ee=d.description||"",R=d.instructions||"";x(d.name||""),j(d.scope||"user"),C(d.source==="agents"?"agents":"opencode"),w(ee),I(R),P(rl(ee,R)),L(""),Z(""),M([]),V(d.pendingFiles||[])}else if(n&&u){_(!0);try{const ee=await a(n);if(ee){const R=ee.sources.md,U=R.description||"",le=R.instructions||"";w(U),I(le),P(rl(U,le)),L(U),Z(le),M(R.supportingFiles||[])}}catch(ee){console.error("Failed to load skill details:",ee)}finally{_(!1)}}})()},[u,f,n,c,d,a]);const Ie=o.useMemo(()=>{const je=[fo(e)],ee=xl(g3);return ee&&je.push(ee),je.push($n.lineWrapping),je},[e]),Pe=o.useMemo(()=>{const je=me.trim()||"supporting-file.md",ee=[fo(e)],R=xl(je);return R&&ee.push(R),ee.push($n.lineWrapping),ee},[e,me]),Ce=o.useCallback(je=>{w(je),P(ee=>y3(ee,je))},[]),X=o.useCallback(je=>{P(je);const ee=hg(je);w(ee.description??""),I(ee.instructions)},[]),ie=async()=>{const je=f?v.trim().replace(/\s+/g,"-").toLowerCase():n?.trim();if(!je){G.error(t("settings.skills.page.toast.skillNameRequired"));return}if(!/^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/.test(je)||je.length>64){G.error(t("settings.skills.page.toast.invalidSkillName"));return}if(!k.trim()){G.error(t("settings.skills.page.toast.descriptionRequired"));return}if(f&&c.some(ee=>ee.name===je)){G.error(t("settings.skills.page.toast.skillExists"));return}$(!0);try{const ee={name:je,description:k.trim(),instructions:S.trim()||void 0,scope:f?h:void 0,source:f?y:void 0,targetPath:f?void 0:u?.path,supportingFiles:f&&O.length>0?O:void 0};let R;f?(R=await i(ee),R&&(p(null),V([]),m(je))):(R=await l(je,ee),R&&(L(k.trim()),Z(S.trim()))),R?G.success(t(f?"settings.skills.page.toast.skillCreated":"settings.skills.page.toast.skillUpdated")):G.error(t(f?"settings.skills.page.toast.createSkillFailed":"settings.skills.page.toast.updateSkillFailed"))}catch(ee){console.error("Error saving skill:",ee),G.error(t("settings.skills.page.toast.saveUnexpectedError"))}finally{$(!1)}},Ne=()=>{W(null),fe(""),K(""),te(""),re(!0)},oe=async je=>{if(W(je),fe(je),f){const R=O.find(U=>U.path===je)?.content||"";K(R),te(R),re(!0);return}if(n){be(!0),re(!0);try{const{readSupportingFile:ee}=ma.getState(),R=await ee(n,je);K(R||""),te(R||"")}catch{G.error(t("settings.skills.page.toast.loadFileContentFailed")),K(""),te("")}finally{be(!1)}}},ke=async()=>{if(!me.trim()){G.error(t("settings.skills.page.toast.fileNameRequired"));return}const je=me.trim(),ee=Q!==null;if(f){if(ee)V(le=>le.map(Me=>Me.path===Q?{path:je,content:H}:Me)),G.success(t("settings.skills.page.toast.fileUpdated",{path:je}));else{if(O.some(le=>le.path===je)){G.error(t("settings.skills.page.toast.fileExists"));return}V(le=>[...le,{path:je,content:H}]),G.success(t("settings.skills.page.toast.fileAdded",{path:je}))}re(!1),W(null);return}if(!n){G.error(t("settings.skills.page.toast.noSkillSelected"));return}const{writeSupportingFile:R}=ma.getState();if(await R(n,je,H)){G.success(ee?t("settings.skills.page.toast.fileUpdated",{path:je}):t("settings.skills.page.toast.fileCreated",{path:je})),re(!1),W(null);const le=await a(n);le&&M(le.sources.md.supportingFiles||[])}else G.error(t(ee?"settings.skills.page.toast.updateFileFailed":"settings.skills.page.toast.createFileFailed"))},Te=je=>{if(f){V(ee=>ee.filter(R=>R.path!==je)),G.success(t("settings.skills.page.toast.fileRemoved",{path:je}));return}n&&ue(je)},Be=async()=>{if(!ge||!n)return;ne(!0);const{deleteSupportingFile:je}=ma.getState();if(await je(n,ge)){G.success(t("settings.skills.page.toast.fileDeleted",{path:ge}));const R=await a(n);R&&M(R.sources.md.supportingFiles||[]),ue(null)}else G.error(t("settings.skills.page.toast.deleteFileFailed"));ne(!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(D,{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")})]})}):F?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(ws,{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(Xi(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(Bt,{value:v,onChange:je=>x(je.target.value.toLowerCase().replace(/\s+/g,"-")),placeholder:t("settings.skills.page.field.skillNamePlaceholder"),className:"h-7 w-40 px-2"}),s.jsxs(is,{value:Xi(h,y),onValueChange:je=>{const ee=fg(je);j(ee.scope),C(ee.source==="agents"?"agents":"opencode")},children:[s.jsxs(os,{className:"w-fit gap-1.5",children:[h==="user"?s.jsx(D,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(D,{name:"folder",className:"h-3.5 w-3.5"}),y==="agents"?s.jsx(D,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:Se(Xi(h,y))})]}),s.jsx(ls,{align:"start",children:ru.map(je=>s.jsx(Mt,{value:je.value,children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[je.scope==="user"?s.jsx(D,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(D,{name:"folder",className:"h-3.5 w-3.5"}),je.source==="agents"?s.jsx(D,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:Se(je.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-6",children:he(je.value)})]})},je.value))})]})]})]}),s.jsxs("div",{className:"py-1.5",children:[s.jsxs("span",{className:"typography-ui-label text-foreground",children:[t("settings.common.field.description")," ",s.jsx("span",{className:"text-[var(--status-error)]",children:"*"})]}),s.jsx("span",{className:"typography-meta text-muted-foreground ml-2",children:t("settings.skills.page.field.descriptionHint")}),s.jsx("div",{className:"mt-1.5",children:s.jsx(jn,{value:k,onChange:je=>Ce(je.target.value),placeholder:t("settings.skills.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] max-h-32 bg-transparent",disabled:g})})]})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 px-1 flex items-center justify-between gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.skills.page.section.instructions")}),s.jsx(Il,{currentMode:A==="preview"?"preview":"edit",onToggle:()=>N(je=>je==="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",x3),children:A==="preview"?s.jsx(ws,{outerClassName:"h-full",className:"h-full",children:s.jsx("div",{className:"min-h-full px-4 py-3",children:s.jsx(ha,{content:T,className:"typography-markdown-body",stripFrontmatter:!0})})}):s.jsx(po,{value:T,onChange:X,readOnly:g,extensions:Ie,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(ve,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:Ne,disabled:g,children:[s.jsx(D,{name:"add",className:"h-3.5 w-3.5"})," ",t("settings.skills.page.actions.addFile")]})]}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:(()=>{const je=f?O:E;return je.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground py-1.5",children:t("settings.skills.page.supportingFiles.empty")}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:je.map(ee=>s.jsxs("div",{className:"flex items-center gap-2 py-1.5 cursor-pointer group",onClick:()=>oe(ee.path),children:[s.jsx(D,{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")}),!g&&s.jsx(ve,{size:"sm",variant:"ghost",className:"h-5 w-5 px-0 flex-shrink-0 text-muted-foreground hover:text-[var(--status-error)] opacity-0 group-hover:opacity-100 transition-opacity",onClick:R=>{R.stopPropagation(),Te(ee.path)},children:s.jsx(D,{name:"delete-bin",className:"h-3 w-3"})})]},ee.path))})})()})]}),s.jsx("div",{className:"px-2 py-1",children:s.jsx(ve,{onClick:ie,disabled:g||B||!pe,size:"xs",className:"!font-normal",children:t(B?"settings.common.actions.saving":f?"settings.skills.page.actions.createSkill":"settings.common.actions.saveChanges")})})]}),s.jsx(ps,{open:ge!==null,onOpenChange:je=>{!je&&!xe&&ue(null)},children:s.jsxs(ms,{className:"max-w-md",children:[s.jsxs(gs,{children:[s.jsx(fs,{children:t("settings.skills.page.deleteFileDialog.title")}),s.jsx(Ns,{children:t("settings.skills.page.deleteFileDialog.description",{path:ge??""})})]}),s.jsxs(Hs,{children:[s.jsx(ve,{size:"sm",variant:"ghost",onClick:()=>ue(null),disabled:xe,children:t("settings.common.actions.cancel")}),s.jsx(ve,{size:"sm",variant:"destructive",onClick:Be,disabled:xe,children:t("settings.common.actions.delete")})]})]})}),s.jsx(ps,{open:ae,onOpenChange:je=>{re(je),je||W(null)},children:s.jsxs(ms,{className:"max-w-3xl max-h-[85vh] flex flex-col",children:[s.jsxs(gs,{className:"flex-shrink-0",children:[s.jsx(fs,{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(Bt,{value:me,onChange:je=>fe(je.target.value),placeholder:t("settings.skills.page.fileDialog.field.filePathPlaceholder"),className:"text-foreground placeholder:text-muted-foreground focus-visible:ring-[var(--primary-base)]",disabled: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(po,{value:H,onChange:K,extensions:Pe,className:"h-full",enableSearch:!0})})]})]}),s.jsxs(Hs,{className:"mt-4",children:[s.jsx(ve,{size:"sm",variant:"ghost",onClick:()=>{re(!1),W(null)},children:t("settings.common.actions.cancel")}),s.jsx(ve,{size:"sm",onClick:ke,disabled:de||!J,children:t(Q?"settings.common.actions.saveChanges":"settings.skills.page.actions.createFile")})]})]})})]})},jp=t=>{const e=ot.c(2),{view:n}=t,r=n===void 0?"installed":n;let a;return e[0]!==r?(a=r==="catalog"?s.jsx(h3,{}):s.jsx(v3,{}),e[0]=r,e[1]=a):a=e[1],a};function w3(){}const gg=t=>{const e=ot.c(26),{header:n,footer:r,children:a,className:i,variant:l}=t,c=l===void 0?"sidebar":l,d=mn(),p=o.useRef(null),[m,u]=o.useState(!1),[f,b]=o.useState(!1),g=c==="background"||d?"bg-background":"bg-sidebar",v=g==="bg-background"?"var(--surface-background)":"var(--surface-muted)";let x;e[0]===Symbol.for("react.memo_cache_sentinel")?(x=()=>{const N=p.current;if(!N){u(!1),b(!1);return}if(!(N.scrollHeight>N.clientHeight+1)){u(!1),b(!1);return}u(N.scrollTop>1),b(N.scrollTop+N.clientHeight<N.scrollHeight-1)},e[0]=x):x=e[0];const h=x;let j;e[1]===Symbol.for("react.memo_cache_sentinel")?(j=()=>{h()},e[1]=j):j=e[1];let y;e[2]!==a?(y=[a,h],e[2]=a,e[3]=y):y=e[3],o.useEffect(j,y);let C,k;e[4]===Symbol.for("react.memo_cache_sentinel")?(C=()=>{const N=p.current;if(!N)return;const E=()=>h();return N.addEventListener("scroll",E,{passive:!0}),()=>N.removeEventListener("scroll",E)},k=[h],e[4]=C,e[5]=k):(C=e[4],k=e[5]),o.useEffect(C,k);let w;e[6]!==g||e[7]!==i?(w=ye("flex h-full flex-col",g,i),e[6]=g,e[7]=i,e[8]=w):w=e[8];let S;e[9]!==a?(S=s.jsx(ws,{ref:p,outerClassName:"flex-1 min-h-0",className:"space-y-0.5 px-3 py-2 overflow-x-hidden",children:a}),e[9]=a,e[10]=S):S=e[10];let I;e[11]!==v||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, ${v} 0%, transparent 100%)`}}),e[11]=v,e[12]=m,e[13]=I):I=e[13];let T;e[14]!==v||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, ${v} 0%, transparent 100%)`}}),e[14]=v,e[15]=f,e[16]=T):T=e[16];let P;e[17]!==T||e[18]!==S||e[19]!==I?(P=s.jsxs("div",{className:"relative flex flex-1 min-h-0 flex-col",children:[S,I,T]}),e[17]=T,e[18]=S,e[19]=I,e[20]=P):P=e[20];let A;return e[21]!==r||e[22]!==n||e[23]!==P||e[24]!==w?(A=s.jsxs("div",{className:w,children:[n,P,r]}),e[21]=r,e[22]=n,e[23]=P,e[24]=w,e[25]=A):A=e[25],A},xg=t=>{const e=ot.c(23),{title:n,metadata:r,selected:a,onSelect:i,icon:l,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 g;e[5]!==l||e[6]!==b?(g=s.jsxs("div",{className:"flex items-center gap-1.5",children:[l,b]}),e[5]=l,e[6]=b,e[7]=g):g=e[7];let v;e[8]!==r?(v=r&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:r}),e[8]=r,e[9]=v):v=e[9];let x;e[10]!==i||e[11]!==g||e[12]!==v?(x=s.jsxs("button",{onClick:i,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[g,v]}),e[10]=i,e[11]=g,e[12]=v,e[13]=x):x=e[13];let h;e[14]!==c||e[15]!==m?(h=m&&s.jsxs(As,{children:[s.jsx(Is,{asChild:!0,children:s.jsx(ve,{size:"icon",variant:"ghost",className:"h-6 w-6 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(D,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Ps,{align:"end",className:"w-fit min-w-20",children:c.map(j3)})]}),e[14]=c,e[15]=m,e[16]=h):h=e[16];let j;e[17]!==x||e[18]!==h?(j=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[x,h]}),e[17]=x,e[18]=h,e[19]=j):j=e[19];let y;return e[20]!==f||e[21]!==j?(y=s.jsx("div",{className:f,children:j}),e[20]=f,e[21]=j,e[22]=y):y=e[22],y};function j3(t){const e=t.icon;return s.jsxs(Ot,{onClick:n=>{n.stopPropagation(),t.onClick()},className:ye(t.destructive&&"text-destructive focus:text-destructive"),children:[e&&s.jsx(D,{name:e,className:"h-4 w-4 mr-px"}),t.label]},t.label)}const N3=t=>{const e=ot.c(41),{onItemSelect:n}=t,{t:r}=ut(),a=Cs(S3),i=Re(k3),l=Re(C3),{currentTheme:c}=vr();let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=new Set,e[0]=d):d=e[0];const[p,m]=o.useState(d);let u;e[1]===Symbol.for("react.memo_cache_sentinel")?(u=mn(),e[1]=u):u=e[1];const f=u,b=I3;let g,v;e[2]!==a||e[3]!==i||e[4]!==l?(g=()=>{if(a.length===0){i!==null&&l(null);return}i&&a.some(P=>P.id===i)||l(a[0].id)},v=[a,i,l],e[2]=a,e[3]=i,e[4]=l,e[5]=g,e[6]=v):(g=e[5],v=e[6]),o.useEffect(g,v);let x;e[7]===Symbol.for("react.memo_cache_sentinel")?(x=ye("border-b px-3","pt-4 pb-3"),e[7]=x):x=e[7];let h;e[8]!==r?(h=r("settings.page.projects.title"),e[8]=r,e[9]=h):h=e[9];let j;e[10]!==h?(j=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:h}),e[10]=h,e[11]=j):j=e[11];let y;e[12]!==a.length||e[13]!==r?(y=r("settings.projects.sidebar.total",{count:a.length}),e[12]=a.length,e[13]=r,e[14]=y):y=e[14];let C;e[15]!==y?(C=s.jsx("span",{className:"typography-meta text-muted-foreground",children:y}),e[15]=y,e[16]=C):C=e[16];let k;e[17]!==r?(k=!f&&s.jsx(ve,{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(D,{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 S;e[22]!==w||e[23]!==j?(S=s.jsxs("div",{className:x,children:[j,w]}),e[22]=w,e[23]=j,e[24]=S):S=e[24];let I;if(e[25]!==p||e[26]!==c||e[27]!==n||e[28]!==a||e[29]!==i||e[30]!==l){let P;e[32]!==p||e[33]!==c||e[34]!==n||e[35]!==i||e[36]!==l?(P=A=>{const N=A.id===i,E=A.icon?zl[A.icon]:null,M=`${A.id}:${A.iconImage?.updatedAt??0}`,O=p.has(M)?null:yo(A,{themeVariant:c.metadata.variant,iconColor:c.colors.surface.foreground}),V=A.color?vo[A.color]??null:null,B=O?s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center overflow-hidden rounded-[2px]",style:A.iconBackground?{backgroundColor:A.iconBackground}:void 0,children:s.jsx("img",{src:O,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>{m($=>{if($.has(M))return $;const F=new Set($);return F.add(M),F})}})}):E?s.jsx(D,{name:E,className:ye("h-4 w-4",N?"text-foreground":"text-muted-foreground/70"),style:V?{color:V}:void 0}):s.jsx(D,{name:"folder",className:ye("h-4 w-4",N?"text-foreground":"text-muted-foreground/70"),style:V?{color:V}:void 0});return s.jsx(xg,{title:A.label||A.path,icon:B,selected:N,onSelect:()=>{l(A.id),n?.()}},A.id)},e[32]=p,e[33]=c,e[34]=n,e[35]=i,e[36]=l,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]=l,e[31]=I}else I=e[31];let T;return e[38]!==S||e[39]!==I?(T=s.jsx(gg,{variant:"background",header:S,children:I}),e[38]=S,e[39]=I,e[40]=T):T=e[40],T};function S3(t){return t.projects}function k3(t){return t.settingsProjectsSelectedId}function C3(t){return t.setSettingsProjectsSelectedId}function I3(){Ar.requestDirectoryDialog()}const P3=({projectRef:t=null})=>{const{t:e}=ut(),{isMobile:n,isTablet:r}=an(),a=n||r,i=Cs(E=>E.getActiveProject()),l=t?.path??i?.path??null,c=$t(E=>E.getWorktreeMetadata),d=Vl(),p=Ks(E=>E.homeDirectory),[m,u]=o.useState([]),[f,b]=o.useState(!1),[g,v]=o.useState(null),[x,h]=o.useState([]),[j,y]=o.useState(!1),C=o.useMemo(()=>t?.id&&t?.path?{id:t.id,path:t.path}:!i?.id||!l?null:{id:i.id,path:l},[i?.id,l,t?.id,t?.path]),k=o.useCallback(async()=>{if(!(!C||g===!1))try{const E=await Zc(C);h(E)}catch{}},[C,g]);o.useEffect(()=>{if(!l)return;let E=!1;return v(null),(async()=>{try{const M=await oh(l);if(E)return;v(M)}catch{}})(),()=>{E=!0}},[l]),o.useEffect(()=>{if(!C){h([]),y(!1);return}if(g===!1){h([]),y(!1);return}let E=!1;return y(!0),h([]),(async()=>{try{const M=await Zc(C);if(E)return;h(M)}catch{}finally{E||y(!1)}})(),()=>{E=!0}},[C,g]),o.useEffect(()=>{if(!C)return;let E=!1;return b(!0),(async()=>{try{const M=await Ud(C);E||u(M.length>0?M:[""])}catch{E||u([""])}finally{E||b(!1)}})(),()=>{E=!0}},[C]);const w=o.useCallback((E,M)=>{u(O=>{const V=[...O];return V[E]=M,V})},[]),S=o.useCallback(()=>{u(E=>[...E,""])},[]),I=o.useCallback(async E=>{if(!C)return;const M=E.filter(O=>O.trim().length>0);await lh(C,M)},[C]),T=o.useCallback(E=>{u(M=>{const O=M.filter((V,B)=>B!==E);return I(O),O.length>0?O:[""]})},[I]),P=o.useCallback(()=>{I(m)},[I,m]),A=o.useCallback(E=>{const M=L=>L.replace(/\\/g,"/").replace(/\/+$/,""),O=M(E.path),V=d.filter(L=>{const Y=c(L.id);if(Y?.path&&M(Y.path)===O)return!0;const Z=L.directory;return!!(Z&&M(Z)===O)}),B=new Set(V.map(L=>L.id)),$=L=>{const Y=d.filter(ae=>{const re=ae.parentID;return re&&L.has(re)});if(Y.length===0)return[];const Z=new Set(Y.map(ae=>ae.id));return[...Y,...$(Z)]},F=$(B),_=new Set,q=[...V,...F].filter(L=>_.has(L.id)?!1:(_.add(L.id),!0));Ar.requestDelete({sessions:q,mode:"worktree",worktree:E})},[d,c]),N=o.useMemo(()=>d.map(E=>E.id).join(","),[d]);return o.useEffect(()=>{g&&l&&k()},[N,g,l,k]),l?g===!1?s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.worktrees.state.gitOnly")}):s.jsxs("div",{className:"max-w-[44rem] space-y-5",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-normal text-foreground",children:e("settings.openchamber.worktrees.setup.title")}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(D,{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((E,M)=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(Bt,{value:E,onChange:O=>w(M,O.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(M)},className:"flex-shrink-0 flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("settings.openchamber.worktrees.setup.removeCommandAria"),children:s.jsx(D,{name:"close",className:"h-4 w-4"})})]},M)),s.jsxs(ve,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:S,children:[s.jsx(D,{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(D,{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")}):x.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground/70 px-1",children:e("settings.openchamber.worktrees.list.empty")}):s.jsx("div",{className:"space-y-1 px-1 max-w-[32.5rem]",children:x.map(E=>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:E.label||E.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:ao(E.path,p)})]}),s.jsx("button",{type:"button",onClick:()=>A(E),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:E.branch||E.label||E.path}),children:s.jsx(D,{name:"delete-bin",className:"h-4 w-4"})})]},E.path))})]})]}):s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.worktrees.state.selectProject")})},A3=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`action_${Date.now()}_${Math.random().toString(36).slice(2,7)}`,D3=()=>({id:A3(),name:"",command:"",icon:"play"}),T3=({projectRef:t})=>{const{t:e}=ut(),n=o.useMemo(()=>Cn(),[]),r=Xs(S=>S.instances),a=Xs(S=>S.load),[i,l]=o.useState([]),[c,d]=o.useState(!1),[p,m]=o.useState(!1),[u,f]=o.useState(null),[b,g]=o.useState({});o.useEffect(()=>{n&&a().catch(()=>{})},[n,a]),o.useEffect(()=>{let S=!1;return d(!0),(async()=>{try{const I=await Xc(t);if(S)return;l(I.actions),f(JSON.stringify({actions:I.actions}))}catch{if(S)return;l([]),f(JSON.stringify({actions:[]}))}finally{S||d(!1)}})(),()=>{S=!0}},[t]);const v=o.useMemo(()=>n?Mh(r):[],[r,n]),x=o.useMemo(()=>i.some(I=>I.name.trim().length===0||I.command.trim().length===0)?e("settings.projects.actions.validation.fillNameAndCommand"):null,[i,e]),h=o.useMemo(()=>u===null?!1:u!==JSON.stringify({actions:i}),[i,u]),j=o.useCallback(()=>{const S=D3();l(I=>[...I,S]),g(I=>({...I,[S.id]:!0}))},[]),y=o.useCallback(S=>{l(I=>I.filter(T=>T.id!==S)),g(I=>{const T={...I};return delete T[S],T})},[]),C=o.useCallback((S,I)=>{l(T=>T.map(P=>P.id===S?I(P):P))},[]),k=o.useCallback(async()=>{if(x){G.error(x);return}m(!0);try{if(!await Bb(t,{actions:i,primaryActionId:null})){G.error(e("settings.projects.actions.toast.saveFailed"));return}f(JSON.stringify({actions:i})),typeof window<"u"&&window.dispatchEvent(new CustomEvent(id,{detail:{projectId:t.id}})),G.success(e("settings.projects.actions.toast.saved"))}catch{G.error(e("settings.projects.actions.toast.saveFailed"))}finally{m(!1)}},[i,t,e,x]),w=!p&&!c&&h&&!x;return s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 flex items-start justify-between gap-2",children:[s.jsxs("div",{children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:e("settings.projects.actions.title")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.description")})]}),s.jsxs(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:j,children:[s.jsx(D,{name:"add",className:"h-3.5 w-3.5"}),e("settings.projects.actions.actions.add")]})]}),s.jsxs("section",{className:"pb-2 pt-0 space-y-2",children:[c?s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.state.loading")}):i.length===0?s.jsx("div",{className:"py-2",children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.state.empty")})}):s.jsx("div",{className:"space-y-0 max-w-[30rem]",children:i.map(S=>{const I=S.icon||"play",T=Xo[I]||"play",P=b[S.id]??!1,A=S.name.trim()||e("settings.projects.actions.state.untitled");return s.jsxs(br,{open:P,onOpenChange:N=>{g(E=>({...E,[S.id]:N}))},className:ye("py-1.5"),children:[s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs(Tr,{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(D,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(D,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"}),s.jsx(D,{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:A})})})]}),s.jsx(ve,{type:"button",variant:"ghost",size:"xs",className:"!font-normal h-7 w-7 px-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>y(S.id),children:s.jsx(D,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),s.jsx(yr,{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(D,{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:Dh.map(N=>{const E=N.Icon,M=(S.icon||"play")===N.key;return s.jsx("button",{type:"button",onClick:()=>C(S.id,O=>({...O,icon:N.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)]",M&&"border-[var(--primary-base)] bg-[var(--primary-base)]/10 text-[var(--primary-base)]"),"aria-label":e("settings.projects.actions.field.iconAria",{icon:N.label}),children:s.jsx(D,{name:E,className:"h-4 w-4"})},N.key)})})})]}),s.jsx(Bt,{value:S.name,onChange:N=>C(S.id,E=>({...E,name:N.target.value})),placeholder:e("settings.projects.actions.field.actionNamePlaceholder"),className:"h-7 max-w-[14rem]"})]}),s.jsxs("div",{className:"py-1",children:[s.jsx("p",{className:"typography-meta mb-0.5 text-muted-foreground",children:e("settings.projects.actions.field.command")}),s.jsx(jn,{value:S.command,onChange:N=>C(S.id,E=>({...E,command:N.target.value})),placeholder:e("settings.projects.actions.field.commandPlaceholder"),className:"min-h-[88px] max-w-[30rem] font-mono text-xs"})]}),s.jsxs("div",{className:"py-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:e("settings.projects.actions.field.autoOpenUrl")}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2",role:"button",tabIndex:0,"aria-pressed":S.autoOpenUrl===!0,onClick:()=>C(S.id,N=>({...N,...N.autoOpenUrl===!0?{autoOpenUrl:void 0}:{autoOpenUrl:!0}})),onKeyDown:N=>{(N.key===" "||N.key==="Enter")&&(N.preventDefault(),C(S.id,E=>({...E,...E.autoOpenUrl===!0?{autoOpenUrl:void 0}:{autoOpenUrl:!0}})))},children:[s.jsx(xs,{checked:S.autoOpenUrl===!0,onChange:N=>C(S.id,E=>({...E,...N?{autoOpenUrl:!0}:{autoOpenUrl:void 0}})),ariaLabel:e("settings.projects.actions.field.autoOpenUrlForAria",{title:A})}),s.jsx("span",{className:"typography-ui-label font-normal text-foreground/80",children:e("settings.projects.actions.field.autoOpenUrlDescription")})]})]}),S.autoOpenUrl===!0?s.jsxs("div",{className:"mt-1",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Bt,{value:S.openUrl||"",onChange:N=>C(S.id,E=>({...E,openUrl:N.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(D,{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")}),v.length>0?s.jsxs(is,{value:S.desktopOpenSshForward&&v.some(N=>N.id===S.desktopOpenSshForward)?S.desktopOpenSshForward:"__none__",onValueChange:N=>{C(S.id,E=>({...E,...N==="__none__"?{desktopOpenSshForward:void 0}:{desktopOpenSshForward:N}}))},children:[s.jsx(os,{className:"h-7 w-full max-w-[30rem]",children:s.jsx(us,{placeholder:e("settings.projects.actions.field.useOutputManualUrl")})}),s.jsxs(ls,{children:[s.jsx(Mt,{value:"__none__",children:e("settings.projects.actions.field.useOutputManualUrl")}),v.map(N=>s.jsx(Mt,{value:N.id,children:N.label},N.id))]})]}):s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.state.noDesktopSshForwards")})]}):null]}):null]})]})})]},S.id)})}),s.jsxs("div",{className:"pt-3",children:[x?s.jsx("p",{className:"typography-meta mb-2 text-[var(--status-warning)]",children:x}):null,s.jsx(ve,{type:"button",size:"xs",className:"!font-normal",onClick:k,disabled:!w,children:e(p?"settings.common.actions.saving":"settings.projects.actions.actions.save")})]})]})]})},M3=()=>{const t=ot.c(201),{t:e}=ut(),n=Cs(E3),r=Cs(R3),a=Cs(F3),i=Cs(O3),l=Cs(L3),c=Re($3),d=Re(_3),{currentTheme:p}=vr();let m;e:{if(!c){m=null;break e}let jt;t[0]!==n||t[1]!==c?(jt=n.find(Zt=>Zt.id===c)??null,t[0]=n,t[1]=c,t[2]=jt):jt=t[2],m=jt}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(jt=>jt.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]),o.useEffect(f,b);const[g,v]=o.useState(""),[x,h]=o.useState(null),[j,y]=o.useState(null),[C,k]=o.useState(null),[w,S]=o.useState(!1),[I,T]=o.useState(!1),[P,A]=o.useState(!1),[N,E]=o.useState(!1),[M,O]=o.useState(null),[V,B]=o.useState(null),[$,F]=o.useState(!1),_=o.useRef(null);let q;t[8]===Symbol.for("react.memo_cache_sentinel")?(q=()=>{O(null),B(B3)},t[8]=q):q=t[8];const L=q;let Y;e:{if(!u){Y=null;break e}let jt;t[9]!==u.id||t[10]!==u.path?(jt={id:u.id,path:u.path},t[9]=u.id,t[10]=u.path,t[11]=jt):jt=t[11],Y=jt}const Z=Y;let ae,re;t[12]!==u?(ae=()=>{if(!u){v(""),h(null),y(null),k(null);return}v(u.label??""),h(u.icon??null),y(u.color??null),k(u.iconBackground??null),E(!1),L(),F(!1)},re=[u,L],t[12]=u,t[13]=ae,t[14]=re):(ae=t[13],re=t[14]),o.useEffect(ae,re);let me,fe;t[15]===Symbol.for("react.memo_cache_sentinel")?(me=()=>()=>{L()},fe=[L],t[15]=me,t[16]=fe):(me=t[15],fe=t[16]),o.useEffect(me,fe);let H;t[17]!==j||t[18]!==x||t[19]!==C||t[20]!==g||t[21]!==N||t[22]!==M||t[23]!==u?(H=!!u&&(g.trim()!==(u?.label??"").trim()||x!==(u?.icon??null)||j!==(u?.color??null)||C!==(u?.iconBackground??null)||N||!!M),t[17]=j,t[18]=x,t[19]=C,t[20]=g,t[21]=N,t[22]=M,t[23]=u,t[24]=H):H=t[24];const K=H;let Q;t[25]!==j||t[26]!==x||t[27]!==C||t[28]!==g||t[29]!==N||t[30]!==M||t[31]!==i||t[32]!==u||t[33]!==e||t[34]!==r||t[35]!==a?(Q=async()=>{if(!u)return;if(M){S(!0);const Zt=await a(u.id,M);if(S(!1),!Zt.ok){G.error(Zt.error||e("settings.projects.page.toast.uploadIconFailed"));return}G.success(e("settings.projects.page.toast.iconUpdated")),L(),E(!1)}const jt=N&&!!u.iconImage;if(jt){T(!0);const Zt=await i(u.id);if(T(!1),!Zt.ok){G.error(Zt.error||e("settings.projects.page.toast.removeIconFailed"));return}G.success(e("settings.projects.page.toast.iconRemoved")),E(!1),k(null)}r(u.id,{label:g.trim(),icon:x,color:j,iconBackground:jt?null:C})},t[25]=j,t[26]=x,t[27]=C,t[28]=g,t[29]=N,t[30]=M,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?vo[j]??null:null,be=!!u?.iconImage,we=!!(M&&V),te=u?.iconImage?.source==="custom",ge=be&&!N||we,ue=ge;let xe;t[37]!==p||t[38]!==we||t[39]!==be||t[40]!==N||t[41]!==V||t[42]!==$||t[43]!==u?(xe=$?null:we?V:u&&be&&!N?yo(u,{themeVariant:p.metadata.variant,iconColor:p.colors.surface.foreground}):null,t[37]=p,t[38]=we,t[39]=be,t[40]=N,t[41]=V,t[42]=$,t[43]=u,t[44]=xe):xe=t[44];const ne=xe;let pe;t[45]!==w||t[46]!==u?(pe=jt=>{!u||!jt||w||(E(!1),F(!1),O(jt),B(Zt=>(Zt&&URL.revokeObjectURL(Zt),URL.createObjectURL(jt))))},t[45]=w,t[46]=u,t[47]=pe):pe=t[47];const J=pe;let Se;t[48]!==we||t[49]!==ue||t[50]!==be||t[51]!==I||t[52]!==u?(Se=()=>{!u||!ue||I||(we&&L(),E(!!be),F(!1))},t[48]=we,t[49]=ue,t[50]=be,t[51]=I,t[52]=u,t[53]=Se):Se=t[53];const he=Se;let Ie;t[54]!==l||t[55]!==P||t[56]!==u||t[57]!==e?(Ie=async()=>{!u||P||(L(),E(!1),F(!1),A(!0),l(u.id).then(jt=>{if(!jt.ok){G.error(jt.error||e("settings.projects.page.toast.discoverIconFailed"));return}if(jt.skipped){G.success(e("settings.projects.page.toast.customIconAlreadySet"));return}G.success(e("settings.projects.page.toast.iconDiscovered"))}).finally(()=>{A(!1)}))},t[54]=l,t[55]=P,t[56]=u,t[57]=e,t[58]=Ie):Ie=t[58];const Pe=Ie;if(!u){let jt;t[59]!==e?(jt=e("settings.projects.page.empty.noProjects"),t[59]=e,t[60]=jt):jt=t[60];let Zt;return t[61]!==jt?(Zt=s.jsx(ws,{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:jt})})}),t[61]=jt,t[62]=Zt):Zt=t[62],Zt}let Ce;t[63]!==u.label||t[64]!==e?(Ce=u.label??e("settings.projects.page.title.default"),t[63]=u.label,t[64]=e,t[65]=Ce):Ce=t[65];let X;t[66]!==Ce?(X=s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:Ce}),t[66]=Ce,t[67]=X):X=t[67];let ie;t[68]!==u.path?(ie=s.jsx("p",{className:"typography-meta text-muted-foreground truncate",title:u.path,children:u.path}),t[68]=u.path,t[69]=ie):ie=t[69];let Ne;t[70]!==X||t[71]!==ie?(Ne=s.jsx("div",{className:"mb-4 flex items-center justify-between gap-4",children:s.jsxs("div",{className:"min-w-0",children:[X,ie]})}),t[70]=X,t[71]=ie,t[72]=Ne):Ne=t[72];let oe;t[73]!==e?(oe=e("settings.projects.page.field.projectName"),t[73]=e,t[74]=oe):oe=t[74];let ke;t[75]!==oe?(ke=s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:oe})}),t[75]=oe,t[76]=ke):ke=t[76];let Te;t[77]===Symbol.for("react.memo_cache_sentinel")?(Te=jt=>v(jt.target.value),t[77]=Te):Te=t[77];let Be;t[78]!==e?(Be=e("settings.projects.page.field.projectNamePlaceholder"),t[78]=e,t[79]=Be):Be=t[79];let je;t[80]!==g||t[81]!==Be?(je=s.jsx("div",{className:"mt-1.5 flex min-w-0 items-center gap-2",children:s.jsx(Bt,{value:g,onChange:Te,placeholder:Be,className:"h-7 min-w-0 w-full sm:max-w-[19rem]"})}),t[80]=g,t[81]=Be,t[82]=je):je=t[82];let ee;t[83]!==ke||t[84]!==je?(ee=s.jsxs("div",{className:"py-1.5",children:[ke,je]}),t[83]=ke,t[84]=je,t[85]=ee):ee=t[85];let R;t[86]!==e?(R=e("settings.projects.page.field.accentColor"),t[86]=e,t[87]=R):R=t[87];let U;t[88]!==R?(U=s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:R})}),t[88]=R,t[89]=U):U=t[89];let le;t[90]===Symbol.for("react.memo_cache_sentinel")?(le=()=>y(null),t[90]=le):le=t[90];const Me=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]!==Me?(Oe=ye("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",Me),t[91]=Me,t[92]=Oe):Oe=t[92];let Ae;t[93]!==e?(Ae=e("settings.projects.page.field.none"),t[93]=e,t[94]=Ae):Ae=t[94];let z;t[95]===Symbol.for("react.memo_cache_sentinel")?(z=s.jsx(D,{name:"close",className:"h-4 w-4 text-muted-foreground"}),t[95]=z):z=t[95];let De;t[96]!==Oe||t[97]!==Ae?(De=s.jsx("button",{type:"button",onClick:le,className:Oe,title:Ae,children:z}),t[96]=Oe,t[97]=Ae,t[98]=De):De=t[98];let Xe;t[99]!==j?(Xe=Vb.map(jt=>s.jsx("button",{type:"button",onClick:()=>y(jt.key),className:ye("h-7 w-7 rounded-md border transition-colors",j===jt.key?"border-2 border-foreground ring-1 ring-[var(--primary-base)]/40":"border-transparent hover:border-border/70"),style:{backgroundColor:jt.cssVar},title:jt.label},jt.key)),t[99]=j,t[100]=Xe):Xe=t[100];let st;t[101]!==De||t[102]!==Xe?(st=s.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-2",children:[De,Xe]}),t[101]=De,t[102]=Xe,t[103]=st):st=t[103];let tt;t[104]!==U||t[105]!==st?(tt=s.jsxs("div",{className:"py-1.5",children:[U,st]}),t[104]=U,t[105]=st,t[106]=tt):tt=t[106];let Ue;t[107]!==e?(Ue=e("settings.projects.page.field.projectIcon"),t[107]=e,t[108]=Ue):Ue=t[108];let it;t[109]!==Ue?(it=s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:Ue})}),t[109]=Ue,t[110]=it):it=t[110];let Ye;t[111]!==J?(Ye=s.jsx("input",{ref:_,type:"file",accept:"image/png,image/jpeg,image/svg+xml,.png,.jpg,.jpeg,.svg",className:"hidden",onChange:jt=>{const Zt=jt.target.files?.[0]??null;J(Zt),jt.currentTarget.value=""}}),t[111]=J,t[112]=Ye):Ye=t[112];let rt;t[113]===Symbol.for("react.memo_cache_sentinel")?(rt=()=>h(null),t[113]=rt):rt=t[113];const Je=x===null?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-border/40 hover:border-border hover:bg-[var(--surface-muted)]";let ce;t[114]!==Je?(ce=ye("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",Je),t[114]=Je,t[115]=ce):ce=t[115];let We;t[116]!==e?(We=e("settings.projects.page.field.none"),t[116]=e,t[117]=We):We=t[117];let Le;t[118]===Symbol.for("react.memo_cache_sentinel")?(Le=s.jsx(D,{name:"close",className:"h-4 w-4 text-muted-foreground"}),t[118]=Le):Le=t[118];let Ge;t[119]!==ce||t[120]!==We?(Ge=s.jsx("button",{type:"button",onClick:rt,className:ce,title:We,children:Le}),t[119]=ce,t[120]=We,t[121]=Ge):Ge=t[121];let at;t[122]!==de||t[123]!==x?(at=zb.map(jt=>{const Zt=jt.Icon;return s.jsx("button",{type:"button",onClick:()=>h(jt.key),className:ye("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",x===jt.key?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-transparent hover:border-border hover:bg-[var(--surface-muted)]"),title:jt.label,children:s.jsx(D,{name:Zt,className:"w-4 h-4",style:de&&x===jt.key?{color:de}:void 0})},jt.key)}),t[122]=de,t[123]=x,t[124]=at):at=t[124];let He;t[125]!==Ge||t[126]!==at?(He=s.jsxs("div",{className:"mt-1.5 flex max-w-[22rem] flex-wrap items-center gap-2",children:[Ge,at]}),t[125]=Ge,t[126]=at,t[127]=He):He=t[127];let ze;t[128]!==ge||t[129]!==C||t[130]!==ne||t[131]!==e?(ze=ge&&ne&&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:ne,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>F(!0)})})})]}),t[128]=ge,t[129]=C,t[130]=ne,t[131]=e,t[132]=ze):ze=t[132];let et;t[133]!==ge||t[134]!==C||t[135]!==e?(et=ge&&s.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[s.jsx("input",{type:"color",value:C??"#000000",onChange:jt=>k(jt.target.value),className:"h-7 w-9 cursor-pointer rounded border border-border bg-transparent p-1","aria-label":e("settings.projects.page.field.projectIconBackgroundAria")}),s.jsx(Bt,{value:C??"",onChange:jt=>k(jt.target.value),placeholder:"#000000",className:"h-7 w-[8rem]"}),s.jsx(ve,{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(D,{name:"close",className:"h-3.5 w-3.5"})})]}),t[133]=ge,t[134]=C,t[135]=e,t[136]=et):et=t[136];let gt;t[137]!==Pe||t[138]!==te||t[139]!==P||t[140]!==w||t[141]!==e?(gt=!te&&s.jsxs(s.Fragment,{children:[s.jsx(ve,{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(ve,{size:"xs",className:"h-6 !font-normal",variant:"outline",onClick:()=>{Pe()},disabled:P,children:e(P?"settings.projects.page.actions.discovering":"settings.projects.page.actions.discoverFavicon")})]}),t[137]=Pe,t[138]=te,t[139]=P,t[140]=w,t[141]=e,t[142]=gt):gt=t[142];let Pt;t[143]!==he||t[144]!==ue||t[145]!==I||t[146]!==e?(Pt=ue&&s.jsx(ve,{size:"xs",className:"!font-normal",variant:"outline",onClick:()=>{he()},disabled:I,children:e(I?"settings.projects.page.actions.removing":"settings.projects.page.actions.removeProjectIcon")}),t[143]=he,t[144]=ue,t[145]=I,t[146]=e,t[147]=Pt):Pt=t[147];let Nt;t[148]!==I||t[149]!==N||t[150]!==e?(Nt=N&&s.jsx(ve,{size:"xs",className:"!font-normal",variant:"outline",onClick:()=>E(!1),disabled:I,children:e("settings.projects.page.actions.undoRemove")}),t[148]=I,t[149]=N,t[150]=e,t[151]=Nt):Nt=t[151];let ht;t[152]!==gt||t[153]!==Pt||t[154]!==Nt?(ht=s.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[gt,Pt,Nt]}),t[152]=gt,t[153]=Pt,t[154]=Nt,t[155]=ht):ht=t[155];let wt;t[156]!==it||t[157]!==Ye||t[158]!==He||t[159]!==ze||t[160]!==et||t[161]!==ht?(wt=s.jsxs("div",{className:"py-1.5",children:[it,Ye,He,ze,et,ht]}),t[156]=it,t[157]=Ye,t[158]=He,t[159]=ze,t[160]=et,t[161]=ht,t[162]=wt):wt=t[162];let es;t[163]!==ee||t[164]!==tt||t[165]!==wt?(es=s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[ee,tt,wt]}),t[163]=ee,t[164]=tt,t[165]=wt,t[166]=es):es=t[166];let Vt;t[167]!==K||t[168]!==I||t[169]!==w||t[170]!==g?(Vt=!K||g.trim().length===0||w||I,t[167]=K,t[168]=I,t[169]=w,t[170]=g,t[171]=Vt):Vt=t[171];let Jt;t[172]!==e?(Jt=e("settings.common.actions.saveChanges"),t[172]=e,t[173]=Jt):Jt=t[173];let mt;t[174]!==W||t[175]!==Vt||t[176]!==Jt?(mt=s.jsx("div",{className:"mt-0.5 px-2 py-1",children:s.jsx(ve,{onClick:W,disabled:Vt,size:"xs",className:"!font-normal",children:Jt})}),t[174]=W,t[175]=Vt,t[176]=Jt,t[177]=mt):mt=t[177];let Lt;t[178]!==es||t[179]!==mt?(Lt=s.jsxs("div",{className:"mb-8",children:[es,mt]}),t[178]=es,t[179]=mt,t[180]=Lt):Lt=t[180];let ts;t[181]!==Z?(ts=Z&&s.jsx(T3,{projectRef:Z}),t[181]=Z,t[182]=ts):ts=t[182];let js;t[183]!==ts?(js=s.jsx("div",{className:"mb-8",children:s.jsx("section",{className:"px-2 pb-2 pt-0",children:ts})}),t[183]=ts,t[184]=js):js=t[184];let ds;t[185]!==e?(ds=e("settings.projects.page.section.worktree"),t[185]=e,t[186]=ds):ds=t[186];let hs;t[187]!==ds?(hs=s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:ds})}),t[187]=ds,t[188]=hs):hs=t[188];let Ut;t[189]!==Z?(Ut=Z&&s.jsx(P3,{projectRef:Z}),t[189]=Z,t[190]=Ut):Ut=t[190];let Qe;t[191]!==Ut?(Qe=s.jsx("section",{className:"px-2 pb-2 pt-0",children:Ut}),t[191]=Ut,t[192]=Qe):Qe=t[192];let At;t[193]!==hs||t[194]!==Qe?(At=s.jsxs("div",{className:"mb-8",children:[hs,Qe]}),t[193]=hs,t[194]=Qe,t[195]=At):At=t[195];let Ht;return t[196]!==Ne||t[197]!==Lt||t[198]!==js||t[199]!==At?(Ht=s.jsx(ws,{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:[Ne,Lt,js,At]})}),t[196]=Ne,t[197]=Lt,t[198]=js,t[199]=At,t[200]=Ht):Ht=t[200],Ht};function E3(t){return t.projects}function R3(t){return t.updateProjectMeta}function F3(t){return t.uploadProjectIcon}function O3(t){return t.removeProjectIcon}function L3(t){return t.discoverProjectIcon}function $3(t){return t.settingsProjectsSelectedId}function _3(t){return t.setSettingsProjectsSelectedId}function B3(t){return t&&URL.revokeObjectURL(t),null}const V3=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`,z3=()=>Math.floor(2e4+Math.random()*3e4),U3=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")},W3=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"}},K3=({onItemSelect:t})=>{const{t:e}=ut(),n=Xs(h=>h.instances),r=Xs(h=>h.statusesById),a=Xs(h=>h.isLoading),i=Xs(h=>h.load),l=Xs(h=>h.loadImports),c=Xs(h=>h.createFromCommand),d=Xs(h=>h.connect),p=Xs(h=>h.disconnect),m=Xs(h=>h.retry),u=Xs(h=>h.removeInstance),f=Xs(h=>h.upsertInstance),b=Re(h=>h.settingsRemoteInstancesSelectedId),g=Re(h=>h.setSettingsRemoteInstancesSelectedId);o.useEffect(()=>{i(),l()},[i,l]),o.useEffect(()=>{if(!a){if(n.length===0){b!==null&&g(null);return}b&&n.some(h=>h.id===b)||g(n[0].id)}},[n,a,b,g]);const v=o.useCallback(async()=>{const h=V3();try{await c(h,"ssh user@example.com",e("settings.remoteInstances.sidebar.newSshInstanceName")),g(h),t?.()}catch(j){G.error(e("settings.remoteInstances.sidebar.toast.createFailed"),{description:j instanceof Error?j.message:String(j)})}},[c,t,g,e]),x=o.useCallback(async h=>{try{await d(h.id);return}catch(j){if(!U3(j)||!window.confirm(e("settings.remoteInstances.sidebar.confirm.localPortInUseRetry")))throw j;const C={...h,localForward:{...h.localForward,preferredLocalPort:z3()}};await f(C),await d(C.id),G.success(e("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[d,e,f]);return s.jsx(gg,{variant:"background",header:s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:e("settings.remoteInstances.sidebar.title")}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.remoteInstances.sidebar.total",{count:n.length})}),s.jsx(ve,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:()=>{v()},"aria-label":e("settings.remoteInstances.sidebar.actions.addSshInstance"),children:s.jsx(D,{name:"add",className:"size-4"})})]})]}),children:n.map(h=>{const j=r[h.id],y=h.id===b,C=h.nickname?.trim()||h.sshParsed?.destination||h.id,k=`${e(W3(j?.phase))}${j?.localUrl?` · ${j.localUrl}`:""}`,w=j?.phase==="ready",S=j?.phase==="error"||j?.phase==="degraded";return s.jsx(xg,{title:C,metadata:k,selected:y,onSelect:()=>{g(h.id),t?.()},actions:[{label:e(w?"settings.remoteInstances.sidebar.actions.disconnect":"settings.remoteInstances.sidebar.actions.connect"),icon:w?"stop":"plug-2",onClick:()=>{(w?p(h.id):x(h)).catch(T=>{G.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:()=>{S&&m(h.id).catch(I=>{G.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);g(I?.id||null)}}).catch(I=>{G.error(e("settings.remoteInstances.sidebar.toast.removeFailed"),{description:I instanceof Error?I.message:String(I)})})}}]},h.id)})})},Np=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 l;e[2]!==r?(l=ye("mx-auto max-w-3xl space-y-6 p-3 sm:p-6 sm:pt-8",r),e[2]=r,e[3]=l):l=e[3];let c;e[4]!==n||e[5]!==l?(c=s.jsx("div",{className:l,children:n}),e[4]=n,e[5]=l,e[6]=c):c=e[6];let d;return e[7]!==i||e[8]!==c?(d=s.jsx(ws,{outerClassName:i,className:"w-full",children:c}),e[7]=i,e[8]=c,e[9]=d):d=e[9],d},yd=()=>Math.floor(2e4+Math.random()*3e4),H3=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")},G3=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"}},q3=new Set(["config_resolved","auth_check","master_connecting","remote_probe","installing","updating","server_detecting","server_starting","forwarding"]),bg=t=>!!(t&&q3.has(t)),Y3=t=>t==="ready"?"bg-[var(--status-success)] animate-pulse":t==="error"?"bg-[var(--status-error)] animate-pulse":t==="degraded"||bg(t)?"bg-[var(--status-warning)] animate-pulse":"bg-muted-foreground/40",Q3=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}`,J3=()=>({id:`forward-${Date.now()}-${Math.random().toString(16).slice(2)}`,enabled:!0,type:"local",localHost:"127.0.0.1",localPort:yd(),remoteHost:"127.0.0.1",remotePort:80}),X3=t=>t.trim().replace(/\*/g,"host").replace(/\?/g,"x")||"user@host",Jr=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(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),e[2]=i):i=e[2];let l;e[3]!==r?(l=s.jsxs(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]=l):l=e[4];let c;return e[5]!==a||e[6]!==l?(c=s.jsxs("span",{className:"inline-flex items-center gap-1 typography-meta text-muted-foreground",children:[a,l]}),e[5]=a,e[6]=l,e[7]=c):c=e[7],c},Z3=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"}},Sp=(t,e)=>{const n=(t||"").trim();return`${!n||n==="127.0.0.1"||n==="::1"?"localhost":n}:${e||0}`},e5=t=>{const e=(t||"").trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},t5=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}`},s5=t=>{const e=t.trim();if(e)try{window.location.assign(e)}catch{window.location.href=e}},n5=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}},r5=()=>{const{t}=ut(),e=Xs(R=>R.instances),n=Xs(R=>R.statusesById),r=Xs(R=>R.importCandidates),a=Xs(R=>R.isImportsLoading),i=Xs(R=>R.isSaving),l=Xs(R=>R.error),c=Xs(R=>R.load),d=Xs(R=>R.loadImports),p=Xs(R=>R.refreshStatuses),m=Xs(R=>R.upsertInstance),u=Xs(R=>R.createFromCommand),f=Xs(R=>R.removeInstance),b=Xs(R=>R.connect),g=Xs(R=>R.disconnect),v=Xs(R=>R.retry),x=Re(R=>R.settingsRemoteInstancesSelectedId),h=Re(R=>R.setSettingsRemoteInstancesSelectedId),j=o.useMemo(()=>x&&e.find(R=>R.id===x)||null,[e,x]),[y,C]=o.useState(null),[k,w]=o.useState(!1),[S,I]=o.useState(!1),[T,P]=o.useState(null),[A,N]=o.useState([]),[E,M]=o.useState(null),[O,V]=o.useState(""),[B,$]=o.useState(!1),[F,_]=o.useState({}),[q,L]=o.useState(!1),[Y,Z]=o.useState(!1),[ae,re]=o.useState(()=>Date.now());o.useEffect(()=>{c(),d()},[c,d]),o.useEffect(()=>{C(j)},[j]),o.useEffect(()=>{if(!x)return;const R=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||p()},2e3);return()=>{window.clearInterval(R)}},[p,x]),o.useEffect(()=>{let R=null,U=Date.now();const le=()=>{const Oe=Date.now();Oe-U>=1e3&&(re(Oe),U=Oe),R=requestAnimationFrame(le)};(typeof document>"u"||document.visibilityState==="visible")&&(R=requestAnimationFrame(le));const Me=()=>{document.visibilityState==="visible"&&R===null?R=requestAnimationFrame(le):document.visibilityState!=="visible"&&R!==null&&(cancelAnimationFrame(R),R=null)};return document.addEventListener("visibilitychange",Me),()=>{document.removeEventListener("visibilitychange",Me),R!==null&&cancelAnimationFrame(R)}},[]);const me=x?n[x]:null,fe=me?.phase,H=fe==="ready",K=fe==="degraded",Q=bg(fe),de=H||(Q||K),be=me?Math.max(0,ae-me.updatedAtMs):0,we=K&&be>12e3,te=o.useMemo(()=>!y||!j?!1:JSON.stringify(y)!==JSON.stringify(j),[y,j]),ge=o.useCallback(R=>{C(U=>U&&R(U))},[]),ue=o.useCallback(async()=>{if(!y)return;const R=n5(y);if(!R.sshCommand.trim()){G.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}if(!(R.localForward.bindHost==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces")))){if(R.auth.sshPassword?.enabled&&R.auth.sshPassword.value?.trim()&&R.auth.sshPassword.store!=="settings"){const U=window.confirm(t("settings.remoteInstances.page.confirm.storeSshPasswordPlaintext"));R.auth.sshPassword.store=U?"settings":"never",U||(R.auth.sshPassword.value=void 0)}if(R.auth.openchamberPassword?.enabled&&R.auth.openchamberPassword.value?.trim()&&R.auth.openchamberPassword.store!=="settings"){const U=window.confirm(t("settings.remoteInstances.page.confirm.storeUiPasswordPlaintext"));R.auth.openchamberPassword.store=U?"settings":"never",U||(R.auth.openchamberPassword.value=void 0)}try{await m(R),G.success(t("settings.remoteInstances.page.toast.instanceSaved"))}catch(U){G.error(t("settings.remoteInstances.page.toast.saveFailed"),{description:U instanceof Error?U.message:String(U)})}}},[y,t,m]),xe=o.useCallback(async(R,U)=>{const le=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{return await u(le,`ssh ${U}`,R),h(le),G.success(t("settings.remoteInstances.page.toast.instanceCreated")),!0}catch(Me){return G.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:Me instanceof Error?Me.message:String(Me)}),!1}},[u,h,t]),ne=o.useCallback(()=>{B||(M(null),V(""))},[B]),pe=o.useCallback((R,U)=>{if(U){M(R),V(X3(R));return}xe(R,R)},[xe]),J=o.useCallback(async()=>{const R=E,U=O.trim();if(R){if(!U){G.error(t("settings.remoteInstances.page.toast.destinationRequired"));return}$(!0);try{await xe(R,U)&&(M(null),V(""))}finally{$(!1)}}},[xe,O,E,t]),Se=o.useCallback(async()=>{if(j)try{await b(j.id);return}catch(R){if(!H3(R)||!window.confirm(t("settings.remoteInstances.sidebar.confirm.localPortInUseRetry")))throw R;const le={...j,localForward:{...j.localForward,preferredLocalPort:yd()}};await m(le),await b(le.id),G.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[b,j,t,m]),he=o.useCallback(async R=>(await Ub(R,600)).map(le=>t5(le)),[]),Ie=o.useCallback(async()=>{if(y){w(!0),I(!0),P(null);try{const R=await he(y.id);N(R)}catch(R){N([]),P(R instanceof Error?R.message:String(R))}finally{I(!1)}}},[y,he]);o.useEffect(()=>{if(!k||!y)return;let R=!1;const U=async()=>{try{const Me=await he(y.id);R||(N(Me),P(null))}catch(Me){R||P(Me instanceof Error?Me.message:String(Me))}};U();const le=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||U()},1e3);return()=>{R=!0,window.clearInterval(le)}},[y,k,he]);const Pe=o.useMemo(()=>A.join(`
|
|
181
|
-
`),[A]),Ce=o.useCallback(()=>{if(!Pe.trim()){G.error(t("settings.remoteInstances.page.toast.noLogsToCopy"));return}Rn(Pe).then(R=>{R.ok&&G.success(t("settings.remoteInstances.page.toast.logsCopied"))})},[Pe,t]),X=o.useCallback(async()=>{if(y)try{await Wb(y.id),N([]),G.success(t("settings.remoteInstances.page.toast.logsCleared"))}catch(R){G.error(t("settings.remoteInstances.page.toast.clearLogsFailed"),{description:R instanceof Error?R.message:String(R)})}},[y,t]),ie=o.useCallback(async()=>{if(!me?.localUrl){G.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}const R=me.localUrl.trim();if(!R){G.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}s5(R)},[me?.localUrl,t]),Ne=o.useCallback(()=>{if(!y)return;L(!0),(de?g(y.id):Se()).catch(U=>{const le=de?H?"settings.remoteInstances.page.toast.disconnectFailed":"settings.remoteInstances.page.toast.cancelConnectionFailed":"settings.remoteInstances.page.toast.connectFailed";G.error(t(le),{description:U instanceof Error?U.message:String(U)})}).finally(()=>{L(!1)})},[de,Se,g,y,H,t]),oe=o.useCallback(()=>{if(!y||Q)return;Z(!0),(K?g(y.id).then(()=>Se()):v(y.id)).catch(U=>{G.error(t("settings.remoteInstances.page.toast.retryFailed"),{description:U instanceof Error?U.message:String(U)})}).finally(()=>{Z(!1)})},[Se,g,y,Q,K,v,t]),ke=t(Q?"settings.remoteInstances.page.actions.connecting":K?we?"settings.remoteInstances.page.actions.reconnectNow":"settings.remoteInstances.page.actions.reconnecting":"settings.remoteInstances.sidebar.actions.retry"),Te=!q&&!Y&&(fe==="error"||fe==="idle"||!fe||K&&we)&&!Q,Be=t(H?"settings.remoteInstances.sidebar.actions.disconnect":de?"settings.remoteInstances.page.actions.cancel":"settings.remoteInstances.sidebar.actions.connect");if(!y)return s.jsxs(Np,{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(R=>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:[R.host,R.pattern?` ${t("settings.remoteInstances.page.import.patternSuffix")}`:""]}),s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[R.source," config"]})]}),s.jsx(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{pe(R.host,R.pattern)},children:t("settings.remoteInstances.page.actions.create")})]},`${R.source}:${R.host}`))})})]}),s.jsx(ps,{open:!!E,onOpenChange:R=>{R||ne()},children:s.jsxs(ms,{className:"sm:max-w-md",children:[s.jsxs(gs,{children:[s.jsx(fs,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Ns,{children:E?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:E}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:R=>{R.preventDefault(),J()},children:[s.jsx(Bt,{value:O,onChange:R=>V(R.target.value),placeholder:t("settings.remoteInstances.page.patternDialog.destinationPlaceholder"),autoFocus:!0}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsx(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:ne,disabled:B,children:t("settings.common.actions.cancel")}),s.jsx(ve,{type:"submit",size:"xs",className:"!font-normal",disabled:B,children:t("settings.remoteInstances.page.actions.create")})]})]})]})})]});const je=y.remoteOpenchamber.mode==="managed",ee=y.nickname?.trim()||y.sshParsed?.destination||y.id;return s.jsxs(Np,{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 ${Y3(fe)}`}),s.jsx("span",{children:t(G3(fe))}),me?.localUrl?s.jsx("span",{className:"font-mono text-foreground/80",children:me.localUrl}):null,we?s.jsx("span",{children:t("settings.remoteInstances.page.status.reconnectStale")}):null]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.section.actions")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.section.actionsDescription")})]}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(ve,{type:"button",variant:de?"outline":"default",size:"xs",className:"!font-normal",onClick:Ne,disabled:q||Y,children:[de?s.jsx(D,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(D,{name:"plug-2",className:"h-3.5 w-3.5"}),Be]}),s.jsxs(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:oe,disabled:!Te,children:[s.jsx(D,{name:"refresh",className:`h-3.5 w-3.5 ${Q||K&&!we?"animate-spin":""}`}),ke]}),s.jsxs(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ie()},children:[s.jsx(D,{name:"terminal-window",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.logs")]}),s.jsxs(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal text-[var(--status-error)] border-[var(--status-error)]/30 hover:text-[var(--status-error)]",onClick:()=>{window.confirm(t("settings.remoteInstances.page.confirm.removeInstance"))&&f(y.id).then(()=>{h(null),G.success(t("settings.remoteInstances.page.toast.instanceRemoved"))}).catch(U=>{G.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:U instanceof Error?U.message:String(U)})})},children:[s.jsx(D,{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(Bt,{className:"h-7 md:max-w-xl",value:y.sshCommand,onChange:R=>ge(U=>({...U,sshCommand:R.target.value})),placeholder:t("settings.remoteInstances.page.field.sshCommandPlaceholder")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.nickname")}),s.jsx(Bt,{className:"h-7 md:max-w-sm",value:y.nickname||"",onChange:R=>ge(U=>({...U,nickname:R.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:y.connectionTimeoutSec,onValueChange:R=>{ge(U=>({...U,connectionTimeoutSec:Number.isFinite(R)?R: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(Jr,{label:t("settings.remoteInstances.page.field.mode"),hint:t("settings.remoteInstances.page.field.modeHint")})}),s.jsxs(is,{value:y.remoteOpenchamber.mode,onValueChange:R=>ge(U=>({...U,remoteOpenchamber:{...U.remoteOpenchamber,mode:R==="external"?"external":"managed"}})),children:[s.jsx(os,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(us,{placeholder:t("settings.remoteInstances.page.field.modePlaceholder")})}),s.jsxs(ls,{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(Jr,{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:y.remoteOpenchamber.preferredPort,onValueChange:R=>{ge(U=>({...U,remoteOpenchamber:{...U.remoteOpenchamber,preferredPort:Number.isFinite(R)&&R>0?R:void 0}}))},onClear:()=>{ge(R=>({...R,remoteOpenchamber:{...R.remoteOpenchamber,preferredPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]}),je?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(Jr,{label:t("settings.remoteInstances.page.field.installMethod"),hint:t("settings.remoteInstances.page.field.installMethodHint")})}),s.jsxs(is,{value:y.remoteOpenchamber.installMethod,onValueChange:R=>ge(U=>({...U,remoteOpenchamber:{...U.remoteOpenchamber,installMethod:R==="npm"||R==="download_release"||R==="upload_bundle"?R:"bun"}})),children:[s.jsx(os,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(us,{placeholder:t("settings.remoteInstances.page.field.selectInstallMethodPlaceholder")})}),s.jsxs(ls,{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,je?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(Jr,{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(yl,{checked:y.remoteOpenchamber.keepRunning,onCheckedChange:R=>ge(U=>({...U,remoteOpenchamber:{...U.remoteOpenchamber,keepRunning:R}}))})})]}):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(Jr,{label:t("settings.remoteInstances.page.field.bindHost"),hint:t("settings.remoteInstances.page.field.bindHostHint")})}),s.jsxs(is,{value:y.localForward.bindHost,onValueChange:R=>{R==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces"))||ge(U=>({...U,localForward:{...U.localForward,bindHost:R==="localhost"||R==="0.0.0.0"?R:"127.0.0.1"}}))},children:[s.jsx(os,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(us,{placeholder:t("settings.remoteInstances.page.field.selectBindHostPlaceholder")})}),s.jsxs(ls,{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(Jr,{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:y.localForward.preferredLocalPort,onValueChange:R=>{ge(U=>({...U,localForward:{...U.localForward,preferredLocalPort:Number.isFinite(R)&&R>0?R:void 0}}))},onClear:()=>{ge(R=>({...R,localForward:{...R.localForward,preferredLocalPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")}),s.jsx(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal h-7 w-7 px-0",title:t("settings.remoteInstances.page.actions.pickRandomPort"),onClick:()=>ge(R=>({...R,localForward:{...R.localForward,preferredLocalPort:yd()}})),children:s.jsx(D,{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(Bt,{className:"h-7 md:max-w-sm",type:"password",value:y.auth.sshPassword?.value||"",onChange:R=>ge(U=>({...U,auth:{...U.auth,sshPassword:{enabled:R.target.value.trim().length>0,value:R.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(Bt,{className:"h-7 md:max-w-sm",type:"password",value:y.auth.openchamberPassword?.value||"",onChange:R=>ge(U=>({...U,auth:{...U.auth,openchamberPassword:{enabled:R.target.value.trim().length>0,value:R.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:[y.portForwards.length===0?s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:t("settings.remoteInstances.page.empty.noExtraForwards")}):null,y.portForwards.map((R,U)=>{const le=Ye=>{ge(rt=>({...rt,portForwards:rt.portForwards.map((Je,ce)=>ce===U?Ye(Je):Je)}))},Me=R.type==="remote"?"Local target":"Local listen",Oe=R.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.",Ae=R.type==="remote"?"Remote listen":"Remote target",z=R.type==="remote"?"Remote host and port where SSH creates the -R listener.":"Remote host and port that receives traffic from local -L listener.",De=Sp(R.localHost||"localhost",R.localPort),Xe=Sp(R.remoteHost||"localhost",R.remotePort),st=R.type==="local"&&typeof R.localPort=="number"&&R.localPort>0,tt=st?`http://${e5(R.localHost)}:${R.localPort}`:"",Ue=!!F[R.id],it=R.type==="local"?t("settings.remoteInstances.page.forwardType.local"):R.type==="remote"?t("settings.remoteInstances.page.forwardType.remote"):t("settings.remoteInstances.page.forwardType.dynamic");return s.jsxs(br,{open:Ue,onOpenChange:Ye=>{_(rt=>({...rt,[R.id]:Ye}))},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(Tr,{className:"flex items-center gap-2 group",children:[s.jsx(D,{name:"arrow-down-s",className:`h-4 w-4 text-muted-foreground transition-transform ${Ue?"rotate-180":""}`}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Q3(R)}),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(yl,{checked:R.enabled,onCheckedChange:Ye=>le(rt=>({...rt,enabled:Ye})),"aria-label":t("settings.remoteInstances.page.actions.enableForwardAria")}),s.jsx(ve,{type:"button",variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0 text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>ge(Ye=>({...Ye,portForwards:Ye.portForwards.filter(rt=>rt.id!==R.id)})),children:s.jsx(D,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),s.jsx(yr,{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(Z3(R.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(Jr,{label:t("settings.remoteInstances.page.field.forwardType"),hint:t("settings.remoteInstances.page.field.forwardTypeHint")})}),s.jsxs(is,{value:R.type,onValueChange:Ye=>le(rt=>({...rt,type:Ye==="dynamic"||Ye==="remote"?Ye:"local"})),children:[s.jsx(os,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(us,{placeholder:t("settings.remoteInstances.page.field.typePlaceholder")})}),s.jsxs(ls,{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(Jr,{label:Me,hint:Oe})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Bt,{className:"h-7 w-32",value:R.localHost||"127.0.0.1",onChange:Ye=>le(rt=>({...rt,localHost:Ye.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:R.localPort,onValueChange:Ye=>{le(rt=>({...rt,localPort:Number.isFinite(Ye)&&Ye>0?Ye:void 0}))},onClear:()=>{le(Ye=>({...Ye,localPort:void 0}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]})]}),R.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(Jr,{label:Ae,hint:z})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Bt,{className:"h-7 w-32",value:R.remoteHost||"",onChange:Ye=>le(rt=>({...rt,remoteHost:Ye.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:R.remotePort,onValueChange:Ye=>{le(rt=>({...rt,remotePort:Number.isFinite(Ye)&&Ye>0?Ye:void 0}))},onClear:()=>{le(Ye=>({...Ye,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:R.type==="dynamic"?s.jsxs(s.Fragment,{children:[s.jsx(D,{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")})]}):R.type==="remote"?s.jsxs(s.Fragment,{children:[s.jsx(D,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Xe}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")}),s.jsx(D,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(D,{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(D,{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(D,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(D,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Xe}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")})]})}),st?s.jsxs(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Zn(tt).then(Ye=>{Ye||G.error(t("settings.remoteInstances.page.toast.openLocalEndpointFailed"))})},children:[s.jsx(D,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.openLocal")]}):null]})]})})]},R.id)}),s.jsxs(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal mt-1",onClick:()=>{const R=J3();ge(U=>({...U,portForwards:[...U.portForwards,R]})),_(U=>({...U,[R.id]:!0}))},children:[s.jsx(D,{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((R,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:[R.host,R.pattern?" (pattern)":""]}),s.jsx("div",{className:"typography-micro text-muted-foreground truncate",children:R.sshCommand})]}),s.jsx(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{pe(R.host,R.pattern)},children:t("settings.common.actions.import")})]},`${R.source}:${R.host}`))})})]}),s.jsx("div",{className:"sticky bottom-0 z-10 -mx-3 sm:-mx-6 bg-[var(--surface-background)] border-t border-[var(--interactive-border)] px-3 sm:px-6 py-3",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ve,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{ue()},disabled:!te||i,children:t("settings.common.actions.saveChanges")}),me?.localUrl?s.jsxs(s.Fragment,{children:[s.jsxs(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Rn(me.localUrl||"").then(R=>{R.ok&&G.success(t("settings.remoteInstances.page.toast.localUrlCopied"))})},children:[s.jsx(D,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.copyLocalUrl")]}),s.jsxs(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ie()},children:[s.jsx(D,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.open")]})]}):null,l?s.jsx("div",{className:"ml-auto typography-meta text-[var(--status-error)]",children:l}):null]})}),s.jsx(ps,{open:k,onOpenChange:w,children:s.jsxs(ms,{className:"sm:max-w-2xl",children:[s.jsxs(gs,{children:[s.jsx(fs,{children:t("settings.remoteInstances.page.logsDialog.title")}),s.jsx(Ns,{children:y?.nickname?.trim()||y?.sshParsed?.destination||y?.id||t("settings.remoteInstances.page.logsDialog.selectedInstanceFallback")})]}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsxs(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Ce,disabled:S||!Pe.trim(),children:[s.jsx(D,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.common.actions.copyAll")]}),s.jsxs(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{X()},disabled:S,children:[s.jsx(D,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.clear")]})]}),S?s.jsx("div",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.logsDialog.loading")}):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:A.length>0?A.join(`
|
|
182
|
-
`):t("settings.remoteInstances.page.logsDialog.empty")})]})}),s.jsx(ps,{open:!!E,onOpenChange:R=>{R||ne()},children:s.jsxs(ms,{className:"sm:max-w-md",children:[s.jsxs(gs,{children:[s.jsx(fs,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Ns,{children:E?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:E}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:R=>{R.preventDefault(),J()},children:[s.jsx(Bt,{value:O,onChange:R=>V(R.target.value),placeholder:t("settings.remoteInstances.page.patternDialog.destinationPlaceholder"),autoFocus:!0}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsx(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:ne,disabled:B,children:t("settings.common.actions.cancel")}),s.jsx(ve,{type:"submit",size:"xs",className:"!font-normal",disabled:B,children:t("settings.common.actions.create")})]})]})]})})]})},a5="__add_provider__",i5=()=>{const t=nn.getDirectory();return typeof t=="string"&&t.trim().length>0?t.trim():null},o5=({onItemSelect:t})=>{const{t:e}=ut(),n=yt(f=>f.providers),r=yt(f=>f.selectedProviderId),a=yt(f=>f.setSelectedProvider),i=Cs(f=>f.activeProjectId),[l,c]=o.useState({}),d=o.useMemo(()=>i5(),[i]);o.useEffect(()=>{if(n.length===0){c({});return}let f=!1;return(async()=>{const g=n.map(async v=>{try{const x=d?`?directory=${encodeURIComponent(d)}`:"",h=await fetch(`/api/provider/${encodeURIComponent(v.id)}/source${x}`,{method:"GET",headers:{Accept:"application/json"}});if(!h.ok)return;const j=await h.json().catch(()=>null),y=j?.sources??j?.data?.sources;if(!y||f)return;c(C=>({...C,[v.id]:y}))}catch{}});await Promise.all(g)})(),()=>{f=!0}},[d,n]);const p="bg-background",m=o.useMemo(()=>n.filter(f=>!!l[f.id]?.project?.exists),[n,l]),u=o.useMemo(()=>n.filter(f=>!l[f.id]?.project?.exists),[n,l]);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(jo,{className:"mb-3"}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.providers.sidebar.total",{count:n.length})}),s.jsx(ve,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:()=>{a(a5),t?.()},"aria-label":e("settings.providers.sidebar.actions.connectProviderAria"),title:e("settings.providers.sidebar.actions.connectProviderTitle"),children:s.jsx(D,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(ws,{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(D,{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(kp,{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(kp,{provider:f,selectedProviderId:r,onSelect:()=>{a(f.id),t?.()}},f.id))]})]})})]})},kp=t=>{const e=ot.c(17),{provider:n,selectedProviderId:r,onSelect:a}=t,i=Array.isArray(n.models)?n.models.length:0,l=n.id===r,c=n.id,d=l?"bg-interactive-selection":"hover:bg-interactive-hover";let 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(xr,{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 g;e[8]!==a||e[9]!==m||e[10]!==f||e[11]!==b?(g=s.jsxs("button",{type:"button",onClick:a,className:"flex min-w-0 flex-1 items-center gap-2 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[m,f,b]}),e[8]=a,e[9]=m,e[10]=f,e[11]=b,e[12]=g):g=e[12];let v;return e[13]!==n.id||e[14]!==p||e[15]!==g?(v=s.jsx("div",{className:p,children:g},c),e[13]=n.id,e[14]=p,e[15]=g,e[16]=v):v=e[16],v},l5=new Intl.NumberFormat("en-US",{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}),Cp=t=>{if(typeof t!="number"||Number.isNaN(t))return null;if(t===0)return"0";const e=l5.format(t);return e.endsWith(".0")?e.slice(0,-2):e},Vo="__add_provider__",ji=t=>typeof t=="object"&&t!==null,Ip=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()},c5=t=>{if(!ji(t))return{};const e={};for(const[n,r]of Object.entries(t))Array.isArray(r)&&(e[n]=r.filter(a=>ji(a)));return e},d5=t=>{if(typeof t=="string")return{id:t};if(!ji(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}},u5=t=>{let e=[];Array.isArray(t)?e=t:ji(t)&&(Array.isArray(t.all)?e=t.all:Array.isArray(t.providers)&&(e=t.providers));const n=e.map(a=>d5(a)).filter(a=>!!a),r=new Set;return n.filter(a=>r.has(a.id)?!1:(r.add(a.id),!0))},m5=()=>{const{t}=ut(),e=yt(ne=>ne.providers),n=yt(ne=>ne.selectedProviderId),r=yt(ne=>ne.setSelectedProvider),a=yt(ne=>ne.getModelMetadata),i=Re(ne=>ne.hiddenModels),l=Re(ne=>ne.toggleHiddenModel),c=Re(ne=>ne.hideAllModels),d=Re(ne=>ne.showAllModels),[p,m]=o.useState({}),[u,f]=o.useState(!1),[b,g]=o.useState({}),[v,x]=o.useState(null),[h,j]=o.useState(""),[y,C]=o.useState(null),[k,w]=o.useState({}),[S,I]=o.useState({}),[T,P]=o.useState([]),[A,N]=o.useState(!1),[E,M]=o.useState(null),[O,V]=o.useState(""),[B,$]=o.useState(""),[F,_]=o.useState(!1),[q,L]=o.useState({}),[Y,Z]=o.useState(!1);o.useEffect(()=>{!n&&e.length>0&&r(e[0].id)},[e,n,r]),o.useEffect(()=>{let ne=!0;return(async()=>{f(!0);try{const J=await fetch("/api/provider/auth",{method:"GET",headers:{Accept:"application/json"}});if(!J.ok)throw new Error(`Auth methods request failed (${J.status})`);const Se=await J.json().catch(()=>({}));if(!ne)return;m(c5(Se))}catch(J){if(!ne)return;console.error("Failed to load provider auth methods:",J),G.error(t("settings.providers.page.toast.authMethodsLoadFailed"))}finally{ne&&f(!1)}})(),()=>{ne=!1}},[t]),o.useEffect(()=>{let ne=!0;return(async()=>{N(!0),M(null);try{const J=await fetch("/api/provider",{method:"GET",headers:{Accept:"application/json"}});if(!J.ok)throw new Error(`Provider list request failed (${J.status})`);const Se=await J.json().catch(()=>({}));if(!ne)return;P(u5(Se))}catch(J){if(!ne)return;console.error("Failed to load available providers:",J),M(t("settings.providers.page.state.unableToLoadProviderList"))}finally{ne&&N(!1)}})(),()=>{ne=!1}},[t]);const ae=o.useMemo(()=>new Set(e.map(ne=>ne.id)),[e]),re=o.useMemo(()=>T.filter(ne=>!ae.has(ne.id)).sort((ne,pe)=>{const J=(ne.name||ne.id).toLowerCase(),Se=(pe.name||pe.id).toLowerCase();return J.localeCompare(Se)}),[T,ae]);o.useEffect(()=>{n===Vo&&O&&!re.some(ne=>ne.id===O)&&V("")},[n,O,re]),o.useEffect(()=>{if(n===Vo){Z(!0);return}Z(!1)},[n,t]),o.useEffect(()=>{if(!n||n===Vo)return;let ne=!1;return(async()=>{try{const J=await fetch(`/api/provider/${encodeURIComponent(n)}/source`,{method:"GET",headers:{Accept:"application/json"}}),Se=await J.json().catch(()=>null);if(!J.ok)throw new Error(Se?.error||t("settings.providers.page.toast.providerSourcesLoadFailed"));const he=Se?.sources??Se?.data?.sources;!ne&&he&&L(Ie=>({...Ie,[n]:he}))}catch(J){ne||console.error("Failed to load provider sources:",J)}})(),()=>{ne=!0}},[n,t]);const me=e.find(ne=>ne.id===n),fe=n?q[n]:void 0,H=async ne=>{const pe=b[ne]?.trim()??"";if(!pe){G.error(t("settings.providers.page.toast.apiKeyRequired"));return}const J=`api:${ne}`;x(J);try{const Se=await fetch(`/api/auth/${encodeURIComponent(ne)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"api",key:pe})}),he=await Se.json().catch(()=>null);if(!Se.ok){const Ie=he?.error||t("settings.providers.page.toast.apiKeySaveFailed");throw new Error(Ie)}G.success(t("settings.providers.page.toast.apiKeySaved")),g(Ie=>({...Ie,[ne]:""})),await ci({scopes:["providers"],mode:"active"}),r(ne)}catch(Se){console.error("Failed to save API key:",Se),G.error(t("settings.providers.page.toast.apiKeySaveFailed"))}finally{x(null)}},K=async(ne,pe)=>{const J=`oauth:${ne}:${pe}`;x(J);try{const Se=await fetch(`/api/provider/${encodeURIComponent(ne)}/oauth/authorize`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({method:pe})}),he=await Se.json().catch(()=>null);if(!Se.ok){const oe=he?.error||t("settings.providers.page.toast.oauthStartFailed");throw new Error(oe)}const Ie=ji(he)?he:{},Pe=ji(Ie.data)?Ie.data:Ie,Ce=typeof Pe.url=="string"&&Pe.url||typeof Pe.verification_uri_complete=="string"&&Pe.verification_uri_complete||typeof Pe.verification_uri=="string"&&Pe.verification_uri||void 0,X=typeof Pe.instructions=="string"&&Pe.instructions||typeof Pe.message=="string"&&Pe.message||void 0,ie=typeof Pe.user_code=="string"&&Pe.user_code||typeof Pe.code=="string"&&Pe.code||typeof Pe.userCode=="string"&&Pe.userCode||void 0;if(!Ce&&!X&&!ie)throw new Error(t("settings.providers.page.toast.oauthDetailsMissing"));const Ne=`${ne}:${pe}`;I(oe=>({...oe,[Ne]:{url:Ce,instructions:X,userCode:ie}})),Ce&&Zn(Ce),C({providerId:ne,methodIndex:pe}),G.message(t("settings.providers.page.toast.completeOAuthInBrowser"))}catch(Se){console.error("Failed to start OAuth flow:",Se),G.error(t("settings.providers.page.toast.oauthStartFailed"))}finally{x(null)}},Q=async(ne,pe)=>{const J=`${ne}:${pe}`,Se=k[J]?.trim(),he=`oauth-complete:${ne}:${pe}`;x(he);try{const Ie={method:pe};Se&&(Ie.code=Se);const Pe=await fetch(`/api/provider/${encodeURIComponent(ne)}/oauth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Ie)}),Ce=await Pe.json().catch(()=>null);if(!Pe.ok){const X=Ce?.error||t("settings.providers.page.toast.oauthCompleteFailed");throw new Error(X)}G.success(t("settings.providers.page.toast.oauthCompleted")),w(X=>({...X,[J]:""})),C(null),await ci({scopes:["providers"],mode:"active"}),r(ne)}catch(Ie){console.error("Failed to complete OAuth flow:",Ie),G.error(t("settings.providers.page.toast.oauthCompleteFailed"))}finally{x(null)}},W=async ne=>{const pe=await Rn(ne);if(pe.ok){G.success(t("settings.providers.page.toast.oauthLinkCopied"));return}console.error("Failed to copy OAuth link:",pe.error),G.error(t("settings.providers.page.toast.oauthLinkCopyFailed"))},de=async ne=>{const pe=await Rn(ne);if(pe.ok){G.success(t("settings.providers.page.toast.deviceCodeCopied"));return}console.error("Failed to copy device code:",pe.error),G.error(t("settings.providers.page.toast.deviceCodeCopyFailed"))},be=async ne=>{const pe=`disconnect:${ne}`;x(pe);try{const J=await fetch(`/api/provider/${encodeURIComponent(ne)}/auth?scope=all`,{method:"DELETE",headers:{"Content-Type":"application/json"}}),Se=await J.json().catch(()=>null);if(!J.ok){const he=Se?.error||t("settings.providers.page.toast.providerDisconnectFailed");throw new Error(he)}G.success(t("settings.providers.page.toast.providerDisconnected")),await ci({scopes:["providers"],mode:"active"})}catch(J){console.error("Failed to disconnect provider:",J),G.error(t("settings.providers.page.toast.providerDisconnectFailed"))}finally{x(null)}},we=n===Vo;if(!we&&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(D,{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(we)return s.jsx(ws,{outerClassName:"h-full",className:"w-full",children:s.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[s.jsx("div",{className:"mb-4",children:s.jsx("h1",{className:"typography-ui-header font-semibold text-foreground",children:t("settings.providers.page.connect.title")})}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h2",{className:"typography-ui-header font-medium text-foreground",children:t("settings.providers.page.connect.selectProviderTitle")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsxs("div",{className:"flex flex-wrap items-center gap-2 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.providers.page.connect.providerField")}),A?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.state.loading")}):E?s.jsx("p",{className:"typography-meta text-muted-foreground",children:E}):re.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.connect.allProvidersConnected")}):s.jsxs(As,{open:F,onOpenChange:ne=>{_(ne),ne||$("")},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:[O?s.jsx(xr,{providerId:O,className:"h-3.5 w-3.5 flex-shrink-0"}):null,s.jsx("span",{className:ye("truncate typography-ui-label font-normal",O?"text-foreground":"text-muted-foreground"),children:O?re.find(ne=>ne.id===O)?.name||O:t("settings.providers.page.connect.selectProviderPlaceholder")})]}),s.jsx(D,{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:ne=>ne.preventDefault(),children:[s.jsxs("div",{className:"flex items-center gap-2 border-b border-[var(--surface-subtle)] px-3 py-2",onKeyDown:ne=>ne.stopPropagation(),children:[s.jsx(D,{name:"search",className:"h-4 w-4 text-muted-foreground"}),s.jsx("input",{type:"text",value:B,onChange:ne=>$(ne.target.value),onKeyDown:ne=>ne.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(ws,{outerClassName:"max-h-[240px]",className:"p-1",children:(()=>{const ne=re.filter(pe=>{const J=B.toLowerCase();return(pe.name||pe.id).toLowerCase().includes(J)||pe.id.toLowerCase().includes(J)});return ne.length===0?s.jsx("p",{className:"py-4 text-center typography-meta text-muted-foreground",children:t("settings.providers.page.connect.noProvidersFound")}):ne.map(pe=>s.jsxs(Ot,{onSelect:()=>{V(pe.id),_(!1),$("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(xr,{providerId:pe.id,className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:pe.name||pe.id})]}),O===pe.id&&s.jsx(D,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},pe.id))})()})]})]})]})})]}),O&&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(D,{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(Bt,{type:"password",value:b[O]??"",onChange:ne=>g(pe=>({...pe,[O]:ne.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(ve,{size:"xs",className:"!font-normal shrink-0",onClick:()=>H(O),disabled:v===`api:${O}`,children:v===`api:${O}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}),(()=>{const pe=(p[O]??[]).filter(J=>Ip(J)==="oauth");return pe.length===0?null:s.jsx("div",{className:"space-y-4 border-t border-[var(--surface-subtle)] pt-2",children:pe.map((J,Se)=>{const he=J.label||J.name||t("settings.providers.page.auth.oauthMethodFallback",{index:String(Se+1)}),Ie=`${O}:${Se}`,Pe=y?.providerId===O&&y?.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:he}),(J.description||J.help)&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:String(J.description||J.help)})]}),s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>K(O,Se),disabled:v===`oauth:${O}:${Se}`,children:t("settings.providers.page.actions.connect")})]}),S[Ie]?.instructions&&s.jsx("p",{className:"typography-meta text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-2 py-1.5 rounded",children:S[Ie]?.instructions}),S[Ie]?.userCode&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Bt,{value:S[Ie]?.userCode,readOnly:!0,className:"font-mono text-center tracking-widest"}),s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>de(S[Ie]?.userCode??""),children:t("settings.providers.page.actions.copyCode")})]}),S[Ie]?.url&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Bt,{value:S[Ie]?.url,readOnly:!0,className:"text-xs text-muted-foreground"}),s.jsxs("div",{className:"flex gap-1 shrink-0",children:[s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Zn(S[Ie]?.url??""),children:t("settings.providers.page.actions.open")}),s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>W(S[Ie]?.url??""),children:t("settings.providers.page.actions.copy")})]})]}),Pe&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Bt,{value:k[Ie]??"",onChange:Ce=>w(X=>({...X,[Ie]:Ce.target.value})),placeholder:t("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs"}),s.jsx(ve,{size:"xs",className:"!font-normal",onClick:()=>Q(O,Se),disabled:v===`oauth-complete:${O}:${Se}`,children:v===`oauth-complete:${O}:${Se}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.complete")})]})]},`${O}-${he}`)})})})()]})]})]})});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(D,{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:[],ue=(p[me.id]??[]).filter(ne=>Ip(ne)==="oauth"),xe=te.filter(ne=>{const pe=typeof ne?.name=="string"?ne.name:"",J=typeof ne?.id=="string"?ne.id:"",Se=h.trim().toLowerCase();return Se?pe.toLowerCase().includes(Se)||J.toLowerCase().includes(Se):!0});return s.jsx(ws,{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(xr,{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(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Z(ne=>!ne),children:t(Y?"settings.providers.page.actions.hide":"settings.providers.page.actions.reconnect")})]}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:Y?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(D,{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(Bt,{type:"password",value:b[me.id]??"",onChange:ne=>g(pe=>({...pe,[me.id]:ne.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(ve,{size:"xs",className:"!font-normal shrink-0",onClick:()=>H(me.id),disabled:v===`api:${me.id}`,children:v===`api:${me.id}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}),ue.length>0&&s.jsx("div",{className:"space-y-4 border-t border-[var(--surface-subtle)] pt-2",children:ue.map((ne,pe)=>{const J=ne.label||ne.name||t("settings.providers.page.auth.oauthMethodFallback",{index:String(pe+1)}),Se=`${me.id}:${pe}`,he=y?.providerId===me.id&&y?.methodIndex===pe;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:J}),(ne.description||ne.help)&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:String(ne.description||ne.help)})]}),s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>K(me.id,pe),disabled:v===`oauth:${me.id}:${pe}`,children:t("settings.providers.page.actions.connect")})]}),S[Se]?.instructions&&s.jsx("p",{className:"typography-meta text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-2 py-1.5 rounded",children:S[Se]?.instructions}),S[Se]?.userCode&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Bt,{value:S[Se]?.userCode,readOnly:!0,className:"font-mono text-center tracking-widest"}),s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>de(S[Se]?.userCode??""),children:t("settings.providers.page.actions.copyCode")})]}),S[Se]?.url&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Bt,{value:S[Se]?.url,readOnly:!0,className:"text-xs text-muted-foreground"}),s.jsxs("div",{className:"flex gap-1 shrink-0",children:[s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Zn(S[Se]?.url??""),children:t("settings.providers.page.actions.open")}),s.jsx(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>W(S[Se]?.url??""),children:t("settings.providers.page.actions.copy")})]})]}),he&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Bt,{value:k[Se]??"",onChange:Ie=>w(Pe=>({...Pe,[Se]:Ie.target.value})),placeholder:t("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs"}),s.jsx(ve,{size:"xs",className:"!font-normal",onClick:()=>Q(me.id,pe),disabled:v===`oauth-complete:${me.id}:${pe}`,children:v===`oauth-complete:${me.id}:${pe}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.complete")})]})]},`${me.id}-${J}`)})})]}):s.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[s.jsx(D,{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:fe&&(fe.auth.exists||fe.user.exists||fe.project.exists||fe.custom?.exists)?s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[t("settings.providers.page.connectionDetails.configuredIn")," ",[fe.auth.exists?t("settings.providers.page.connectionDetails.source.authCredentials"):null,fe.user.exists?t("settings.providers.page.connectionDetails.source.userConfig"):null,fe.project.exists?t("settings.providers.page.connectionDetails.source.projectConfig"):null,fe.custom?.exists?t("settings.providers.page.connectionDetails.source.customConfig"):null].filter(Boolean).join(", ")]}):s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.connectionDetails.noActiveSource")})}),s.jsx(ve,{variant:"ghost",size:"xs",className:"!font-normal text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>be(me.id),disabled:v===`disconnect:${me.id}`,children:v===`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(ve,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const ne=te.map(pe=>typeof pe?.id=="string"?pe.id:"").filter(pe=>pe.length>0);c(me.id,ne)},children:t("settings.providers.page.actions.hideAll")}),s.jsx(ve,{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(D,{name:"search",className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Bt,{value:h,onChange:ne=>j(ne.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(ne=>{const pe=typeof ne?.id=="string"?ne.id:"",J=typeof ne?.name=="string"?ne.name:pe,Se=pe?a(me.id,pe):void 0,he=i.some(X=>X.providerID===me.id&&X.modelID===pe),Ie=Cp(Se?.limit?.context),Pe=Cp(Se?.limit?.output),Ce=[];return Se?.tool_call&&Ce.push({key:"tools",icon:"tools",label:t("settings.providers.page.models.capability.toolCalling")}),Se?.reasoning&&Ce.push({key:"reasoning",icon:"brain-ai-3",label:t("settings.providers.page.models.capability.reasoning")}),Se?.attachment&&Ce.push({key:"image",icon:"file-image",label:t("settings.providers.page.models.capability.imageInput")}),s.jsx("div",{className:"py-1.5",children:s.jsxs("div",{className:ye("flex items-center gap-3",he&&"opacity-50"),children:[s.jsx("span",{className:"typography-meta font-medium text-foreground truncate flex-1 min-w-0",children:J}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[(Ie||Pe)&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex-shrink-0 bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:[Ie?`${Ie} ${t("settings.providers.page.models.tokenBadge.context")}`:"",Ie&&Pe?" · ":"",Pe?`${Pe} ${t("settings.providers.page.models.tokenBadge.output")}`:""]}),Ce.length>0&&s.jsx("div",{className:"flex items-center gap-1 flex-shrink-0",children:Ce.map(({key:X,icon:ie,label:Ne})=>s.jsx("span",{className:"flex h-5 w-5 rounded items-center justify-center text-muted-foreground bg-[var(--surface-muted)]",title:Ne,"aria-label":Ne,children:s.jsx(D,{name:ie,className:"h-3 w-3"})},X))}),s.jsx("button",{type:"button",onClick:()=>l(me.id,pe),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(he?"settings.providers.page.models.actions.showModelInSelectors":"settings.providers.page.models.actions.hideModelFromSelectors"),"aria-label":t(he?"settings.providers.page.models.actions.showModel":"settings.providers.page.models.actions.hideModel"),children:he?s.jsx(D,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(D,{name:"eye",className:"h-3.5 w-3.5"})})]})]})},pe)})})]})]})]})})},p5=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)},f5=t=>{const e=ot.c(106),{onItemSelect:n}=t,{t:r}=ut(),a=Es(h5),i=Es(g5),l=Es(x5),c=Es(b5),d=Es(y5),p=Es(v5),m=Es(w5),u=Es(j5),f=Es(N5),b=Es(S5),g=Es(k5),v=Es(C5);let x,h;e[0]!==v?(x=()=>{v()},h=[v],e[0]=v,e[1]=x,e[2]=h):(x=e[1],h=e[2]),o.useEffect(x,h);const j=I5;let y;e[3]!==f?(y=ie=>{f(ie),j({usageAutoRefresh:ie})},e[3]=f,e[4]=y):y=e[4];const C=y;let k;e[5]!==b?(k=ie=>{const Ne=Number(ie);Number.isFinite(Ne)&&(b(Ne),j({usageRefreshIntervalMs:Ne}))},e[5]=b,e[6]=k):k=e[6];const w=k;let S;e[7]!==g?(S=ie=>{ie!=="usage"&&ie!=="remaining"||(g(ie),j({usageDisplayMode:ie}))},e[7]=g,e[8]=S):S=e[8];const I=S;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 A;e[12]!==P?(A=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:P}),e[12]=P,e[13]=A):A=e[13];let N;e[14]!==r?(N=r("settings.usage.sidebar.total",{count:Wr.length}),e[14]=r,e[15]=N):N=e[15];let E;e[16]!==N?(E=s.jsx("span",{className:"typography-meta text-muted-foreground",children:N}),e[16]=N,e[17]=E):E=e[17];let M;e[18]!==r?(M=r("settings.usage.sidebar.actions.toggleAutoRefreshAria"),e[18]=r,e[19]=M):M=e[19];let O;e[20]!==C||e[21]!==M||e[22]!==p?(O=s.jsx(Ct,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(xs,{checked:p,onChange:C,ariaLabel:M})})}),e[20]=C,e[21]=M,e[22]=p,e[23]=O):O=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]!==O||e[29]!==B?($=s.jsxs(kt,{children:[O,B]}),e[28]=O,e[29]=B,e[30]=$):$=e[30];const F=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(os,{className:"w-fit",children:s.jsx(us,{placeholder:q})}),e[33]=q,e[34]=L):L=e[34];let Y;e[35]===Symbol.for("react.memo_cache_sentinel")?(Y=s.jsxs(ls,{children:[s.jsx(Mt,{value:"30000",children:"30s"}),s.jsx(Mt,{value:"60000",children:"1m"}),s.jsx(Mt,{value:"300000",children:"5m"})]}),e[35]=Y):Y=e[35];let Z;e[36]!==w||e[37]!==F||e[38]!==_||e[39]!==L?(Z=s.jsxs(is,{value:F,onValueChange:w,disabled:_,children:[L,Y]}),e[36]=w,e[37]=F,e[38]=_,e[39]=L,e[40]=Z):Z=e[40];let ae;e[41]!==c?(ae=()=>c(),e[41]=c,e[42]=ae):ae=e[42];let re;e[43]!==r?(re=r("settings.usage.sidebar.actions.refreshAria"),e[43]=r,e[44]=re):re=e[44];let me;e[45]!==r?(me=r("settings.usage.sidebar.actions.refreshTitle"),e[45]=r,e[46]=me):me=e[46];const fe=d&&"animate-spin";let H;e[47]!==fe?(H=ye("h-3.5 w-3.5",fe),e[47]=fe,e[48]=H):H=e[48];let K;e[49]!==H?(K=s.jsx(D,{name:"refresh",className:H}),e[49]=H,e[50]=K):K=e[50];let Q;e[51]!==d||e[52]!==ae||e[53]!==re||e[54]!==me||e[55]!==K?(Q=s.jsx(ve,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 text-muted-foreground",onClick:ae,"aria-label":re,title:me,disabled:d,children:K}),e[51]=d,e[52]=ae,e[53]=re,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]!==E||e[62]!==W?(de=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[E,W]}),e[61]=E,e[62]=W,e[63]=de):de=e[63];let be;e[64]!==r?(be=r("settings.usage.sidebar.field.display"),e[64]=r,e[65]=be):be=e[65];let we;e[66]!==be?(we=s.jsx("span",{className:"typography-micro text-muted-foreground",children:be}),e[66]=be,e[67]=we):we=e[67];let te;e[68]!==r?(te=r("settings.usage.sidebar.field.displayModePlaceholder"),e[68]=r,e[69]=te):te=e[69];let ge;e[70]!==te?(ge=s.jsx(os,{className:"w-fit",children:s.jsx(us,{placeholder:te})}),e[70]=te,e[71]=ge):ge=e[71];let ue;e[72]!==r?(ue=r("settings.usage.sidebar.field.displayModeUsage"),e[72]=r,e[73]=ue):ue=e[73];let xe;e[74]!==ue?(xe=s.jsx(Mt,{value:"usage",children:ue}),e[74]=ue,e[75]=xe):xe=e[75];let ne;e[76]!==r?(ne=r("settings.usage.sidebar.field.displayModeRemaining"),e[76]=r,e[77]=ne):ne=e[77];let pe;e[78]!==ne?(pe=s.jsx(Mt,{value:"remaining",children:ne}),e[78]=ne,e[79]=pe):pe=e[79];let J;e[80]!==xe||e[81]!==pe?(J=s.jsxs(ls,{children:[xe,pe]}),e[80]=xe,e[81]=pe,e[82]=J):J=e[82];let Se;e[83]!==I||e[84]!==ge||e[85]!==J||e[86]!==u?(Se=s.jsxs(is,{value:u,onValueChange:I,children:[ge,J]}),e[83]=I,e[84]=ge,e[85]=J,e[86]=u,e[87]=Se):Se=e[87];let he;e[88]!==we||e[89]!==Se?(he=s.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[we,Se]}),e[88]=we,e[89]=Se,e[90]=he):he=e[90];let Ie;e[91]!==de||e[92]!==he||e[93]!==A?(Ie=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[A,de,he]}),e[91]=de,e[92]=he,e[93]=A,e[94]=Ie):Ie=e[94];let Pe;e[95]!==n||e[96]!==a||e[97]!==i||e[98]!==l||e[99]!==r?(Pe=Wr.map(ie=>{const Ne=a.find(ee=>ee.providerId===ie.id),oe=p5(Ne?.usage),ke=jh(oe),Te=ie.id===i,Be=Ne?.configured??!1,je=Be?ke==="critical"?{backgroundColor:"var(--status-error)"}:ke==="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",Te?"bg-interactive-selection":"hover:bg-interactive-hover"),children:s.jsxs("button",{type:"button",onClick:()=>{l(ie.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:je}),s.jsx(xr,{providerId:ie.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:ie.name}),!Be&&s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:r("settings.usage.sidebar.status.notSet")})]})},ie.id)}),e[95]=n,e[96]=a,e[97]=i,e[98]=l,e[99]=r,e[100]=Pe):Pe=e[100];let Ce;e[101]!==Pe?(Ce=s.jsx(ws,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:Pe}),e[101]=Pe,e[102]=Ce):Ce=e[102];let X;return e[103]!==Ie||e[104]!==Ce?(X=s.jsxs("div",{className:T,children:[Ie,Ce]}),e[103]=Ie,e[104]=Ce,e[105]=X):X=e[105],X};function h5(t){return t.results}function g5(t){return t.selectedProviderId}function x5(t){return t.setSelectedProvider}function b5(t){return t.fetchAllQuotas}function y5(t){return t.isLoading}function v5(t){return t.autoRefresh}function w5(t){return t.refreshIntervalMs}function j5(t){return t.displayMode}function N5(t){return t.setAutoRefresh}function S5(t){return t.setRefreshInterval}function k5(t){return t.setDisplayMode}function C5(t){return t.loadSettings}async function I5(t){try{await Ss(t)}catch(e){console.warn("Failed to save usage settings:",e)}}const Rc=t=>{const e=ot.c(52),{title:n,window:r,subtitle:a,showToggle:i,toggleEnabled:l,onToggle:c}=t,d=i===void 0?!1:i,p=l===void 0?!1:l,m=Es(P5),u=m==="remaining"?r.remainingPercent:r.usedPercent,f=m==="remaining"?"remaining":"used";let b;e[0]!==u||e[1]!==r.valueLabel?(b=oo(r.valueLabel,u),e[0]=u,e[1]=r.valueLabel,e[2]=b):b=e[2];const g=b,v=r.resetAfterFormatted??r.resetAtFormatted;let x;e[3]!==v||e[4]!==r.resetAt?(x=Hd(r.resetAt,v),e[3]=v,e[4]=r.resetAt,e[5]=x):x=e[5];const h=x;let j;e[6]!==n?(j=Gd(n),e[6]=n,e[7]=j):j=e[7];const y=j;let C;e[8]!==n||e[9]!==r.resetAt||e[10]!==r.usedPercent||e[11]!==r.windowSeconds?(C=lo(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=ea(k.elapsedRatio);w=m==="remaining"?100-Z:Z}const S=w;let I;e[13]!==c||e[14]!==d||e[15]!==p?(I=d&&s.jsx(xs,{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]!==y?(T=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:y}),e[17]=y,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 A;e[21]!==T||e[22]!==P?(A=s.jsxs("div",{className:"min-w-0 flex flex-col",children:[T,P]}),e[21]=T,e[22]=P,e[23]=A):A=e[23];let N;e[24]!==A||e[25]!==I?(N=s.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[I,A]}),e[24]=A,e[25]=I,e[26]=N):N=e[26];const E=g==="-"?"":g;let M;e[27]!==E?(M=s.jsx("div",{className:"typography-ui-label text-foreground tabular-nums flex items-center justify-end",children:E}),e[27]=E,e[28]=M):M=e[28];let O;e[29]!==N||e[30]!==M?(O=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[N,M]}),e[29]=N,e[30]=M,e[31]=O):O=e[31];let V;e[32]!==u||e[33]!==S||e[34]!==r.usedPercent?(V=s.jsx(uo,{percent:u,tonePercent:r.usedPercent,expectedMarkerPercent:S,className:"h-1.5"}),e[32]=u,e[33]=S,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 F;e[38]!==f?(F=s.jsx("span",{className:"typography-micro text-muted-foreground",children:f}),e[38]=f,e[39]=F):F=e[39];let _;e[40]!==$||e[41]!==F?(_=s.jsxs("div",{className:"mt-1 flex items-center justify-between",children:[$,F]}),e[40]=$,e[41]=F,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(mo,{paceInfo:k})}),e[46]=k,e[47]=L):L=e[47];let Y;return e[48]!==O||e[49]!==q||e[50]!==L?(Y=s.jsxs("div",{className:"py-3",children:[O,q,L]}),e[48]=O,e[49]=q,e[50]=L,e[51]=Y):Y=e[51],Y};function P5(t){return t.displayMode}const A5=t=>{if(!t)return"-";try{return new Date(t).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"})}catch{return"-"}},D5=()=>{const{t}=ut(),e=Es(N=>N.results),n=Es(N=>N.selectedProviderId),r=Es(N=>N.setSelectedProvider),a=Es(N=>N.loadSettings),i=Es(N=>N.fetchAllQuotas),l=Es(N=>N.isLoading),c=Es(N=>N.lastUpdated),d=Es(N=>N.error),p=Es(N=>N.dropdownProviderIds),m=Es(N=>N.setDropdownProviderIds),u=Es(N=>N.selectedModels),f=Es(N=>N.toggleModelSelected),b=Es(N=>N.applyDefaultSelections);Ih(),o.useEffect(()=>{a(),i()},[a,i]),o.useEffect(()=>{if(n||e.length===0)return;const N=e.find(E=>E.configured)?.providerId;r(N??Wr[0]?.id??null)},[e,n,r]);const g=e.find(N=>N.providerId===n)??null,x=Wr.find(N=>N.id===n)?.name??n??t("settings.usage.sidebar.title"),h=g?.usage,j=n?p.includes(n):!1,y=o.useCallback(N=>{if(!n)return;const E=N?Array.from(new Set([...p,n])):p.filter(M=>M!==n);m(E),Ss({usageDropdownProviders:E})},[p,n,m]),C=o.useMemo(()=>h?.models?Object.entries(h.models).map(([N,E])=>({name:N,windows:E})).filter(N=>Object.keys(N.windows.windows).length>0):[],[h?.models]);o.useEffect(()=>{n&&C.length>0&&b(n,C.map(N=>N.name))},[n,C,b]);const k=o.useMemo(()=>!n||C.length===0?new Map:Wv(C,N=>N.name,n),[C,n]),w=o.useMemo(()=>{if(!n)return[];const N=kh(n);return Ch(N)},[n]),[S,I]=o.useState(()=>({})),T=o.useCallback(N=>{I(E=>({...E,[N]:!E[N]}))},[]),P=o.useCallback(N=>{if(!n)return;f(n,N);const E=u[n]??[],O=E.includes(N)?E.filter(B=>B!==N):[...E,N],V={...u,[n]:O};Ss({usageSelectedModels:V})},[n,u,f]),A=n?u[n]??[]:[];return n?s.jsx(ws,{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(xr,{providerId:n,className:"h-5 w-5 shrink-0"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:t("settings.usage.page.header.providerUsage",{provider:x})}),s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:l?s.jsx("span",{className:"animate-pulse",children:t("settings.usage.page.header.refreshing")}):t("settings.usage.page.header.lastUpdated",{time:A5(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:()=>y(!j),onKeyDown:N=>{(N.key===" "||N.key==="Enter")&&(N.preventDefault(),y(!j))},children:[s.jsx(xs,{checked:j,onChange:y,ariaLabel:t("settings.usage.page.options.showInHeaderAria")}),s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.usage.page.options.showInHeader")}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(D,{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")})]})]})]})}),!g&&s.jsx("div",{className:"mb-8 px-2",children:s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.usage.page.state.noData")})}),d&&s.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-4 py-3",children:[s.jsx("p",{className:"typography-ui-label font-medium text-[var(--status-error)]",children:t("settings.usage.page.state.refreshFailedTitle")}),s.jsx("p",{className:"typography-meta text-[var(--status-error)]/80 mt-1",children:d})]}),g&&!g.configured&&s.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] px-4 py-3",children:[s.jsx("p",{className:"typography-ui-label font-medium text-[var(--status-warning)]",children:t("settings.usage.page.state.providerNotConfiguredTitle")}),s.jsx("p",{className:"typography-meta text-[var(--status-warning)]/80 mt-1",children:t("settings.usage.page.state.providerNotConfiguredDescription")})]}),h?.windows&&Object.keys(h.windows).length>0&&s.jsx("div",{className:"mb-8",children:s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:Object.entries(h.windows).map(([N,E])=>s.jsx(Rc,{title:N,window:E},N))})})}),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(N=>{const E=k.get(N.id)??[];if(E.length===0)return null;const M=S[N.id]??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(br,{open:!M,onOpenChange:()=>T(N.id),children:[s.jsxs(Tr,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:N.label}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",E.length,")"]})]}),M?s.jsx(D,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(D,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(yr,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:E.map(O=>{const V=Object.entries(O.windows.windows);if(V.length===0)return null;const[B,$]=V[0],F=A.includes(O.name);return s.jsx(Rc,{title:B,subtitle:bl(O.name),window:$,showToggle:!0,toggleEnabled:F,onToggle:()=>P(O.name)},O.name)})})})]})},N.id)}),(()=>{const N=k.get(null)??[];if(N.length===0)return null;const E=S.other??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(br,{open:!E,onOpenChange:()=>T("other"),children:[s.jsxs(Tr,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:t("settings.usage.page.section.otherModels")}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",N.length,")"]})]}),E?s.jsx(D,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(D,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(yr,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:N.map(M=>{const O=Object.entries(M.windows.windows);if(O.length===0)return null;const[V,B]=O[0],$=A.includes(M.name);return s.jsx(Rc,{title:V,subtitle:bl(M.name),window:B,showToggle:!0,toggleEnabled:$,onToggle:()=>P(M.name)},M.name)})})})]})})})()]})]}),g?.configured&&h&&Object.keys(h.windows??{}).length===0&&C.length===0&&s.jsxs("div",{className:"mb-8 px-2",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.usage.page.state.noQuotaWindowsTitle")}),s.jsx("p",{className:"typography-meta text-muted-foreground mt-1",children:t("settings.usage.page.state.noQuotaWindowsDescription")})]})]})}):s.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground",children:s.jsx("p",{className:"typography-body",children:t("settings.usage.page.empty.selectProvider")})})},T5="git.commit.generate",vd=rr(t=>({selectedPromptId:T5,setSelectedPromptId:e=>{t(n=>n.selectedPromptId===e?n:{selectedPromptId:e})}})),M5=t=>{const e=ot.c(23),{onItemSelect:n}=t,{t:r}=ut(),a=vd(E5),i=vd(R5);let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l={groupKey:"settings.magicPrompts.sidebar.group.git",items:[{id:"git.commit.generate",titleKey:"settings.magicPrompts.sidebar.item.gitCommitGenerate"},{id:"git.pr.generate",titleKey:"settings.magicPrompts.sidebar.item.gitPrGenerate"},{id:"git.conflict.resolve",titleKey:"settings.magicPrompts.sidebar.item.gitConflictResolve"},{id:"git.integrate.cherrypick.resolve",titleKey:"settings.magicPrompts.sidebar.item.gitCherrypickConflictResolve"}]},e[0]=l):l=e[0];let c;e[1]===Symbol.for("react.memo_cache_sentinel")?(c={groupKey:"settings.magicPrompts.sidebar.group.github",items:[{id:"github.pr.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrReview"},{id:"github.issue.review",titleKey:"settings.magicPrompts.sidebar.item.githubIssueReview"},{id:"github.pr.checks.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrFailedChecksReview"},{id:"github.pr.comments.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrCommentsReview"},{id:"github.pr.comment.single",titleKey:"settings.magicPrompts.sidebar.item.githubSinglePrCommentReview"}]},e[1]=c):c=e[1];let d;e[2]===Symbol.for("react.memo_cache_sentinel")?(d={groupKey:"settings.magicPrompts.sidebar.group.planning",items:[{id:"plan.todo",titleKey:"settings.magicPrompts.sidebar.item.planTodo"},{id:"plan.improve",titleKey:"settings.magicPrompts.sidebar.item.planImprove"},{id:"plan.implement",titleKey:"settings.magicPrompts.sidebar.item.planImplement"}]},e[2]=d):d=e[2];let p;e[3]===Symbol.for("react.memo_cache_sentinel")?(p=[l,c,d,{groupKey:"settings.magicPrompts.sidebar.group.session",items:[{id:"session.summary",titleKey:"settings.magicPrompts.sidebar.item.sessionSummary"},{id:"session.review",titleKey:"settings.magicPrompts.sidebar.item.sessionWorkspaceReview"},{id:"session.fusion",titleKey:"settings.magicPrompts.sidebar.item.sessionFusion"}]}],e[3]=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 g;e[10]!==b?(g=s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:b}),e[10]=b,e[11]=g):g=e[11];let v;e[12]!==f||e[13]!==g?(v=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[f,g]}),e[12]=f,e[13]=g,e[14]=v):v=e[14];let x;e[15]!==n||e[16]!==a||e[17]!==i||e[18]!==r?(x=s.jsx(ws,{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(y=>{const C=a===y.id;return s.jsx("button",{type:"button",onClick:()=>{i(y.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(y.titleKey)})},y.id)})]},j.groupKey))}),e[15]=n,e[16]=a,e[17]=i,e[18]=r,e[19]=x):x=e[19];let h;return e[20]!==x||e[21]!==v?(h=s.jsxs("div",{className:"flex h-full flex-col bg-background",children:[v,x]}),e[20]=x,e[21]=v,e[22]=h):h=e[22],h};function E5(t){return t.selectedPromptId}function R5(t){return t.setSelectedPromptId}const Pp={"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"}]}},Ap=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),Dp=t=>t.endsWith(".visible"),F5=()=>{const{t}=ut(),e=o.useCallback(w=>t(w),[t]),n=vd(w=>w.selectedPromptId),[r,a]=o.useState(!0),[i,l]=o.useState({}),[c,d]=o.useState({}),[p,m]=o.useState({}),[u,f]=o.useState({}),[b,g]=o.useState(!1);o.useEffect(()=>{let w=!0;return(async()=>{a(!0);try{const I=await qb();if(!w)return;l(I)}catch(I){console.warn("Failed to load magic prompts:",I),G.error(t("settings.magicPrompts.page.toast.loadFailed"))}finally{w&&a(!1)}})(),()=>{w=!1}},[t]);const v=Pp[n]??Pp["git.commit.generate"],x=o.useCallback(w=>Ap(i,w)?i[w]:tc(w),[i]),h=o.useCallback(w=>c[w]??x(w),[c,x]),j=o.useCallback((w,S)=>{d(I=>I[w]===S?I:{...I,[w]:S})},[]),y=o.useCallback(async w=>{const S=h(w);if(Dp(w)&&S.trim().length===0){G.error(t("settings.magicPrompts.page.toast.visiblePromptRequired"));return}m(I=>({...I,[w]:!0}));try{const I=S===tc(w)?await Au(w):await Kb(w,S);l(I.overrides),G.success(t("settings.magicPrompts.page.toast.saved"))}catch(I){const T=I instanceof Error?I.message:String(I);G.error(t("settings.magicPrompts.page.toast.saveFailed"),{description:T})}finally{m(I=>({...I,[w]:!1}))}},[h,t]),C=o.useCallback(async w=>{f(S=>({...S,[w]:!0}));try{const S=await Au(w);l(S.overrides),d(I=>({...I,[w]:tc(w)})),G.success(t("settings.magicPrompts.page.toast.resetSuccess"))}catch(S){const I=S instanceof Error?S.message:String(S);G.error(t("settings.magicPrompts.page.toast.resetFailed"),{description:I})}finally{f(S=>({...S,[w]:!1}))}},[t]),k=o.useCallback(async()=>{g(!0);try{const w=await Hb();l(w.overrides),d({}),G.success(t("settings.magicPrompts.page.toast.resetAllSuccess"))}catch(w){const S=w instanceof Error?w.message:String(w);G.error(t("settings.magicPrompts.page.toast.resetAllFailed"),{description:S})}finally{g(!1)}},[t]);return r?s.jsxs("div",{className:"py-6 px-6 flex items-center gap-2 text-muted-foreground",children:[s.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-current animate-busy-pulse","aria-label":t("settings.magicPrompts.page.loading.aria")}),s.jsx("span",{className:"typography-ui",children:t("settings.magicPrompts.page.loading.text")})]}):s.jsx("div",{className:"h-full overflow-auto",children:s.jsxs("div",{className:"mx-auto w-full max-w-4xl px-6 py-6 space-y-4",children:[s.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[s.jsx("div",{className:"space-y-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground",children:e(v.titleKey)}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(D,{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(v.descriptionKey)})]})]})}),s.jsx(ve,{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")})]}),v.blocks.map((w,S)=>{const I=Gb(w.id),T=x(w.id),P=h(w.id),A=Ap(i,w.id),N=P!==T,E=Dp(w.id)&&P.trim().length===0,M=p[w.id]===!0,O=u[w.id]===!0;return s.jsxs("section",{className:S>0?"space-y-3 pt-5 border-t border-border":"space-y-3",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-label text-foreground",children:e(w.titleKey)}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(D,{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(jn,{value:P,onChange:V=>j(w.id,V.target.value),className:"min-h-[220px] font-mono text-sm"}),E&&s.jsx("div",{className:"typography-micro text-[var(--status-error)]",children:t("settings.magicPrompts.page.validation.visiblePromptRequired")}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:t(N?"settings.magicPrompts.page.status.unsavedChanges":A?"settings.magicPrompts.page.status.usingSavedOverride":"settings.magicPrompts.page.status.usingBuiltinDefault")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ve,{variant:"outline",size:"sm",onClick:()=>{C(w.id)},disabled:!A||M||O,children:t(O?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetToDefault")}),s.jsx(ve,{size:"sm",onClick:()=>{y(w.id)},disabled:!N||M||O||E,children:t(M?"settings.common.actions.saving":"settings.magicPrompts.page.actions.save")})]})]})]},w.id)})]})})},O5=t=>{const e=ot.c(87),{onItemSelect:n}=t,{t:r}=ut(),[a,i]=o.useState(null),[l,c]=o.useState(null),{selectedSnippetName:d,snippets:p,setSelectedSnippet:m,setSnippetDraft:u,deleteSnippet:f,loadSnippets:b}=Ul(er(L5));let g,v;e[0]!==b?(g=()=>{b()},v=[b],e[0]=b,e[1]=g,e[2]=v):(g=e[1],v=e[2]),o.useEffect(g,v);let x;e[3]!==n||e[4]!==m||e[5]!==u||e[6]!==p?(x=async()=>{const we=new Set(p.map($5));let te="new-snippet",ge=1;for(;we.has(te);)te=`new-snippet-${ge++}`;u({name:te,scope:"global"}),m(te),n?.()},e[3]=n,e[4]=m,e[5]=u,e[6]=p,e[7]=x):x=e[7];const h=x;let j;e[8]!==a||e[9]!==f||e[10]!==r?(j=async()=>{if(!a)return;await f(a.name)?(G.success(r("settings.snippets.sidebar.toast.deleted")),i(null)):G.error(r("settings.snippets.sidebar.toast.deleteFailed"))},e[8]=a,e[9]=f,e[10]=r,e[11]=j):j=e[11];const y=j;let C;e[12]!==p?(C=[...p].sort(_5),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 S;e[15]!==r?(S=r("settings.snippets.sidebar.title"),e[15]=r,e[16]=S):S=e[16];let I;e[17]!==S?(I=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:S}),e[17]=S,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 A;e[24]!==r?(A=r("settings.snippets.sidebar.actions.create"),e[24]=r,e[25]=A):A=e[25];let N;e[26]===Symbol.for("react.memo_cache_sentinel")?(N=s.jsx(D,{name:"add",className:"h-3.5 w-3.5"}),e[26]=N):N=e[26];let E;e[27]!==h||e[28]!==A?(E=s.jsx(ve,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:h,"aria-label":A,children:N}),e[27]=h,e[28]=A,e[29]=E):E=e[29];let M;e[30]!==P||e[31]!==E?(M=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[P,E]}),e[30]=P,e[31]=E,e[32]=M):M=e[32];let O;e[33]!==M||e[34]!==I?(O=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[I,M]}),e[33]=M,e[34]=I,e[35]=O):O=e[35];let V;if(e[36]!==n||e[37]!==l||e[38]!==d||e[39]!==m||e[40]!==k||e[41]!==r){let we;e[43]!==n||e[44]!==l||e[45]!==d||e[46]!==m||e[47]!==r?(we=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:l===te.name,onOpenChange:ge=>c(ge?te.name:null),children:[s.jsx(Is,{asChild:!0,children:s.jsx(ve,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100","aria-label":r("settings.snippets.sidebar.actions.more",{name:te.name}),children:s.jsx(D,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Ps,{align:"end",className:"w-fit min-w-20",children:s.jsxs(Ot,{onClick:ge=>{ge.stopPropagation(),i(te)},className:"text-destructive focus:text-destructive",children:[s.jsx(D,{name:"delete-bin",className:"h-4 w-4 mr-px"}),r("settings.common.actions.delete")]})})]})]},`${te.source}:${te.filePath}`),e[43]=n,e[44]=l,e[45]=d,e[46]=m,e[47]=r,e[48]=we):we=e[48],V=k.map(we),e[36]=n,e[37]=l,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(ws,{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 F;e[51]===Symbol.for("react.memo_cache_sentinel")?(F=we=>{we||i(null)},e[51]=F):F=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(fs,{children:_}),e[54]=_,e[55]=q):q=e[55];const L=a?.name??"";let Y;e[56]!==r||e[57]!==L?(Y=r("settings.snippets.sidebar.dialog.deleteDescription",{name:L}),e[56]=r,e[57]=L,e[58]=Y):Y=e[58];let Z;e[59]!==Y?(Z=s.jsx(Ns,{children:Y}),e[59]=Y,e[60]=Z):Z=e[60];let ae;e[61]!==q||e[62]!==Z?(ae=s.jsxs(gs,{children:[q,Z]}),e[61]=q,e[62]=Z,e[63]=ae):ae=e[63];let re;e[64]===Symbol.for("react.memo_cache_sentinel")?(re=()=>i(null),e[64]=re):re=e[64];let me;e[65]!==r?(me=r("settings.common.actions.cancel"),e[65]=r,e[66]=me):me=e[66];let fe;e[67]!==me?(fe=s.jsx(ve,{size:"sm",variant:"ghost",onClick:re,children:me}),e[67]=me,e[68]=fe):fe=e[68];let H;e[69]!==r?(H=r("settings.common.actions.delete"),e[69]=r,e[70]=H):H=e[70];let K;e[71]!==y||e[72]!==H?(K=s.jsx(ve,{size:"sm",onClick:y,children:H}),e[71]=y,e[72]=H,e[73]=K):K=e[73];let Q;e[74]!==fe||e[75]!==K?(Q=s.jsxs(Hs,{children:[fe,K]}),e[74]=fe,e[75]=K,e[76]=Q):Q=e[76];let W;e[77]!==ae||e[78]!==Q?(W=s.jsxs(ms,{className:"max-w-md",children:[ae,Q]}),e[77]=ae,e[78]=Q,e[79]=W):W=e[79];let de;e[80]!==$||e[81]!==W?(de=s.jsx(ps,{open:$,onOpenChange:F,children:W}),e[80]=$,e[81]=W,e[82]=de):de=e[82];let be;return e[83]!==O||e[84]!==B||e[85]!==de?(be=s.jsxs("div",{className:w,children:[O,B,de]}),e[83]=O,e[84]=B,e[85]=de,e[86]=be):be=e[86],be};function L5(t){return{selectedSnippetName:t.selectedSnippetName,snippets:t.snippets,setSelectedSnippet:t.setSelectedSnippet,setSnippetDraft:t.setSnippetDraft,deleteSnippet:t.deleteSnippet,loadSnippets:t.loadSnippets}}function $5(t){return t.name}function _5(t,e){return t.name.localeCompare(e.name)}const B5=()=>{const{t}=ut(),{selectedSnippetName:e,snippets:n,snippetDraft:r,setSnippetDraft:a,updateSnippet:i,createSnippet:l}=Ul(er(I=>({selectedSnippetName:I.selectedSnippetName,snippets:I.snippets,snippetDraft:I.snippetDraft,setSnippetDraft:I.setSnippetDraft,updateSnippet:I.updateSnippet,createSnippet:I.createSnippet}))),c=o.useMemo(()=>e?n.find(I=>I.name===e||I.aliases.includes(e))??null:null,[e,n]),d=!!(r&&r.name===e&&!c),[p,m]=o.useState(""),[u,f]=o.useState("global"),[b,g]=o.useState(""),[v,x]=o.useState(""),[h,j]=o.useState(""),[y,C]=o.useState(!1),k=o.useRef(null);o.useEffect(()=>{if(d&&r){const I={draftName:r.name||"",draftScope:r.scope||"global",description:r.description||"",aliases:(r.aliases||[]).join(", "),content:r.content||""};m(I.draftName),f(I.draftScope),g(I.description),x(I.aliases),j(I.content),k.current=I}else if(c){const I={draftName:"",draftScope:"global",description:c.description??"",aliases:c.aliases.join(", "),content:c.content};g(I.description),x(I.aliases),j(I.content),k.current=I}},[c,d,e,r]);const w=o.useMemo(()=>{const I=k.current;return I?d&&p!==I.draftName||d&&u!==I.draftScope?!0:b!==I.description||v!==I.aliases||h!==I.content:!1},[v,h,b,p,u,d]),S=async()=>{const I=d?p.trim().replace(/\s+/g,"-"):e?.trim();if(!I){G.error(t("settings.snippets.page.toast.nameRequired"));return}if(!h.trim()){G.error(t("settings.snippets.page.toast.contentRequired"));return}const T=v.split(",").map(P=>P.trim()).filter(Boolean);C(!0);try{if(!(d?await l(I,h,{aliases:T,description:b,scope:u}):await i(I,{content:h,aliases:T,description:b}))){G.error(t("settings.snippets.page.toast.saveFailed"));return}G.success(t("settings.snippets.page.toast.saved")),d&&a(null)}finally{C(!1)}};return e?s.jsx(ws,{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(Bt,{value:p,onChange:I=>m(I.target.value),placeholder:t("settings.snippets.page.field.namePlaceholder"),className:"h-7 w-44 px-2"}),s.jsxs(is,{value:u,onValueChange:I=>f(I),children:[s.jsx(os,{className:"w-fit min-w-[100px]",children:s.jsx(us,{})}),s.jsxs(ls,{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(Bt,{value:b,onChange:I=>g(I.target.value),placeholder:t("settings.snippets.page.field.descriptionPlaceholder"),className:"mt-1.5 h-7 w-full max-w-sm px-2"})]}),s.jsxs("div",{children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.snippets.page.field.aliases")}),s.jsx(Bt,{value:v,onChange:I=>x(I.target.value),placeholder:t("settings.snippets.page.field.aliasesPlaceholder"),className:"mt-1.5 h-7 w-full max-w-sm px-2"})]})]}),s.jsxs("div",{className:"mb-2 px-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.snippets.page.field.content")}),s.jsx(jn,{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(ve,{onClick:S,disabled:y||!w,size:"xs",className:"!font-normal",children:t(y?"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(D,{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")})]})})},yg=()=>{const{t}=ut(),e=yt(u=>u.settingsGitmojiEnabled),n=yt(u=>u.setSettingsGitmojiEnabled),r=$d(),a=Re(u=>u.gitChangesViewMode),i=Re(u=>u.setGitChangesViewMode),[l,c]=o.useState(!0),d=o.useMemo(()=>[{id:"flat",label:t("settings.openchamber.git.option.flatList")},{id:"tree",label:t("settings.openchamber.git.option.treeView")}],[t]);o.useEffect(()=>{(async()=>{try{let f=null;if(!f){const b=nr()?.settings;if(b)try{const v=(await b.load())?.settings;v&&(f={gitmojiEnabled:typeof v.gitmojiEnabled=="boolean"?v.gitmojiEnabled:void 0,gitChangesViewMode:v.gitChangesViewMode==="flat"||v.gitChangesViewMode==="tree"?v.gitChangesViewMode:void 0})}catch{}}if(!f){const b=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});b.ok&&(f=await b.json())}f&&(typeof f.gitmojiEnabled=="boolean"&&n(f.gitmojiEnabled),(f.gitChangesViewMode==="flat"||f.gitChangesViewMode==="tree")&&i(f.gitChangesViewMode))}catch(f){console.warn("Failed to load git settings:",f)}finally{c(!1)}})()},[i,n]);const p=o.useCallback(async u=>{n(u);try{await Ss({gitmojiEnabled:u})}catch(f){console.warn("Failed to save gitmoji setting:",f)}},[n]),m=o.useCallback(u=>{u!==a&&(i(u),Ss({gitChangesViewMode:u}))},[a,i]);return l?null:s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.openchamber.git.title")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[s.jsxs("div",{className:"pt-1 pb-1",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:t("settings.openchamber.git.changesViewTitle")}),s.jsx("div",{role:"radiogroup","aria-label":t("settings.openchamber.git.changesViewAria"),className:"mt-0.5 space-y-0",children:d.map(u=>{const 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(ti,{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(xs,{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:()=>sc(!r),onKeyDown:u=>{(u.key===" "||u.key==="Enter")&&(u.preventDefault(),sc(!r))},children:[s.jsx(xs,{checked:r,onChange:sc,ariaLabel:t("settings.openchamber.git.showGitignoredAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.git.showGitignored")})]})]})]})},vg=()=>{const{t}=ut(),{isMobile:e}=an(),n=nr()?.github,r=Hn(I=>I.status),a=Hn(I=>I.isLoading),i=Hn(I=>I.hasChecked),l=Hn(I=>I.refreshStatus),c=Hn(I=>I.setStatus),d=o.useCallback(async I=>{await Zn(I)},[]),[p,m]=o.useState(!1),[u,f]=o.useState(null),[b,g]=o.useState(null),v=o.useRef(null),x=o.useCallback(()=>{v.current!=null&&(window.clearInterval(v.current),v.current=null),g(null)},[]);o.useEffect(()=>((async()=>{try{i||await l(n)}catch(I){console.warn("Failed to load GitHub auth status:",I)}})(),()=>{x()}),[i,l,n,x]);const h=o.useCallback(async()=>{m(!0);try{const I=n?await n.authStart():await(async()=>{const P=await fetch("/api/github/auth/start",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),A=await P.json().catch(()=>null);if(!P.ok||!A||!("deviceCode"in A))throw new Error(A?.error||P.statusText);return A})();f(I),g(Math.max(1,I.interval)*1e3);const T=I.verificationUriComplete||I.verificationUri;d(T)}catch(I){console.error("Failed to start GitHub connect:",I),G.error(t("settings.github.page.toast.startConnectFailed"))}finally{m(!1)}},[d,n,t]),j=o.useCallback(async I=>{if(n)return n.authComplete(I);const 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]);o.useEffect(()=>{if(!(!u?.deviceCode||!b)&&v.current==null)return v.current=window.setInterval(()=>{(async()=>{try{const I=await j(u.deviceCode);if(I.connected){G.success(t("settings.github.page.toast.connected")),f(null),x(),await l(n,{force:!0});return}I.status==="slow_down"&&g(T=>T?T+5e3:5e3),(I.status==="expired_token"||I.status==="access_denied")&&(G.error(I.error||t("settings.github.page.toast.authorizationFailed")),f(null),x())}catch(I){console.warn("GitHub polling failed:",I)}})()},b),()=>{v.current!=null&&(window.clearInterval(v.current),v.current=null)}},[u,b,j,l,n,x,t]);const y=o.useCallback(async()=>{m(!0);try{if(x(),f(null),n)await n.authDisconnect();else{const I=await fetch("/api/github/auth",{method:"DELETE",headers:{Accept:"application/json"}});if(!I.ok)throw new Error(I.statusText)}G.success(t("settings.github.page.toast.disconnected")),await l(n,{force:!0})}catch(I){console.error("Failed to disconnect GitHub:",I),G.error(t("settings.github.page.toast.disconnectFailed"))}finally{m(!1)}},[l,n,x,t]),C=o.useCallback(async I=>{if(I){m(!0);try{const 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})}),A=await P.json().catch(()=>null);if(!P.ok||!A)throw new Error(A?.error||P.statusText);return A})();c(T),G.success(t("settings.github.page.toast.accountSwitched"))}catch(T){console.error("Failed to switch GitHub account:",T),G.error(t("settings.github.page.toast.accountSwitchFailed"))}finally{m(!1)}}},[n,c,t]);if(a)return null;const k=!!r?.connected,w=r?.user,S=r?.accounts??[];return s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-3 px-1 flex items-start justify-between gap-4",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:"GitHub"}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(D,{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(D,{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(ve,{size:"sm",variant:"outline",onClick:y,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(ve,{size:"sm",variant:"default",onClick:h,disabled:p,children:t("settings.github.page.actions.connect")})]}),S.length>1&&s.jsxs("div",{className:"mt-2 border-t border-[var(--surface-subtle)] pt-2 px-2 pb-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground mb-2 px-1",children:t("settings.github.page.label.otherAccounts")}),s.jsx("div",{className:"space-y-1",children:S.map(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(D,{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(ve,{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(ve,{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(ve,{size:"sm",asChild:!0,children:s.jsx("a",{href:u.verificationUriComplete||u.verificationUri,target:"_blank",rel:"noopener noreferrer",children:t("settings.github.page.actions.openGithub")})})]}),s.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[s.jsx("span",{className:"typography-micro text-muted-foreground animate-pulse",children:t("settings.github.page.flow.waiting")}),s.jsx(ve,{size:"sm",variant:"ghost",disabled:p,onClick:()=>{x(),f(null)},children:t("settings.common.actions.cancel")})]})]})]})},Tp=[{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)"}],V5=[{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"}],z5=({open:t,onOpenChange:e,profileId:n,importData:r})=>{const{t:a}=ut(),i=Qn(L=>L.getProfileById),l=Qn(L=>L.createProfile),c=Qn(L=>L.updateProfile),d=Qn(L=>L.deleteProfile),p=o.useMemo(()=>n&&n!=="new"&&!r?i(n):null,[n,i,r]),m=n==="new"||r!=null,u=n==="global",[f,b]=o.useState(""),[g,v]=o.useState(""),[x,h]=o.useState(""),[j,y]=o.useState("ssh"),[C,k]=o.useState(""),[w,S]=o.useState(""),[I,T]=o.useState("keyword"),[P,A]=o.useState("branch"),[N,E]=o.useState(!1),[M,O]=o.useState(!1),[V,B]=o.useState(!1);o.useEffect(()=>{if(t){if(r){const L=r.host.split("/"),Y=L.length>=3?L[L.length-1]:r.host;b(Y),v(r.username),h(""),y("token"),k(""),S(r.host),T("string"),A("code")}else if(m)b(""),v(""),h(""),y("ssh"),k(""),S(""),T("keyword"),A("branch");else if(p)b(p.name),v(p.userName),h(p.userEmail),y(p.authType||"ssh"),k(p.sshKey||""),S(p.host||""),T(p.color||"keyword"),A(p.icon||"branch");else if(u){const L=i("global");L&&(b(L.name),v(L.userName),h(L.userEmail),y(L.authType||"ssh"),k(L.sshKey||""),S(L.host||""),T(L.color||"keyword"),A(L.icon||"branch"))}}},[t,n,p,m,r,u,i]);const $=async()=>{if(!g.trim()||!x.trim()){G.error(a("settings.gitIdentities.editor.toast.userNameEmailRequired"));return}if(j==="token"&&!w.trim()){G.error(a("settings.gitIdentities.editor.toast.hostRequiredForToken"));return}E(!0);try{const L={name:f.trim()||g.trim(),userName:g.trim(),userEmail:x.trim(),authType:j,sshKey:j==="ssh"&&C.trim()||null,host:j==="token"&&w.trim()||null,color:I,icon:P};let Y;if(m)Y=await l(L);else if(n)Y=await c(n,L);else return;Y?(G.success(a(m?"settings.gitIdentities.editor.toast.profileCreated":"settings.gitIdentities.editor.toast.profileUpdated")),e(!1)):G.error(a(m?"settings.gitIdentities.editor.toast.createProfileFailed":"settings.gitIdentities.editor.toast.updateProfileFailed"))}catch(L){console.error("Error saving profile:",L),G.error(a("settings.gitIdentities.editor.toast.saveUnexpectedError"))}finally{E(!1)}},F=async()=>{if(!(!n||m)){B(!0);try{await d(n)?(G.success(a("settings.gitIdentities.editor.toast.profileDeleted")),O(!1),e(!1)):G.error(a("settings.gitIdentities.editor.toast.deleteProfileFailed"))}catch(L){console.error("Error deleting profile:",L),G.error(a("settings.gitIdentities.editor.toast.deleteUnexpectedError"))}finally{B(!1)}}},_=o.useMemo(()=>Tp.find(Y=>Y.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(ps,{open:t,onOpenChange:e,children:s.jsxs(ms,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[s.jsxs(gs,{children:[s.jsx(fs,{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(Bt,{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:Tp.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:V5.map(L=>{const Y=L.Icon;return s.jsx("button",{type:"button",onClick:()=>A(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(D,{name:Y,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(D,{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(Bt,{value:g,onChange:L=>v(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(D,{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(Bt,{type:"email",value:x,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(ve,{size:"sm",type:"button",variant:"chip","aria-pressed":j==="ssh",onClick:()=>y("ssh"),children:[s.jsx(D,{name:"lock-2",className:"w-3.5 h-3.5 mr-1"})," SSH"]}),s.jsxs(ve,{size:"sm",type:"button",variant:"chip","aria-pressed":j==="token",onClick:()=>y("token"),children:[s.jsx(D,{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(D,{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(Bt,{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(D,{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(Bt,{value:w,onChange:L=>S(L.target.value),placeholder:a("settings.gitIdentities.editor.field.hostPlaceholder"),required:!0,className:"h-8 font-mono text-xs"})]})]})]})]}),s.jsxs(Hs,{className:"gap-2",children:[!u&&!m&&s.jsxs(ve,{variant:"outline",size:"sm",onClick:()=>O(!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(D,{name:"delete-bin",className:"w-3.5 h-3.5 mr-1"})," ",a("settings.common.actions.delete")]}),s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>e(!1),className:"text-foreground hover:bg-interactive-hover hover:text-foreground",children:a(u?"settings.gitIdentities.editor.actions.close":"settings.common.actions.cancel")}),!u&&s.jsx(ve,{size:"sm",onClick:$,disabled:N,children:a(N?"settings.common.actions.saving":m?"settings.gitIdentities.editor.actions.create":"settings.gitIdentities.editor.actions.save")})]})]})}),s.jsx(ps,{open:M,onOpenChange:L=>{V||O(L)},children:s.jsxs(ms,{className:"max-w-md",children:[s.jsxs(gs,{children:[s.jsx(fs,{children:a("settings.gitIdentities.page.deleteDialog.title")}),s.jsx(Ns,{children:a("settings.gitIdentities.page.deleteDialog.description",{name:p?.name||f})})]}),s.jsxs(Hs,{children:[s.jsx(ve,{variant:"ghost",onClick:()=>O(!1),disabled:V,children:a("settings.common.actions.cancel")}),s.jsx(ve,{size:"sm",variant:"destructive",onClick:()=>{F()},disabled:V,children:a("settings.common.actions.delete")})]})]})})]})},U5={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart"},W5={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)"},K5=()=>{const t=ot.c(116),{t:e}=ut(),{profiles:n,globalIdentity:r,defaultGitIdentityId:a,deleteProfile:i,loadProfiles:l,loadGlobalIdentity:c,loadDiscoveredCredentials:d,loadDefaultGitIdentityId:p,setDefaultGitIdentityId:m,getUnimportedCredentials:u}=Qn(er(G5)),[f,b]=o.useState(!1),[g,v]=o.useState(null),[x,h]=o.useState(null),[j,y]=o.useState(null),[C,k]=o.useState(!1);let w,S;t[0]!==p||t[1]!==d||t[2]!==c||t[3]!==l?(w=()=>{l(),c(),d(),p()},S=[l,c,d,p],t[0]=p,t[1]=d,t[2]=c,t[3]=l,t[4]=w,t[5]=S):(w=t[4],S=t[5]),o.useEffect(w,S);let I,T,P,A,N,E,M,O,V,B,$,F,_;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 Ie=u();let Pe;t[27]===Symbol.for("react.memo_cache_sentinel")?(Pe=(R,U)=>{v(R),h(U??null),b(!0)},t[27]=Pe):Pe=t[27];const Ce=Pe;let X;t[28]!==a||t[29]!==m||t[30]!==e?(X=async R=>{const U=a===R?null:R;if(!await m(U)){G.error(e("settings.gitIdentities.page.toast.updateDefaultFailed"));return}G.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 ie=X;let Ne;t[32]!==j||t[33]!==i||t[34]!==e?(Ne=async()=>{if(!j)return;k(!0),await i(j.id)?(G.success(e("settings.gitIdentities.page.toast.profileDeleted",{name:j.name})),y(null)):G.error(e("settings.gitIdentities.page.toast.deleteProfileFailed")),k(!1)},t[32]=j,t[33]=i,t[34]=e,t[35]=Ne):Ne=t[35],T=Ne,I=ws,A="h-full",N="w-full bg-background",_="mx-auto w-full max-w-3xl space-y-6 p-3 sm:p-6 sm:pt-8",t[36]===Symbol.for("react.memo_cache_sentinel")?(P=s.jsx(vg,{}),t[36]=P):P=t[36],$="border-t border-border/40 pt-6";let oe;t[37]!==e?(oe=e("settings.gitIdentities.page.section.title"),t[37]=e,t[38]=oe):oe=t[38];let ke;t[39]!==oe?(ke=s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:oe})}),t[39]=oe,t[40]=ke):ke=t[40];let Te,Be;t[41]===Symbol.for("react.memo_cache_sentinel")?(Te=()=>Ce("new"),Be=s.jsx(D,{name:"add",className:"w-3.5 h-3.5 mr-1"}),t[41]=Te,t[42]=Be):(Te=t[41],Be=t[42]);let je;t[43]!==e?(je=e("settings.common.badge.new"),t[43]=e,t[44]=je):je=t[44];let ee;t[45]!==je?(ee=s.jsxs(ve,{size:"sm",variant:"outline",onClick:Te,children:[Be," ",je]}),t[45]=je,t[46]=ee):ee=t[46],t[47]!==ke||t[48]!==ee?(F=s.jsxs("div",{className:"mb-3 px-1 flex items-start justify-between gap-4",children:[ke,ee]}),t[47]=ke,t[48]=ee,t[49]=F):F=t[49],E="rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",M=r&&s.jsx(Mp,{profile:r,isDefault:a==="global",onEdit:()=>Ce("global"),onToggleDefault:()=>ie("global"),isReadOnly:!0,hasBorder:n.length>0||Ie.length>0}),O=n.map((R,U)=>s.jsx(Mp,{profile:R,isDefault:a===R.id,onEdit:()=>Ce(R.id),onToggleDefault:()=>ie(R.id),onDelete:()=>y(R),hasBorder:U<n.length-1||Ie.length>0},R.id)),V=!r&&n.length===0&&Ie.length===0&&s.jsxs("div",{className:"py-8 px-4 text-center text-muted-foreground",children:[s.jsx(D,{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=Ie.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")})}),Ie.map((R,U)=>s.jsx(H5,{credential:R,onImport:()=>Ce("new",{host:R.host,username:R.username}),hasBorder:U<Ie.length-1},`${R.host}-${R.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]=A,t[18]=N,t[19]=E,t[20]=M,t[21]=O,t[22]=V,t[23]=B,t[24]=$,t[25]=F,t[26]=_}else I=t[14],T=t[15],P=t[16],A=t[17],N=t[18],E=t[19],M=t[20],O=t[21],V=t[22],B=t[23],$=t[24],F=t[25],_=t[26];let q;t[50]!==E||t[51]!==M||t[52]!==O||t[53]!==V||t[54]!==B?(q=s.jsxs("div",{className:E,children:[M,O,V,B]}),t[50]=E,t[51]=M,t[52]=O,t[53]=V,t[54]=B,t[55]=q):q=t[55];let L;t[56]!==q||t[57]!==$||t[58]!==F?(L=s.jsxs("div",{className:$,children:[F,q]}),t[56]=q,t[57]=$,t[58]=F,t[59]=L):L=t[59];let Y;t[60]===Symbol.for("react.memo_cache_sentinel")?(Y=s.jsx(yg,{}),t[60]=Y):Y=t[60];let Z;t[61]!==P||t[62]!==L||t[63]!==_?(Z=s.jsxs("div",{className:_,children:[P,L,Y]}),t[61]=P,t[62]=L,t[63]=_,t[64]=Z):Z=t[64];let ae;t[65]!==I||t[66]!==A||t[67]!==N||t[68]!==Z?(ae=s.jsx(I,{outerClassName:A,className:N,children:Z}),t[65]=I,t[66]=A,t[67]=N,t[68]=Z,t[69]=ae):ae=t[69];let re;t[70]!==x||t[71]!==f||t[72]!==g?(re=s.jsx(z5,{open:f,onOpenChange:b,profileId:g,importData:x}),t[70]=x,t[71]=f,t[72]=g,t[73]=re):re=t[73];const me=j!==null;let fe;t[74]!==C?(fe=Ie=>{C||Ie||y(null)},t[74]=C,t[75]=fe):fe=t[75];let H;t[76]!==e?(H=e("settings.gitIdentities.page.deleteDialog.title"),t[76]=e,t[77]=H):H=t[77];let K;t[78]!==H?(K=s.jsx(fs,{children:H}),t[78]=H,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 be;t[85]!==K||t[86]!==de?(be=s.jsxs(gs,{children:[K,de]}),t[85]=K,t[86]=de,t[87]=be):be=t[87];let we;t[88]===Symbol.for("react.memo_cache_sentinel")?(we=()=>y(null),t[88]=we):we=t[88];let te;t[89]!==e?(te=e("settings.common.actions.cancel"),t[89]=e,t[90]=te):te=t[90];let ge;t[91]!==C||t[92]!==te?(ge=s.jsx(ve,{variant:"ghost",onClick:we,disabled:C,children:te}),t[91]=C,t[92]=te,t[93]=ge):ge=t[93];let ue;t[94]!==T?(ue=()=>{T()},t[94]=T,t[95]=ue):ue=t[95];let xe;t[96]!==e?(xe=e("settings.common.actions.delete"),t[96]=e,t[97]=xe):xe=t[97];let ne;t[98]!==C||t[99]!==ue||t[100]!==xe?(ne=s.jsx(ve,{size:"sm",variant:"destructive",onClick:ue,disabled:C,children:xe}),t[98]=C,t[99]=ue,t[100]=xe,t[101]=ne):ne=t[101];let pe;t[102]!==ge||t[103]!==ne?(pe=s.jsxs(Hs,{children:[ge,ne]}),t[102]=ge,t[103]=ne,t[104]=pe):pe=t[104];let J;t[105]!==be||t[106]!==pe?(J=s.jsxs(ms,{className:"max-w-md",children:[be,pe]}),t[105]=be,t[106]=pe,t[107]=J):J=t[107];let Se;t[108]!==me||t[109]!==fe||t[110]!==J?(Se=s.jsx(ps,{open:me,onOpenChange:fe,children:J}),t[108]=me,t[109]=fe,t[110]=J,t[111]=Se):Se=t[111];let he;return t[112]!==ae||t[113]!==re||t[114]!==Se?(he=s.jsxs(s.Fragment,{children:[ae,re,Se]}),t[112]=ae,t[113]=re,t[114]=Se,t[115]=he):he=t[115],he},Mp=t=>{const e=ot.c(54),{profile:n,isDefault:r,onEdit:a,onToggleDefault:i,onDelete:l,isReadOnly:c,hasBorder:d}=t,{t:p}=ut(),m=U5[n.icon||"branch"]||"git-branch",u=W5[n.color||""],f=n.authType||"ssh";let b;e[0]!==a?(b=F=>{F.currentTarget===F.target&&(F.key!=="Enter"&&F.key!==" "||(F.preventDefault(),a()))},e[0]=a,e[1]=b):b=e[1];const g=b,v=d&&"border-b border-[var(--surface-subtle)]";let x;e[2]!==v?(x=ye("group flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30 cursor-pointer",v),e[2]=v,e[3]=x):x=e[3];let h;e[4]!==u?(h={color:u},e[4]=u,e[5]=h):h=e[5];let j;e[6]!==m||e[7]!==h?(j=s.jsx(D,{name:m,className:"w-4 h-4 shrink-0",style:h}),e[6]=m,e[7]=h,e[8]=j):j=e[8];let y;e[9]!==n.name?(y=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:n.name}),e[9]=n.name,e[10]=y):y=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 S;e[19]!==y||e[20]!==C||e[21]!==k||e[22]!==w?(S=s.jsxs("div",{className:"flex items-center gap-1.5",children:[y,C,k,w]}),e[19]=y,e[20]=C,e[21]=k,e[22]=w,e[23]=S):S=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]!==S||e[27]!==T?(P=s.jsxs("div",{className:"min-w-0",children:[S,T]}),e[26]=S,e[27]=T,e[28]=P):P=e[28];let A;e[29]!==P||e[30]!==j?(A=s.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[j,P]}),e[29]=P,e[30]=j,e[31]=A):A=e[31];let N;e[32]===Symbol.for("react.memo_cache_sentinel")?(N=s.jsx(Is,{asChild:!0,children:s.jsx(ve,{size:"icon",variant:"ghost",className:"h-6 w-6 shrink-0 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",onClick:q5,children:s.jsx(D,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[32]=N):N=e[32];let E;e[33]!==i?(E=F=>{F.stopPropagation(),i()},e[33]=i,e[34]=E):E=e[34];let M;e[35]!==r||e[36]!==p?(M=p(r?"settings.gitIdentities.page.actions.unsetDefault":"settings.gitIdentities.page.actions.setAsDefault"),e[35]=r,e[36]=p,e[37]=M):M=e[37];let O;e[38]!==E||e[39]!==M?(O=s.jsx(Ot,{onClick:E,children:M}),e[38]=E,e[39]=M,e[40]=O):O=e[40];let V;e[41]!==c||e[42]!==l||e[43]!==p?(V=!c&&l&&s.jsxs(Ot,{onClick:F=>{F.stopPropagation(),l()},className:"text-destructive focus:text-destructive",children:[s.jsx(D,{name:"delete-bin",className:"h-4 w-4 mr-px"}),p("settings.common.actions.delete")]}),e[41]=c,e[42]=l,e[43]=p,e[44]=V):V=e[44];let B;e[45]!==O||e[46]!==V?(B=s.jsxs(As,{children:[N,s.jsxs(Ps,{align:"end",className:"w-fit min-w-28",children:[O,V]})]}),e[45]=O,e[46]=V,e[47]=B):B=e[47];let $;return e[48]!==g||e[49]!==a||e[50]!==A||e[51]!==B||e[52]!==x?($=s.jsxs("div",{className:x,onClick:a,role:"button",tabIndex:0,onKeyDown:g,children:[A,B]}),e[48]=g,e[49]=a,e[50]=A,e[51]=B,e[52]=x,e[53]=$):$=e[53],$},H5=t=>{const e=ot.c(21),{credential:n,onImport:r,hasBorder:a}=t,{t:i}=ut();let l;e[0]!==n.host?(l=n.host.split("/"),e[0]=n.host,e[1]=l):l=e[1];const c=l,d=c.length>=3?c[c.length-1]:n.host,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 g;e[6]!==b?(g=s.jsx("span",{className:"typography-micro text-muted-foreground/60 truncate block leading-tight",children:b}),e[6]=b,e[7]=g):g=e[7];let v;e[8]!==f||e[9]!==g?(v=s.jsxs("div",{className:"min-w-0",children:[f,g]}),e[8]=f,e[9]=g,e[10]=v):v=e[10];let x;e[11]===Symbol.for("react.memo_cache_sentinel")?(x=s.jsx(D,{name:"download",className:"h-3 w-3"}),e[11]=x):x=e[11];let h;e[12]!==i?(h=i("settings.gitIdentities.page.actions.import"),e[12]=i,e[13]=h):h=e[13];let j;e[14]!==r||e[15]!==h?(j=s.jsxs(ve,{size:"sm",variant:"ghost",onClick:r,className:"gap-1 shrink-0",children:[x,h]}),e[14]=r,e[15]=h,e[16]=j):j=e[16];let y;return e[17]!==j||e[18]!==u||e[19]!==v?(y=s.jsxs("div",{className:u,children:[v,j]}),e[17]=j,e[18]=u,e[19]=v,e[20]=y):y=e[20],y};function G5(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 q5(t){return t.stopPropagation()}const wg=()=>{const t=Yb();return{displayMode:t,installed:t!=="browser",browserTab:t==="browser"}},jg=()=>{const t=ot.c(2),[e,n]=o.useState(Y5);let r,a;return t[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const i=[window.matchMedia("(display-mode: standalone)"),window.matchMedia("(display-mode: minimal-ui)"),window.matchMedia("(display-mode: fullscreen)"),window.matchMedia("(display-mode: window-controls-overlay)")],l=()=>{n(wg())};l();for(const c of i)typeof c.addEventListener=="function"?c.addEventListener("change",l):typeof c.addListener=="function"&&c.addListener(l);return window.addEventListener("appinstalled",l),window.addEventListener("focus",l),()=>{for(const c of i)typeof c.removeEventListener=="function"?c.removeEventListener("change",l):typeof c.removeListener=="function"&&c.removeListener(l);window.removeEventListener("appinstalled",l),window.removeEventListener("focus",l)}},a=[],t[0]=r,t[1]=a):(r=t[0],a=t[1]),o.useEffect(r,a),e};function Y5(){return wg()}const Q5=[{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"}],J5=[{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"}],X5=[{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"}],Z5=[{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"}],_i="OpenChamber - AI Coding Assistant",Ep=[{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"}],Rp=[{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"}],Fc=t=>t==="portrait"||t==="landscape"?t:"system",eC=[{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"}],tC=[{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"}],Fp=[{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"}],sC=[{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"}],Op=[{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"}],Lp=[{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"}],nC=t=>t==="markdown"?"markdown":"plain",au=({visibleSettings:t})=>{const{locale:e,locales:n,setLocale:r,label:a,t:i}=ut(),l=o.useCallback(se=>i(se),[i]),{isMobile:c}=an(),{browserTab:d}=jg(),p=_l(),m=Re(se=>se.showReasoningTraces),u=Re(se=>se.setShowReasoningTraces),f=Re(se=>se.collapsibleThinkingBlocks),b=Re(se=>se.setCollapsibleThinkingBlocks),g=Re(se=>se.mermaidRenderingMode),v=Re(se=>se.setMermaidRenderingMode),x=Re(se=>se.userMessageRenderingMode),h=Re(se=>se.setUserMessageRenderingMode),j=Re(se=>se.stickyUserHeader),y=Re(se=>se.setStickyUserHeader),C=Re(se=>se.wideChatLayoutEnabled),k=Re(se=>se.setWideChatLayoutEnabled),w=Re(se=>se.chatRenderMode),S=Re(se=>se.setChatRenderMode),I=Re(se=>se.activityRenderMode),T=Re(se=>se.setActivityRenderMode),P=Re(se=>se.fontSize),A=Re(se=>se.setFontSize),N=Re(se=>se.terminalFontSize),E=Re(se=>se.setTerminalFontSize),M=Re(se=>se.uiFont),O=Re(se=>se.setUiFont),V=Re(se=>se.monoFont),B=Re(se=>se.setMonoFont),$=Re(se=>se.padding),F=Re(se=>se.setPadding),_=Re(se=>se.inputBarOffset),q=Re(se=>se.setInputBarOffset),L=Re(se=>se.mobileKeyboardMode),Y=Re(se=>se.setMobileKeyboardMode),Z=Re(se=>se.diffLayoutPreference),ae=Re(se=>se.setDiffLayoutPreference),re=Re(se=>se.diffViewMode),me=Re(se=>se.setDiffViewMode),fe=Re(se=>se.showTerminalQuickKeysOnDesktop),H=Re(se=>se.setShowTerminalQuickKeysOnDesktop),K=Du(se=>se.queueModeEnabled),Q=Du(se=>se.setQueueMode),W=Re(se=>se.persistChatDraft),de=Re(se=>se.setPersistChatDraft),be=Re(se=>se.inputSpellcheckEnabled),we=Re(se=>se.setInputSpellcheckEnabled),te=Re(se=>se.showToolFileIcons),ge=Re(se=>se.setShowToolFileIcons),ue=Re(se=>se.showExpandedBashTools),xe=Re(se=>se.setShowExpandedBashTools),ne=Re(se=>se.showExpandedEditTools),pe=Re(se=>se.setShowExpandedEditTools),J=Re(se=>se.timeFormatPreference),Se=Re(se=>se.setTimeFormatPreference),he=Re(se=>se.weekStartPreference),Ie=Re(se=>se.setWeekStartPreference),Pe=Re(se=>se.showSplitAssistantMessageActions),Ce=Re(se=>se.setShowSplitAssistantMessageActions),X=Re(se=>se.showMobileSessionStatusBar),ie=Re(se=>se.setShowMobileSessionStatusBar),Ne=yt(se=>se.settingsMessageStreamTransport),oe=yt(se=>se.setSettingsMessageStreamTransport),ke=Re(se=>se.isSettingsDialogOpen),{themeMode:Te,setThemeMode:Be,availableThemes:je,customThemesLoading:ee,reloadCustomThemes:R,lightThemeId:U,darkThemeId:le,setLightThemePreference:Me,setDarkThemePreference:Oe}=vr(),[Ae,z]=o.useState(!1),[De,Xe]=o.useState(0),st=Re(se=>se.reportUsage),tt=Re(se=>se.setReportUsage),Ue=o.useCallback(se=>{tt(se),Ss({reportUsage:se})},[tt]),it=ke&&(t?t.includes("chatRenderMode"):!0);o.useEffect(()=>{if(!it)return;let se=null,bt=Date.now();const _t=()=>{const ss=Date.now();ss-bt>=420&&(Xe(cs=>(cs+1)%24),bt=ss),se=requestAnimationFrame(_t)};(typeof document>"u"||document.visibilityState==="visible")&&(se=requestAnimationFrame(_t));const lt=()=>{document.visibilityState==="visible"&&se===null?se=requestAnimationFrame(_t):document.visibilityState!=="visible"&&se!==null&&(cancelAnimationFrame(se),se=null)};return document.addEventListener("visibilitychange",lt),()=>{document.removeEventListener("visibilitychange",lt),se!==null&&cancelAnimationFrame(se)}},[it]);const Ye=o.useCallback(se=>{h(se),Ss({userMessageRenderingMode:se})},[h]),rt=o.useCallback(se=>{y(se),Ss({stickyUserHeader:se})},[y]),Je=o.useCallback(se=>{k(se),Ss({wideChatLayoutEnabled:se})},[k]),ce=o.useCallback(se=>{Ce(se),Ss({showSplitAssistantMessageActions:se})},[Ce]),We=o.useCallback(se=>{we(se),Ss({inputSpellcheckEnabled:se})},[we]),Le=o.useCallback(se=>{S(se),Ss({chatRenderMode:se})},[S]),Ge=o.useCallback(se=>{oe(se),Ss({messageStreamTransport:se})},[oe]),at=o.useCallback(se=>{T(se),Ss({activityRenderMode:se})},[T]),He=o.useCallback(se=>{v(se),Ss({mermaidRenderingMode:se})},[v]),ze=o.useCallback(se=>{ge(se),Ss({showToolFileIcons:se})},[ge]),et=o.useCallback(se=>{xe(se),Ss({showExpandedBashTools:se})},[xe]),gt=o.useCallback(se=>{pe(se),Ss({showExpandedEditTools:se})},[pe]),Pt=o.useCallback(se=>{Se(se),Ss({timeFormatPreference:se})},[Se]),Nt=o.useCallback(se=>{Ie(se),Ss({weekStartPreference:se})},[Ie]),ht=o.useMemo(()=>je.filter(se=>se.metadata.variant==="light").sort((se,bt)=>se.metadata.name.localeCompare(bt.metadata.name)),[je]),wt=o.useMemo(()=>je.filter(se=>se.metadata.variant==="dark").sort((se,bt)=>se.metadata.name.localeCompare(bt.metadata.name)),[je]),es=o.useMemo(()=>ht.find(se=>se.metadata.id===U)??ht[0],[ht,U]),Vt=o.useMemo(()=>wt.find(se=>se.metadata.id===le)??wt[0],[wt,le]),Jt=o.useCallback((se,bt)=>{const _t=bt==="dark"?" Dark":" Light";return se.endsWith(_t)?se.slice(0,-_t.length):se},[]),mt=se=>t?t.includes(se):!0,Lt=mn(),ts=mt("theme")&&!Lt,js=mt("theme")||mt("timeFormat")||mt("weekStart"),ds=Lt?js:mt("theme")||mt("pwaInstallName")||mt("pwaOrientation")||mt("timeFormat")||mt("weekStart"),hs=mt("fontSize")||mt("terminalFontSize")||mt("spacing")||mt("inputBarOffset"),Ut=mt("terminalQuickKeys")&&!c,Qe=mt("mermaidRendering")||mt("userMessageRendering")||mt("chatRenderMode")||mt("messageTransport")||mt("activityRenderMode")&&w==="sorted"||mt("stickyUserHeader")||mt("wideChatLayout")||mt("splitAssistantMessageActions")||mt("diffLayout")||mt("mobileStatusBar")&&c||mt("dotfiles")||mt("reasoning")||mt("queueMode")||mt("persistDraft")||mt("showToolFileIcons")||mt("expandedTools")||!c&&mt("inputSpellcheck"),At=mt("pwaInstallName")&&ta()&&d&&!Cn()&&!Lt,Ht=mt("pwaOrientation")&&ta()&&!Cn()&&!Lt,jt=mt("mobileKeyboardMode")&&ta()&&!Cn()&&!Lt&&Qb(),[Zt,rs]=o.useState(""),[Ds,ns]=o.useState("system"),zs=o.useMemo(()=>{const se=Op.find(bt=>bt.id===J);return l(se?.labelKey??"settings.openchamber.visual.option.timeFormat.auto.label")},[J,l]),$s=o.useMemo(()=>{const se=Lp.find(bt=>bt.id===he);return l(se?.labelKey??"settings.openchamber.visual.option.weekStart.auto.label")},[he,l]),gn=o.useMemo(()=>{const se=Ep.find(bt=>bt.id===Ds);return se?l(se.labelKey):void 0},[Ds,l]),rn=o.useMemo(()=>{const se=Rp.find(bt=>bt.id===L);return se?l(se.labelKey):void 0},[L,l]),Wt=o.useCallback(async se=>{if(typeof window>"u")return;const bt=window,lt=se.trim().replace(/\s+/g," ").slice(0,64);if(await Ss({pwaAppName:lt}),typeof bt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__=="function"){const ss=bt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__(lt);rs(ss);return}rs(lt||_i),bt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]),Kt=o.useCallback(async se=>{if(typeof window>"u")return;const bt=window,_t=Fc(se);if(await Ss({pwaOrientation:_t}),typeof bt.__OPENCHAMBER_SET_PWA_ORIENTATION__=="function"){const lt=bt.__OPENCHAMBER_SET_PWA_ORIENTATION__(_t);ns(lt);return}ns(_t),bt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]);return o.useEffect(()=>{if(typeof window>"u"||!At&&!Ht&&!jt)return;let se=!1;return(async()=>{try{const _t=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},cache:"no-store"});if(!_t.ok){se||rs(_i);return}const lt=await _t.json().catch(()=>({})),cs=(typeof lt?.pwaAppName=="string"?lt.pwaAppName:"").trim().replace(/\s+/g," ").slice(0,64),Ke=Fc(lt?.pwaOrientation),xt=Fu(lt?.mobileKeyboardMode);se||(At&&rs(cs||_i),Ht&&ns(Ke),jt&&Y(xt))}catch{se||(At&&rs(_i),Ht&&ns("system"),jt&&Y("native"))}})(),()=>{se=!0}},[Y,jt,At,Ht]),s.jsxs("div",{className:"space-y-8",children:[ds&&s.jsxs("div",{className:"mb-8 space-y-6",children:[ts&&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:Q5.map(se=>s.jsx(ve,{variant:"chip",size:"xs","aria-pressed":Te===se.value,className:"!font-normal",onClick:()=>Be(se.value),children:l(se.labelKey)},se.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(is,{value:es?.metadata.id??"",onValueChange:Me,children:[s.jsx(os,{"aria-label":i("settings.openchamber.visual.field.selectLightThemeAria"),className:"w-fit",children:s.jsx(us,{placeholder:i("settings.openchamber.visual.field.selectThemePlaceholder"),children:es?Jt(es.metadata.name,"light"):void 0})}),s.jsx(ls,{children:ht.map(se=>s.jsx(Mt,{value:se.metadata.id,children:Jt(se.metadata.name,"light")},se.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(is,{value:Vt?.metadata.id??"",onValueChange:Oe,children:[s.jsx(os,{"aria-label":i("settings.openchamber.visual.field.selectDarkThemeAria"),className:"w-fit",children:s.jsx(us,{placeholder:i("settings.openchamber.visual.field.selectThemePlaceholder"),children:Vt?Jt(Vt.metadata.name,"dark"):void 0})}),s.jsx(ls,{children:wt.map(se=>s.jsx(Mt,{value:se.metadata.id,children:Jt(se.metadata.name,"dark")},se.metadata.id))})]})]})]}),s.jsxs("div",{className:"flex items-center gap-2 py-1.5",children:[s.jsx("button",{type:"button",disabled:ee||Ae,onClick:()=>{const se=Date.now();z(!0),R().finally(()=>{const bt=Date.now()-se;if(bt<500){window.setTimeout(()=>{z(!1)},500-bt);return}z(!1)})},className:"inline-flex items-center typography-ui-label font-normal text-foreground underline decoration-[1px] underline-offset-2 hover:text-foreground/80 disabled:cursor-not-allowed disabled:text-muted-foreground/60",children:i(Ae?"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(D,{name:"information",className:"h-3.5 w-3.5"})})}),s.jsx(It,{sideOffset:8,children:i("settings.openchamber.visual.field.themeImportInfoTooltip")})]})]})]}),js&&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(is,{value:e,onValueChange:se=>r(se),children:[s.jsx(os,{"aria-label":i("settings.appearance.language.select"),className:"w-fit",children:s.jsx(us,{children:a(e)})}),s.jsx(ls,{children:n.map(se=>s.jsx(Mt,{value:se,children:a(se)},se))})]})]}),!Lt&&(mt("timeFormat")||mt("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:[mt("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(is,{value:J,onValueChange:se=>Pt(se),children:[s.jsx(os,{"aria-label":i("settings.openchamber.visual.field.selectTimeFormatAria"),className:"w-fit",children:s.jsx(us,{children:zs})}),s.jsx(ls,{children:Op.map(se=>s.jsx(Mt,{value:se.id,children:l(se.labelKey)},se.id))})]})]}),mt("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(is,{value:he,onValueChange:se=>Nt(se),children:[s.jsx(os,{"aria-label":i("settings.openchamber.visual.field.selectWeekStartAria"),className:"w-fit",children:s.jsx(us,{children:$s})}),s.jsx(ls,{children:Lp.map(se=>s.jsx(Mt,{value:se.id,children:l(se.labelKey)},se.id))})]})]})]})]}),(At||Ht||jt)&&s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[At&&s.jsxs("div",{className:"py-1.5 space-y-1.5",children:[s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.installAppName")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.openchamber.visual.field.installAppNameHint")})]}),s.jsxs("div",{className:"flex w-full max-w-[28rem] items-center gap-2",children:[s.jsx(Bt,{value:Zt,onChange:se=>{rs(se.target.value)},onBlur:()=>{Wt(Zt)},onKeyDown:se=>{se.key==="Enter"&&(se.preventDefault(),Wt(Zt))},className:"h-7",maxLength:64,"aria-label":i("settings.openchamber.visual.field.pwaInstallAppNameAria")}),s.jsx(ve,{size:"sm",type:"button",variant:"ghost",onClick:()=>{rs(_i),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(D,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),Ht&&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(is,{value:Ds,onValueChange:se=>{const bt=Fc(se);ns(bt),Kt(bt)},children:[s.jsx(os,{"aria-label":i("settings.openchamber.visual.field.pwaInstallOrientationAria"),className:"w-full",children:s.jsx(us,{placeholder:i("settings.openchamber.visual.field.selectOrientationPlaceholder"),children:gn})}),s.jsx(ls,{children:Ep.map(se=>s.jsx(Mt,{value:se.id,children:l(se.labelKey)},se.id))})]}),s.jsx(ve,{size:"sm",type:"button",variant:"ghost",onClick:()=>{ns("system"),Kt("system")},disabled:Ds==="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(D,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),jt&&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(is,{value:L,onValueChange:se=>{const bt=Fu(se);Y(bt),Ss({mobileKeyboardMode:bt})},children:[s.jsx(os,{"aria-label":i("settings.openchamber.visual.field.mobileKeyboardModeAria"),className:"w-full",children:s.jsx(us,{placeholder:i("settings.openchamber.visual.field.selectMobileKeyboardModePlaceholder"),children:rn})}),s.jsx(ls,{children:Rp.map(se=>s.jsx(Mt,{value:se.id,children:l(se.labelKey)},se.id))})]}),s.jsx(ve,{size:"sm",type:"button",variant:"ghost",onClick:()=>{Y("native"),Ss({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(D,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]})]}),hs&&s.jsx("div",{className:"mb-8 space-y-3",children:s.jsxs("section",{className:"p-2 space-y-0.5",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.spacingAndLayout")}),s.jsxs("div",{className:"pl-2",children:[mt("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(is,{value:M,onValueChange:se=>O(se),children:[s.jsx(os,{"aria-label":i("settings.openchamber.visual.field.selectInterfaceFontAria"),className:"w-[13rem]",children:s.jsx(us,{children:Tu.find(se=>se.id===M)?.label})}),s.jsx(ls,{children:Tu.map(se=>s.jsx(Mt,{value:se.id,children:s.jsx("span",{style:{fontFamily:se.stack},children:se.label})},se.id))})]}),s.jsx(ve,{size:"sm",type:"button",variant:"ghost",onClick:()=>O(Mu),disabled:M===Mu,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(D,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),mt("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(is,{value:V,onValueChange:se=>B(se),children:[s.jsx(os,{"aria-label":i("settings.openchamber.visual.field.selectCodeFontAria"),className:"w-[13rem]",children:s.jsx(us,{children:Eu.find(se=>se.id===V)?.label})}),s.jsx(ls,{children:Eu.map(se=>s.jsx(Mt,{value:se.id,children:s.jsx("span",{style:{fontFamily:se.stack},children:se.label})},se.id))})]}),s.jsx(ve,{size:"sm",type:"button",variant:"ghost",onClick:()=>B(Ru),disabled:V===Ru,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(D,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),mt("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:A,min:50,max:200,step:5,"aria-label":i("settings.openchamber.visual.field.fontSizePercentageAria"),className:"w-16"}),s.jsx(ve,{size:"sm",type:"button",variant:"ghost",onClick:()=>A(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(D,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),mt("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:N,onValueChange:E,min:9,max:52,step:1,className:"w-16"}),s.jsx(ve,{size:"sm",type:"button",variant:"ghost",onClick:()=>E(13),disabled:N===13,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetTerminalFontSizeAria"),title:i("settings.common.actions.reset"),children:s.jsx(D,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),mt("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:F,min:50,max:200,step:5,className:"w-16"}),s.jsx(ve,{size:"sm",type:"button",variant:"ghost",onClick:()=>F(100),disabled:$===100,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetSpacingAria"),title:i("settings.common.actions.reset"),children:s.jsx(D,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),mt("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(D,{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(ve,{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(D,{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")}),mt("terminalQuickKeys")&&!c&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":fe,onClick:()=>H(!fe),onKeyDown:se=>{(se.key===" "||se.key==="Enter")&&(se.preventDefault(),H(!fe))},children:[s.jsx(xs,{checked:fe,onChange:H,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(D,{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")})]})]})]})]})}),Qe&&s.jsxs("div",{className:"space-y-3",children:[(mt("userMessageRendering")||mt("mermaidRendering")||mt("chatRenderMode")||mt("messageTransport")||mt("activityRenderMode")&&w==="sorted"||mt("diffLayout")&&!Lt)&&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:[mt("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:tC.map(se=>{const bt=w===se.id,_t=De%12;return s.jsxs("button",{type:"button",onClick:()=>Le(se.id),"aria-pressed":bt,className:ye("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",bt?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[s.jsx("span",{className:ye("typography-ui-label",bt?"text-foreground":"text-muted-foreground"),children:l(se.labelKey)}),s.jsx("div",{className:"mt-2 w-full rounded-md border border-border/60 bg-muted/30 p-2",children:se.id==="live"?s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(lt=>{const ss=lt*3+1,cs=_t-ss+1,Ke=cs<=0?0:cs===1?42:cs===2?68:92,xt=Ke>0;return s.jsxs("div",{className:ye("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",xt?"translate-y-0 opacity-100":"translate-y-1 opacity-0"),children:[s.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full bg-muted-foreground/55"}),s.jsx("span",{className:"h-1.5 rounded bg-muted-foreground/30 transition-all duration-300 motion-reduce:transition-none",style:{width:`${Ke}%`}})]},lt)})}):s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(lt=>{const ss=_t>=(lt+1)*3;return s.jsxs("div",{className:ye("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",ss?"translate-y-0 opacity-100":"translate-y-1 opacity-0"),children:[s.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full bg-muted-foreground/55"}),s.jsx("span",{className:"h-1.5 rounded bg-muted-foreground/30",style:{width:"92%"}})]},lt)})})})]},se.id)})})]}),mt("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:Fp.map(se=>s.jsx(ve,{variant:"chip",size:"xs","aria-pressed":Ne===se.id,className:"!font-normal",onClick:()=>Ge(se.id),children:l(se.labelKey)},se.id))}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:(()=>{const se=Fp.find(bt=>bt.id===Ne);return se?.descriptionKey?l(se.descriptionKey):""})()})]})]}),mt("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:sC.map(se=>{const bt=I===se.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":bt,onClick:()=>at(se.id),onKeyDown:_t=>{(_t.key===" "||_t.key==="Enter")&&(_t.preventDefault(),at(se.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(ti,{checked:bt,onChange:()=>at(se.id),ariaLabel:i("settings.openchamber.visual.field.activityDefaultModeAria",{option:l(se.labelKey)})}),s.jsx("span",{className:ye("typography-ui-label font-normal",bt?"text-foreground":"text-foreground/50"),children:l(se.labelKey)})]},se.id)})})]}),mt("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":ue,onClick:()=>et(!ue),onKeyDown:se=>{(se.key===" "||se.key==="Enter")&&(se.preventDefault(),et(!ue))},children:[s.jsx(xs,{checked:ue,onChange:et,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":ne,onClick:()=>gt(!ne),onKeyDown:se=>{(se.key===" "||se.key==="Enter")&&(se.preventDefault(),gt(!ne))},children:[s.jsx(xs,{checked:ne,onChange:gt,ariaLabel:i("settings.openchamber.visual.field.showExpandedEditToolsAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.editTools")})]})]}),mt("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:eC.map(se=>{const bt=nC(x)===se.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":bt,onClick:()=>Ye(se.id),onKeyDown:_t=>{(_t.key===" "||_t.key==="Enter")&&(_t.preventDefault(),Ye(se.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(ti,{checked:bt,onChange:()=>Ye(se.id),ariaLabel:i("settings.openchamber.visual.field.userMessageRenderingAria",{option:l(se.labelKey)})}),s.jsx("span",{className:ye("typography-ui-label font-normal",bt?"text-foreground":"text-foreground/50"),children:l(se.labelKey)})]},se.id)})})]}),mt("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:Z5.map(se=>{const bt=g===se.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":bt,onClick:()=>He(se.id),onKeyDown:_t=>{(_t.key===" "||_t.key==="Enter")&&(_t.preventDefault(),He(se.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(ti,{checked:bt,onChange:()=>He(se.id),ariaLabel:i("settings.openchamber.visual.field.mermaidRenderingAria",{option:l(se.labelKey)})}),s.jsx("span",{className:ye("typography-ui-label font-normal",bt?"text-foreground":"text-foreground/50"),children:l(se.labelKey)})]},se.id)})})]}),mt("diffLayout")&&!Lt&&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:J5.map(se=>{const bt=Z===se.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":bt,onClick:()=>ae(se.id),onKeyDown:_t=>{(_t.key===" "||_t.key==="Enter")&&(_t.preventDefault(),ae(se.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(ti,{checked:bt,onChange:()=>ae(se.id),ariaLabel:i("settings.openchamber.visual.field.diffLayoutAria",{option:l(se.labelKey)})}),s.jsx("span",{className:ye("typography-ui-label font-normal",bt?"text-foreground":"text-foreground/50"),children:l(se.labelKey)})]},se.id)})})]}),mt("diffLayout")&&!Lt&&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:X5.map(se=>{const bt=re===se.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":bt,onClick:()=>me(se.id),onKeyDown:_t=>{(_t.key===" "||_t.key==="Enter")&&(_t.preventDefault(),me(se.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(ti,{checked:bt,onChange:()=>me(se.id),ariaLabel:i("settings.openchamber.visual.field.diffViewModeAria",{option:l(se.labelKey)})}),s.jsx("span",{className:ye("typography-ui-label font-normal",bt?"text-foreground":"text-foreground/50"),children:l(se.labelKey)})]},se.id)})})]})]}),(mt("stickyUserHeader")||mt("wideChatLayout")||mt("splitAssistantMessageActions")||mt("mobileStatusBar")&&c||mt("dotfiles")||mt("queueMode")||mt("persistDraft")||mt("showToolFileIcons")||!c&&mt("inputSpellcheck")||mt("reasoning"))&&s.jsxs("section",{className:"p-2 space-y-0.5",children:[mt("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:se=>{(se.key===" "||se.key==="Enter")&&(se.preventDefault(),u(!m))},children:[s.jsx(xs,{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")})]}),mt("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:se=>{(se.key===" "||se.key==="Enter")&&(se.preventDefault(),b(!f))},children:[s.jsx(xs,{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")})]}),mt("stickyUserHeader")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":j,onClick:()=>rt(!j),onKeyDown:se=>{(se.key===" "||se.key==="Enter")&&(se.preventDefault(),rt(!j))},children:[s.jsx(xs,{checked:j,onChange:rt,ariaLabel:i("settings.openchamber.visual.field.stickyUserHeaderAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.stickyUserHeader")})]}),mt("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:se=>{(se.key===" "||se.key==="Enter")&&(se.preventDefault(),Je(!C))},children:[s.jsx(xs,{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")})]}),mt("splitAssistantMessageActions")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":Pe,onClick:()=>ce(!Pe),onKeyDown:se=>{(se.key===" "||se.key==="Enter")&&(se.preventDefault(),ce(!Pe))},children:[s.jsx(xs,{checked:Pe,onChange:ce,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(D,{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")})]})]})]}),mt("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:se=>{(se.key===" "||se.key==="Enter")&&(se.preventDefault(),ze(!te))},children:[s.jsx(xs,{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")})]}),mt("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:()=>ie(!X),onKeyDown:se=>{(se.key===" "||se.key==="Enter")&&(se.preventDefault(),ie(!X))},children:[s.jsx(xs,{checked:X,onChange:ie,ariaLabel:i("settings.openchamber.visual.field.showMobileStatusBarAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showMobileStatusBar")})]}),mt("dotfiles")&&!mn()&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":p,onClick:()=>Yo(!p),onKeyDown:se=>{(se.key===" "||se.key==="Enter")&&(se.preventDefault(),Yo(!p))},children:[s.jsx(xs,{checked:p,onChange:Yo,ariaLabel:i("settings.openchamber.visual.field.showDotfilesAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showDotfiles")})]}),mt("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:se=>{(se.key===" "||se.key==="Enter")&&(se.preventDefault(),Q(!K))},children:[s.jsx(xs,{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(D,{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:Gi()})})]})]})]}),mt("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:se=>{(se.key===" "||se.key==="Enter")&&(se.preventDefault(),de(!W))},children:[s.jsx(xs,{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&&mt("inputSpellcheck")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":be,onClick:()=>We(!be),onKeyDown:se=>{(se.key===" "||se.key==="Enter")&&(se.preventDefault(),We(!be))},children:[s.jsx(xs,{checked:be,onChange:We,ariaLabel:i("settings.openchamber.visual.field.enableSpellcheckInTextInputsAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.enableSpellcheckInTextInputs")})]})]})]}),mt("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(xs,{checked:st,onChange:Ue,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":st,onClick:()=>Ue(!st),onKeyDown:se=>{(se.key===" "||se.key==="Enter")&&(se.preventDefault(),Ue(!st))},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 rC(){if(typeof window>"u")return"unknown";try{const{deviceType:t}=ey();return t}catch{return"unknown"}}function aC(){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 iC(){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 oC(t){const e=Re.getState().reportUsage,n=new URLSearchParams({reportUsage:e?"true":"false"});return n.set("deviceClass",rC()),n.set("arch",aC()),n.set("platform",iC()),t==="desktop"?(n.set("appType",Zb()?"desktop-electron":"desktop-tauri"),n.set("instanceMode",sa()?"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 Oc(t,e){try{const n=oC(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 lC(){return Va()?sa()?"desktop":"web":mn()?"vscode":ta()?"web":null}const $p={checking:!1,available:!1,downloading:!1,downloaded:!1,info:null,progress:null,error:null,runtimeType:null,lastChecked:null,nextCheckInSec:null},_a=rr()((t,e)=>({...$p,checkForUpdates:async()=>{const n=lC();if(!n)return null;t({checking:!0,error:null,runtimeType:n});try{let r=null,a=null;if(n==="desktop"){let i=await nc();t({checking:!1,available:i?.available??!1,info:i,lastChecked:Date.now(),nextCheckInSec:null});const l=await Oc("desktop",i?.currentVersion);if(a=l?.nextSuggestedCheckInSec??null,l?.available&&!i?.available){const c=await nc();c&&(i=c)}if(l){const c={...i??{available:!1,currentVersion:l.currentVersion??"unknown"},...l,currentVersion:i?.currentVersion??l.currentVersion??"unknown",available:l.available};t({available:c.available,info:c,nextCheckInSec:a})}else t({nextCheckInSec:a});return a}else n==="web"?(r=await Oc("web"),a=r?.nextSuggestedCheckInSec??null):n==="vscode"&&(a=(await Oc("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 nc();if(!a?.available)throw new Error("Update detected, but desktop package is not ready yet. Retry in a moment.");if(t(l=>({info:l.info?{...l.info,...a,body:l.info.body||a.body,available:l.info.available}:a})),!await Xb(l=>{t({progress:l})}))throw new Error("Desktop update only works on Local instance");t({downloading:!1,downloaded:!0})}catch(a){t({downloading:!1,error:a instanceof Error?a.message:"Failed to download update"})}}},restartToUpdate:async()=>{const{downloaded:n,runtimeType:r}=e();if(!(r!=="desktop"||!n))try{if(!await Jb())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($p)}})),_p="https://github.com/btriapitsyn/openchamber/releases";function cC(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 dC(t){return t.replace(/^## \[[^\]]+\] - \d{4}-\d{2}-\d{2}\s*\n?/,"").trim()}function Bp(t){return t.replace(/(^|[^a-zA-Z0-9])@([a-zA-Z0-9-]+)/g,"$1[@$2](https://github.com/$2)")}function uC(t,e){const n=t.split(".").map(a=>Number.parseInt(a,10)),r=e.split(".").map(a=>Number.parseInt(a,10));for(let a=0;a<3;a+=1){const i=Number.isFinite(n[a])?n[a]:0,l=Number.isFinite(r[a])?r[a]:0;if(i!==l)return l-i}return 0}function mC(t){const e=/^## \[(\d+\.\d+\.\d+)\] - (\d{4}-\d{2}-\d{2})\s*$/gm,n=[];let r;for(;(r=e.exec(t))!==null;)n.push({version:r[1]??"",date:r[2]??"",start:r.index});return n.length===0?[]:n.map((a,i)=>{const l=n[i+1]?.start??t.length,c=t.slice(a.start,l).trim();return{version:a.version,date:a.date,start:a.start,end:l,raw:c}})}const Vp=2e3,pC=600*1e3;async function fC(){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 hC(){try{return(await fetch("/health",{method:"GET",headers:{Accept:"application/json"}})).ok}catch{return!1}}async function gC(t,e=Math.ceil(pC/Vp),n=Vp){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 hC())return!0}catch{}await new Promise(a=>setTimeout(a,n))}return!1}const wd=({open:t,onOpenChange:e,info:n,downloading:r,downloaded:a,progress:i,error:l,onDownload:c,onRestart:d,runtimeType:p="desktop"})=>{const{t:m}=ut(),[u,f]=_e.useState(!1),[b,g]=_e.useState("idle"),[v,x]=_e.useState(null),h=n?.version?`${_p}/tag/v${n.version}`:_p,j=i?.total?Math.round(i.downloaded/i.total*100):0,y=p==="web",C=n?.updateCommand||"openchamber update";_e.useEffect(()=>{t||(g("idle"),x(null))},[t]);const k=async()=>{(await Rn(C)).ok&&(f(!0),setTimeout(()=>f(!1),2e3))},w=_e.useCallback(async P=>{await Zn(P)},[]),S=_e.useCallback(async()=>{g("updating"),x(null);const P=await fC();if(!P.success){g("error"),x(P.error||m("updateDialog.error.updateFailed"));return}P.autoRestart&&(g("restarting"),await new Promise(N=>setTimeout(N,2e3))),g("reconnecting"),await gC(n?.currentVersion)?window.location.reload():(g("error"),x(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 A=mC(P);if(A.length===0)return{kind:"raw",title:m("updateDialog.changelog.title"),content:Bp(P)};const N=[...A].sort((E,M)=>uC(E.version,M.version));return{kind:"sections",title:m("updateDialog.changelog.title"),sections:N.map(E=>({version:E.version,dateLabel:cC(E.date),content:Bp(dC(E.raw)||P)}))}},[n?.body,m]);return s.jsx(ps,{open:t,onOpenChange:I?void 0:e,children:s.jsxs(ms,{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(fs,{className:"flex items-center gap-2.5",children:[s.jsx(D,{name:"download-cloud",className:"h-5 w-5 text-[var(--primary-base)]"}),s.jsx("span",{className:"text-lg font-semibold text-foreground",children:m(b==="restarting"||b==="reconnecting"?"updateDialog.header.updating":"updateDialog.header.updateAvailable")})]}),(n?.currentVersion||n?.version)&&s.jsxs("div",{className:"flex items-center gap-2 font-mono text-sm ml-3",children:[n?.currentVersion&&s.jsx("span",{className:"text-muted-foreground",children:n.currentVersion}),n?.currentVersion&&n?.version&&s.jsx("span",{className:"text-muted-foreground/50",children:"→"}),n?.version&&s.jsx("span",{className:"text-[var(--primary-base)] font-medium",children:n.version})]})]}),s.jsxs("div",{className:"space-y-2",children:[y&&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(D,{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(ws,{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 N=P.target.closest("a");N&&N.href&&(P.preventDefault(),P.stopPropagation(),w(N.href))},children:s.jsx(ha,{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:A=>{const E=A.target.closest("a");E&&E.href&&(A.preventDefault(),A.stopPropagation(),w(E.href))},children:s.jsx(ha,{content:P.content,disableLinkSafety:!0})})]},P.version))})})}),y&&b==="error"&&s.jsxs("div",{className:"space-y-2 mt-4",children:[s.jsxs("div",{className:"flex items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx(D,{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(D,{name:"check",className:"h-4 w-4"}):s.jsx(D,{name:"clipboard",className:"h-4 w-4"})})]})]}),!y&&r&&s.jsxs("div",{className:"space-y-2 mt-4",children:[s.jsxs("div",{className:"flex items-center justify-between text-sm",children:[s.jsx("span",{className:"text-muted-foreground",children:m("updateDialog.status.downloadingPayload")}),s.jsxs("span",{className:"font-mono text-foreground",children:[j,"%"]})]}),s.jsx("div",{className:"h-1.5 bg-[var(--surface-subtle)] rounded-full overflow-hidden",children:s.jsx("div",{className:"h-full bg-[var(--primary-base)] transition-all duration-300",style:{width:`${j}%`}})})]}),(l||v)&&s.jsx("div",{className:"p-3 mt-4 bg-[var(--status-error-background)] border border-[var(--status-error-border)] rounded-lg",children:s.jsx("p",{className:"text-sm text-[var(--status-error)]",children:l||v})})]}),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(D,{name:"external-link",className:"h-4 w-4"}),"GitHub"]}),s.jsxs("div",{className:"flex-1 flex justify-end",children:[!y&&!a&&!r&&s.jsxs("button",{onClick:c,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)] text-[var(--primary-foreground)] hover:opacity-90 transition-opacity",children:[s.jsx(D,{name:"download",className:"h-4 w-4"}),m("updateDialog.actions.downloadUpdate")]}),!y&&r&&s.jsxs("button",{disabled:!0,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)]/50 text-[var(--primary-foreground)] cursor-not-allowed",children:[s.jsx(D,{name:"loader",className:"h-4 w-4 animate-spin"}),m("updateDialog.status.downloading")]}),!y&&a&&s.jsxs("button",{onClick:d,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--status-success)] text-white hover:opacity-90 transition-opacity",children:[s.jsx(D,{name:"restart",className:"h-4 w-4"}),m("updateDialog.actions.restartToUpdate")]}),y&&!I&&s.jsxs("button",{onClick:S,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)] text-[var(--primary-foreground)] hover:opacity-90 transition-opacity",children:[s.jsx(D,{name:"download",className:"h-4 w-4"}),m("updateDialog.actions.updateNow")]}),y&&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(D,{name:"loader",className:"h-4 w-4 animate-spin"}),m("updateDialog.status.updating")]})]})]})]})})},zp="https://github.com/btriapitsyn/openchamber",xC=800,bC=()=>{const t=ot.c(103),{t:e}=ut(),[n,r]=o.useState(!1),[a,i]=o.useState(!1),l=_a(er(yC)),{isMobile:c}=an(),d=l.info?.currentVersion||"unknown",p=o.useRef(!1);let m,u;t[0]!==a||t[1]!==e||t[2]!==l.available||t[3]!==l.checking||t[4]!==l.error?(m=()=>{if(l.checking)i(!0),p.current=!0;else if(a){const $=setTimeout(()=>{i(!1),p.current&&!l.available&&!l.error&&(G.success(e("settings.openchamber.about.toast.latestVersion")),p.current=!1)},xC);return()=>clearTimeout($)}},u=[e,l.checking,a,l.available,l.error],t[0]=a,t[1]=e,t[2]=l.available,t[3]=l.checking,t[4]=l.error,t[5]=m,t[6]=u):(m=t[5],u=t[6]),o.useEffect(m,u);const f=l.checking||a;if(c){let $;t[7]!==d?($=s.jsxs("span",{className:"typography-meta text-muted-foreground",children:["v",d]}),t[7]=d,t[8]=$):$=t[8];let F;t[9]!==f||t[10]!==e||t[11]!==l?(F=!l.available&&!l.error&&s.jsx("button",{onClick:()=>l.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]=l,t[12]=F):F=t[12];let _;t[13]!==f||t[14]!==e||t[15]!==l.available?(_=!f&&l.available&&s.jsxs("button",{onClick:()=>r(!0),className:"flex items-center gap-1 typography-meta text-[var(--primary-base)] hover:underline",children:[s.jsx(D,{name:"download",className:"h-3.5 w-3.5"}),e("settings.openchamber.about.actions.update")]}),t[13]=f,t[14]=e,t[15]=l.available,t[16]=_):_=t[16];let q;t[17]!==$||t[18]!==F||t[19]!==_?(q=s.jsxs("div",{className:"flex items-center justify-between",children:[$,F,_]}),t[17]=$,t[18]=F,t[19]=_,t[20]=q):q=t[20];let L;t[21]!==l.error?(L=l.error&&s.jsx("p",{className:"typography-micro text-[var(--status-error)] truncate",children:l.error}),t[21]=l.error,t[22]=L):L=t[22];let Y;t[23]===Symbol.for("react.memo_cache_sentinel")?(Y=s.jsxs("a",{href:zp,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(D,{name:"github-fill",className:"h-3.5 w-3.5"}),s.jsx("span",{children:"GitHub"})]}),t[23]=Y):Y=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(D,{name:"discord-fill",className:"h-3.5 w-3.5"}),s.jsx("span",{children:"Discord"})]}),t[24]=Z):Z=t[24];let ae;t[25]===Symbol.for("react.memo_cache_sentinel")?(ae=s.jsxs("div",{className:"flex items-center gap-3",children:[Y,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(D,{name:"twitter-xfill",className:"h-3.5 w-3.5"}),s.jsx("span",{children:"@btriapitsyn"})]})]}),t[25]=ae):ae=t[25];let re;t[26]!==n||t[27]!==l.downloadUpdate||t[28]!==l.downloaded||t[29]!==l.downloading||t[30]!==l.error||t[31]!==l.info||t[32]!==l.progress||t[33]!==l.restartToUpdate||t[34]!==l.runtimeType?(re=s.jsx(wd,{open:n,onOpenChange:r,info:l.info,downloading:l.downloading,downloaded:l.downloaded,progress:l.progress,error:l.error,onDownload:l.downloadUpdate,onRestart:l.restartToUpdate,runtimeType:l.runtimeType}),t[26]=n,t[27]=l.downloadUpdate,t[28]=l.downloaded,t[29]=l.downloading,t[30]=l.error,t[31]=l.info,t[32]=l.progress,t[33]=l.restartToUpdate,t[34]=l.runtimeType,t[35]=re):re=t[35];let me;return t[36]!==re||t[37]!==q||t[38]!==L?(me=s.jsxs("div",{className:"w-full space-y-2",children:[q,L,ae,re]}),t[36]=re,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 g;t[42]!==b?(g=s.jsx("div",{className:"mb-3 px-1",children:s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:b})}),t[42]=b,t[43]=g):g=t[43];let v;t[44]!==e?(v=e("settings.openchamber.about.field.version"),t[44]=e,t[45]=v):v=t[45];let x;t[46]!==v?(x=s.jsx("span",{className:"typography-ui-label text-foreground",children:v}),t[46]=v,t[47]=x):x=t[47];let h;t[48]!==d?(h=s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:d}),t[48]=d,t[49]=h):h=t[49];let j;t[50]!==x||t[51]!==h?(j=s.jsxs("div",{className:"flex min-w-0 flex-col",children:[x,h]}),t[50]=x,t[51]=h,t[52]=j):j=t[52];let y;t[53]!==e||t[54]!==l.checking?(y=l.checking&&s.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[s.jsx(D,{name:"loader",className:"h-4 w-4 animate-spin"}),s.jsx("span",{className:"typography-meta",children:e("settings.openchamber.about.state.checking")})]}),t[53]=e,t[54]=l.checking,t[55]=y):y=t[55];let C;t[56]!==e||t[57]!==l.available||t[58]!==l.checking||t[59]!==l.info?.version?(C=!l.checking&&l.available&&s.jsxs(ve,{size:"sm",variant:"default",onClick:()=>r(!0),children:[s.jsx(D,{name:"download",className:"h-4 w-4 mr-1"}),e("settings.openchamber.about.actions.updateToVersion",{version:l.info?.version||""})]}),t[56]=e,t[57]=l.available,t[58]=l.checking,t[59]=l.info?.version,t[60]=C):C=t[60];let k;t[61]!==e||t[62]!==l.available||t[63]!==l.checking||t[64]!==l.error?(k=!l.checking&&!l.available&&!l.error&&s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.about.state.upToDate")}),t[61]=e,t[62]=l.available,t[63]=l.checking,t[64]=l.error,t[65]=k):k=t[65];let w;t[66]!==l?(w=()=>l.checkForUpdates(),t[66]=l,t[67]=w):w=t[67];const S=l.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]!==l.checking?(T=s.jsx(ve,{size:"sm",variant:"outline",onClick:w,disabled:S,children:I}),t[70]=w,t[71]=I,t[72]=l.checking,t[73]=T):T=t[73];let P;t[74]!==k||t[75]!==T||t[76]!==y||t[77]!==C?(P=s.jsxs("div",{className:"flex items-center gap-3",children:[y,C,k,T]}),t[74]=k,t[75]=T,t[76]=y,t[77]=C,t[78]=P):P=t[78];let A;t[79]!==P||t[80]!==j?(A=s.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4 px-4 py-3 border-b border-[var(--surface-subtle)]",children:[j,P]}),t[79]=P,t[80]=j,t[81]=A):A=t[81];let N;t[82]!==l.error?(N=l.error&&s.jsx("div",{className:"px-3 py-2 border-b border-[var(--surface-subtle)]",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:l.error})}),t[82]=l.error,t[83]=N):N=t[83];let E;t[84]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsxs("a",{href:zp,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(D,{name:"github-fill",className:"h-4 w-4"}),s.jsx("span",{children:"GitHub"})]}),t[84]=E):E=t[84];let M;t[85]===Symbol.for("react.memo_cache_sentinel")?(M=s.jsxs("div",{className:"flex items-center gap-4 px-4 py-4",children:[E,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(D,{name:"twitter-xfill",className:"h-4 w-4"}),s.jsx("span",{children:"@btriapitsyn"})]})]}),t[85]=M):M=t[85];let O;t[86]!==A||t[87]!==N?(O=s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[A,N,M]}),t[86]=A,t[87]=N,t[88]=O):O=t[88];let V;t[89]!==n||t[90]!==l.downloadUpdate||t[91]!==l.downloaded||t[92]!==l.downloading||t[93]!==l.error||t[94]!==l.info||t[95]!==l.progress||t[96]!==l.restartToUpdate||t[97]!==l.runtimeType?(V=s.jsx(wd,{open:n,onOpenChange:r,info:l.info,downloading:l.downloading,downloaded:l.downloaded,progress:l.progress,error:l.error,onDownload:l.downloadUpdate,onRestart:l.restartToUpdate,runtimeType:l.runtimeType}),t[89]=n,t[90]=l.downloadUpdate,t[91]=l.downloaded,t[92]=l.downloading,t[93]=l.error,t[94]=l.info,t[95]=l.progress,t[96]=l.restartToUpdate,t[97]=l.runtimeType,t[98]=V):V=t[98];let B;return t[99]!==O||t[100]!==V||t[101]!==g?(B=s.jsxs("div",{className:"mb-8",children:[g,O,V]}),t[99]=O,t[100]=V,t[101]=g,t[102]=B):B=t[102],B};function yC(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 vC=1,wC=365,Up=30,jC=[{value:"archive",labelKey:"settings.openchamber.sessionRetention.action.archive"},{value:"delete",labelKey:"settings.openchamber.sessionRetention.action.delete"}],Ng=()=>{const t=ot.c(113),{t:e}=ut(),n=Re(NC),r=Re(SC),a=Re(kC),i=Re(CC),l=Re(IC),c=Re(PC);let d;t[0]===Symbol.for("react.memo_cache_sentinel")?(d={autoRun:!1},t[0]=d):d=t[0];const{candidates:p,isRunning:m,runCleanup:u,action:f}=ty(d),b=p.length;let g;t[1]!==u||t[2]!==e?(g=async()=>{const J=await u({force:!0});if(J.completedIds.length===0&&J.failedIds.length===0){G.message(J.action==="archive"?e("settings.openchamber.sessionRetention.toast.noneEligibleArchive"):e("settings.openchamber.sessionRetention.toast.noneEligibleDelete"));return}J.completedIds.length>0&&G.success(J.action==="archive"?e("settings.openchamber.sessionRetention.toast.archivedCount",{count:J.completedIds.length}):e("settings.openchamber.sessionRetention.toast.deletedCount",{count:J.completedIds.length})),J.failedIds.length>0&&G.error(J.action==="archive"?e("settings.openchamber.sessionRetention.toast.failedArchiveCount",{count:J.failedIds.length}):e("settings.openchamber.sessionRetention.toast.failedDeleteCount",{count:J.failedIds.length}))},t[1]=u,t[2]=e,t[3]=g):g=t[3];const v=g;let x;t[4]!==e?(x=e("settings.openchamber.sessionRetention.title"),t[4]=e,t[5]=x):x=t[5];let h;t[6]!==x?(h=s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:x}),t[6]=x,t[7]=h):h=t[7];let j;t[8]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(Ct,{asChild:!0,children:s.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t[8]=j):j=t[8];let y;t[9]!==e?(y=e("settings.openchamber.sessionRetention.tooltip"),t[9]=e,t[10]=y):y=t[10];let C;t[11]!==y?(C=s.jsxs(kt,{children:[j,s.jsx(It,{sideOffset:8,className:"max-w-xs",children:y})]}),t[11]=y,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,S;t[16]!==n||t[17]!==i?(w=()=>i(!n),S=J=>{(J.key===" "||J.key==="Enter")&&(J.preventDefault(),i(!n))},t[16]=n,t[17]=i,t[18]=w,t[19]=S):(w=t[18],S=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(xs,{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 A;t[28]!==P?(A=s.jsx("span",{className:"typography-ui-label text-foreground",children:P}),t[28]=P,t[29]=A):A=t[29];let N;t[30]!==n||t[31]!==T||t[32]!==A||t[33]!==w||t[34]!==S?(N=s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":n,onClick:w,onKeyDown:S,children:[T,A]}),t[30]=n,t[31]=T,t[32]=A,t[33]=w,t[34]=S,t[35]=N):N=t[35];let E;t[36]!==e?(E=e("settings.openchamber.sessionRetention.field.retentionPeriod"),t[36]=e,t[37]=E):E=t[37];let M;t[38]!==E?(M=s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:E})}),t[38]=E,t[39]=M):M=t[39];let O;t[40]!==e?(O=e("settings.openchamber.sessionRetention.field.retentionPeriodAria"),t[40]=e,t[41]=O):O=t[41];let V;t[42]!==r||t[43]!==l||t[44]!==O?(V=s.jsx(_n,{value:r,onValueChange:l,min:vC,max:wC,step:1,"aria-label":O,className:"w-20 tabular-nums"}),t[42]=r,t[43]=l,t[44]=O,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 F;t[50]!==l?(F=()=>l(Up),t[50]=l,t[51]=F):F=t[51];const _=r===Up;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 Y;t[56]===Symbol.for("react.memo_cache_sentinel")?(Y=s.jsx(D,{name:"restart",className:"h-3.5 w-3.5"}),t[56]=Y):Y=t[56];let Z;t[57]!==F||t[58]!==_||t[59]!==q||t[60]!==L?(Z=s.jsx(ve,{size:"sm",type:"button",variant:"ghost",onClick:F,disabled:_,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":q,title:L,children:Y}),t[57]=F,t[58]=_,t[59]=q,t[60]=L,t[61]=Z):Z=t[61];let ae;t[62]!==V||t[63]!==$||t[64]!==Z?(ae=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]=ae):ae=t[65];let re;t[66]!==M||t[67]!==ae?(re=s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[M,ae]}),t[66]=M,t[67]=ae,t[68]=re):re=t[68];let me;t[69]!==e?(me=e("settings.openchamber.sessionRetention.field.whenSessionsExpire"),t[69]=e,t[70]=me):me=t[70];let fe;t[71]!==me?(fe=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]=fe):fe=t[72];let H;t[73]!==a||t[74]!==c||t[75]!==e?(H=jC.map(J=>s.jsx(ve,{type:"button",variant:"chip",size:"xs","aria-pressed":a===J.value,className:"!font-normal",onClick:()=>c(J.value),children:e(J.labelKey)},J.value)),t[73]=a,t[74]=c,t[75]=e,t[76]=H):H=t[76];let K;t[77]!==H?(K=s.jsx("div",{className:"flex flex-wrap items-center gap-1 sm:w-fit",children:H}),t[77]=H,t[78]=K):K=t[78];let Q;t[79]!==fe||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:[fe,K]}),t[79]=fe,t[80]=K,t[81]=Q):Q=t[81];let W;t[82]!==N||t[83]!==re||t[84]!==Q?(W=s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[N,re,Q]}),t[82]=N,t[83]=re,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 be;t[88]!==de?(be=s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("p",{className:"typography-meta text-foreground font-medium",children:de})}),t[88]=de,t[89]=be):be=t[89];let we;t[90]!==m||t[91]!==e?(we=e(m?"settings.openchamber.sessionRetention.actions.cleaningUp":"settings.openchamber.sessionRetention.actions.runCleanupNow"),t[90]=m,t[91]=e,t[92]=we):we=t[92];let te;t[93]!==v||t[94]!==m||t[95]!==we?(te=s.jsx("div",{className:"flex items-center gap-2 sm:w-fit",children:s.jsx(ve,{type:"button",variant:"outline",size:"xs",onClick:v,disabled:m,className:"!font-normal",children:we})}),t[93]=v,t[94]=m,t[95]=we,t[96]=te):te=t[96];let ge;t[97]!==be||t[98]!==te?(ge=s.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-8",children:[be,te]}),t[97]=be,t[98]=te,t[99]=ge):ge=t[99];let ue;t[100]!==f||t[101]!==b||t[102]!==e?(ue=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]=ue):ue=t[103];let xe;t[104]!==ue?(xe=s.jsx("p",{className:"typography-meta text-muted-foreground",children:ue}),t[104]=ue,t[105]=xe):xe=t[105];let ne;t[106]!==ge||t[107]!==xe?(ne=s.jsxs("div",{className:"mt-1 px-2 py-1.5 space-y-1",children:[ge,xe]}),t[106]=ge,t[107]=xe,t[108]=ne):ne=t[108];let pe;return t[109]!==W||t[110]!==ne||t[111]!==k?(pe=s.jsxs("div",{className:"mb-8",children:[k,W,ne]}),t[109]=W,t[110]=ne,t[111]=k,t[112]=pe):pe=t[112],pe};function NC(t){return t.autoDeleteEnabled}function SC(t){return t.autoDeleteAfterDays}function kC(t){return t.sessionRetentionAction}function CC(t){return t.setAutoDeleteEnabled}function IC(t){return t.setAutoDeleteAfterDays}function PC(t){return t.setSessionRetentionAction}const Wp=(t,e)=>!t||!Number.isFinite(t)?e:new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"}).format(t),Sg=()=>{const{t}=ut(),[e,n]=o.useState(!1),[r,a]=o.useState(!0),[i,l]=o.useState(!1),[c,d]=o.useState(null),[p,m]=o.useState(!1),[u,f]=o.useState([]),[b,g]=o.useState(sy),[v,x]=o.useState(""),h=o.useMemo(()=>ny(),[]),j=o.useCallback(async()=>{a(!0),x("");try{const w=await ry();f(w)}catch(w){const S=w instanceof Error?w.message:t("settings.openchamber.passkeys.toast.loadFailed");x(S)}finally{a(!1)}},[t]);o.useEffect(()=>{let w=!1;return(async()=>{try{if(!h.supported){w||(n(!1),a(!1));return}w||n(!0)}catch{w||n(!1)}if(!w){const S=await rc();if(g(S),!S.enabled){f([]),a(!1);return}await j()}})(),()=>{w=!0,Ou()}},[j,h.supported]);const y=o.useCallback(async()=>{if(!b.enabled){const w=t("settings.openchamber.passkeys.toast.enableUiPasswordFirst");x(w),G.message(w);return}if(!e){x(h.reason),G.message(h.reason);return}if(i){Ou(),l(!1);return}x(""),l(!0);try{await ay(),g(await rc()),await j(),G.success(t("settings.openchamber.passkeys.toast.added"))}catch(w){if(iy(w)){G.message(t("settings.openchamber.passkeys.toast.setupCanceled"));return}const S=w instanceof Error?w.message:t("settings.openchamber.passkeys.toast.addFailed");x(S),G.error(S)}finally{l(!1)}},[i,j,b.enabled,h.reason,e,t]),C=o.useCallback(async w=>{d(w),x("");try{await oy(w),g(await rc()),await j(),G.success(t("settings.openchamber.passkeys.toast.removed"))}catch(S){const I=S instanceof Error?S.message:t("settings.openchamber.passkeys.toast.removeFailed");x(I),G.error(I)}finally{d(null)}},[j,t]),k=o.useCallback(async()=>{m(!0),x("");try{await ly(),window.location.reload()}catch(w){const S=w instanceof Error?w.message:t("settings.openchamber.passkeys.toast.clearAuthFailed");x(S),G.error(S),m(!1)}},[t]);return s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.openchamber.passkeys.title")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.passkeys.field.currentDevice")})}),s.jsxs("div",{className:"flex items-center gap-2 sm:w-fit",children:[s.jsx(ve,{type:"button",variant:i?"secondary":"outline",size:"xs",onClick:()=>{y()},disabled:r||p,className:"!font-normal",children:t(i?"settings.openchamber.passkeys.actions.cancelSetup":"settings.openchamber.passkeys.actions.add")}),s.jsx(ve,{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:Wp(w.lastUsedAt,t("settings.openchamber.passkeys.time.neverUsed"))}):t("settings.openchamber.passkeys.item.added",{time:Wp(w.createdAt,t("settings.openchamber.passkeys.time.neverUsed"))})}),s.jsx(ve,{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))})]}),v&&s.jsx("div",{className:"mt-1 px-2 py-1.5",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:v})})]})},AC=t=>{const e=yi(t);return e||{providerId:"",modelId:""}},kg=()=>{const{t}=ut(),e=yt(M=>M.setProvider),n=yt(M=>M.setModel),r=yt(M=>M.setAgent),a=yt(M=>M.setCurrentVariant),i=yt(M=>M.setSettingsDefaultModel),l=yt(M=>M.setSettingsDefaultVariant),c=yt(M=>M.setSettingsDefaultAgent),d=yt(M=>M.setSettingsDefaultFileViewerPreview),p=yt(M=>M.settingsDefaultFileViewerPreview),m=Re(M=>M.showDeletionDialog),u=Re(M=>M.setShowDeletionDialog),f=yt(M=>M.providers),[b,g]=o.useState(),[v,x]=o.useState(),[h,j]=o.useState(),[y,C]=o.useState(!0),k=o.useMemo(()=>AC(b),[b]);o.useEffect(()=>{(async()=>{try{let O=null;if(!O){const V=nr()?.settings;if(V)try{const $=(await V.load())?.settings;$&&(O={defaultModel:typeof $.defaultModel=="string"?$.defaultModel:void 0,defaultVariant:typeof $.defaultVariant=="string"?$.defaultVariant:void 0,defaultAgent:typeof $.defaultAgent=="string"?$.defaultAgent:void 0})}catch{}}if(!O){const V=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});V.ok&&(O=await V.json())}if(O){const V=typeof O.defaultModel=="string"&&O.defaultModel.trim().length>0?O.defaultModel.trim():void 0,B=typeof O.defaultVariant=="string"&&O.defaultVariant.trim().length>0?O.defaultVariant.trim():void 0,$=typeof O.defaultAgent=="string"&&O.defaultAgent.trim().length>0?O.defaultAgent.trim():void 0;V!==void 0&&g(V),B!==void 0&&x(B),$!==void 0&&j($)}}catch(O){console.warn("Failed to load defaults settings:",O)}finally{C(!1)}})()},[]);const w=o.useCallback(async(M,O)=>{const V=M&&O?`${M}/${O}`:void 0;g(V),x(void 0),l(void 0),a(void 0),i(V),M&&O&&f.find($=>$.id===M)&&(e(M),n(O));try{await Ss({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,l]),S="__default__",I=o.useCallback(M=>M===S?t("settings.openchamber.defaults.option.default"):M.charAt(0).toUpperCase()+M.slice(1),[t]),T=o.useCallback(async M=>{const O=M===S?void 0:M||void 0;x(O),l(O),a(O);try{await Ss({defaultVariant:O??""})}catch(V){console.warn("Failed to save default variant:",V)}},[a,l]),P=o.useCallback(async M=>{const O=M||void 0;j(O),c(O),M&&r(M);try{await Ss({defaultAgent:O??""})}catch(V){console.warn("Failed to save default agent:",V)}},[r,c]),A=o.useCallback(()=>{const M=!p;d(M),Ss({defaultFileViewerPreview:M}).catch(console.warn)},[p,d]),N=o.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]),E=N.length>0;return o.useEffect(()=>{!E&&v&&(x(void 0),l(void 0),a(void 0),Ss({defaultVariant:""}).catch(()=>{}))},[v,a,l,E]),y?null:s.jsxs("div",{className:"mb-6",children:[s.jsx("div",{className:"mb-0.5 px-1",children:s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.openchamber.defaults.title")})})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[s.jsxs("div",{className:"mt-0 mb-1 typography-meta text-muted-foreground",children:[t("settings.openchamber.defaults.summaryPrefix")," ",k.providerId?s.jsxs("span",{className:"text-foreground",children:[k.providerId,"/",k.modelId,E?` (${v??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(wo,{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(is,{value:v??S,onValueChange:T,disabled:!E,children:[s.jsx(os,{className:"w-fit min-w-[120px]",children:s.jsx(us,{placeholder:t("settings.openchamber.defaults.field.thinkingPlaceholder"),children:I(v??S)})}),s.jsxs(ls,{children:[s.jsx(Mt,{value:S,children:t("settings.openchamber.defaults.option.default")}),N.map(M=>s.jsx(Mt,{value:M,children:I(M)},M))]})]})})]}),s.jsxs("div",{className:"flex flex-col gap-2 py-1 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.defaults.field.defaultAgent")})}),s.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:s.jsx(Kl,{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:M=>{(M.key===" "||M.key==="Enter")&&(M.preventDefault(),u(!m))},children:[s.jsx(xs,{checked:m,onChange:u,ariaLabel:t("settings.openchamber.defaults.field.showDeletionDialogAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.defaults.field.showDeletionDialog")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1",role:"button",tabIndex:0,"aria-pressed":p,onClick:A,onKeyDown:M=>{(M.key===" "||M.key==="Enter")&&(M.preventDefault(),A())},children:[s.jsx(xs,{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")})]})]})]})},Kp={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"}},DC={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"},TC=()=>{const{t}=ut(),e=o.useMemo(()=>Cn(),[]),n=o.useMemo(()=>mn(),[]),r=!e&&!n,a=Re(L=>L.nativeNotificationsEnabled),i=Re(L=>L.setNativeNotificationsEnabled),l=Re(L=>L.notificationMode),c=Re(L=>L.setNotificationMode),d=Re(L=>L.notifyOnSubtasks),p=Re(L=>L.setNotifyOnSubtasks),m=Re(L=>L.notifyOnCompletion),u=Re(L=>L.setNotifyOnCompletion),f=Re(L=>L.notifyOnError),b=Re(L=>L.setNotifyOnError),g=Re(L=>L.notifyOnQuestion),v=Re(L=>L.setNotifyOnQuestion),x=Re(L=>L.notificationTemplates),h=Re(L=>L.setNotificationTemplates),[j,y]=o.useState("default"),[C,k]=o.useState(!1),[w,S]=o.useState(!1),[I,T]=o.useState(!1);o.useEffect(()=>{if(!r){k(!1),S(!1);return}typeof Notification<"u"&&y(Notification.permission);const L=typeof window<"u"&&"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window;k(L),(async()=>{if(!L){S(!1);return}try{const Z=await navigator.serviceWorker.getRegistration();if(!Z){S(!1);return}const ae=await Z.pushManager.getSubscription();S(!!ae)}catch{S(!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 Y=await Notification.requestPermission();y(Y),Y==="granted"?i(!0):G.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.description")})}catch(Y){console.error("Failed to request notification permission:",Y),G.error(t("settings.notifications.page.toast.requestPermissionFailed"))}else i(!!(L&&j==="granted"))},A=e||n||r&&typeof Notification<"u"&&Notification.permission==="granted",N=(L,Y,Z)=>{h({...x,[L]:{...x[L],[Y]:Z}})},E=L=>{const Y="=".repeat((4-L.length%4)%4),Z=(L+Y).replace(/-/g,"+").replace(/_/g,"/"),ae=atob(Z),re=new Uint8Array(ae.length);for(let me=0;me<ae.length;me+=1)re[me]=ae.charCodeAt(me);return re},M=async(L,Y,Z)=>{let ae=null;const re=new Promise((me,fe)=>{ae=setTimeout(()=>{fe(new Error(Z))},Y)});try{return await Promise.race([L,re])}finally{ae&&clearTimeout(ae)}},O=async L=>{if(L.active)return;const Y=L.installing||L.waiting;Y&&Y.state!=="activated"&&await M(new Promise(Z=>{const ae=()=>{Y.state==="activated"&&(Y.removeEventListener("statechange",ae),Z())};Y.addEventListener("statechange",ae),ae()}),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 Y=null;for(const Z of L)try{const ae=Z.opts?navigator.serviceWorker.register("/sw.js",Z.opts):navigator.serviceWorker.register("/sw.js");return await M(ae,1e4,`Service worker registration timed out (${Z.label})`)}catch(ae){Y=ae}throw Y instanceof Error?Y: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 Y=await V();try{await Y.update()}catch{}return await O(Y),Y},$=L=>{const Y=L,Z=[`type=${typeof L}`,`toString=${String(L)}`,`name=${String(Y?.name??"")}`,`message=${String(Y?.message??"")}`];let ae="";try{ae=JSON.stringify(L)}catch{}return{summary:Z.filter(Boolean).join(" | "),json:ae,stack:typeof Y?.stack=="string"?Y.stack:""}},F=async()=>{const L=nr();if(!L?.notifications){G.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"})?G.success(t("settings.notifications.page.toast.testNotificationSent")):G.error(t("settings.notifications.page.toast.testNotificationFailed"))}catch(Y){console.error("Test notification failed:",Y),G.error(t("settings.notifications.page.toast.testNotificationFailed"))}},_=async()=>{if(!C){G.error(t("settings.notifications.page.toast.pushUnsupported"));return}const L=nr();if(!L?.push){G.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}T(!0);try{if(typeof Notification<"u"&&Notification.permission==="default"){const K=await Notification.requestPermission();if(y(K),K!=="granted"){G.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}}if(typeof Notification<"u"&&Notification.permission!=="granted"){G.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}const Y=await L.push.getVapidPublicKey();if(!Y?.publicKey){G.error(t("settings.notifications.page.toast.pushKeyLoadFailed"));return}const Z=await B();await O(Z);const ae=await Z.pushManager.getSubscription();if(!("pushManager"in Z)||!Z.pushManager)throw new Error("PushManager unavailable (requires installed PWA + iOS 16.4+)");const me=(ae??await M(Z.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:E(Y.publicKey)}),15e3,"Push subscription timed out")).toJSON(),fe=me.keys;if(!me.endpoint||!fe?.p256dh||!fe.auth)throw new Error("Push subscription missing keys");if(!(await M(L.push.subscribe({endpoint:me.endpoint,keys:{p256dh:fe.p256dh,auth:fe.auth},origin:typeof window<"u"?window.location.origin:void 0}),15e3,"Push subscribe request timed out"))?.ok){G.error(t("settings.notifications.page.toast.enableBackgroundFailed"));return}S(!0),G.success(t("settings.notifications.page.toast.backgroundEnabled"))}catch(Y){console.error("[Push] Enable failed:",Y);const Z=$(Y);G.error(t("settings.notifications.page.toast.enableBackgroundFailed"),{description:Z.summary})}finally{T(!1)}},q=async()=>{if(!C){S(!1);return}const L=nr();if(!L?.push){G.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}T(!0);try{const Z=await(await B()).pushManager.getSubscription();if(!Z){S(!1);return}const ae=Z.endpoint;await Z.unsubscribe(),await L.push.unsubscribe({endpoint:ae}),S(!1),G.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&&A,onClick:()=>{P(!(a&&A))},onKeyDown:L=>{(L.key===" "||L.key==="Enter")&&(L.preventDefault(),P(!(a&&A)))},children:[s.jsx(xs,{checked:a&&A,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&&A&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":l==="always",onClick:()=>c(l==="always"?"hidden-only":"always"),onKeyDown:L=>{(L.key===" "||L.key==="Enter")&&(L.preventDefault(),c(l==="always"?"hidden-only":"always"))},children:[s.jsx(xs,{checked:l==="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(ve,{type:"button",variant:"outline",size:"sm",onClick:()=>{F()},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&&A&&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(xs,{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(xs,{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(xs,{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":g,onClick:()=>v(!g),onKeyDown:L=>{(L.key===" "||L.key==="Enter")&&(L.preventDefault(),v(!g))},children:[s.jsx(xs,{checked:g,onChange:v,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(DC[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(Bt,{value:x[L].title,onChange:Y=>N(L,"title",Y.target.value),className:"h-7",placeholder:t(Kp[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(Bt,{value:x[L].message,onChange:Y=>N(L,"message",Y.target.value),className:"h-7",placeholder:t(Kp[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(xs,{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")})})]})})]})]})},qn=t=>{if(!t)return;t.pause();const{src:e}=t;e.startsWith("blob:")&&URL.revokeObjectURL(e),t.removeAttribute("src"),t.load()},MC=[{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:"Українська"}],EC=t=>{const e=ot.c(45),{modelId:n}=t,{t:r}=ut();let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=Ui.getModelStatus(),e[0]=a):a=e[0];const[i,l]=_e.useState(a),[c,d]=_e.useState(!1);let p,m;e[1]===Symbol.for("react.memo_cache_sentinel")?(p=()=>{const w=S=>l(S);return Ui.onModelStatusChange=w,OC},m=[],e[1]=p,e[2]=m):(p=e[1],m=e[2]),_e.useEffect(p,m);const u=Ui.getCurrentModelId(),f=i.state==="downloading"||i.state==="loading";let b,g;e[3]!==i.state?(b=()=>{i.state!=="downloading"&&i.state!=="loading"&&d(!1)},g=[i.state],e[3]=i.state,e[4]=b,e[5]=g):(b=e[4],g=e[5]),_e.useEffect(b,g);let v;e[6]!==n?(v=async()=>{d(!0);try{await Ui.loadModel(n)}catch{}},e[6]=n,e[7]=v):v=e[7];const x=v;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 S;return e[10]!==w?(S=s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("span",{className:"typography-ui-compact text-green-600 dark:text-green-400",children:w})}),e[10]=w,e[11]=S):S=e[11],S}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 S=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=S!==void 0?` (${S}%)`:"";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 S;e[23]!==r?(S=r("settings.voice.page.stt.wasmRetry"),e[23]=r,e[24]=S):S=e[24];let I;e[25]!==x||e[26]!==c||e[27]!==S?(I=s.jsx(ve,{variant:"chip",size:"xs",disabled:c,onClick:x,children:S}),e[25]=x,e[26]=c,e[27]=S,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 y;e[36]!==r?(y=r("settings.voice.page.stt.wasmDownload"),e[36]=r,e[37]=y):y=e[37];let C;e[38]!==x||e[39]!==c||e[40]!==y?(C=s.jsx(ve,{variant:"chip",size:"xs",disabled:c,onClick:x,children:y}),e[38]=x,e[39]=c,e[40]=y,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},RC=[{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"}],FC=()=>{const{t}=ut(),{isMobile:e}=an(),{isSupported:n,language:r,setLanguage:a}=cy(),i=yt(z=>z.voiceProvider),l=yt(z=>z.setVoiceProvider),c=yt(z=>z.speechRate),d=yt(z=>z.setSpeechRate),p=yt(z=>z.speechPitch),m=yt(z=>z.setSpeechPitch),u=yt(z=>z.speechVolume),f=yt(z=>z.setSpeechVolume),b=yt(z=>z.sayVoice),g=yt(z=>z.setSayVoice),v=yt(z=>z.browserVoice),x=yt(z=>z.setBrowserVoice),h=yt(z=>z.openaiVoice),j=yt(z=>z.setOpenaiVoice),y=yt(z=>z.openaiApiKey),C=yt(z=>z.setOpenaiApiKey),k=yt(z=>z.openaiCompatibleUrl),w=yt(z=>z.setOpenaiCompatibleUrl),S=yt(z=>z.openaiCompatibleApiKey),I=yt(z=>z.setOpenaiCompatibleApiKey),T=yt(z=>z.openaiCompatibleVoice),P=yt(z=>z.setOpenaiCompatibleVoice),A=yt(z=>z.openaiCompatibleTtsModel),N=yt(z=>z.setOpenaiCompatibleTtsModel),E=yt(z=>z.showMessageTTSButtons),M=yt(z=>z.sttProvider),O=yt(z=>z.setSttProvider),V=yt(z=>z.sttServerUrl),B=yt(z=>z.setSttServerUrl),$=yt(z=>z.sttApiKey),F=yt(z=>z.setSttApiKey),_=yt(z=>z.sttModel),q=yt(z=>z.setSttModel),L=yt(z=>z.wasmSttModel),Y=yt(z=>z.setWasmSttModel),Z=yt(z=>z.sttLanguage),ae=yt(z=>z.setSttLanguage),re=yt(z=>z.sttSilenceThresholdDb),me=yt(z=>z.setSttSilenceThresholdDb),fe=yt(z=>z.sttSilenceHoldMs),H=yt(z=>z.setSttSilenceHoldMs),K=yt(z=>z.sttTranscribeOnStop),Q=yt(z=>z.setSttTranscribeOnStop),W=yt(z=>z.setShowMessageTTSButtons),de=yt(z=>z.voiceModeEnabled),be=yt(z=>z.setVoiceModeEnabled),[we,te]=_e.useState(!1),[ge,ue]=_e.useState([]),[xe,ne]=_e.useState(!1),[pe,J]=_e.useState(null),[Se,he]=_e.useState(!1),[Ie,Pe]=_e.useState(!1),[Ce,X]=_e.useState(null),[ie,Ne]=_e.useState(!1),[oe,ke]=_e.useState(null),[Te,Be]=_e.useState([]),[je,ee]=_e.useState(!1);_e.useEffect(()=>((async()=>{const De=await ac.waitForVoices();Be(De)})(),"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=()=>{Be(window.speechSynthesis.getVoices())}),()=>{"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=null)}),[]);const R=_e.useMemo(()=>Te.filter(z=>z.lang).sort((z,De)=>{const Xe=z.lang.startsWith("en"),st=De.lang.startsWith("en");if(Xe&&!st)return-1;if(!Xe&&st)return 1;const tt=z.lang.localeCompare(De.lang);return tt!==0?tt:z.name.localeCompare(De.name)}),[Te]),U=_e.useCallback(()=>{if(je){ac.cancelSpeech(),ee(!1);return}const z=Te.find(tt=>tt.name===v),De=z?.name??t("settings.voice.page.preview.browserVoiceFallback"),Xe=t("settings.voice.page.preview.voiceLine",{voiceName:De});ee(!0);const st=new SpeechSynthesisUtterance(Xe);st.rate=c,st.pitch=p,st.volume=u,z&&(st.voice=z,st.lang=z.lang),st.onend=()=>ee(!1),st.onerror=()=>ee(!1),window.speechSynthesis.cancel(),window.speechSynthesis.speak(st)},[v,Te,c,p,u,je,t]);_e.useEffect(()=>()=>{je&&ac.cancelSpeech()},[je]),_e.useEffect(()=>{if(!de||i!=="openai"&&i!=="openai-compatible"){he(y.trim().length>0);return}(async()=>{try{const st=(await(await fetch("/api/tts/status")).json()).available,tt=y.trim().length>0;he(st||tt)}catch{he(y.trim().length>0)}})()},[y,de,i]),_e.useEffect(()=>{if(!de){te(!1),ue([]);return}fetch("/api/tts/say/status").then(z=>z.json()).then(z=>{if(te(z.available),z.voices){const De=z.voices.filter((Xe,st,tt)=>tt.findIndex(Ue=>Ue.name===Xe.name)===st).sort((Xe,st)=>Xe.name.localeCompare(st.name));ue(De)}}).catch(()=>{te(!1)})},[de]);const le=_e.useCallback(async()=>{if(pe){qn(pe),J(null),ne(!1);return}ne(!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 Xe=await De.blob(),st=URL.createObjectURL(Xe);z=new Audio(st),z.onended=()=>{qn(z),J(null),ne(!1)},z.onerror=()=>{qn(z),J(null),ne(!1)},J(z),await z.play()}catch{qn(z),J(null),ne(!1)}},[b,c,pe,t]);_e.useEffect(()=>()=>{qn(pe)},[pe]);const Me=_e.useCallback(async()=>{if(Ce){qn(Ce),X(null),Pe(!1);return}Pe(!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:y||void 0})});if(!De.ok){const tt=await De.json().catch(()=>({error:"Unknown error"}));throw new Error(tt.error||`HTTP ${De.status}`)}const Xe=await De.blob(),st=URL.createObjectURL(Xe);z=new Audio(st),z.onended=()=>{qn(z),X(null),Pe(!1)},z.onerror=()=>{qn(z),X(null),Pe(!1)},X(z),await z.play()}catch{qn(z),X(null),Pe(!1)}},[h,c,Ce,y,t]);_e.useEffect(()=>()=>{qn(Ce)},[Ce]);const Oe=_e.useCallback(async()=>{if(oe){qn(oe),ke(null),Ne(!1);return}if(!k.trim())return;Ne(!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:A||void 0,speed:c,baseURL:k,apiKey:S||void 0})});if(!De.ok){const tt=await De.json().catch(()=>({error:"Unknown error"}));throw new Error(tt.error||`HTTP ${De.status}`)}const Xe=await De.blob(),st=URL.createObjectURL(Xe);z=new Audio(st),z.onended=()=>{qn(z),ke(null),Ne(!1)},z.onerror=()=>{qn(z),ke(null),Ne(!1)},ke(z),await z.play()}catch{qn(z),ke(null),Ne(!1)}},[k,T,A,S,c,oe,t]);_e.useEffect(()=>()=>{qn(oe)},[oe]);const Ae="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:()=>be(!de),onKeyDown:z=>{(z.key===" "||z.key==="Enter")&&(z.preventDefault(),be(!de))},children:[s.jsx(xs,{checked:de,onChange:be,ariaLabel:t("settings.voice.page.field.enableVoiceModeAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.enableVoiceMode")})]}),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(D,{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(ve,{variant:"chip",size:"xs","aria-pressed":i==="browser",onClick:()=>l("browser"),className:"!font-normal",children:t("settings.voice.page.provider.browser")}),s.jsx(ve,{variant:"chip",size:"xs","aria-pressed":i==="openai",onClick:()=>l("openai"),className:"!font-normal",children:"OpenAI"}),s.jsx(ve,{variant:"chip",size:"xs","aria-pressed":i==="openai-compatible",onClick:()=>l("openai-compatible"),className:"!font-normal",children:t("settings.voice.page.provider.custom")}),we&&s.jsxs(ve,{variant:"chip",size:"xs","aria-pressed":i==="say",onClick:()=>l("say"),className:"!font-normal",children:[s.jsx(D,{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&&!y?"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:y,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"}),y&&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(D,{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(D,{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:S,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"}),S&&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(D,{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:A,onChange:z=>N(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(ve,{size:"xs",variant:"ghost",onClick:Oe,title:t("settings.voice.page.actions.preview"),disabled:!k.trim(),children:ie?s.jsx(D,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(D,{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(is,{value:h,onValueChange:j,children:[s.jsx(os,{className:"w-fit",children:s.jsx(us,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(ls,{children:RC.map(z=>s.jsx(Mt,{value:z.value,children:z.label},z.value))})]}),s.jsx(ve,{size:"xs",variant:"ghost",onClick:Me,title:t("settings.voice.page.actions.preview"),children:Ie?s.jsx(D,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(D,{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"&&we&&ge.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(is,{value:b,onValueChange:g,children:[s.jsx(os,{className:"w-fit",children:s.jsx(us,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(ls,{children:ge.map(z=>s.jsx(Mt,{value:z.name,children:z.name},z.name))})]}),s.jsx(ve,{size:"xs",variant:"ghost",onClick:le,title:t("settings.voice.page.actions.preview"),children:xe?s.jsx(D,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(D,{name:"play",className:"w-3.5 h-3.5"})})]}),i==="browser"&&R.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(is,{value:v||"$auto",onValueChange:z=>x(z==="$auto"?"":z),children:[s.jsx(os,{className:"w-fit max-w-[200px]",children:s.jsx(us,{placeholder:t("settings.voice.page.field.auto")})}),s.jsxs(ls,{children:[s.jsx(Mt,{value:"$auto",children:t("settings.voice.page.field.auto")}),R.map(z=>s.jsxs(Mt,{value:z.name,children:[z.name," (",z.lang,")"]},z.name))]})]}),s.jsx(ve,{size:"xs",variant:"ghost",onClick:U,title:t("settings.voice.page.actions.preview"),children:je?s.jsx(D,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(D,{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:Ae}),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:Ae}),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:Ae}),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(is,{value:r,onValueChange:a,disabled:!n,children:[s.jsx(os,{className:"w-fit",children:s.jsx(us,{placeholder:t("settings.voice.page.field.selectLanguagePlaceholder")})}),s.jsx(ls,{children:MC.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(D,{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(ve,{variant:"chip",size:"xs","aria-pressed":M==="browser",onClick:()=>O("browser"),className:"!font-normal",children:t("settings.voice.page.provider.browser")}),s.jsx(ve,{variant:"chip",size:"xs","aria-pressed":M==="server",onClick:()=>O("server"),className:"!font-normal",children:t("settings.voice.page.provider.server")}),s.jsx(ve,{variant:"chip",size:"xs","aria-pressed":M==="wasm",onClick:()=>O("wasm"),className:"!font-normal",children:t("settings.voice.page.provider.wasm")})]})]})}),M==="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(xs,{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")})]}),!dy.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(D,{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=>F(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:()=>F(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(D,{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=>ae(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:re,onChange:z=>me(Number(z.target.value)),className:Ae}),s.jsxs("span",{className:"typography-ui-label text-foreground tabular-nums min-w-[3.5rem] text-right",children:[re," 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:fe,onChange:z=>H(Number(z.target.value)),className:Ae}),s.jsx(_n,{value:fe,onValueChange:H,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")})]})]})]}),M==="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(is,{value:L,onValueChange:Y,children:[s.jsx(os,{className:"mt-0.5",children:s.jsx(us,{placeholder:t("settings.voice.page.stt.wasmModel")})}),s.jsx(ls,{children:Lu.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:Lu.find(z=>z.id===L)?.description})]}),s.jsx(EC,{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":E,onClick:()=>W(!E),onKeyDown:z=>{(z.key===" "||z.key==="Enter")&&(z.preventDefault(),W(!E))},children:[s.jsx(xs,{checked:E,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 OC(){Ui.onModelStatusChange=null}const Lc=[{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}],$c=[{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}],LC="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/get-started/create-remote-tunnel/",$C="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/do-more-with-tunnels/local-management/configuration-file/",Hp=[{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"}],_C=[".yml",".yaml",".json"],BC="settings.openchamber.tunnel.error.invalidConfigExtension",Bi=t=>{const e=t.trim().toLowerCase();return _C.some(n=>e.endsWith(n))},Cg=t=>t==="cloudflare"?"Cloudflare":t,Gp=t=>{const e=ot.c(11),{provider:n}=t;let r;e[0]!==n?(r=Cg(n),e[0]=n,e[1]=r):r=e[1];const a=r,l=n==="cloudflare"?"text-[var(--status-warning)]":"text-muted-foreground";let c;e[2]!==l?(c=ye("size-4 shrink-0",l),e[2]=l,e[3]=c):c=e[3];let d;e[4]!==c?(d=s.jsx(D,{name:"cloud",className:c}),e[4]=c,e[5]=d):d=e[5];let p;e[6]!==a?(p=s.jsx("span",{children:a}),e[6]=a,e[7]=p):p=e[7];let m;return e[8]!==d||e[9]!==p?(m=s.jsxs("span",{className:"flex items-center gap-2",children:[d,p]}),e[8]=d,e[9]=p,e[10]=m):m=e[10],m},ka=t=>t==="quick"?"quick":t==="managed-remote"?"managed-remote":t==="managed-local"?"managed-local":"quick",qp=(t,e,n)=>t.find(a=>a.ms===e)?.value||n,Yp=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`},VC=t=>new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"}),al=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()}},zC=t=>{if(!Array.isArray(t))return[];const e=new Set,n=new Set,r=[];for(const a of t){if(!a||typeof a!="object")continue;const i=a,l=typeof i.id=="string"?i.id.trim():"",c=typeof i.name=="string"?i.name.trim():"",d=al(typeof i.hostname=="string"?i.hostname:"");!l||!c||!d||e.has(l)||n.has(d)||(e.add(l),n.add(d),r.push({id:l,name:c,hostname:d}))}return r},UC=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2,10)}`,WC=()=>{const{t}=ut(),e=o.useCallback(ce=>t(ce),[t]),[n,r]=o.useState("checking"),[a,i]=o.useState(null),[l,c]=o.useState(null),[d,p]=o.useState(null),[m,u]=o.useState(null),[f,b]=o.useState(null),[g,v]=o.useState(!1),[x,h]=o.useState(!1),[j,y]=o.useState(!1),[C,k]=o.useState("cloudflare"),[w,S]=o.useState([]),[I,T]=o.useState("quick"),[P,A]=o.useState(null),[N,E]=o.useState([]),[M,O]=o.useState({}),[V,B]=o.useState(""),[$,F]=o.useState({}),[_,q]=o.useState(new Set),[L,Y]=o.useState(!1),[Z,ae]=o.useState(""),[re,me]=o.useState(""),[fe,H]=o.useState(""),[K,Q]=o.useState(1800*1e3),[W,de]=o.useState(480*60*1e3),[be,we]=o.useState(""),[te,ge]=o.useState([]),[ue,xe]=o.useState(()=>Date.now()),[ne,pe]=o.useState(null),J=t(BC),Se=o.useRef(null),he=o.useMemo(()=>P?!Bi(P):!1,[P]),Ie=o.useMemo(()=>N.find(ce=>ce.id===V)||N[0]||null,[N,V]),Pe=o.useMemo(()=>te.map(ce=>{const We=ce.expiresAt<=ue,Le=ce.status==="active"&&!We,Ge=Le?Yp(ce.expiresAt-ue):ce.inactiveReason==="expired"||We?"expired":"inactive",at=Ge==="expired"?t("settings.openchamber.tunnel.state.expired"):ce.inactiveReason==="tunnel-revoked"?t("settings.openchamber.tunnel.state.revoked"):t("settings.openchamber.tunnel.state.inactive"),He=ka(ce.mode);return{...ce,isActive:Le,mode:He,remainingTextForSession:Ge,inactiveLabel:at}}),[ue,te,t]),Ce=o.useMemo(()=>a?.connectUrl?a.bootstrapExpiresAt===null?!0:a.bootstrapExpiresAt>ue:!1,[ue,a?.bootstrapExpiresAt,a?.connectUrl]),X=o.useMemo(()=>!a||n!=="active"&&n!=="stopping"?!1:l===I,[l,n,a,I]),ie=o.useMemo(()=>!a||n!=="active"||!l?!1:l!==I,[l,n,a,I]),Ne=o.useMemo(()=>{if(typeof ne=="number"&&Number.isFinite(ne)&&ne>0)return ne;if(typeof window>"u")return null;const ce=Number(window.location.port);return Number.isFinite(ce)&&ce>0?ce:null},[ne]),oe=o.useCallback(async ce=>{await Zn(ce)},[]),ke=o.useCallback(async ce=>{try{const[We,Le,Ge,at]=await Promise.all([fetch("/api/openchamber/tunnel/check",{signal:ce}),fetch("/api/openchamber/tunnel/status",{signal:ce}),fetch("/api/config/settings",{signal:ce,headers:{Accept:"application/json"}}),fetch("/api/openchamber/tunnel/providers",{signal:ce})]),He=await We.json(),ze=await Le.json(),et=Ge.ok?await Ge.json():{},gt=at.ok?await at.json():{},Pt=ze.ttlConfig?.bootstrapTtlMs??(et?.tunnelBootstrapTtlMs===null?null:typeof et?.tunnelBootstrapTtlMs=="number"?et.tunnelBootstrapTtlMs:1800*1e3),Nt=typeof ze.ttlConfig?.sessionTtlMs=="number"?ze.ttlConfig.sessionTtlMs:typeof et?.tunnelSessionTtlMs=="number"?et.tunnelSessionTtlMs:480*60*1e3,ht=ka(ze.mode??et?.tunnelMode),wt=typeof et?.tunnelProvider=="string"&&et.tunnelProvider.trim().length>0?et.tunnelProvider.trim().toLowerCase():"cloudflare",es=typeof et?.managedLocalTunnelConfigPath=="string"&&et.managedLocalTunnelConfigPath.trim()||null,Vt=zC(ze?.managedRemoteTunnelPresets),Jt=typeof ze.managedRemoteTunnelHostname=="string"?ze.managedRemoteTunnelHostname:"",mt=Vt.length>0?Vt:Jt?[{id:`legacy-${al(Jt)}`,name:Jt,hostname:al(Jt)}]:[],Lt=mt[0]?.id||"";if(Q(Pt),de(Nt),k(wt),S(Array.isArray(gt?.providers)?gt.providers:[]),T(ht),A(es),E(mt),B(Lt),ge(Array.isArray(ze.activeSessions)?ze.activeSessions:[]),c(ze.activeTunnelMode?ka(ze.activeTunnelMode):ze.active&&ze.mode?ka(ze.mode):null),q(new Set(Array.isArray(ze.managedRemoteTunnelTokenPresetIds)?ze.managedRemoteTunnelTokenPresetIds:[])),pe(typeof ze.localPort=="number"?ze.localPort:null),ze.active&&ze.url){i({url:ze.url,connectUrl:null,bootstrapExpiresAt:typeof ze.bootstrapExpiresAt=="number"?ze.bootstrapExpiresAt:null}),r("active");return}r(He.available?"idle":"not-available")}catch{ce.aborted||(r("error"),u(t("settings.openchamber.tunnel.toast.checkAvailabilityFailed")))}},[t]);o.useEffect(()=>{const ce=new AbortController;return ke(ce.signal),()=>ce.abort()},[ke]),o.useEffect(()=>{if(!a?.connectUrl){p(null);return}let ce=!1;return Tx.toDataURL(a.connectUrl,{width:256,margin:2,color:{dark:"#000000",light:"#ffffff"}}).then(We=>{ce||p(We)}).catch(()=>{ce||p(null)}),()=>{ce=!0}},[a?.connectUrl]),o.useEffect(()=>{if(!a?.bootstrapExpiresAt){we(t("settings.openchamber.tunnel.state.noExpiry"));return}let ce=null,We=Date.now();const Le=()=>{const He=a.bootstrapExpiresAt?a.bootstrapExpiresAt-Date.now():0;He<=0?we(t("settings.openchamber.tunnel.state.expired")):we(Yp(He))},Ge=()=>{const He=Date.now();He-We>=1e3&&(Le(),We=He),ce=requestAnimationFrame(Ge)};Le(),(typeof document>"u"||document.visibilityState==="visible")&&(ce=requestAnimationFrame(Ge));const at=()=>{document.visibilityState==="visible"&&ce===null?ce=requestAnimationFrame(Ge):document.visibilityState!=="visible"&&ce!==null&&(cancelAnimationFrame(ce),ce=null)};return document.addEventListener("visibilitychange",at),()=>{document.removeEventListener("visibilitychange",at),ce!==null&&cancelAnimationFrame(ce)}},[t,a?.bootstrapExpiresAt]),o.useEffect(()=>{let ce=null,We=Date.now();const Le=()=>{const at=Date.now();at-We>=1e3&&(xe(at),We=at),ce=requestAnimationFrame(Le)};(typeof document>"u"||document.visibilityState==="visible")&&(ce=requestAnimationFrame(Le));const Ge=()=>{document.visibilityState==="visible"&&ce===null?ce=requestAnimationFrame(Le):document.visibilityState!=="visible"&&ce!==null&&(cancelAnimationFrame(ce),ce=null)};return document.addEventListener("visibilitychange",Ge),()=>{document.removeEventListener("visibilitychange",Ge),ce!==null&&cancelAnimationFrame(ce)}},[]),o.useEffect(()=>{if(n==="starting"||n==="stopping"||n==="checking")return;let ce=!1;const We=async()=>{try{const Ge=await fetch("/api/openchamber/tunnel/status");if(!Ge.ok||ce)return;const at=await Ge.json();if(ce)return;ge(Array.isArray(at.activeSessions)?at.activeSessions:[]),q(new Set(Array.isArray(at.managedRemoteTunnelTokenPresetIds)?at.managedRemoteTunnelTokenPresetIds:[])),pe(typeof at.localPort=="number"?at.localPort:null)}catch{}},Le=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||We()},5e3);return()=>{ce=!0,window.clearInterval(Le)}},[n]);const Te=o.useCallback(async ce=>{y(!0);try{await Ss(ce),Object.prototype.hasOwnProperty.call(ce,"tunnelMode")&&ce.tunnelMode&&T(ce.tunnelMode),Object.prototype.hasOwnProperty.call(ce,"tunnelProvider")&&typeof ce.tunnelProvider=="string"&&k(ce.tunnelProvider),Object.prototype.hasOwnProperty.call(ce,"managedLocalTunnelConfigPath")&&A(ce.managedLocalTunnelConfigPath??null),Object.prototype.hasOwnProperty.call(ce,"managedRemoteTunnelPresets")&&ce.managedRemoteTunnelPresets&&E(ce.managedRemoteTunnelPresets)}catch{G.error(t("settings.openchamber.tunnel.toast.saveSettingsFailed"))}finally{y(!1)}},[t]),Be=o.useCallback(async(ce,We)=>{h(!0);try{await Ss({tunnelBootstrapTtlMs:ce,tunnelSessionTtlMs:We})}catch{G.error(t("settings.openchamber.tunnel.toast.saveTtlFailed"))}finally{h(!1)}},[t]),je=o.useCallback(async ce=>{const We=ce.token.trim();if(We)try{const Le={...$,[ce.presetId]:We};await Ss({managedRemoteTunnelPresetTokens:Le}),q(Ge=>{const at=new Set(Ge);return at.add(ce.presetId),at})}catch{G.error(t("settings.openchamber.tunnel.toast.saveTokenFailed"))}},[$,t]),ee=o.useCallback(async ce=>{b(null),u(null),await Te({tunnelProvider:ce})},[Te]),R=o.useCallback(async()=>{const ce=await sh({filters:[{name:"Config",extensions:["yml","yaml","json"]}]});if(ce.success&&typeof ce.path=="string"&&ce.path.trim().length>0){const We=ce.path.trim();if(!Bi(We)){G.error(J);return}A(We),await Te({managedLocalTunnelConfigPath:We});return}Se.current?.click()},[J,Te]),U=o.useCallback(ce=>{const We=ce.trim();A(We.length>0?We:null)},[]),le=o.useCallback(async()=>{if(P&&!Bi(P)){G.error(J);return}await Te({managedLocalTunnelConfigPath:P})},[J,P,Te]),Me=o.useCallback(async()=>{A(null),await Te({managedLocalTunnelConfigPath:null})},[Te]),Oe=o.useCallback(async ce=>{const We=ce.target.files?.[0];if(!We)return;const Le=We.name.trim();if(Le.length!==0){if(!Bi(Le)){G.error(J);return}A(Le),await Te({managedLocalTunnelConfigPath:Le}),ce.target.value=""}},[J,Te]),Ae=o.useCallback(async()=>{if(u(null),b(null),I==="managed-local"&&P&&!Bi(P)){u(J),G.error(J);return}r("starting");try{let ce="",We="";if(I==="managed-remote"){if(!Ie){r("idle"),b(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst")),G.error(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst"));return}ce=Ie.hostname,We=($[Ie.id]||"").trim(),await Te({tunnelMode:"managed-remote",managedRemoteTunnelPresets:N})}const Le=await fetch("/api/openchamber/tunnel/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:C,mode:I,...I==="managed-remote"&&Ie?{managedRemoteTunnelPresetId:Ie.id,managedRemoteTunnelPresetName:Ie.name}:{},...I==="managed-remote"&&ce?{managedRemoteTunnelHostname:ce}:{},...I==="managed-remote"&&We?{managedRemoteTunnelToken:We}:{},...I==="managed-local"&&P?{configPath:P}:{}})}),Ge=await Le.json();if(!Le.ok||!Ge.ok){if(I==="managed-remote"&&typeof Ge.error=="string"&&Ge.error.includes("Managed remote tunnel token is required")){r("idle"),b(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequiredBeforeStarting")),G.error(t("settings.openchamber.tunnel.toast.addManagedRemoteTokenBeforeStarting"));return}r("error"),u(Ge.error||t("settings.openchamber.tunnel.toast.startFailed")),G.error(Ge.error||t("settings.openchamber.tunnel.toast.startFailed"));return}const at=typeof Ge.url=="string"?Ge.url:"";if(!at){r("error"),u(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl")),G.error(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl"));return}if(i({url:at,connectUrl:typeof Ge.connectUrl=="string"?Ge.connectUrl:null,bootstrapExpiresAt:typeof Ge.bootstrapExpiresAt=="number"?Ge.bootstrapExpiresAt:null}),c(Ge.activeTunnelMode?ka(Ge.activeTunnelMode):Ge.mode?ka(Ge.mode):I),ge(Array.isArray(Ge.activeSessions)?Ge.activeSessions:[]),Array.isArray(Ge.managedRemoteTunnelTokenPresetIds)&&q(new Set(Ge.managedRemoteTunnelTokenPresetIds)),typeof Ge.localPort=="number"&&pe(Ge.localPort),typeof Ge.mode=="string"&&T(ka(Ge.mode)),r("active"),Ge.replacedTunnel){const He=typeof Ge.revokedBootstrapCount=="number"?Ge.revokedBootstrapCount:0,ze=typeof Ge.invalidatedSessionCount=="number"?Ge.invalidatedSessionCount:0;He===1&&ze===1?G.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleSingle")):He===1?G.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleManySessions",{invalidatedSessionCount:ze})):ze===1?G.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyLinksSingleSession",{revokedBootstrapCount:He})):G.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyMany",{revokedBootstrapCount:He,invalidatedSessionCount:ze}))}else G.success(t("settings.openchamber.tunnel.toast.linkReady"))}catch{r("error"),u(t("settings.openchamber.tunnel.toast.startFailed")),G.error(t("settings.openchamber.tunnel.toast.startFailed"))}},[J,N,Te,Ie,$,t,C,I,P]),z=o.useCallback(async()=>{r("stopping");try{await fetch("/api/openchamber/tunnel/stop",{method:"POST"});const ce=await fetch("/api/openchamber/tunnel/status");if(ce.ok){const We=await ce.json();ge(Array.isArray(We.activeSessions)?We.activeSessions:[]),q(new Set(Array.isArray(We.managedRemoteTunnelTokenPresetIds)?We.managedRemoteTunnelTokenPresetIds:[])),pe(typeof We.localPort=="number"?We.localPort:null)}i(null),c(null),p(null),r("idle"),G.success(t("settings.openchamber.tunnel.toast.stopped"))}catch{r("error"),u(t("settings.openchamber.tunnel.toast.stopFailed")),G.error(t("settings.openchamber.tunnel.toast.stopFailed"))}},[t]),De=o.useCallback(async()=>{if(a?.connectUrl)try{await navigator.clipboard.writeText(a.connectUrl),v(!0),G.success(t("settings.openchamber.tunnel.toast.connectLinkCopied")),setTimeout(()=>v(!1),2e3)}catch{G.error(t("settings.openchamber.tunnel.toast.copyUrlFailed"))}},[t,a?.connectUrl]),Xe=o.useCallback(async ce=>{const We=Lc.find(Le=>Le.value===ce);We&&(Q(We.ms),await Be(We.ms,W))},[Be,W]),st=o.useCallback(async ce=>{const We=$c.find(Le=>Le.value===ce);!We||We.ms===null||(de(We.ms),await Be(K,We.ms))},[K,Be]),tt=o.useCallback(async ce=>{b(null),u(null),n!=="active"&&n!=="stopping"&&n!=="starting"&&r("idle"),await Te({tunnelMode:ce,managedRemoteTunnelPresets:N})},[N,Te,n]),Ue=o.useCallback(async(ce,We)=>{try{await Ss({managedRemoteTunnelPresets:We})}catch{G.error(t("settings.openchamber.tunnel.toast.saveSelectedManagedRemoteFailed"))}},[t]),it=o.useCallback(ce=>{const We=N.find(Le=>Le.id===ce);We&&(B(We.id),b(null),Ue(We,N))},[N,Ue]),Ye=o.useCallback(async()=>{const ce=Z.trim(),We=al(re),Le=fe.trim();if(!ce){G.error(t("settings.openchamber.tunnel.toast.tunnelNameRequired"));return}if(!We){G.error(t("settings.openchamber.tunnel.toast.managedRemoteHostnameRequired"));return}if(!Le){G.error(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequired"));return}if(N.some(He=>He.hostname===We)){G.error(t("settings.openchamber.tunnel.toast.hostnameAlreadyExists"));return}const Ge={id:UC(),name:ce,hostname:We},at=[...N,Ge];E(at),B(Ge.id),O(He=>({...He,[Ge.id]:!0})),F(He=>({...He,[Ge.id]:Le})),b(null),Y(!1),ae(""),me(""),H(""),await Te({tunnelMode:"managed-remote",managedRemoteTunnelPresets:at,managedRemoteTunnelPresetTokens:{...$,[Ge.id]:Le}}),await je({presetId:Ge.id,presetName:Ge.name,hostname:Ge.hostname,token:Le}),G.success(t("settings.openchamber.tunnel.toast.managedRemoteSaved"))},[N,re,Z,fe,je,Te,$,t]),rt=o.useCallback(async ce=>{const We=N.find(ze=>ze.id===ce);if(!We)return;const Le=N.filter(ze=>ze.id!==We.id),Ge=Le[0]?.id||"",at=V===We.id?Ge:V,He=Object.fromEntries(Object.entries($).filter(([ze,et])=>ze!==We.id&&et.trim().length>0));E(Le),B(at),O(ze=>{const et={...ze};return delete et[We.id],et}),F(ze=>{const et={...ze};return delete et[We.id],et}),q(ze=>{const et=new Set(ze);return et.delete(We.id),et}),b(null),await Te({managedRemoteTunnelPresets:Le,managedRemoteTunnelPresetTokens:He}),G.success(t("settings.openchamber.tunnel.toast.managedRemoteRemoved"))},[N,Te,V,$,t]),Je="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")})]}),Pe.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(D,{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:Pe.map(ce=>{const We=ce.mode==="quick",Le=ce.mode==="managed-remote",Ge=We?"border-[var(--status-warning-border)] bg-[var(--status-warning-background)] text-[var(--status-warning)]":Le?"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)]",at=ce.isActive?We?"text-[var(--status-warning)]":Le?"text-[var(--status-info)]":"text-[var(--status-success)]":"text-muted-foreground/50",He=t(We?"settings.openchamber.tunnel.badge.quick":Le?"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(D,{name:"checkbox-blank-circle-fill",className:ye("size-2.5 shrink-0",at)}),s.jsx("span",{className:ye("typography-micro rounded border px-1.5 py-0.5 uppercase",Ge),children:He}),s.jsx("span",{className:"typography-meta text-muted-foreground/80",children:t("settings.openchamber.tunnel.session.redeemedAt",{time:VC(ce.createdAt)})}),s.jsx("span",{className:"typography-meta text-foreground",children:ce.isActive?t("settings.openchamber.tunnel.session.expiresIn",{remaining:ce.remainingTextForSession}):ce.inactiveLabel===t("settings.openchamber.tunnel.state.inactive")?t("settings.openchamber.tunnel.state.inactive"):t("settings.openchamber.tunnel.session.inactiveWithReason",{reason:ce.inactiveLabel})})]},ce.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(D,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"typography-meta font-medium text-foreground",children:t("settings.openchamber.tunnel.notAvailable.cloudflaredNotFound")}),s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.openchamber.tunnel.notAvailable.installHint")}),s.jsx("code",{className:"typography-code block rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:"brew install cloudflared"})]})]})}),n!=="not-available"&&s.jsxs("section",{className:"space-y-4 px-2 pb-2 pt-0",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.tunnel.field.provider")}),s.jsxs(is,{value:C,onValueChange:ce=>{ee(ce)},disabled:j||n==="starting"||n==="stopping",children:[s.jsx(os,{className:"max-w-[16rem]",children:s.jsx(us,{placeholder:t("settings.openchamber.tunnel.field.providerPlaceholder"),children:Cg(C)})}),s.jsxs(ls,{children:[w.length>0?w.map(ce=>s.jsx(Mt,{value:ce.provider,children:s.jsx(Gp,{provider:ce.provider})},ce.provider)):s.jsx(Mt,{value:"cloudflare",children:s.jsx(Gp,{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:Hp.map(ce=>s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(ve,{variant:"chip",size:"xs","aria-pressed":I===ce.value,className:"!font-normal",onClick:()=>{tt(ce.value)},disabled:j||n==="starting"||n==="stopping",children:e(ce.labelKey)})}),s.jsx(It,{sideOffset:8,className:"max-w-xs",children:e(ce.tooltipKey)})]},ce.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(is,{value:qp(Lc,K,"1800000"),onValueChange:ce=>{Xe(ce)},disabled:x||j||n==="starting"||n==="stopping",children:[s.jsx(os,{className:"max-w-[11rem] min-w-0",children:s.jsx(us,{className:"truncate"})}),s.jsx(ls,{children:Lc.map(ce=>s.jsx(Mt,{value:ce.value,children:ce.label},ce.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(is,{value:qp($c,W,"28800000"),onValueChange:ce=>{st(ce)},disabled:x||j||n==="starting"||n==="stopping",children:[s.jsx(os,{className:"max-w-[11rem] min-w-0",children:s.jsx(us,{className:"truncate"})}),s.jsx(ls,{children:$c.map(ce=>s.jsx(Mt,{value:ce.value,children:ce.label},ce.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(D,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.option.mode.quick.tooltip")}),s.jsx("p",{className:"typography-meta mt-1 text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.warning.quickModeReliability")})]})]})}),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 Ne=="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:",Ne]})]})}),s.jsxs("div",{className:"mb-1 flex items-center justify-between gap-3",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.tunnel.section.savedManagedRemoteTunnels")}),s.jsxs(ve,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Y(ce=>!ce),disabled:n==="starting"||n==="stopping"||j,children:[s.jsx(D,{name:"add",className:"h-3.5 w-3.5"}),t("settings.common.actions.create")]})]}),N.length>0?s.jsx("div",{className:"overflow-hidden rounded-md border border-[var(--surface-subtle)]",children:N.map((ce,We)=>{const Le=$[ce.id]||"",Ge=_.has(ce.id),at=M[ce.id]??!1;return s.jsx("div",{className:ye(We<N.length-1&&"border-b border-[var(--surface-subtle)]"),children:s.jsxs(br,{open:at,onOpenChange:He=>{O(ze=>({...ze,[ce.id]:He})),He&&it(ce.id)},className:"py-1.5",children:[s.jsxs("div",{className:"flex items-start gap-2 px-3",children:[s.jsxs(Tr,{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:[at?s.jsx(D,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(D,{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:ce.name})]}),s.jsx(ve,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:text-[var(--status-error)]","aria-label":t("settings.openchamber.tunnel.actions.removePresetAria",{name:ce.name}),onClick:()=>{rt(ce.id)},disabled:n==="starting"||n==="stopping"||j,children:s.jsx(D,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),s.jsx(yr,{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:ce.hostname})]}),s.jsx(Bt,{type:"password",value:Le,onChange:He=>{const ze=He.target.value;b(null),F(et=>({...et,[ce.id]:ze}))},onBlur:He=>{const ze=He.currentTarget.value.trim();ze&&je({presetId:ce.id,presetName:ce.name,hostname:ce.hostname,token:ze})},placeholder:t(Ge?"settings.openchamber.tunnel.field.savedTokenAvailablePlaceholder":"settings.openchamber.tunnel.field.pasteTokenPlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"}),s.jsx("div",{className:"flex items-center justify-end",children:s.jsx(ve,{variant:"ghost",size:"xs",className:"!font-normal",disabled:n==="starting"||n==="stopping"||Le.trim().length===0,onClick:()=>{je({presetId:ce.id,presetName:ce.name,hostname:ce.hostname,token:Le})},children:t("settings.openchamber.tunnel.actions.saveToken")})})]})})]})},ce.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(Bt,{value:Z,onChange:ce=>ae(ce.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetNamePlaceholder"),className:"h-7",disabled:j||n==="starting"||n==="stopping"}),s.jsx(Bt,{value:re,onChange:ce=>me(ce.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetHostnamePlaceholder"),className:"h-7",disabled:j||n==="starting"||n==="stopping"}),s.jsx(Bt,{type:"password",value:fe,onChange:ce=>H(ce.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetTokenPlaceholder"),className:"h-7",disabled:j||n==="starting"||n==="stopping"}),typeof Ne=="number"&&s.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[t("settings.openchamber.tunnel.note.cloudflareConnectorTargetUse")," ",s.jsxs("code",{children:["http://localhost:",Ne]}),"."]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ve,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Ye()},disabled:j||n==="starting"||n==="stopping",children:t("settings.common.actions.saveChanges")}),s.jsx(ve,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Y(!1),ae(""),me(""),H("")},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(D,{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")})]})]}),!Ie&&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:ce=>{Oe(ce)}}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Bt,{value:P||"",onChange:ce=>{U(ce.target.value)},onBlur:()=>{le()},placeholder:t("settings.openchamber.tunnel.field.configurationFilePlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"||j}),s.jsx(ve,{variant:"outline",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.browseConfigFileAria"),onClick:()=>{R()},disabled:n==="starting"||n==="stopping"||j,children:s.jsx(D,{name:"folder",className:"size-3.5"})}),P&&s.jsx(ve,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.clearConfigFileAria"),onClick:()=>{Me()},disabled:n==="starting"||n==="stopping"||j,children:s.jsx(D,{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")}),he&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:J})]})}),!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(D,{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:()=>{oe(LC)},children:[t("settings.openchamber.tunnel.actions.openManagedRemoteDocs"),s.jsx(D,{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:()=>{oe($C)},children:[t("settings.openchamber.tunnel.actions.openManagedLocalDocs"),s.jsx(D,{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(Hp.find(ce=>ce.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(is,{value:V||(N[0]?.id??""),onValueChange:ce=>{it(ce)},disabled:j||n==="starting"||n==="stopping"||N.length<=1,children:[s.jsx(os,{children:s.jsx(us,{placeholder:t("settings.openchamber.tunnel.field.selectSavedTunnelPlaceholder"),children:Ie?.name})}),s.jsx(ls,{fitContent:!0,children:N.map(ce=>s.jsx(Mt,{value:ce.id,children:ce.name},ce.id))})]})]}),ie&&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(D,{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(ve,{size:"sm",variant:"outline",onClick:Ae,disabled:n==="starting"||j||I==="managed-remote"&&!Ie||I==="managed-local"&&he,className:ye(Je,n==="starting"&&"opacity-70"),children:n==="starting"?s.jsxs(s.Fragment,{children:[s.jsx(D,{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})]}),Ce&&a.connectUrl&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta mb-1 text-muted-foreground/70",children:t("settings.openchamber.tunnel.field.connectLink")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("code",{className:"typography-code flex-1 truncate rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:a.connectUrl}),s.jsxs(ve,{size:"sm",variant:"ghost",onClick:De,className:"shrink-0 gap-1.5",children:[g?s.jsx(D,{name:"check",className:"size-3.5 text-[var(--status-success)]"}):s.jsx(D,{name:"file-copy",className:"size-3.5"}),t(g?"settings.openchamber.tunnel.actions.copied":"settings.common.actions.copyAll")]})]}),s.jsxs("p",{className:"typography-meta mt-1 text-muted-foreground/70",children:[t("settings.openchamber.tunnel.field.expires"),": ",a.bootstrapExpiresAt?be:t("settings.openchamber.tunnel.state.never")]})]}),s.jsxs("div",{className:"flex flex-col items-center gap-2 rounded-lg border border-border/50 bg-[var(--surface-elevated)] p-4",children:[d?s.jsx("img",{src:d,alt:t("settings.openchamber.tunnel.field.connectQrAlt"),className:"size-48"}):s.jsx("div",{className:"size-48 rounded bg-muted/30"}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.tunnel.note.scanQrToConnect")})]})]})]}),s.jsx("div",{className:"pt-1",children:s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(ve,{size:"sm",variant:"outline",onClick:Ae,disabled:n==="stopping"||j||I==="managed-local"&&he,className:Je,children:[s.jsx(D,{name:"restart",className:"size-3.5"}),t("settings.openchamber.tunnel.actions.newConnectLink")]}),s.jsx(ve,{size:"sm",variant:"ghost",onClick:z,disabled:n==="stopping"||j,className:"gap-2 text-[var(--status-error)]",children:n==="stopping"?s.jsxs(s.Fragment,{children:[s.jsx(D,{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(ve,{size:"sm",variant:"ghost",onClick:Ae,children:t("settings.openchamber.tunnel.actions.retry")})]})]})},Ig=()=>{const{t}=ut(),[e,n]=_e.useState(""),[r,a]=_e.useState(!0),[i,l]=_e.useState(!1),c=Re(u=>u.showOpenCodeUpdateNotifications),d=Re(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 g=typeof b.opencodeBinary=="string"?b.opencodeBinary.trim():"";n(g)}catch{}finally{u||a(!1)}})(),()=>{u=!0}},[]);const p=_e.useCallback(async()=>{if(typeof window>"u"||!Cn()||!Va())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()=>{l(!0);try{await Ss({opencodeBinary:e.trim()}),await ci({message:t("settings.openchamber.opencodeCli.actions.restartingOpenCode"),mode:"projects",scopes:["all"]})}finally{l(!1)}},[t,e]);return s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.openchamber.opencodeCli.title")}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(D,{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(Bt,{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(ve,{type:"button",variant:"outline",size:"xs",onClick:p,disabled:r||i||!Cn()||!Va(),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(D,{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(xs,{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(ve,{type:"button",size:"xs",onClick:m,disabled:r||i,className:"shrink-0 !font-normal",children:t(i?"settings.common.actions.saving":"settings.openchamber.opencodeCli.actions.saveAndReload")})})]})]})},Pg=()=>{const{t}=ut(),e=Cn()&&sa(),[n,r]=_e.useState(!1),[a,i]=_e.useState(!1),[l,c]=_e.useState(!0),[d,p]=_e.useState(!1),[m,u]=_e.useState(null),[f,b]=_e.useState(null);_e.useEffect(()=>{if(!e){c(!1);return}let y=!1;return(async()=>{try{const C=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!C.ok)throw new Error(t("settings.openchamber.desktopNetwork.error.loadFailed"));const k=await C.json().catch(()=>null);if(y)return;const w=k?.desktopLanAccessEnabled===!0;r(w),i(w),u(null)}catch(C){y||u(C instanceof Error?C.message:t("settings.openchamber.desktopNetwork.error.loadFailed"))}finally{y||c(!1)}})(),()=>{y=!0}},[e,t]),_e.useEffect(()=>{if(!e||!a){b(null);return}let y=!1;return(async()=>{const C=await uy();y||b(C)})(),()=>{y=!0}},[a,e]);const g=a!==n,v=_e.useMemo(()=>{if(typeof window>"u")return null;const y=Number(window.location.port);return Number.isFinite(y)&&y>0?y:null},[]),x=a&&f&&v?`http://${f}:${v}`:null,h=_e.useCallback(()=>{i(y=>!y)},[]),j=_e.useCallback(async()=>{if(g){p(!0),u(null);try{if(!(await fetch("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({desktopLanAccessEnabled:a})})).ok)throw new Error(t("settings.openchamber.desktopNetwork.error.saveFailed"));if(r(a),!await ch())throw new Error(t("settings.openchamber.desktopNetwork.error.savedRestartFailed"))}catch(y){u(y instanceof Error?y.message:t("settings.openchamber.desktopNetwork.error.saveFailed")),p(!1)}}},[a,g,t]);return e?s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.openchamber.desktopNetwork.title")})}),s.jsxs("section",{className:"space-y-2 px-2 pb-2 pt-0",children:[s.jsxs("div",{className:"group flex cursor-pointer items-start gap-2 py-1.5",role:"button",tabIndex:0,onClick:h,onKeyDown:y=>{(y.key==="Enter"||y.key===" ")&&(y.preventDefault(),h())},children:[s.jsx(xs,{checked:a,onChange:h,ariaLabel:t("settings.openchamber.desktopNetwork.field.allowLanAccessAria"),disabled:l||d}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.desktopNetwork.field.allowLanAccess")}),s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:t("settings.openchamber.desktopNetwork.field.allowLanAccessDescription")}),s.jsx("div",{className:"typography-micro text-[var(--status-warning)]/85",children:t("settings.openchamber.desktopNetwork.field.warning")})]})]}),m?s.jsx("div",{className:"px-2 typography-micro text-[var(--status-error)]",children:m}):null,x?s.jsxs("div",{className:"px-2 typography-micro text-muted-foreground/80",children:[t(g&&!n?"settings.openchamber.desktopNetwork.hint.openAfterRestart":"settings.openchamber.desktopNetwork.hint.openNow"),s.jsx("span",{className:"font-mono text-foreground",children:x})]}):null,s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(ve,{type:"button",size:"xs",onClick:j,disabled:l||d||!g,className:"shrink-0 !font-normal",children:t(d?"settings.common.actions.saving":"settings.openchamber.desktopNetwork.actions.saveAndRestart")})})]})]}):null},KC=new Set(["shift","control","alt","meta"]),HC=t=>{if(KC.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=py(t.key);return n?(e.push(n),si(e.join("+"))):null},GC=()=>{const t=ot.c(58),{t:e}=ut();let n;t[0]!==e?(n=fe=>e(fe),t[0]=e,t[1]=n):n=t[1];const r=n,a=Re(qC),i=Re(YC),l=Re(QC),c=Re(JC);let d;t[2]===Symbol.for("react.memo_cache_sentinel")?(d=my(),t[2]=d):d=t[2];const p=d;let m;t[3]!==r?(m=(fe,H)=>{const K=`settings.openchamber.keyboardShortcuts.action.${fe}.label`,Q=r(K);return Q===K?H:Q},t[3]=r,t[4]=m):m=t[4];const u=m,[f,b]=o.useState(null);let g;t[5]===Symbol.for("react.memo_cache_sentinel")?(g={},t[5]=g):g=t[5];const[v,x]=o.useState(g),[h,j]=o.useState(""),[y,C]=o.useState(""),[k,w]=o.useState(null);let S;t[6]!==a?(S=(fe,H)=>{const K=si(H);for(const Q of p){if(Q.id===fe)continue;const W=Zr(Q.id,a);if(si(W)===K)return Q.id}return null},t[6]=a,t[7]=S):S=t[7];const I=S;let T;t[8]!==I||t[9]!==i||t[10]!==e?(T=(fe,H)=>{const K=si(H),Q=I(fe,K);if(Q){w({actionId:fe,combo:K,conflictActionId:Q}),j("");return}i(fe,K),w(null),j(""),C($u(K)?e("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut"):""),x(W=>{const de={...W};return delete de[fe],de})},t[8]=I,t[9]=i,t[10]=e,t[11]=T):T=t[11];const P=T;let A;t[12]!==k||t[13]!==i||t[14]!==e?(A=()=>{k&&(i(k.conflictActionId,fy),i(k.actionId,k.combo),w(null),j(""),C($u(k.combo)?e("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut"):""),x(fe=>{const H={...fe};return delete H[k.actionId],H}))},t[12]=k,t[13]=i,t[14]=e,t[15]=A):A=t[15];const N=A;let E;t[16]!==l?(E=fe=>{l(fe),x(H=>{const K={...H};return delete K[fe],K}),w(null),j(""),C("")},t[16]=l,t[17]=E):E=t[17];const M=E;let O;t[18]!==e?(O=e("settings.openchamber.keyboardShortcuts.title"),t[18]=e,t[19]=O):O=t[19];let V;t[20]!==O?(V=s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:O}),t[20]=O,t[21]=V):V=t[21];let B;t[22]!==c?(B=()=>{c(),x({}),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 F;t[26]!==B||t[27]!==$?(F=s.jsx(ve,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:B,children:$}),t[26]=B,t[27]=$,t[28]=F):F=t[28];let _;t[29]===Symbol.for("react.memo_cache_sentinel")?(_=s.jsx(Ct,{asChild:!0,children:s.jsx(D,{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 Y;t[34]!==F||t[35]!==L||t[36]!==V?(Y=s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[V,F,L]})}),t[34]=F,t[35]=L,t[36]=V,t[37]=Y):Y=t[37];let Z;t[38]!==N||t[39]!==h||t[40]!==k||t[41]!==e||t[42]!==y?(Z=(h||y||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(ve,{type:"button",size:"xs",className:"!font-normal",onClick:N,children:e("settings.openchamber.keyboardShortcuts.actions.overwrite")}),s.jsx(ve,{type:"button",size:"xs",className:"!font-normal",variant:"ghost",onClick:()=>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}),y&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3 typography-meta text-foreground",children:y})]}),t[38]=N,t[39]=h,t[40]=k,t[41]=e,t[42]=y,t[43]=Z):Z=t[43];let ae;t[44]!==u||t[45]!==f||t[46]!==v||t[47]!==M||t[48]!==P||t[49]!==a||t[50]!==e?(ae=p.map((fe,H)=>{const K=Zr(fe.id,a),Q=v[fe.id],W=Q??K,de=typeof Q=="string"&&si(Q)!==si(K);return s.jsxs("div",{className:ye("flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",H>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(fe.id,fe.label)})}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:[s.jsx(Bt,{readOnly:!0,value:f===fe.id?e("settings.openchamber.keyboardShortcuts.field.pressKeys"):Fl(W),onFocus:()=>{b(fe.id),j("")},onBlur:()=>{f===fe.id&&b(null)},onKeyDown:be=>{if(be.preventDefault(),be.stopPropagation(),be.key==="Escape"){b(null);return}const we=HC(be);we&&(x(te=>({...te,[fe.id]:we})),b(null),w(null),j(""))},className:"h-7 w-40 min-w-0 typography-ui-label text-center"}),s.jsx(ve,{type:"button",variant:"secondary",size:"xs",className:"!font-normal",onClick:()=>{const be=v[fe.id];if(!be){j(e("settings.openchamber.keyboardShortcuts.error.captureFirst"));return}P(fe.id,be)},disabled:!de,children:e("settings.common.actions.saveChanges")}),s.jsx(ve,{type:"button",size:"xs",className:"!font-normal",variant:"ghost",onClick:()=>M(fe.id),children:e("settings.common.actions.reset")})]})]},fe.id)}),t[44]=u,t[45]=f,t[46]=v,t[47]=M,t[48]=P,t[49]=a,t[50]=e,t[51]=ae):ae=t[51];let re;t[52]!==ae?(re=s.jsx("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:ae}),t[52]=ae,t[53]=re):re=t[53];let me;return t[54]!==Y||t[55]!==Z||t[56]!==re?(me=s.jsxs("div",{className:"mb-8",children:[Y,Z,re]}),t[54]=Y,t[55]=Z,t[56]=re,t[57]=me):me=t[57],me};function qC(t){return t.shortcutOverrides}function YC(t){return t.setShortcutOverride}function QC(t){return t.clearShortcutOverride}function JC(t){return t.resetAllShortcutOverrides}const XC=t=>{const e=ot.c(20),{section:n}=t,{isMobile:r}=an();let a;e[0]!==r?(a=r&&ta(),e[0]=r,e[1]=a):a=e[1];const i=a;let l;e[2]===Symbol.for("react.memo_cache_sentinel")?(l=mn(),e[2]=l):l=e[2];const c=l;let d;e[3]===Symbol.for("react.memo_cache_sentinel")?(d=Cn()&&sa(),e[3]=d):d=e[3];const p=d;if(!n){let g;e[4]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(au,{}),e[4]=g):g=e[4];let v,x,h;e[5]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(kg,{})}),x=!c&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Ig,{})}),h=p&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Pg,{})}),e[5]=v,e[6]=x,e[7]=h):(v=e[5],x=e[6],h=e[7]);let j;e[8]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Ng,{})}),e[8]=j):j=e[8];let y;e[9]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Sg,{})}),e[9]=y):y=e[9];let C;e[10]!==i?(C=i&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(bC,{})}),e[10]=i,e[11]=C):C=e[11];let k;return e[12]!==C?(k=s.jsx(ws,{outerClassName:"h-full",className:"w-full",children:s.jsxs("div",{className:"openchamber-page-body mx-auto max-w-3xl space-y-3 p-3 sm:space-y-6 sm:p-6 sm:pt-8",children:[g,v,x,h,j,y,C]})}),e[12]=C,e[13]=k):k=e[13],k}let m;e[14]!==n?(m=()=>{switch(n){case"visual":return s.jsx(e4,{});case"chat":return s.jsx(t4,{});case"sessions":return s.jsx(s4,{});case"shortcuts":return s.jsx(ZC,{});case"git":return s.jsx(n4,{});case"github":return s.jsx(r4,{});case"notifications":return s.jsx(a4,{});case"voice":return s.jsx(i4,{});case"tunnel":return s.jsx(o4,{});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(ws,{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},ZC=()=>{const t=ot.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(GC,{}),t[0]=e):e=t[0],e},e4=()=>{const t=ot.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=mn(),t[0]=e):e=t[0];const n=e;let r;return t[1]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(au,{visibleSettings:["theme","pwaInstallName","pwaOrientation","mobileKeyboardMode","timeFormat","weekStart","fontSize","terminalFontSize","spacing","inputBarOffset",...n?[]:["terminalQuickKeys"],"reportUsage"]}),t[1]=r):r=t[1],r},t4=()=>{const t=ot.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(au,{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},s4=()=>{const t=ot.c(7);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=mn(),t[0]=e):e=t[0];const n=e;let r;t[1]===Symbol.for("react.memo_cache_sentinel")?(r=Cn()&&sa(),t[1]=r):r=t[1];const a=r;let i,l,c;t[2]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx(kg,{}),l=!n&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Ig,{})}),c=a&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Pg,{})}),t[2]=i,t[3]=l,t[4]=c):(i=t[2],l=t[3],c=t[4]);let d;t[5]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Ng,{})}),t[5]=d):d=t[5];let p;return t[6]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsxs("div",{className:"space-y-6",children:[i,l,c,d,s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Sg,{})})]}),t[6]=p):p=t[6],p},n4=()=>{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(yg,{})}),t[0]=e):e=t[0],e},r4=()=>{const t=ot.c(1);if(mn())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(vg,{}),t[0]=e):e=t[0],e},a4=()=>{const t=ot.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(TC,{}),t[0]=e):e=t[0],e},i4=()=>{const t=ot.c(1);if(mn())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(FC,{}),t[0]=e):e=t[0],e},o4=()=>{const t=ot.c(1);if(mn())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(WC,{}),t[0]=e):e=t[0],e},jd=176,Nd=280,Qp=8,Ag="__openchamberSettingsDetail";function _c(t){return Math.min(Nd,Math.max(jd,t))}const l4=["appearance","chat","notifications","sessions","shortcuts","git","magic-prompts","snippets","projects","remote-instances","agents","behavior","commands","mcp","providers","usage","skills.installed","skills.catalog","voice","tunnel"],c4={icon:"chat-thread"};function d4(t){const e=mn(),n=!t&&ta();return{isVSCode:e,isWeb:n,isDesktop:t}}function Jp(t,e){return t.isAvailable?t.isAvailable(e):!0}function Sd(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Bc(t){if(!Sd(t))return null;const e=t[Ag];if(!Sd(e))return null;const n=e.page,r=e.stage;return typeof n!="string"||r!=="page-content"?null:{page:su(n),stage:r}}function u4(){return typeof window>"u"||!Sd(window.history.state)?{}:window.history.state}function iu(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 c4.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"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 Vc=t=>{const e=ot.c(95),{onOpen:n}=t,{t:r}=ut();let a;e[0]!==r?(a=r("settings.view.home.title"),e[0]=r,e[1]=a):a=e[1];let i;e[2]!==a?(i=s.jsx("h1",{className:"typography-ui-header font-semibold text-foreground",children:a}),e[2]=a,e[3]=i):i=e[3];let l;e[4]!==r?(l=r("settings.view.home.description"),e[4]=r,e[5]=l):l=e[5];let c;e[6]!==l?(c=s.jsx("p",{className:"typography-ui text-muted-foreground",children:l}),e[6]=l,e[7]=c):c=e[7];let d;e[8]!==i||e[9]!==c?(d=s.jsxs("div",{className:"space-y-1",children:[i,c]}),e[8]=i,e[9]=c,e[10]=d):d=e[10];let 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 g;e[20]!==b?(g=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:b}),e[20]=b,e[21]=g):g=e[21];let v;e[22]!==g||e[23]!==p||e[24]!==f?(v=s.jsxs("button",{type:"button",onClick:p,className:m,children:[f,g]}),e[22]=g,e[23]=p,e[24]=f,e[25]=v):v=e[25];let x;e[26]!==n?(x=()=>n("agents"),e[26]=n,e[27]=x):x=e[27];let 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 y;e[31]!==j?(y=s.jsx("div",{className:"typography-ui-label text-foreground",children:j}),e[31]=j,e[32]=y):y=e[32];let C;e[33]!==r?(C=r("settings.view.home.cards.agents.description"),e[33]=r,e[34]=C):C=e[34];let k;e[35]!==C?(k=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:C}),e[35]=C,e[36]=k):k=e[36];let w;e[37]!==x||e[38]!==y||e[39]!==k?(w=s.jsxs("button",{type:"button",onClick:x,className:h,children:[y,k]}),e[37]=x,e[38]=y,e[39]=k,e[40]=w):w=e[40];let S;e[41]!==n?(S=()=>n("skills.catalog"),e[41]=n,e[42]=S):S=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 A;e[48]!==r?(A=r("settings.view.home.cards.skillsCatalog.description"),e[48]=r,e[49]=A):A=e[49];let N;e[50]!==A?(N=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:A}),e[50]=A,e[51]=N):N=e[51];let E;e[52]!==S||e[53]!==P||e[54]!==N?(E=s.jsxs("button",{type:"button",onClick:S,className:I,children:[P,N]}),e[52]=S,e[53]=P,e[54]=N,e[55]=E):E=e[55];let M;e[56]!==n?(M=()=>n("mcp"),e[56]=n,e[57]=M):M=e[57];let O;e[58]===Symbol.for("react.memo_cache_sentinel")?(O=ye("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[58]=O):O=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 F;e[65]!==$?(F=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:$}),e[65]=$,e[66]=F):F=e[66];let _;e[67]!==M||e[68]!==B||e[69]!==F?(_=s.jsxs("button",{type:"button",onClick:M,className:O,children:[B,F]}),e[67]=M,e[68]=B,e[69]=F,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 Y;e[74]!==r?(Y=r("settings.view.home.cards.usage.title"),e[74]=r,e[75]=Y):Y=e[75];let Z;e[76]!==Y?(Z=s.jsx("div",{className:"typography-ui-label text-foreground",children:Y}),e[76]=Y,e[77]=Z):Z=e[77];let ae;e[78]!==r?(ae=r("settings.view.home.cards.usage.description"),e[78]=r,e[79]=ae):ae=e[79];let re;e[80]!==ae?(re=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:ae}),e[80]=ae,e[81]=re):re=e[81];let me;e[82]!==q||e[83]!==Z||e[84]!==re?(me=s.jsxs("button",{type:"button",onClick:q,className:L,children:[Z,re]}),e[82]=q,e[83]=Z,e[84]=re,e[85]=me):me=e[85];let fe;e[86]!==v||e[87]!==w||e[88]!==E||e[89]!==_||e[90]!==me?(fe=s.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[v,w,E,_,me]}),e[86]=v,e[87]=w,e[88]=E,e[89]=_,e[90]=me,e[91]=fe):fe=e[91];let H;return e[92]!==fe||e[93]!==d?(H=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,fe]})}),e[92]=fe,e[93]=d,e[94]=H):H=e[94],H},m4=t=>{const e=ot.c(97),{onClose:n,forceMobile:r,isWindowed:a}=t,{t:i}=ut(),l=an(),c=r??l.isMobile,d=Re(p4),p=Re(f4),m=Re(h4);let u;e[0]!==d?(u=su(d),e[0]=d,e[1]=u):u=e[1];const f=u,[b,g]=o.useState("nav"),v=o.useRef(null),[x,h]=o.useState(216),[j,y]=o.useState(!1),[C,k]=o.useState(!1),w=o.useRef(0),S=o.useRef(x),I=o.useRef(null);let T;e[2]===Symbol.for("react.memo_cache_sentinel")?(T=Cn(),e[2]=T):T=e[2];const P=T;let A;e[3]===Symbol.for("react.memo_cache_sentinel")?(A=d4(P),e[3]=A):A=e[3];const N=A;let E;if(e[4]!==c){let Je;e[6]===Symbol.for("react.memo_cache_sentinel")?(Je=We=>Jp(We,N),e[6]=Je):Je=e[6];let ce;e[7]===Symbol.for("react.memo_cache_sentinel")?(ce=We=>!(N.isVSCode&&We.slug==="projects"),e[7]=ce):ce=e[7],E=tu.filter(g4).filter(Je).filter(ce).filter(We=>!(c&&We.slug==="shortcuts")),e[4]=c,e[5]=E}else E=e[5];const M=E;let O;e[8]===Symbol.for("react.memo_cache_sentinel")?(O=new Map(l4.map(x4)),e[8]=O):O=e[8];const V=O;let B;if(e[9]!==M){let Je;e[11]===Symbol.for("react.memo_cache_sentinel")?(Je=(ce,We)=>(V.get(ce.slug)??999)-(V.get(We.slug)??999),e[11]=Je):Je=e[11],B=M.slice().sort(Je),e[9]=M,e[10]=B}else B=e[10];const $=B,F=Cs(b4);let _,q;e[12]!==j?(_=()=>{if(typeof window>"u")return;const Je=()=>{if(!j){const ce=_c(Math.floor(window.innerWidth*.12));h(ce)}};return window.addEventListener("resize",Je),()=>window.removeEventListener("resize",Je)},q=[j],e[12]=j,e[13]=_,e[14]=q):(_=e[13],q=e[14]),o.useEffect(_,q);let L,Y;e[15]!==C?(Y=()=>{if(!C)return;const Je=We=>{const Le=We.clientX-w.current,Ge=_c(S.current+Le);h(Ge),y(!0)},ce=()=>k(!1);return window.addEventListener("pointermove",Je),window.addEventListener("pointerup",ce,{once:!0}),()=>{window.removeEventListener("pointermove",Je),window.removeEventListener("pointerup",ce)}},L=[C],e[15]=C,e[16]=L,e[17]=Y):(L=e[16],Y=e[17]),o.useEffect(Y,L);let Z;e[18]!==x?(Z=Je=>{k(!0),w.current=Je.clientX,S.current=x,Je.preventDefault()},e[18]=x,e[19]=Z):Z=e[19];const ae=Z;let re;e[20]!==x?(re=Je=>{const ce=Je.shiftKey?Qp*4:Qp;let We;e:switch(Je.key){case"ArrowLeft":{We=x-ce;break e}case"ArrowRight":{We=x+ce;break e}case"Home":{We=jd;break e}case"End":{We=Nd;break e}default:return}Je.preventDefault(),h(_c(We)),y(!0)},e[20]=x,e[21]=re):re=e[21];const me=re;let fe;e[22]!==p||e[23]!==a||e[24]!==f?(fe=()=>{if(!(!p&&!N.isVSCode&&!a)){if(f==="agents"){fi.getState().loadAgents();return}if(f==="commands"){zd.getState().loadCommands();return}if(f==="mcp"){co.getState().loadMcpConfigs();return}(f==="skills.installed"||f==="skills.catalog")&&(ma.getState().loadSkills(),La.getState().loadCatalog()),f==="snippets"&&Ul.getState().loadSnippets()}},e[22]=p,e[23]=a,e[24]=f,e[25]=fe):fe=e[25];let H;e[26]!==F||e[27]!==p||e[28]!==a||e[29]!==f?(H=[F,p,a,N.isVSCode,f],e[26]=F,e[27]=p,e[28]=a,e[29]=f,e[30]=H):H=e[30],o.useEffect(fe,H);let K;e[31]!==c||e[32]!==m?(K=Je=>{if(m(Je),v.current=Je,!c)return;const ce=Ki(Je);if(!ce||ce.slug==="home"){g("nav");return}g(ce.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=Ki(f),e[34]=f,e[35]=W):W=e[35];const de=W;let be;e[36]===Symbol.for("react.memo_cache_sentinel")?(be={appearance:"visual",chat:"chat",shortcuts:"shortcuts",sessions:"sessions",notifications:"notifications",voice:"voice",tunnel:"tunnel"},e[36]=be):be=e[36];const we=be;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"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 ge=te;let ue;e[39]!==i?(ue=()=>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]=ue):ue=e[40];const xe=ue,ne=y4;let pe;e[41]!==Q||e[42]!==xe?(pe=Je=>{const ce=Ki(Je);if(ce&&!Jp(ce,N))return xe();switch(Je){case"home":return s.jsx(Vc,{onOpen:Q});case"projects":return s.jsx(M3,{});case"remote-instances":return s.jsx(r5,{});case"agents":return s.jsx(ZS,{});case"behavior":return s.jsx(rk,{});case"commands":return s.jsx(pk,{});case"mcp":return s.jsx(Vk,{});case"skills.installed":return s.jsx(jp,{view:"installed"});case"skills.catalog":return s.jsx(jp,{view:"catalog"});case"providers":return s.jsx(m5,{});case"usage":return s.jsx(D5,{});case"magic-prompts":return s.jsx(F5,{});case"snippets":return s.jsx(B5,{});case"git":return s.jsx(K5,{});case"appearance":case"chat":case"shortcuts":case"sessions":case"notifications":case"voice":case"tunnel":{const We=we[Je]??"visual";return s.jsx(XC,{section:We})}default:return s.jsx(Vc,{onOpen:Q})}},e[41]=Q,e[42]=xe,e[43]=pe):pe=e[43];const J=pe;let Se,he;e[44]!==c||e[45]!==b||e[46]!==f?(Se=()=>{if(!c||b!=="nav"||f==="home"||v.current===f)return;const Je=Ki(f);!Je||Je.slug==="home"||(v.current=f,g(Je.kind==="split"?"page-sidebar":"page-content"))},he=[c,b,f],e[44]=c,e[45]=b,e[46]=f,e[47]=Se,e[48]=he):(Se=e[47],he=e[48]),o.useEffect(Se,he);const Ie=c&&b!=="nav",Pe=c&&b==="page-content"&&f==="skills.installed",Ce=b==="page-content"&&de?.kind==="split"&&!Pe;let X;e[49]!==Pe||e[50]!==Ie||e[51]!==i?(X=i(Pe?"settings.view.actions.back":Ie?"settings.view.actions.backToSettings":"settings.view.actions.closeSettings"),e[49]=Pe,e[50]=Ie,e[51]=i,e[52]=X):X=e[52];const ie=X,Ne=Gi();let oe;e[53]===Symbol.for("react.memo_cache_sentinel")?(oe=Je=>{if(typeof window>"u"||N.isVSCode)return;const ce=Bc(window.history.state);ce?.page===Je&&ce.stage==="page-content"||window.history.pushState({...u4(),[Ag]:{page:Je,stage:"page-content"}},"",window.location.href)},e[53]=oe):oe=e[53];const ke=oe;let Te;e[54]!==f?(Te=()=>{g("page-content"),f==="skills.installed"&&ke(f)},e[54]=f,e[55]=Te):Te=e[55];const Be=Te;let je;e[56]!==Pe||e[57]!==f?(je=()=>{if(Pe){if((typeof window<"u"?Bc(window.history.state):null)?.page===f&&!N.isVSCode){window.history.back();return}g("page-sidebar");return}g("nav")},e[56]=Pe,e[57]=f,e[58]=je):je=e[58];const ee=je;let R,U;e[59]!==c||e[60]!==f?(R=()=>{if(!c||N.isVSCode)return;const Je=ce=>{if(f!=="skills.installed")return;if(Bc(ce.state)?.page==="skills.installed"){g("page-content");return}g(v4)};return window.addEventListener("popstate",Je),()=>{window.removeEventListener("popstate",Je)}},U=[c,N.isVSCode,f],e[59]=c,e[60]=f,e[61]=R,e[62]=U):(R=e[61],U=e[62]),o.useEffect(R,U);let le;e[63]===Symbol.for("react.memo_cache_sentinel")?(le=()=>{g("page-sidebar")},e[63]=le):le=e[63];const Me=le;let Oe;e[64]!==ge||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 ce=f===Je.slug,We=iu(Je.slug);return We?s.jsx(kt,{children:s.jsx(Ct,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>Q(Je.slug),"aria-current":ce?"page":void 0,className:ye("flex h-8 items-center gap-2 rounded-md px-2 overflow-hidden",ce?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:[s.jsx(D,{name:We,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:ge(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:!N.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:w4,children:[s.jsx(D,{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]=ge,e[65]=Q,e[66]=f,e[67]=$,e[68]=i,e[69]=Oe):Oe=e[69];const Ae=Oe;let z;e[70]!==de||e[71]!==Be||e[72]!==b||e[73]!==J||e[74]!==Ae||e[75]!==f?(z=()=>{if(b==="nav")return s.jsx("div",{className:ye("flex-1 min-h-0 overflow-hidden",N.isVSCode?"bg-background":"bg-sidebar"),children:s.jsx("div",{className:"flex h-full min-h-0 flex-col",children:s.jsx(en,{children:Ae()})})});if(!de)return s.jsx("div",{className:"flex-1 bg-background"});if(b==="page-sidebar"){if(de.kind!=="split"){const ce=J(f);return s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:s.jsx(en,{children:ce})})}return s.jsx("div",{className:ye("flex-1 min-h-0 overflow-hidden",N.isVSCode?"bg-background":"bg-sidebar"),children:s.jsx(en,{children:ne(f,{onItemSelect:Be})})})}const Je=J(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]=Be,e[72]=b,e[73]=J,e[74]=Ae,e[75]=f,e[76]=z):z=e[76];const De=z;let Xe;e[77]!==de||e[78]!==Q||e[79]!==J||e[80]!==f?(Xe=()=>!de||f==="home"?s.jsx(Vc,{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",N.isVSCode?"bg-background":"bg-sidebar"),style:{borderColor:"var(--interactive-border)"},children:s.jsx(en,{children:ne(f,{})})}),s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:s.jsx(en,{children:J(f)})})]}):s.jsx("div",{className:"h-full min-h-0 overflow-hidden bg-background",children:s.jsx(en,{children:J(f)})}),e[77]=de,e[78]=Q,e[79]=J,e[80]=f,e[81]=Xe):Xe=e[81];const st=Xe,tt="true";let Ue;e[82]===Symbol.for("react.memo_cache_sentinel")?(Ue=ye("relative flex h-full min-h-0 flex-col overflow-hidden bg-background"),e[82]=Ue):Ue=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:Ie?ee:n,"aria-label":ie,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(D,{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?ge(de.slug):i("settings.view.home.title")}),Ce&&s.jsx("button",{type:"button",onClick:Me,"aria-label":i("settings.view.actions.openSectionList"),className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(D,{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:Ne}),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(D,{name:"close",className:"h-5 w-5"})})]}):s.jsxs(s.Fragment,{children:[Ie&&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(D,{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:Ne}),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(D,{name:"close",className:"h-5 w-5"})})})]});let Ye;e[83]!==ae||e[84]!==me||e[85]!==c||e[86]!==C||e[87]!==x||e[88]!==st||e[89]!==De||e[90]!==Ae||e[91]!==i?(Ye=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":N.isVSCode?"bg-background":"bg-sidebar",C?"":"transition-[width,min-width] duration-200 ease-[cubic-bezier(0.25,0.1,0.25,1)]"),style:{width:`${x}px`,minWidth:`${x}px`,borderColor:"var(--interactive-border)"},children:[s.jsx("div",{className: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:ae,onKeyDown:me,role:"separator","aria-orientation":"vertical","aria-valuemin":jd,"aria-valuemax":Nd,"aria-valuenow":x,"aria-label":i("settings.view.actions.resizeNavigation")}),s.jsx(en,{children:Ae()})]}),s.jsx("div",{className:"flex-1 overflow-hidden bg-background",children:st()})]})}),e[83]=ae,e[84]=me,e[85]=c,e[86]=C,e[87]=x,e[88]=st,e[89]=De,e[90]=Ae,e[91]=i,e[92]=Ye):Ye=e[92];let rt;return e[93]!==Ue||e[94]!==it||e[95]!==Ye?(rt=s.jsxs("div",{ref:I,"data-settings-view":tt,className:Ue,children:[it,Ye]}),e[93]=Ue,e[94]=it,e[95]=Ye,e[96]=rt):rt=e[96],rt};function p4(t){return t.settingsPage}function f4(t){return t.isSettingsDialogOpen}function h4(t){return t.setSettingsPage}function g4(t){return t.slug!=="home"}function x4(t,e){return[t,e]}function b4(t){return t.activeProjectId}function y4(t,e){switch(t){case"projects":return s.jsx(N3,{onItemSelect:e.onItemSelect});case"remote-instances":return s.jsx(K3,{onItemSelect:e.onItemSelect});case"agents":return s.jsx(HS,{onItemSelect:e.onItemSelect});case"commands":return s.jsx(ak,{onItemSelect:e.onItemSelect});case"mcp":return s.jsx(fk,{onItemSelect:e.onItemSelect});case"skills.installed":return s.jsx(Uk,{onItemSelect:e.onItemSelect});case"providers":return s.jsx(o5,{onItemSelect:e.onItemSelect});case"usage":return s.jsx(f5,{onItemSelect:e.onItemSelect});case"magic-prompts":return s.jsx(M5,{onItemSelect:e.onItemSelect});case"snippets":return s.jsx(O5,{onItemSelect:e.onItemSelect});default:return null}}function v4(t){return t==="page-content"?"page-sidebar":t}function w4(){ci({message:"Restarting OpenCode…",mode:"projects",scopes:["all"]})}const j4=Object.freeze(Object.defineProperty({__proto__:null,SettingsView:m4,getSettingsNavIcon:iu},Symbol.toStringTag,{value:"Module"})),kd=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+/g,"/");n&&!r.startsWith("//")&&(r=`/${r}`);const a=r==="/",i=/^[A-Za-z]:\/$/.test(r);return!a&&!i&&(r=r.replace(/\/+$/,"")),r},N4=()=>{const t=ot.c(162),{t:e}=ut(),n=Re(S4),r=Re(k4),a=Re(C4),i=Re(I4),l=Re(P4),c=Re(A4),d=Re(D4),p=Re(T4),m=Re(M4),u=Re(E4),f=Re(R4),b=Re(F4),g=$t(O4),v=$t(L4),x=Oa($4),h=Ks(_4),j=Cs(B4),y=ra(),C=_d(V4),{files:k,git:w}=Bn(),S=Qs(z4),{isMobile:I}=an();let T;t[0]!==y?(T=y?kd(y):null,t[0]=y,t[1]=T):T=t[1];const P=T,[A,N]=o.useState(""),E=Bl(A,200);let M;t[2]!==E?(M=E.trim(),t[2]=E,t[3]=M):M=t[3];const O=M;let V;t[4]!==A?(V=A.trim(),t[4]=A,t[5]=V):V=t[5];const B=V;let $,F;t[6]!==n?($=()=>{n&&N("")},F=[n],t[6]=n,t[7]=$,t[8]=F):($=t[7],F=t[8]),o.useEffect($,F);let _,q;t[9]!==x||t[10]!==S||t[11]!==w||t[12]!==n?(_=()=>{if(!n||!w)return;const He=setTimeout(()=>{const ze=new Set;for(const et of x){const gt=qi(et);!gt||ze.has(gt)||(ze.add(gt),S(gt,w))}},0);return()=>clearTimeout(He)},q=[n,x,w,S],t[9]=x,t[10]=S,t[11]=w,t[12]=n,t[13]=_,t[14]=q):(_=t[13],q=t[14]),o.useEffect(_,q);let L;t[15]!==r?(L=()=>r(!1),t[15]=r,t[16]=L):L=t[16];const Y=L;let Z;t[17]!==Y?(Z=He=>()=>{Y(),He()},t[17]=Y,t[18]=Z):Z=t[18];const ae=Z;let re;t[19]!==j?.id||t[20]!==j?.path||t[21]!==h||t[22]!==I||t[23]!==u||t[24]!==g||t[25]!==ae||t[26]!==a||t[27]!==c||t[28]!==i||t[29]!==e||t[30]!==m||t[31]!==p||t[32]!==d?(re=()=>{const He=[{id:"new-session",title:e("commandPalette.item.newSession"),icon:s.jsx(D,{name:"add",className:"mr-2 h-4 w-4"}),shortcutId:"new_chat",searchText:e("commandPalette.item.newSession"),onSelect:ae(()=>{a("chat"),c(!1),g()})},{id:"new-worktree",title:e("commandPalette.item.newWorktreeDraft"),icon:s.jsx(D,{name:"git-branch",className:"mr-2 h-4 w-4"}),shortcutId:"new_chat_worktree",searchText:e("commandPalette.item.newWorktreeDraft"),onSelect:ae(U4)},{id:"add-project",title:e("commandPalette.item.addProject"),icon:s.jsx(D,{name:"folder-add",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.addProject"),onSelect:ae(W4)},{id:"toggle-sidebar",title:e(I?"commandPalette.item.showSessionSwitcher":"commandPalette.item.toggleSidebar"),icon:s.jsx(D,{name:"layout-left",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_sidebar",searchText:e(I?"commandPalette.item.showSessionSwitcher":"commandPalette.item.toggleSidebar"),onSelect:ae(()=>{if(I){const{isSessionSwitcherOpen:ze}=Re.getState();c(!ze)}else d()})},{id:"toggle-right-sidebar",title:e("commandPalette.item.toggleRightSidebar"),icon:s.jsx(D,{name:"layout-right",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_right_sidebar",searchText:e("commandPalette.item.toggleRightSidebar"),onSelect:ae(()=>p())},{id:"toggle-terminal",title:e("commandPalette.item.toggleTerminal"),icon:s.jsx(D,{name:"terminal-box",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_terminal",searchText:e("commandPalette.item.toggleTerminal"),onSelect:ae(()=>m())},{id:"context-usage",title:e("commandPalette.item.showContextUsage"),icon:s.jsx(D,{name:"pie-chart",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.showContextUsage"),onSelect:ae(()=>{h&&u(h)})},{id:"open-settings",title:e("commandPalette.item.openSettings"),icon:s.jsx(D,{name:"settings-3",className:"mr-2 h-4 w-4"}),shortcutId:"open_settings",searchText:e("commandPalette.item.openSettings"),onSelect:ae(()=>i(!0))}];return Md()&&He.splice(1,0,{id:"new-mini-chat",title:e("commandPalette.item.newMiniChat"),icon:s.jsx(D,{name:"window",className:"mr-2 h-4 w-4"}),shortcutId:"new_mini_chat",searchText:e("commandPalette.item.newMiniChat"),onSelect:ae(()=>{fl("desktop_open_draft_mini_chat_window",{directory:kd(h||j?.path||""),projectId:j?.id??null}).catch(K4)})}),He},t[19]=j?.id,t[20]=j?.path,t[21]=h,t[22]=I,t[23]=u,t[24]=g,t[25]=ae,t[26]=a,t[27]=c,t[28]=i,t[29]=e,t[30]=m,t[31]=p,t[32]=d,t[33]=re):re=t[33],j?.id,j?.path;let me;t[34]!==re?(me=re(),t[34]=re,t[35]=me):me=t[35];const fe=me;let H;t[36]===Symbol.for("react.memo_cache_sentinel")?(H=Cn(),t[36]=H):H=t[36];const K=H;let Q;t[37]===Symbol.for("react.memo_cache_sentinel")?(Q={isVSCode:mn(),isWeb:!K&&ta(),isDesktop:K},t[37]=Q):Q=t[37];const W=Q;let de;if(t[38]!==ae||t[39]!==i||t[40]!==l){let He;t[42]===Symbol.for("react.memo_cache_sentinel")?(He=ze=>ze.isAvailable?ze.isAvailable(W):!0,t[42]=He):He=t[42],de=tu.filter(H4).filter(He).map(ze=>{const et=iu(ze.slug)??"settings-3",gt=(ze.keywords??[]).join(" ");return{id:`settings:${ze.slug}`,title:ze.title,icon:s.jsx(D,{name:et,className:"mr-2 h-4 w-4"}),searchText:`${ze.title} ${ze.group} ${gt}`,onSelect:ae(()=>{l(ze.slug),i(!0)})}}),t[38]=ae,t[39]=i,t[40]=l,t[41]=de}else de=t[41];const be=de,we=G4;let te;if(t[43]!==x){let He;t[45]===Symbol.for("react.memo_cache_sentinel")?(He=(ze,et)=>we(et)-we(ze),t[45]=He):He=t[45],te=[...x].sort(He),t[43]=x,t[44]=te}else te=t[44];const ge=te,ue=dh(),xe=$t(q4);let ne;t[46]!==ue||t[47]!==xe?(ne=(He,ze)=>{const et=xe.get(He);return et?.branch?et.branch.trim()||null:ze&&ue.get(ze)?.trim()||null},t[46]=ue,t[47]=xe,t[48]=ne):ne=t[48];const pe=ne;let J;t[49]===Symbol.for("react.memo_cache_sentinel")?(J=[],t[49]=J):J=t[49];const[Se,he]=o.useState(J),[Ie,Pe]=o.useState(!1);let Ce,X;t[50]!==P||t[51]!==n||t[52]!==C||t[53]!==O?(Ce=()=>{if(!n){he([]),Pe(!1);return}if(!P||O.length===0){he([]),Pe(!1);return}let He=!1;return Pe(!0),C(P,O,10,{type:"file"}).then(ze=>{He||he(ze.map(Y4))}).catch(()=>{He||he([])}).finally(()=>{He||Pe(!1)}),()=>{He=!0}},X=[n,P,O,C],t[50]=P,t[51]=n,t[52]=C,t[53]=O,t[54]=Ce,t[55]=X):(Ce=t[54],X=t[55]),o.useEffect(Ce,X);const ie=B.length>0;let Ne;e:{if(!ie){let ze;t[56]!==fe?(ze=fe.map(Q4),t[56]=fe,t[57]=ze):ze=t[57],Ne=ze;break e}let He;t[58]!==fe||t[59]!==B?(He=Io(fe,B,J4,{limit:7,noFuzzy:!0}),t[58]=fe,t[59]=B,t[60]=He):He=t[60],Ne=He}const oe=Ne;let ke;e:{if(!ie){let ze;t[61]===Symbol.for("react.memo_cache_sentinel")?(ze=[],t[61]=ze):ze=t[61],ke=ze;break e}let He;t[62]!==B||t[63]!==be?(He=Io(be,B,X4,{limit:7,noFuzzy:!0}),t[62]=B,t[63]=be,t[64]=He):He=t[64],ke=He}const Te=ke;let Be;e:{if(!ie){let ze;t[65]!==ge?(ze=ge.slice(0,5).map(Z4),t[65]=ge,t[66]=ze):ze=t[66],Be=ze;break e}let He;t[67]!==B||t[68]!==ge?(He=Io(ge,B,eI,{limit:7,threshold:.2}),t[67]=B,t[68]=ge,t[69]=He):He=t[69],Be=He}const je=Be;let ee;e:{if(!ie||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 He;t[71]!==Se||t[72]!==B?(He=Io(Se,B,tI,{limit:10,threshold:.4}),t[71]=Se,t[72]=B,t[73]=He):He=t[73],ee=He}const R=ee;let U,le,Me,Oe,Ae,z,De,Xe,st,tt,Ue,it,Ye,rt,Je;if(t[74]!==pe||t[75]!==Y||t[76]!==P||t[77]!==k||t[78]!==ie||t[79]!==n||t[80]!==f||t[81]!==A||t[82]!==oe||t[83]!==R||t[84]!==je||t[85]!==Te||t[86]!==r||t[87]!==v||t[88]!==b||t[89]!==e){const He=oe.map(sI),ze=Te.map(nI),et=je.map(rI);Je=ie?R.map(aI):[];let gt;e:{if(!ie){gt=["commands","sessions"];break e}const Ut=iI,Qe=[{key:"commands",score:Ut(oe)},{key:"settings",score:Ut(Te)},{key:"sessions",score:Ut(je)},{key:"files",score:Ut(R)}];Qe.sort(oI),gt=Qe.map(lI)}const Pt=gt;let Nt;t[105]!==Y||t[106]!==v?(Nt=Ut=>{Y(),v(Ut.id,qi(Ut))},t[105]=Y,t[106]=v,t[107]=Nt):Nt=t[107];const ht=Nt;let wt;t[108]!==Y||t[109]!==P||t[110]!==k||t[111]!==f?(wt=async Ut=>{if(!P)return;const Qe=await Zd(k,Ut);if(!Qe.ok){G.error(eu(Qe.reason));return}f(P,Ut),Y()},t[108]=Y,t[109]=P,t[110]=k,t[111]=f,t[112]=wt):wt=t[112];const es=wt;let Vt;t[113]!==b?(Vt=Ut=>Fl(Zr(Ut,b)),t[113]=b,t[114]=Vt):Vt=t[114];const Jt=Vt;Oe=ps,it=n,Ye=r;let mt;t[115]!==e?(mt=e("commandPalette.title"),t[115]=e,t[116]=mt):mt=t[116];let Lt;t[117]!==mt?(Lt=s.jsx(fs,{children:mt}),t[117]=mt,t[118]=Lt):Lt=t[118];let ts;t[119]!==e?(ts=e("commandPalette.description"),t[119]=e,t[120]=ts):ts=t[120];let js;t[121]!==ts?(js=s.jsx(Ns,{children:ts}),t[121]=ts,t[122]=js):js=t[122],t[123]!==Lt||t[124]!==js?(rt=s.jsxs(gs,{className:"sr-only",children:[Lt,js]}),t[123]=Lt,t[124]=js,t[125]=rt):rt=t[125],Me=ms,tt="overflow-hidden p-0",Ue=!0,le=Wa,De=!1,Xe="[&_[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 ds;t[126]!==e?(ds=e("commandPalette.input.placeholder"),t[126]=e,t[127]=ds):ds=t[127],t[128]!==A||t[129]!==ds?(st=s.jsx(ga,{value:A,onValueChange:N,placeholder:ds}),t[128]=A,t[129]=ds,t[130]=st):st=t[130],U=Ka;let hs;t[131]!==e?(hs=e("commandPalette.empty.noResults"),t[131]=e,t[132]=hs):hs=t[132],t[133]!==hs?(Ae=s.jsx(Ha,{children:hs}),t[133]=hs,t[134]=Ae):Ae=t[134],z=Pt.map(Ut=>Ut==="commands"&&He.length>0?s.jsx(Ln,{children:He.map(Qe=>s.jsxs(An,{value:Qe.id,onSelect:Qe.onSelect,children:[Qe.icon,s.jsx("span",{children:Qe.title}),Qe.shortcutId?s.jsx(Rw,{children:Jt(Qe.shortcutId)}):null]},Qe.id))},"commands"):Ut==="settings"&&ze.length>0?s.jsx(Ln,{children:ze.map(cI)},"settings"):Ut==="sessions"&&et.length>0?s.jsx(Ln,{children:et.map(Qe=>{const At=Qe.title||e("commandPalette.session.untitled"),Ht=qi(Qe),jt=pe(Qe.id,Ht);return s.jsxs(An,{value:`session:${Qe.id}`,onSelect:()=>ht(Qe),children:[s.jsx(D,{name:"chat-ai-3",className:"mr-2 h-4 w-4"}),s.jsx("span",{className:"truncate",children:At}),jt?s.jsxs("span",{className:"ml-auto inline-flex items-center gap-1 text-muted-foreground typography-meta",children:[s.jsx(D,{name:"git-branch",className:"h-3 w-3"}),s.jsx("span",{className:"truncate max-w-[160px]",children:jt})]}):null]},Qe.id)})},"sessions"):Ut==="files"&&Je.length>0?s.jsx(Ln,{children:Je.map(Qe=>{const At=hy(Qe.relativePath||Qe.name,{maxLength:80});return s.jsxs(An,{value:`file:${Qe.path}`,onSelect:()=>{es(Qe.path)},children:[s.jsx(Pr,{filePath:Qe.path,className:"mr-2 size-4 shrink-0"}),s.jsx("span",{className:"truncate","aria-label":Qe.relativePath,children:At})]},`file:${Qe.path}`)})},"files"):null),t[74]=pe,t[75]=Y,t[76]=P,t[77]=k,t[78]=ie,t[79]=n,t[80]=f,t[81]=A,t[82]=oe,t[83]=R,t[84]=je,t[85]=Te,t[86]=r,t[87]=v,t[88]=b,t[89]=e,t[90]=U,t[91]=le,t[92]=Me,t[93]=Oe,t[94]=Ae,t[95]=z,t[96]=De,t[97]=Xe,t[98]=st,t[99]=tt,t[100]=Ue,t[101]=it,t[102]=Ye,t[103]=rt,t[104]=Je}else U=t[90],le=t[91],Me=t[92],Oe=t[93],Ae=t[94],z=t[95],De=t[96],Xe=t[97],st=t[98],tt=t[99],Ue=t[100],it=t[101],Ye=t[102],rt=t[103],Je=t[104];let ce;t[135]!==ie||t[136]!==Ie||t[137]!==e||t[138]!==Je?(ce=ie&&Ie&&Je.length===0?s.jsx("div",{className:"px-3 py-2 typography-meta text-muted-foreground",children:e("commandPalette.empty.searchingFiles")}):null,t[135]=ie,t[136]=Ie,t[137]=e,t[138]=Je,t[139]=ce):ce=t[139];let We;t[140]!==U||t[141]!==Ae||t[142]!==z||t[143]!==ce?(We=s.jsxs(U,{children:[Ae,z,ce]}),t[140]=U,t[141]=Ae,t[142]=z,t[143]=ce,t[144]=We):We=t[144];let Le;t[145]!==le||t[146]!==De||t[147]!==Xe||t[148]!==st||t[149]!==We?(Le=s.jsxs(le,{shouldFilter:De,className:Xe,children:[st,We]}),t[145]=le,t[146]=De,t[147]=Xe,t[148]=st,t[149]=We,t[150]=Le):Le=t[150];let Ge;t[151]!==Me||t[152]!==tt||t[153]!==Ue||t[154]!==Le?(Ge=s.jsx(Me,{className:tt,showCloseButton:Ue,children:Le}),t[151]=Me,t[152]=tt,t[153]=Ue,t[154]=Le,t[155]=Ge):Ge=t[155];let at;return t[156]!==Oe||t[157]!==it||t[158]!==Ye||t[159]!==rt||t[160]!==Ge?(at=s.jsxs(Oe,{open:it,onOpenChange:Ye,children:[rt,Ge]}),t[156]=Oe,t[157]=it,t[158]=Ye,t[159]=rt,t[160]=Ge,t[161]=at):at=t[161],at};function S4(t){return t.isCommandPaletteOpen}function k4(t){return t.setCommandPaletteOpen}function C4(t){return t.setActiveMainTab}function I4(t){return t.setSettingsDialogOpen}function P4(t){return t.setSettingsPage}function A4(t){return t.setSessionSwitcherOpen}function D4(t){return t.toggleSidebar}function T4(t){return t.toggleRightSidebar}function M4(t){return t.toggleBottomTerminal}function E4(t){return t.openContextOverview}function R4(t){return t.openContextFile}function F4(t){return t.shortcutOverrides}function O4(t){return t.openNewSessionDraft}function L4(t){return t.setCurrentSession}function $4(t){return t.activeSessions}function _4(t){return t.currentDirectory}function B4(t){return t.getActiveProject()}function V4(t){return t.searchFiles}function z4(t){return t.ensureStatus}function U4(){uh()}function W4(){Ar.requestDirectoryDialog()}function K4(t){console.warn("[command-palette] failed to open draft mini chat window",t)}function H4(t){return t.slug!=="home"}function G4(t){return(typeof t.time?.updated=="number"?t.time.updated:0)||(typeof t.time?.created=="number"?t.time.created:0)}function q4(t){return t.worktreeMetadata}function Y4(t){return{path:kd(t.path),name:t.name,relativePath:t.relativePath}}function Q4(t){return{item:t,score:0}}function J4(t){return t.searchText}function X4(t){return t.searchText}function Z4(t){return{item:t,score:0}}function eI(t){return t.title||""}function tI(t){return t.name}function sI(t){return t.item}function nI(t){return t.item}function rI(t){return t.item}function aI(t){return t.item}function iI(t){return t.length?t[0].score:1/0}function oI(t,e){return t.score-e.score}function lI(t){return t.key}function cI(t){return s.jsxs(An,{value:t.id,onSelect:t.onSelect,children:[t.icon,s.jsx("span",{children:t.title})]},t.id)}const Xp=(t,e,n)=>xy(t)?Fl(Zr(t,n)):e,dI=()=>{const t=ot.c(68),{t:e}=ut(),n=Re(uI),r=Re(mI),a=Re(pI);let i;t[0]===Symbol.for("react.memo_cache_sentinel")?(i=gy(),t[0]=i):i=t[0];const l=i;let c,d,p,m,u,f,b,g,v;if(t[1]!==n||t[2]!==r||t[3]!==a||t[4]!==e){const O=[{categoryKey:"helpDialog.section.navigationCommands",items:[{id:"open_command_palette",descriptionKey:"helpDialog.item.openCommandPalette",icon:"command",keys:""},{id:"open_help",descriptionKey:"helpDialog.item.showKeyboardShortcuts",icon:"question",keys:""},{id:"toggle_sidebar",descriptionKey:"helpDialog.item.toggleSessionSidebar",icon:"layout-left",keys:""},{id:"cycle_agent",keys:"",descriptionKey:"helpDialog.item.cycleAgent",icon:"ai-agent"},{id:"open_model_selector",descriptionKey:"helpDialog.item.openModelSelector",icon:"ai-generate-2",keys:""},{keys:["↑↓"],descriptionKey:"helpDialog.item.navigateModels",icon:"ai-generate-2"},{keys:["←→"],descriptionKey:"helpDialog.item.adjustThinkingMode",icon:"brain-ai-3"},{id:"cycle_thinking_variant",descriptionKey:"helpDialog.item.cycleThinkingVariant",icon:"brain-ai-3",keys:""},{keys:[`Shift + Alt + ${l} + N`],descriptionKey:"helpDialog.item.newWindow",icon:"window"}]},{categoryKey:"helpDialog.section.sessionManagement",items:[{id:"new_chat",descriptionKey:"helpDialog.item.createNewSession",icon:"add",keys:""},{id:"new_chat_worktree",descriptionKey:"helpDialog.item.createNewWorktreeDraft",icon:"git-branch",keys:""},{id:"focus_input",descriptionKey:"helpDialog.item.focusChatInput",icon:"text",keys:""},{id:"abort_run",descriptionKey:"helpDialog.item.abortActiveRun",icon:"close-circle",keys:""}]},{categoryKey:"helpDialog.section.panels",items:[{id:"toggle_right_sidebar",descriptionKey:"helpDialog.item.toggleRightSidebar",icon:"layout-right",keys:""},{id:"open_right_sidebar_git",descriptionKey:"helpDialog.item.openRightSidebarGitTab",icon:"git-branch",keys:""},{id:"open_right_sidebar_files",descriptionKey:"helpDialog.item.openRightSidebarFilesTab",icon:"layout-right",keys:""},{id:"cycle_right_sidebar_tab",descriptionKey:"helpDialog.item.cycleRightSidebarTab",icon:"layout-right",keys:""},{id:"toggle_terminal",descriptionKey:"helpDialog.item.toggleTerminalDock",icon:"window",keys:""},{id:"toggle_terminal_expanded",descriptionKey:"helpDialog.item.toggleTerminalExpanded",icon:"window",keys:""},{id:"toggle_context_plan",descriptionKey:"helpDialog.item.togglePlanContextPanel",icon:"time",keys:""}]},{categoryKey:"helpDialog.section.interface",items:[{id:"cycle_theme",descriptionKey:"helpDialog.item.cycleTheme",icon:"palette",keys:""},{keys:[`${l} + 1...9`],descriptionKey:"helpDialog.item.switchProject",icon:"layout-left"},{id:"toggle_services_menu",descriptionKey:"helpDialog.item.toggleServicesMenu",icon:"stack",keys:""},{id:"cycle_services_tab",descriptionKey:"helpDialog.item.cycleServicesTab",icon:"stack",keys:""},{id:"open_settings",descriptionKey:"helpDialog.item.openSettings",icon:"settings-3",keys:""}]}];d=ps,g=n,v=r,c=ms,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(D,{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(fs,{className:"flex items-center gap-2",children:[V,B]}),t[17]=B,t[18]=$):$=t[18];let F;t[19]!==e?(F=e("helpDialog.description"),t[19]=e,t[20]=F):F=t[20];let _;t[21]!==F?(_=s.jsx(Ns,{children:F}),t[21]=F,t[22]=_):_=t[22],t[23]!==$||t[24]!==_?(b=s.jsxs(gs,{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=O.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 Y=L.id?Xp(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(D,{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(Y)?Y:[Y]).map((Z,ae)=>s.jsxs(o.Fragment,{children:[ae>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}-${ae}`))})]},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]=g,t[13]=v}else c=t[5],d=t[6],p=t[7],m=t[8],u=t[9],f=t[10],b=t[11],g=t[12],v=t[13];let x;t[26]!==p||t[27]!==m?(x=s.jsx("div",{className:p,children:m}),t[26]=p,t[27]=m,t[28]=x):x=t[28];let h;t[29]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(D,{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 y;t[32]!==j?(y=s.jsx("p",{className:"font-medium mb-1",children:j}),t[32]=j,t[33]=y):y=t[33];let C;t[34]!==a||t[35]!==e?(C=e("helpDialog.proTips.commandPalette",{shortcut:Xp("open_command_palette",`${l} P`,a)}),t[34]=a,t[35]=e,t[36]=C):C=t[36];let k;t[37]!==C?(k=s.jsxs("li",{children:["• ",C]}),t[37]=C,t[38]=k):k=t[38];let w;t[39]!==e?(w=e("helpDialog.proTips.recentSessions"),t[39]=e,t[40]=w):w=t[40];let S;t[41]!==w?(S=s.jsxs("li",{children:["• ",w]}),t[41]=w,t[42]=S):S=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]!==S||t[49]!==T?(P=s.jsxs("ul",{className:"space-y-0.5 typography-meta",children:[k,S,T]}),t[47]=k,t[48]=S,t[49]=T,t[50]=P):P=t[50];let A;t[51]!==y||t[52]!==P?(A=s.jsx("div",{className:"mt-4 p-2 bg-muted/30 rounded-xl",children:s.jsxs("div",{className:"flex items-start gap-2",children:[h,s.jsxs("div",{className:"typography-meta text-muted-foreground",children:[y,P]})]})}),t[51]=y,t[52]=P,t[53]=A):A=t[53];let N;t[54]!==A||t[55]!==u||t[56]!==x?(N=s.jsxs("div",{className:u,children:[x,A]}),t[54]=A,t[55]=u,t[56]=x,t[57]=N):N=t[57];let E;t[58]!==c||t[59]!==N||t[60]!==f||t[61]!==b?(E=s.jsxs(c,{className:f,children:[b,N]}),t[58]=c,t[59]=N,t[60]=f,t[61]=b,t[62]=E):E=t[62];let M;return t[63]!==d||t[64]!==E||t[65]!==g||t[66]!==v?(M=s.jsx(d,{open:g,onOpenChange:v,children:E}),t[63]=d,t[64]=E,t[65]=g,t[66]=v,t[67]=M):M=t[67],M};function uI(t){return t.isHelpDialogOpen}function mI(t){return t.setHelpDialogOpen}function pI(t){return t.shortcutOverrides}const fI=()=>{const t=ot.c(32),{t:e}=ut(),n=Re(hI),r=Re(gI),a=Re(xI);let i;t[0]!==a||t[1]!==e?(i=async()=>{if(!a)return;if((await Rn(a)).ok){G.success(e("openCodeStatusDialog.toast.copiedTitle"),{description:e("openCodeStatusDialog.toast.copiedDescription")});return}G.error(e("openCodeStatusDialog.toast.copyFailed"))},t[0]=a,t[1]=e,t[2]=i):i=t[2];const l=i;let c;t[3]!==e?(c=e("openCodeStatusDialog.title"),t[3]=e,t[4]=c):c=t[4];let d;t[5]!==c?(d=s.jsx(fs,{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(gs,{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]!==l||t[17]!==f?(b=s.jsx("div",{className:"flex items-center justify-end",children:s.jsx("button",{type:"button",onClick:l,className:"app-region-no-drag inline-flex h-9 items-center justify-center rounded-md px-3 typography-ui-label font-medium text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:f})}),t[16]=l,t[17]=f,t[18]=b):b=t[18];let g;t[19]!==a||t[20]!==e?(g=a||e("openCodeStatusDialog.empty.noData"),t[19]=a,t[20]=e,t[21]=g):g=t[21];let v;t[22]!==g?(v=s.jsx("pre",{className:"max-h-[60vh] overflow-auto rounded-lg bg-surface-muted p-4 typography-code text-foreground whitespace-pre-wrap",children:g}),t[22]=g,t[23]=v):v=t[23];let x;t[24]!==u||t[25]!==b||t[26]!==v?(x=s.jsxs(ms,{className:"max-w-2xl",children:[u,b,v]}),t[24]=u,t[25]=b,t[26]=v,t[27]=x):x=t[27];let h;return t[28]!==n||t[29]!==r||t[30]!==x?(h=s.jsx(ps,{open:n,onOpenChange:r,children:x}),t[28]=n,t[29]=r,t[30]=x,t[31]=h):h=t[31],h};function hI(t){return t.isOpenCodeStatusDialogOpen}function gI(t){return t.setOpenCodeStatusDialogOpen}function xI(t){return t.openCodeStatusText}const bI=180,Zp=600,yI=1,vI=6,wI=({currentSessionId:t,sortedSessions:e,recentSessionIds:n=[],ensureSessionRenderable:r})=>{const a=o.useRef(new Map),i=o.useRef([]),l=o.useRef(new Set),c=o.useMemo(()=>mn(),[]),d=o.useCallback(()=>{if(!(c||typeof window>"u"))for(;l.current.size<yI&&i.current.length>0;){const m=i.current.shift();if(!m)break;$t.getState().currentSessionId!==m&&(_u(m).renderable||(l.current.add(m),r(m).catch(()=>{}).finally(()=>{l.current.delete(m),d()})))}},[r,c]),p=o.useCallback(m=>{if(c||!m||m===t||typeof window>"u"||_u(m).renderable||l.current.has(m)||i.current.includes(m))return;i.current.length>=vI&&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()},bI);a.current.set(m,f)},[t,c,d]);o.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))},Zp);return()=>window.clearTimeout(m)},[t,c,p,e]),o.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]))},Zp);return()=>window.clearTimeout(m)},[t,c,n,p]),o.useEffect(()=>{const m=a.current;return()=>{m.forEach(u=>{clearTimeout(u)}),m.clear(),i.current=[]}},[])};function ef(t){const{localBranches:e,remoteBranches:n,query:r}=t,a=r.trim();if(!a)return{matching:[],otherLocal:e,otherRemote:n};const i=Bu(e,a,m=>m),l=Bu(n,a,m=>m),c=[],d=i.other,p=l.other;for(const m of i.matching)c.push({label:m,value:m,source:"local"});for(const m of l.matching)c.push({label:m,value:`remotes/${m}`,source:"remote"});return c.sort((m,u)=>{const 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 jI({open:t,onOpenChange:e,onSelect:n}){const{t:r}=ut(),a=Re(ue=>ue.isMobile),{github:i}=Bn(),l=Hn(ue=>ue.status),c=Hn(ue=>ue.hasChecked),d=Re(ue=>ue.setSettingsDialogOpen),p=Re(ue=>ue.setSettingsPage),m=Cs(ue=>ue.getActiveProject()),u=m?.path??null,f=_e.useMemo(()=>u&&m?{id:m.id,path:u}:null,[m,u]),[b,g]=_e.useState("issues"),[v,x]=_e.useState(""),[h,j]=_e.useState([]),[y,C]=_e.useState([]),[k,w]=_e.useState(!1),[S,I]=_e.useState(!1),[T,P]=_e.useState(null),[A,N]=_e.useState(null),[E,M]=_e.useState(null),[O,V]=_e.useState(!1),[B,$]=_e.useState(new Map),[F,_]=_e.useState(1),[q,L]=_e.useState(!1),Y=_e.useCallback(async()=>{if(!(!u||!i)&&!(c&&l?.connected===!1)){w(!0),P(null),_(1),L(!1);try{if(b==="issues"&&i.issuesList){const ue=await i.issuesList(u,{page:1});ue.connected===!1?(P(r("session.githubIntegration.error.notConnected")),j([])):(j(ue.issues??[]),_(ue.page??1),L(!!ue.hasMore))}else if(b==="prs"&&i.prsList){const ue=await i.prsList(u,{page:1});ue.connected===!1?(P(r("session.githubIntegration.error.notConnected")),C([])):(C(ue.prs??[]),_(ue.page??1),L(!!ue.hasMore))}}catch(ue){P(ue instanceof Error?ue.message:r("session.githubIntegration.error.loadDataFailed"))}finally{w(!1)}}},[u,i,c,l,b,r]),Z=_e.useCallback(async()=>{if(!(!u||!i)&&!(k||S)&&q){I(!0);try{const ue=F+1;if(b==="issues"&&i.issuesList){const xe=await i.issuesList(u,{page:ue});xe.connected!==!1&&(j(ne=>[...ne,...xe.issues??[]]),_(xe.page??ue),L(!!xe.hasMore))}else if(b==="prs"&&i.prsList){const xe=await i.prsList(u,{page:ue});xe.connected!==!1&&(C(ne=>[...ne,...xe.prs??[]]),_(xe.page??ue),L(!!xe.hasMore))}}catch{}finally{I(!1)}}},[u,i,b,F,q,k,S]);_e.useEffect(()=>{if(!t){g("issues"),x(""),j([]),C([]),N(null),M(null),V(!1),P(null),$(new Map),_(1),L(!1);return}Y()},[t,Y]);const ae=_e.useCallback(async ue=>{if(!(!f||!ue)&&!B.has(ue))try{const ne=(await mh(f,{mode:"new",branchName:ue,worktreeName:ue})).errors.find(pe=>pe.code==="branch_in_use");$(pe=>new Map(pe).set(ue,{isValid:!ne,error:ne?r(ne.code==="branch_exists"?"session.githubIntegration.validation.branchAlreadyExists":"session.githubIntegration.validation.branchAlreadyCheckedOut"):null}))}catch{$(xe=>new Map(xe).set(ue,{isValid:!1,error:r("session.githubIntegration.validation.failed")}))}},[f,B,r]);_e.useEffect(()=>{!t||b!=="prs"||y.forEach(ue=>{ue.head&&ae(ue.head)})},[t,b,y,ae]);const re=_e.useMemo(()=>{const ue=v.trim().toLowerCase();return ue?h.filter(xe=>String(xe.number)===ue.replace(/^#/,"")?!0:xe.title.toLowerCase().includes(ue)):h},[h,v]),me=_e.useMemo(()=>{const ue=v.trim().toLowerCase();return ue?y.filter(xe=>String(xe.number)===ue.replace(/^#/,"")?!0:xe.title.toLowerCase().includes(ue)):y},[y,v]),fe=c&&l?.connected===!0,H=()=>{p("github"),d(!0)},K=ue=>{N(ue),M(null)},Q=ue=>{M(ue),N(null)},W=()=>{A?n({type:"issue",item:A}):E&&n({type:"pr",item:E,includeDiff:O}),e(!1)},de=()=>{N(null),M(null),V(!1)},be=A||E&&B.get(E.head??"")?.isValid!==!1,we=ue=>ue.head?B.get(ue.head)?.isValid===!1:!0,te=s.jsx(s.Fragment,{children:fe?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"relative mt-2",children:[s.jsx(D,{name:"search",className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),s.jsx(Bt,{value:v,onChange:ue=>x(ue.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(D,{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(D,{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:[re.length>0?re.map(ue=>s.jsx("button",{onClick:()=>K(ue),className:ye("w-full text-left px-2 py-1.5 rounded transition-colors",A?.number===ue.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:["#",ue.number]}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("span",{className:"typography-small line-clamp-2",children:ue.title}),ue.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:[ue.sourceRepo.owner,"/",ue.sourceRepo.repo]}):null]})]})},`${ue.sourceRepo?.owner??""}-${ue.sourceRepo?.repo??""}-${ue.number}`)):s.jsx("div",{className:"flex items-center justify-center h-[300px] text-center typography-small text-muted-foreground",children:r("session.githubIntegration.empty.noIssuesFound")}),q&&!S&&s.jsx("div",{className:"flex justify-center pt-2",children:s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>{Z()},className:"h-7 text-xs",children:r("session.githubIntegration.actions.loadMore")})}),S&&s.jsx("div",{className:"flex items-center justify-center py-2",children:s.jsx(D,{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(ue=>{const xe=we(ue),ne=ue.head?B.get(ue.head):void 0;return s.jsx("button",{onClick:()=>!xe&&Q(ue),disabled:xe,className:ye("w-full text-left px-2 py-1.5 rounded transition-colors",E?.number===ue.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:["#",ue.number]}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("span",{className:"typography-small line-clamp-1",children:ue.title}),s.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[s.jsxs("span",{className:"typography-micro text-muted-foreground",children:[ue.head," → ",ue.base]}),ue.sourceRepo?.source==="upstream"?s.jsxs("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info",children:[ue.sourceRepo.owner,"/",ue.sourceRepo.repo]}):null,xe&&ne?.error&&s.jsx("span",{className:"typography-micro text-destructive",children:ne.error})]})]})]})},`${ue.sourceRepo?.owner??""}-${ue.sourceRepo?.repo??""}-${ue.number}`)}):s.jsx("div",{className:"flex items-center justify-center h-[300px] text-center typography-small text-muted-foreground",children:r("session.githubIntegration.empty.noPullRequestsFound")}),q&&!S&&s.jsx("div",{className:"flex justify-center pt-2",children:s.jsx(ve,{variant:"ghost",size:"sm",onClick:()=>{Z()},className:"h-7 text-xs",children:r("session.githubIntegration.actions.loadMore")})}),S&&s.jsx("div",{className:"flex items-center justify-center py-2",children:s.jsx(D,{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(D,{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(ve,{onClick:H,size:"sm",children:r("session.githubIntegration.connect.action")})]})}),ge=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&&(A||E)&&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(D,{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:A?r("session.githubIntegration.selected.issueNumber",{number:A.number}):r("session.githubIntegration.selected.prNumber",{number:E?.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(D,{name:"close",className:"h-3.5 w-3.5"})})]}),b==="prs"&&E&&s.jsxs("label",{className:"flex items-center gap-2 cursor-pointer h-8",children:[s.jsx(xs,{checked:O,onChange:ue=>V(ue),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(ve,{variant:"outline",size:"sm",onClick:()=>e(!1),className:ye(a&&"flex-1"),children:r("session.githubIntegration.actions.cancel")}),s.jsx(ve,{size:"sm",onClick:W,disabled:!be,className:ye(a&&"flex-1"),children:r("session.githubIntegration.actions.select")})]})]});return s.jsx(s.Fragment,{children:a?s.jsx(Br,{open:t,title:r("session.githubIntegration.title"),onClose:()=>e(!1),footer:fe?ge:void 0,renderHeader:ue=>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")}),ue]}),s.jsx("div",{className:"w-full",children:s.jsx(Vr,{items:[{id:"issues",label:r("session.githubIntegration.tabs.issues"),icon:s.jsx(D,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"prs",label:r("session.githubIntegration.tabs.pullRequests"),icon:s.jsx(D,{name:"git-pull-request",className:"h-3.5 w-3.5"})}],activeId:b,onSelect:xe=>{g(xe),x("")},variant:"active-pill",layoutMode:"fit"})}),(A||E)&&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(D,{name:"check",className:"h-3.5 w-3.5 text-status-success shrink-0"}),s.jsx("span",{className:"typography-small truncate flex-1",children:A?r("session.githubIntegration.selected.issueNumber",{number:A.number}):r("session.githubIntegration.selected.prNumber",{number:E?.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(D,{name:"close",className:"h-3.5 w-3.5"})})]})]}),children:te}):s.jsx(ps,{open:t,onOpenChange:e,children:s.jsxs(ms,{className:"max-w-2xl max-h-[70vh] flex flex-col",children:[s.jsx(gs,{className:"flex flex-row items-center justify-between",children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsxs(fs,{className:"flex items-center gap-2 shrink-0",children:[s.jsx(D,{name:"github",className:"h-5 w-5"}),r("session.githubIntegration.title")]}),s.jsx("div",{className:"w-[220px]",children:s.jsx(Vr,{items:[{id:"issues",label:r("session.githubIntegration.tabs.issues"),icon:s.jsx(D,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"prs",label:r("session.githubIntegration.tabs.pullRequests"),icon:s.jsx(D,{name:"git-pull-request",className:"h-3.5 w-3.5"})}],activeId:b,onSelect:ue=>{g(ue),x("")},variant:"active-pill",layoutMode:"fit"})})]})}),te,s.jsx(Hs,{className:"mt-1",children:ge})]})})})}const Hi=t=>t.trim().replace(/^refs\/heads\//,"").replace(/^heads\//,"").replace(/\s+/g,"-").replace(/^\/+|\/+$/g,""),Fn=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),tf="oc:lastWorktreeSourceBranch",NI=t=>String(t).trim().toLowerCase().replace(/[^a-z0-9._-]+/g,"-").replace(/-+/g,"-").replace(/^-+|-+$/g,"")||"pr-head",sf=(t,e,n)=>{const r=Hi(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(),l=t.headRepo?.owner||i||"pr-head",c=`pr-${NI(l)}`,d=t.headRepo?.sshUrl||t.headRepo?.cloneUrl||"";if(!d)throw new Error("PR head repository URL is unavailable");return{existingBranch:`remotes/${c}/${r}`,setUpstream:!0,upstreamRemote:c,upstreamBranch:r,ensureRemoteName:c,ensureRemoteUrl:d,sourceLabel:`${c}/${r}`}},SI=t=>{const e={repo:t.repo??null,issue:t.issue,comments:t.comments};return`GitHub issue context (JSON)
|
|
183
|
-
${JSON.stringify(e,null,2)}`},kI=t=>`GitHub pull request context (JSON)
|
|
184
|
-
${JSON.stringify(t,null,2)}`;function CI({open:t,onOpenChange:e,onWorktreeCreated:n}){const{t:r}=ut(),{github:a,git:i}=Bn(),l=Re(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"),[g,v]=_e.useState({branchName:"",worktreeName:"",isSyncingWorktreeName:!0,sourceBranch:"",linkedIssue:null,linkedPr:null,includePrDiff:!1}),[x,h]=_e.useState({selectedBranch:"",worktreeName:""}),j=Od(m),y=ph(m),C=Qs(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]),S=$t(z=>z.availableWorktreesByProject),I=_e.useMemo(()=>{if(!m)return new Set;const z=S.get(m)??[];return new Set(z.map(De=>De.name))},[S,m]),T=_e.useCallback((z=10)=>{for(let De=0;De<z;De++){const Xe=ic();if(!I.has(Xe))return Xe}return`${ic()}-${Date.now().toString(36).slice(-4)}`},[I]),[P,A]=_e.useState(!1),[N,E]=_e.useState(!1),[M,O]=_e.useState(!1),[V,B]=_e.useState(!1),[$,F]=_e.useState(!1),[_,q]=_e.useState(""),[L,Y]=_e.useState(""),Z=_e.useRef(null),ae=_e.useRef(null),re=_e.useRef(null),me=_e.useRef(null),fe=_e.useCallback(z=>{z.stopPropagation()},[]),H=_e.useCallback(z=>{let De=z;for(;De&&De!==document.body;){const{overflowY:Xe}=window.getComputedStyle(De);if((Xe==="auto"||Xe==="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=H(z.current);K(De)},[H,K]),de=_e.useMemo(()=>ef({localBranches:k,remoteBranches:w,query:_}),[k,w,_]),be=_e.useMemo(()=>ef({localBranches:k,remoteBranches:w,query:L}),[k,w,L]),we=_.trim().length>0,te=L.trim().length>0,ge=de.matching.length>0,ue=be.matching.length>0,xe=!!(m&&i),ne=_e.useCallback(()=>{!m||!i||C(m,i)},[m,i,C]);_e.useEffect(()=>{!N&&!V&&q("")},[N,V]),_e.useEffect(()=>{!M&&!$&&Y("")},[M,$]),_e.useEffect(()=>{N&&Q(Z),V&&W(re)},[N,V,_,Q,W]),_e.useEffect(()=>{M&&Q(ae),$&&W(me)},[M,$,L,Q,W]);const[pe,J]=_e.useState({isValidating:!1,branchError:null,worktreeError:null,touched:!1}),[Se,he]=_e.useState(!1),[Ie,Pe]=_e.useState(null),Ce=_e.useCallback(()=>{const z=yt.getState(),De=z.getVisibleAgents();if(z.settingsDefaultAgent){const Xe=De.find(st=>st.name===z.settingsDefaultAgent);if(Xe)return Xe.name}return De.find(Xe=>Xe.name==="build")?.name||De[0]?.name},[]),X=_e.useCallback(()=>{const z=yt.getState(),De=z.settingsDefaultModel;if(!De)return null;const Xe=yi(De);if(!Xe)return null;const{providerId:st,modelId:tt}=Xe;return z.getModelMetadata(st,tt)?{providerID:st,modelID:tt}:null},[]),ie=_e.useCallback((z,De)=>{const Xe=yt.getState(),st=Xe.settingsDefaultVariant;if(!st)return;const it=Xe.providers.find(Ye=>Ye.id===z)?.models.find(Ye=>Ye.id===De)?.variants;if(it&&Object.prototype.hasOwnProperty.call(it,st))return st},[]),Ne=_e.useCallback(z=>{const De=yt.getState();try{Po.getState().saveSessionModelSelection(z.sessionId,z.providerID,z.modelID)}catch{}if(z.agentName){try{De.setAgent(z.agentName)}catch{}try{Po.getState().saveSessionAgentSelection(z.sessionId,z.agentName)}catch{}try{Po.getState().saveAgentModelForSession(z.sessionId,z.agentName,z.providerID,z.modelID)}catch{}if(z.variant!==void 0){try{De.setCurrentVariant(z.variant)}catch{}try{Po.getState().saveAgentModelVariantForSession(z.sessionId,z.agentName,z.providerID,z.modelID,z.variant)}catch{}}}},[]),oe=_e.useCallback(async z=>{if(!m||!a)return;const De=yt.getState(),Xe=Ol.getState().lastUsedProvider,st=X(),tt=st?.providerID||De.currentProviderId||Xe?.providerID,Ue=st?.modelID||De.currentModelId||Xe?.modelID,it=Ce()||De.currentAgentName||void 0;if(!tt||!Ue){G.error(r("session.newWorktree.error.noModelSelected"));return}const Ye=ie(tt,Ue);if(Ne({sessionId:z.sessionId,providerID:tt,modelID:Ue,agentName:it,variant:Ye}),z.issue){if(!a.issueGet||!a.issueComments)return;const rt=await a.issueGet(m,z.issue.number);if(rt.connected===!1||!rt.repo||!rt.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 ce=await kn("github.issue.review.visible",{issue_number:String(z.issue.number)}),We=await kn("github.issue.review.instructions"),Le=SI({repo:rt.repo,issue:rt.issue,comments:Je.comments??[]});await nn.sendMessage({id:z.sessionId,providerID:tt,modelID:Ue,agent:it,variant:Ye,text:ce,additionalParts:[{text:We,synthetic:!0},{text:Le,synthetic:!0}]}),G.success(r("session.newWorktree.toast.sessionFromIssue"));return}if(z.pr){if(!a.prContext)return;const rt=await a.prContext(m,z.pr.number,{includeDiff:z.includeDiff,includeCheckDetails:!1});if(rt.connected===!1||!rt.repo||!rt.pr)throw new Error("Failed to load PR context");const Je=await kn("github.pr.review.visible",{pr_number:String(z.pr.number)}),ce=await kn("github.pr.review.instructions"),We=kI(rt);await nn.sendMessage({id:z.sessionId,providerID:tt,modelID:Ue,agent:it,variant:Ye,text:Je,additionalParts:[{text:ce,synthetic:!0},{text:We,synthetic:!0}]}),G.success(r("session.newWorktree.toast.sessionFromPr"))}},[Ne,a,m,Ce,X,ie,r]),ke=f==="new-branch"?g:x;_e.useEffect(()=>{if(!j?.all||!m||g.sourceBranch)return;(async()=>{try{const De=await xo(m).catch(()=>null),Xe=localStorage.getItem(tf),st=Xe&&j.all?.includes(Xe)?Xe:De&&j.all?.includes(De)?De:j.all?.includes("main")?"main":j.all?.includes("master")?"master":j.all?.[0]||"";st&&v(tt=>({...tt,sourceBranch:st}))}catch{}})()},[j,m,g.sourceBranch]),_e.useEffect(()=>{if(!t)return;b("new-branch"),h({selectedBranch:"",worktreeName:""}),E(!1),O(!1),B(!1),F(!1),q(""),Y(""),J({isValidating:!1,branchError:null,worktreeError:null,touched:!1});const z=T();v({branchName:z,worktreeName:z,isSyncingWorktreeName:!0,sourceBranch:"",linkedIssue:null,linkedPr:null,includePrDiff:!1})},[t,T]),_e.useEffect(()=>{if(f!=="new-branch"||!g.isSyncingWorktreeName)return;const z=Hi(g.branchName),De=Fn(z);v(Xe=>({...Xe,worktreeName:De}))},[f,g.branchName,g.isSyncingWorktreeName]);const Te=_e.useCallback(async()=>{if(!u||!pe.touched||Se)return;Ie&&Ie.abort();const z=new AbortController;Pe(z),J(De=>({...De,isValidating:!0}));try{const De=f==="new-branch"?g.branchName:x.selectedBranch,Xe=ke.worktreeName,st=Hi(De),tt=Fn(Xe);let Ue=null,it=null;if(st||(Ue=r("session.newWorktree.error.branchNameRequired")),tt||(it=r("session.newWorktree.error.worktreeDirectoryRequired")),st&&tt){const Ye=f==="new-branch"?g.linkedPr:null,rt=Ye?sf(Ye,k,w):null,Je=await mh(u,{mode:f==="existing-branch"||rt?"existing":"new",branchName:st,worktreeName:tt,existingBranch:rt?.existingBranch??(f==="existing-branch"?st:void 0),...rt?.ensureRemoteName?{ensureRemoteName:rt.ensureRemoteName}:{},...rt?.ensureRemoteUrl?{ensureRemoteUrl:rt.ensureRemoteUrl}:{}});if(z.signal.aborted)return;Je.ok||Je.errors.forEach(ce=>{if(ce.code==="worktree_exists"){it=it??ce.message;return}ce.code.startsWith("branch_")&&(Ue=Ue??ce.message)})}z.signal.aborted||J(Ye=>({...Ye,isValidating:!1,branchError:Ue,worktreeError:it}))}catch{z.signal.aborted||J(De=>({...De,isValidating:!1}))}},[u,f,g.branchName,g.linkedPr,x.selectedBranch,ke.worktreeName,k,w,pe.touched,Ie,Se,r]),Be=f==="new-branch"?g.branchName:x.selectedBranch;_e.useEffect(()=>{if(!t||!u||!pe.touched||Se)return;const z=setTimeout(()=>{Te()},300);return()=>clearTimeout(z)},[ke.worktreeName,Be,t,u,Te,pe.touched,Se]);const je=async()=>{if(!u||!m){G.error(r("session.newWorktree.error.noActiveProject"));return}J(tt=>({...tt,touched:!0}));const z=f==="new-branch"?g.branchName:x.selectedBranch,De=ke.worktreeName,Xe=Hi(z),st=Fn(De);if(!Xe){G.error(r("session.newWorktree.error.branchNameRequired"));return}if(!st){G.error(r("session.newWorktree.error.worktreeDirectoryRequired"));return}Ie&&(Ie.abort(),Pe(null)),J(tt=>({...tt,isValidating:!1,branchError:null,worktreeError:null})),he(!0);try{const tt=await Ud(u),Ue=f==="new-branch"?g.linkedPr:null,it=g.sourceBranch;let Ye="";const rt=(()=>{if(Ue){const He=sf(Ue,k,w);return Ye=He.sourceLabel,{preferredName:Xe||st,mode:"existing",branchName:Xe,worktreeName:st,existingBranch:He.existingBranch,setupCommands:tt,setUpstream:He.setUpstream,upstreamRemote:He.upstreamRemote,upstreamBranch:He.upstreamBranch,...He.ensureRemoteName?{ensureRemoteName:He.ensureRemoteName}:{},...He.ensureRemoteUrl?{ensureRemoteUrl:He.ensureRemoteUrl}:{}}}return Ye=f==="new-branch"?it:"",{preferredName:Xe||st,mode:f==="existing-branch"?"existing":"new",branchName:f==="existing-branch"?void 0:Xe,worktreeName:st,existingBranch:f==="existing-branch"?Xe:void 0,setupCommands:tt,...it&&f==="new-branch"?{startRef:it}:{}}})(),Je=await by(m,rt),ce=await yy(u,Je),We=f==="new-branch"?g.linkedIssue:null,Le=f==="new-branch"?g.linkedPr:null,Ge=f==="new-branch"?g.includePrDiff:!1;let at=null;if(We||Le){const He=We?`#${We.number} ${We.title}`.trim():Le?`#${Le.number} ${Le.title}`.trim():r("session.newWorktree.newSessionTitle"),ze=await vy(He,ce.path,null);if(!ze?.id)throw new Error("Failed to create session");at=ze.id,wy(ze.id,He).catch(()=>{});try{$t.getState().initializeNewOpenChamberSession(ze.id,yt.getState().agents)}catch{}}g.sourceBranch&&f==="new-branch"&&!g.linkedPr&&localStorage.setItem(tf,g.sourceBranch),G.success(r("session.newWorktree.toast.worktreeCreated"),{description:r("session.newWorktree.toast.worktreeCreatedDescription",{target:`${ce.branch||ce.name}${Ye?` ${r("session.newWorktree.fromSource",{source:Ye})}`:""}`})}),e(!1),at?(n?.(ce.path,{sessionId:at}),oe({sessionId:at,issue:We,pr:Le,includeDiff:Ge}).catch(He=>{const ze=He instanceof Error?He.message:r("session.newWorktree.error.sendGitHubContextFailed");G.error(r("session.newWorktree.error.sendGitHubContextFailed"),{description:ze})})):n?.(ce.path)}catch(tt){const Ue=tt instanceof Error?tt.message:r("session.newWorktree.error.createWorktreeFailed");G.error(r("session.newWorktree.error.createWorktreeFailed"),{description:Ue})}finally{he(!1)}},ee=z=>{b(z),J(De=>({...De,touched:!1,branchError:null,worktreeError:null}))},R=z=>{if(!z){v(De=>({...De,linkedIssue:null,linkedPr:null,includePrDiff:!1,branchName:""}));return}if(z.type==="issue"){const De=z.item,Xe=`issue-${De.number}-${ic()}`;v(st=>({...st,linkedIssue:De,linkedPr:null,includePrDiff:!1,branchName:Xe,worktreeName:Fn(Xe),isSyncingWorktreeName:!0}))}else if(z.type==="pr"){const De=z.item;v(Xe=>({...Xe,linkedPr:De,linkedIssue:null,includePrDiff:z.includeDiff??!1,branchName:De.head,worktreeName:Fn(De.head),isSyncingWorktreeName:!0}))}},U=d&&c?.connected===!0,Me=(f==="existing-branch"?!!x.selectedBranch&&!!x.worktreeName&&!pe.branchError&&!pe.worktreeError:!!Hi(g.branchName)&&!!g.worktreeName&&!pe.branchError&&!pe.worktreeError)&&!Se,Oe=()=>{v(z=>({...z,linkedIssue:null,linkedPr:null,branchName:"",includePrDiff:!1,isSyncingWorktreeName:!0}))},Ae=s.jsxs("div",{className:ye("flex gap-2",l?"flex-col w-full":"flex-row items-center"),children:[s.jsx("div",{className:ye("flex items-center gap-1.5 text-destructive",l?"w-full justify-center order-first":"mr-auto"),children:pe.touched&&(pe.branchError||pe.worktreeError)&&s.jsxs(s.Fragment,{children:[s.jsx(D,{name:"error-warning",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"typography-micro",children:pe.branchError||pe.worktreeError})]})}),s.jsxs("div",{className:ye("flex gap-2",l&&"w-full"),children:[s.jsx(ve,{variant:"outline",size:"sm",onClick:()=>e(!1),disabled:Se,className:ye(l&&"flex-1"),children:r("session.newWorktree.actions.cancel")}),s.jsxs(ve,{size:"sm",onClick:je,disabled:!Me||Se,className:ye("gap-1.5",l&&"flex-1"),children:[Se&&s.jsx(D,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),r(Se?"session.newWorktree.actions.creating":"session.newWorktree.actions.createWorktree")]})]})]});return s.jsxs(s.Fragment,{children:[l?s.jsxs(Br,{open:t,title:r("session.newWorktree.title"),onClose:()=>e(!1),footer:Ae,children:[s.jsx("div",{className:"w-full mb-4",children:s.jsx(Vr,{items:[{id:"new-branch",label:r("session.newWorktree.mode.newBranch"),icon:s.jsx(D,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"existing-branch",label:r("session.newWorktree.mode.existingBranch"),icon:s.jsx(D,{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(ve,{variant:"outline",size:"sm",onClick:()=>B(!0),className:"flex-1 justify-between h-9",children:[s.jsx("span",{className:x.selectedBranch?"text-foreground":"text-muted-foreground",children:x.selectedBranch||r("session.newWorktree.chooseBranch")}),s.jsx(D,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"})]}),s.jsx(ve,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0 shrink-0",onClick:ne,disabled:!xe||y,title:r("session.newWorktree.fetchBranches"),children:y?s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(D,{name:"refresh",className:"size-4"})})]}),s.jsx(Br,{open:V,title:r("session.newWorktree.selectBranch"),onClose:()=>B(!1),children:s.jsxs("div",{className:"space-y-4",ref:re,children:[s.jsx(Bt,{value:_,onChange:z=>q(z.target.value),placeholder:r("session.newWorktree.searchBranches"),className:"h-8"}),y?s.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:r("session.newWorktree.loadingBranches")}):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:[we&&ge&&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:Fn(z.label)})),J(De=>({...De,touched:!0})),B(!1)},className:ye("w-full text-left px-3 py-2.5 rounded-md transition-colors",x.selectedBranch===z.value?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:z.label})},`${z.source}-${z.value}`))})]}),we&&!ge&&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(we?"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:Fn(z)})),J(De=>({...De,touched:!0})),B(!1)},className:ye("w-full text-left px-3 py-2.5 rounded-md transition-colors",x.selectedBranch===z?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:z})},z))})]}),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(we?"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:Fn(z)})),J(De=>({...De,touched:!0})),B(!1)},className:ye("w-full text-left px-3 py-2.5 rounded-md transition-colors",x.selectedBranch===`remotes/${z}`?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:z})},`remotes/${z}`))})]})]})]})})]}):s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("div",{className:"flex flex-col items-start gap-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.branchName")}),f==="new-branch"&&U&&s.jsxs(ve,{variant:"outline",size:"sm",onClick:()=>A(!0),className:"gap-1.5 h-7",children:[s.jsx(D,{name:"github",className:"size-4 text-status-success"}),g.linkedIssue||g.linkedPr?r("session.newWorktree.actions.change"):r("session.newWorktree.actions.startFromGitHubIssuePr")]})]}),s.jsx(Bt,{value:g.branchName,onChange:z=>{v(De=>({...De,branchName:z.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>J(z=>({...z,touched:!0})),placeholder:r("session.newWorktree.branchNamePlaceholder"),disabled:!!g.linkedPr,className:ye("h-8",pe.touched&&pe.branchError&&"border-destructive",g.linkedPr&&"bg-muted text-muted-foreground")}),g.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(D,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),s.jsx("span",{className:"typography-micro",children:r("session.newWorktree.usingPrBranch",{branch:g.linkedPr.head})})]}),g.linkedIssue&&!g.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(D,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),s.jsx("span",{className:"typography-micro",children:r("session.newWorktree.fromIssue",{number:g.linkedIssue.number,title:g.linkedIssue.title})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("label",{className:"typography-ui-label text-foreground font-semibold",children:r("session.newWorktree.worktreeDirectory")}),f!=="existing-branch"&&s.jsxs("button",{onClick:()=>{const z=Fn(f==="new-branch"?g.branchName:"");v(De=>({...De,worktreeName:z,isSyncingWorktreeName:!0}))},disabled:!g.branchName||g.worktreeName===Fn(g.branchName),className:ye("flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded",g.worktreeName===Fn(g.branchName)||!g.branchName?"text-muted-foreground/40 cursor-not-allowed":"text-muted-foreground hover:text-foreground hover:bg-muted"),title:r("session.newWorktree.resetToMatchBranchName"),children:[s.jsx(D,{name:"refresh",className:"h-3 w-3"}),s.jsx("span",{children:r("session.newWorktree.actions.reset")})]})]}),s.jsx(Bt,{value:ke.worktreeName,onChange:z=>{f==="new-branch"?v(De=>({...De,worktreeName:z.target.value,isSyncingWorktreeName:!1})):h(De=>({...De,worktreeName:z.target.value}))},onBlur:()=>J(z=>({...z,touched:!0})),placeholder:r("session.newWorktree.worktreeDirectoryPlaceholder"),className:ye("h-8",pe.touched&&pe.worktreeError&&"border-destructive")})]}),f==="new-branch"&&!g.linkedPr&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.sourceBranch")}),s.jsxs(ve,{variant:"outline",size:"sm",onClick:()=>F(!0),className:"w-full justify-between h-9",children:[s.jsx("span",{className:g.sourceBranch?"text-foreground":"text-muted-foreground",children:g.sourceBranch||r("session.newWorktree.selectSourceBranchPlaceholder")}),s.jsx(D,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"})]}),g.sourceBranch&&s.jsx("div",{className:"typography-micro text-muted-foreground",children:r("session.newWorktree.newBranchFromSource",{source:g.sourceBranch})}),s.jsx(Br,{open:$,title:r("session.newWorktree.selectSourceBranch"),onClose:()=>F(!1),children:s.jsxs("div",{className:"space-y-4",ref:me,children:[s.jsx(Bt,{value:L,onChange:z=>Y(z.target.value),placeholder:r("session.newWorktree.searchBranches"),className:"h-8"}),y?s.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:r("session.newWorktree.loadingBranches")}):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&&ue&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:r("session.newWorktree.matchingBranches")}),s.jsx("div",{className:"space-y-1",children:be.matching.map(z=>s.jsx("button",{onClick:()=>{v(De=>({...De,sourceBranch:z.value})),F(!1)},className:ye("w-full text-left px-3 py-2.5 rounded-md transition-colors",g.sourceBranch===z.value?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:z.label})},`${z.source}-${z.value}`))})]}),te&&!ue&&s.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),be.otherLocal.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:r(te?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches")}),s.jsx("div",{className:"space-y-1",children:be.otherLocal.map(z=>s.jsx("button",{onClick:()=>{v(De=>({...De,sourceBranch:z})),F(!1)},className:ye("w-full text-left px-3 py-2.5 rounded-md transition-colors",g.sourceBranch===z?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:z})},z))})]}),be.otherRemote.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:r(te?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches")}),s.jsx("div",{className:"space-y-1",children:be.otherRemote.map(z=>s.jsx("button",{onClick:()=>{v(De=>({...De,sourceBranch:`remotes/${z}`})),F(!1)},className:ye("w-full text-left px-3 py-2.5 rounded-md transition-colors",g.sourceBranch===`remotes/${z}`?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:z})},`remotes/${z}`))})]})]})]})})]}),(g.linkedIssue||g.linkedPr)&&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(D,{name:"github",className:"h-3.5 w-3.5 text-status-success shrink-0"}),g.linkedIssue&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.issueNumber",{number:g.linkedIssue.number})}),g.linkedPr&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.prNumber",{number:g.linkedPr.number})}),s.jsx("span",{className:"typography-micro text-foreground truncate flex-1",children:g.linkedIssue?.title||g.linkedPr?.title}),s.jsx("a",{href:g.linkedIssue?.url||g.linkedPr?.url,target:"_blank",rel:"noopener noreferrer",className:"text-muted-foreground hover:text-foreground shrink-0",onClick:z=>z.stopPropagation(),children:s.jsx(D,{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(D,{name:"close",className:"h-3.5 w-3.5"})})]}),g.linkedPr&&s.jsxs("div",{className:"flex items-center gap-2 mt-0.5 pl-5",children:[s.jsxs("span",{className:"typography-micro text-muted-foreground",children:[g.linkedPr.head," → ",g.linkedPr.base]}),g.includePrDiff&&s.jsx("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success",children:r("session.newWorktree.includeDiffBadge")})]})]})]})]}):s.jsx(ps,{open:t,onOpenChange:e,children:s.jsxs(ms,{className:"max-w-lg max-h-[80vh] flex flex-col",children:[s.jsx(gs,{className:"flex flex-row items-center justify-between",children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsxs(fs,{className:"flex items-center gap-2 shrink-0",children:[s.jsx(D,{name:"git-branch",className:"h-5 w-5"}),r("session.newWorktree.title")]}),s.jsx("div",{className:"w-[280px] shrink-0",children:s.jsx(Vr,{items:[{id:"new-branch",label:r("session.newWorktree.mode.newBranch"),icon:s.jsx(D,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"existing-branch",label:r("session.newWorktree.mode.existingBranch"),icon:s.jsx(D,{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:N,onOpenChange:E,children:[s.jsx(Is,{asChild:!0,children:s.jsxs(ve,{variant:"outline",size:"sm",className:"h-9 min-w-[220px] max-w-full justify-between gap-2",children:[s.jsx("span",{className:ye("truncate",x.selectedBranch?"text-foreground":"text-muted-foreground"),children:x.selectedBranch||r("session.newWorktree.chooseBranch")}),s.jsx(D,{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(Wa,{shouldFilter:!1,children:[s.jsx(ga,{placeholder:r("session.newWorktree.searchBranches"),value:_,onValueChange:q,onKeyDown:fe}),s.jsx(Ka,{disableHorizontal:!0,children:y?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(Ha,{children:r("session.newWorktree.noBranchesFound")}):s.jsxs(s.Fragment,{children:[we&&ge&&s.jsx(Ln,{heading:r("session.newWorktree.matchingBranches"),children:de.matching.map(z=>s.jsx(An,{value:z.value,onSelect:()=>{h(De=>({...De,selectedBranch:z.value,worktreeName:Fn(z.label)})),J(De=>({...De,touched:!0})),E(!1)},children:s.jsx("span",{className:"typography-small break-all",children:z.label})},`${z.source}-${z.value}`))}),we&&!ge&&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:[we&&s.jsx(Ra,{}),s.jsx(Ln,{heading:r(we?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches"),children:de.otherLocal.map(z=>s.jsx(An,{value:z,onSelect:()=>{h(De=>({...De,selectedBranch:z,worktreeName:Fn(z)})),J(De=>({...De,touched:!0})),E(!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||we)&&s.jsx(Ra,{}),s.jsx(Ln,{heading:r(we?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches"),children:de.otherRemote.map(z=>s.jsx(An,{value:`remotes/${z}`,onSelect:()=>{h(De=>({...De,selectedBranch:`remotes/${z}`,worktreeName:Fn(z)})),J(De=>({...De,touched:!0})),E(!1)},children:s.jsx("span",{className:"typography-small break-all",children:z})},`remote-${z}`))})]})]})})]})})]}),s.jsx(ve,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0 shrink-0",onClick:ne,disabled:!xe||y,title:r("session.newWorktree.fetchBranches"),children:y?s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(D,{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(ve,{variant:"outline",size:"sm",onClick:()=>A(!0),className:"gap-1.5 h-7",children:[s.jsx(D,{name:"github",className:"size-4 text-status-success"}),g.linkedIssue||g.linkedPr?r("session.newWorktree.actions.change"):r("session.newWorktree.actions.startFromGitHubIssuePr")]})]}),s.jsx(Bt,{value:g.branchName,onChange:z=>{v(De=>({...De,branchName:z.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>J(z=>({...z,touched:!0})),placeholder:r("session.newWorktree.branchNamePlaceholder"),disabled:!!g.linkedPr,className:ye("h-8",pe.touched&&pe.branchError&&"border-destructive",g.linkedPr&&"bg-muted text-muted-foreground")}),g.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(D,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),s.jsx("span",{className:"typography-micro",children:r("session.newWorktree.usingPrBranch",{branch:g.linkedPr.head})})]}),g.linkedIssue&&!g.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(D,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),s.jsx("span",{className:"typography-micro",children:r("session.newWorktree.fromIssue",{number:g.linkedIssue.number,title:g.linkedIssue.title})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("label",{className:"typography-ui-label text-foreground font-semibold",children:r("session.newWorktree.worktreeDirectory")}),f!=="existing-branch"&&s.jsxs("button",{onClick:()=>{const z=Fn(f==="new-branch"?g.branchName:"");v(De=>({...De,worktreeName:z,isSyncingWorktreeName:!0}))},disabled:!g.branchName||g.worktreeName===Fn(g.branchName),className:ye("flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded",g.worktreeName===Fn(g.branchName)||!g.branchName?"text-muted-foreground/40 cursor-not-allowed":"text-muted-foreground hover:text-foreground hover:bg-muted"),title:r("session.newWorktree.resetToMatchBranchName"),children:[s.jsx(D,{name:"refresh",className:"h-3 w-3"}),s.jsx("span",{children:r("session.newWorktree.actions.reset")})]})]}),s.jsx(Bt,{value:ke.worktreeName,onChange:z=>{f==="new-branch"?v(De=>({...De,worktreeName:z.target.value,isSyncingWorktreeName:!1})):h(De=>({...De,worktreeName:z.target.value}))},onBlur:()=>J(z=>({...z,touched:!0})),placeholder:r("session.newWorktree.worktreeDirectoryPlaceholder"),className:ye("h-8",pe.touched&&pe.worktreeError&&"border-destructive")})]}),f==="new-branch"&&!g.linkedPr&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.sourceBranch")}),s.jsxs(As,{open:M,onOpenChange:O,children:[s.jsx(Is,{asChild:!0,children:s.jsxs(ve,{variant:"outline",size:"sm",className:"h-9 min-w-[220px] max-w-full justify-between gap-2",children:[s.jsx("span",{className:ye("truncate",g.sourceBranch?"text-foreground":"text-muted-foreground"),children:g.sourceBranch||r("session.newWorktree.selectSourceBranchPlaceholder")}),s.jsx(D,{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:ae,children:s.jsxs(Wa,{shouldFilter:!1,children:[s.jsx(ga,{placeholder:r("session.newWorktree.searchBranches"),value:L,onValueChange:Y,onKeyDown:fe}),s.jsx(Ka,{disableHorizontal:!0,children:y?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(Ha,{children:r("session.newWorktree.noBranchesFound")}):s.jsxs(s.Fragment,{children:[te&&ue&&s.jsx(Ln,{heading:r("session.newWorktree.matchingBranches"),children:be.matching.map(z=>s.jsx(An,{value:z.value,onSelect:()=>{v(De=>({...De,sourceBranch:z.value})),O(!1)},children:s.jsx("span",{className:"typography-small break-all",children:z.label})},`${z.source}-${z.value}`))}),te&&!ue&&s.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),be.otherLocal.length>0&&s.jsxs(s.Fragment,{children:[te&&s.jsx(Ra,{}),s.jsx(Ln,{heading:r(te?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches"),children:be.otherLocal.map(z=>s.jsx(An,{value:z,onSelect:()=>{v(De=>({...De,sourceBranch:z})),O(!1)},children:s.jsx("span",{className:"typography-small break-all",children:z})},`local-${z}`))})]}),be.otherRemote.length>0&&s.jsxs(s.Fragment,{children:[(be.otherLocal.length>0||te)&&s.jsx(Ra,{}),s.jsx(Ln,{heading:r(te?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches"),children:be.otherRemote.map(z=>s.jsx(An,{value:`remotes/${z}`,onSelect:()=>{v(De=>({...De,sourceBranch:`remotes/${z}`})),O(!1)},children:s.jsx("span",{className:"typography-small break-all",children:z})},`remote-${z}`))})]})]})})]})})]}),g.sourceBranch&&s.jsx("div",{className:"typography-micro text-muted-foreground",children:r("session.newWorktree.newBranchFromSource",{source:g.sourceBranch})})]}),(g.linkedIssue||g.linkedPr)&&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(D,{name:"github",className:"h-3.5 w-3.5 text-status-success shrink-0"}),g.linkedIssue&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.issueNumber",{number:g.linkedIssue.number})}),g.linkedPr&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.prNumber",{number:g.linkedPr.number})}),s.jsx("span",{className:"typography-micro text-foreground truncate flex-1",children:g.linkedIssue?.title||g.linkedPr?.title}),s.jsx("a",{href:g.linkedIssue?.url||g.linkedPr?.url,target:"_blank",rel:"noopener noreferrer",className:"text-muted-foreground hover:text-foreground shrink-0",onClick:z=>z.stopPropagation(),children:s.jsx(D,{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(D,{name:"close",className:"h-3.5 w-3.5"})})]}),g.linkedPr&&s.jsxs("div",{className:"flex items-center gap-2 mt-0.5 pl-5",children:[s.jsxs("span",{className:"typography-micro text-muted-foreground",children:[g.linkedPr.head," → ",g.linkedPr.base]}),g.includePrDiff&&s.jsx("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success",children:r("session.newWorktree.includeDiffBadge")})]})]})]}),s.jsxs(Hs,{className:"mt-1 flex items-center justify-between",children:[s.jsx("div",{className:"flex items-center gap-1.5 text-destructive",children:pe.touched&&(pe.branchError||pe.worktreeError)&&s.jsxs(s.Fragment,{children:[s.jsx(D,{name:"error-warning",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"typography-micro",children:pe.branchError||pe.worktreeError})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ve,{variant:"outline",size:"sm",onClick:()=>e(!1),disabled:Se,children:r("session.newWorktree.actions.cancel")}),s.jsxs(ve,{size:"sm",onClick:je,disabled:!Me||Se,className:"gap-1.5",children:[Se&&s.jsx(D,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),r(Se?"session.newWorktree.actions.creating":"session.newWorktree.actions.createWorktree")]})]})]})]})}),s.jsx(jI,{open:P,onOpenChange:A,onSelect:R})]})}let ui=null,mi=null,il=null,Al=0;const Ba=new Set,II=3e4,PI=45e3,Dg=()=>{il&&(clearTimeout(il),il=null)},Tg=()=>{if(mi||Ba.size===0)return;const t=Math.min(1e3*Math.pow(2,Math.min(Al,5)),II);mi=setTimeout(()=>{mi=null,Al+=1,Mg()},t)},Dl=()=>{Dg(),ui&&ui.close(),ui=null},nf=()=>{Dg(),Ba.size!==0&&(il=setTimeout(()=>{Dl(),Tg()},PI))},AI=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}},DI=t=>{if(t.type==="openchamber:event-stream-ready"){Al=0;return}if(t.type==="openchamber:heartbeat"||t.type!=="openchamber:scheduled-task-ran")return;const e=t.properties&&typeof t.properties=="object"?t.properties:null,n=typeof e?.projectId=="string"?e.projectId:"",r=typeof e?.taskId=="string"?e.taskId:"",a=typeof e?.ranAt=="number"?e.ranAt:Date.now(),i=e?.status,l=i==="running"||i==="error"?i:"success";if(!n||!r)return;const c={type:"scheduled-task-ran",projectId:n,taskId:r,ranAt:a,status:l,...typeof e?.sessionId=="string"&&e.sessionId.length>0?{sessionId:e.sessionId}:{}};for(const d of Ba)d(c)},Mg=()=>{if(typeof window>"u"||Ba.size===0||typeof EventSource!="function"||ui&&ui.readyState!==EventSource.CLOSED)return;Dl();const t=new EventSource("/api/openchamber/events");t.onopen=()=>{nf()},t.onmessage=e=>{nf();const n=AI(e.data);n&&DI(n)},t.onerror=()=>{Dl(),Tg()},ui=t},Eg=t=>(Ba.add(t),Mg(),()=>{Ba.delete(t),Ba.size===0&&(mi&&(clearTimeout(mi),mi=null),Al=0,Dl())}),Gl=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},Ni=t=>{const e=typeof t=="string"?t.trim():"";if(!e)throw new Error("projectId is required");return e},TI=async t=>{const e=Ni(t),n=await fetch(`/api/projects/${encodeURIComponent(e)}/scheduled-tasks`);if(!n.ok)throw new Error(await Gl(n,"Failed to load scheduled tasks"));const r=await n.json().catch(()=>null);return!r||!Array.isArray(r.tasks)?[]:r.tasks},rf=async(t,e)=>{const n=Ni(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 Gl(r,"Failed to save scheduled task"));const a=await r.json().catch(()=>null);return!a||!Array.isArray(a.tasks)?[]:a.tasks},MI=async(t,e)=>{const n=Ni(t),r=Ni(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 Gl(a,"Failed to delete scheduled task"));const i=await a.json().catch(()=>null);return!i||!Array.isArray(i.tasks)?[]:i.tasks},EI=async(t,e)=>{const n=Ni(t),r=Ni(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 Gl(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}},Rg=[0,1,2,3,4,5,6],af=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"],of=()=>{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}`},ol=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},lf=t=>{const e=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${e}-${n}-${r}`},RI=(t,e,n)=>{const r=ol(t);return r?new Intl.DateTimeFormat(n,{month:"short",day:"numeric",year:"numeric"}).format(r):e},cf=(t,e)=>new Date(t.getFullYear(),t.getMonth()+e,1),FI=(t,e)=>{const n=t.getFullYear(),r=t.getMonth(),l=(new Date(n,r,1).getDay()-e+7)%7,c=new Date(n,r+1,0).getDate(),d=new Date(n,r,0).getDate(),p=[];for(let m=0;m<42;m+=1){const u=m-l+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},OI=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}},Ca=(t,e,n)=>{const r=Number(t),a=Number(e),i=Number.isFinite(r)?Math.min(12,Math.max(1,r)):12,l=Number.isFinite(a)?Math.min(59,Math.max(0,a)):0;let c=i%12;return n==="PM"&&(c+=12),`${String(c).padStart(2,"0")}:${String(l).padStart(2,"0")}`},Ci=(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"},df=t=>/^(0[1-9]|1[0-2])$/.test(t)?t:Ci(t,{min:1,max:12}),zo=t=>/^[0-5][0-9]$/.test(t)?t:Ci(t,{max:59}),LI=(t,e)=>Ci(String(Number.parseInt(t,10)+e),{min:1,max:12,loop:!0}),uf=(t,e)=>Ci(String(Number.parseInt(t,10)+e),{min:0,max:59,loop:!0}),$I=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}},_I=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}},BI=t=>{const e=new Intl.DateTimeFormat(t,{weekday:"short"}),n=new Date(2023,0,1);return Rg.map(r=>e.format(new Date(n.getFullYear(),n.getMonth(),n.getDate()+r)))},VI=(t,e)=>[...t.slice(e),...t.slice(0,e)],kr=t=>{const e=ot.c(6),{htmlFor:n,required:r,children:a}=t;let i;e[0]!==r?(i=r&&s.jsx("span",{className:"ml-0.5 text-destructive",children:"*"}),e[0]=r,e[1]=i):i=e[1];let l;return e[2]!==a||e[3]!==n||e[4]!==i?(l=s.jsx("div",{className:"flex items-center gap-1.5",children:s.jsxs("label",{htmlFor:n,className:"typography-meta font-medium text-foreground",children:[a,i]})}),e[2]=a,e[3]=n,e[4]=i,e[5]=l):l=e[5],l},mf=t=>{const e=ot.c(84),{value:n,onChange:r,use24Hour:a,hourAriaLabel:i,minuteAriaLabel:l,periodAriaLabel:c,amLabel:d,pmLabel:p}=t;let m;e[0]!==n?(m=OI(n),e[0]=n,e[1]=m):m=e[1];const u=m,f=_e.useRef(null),b=_e.useRef(null),[g,v]=_e.useState(null),[x,h]=_e.useState(null),j=_e.useRef(null),y=_e.useRef(null);let C;e[2]===Symbol.for("react.memo_cache_sentinel")?(C=J=>{j.current=J,v(J)},e[2]=C):C=e[2];const k=C;let w;e[3]===Symbol.for("react.memo_cache_sentinel")?(w=J=>{y.current=J,h(J)},e[3]=w):w=e[3];const S=w,I=GI,T=qI,P=YI;let A;e[4]!==r||e[5]!==u.meridiem||e[6]!==u.minute||e[7]!==a?(A=J=>{const Se=J.replace(/\D/g,"").slice(0,2);k(Se),Se.length===2&&(r(a?P(I(Se),u.minute):Ca(df(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]=A):A=e[8];const N=A;let E;e[9]!==r||e[10]!==u.meridiem||e[11]!==u.minute||e[12]!==a?(E=()=>{const J=j.current;if(J!==null&&(k(null),J.length!==0)){if(a){r(P(I(J.padStart(2,"0")),u.minute));return}r(Ca(df(J.padStart(2,"0")),u.minute,u.meridiem))}},e[9]=r,e[10]=u.meridiem,e[11]=u.minute,e[12]=a,e[13]=E):E=e[13];const M=E;let O;e[14]!==r||e[15]!==u.hour12||e[16]!==u.hour24||e[17]!==u.meridiem||e[18]!==a?(O=J=>{const Se=J.replace(/\D/g,"").slice(0,2);S(Se),Se.length===2&&(r(a?P(u.hour24,zo(Se)):Ca(u.hour12,zo(Se),u.meridiem)),S(null))},e[14]=r,e[15]=u.hour12,e[16]=u.hour24,e[17]=u.meridiem,e[18]=a,e[19]=O):O=e[19];const V=O;let B;e[20]!==r||e[21]!==u.hour12||e[22]!==u.hour24||e[23]!==u.meridiem||e[24]!==a?(B=()=>{const J=y.current;J!==null&&(S(null),J.length!==0&&r(a?P(u.hour24,zo(J.padStart(2,"0"))):Ca(u.hour12,zo(J.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 F;e[26]!==r||e[27]!==u.hour12||e[28]!==u.hour24||e[29]!==u.meridiem||e[30]!==u.minute||e[31]!==a?(F=J=>r(a?P(T(u.hour24,J),u.minute):Ca(LI(u.hour12,J),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]=F):F=e[32];const _=F;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=J=>r(a?P(u.hour24,uf(u.minute,J)):Ca(u.hour12,uf(u.minute,J),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 Y;e[40]!==r||e[41]!==u.hour12||e[42]!==u.meridiem||e[43]!==u.minute?(Y=J=>{J!==u.meridiem&&r(Ca(u.hour12,u.minute,J))},e[40]=r,e[41]=u.hour12,e[42]=u.meridiem,e[43]=u.minute,e[44]=Y):Y=e[44];const Z=Y;let ae;e[45]!==M||e[46]!==_?(ae=J=>{if(J.key==="ArrowRight"){J.preventDefault(),M(),b.current?.focus();return}(J.key==="ArrowUp"||J.key==="ArrowDown")&&(J.preventDefault(),k(null),_(J.key==="ArrowUp"?1:-1))},e[45]=M,e[46]=_,e[47]=ae):ae=e[47];const re=ae;let me;e[48]!==$||e[49]!==L?(me=J=>{if(J.key==="ArrowLeft"&&(J.currentTarget.selectionStart??0)===0){J.preventDefault(),$(),f.current?.focus();return}(J.key==="ArrowUp"||J.key==="ArrowDown")&&(J.preventDefault(),S(null),L(J.key==="ArrowUp"?1:-1))},e[48]=$,e[49]=L,e[50]=me):me=e[50];const fe=me,H=a?"px-2":"pl-2 pr-1";let K;e[51]!==H?(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",H),e[51]=H,e[52]=K):K=e[52];const Q=g??(a?u.hour24:u.hour12);let W;e[53]!==N?(W=J=>N(J.target.value),e[53]=N,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 be;e[56]!==M||e[57]!==i||e[58]!==re||e[59]!==Q||e[60]!==W?(be=s.jsx("input",{ref:f,inputMode:"numeric",value:Q,onChange:W,onKeyDown:re,onFocus:de,onBlur:M,maxLength:2,"aria-label":i,className:"h-7 w-7 shrink-0 rounded-sm bg-transparent text-center font-mono text-sm tabular-nums text-foreground outline-none caret-transparent focus:bg-interactive-hover"}),e[56]=M,e[57]=i,e[58]=re,e[59]=Q,e[60]=W,e[61]=be):be=e[61];let we;e[62]===Symbol.for("react.memo_cache_sentinel")?(we=s.jsx("span",{className:"font-mono text-sm text-muted-foreground",children:":"}),e[62]=we):we=e[62];const te=x??u.minute;let ge;e[63]!==V?(ge=J=>V(J.target.value),e[63]=V,e[64]=ge):ge=e[64];let ue;e[65]===Symbol.for("react.memo_cache_sentinel")?(ue=()=>S(""),e[65]=ue):ue=e[65];let xe;e[66]!==$||e[67]!==l||e[68]!==fe||e[69]!==te||e[70]!==ge?(xe=s.jsx("input",{ref:b,inputMode:"numeric",value:te,onChange:ge,onKeyDown:fe,onFocus:ue,onBlur:$,maxLength:2,"aria-label":l,className:"h-7 w-7 shrink-0 rounded-sm bg-transparent text-center font-mono text-sm tabular-nums text-foreground outline-none caret-transparent focus:bg-interactive-hover"}),e[66]=$,e[67]=l,e[68]=fe,e[69]=te,e[70]=ge,e[71]=xe):xe=e[71];let ne;e[72]!==d||e[73]!==u.meridiem||e[74]!==c||e[75]!==p||e[76]!==Z||e[77]!==a?(ne=a?null:s.jsxs(is,{value:u.meridiem,onValueChange:J=>Z(J),children:[s.jsx(os,{"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(us,{})}),s.jsxs(ls,{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]=ne):ne=e[78];let pe;return e[79]!==K||e[80]!==be||e[81]!==xe||e[82]!==ne?(pe=s.jsxs("div",{className:K,children:[be,we,xe,ne]}),e[79]=K,e[80]=be,e[81]=xe,e[82]=ne,e[83]=pe):pe=e[83],pe},pf=t=>new Date(t.getFullYear(),t.getMonth(),1),zI=()=>{const t=new Date;return new Date(t.getFullYear(),t.getMonth(),t.getDate())},ff=(t,e)=>t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth()&&t.getDate()===e.getDate(),UI=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"]},hf=(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:UI(t),onceDate:typeof t.schedule.date=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(t.schedule.date)?t.schedule.date:of(),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:of(),onceTime:"09:00",weekdays:[1],timezone:n},execution:{prompt:"",providerID:e.providerID,modelID:e.modelID,variant:e.variant,agent:e.agent}}},WI=(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")},KI=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 HI(t){const{open:e,task:n,onOpenChange:r,onSave:a}=t,{t:i,locale:l}=ut(),c=yt(U=>U.loadProviders),d=yt(U=>U.loadAgents),p=yt(U=>U.providers),m=yt(U=>U.currentProviderId),u=yt(U=>U.currentModelId),f=yt(U=>U.currentVariant||""),b=yt(U=>U.currentAgentName||""),g=Re(U=>U.timeFormatPreference),v=Re(U=>U.weekStartPreference),x=Re(U=>U.isMobile),[h,j]=_e.useState(()=>hf(n,{providerID:m,modelID:u,variant:f,agent:b})),[y,C]=_e.useState(!1),[k,w]=_e.useState(!1),[S,I]=_e.useState(!1),[T,P]=_e.useState(""),[A,N]=_e.useState(!1),[E,M]=_e.useState(""),[O,V]=_e.useState(!1),[B,$]=_e.useState(""),[F,_]=_e.useState(()=>{const U=ol(n?.schedule?.date||"")||new Date;return new Date(U.getFullYear(),U.getMonth(),1)}),q=_e.useRef(null),L=_e.useRef(null),Y=_e.useRef(null),Z=_e.useRef(null),ae=_e.useRef(null),re=_e.useMemo(()=>_I(l),[l]),me=_e.useMemo(()=>$I(l),[l]),fe=_e.useMemo(()=>g==="24h"?!0:g==="12h"?!1:re,[g,re]),H=_e.useMemo(()=>v==="sunday"?0:v==="monday"?1:me,[v,me]),K=_e.useMemo(()=>{const U=BI(l);return VI(Rg.map(le=>({value:le,label:U[le]||""})),H)},[l,H]);_e.useEffect(()=>{e&&(c(),d())},[e,c,d]),_e.useEffect(()=>{if(!e)return;j(hf(n,{providerID:m,modelID:u,variant:f,agent:b}));const U=ol(n?.schedule?.date||"")||new Date;_(new Date(U.getFullYear(),U.getMonth(),1)),w(!1),N(!1),I(!1),M(""),P("")},[e,n,m,u,f,b]),_e.useEffect(()=>{if(!k)return;const U=le=>{q.current&&!q.current.contains(le.target)&&w(!1)};return document.addEventListener("mousedown",U),()=>{document.removeEventListener("mousedown",U)}},[k]);const Q=_e.useMemo(()=>{const le=p.find(Me=>Me.id===h.execution.providerID)?.models?.find(Me=>Me.id===h.execution.modelID);return le?.variants?Object.keys(le.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 be=_e.useCallback((U,le)=>{j(Me=>{const Oe=new Set(Me.schedule.weekdays);return le?Oe.add(U):Oe.delete(U),{...Me,schedule:{...Me.schedule,weekdays:Array.from(Oe).sort((Ae,z)=>Ae-z)}}})},[]),we=_e.useCallback((U,le)=>{j(Me=>{const Oe=Me.schedule.times.slice();return Oe[U]=le,{...Me,schedule:{...Me.schedule,times:Oe}}})},[]),te=_e.useCallback(U=>{j(le=>{const Me=le.schedule.times.filter((Oe,Ae)=>Ae!==U);return{...le,schedule:{...le.schedule,times:Me.length>0?Me:["09:00"]}}})},[]),ge=_e.useCallback(()=>{j(U=>({...U,schedule:{...U.schedule,times:[...U.schedule.times,"12:00"]}}))},[]),ue=_e.useMemo(()=>zI(),[]),xe=_e.useMemo(()=>pf(ue),[ue]),ne=_e.useMemo(()=>{const U=ol(h.schedule.onceDate);return U?ff(U,ue)?i("sessions.scheduledTasks.editor.date.today"):new Intl.DateTimeFormat(l,{weekday:"short"}).format(U):null},[h.schedule.onceDate,l,i,ue]),pe=_e.useMemo(()=>pf(F).getTime()<=xe.getTime(),[F,xe]),J=_e.useMemo(()=>K.map(U=>U.label),[K]),Se=_e.useCallback(U=>{j(le=>({...le,schedule:{...le.schedule,onceDate:U}}))},[]),he=_e.useCallback((U,le)=>{if(U.startsWith("/")){const z=U.indexOf(" "),De=U.indexOf(`
|
|
185
|
-
`),Xe=Math.min(z===-1?U.length:z,De===-1?U.length:De);if(le<=Xe&&z===-1){M(U.substring(1,Xe)),N(!0),I(!1),V(!1);return}}N(!1);const Me=U.substring(0,le),Oe=Me.lastIndexOf("#");if(Oe!==-1){const z=Oe>0?Me[Oe-1]:null,De=Me.substring(Oe+1);if((!z||/\s/.test(z))&&!De.includes(" ")&&!De.includes(`
|
|
186
|
-
`)){$(De),V(!0),I(!1);return}}V(!1);const Ae=Me.lastIndexOf("@");if(Ae!==-1){const z=Ae>0?Me[Ae-1]:null,De=Me.substring(Ae+1);(!z||/\s/.test(z))&&!De.includes(" ")&&!De.includes(`
|
|
187
|
-
`)?(P(De),I(!0)):I(!1);return}I(!1)},[]),Ie=_e.useCallback(U=>{j(le=>({...le,execution:{...le.execution,prompt:U}}))},[]),Pe=_e.useCallback(U=>{const le=h.execution.prompt,Oe=L.current?.selectionStart??le.length,z=le.substring(0,Oe).lastIndexOf("@"),De=U.relativePath&&U.relativePath.trim().length>0?U.relativePath.trim():U.path||U.name,Xe=z!==-1?z:Oe,st=`${le.substring(0,Xe)}@${De} ${le.substring(Oe)}`,tt=Xe+De.length+2;Ie(st),I(!1),P(""),requestAnimationFrame(()=>{const Ue=L.current;Ue&&(Ue.selectionStart=tt,Ue.selectionEnd=tt,Ue.focus()),he(st,tt)})},[h.execution.prompt,Ie,he]),Ce=_e.useCallback(U=>{const le=h.execution.prompt,Oe=L.current?.selectionStart??le.length,z=le.substring(0,Oe).lastIndexOf("@"),De=z!==-1?z:Oe,Xe=`${le.substring(0,De)}@${U} ${le.substring(Oe)}`,st=De+U.length+2;Ie(Xe),I(!1),P(""),requestAnimationFrame(()=>{const tt=L.current;tt&&(tt.selectionStart=st,tt.selectionEnd=st,tt.focus()),he(Xe,st)})},[h.execution.prompt,Ie,he]),X=_e.useCallback(U=>{const le=`/${U.name} `;Ie(le),N(!1),M(""),V(!1),requestAnimationFrame(()=>{const Me=L.current;Me&&(Me.focus(),Me.selectionStart=Me.value.length,Me.selectionEnd=Me.value.length),he(le,le.length)})},[Ie,he]),ie=_e.useCallback((U,le)=>{const Me=h.execution.prompt,Ae=L.current?.selectionStart??Me.length,De=Me.substring(0,Ae).lastIndexOf("#"),Xe=De!==-1?De:Ae,st=`${Me.substring(0,Xe)}#${le} ${Me.substring(Ae)}`,tt=Xe+le.length+2;Ie(st),V(!1),$(""),requestAnimationFrame(()=>{const Ue=L.current;Ue&&(Ue.selectionStart=tt,Ue.selectionEnd=tt,Ue.focus()),he(st,tt)})},[h.execution.prompt,Ie,he]),Ne=_e.useCallback(U=>{if(A&&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}S&&Y.current&&(U.key==="Enter"||U.key==="ArrowUp"||U.key==="ArrowDown"||U.key==="Escape"||U.key==="Tab")&&(U.preventDefault(),Y.current.handleKeyDown(U.key)),O&&ae.current&&(U.key==="Enter"||U.key==="ArrowUp"||U.key==="ArrowDown"||U.key==="Escape"||U.key==="Tab")&&(U.preventDefault(),ae.current.handleKeyDown(U.key))},[A,S,O]),oe=_e.useCallback(async()=>{const U=WI(h,i);if(U){G.error(U);return}const le=KI(h.schedule.times),Me={...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:le,...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(Me),r(!1)}catch(Oe){G.error(Oe instanceof Error?Oe.message:i("sessions.scheduledTasks.editor.toast.saveFailed"))}finally{C(!1)}},[h,r,a,i]),ke=_e.useId(),Te=_e.useCallback(()=>typeof document>"u"?!1:!!document.querySelector('[data-slot="dropdown-menu-content"], [data-slot="select-content"]'),[]),Be=i(n?"sessions.scheduledTasks.editor.title.edit":"sessions.scheduledTasks.editor.title.new"),je=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(kr,{htmlFor:"sched-name",required:!0,children:i("sessions.scheduledTasks.editor.taskName.label")}),s.jsx(Bt,{id:"sched-name",value:h.name,onChange:U=>j(le=>({...le,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(kr,{children:i("sessions.scheduledTasks.editor.scheduleType.label")}),s.jsxs(is,{value:h.schedule.kind,onValueChange:U=>{j(le=>({...le,schedule:{...le.schedule,kind:U}}))},children:[s.jsx(os,{className:"w-fit max-w-full",children:s.jsx(us,{children:U=>i(U==="daily"?"sessions.scheduledTasks.editor.scheduleType.daily":U==="weekly"?"sessions.scheduledTasks.editor.scheduleType.weekly":"sessions.scheduledTasks.editor.scheduleType.once")})}),s.jsxs(ls,{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(kr,{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(D,{name:"calendar",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:RI(h.schedule.onceDate,i("sessions.scheduledTasks.editor.date.placeholder"),l)})]}),s.jsx(D,{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=>cf(U,-1)),"aria-label":i("sessions.scheduledTasks.editor.date.previousMonth"),disabled:pe,children:s.jsx(D,{name:"arrow-left-s",className:"h-4 w-4"})}),s.jsx("div",{className:"typography-ui-label text-foreground",children:new Intl.DateTimeFormat(l,{month:"long",year:"numeric"}).format(F)}),s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-interactive-hover",onClick:()=>_(U=>cf(U,1)),"aria-label":i("sessions.scheduledTasks.editor.date.nextMonth"),children:s.jsx(D,{name:"arrow-right-s",className:"h-4 w-4"})})]}),s.jsx("div",{className:"mb-1 grid grid-cols-7 gap-1 px-1",children:J.map((U,le)=>s.jsx("div",{className:"py-1 text-center typography-micro text-muted-foreground",children:U},`${U}-${le}`))}),s.jsx("div",{className:"grid grid-cols-7 gap-1",children:FI(F,H).map(({date:U,inCurrentMonth:le})=>{const Me=lf(U),Oe=Me===h.schedule.onceDate,Ae=ff(U,ue),z=U.getTime()<ue.getTime(),De=Oe?"bg-interactive-selection text-interactive-selection-foreground":z?"text-muted-foreground/40":le?"text-foreground hover:bg-interactive-hover":"text-muted-foreground/60 hover:bg-interactive-hover";return s.jsx("button",{type:"button",onClick:()=>{z||(Se(Me),w(!1))},disabled:z,className:["h-8 rounded-md typography-ui-label",De,Ae&&!Oe?"ring-1 ring-inset ring-interactive-focusRing bg-interactive-hover/50":"",z?"cursor-not-allowed opacity-45":""].join(" "),children:U.getDate()},Me)})}),s.jsxs("div",{className:"mt-2 flex items-center justify-between border-t border-border pt-2",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:ne||""}),s.jsx(ve,{type:"button",size:"xs",variant:"ghost",onClick:()=>{Se(lf(ue)),_(new Date(ue.getFullYear(),ue.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(kr,{children:i("sessions.scheduledTasks.editor.time.label")}),s.jsx(mf,{value:h.schedule.onceTime,use24Hour:fe,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(le=>({...le,schedule:{...le.schedule,onceTime:U}}))}),s.jsxs("div",{className:"mt-2 flex flex-col gap-1",children:[s.jsx(kr,{children:i("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(is,{value:h.schedule.timezone,onValueChange:U=>{j(le=>({...le,schedule:{...le.schedule,timezone:U}}))},children:[s.jsx(os,{className:"w-fit max-w-full",children:s.jsx(us,{})}),s.jsx(ls,{children:af.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(kr,{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 le=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",le?"text-foreground":"text-muted-foreground"].join(" "),children:[s.jsx(xs,{checked:le,onChange:Me=>be(U.value,Me),ariaLabel:U.label}),s.jsx("button",{type:"button",onClick:()=>be(U.value,!le),className:"group-hover:text-foreground",children:U.label})]},U.value)})})]}):null,s.jsxs("div",{className:"flex flex-col gap-2",children:[s.jsx(kr,{children:i("sessions.scheduledTasks.editor.times.label")}),s.jsx("div",{className:"flex flex-col gap-2",children:h.schedule.times.map((U,le)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(mf,{value:U,use24Hour:fe,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:Me=>we(le,Me)}),h.schedule.times.length>1?s.jsx(ve,{type:"button",size:"icon",variant:"ghost",onClick:()=>te(le),"aria-label":i("sessions.scheduledTasks.editor.times.removeAria"),children:s.jsx(D,{name:"close",className:"h-4 w-4"})}):null]},le))}),s.jsx("div",{children:s.jsxs(ve,{type:"button",size:"sm",variant:"outline",onClick:ge,children:[s.jsx(D,{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(kr,{children:i("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(is,{value:h.schedule.timezone,onValueChange:U=>{j(le=>({...le,schedule:{...le.schedule,timezone:U}}))},children:[s.jsx(os,{className:"w-fit max-w-full",children:s.jsx(us,{})}),s.jsx(ls,{children:af.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(kr,{required:!0,children:i("sessions.scheduledTasks.editor.model.label")}),s.jsx(wo,{providerId:h.execution.providerID,modelId:h.execution.modelID,onChange:(U,le)=>{j(Me=>({...Me,execution:{...Me.execution,providerID:U,modelID:le,variant:""}}))}})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(kr,{children:i("sessions.scheduledTasks.editor.thinkingLevel.label")}),s.jsxs(is,{value:de,disabled:!W,onValueChange:U=>{j(le=>({...le,execution:{...le.execution,variant:U==="__default"?"":U}}))},children:[s.jsx(os,{className:"w-fit max-w-full",children:s.jsx(us,{children:U=>U==="__default"?i("sessions.scheduledTasks.editor.thinkingLevel.default"):U})}),s.jsxs(ls,{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(kr,{children:i("sessions.scheduledTasks.editor.agent.label")}),s.jsx(Kl,{agentName:h.execution.agent,filter:U=>Zf(U.mode),onChange:U=>j(le=>({...le,execution:{...le.execution,agent:U}}))})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(kr,{htmlFor:"sched-prompt",required:!0,children:i("sessions.scheduledTasks.editor.prompt.label")}),s.jsxs("div",{className:"relative",children:[s.jsx(jn,{id:"sched-prompt",ref:L,value:h.execution.prompt,onChange:U=>{const le=U.target.value;Ie(le);const Me=U.target.selectionStart??le.length;he(le,Me)},onKeyDown:Ne,rows:8,placeholder:i("sessions.scheduledTasks.editor.prompt.placeholder"),className:"typography-meta min-h-[120px] max-h-[300px] resize-none overflow-y-auto"}),A?s.jsx(fh,{ref:Z,searchQuery:E,onCommandSelect:X,onClose:()=>N(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,S?s.jsx(hh,{ref:Y,searchQuery:T,onFileSelect:Pe,onAgentSelect:Ce,onClose:()=>I(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,O?s.jsx(gh,{ref:ae,searchQuery:B,onSnippetSelect:ie,onClose:()=>V(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null]})]})]}),R=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(xs,{checked:h.enabled,onChange:U=>j(le=>({...le,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(ve,{type:"button",variant:"ghost",size:"sm",onClick:()=>r(!1),disabled:y,children:i("sessions.scheduledTasks.editor.actions.cancel")}),s.jsx(ve,{type:"button",size:"sm",onClick:oe,disabled:y,children:i(y?"sessions.scheduledTasks.editor.actions.saving":"sessions.scheduledTasks.editor.actions.save")})]})]});return x?s.jsx(Br,{open:e,title:Be,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:Be}),U]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:je})]}),footer:R,children:ee}):s.jsx(ps,{open:e,onOpenChange:U=>{!U&&Te()||r(U)},children:s.jsxs(ms,{"aria-describedby":ke,className:"!max-w-[720px] w-[90vw] h-[680px] max-h-[85vh] gap-0 p-0 overflow-hidden",children:[s.jsx(Ns,{id:ke,className:"sr-only",children:je}),s.jsx("header",{className:"shrink-0 px-4 sm:px-6 pt-5 pb-3",children:s.jsxs("div",{className:"mx-auto w-full max-w-2xl",children:[s.jsx(fs,{className:"typography-ui-label font-medium text-foreground",children:Be}),s.jsx("p",{className:"typography-meta mt-0.5 text-muted-foreground",children:je})]})}),s.jsx(go,{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:R})})]})})}function GI(t){return Ci(t,{min:0,max:23})}function qI(t,e){return Ci(String(Number.parseInt(t,10)+e),{min:0,max:23,loop:!0})}function YI(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 QI=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))},JI=(t,e)=>{const n=QI(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||""})},XI=t=>!t||!Number.isFinite(t)?"":new Date(t).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"}),gf=(t,e)=>{if(!t||!Number.isFinite(t))return"";const n=t-Date.now(),r=Math.abs(n),a=6e4,i=60*a,l=24*i,c=n>=0;if(r<a)return e(c?"sessions.scheduledTasks.dialog.relativeTime.inLessThanOneMinute":"sessions.scheduledTasks.dialog.relativeTime.justNow");if(r<i){const u=Math.round(r/a);return c?e("sessions.scheduledTasks.dialog.relativeTime.inMinutes",{count:u}):e("sessions.scheduledTasks.dialog.relativeTime.minutesAgo",{count:u})}if(r<l){const u=Math.floor(r/i),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/l),p=Math.round(r%l/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})},ZI={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"}},e6=t=>({color:`var(--status-${t})`,backgroundColor:`var(--status-${t}-background)`,borderColor:`var(--status-${t}-border)`});function t6(){const{t}=ut(),e=Re(M=>M.isScheduledTasksDialogOpen),n=Re(M=>M.setScheduledTasksDialogOpen),r=Re(M=>M.isMobile),a=Cs(M=>M.projects),i=Cs(M=>M.getActiveProject()),l=Ks(M=>M.homeDirectory),{currentTheme:c}=vr(),[d,p]=_e.useState(""),[m,u]=_e.useState([]),[f,b]=_e.useState(!0),[g,v]=_e.useState(!1),[x,h]=_e.useState(null),[j,y]=_e.useState(null),C=_e.useMemo(()=>a.find(M=>M.id===d)||null,[a,d]),k=_e.useCallback(M=>{const O=M.label?.trim()||Ua(M.path,l||void 0),V=yo({id:M.id,iconImage:M.iconImage??null},{themeVariant:c.metadata.variant,iconColor:c.colors.surface.foreground}),B=M.icon?zl[M.icon]:null,$=M.color?vo[M.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:M.iconBackground?{backgroundColor:M.iconBackground}:void 0,children:s.jsx("img",{src:V,alt:"",className:"h-full w-full object-contain",draggable:!1})}):B?s.jsx(D,{name:B,className:"h-3.5 w-3.5 shrink-0",style:$?{color:$}:void 0}):s.jsx(D,{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:O})]})},[l,c.metadata.variant,c.colors.surface.foreground]),w=_e.useCallback(async(M,O)=>{if(!M){u([]);return}O?.silent||b(!0);try{const V=await TI(M);V.sort((B,$)=>{if(B.enabled!==$.enabled)return B.enabled?-1:1;const F=B.name.localeCompare($.name);return F!==0?F:(B.state?.nextRunAt||Number.MAX_SAFE_INTEGER)-($.state?.nextRunAt||Number.MAX_SAFE_INTEGER)}),u(V)}catch(V){G.error(V instanceof Error?V.message:t("sessions.scheduledTasks.dialog.toast.loadFailed")),O?.silent||u([])}finally{O?.silent||b(!1)}},[t]);_e.useEffect(()=>{if(!e)return;const M=i?.id||a[0]?.id||"";p(M),M?w(M):(u([]),b(!1))},[e,i,a,w]),_e.useEffect(()=>{if(!e)return;let M=null;const O=Eg(V=>{V.type==="scheduled-task-ran"&&V.projectId===d&&(M&&clearTimeout(M),M=setTimeout(()=>{w(d,{silent:!0})},400))});return()=>{M&&clearTimeout(M),O()}},[e,d,w]);const S=_e.useCallback(async M=>{if(!d)throw new Error(t("sessions.scheduledTasks.dialog.error.chooseProjectFirst"));await rf(d,M),await w(d),G.success(t("sessions.scheduledTasks.dialog.toast.saved"))},[d,w,t]),I=_e.useCallback(async(M,O)=>{if(d){y(M.id),u(V=>V.map(B=>B.id===M.id?{...B,enabled:O}:B));try{await rf(d,{...M,enabled:O}),await w(d,{silent:!0})}catch(V){G.error(V instanceof Error?V.message:t("sessions.scheduledTasks.dialog.toast.updateFailed")),await w(d,{silent:!0})}finally{y(null)}}},[d,w,t]),T=_e.useCallback(async M=>{if(!(!d||!window.confirm(t("sessions.scheduledTasks.dialog.confirm.deleteTask",{taskName:M.name})))){y(M.id);try{await MI(d,M.id),await w(d,{silent:!0}),G.success(t("sessions.scheduledTasks.dialog.toast.deleted"))}catch(V){G.error(V instanceof Error?V.message:t("sessions.scheduledTasks.dialog.toast.deleteFailed"))}finally{y(null)}}},[d,w,t]),P=_e.useCallback(async M=>{if(d){y(M.id);try{await EI(d,M.id),await Promise.all([w(d,{silent:!0}),ed()]),G.success(t("sessions.scheduledTasks.dialog.toast.started"))}catch(O){G.error(O instanceof Error?O.message:t("sessions.scheduledTasks.dialog.toast.runFailed"))}finally{y(null)}}},[d,w,t]),A=s.jsxs("div",{className:"flex flex-col items-start gap-1",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("sessions.scheduledTasks.dialog.project.label")}),s.jsxs(is,{value:d||"__none",onValueChange:M=>{const O=M==="__none"?"":M;p(O),O?w(O):u([])},children:[s.jsx(os,{className:r?"w-full":void 0,children:C?s.jsx(us,{children:k(C)}):s.jsx(us,{placeholder:t("sessions.scheduledTasks.dialog.project.placeholder")})}),s.jsxs(ls,{children:[a.length===0?s.jsx(Mt,{value:"__none",children:t("sessions.scheduledTasks.dialog.project.empty")}):null,a.map(M=>s.jsx(Mt,{value:M.id,children:k(M)},M.id))]})]})]}),N=()=>{h(null),v(!0)},E=s.jsxs("div",{className:"space-y-4",children:[r?A:s.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[A,s.jsxs(ve,{onClick:N,disabled:!d,children:[s.jsx(D,{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(D,{name:"loader-4",className:"h-4 w-4 animate-spin"})," ",t("sessions.scheduledTasks.dialog.loading")]}):m.length===0?s.jsx("div",{className:"rounded-lg border border-dashed border-border p-4 typography-meta text-muted-foreground",children:t(d?"sessions.scheduledTasks.dialog.empty.noTasks":"sessions.scheduledTasks.dialog.empty.selectProject")}):s.jsx("div",{className:"space-y-2.5",children:m.map(M=>{const O=j===M.id,V=M.state?.lastStatus||"idle",B=ZI[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"),F=M.state?.nextRunAt,_=M.state?.lastRunAt;return s.jsxs("div",{className:ye("rounded-lg border border-border p-4 transition-opacity",!M.enabled&&"opacity-60"),children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-header truncate font-semibold text-foreground",children:M.name}),s.jsx("div",{className:"typography-micro truncate text-muted-foreground",children:JI(M,t)})]}),s.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-x-5 gap-y-1 typography-micro text-muted-foreground",children:[s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(D,{name:"timer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-medium text-foreground",children:t("sessions.scheduledTasks.dialog.nextRun.label")}),F?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"text-foreground",children:gf(F,t)}),s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:XI(F)})]}):s.jsx("span",{children:"—"})]}),s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(D,{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(D,{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(D,{name:B.Icon,className:"h-3.5 w-3.5"}),$]}):null,s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:gf(_,t)})]}):s.jsx("span",{children:t("sessions.scheduledTasks.dialog.lastRun.never")})]})]}),M.state?.lastError?s.jsxs("div",{className:"mt-3 flex items-start gap-2 rounded-md border p-2 typography-micro",style:e6("error"),children:[s.jsx(D,{name:"error-warning",className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"min-w-0 break-words",children:M.state.lastError})]}):null,s.jsxs("div",{className:"mt-4 flex flex-wrap items-center justify-between gap-2",children:[s.jsxs("label",{className:ye("inline-flex cursor-pointer items-center gap-2 typography-micro font-medium",M.enabled?"text-foreground":"text-muted-foreground",O&&"cursor-not-allowed opacity-50"),children:[s.jsx(xs,{checked:M.enabled,onChange:q=>{I(M,q)},ariaLabel:M.enabled?t("sessions.scheduledTasks.dialog.taskToggle.pauseAria",{taskName:M.name}):t("sessions.scheduledTasks.dialog.taskToggle.enableAria",{taskName:M.name}),disabled:O}),M.enabled?t("sessions.scheduledTasks.dialog.taskToggle.enabled"):t("sessions.scheduledTasks.dialog.taskToggle.paused")]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[s.jsxs(ve,{variant:"outline",size:"sm",onClick:()=>{P(M)},disabled:O,children:[s.jsx(D,{name:"play",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.runNow")]}),s.jsxs(ve,{variant:"outline",size:"sm",onClick:()=>{h(M),v(!0)},disabled:O,"aria-label":t("sessions.scheduledTasks.dialog.actions.editAria",{taskName:M.name}),children:[s.jsx(D,{name:"edit-2",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.edit")]}),s.jsx(ve,{variant:"destructive",size:"sm",onClick:()=>{T(M)},disabled:O,"aria-label":t("sessions.scheduledTasks.dialog.actions.deleteAria",{taskName:M.name}),children:s.jsx(D,{name:"delete-bin",className:"h-4 w-4"})})]})]})]},M.id)})})})]});return s.jsxs(s.Fragment,{children:[r?s.jsx(Br,{open:e,title:t("sessions.scheduledTasks.dialog.title"),onClose:()=>n(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:M=>s.jsxs("div",{className:"flex flex-col gap-1 border-b border-border/40 px-3 py-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("h2",{className:"typography-ui-label font-semibold text-foreground",children:t("sessions.scheduledTasks.dialog.title")}),M]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("sessions.scheduledTasks.dialog.description")})]}),footer:s.jsxs(ve,{className:"w-full",onClick:N,disabled:!d,children:[s.jsx(D,{name:"add",className:"mr-1 h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.newTask")]}),children:E}):s.jsx(ps,{open:e,onOpenChange:n,children:s.jsxs(ms,{className:"max-h-[85vh] max-w-2xl overflow-y-auto",children:[s.jsxs(gs,{children:[s.jsx(fs,{children:t("sessions.scheduledTasks.dialog.title")}),s.jsx(Ns,{children:t("sessions.scheduledTasks.dialog.description")})]}),E]})}),s.jsx(HI,{open:g,task:x,onOpenChange:v,onSave:S})]})}const s6=(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=>io(d,t.normalizedPath,r)))(e.archivedSessions),l=e.sessions.filter(c=>c.time?.archived||bs(c.directory??null)?!1:io(c,t.normalizedPath,r));return vi([...i,...l])},n6=t=>{const e=ot.c(12),{normalizedProjects:n,sessions:r,archivedSessions:a,availableWorktreesByProject:i,isVSCode:l,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]!==l||e[8]!==n||e[9]!==r?(f=()=>{c||n.forEach(g=>{const v=Wd(g.normalizedPath),x=s6(g,{sessions:r,archivedSessions:a,availableWorktreesByProject:i,isVSCode:l}),h=new Set(x.map(r6)),j=d[v]??[],y=new Map(j.map(a6));x.forEach(C=>{const k=jy(C,g.normalizedPath),w=k.toLowerCase();let S=y.get(w);S||(S=p(v,k),y.set(w,S)),S.sessionIds.includes(C.id)||m(v,S.id,C.id)}),u(v,h)})},b=[n,r,a,i,l,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]=l,e[8]=n,e[9]=r,e[10]=f,e[11]=b):(f=e[10],b=e[11]),o.useEffect(f,b)};function r6(t){return t.id}function a6(t){return[t.name.toLowerCase(),t]}const i6=t=>{const e=ot.c(41),{normalizedProjects:n,getSessionsForProject:r,getArchivedSessionsForProject:a,availableWorktreesByProject:i,projectRepoStatus:l,projectRootBranches:c,lastRepoStatus:d,buildGroupedSessions:p,hasSessionSearchQuery:m,normalizedSessionSearchQuery:u,filterSessionNodesForSearch:f,buildGroupSearchText:b,foldersMap:g}=t;let v;if(e[0]!==i||e[1]!==p||e[2]!==a||e[3]!==r||e[4]!==d||e[5]!==n||e[6]!==l||e[7]!==c){let P;e[9]!==i||e[10]!==p||e[11]!==a||e[12]!==r||e[13]!==d||e[14]!==l||e[15]!==c?(P=A=>{const N=vi([...r(A),...a(A)]),E=i.get(A.normalizedPath)??[],M=l.has(A.id)?!!l.get(A.id):d,O=p(N,A.normalizedPath,E,c.get(A.id)??null,M);return{project:A,groups:O}},e[9]=i,e[10]=p,e[11]=a,e[12]=r,e[13]=d,e[14]=l,e[15]=c,e[16]=P):P=e[16],v=n.map(P),e[0]=i,e[1]=p,e[2]=a,e[3]=r,e[4]=d,e[5]=n,e[6]=l,e[7]=c,e[8]=v}else v=e[8];const x=v,h=x;let j;if(e[17]!==b||e[18]!==f||e[19]!==g||e[20]!==m||e[21]!==u||e[22]!==h){e:{const P=new WeakMap;if(!m){j=P;break e}const A=N=>N.reduce((E,M)=>E+1+A(M.children),0);h.forEach(N=>{N.groups.forEach(E=>{const M=f(E.sessions,u),O=A(M),V=b(E).includes(u),B=bs(E.directory??null),F=(B?g[B]??[]:[]).filter(_=>_.name.toLowerCase().includes(u)).length;P.set(E,{filteredNodes:M,matchedSessionCount:O,folderNameMatchCount:F,groupMatches:V,hasMatch:V||O>0||F>0})})}),j=P}e[17]=b,e[18]=f,e[19]=g,e[20]=m,e[21]=u,e[22]=h,e[23]=j}else j=e[23];const y=j;let C;e:{if(!m){C=h;break e}let P;if(e[24]!==y||e[25]!==h){let A;e[27]!==y?(A=N=>({...N,groups:N.groups.filter(E=>y.get(E)?.hasMatch===!0)}),e[27]=y,e[28]=A):A=e[28],P=h.map(A).filter(o6),e[24]=y,e[25]=h,e[26]=P}else P=e[26];C=P}const k=C,w=m?k:h;let S;e:{if(!m){S=0;break e}let P;if(e[29]!==y||e[30]!==w){let A;e[32]!==y?(A=(N,E)=>N+E.groups.reduce((M,O)=>{const V=y.get(O);if(!V)return M;const B=V.folderNameMatchCount+(V.groupMatches?1:0);return M+V.matchedSessionCount+B},0),e[32]=y,e[33]=A):A=e[33],P=w.reduce(A,0),e[29]=y,e[30]=w,e[31]=P}else P=e[31];S=P}const I=S;let T;return e[34]!==y||e[35]!==x||e[36]!==I||e[37]!==k||e[38]!==w||e[39]!==h?(T={projectSections:x,visibleProjectSections:h,groupSearchDataByGroup:y,searchableProjectSections:k,sectionsForRender:w,searchMatchCount:I},e[34]=y,e[35]=x,e[36]=I,e[37]=k,e[38]=w,e[39]=h,e[40]=T):T=e[40],T};function o6(t){return t.groups.length>0}const l6=t=>{const e=ot.c(34),{projectSections:n,activeProjectId:r,activeSessionByProject:a,setActiveSessionByProject:i,currentSessionId:l,handleSessionSelect:c,newSessionDraftOpen:d,mobileVariant:p,openNewSessionDraft:m,setActiveMainTab:u,setSessionSwitcherOpen:f,sessions:b,worktreeMetadata:g}=t;let v,x;if(e[0]!==n){x=new Map,v=new Map;const A=(N,E,M,O)=>{x.has(N)||x.set(N,new Map);const V=x.get(N);O.forEach(B=>{const $=bs(B.worktree?.path??B.session.directory??M??E);V.set(B.session.id,{directory:$}),v.has(N)||v.set(N,{id:B.session.id,directory:$}),B.children.length>0&&A(N,E,$,B.children)})};n.forEach(N=>{N.groups.forEach(E=>{A(N.project.id,N.project.normalizedPath,E.directory,E.sessions)})}),e[0]=n,e[1]=v,e[2]=x}else v=e[1],x=e[2];let h;e[3]!==v||e[4]!==x?(h={metaByProject:x,firstSessionByProject:v},e[3]=v,e[4]=x,e[5]=h):h=e[5];const j=h,y=o.useRef(null);let C,k;e[6]!==r||e[7]!==a||e[8]!==l||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||y.current===r)return;const A=n.find($=>$.project.id===r);if(!A)return;y.current=r;const N=j.metaByProject.get(r);if(l&&N&&N.has(l)){i($=>{if($.get(r)===l)return $;const F=new Map($);return F.set(r,l),F});return}if(!N||N.size===0){u("chat"),p&&f(!1),m({directoryOverride:A.project.normalizedPath});return}const E=a.get(r),M=E&&N.has(E)?E:null,O=j.firstSessionByProject.get(r)?.id??null,V=M??O;if(!V||V===l)return;const B=N.get(V)?.directory??null;c(V,B,!1,r)},k=[r,a,l,c,d,p,m,n,j,u,f,i],e[6]=r,e[7]=a,e[8]=l,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]),o.useLayoutEffect(C,k);let w,S;e[20]!==r||e[21]!==l||e[22]!==j||e[23]!==i?(w=()=>{if(!r||!l)return;const A=j.metaByProject.get(r);!A||!A.has(l)||i(N=>{if(N.get(r)===l)return N;const E=new Map(N);return E.set(r,l),E})},S=[r,l,j,i],e[20]=r,e[21]=l,e[22]=j,e[23]=i,e[24]=w,e[25]=S):(w=e[24],S=e[25]),o.useEffect(w,S);let I;if(e[26]!==l||e[27]!==b||e[28]!==g){e:{if(!l){I=null;break e}const A=g.get(l)?.path;if(A){I=bs(A)??A;break e}let N;e[30]!==l?(N=M=>M.id===l,e[30]=l,e[31]=N):N=e[31];const E=b.find(N);if(!E){I=null;break e}I=bs(E.directory??null)}e[26]=l,e[27]=b,e[28]=g,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},c6=t=>{const e=ot.c(4);let n;e[0]!==t?(n=(i,l)=>{const c=t.get(i);if(!c||c.length===0)return l;const d=new Map(l.map(d6)),p=[];return c.forEach(m=>{const u=d.get(m);u&&(p.push(u),d.delete(m))}),l.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 d6(t){return[t.id,t]}const Uo=t=>!!t.time?.archived,u6=t=>{const{t:e}=ut(),n=o.useCallback(l=>[l.label,l.branch??"",l.description??"",l.directory??""].join(" ").toLowerCase(),[]),r=o.useCallback(l=>{const c=bs(l.directory??null)??"";return`${(l.title||e("sessions.sidebar.session.untitled")).trim()} ${c}`.toLowerCase()},[e]),a=o.useCallback((l,c)=>c?l.flatMap(d=>{if(r(d.session).includes(c))return[d];const m=a(d.children,c);return m.length===0?[]:[{...d,children:m}]}):l,[r]),i=o.useCallback((l,c,d,p,m)=>{const u=bs(c??null),f=vi(l).sort((A,N)=>di(A,N,t.pinnedSessionIds)),b=new Map(f.map(A=>[A.id,A])),g=new Map;f.forEach(A=>{const N=A.parentID;if(!N)return;const E=b.get(N);if(!E||Uo(E)!==Uo(A))return;const M=g.get(N)??[];M.push(A),g.set(N,M)}),g.forEach(A=>A.sort((N,E)=>di(N,E,t.pinnedSessionIds)));const v=new Map;d.forEach(A=>{if(A.path){const N=bs(A.path)??A.path;v.set(N,A)}});const x=A=>{const N=bs(A.directory??null),E=t.worktreeMetadata.get(A.id)??null;if(E)return E;if(N){const M=v.get(N)??null;if(M&&N!==u)return M}return null},h=A=>{const N=g.get(A.id)??[];return{session:A,children:N.map(E=>h(E)),worktree:x(A)}},j=f.filter(A=>{const N=A.parentID;if(!N)return!0;const E=b.get(N);return E?Uo(E)!==Uo(A):!0}),y=new Map,C="__archived__",k=A=>{if(A.time?.archived)return C;const N=bs(t.worktreeMetadata.get(A.id)?.path??null),E=bs(A.directory??null);if(!N&&!E)return C;const M=bs(A.project?.worktree??null),O=N??E??M;return O?O!==u&&v.has(O)?O:O===u?u??"__project_root__":C:C};j.forEach(A=>{const N=h(A),E=k(A);y.has(E)||y.set(E,[]),y.get(E)?.push(N)});const w=u??"__project_root__",S=[{id:"root",label:m&&p&&p!=="HEAD"?e("sessions.sidebar.grouping.projectRootWithBranch",{branch:p}):e("sessions.sidebar.grouping.projectRoot"),branch:p??null,description:u?ao(u,t.homeDirectory):null,isMain:!0,isArchivedBucket:!1,worktree:null,directory:u,folderScopeKey:u,sessions:y.get(w)??[]}],I=new Map;d.forEach(A=>{const N=bs(A.path)??A.path,E=y.get(N)??[],M=E.length>0,O=E.reduce((V,B)=>{const $=Number(B.session.time?.updated??B.session.time?.created??0);return Number.isFinite($)?Math.max(V,$):V},0);I.set(N,{hasActiveSession:M,lastUpdatedAt:O})}),[...d].sort((A,N)=>{const E=bs(A.path)??A.path,M=bs(N.path)??N.path,O=I.get(E)??{hasActiveSession:!1,lastUpdatedAt:0},V=I.get(M)??{hasActiveSession:!1,lastUpdatedAt:0};if(O.hasActiveSession!==V.hasActiveSession)return O.hasActiveSession?-1:1;if(O.hasActiveSession&&V.hasActiveSession)return V.lastUpdatedAt-O.lastUpdatedAt;const B=(A.label||A.branch||A.name||A.path||"").toLowerCase(),$=(N.label||N.branch||N.name||N.path||"").toLowerCase();return B.localeCompare($)}).forEach(A=>{const N=bs(A.path)??A.path,E=t.gitBranches.get(N)?.trim()||null,M=A.branch?.trim()||null,V=!!(E&&M&&A.label&&Vu(A.label)===Vu(M))?E:A.label||A.name||Ua(N,t.homeDirectory)||N;S.push({id:`worktree:${N}`,label:V,branch:E||M,description:ao(N,t.homeDirectory),isMain:!1,isArchivedBucket:!1,worktree:A,directory:N,folderScopeKey:N,sessions:y.get(N)??[]})});const P=y.get(C)??[];return P.length>0&&S.push({id:"archived",label:e("sessions.sidebar.grouping.archived"),branch:null,description:e("sessions.sidebar.grouping.archivedDescription"),isMain:!1,isArchivedBucket:!0,worktree:null,directory:null,folderScopeKey:!t.isVSCode&&u?Wd(u):null,sessions:P}),S},[t.homeDirectory,t.worktreeMetadata,t.pinnedSessionIds,t.gitBranches,t.isVSCode,e]);return{buildGroupSearchText:n,buildSessionSearchText:r,filterSessionNodesForSearch:a,buildGroupedSessions:i}},m6=t=>{const e=ot.c(9),{isSessionSearchOpen:n,setIsSessionSearchOpen:r,sessionSearchInputRef:a,sessionSearchContainerRef:i}=t;let l,c;e[0]!==n||e[1]!==a?(l=()=>{if(!n||typeof window>"u")return;const m=window.requestAnimationFrame(()=>{a.current?.focus(),a.current?.select()});return()=>window.cancelAnimationFrame(m)},c=[n,a],e[0]=n,e[1]=a,e[2]=l,e[3]=c):(l=e[2],c=e[3]),o.useEffect(l,c);let d,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]),o.useEffect(d,p)},p6=t=>{const e=ot.c(42),{t:n}=ut(),[r,a]=o.useState(null),i=o.useRef(null);let l,c;e[0]===Symbol.for("react.memo_cache_sentinel")?(l=()=>()=>{i.current&&clearTimeout(i.current)},c=[],e[0]=l,e[1]=c):(l=e[0],c=e[1]),o.useEffect(l,c);let d;e[2]!==t?(d=(V,B,$,F)=>{if($)return;const _=()=>{!t.isSessionSearchOpen&&t.sessionSearchQuery.length===0||(t.setSessionSearchQuery(""),t.setIsSessionSearchOpen(!1))};if(F&&F!==t.activeProjectId&&t.setActiveProjectIdOnly(F),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 g;e[8]!==t?(g=()=>{t.setEditingId(null),t.setEditTitle("")},e[8]=t,e[9]=g):g=e[9];const v=g;let x;e[10]!==t||e[11]!==n?(x=async V=>{const B=await t.shareSession(V.id);B&&B.share?.url?G.success(n("sessions.sidebar.session.share.successTitle"),{description:n("sessions.sidebar.session.share.successDescription")}):G.error(n("sessions.sidebar.session.share.error"))},e[10]=t,e[11]=n,e[12]=x):x=e[12];const h=x;let j;e[13]!==n?(j=(V,B)=>{Rn(V).then($=>{if(!$.ok){G.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(()=>{G.error(n("sessions.sidebar.session.share.copyUrlError"))})},e[13]=n,e[14]=j):j=e[14];const y=j;let C;e[15]!==t||e[16]!==n?(C=async V=>{await t.unshareSession(V)?G.success(n("sessions.sidebar.session.unshare.success")):G.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=[],$=F=>{(t.childrenMap.get(F)??[]).forEach(q=>{B.push(q),$(q.id)})};return $(V),B},e[18]=t.childrenMap,e[19]=w):w=e[19];const S=w,I=h6;let T;e[20]!==t||e[21]!==S||e[22]!==n?(T=async(V,B,$)=>{const F=B?.archivedBucket===!0,_=$?.descendantIds??I(S(V.id),F).map(g6);if(_.length===0){(F?await t.deleteSession(V.id):await t.archiveSession(V.id))?G.success(n(F?"sessions.sidebar.session.delete.success":"sessions.sidebar.session.archive.success")):G.error(n(F?"sessions.sidebar.session.delete.error":"sessions.sidebar.session.archive.error"));return}const q=[V.id,..._];if(F){const{deletedIds:Z,failedIds:ae}=await t.deleteSessions(q);Z.length>0&&G.success(Z.length===1?n("sessions.sidebar.bulkActions.deletedSingle",{count:Z.length}):n("sessions.sidebar.bulkActions.deletedPlural",{count:Z.length})),ae.length>0&&G.error(ae.length===1?n("sessions.sidebar.bulkActions.failedDeleteSingle",{count:ae.length}):n("sessions.sidebar.bulkActions.failedDeletePlural",{count:ae.length}));return}const{archivedIds:L,failedIds:Y}=await t.archiveSessions(q);L.length>0&&G.success(L.length===1?n("sessions.sidebar.bulkActions.archivedSingle",{count:L.length}):n("sessions.sidebar.bulkActions.archivedPlural",{count:L.length})),Y.length>0&&G.error(Y.length===1?n("sessions.sidebar.bulkActions.failedArchiveSingle",{count:Y.length}):n("sessions.sidebar.bulkActions.failedArchivePlural",{count:Y.length}))},e[20]=t,e[21]=S,e[22]=n,e[23]=T):T=e[23];const P=T;let A;e[24]!==t||e[25]!==S||e[26]!==P?(A=(V,B)=>{const $=B?.archivedBucket===!0,F=I(S(V.id),$).map(x6);if(!t.showDeletionDialog){P(V,B,{descendantIds:F});return}t.setDeleteSessionConfirm({session:V,descendantCount:F.length,descendantIds:F,archivedBucket:$})},e[24]=t,e[25]=S,e[26]=P,e[27]=A):A=e[27];const N=A;let E;e[28]!==t||e[29]!==P?(E=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]=E):E=e[30];const M=E;let O;return e[31]!==M||e[32]!==r||e[33]!==v||e[34]!==y||e[35]!==N||e[36]!==b||e[37]!==u||e[38]!==p||e[39]!==h||e[40]!==k?(O={copiedSessionId:r,handleSessionSelect:p,handleSessionDoubleClick:u,handleSaveEdit:b,handleCancelEdit:v,handleShareSession:h,handleCopyShareUrl:y,handleUnshareSession:k,handleDeleteSession:N,confirmDeleteSession:M},e[31]=M,e[32]=r,e[33]=v,e[34]=y,e[35]=N,e[36]=b,e[37]=u,e[38]=p,e[39]=h,e[40]=k,e[41]=O):O=e[41],O};function f6(t){return!t.time?.archived}function h6(t,e){return e?t:t.filter(f6)}function g6(t){return t.id}function x6(t){return t.id}const b6=["project:active:","project:archived:","recent:active:","recent:archived:"],y6=t=>{const{isVSCode:e,hasLoadedGlobalSessions:n,safeStorage:r,keys:a,sessions:i,setPinnedSessionIds:l,groupOrderByProject:c,activeSessionByProject:d,collapsedGroups:p,setExpandedParents:m,setCollapsedProjects:u}=t,f=o.useRef(null),b=o.useRef(null),g=o.useCallback(()=>{if(e)return;const x=b.current;if(b.current=null,f.current=null,!x)return;const{projects:h}=Cs.getState(),j=h.map(y=>({...y,sidebarCollapsed:x.has(y.id)}));Ss({projects:j}).catch(()=>{})},[e]),v=o.useCallback(x=>{typeof window>"u"||e||(b.current=x,f.current!==null&&window.clearTimeout(f.current),f.current=window.setTimeout(()=>{g()},700))},[e,g]);return o.useEffect(()=>()=>{typeof window<"u"&&f.current!==null&&window.clearTimeout(f.current),f.current=null,b.current=null},[]),o.useEffect(()=>{try{const x=r.getItem(a.sessionExpanded);if(x){const j=JSON.parse(x);Array.isArray(j)&&m(new Set(j.filter(y=>typeof y=="string")))}else{const j=r.getItem(a.sessionExpandedLegacy);if(j){try{const y=JSON.parse(j);if(Array.isArray(y)){const C=new Set;if(y.forEach(k=>{typeof k!="string"||k.length===0||b6.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(y=>typeof y=="string")))}}catch{}},[a.projectCollapse,a.sessionExpanded,a.sessionExpandedLegacy,r,u,m]),o.useEffect(()=>{if(!n)return;const x=new Set(i.map(h=>h.id));l(h=>{let j=!1;const y=new Set;return h.forEach(C=>{x.has(C)?y.add(C):j=!0}),j?y:h})},[n,i,l]),o.useEffect(()=>{try{const x=Object.fromEntries(c.entries());r.setItem(a.groupOrder,JSON.stringify(x))}catch{}},[c,a.groupOrder,r]),o.useEffect(()=>{try{const x=Object.fromEntries(d.entries());r.setItem(a.projectActiveSession,JSON.stringify(x))}catch{}},[d,a.projectActiveSession,r]),o.useEffect(()=>{try{r.setItem(a.groupCollapse,JSON.stringify(Array.from(p)))}catch{}},[p,a.groupCollapse,r]),{scheduleCollapsedProjectsPersist:v}},v6=async(t,e,n)=>{if(t.length===0)return[];const r=Math.max(1,Math.min(e,t.length)),a=new Array(t.length);let i=0;const l=async()=>{for(;;){const c=i;if(i+=1,c>=t.length)return;a[c]=await n(t[c])}};return await Promise.all(Array.from({length:r},()=>l())),a},w6=t=>{const e=ot.c(26),{normalizedProjects:n,gitRepoStatus:r,setProjectRepoStatus:a,setProjectRootBranches:i}=t,{git:l}=Bn(),c=Qs(j6);let d,p;e[0]!==c||e[1]!==l||e[2]!==n||e[3]!==a?(d=()=>{if(!l||n.length===0){a(new Map);return}n.forEach(j=>{c(j.normalizedPath,l)})},p=[n,l,c,a],e[0]=c,e[1]=l,e[2]=n,e[3]=a,e[4]=d,e[5]=p):(d=e[4],p=e[5]),o.useEffect(d,p);let m,u;e[6]!==r||e[7]!==n||e[8]!==a?(m=()=>{const j=new Map;n.forEach(y=>{j.set(y.id,r.get(y.normalizedPath)?.isGitRepo??null)}),a(j)},u=[n,r,a],e[6]=r,e[7]=n,e[8]=a,e[9]=m,e[10]=u):(m=e[9],u=e[10]),o.useEffect(m,u);let f;if(e[11]!==r||e[12]!==n){let j;e[14]!==r?(j=y=>{const C=r.get(y.normalizedPath)?.branch??"";return`${y.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 g;e[16]===Symbol.for("react.memo_cache_sentinel")?(g=new Map,e[16]=g):g=e[16];const v=o.useRef(g);let x;e[17]!==r||e[18]!==n||e[19]!==i?(x=()=>{let j=!1;const y=setTimeout(()=>{(async()=>{const k=new Set(n.map(N6));for(const T of v.current.keys())k.has(T)||v.current.delete(T);const w=n.filter(T=>{const P=r.get(T.normalizedPath);if(P?.isGitRepo===!1)return v.current.delete(T.id),!1;if(P?.isGitRepo!==!0||P.branch===null)return!1;const A=P.branch.trim(),N=`${T.normalizedPath}\0${A}`,E=v.current.get(T.id);return E===void 0||E!==N});if(w.length===0)return;const S=await v6(w,2,async T=>{const P=r.get(T.normalizedPath)?.branch?.trim()??"",A=`${T.normalizedPath}\0${P}`,N=await xo(T.normalizedPath,P?{knownBranch:P}:void 0).catch(S6);return{id:T.id,inputKey:A,branch:N}});if(j)return;const I=S.filter(k6);I.length!==0&&(i(T=>{const P=new Map(T);return I.forEach(A=>{const{id:N,branch:E}=A;E&&P.set(N,E)}),P}),I.forEach(T=>{const{id:P,inputKey:A}=T;v.current.set(P,A)}))})()},150);return()=>{j=!0,clearTimeout(y)}},e[17]=r,e[18]=n,e[19]=i,e[20]=x):x=e[20];let h;e[21]!==r||e[22]!==n||e[23]!==b||e[24]!==i?(h=[n,b,r,i],e[21]=r,e[22]=n,e[23]=b,e[24]=i,e[25]=h):h=e[25],o.useEffect(x,h)};function j6(t){return t.ensureStatus}function N6(t){return t.id}function S6(){return null}function k6(t){return t.branch}const C6=t=>{const e=ot.c(14),{isVSCode:n,sessions:r,archivedSessions:a,availableWorktreesByProject:i}=t;let l;e[0]!==r?(l=new Map,r.forEach(b=>{const g=bs(b.directory??null)??bs(b.project?.worktree??null);if(!g)return;const v=l.get(g)??[];v.push(b),l.set(g,v)}),e[0]=r,e[1]=l):l=e[1];const c=l;let d;e[2]!==i||e[3]!==n||e[4]!==c?(d=b=>{const g=n?[]:i.get(b.normalizedPath)??[],v=[b.normalizedPath,...g.map(I6).filter(P6)],x=new Set,h=[];return v.forEach(j=>{(c.get(j)??[]).forEach(C=>{x.has(C.id)||(x.add(C.id),h.push(C))})}),h},e[2]=i,e[3]=n,e[4]=c,e[5]=d):d=e[5];const p=d;let m;e[6]!==a||e[7]!==i||e[8]!==n||e[9]!==r?(m=b=>{if(n){const y=a.filter(k=>{const w=bs(k.directory??null),S=bs(k.project?.worktree??null);return w?w===b.normalizedPath:S===b.normalizedPath}),C=r.filter(k=>k.time?.archived||bs(k.directory??null)?!1:bs(k.project?.worktree??null)===b.normalizedPath);return vi([...y,...C])}const g=n?[]:i.get(b.normalizedPath)??[],v=new Set([b.normalizedPath,...g.map(A6).filter(D6)]),h=(y=>y.filter(C=>io(C,b.normalizedPath,v)))(a),j=r.filter(y=>{if(y.time?.archived||bs(y.directory??null))return!1;const k=bs(y.project?.worktree??null);return k?k===b.normalizedPath||k.startsWith(`${b.normalizedPath}/`):!1});return vi([...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 I6(t){return bs(t.path)??t.path}function P6(t){return!!t}function A6(t){return bs(t.path)??t.path}function D6(t){return!!t}const T6=t=>{const e=ot.c(9),{isSessionsLoading:n,sessions:r,archivedSessions:a,normalizedProjects:i,isVSCode:l,availableWorktreesByProject:c,cleanupSessions:d}=t;let p,m;e[0]!==a||e[1]!==c||e[2]!==d||e[3]!==n||e[4]!==l||e[5]!==i||e[6]!==r?(p=()=>{if(n)return;const u=new Map;r.forEach(g=>{const v=bs(g.directory??null);if(!v)return;const x=u.get(v);if(x){x.add(g.id);return}u.set(v,new Set([g.id]))}),i.forEach(g=>{const v=Wd(g.normalizedPath),x=l?[]:c.get(g.normalizedPath)??[],h=new Set([g.normalizedPath,...x.map(M6).filter(E6)]),j=vi([...a,...r.filter(y=>y.time?.archived||bs(y.directory??null)?!1:io(y,g.normalizedPath,h))]).filter(y=>io(y,g.normalizedPath,h));u.set(v,new Set(j.map(R6)))});const f=Yn.getState().foldersMap;new Set([...Object.keys(f),...u.keys()]).forEach(g=>{d(g,u.get(g)??new Set)})},m=[a,c,d,n,l,i,r],e[0]=a,e[1]=c,e[2]=d,e[3]=n,e[4]=l,e[5]=i,e[6]=r,e[7]=p,e[8]=m):(p=e[7],m=e[8]),o.useEffect(p,m)};function M6(t){return bs(t.path)??t.path}function E6(t){return!!t}function R6(t){return t.id}const F6=t=>{const e=ot.c(8),{isDesktopShellRuntime:n,projectSections:r,projectHeaderSentinelRefs:a}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=new Set,e[0]=i):i=e[0];const[l,c]=o.useState(i);let d;e[1]!==n||e[2]!==a?(d=()=>{if(!n)return;const m=new IntersectionObserver(u=>{u.forEach(f=>{const b=f.target.dataset.projectId;b&&c(g=>{const v=new Set(g);return f.isIntersecting?v.delete(b):v.add(b),v})})},{threshold:0});return a.current.forEach(u=>{u&&m.observe(u)}),()=>m.disconnect()},e[1]=n,e[2]=a,e[3]=d):d=e[3];let p;return e[4]!==n||e[5]!==a||e[6]!==r?(p=[n,a,r],e[4]=n,e[5]=a,e[6]=r,e[7]=p):p=e[7],o.useEffect(d,p),l},O6=t=>{const e=ot.c(85),{folder:n,sessions:r,subFolderItems:a,isCollapsed:i,onToggle:l,onRename:c,onDelete:d,renderSessionNode:p,groupDirectory:m,projectId:u,mobileVariant:f,alwaysShowActions:b,isRenaming:g,renameDraft:v,onRenameDraftChange:x,onRenameSave:h,onRenameCancel:j,droppableRef:y,isDropTarget:C,onNewSession:k,onNewSubFolder:w,depth:S,hideActions:I,archivedBucket:T}=t,A=b===void 0?f===void 0?!1:f:b,N=g===void 0?!1:g,E=v===void 0?"":v,M=C===void 0?!1:C,O=S===void 0?0:S,V=I===void 0?!1:I,B=T===void 0?!1:T,{t:$}=ut(),[F,_]=o.useState(!1),[q,L]=o.useState(""),Y=o.useRef(null),Z=N||F,ae=N?E:q;let re;e[0]!==n.name?(re=()=>{L(n.name),_(!0)},e[0]=n.name,e[1]=re):re=e[1];const me=re;let fe;e[2]!==ae||e[3]!==n.name||e[4]!==N||e[5]!==c||e[6]!==h?(fe=()=>{const U=ae.trim();U&&U!==n.name&&c(U),N&&h&&h(),_(!1),L("")},e[2]=ae,e[3]=n.name,e[4]=N,e[5]=c,e[6]=h,e[7]=fe):fe=e[7];const H=fe;let K;e[8]!==N||e[9]!==j?(K=()=>{N&&j&&j(),_(!1),L("")},e[8]=N,e[9]=j,e[10]=K):K=e[10];const Q=K;let W;e[11]!==N||e[12]!==x?(W=U=>{N&&x?x(U):L(U)},e[11]=N,e[12]=x,e[13]=W):W=e[13];const de=W;let be,we;e[14]!==N?(be=()=>{if(!N)return;const U=()=>{const Oe=Y.current;Oe&&(Oe.focus(),Oe.select())},le=requestAnimationFrame(U),Me=window.setTimeout(U,0);return()=>{cancelAnimationFrame(le),window.clearTimeout(Me)}},we=[N],e[14]=N,e[15]=be,e[16]=we):(be=e[15],we=e[16]),o.useEffect(be,we);const te=i?"folder":"folder-open",ue=O>0&&"ml-3";let xe;e[17]!==ue?(xe=ye("oc-folder",ue),e[17]=ue,e[18]=xe):xe=e[18];const ne=M&&"bg-primary/10 ring-1 ring-inset ring-primary/30";let pe;e[19]!==ne?(pe=ye("group/folder relative flex items-center justify-between gap-1.5 py-1 min-w-0 rounded-md","cursor-pointer",ne),e[19]=ne,e[20]=pe):pe=e[20];const J=Z?void 0:l,Se=Z?void 0:"button",he=Z?void 0:0;let Ie;e[21]!==l||e[22]!==Z?(Ie=Z?void 0:U=>{(U.key==="Enter"||U.key===" ")&&(U.preventDefault(),l())},e[21]=l,e[22]=Z,e[23]=Ie):Ie=e[23];let Pe;e[24]!==n.name||e[25]!==i||e[26]!==$?(Pe=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]=Pe):Pe=e[27];const Ce=B?A?"pr-7":"group-hover/folder:pr-7 group-focus-within/folder:pr-7":"";let X;e[28]!==Ce?(X=ye("min-w-0 flex items-center gap-1.5 pl-1.5 flex-1 transition-[padding]",Ce),e[28]=Ce,e[29]=X):X=e[29];const ie=M?"text-primary":"text-muted-foreground";let Ne;e[30]!==ie?(Ne=ye("h-3.5 w-3.5 flex-shrink-0",ie),e[30]=ie,e[31]=Ne):Ne=e[31];let oe;e[32]!==te||e[33]!==Ne?(oe=s.jsx(D,{name:te,className:Ne}),e[32]=te,e[33]=Ne,e[34]=oe):oe=e[34];let ke;e[35]!==ae||e[36]!==n.name||e[37]!==Q||e[38]!==de||e[39]!==H||e[40]!==i||e[41]!==M||e[42]!==Z||e[43]!==r||e[44]!==$?(ke=Z?s.jsxs("form",{className:"flex min-w-0 flex-1 items-center gap-1",onPointerDown:$6,onMouseDown:_6,onSubmit:U=>{U.preventDefault(),H()},children:[s.jsx("input",{ref:Y,value:ae,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:B6,onPointerDown:V6,onMouseDown:z6,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:U6,onPointerDown:W6,onMouseDown:K6,children:s.jsx(D,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:U=>{U.stopPropagation(),Q()},onPointerDown:H6,onMouseDown:G6,className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(D,{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",M?"text-primary":"text-muted-foreground"),children:n.name}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70 flex-shrink-0",children:["• ",r.length]}),i?s.jsx(D,{name:"arrow-right-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):s.jsx(D,{name:"arrow-down-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"})]}),e[35]=ae,e[36]=n.name,e[37]=Q,e[38]=de,e[39]=H,e[40]=i,e[41]=M,e[42]=Z,e[43]=r,e[44]=$,e[45]=ke):ke=e[45];let Te;e[46]!==X||e[47]!==oe||e[48]!==ke?(Te=s.jsxs("div",{className:X,children:[oe,ke]}),e[46]=X,e[47]=oe,e[48]=ke,e[49]=Te):Te=e[49];let Be;e[50]!==A||e[51]!==B||e[52]!==O||e[53]!==n.name||e[54]!==me||e[55]!==V||e[56]!==d||e[57]!==k||e[58]!==w||e[59]!==Z||e[60]!==$?(Be=!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",A?"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(D,{name:"add",className:"h-3.5 w-3.5"})}):null,!B&&w&&O===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(D,{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(D,{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(D,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})}):null,e[50]=A,e[51]=B,e[52]=O,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]=Be):Be=e[61];let je;e[62]!==y||e[63]!==pe||e[64]!==J||e[65]!==Se||e[66]!==he||e[67]!==Ie||e[68]!==Pe||e[69]!==Te||e[70]!==Be?(je=s.jsxs("div",{ref:y,className:pe,onClick:J,role:Se,tabIndex:he,onKeyDown:Ie,"aria-label":Pe,children:[Te,Be]}),e[62]=y,e[63]=pe,e[64]=J,e[65]=Se,e[66]=he,e[67]=Ie,e[68]=Pe,e[69]=Te,e[70]=Be,e[71]=je):je=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 R;return e[81]!==xe||e[82]!==je||e[83]!==ee?(R=s.jsxs("div",{className:xe,children:[je,ee]}),e[81]=xe,e[82]=je,e[83]=ee,e[84]=R):R=e[84],R},L6=o.memo(O6);function $6(t){return t.stopPropagation()}function _6(t){return t.stopPropagation()}function B6(t){return t.stopPropagation()}function V6(t){return t.stopPropagation()}function z6(t){return t.stopPropagation()}function U6(t){return t.stopPropagation()}function W6(t){return t.stopPropagation()}function K6(t){return t.stopPropagation()}function H6(t){return t.stopPropagation()}function G6(t){return t.stopPropagation()}const q6=t=>{const e=ot.c(15),{sessionId:n,sessionDirectory:r,sessionTitle:a,children:i}=t,l=`session-drag:${n}`;let c;e[0]!==r||e[1]!==n||e[2]!==a?(c={type:"session",sessionId:n,sessionDirectory:r,sessionTitle:a},e[0]=r,e[1]=n,e[2]=a,e[3]=c):c=e[3];let d;e[4]!==l||e[5]!==c?(d={id:l,data:c},e[4]=l,e[5]=c,e[6]=d):d=e[6];const{attributes:p,listeners:m,setNodeRef:u,isDragging:f}=Mx(d);let b;e[7]!==m?(b=h=>{h.stopPropagation(),m?.onPointerDown&&m.onPointerDown(h)},e[7]=m,e[8]=b):b=e[8];const g=b,v=f?"opacity-30":void 0;let x;return e[9]!==p||e[10]!==i||e[11]!==g||e[12]!==u||e[13]!==v?(x=s.jsx("div",{ref:u,...p,onPointerDown:g,className:v,children:i}),e[9]=p,e[10]=i,e[11]=g,e[12]=u,e[13]=v,e[14]=x):x=e[14],x},Y6=t=>{const e=ot.c(11),{folderId:n,children:r}=t,a=`folder-drop:${n}`;let i;e[0]!==n?(i={type:"folder",folderId:n},e[0]=n,e[1]=i):i=e[1];let l;e[2]!==a||e[3]!==i?(l={id:a,data:i},e[2]=a,e[3]=i,e[4]=l):l=e[4];const{setNodeRef:c,isOver:d}=Ex(l);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},Q6=t=>{const e=ot.c(20),{scopeKey:n,hasFolders:r,onSessionDroppedOnFolder:a,children:i}=t;let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l={activationConstraint:{distance:8}},e[0]=l):l=e[0];const c=eo(oi(to,l)),[d,p]=o.useState(null),[m,u]=o.useState("Session"),[f,b]=o.useState(null),[g,v]=o.useState(null);if(!n){let S;return e[1]!==i?(S=s.jsx(s.Fragment,{children:i}),e[1]=i,e[2]=S):S=e[2],S}let x;e[3]!==a?(x=S=>{p(null),b(null),v(null);const{active:I,over:T}=S;if(!T)return;const P=I.data.current,A=T.data.current;P?.type==="session"&&P.sessionId&&A?.type==="folder"&&A.folderId&&a(P.sessionId,A.folderId)},e[3]=a,e[4]=x):x=e[4];const h=x;let j,y;e[5]===Symbol.for("react.memo_cache_sentinel")?(j=S=>{const I=S.active.data.current;if(I?.type==="session"&&I.sessionId){p(I.sessionId),u(I.sessionTitle??"Session");const T=S.active.rect.current.initial?.width,P=S.active.rect.current.initial?.height;b(typeof T=="number"?T:null),v(typeof P=="number"?P:null)}},y=()=>{p(null),b(null),v(null)},e[5]=j,e[6]=y):(j=e[5],y=e[6]);let C;e[7]!==g||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:g?`${g}px`:"auto"},className:"flex items-center rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-2.5 py-1 shadow-none pointer-events-none",children:[s.jsx(D,{name:"sticky-note",className:"h-4 w-4 text-muted-foreground mr-2 flex-shrink-0"}),s.jsx("div",{className:"min-w-0 flex-1 truncate typography-ui-label font-normal text-foreground",children:m})]}):null,e[7]=g,e[8]=d,e[9]=m,e[10]=f,e[11]=r,e[12]=C):C=e[12];let k;e[13]!==C?(k=s.jsx(ul,{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(so,{sensors:c,collisionDetection:no,onDragStart:j,onDragCancel:y,onDragEnd:h,children:[i,k]}),e[15]=i,e[16]=h,e[17]=c,e[18]=k,e[19]=w):w=e[19],w},Fa=rr()(ho(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"})),J6=50,X6=28;function Z6(t){const{t:e}=ut(),{group:n,groupKey:r,projectId:a,hideGroupLabel:i,hasSessionSearchQuery:l,normalizedSessionSearchQuery:c,groupSearchDataByGroup:d,expandedSessionGroups:p,collapsedGroups:m,hideDirectoryControls:u,collapsedFolderIds:f,toggleFolderCollapse:b,renameFolder:g,deleteFolder:v,showDeletionDialog:x,setDeleteFolderConfirm:h,renderSessionNode:j,projectRepoStatus:y,lastRepoStatus:C,toggleGroupSessionLimit:k,mobileVariant:w,alwaysShowActions:S,activeProjectId:I,setActiveProjectIdOnly:T,setActiveMainTab:P,setSessionSwitcherOpen:A,openNewSessionDraft:N,addSessionToFolder:E,createFolderAndStartRename:M,renamingFolderId:O,renameFolderDraft:V,setRenameFolderDraft:B,setRenamingFolderId:$,pinnedSessionIds:F,sessionOrderIndex:_,prVisualStateByDirectoryBranch:q,onToggleCollapsedGroup:L,dragHandleProps:Y,compactBodyPadding:Z=!1}=t,ae=o.useCallback((et,gt)=>{const Pt=_.get(et.session.id),Nt=_.get(gt.session.id);if(Pt!==void 0||Nt!==void 0){if(Pt===void 0)return 1;if(Nt===void 0)return-1;if(Pt!==Nt)return Pt-Nt}return di(et.session,gt.session,F)},[F,_]),re=l?d.get(n):null,me=Fa(et=>et.displayMode),fe=Yn(et=>et.foldersMap),H=me==="minimal",K=p.has(r),Q=l?!1:m.has(r),W=u?10:5,de=l?re?.groupMatches===!0:!1,be=l,we=o.useMemo(()=>[...be?re?.filteredNodes??[]:n.sessions].sort(ae),[ae,n.sessions,re?.filteredNodes,be]),te=n.folderScopeKey??bs(n.directory??null),ge=o.useMemo(()=>te?fe[te]??[]:[],[te,fe]),ue=o.useMemo(()=>{const et=new Map,gt=Pt=>{Pt.forEach(Nt=>{et.set(Nt.session.id,Nt),Nt.children.length>0&>(Nt.children)})};return gt(we),et},[we]),xe=o.useMemo(()=>ge.map(et=>{const gt=et.sessionIds.map(Pt=>ue.get(Pt)).filter(Pt=>!!Pt).sort(ae);return{folder:et,nodes:gt}}),[ge,ue,ae]),ne=o.useMemo(()=>{const et=new Map(xe.map(ht=>[ht.folder.id,ht])),gt=new Map;for(const{folder:ht}of xe){if(!ht.parentId)continue;const wt=gt.get(ht.parentId);wt?wt.push(ht.id):gt.set(ht.parentId,[ht.id])}const Pt=new Map,Nt=ht=>{const wt=Pt.get(ht);if(wt!==void 0)return wt;const es=et.get(ht);if(!es)return Pt.set(ht,!1),!1;const Vt=gt.get(ht)??[];if(n.isArchivedBucket&&es.nodes.length===0){const Lt=Vt.some(ts=>Nt(ts));return Pt.set(ht,Lt),Lt}if(!l||es.folder.name.toLowerCase().includes(c)||es.nodes.length>0)return Pt.set(ht,!0),!0;const mt=Vt.some(Lt=>Nt(Lt));return Pt.set(ht,mt),mt};return xe.filter(({folder:ht})=>Nt(ht.id))},[xe,n.isArchivedBucket,l,c]),pe=o.useMemo(()=>new Set(ne.flatMap(et=>et.folder.sessionIds)),[ne]),J=o.useMemo(()=>we.filter(et=>!pe.has(et.session.id)),[we,pe]),Se=o.useMemo(()=>ne.filter(({folder:et})=>!et.parentId),[ne]),he=J.length,Ie=n.isArchivedBucket||l||K?J:J.slice(0,W),Pe=he-Ie.length,Ce=n.isArchivedBucket===!0&&!l&&Ie.length>=J6,X=o.useRef(null),[ie,Ne]=o.useState(null),[oe,ke]=o.useState(0),Te=Vf({count:Ie.length,getScrollElement:()=>ie,estimateSize:()=>X6,overscan:8,enabled:Ce&&ie!==null,scrollMargin:oe});o.useLayoutEffect(()=>{if(!Ce){ie!==null&&Ne(null),oe!==0&&ke(0);return}const et=X.current;if(!et)return;let gt=ie;if(!gt||!gt.contains(et)){let Nt=et.parentElement;for(;Nt;){const ht=window.getComputedStyle(Nt);if(ht.overflowY==="auto"||ht.overflowY==="scroll"){gt=Nt;break}Nt=Nt.parentElement}if(gt!==ie){Ne(gt);return}}if(!gt)return;const Pt=et.getBoundingClientRect().top-gt.getBoundingClientRect().top+gt.scrollTop;ke(Nt=>Math.abs(Nt-Pt)<1?Nt:Pt)}),o.useEffect(()=>{if(!Ce||!ie)return;const et=new ResizeObserver(()=>{Te.measure()});return et.observe(ie),()=>et.disconnect()},[Ce,ie,Te]);const Be=Te.getTotalSize(),je=Ce&&ie!==null?Te.getVirtualItems():[];if(l&&!de&&Se.length===0&&J.length===0)return null;const ee=et=>{const gt=[],Pt=Nt=>{Nt.forEach(ht=>{gt.push(ht.session),ht.children.length>0&&Pt(ht.children)})};return Pt(et),gt},R=ee(we),U=a&&y.has(a)?!!y.get(a):C,le=bs(n.directory??null),Me=n.branch?.trim()??null,Oe=le&&Me?q.get(`${le}::${Me}`)??null:null,Ae=!!(Oe&&n.branch),z=!Oe&&!n.isMain&&!!n.branch,De=Oe?.visualState??null,Xe=Oe&&Oe.state==="open"&&Oe.checks?e("sessions.sidebar.group.pr.checksPassed",{success:Oe.checks.success,total:Oe.checks.total}):null,st=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(et=>!!et).join(", "):null,tt=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,Ue=Oe&&Oe.state==="open"&&Oe.mergeableState?e("sessions.sidebar.group.pr.mergeState",{state:Oe.mergeableState}):null,it=Oe?.base??null,Ye=Oe?.head??null,rt=(()=>{if(!Oe)return n.branch&&Ny(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=rt?.color??(De?`var(--pr-${De})`:void 0),ce=et=>{et.preventDefault(),et.stopPropagation();const gt=Oe?.url;gt&&Zn(gt)},We=(et,gt,Pt)=>{const Nt=ne.filter(({folder:Vt})=>Vt.parentId===et.id),ht=Nt.length>0?s.jsx(s.Fragment,{children:Nt.map(({folder:Vt,nodes:Jt})=>We(Vt,Jt,Pt+1))}):void 0,wt=Vt=>{const Jt=ne.find(({folder:Lt})=>Lt.id===Vt)?.nodes??[],mt=ne.filter(({folder:Lt})=>Lt.parentId===Vt);return[...ee(Jt),...mt.flatMap(({folder:Lt})=>wt(Lt.id))]},es=n.isArchivedBucket?wt(et.id):[];return s.jsx(Y6,{folderId:et.id,children:(Vt,Jt)=>s.jsx(L6,{folder:et,sessions:gt,subFolderItems:ht,isCollapsed:l?!1:f.has(et.id),onToggle:()=>b(et.id),onRename:mt=>{te&&g(te,et.id,mt)},onDelete:()=>{if(n.isArchivedBucket){Ar.requestDelete({sessions:es,mode:"session"});return}if(!te)return;if(!x){v(te,et.id);return}const mt=ne.filter(({folder:ts})=>ts.parentId===et.id).length,Lt=gt.length;h({scopeKey:te,folderId:et.id,folderName:et.name,subFolderCount:mt,sessionCount:Lt})},renderSessionNode:j,groupDirectory:n.directory,projectId:a,mobileVariant:w,alwaysShowActions:S,isRenaming:O===et.id,renameDraft:O===et.id?V:void 0,onRenameDraftChange:mt=>B(mt),onRenameSave:()=>{const mt=V.trim();mt&&te&&g(te,et.id,mt),$(null),B("")},onRenameCancel:()=>{$(null),B("")},droppableRef:Vt,isDropTarget:Jt,depth:Pt,onNewSession:()=>{a&&a!==I&&T(a),P("chat"),w&&A(!1),N({directoryOverride:n.directory,targetFolderId:et.id})},onNewSubFolder:Pt===0?()=>{te&&M(te,et.id)}:void 0,hideActions:!1,archivedBucket:n.isArchivedBucket===!0})},et.id)},Le=()=>Se.map(({folder:et,nodes:gt})=>We(et,gt,0)),Ge=!!(!n.isMain&&n.worktree),at=S?Ge?"pr-14":"pr-7":H?Ge?"pr-2 group-hover/gh:pr-14 group-focus-within/gh:pr-14":"pr-2":Ge?"pr-5 group-hover/gh:pr-14 group-focus-within/gh:pr-14":"pr-5",He=s.jsxs(Q6,{scopeKey:te,hasFolders:ne.length>0,onSessionDroppedOnFolder:(et,gt)=>{te&&E(te,gt,et)},children:[Le(),Ce?s.jsx("div",{ref:X,style:{position:"relative",height:Be>0?Be:void 0,width:"100%"},children:je.map(et=>{const gt=Ie[et.index];return gt?s.jsx("div",{"data-index":et.index,ref:Te.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${et.start-oe}px)`},children:j(gt,0,n.directory,a,!0)},et.key):null})}):Ie.map(et=>j(et,0,n.directory,a,n.isArchivedBucket===!0)),he===0&&ne.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,Pe>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:Pe===1?e("sessions.sidebar.group.showMoreSingle",{count:Pe}):e("sessions.sidebar.group.showMorePlural",{count:Pe})}):null,K&&he>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:He})}):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:et=>{(et.key==="Enter"||et.key===" ")&&(et.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:Y?.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",at),...Y?.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:Ae&&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(D,{name:"git-branch",className:ye("h-3.5 w-3.5 shrink-0",S?"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",S?"inline-flex":"hidden group-hover/gh:inline-flex"),children:Q?s.jsx(D,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(D,{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:et=>et.stopPropagation(),onClick:ce,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||Ye?s.jsx("div",{className:"text-muted-foreground truncate",children:it&&Ye?s.jsxs(s.Fragment,{children:[s.jsx("span",{children:it}),s.jsx(D,{name:"arrow-left-long",className:"mx-0.5 inline h-3 w-3 align-[-2px]"}),s.jsx("span",{children:Ye})]}):s.jsx("span",{children:it??Ye??""})}):null,Ue?s.jsx("div",{className:"text-muted-foreground truncate",children:Ue}):null,tt||Xe?s.jsxs("div",{className:"text-muted-foreground truncate",children:[tt??"",tt&&Xe?" • ":"",Xe??"",st?` (${st})`:""]}):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(D,{name:"archive",className:ye("h-3.5 w-3.5 shrink-0 text-muted-foreground",S?"hidden":"group-hover/gh:hidden")}),s.jsx("span",{className:ye("text-muted-foreground h-3.5 w-3.5 items-center justify-center",S?"inline-flex":"hidden group-hover/gh:inline-flex"),children:Q?s.jsx(D,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(D,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:Yi(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(D,{name:"git-branch",className:ye("h-3.5 w-3.5 shrink-0 text-muted-foreground",S?"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",S?"inline-flex":"hidden group-hover/gh:inline-flex"),children:Q?s.jsx(D,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(D,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:Yi(n.label,c)})]}):Yi(n.label,c)}),z&&rt?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5 leading-tight",children:[n.isArchivedBucket?s.jsx(D,{name:"archive",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):!n.isMain||U?Ae&&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(D,{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||Ye?s.jsx("div",{className:"text-muted-foreground truncate",children:it&&Ye?s.jsxs(s.Fragment,{children:[s.jsx("span",{children:it}),s.jsx(D,{name:"arrow-left-long",className:"mx-0.5 inline h-3 w-3 align-[-2px]"}),s.jsx("span",{children:Ye})]}):s.jsx("span",{children:it??Ye??""})}):null,Ue?s.jsx("div",{className:"text-muted-foreground truncate",children:Ue}):null,tt||Xe?s.jsxs("div",{className:"text-muted-foreground truncate",children:[tt??"",tt&&Xe?" • ":"",Xe??"",st?` (${st})`:""]}):null]})})]}):s.jsx(D,{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",!rt.color&&"text-muted-foreground/80"),style:rt.color?{color:rt.color}:void 0,children:rt.label})]}):null]})}),n.isArchivedBucket&&R.length>0?s.jsx("div",{className:ye("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",S?"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:et=>{et.stopPropagation(),Ar.requestDelete({sessions:R,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(D,{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",S?"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:et=>{et.stopPropagation(),Ar.requestDelete({sessions:R,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(D,{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",S?"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:et=>{et.stopPropagation(),a&&a!==I&&T(a),P("chat"),w&&A(!1),N({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(D,{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:He})]})}function eP(t){const e=ot.c(189),{t:n}=ut(),{hideDirectoryControls:r,handleOpenDirectoryDialog:a,canOpenMultiRun:i,openMultiRunLauncher:l,headerActionIconClass:c,headerActionButtonClass:d,isSessionSearchOpen:p,setIsSessionSearchOpen:m,sessionSearchInputRef:u,sessionSearchQuery:f,setSessionSearchQuery:b,hasSessionSearchQuery:g,searchMatchCount:v,collapseAllProjects:x,expandAllProjects:h,openScheduledTasksDialog:j,selectionModeEnabled:y,onToggleSelectionMode:C}=t,k=Fa(aP),w=Fa(rP),S=Fa(nP),I=Fa(sP);if(r)return null;let T;e[0]!==n?(T=n("sessions.sidebar.header.actions.addProject"),e[0]=n,e[1]=T):T=e[1];let P;e[2]!==c?(P=s.jsx(D,{name:"folder-add",className:c}),e[2]=c,e[3]=P):P=e[3];let A;e[4]!==a||e[5]!==d||e[6]!==T||e[7]!==P?(A=s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:a,className:d,"aria-label":T,children:P})}),e[4]=a,e[5]=d,e[6]=T,e[7]=P,e[8]=A):A=e[8];let N;e[9]!==n?(N=n("sessions.sidebar.header.actions.addProject"),e[9]=n,e[10]=N):N=e[10];let E;e[11]!==N?(E=s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:N})}),e[11]=N,e[12]=E):E=e[12];let M;e[13]!==A||e[14]!==E?(M=s.jsxs(kt,{children:[A,E]}),e[13]=A,e[14]=E,e[15]=M):M=e[15];let O;e[16]!==n?(O=n("sessions.sidebar.header.actions.newMultiRun"),e[16]=n,e[17]=O):O=e[17];const V=!i;let B;e[18]!==c?(B=s.jsx(Sy,{className:c}),e[18]=c,e[19]=B):B=e[19];let $;e[20]!==d||e[21]!==l||e[22]!==O||e[23]!==V||e[24]!==B?($=s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:l,className:d,"aria-label":O,disabled:V,children:B})}),e[20]=d,e[21]=l,e[22]=O,e[23]=V,e[24]=B,e[25]=$):$=e[25];let F;e[26]!==n?(F=n("sessions.sidebar.header.actions.newMultiRun"),e[26]=n,e[27]=F):F=e[27];let _;e[28]!==F?(_=s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:F})}),e[28]=F,e[29]=_):_=e[29];let q;e[30]!==_||e[31]!==$?(q=s.jsxs(kt,{children:[$,_]}),e[30]=_,e[31]=$,e[32]=q):q=e[32];let L;e[33]!==n?(L=n("sessions.sidebar.header.actions.scheduledTasks"),e[33]=n,e[34]=L):L=e[34];let Y;e[35]!==c?(Y=s.jsx(D,{name:"calendar-schedule",className:c}),e[35]=c,e[36]=Y):Y=e[36];let Z;e[37]!==d||e[38]!==j||e[39]!==L||e[40]!==Y?(Z=s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:j,className:d,"aria-label":L,children:Y})}),e[37]=d,e[38]=j,e[39]=L,e[40]=Y,e[41]=Z):Z=e[41];let ae;e[42]!==n?(ae=n("sessions.sidebar.header.actions.scheduledTasks"),e[42]=n,e[43]=ae):ae=e[43];let re;e[44]!==ae?(re=s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:ae})}),e[44]=ae,e[45]=re):re=e[45];let me;e[46]!==Z||e[47]!==re?(me=s.jsxs(kt,{children:[Z,re]}),e[46]=Z,e[47]=re,e[48]=me):me=e[48];let fe;e[49]!==q||e[50]!==me||e[51]!==M?(fe=s.jsxs("div",{className:"flex items-center gap-1.5",children:[M,q,me]}),e[49]=q,e[50]=me,e[51]=M,e[52]=fe):fe=e[52];let H;e[53]!==m?(H=()=>m(tP),e[53]=m,e[54]=H):H=e[54];let K;e[55]!==n?(K=n("sessions.sidebar.header.actions.searchSessions"),e[55]=n,e[56]=K):K=e[56];let Q;e[57]!==c?(Q=s.jsx(D,{name:"search",className:c}),e[57]=c,e[58]=Q):Q=e[58];let W;e[59]!==d||e[60]!==p||e[61]!==H||e[62]!==K||e[63]!==Q?(W=s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:H,className:d,"aria-label":K,"aria-expanded":p,children:Q})}),e[59]=d,e[60]=p,e[61]=H,e[62]=K,e[63]=Q,e[64]=W):W=e[64];let de;e[65]!==n?(de=n("sessions.sidebar.header.actions.searchSessions"),e[65]=n,e[66]=de):de=e[66];let be;e[67]!==de?(be=s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:de})}),e[67]=de,e[68]=be):be=e[68];let we;e[69]!==W||e[70]!==be?(we=s.jsxs(kt,{children:[W,be]}),e[69]=W,e[70]=be,e[71]=we):we=e[71];const te=y&&"bg-interactive-hover text-primary";let ge;e[72]!==d||e[73]!==te?(ge=ye(d,te),e[72]=d,e[73]=te,e[74]=ge):ge=e[74];let ue;e[75]!==y||e[76]!==n?(ue=n(y?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions"),e[75]=y,e[76]=n,e[77]=ue):ue=e[77];let xe;e[78]!==c?(xe=s.jsx(D,{name:"checkbox-multiple",className:c}),e[78]=c,e[79]=xe):xe=e[79];let ne;e[80]!==C||e[81]!==y||e[82]!==ge||e[83]!==ue||e[84]!==xe?(ne=s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:C,className:ge,"aria-label":ue,"aria-pressed":y,children:xe})}),e[80]=C,e[81]=y,e[82]=ge,e[83]=ue,e[84]=xe,e[85]=ne):ne=e[85];let pe;e[86]!==y||e[87]!==n?(pe=n(y?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions"),e[86]=y,e[87]=n,e[88]=pe):pe=e[88];let J;e[89]!==pe?(J=s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:pe})}),e[89]=pe,e[90]=J):J=e[90];let Se;e[91]!==ne||e[92]!==J?(Se=s.jsxs(kt,{children:[ne,J]}),e[91]=ne,e[92]=J,e[93]=Se):Se=e[93];let he;e[94]!==n?(he=n("sessions.sidebar.header.actions.sessionDisplayMode"),e[94]=n,e[95]=he):he=e[95];let Ie;e[96]!==c?(Ie=s.jsx(D,{name:"equalizer-2",className:c}),e[96]=c,e[97]=Ie):Ie=e[97];let Pe;e[98]!==d||e[99]!==he||e[100]!==Ie?(Pe=s.jsx(Ct,{asChild:!0,children:s.jsx(Is,{asChild:!0,children:s.jsx("button",{type:"button",className:d,"aria-label":he,children:Ie})})}),e[98]=d,e[99]=he,e[100]=Ie,e[101]=Pe):Pe=e[101];let Ce;e[102]!==n?(Ce=n("sessions.sidebar.header.displayMode.label"),e[102]=n,e[103]=Ce):Ce=e[103];let X;e[104]!==Ce?(X=s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:Ce})}),e[104]=Ce,e[105]=X):X=e[105];let ie;e[106]!==Pe||e[107]!==X?(ie=s.jsxs(kt,{children:[Pe,X]}),e[106]=Pe,e[107]=X,e[108]=ie):ie=e[108];let Ne;e[109]!==S?(Ne=()=>S("default"),e[109]=S,e[110]=Ne):Ne=e[110];let oe;e[111]!==n?(oe=n("sessions.sidebar.header.displayMode.default"),e[111]=n,e[112]=oe):oe=e[112];let ke;e[113]!==oe?(ke=s.jsx("span",{children:oe}),e[113]=oe,e[114]=ke):ke=e[114];let Te;e[115]!==k?(Te=k==="default"?s.jsx(D,{name:"check",className:"h-4 w-4 text-primary"}):null,e[115]=k,e[116]=Te):Te=e[116];let Be;e[117]!==Ne||e[118]!==ke||e[119]!==Te?(Be=s.jsxs(Ot,{onClick:Ne,className:"flex items-center justify-between",children:[ke,Te]}),e[117]=Ne,e[118]=ke,e[119]=Te,e[120]=Be):Be=e[120];let je;e[121]!==S?(je=()=>S("minimal"),e[121]=S,e[122]=je):je=e[122];let ee;e[123]!==n?(ee=n("sessions.sidebar.header.displayMode.minimal"),e[123]=n,e[124]=ee):ee=e[124];let R;e[125]!==ee?(R=s.jsx("span",{children:ee}),e[125]=ee,e[126]=R):R=e[126];let U;e[127]!==k?(U=k==="minimal"?s.jsx(D,{name:"check",className:"h-4 w-4 text-primary"}):null,e[127]=k,e[128]=U):U=e[128];let le;e[129]!==je||e[130]!==R||e[131]!==U?(le=s.jsxs(Ot,{onClick:je,className:"flex items-center justify-between",children:[R,U]}),e[129]=je,e[130]=R,e[131]=U,e[132]=le):le=e[132];let Me;e[133]===Symbol.for("react.memo_cache_sentinel")?(Me=s.jsx(Xn,{}),e[133]=Me):Me=e[133];let Oe;e[134]!==n?(Oe=n("sessions.sidebar.header.displayMode.showRecent"),e[134]=n,e[135]=Oe):Oe=e[135];let Ae;e[136]!==Oe?(Ae=s.jsx("span",{children:Oe}),e[136]=Oe,e[137]=Ae):Ae=e[137];let z;e[138]!==w?(z=w?s.jsx(D,{name:"check",className:"h-4 w-4 text-primary"}):null,e[138]=w,e[139]=z):z=e[139];let De;e[140]!==Ae||e[141]!==z||e[142]!==I?(De=s.jsxs(Ot,{onClick:I,className:"flex items-center justify-between",children:[Ae,z]}),e[140]=Ae,e[141]=z,e[142]=I,e[143]=De):De=e[143];let Xe;e[144]===Symbol.for("react.memo_cache_sentinel")?(Xe=s.jsx(Xn,{}),e[144]=Xe):Xe=e[144];let st;e[145]===Symbol.for("react.memo_cache_sentinel")?(st=s.jsx(D,{name:"contract-up-down",className:"h-4 w-4"}),e[145]=st):st=e[145];let tt;e[146]!==n?(tt=n("sessions.sidebar.header.displayMode.collapseAll"),e[146]=n,e[147]=tt):tt=e[147];let Ue;e[148]!==tt?(Ue=s.jsx("span",{children:tt}),e[148]=tt,e[149]=Ue):Ue=e[149];let it;e[150]!==x||e[151]!==Ue?(it=s.jsxs(Ot,{onClick:x,className:"flex items-center gap-2",children:[st,Ue]}),e[150]=x,e[151]=Ue,e[152]=it):it=e[152];let Ye;e[153]===Symbol.for("react.memo_cache_sentinel")?(Ye=s.jsx(D,{name:"expand-up-down",className:"h-4 w-4"}),e[153]=Ye):Ye=e[153];let rt;e[154]!==n?(rt=n("sessions.sidebar.header.displayMode.expandAll"),e[154]=n,e[155]=rt):rt=e[155];let Je;e[156]!==rt?(Je=s.jsx("span",{children:rt}),e[156]=rt,e[157]=Je):Je=e[157];let ce;e[158]!==h||e[159]!==Je?(ce=s.jsxs(Ot,{onClick:h,className:"flex items-center gap-2",children:[Ye,Je]}),e[158]=h,e[159]=Je,e[160]=ce):ce=e[160];let We;e[161]!==Be||e[162]!==le||e[163]!==De||e[164]!==it||e[165]!==ce?(We=s.jsxs(Ps,{align:"end",className:"min-w-[160px]",children:[Be,le,Me,De,Xe,it,ce]}),e[161]=Be,e[162]=le,e[163]=De,e[164]=it,e[165]=ce,e[166]=We):We=e[166];let Le;e[167]!==ie||e[168]!==We?(Le=s.jsxs(As,{children:[ie,We]}),e[167]=ie,e[168]=We,e[169]=Le):Le=e[169];let Ge;e[170]!==we||e[171]!==Se||e[172]!==Le?(Ge=s.jsxs("div",{className:"flex items-center gap-1.5",children:[we,Se,Le]}),e[170]=we,e[171]=Se,e[172]=Le,e[173]=Ge):Ge=e[173];let at;e[174]!==fe||e[175]!==Ge?(at=s.jsxs("div",{className:"flex h-8 items-center justify-between gap-2",children:[fe,Ge]}),e[174]=fe,e[175]=Ge,e[176]=at):at=e[176];let He;e[177]!==g||e[178]!==p||e[179]!==v||e[180]!==u||e[181]!==f||e[182]!==m||e[183]!==b||e[184]!==n?(He=p?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:v===1?n("sessions.sidebar.header.search.matchCountSingle",{count:v}):n("sessions.sidebar.header.search.matchCountPlural",{count:v})}):s.jsx("span",{}),s.jsx("span",{children:n("sessions.sidebar.header.search.escapeHint")})]}),s.jsxs("div",{className:"relative",children:[s.jsx(D,{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:u,value:f,onChange:et=>b(et.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:et=>{et.key==="Escape"&&(et.stopPropagation(),g?b(""):m(!1))}}),f.length>0?s.jsx("button",{type:"button",onClick:()=>b(""),className:"absolute right-1 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":n("sessions.sidebar.header.search.clear"),children:s.jsx(D,{name:"close",className:"h-3.5 w-3.5"})}):null]})]}):null,e[177]=g,e[178]=p,e[179]=v,e[180]=u,e[181]=f,e[182]=m,e[183]=b,e[184]=n,e[185]=He):He=e[185];let ze;return e[186]!==at||e[187]!==He?(ze=s.jsx("div",{className:"select-none flex-shrink-0 px-2.5 py-1",children:s.jsxs("div",{className:"flex h-auto min-h-8 flex-col gap-1",children:[at,He]})}),e[186]=at,e[187]=He,e[188]=ze):ze=e[188],ze}function tP(t){return!t}function sP(t){return t.toggleRecentSection}function nP(t){return t.setDisplayMode}function rP(t){return t.showRecentSection}function aP(t){return t.displayMode}const xf=7;function iP(t){const e=ot.c(20),{sections:n,renderSessionNode:r}=t,{t:a}=ut();let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=new Set,e[0]=i):i=e[0];const[l,c]=o.useState(i);let d;e[1]===Symbol.for("react.memo_cache_sentinel")?(d=new Set,e[1]=d):d=e[1];const[p,m]=o.useState(d);let u;e[2]===Symbol.for("react.memo_cache_sentinel")?(u=y=>{c(C=>{const k=new Set(C);return k.has(y)?k.delete(y):k.add(y),k})},e[2]=u):u=e[2];const f=u;let b;e[3]===Symbol.for("react.memo_cache_sentinel")?(b=y=>{m(C=>{const k=new Set(C);return k.has(y)?k.delete(y):k.add(y),k})},e[3]=b):b=e[3];const g=b;let v,x,h;if(e[4]!==l||e[5]!==p||e[6]!==r||e[7]!==n||e[8]!==a){h=Symbol.for("react.early_return_sentinel");e:{const y=n.filter(oP);if(y.length===0){h=null;break e}v="space-y-2 pb-2 pt-1";let C;e[12]!==l||e[13]!==p||e[14]!==r||e[15]!==a?(C=k=>{const w=l.has(k.key),S=p.has(k.key),I=S?k.items:k.items.slice(0,xf),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(D,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(D,{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&&!S?s.jsx("button",{type:"button",onClick:()=>g(k.key),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:T===1?a("sessions.sidebar.group.showMoreSingle",{count:T}):a("sessions.sidebar.group.showMorePlural",{count:T})}):null,S&&k.items.length>xf?s.jsx("button",{type:"button",onClick:()=>g(k.key),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:a("sessions.sidebar.group.showFewer")}):null]})]},k.key)},e[12]=l,e[13]=p,e[14]=r,e[15]=a,e[16]=C):C=e[16],x=y.map(C)}e[4]=l,e[5]=p,e[6]=r,e[7]=n,e[8]=a,e[9]=v,e[10]=x,e[11]=h}else v=e[9],x=e[10],h=e[11];if(h!==Symbol.for("react.early_return_sentinel"))return h;let j;return e[17]!==v||e[18]!==x?(j=s.jsx("div",{className:v,children:x}),e[17]=v,e[18]=x,e[19]=j):j=e[19],j}function oP(t){return t.items.length>0}const zc="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 lP(t){const e=ot.c(13),{onOpenSettings:n,onOpenShortcuts:r,onOpenAbout:a,onOpenUpdate:i,showRuntimeButtons:l,showUpdateButton:c}=t,d=l===void 0?!0:l,p=c===void 0?!0:c,{t:m}=ut();let u;e[0]!==a||e[1]!==n||e[2]!==r||e[3]!==d||e[4]!==m?(u=d?s.jsxs(s.Fragment,{children:[s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,className:zc,"aria-label":m("sessions.sidebar.footer.actions.settings"),children:s.jsx(D,{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:zc,"aria-label":m("sessions.sidebar.footer.actions.shortcuts"),children:s.jsx(D,{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:zc,"aria-label":m("sessions.sidebar.footer.actions.aboutOpenChamber"),children:s.jsx(D,{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(ve,{type:"button",variant:"default",size:"xs",className:"ml-auto border-[var(--status-info-border)] bg-[var(--status-info-background)] text-[var(--status-info)] hover:bg-[var(--status-info-background)]/80 hover:text-[var(--status-info)] dark:border-[var(--status-info-border)] dark:bg-[var(--status-info-background)] dark:hover:bg-[var(--status-info-background)]/80",onClick:i,children:m("sessions.sidebar.footer.actions.update")}):null,e[6]=i,e[7]=p,e[8]=m,e[9]=f):f=e[9];let 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 cP=t=>{const e=ot.c(58),{id:n,projectLabel:r,projectDescription:a,projectIcon:i,projectColor:l,projectIconImage:c,projectIconBackground:d,isCollapsed:p,isActiveProject:m,isRepo:u,isDesktopShell:f,isStuck:b,hideDirectoryControls:g,alwaysShowActions:v,onToggle:x,onNewSession:h,onNewWorktreeSession:j,onRenameStart:y,onClose:C,sentinelRef:k,children:w,showCreateButtons:S,hideHeader:I,openSidebarMenuKey:T,setOpenSidebarMenuKey:P}=t,A=S===void 0?!0:S,N=I===void 0?!1:I,{t:E}=ut(),{currentTheme:M}=vr();let O;e[0]!==n?(O={id:n},e[0]=n,e[1]=O):O=e[1];const{attributes:V,listeners:B,setNodeRef:$,transform:F,transition:_,isDragging:q}=Ml(O),[L,Y]=o.useState(!1),Z=o.useRef(!1),ae=`project:${n}`,re=T===ae;let me;e[2]===Symbol.for("react.memo_cache_sentinel")?(me=()=>{Y(!1)},e[2]=me):me=e[2];const fe=c?.updatedAt;let H;e[3]!==n||e[4]!==fe?(H=[n,fe],e[3]=n,e[4]=fe,e[5]=H):H=e[5],o.useEffect(me,H);const K=i?zl[i]:null,Q=l?vo[l]??null:null;let W;e[6]!==M||e[7]!==n||e[8]!==L||e[9]!==c?(W=L?null:yo({id:n,iconImage:c},{themeVariant:M.metadata.variant,iconColor:M.colors.surface.foreground}),e[6]=M,e[7]=n,e[8]=L,e[9]=c,e[10]=W):W=e[10];const de=W;let be;e[11]!==ae||e[12]!==P?(be=ie=>{P(ie?ae:null)},e[11]=ae,e[12]=P,e[13]=be):be=e[13];const we=be,te=mP,ge=pP,ue=fP;let xe;e[14]===Symbol.for("react.memo_cache_sentinel")?(xe=ie=>{(ie.button===2||ie.button===0&&ie.ctrlKey)&&(Z.current=!0)},e[14]=xe):xe=e[14];const ne=xe;let pe;e[15]!==x?(pe=()=>{if(Z.current){Z.current=!1;return}x()},e[15]=x,e[16]=pe):pe=e[16];const J=pe;let Se;e[17]!==F?(Se=El.Transform.toString(F),e[17]=F,e[18]=Se):Se=e[18];let he;e[19]!==Se||e[20]!==_?(he={transform:Se,transition:_},e[19]=Se,e[20]=_,e[21]=he):he=e[21];const Ie=q&&"opacity-30";let Pe;e[22]!==Ie?(Pe=ye("relative",Ie),e[22]=Ie,e[23]=Pe):Pe=e[23];let Ce;e[24]!==v||e[25]!==V||e[26]!==we||e[27]!==J||e[28]!==g||e[29]!==N||e[30]!==Q||e[31]!==n||e[32]!==de||e[33]!==m||e[34]!==p||e[35]!==f||e[36]!==re||e[37]!==u||e[38]!==b||e[39]!==B||e[40]!==C||e[41]!==h||e[42]!==j||e[43]!==y||e[44]!==a||e[45]!==d||e[46]!==K||e[47]!==r||e[48]!==k||e[49]!==A||e[50]!==E?(Ce=N?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:ne,onClick:J,...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&&!g?v?"pr-20":"pr-7 group-hover/project:pr-20 group-focus-within/project:pr-20":v?"pr-14":"pr-7 group-hover/project:pr-14 group-focus-within/project:pr-14"),children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 flex-shrink-0 items-center justify-center",children:[s.jsx("span",{className:ye("h-3.5 w-3.5 items-center justify-center text-muted-foreground",v?"inline-flex":"hidden group-hover/project:inline-flex group-focus-within/project:inline-flex"),children:p?s.jsx(D,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(D,{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]",v?"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:()=>Y(!0)})}):K?s.jsx(D,{name:K,className:ye("h-3.5 w-3.5",v?"hidden":"group-hover/project:hidden group-focus-within/project:hidden"),style:Q?{color:Q}:void 0}):s.jsx(D,{name:"folder",className:ye("h-3.5 w-3.5 text-muted-foreground/80",v?"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",A?"right-7":"right-0.5"),children:[A&&u&&!g&&j?s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:ie=>{ie.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",v?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":E("sessions.sidebar.project.actions.newWorktree"),children:s.jsx(D,{name:"node-tree",className:"h-4 w-4"})})}),s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:E("sessions.sidebar.project.actions.newWorktreeEllipsis")})})]}):null,s.jsxs(As,{open:re,onOpenChange:we,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",re?"opacity-100 pointer-events-auto":v?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":E("sessions.sidebar.project.actions.projectMenu"),onPointerDown:ge,onMouseDown:ue,onClick:te,children:s.jsx(D,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsxs(Ps,{align:"end",className:"min-w-[180px]",children:[A&&!u&&!g&&h&&s.jsxs(Ot,{onClick:h,children:[s.jsx(D,{name:"add",className:"mr-1.5 h-4 w-4"}),E("sessions.sidebar.project.actions.newSession")]}),s.jsxs(Ot,{onClick:y,children:[s.jsx(D,{name:"pencil-ai",className:"mr-1.5 h-4 w-4"}),E("sessions.sidebar.session.menu.rename")]}),s.jsxs(Ot,{onClick:C,className:"text-destructive focus:text-destructive",children:[s.jsx(D,{name:"close",className:"mr-1.5 h-4 w-4"}),E("sessions.sidebar.project.actions.closeProject")]})]})]})]}),A&&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:ie=>{ie.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",v?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":E(u?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession"),children:s.jsx(D,{name:"add",className:"h-4 w-4"})})}),s.jsx(It,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:E(u?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession")})})]})}):null]})})]}),e[24]=v,e[25]=V,e[26]=we,e[27]=J,e[28]=g,e[29]=N,e[30]=Q,e[31]=n,e[32]=de,e[33]=m,e[34]=p,e[35]=f,e[36]=re,e[37]=u,e[38]=b,e[39]=B,e[40]=C,e[41]=h,e[42]=j,e[43]=y,e[44]=a,e[45]=d,e[46]=K,e[47]=r,e[48]=k,e[49]=A,e[50]=E,e[51]=Ce):Ce=e[51];let X;return e[52]!==w||e[53]!==$||e[54]!==he||e[55]!==Pe||e[56]!==Ce?(X=s.jsxs("div",{ref:$,style:he,className:Pe,children:[Ce,w]}),e[52]=w,e[53]=$,e[54]=he,e[55]=Pe,e[56]=Ce,e[57]=X):X=e[57],X},dP=t=>{const e=ot.c(21),{id:n,disabled:r,children:a}=t,i=r===void 0?!1:r;let l;e[0]!==i||e[1]!==n?(l={id:n,disabled:i},e[0]=i,e[1]=n,e[2]=l):l=e[2];const{listeners:c,setNodeRef:d,setActivatorNodeRef:p,transform:m,transition:u,isDragging:f}=Ml(l);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 g=b;let v;e[6]!==m?(v=El.Transform.toString(m),e[6]=m,e[7]=v):v=e[7];let x;e[8]!==v||e[9]!==u?(x={transform:v,transition:u},e[8]=v,e[9]=u,e[10]=x):x=e[10];const 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 y;e[13]!==a||e[14]!==g?(y=typeof a=="function"?a(g):a,e[13]=a,e[14]=g,e[15]=y):y=e[15];let C;return e[16]!==d||e[17]!==x||e[18]!==j||e[19]!==y?(C=s.jsx("div",{ref:d,style:x,className:j,children:y}),e[16]=d,e[17]=x,e[18]=j,e[19]=y,e[20]=C):C=e[20],C},uP=o.memo(dP);function mP(t){t.stopPropagation()}function pP(t){t.stopPropagation()}function fP(t){t.stopPropagation()}function hP(t){const e=ot.c(25),{t:n}=ut();let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={activationConstraint:{distance:8}},e[0]=r):r=e[0];let a;e[1]===Symbol.for("react.memo_cache_sentinel")?(a={coordinateGetter:Fx},e[1]=a):a=e[1];const i=eo(oi(to,r),oi(Rx,a));let l;e[2]===Symbol.for("react.memo_cache_sentinel")?(l={activationConstraint:{distance:8}},e[2]=l):l=e[2];const c=eo(oi(to,l));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 g;return e[5]!==t.emptyState||e[6]!==t.topContent||e[7]!==b?(g=s.jsxs(ws,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:b,children:[t.topContent,t.emptyState]}),e[5]=t.emptyState,e[6]=t.topContent,e[7]=b,e[8]=g):g=e[8],g}if(t.sectionsForRender.length===0){const 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 g;return e[11]!==t.searchEmptyState||e[12]!==b?(g=s.jsx(ws,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:b,children:t.searchEmptyState}),e[11]=t.searchEmptyState,e[12]=b,e[13]=g):g=e[13],g}const d=(t.mobileVariant,"");let 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(x=>x.project.id===t.activeProjectId)??t.sectionsForRender[0];if(!f)return t.hasSessionSearchQuery?t.searchEmptyState:t.emptyState;const b=f.groups.find(NP)??f.groups.find(jP)??f.groups.find(wP)??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 g=f.groups.find(vP);return[b,...g&&g.id!==b.id?[g]:[]].map(x=>{const h=`${f.project.id}:${x.id}`,j=x.id===b.id;return s.jsx(o.Fragment,{children:t.renderGroupSessions(x,h,f.project.id,j,null,!0)},h)})})()}):s.jsx(s.Fragment,{children:s.jsxs(so,{sensors:i,collisionDetection:no,onDragEnd:f=>{if(t.isInlineEditing)return;const{active:b,over:g}=f;if(!g||b.id===g.id)return;const v=t.sectionsForRender.findIndex(h=>h.project.id===b.id),x=t.sectionsForRender.findIndex(h=>h.project.id===g.id);v===-1||x===-1||v===x||t.reorderProjects(v,x)},children:[s.jsx(dl,{items:t.sectionsForRender.map(yP),strategy:Jc,children:t.sectionsForRender.map(f=>{const b=f.project,g=b.id,v=xh(b.label?.trim()||Ua(b.normalizedPath,t.homeDirectory)||b.normalizedPath),x=ao(b.normalizedPath,t.homeDirectory),h=t.collapsedProjects.has(g),j=g===t.activeProjectId,y=t.projectRepoStatus.get(g),C=t.getOrderedGroups(g,f.groups),k=C.find(bP)??null,w=k?C.filter(S=>S.id!==k.id):C;return s.jsx(cP,{id:g,projectLabel:v,projectDescription:x,projectIcon:b.icon,projectColor:b.color,projectIconImage:b.iconImage,projectIconBackground:b.iconBackground,isCollapsed:h,isActiveProject:j,isRepo:!!y,isDesktopShell:t.isDesktopShellRuntime,isStuck:t.stuckProjectHeaders.has(g),hideDirectoryControls:t.hideDirectoryControls,mobileVariant:t.mobileVariant,alwaysShowActions:t.alwaysShowActions,onToggle:()=>t.toggleProject(g),onNewSession:()=>{g!==t.activeProjectId&&t.setActiveProjectIdOnly(g),t.setActiveMainTab("chat"),t.mobileVariant&&t.setSessionSwitcherOpen(!1),t.openNewSessionDraft({directoryOverride:b.normalizedPath})},onNewWorktreeSession:()=>{g!==t.activeProjectId&&t.setActiveProjectIdOnly(g),t.setActiveMainTab("chat"),t.mobileVariant&&t.setSessionSwitcherOpen(!1),t.openNewWorktreeDialog()},onRenameStart:()=>t.openProjectEditDialog(g),onClose:()=>t.removeProject(g),sentinelRef:S=>{t.projectHeaderSentinelRefs.current.set(g,S)},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(so,{sensors:c,collisionDetection:no,onDragEnd:S=>{if(t.isInlineEditing)return;const{active:I,over:T}=S;if(!T||I.id===T.id)return;const P=w.findIndex(M=>M.id===I.id),A=w.findIndex(M=>M.id===T.id);if(P===-1||A===-1||P===A)return;const N=Bf(w,P,A).map(xP),E=k?[k.id,...N]:N;t.setGroupOrderByProject(M=>{const O=new Map(M);return O.set(g,E),O})},children:[k?t.renderGroupSessions(k,`${g}:${k.id}`,g,!0):null,s.jsx(dl,{items:w.map(gP),strategy:Jc,children:w.map(S=>{const I=`${g}:${S.id}`;return s.jsx(uP,{id:S.id,disabled:t.isInlineEditing,children:T=>t.renderGroupSessions(S,I,g,!1,T)},S.id)})}),s.jsx(ul,{dropAnimation:null})]}):s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:n("sessions.sidebar.empty.noSessions.title")})})},g)})}),s.jsx(ul,{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(ws,{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 gP(t){return t.id}function xP(t){return t.id}function bP(t){return t.isMain}function yP(t){return t.project.id}function vP(t){return t.isArchivedBucket}function wP(t){return t.isMain}function jP(t){return t.sessions.length>0}function NP(t){return t.isMain&&t.sessions.length>0}function SP(t){if(typeof t!="number"||!Number.isFinite(t))return"";const e=new Date(t);if(Number.isNaN(e.getTime()))return"";const n=e.toLocaleString(void 0,{month:"short"}),r=e.getDate(),a=e.getFullYear(),i=String(e.getHours()).padStart(2,"0"),l=String(e.getMinutes()).padStart(2,"0");return`${n} ${r}, ${a}, ${i}:${l}`}function kP(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 CP(t){const e=t.info.role==="user"?"User":"Assistant",n=SP(t.info.time?.created),r=kP(t),a=n&&r?`${n} (${r})`:n||r;return a?`**${e}**
|
|
188
|
-
|
|
189
|
-
*${a}*`:`**${e}**`}function IP(t){return t.filter(e=>e.type==="text"&&typeof e.text=="string").map(e=>e.text).join("")}function Fg(t){const e=CP(t),n=IP(t.parts).trim();return n?`${e}
|
|
190
|
-
|
|
191
|
-
${n}`:""}function Og(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(Fg).filter(Boolean).join(`
|
|
196
|
-
|
|
197
|
-
---
|
|
198
|
-
|
|
199
|
-
`),l=[a+i];for(const c of t.children)l.push(Og(c,e+1));return l.join(`
|
|
200
|
-
|
|
201
|
-
---
|
|
202
|
-
|
|
203
|
-
`)}function PP(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
|
-
`,l=t.map(Fg).filter(Boolean).join(`
|
|
210
|
-
|
|
211
|
-
---
|
|
212
|
-
|
|
213
|
-
`);let c=i+l;if(n&&n.length>0){const d=n.map(p=>Og(p,1)).join(`
|
|
214
|
-
|
|
215
|
-
---
|
|
216
|
-
|
|
217
|
-
`);c+=`
|
|
218
|
-
|
|
219
|
-
---
|
|
220
|
-
|
|
221
|
-
`+d}return c}function AP(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 DP(t,e){const n=await ky(e,t);if(n)return n;if(!mn())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 TP(t){const e=nr()?.files;if(e?.revealPath)try{return!!(await e.revealPath(t))?.success}catch{return!1}return await Cy(t)?!0:pl(t)}function MP(){return Bd()}function EP(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 RP=(t,e)=>{if(!e)return Array.from(t);const n=[],r=new Set;for(const a of t){r.has(a)||(r.add(a),n.push(a));const i=e.get(a);if(i)for(const l of i)r.has(l)||(r.add(l),n.push(l))}return n},hr=rr()((t,e)=>({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null,enable:()=>{e().enabled||t({enabled:!0})},disable:()=>{t({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null})},toggleMode:()=>{e().enabled?t({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null}):t({enabled:!0})},toggleSelected:(n,r,a)=>{const i=e(),l=new Set(i.selectedIds);let c=i.scopeKey,d=i.anchorId;r!==null&&i.scopeKey!==null&&r!==i.scopeKey?(l.clear(),c=r,d=null):c===null&&r!==null&&(c=r);const m=a&&a.length>0?[n,...a]:[n];if(l.has(n)){for(const f of m)l.delete(f);d===n&&(d=null)}else{for(const f of m)l.add(f);d=n}l.size===0?t({selectedIds:l,scopeKey:null,anchorId:null}):t({selectedIds:l,scopeKey:c,anchorId:d})},setRange:(n,r,a,i,l)=>{const c=e();if(a.length===0)return;const d=n&&a.includes(n)?n:a[0],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),g=RP(b,l),x=i!==null&&c.scopeKey!==null&&i!==c.scopeKey?new Set:new Set(c.selectedIds);for(const h of g)x.add(h);t({selectedIds:x,scopeKey:i??c.scopeKey,anchorId:d})},replaceAll:(n,r)=>{if(n.length===0){t({selectedIds:new Set,scopeKey:null,anchorId:null});return}t({selectedIds:new Set(n),scopeKey:r,anchorId:n[0]??null})},clear:()=>{t({selectedIds:new Set,scopeKey:null,anchorId:null})},removeMany:n=>{const r=e();if(r.selectedIds.size===0||n.length===0)return;const a=new Set(r.selectedIds);for(const i of n)a.delete(i);a.size!==r.selectedIds.size&&(a.size===0?t({selectedIds:a,scopeKey:null,anchorId:null}):t({selectedIds:a}))}})),FP=/^[a-z0-9](?:[a-z0-9-]{0,48}[a-z0-9])?$/,Lg=/^g[1-9]\d*$/,Vi=(t,e,n,r,a)=>{if(!FP.test(t)||e!==void 0&&!Lg.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}},ll=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 Vi(n,void 0,e[1],e[2],void 0);if(e.length===4){const[,c,d,p]=e;return Lg.test(c)?Vi(n,c,d,p,void 0):Vi(n,void 0,c,d,p)}const[,r,a,i,l]=e;return r===""?Vi(n,void 0,a,i,l):Vi(n,r,a,i,l)},OP=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("/")},LP=(t,e,n,r)=>{const a=[t];return r&&a.push(r),a.push(e,n,"fusion"),a.join("/")},$g=t=>{const e=ot.c(35),{value:n,onChange:r,className:a,disabled:i,id:l,portalToBody:c}=t,{t:d}=ut(),p=yt($P),m=yt(_P),u=yt(BP);let f;e[0]!==p?(f=p(),e[0]=p,e[1]=f):f=e[1];const b=f;let g;e[2]!==b?(g=b.filter(VP),e[2]=b,e[3]=g):g=e[3];const v=g;let x,h;e[4]!==m?(x=()=>{m()},h=[m],e[4]=m,e[5]=x,e[6]=h):(x=e[5],h=e[6]),o.useEffect(x,h);let j,y;e[7]!==u||e[8]!==i||e[9]!==r||e[10]!==v||e[11]!==n?(j=()=>{if(i)return;const N=n.trim();if(N.length>0&&v.some(O=>O.name===N))return;const E=typeof u=="string"&&u.trim().length>0?u.trim():null;if(E&&v.some(O=>O.name===E)){r(E);return}const M=v[0]?.name;M&&r(M)},y=[u,i,r,v,n],e[7]=u,e[8]=i,e[9]=r,e[10]=v,e[11]=n,e[12]=j,e[13]=y):(j=e[12],y=e[13]),o.useEffect(j,y);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 S;e[18]!==w?(S=s.jsx(us,{placeholder:w}),e[18]=w,e[19]=S):S=e[19];let I;e[20]!==l||e[21]!==k||e[22]!==S?(I=s.jsx(os,{id:l,size:"lg",className:k,children:S}),e[20]=l,e[21]=k,e[22]=S,e[23]=I):I=e[23];let T;e[24]!==v?(T=v.length>0&&s.jsx(td,{children:v.map(zP)}),e[24]=v,e[25]=T):T=e[25];let P;e[26]!==c||e[27]!==T?(P=s.jsx(ls,{fitContent:!0,portalToBody:c,children:T}),e[26]=c,e[27]=T,e[28]=P):P=e[28];let A;return e[29]!==i||e[30]!==r||e[31]!==C||e[32]!==I||e[33]!==P?(A=s.jsxs(is,{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]=A):A=e[34],A};function $P(t){return t.getVisibleAgents}function _P(t){return t.loadAgents}function BP(t){return t.currentAgentName}function VP(t){return t.mode!=="subagent"}function zP(t){return s.jsx(Mt,{value:t.name,className:"w-auto whitespace-nowrap",children:t.name},t.name)}const _g="h-7",Zi=()=>`${Date.now()}-${Math.random().toString(36).substring(2,9)}`,UP=t=>{const e=ot.c(12),{model:n,instanceIndex:r,totalSameModel:a,onRemove:i}=t,l=n.displayName||`${n.providerID}/${n.modelID}`,c=a>1?`${l} (${r})`:l;let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=ye("flex items-center gap-1.5 px-2 rounded-md bg-interactive-selection/20 border border-border/30",_g),e[0]=d):d=e[0];let p;e[1]!==n.providerID?(p=s.jsx(xr,{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(D,{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},Bg=t=>{const e=ot.c(117),{selectedModels:n,onAdd:r,onRemove:a,onUpdate:i,minModels:l,addButtonLabel:c,showChips:d,maxModels:p,addButtonClassName:m,dropdownSide:u,dropdownClassName:f,containerClassName:b,triggerIcon:g}=t,v=d===void 0?!0:d,x=u===void 0?"top":u,{t:h}=ut(),j=yt(WP),y=yt(KP),C=Re(HP),k=Re(GP),{favoriteModelsList:w,recentModelsList:S}=Jf(),[I,T]=o.useState(!1),[P,A]=o.useState(""),[N,E]=o.useState(null),M=o.useRef(null),O=o.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 le=`${U.providerID}:${U.modelID}`;$.set(le,($.get(le)||0)+1)}e[0]=n,e[1]=$}else $=e[1];const F=$;let _;e[2]!==n?(_=U=>n.filter(Me=>Me.providerID===U.providerID&&Me.modelID===U.modelID).findIndex(Me=>Me.instanceId===U.instanceId)+1,e[2]=n,e[3]=_):_=e[3];const q=_;let L,Y;e[4]!==x||e[5]!==I?(L=()=>{if(!I||!O.current)return;const U=O.current.getBoundingClientRect();if(x==="bottom"){const De=(window.visualViewport?.height??document.documentElement.clientHeight??window.innerHeight)-U.bottom-16-112;E(Math.max(160,Math.min(320,De)));return}let le=O.current.parentElement;for(;le&&!(le.getAttribute("role")==="dialog"||le.hasAttribute("data-scroll-shadow"));){const Ae=getComputedStyle(le);if(Ae.overflow==="auto"||Ae.overflow==="hidden"||Ae.overflowY==="auto"||Ae.overflowY==="hidden")break;le=le.parentElement}const Me=le?le.getBoundingClientRect().top:0,Oe=U.top-Me-16;E(Math.max(150,Math.min(300,Oe)))},Y=[x,I],e[4]=x,e[5]=I,e[6]=L,e[7]=Y):(L=e[6],Y=e[7]),o.useEffect(L,Y);let Z,ae;e[8]!==B||e[9]!==I?(Z=()=>{!B&&I&&(T(!1),A(""))},ae=[B,I],e[8]=B,e[9]=I,e[10]=Z,e[11]=ae):(Z=e[10],ae=e[11]),o.useEffect(Z,ae);let re,me;e[12]!==I?(re=()=>{if(!I)return;const U=le=>{M.current&&!M.current.contains(le.target)&&(T(!1),A(""))};return document.addEventListener("mousedown",U),()=>document.removeEventListener("mousedown",U)},me=[I],e[12]=I,e[13]=re,e[14]=me):(re=e[13],me=e[14]),o.useEffect(re,me);let fe;e[15]!==V||e[16]!==r||e[17]!==i||e[18]!==n.length?(fe=U=>{const le={providerID:U.providerID,modelID:U.modelID,displayName:U.model.name||U.modelID,instanceId:Zi()};V&&n.length>0&&i?i(0,le):r(le),V&&(T(!1),A(""))},e[15]=V,e[16]=r,e[17]=i,e[18]=n.length,e[19]=fe):fe=e[19];const H=fe;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 be;e[28]!==h?(be=h("multirun.modelMultiSelect.keyboard.hint"),e[28]=h,e[29]=be):be=e[29];let we;e[30]!==h?(we=h("settings.agents.modelSelector.actions.favorite"),e[30]=h,e[31]=we):we=e[31];let te;e[32]!==h?(te=h("settings.agents.modelSelector.actions.unfavorite"),e[32]=h,e[33]=te):te=e[33];let ge;e[34]!==h?(ge=h("chat.modelControls.capabilities"),e[34]=h,e[35]=ge):ge=e[35];let ue;e[36]!==h?(ue=h("chat.modelControls.capability.toolCalling"),e[36]=h,e[37]=ue):ue=e[37];let xe;e[38]!==h?(xe=h("chat.modelControls.capability.reasoning"),e[38]=h,e[39]=xe):xe=e[39];let ne;e[40]!==h?(ne=h("chat.modelControls.input"),e[40]=h,e[41]=ne):ne=e[41];let pe;e[42]!==h?(pe=h("chat.modelControls.output"),e[42]=h,e[43]=pe):pe=e[43];let J;e[44]!==h?(J=h("chat.modelControls.costPerMillion"),e[44]=h,e[45]=J):J=e[45];let Se;e[46]!==K||e[47]!==Q||e[48]!==W||e[49]!==de||e[50]!==be||e[51]!==we||e[52]!==te||e[53]!==ge||e[54]!==ue||e[55]!==xe||e[56]!==ne||e[57]!==pe||e[58]!==J?(Se={searchPlaceholder:K,noResults:Q,favorites:W,recent:de,keyboardHint:be,favorite:we,unfavorite:te,capabilities:ge,capabilityToolCalling:ue,capabilityReasoning:xe,input:ne,output:pe,costPerMillion:J},e[46]=K,e[47]=Q,e[48]=W,e[49]=de,e[50]=be,e[51]=we,e[52]=te,e[53]=ge,e[54]=ue,e[55]=xe,e[56]=ne,e[57]=pe,e[58]=J,e[59]=Se):Se=e[59];const he=Se;let Ie;e[60]!==b?(Ie=ye("relative",b),e[60]=b,e[61]=Ie):Ie=e[61];let Pe;e[62]!==m?(Pe=ye(_g,"!border-border/80 !bg-[var(--surface-subtle)] hover:!bg-[var(--interactive-hover)]/70",m),e[62]=m,e[63]=Pe):Pe=e[63];const Ce=!B;let X;e[64]!==I?(X=()=>{T(!I)},e[64]=I,e[65]=X):X=e[65];let ie;e[66]!==g?(ie=g??s.jsx(D,{name:"add",className:"h-3.5 w-3.5 mr-1"}),e[66]=g,e[67]=ie):ie=e[67];let Ne;e[68]!==c||e[69]!==h?(Ne=c??h("multirun.modelMultiSelect.actions.addModel"),e[68]=c,e[69]=h,e[70]=Ne):Ne=e[70];let oe;e[71]!==Pe||e[72]!==Ce||e[73]!==X||e[74]!==ie||e[75]!==Ne?(oe=s.jsxs(ve,{ref:O,type:"button",variant:"outline",size:"sm",className:Pe,disabled:Ce,onClick:X,children:[ie,Ne]}),e[71]=Pe,e[72]=Ce,e[73]=X,e[74]=ie,e[75]=Ne,e[76]=oe):oe=e[76];let ke;e[77]!==N||e[78]!==B||e[79]!==f||e[80]!==x||e[81]!==w||e[82]!==H||e[83]!==k||e[84]!==I||e[85]!==he||e[86]!==F||e[87]!==y||e[88]!==j||e[89]!==S||e[90]!==P||e[91]!==C?(ke=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",x==="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(Xf,{providers:j,favoriteModels:w,recentModels:S,modelsMetadata:y,searchQuery:P,onSearchQueryChange:A,onSelect:H,labels:he,selectionCount:U=>F.get(`${U.providerID}:${U.modelID}`)||0,disabled:!B,maxHeightClassName:"flex-1",maxHeightStyle:{maxHeight:N?`${N}px`:"300px"},stickyHeaders:!0,tooltipsEnabled:I,isFavorite:U=>k(U.providerID,U.modelID),onToggleFavorite:U=>C(U.providerID,U.modelID),onEscape:()=>{T(!1),A("")}})}):null,e[77]=N,e[78]=B,e[79]=f,e[80]=x,e[81]=w,e[82]=H,e[83]=k,e[84]=I,e[85]=he,e[86]=F,e[87]=y,e[88]=j,e[89]=S,e[90]=P,e[91]=C,e[92]=ke):ke=e[92];let Te;e[93]!==Ie||e[94]!==oe||e[95]!==ke?(Te=s.jsxs("div",{className:Ie,ref:M,children:[oe,ke]}),e[93]=Ie,e[94]=oe,e[95]=ke,e[96]=Te):Te=e[96];let Be;e[97]!==q||e[98]!==F||e[99]!==a||e[100]!==i||e[101]!==j||e[102]!==n||e[103]!==v||e[104]!==h?(Be=v&&n.length>0&&s.jsx("div",{className:"flex flex-col gap-2 w-full",children:n.map((U,le)=>{const Me=`${U.providerID}:${U.modelID}`,Oe=F.get(Me)||1,Ae=q(U),De=j.find(Ue=>Ue.id===U.providerID)?.models?.find(Ue=>Ue.id===U.modelID),Xe=De?.variants?Object.keys(De.variants):[],st=Xe.length>0,tt=U.variant??"__default__";return s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(UP,{model:U,instanceIndex:Ae,totalSameModel:Oe,onRemove:()=>a(le)}),st&&s.jsxs(is,{value:tt,onValueChange:Ue=>{if(!i)return;i(le,{...U,variant:Ue==="__default__"?void 0:Ue})},children:[s.jsxs(os,{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(D,{name:"brain-ai-3",className:ye("h-3.5 w-3.5 flex-shrink-0",tt==="__default__"?"text-muted-foreground":"text-[color:var(--status-info)]")}),s.jsx(us,{placeholder:h("multirun.modelMultiSelect.variant.placeholder"),children:Ue=>Ue==="__default__"?h("multirun.modelMultiSelect.variant.default"):Ue})]}),s.jsxs(ls,{fitContent:!0,children:[s.jsx(Mt,{value:"__default__",className:"pr-2 [&>span:first-child]:hidden",children:h("multirun.modelMultiSelect.variant.default")}),Xe.map(qP)]})]})]},U.instanceId)})}),e[97]=q,e[98]=F,e[99]=a,e[100]=i,e[101]=j,e[102]=n,e[103]=v,e[104]=h,e[105]=Be):Be=e[105];let je;e[106]!==Te||e[107]!==Be?(je=s.jsxs("div",{className:"flex flex-wrap gap-1.5 items-center",children:[Te,Be]}),e[106]=Te,e[107]=Be,e[108]=je):je=e[108];let ee;e[109]!==p||e[110]!==l||e[111]!==n.length||e[112]!==h?(ee=l!==void 0&&n.length<l&&s.jsx("p",{className:"typography-micro text-muted-foreground",children:p!==void 0?h("multirun.modelMultiSelect.validation.minToMax",{min:l,max:p}):h("multirun.modelMultiSelect.validation.minOnly",{min:l})}),e[109]=p,e[110]=l,e[111]=n.length,e[112]=h,e[113]=ee):ee=e[113];let R;return e[114]!==je||e[115]!==ee?(R=s.jsxs("div",{className:"space-y-2",children:[je,ee]}),e[114]=je,e[115]=ee,e[116]=R):R=e[116],R};function WP(t){return t.providers}function KP(t){return t.modelsMetadata}function HP(t){return t.toggleFavoriteModel}function GP(t){return t.isFavoriteModel}function qP(t){return s.jsx(Mt,{value:t,className:"pr-2 [&>span:first-child]:hidden",children:t},t)}const YP=(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} ---`},bf=(t,e)=>$t.getState().getWorktreeMetadata(t)?.projectDirectory??e,QP=async t=>{const e=t.directory??void 0,n=Iy(t.session.id,e);if(n.length===0&&t.directory){const a=(await nn.withDirectory(t.directory,()=>nn.getSdkClient().session.messages({sessionID:t.session.id,directory:t.directory??void 0,limit:50}))).data??[];for(let i=a.length-1;i>=0;i-=1){const l=a[i];if(l.info?.role==="assistant")return zu(l.parts??[]).trim()}return""}for(let r=n.length-1;r>=0;r-=1){const a=n[r];if(a.role==="assistant")return zu(Py(a.id,e)).trim()}return""};function JP({session:t,open:e,onOpenChange:n}){const{t:r}=ut(),a=Td(),i=Oa($=>$.activeSessions),l=Oa($=>$.archivedSessions),c=yt($=>$.providers),d=yt($=>$.currentProviderId),p=yt($=>$.currentModelId),m=yt($=>$.currentAgentName),[u,f]=o.useState(d??""),[b,g]=o.useState(p??""),[v,x]=o.useState(()=>d&&p?[{providerID:d,modelID:p,instanceId:Zi()}]:[]),[h,j]=o.useState(""),[y,C]=o.useState(m??""),[k,w]=o.useState([]),[S,I]=o.useState(!1),T=o.useMemo(()=>ll(t.title),[t.title]),P=o.useMemo(()=>{const $=new Map;for(const F of a)$.set(F.id,F);for(const F of i)$.set(F.id,F);for(const F of l)$.set(F.id,F);return t.id&&$.set(t.id,t),Array.from($.values())},[i,l,a,t]);o.useEffect(()=>{if(!e||!T)return;const $=$t.getState().getDirectoryForSession(t.id),F=bf(t.id,$),_=P.map(q=>{const L=ll(q.title);if(!L||L.groupSlug!==T.groupSlug||L.fusion||(L.runGroup??null)!==(T.runGroup??null))return null;const Y=$t.getState().getDirectoryForSession(q.id)??qi(q),Z=bf(q.id,Y);return F&&Z&&F!==Z?null:{session:q,directory:Y,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 N=c.find($=>$.id===u)?.models.find($=>$.id===b),E=N?.variants?Object.keys(N.variants):[],M=!!(T&&u&&b&&k.length>0&&!S),O=o.useCallback($=>{x([$]),f($.providerID),g($.modelID),j("")},[]),V=v[0]?.displayName||v[0]?.modelID||r("multirun.fusion.model.placeholder"),B=async()=>{if(!(!T||!u||!b)){I(!0);try{const $=await Promise.all(k.map(ae=>QP(ae))),F=k.map((ae,re)=>({source:ae,text:$[re]??""})).filter(ae=>ae.text.trim().length>0);if(F.length===0){G.error(r("multirun.fusion.toast.noOutputs"));return}const _=k[0]?.projectDirectory??k[0]?.directory??null,q=LP(T.groupSlug,u,b,T.runGroup),[L,Y]=await Promise.all([kn("session.fusion.visible"),kn("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 nn.withDirectory(_??nn.getDirectory(),()=>nn.sendMessage({id:Z.id,providerID:u,modelID:b,variant:h||void 0,agent:y||void 0,text:L,additionalParts:[{text:Y,synthetic:!0},...F.map((ae,re)=>({text:YP(ae.source,ae.text,re),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",$),G.error(r("multirun.fusion.toast.failed"))}finally{I(!1)}}};return s.jsx(ps,{open:e,onOpenChange:n,children:s.jsxs(ms,{className:"max-w-xl overflow-visible",children:[s.jsxs(gs,{children:[s.jsx(fs,{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(Bg,{selectedModels:v,onAdd:O,onUpdate:($,F)=>O(F),onRemove:()=>{x([]),f(""),g(""),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(xr,{providerId:u,className:"h-3.5 w-3.5 mr-1"}):void 0})}),E.length>0?s.jsxs(is,{value:h||"__default__",onValueChange:$=>j($==="__default__"?"":$),children:[s.jsxs(os,{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(D,{name:"brain-ai-3",className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx(us,{children:$=>$==="__default__"?r("multirun.modelMultiSelect.variant.default"):$})]}),s.jsxs(ls,{fitContent:!0,portalToBody:!0,children:[s.jsx(Mt,{value:"__default__",children:r("multirun.modelMultiSelect.variant.default")}),E.map($=>s.jsx(Mt,{value:$,children:$},$))]})]}):null,s.jsx($g,{value:y,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(xr,{providerId:ll($.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(F=>F.filter(_=>_.session.id!==$.session.id)),className:"text-muted-foreground hover:text-foreground",children:s.jsx(D,{name:"close",className:"h-4 w-4"})})]},$.session.id))})]}),s.jsxs(Hs,{children:[s.jsx(ve,{variant:"ghost",onClick:()=>n(!1),children:r("multirun.fusion.actions.cancel")}),s.jsx(ve,{onClick:B,disabled:!M,children:r(S?"multirun.fusion.actions.starting":"multirun.fusion.actions.start")})]})]})})}function XP(t){const e=ot.c(7);let n,r,a,i,l;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx("path",{d:"M12 4.5v6.25M12 10.75v3.5M12 10.75H7.25A3.25 3.25 0 0 0 4 14v1.25M12 10.75h4.75A3.25 3.25 0 0 1 20 14v1.25",stroke:"currentColor",strokeWidth:"1.65",strokeLinecap:"round",strokeLinejoin:"round"}),r=s.jsx("path",{d:"M9.25 7.25 12 4.5l2.75 2.75",stroke:"currentColor",strokeWidth:"1.65",strokeLinecap:"round",strokeLinejoin:"round"}),a=s.jsx("circle",{cx:"4",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),i=s.jsx("circle",{cx:"12",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),l=s.jsx("circle",{cx:"20",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),e[0]=n,e[1]=r,e[2]=a,e[3]=i,e[4]=l):(n=e[0],r=e[1],a=e[2],i=e[3],l=e[4]);let c;return e[5]!==t?(c=s.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",...t,children:[n,r,a,i,l]}),e[5]=t,e[6]=c):c=e[6],c}const yf=t=>t.children.length===0?"":t.children.map(e=>`${e.session.id}:${e.children.length}`).join("|"),Da=(t,e)=>{if(!e)return!1;if(t.session.id===e)return!0;for(const n of t.children)if(Da(n,e))return!0;return!1},Cd=(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(Cd(i,e,n,r))return!0;return!1},ZP=(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||yf(t.node)!==yf(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=Da(t.node,t.currentSessionId),u=Da(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,g=`${m}:${f?"archived":"active"}:${a}`,v=`${u}:${b?"archived":"active"}:${i}`;if(t.expandedParents.has(g)!==e.expandedParents.has(v))return!1}if(t.hasSessionSearchQuery!==e.hasSessionSearchQuery||t.normalizedSessionSearchQuery!==e.normalizedSessionSearchQuery||t.notifyOnSubtasks!==e.notifyOnSubtasks)return!1;if(t.editingId!==e.editingId){const m=Da(t.node,t.editingId),u=Da(e.node,e.editingId);if(m||u)return!1}if(t.editTitle!==e.editTitle){const m=Da(t.node,t.editingId),u=Da(e.node,e.editingId);if(m||u)return!1}if(t.copiedSessionId===a!=(e.copiedSessionId===i))return!1;const l=Cd(t.node,t.openSidebarMenuKey,t.renderContext??"project",t.archivedBucket??!1),c=Cd(e.node,e.openSidebarMenuKey,e.renderContext??"project",e.archivedBucket??!1);if(l!==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 eA(t){const{t:e}=ut(),{node:n,depth:r=0,groupDirectory:a,projectId:i,archivedBucket:l=!1,directoryStatus:c,currentSessionId:d,pinnedSessionIds:p,expandedParents:m,hasSessionSearchQuery:u,normalizedSessionSearchQuery:f,notifyOnSubtasks:b,editingId:g,setEditingId:v,editTitle:x,setEditTitle:h,handleSaveEdit:j,handleCancelEdit:y,toggleParent:C,handleSessionSelect:k,handleSessionDoubleClick:w,togglePinnedSession:S,handleShareSession:I,copiedSessionId:T,handleCopyShareUrl:P,handleUnshareSession:A,openSidebarMenuKey:N,setOpenSidebarMenuKey:E,renamingFolderId:M,getFoldersForScope:O,getSessionFolderId:V,removeSessionFromFolder:B,addSessionToFolder:$,createFolderAndStartRename:F,openContextPanelTab:_,handleDeleteSession:q,mobileVariant:L,alwaysShowActions:Y,renderSessionNode:Z,secondaryMeta:ae,renderContext:re="project"}=t,me=!!ae?.projectLabel,fe=!!ae?.branchLabel,K=Fa(lt=>lt.displayMode)==="minimal",Q=o.useMemo(()=>mn(),[]),W=o.useMemo(()=>Md(),[]),de=o.useContext(Ay),be=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",we=Q?"group-hover:opacity-0":"group-hover:opacity-0 group-focus-within:opacity-0",te=Q,ge=!l&&!L,ue=K?Q?"group-hover:pr-2":"group-hover:pr-2 group-focus-within:pr-2":Q?ge&&te?"group-hover:pr-18":ge||te?"group-hover:pr-12":"group-hover:pr-5":ge?"group-hover:pr-12 group-focus-within:pr-12":"group-hover:pr-5 group-focus-within:pr-5",xe=ge?"pr-13":"pr-7",ne=o.useRef(!1),pe=o.useRef(!1),[J,Se]=o.useState(!1),he=n.session,Pe=Hf(he.id)??he,Ce=bs(he.directory??null)??bs(a??null),X=Dy(Ce??void 0),ie=Kd(),Ne=hr(lt=>lt.enabled),oe=hr(o.useCallback(lt=>lt.selectedIds.has(he.id),[he.id])),ke=hr(lt=>lt.toggleSelected),Te=hr(lt=>lt.setRange),Be=o.useCallback(lt=>{const ss=[],cs=Ke=>{Ke.children.forEach(xt=>{ss.push(xt.session.id),cs(xt)})};return cs(lt),ss},[]),[je,ee]=o.useState(!1),[R,U]=o.useState(!0),le=`${re}:${l?"archived":"active"}:${he.id}`,Me=bh(o.useCallback(lt=>!!lt.sessionMemoryState.get(he.id)?.isZombie,[he.id])),Oe=Ty(he.id),Ae=My(he.id,Ce??void 0),De=(Ce?c.get(Ce):null)==="missing",Xe=d===he.id,st=Pe.title||e("sessions.sidebar.session.untitled"),tt=n.children.length>0,Ue=p.has(he.id),it=le,Ye=u?!0:m.has(it),rt=!!Pe.parentID,ce=Ey(he.id)>0&&(!rt||b),We=Pe.summary,Le=Yf(We),Ge=Pe.time?.updated||Pe.time?.created||Date.now(),at=Ry(Ge),He=$y(Ge),ze=N===le,et=o.useMemo(()=>ll(Pe.title)!==null,[Pe.title]),[gt,Pt]=o.useState(!1),Nt=o.useMemo(()=>Be(n).length,[Be,n]),ht=o.useCallback(async lt=>{const ss=[];let cs=0;for(const Ke of lt)try{await ie.ensureSessionRenderable(Ke.session.id);const xt=Uu(X.getState(),Ke.session.id).list,Tt=Ke.session.title||e("sessions.sidebar.session.export.untitledSubagent"),Et=Ke.session.agent,Qt=await ht(Ke.children);cs+=Qt.skipped,ss.push({title:Tt,agent:Et,records:xt,children:Qt.children})}catch{cs+=Be(Ke).length+1}return{children:ss,skipped:cs}},[Be,X,ie,e]),wt=o.useCallback(lt=>{lt<=0||G.warning(lt===1?e("sessions.sidebar.session.export.skippedSubtaskSingle",{count:lt}):e("sessions.sidebar.session.export.skippedSubtaskMany",{count:lt}))},[e]),es=o.useCallback(async lt=>{if(!Ce){G.error(e("sessions.sidebar.session.export.nothingToExport"));return}await ie.ensureSessionRenderable(he.id);const ss=Uu(X.getState(),he.id).list;if(ss.length===0){G.error(e("sessions.sidebar.session.export.nothingToExport"));return}let cs,Ke=0;if(lt&&n.children.length>0){const Qt=await ht(n.children);cs=Qt.children,Ke=Qt.skipped}const xt=PP(ss,Pe.title??null,cs),Tt=EP(Pe.title??null),Et=await DP(xt,Tt);if(Et){G.success(e("sessions.sidebar.session.export.success"),{action:{label:e(MP()),onClick:()=>{TP(Et).then(Qt=>{Qt||G.error(e("sessions.sidebar.session.export.failedRevealPath"))})}}}),wt(Ke);return}AP(xt,Tt),G.success(e("sessions.sidebar.session.export.success")),wt(Ke)},[ht,X,n.children,Pe.title,he.id,Ce,wt,ie,e]),Vt=o.useCallback(async()=>{if(n.children.length>0){U(!0),ee(!0);return}await es(!1)},[es,n.children.length]),Jt=o.useCallback(()=>{Ce&&fl("desktop_open_session_mini_chat_window",{sessionId:he.id,directory:Ce}).catch(lt=>{console.warn("[session-sidebar] failed to open mini chat window",lt)})},[he.id,Ce]);if(g===he.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:lt=>{lt.preventDefault(),j()},children:[s.jsx("input",{value:x,onChange:lt=>h(lt.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:lt=>{if(lt.key==="Escape"){lt.stopPropagation(),pe.current=!0,y();return}(lt.key===" "||lt.key==="Enter")&<.stopPropagation()},onBlur:()=>{if(pe.current){pe.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(D,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:y,"aria-label":e("sessions.sidebar.session.rename.cancel"),title:e("sessions.sidebar.session.rename.cancel"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(D,{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:[tt?s.jsx("span",{className:"inline-flex items-center justify-center flex-shrink-0",children:Ye?s.jsx(D,{name:"arrow-down-s",className:"h-3 w-3"}):s.jsx(D,{name:"arrow-right-s",className:"h-3 w-3"})}):null,s.jsx("span",{className:"flex-shrink-0",children:at}),Le?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:["+",Le.additions]}),s.jsxs("span",{className:"text-status-error/65",children:["/-",Le.deletions]})]}):null,me?s.jsx("span",{className:"truncate",children:ae?.projectLabel}):null,fe?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(D,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:ae?.branchLabel})]}):null]})})]})},he.id);const mt=Oe?.type??"idle",Lt=mt==="busy"||mt==="retry",ts=Ae.length,ds=Lt||!Lt&&ce&&!Xe,hs=Lt?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=ds||Ue?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",ds&&Ue?"left-[-18px] w-6":"left-[-10px] w-3.5",tt&&!Y?"opacity-100 group-hover:opacity-0 group-focus-within:opacity-0":""),children:[ds?hs:null,Ue?s.jsx(D,{name:"pushpin",className:"h-3 w-3 flex-shrink-0 text-primary","aria-label":e("sessions.sidebar.session.status.pinned")}):null]}):null,Qe=tt?s.jsx("span",{role:"button",tabIndex:0,onClick:lt=>{lt.stopPropagation(),C(it)},onKeyDown:lt=>{(lt.key==="Enter"||lt.key===" ")&&(lt.preventDefault(),lt.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&&ds&&!Y?"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(Ye?"sessions.sidebar.session.subsessions.collapse":"sessions.sidebar.session.subsessions.expand"),children:Ye?s.jsx(D,{name:"arrow-down-s",className:"h-3 w-3"}):s.jsx(D,{name:"arrow-right-s",className:"h-3 w-3"})}):null,At=Me?s.jsx(D,{name:"error-warning",className:"h-4 w-4 text-status-warning"}):null,Ht=lt=>{E(lt?le:null)},jt=lt=>{lt.preventDefault(),lt.stopPropagation(),E(ze?null:le)},Zt=lt=>{lt.preventDefault(),lt.stopPropagation()},rs=lt=>{lt.preventDefault(),lt.stopPropagation()},Ds=lt=>{lt.preventDefault(),lt.stopPropagation()},ns=lt=>{lt.preventDefault(),lt.stopPropagation()},zs=lt=>{lt.preventDefault(),lt.stopPropagation(),E(null),q(he,{archivedBucket:l})},$s=lt=>{lt.preventDefault(),lt.stopPropagation()},gn=lt=>{lt.preventDefault(),lt.stopPropagation()},rn=lt=>{lt.preventDefault(),lt.stopPropagation(),de?.vscode?.executeCommand("openchamber.openSessionInEditor",he.id,st)},Wt=lt=>{if(ne.current){ne.current=!1;return}if(Ne){if(lt?.preventDefault(),lt?.stopPropagation(),lt?.shiftKey){const cs=(typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[]).map(Tt=>Tt.getAttribute("data-session-row")).filter(Tt=>typeof Tt=="string"&&Tt.length>0),Ke=hr.getState().anchorId,xt=new Map;xt.set(he.id,Be(n)),Te(Ke,he.id,cs,Ce??null,xt);return}ke(he.id,Ce??null,Be(n));return}k(he.id,Ce,De,i)},Kt=lt=>{(lt.button===2||lt.button===0&<.ctrlKey&&!Ne)&&(ne.current=!0)},se=lt=>{L&<.pointerType==="touch"&&Se(!0)},bt=lt=>{L&<.pointerType==="touch"&&Se(!1)},_t=s.jsxs(Ps,{align:"end",className:"min-w-[180px]",onCloseAutoFocus:lt=>{M&<.preventDefault()},children:[s.jsxs(Ot,{onClick:()=>{v(he.id),h(st)},className:"[&>svg]:mr-1",children:[s.jsx(D,{name:"pencil-ai",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.rename")]}),s.jsxs(Ot,{onClick:()=>S(he.id),className:"[&>svg]:mr-1",children:[Ue?s.jsx(D,{name:"unpin",className:"mr-1 h-4 w-4"}):s.jsx(D,{name:"pushpin",className:"mr-1 h-4 w-4"}),e(Ue?"sessions.sidebar.session.menu.unpin":"sessions.sidebar.session.menu.pin")]}),Pe.share?s.jsxs(s.Fragment,{children:[s.jsx(Ot,{onClick:()=>{Pe.share?.url&&P(Pe.share.url,he.id)},className:"[&>svg]:mr-1",children:T===he.id?s.jsxs(s.Fragment,{children:[s.jsx(D,{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(D,{name:"file-copy",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.copyLink")]})}),s.jsxs(Ot,{onClick:()=>A(he.id),className:"[&>svg]:mr-1",children:[s.jsx(D,{name:"link-unlink-m",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.unshare")]})]}):s.jsxs(Ot,{onClick:()=>I(Pe),className:"[&>svg]:mr-1",children:[s.jsx(D,{name:"share-2",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.share")]}),s.jsxs(Ot,{onClick:()=>{Vt()},className:"[&>svg]:mr-1",children:[s.jsx(D,{name:"download",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.exportMarkdown")]}),et?s.jsxs(Ot,{onClick:()=>Pt(!0),className:"[&>svg]:mr-1",children:[s.jsx(XP,{className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.runFusion")]}):null,Ce&&!l?(()=>{const lt=O(Ce),ss=V(Ce,he.id);return s.jsxs(s.Fragment,{children:[s.jsx(Xn,{}),s.jsxs(Fy,{children:[s.jsxs(Oy,{className:"[&>svg]:mr-1",children:[s.jsx(D,{name:"folder",className:"h-4 w-4"}),e("sessions.sidebar.folders.moveToFolder")]}),s.jsxs(Ly,{className:"min-w-[180px]",children:[lt.length===0?s.jsx(Ot,{disabled:!0,className:"text-muted-foreground",children:e("sessions.sidebar.folders.none")}):lt.map(cs=>s.jsxs(Ot,{onClick:()=>{ss===cs.id?B(Ce,he.id):$(Ce,cs.id,he.id)},children:[s.jsx("span",{className:"flex-1 truncate",children:cs.name}),ss===cs.id?s.jsx(D,{name:"check",className:"ml-2 h-3.5 w-3.5 text-primary flex-shrink-0"}):null]},cs.id)),s.jsx(Xn,{}),s.jsxs(Ot,{onClick:()=>{const cs=F(Ce);cs&&$(Ce,cs.id,he.id)},children:[s.jsx(D,{name:"add",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.newFolderEllipsis")]}),ss?s.jsxs(Ot,{onClick:()=>{B(Ce,he.id)},className:"text-destructive focus:text-destructive",children:[s.jsx(D,{name:"close",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.removeFromFolder")]}):null]})]})]})})():null,Q?null:s.jsxs(Ot,{disabled:!Ce,onClick:()=>{Ce&&_(Ce,{mode:"chat",dedupeKey:`session:${he.id}`,label:st})},className:"[&>svg]:mr-1",children:[s.jsx(D,{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(Ot,{disabled:!Ce,onClick:Jt,className:"[&>svg]:mr-1",children:[s.jsx(D,{name:"window",className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:e("sessions.sidebar.session.menu.openMiniChatWindow")})]}):null,s.jsx(Xn,{}),s.jsxs(Ot,{className:"text-destructive focus:text-destructive [&>svg]:mr-1",onClick:()=>q(he,{archivedBucket:l}),children:[s.jsx(D,{name:"delete-bin",className:"mr-1 h-4 w-4"}),e(l?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive")]})]});return s.jsxs(o.Fragment,{children:[s.jsx(q6,{sessionId:he.id,sessionDirectory:Ce??null,sessionTitle:st,children:s.jsxs("div",{"data-session-row":he.id,"data-session-scope":Ce??"","data-session-archived":l?"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]",oe&&"bg-primary/15"),children:[Ut,Qe,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:se,onPointerUp:bt,onPointerCancel:bt,onMouseDown:Kt,onClick:lt=>Wt(lt),onDoubleClick:lt=>{lt.stopPropagation(),w(he.id,st)},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]",J&&"bg-interactive-hover/70",Y?Q?ue:xe:ue),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",Xe?"text-primary":"text-foreground"),children:Yi(st,f)}),Y?s.jsx("span",{className:"ml-2 flex-shrink-0 text-[0.72rem] text-muted-foreground/75",children:He}):null,Y?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":we),children:He})}),ts>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(D,{name:"shield",className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:ts})]}):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",ae?.projectLabel?"justify-between":"justify-start"),children:[ae?.projectLabel?s.jsx("div",{className:"min-w-0 truncate",children:ae.projectLabel}):null,s.jsx("div",{className:"flex-shrink-0",children:at})]}),ae?.branchLabel||Le?s.jsxs("div",{className:ye("flex items-center gap-3 text-left text-muted-foreground",ae?.branchLabel?"justify-between":"justify-start"),children:[ae?.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(D,{name:"git-branch",className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:ae.branchLabel})]})}):null,Le?s.jsxs("span",{className:"flex flex-shrink-0 items-center gap-0.5",children:[s.jsxs("span",{className:"text-status-success",children:["+",Le.additions]}),s.jsxs("span",{className:"text-status-error",children:["-",Le.deletions]})]}):null]}):null]})})]}):s.jsxs("button",{type:"button",disabled:De,onPointerDown:se,onPointerUp:bt,onPointerCancel:bt,onMouseDown:Kt,onClick:lt=>Wt(lt),onDoubleClick:lt=>{lt.stopPropagation(),w(he.id,st)},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]",J&&"bg-interactive-hover/70",Y?Q?ue:xe:ue),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",Xe?"text-primary":"text-foreground"),children:Yi(st,f)}),ts>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(D,{name:"shield",className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:ts})]}):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:at}),Le?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:["+",Le.additions]}),s.jsx("span",{className:"text-muted-foreground/60",children:"/"}),s.jsxs("span",{className:"text-status-error/65",children:["-",Le.deletions]})]}):null,me?s.jsx("span",{className:"truncate",children:ae?.projectLabel}):null,fe?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(D,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:ae?.branchLabel})]}):null]})})]})}),At&&!L?s.jsx("div",{className:ye("absolute top-1/2 -translate-y-1/2 z-10",K?"right-0":"right-[30px]"),children:At}):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||Y&&!Q?"opacity-100":ye("opacity-0",be)),children:[ge?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&&!Y?"h-4 w-4":"h-6 w-6"),"aria-label":e("sessions.sidebar.bulkActions.archive"),onPointerDown:Ds,onMouseDown:ns,onClick:zs,onKeyDown:lt=>lt.stopPropagation(),children:s.jsx(D,{name:"archive",className:ye(K&&!Y?"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&&!Y?"h-4 w-4":"h-6 w-6"),"aria-label":e("sessions.sidebar.session.actions.openInEditor"),onPointerDown:$s,onMouseDown:gn,onClick:rn,onKeyDown:lt=>lt.stopPropagation(),children:s.jsx(D,{name:"external-link",className:ye(K&&!Y?"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:Ht,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&&!Y?ze?"h-4 w-4 opacity-100":ye("h-4 w-4 opacity-0",be):"h-6 w-6 opacity-100"),"aria-label":e("sessions.sidebar.session.menu.label"),onPointerDown:Zt,onMouseDown:rs,onClick:jt,onKeyDown:lt=>lt.stopPropagation(),children:s.jsx(D,{name:"more-2",className:ye(K&&!Y?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),_t]})]})]})}),tt&&Ye?n.children.map(lt=>Z(lt,r+1,Ce??a,i,l,void 0,re)):null,s.jsx(ps,{open:je,onOpenChange:ee,children:s.jsxs(ms,{showCloseButton:!1,className:"max-w-sm gap-5",children:[s.jsxs(gs,{children:[s.jsx(fs,{children:e("sessions.sidebar.session.export.dialog.title")}),s.jsx(Ns,{children:Nt===1?e("sessions.sidebar.session.export.dialog.descriptionSingle",{count:Nt}):e("sessions.sidebar.session.export.dialog.descriptionMany",{count:Nt})})]}),s.jsxs("label",{className:"flex items-center gap-2 typography-ui-label cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:R,onChange:lt=>U(lt.target.checked),className:"h-4 w-4 rounded border-border accent-primary"}),e("sessions.sidebar.session.export.dialog.includeSubtasks")]}),s.jsxs(Hs,{children:[s.jsx(ve,{type:"button",onClick:()=>ee(!1),variant:"outline",size:"sm",children:e("sessions.sidebar.dialogs.cancel")}),s.jsx(ve,{type:"button",onClick:()=>{ee(!1),es(R)},size:"sm",children:e("sessions.sidebar.session.export.dialog.confirm")})]})]})}),et?s.jsx(JP,{session:Pe,open:gt,onOpenChange:Pt}):null]},he.id)}const tA=o.memo(eA,ZP);function sA(t){const e=ot.c(71),{t:n}=ut(),{value:r,setValue:a,showDeletionDialog:i,setShowDeletionDialog:l,onConfirm:c}=t;let d,p,m,u,f,b,g,v,x,h;if(e[0]!==a||e[1]!==n||e[2]!==r){const F=n("sessions.sidebar.session.untitled");u=ps,x=!!r,e[13]!==a?(h=q=>{q||a(null)},e[13]=a,e[14]=h):h=e[14],m=ms,g=!1,v="max-w-sm gap-5",p=gs;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(fs,{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||F,count:r.descendantCount}):n("sessions.sidebar.dialogs.deleteSession.withManySubtasks",{sessionTitle:r.session.title||F,count:r.descendantCount}):r.descendantCount===1?n("sessions.sidebar.dialogs.archiveSession.withOneSubtask",{sessionTitle:r.session.title||F,count:r.descendantCount}):n("sessions.sidebar.dialogs.archiveSession.withManySubtasks",{sessionTitle:r.session.title||F,count:r.descendantCount}):r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.single",{sessionTitle:r?.session.title||F}):n("sessions.sidebar.dialogs.archiveSession.single",{sessionTitle:r?.session.title||F}),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]=g,e[10]=v,e[11]=x,e[12]=h}else d=e[3],p=e[4],m=e[5],u=e[6],f=e[7],b=e[8],g=e[9],v=e[10],x=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 y;e[23]!==p||e[24]!==b||e[25]!==j?(y=s.jsxs(p,{children:[b,j]}),e[23]=p,e[24]=b,e[25]=j,e[26]=y):y=e[26];let C;e[27]!==l||e[28]!==i?(C=()=>l(!i),e[27]=l,e[28]=i,e[29]=C):C=e[29];const k=!i;let w;e[30]!==i?(w=i?s.jsx(D,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(D,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[30]=i,e[31]=w):w=e[31];let S;e[32]!==n?(S=n("sessions.sidebar.dialogs.neverAsk"),e[32]=n,e[33]=S):S=e[33];let I;e[34]!==w||e[35]!==S||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,S]}),e[34]=w,e[35]=S,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 A;e[43]!==T||e[44]!==P?(A=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]=A):A=e[45];let N;e[46]!==c?(N=()=>{c()},e[46]=c,e[47]=N):N=e[47];let E;e[48]!==n||e[49]!==r?.archivedBucket?(E=r?.archivedBucket?n("sessions.sidebar.bulkActions.delete"):n("sessions.sidebar.bulkActions.archive"),e[48]=n,e[49]=r?.archivedBucket,e[50]=E):E=e[50];let M;e[51]!==N||e[52]!==E?(M=s.jsx("button",{type:"button",onClick:N,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:E}),e[51]=N,e[52]=E,e[53]=M):M=e[53];let O;e[54]!==A||e[55]!==M?(O=s.jsxs("div",{className:"flex items-center gap-2",children:[A,M]}),e[54]=A,e[55]=M,e[56]=O):O=e[56];let V;e[57]!==I||e[58]!==O?(V=s.jsxs(Hs,{className:"w-full sm:items-center sm:justify-between",children:[I,O]}),e[57]=I,e[58]=O,e[59]=V):V=e[59];let B;e[60]!==m||e[61]!==g||e[62]!==V||e[63]!==v||e[64]!==y?(B=s.jsxs(m,{showCloseButton:g,className:v,children:[y,V]}),e[60]=m,e[61]=g,e[62]=V,e[63]=v,e[64]=y,e[65]=B):B=e[65];let $;return e[66]!==u||e[67]!==B||e[68]!==x||e[69]!==h?($=s.jsx(u,{open:x,onOpenChange:h,children:B}),e[66]=u,e[67]=B,e[68]=x,e[69]=h,e[70]=$):$=e[70],$}function nA(t){const e=ot.c(57),{t:n}=ut(),{value:r,setValue:a,showDeletionDialog:i,setShowDeletionDialog:l,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,g=!!r;let v;e[8]!==a?(v=$=>{$||a(null)},e[8]=a,e[9]=v):v=e[9];let x;e[10]!==u?(x=s.jsx(fs,{children:u}),e[10]=u,e[11]=x):x=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]!==x||e[15]!==h?(j=s.jsxs(gs,{children:[x,h]}),e[14]=x,e[15]=h,e[16]=j):j=e[16];let y;e[17]!==l||e[18]!==i?(y=()=>l(!i),e[17]=l,e[18]=i,e[19]=y):y=e[19];const C=!i;let k;e[20]!==i?(k=i?s.jsx(D,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(D,{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 S;e[24]!==w||e[25]!==y||e[26]!==C||e[27]!==k?(S=s.jsxs("button",{type:"button",onClick:y,className:"inline-flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":C,children:[k,w]}),e[24]=w,e[25]=y,e[26]=C,e[27]=k,e[28]=S):S=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 A;e[36]!==c?(A=()=>{c()},e[36]=c,e[37]=A):A=e[37];let N;e[38]!==d||e[39]!==n?(N=n(d?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[38]=d,e[39]=n,e[40]=N):N=e[40];let E;e[41]!==A||e[42]!==N?(E=s.jsx("button",{type:"button",onClick:A,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:N}),e[41]=A,e[42]=N,e[43]=E):E=e[43];let M;e[44]!==P||e[45]!==E?(M=s.jsxs("div",{className:"flex items-center gap-2",children:[P,E]}),e[44]=P,e[45]=E,e[46]=M):M=e[46];let O;e[47]!==S||e[48]!==M?(O=s.jsxs(Hs,{className:"w-full sm:items-center sm:justify-between",children:[S,M]}),e[47]=S,e[48]=M,e[49]=O):O=e[49];let V;e[50]!==O||e[51]!==j?(V=s.jsxs(ms,{showCloseButton:!1,className:"max-w-sm gap-5",children:[j,O]}),e[50]=O,e[51]=j,e[52]=V):V=e[52];let B;return e[53]!==g||e[54]!==V||e[55]!==v?(B=s.jsx(ps,{open:g,onOpenChange:v,children:V}),e[53]=g,e[54]=V,e[55]=v,e[56]=B):B=e[56],B}function rA(t){const e=ot.c(36),{t:n}=ut(),{value:r,setValue:a,onConfirm:i}=t,l=!!r;let c;e[0]!==a?(c=k=>{k||a(null)},e[0]=a,e[1]=c):c=e[1];let d;e[2]!==n?(d=n("sessions.sidebar.dialogs.deleteFolder.title"),e[2]=n,e[3]=d):d=e[3];let p;e[4]!==d?(p=s.jsx(fs,{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(gs,{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 g;e[16]!==n?(g=n("sessions.sidebar.dialogs.cancel"),e[16]=n,e[17]=g):g=e[17];let v;e[18]!==b||e[19]!==g?(v=s.jsx("button",{type:"button",onClick:b,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:g}),e[18]=b,e[19]=g,e[20]=v):v=e[20];let x;e[21]!==n?(x=n("sessions.sidebar.bulkActions.delete"),e[21]=n,e[22]=x):x=e[22];let h;e[23]!==i||e[24]!==x?(h=s.jsx("button",{type:"button",onClick:i,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:x}),e[23]=i,e[24]=x,e[25]=h):h=e[25];let j;e[26]!==h||e[27]!==v?(j=s.jsxs(Hs,{children:[v,h]}),e[26]=h,e[27]=v,e[28]=j):j=e[28];let y;e[29]!==j||e[30]!==f?(y=s.jsxs(ms,{showCloseButton:!1,className:"max-w-sm gap-5",children:[f,j]}),e[29]=j,e[30]=f,e[31]=y):y=e[31];let C;return e[32]!==l||e[33]!==c||e[34]!==y?(C=s.jsx(ps,{open:l,onOpenChange:c,children:y}),e[32]=l,e[33]=c,e[34]=y,e[35]=C):C=e[35],C}const aA=t=>{const e=ot.c(46),{selectedCount:n,scopeKey:r,scopeFolders:a,archivedBucket:i,onMoveToFolder:l,onCreateFolderAndMove:c,onRemoveFromFolder:d,canRemoveFromFolder:p,onDelete:m,onDone:u}=t,{t:f}=ut(),b=!!r&&!i;let g;e[0]!==i||e[1]!==f?(g=f(i?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[0]=i,e[1]=f,e[2]=g):g=e[2];const v=g;let x;e[3]!==n||e[4]!==f?(x=f("sessions.sidebar.bulkActions.selectedCount",{count:n}),e[3]=n,e[4]=f,e[5]=x):x=e[5];let h;e[6]!==x?(h=s.jsx("span",{className:"typography-ui-label text-muted-foreground whitespace-nowrap",children:x}),e[6]=x,e[7]=h):h=e[7];let j;e[8]!==b||e[9]!==p||e[10]!==c||e[11]!==l||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(D,{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(Ot,{disabled:!0,className:"text-muted-foreground",children:f("sessions.sidebar.folders.none")}):a.map(V=>s.jsx(Ot,{onClick:()=>l(V.id),children:s.jsx("span",{className:"flex-1 truncate",children:V.name})},V.id)),s.jsx(Xn,{}),s.jsxs(Ot,{onClick:c,children:[s.jsx(D,{name:"add",className:"mr-1 h-4 w-4"}),f("sessions.sidebar.folders.newFolderEllipsis")]}),p?s.jsxs(Ot,{onClick:d,className:"text-destructive focus:text-destructive",children:[s.jsx(D,{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]=l,e[12]=d,e[13]=a,e[14]=f,e[15]=j):j=e[15];let y;e[16]===Symbol.for("react.memo_cache_sentinel")?(y=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]=y):y=e[16];let C;e[17]===Symbol.for("react.memo_cache_sentinel")?(C=s.jsx(D,{name:"delete-bin",className:"h-4 w-4"}),e[17]=C):C=e[17];let k;e[18]!==v||e[19]!==m?(k=s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:m,className:y,"aria-label":v,children:C})}),e[18]=v,e[19]=m,e[20]=k):k=e[20];let w;e[21]!==v?(w=s.jsx(It,{side:"top",sideOffset:4,children:s.jsx("p",{children:v})}),e[21]=v,e[22]=w):w=e[22];let S;e[23]!==k||e[24]!==w?(S=s.jsxs(kt,{children:[k,w]}),e[23]=k,e[24]=w,e[25]=S):S=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(D,{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 A;e[32]!==f?(A=f("sessions.sidebar.header.actions.exitSelection"),e[32]=f,e[33]=A):A=e[33];let N;e[34]!==A?(N=s.jsx(It,{side:"top",sideOffset:4,children:s.jsx("p",{children:A})}),e[34]=A,e[35]=N):N=e[35];let E;e[36]!==P||e[37]!==N?(E=s.jsxs(kt,{children:[P,N]}),e[36]=P,e[37]=N,e[38]=E):E=e[38];let M;e[39]!==E||e[40]!==j||e[41]!==S?(M=s.jsxs("div",{className:"ml-auto flex items-center gap-0.5",children:[j,S,E]}),e[39]=E,e[40]=j,e[41]=S,e[42]=M):M=e[42];let O;return e[43]!==M||e[44]!==h?(O=s.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-t border-border px-2.5 py-1.5",children:[h,M]}),e[43]=M,e[44]=h,e[45]=O):O=e[45],O},Vg="oc.sessions.activeNow",iA=2160*60*1e3,zg=t=>!!t.parentID,ou=t=>!!t.time?.archived,Id=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},oA=t=>{try{const e=t.getItem(Vg);if(!e)return[];const n=JSON.parse(e);if(!Array.isArray(n))return[];const r=new Set,a=[];return n.forEach(i=>{const l=typeof i=="string"?i:i&&typeof i=="object"&&"sessionId"in i&&typeof i.sessionId=="string"?i.sessionId:null;!l||r.has(l)||(r.add(l),a.push({sessionId:l}))}),a}catch{return[]}},Uc=(t,e)=>{try{t.setItem(Vg,JSON.stringify(e))}catch{}},lA=(t,e,n=Date.now())=>{const r=n-iA;return t.filter(a=>{const i=e.get(a.sessionId);return i?ou(i)?!1:Id(i)>=r:!0})},cA=(t,e)=>!e||t.some(n=>n.sessionId===e)?t:[{sessionId:e},...t],Ug=t=>[...t].sort((e,n)=>Id(n)-Id(e)),dA=(t,e)=>{const n=t.map(r=>e.get(r.sessionId)??null).filter(r=>!!r).filter(r=>!ou(r)).filter(r=>!zg(r));return Ug(n)},uA=(t,e)=>{const n=t.filter(r=>{if(ou(r)||zg(r))return!1;const a=e[r.id];return a?.type==="busy"||a?.type==="retry"});return Ug(n)},Wo=Cr(),Wc=rr((t,e)=>({entries:oA(Wo),setEntries:n=>{n!==e().entries&&(t({entries:n}),Uc(Wo,n))},addSession:n=>{const r=cA(e().entries,n);r!==e().entries&&(t({entries:r}),Uc(Wo,r))},prune:n=>{const r=e().entries,a=lA(r,n);a.length===r.length&&a.every((i,l)=>i.sessionId===r[l]?.sessionId)||(t({entries:a}),Uc(Wo,a))}})),Ko="oc.sessions.projectCollapse",vf="oc.sessions.groupOrder",wf="oc.sessions.groupCollapse",jf="oc.sessions.activeSessionByProject",Kc="oc.sessions.expandedParents.v2",mA="oc.sessions.expandedParents",pA="oc.sessions.pinned",fA=(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},hA=(t,e)=>{if(t.time?.archived)return!0;const n=bs(qi(t))?.toLowerCase();return!n||e.size===0?!0:e.has(n)},gA=5*6e4,Nf=({mobileVariant:t=!1,onSessionSelected:e,allowReselect:n=!1,hideDirectoryControls:r=!1,showOnlyMainWorkspace:a=!1})=>{const{t:i}=ut(),[l,c]=o.useState(!1),[d,p]=o.useState(""),m=o.useRef(null),u=o.useRef(null),f=o.useRef(new Set),[b,g]=o.useState(null),[v,x]=o.useState(""),[h,j]=o.useState(null),[y,C]=o.useState(new Set),[k]=o.useState(()=>new Map),w=o.useMemo(()=>Cr(),[]),S=Wc($e=>$e.entries),I=Wc($e=>$e.addSession),T=Wc($e=>$e.prune),[P,A]=o.useState(new Set),[N,E]=o.useState(new Map),[M,O]=o.useState(new Set),[V,B]=o.useState(!1),[$,F]=o.useState(!1),[_,q]=o.useState(null),[L,Y]=o.useState(null),[Z,ae]=o.useState(""),[re,me]=o.useState(null),[fe,H]=o.useState(null),[K,Q]=o.useState(null),W=oc($e=>$e.ids),de=oc($e=>$e.setIds),be=oc($e=>$e.toggle),[we,te]=o.useState(()=>{try{const $e=Cr().getItem(wf);if(!$e)return new Set;const St=JSON.parse($e);return new Set(Array.isArray(St)?St.filter(ft=>typeof ft=="string"):[])}catch{return new Set}}),[ge,ue]=o.useState(()=>{try{const $e=Cr().getItem(vf);if(!$e)return new Map;const St=JSON.parse($e),ft=new Map;return Object.entries(St).forEach(([Yt,vs])=>{Array.isArray(vs)&&ft.set(Yt,vs.filter(sn=>typeof sn=="string"))}),ft}catch{return new Map}}),[xe,ne]=o.useState(()=>{try{const $e=Cr().getItem(jf);if(!$e)return new Map;const St=JSON.parse($e),ft=new Map;return Object.entries(St).forEach(([Yt,vs])=>{typeof vs=="string"&&vs.length>0&&ft.set(Yt,vs)}),ft}catch{return new Map}}),[pe,J]=o.useState(new Map),Se=o.useRef(new Map),he=o.useRef(0),Ie=Ks($e=>$e.homeDirectory),Pe=Ks($e=>$e.currentDirectory),Ce=Ks($e=>$e.setDirectory),X=Cs($e=>$e.projects),ie=Cs($e=>$e.activeProjectId),Ne=Cs($e=>$e.removeProject),oe=Cs($e=>$e.setActiveProjectIdOnly),ke=Cs($e=>$e.updateProjectMeta),Te=Cs($e=>$e.reorderProjects),Be=Re($e=>$e.setActiveMainTab),je=Re($e=>$e.openContextPanelTab),ee=Re($e=>$e.setSettingsDialogOpen),R=Re($e=>$e.toggleHelpDialog),U=Re($e=>$e.setAboutDialogOpen),le=Re($e=>$e.setSessionSwitcherOpen),Me=Re($e=>$e.setScheduledTasksDialogOpen),Oe=Re($e=>$e.openMultiRunLauncher),Ae=Re($e=>$e.notifyOnSubtasks),z=Re($e=>$e.showDeletionDialog),De=Re($e=>$e.setShowDeletionDialog),Xe=Bl(d,120),st=o.useMemo(()=>Xe.trim().toLowerCase(),[Xe]),tt=st.length>0,Ue=Yn($e=>$e.collapsedFolderIds),it=Yn($e=>$e.foldersMap),Ye=Yn($e=>$e.getFoldersForScope),rt=Yn($e=>$e.createFolder),Je=Yn($e=>$e.renameFolder),ce=Yn($e=>$e.deleteFolder),We=Yn($e=>$e.addSessionToFolder),Le=Yn($e=>$e.addSessionsToFolder),Ge=Yn($e=>$e.removeSessionFromFolder),at=Yn($e=>$e.removeSessionsFromFolders),He=Yn($e=>$e.toggleFolderCollapse),ze=Yn($e=>$e.cleanupSessions),et=Yn($e=>$e.getSessionFolderId);m6({isSessionSearchOpen:l,setIsSessionSearchOpen:c,sessionSearchInputRef:u,sessionSearchContainerRef:m});const gt=dh(),Pt=Kd(),Nt=Td(),ht=_y(),wt=Oa($e=>$e.hasLoaded),es=Oa($e=>$e.activeSessions),Vt=Oa($e=>$e.archivedSessions),Jt=$t($e=>$e.currentSessionId),mt=$t($e=>!!$e.newSessionDraft?.open),Lt=$t($e=>$e.setCurrentSession),ts=$t($e=>$e.updateSessionTitle),js=$t($e=>$e.shareSession),ds=$t($e=>$e.unshareSession),hs=$t($e=>$e.worktreeMetadata),Ut=$t($e=>$e.availableWorktreesByProject),Qe=$t($e=>$e.openNewSessionDraft),At=_a(er($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}))),Ht=o.useMemo(()=>fA(X,Ut),[Ut,X]),jt=o.useMemo(()=>{const $e=new Map(Nt.map(Yt=>[Yt.id,Yt])),St=es.map(Yt=>$e.get(Yt.id)??Yt),ft=new Set(St.map(Yt=>Yt.id));return Nt.forEach(Yt=>{ft.has(Yt.id)||St.push(Yt)}),St.filter(Yt=>hA(Yt,Ht))},[es,Ht,Nt]),Zt=o.useMemo(()=>Nt.map($e=>{const St=bs($e.directory??null)??"";return`${$e.id}:${$e.title??""}:${$e.time?.archived?1:0}:${St}`}).join("|"),[Nt]),rs=o.useRef(Nt);o.useEffect(()=>{rs.current=Nt},[Zt,Nt]),o.useEffect(()=>{let $e=!1;const St=async()=>{const ft=Cs.getState().projects;if(ft.length===0)return;const Yt=new Map,vs=[];await Promise.all(ft.map(async sn=>{const fn=bs(sn.path);if(fn)try{if(!(Qs.getState().directories.get(fn)?.isGitRepo??await Dr(()=>import("./modelPrefsAutoSave-Ctdc3cCY.js").then(En=>En.eW),__vite__mapDeps([2,0,1,3,4])).then(En=>En.checkIsGitRepository(fn))))return;const Mn=await Zc({id:sn.id,path:fn});if($e||Mn.length===0)return;Yt.set(fn,Mn),vs.push(...Mn)}catch{}})),!$e&&$t.setState({availableWorktrees:vs,availableWorktreesByProject:Yt})};return ed(rs.current),St(),()=>{$e=!0}},[Pe,Zt,X]),o.useEffect(()=>{let $e=null;const St=Eg(ft=>{ft.type==="scheduled-task-ran"&&($e&&clearTimeout($e),$e=setTimeout(()=>{ed(rs.current)},500))});return()=>{$e&&clearTimeout($e),St()}},[]);const Ds=o.useMemo(()=>Cn(),[]),ns=o.useMemo(()=>mn(),[]),{isTablet:zs}=an(),$s=t||zs,{buildGroupSearchText:gn,filterSessionNodesForSearch:rn,buildGroupedSessions:Wt}=u6({homeDirectory:Ie,worktreeMetadata:hs,pinnedSessionIds:W,gitBranches:gt,isVSCode:ns}),{scheduleCollapsedProjectsPersist:Kt}=y6({isVSCode:ns,hasLoadedGlobalSessions:wt,safeStorage:w,keys:{sessionExpanded:Kc,sessionExpandedLegacy:mA,projectCollapse:Ko,sessionPinned:pA,groupOrder:vf,projectActiveSession:jf,groupCollapse:wf},sessions:jt,setPinnedSessionIds:de,groupOrderByProject:ge,activeSessionByProject:xe,collapsedGroups:we,setExpandedParents:C,setCollapsedProjects:A}),se=o.useMemo(()=>[...jt].sort(($e,St)=>di($e,St,W)),[jt,W]),bt=o.useMemo(()=>new Map(se.map(($e,St)=>[$e.id,St])),[se]),_t=o.useMemo(()=>{const $e=new Map;return se.forEach(St=>{const ft=St.parentID;if(!ft)return;const Yt=$e.get(ft)??[];Yt.push(St),$e.set(ft,Yt)}),$e.forEach(St=>St.sort((ft,Yt)=>di(ft,Yt,W))),$e},[se,W]),lt=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")})]}),ss=o.useMemo(()=>X.find($e=>$e.id===h)??null,[X,h]),cs=o.useCallback($e=>{h&&(ke(h,$e),j(null))},[h,ke]),Ke=o.useCallback(()=>{B(!0)},[]),xt=o.useCallback(()=>{const $e=_a.getState();if($e.available&&$e.info){F(!0);return}At.checkForUpdates().then(()=>{const{available:St,error:ft}=_a.getState();if(ft){G.error(i("sessions.sidebar.updateCheck.errorTitle"),{description:ft});return}if(!St){G.success(i("sessions.sidebar.updateCheck.latestVersion"));return}F(!0)})},[i,At]),Tt=o.useCallback(()=>{t&&le(!1),ee(!0)},[t,le,ee]),Et=At.available&&(At.runtimeType==="desktop"||At.runtimeType==="web"),Qt=$t($e=>$e.deleteSession),Rt=$t($e=>$e.deleteSessions),Os=$t($e=>$e.archiveSession),Ts=$t($e=>$e.archiveSessions),{copiedSessionId:ks,handleSessionSelect:Bs,handleSessionDoubleClick:ys,handleSaveEdit:Gn,handleCancelEdit:xn,handleShareSession:ln,handleCopyShareUrl:ar,handleUnshareSession:Us,handleDeleteSession:bn,confirmDeleteSession:ir}=p6({activeProjectId:ie,currentDirectory:Pe,currentSessionId:Jt,mobileVariant:t,allowReselect:n,onSessionSelected:e,isSessionSearchOpen:l,sessionSearchQuery:d,setSessionSearchQuery:p,setIsSessionSearchOpen:c,setActiveProjectIdOnly:oe,setDirectory:Ce,setActiveMainTab:Be,setSessionSwitcherOpen:le,setCurrentSession:Lt,updateSessionTitle:ts,shareSession:js,unshareSession:ds,deleteSession:Qt,deleteSessions:Rt,archiveSession:Os,archiveSessions:Ts,childrenMap:_t,showDeletionDialog:z,setDeleteSessionConfirm:me,deleteSessionConfirm:re,setEditingId:g,setEditTitle:x,editingId:b,editTitle:v}),Vn=o.useCallback(()=>{if(!fe)return;const{scopeKey:$e,folderId:St}=fe;H(null),ce($e,St)},[fe,ce]),Mr=o.useCallback(()=>{Ar.requestDirectoryDialog()},[]);o.useEffect(()=>{if(!Jt)return;const St=jt.find(Yt=>Yt.id===Jt)?.parentID;if(!St)return;const ft=[`project:active:${St}`,`project:archived:${St}`,`recent:active:${St}`,`recent:archived:${St}`];C(Yt=>{if(ft.every(sn=>Yt.has(sn)))return Yt;const vs=new Set(Yt);ft.forEach(sn=>vs.add(sn));try{w.setItem(Kc,JSON.stringify(Array.from(vs)))}catch{}return vs})},[Jt,jt,w]);const Ls=o.useCallback($e=>{C(St=>{const ft=new Set(St);ft.has($e)?ft.delete($e):ft.add($e);try{w.setItem(Kc,JSON.stringify(Array.from(ft)))}catch{}return ft})},[w]),Rs=o.useCallback(($e,St)=>{if(!$e)return null;St&&Ue.has(St)&&He(St);const ft=rt($e,i("sessions.sidebar.folder.newFolderName"),St);return Y(ft.id),ae(ft.name),ft},[Ue,He,rt,i]),Ve=o.useCallback($e=>{O(St=>{const ft=new Set(St);return ft.has($e)?ft.delete($e):ft.add($e),ft})},[]),Dt=o.useCallback(()=>{he.current=Date.now()+150,A(()=>{const $e=new Set(X.map(St=>St.id));try{w.setItem(Ko,JSON.stringify(Array.from($e)))}catch{}return ns||Kt($e),$e})},[X,ns,w,Kt]),Gt=o.useCallback(()=>{he.current=Date.now()+150,A(()=>{const $e=new Set;try{w.setItem(Ko,JSON.stringify([]))}catch{}return ns||Kt($e),$e})},[ns,w,Kt]),as=o.useCallback($e=>{he.current=Date.now()+150,A(St=>{const ft=new Set(St);ft.has($e)?ft.delete($e):ft.add($e);try{w.setItem(Ko,JSON.stringify(Array.from(ft)))}catch{}return ns||Kt(ft),ft})},[ns,w,Kt]),_s=o.useMemo(()=>X.map($e=>({...$e,normalizedPath:bs($e.path)})).filter($e=>!!$e.normalizedPath),[X]),qs=o.useMemo(()=>_s.map($e=>$e.normalizedPath),[_s]),{github:Ws}=Bn(),Zs=Hn($e=>$e.status),tn=Hn($e=>$e.hasChecked),or=By(qs),tr=gr($e=>$e.ensureEntry),Kr=gr($e=>$e.setParams),zr=gr($e=>$e.refreshTargets);w6({normalizedProjects:_s,gitRepoStatus:or,setProjectRepoStatus:E,setProjectRootBranches:J});const In=$t($e=>$e.isLoading);T6({isSessionsLoading:In,sessions:jt,archivedSessions:Vt,normalizedProjects:_s,isVSCode:ns,availableWorktreesByProject:Ut,cleanupSessions:ze});const{getSessionsForProject:cn,getArchivedSessionsForProject:pn}=C6({isVSCode:ns,sessions:jt,archivedSessions:Vt,availableWorktreesByProject:Ut});n6({normalizedProjects:_s,sessions:jt,archivedSessions:Vt,availableWorktreesByProject:Ut,isVSCode:ns,isSessionsLoading:In,foldersMap:it,createFolder:rt,addSessionToFolder:We,cleanupSessions:ze});const yn=o.useRef(!1);ie&&N.has(ie)&&(yn.current=!!N.get(ie));const{projectSections:Nn,groupSearchDataByGroup:wr,sectionsForRender:vn,searchMatchCount:Ur}=i6({normalizedProjects:_s,getSessionsForProject:cn,getArchivedSessionsForProject:pn,availableWorktreesByProject:Ut,projectRepoStatus:N,projectRootBranches:pe,lastRepoStatus:yn.current,buildGroupedSessions:Wt,hasSessionSearchQuery:tt,normalizedSessionSearchQuery:st,filterSessionNodesForSearch:rn,buildGroupSearchText:gn,foldersMap:it}),lr=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:zn}=l6({projectSections:Nn,activeProjectId:ie,activeSessionByProject:xe,setActiveSessionByProject:ne,currentSessionId:Jt,handleSessionSelect:Bs,newSessionDraftOpen:mt,mobileVariant:t,openNewSessionDraft:Qe,setActiveMainTab:Be,setSessionSwitcherOpen:le,sessions:jt,worktreeMetadata:hs}),{getOrderedGroups:Ya}=c6(ge),xa=o.useRef(!1);o.useEffect(()=>{if(xa.current||Nn.length===0)return;const $e=Nn.flatMap(St=>St.groups.filter(ft=>ft.isArchivedBucket).map(ft=>`${St.project.id}:${ft.id}`));$e.length>0&&te(St=>new Set([...St,...$e])),xa.current=!0},[Nn]);const ba=o.useMemo(()=>{const $e=new Map,St=new Map;return Nn.forEach(ft=>{const Yt=xh(ft.project.label?.trim()||Ua(ft.project.normalizedPath,Ie)||ft.project.normalizedPath);ft.groups.forEach(vs=>{const sn=vs.branch&&vs.branch!=="HEAD"&&vs.branch!==Yt?vs.branch:null,fn={projectLabel:Yt,branchLabel:sn},Sr=sr=>{sr.forEach(Mn=>{const En=ft.project.normalizedPath.length,Di=St.get(Mn.session.id)??-1;En<Di||($e.set(Mn.session.id,{node:Mn,projectId:ft.project.id,groupDirectory:vs.directory,secondaryMeta:fn}),St.set(Mn.session.id,En),Mn.children.length>0&&Sr(Mn.children))})};Sr(vs.sessions)})}),$e},[Nn,Ie]),dn=Fa($e=>$e.showRecentSection),jr=o.useMemo(()=>dn?dA(S,new Map(jt.map($e=>[$e.id,$e]))).sort(($e,St)=>di($e,St,W)):[],[S,W,jt,dn]),un=o.useMemo(()=>dn?uA(jt,ht):[],[ht,jt,dn]);o.useEffect(()=>{!dn||un.length===0||un.forEach($e=>I($e.id))},[I,un,dn]),o.useEffect(()=>{if(!dn)return;const $e=new Map;[...jt,...Vt].forEach(St=>{$e.set(St.id,St)}),T($e)},[Vt,T,jt,dn]);const cr=o.useMemo(()=>{if(!dn)return[];const $e=St=>{const ft=ba.get(St.id),Yt=bs(St.directory??null);return{node:ft?.node??{session:St,children:[],worktree:null},projectId:ft?.projectId??null,groupDirectory:ft?.groupDirectory??Yt,secondaryMeta:ft?.secondaryMeta??null}};return[{key:"active-now",title:i("sessions.sidebar.activity.recentTitle"),items:jr.map($e)}]},[jr,ba,dn,i]),Hr=o.useMemo(()=>new Set(jr.map($e=>$e.id)),[jr]),ia=o.useMemo(()=>[...Hr],[Hr]);wI({currentSessionId:Jt,sortedSessions:se,recentSessionIds:ia,ensureSessionRenderable:Pt.ensureSessionRenderable});const Nr=o.useMemo(()=>{if(!ns||tt||Hr.size===0)return vn;const $e=St=>St.reduce((ft,Yt)=>{if(Hr.has(Yt.session.id))return ft;const vs=$e(Yt.children);return vs.length===Yt.children.length?(ft.push(Yt),ft):(ft.push({...Yt,children:vs}),ft)},[]);return vn.map(St=>({...St,groups:St.groups.map(ft=>({...ft,sessions:$e(ft.sessions)}))}))},[ns,tt,Hr,vn]),Qa=o.useMemo(()=>{const $e=new Set;return Nr.forEach(St=>{St.groups.forEach(ft=>{const Yt=bs(ft.directory??null),vs=ft.branch?.trim()||gt.get(Yt||"")?.trim();!Yt||!vs||$e.add(Ji(Yt,vs))})}),[...$e]},[gt,Nr]),wn=j0(Qa);o.useEffect(()=>{if(!tn||!Zs?.connected||!Ws)return;const $e=[],St=Date.now();if(Nr.forEach(Yt=>{P.has(Yt.project.id)||Yt.groups.forEach(vs=>{const sn=bs(vs.directory??null),fn=vs.branch?.trim()||gt.get(sn||"")?.trim();if(!sn||!fn)return;const Sr=Ji(sn,fn),sr=gr.getState().entries[Sr],Mn=!!sr?.status?.pr,En=`${sn}::${fn}`,Di=Math.max(sr?.lastRefreshAt??0,sr?.lastDiscoveryPollAt??0),Ti=!!(sr?.isInitialStatusResolved&&!Mn&&(!f.current.has(En)||St-Di>=gA));(!sr||!sr.isInitialStatusResolved||Ti)&&(Ti&&f.current.add(En),$e.push({directory:sn,branch:fn}))})}),$e.length===0)return;const ft=new Map;$e.forEach(Yt=>{const vs=Ji(Yt.directory,Yt.branch,Yt.remoteName??null);ft.has(vs)||ft.set(vs,Yt)}),ft.forEach((Yt,vs)=>{tr(vs),Kr(vs,{directory:Yt.directory,branch:Yt.branch,remoteName:Yt.remoteName??null,canShow:!0,github:Ws,githubAuthChecked:tn,githubConnected:Zs.connected})}),zr([...ft.values()],{force:!0,silent:!0,markInitialResolved:!0})},[P,tr,Ws,tn,Zs?.connected,gt,zr,Nr,Kr]);const oa=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",dr="h-4.5 w-4.5",Dn=F6({isDesktopShellRuntime:Ds,projectSections:Nn,projectHeaderSentinelRefs:Se}),Er=o.useCallback(($e,St=0,ft,Yt,vs=!1,sn,fn="project")=>s.jsx(tA,{node:$e,depth:St,groupDirectory:ft,projectId:Yt,archivedBucket:vs,directoryStatus:k,currentSessionId:Jt,pinnedSessionIds:W,expandedParents:y,hasSessionSearchQuery:tt,normalizedSessionSearchQuery:st,notifyOnSubtasks:Ae,editingId:b,setEditingId:g,editTitle:v,setEditTitle:x,handleSaveEdit:Gn,handleCancelEdit:xn,toggleParent:Ls,handleSessionSelect:Bs,handleSessionDoubleClick:ys,togglePinnedSession:be,handleShareSession:ln,copiedSessionId:ks,handleCopyShareUrl:ar,handleUnshareSession:Us,openSidebarMenuKey:_,setOpenSidebarMenuKey:q,renamingFolderId:L,getFoldersForScope:Ye,getSessionFolderId:et,removeSessionFromFolder:Ge,addSessionToFolder:We,createFolderAndStartRename:Rs,openContextPanelTab:je,handleDeleteSession:bn,mobileVariant:t,alwaysShowActions:$s,renderSessionNode:Er,secondaryMeta:sn,renderContext:fn}),[k,Jt,W,y,tt,st,Ae,b,g,v,x,Gn,xn,Ls,Bs,ys,be,ln,ks,ar,Us,_,q,L,Ye,et,Ge,We,Rs,je,bn,t,$s]),Ja=o.useCallback($e=>{te(St=>{const ft=new Set(St);return ft.has($e)?ft.delete($e):ft.add($e),ft})},[]),Gr=o.useMemo(()=>{const $e=new Map;for(const[St,ft]of wn)$e.set(St,{visualState:ft.visualState,number:ft.number,url:ft.url,state:ft.prState,draft:ft.draft,title:ft.title,base:ft.base,head:ft.head,checks:ft.checks,canMerge:ft.canMerge,mergeableState:ft.mergeableState,repo:ft.repo});return $e},[wn]),Xa=o.useCallback(($e,St,ft,Yt,vs,sn)=>s.jsx(Z6,{group:$e,groupKey:St,projectId:ft,hideGroupLabel:Yt,compactBodyPadding:sn,hasSessionSearchQuery:tt,normalizedSessionSearchQuery:st,groupSearchDataByGroup:wr,expandedSessionGroups:M,collapsedGroups:we,hideDirectoryControls:r,collapsedFolderIds:Ue,toggleFolderCollapse:He,renameFolder:Je,deleteFolder:ce,showDeletionDialog:z,setDeleteFolderConfirm:H,renderSessionNode:Er,currentSessionDirectory:zn,projectRepoStatus:N,lastRepoStatus:yn.current,toggleGroupSessionLimit:Ve,mobileVariant:t,alwaysShowActions:$s,activeProjectId:ie,setActiveProjectIdOnly:oe,setActiveMainTab:Be,setSessionSwitcherOpen:le,openNewSessionDraft:Qe,addSessionToFolder:We,createFolderAndStartRename:Rs,renamingFolderId:L,renameFolderDraft:Z,setRenameFolderDraft:ae,setRenamingFolderId:Y,pinnedSessionIds:W,sessionOrderIndex:bt,prVisualStateByDirectoryBranch:Gr,onToggleCollapsedGroup:Ja,dragHandleProps:vs}),[tt,st,wr,M,we,r,Ue,He,Je,ce,z,Er,zn,N,Ve,t,$s,ie,oe,Be,le,Qe,We,Rs,L,Z,W,bt,Gr,Ja]),Tn=dn&&!tt?s.jsx(iP,{sections:cr,renderSessionNode:Er}):null,Rr=!!(L||b||h),qr=hr($e=>$e.enabled),Ys=hr($e=>$e.selectedIds),Fr=hr($e=>$e.scopeKey),ya=hr,Pi=o.useCallback(()=>{hr.getState().toggleMode()},[]),Fe=o.useCallback(()=>{hr.getState().disable()},[]),qe=o.useMemo(()=>{if(Ys.size===0||typeof document>"u")return!1;let $e=!1,St=!1;for(const ft of Ys){const Yt=document.querySelectorAll(`[data-session-row="${CSS.escape(ft)}"]`);for(const vs of Yt)vs.getAttribute("data-session-archived")==="1"?St=!0:$e=!0}return St&&!$e},[Ys]),Ze=o.useMemo(()=>{if(Fr)return Fr;if(Ys.size===0||typeof document>"u")return null;for(const $e of Ys){const ft=document.querySelector(`[data-session-row="${CSS.escape($e)}"]`)?.getAttribute("data-session-scope");if(ft&&ft.length>0)return ft}return null},[Ys,Fr]),dt=o.useMemo(()=>Ze?it[Ze]??[]:[],[it,Ze]),Ft=o.useMemo(()=>{if(!Ze||Ys.size===0)return!1;const $e=it[Ze]??[];for(const St of $e)for(const ft of St.sessionIds)if(Ys.has(ft))return!0;return!1},[it,Ze,Ys]),zt=o.useCallback($e=>{!Ze||Ys.size===0||Le(Ze,$e,Array.from(Ys))},[Le,Ys,Ze]),Vs=o.useCallback(()=>{if(!Ze||Ys.size===0)return;const $e=Rs(Ze);$e&&Le(Ze,$e.id,Array.from(Ys))},[Le,Rs,Ys,Ze]),Fs=o.useCallback(()=>{!Ze||Ys.size===0||at(Ze,Array.from(Ys))},[at,Ys,Ze]),Pn=o.useCallback(async()=>{const $e=Array.from(Ys);if($e.length!==0){if(qe){const{deletedIds:St,failedIds:ft}=await Rt($e);St.length>0&&G.success(St.length===1?i("sessions.sidebar.bulkActions.deletedSingle",{count:St.length}):i("sessions.sidebar.bulkActions.deletedPlural",{count:St.length})),ft.length>0&&G.error(ft.length===1?i("sessions.sidebar.bulkActions.failedDeleteSingle",{count:ft.length}):i("sessions.sidebar.bulkActions.failedDeletePlural",{count:ft.length}))}else{const{archivedIds:St,failedIds:ft}=await Ts($e);St.length>0&&G.success(St.length===1?i("sessions.sidebar.bulkActions.archivedSingle",{count:St.length}):i("sessions.sidebar.bulkActions.archivedPlural",{count:St.length})),ft.length>0&&G.error(ft.length===1?i("sessions.sidebar.bulkActions.failedArchiveSingle",{count:ft.length}):i("sessions.sidebar.bulkActions.failedArchivePlural",{count:ft.length}))}hr.getState().clear()}},[Ts,qe,Rt,Ys,i]),va=o.useCallback(()=>{const $e=Ys.size;if($e!==0){if(!z){Pn();return}Q({sessionCount:$e,archivedBucket:qe})}},[qe,Pn,Ys,z]),Ai=o.useCallback(async()=>{Q(null),await Pn()},[Pn]);o.useEffect(()=>{if(!qr)return;const $e=typeof navigator<"u"&&/Macintosh|Mac OS X/.test(navigator.userAgent||""),St=ft=>{if(Rr)return;const Yt=ft.target;if(Yt&&(Yt.tagName==="INPUT"||Yt.tagName==="TEXTAREA"||Yt.isContentEditable))return;const vs=$e?ft.metaKey:ft.ctrlKey;if(ft.key==="Escape"){ft.preventDefault(),hr.getState().disable();return}if(vs&&ft.key==="Backspace"){ft.preventDefault(),va();return}if(vs&&(ft.key==="a"||ft.key==="A")){const sn=typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[];if(sn.length===0)return;ft.preventDefault();const Sr=ya.getState().scopeKey??sn[0]?.getAttribute("data-session-scope")??null,sr=En=>Sr?En.getAttribute("data-session-scope")===Sr:!0,Mn=sn.filter(sr).map(En=>En.getAttribute("data-session-row")).filter(En=>typeof En=="string"&&En.length>0);if(Mn.length===0)return;ya.getState().replaceAll(Mn,Sr||null)}};return window.addEventListener("keydown",St),()=>window.removeEventListener("keydown",St)},[va,Rr,ya,qr]);const wa=o.useCallback(()=>{Be("chat"),t&&le(!1),Oe()},[t,Oe,Be,le]);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(eP,{hideDirectoryControls:r,handleOpenDirectoryDialog:Mr,canOpenMultiRun:X.length>0,openMultiRunLauncher:wa,headerActionIconClass:dr,headerActionButtonClass:oa,isSessionSearchOpen:l,setIsSessionSearchOpen:c,sessionSearchInputRef:u,sessionSearchQuery:d,setSessionSearchQuery:p,hasSessionSearchQuery:tt,searchMatchCount:Ur,collapseAllProjects:Dt,expandAllProjects:Gt,openScheduledTasksDialog:()=>Me(!0),selectionModeEnabled:qr,onToggleSelectionMode:Pi}),s.jsx(hP,{topContent:Tn,sectionsForRender:Nr,projectSections:Nn,activeProjectId:ie,showOnlyMainWorkspace:a,hasSessionSearchQuery:tt,emptyState:lt,searchEmptyState:lr,renderGroupSessions:Xa,homeDirectory:Ie,collapsedProjects:P,hideDirectoryControls:r,projectRepoStatus:N,isDesktopShellRuntime:Ds,stuckProjectHeaders:Dn,mobileVariant:t,alwaysShowActions:$s,toggleProject:as,setActiveProjectIdOnly:oe,setActiveMainTab:Be,setSessionSwitcherOpen:le,openNewSessionDraft:Qe,openNewWorktreeDialog:Ke,openProjectEditDialog:j,removeProject:Ne,projectHeaderSentinelRefs:Se,reorderProjects:Te,getOrderedGroups:Ya,setGroupOrderByProject:ue,openSidebarMenuKey:_,setOpenSidebarMenuKey:q,isInlineEditing:Rr}),qr&&Ys.size>0?s.jsx(aA,{selectedCount:Ys.size,scopeKey:Ze,scopeFolders:dt,archivedBucket:qe,onMoveToFolder:zt,onCreateFolderAndMove:Vs,onRemoveFromFolder:Fs,canRemoveFromFolder:Ft,onDelete:va,onDone:Fe}):null,s.jsx(lP,{onOpenSettings:Tt,onOpenShortcuts:R,onOpenAbout:()=>U(!0),onOpenUpdate:xt,showRuntimeButtons:!ns,showUpdateButton:Et}),s.jsx(wd,{open:$,onOpenChange:F,info:At.info,downloading:At.downloading,downloaded:At.downloaded,progress:At.progress,error:At.error,onDownload:At.downloadUpdate,onRestart:At.restartToUpdate,runtimeType:At.runtimeType}),ss?s.jsx(Vy,{open:!!ss,onOpenChange:$e=>{$e||j(null)},projectId:ss.id,projectName:ss.label||Ua(ss.path,Ie),projectPath:ss.path,initialIcon:ss.icon,initialColor:ss.color,initialIconBackground:ss.iconBackground,onSave:cs}):null,s.jsx(CI,{open:V,onOpenChange:B,onWorktreeCreated:($e,St)=>{if(Be("chat"),t&&le(!1),St?.sessionId){Lt(St.sessionId);return}Qe({directoryOverride:$e})}}),s.jsx(t6,{}),s.jsx(sA,{value:re,setValue:me,showDeletionDialog:z,setShowDeletionDialog:De,onConfirm:ir}),s.jsx(rA,{value:fe,setValue:H,onConfirm:Vn}),s.jsx(nA,{value:K,setValue:Q,showDeletionDialog:z,setShowDeletionDialog:De,onConfirm:Ai})]})},xA=()=>{const t=ot.c(13),[e,n]=_e.useState(!1);let r,a;t[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>{n(Cn())},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 zy(f):{success:!0,path:f},t[2]=e,t[3]=i):i=t[3];const l=i;let c;t[4]!==e?(c=async f=>e?await Uy():{success:!0},t[4]=e,t[5]=c):c=t[5];const d=c;let p;t[6]!==e?(p=async f=>e?await Wy():{success:!0},t[6]=e,t[7]=p):p=t[7];const m=p;let u;return t[8]!==e||t[9]!==l||t[10]!==d||t[11]!==m?(u={isDesktop:e,requestAccess:l,startAccessing:d,stopAccessing:m},t[8]=e,t[9]=l,t[10]=d,t[11]=m,t[12]=u):u=t[12],u},bA=t=>t==="/",Tl=t=>t.replace(/\\/g,"/"),lu=t=>{if(!t||bA(t))return t;let e=t;for(;e.length>1&&e.endsWith("/");)e=e.slice(0,-1);return e},pi=t=>t.endsWith("/"),yA=t=>{const e=t.trim();return!e||pi(e)?e:`${e}/`},cu=t=>t.lastIndexOf("/"),Wg=t=>{if(pi(t))return t;const e=cu(t);return e<0?t:t.slice(0,e+1)},vA=t=>{const e=cu(t);return t.slice(e+1)},Kg=t=>{const e=lu(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)}/`},wA=t=>pi(t)&&Kg(t)!==null,jA=(t,e)=>`${Wg(t)}${e}/`,Ia=t=>{if(!t)return null;const e=lu(Tl(t.trim()));return e?e.toLowerCase():null},Sf=(t,e)=>{const n=t.trim();return n==="~"?e:n.startsWith("~/")?`${e}${n.slice(1)}`:n},NA=t=>typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?t.metaKey&&!t.ctrlKey:t.ctrlKey&&!t.metaKey,Hc=t=>{if(!t)return;t.focus({preventScroll:!0});const e=t.value.length;t.setSelectionRange(e,e),t.scrollLeft=t.scrollWidth},SA=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 Tl(e.home.trim())}}catch{}return nn.getFilesystemHome().catch(()=>null)},kA=({open:t,onOpenChange:e})=>{const{t:n}=ut(),r=Ks(Ae=>Ae.homeDirectory),a=Cs(Ae=>Ae.projects),i=Cs(Ae=>Ae.addProject),l=Qn(Ae=>Ae.profiles),c=Qn(Ae=>Ae.globalIdentity),d=Qn(Ae=>Ae.defaultGitIdentityId),p=Qn(Ae=>Ae.loadProfiles),m=Qn(Ae=>Ae.loadGlobalIdentity),u=Qn(Ae=>Ae.loadDefaultGitIdentityId),f=_l(),{isDesktop:b,requestAccess:g,startAccessing:v}=xA(),{isMobile:x}=an(),h=o.useRef(null),j=o.useRef(null),y=o.useRef(new Map),[C,k]=o.useState(""),[w,S]=o.useState("~/"),[I,T]=o.useState([]),[P,A]=o.useState(!1),[N,E]=o.useState(!1),[M,O]=o.useState(0),[V,B]=o.useState(!1),[$,F]=o.useState(!1),[_,q]=o.useState(0),[L,Y]=o.useState(!1),[Z,ae]=o.useState(""),[re,me]=o.useState(null),fe=C||r,H=o.useMemo(()=>new Set(a.map(Ae=>Ia(Ae.path)).filter(Ae=>!!Ae)),[a]);o.useEffect(()=>{if(!t)return;S("~/"),T([]),O(0),B(!1),F(!1),Y(!1),ae(""),me(null),requestAnimationFrame(()=>Hc(h.current));let Ae=!1;return(async()=>{const De=await SA();Ae||(k(De||r||""),requestAnimationFrame(()=>Hc(h.current)))})(),()=>{Ae=!0}},[r,t]),o.useEffect(()=>{t&&(p(),m(),u())},[u,p,m,t]);const K=o.useMemo(()=>{const Ae=new Map;c&&Ae.set(c.id,c);for(const z of l)Ae.set(z.id,z);return Array.from(Ae.values())},[l,c]);o.useEffect(()=>{if(!t||!L||re!==null)return;const Ae=typeof d=="string"?d.trim():"";if(Ae&&K.some(De=>De.id===Ae)){me(Ae);return}const z=K.find(De=>De.authType==="ssh"||De.sshKey);z&&me(z.id)},[K,d,L,t,re]);const Q=o.useMemo(()=>K.find(Ae=>Ae.id===re)??null,[K,re]),W=o.useMemo(()=>Wg(w),[w]),de=o.useMemo(()=>pi(w)?"":vA(w),[w]),be=o.useMemo(()=>fe?Sf(W,fe):"",[W,fe]);o.useEffect(()=>{if(!t||!be){T([]);return}let Ae=!1;return A(!0),E(!1),nn.listLocalDirectory(be).then(z=>{if(Ae)return;E(!1);const De=z.filter(Xe=>Xe.isDirectory).map(Xe=>({name:Xe.name,path:Tl(Xe.path)})).sort((Xe,st)=>Xe.name.localeCompare(st.name));T(De)}).catch(()=>{Ae||(T([]),E(!0))}).finally(()=>{Ae||A(!1)}),()=>{Ae=!0}},[be,t]);const we=o.useMemo(()=>{const Ae=de.toLowerCase(),z=f||de.startsWith(".");return I.filter(De=>De.name.toLowerCase().startsWith(Ae)&&(z||!De.name.startsWith(".")))},[de,I,f]),te=o.useMemo(()=>{const Ae=[];wA(w)&&Ae.push({type:"up",value:"browse:up",name:"..",path:Kg(w)});for(const z of we){const De=Ia(z.path);Ae.push({type:"directory",value:`browse:${z.path}`,name:z.name,path:z.path,disabled:!!(De&&H.has(De))})}return Ae},[H,we,w]);o.useEffect(()=>{O(0)},[w,te.length]);const ge=o.useMemo(()=>fe?lu(Sf(w,fe)):"",[fe,w]),ue=Ia(ge),xe=!!(ue&&H.has(ue)),ne=o.useMemo(()=>de?we.find(Ae=>Ae.name===de)??null:null,[de,we]),pe=!!(ge&&!xe&&(pi(w)&&N||!pi(w)&&de.trim().length>0&&ne===null)),J=!V&&!$&&!xe&&!!ge,Se=J&&Z.trim().length>0,he=te[M]??null,Ie=!!(he&&(he.type==="up"||he.type==="directory"&&!he.disabled)),Pe=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?"⌘":"Ctrl",Ce=n(xe?"directoryExplorerDialog.actions.alreadyAdded":L?V?"directoryExplorerDialog.actions.cloning":"directoryExplorerDialog.actions.cloneAndAdd":V?"directoryExplorerDialog.actions.adding":pe?"directoryExplorerDialog.actions.createAndAdd":"directoryExplorerDialog.actions.addProject");o.useLayoutEffect(()=>{const Ae=j.current;if(!Ae)return;const z=()=>q(Math.ceil(Ae.getBoundingClientRect().width));if(z(),typeof ResizeObserver>"u")return;const De=new ResizeObserver(z);return De.observe(Ae),()=>De.disconnect()},[Ce]),o.useLayoutEffect(()=>{const Ae=h.current;Ae&&(Ae.scrollLeft=Ae.scrollWidth)},[_,w]),o.useLayoutEffect(()=>{t&&Hc(h.current)},[t]),o.useLayoutEffect(()=>{const Ae=te[M];Ae&&y.current.get(Ae.value)?.scrollIntoView({block:"nearest"})},[M,te]);const X=o.useCallback(()=>{e(!1)},[e]),ie=o.useCallback((Ae,z)=>{Ae.stopPropagation();const De=Ia(z);if(De&&H.has(De))return;i(z)||G.error(n("directoryExplorerDialog.toast.failedToAddProject"),{description:n("directoryExplorerDialog.toast.selectValidDirectoryPath")})},[i,H,n]),Ne=o.useCallback(async Ae=>{if(!Ae||V)return;const z=Ia(Ae);if(z&&H.has(z))return;let De=Ae;B(!0);try{const Xe=!L&&pe&&Ia(Ae)===Ia(ge);if(L){const tt=Z.trim();if(!tt){G.error(n("directoryExplorerDialog.toast.cloneUrlRequired"));return}De=(await nn.cloneRepository({remoteUrl:tt,destinationPath:Ae,gitIdentityId:Q?.id??null})).path}else Xe&&await nn.createDirectory(Ae,{allowOutsideWorkspace:!0});if(!i(De)){G.error(n("directoryExplorerDialog.toast.failedToAddProject"),{description:n("directoryExplorerDialog.toast.selectValidDirectoryPath")});return}X()}catch(Xe){G.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:Xe instanceof Error?Xe.message:n("directoryExplorerDialog.toast.unknownError")})}finally{B(!1)}},[i,H,Z,X,L,V,Q?.id,pe,ge,n]),oe=o.useCallback(Ae=>{S(yA(Ae))},[]),ke=o.useCallback(Ae=>{S(jA(w,Ae.name))},[w]),Te=o.useCallback(Ae=>{if(Ae){if(Ae.type==="up"){Ae.path&&oe(Ae.path);return}Ae.disabled||ke(Ae)}},[oe,ke]),Be=o.useCallback(async()=>{if(!(!b||$)){F(!0);try{const Ae=await g(ge);if(!Ae.success||!Ae.path){Ae.error&&Ae.error!=="Directory selection cancelled"&&G.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:Ae.error});return}const z=await v(Ae.path);if(!z.success){G.error(n("directoryExplorerDialog.toast.failedToOpenDirectory"),{description:z.error||n("directoryExplorerDialog.toast.desktopCouldNotGrantAccess")});return}await Ne(Ae.path)}catch(Ae){G.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:Ae instanceof Error?Ae.message:n("directoryExplorerDialog.toast.unknownError")})}finally{F(!1)}}},[Ne,b,$,g,v,n,ge]),je=o.useCallback(Ae=>{if(Ae.key==="ArrowDown"){Ae.preventDefault(),O(z=>Math.min(te.length-1,z+1));return}if(Ae.key==="ArrowUp"){Ae.preventDefault(),O(z=>Math.max(0,z-1));return}if(Ae.key==="Enter"){if(Ae.preventDefault(),NA(Ae)){Ne(ge);return}Ie&&Te(he);return}Ae.key==="Backspace"&&w===""&&(Ae.preventDefault(),X())},[Te,Ne,X,Ie,he,w,te.length,ge]),ee=s.jsxs("button",{type:"button",onClick:()=>Yo(!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(D,{name:"checkbox",className:"h-4 w-4 text-primary"}):s.jsx(D,{name:"checkbox-blank",className:"h-4 w-4"}),n("directoryExplorerDialog.toggle.showHidden")]}),R=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(Bt,{value:Z,onChange:Ae=>ae(Ae.target.value),placeholder:n("directoryExplorerDialog.clone.remoteUrlPlaceholder"),className:"min-w-0 flex-1 border-border/60 bg-[var(--surface-elevated)] font-mono typography-ui-label shadow-none",spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off"}),s.jsx(Bh,{activeProfile:Q,identities:K,onSelect:Ae=>me(Ae.id),isApplying:V,iconOnly:!0})]}):null,s.jsxs("div",{className:"relative",children:[s.jsx(D,{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(Bt,{ref:h,value:w,onChange:Ae=>S(Tl(Ae.target.value)),onKeyDown:je,placeholder:n("directoryExplorerDialog.pathInput.placeholder"),className:"border-transparent bg-transparent pl-9 font-mono typography-ui-label shadow-none focus-visible:ring-0",style:!x&&_>0?{paddingRight:`${_+24}px`}:void 0,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off"}),x?null:s.jsx(ve,{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:!J,onMouseDown:Ae=>Ae.preventDefault(),onClick:()=>{Ne(ge)},title:Ce,children:Ce})]})]}),U=s.jsx("div",{className:"relative min-h-0 flex-1 overflow-hidden rounded-xl border border-border/60 bg-[var(--surface-elevated)] shadow-sm",children:s.jsxs("div",{className:"max-h-[min(28rem,58vh)] overflow-y-auto p-2",children:[s.jsx("div",{className:"px-2 pb-1 pt-0.5 typography-meta font-medium uppercase tracking-wide text-muted-foreground/80",children:n("directoryExplorerDialog.browse.directories")}),P?s.jsx("div",{className:"py-10 text-center typography-ui-label text-muted-foreground",children:n("directoryExplorerDialog.browse.loading")}):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((Ae,z)=>{const De=z===M;return s.jsxs("button",{ref:Xe=>{Xe?y.current.set(Ae.value,Xe):y.current.delete(Ae.value)},type:"button",disabled:Ae.type==="directory"&&Ae.disabled,onMouseEnter:()=>O(z),onMouseDown:Xe=>Xe.preventDefault(),onClick:()=>Te(Ae),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",Ae.type==="directory"&&Ae.disabled&&"cursor-not-allowed opacity-45 hover:bg-transparent"),children:[Ae.type==="up"?s.jsx(D,{name:"arrow-left-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80"}):s.jsx(D,{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:Ae.name})}),Ae.type==="directory"&&Ae.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")}):Ae.type==="directory"?s.jsx("button",{type:"button",onMouseDown:Xe=>Xe.stopPropagation(),onClick:Xe=>ie(Xe,Ae.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(D,{name:"add",className:"h-3.5 w-3.5"})}):null]},Ae.value)})})]})}),le=s.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3",children:[R,U]}),Me=s.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 typography-micro text-muted-foreground",children:[s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx(D,{name:"arrow-up-s",className:"h-3.5 w-3.5"}),s.jsx(D,{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(D,{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:Pe}),s.jsx(D,{name:"corner-down-left",className:"h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.add")]})]}),Oe=()=>s.jsxs(s.Fragment,{children:[x?null:Me,s.jsxs("div",{className:ye("flex w-full flex-row justify-end gap-2 sm:w-auto",x&&"justify-stretch"),children:[b?s.jsx(ve,{variant:"ghost",size:"xs",onClick:Be,disabled:V||$||L,children:n($?"directoryExplorerDialog.actions.openingFinder":"directoryExplorerDialog.actions.openInFinder")}):null,s.jsx(ve,{variant:"ghost",size:"xs",onClick:()=>Y(Ae=>!Ae),disabled:V||$,className:ye(x&&"flex-1"),children:n(L?"directoryExplorerDialog.actions.addLocalProject":"directoryExplorerDialog.actions.cloneRepository")}),x?s.jsx(ve,{size:"xs",onClick:()=>{Ne(ge)},disabled:L?!Se:!J,className:"flex-1",children:Ce}):null]})]});return x?s.jsx(Br,{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}),le]})}):s.jsx(ps,{open:t,onOpenChange:e,children:s.jsxs(ms,{className:"flex w-full max-w-xl flex-col gap-0 overflow-hidden p-0 sm:max-h-[80vh]",initialFocus:!1,children:[s.jsx(gs,{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(fs,{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:le}),s.jsx(Hs,{className:"flex w-full flex-col gap-3 px-5 py-3 sm:flex-row sm:items-center sm:justify-between",children:Oe()})]})})},Pa=t=>t?s.jsx("span",{className:"text-foreground/80 dark:text-foreground/70",children:t}):void 0,Lr=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},CA=()=>{const{t}=ut(),[e,n]=o.useState(!1),[r,a]=o.useState(!1),[i,l]=o.useState(null),[c,d]=o.useState([]),[p,m]=o.useState(!1),[u,f]=o.useState(!1),[b,g]=o.useState(!1),[v,x]=o.useState(!1),[h,j]=o.useState(new Set),y=$t(J=>J.getWorktreeMetadata),C=$t(J=>J.newSessionDraft),k=$t(J=>J.setNewSessionDraftTarget),w=$t(J=>J.setDraftBootstrapPendingDirectory),S=Ky,I=qy,T=$t(J=>J.deleteSessions),P=$t(J=>J.archiveSessions),A=Re(J=>J.showDeletionDialog),N=Re(J=>J.setShowDeletionDialog),E=Ks(J=>J.currentDirectory),M=Ks(J=>J.homeDirectory),O=Ks(J=>J.isHomeReady),V=Cs(J=>J.projects),B=Cs(J=>J.activeProjectId),{isMobile:$,isTablet:F,hasTouchInput:_}=an(),q=$||F||_,L=o.useMemo(()=>{const Se=(B?V.find(he=>he.id===B)??null:null)?.path??E;return Lr(Se)},[B,E,V]),Y=o.useCallback(J=>{const he=Lr(J.projectDirectory)||L;return{id:(V.find(Pe=>Lr(Pe.path)===he)??null)?.id??`path:${he}`,path:he}},[L,V]),Z=v&&h.size>0,ae=o.useMemo(()=>{const J=i?.worktree;return J&&typeof J.branch=="string"&&J.branch.trim().length>0?!0:c.length>0&&c.every(({metadata:Se})=>typeof Se.branch=="string"&&Se.branch.trim().length>0)},[i?.worktree,c]),re=i?.mode==="worktree",me=re,fe=b||!re||!ae,H=b||!re;o.useEffect(()=>{r||!O||V.length>0||(a(!0),n(!0))},[r,O,V.length]);const K=o.useCallback(J=>{l({sessions:J.sessions,dateLabel:J.dateLabel,mode:J.mode??"session",worktree:J.worktree??null})},[]),Q=o.useCallback(()=>{l(null),d([]),m(!1),f(!1),g(!1),x(!1),j(new Set)},[]),W=o.useCallback(async J=>{if(J.sessions.length===0)return;if(J.sessions.length===1){const Pe=J.sessions[0];await S(Pe.id)?G.success(t("sessions.sidebar.session.delete.success")):G.error(t("sessions.sidebar.session.delete.error"));return}const Se=J.sessions.map(Pe=>Pe.id),{deletedIds:he,failedIds:Ie}=await T(Se);if(he.length>0){const Pe=Ie.length>0?Ie.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:Ie.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:Ie.length}):J.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:J.dateLabel}):void 0;G.success(he.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:he.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:he.length}),{description:Pa(Pe)})}Ie.length>0&&G.error(Ie.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:Ie.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:Ie.length}),{description:Pa(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))})},[S,T,t]);o.useEffect(()=>Ar.onDeleteRequest(J=>{if(!A&&(J.mode??"session")==="session"){W(J);return}K(J)}),[K,A,W]),o.useEffect(()=>Ar.onDirectoryRequest(()=>{n(!0)}),[]),o.useEffect(()=>{if(!i){d([]),m(!1),f(!1),x(!1),j(new Set);return}const J=i.sessions.map(Ie=>{const Pe=y(Ie.id);return Pe?{session:Ie,metadata:Pe}:null}).filter(Ie=>!!Ie);d(J),m(!1),x(!1),j(new Set);const Se=new Map;if(i.worktree?.path&&Se.set(Lr(i.worktree.path),i.worktree),J.forEach(({metadata:Ie})=>{Ie.path&&Se.set(Lr(Ie.path),Ie)}),Se.size===0){x(!0);return}let he=!1;return(async()=>{const Ie=new Map,Pe=new Set;await Promise.all(Array.from(Se.entries()).map(async([Ce,X])=>{try{const ie=await Hy(X.path);Ie.set(Ce,ie),ie?.isDirty&&Pe.add(Ce)}catch{X.status&&(Ie.set(Ce,X.status),X.status.isDirty&&Pe.add(Ce))}})).catch(Ce=>{console.warn("Failed to inspect worktree status before deletion:",Ce)}),!he&&(j(Pe),x(!0),l(Ce=>{if(!Ce?.worktree?.path)return Ce;const X=Lr(Ce.worktree.path),ie=Ie.get(X);if(!ie)return Ce;const Ne=Ce.worktree.status;return Ne?.isDirty===ie.isDirty&&Ne?.ahead===ie.ahead&&Ne?.behind===ie.behind&&Ne?.upstream===ie.upstream?Ce:{...Ce,worktree:{...Ce.worktree,status:ie}}}),d(Ce=>Ce.map(X=>{const ie=Lr(X.metadata.path),Ne=Ie.get(ie);return Ne?{session:X.session,metadata:{...X.metadata,status:Ne}}:X})))})(),()=>{he=!0}},[i,y]),o.useEffect(()=>{ae||m(!1)},[ae]);const de=o.useCallback(async(J,Se)=>{const he=p&&ae,Ie=Y(J),Pe=Lr(J.path),Ce=Lr(Ie.path);try{await Gy(Ie,J,{deleteRemoteBranch:he,deleteLocalBranch:Se});const X=Lr(C?.directoryOverride);return C?.open&&Pe&&X===Pe&&Ce&&(w(null),k({projectId:Ie.id,directoryOverride:Ce},{force:!0})),Lr(E)===Pe&&Ce&&Ks.getState().setDirectory(Ce,{showOverlay:!1}),!0}catch(X){return G.error(t("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle"),{description:Pa(X instanceof Error?X.message:t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),!1}},[ae,E,p,Y,C?.directoryOverride,C?.open,w,k,t]),be=o.useCallback(async()=>{if(i){g(!0);try{const J=me,Se=J&&p,he=J&&u;if(i.sessions.length===0&&re&&i.worktree){if(!await de(i.worktree,he)){Q();return}const Ce=t(p&&ae?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.removed");G.success(t("sessions.sidebar.sessionDialogs.worktree.removedTitle"),{description:Pa(Ce)}),Q();return}if(i.sessions.length===1){const Ie=i.sessions[0];if(!(re?await I(Ie.id):await S(Ie.id,{archiveWorktree:!1,deleteRemoteBranch:Se,deleteLocalBranch:he}))){G.error(t(re?"sessions.sidebar.session.archive.error":"sessions.sidebar.session.delete.error")),g(!1);return}const Ce=!re&&J?t(Se?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.attachedArchived"):void 0;G.success(t(re?"sessions.sidebar.session.archive.success":"sessions.sidebar.session.delete.success"),{description:Pa(Ce),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}else{const Ie=i.sessions.map(X=>X.id);let Pe=[],Ce=[];if(re){const X=await P(Ie);Pe=X.archivedIds,Ce=X.failedIds}else{const X=await T(Ie);Pe=X.deletedIds,Ce=X.failedIds}if(re&&i.worktree&&Ce.length===0&&await de(i.worktree,he),Pe.length>0){const X=!re&&J?t(Se?"sessions.sidebar.sessionDialogs.worktree.archivedAndRemoteRemoved":"sessions.sidebar.sessionDialogs.worktree.attachedArchivedPlural"):void 0,Ne=[Ce.length>0?re?Ce.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToArchive",{count:Ce.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToArchive",{count:Ce.length}):Ce.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:Ce.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:Ce.length}):i.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:i.dateLabel}):void 0,X].filter(Boolean).join(" ");G.success(re?Pe.length===1?t("sessions.sidebar.bulkActions.archivedSingle",{count:Pe.length}):t("sessions.sidebar.bulkActions.archivedPlural",{count:Pe.length}):Pe.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:Pe.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:Pe.length}),{description:Pa(Ne||void 0),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}if(Ce.length>0&&(G.error(re?Ce.length===1?t("sessions.sidebar.bulkActions.failedArchiveSingle",{count:Ce.length}):t("sessions.sidebar.bulkActions.failedArchivePlural",{count:Ce.length}):Ce.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:Ce.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:Ce.length}),{description:Pa(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),Pe.length===0)){g(!1);return}}re&&i.sessions.length===1&&i.worktree&&await de(i.worktree,he),Q()}finally{g(!1)}}},[i,p,u,S,T,I,P,Q,me,re,ae,de,t]),we=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}):"",ge=i?s.jsxs("div",{className:ye(re?"space-y-3":"space-y-2"),children:[i.sessions.length>0&&s.jsxs("div",{className:ye(re?"rounded-lg bg-muted/30 p-3":"space-y-1.5 rounded-xl border border-border/40 bg-sidebar/60 p-3"),children:[re&&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(re?"mt-2 space-y-1":"space-y-0.5"),children:[i.sessions.slice(0,5).map(J=>s.jsxs("li",{className:ye(re?"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(!re&&"hidden"),children:"•"}),s.jsx("span",{className:"truncate",children:J.title||t("sessions.sidebar.session.untitled")})]},J.id)),i.sessions.length>5&&s.jsx("li",{className:ye(re?"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})})]})]}),re?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(D,{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")}),we?.label?s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:we.label}):null]}),s.jsx("p",{className:"typography-micro text-muted-foreground/80 break-all",children:we?ao(we.path,M):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,ue=re?ae?s.jsxs("button",{type:"button",onClick:()=>{fe||m(J=>!J)},disabled:fe,className:ye("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",fe?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[p?s.jsx(D,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(D,{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=re?s.jsxs("button",{type:"button",onClick:()=>{H||f(J=>!J)},disabled:H,className:ye("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",H?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[u?s.jsx(D,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(D,{name:"checkbox-blank",className:"size-4"}),t("sessions.sidebar.sessionDialogs.actions.deleteLocalBranch")]}):null,ne=re?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,ue]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ve,{variant:"ghost",onClick:Q,disabled:b,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(ve,{variant:"destructive",onClick:be,disabled:b,children:t(b?"sessions.sidebar.sessionDialogs.actions.deleting":"sessions.sidebar.sessionDialogs.actions.deleteWorktree")})]})]}):s.jsxs("div",{className:"flex w-full items-center justify-between gap-3",children:[s.jsxs("button",{type:"button",onClick:()=>N(!A),className:"inline-flex items-center gap-1.5 typography-meta text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":!A,children:[A?s.jsx(D,{name:"checkbox-blank",className:"size-4"}):s.jsx(D,{name:"checkbox",className:"size-4 text-primary"}),t("sessions.sidebar.dialogs.neverAsk")]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ve,{variant:"ghost",onClick:Q,disabled:b,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(ve,{variant:"destructive",onClick:be,disabled:b,children:b?t("sessions.sidebar.sessionDialogs.actions.deleting"):i?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction")})]})]}),pe=re?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(Br,{open:!!i,onClose:()=>{b||Q()},title:pe,footer:s.jsx("div",{className:"flex justify-end gap-2",children:ne}),children:s.jsxs("div",{className:"space-y-2 pb-2",children:[te&&s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:te}),ge]})}):s.jsx(ps,{open:!!i,onOpenChange:J=>{if(!J){if(b)return;Q()}},children:s.jsxs(ms,{className:ye(re?"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(gs,{children:[s.jsxs(fs,{className:ye(re&&"flex items-center gap-2"),children:[re&&s.jsx(D,{name:"delete-bin",className:"h-5 w-5"}),pe]}),te&&s.jsx(Ns,{children:te})]}),s.jsx("div",{className:ye(re&&"flex-1 min-h-0 overflow-y-auto space-y-2"),children:ge}),s.jsx(Hs,{className:"mt-2 gap-2 pt-1 pb-1",children:ne})]})}),s.jsx(kA,{open:e,onOpenChange:n})]})},Pd=t=>t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").substring(0,50),IA=(t,e)=>{const n=Pd(t),r=Pd(e);return`${n}-${r}`.substring(0,60)},kf=(t,e)=>`${t}/${e}`,PA=()=>{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=Ks.getState().currentDirectory??null;if(r&&r.trim().length>0){const a=r.replace(/\\/g,"/").replace(/\/+$/,"")||r;return{id:`path:${a}`,path:a}}return null},Gc=rr()(Si(t=>({isLoading:!1,error:null,createMultiRun:async e=>{const n=e.name.trim(),{groups:r,agent:a,files:i,setupCommands:l}=e;if(!n)return t({error:"Group name is required"}),null;if(!r||r.length===0)return t({error:"At least one run group is required"}),null;for(let c=0;c<r.length;c++){if(!r[c].prompt.trim())return t({error:`Group ${c+1}: prompt is required`}),null;if(r[c].models.length<1)return t({error:`Group ${c+1}: select at least 1 model`}),null;if(r[c].models.length>5)return t({error:`Group ${c+1}: maximum 5 models allowed`}),null}t({isLoading:!0,error:null});try{const c=PA();if(!c)return t({error:"Select a project",isLoading:!1}),null;const d=c.path,m=await oh(d)&&e.isolateRuns!==!1,u=Pd(n),f=m?await xo(d):void 0,b=m?await Yy(d):null,g=[],v=l?.filter(C=>C.trim().length>0)??[];for(let C=0;C<r.length;C++){const k=r[C],w=k.prompt,S=new Map;for(const T of k.models){const P=`${T.providerID}:${T.modelID}`;S.set(P,(S.get(P)||0)+1)}const I=new Map;for(const T of k.models){const P=`${T.providerID}:${T.modelID}`,A=S.get(P)||1,N=(I.get(P)||0)+1;I.set(P,N);const E=IA(T.providerID,T.modelID),M=r.length>1?`g${C+1}`:void 0,O=A>1?kf(u,`${E}/${N}`):kf(u,E),V=M?`${M}/${O}`:O,B=OP({groupSlug:u,runGroup:M,providerID:T.providerID,modelID:T.modelID,index:A>1?N:void 0});try{if(!m){const q=await nn.withDirectory(d,()=>nn.createSession({title:B}));g.push({sessionId:q.id,worktreePath:d,providerID:T.providerID,modelID:T.modelID,variant:T.variant,prompt:w});continue}const $=await Qy(c,{preferredName:V,mode:"new",branchName:V,worktreeName:V,startRef:e.worktreeBaseBranch||"HEAD",setupCommands:v},{resolvedRootTrackingRemote:b}),F={...$,createdFromBranch:f,kind:"standard"},_=await nn.withDirectory($.path,()=>nn.createSession({title:B}));$t.getState().setWorktreeMetadata(_.id,F),g.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 x=l?.filter(C=>C.trim().length>0)??[];x.length>0&&lh(c,x).catch(()=>{console.warn("[MultiRun] Failed to save worktree setup commands")});const h=g.map(C=>C.sessionId),j=g[0]?.sessionId??null;if(h.length===0)return t({error:"Failed to create any sessions",isLoading:!1}),null;const y=i?.map(C=>({type:"file",mime:C.mime,filename:C.filename,url:C.url}));return(async()=>{try{const C=Ul.getState().expandText;await Promise.allSettled(g.map(async k=>{try{const w=await C(k.prompt).catch(()=>k.prompt);await nn.withDirectory(k.worktreePath,()=>nn.sendMessage({id:k.sessionId,providerID:k.providerID,modelID:k.modelID,variant:k.variant,text:w,agent:a,files:y}))}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"})),AA="oc:lastWorktreeSourceBranch";function Hg(t){const e=ot.c(30),{git:n}=Bn(),r=Od(t),a=Fd(t),i=Ld(t),l=ph(t),c=Qs(RA),d=Qs(EA);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]),o.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],o.useEffect(u,b);const g=i||a===!0&&l;let v;e:{if(!r?.all){let S;e[19]===Symbol.for("react.memo_cache_sentinel")?(S=[],e[19]=S):S=e[19],v=S;break e}let w;e[20]!==r.all?(w=r.all.filter(MA).sort(),e[20]=r.all,e[21]=w):w=e[21],v=w}const x=v;let h;e:{if(!r?.all){let S;e[22]===Symbol.for("react.memo_cache_sentinel")?(S=[],e[22]=S):S=e[22],h=S;break e}let w;e[23]!==r.all?(w=r.all.filter(TA).map(DA).sort(),e[23]=r.all,e[24]=w):w=e[24],h=w}const j=h;let y;e:{if(!t){y=null;break e}if(a!==null){y=a;break e}if(g){y=null;break e}y=r?.all?!0:null}const C=y;let k;return e[25]!==C||e[26]!==g||e[27]!==x||e[28]!==j?(k={localBranches:x,remoteBranches:j,isLoading:g,isGitRepository:C},e[25]=C,e[26]=g,e[27]=x,e[28]=j,e[29]=k):k=e[29],k}function DA(t){return t.replace(/^remotes\//,"")}function TA(t){return t.startsWith("remotes/")}function MA(t){return!t.startsWith("remotes/")}function EA(t){return t.fetchStatus}function RA(t){return t.fetchBranches}const FA=({directory:t,value:e,onChange:n,className:r,disabled:a,id:i})=>{const{t:l}=ut(),{localBranches:c,remoteBranches:d,isLoading:p,isGitRepository:m}=Hg(t),u=o.useMemo(()=>[...c,...d.map(b=>`remotes/${b}`)],[c,d]);o.useEffect(()=>{if(a||p||u.length===0||e&&u.includes(e))return;(async()=>{try{const g=t?await xo(t).catch(()=>null):null,v=localStorage.getItem(AA);v&&u.includes(v)?n(v):g&&u.includes(g)?n(g):u.includes("main")?n("main"):u.includes("master")?n("master"):u[0]&&n(u[0])}catch{}})()},[u,t,a,p,n,e]);const f=a||!m||p;return s.jsxs("div",{children:[s.jsxs(is,{value:e,onValueChange:n,disabled:f,children:[s.jsx(os,{id:i,size:"lg",className:r??"w-fit typography-meta text-foreground",children:s.jsx(us,{placeholder:l(p?"multiRun.branchSelector.status.loadingBranches":"multiRun.branchSelector.placeholder.selectSourceBranch")})}),s.jsx(ls,{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:l("multiRun.branchSelector.status.loadingBranches")}):c.length===0&&d.length===0?s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:l("multiRun.branchSelector.status.noBranchesFound")}):s.jsxs(s.Fragment,{children:[c.length>0&&s.jsxs(td,{children:[s.jsx(Wu,{className:"font-semibold text-foreground",children:l("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(Jy,{}),d.length>0&&s.jsxs(td,{children:[s.jsx(Wu,{className:"font-semibold text-foreground",children:l("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:l("multiRun.branchSelector.status.notInGitRepository")})]})},OA=10*1024*1024,qc=5,cl=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(D,{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},Ea=t=>{const e=ot.c(9),{htmlFor:n,required:r,children:a,info:i}=t;let l;e[0]!==r?(l=r&&s.jsx("span",{className:"text-destructive ml-0.5",children:"*"}),e[0]=r,e[1]=l):l=e[1];let c;e[2]!==a||e[3]!==n||e[4]!==l?(c=s.jsxs("label",{htmlFor:n,className:"typography-meta font-medium text-foreground",children:[a,l]}),e[2]=a,e[3]=n,e[4]=l,e[5]=c):c=e[5];const d=i&&i;let 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},LA=({initialPrompt:t,onCreated:e,onCancel:n,isWindowed:r=!1})=>{const{t:a}=ut(),[i,l]=o.useState(""),[c,d]=o.useState(()=>[{id:Zi(),prompt:"",models:[]}]),[p,m]=o.useState(""),[u,f]=o.useState([]),[b,g]=o.useState(!1),[v,x]=o.useState([]),[h,j]=o.useState(!1),[y,C]=o.useState(!1),[k,w]=o.useState(!0),S=o.useRef(null),I=Ks(X=>X.currentDirectory??null),T=Ks(X=>X.homeDirectory??null),P=o.useMemo(()=>{if(typeof window>"u")return null;const X=window.__VSCODE_CONFIG__?.workspaceFolder;return typeof X=="string"&&X.trim().length>0?X.trim():null},[]),A=Cs(X=>X.activeProjectId),N=Cs(X=>X.setActiveProjectIdOnly),E=Cs(X=>X.projects),[M,O]=o.useState(()=>A??null);o.useEffect(()=>{if(A){O(A);return}!M&&E.length>0&&O(E[0].id)},[A,E,M]);const V=o.useMemo(()=>M?E.find(X=>X.id===M)??null:null,[E,M]),B=V?.path??I,$=o.useCallback(X=>{O(X),X!==A&&N(X)},[A,N]),{currentTheme:F}=vr(),_=o.useCallback(X=>{const ie=X.label?.trim()||Ua(X.path,T),Ne=yo({id:X.id,iconImage:X.iconImage??null},{themeVariant:F.metadata.variant,iconColor:F.colors.surface.foreground}),oe=X.icon?zl[X.icon]:null,ke=X.color?vo[X.color]:void 0;return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[Ne?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:Ne,alt:"",className:"h-full w-full object-contain",draggable:!1})}):oe?s.jsx(D,{name:oe,className:"h-3.5 w-3.5 shrink-0",style:ke?{color:ke}:void 0}):s.jsx(D,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:ke?{color:ke}:void 0}),s.jsx("span",{className:"truncate",children:ie})]})},[T,F.metadata.variant,F.colors.surface.foreground]),q=o.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]=o.useState(()=>typeof window<"u"?Cn():!1),Y=o.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),Z=Gf(),ae=o.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 ie=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!ie)return null;const Ne=Number.parseInt(ie[1],10),oe=Number.parseInt(ie[2],10);return Number.isNaN(Ne)?null:Ne===10?oe:Ne},[]),re=o.useMemo(()=>L&&Y||Z?"pl-[5.5rem]":"pl-3",[L,Y,Z]),me=o.useMemo(()=>!L||!Y||ae===null?"":ae>=26?"h-12":ae<=15?"h-14":"",[L,Y,ae]),fe=o.useCallback(async X=>{X.target.closest("button, a, input, select, textarea")||X.button===0&&L&&await Xy()},[L]);o.useEffect(()=>{if(!n)return;const X=ie=>{ie.key==="Escape"&&(ie.preventDefault(),ie.stopPropagation(),n())};return window.addEventListener("keydown",X,!0),()=>window.removeEventListener("keydown",X,!0)},[n]);const[H,K]=o.useState(""),{isLoading:Q,isGitRepository:W}=Hg(B),de=o.useRef(!1),be=W===!0,we=be&&k;o.useEffect(()=>{if(W===!1){de.current=!0,w(!1);return}W===!0&&de.current&&(de.current=!1,w(!0))},[W]);const te=Gc(X=>X.createMultiRun),ge=Gc(X=>X.error),ue=Gc(X=>X.clearError);o.useEffect(()=>{typeof t=="string"&&t.trim().length>0&&d(X=>{const ie=[...X];return ie.length>0&&!ie[0].prompt.trim()&&(ie[0]={...ie[0],prompt:t}),ie})},[t]),o.useEffect(()=>{if(!q)return;let X=!1;return C(!0),(async()=>{try{const ie=await Ud(q);X||x(ie)}catch{}finally{X||C(!1)}})(),()=>{X=!0}},[q]);const xe=o.useCallback((X,ie)=>{d(Ne=>Ne.map(oe=>oe.id===X?{...oe,...ie}:oe))},[]),ne=o.useCallback(X=>{d(ie=>ie.filter(Ne=>Ne.id!==X))},[]),pe=o.useCallback(()=>{d(X=>[...X,{id:Zi(),prompt:"",models:[]}])},[]),J=async X=>{const ie=X.target.files;if(!ie)return;let Ne=0;for(let oe=0;oe<ie.length;oe++){const ke=ie[oe];if(ke.size>OA){G.error(a("multirun.launcher.toast.fileTooLarge",{fileName:ke.name}));continue}try{const Te=await new Promise((Be,je)=>{const ee=new FileReader;ee.onload=()=>Be(ee.result),ee.onerror=je,ee.readAsDataURL(ke)});f(Be=>[...Be,{id:Zi(),filename:ke.name,mimeType:ke.type||"application/octet-stream",size:ke.size,dataUrl:Te}]),Ne++}catch(Te){console.error("File attach failed",Te),G.error(a("multirun.launcher.toast.attachFailed",{fileName:ke.name}))}}Ne>0&&G.success(Ne===1?a("multirun.launcher.toast.attachedSingle",{count:Ne}):a("multirun.launcher.toast.attachedPlural",{count:Ne})),S.current&&(S.current.value="")},Se=X=>{f(ie=>ie.filter(Ne=>Ne.id!==X))},he=o.useMemo(()=>c.reduce((X,ie)=>X+ie.models.length,0),[c]),Ie=async X=>{X.preventDefault();const ie=c.filter(Ne=>Ne.prompt.trim()&&Ne.models.length>=1);if(ie.length!==0&&!(he<1)){g(!0),ue();try{M&&M!==A&&N(M);const Ne=u.map(je=>({mime:je.mimeType,filename:je.filename,url:je.dataUrl})),oe=v.filter(je=>je.trim().length>0),ke=ie.map(je=>({prompt:je.prompt.trim(),models:je.models.map(ee=>({providerID:ee.providerID,modelID:ee.modelID,displayName:ee.displayName,variant:ee.variant}))})),Te={name:i.trim(),groups:ke,agent:p||void 0,worktreeBaseBranch:we?H:void 0,isolateRuns:we,files:Ne.length>0?Ne:void 0,setupCommands:oe.length>0?oe:void 0},Be=await te(Te);Be&&(Be.firstSessionId&&$t.getState().setCurrentSession(Be.firstSessionId),e?.())}finally{g(!1)}}},Pe=!!(i.trim()&&c.some(X=>X.prompt.trim()&&X.models.length>=1)&&he>=1&&B&&!Q&&(W===!1||!we||H)),Ce=v.filter(X=>X.trim()).length;return s.jsxs("form",{onSubmit:Ie,className:"flex flex-col h-full bg-background",children:[r?null:s.jsxs("header",{onMouseDown:fe,className:ye("relative flex h-12 shrink-0 items-center justify-center border-b app-region-drag select-none",re,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(D,{name:"close",className:"h-5 w-5"})})}),s.jsx(It,{children:s.jsx("p",{children:a("multirun.launcher.actions.closeEsc")})})]})})]}),s.jsx(go,{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(Ea,{htmlFor:"multirun-project",required:!0,children:a("multirun.launcher.project.label")}),E.length>0?s.jsxs(is,{value:M??void 0,onValueChange:$,children:[s.jsx(os,{id:"multirun-project",size:"lg",className:"w-fit max-w-full",children:V?s.jsx(us,{children:_(V)}):s.jsx(us,{placeholder:a("multirun.launcher.project.placeholder")})}),s.jsx(ls,{fitContent:!0,children:E.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(Ea,{htmlFor:"group-name",required:!0,info:s.jsx(cl,{children:a("multirun.launcher.groupName.info")}),children:a("multirun.launcher.groupName.label")}),s.jsx(Bt,{id:"group-name",value:i,onChange:X=>l(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(Ea,{htmlFor:"multirun-worktree-base-branch",info:s.jsx(cl,{children:a("multirun.launcher.baseBranch.info")}),children:a("multirun.launcher.baseBranch.label")}),s.jsx(FA,{directory:B,value:H,onChange:K,disabled:!we,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(xs,{checked:k,onChange:w,disabled:!be,ariaLabel:a("multirun.launcher.isolateRuns.label")}),s.jsx("span",{children:a("multirun.launcher.isolateRuns.label")})]})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Ea,{htmlFor:"multirun-agent",info:s.jsx(cl,{children:a("multirun.launcher.agent.info")}),children:a("multirun.launcher.agent.label")}),s.jsx($g,{value:p,onChange:m,id:"multirun-agent"})]})]}),s.jsxs(br,{open:h,onOpenChange:j,children:[s.jsxs(Tr,{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(D,{name:"terminal",className:"h-3.5 w-3.5 text-muted-foreground/70"}),s.jsx("span",{className:"typography-meta font-medium text-muted-foreground group-hover:text-foreground transition-colors",children:a("multirun.launcher.setupCommands.label")}),Ce>0&&s.jsx("span",{className:"inline-flex items-center justify-center h-4 min-w-4 px-1 rounded-full typography-micro font-medium",style:{backgroundColor:"var(--primary-base)",color:"var(--primary-foreground)",fontSize:"0.625rem",lineHeight:1},children:Ce}),s.jsx(D,{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(yr,{children:s.jsx("div",{className:"pt-2 space-y-1.5",children:y?s.jsx("p",{className:"typography-meta text-muted-foreground/70 px-2",children:a("multirun.launcher.setupCommands.loading")}):s.jsxs(s.Fragment,{children:[v.map((X,ie)=>s.jsxs("div",{className:"flex gap-1.5",children:[s.jsx(Bt,{value:X,onChange:Ne=>{const oe=[...v];oe[ie]=Ne.target.value,x(oe)},placeholder:a("multirun.launcher.setupCommands.commandPlaceholder"),className:"h-8 flex-1 font-mono text-xs"}),s.jsx("button",{type:"button",onClick:()=>x(v.filter((Ne,oe)=>oe!==ie)),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(D,{name:"close",className:"h-3.5 w-3.5"})})]},`${X}-${ie}`)),s.jsxs("button",{type:"button",onClick:()=>x([...v,""]),className:"flex items-center gap-1 typography-meta text-muted-foreground hover:text-foreground transition-colors px-1",children:[s.jsx(D,{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(Ea,{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:S,type:"file",multiple:!0,className:"hidden",onChange:J,accept:"*/*"}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>S.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(D,{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(D,{name:"file-image",className:"h-3 w-3 text-muted-foreground"}):s.jsx(D,{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(D,{name:"close",className:"h-3 w-3"})})]},X.id))]})]}),c.map((X,ie)=>s.jsx($A,{group:X,groupIndex:ie,canRemove:c.length>1,onUpdate:xe,onRemove:ne},X.id)),s.jsxs("button",{type:"button",onClick:pe,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(D,{name:"add",className:"h-3.5 w-3.5"}),a("multirun.launcher.groups.addGroup")]}),ge&&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:ge})]})})}),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:[!we&&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(D,{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(ve,{type:"button",variant:"ghost",size:"sm",onClick:n,children:a("multirun.launcher.actions.cancel")}),s.jsx(ve,{type:"submit",size:"sm",disabled:!Pe||b,children:b?a("multirun.launcher.actions.creating"):s.jsx(s.Fragment,{children:a("multirun.launcher.actions.startWithRunCount",{count:he})})})]})})]})},$A=t=>{const e=ot.c(99),{group:n,groupIndex:r,canRemove:a,onUpdate:i,onRemove:l}=t,{t:c}=ut(),[d,p]=o.useState(!1),[m,u]=o.useState(""),[f,b]=o.useState(!1),[g,v]=o.useState(""),[x,h]=o.useState(!1),[j,y]=o.useState(""),C=o.useRef(null),k=o.useRef(null),w=o.useRef(null),S=o.useRef(null);let I;e[0]!==n.id||e[1]!==n.models||e[2]!==i?(I=oe=>{n.models.length>=qc||i(n.id,{models:[...n.models,oe]})},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=oe=>{i(n.id,{models:n.models.filter((ke,Te)=>Te!==oe)})},e[4]=n.id,e[5]=n.models,e[6]=i,e[7]=P):P=e[7];const A=P;let N;e[8]!==n.id||e[9]!==n.models||e[10]!==i?(N=(oe,ke)=>{i(n.id,{models:n.models.map((Te,Be)=>Be===oe?ke:Te)})},e[8]=n.id,e[9]=n.models,e[10]=i,e[11]=N):N=e[11];const E=N;let M;e[12]===Symbol.for("react.memo_cache_sentinel")?(M=(oe,ke)=>{if(oe.startsWith("/")){const ee=oe.indexOf(" "),R=oe.indexOf(`
|
|
229
|
-
`),U=Math.min(ee===-1?oe.length:ee,R===-1?oe.length:R);if(ke<=U&&ee===-1){v(oe.substring(1,U)),b(!0),p(!1),h(!1);return}}b(!1);const Te=oe.substring(0,ke),Be=Te.lastIndexOf("#");if(Be!==-1){const ee=Be>0?Te[Be-1]:null,R=Te.substring(Be+1);if((!ee||/\s/.test(ee))&&!R.includes(" ")&&!R.includes(`
|
|
230
|
-
`)){y(R),h(!0),p(!1);return}}h(!1);const je=Te.lastIndexOf("@");if(je!==-1){const ee=je>0?Te[je-1]:null,R=Te.substring(je+1);(!ee||/\s/.test(ee))&&!R.includes(" ")&&!R.includes(`
|
|
231
|
-
`)?(u(R),p(!0)):p(!1);return}p(!1)},e[12]=M):M=e[12];const O=M;let V;e[13]!==n.id||e[14]!==i?(V=oe=>{i(n.id,{prompt:oe})},e[13]=n.id,e[14]=i,e[15]=V):V=e[15];const B=V;let $;e[16]!==n.prompt||e[17]!==B?($=oe=>{const ke=n.prompt,Be=C.current?.selectionStart??ke.length,ee=ke.substring(0,Be).lastIndexOf("@"),R=oe.relativePath&&oe.relativePath.trim().length>0?oe.relativePath.trim():oe.path||oe.name,U=ee!==-1?ee:Be,le=`${ke.substring(0,U)}@${R} ${ke.substring(Be)}`,Me=U+R.length+2;B(le),p(!1),u(""),requestAnimationFrame(()=>{const Oe=C.current;Oe&&(Oe.selectionStart=Me,Oe.selectionEnd=Me,Oe.focus()),O(le,Me)})},e[16]=n.prompt,e[17]=B,e[18]=$):$=e[18];const F=$;let _;e[19]!==n.prompt||e[20]!==B?(_=oe=>{const ke=n.prompt,Be=C.current?.selectionStart??ke.length,ee=ke.substring(0,Be).lastIndexOf("@"),R=ee!==-1?ee:Be,U=`${ke.substring(0,R)}@${oe} ${ke.substring(Be)}`,le=R+oe.length+2;B(U),p(!1),u(""),requestAnimationFrame(()=>{const Me=C.current;Me&&(Me.selectionStart=le,Me.selectionEnd=le,Me.focus()),O(U,le)})},e[19]=n.prompt,e[20]=B,e[21]=_):_=e[21];const q=_;let L;e[22]!==B?(L=oe=>{const ke=`/${oe.name} `;B(ke),b(!1),v(""),h(!1),requestAnimationFrame(()=>{const Te=C.current;Te&&(Te.focus(),Te.selectionStart=Te.value.length,Te.selectionEnd=Te.value.length),O(ke,ke.length)})},e[22]=B,e[23]=L):L=e[23];const Y=L;let Z;e[24]!==n.prompt||e[25]!==B?(Z=(oe,ke)=>{const Te=n.prompt,je=C.current?.selectionStart??Te.length,R=Te.substring(0,je).lastIndexOf("#"),U=R!==-1?R:je,le=`${Te.substring(0,U)}#${ke} ${Te.substring(je)}`,Me=U+ke.length+2;B(le),h(!1),y(""),requestAnimationFrame(()=>{const Oe=C.current;Oe&&(Oe.selectionStart=Me,Oe.selectionEnd=Me,Oe.focus()),O(le,Me)})},e[24]=n.prompt,e[25]=B,e[26]=Z):Z=e[26];const ae=Z;let re;e[27]!==f||e[28]!==d||e[29]!==x?(re=oe=>{if(f&&w.current&&(oe.key==="Enter"||oe.key==="ArrowUp"||oe.key==="ArrowDown"||oe.key==="Escape"||oe.key==="Tab")){oe.preventDefault(),w.current.handleKeyDown(oe.key);return}d&&k.current&&(oe.key==="Enter"||oe.key==="ArrowUp"||oe.key==="ArrowDown"||oe.key==="Escape"||oe.key==="Tab")&&(oe.preventDefault(),k.current.handleKeyDown(oe.key)),x&&S.current&&(oe.key==="Enter"||oe.key==="ArrowUp"||oe.key==="ArrowDown"||oe.key==="Escape"||oe.key==="Tab")&&(oe.preventDefault(),S.current.handleKeyDown(oe.key))},e[27]=f,e[28]=d,e[29]=x,e[30]=re):re=e[30];const me=re,fe=r+1;let H;e[31]!==c||e[32]!==fe?(H=c("multirun.launcher.groups.groupLabel",{index:fe}),e[31]=c,e[32]=fe,e[33]=H):H=e[33];let K;e[34]!==H?(K=s.jsx("span",{className:"typography-meta font-medium text-foreground",children:H}),e[34]=H,e[35]=K):K=e[35];let Q;e[36]!==a||e[37]!==n.id||e[38]!==l||e[39]!==c?(Q=a&&s.jsx("button",{type:"button",onClick:()=>l(n.id),className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10","aria-label":c("multirun.launcher.groups.removeGroup"),children:s.jsx(D,{name:"close",className:"h-3.5 w-3.5"})}),e[36]=a,e[37]=n.id,e[38]=l,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 be;e[46]!==de?(be=s.jsx(Ea,{required:!0,children:de}),e[46]=de,e[47]=be):be=e[47];const we=n.prompt;let te;e[48]!==B?(te=oe=>{const ke=oe.target.value;B(ke);const Te=oe.target.selectionStart??ke.length;O(ke,Te)},e[48]=B,e[49]=te):te=e[49];let ge;e[50]!==c?(ge=c("multirun.launcher.groups.prompt.placeholder"),e[50]=c,e[51]=ge):ge=e[51];let ue;e[52]!==n.prompt||e[53]!==me||e[54]!==te||e[55]!==ge?(ue=s.jsx(jn,{ref:C,value:we,onChange:te,onKeyDown:me,placeholder:ge,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]=ge,e[56]=ue):ue=e[56];let xe;e[57]!==g||e[58]!==Y||e[59]!==f?(xe=f?s.jsx(fh,{ref:w,searchQuery:g,onCommandSelect:Y,onClose:()=>b(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[57]=g,e[58]=Y,e[59]=f,e[60]=xe):xe=e[60];let ne;e[61]!==q||e[62]!==F||e[63]!==m||e[64]!==d?(ne=d?s.jsx(hh,{ref:k,searchQuery:m,onFileSelect:F,onAgentSelect:q,onClose:()=>p(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[61]=q,e[62]=F,e[63]=m,e[64]=d,e[65]=ne):ne=e[65];let pe;e[66]!==ae||e[67]!==x||e[68]!==j?(pe=x?s.jsx(gh,{ref:S,searchQuery:j,onSnippetSelect:ae,onClose:()=>h(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[66]=ae,e[67]=x,e[68]=j,e[69]=pe):pe=e[69];let J;e[70]!==ue||e[71]!==xe||e[72]!==ne||e[73]!==pe?(J=s.jsxs("div",{className:"relative",children:[ue,xe,ne,pe]}),e[70]=ue,e[71]=xe,e[72]=ne,e[73]=pe,e[74]=J):J=e[74];let Se;e[75]!==be||e[76]!==J?(Se=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[be,J]}),e[75]=be,e[76]=J,e[77]=Se):Se=e[77];let he;e[78]!==c?(he=c("multirun.launcher.models.info",{max:qc}),e[78]=c,e[79]=he):he=e[79];let Ie;e[80]!==he?(Ie=s.jsx(cl,{children:he}),e[80]=he,e[81]=Ie):Ie=e[81];let Pe;e[82]!==c?(Pe=c("multirun.launcher.models.label"),e[82]=c,e[83]=Pe):Pe=e[83];let Ce;e[84]!==Ie||e[85]!==Pe?(Ce=s.jsx(Ea,{required:!0,info:Ie,children:Pe}),e[84]=Ie,e[85]=Pe,e[86]=Ce):Ce=e[86];let X;e[87]!==n.models||e[88]!==T||e[89]!==A||e[90]!==E?(X=s.jsx(Bg,{selectedModels:n.models,onAdd:T,onRemove:A,onUpdate:E,minModels:1,maxModels:qc}),e[87]=n.models,e[88]=T,e[89]=A,e[90]=E,e[91]=X):X=e[91];let ie;e[92]!==Ce||e[93]!==X?(ie=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[Ce,X]}),e[92]=Ce,e[93]=X,e[94]=ie):ie=e[94];let Ne;return e[95]!==W||e[96]!==Se||e[97]!==ie?(Ne=s.jsxs("div",{className:"rounded-lg border border-border p-3 space-y-3",children:[W,Se,ie]}),e[95]=W,e[96]=Se,e[97]=ie,e[98]=Ne):Ne=e[98],Ne},Cf=()=>{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}},_A=()=>{const t=ot.c(2),[e,n]=o.useState(Cf),r=o.useRef(null);let a,i;return t[0]===Symbol.for("react.memo_cache_sentinel")?(a=()=>{if(typeof window>"u")return;const l=window.visualViewport,c=()=>{r.current===null&&(r.current=requestAnimationFrame(()=>{r.current=null;const d=Cf();n(p=>p.height===d.height&&p.keyboardHeight===d.keyboardHeight?p:d)}))};return l?(l.addEventListener("resize",c),l.addEventListener("scroll",c,{passive:!0})):window.addEventListener("resize",c),c(),()=>{r.current!==null&&cancelAnimationFrame(r.current),l?(l.removeEventListener("resize",c),l.removeEventListener("scroll",c)):window.removeEventListener("resize",c)}},i=[],t[0]=a,t[1]=i):(a=t[0],i=t[1]),o.useEffect(a,i),e};class BA extends o.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,n){this.setState({error:e,errorInfo:n})}handleReset=()=>{this.setState({hasError:!1,error:void 0,errorInfo:void 0})};render(){return this.state.hasError?s.jsx("div",{className:"flex items-center justify-center min-h-screen p-4",children:s.jsxs(yh,{className:"w-full max-w-md",children:[s.jsx(Zy,{className:"text-center",children:s.jsxs(ev,{className:"flex items-center justify-center gap-2 text-destructive",children:[s.jsx(D,{name:"chat-3",className:"h-5 w-5"}),this.props.texts.title]})}),s.jsxs(tv,{className:"space-y-4",children:[s.jsx("p",{className:"text-sm text-muted-foreground text-center",children:this.props.texts.description}),this.props.sessionId&&s.jsxs("div",{className:"text-xs text-muted-foreground text-center",children:[this.props.texts.sessionLabel,": ",this.props.sessionId]}),this.state.error&&s.jsxs("details",{className:"text-xs font-mono bg-muted p-3 rounded",children:[s.jsx("summary",{className:"cursor-pointer hover:bg-interactive-hover/80",children:this.props.texts.detailsSummary}),s.jsx("pre",{className:"mt-2 max-h-48 overflow-auto",children:this.state.error.toString()})]}),s.jsx("div",{className:"flex gap-2",children:s.jsxs(ve,{onClick:this.handleReset,variant:"outline",className:"flex-1",children:[s.jsx(D,{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 VA(t){const e=ot.c(22),{t:n}=ut();let r;e[0]!==n?(r=n("chat.errorBoundary.title"),e[0]=n,e[1]=r):r=e[1];let a;e[2]!==n?(a=n("chat.errorBoundary.description"),e[2]=n,e[3]=a):a=e[3];let i;e[4]!==n?(i=n("chat.errorBoundary.sessionLabel"),e[4]=n,e[5]=i):i=e[5];let l;e[6]!==n?(l=n("chat.errorBoundary.detailsSummary"),e[6]=n,e[7]=l):l=e[7];let c;e[8]!==n?(c=n("chat.errorBoundary.resetAction"),e[8]=n,e[9]=c):c=e[9];let d;e[10]!==n?(d=n("chat.errorBoundary.persistentHint"),e[10]=n,e[11]=d):d=e[11];let p;e[12]!==r||e[13]!==a||e[14]!==i||e[15]!==l||e[16]!==c||e[17]!==d?(p={title:r,description:a,sessionLabel:i,detailsSummary:l,resetAction:c,persistentHint:d},e[12]=r,e[13]=a,e[14]=i,e[15]=l,e[16]=c,e[17]=d,e[18]=p):p=e[18];let m;return e[19]!==t||e[20]!==p?(m=s.jsx(BA,{...t,texts:p}),e[19]=t,e[20]=p,e[21]=m):m=e[21],m}const Ad=t=>{const e=ot.c(5),{readOnly:n}=t,r=n===void 0?!1:n,i=$t(zA)||void 0;let l;e[0]!==r?(l=s.jsx(sv,{readOnly:r}),e[0]=r,e[1]=l):l=e[1];let c;return e[2]!==i||e[3]!==l?(c=s.jsx(VA,{sessionId:i,children:l}),e[2]=i,e[3]=l,e[4]=c):c=e[4],c};function zA(t){return t.currentSessionId}const UA=aa(()=>Dr(()=>Promise.resolve().then(()=>Y2),void 0).then(t=>({default:t.PlanView}))),If=aa(()=>Dr(()=>Promise.resolve().then(()=>aN),void 0).then(t=>({default:t.GitView}))),WA=aa(()=>Dr(()=>Promise.resolve().then(()=>b2),void 0).then(t=>({default:t.DiffView}))),Pf=aa(()=>Dr(()=>import("./TerminalView-D7IIkSGJ.js"),__vite__mapDeps([5,0,1,2,3,4])).then(t=>({default:t.TerminalView}))),KA=aa(()=>Dr(()=>Promise.resolve().then(()=>U2),void 0).then(t=>({default:t.FilesView}))),HA=aa(()=>Dr(()=>Promise.resolve().then(()=>j4),void 0).then(t=>({default:t.SettingsView}))),GA=aa(()=>Dr(()=>import("./SettingsWindow-B8QKr5dB.js"),__vite__mapDeps([6,0,1,2,3,4])).then(t=>({default:t.SettingsWindow}))),qA=aa(()=>Dr(()=>import("./MultiRunWindow-BDfPzMDy.js"),__vite__mapDeps([7,0,1,2,3,4])).then(t=>({default:t.MultiRunWindow}))),YA=280,QA=500,JA=360,XA=860,ZA=()=>{const a=Re(K=>K.isSidebarOpen),i=Re(K=>K.isRightSidebarOpen),l=Re(K=>K.isBottomTerminalOpen),c=Re(K=>K.setRightSidebarOpen),d=Re(K=>K.setBottomTerminalOpen),p=Re(K=>K.activeMainTab),m=Re(K=>K.setIsMobile),u=Re(K=>K.isSessionSwitcherOpen),f=Re(K=>K.isSettingsDialogOpen),b=Re(K=>K.setSettingsDialogOpen),g=Re(K=>K.isMultiRunLauncherOpen),v=Re(K=>K.setMultiRunLauncherOpen),x=Re(K=>K.multiRunLauncherPrefillPrompt),{isMobile:h,isTablet:j}=an(),y=_A(),C=Re(K=>K.sidebarWidth),k=Re(K=>K.rightSidebarWidth),w=o.useRef(!1),S=o.useRef(!1),I=o.useRef(!1),[T,P]=o.useState(!1),[A,N]=o.useState(!1),[E,M]=o.useState(!1),[O,V]=o.useState(!1),B=o.useCallback(K=>{P(K),Re.getState().setSessionSwitcherOpen(K)},[]),$=o.useRef(!1),F=o.useRef(typeof window>"u"?0:window.innerWidth),_=bu(-F.current),q=_e.useRef(0),L=bu(F.current),Y=_e.useRef(0);_e.useEffect(()=>{h&&(q.current=window.innerWidth,Y.current=window.innerWidth)},[h]),_e.useEffect(()=>{if(!h){M(!1);return}T&&M(!0),yu(_,T?0:-q.current,{type:"spring",stiffness:400,damping:35,mass:.8})},[T,h,_]),_e.useEffect(()=>{if(!h){V(!1);return}$.current=A,A&&V(!0),yu(L,A?0:Y.current,{type:"spring",stiffness:400,damping:35,mass:.8})},[h,A,L]),_e.useEffect(()=>{if(h)return _.on("change",K=>{const Q=q.current||F.current,W=T||K>-Q+.5;M(de=>de===W?de:W)})},[h,_,T]),_e.useEffect(()=>{if(h)return L.on("change",K=>{const Q=Y.current||F.current,W=A||K<Q-.5;V(de=>de===W?de:W)})},[h,A,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),N(!1),Re.getState().isRightSidebarOpen&&c(!1))},[h,B,c]),_e.useEffect(()=>{if(!h||p!=="chat"||T||A||f)return;let K=!1,Q;const W=de=>{Q=window.setTimeout(()=>{if(K)return;const be=$t.getState(),we=Re.getState();if(!(we.activeMainTab!=="chat"||we.isSettingsDialogOpen||be.currentSessionId||be.newSessionDraft?.open)){if(be.isLoading){W(250);return}be.openNewSessionDraft()}},de)};return W(500),()=>{K=!0,Q!==void 0&&window.clearTimeout(Q)}},[p,h,f,T,A]),_e.useEffect(()=>{!h||!f||(B(!1),N(!1),i&&c(!1))},[h,f,i,B,c]);const Z=_a(K=>K.checkForUpdates);o.useEffect(()=>{let be=!1,we=null;const te=ue=>{const xe=Math.round(ue*1e3);return Math.max(3e5,Math.min(864e5,xe))},ge=ue=>{be||(we=window.setTimeout(async()=>{const xe=await Z(),ne=typeof xe=="number"&&Number.isFinite(xe)?te(xe):36e5;ge(ne)},ue))};return ge(3e3),()=>{be=!0,we!==null&&window.clearTimeout(we)}},[Z]),o.useEffect(()=>{Re.getState().isMobile!==h&&m(h)},[h,m]),o.useEffect(()=>{if(typeof window>"u")return;let K;const Q=()=>{K!==void 0&&window.clearTimeout(K),K=window.setTimeout(()=>{Re.getState().updateProportionalSidebarWidths()},150)};return window.addEventListener("resize",Q),()=>{window.removeEventListener("resize",Q),K!==void 0&&window.clearTimeout(K)}},[]),o.useEffect(()=>{if(typeof window>"u")return;let K;const Q=()=>{const de=Re.getState(),be=window.innerWidth,we=window.innerHeight;if(!h&&!j){const te=be<1140,ge=be>=1220;te?de.isRightSidebarOpen&&(c(!1),w.current=!0):ge&&w.current&&(c(!0),w.current=!1);const ue=we<640,xe=we>=700;ue?de.isBottomTerminalOpen&&(d(!1),S.current=!0):xe&&S.current&&(d(!0),S.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]),o.useEffect(()=>{if(typeof window>"u")return;const K=Re.subscribe((Q,W)=>{const de=window.innerWidth,be=window.innerHeight,we=de>=1220,te=be>=700;Q.isRightSidebarOpen!==W.isRightSidebarOpen&&we&&(w.current=!1),Q.isBottomTerminalOpen!==W.isBottomTerminalOpen&&te&&(S.current=!1)});return()=>{K()}},[h,j,d,c]);const ae=o.useCallback(()=>{T&&B(!1),N(!A)},[T,A,B]),re=o.useMemo(()=>{switch(p){case"plan":return s.jsx(o.Suspense,{fallback:null,children:s.jsx(UA,{})});case"git":return s.jsx(o.Suspense,{fallback:null,children:s.jsx(If,{})});case"diff":return s.jsx(o.Suspense,{fallback:null,children:s.jsx(WA,{})});case"terminal":return s.jsx(o.Suspense,{fallback:null,children:s.jsx(Pf,{})});case"files":return s.jsx(o.Suspense,{fallback:null,children:s.jsx(KA,{})});case"context":return s.jsx(o.Suspense,{fallback:null,children:s.jsx(Xh,{})});default:return null}},[p]),me=p==="chat",fe=o.useMemo(()=>Math.min(QA,Math.max(YA,C||od)),[C]),H=o.useMemo(()=>Math.min(XA,Math.max(JA,k||ld)),[k]);return s.jsx(zj,{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&&y.height>0?{height:y.height}:void 0,children:[s.jsx(N4,{}),s.jsx(dI,{}),s.jsx(fI,{}),s.jsx(CA,{}),h?s.jsxs(nv,{value:{leftDrawerOpen:T,rightDrawerOpen:A,toggleLeftDrawer:()=>{const K=!T;A&&N(!1),B(K)},toggleRightDrawer:ae,leftDrawerX:_,rightDrawerX:L,leftDrawerWidth:q,rightDrawerWidth:Y,setMobileLeftDrawerOpen:B,setRightSidebarOpen:N},children:[!f&&s.jsx(cm,{onToggleLeftDrawer:()=>{const K=!T;A&&N(!1),B(K)},onToggleRightDrawer:()=>{ae()},leftDrawerOpen:T,rightDrawerOpen:A}),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(Ad,{})})}),re&&s.jsx("div",{className:"absolute inset-0",children:s.jsx(en,{children:re})}),g&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",children:s.jsx(en,{children:s.jsx(LA,{initialPrompt:x,onCreated:()=>v(!1),onCancel:()=>v(!1)})})}),E&&s.jsx(vu.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(Nf,{mobileVariant:!0})})}),O&&s.jsx(vu.div,{className:"absolute inset-0 z-20 bg-sidebar","data-page-scroll-lock":"true",style:{x:L},"aria-hidden":!A,children:s.jsx(en,{children:s.jsx(o.Suspense,{fallback:null,children:s.jsx(If,{})})})})]})}),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(o.Suspense,{fallback:null,children:s.jsx(HA,{onClose:()=>b(!1)})})})})]}):s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[s.jsx(cm,{}),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?fe: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?fe: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?H: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?H: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(Y1,{isOpen:a,isMobile:h,className:"border-0",children:s.jsx(Nf,{})}),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(Ad,{})})}),re&&s.jsx("div",{className:"absolute inset-0",children:s.jsx(en,{children:re})})]}),s.jsx(FS,{})]})}),s.jsx(W1,{isOpen:l,isMobile:h,children:l?s.jsx(en,{children:s.jsx(o.Suspense,{fallback:null,children:s.jsx(Pf,{})})}):null})]}),s.jsx(Q1,{isOpen:i,className:"border-0",children:s.jsx(en,{children:s.jsx($N,{})})})]})]}),s.jsx(o.Suspense,{fallback:null,children:s.jsx(GA,{open:f,onOpenChange:b})}),s.jsx(o.Suspense,{fallback:null,children:s.jsx(qA,{open:g,onOpenChange:v,initialPrompt:x})})]})]})})},eD=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`},fr=t=>{const e=ot.c(8),{label:n,value:r}=t;let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[0]=a):a=e[0];let i;e[1]!==n?(i=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:n}),e[1]=n,e[2]=i):i=e[2];let l;e[3]!==r?(l=s.jsx("div",{className:"typography-markdown font-semibold text-[var(--surface-foreground)]",children:r}),e[3]=r,e[4]=l):l=e[4];let c;return e[5]!==i||e[6]!==l?(c=s.jsxs("div",{className:"rounded-md p-2",style:a,children:[i,l]}),e[5]=i,e[6]=l,e[7]=c):c=e[7],c},Af=t=>{const e=ot.c(43),{title:n,snapshot:r,emptyLabel:a}=t,{t:i}=ut();let l;if(e[0]!==a||e[1]!==r.durationMs||e[2]!==r.entries||e[3]!==r.lastUpdatedAt||e[4]!==r.startedAt||e[5]!==i||e[6]!==n){const c=r.entries.slice(0,12);let d;e[8]!==r.entries?(d=r.entries.reduce(nD,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?eD(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 g;e[21]!==i?(g=i("memoryDebugPanel.metric.metrics"),e[21]=i,e[22]=g):g=e[22];let v;e[23]!==r.entries.length||e[24]!==g?(v=s.jsx(fr,{label:g,value:r.entries.length}),e[23]=r.entries.length,e[24]=g,e[25]=v):v=e[25];let x;e[26]!==i?(x=i("memoryDebugPanel.metric.samples"),e[26]=i,e[27]=x):x=e[27];let h;e[28]!==x||e[29]!==p?(h=s.jsx(fr,{label:x,value:p}),e[28]=x,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 y;e[33]!==r.lastUpdatedAt||e[34]!==i?(y=r.lastUpdatedAt?i("memoryDebugPanel.common.live"):i("memoryDebugPanel.common.notAvailable"),e[33]=r.lastUpdatedAt,e[34]=i,e[35]=y):y=e[35];let C;e[36]!==j||e[37]!==y?(C=s.jsx(fr,{label:j,value:y}),e[36]=j,e[37]=y,e[38]=C):C=e[38];let k;e[39]!==h||e[40]!==C||e[41]!==v?(k=s.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[v,h,C]}),e[39]=h,e[40]=C,e[41]=v,e[42]=k):k=e[42],l=s.jsxs("div",{className:"space-y-2 border-t border-[var(--interactive-border)] pt-2 first:border-t-0 first:pt-0",children:[b,k,c.length===0?s.jsx("div",{className:"rounded-md p-3 typography-meta text-[var(--surface-muted-foreground)]",style:{backgroundColor:"color-mix(in srgb, var(--surface-muted) 45%, transparent)"},children:a}):s.jsx(ws,{outerClassName:"max-h-64",className:"pr-1",children:s.jsx("div",{className:"space-y-1",children:c.map(w=>s.jsxs("div",{className:"rounded-md border border-[var(--interactive-border)] p-2",style:{backgroundColor:"color-mix(in srgb, var(--surface-elevated) 88%, transparent)"},children:[s.jsx("div",{className:"typography-meta font-medium text-[var(--surface-foreground)] break-all",children:w.metric}),s.jsxs("div",{className:"mt-1 grid grid-cols-4 gap-2 typography-meta text-[var(--surface-muted-foreground)]",children:[s.jsx("span",{children:i("memoryDebugPanel.metric.countValue",{value:w.count})}),s.jsx("span",{children:i("memoryDebugPanel.metric.avgValue",{value:w.avg})}),s.jsx("span",{children:i("memoryDebugPanel.metric.maxValue",{value:w.max})}),s.jsx("span",{children:i("memoryDebugPanel.metric.totalValue",{value:w.total})})]})]},w.metric))})})]}),e[0]=a,e[1]=r.durationMs,e[2]=r.entries,e[3]=r.lastUpdatedAt,e[4]=r.startedAt,e[5]=i,e[6]=n,e[7]=l}else l=e[7];return l},tD=t=>{const e=ot.c(101),{onClose:n}=t,{t:r}=ut(),[a,i]=o.useState("memory"),[l,c]=o.useState("idle"),d=$t(rD),p=bh(aD),m=Vl(),u=ah(iD),f=gr(oD),[b,g]=o.useState(lD),[v,x]=o.useState(cD);let h;e[0]!==b.entries?(h=new Map,b.entries.forEach(he=>{h.set(he.metric,he.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 y;e[4]!==h?(y=h.get("ui.message_list.render.streaming")??0,e[4]=h,e[5]=y):y=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 S;e[12]!==h?(S=h.get("ui.chat_message.render.static_outside_active_turn_during_stream")??0,e[12]=h,e[13]=S):S=e[13];let I;e[14]!==j||e[15]!==y||e[16]!==C||e[17]!==k||e[18]!==w||e[19]!==S?(I={messageListRender:j,messageListRenderStreaming:y,chatMessageRender:C,chatMessageRenderStreaming:k,chatMessageRenderStaticDuringStream:w,chatMessageRenderStaticOutsideActiveTurnDuringStream:S},e[14]=j,e[15]=y,e[16]=C,e[17]=k,e[18]=w,e[19]=S,e[20]=I):I=e[20];const T=I;let P,A;e[21]===Symbol.for("react.memo_cache_sentinel")?(P=()=>{const he=()=>{g(Qo()),x(Jo())};he();const Ie=window.setInterval(he,500);return()=>window.clearInterval(Ie)},A=[],e[21]=P,e[22]=A):(P=e[21],A=e[22]),o.useEffect(P,A);let N,E;e[23]!==l?(N=()=>{if(l==="idle")return;const he=window.setTimeout(()=>{c("idle")},1500);return()=>window.clearTimeout(he)},E=[l],e[23]=l,e[24]=N,e[25]=E):(N=e[24],E=e[25]),o.useEffect(N,E);let M=0,O;if(e[26]!==u?(O=Object.keys(u),e[26]=u,e[27]=O):O=e[27],e[28]!==u||e[29]!==O||e[30]!==M){for(const he of O)M=M+(u[he]?.length??0);e[28]=u,e[29]=O,e[30]=M,e[31]=M}else M=e[31];const V=M;let B;if(e[32]!==d||e[33]!==u||e[34]!==p||e[35]!==m||e[36]!==r){let he;e[38]!==d||e[39]!==u||e[40]!==p||e[41]!==r?(he=Ie=>{const Pe=u[Ie.id]?.length||0,Ce=p.get(Ie.id);return{id:Ie.id,title:Ie.title||r("memoryDebugPanel.common.untitled"),messageCount:Pe,isStreaming:Ce?.isStreaming||!1,isZombie:Ce?.isZombie||!1,backgroundCount:Ce?.backgroundMessageCount||0,lastAccessed:Ce?.lastAccessedAt||0,isCurrent:Ie.id===d}},e[38]=d,e[39]=u,e[40]=p,e[41]=r,e[42]=he):he=e[42],B=m.map(he).sort(dD),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 F;e[43]!==u?(F=Object.keys(u),e[43]=u,e[44]=F):F=e[44];const _=F.length;let q;e[45]===Symbol.for("react.memo_cache_sentinel")?(q=async()=>{try{const he={generatedAt:new Date().toISOString(),ui:Qo(),vscode:Jo()};await navigator.clipboard.writeText(JSON.stringify(he,null,2)),c("copied")}catch{c("error")}},e[45]=q):q=e[45];const L=q;let Y;e[46]===Symbol.for("react.memo_cache_sentinel")?(Y={backgroundColor:"color-mix(in srgb, var(--surface-background) 94%, transparent)"},e[46]=Y):Y=e[46];let Z;e[47]!==a?(Z=a==="memory"?s.jsx(D,{name:"database-2",className:"h-4 w-4 text-[var(--surface-foreground)]"}):s.jsx(D,{name:"bar-chart-box",className:"h-4 w-4 text-[var(--surface-foreground)]"}),e[47]=a,e[48]=Z):Z=e[48];let ae;e[49]!==r?(ae=r("memoryDebugPanel.title"),e[49]=r,e[50]=ae):ae=e[50];let re;e[51]!==ae?(re=s.jsx("h3",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:ae}),e[51]=ae,e[52]=re):re=e[52];let me;e[53]!==Z||e[54]!==re?(me=s.jsxs("div",{className:"flex items-center gap-2",children:[Z,re]}),e[53]=Z,e[54]=re,e[55]=me):me=e[55];let fe;e[56]!==a?(fe=a==="streaming"?s.jsxs(s.Fragment,{children:[s.jsx(ve,{size:"xs",variant:"ghost",onClick:L,children:s.jsx(D,{name:"file-copy",className:"h-3.5 w-3.5"})}),s.jsx(ve,{size:"xs",variant:"ghost",onClick:()=>{av(),g(Qo()),x(Jo())},children:s.jsx(D,{name:"refresh",className:"h-3.5 w-3.5"})})]}):null,e[56]=a,e[57]=fe):fe=e[57];let H;e[58]!==n?(H=n?s.jsx(ve,{size:"icon",variant:"ghost",className:"h-6 w-6",onClick:n,children:s.jsx(D,{name:"close",className:"h-4 w-4"})}):null,e[58]=n,e[59]=H):H=e[59];let K;e[60]!==fe||e[61]!==H?(K=s.jsxs("div",{className:"flex items-center gap-1",children:[fe,H]}),e[60]=fe,e[61]=H,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 be;e[67]===Symbol.for("react.memo_cache_sentinel")?(be=()=>i("memory"),e[67]=be):be=e[67];let we;e[68]!==r?(we=r("memoryDebugPanel.tabs.memory"),e[68]=r,e[69]=we):we=e[69];let te;e[70]!==de||e[71]!==we?(te=s.jsx(ve,{size:"sm",variant:de,className:"flex-1",onClick:be,children:we}),e[70]=de,e[71]=we,e[72]=te):te=e[72];const ge=a==="streaming"?"secondary":"ghost";let ue;e[73]===Symbol.for("react.memo_cache_sentinel")?(ue=()=>i("streaming"),e[73]=ue):ue=e[73];let xe;e[74]!==r?(xe=r("memoryDebugPanel.tabs.streaming"),e[74]=r,e[75]=xe):xe=e[75];let ne;e[76]!==ge||e[77]!==xe?(ne=s.jsx(ve,{size:"sm",variant:ge,className:"flex-1",onClick:ue,children:xe}),e[76]=ge,e[77]=xe,e[78]=ne):ne=e[78];let pe;e[79]!==te||e[80]!==ne?(pe=s.jsxs("div",{className:"mb-3 flex gap-1 rounded-md p-1",style:W,children:[te,ne]}),e[79]=te,e[80]=ne,e[81]=pe):pe=e[81];let J;e[82]!==a||e[83]!==_||e[84]!==l||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]!==v?(J=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(fr,{label:r("memoryDebugPanel.metric.totalMessages"),value:V}),s.jsx(fr,{label:r("memoryDebugPanel.metric.cachedSessions"),value:`${_} / ${Ku.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:rv()})})]}),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:Ku.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(ws,{outerClassName:"max-h-48",className:"space-y-1 pr-1",children:$.map(he=>s.jsxs("div",{className:"typography-meta flex items-center justify-between rounded p-1.5",style:{backgroundColor:he.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:he.title}),he.isStreaming?s.jsx(D,{name:"pulse",className:"h-3 w-3 animate-pulse text-[var(--status-info)]"}):null,he.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:he.messageCount})}),he.backgroundCount>0?s.jsxs("span",{className:"text-[var(--status-info)]",children:["+",he.backgroundCount]}):null]})]},he.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(ve,{size:"sm",variant:"outline",className:"typography-meta",onClick:()=>{console.log("[DebugPanel] Session store state:",{sessions:m.map(uD),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(l==="copied"?"memoryDebugPanel.streaming.copy.copied":l==="error"?"memoryDebugPanel.streaming.copy.failed":"memoryDebugPanel.streaming.copy.hint")}),s.jsx(ve,{size:"xs",variant:"outline",onClick:L,children:r("memoryDebugPanel.actions.copyJson")})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[s.jsx(fr,{label:r("memoryDebugPanel.metric.uiMetrics"),value:b.entries.length}),s.jsx(fr,{label:r("memoryDebugPanel.metric.vscodeMetrics"),value:v.entries.length}),s.jsx(fr,{label:r("memoryDebugPanel.metric.messageListRenders"),value:T.messageListRender}),s.jsx(fr,{label:r("memoryDebugPanel.metric.messageListStreamRenders"),value:T.messageListRenderStreaming}),s.jsx(fr,{label:r("memoryDebugPanel.metric.chatMessageRenders"),value:T.chatMessageRender}),s.jsx(fr,{label:r("memoryDebugPanel.metric.chatMessageStreamRenders"),value:T.chatMessageRenderStreaming}),s.jsx(fr,{label:r("memoryDebugPanel.metric.chatMessageStaticDuringStream"),value:T.chatMessageRenderStaticDuringStream}),s.jsx(fr,{label:r("memoryDebugPanel.metric.chatMessageStaticOutsideActiveTurn"),value:T.chatMessageRenderStaticOutsideActiveTurnDuringStream})]}),s.jsx(Af,{title:r("memoryDebugPanel.section.uiStreamingMetrics"),snapshot:b,emptyLabel:r("memoryDebugPanel.section.noUiSamples")}),v.entries.length>0?s.jsx(Af,{title:r("memoryDebugPanel.section.vscodeBridgeMetrics"),snapshot:v,emptyLabel:r("memoryDebugPanel.section.noVscodeSamples")}):null]}),e[82]=a,e[83]=_,e[84]=l,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]=v,e[96]=J):J=e[96];let Se;return e[97]!==Q||e[98]!==pe||e[99]!==J?(Se=s.jsxs(yh,{className:"fixed bottom-4 right-4 z-50 w-[28rem] p-4 shadow-none bottom-safe-area",style:Y,children:[Q,pe,J]}),e[97]=Q,e[98]=pe,e[99]=J,e[100]=Se):Se=e[100],Se},sD=tD;function nD(t,e){return t+e.count}function rD(t){return t.currentSessionId}function aD(t){return t.sessionMemoryState}function iD(t){return t.message}function oD(t){return t.totalRequestCount}function lD(){return Qo()}function cD(){return Jo()}function dD(t,e){return e.lastAccessed-t.lastAccessed}function uD(t){return{id:t.id,title:t.title}}const mD=()=>{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()??"":""},pD=async()=>{const t=mD()||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")},Df="openchamber:menu-action",Yc="openchamber:check-for-updates",fD=t=>{const e=$t(k=>k.openNewSessionDraft),n=Re(k=>k.toggleCommandPalette),r=Re(k=>k.setCommandPaletteOpen),a=Re(k=>k.toggleHelpDialog),i=Re(k=>k.toggleSidebar),l=Re(k=>k.setSessionSwitcherOpen),c=Re(k=>k.setActiveMainTab),d=Re(k=>k.setSettingsDialogOpen),p=Re(k=>k.setAboutDialogOpen),m=Re(k=>k.toggleRightSidebar),u=Re(k=>k.setRightSidebarOpen),f=Re(k=>k.setRightSidebarTab),b=Re(k=>k.toggleBottomTerminal),g=Re(k=>k.setBottomTerminalExpanded),v=_a(k=>k.checkForUpdates),{setThemeMode:x}=vr(),h=o.useRef(!1),j=o.useCallback(()=>{h.current||(h.current=!0,v().then(()=>{const{available:k,error:w}=_a.getState();if(w){G.error("Failed to check for updates",{description:w});return}k||G.success("You are on the latest version")}).finally(()=>{h.current=!1}))},[v]),y=o.useCallback(()=>{Ar.requestDirectoryDialog()},[]),C=o.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"),l(!1),e();break;case"new-worktree-session":c("chat"),l(!1),uh();break;case"change-workspace":y();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":g(!Re.getState().isBottomTerminalExpanded);break;case"copy":{const w=new Event("openchamber:copy",{cancelable:!0});!window.dispatchEvent(w)||pD();break}case"theme-light":x("light");break;case"theme-dark":x("dark");break;case"theme-system":x("system");break;case"toggle-sidebar":i();break;case"toggle-memory-debug":t?.();break;case"help-dialog":a();break;case"download-logs":{iv().catch(()=>{G.error("Failed to collect OpenCode status")});break}}},[y,t,e,p,c,l,r,d,g,u,f,x,b,n,a,m,i]);o.useEffect(()=>{const k=S=>{const I=S.detail;I&&C(I)},w=()=>{j()};return window.addEventListener(Df,k),window.addEventListener(Yc,w),()=>{window.removeEventListener(Df,k),window.removeEventListener(Yc,w)}},[C,j]),o.useEffect(()=>{if(typeof window>"u")return;const w=window.__TAURI__?.event?.listen;if(typeof w!="function")return;let S=null,I=null;return w("openchamber:menu-action",T=>{const P=T?.payload;typeof P=="string"&&C(P)}).then(T=>{S=T}).catch(()=>{}),w("openchamber:check-for-updates",()=>{window.dispatchEvent(new Event(Yc))}).then(T=>{I=T}).catch(()=>{}),()=>{(async()=>{try{const P=S?.();P instanceof Promise&&await P}catch{}try{const P=I?.();P instanceof Promise&&await P}catch{}})()}},[C])},hD=["chat","git","diff","terminal","files"],gD=["settings","agents","commands","skills","providers","usage","git-identities"],Ir={SESSION:"session",TAB:"tab",SETTINGS:"settings",FILE:"file"};function Tf(t){const e=xD();return{sessionId:bD(e),tab:yD(e),settingsPath:vD(e),diffFile:wD(e)}}function xD(){if(typeof window>"u")return new URLSearchParams;try{return new URLSearchParams(window.location.search)}catch{return new URLSearchParams}}function bD(t){const e=t.get(Ir.SESSION);return!e||e.trim().length===0?null:e.trim()}function yD(t){const e=t.get(Ir.TAB);if(!e)return null;const n=e.toLowerCase().trim();return hD.includes(n)?n:null}function vD(t){const e=t.get(Ir.SETTINGS);if(!e)return null;const n=e.toLowerCase().trim();return n.length===0?null:n==="openchamber"||n==="general"||n==="preferences"?"home":(gD.includes(n),n)}function wD(t){const e=t.get(Ir.FILE);if(!e||e.trim().length===0)return null;try{return decodeURIComponent(e.trim())}catch{return e.trim()}}function Mf(){if(typeof window>"u")return!1;try{const t=new URLSearchParams(window.location.search);return t.has(Ir.SESSION)||t.has(Ir.TAB)||t.has(Ir.SETTINGS)||t.has(Ir.FILE)}catch{return!1}}const jD="chat";function Gg(t){const e=new URLSearchParams;if(t.sessionId&&t.sessionId.trim().length>0&&e.set(Ir.SESSION,t.sessionId),t.isSettingsOpen){const n=t.settingsPath.trim().length>0?t.settingsPath:"home";return e.set(Ir.SETTINGS,n),e}return t.tab!==jD&&e.set(Ir.TAB,t.tab),t.tab==="diff"&&t.diffFile&&t.diffFile.trim().length>0&&e.set(Ir.FILE,t.diffFile),e}function ND(t,e){const n=typeof window<"u"?window.location.pathname:"/",r=t.toString();return r?`${n}?${r}`:n}function SD(t){if(typeof window>"u")return!0;try{const e=new URLSearchParams(window.location.search),n=Gg(t),r=[...e.entries()].sort((i,l)=>i[0].localeCompare(l[0])),a=[...n.entries()].sort((i,l)=>i[0].localeCompare(l[0]));if(r.length!==a.length)return!1;for(let i=0;i<r.length;i++)if(r[i][0]!==a[i][0]||r[i][1]!==a[i][1])return!1;return!0}catch{return!0}}function kD(t,e={}){if(!(typeof window>"u")&&!CD()&&!(!e.force&&SD(t)))try{const n=Gg(t),r=ND(n);e.replace?window.history.replaceState({...window.history.state,route:t},"",r):window.history.pushState({route:t},"",r)}catch{}}function CD(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function ID(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function PD(){const t=o.useMemo(()=>ID(),[]),e=o.useRef(!1),n=o.useRef(!1),r=$t(u=>u.setCurrentSession),a=Re(u=>u.setActiveMainTab),i=Re(u=>u.setSettingsDialogOpen),l=Re(u=>u.setSettingsPage),c=Re(u=>u.navigateToDiff),d=o.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){l(su(u.settingsPath)),i(!0);return}Re.getState().isSettingsDialogOpen&&i(!1),u.tab&&a(u.tab),u.diffFile&&(u.tab==="diff"||!u.tab)&&c(u.diffFile)}finally{n.current=!1}}},[r,a,i,l,c]),p=o.useCallback(()=>{const u=$t.getState(),f=Re.getState();return{sessionId:u.currentSessionId,tab:f.activeMainTab,isSettingsOpen:f.isSettingsDialogOpen,settingsPath:f.settingsPage,diffFile:f.pendingDiffFile}},[]),m=o.useCallback((u={})=>{if(t||n.current)return;const f=p();kD(f,u)},[t,p]);o.useEffect(()=>{if(e.current||(e.current=!0,!Mf()))return;const u=Tf();(async()=>(await d(u),t||m({replace:!0})))()},[d,t,m]),o.useEffect(()=>{if(t)return;let u=$t.getState().currentSessionId;return $t.subscribe(b=>{const g=b.currentSessionId;g===u||n.current||(u=g,m())})},[t,m]),o.useEffect(()=>{if(t)return;let u=Re.getState().activeMainTab,f=Re.getState().isSettingsDialogOpen,b=Re.getState().settingsPage,g=Re.getState().pendingDiffFile;return Re.subscribe(x=>{if(n.current)return;const h=x.activeMainTab!==u,j=x.isSettingsDialogOpen!==f,y=x.settingsPage!==b,C=x.pendingDiffFile!==g&&x.activeMainTab==="diff";u=x.activeMainTab,f=x.isSettingsDialogOpen,b=x.settingsPage,g=x.pendingDiffFile,(h||j||y||C)&&m()})},[t,m]),o.useEffect(()=>{if(typeof window>"u"||t)return;const u=()=>{const f=Tf();if(Mf())d(f);else{const b=Re.getState();b.isSettingsDialogOpen&&i(!1),b.activeMainTab!=="chat"&&a("chat")}};return window.addEventListener("popstate",u),()=>{window.removeEventListener("popstate",u)}},[d,t,a,i])}const AD="/api/notifications/stream",DD=()=>typeof document>"u"?!0:document.visibilityState==="visible"&&document.hasFocus(),TD=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}},MD=t=>{const e=ot.c(3),n=t?.enabled??!0;let r,a;e[0]!==n?(r=()=>{if(!n||Cn()||!ta()||typeof window>"u"||typeof EventSource>"u")return;const i=new EventSource(AD);return i.onmessage=ED,()=>{i.close()}},a=[n],e[0]=n,e[1]=r,e[2]=a):(r=e[1],a=e[2]),o.useEffect(r,a)};function ED(t){let e;try{e=JSON.parse(t.data)}catch{return}const n=Re.getState();if(!n.nativeNotificationsEnabled||n.notificationMode!=="always"&&DD())return;const r=TD(e);if(!r)return;nr()?.notifications?.notifyAgentCompletion(r)}const RD=t=>!(t.dismissed==="true"||t.sessionShown==="true"||t.hasActiveToast),FD=t=>!(!t.version||t.seenVersions.has(t.version)||t.dismissedVersion!==null&&t.dismissedVersion===t.version),OD=t=>{if(t===null||typeof t!="object")return"";const e=t.version;return typeof e!="string"?"":e.trim()},LD=t=>!t||t.available!==!0||typeof t.latestVersion!="string"?"":t.latestVersion.trim(),Ef="pwa-install-toast-shown",Rf="pwa-install-toast-dismissed",$D=()=>{const t=ot.c(6),{browserTab:e}=jg(),{t:n}=ut(),r=o.useRef(n);let a,i;t[0]!==n?(a=()=>{r.current=n},i=[n],t[0]=n,t[1]=a,t[2]=i):(a=t[1],i=t[2]),o.useEffect(a,i);let l,c;t[3]!==e?(l=()=>{if(typeof window>"u"||!ta()||!e)return;let d=null,p=null;const m=()=>{p!==null&&(G.dismiss(p),p=null)},u=async()=>{if(!d)return;const g=d;d=null,m(),await g.prompt();const{outcome:v}=await g.userChoice;v==="accepted"&&G.success(r.current("pwa.installPrompt.started"))},f=g=>{const v=g;if(typeof v.prompt!="function")return;v.preventDefault(),d=v;const x=Cr(),h=Wf();RD({dismissed:x.getItem(Rf),sessionShown:h.getItem(Ef),hasActiveToast:p!==null})&&(h.setItem(Ef,"true"),p=G.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:()=>{Cr().setItem(Rf,"true"),m()}}}))},b=()=>{d=null,m(),G.success(r.current("pwa.installPrompt.installed"))};return window.addEventListener("beforeinstallprompt",f),window.addEventListener("appinstalled",b),()=>{m(),window.removeEventListener("beforeinstallprompt",f),window.removeEventListener("appinstalled",b)}},c=[e],t[3]=e,t[4]=l,t[5]=c):(l=t[4],c=t[5]),o.useEffect(l,c)},_D=["local","remote",null],BD=["ok","not-configured","unreachable","wrong-service","missing"];function qg(t){if(!t||typeof t!="object")return{valid:!1};const e=t,n=e.target,r=e.status;if(n!==null&&(typeof n!="string"||!_D.includes(n)))return{valid:!1};if(typeof r!="string"||!BD.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 Ff(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 VD(t){return t.isDesktopShell?t.bootOutcomeKnown?t.bootViewIsMain===!1?!0:t.isInitialized:!1:t.isInitialized}function zD(t){return t.isTauriShell&&!t.isDesktopLocalOriginActive}function Of(){if(Dd()!=="valid")return null;const e=window.__OPENCHAMBER_DESKTOP_BOOT_OUTCOME__,n=qg(e);return n.valid?n.outcome:null}function Dd(){if(typeof window>"u")return"not-injected";const t=window.__OPENCHAMBER_DESKTOP_BOOT_OUTCOME__;return t==null?"not-injected":qg(t).valid?"valid":"malformed"}const UD=()=>{const t=ot.c(5),[e,n]=o.useState(WD),{isUpdating:r,message:a}=e;let i,l;if(t[0]===Symbol.for("react.memo_cache_sentinel")?(i=()=>lv(n),l=[],t[0]=i,t[1]=l):(i=t[0],l=t[1]),o.useEffect(i,l),!r)return null;let c;t[2]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(Vd,{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 WD(){return ov()}const KD=({open:t,onOpenChange:e})=>{const{t:n}=ut(),r=!1,[a,i]=o.useState(null),[l,c]=o.useState(null),[d,p]=o.useState(!1),[m,u]=o.useState(!1),[f,b]=o.useState(null),[g,v]=o.useState(!1);o.useCallback(async()=>{},[f,d,r,n]),o.useEffect(()=>{if(!t)return;(async()=>{try{const j=await fetch("/api/system/info");if(j.ok){const y=await j.json();if(typeof y.openchamberVersion=="string"&&y.openchamberVersion.trim()){i(y.openchamberVersion);return}}}catch{}i(await cv())})()},[t]),o.useEffect(()=>{if(!t)return;let h=!1;return(async()=>{try{const y=await fetch("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!y.ok)return;const C=await y.json().catch(()=>null),k=typeof C?.currentVersion=="string"?C.currentVersion.trim():"";!h&&k&&c(k)}catch{}})(),()=>{h=!0}},[t]),o.useEffect(()=>{{b(null),v(!1);return}},[t,r]);const x=a;return s.jsx(ps,{open:t,onOpenChange:e,children:s.jsx(ms,{className:"max-w-xs p-6",children:s.jsxs("div",{className:"flex flex-col items-center text-center space-y-4",children:[s.jsx(Vd,{width:64,height:64}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("h2",{className:"text-lg font-semibold",children:"OpenChamber"}),s.jsxs("div",{className:"space-y-0.5 typography-meta text-muted-foreground",children:[x&&s.jsx("p",{children:n("aboutDialog.openChamberVersionLabel",{version:x})}),l&&s.jsx("p",{children:n("aboutDialog.openCodeVersionLabel",{version:l})})]})]}),r,s.jsxs("div",{className:"flex flex-col items-center gap-2 pt-2",children:[s.jsxs("div",{className:"flex items-center justify-center gap-4",children:[s.jsxs("a",{href:"https://github.com/btriapitsyn/openchamber",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(D,{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(D,{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(D,{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")})]})})})},Qc=(t,e)=>{const n=t.get(e);return typeof n!="string"?null:n.trim()||null},HD=(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},GD=()=>{const t=Sn(i=>i.completeAuth),[e,n]=o.useState("working"),[r,a]=o.useState("Completing MCP authorization...");return o.useEffect(()=>{if(typeof window>"u"){n("error"),a("Browser context unavailable.");return}const i=new URLSearchParams(window.location.search),l=Qc(i,"code"),c=pg(i),d=nu(i),p=Qc(i,"error"),m=Qc(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(!l)throw new Error("Missing OAuth authorization code. Start authorization again from MCP Settings or paste the returned code into OpenChamber manually.");let u=c;if(!u&&d){const 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,l,u.directory),d&&await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("success"),a("Authorization completed. You can close this tab and return to OpenChamber.")}catch(u){d&&await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("error"),a(HD(u,"Failed to complete MCP authorization."))}})()},[t]),s.jsx("div",{className:"flex min-h-screen items-center justify-center bg-background px-6 py-12 text-foreground",children:s.jsxs("div",{className:"w-full max-w-xl rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-8 shadow-sm",children:[s.jsxs("div",{className:"space-y-3 text-center",children:[s.jsx("div",{className:e==="error"?"text-[var(--status-error)]":e==="success"?"text-[var(--status-success)]":"text-[var(--status-info)]",children:s.jsx("h1",{className:"typography-hero font-semibold",children:e==="working"?"Completing Authorization":e==="success"?"Authorization Complete":"Authorization Failed"})}),s.jsx("p",{className:"typography-body text-muted-foreground",children:r})]}),e!=="working"&&s.jsx("div",{className:"mt-8 flex justify-center",children:s.jsx(ve,{type:"button",onClick:()=>{typeof window>"u"||window.location.replace("/")},children:"Return to OpenChamber"})})]})})},zi="opencode-update-available",Ho="opencode-upgrade-progress",qD=5e3,YD=[1e4,6e4],Lf="opencode-update-toast-dismissed-version",Yg=()=>{const{t}=ut(),e=Re(l=>l.showOpenCodeUpdateNotifications),n=_e.useRef(new Set),r=_e.useRef(!1);_e.useEffect(()=>{e||G.dismiss(zi)},[e]);const a=_e.useCallback(()=>{G.dismiss(Ho),ci({message:t("opencodeUpdate.toast.reload.message"),mode:"projects",scopes:["all"]})},[t]),i=_e.useCallback(async()=>{if(!r.current){r.current=!0,G.dismiss(zi),G.message(t("opencodeUpdate.toast.upgrading.title"),{id:Ho,description:t("opencodeUpdate.toast.upgrading.description"),duration:1/0,icon:s.jsx(D,{name:"refresh",className:"h-4 w-4 animate-spin text-muted-foreground"})});try{const l=await fetch("/api/opencode/upgrade",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),c=await l.json().catch(()=>null);if(!l.ok||c?.success===!1)throw new Error(c?.error||l.statusText||t("opencodeUpdate.toast.failed.description"));G.success(t("opencodeUpdate.toast.updated.title"),{id:Ho,description:c?.version?t("opencodeUpdate.toast.updated.descriptionWithVersion",{version:c.version}):t("opencodeUpdate.toast.updated.description"),duration:1/0,icon:s.jsx(D,{name:"check",className:"h-4 w-4 text-[var(--status-success)]"}),action:{label:t("opencodeUpdate.toast.actions.reload"),onClick:a}})}catch(l){G.error(t("opencodeUpdate.toast.failed.title"),{id:Ho,description:l instanceof Error?l.message:t("opencodeUpdate.toast.failed.description"),duration:1/0})}finally{r.current=!1}}},[a,t]);return _e.useEffect(()=>{const l=u=>{if(!Re.getState().showOpenCodeUpdateNotifications){G.dismiss(zi);return}FD({version:u,dismissedVersion:Cr().getItem(Lf),seenVersions:n.current})&&(n.current.add(u),G.info(t("opencodeUpdate.toast.available.title"),{id:zi,description:t("opencodeUpdate.toast.available.description",{version:u}),duration:1/0,action:{label:t("opencodeUpdate.toast.actions.update"),onClick:i},cancel:{label:t("opencodeUpdate.toast.actions.dismiss"),onClick:()=>{Cr().setItem(Lf,u),G.dismiss(zi)}}}))},c=u=>{const f=OD(u.detail);l(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),g=LD(b);!d&&g&&l(g)}catch{const f=YD[u];!d&&f!==void 0&&p.push(setTimeout(()=>{m(u+1)},f))}};return e&&p.push(setTimeout(()=>{m(0)},qD)),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},$f=aa(()=>Dr(()=>import("./OnboardingScreen-DGgh4IXB.js"),__vite__mapDeps([8,0,1,2,3,4])).then(t=>({default:t.OnboardingScreen}))),QD=()=>{const t=ot.c(3),e=Re(sT),n=Re(nT);let r;return t[0]!==e||t[1]!==n?(r=s.jsx(KD,{open:e,onOpenChange:n}),t[0]=e,t[1]=n,t[2]=r):r=t[2],r},JD=t=>{const e=ot.c(21),{onRetry:n,isRetrying:r}=t,{t:a}=ut();let i;e[0]!==a?(i=a("startup.initRecovery.title"),e[0]=a,e[1]=i):i=e[1];let l;e[2]!==i?(l=s.jsx("h1",{className:"typography-title text-foreground",children:i}),e[2]=i,e[3]=l):l=e[3];let c;e[4]!==a?(c=a("startup.initRecovery.description"),e[4]=a,e[5]=c):c=e[5];let d;e[6]!==c?(d=s.jsx("p",{className:"typography-body text-muted-foreground",children:c}),e[6]=c,e[7]=d):d=e[7];let p;e[8]!==l||e[9]!==d?(p=s.jsxs("div",{className:"flex flex-col gap-2",children:[l,d]}),e[8]=l,e[9]=d,e[10]=p):p=e[10];let m;e[11]!==r||e[12]!==a?(m=a(r?"startup.initRecovery.retrying":"startup.initRecovery.retry"),e[11]=r,e[12]=a,e[13]=m):m=e[13];let u;e[14]!==r||e[15]!==n||e[16]!==m?(u=s.jsx(ve,{type:"button",onClick:n,disabled:r,children:m}),e[14]=r,e[15]=n,e[16]=m,e[17]=u):u=e[17];let f;return e[18]!==p||e[19]!==u?(f=s.jsx("div",{className:"flex h-full items-center justify-center bg-background px-6 text-foreground",children:s.jsxs("div",{className:"flex max-w-md flex-col items-center gap-4 text-center",children:[p,u]})}),e[18]=p,e[19]=u,e[20]=f):f=e[20],f},_f=t=>t?t.replace(/\\/g,"/").replace(/\/+$/g,""):"",XD=()=>{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"}},ZD=()=>typeof window>"u"?!1:window.location.pathname===mg,eT=t=>{const e=ot.c(23),{embeddedSessionChat:n,isVSCodeRuntime:r,embeddedBackgroundWorkEnabled:a}=t,i=Ks(rT),l=$t(aT),c=$t(iT),d=Kd(),p=o.useRef(null);let m;e[0]!==n.directory?(m=_f(n.directory),e[0]=n.directory,e[1]=m):m=e[1];const u=m;let f;e[2]!==i?(f=_f(i),e[2]=i,e[3]=f):f=e[3];const b=f;let g,v;if(e[4]!==b||e[5]!==l||e[6]!==n.directory||e[7]!==n.sessionId||e[8]!==u||e[9]!==r||e[10]!==c||e[11]!==d?(g=()=>{if(r||u&&b!==u)return;const k=`${u}
|
|
232
|
-
${n.sessionId}`;p.current===k&&l===n.sessionId||(p.current=k,c(n.sessionId,n.directory),d.ensureSessionRenderable(n.sessionId,!0))},v=[b,l,n.directory,n.sessionId,u,r,c,d],e[4]=b,e[5]=l,e[6]=n.directory,e[7]=n.sessionId,e[8]=u,e[9]=r,e[10]=c,e[11]=d,e[12]=g,e[13]=v):(g=e[12],v=e[13]),o.useEffect(g,v),u&&b!==u)return null;let x;e[14]!==a?(x=s.jsx(vh,{embeddedBackgroundWorkEnabled:a}),e[14]=a,e[15]=x):x=e[15];let h;e[16]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(Yg,{}),e[16]=h):h=e[16];let j;e[17]!==n.readOnly?(j=s.jsx(Ad,{readOnly:n.readOnly}),e[17]=n.readOnly,e[18]=j):j=e[18];let y;e[19]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx(wh,{}),e[19]=y):y=e[19];let C;return e[20]!==x||e[21]!==j?(C=s.jsxs(s.Fragment,{children:[x,h,j,y]}),e[20]=x,e[21]=j,e[22]=C):C=e[22],C};function tT({apis:t}){const e=yt(H=>H.initializeApp),n=yt(H=>H.isInitialized),r=yt(H=>H.isConnected),a=yt(H=>H.providers.length),i=yt(H=>H.agents.length),l=yt(H=>H.loadProviders),c=yt(H=>H.loadAgents),d=$t(H=>H.error),p=$t(H=>H.clearError),m=Ks(H=>H.currentDirectory),u=Ks(H=>H.setDirectory),f=Ks(H=>H.isSwitchingDirectory),[b,g]=o.useState(!1),v=Hn(H=>H.refreshStatus),[x,h]=o.useState(()=>t.runtime.isVSCode),[j,y]=o.useState(!0),[C,k]=o.useState(!1),[w,S]=o.useState(0),[I,T]=o.useState(!1),P=Re(H=>H.wideChatLayoutEnabled),A=Re(H=>H.mobileKeyboardMode),N=o.useMemo(()=>Cn(),[]),E=Ed(H=>H.setPlanModeEnabled),[M,O]=o.useState(()=>Dd()),[V,B]=o.useState(()=>{const H=Of();return H!==null?Ff({isDesktopShell:!0,bootOutcome:H}):null}),$=o.useRef(!1),F=o.useMemo(()=>XD(),[]),_=!F||j,q=o.useMemo(()=>ZD(),[]);o.useEffect(()=>(Hu(b),()=>{Hu(!1)}),[b]),o.useEffect(()=>{dv(A)},[A]),o.useEffect(()=>{h(t.runtime.isVSCode)},[t.runtime.isVSCode]),o.useEffect(()=>(document.documentElement.classList.toggle("wide-chat-layout",P),()=>{document.documentElement.classList.remove("wide-chat-layout")}),[P]),o.useEffect(()=>(Gu(t),()=>Gu(null)),[t]),o.useEffect(()=>{F||v(t.github,{force:!0})},[t.github,F,v]),uv();const L=M==="valid",Y=V?.screen==="main";o.useEffect(()=>{if(!VD({isDesktopShell:N,isInitialized:n,bootOutcomeKnown:L,bootViewIsMain:Y}))return;const H=setTimeout(()=>{const K=document.getElementById("initial-loading");K&&(K.classList.add("fade-out"),setTimeout(()=>{K.remove()},300))},150);return()=>clearTimeout(H)},[N,n,L,Y]),o.useEffect(()=>{if(!N||M!=="malformed")return;const H=document.getElementById("initial-loading");H&&(H.textContent="Desktop startup failed — please restart the app.")},[N,M]),o.useEffect(()=>{if(N)return;const H=setTimeout(()=>{const K=document.getElementById("initial-loading");K&&!n&&(K.classList.add("fade-out"),setTimeout(()=>{K.remove()},300))},5e3);return()=>clearTimeout(H)},[N,n]),o.useEffect(()=>{let H=!1;return(async()=>{const Q=await fetch("/health",{method:"GET"}).catch(()=>null);if(!Q||!Q.ok||H)return;const W=await Q.json().catch(()=>null);if(!W||H)return;const de=W.planModeExperimentalEnabled;E(de===!0||de===1||de==="1"||de==="true")})(),()=>{H=!0}},[E]),o.useEffect(()=>{x||e()},[e,x]),o.useEffect(()=>{if(x||n)return;let H=!0,K,Q=0;const W=10,de=1e3,be=async()=>{if(!H)return;if(Q>=W){k(!0);return}const we=yt.getState();if(we.isInitialized){k(!1);return}Q+=1,await we.initializeApp();const te=yt.getState();if(!H)return;if(te.isInitialized){k(!1);return}if(Q>=W){k(!0);return}const ge=Math.min(de*Math.pow(2,Q-1),16e3);K=setTimeout(be,ge)};return K=setTimeout(be,de),()=>{H=!1,K&&clearTimeout(K)}},[w,n,x]),o.useEffect(()=>{n&&k(!1)},[n]),o.useEffect(()=>{if(!C)return;const H=document.getElementById("initial-loading");H&&(H.classList.add("fade-out"),setTimeout(()=>{H.remove()},300))},[C]),o.useEffect(()=>{if(x||!r||a>0&&i>0)return;let H=!0,K=0;const Q=15,W=async()=>{const be=yt.getState();if(!(be.providers.length>0&&be.agents.length>0))try{be.providers.length===0&&await l(),yt.getState().agents.length===0&&await c()}catch{}};W();const de=setInterval(()=>{if(H){if(++K>=Q){clearInterval(de);return}W()}},2e3);return()=>{H=!1,clearInterval(de)}},[r,x,c,l,a,i]),o.useEffect(()=>{f||x||r&&nn.setDirectory(m)},[m,f,r,x]),o.useEffect(()=>{if(!F||typeof window>"u")return;const H=W=>{const de=W?.visible===!0;y(de)},K=W=>{if(W.origin!==window.location.origin)return;const de=W.data;de?.type==="openchamber:embedded-visibility"&&H(de.payload)},Q=window;return Q.__openchamberSetEmbeddedVisibility=H,window.addEventListener("message",K),()=>{window.removeEventListener("message",K),Q.__openchamberSetEmbeddedVisibility===H&&delete Q.__openchamberSetEmbeddedVisibility}},[F]),o.useEffect(()=>{!F?.directory||x||m!==F.directory&&u(F.directory,{showOverlay:!1})},[m,F,x,u]),o.useEffect(()=>{if(!F||typeof window>"u")return;const H=K=>{K.storageArea===window.localStorage&&K.key==="ui-store"&&Re.persist.rehydrate()};return window.addEventListener("storage",H),()=>{window.removeEventListener("storage",H)}},[F]),o.useEffect(()=>{if(typeof window>"u")return;const H=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;Re.getState().setActiveMainTab("chat"),$t.getState().setCurrentSession(W,de)};return window.addEventListener("openchamber:open-session",H),()=>window.removeEventListener("openchamber:open-session",H)},[]),o.useEffect(()=>{if(typeof window>"u")return;const H=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;Re.getState().setActiveMainTab("chat"),Re.getState().setSessionSwitcherOpen(!1),$t.getState().openNewSessionDraft({selectedProjectId:de,directoryOverride:W,preserveDirectoryOverride:!!W})};return window.addEventListener("openchamber:open-draft-session",H),()=>window.removeEventListener("openchamber:open-draft-session",H)},[]),o.useEffect(()=>{if(typeof window>"u")return;const H=K=>{const Q=K.detail,W=typeof Q?.projectPath=="string"?Q.projectPath.trim():"";if(!W)return;const de=Cs.getState(),be=de.projects.find(we=>we.path===W);be?de.setActiveProject(be.id):de.addProject(W)};return window.addEventListener("openchamber:open-project",H),()=>window.removeEventListener("openchamber:open-project",H)},[]),o.useEffect(()=>{typeof window>"u"||!n||f||$.current||($.current=!0,window.__openchamberAppReady=!0,window.dispatchEvent(new Event("openchamber:app-ready")))},[n,f]),mv({enabled:_}),MD({enabled:_}),$D(),pv(),PD();const Z=o.useCallback(()=>{g(H=>!H)},[]);fD(Z),o.useEffect(()=>{if(F)return;const H=K=>{Rd(K)&&K.shiftKey&&!K.altKey&&(K.code==="KeyD"||K.key.toLowerCase()==="d")&&(K.preventDefault(),g(W=>!W))};return window.addEventListener("keydown",H,!0),()=>window.removeEventListener("keydown",H,!0)},[F]),o.useEffect(()=>{F||d&&setTimeout(()=>p(),5e3)},[p,F,d]),o.useEffect(()=>{if(!N||M!=="not-injected")return;let H=!1,K=0;const Q=200,W=2e3,de=50,be=()=>{if(H)return;K++;const we=Dd();if(we!=="not-injected"){if(H=!0,O(we),we==="valid"){const ge=Of();ge&&B(Ff({isDesktopShell:!0,bootOutcome:ge}))}return}const te=Math.min(Q*Math.pow(1.1,K),W);if(K>=de){const ge=document.getElementById("initial-loading");ge&&!ge.textContent?.includes("taking longer")&&(ge.textContent="Desktop startup is taking longer than expected...")}window.setTimeout(be,te)};return window.setTimeout(be,Q),()=>{H=!0}},[N,M]);const ae=o.useCallback(async()=>{if(zD({isTauriShell:Va(),isDesktopLocalOriginActive:sa()})){await ch();return}window.location.reload()},[]),re=o.useCallback(async()=>{if(!I){k(!1),T(!0);try{await yt.getState().initializeApp()}finally{T(!1)}yt.getState().isInitialized||S(H=>H+1)}},[I]),me=H=>{if(H.screen==="recovery")return H.variant};if(N&&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(o.Suspense,{fallback:s.jsx("div",{className:"h-full"}),children:s.jsx($f,{mode:"first-launch",onCliAvailable:ae,onChooseRemote:()=>{}})})})});const H=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(o.Suspense,{fallback:s.jsx("div",{className:"h-full"}),children:s.jsx($f,{mode:"recovery",recoveryVariant:H,recoveryHostUrl:K,recoveryHostLabel:void 0,onCliAvailable:ae})})})})}if(F)return s.jsx(en,{children:s.jsx(qu,{sdk:nn.getSdkClient(),directory:m||"",children:s.jsx(Yu,{apis:t,children:s.jsx(Qu,{delayDuration:300,skipDelayDuration:150,children:s.jsx("div",{className:"h-full text-foreground bg-background",children:s.jsx(eT,{embeddedSessionChat:F,isVSCodeRuntime:x,embeddedBackgroundWorkEnabled:_})})})})})});if(q)return s.jsx(en,{children:s.jsx(GD,{})});if(C&&!n&&!x&&!F)return s.jsx(en,{children:s.jsx(JD,{onRetry:()=>{re()},isRetrying:I})});const fe=!n&&!N;return s.jsx(en,{children:s.jsx(qu,{sdk:nn.getSdkClient(),directory:m||"",children:s.jsx(Yu,{apis:t,children:s.jsx(Mw,{children:s.jsx(fv,{children:s.jsx(Qu,{delayDuration:300,skipDelayDuration:150,children:s.jsxs("div",{className:N?"h-full text-foreground bg-transparent":"h-full text-foreground bg-background",children:[s.jsx(vh,{embeddedBackgroundWorkEnabled:_}),s.jsx(Yg,{}),s.jsx(ZA,{}),s.jsx(wh,{}),!fe&&s.jsxs(s.Fragment,{children:[s.jsx(UD,{}),s.jsx(QD,{}),b&&s.jsx(sD,{onClose:()=>g(!1)})]})]})})})})})})})}function sT(t){return t.isAboutDialogOpen}function nT(t){return t.setAboutDialogOpen}function rT(t){return t.currentDirectory}function aT(t){return t.currentSessionId}function iT(t){return t.setCurrentSession}const oT=typeof window<"u"&&window.__OPENCHAMBER_RUNTIME_APIS__||(()=>{throw new Error("Runtime APIs not provided for legacy UI entrypoint.")})();hv();gv().then(()=>{Promise.all([xv(),bv()]).catch(t=>{console.error("[main] settings init failed:",t)}),yv(),vv(),wv()}).catch(t=>{console.error("[main] appearance init failed:",t)});const Qg=document.getElementById("root");if(!Qg)throw new Error("Root element not found");Ox.createRoot(Qg).render(s.jsx(_e.StrictMode,{children:s.jsx(jv,{children:s.jsx(Nv,{children:s.jsx(Sv,{children:s.jsx(kv,{children:s.jsx(tT,{apis:oT})})})})})}));const hT=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"}));export{LA as M,Xo as P,Vr as S,m4 as a,hT as m,on as u};
|