@openchamber/web 1.11.3 → 1.11.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/assets/{JsonTreeView-4KDa8lGo.js → JsonTreeView-YQcDxcEK.js} +1 -1
  2. package/dist/assets/MarkdownRendererImpl-h6uFn35l.js +6 -0
  3. package/dist/assets/{MultiRunWindow-BBmUkZot.js → MultiRunWindow-BXZBRXf8.js} +1 -1
  4. package/dist/assets/{OnboardingScreen-CmfCd-NF.js → OnboardingScreen-AGACaSpL.js} +2 -2
  5. package/dist/assets/{SettingsWindow-Cju1ws5b.js → SettingsWindow-DbIrbkwH.js} +1 -1
  6. package/dist/assets/TerminalView-ClACTVsY.js +1 -0
  7. package/dist/assets/{ToolOutputDialog-v9jBbw8P.js → ToolOutputDialog-C9M1QAxc.js} +1 -1
  8. package/dist/assets/{es-jann2TW8.js → es-nmO_Sy-z.js} +4 -4
  9. package/dist/assets/index-BWxr-Sly.css +1 -0
  10. package/dist/assets/{ko-BI4PbFHS.js → ko-DgzWO49N.js} +4 -4
  11. package/dist/assets/{main-d-4uuoz4.js → main-BG6I-VaN.js} +2 -2
  12. package/dist/assets/main-DLomPR7m.js +227 -0
  13. package/dist/assets/miniChat-ata1oHqJ.js +2 -0
  14. package/dist/assets/{modelPrefsAutoSave-bm-G98P3.js → modelPrefsAutoSave-D4IOtl1d.js} +97 -98
  15. package/dist/assets/{pl-eehxx-j8.js → pl-CdOdV9f8.js} +3 -3
  16. package/dist/assets/{pt-BR-D34YtT2a.js → pt-BR-gg2QcqbT.js} +5 -5
  17. package/dist/assets/renderElectronMiniChatApp-F0L1QF1k.js +2 -0
  18. package/dist/assets/{uk-Ce5zhj4w.js → uk-CrnDWkt0.js} +4 -4
  19. package/dist/assets/{vendor-.bun-CJSRTa27.js → vendor-.bun-BIr1wmDP.js} +2 -10
  20. package/dist/assets/{zh-CN-DOs9jvCa.js → zh-CN-CWGQwc9R.js} +5 -5
  21. package/dist/index.html +4 -4
  22. package/dist/mini-chat.html +4 -4
  23. package/package.json +1 -1
  24. package/server/lib/opencode/DOCUMENTATION.md +4 -0
  25. package/server/lib/opencode/config-entity-routes.js +115 -0
  26. package/server/lib/opencode/core-routes.js +1 -0
  27. package/server/lib/opencode/core-routes.test.js +17 -1
  28. package/server/lib/opencode/feature-routes-runtime.js +12 -0
  29. package/server/lib/opencode/index.js +9 -0
  30. package/server/lib/opencode/routes.js +14 -1
  31. package/server/lib/opencode/snippets.js +233 -0
  32. package/server/lib/opencode/snippets.test.js +68 -0
  33. package/server/lib/scheduled-tasks/runtime.js +4 -3
  34. package/dist/assets/MarkdownRendererImpl-ShCeV10r.js +0 -6
  35. package/dist/assets/TerminalView-K9P6-TDg.js +0 -1
  36. package/dist/assets/index-BG2LvnTV.css +0 -1
  37. package/dist/assets/main-BCXofLIN.js +0 -225
  38. package/dist/assets/miniChat-DCx1bzpk.js +0 -2
  39. package/dist/assets/renderElectronMiniChatApp-exfEAtnm.js +0 -2
  40. /package/dist/assets/{index-CQjRYgmJ.js → index-Dc1XJWqt.js} +0 -0
@@ -0,0 +1,227 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-.bun-BIr1wmDP.js","assets/vendor--V65Sl9C2.css","assets/modelPrefsAutoSave-D4IOtl1d.js","assets/index-Dc1XJWqt.js","assets/index-BWxr-Sly.css","assets/TerminalView-ClACTVsY.js","assets/JsonTreeView-YQcDxcEK.js","assets/SettingsWindow-DbIrbkwH.js","assets/MultiRunWindow-BXZBRXf8.js","assets/OnboardingScreen-AGACaSpL.js"])))=>i.map(i=>d[i]);
2
+ import{c as st,R as l,u as Ji,a as ti,j as s,b as Sl,C as kl,P as Yi,S as rl,d as Qg,D as al,e as Qi,f as Xi,g as Zn,i as bi,r as Oe,k as Xg,l as Zg,p as oo,m as Cl,n as ex,o as tx,q as sx,_ as Sr,s as Mf,v as Vc,t as za,w as Ef,x as Vo,W as nx,y as rx,V as ax,F as ix,z as ox,A as Jn,E as lx,B as Hn,G as cx,H as yi,I as cu,J as dx,K as ux,L as Ul,M as mx,N as px,O as fx,Q as du,T as uu,U as hx,X as Rf,Y as Ff,Z as gx,$ as mu,a0 as xx,a1 as bx,a2 as yx,a3 as vx,a4 as wx,a5 as jx,a6 as Nx,a7 as Of,a8 as Sx,a9 as Uc,aa as Lf,ab as $f,ac as Xa,ad as $i,ae as Wc,af as ot,ag as _f,ah as Bf,ai as kx,aj as Cx,ak as Ix,al as Px,am as Ax,an as Dx,ao as Tx,ap as Mx,aq as Ex,ar as Rx,as as pu,at as fu,au as Wl,av as Fx}from"./vendor-.bun-BIr1wmDP.js";import{a as Ox,b as Lx,f as $x}from"./index-Dc1XJWqt.js";import{u as dt,a as Re,b as nn,c as xe,I as D,d as Is,i as on,g as Xn,e as vr,s as Kl,r as Hl,f as Gl,h as Ps,o as sn,j as zs,T as Ct,k as It,l as At,m as Ea,n as Qr,p as hu,D as $t,q as _x,t as il,v as In,w as H,x as As,y as Gn,z as Ds,A as Ts,B as zf,C as gu,E as Bx,F as zx,G as xu,H as Vx,J as Ux,K as Wx,L as Kx,M as Rn,N as vn,O as qn,P as Kc,Q as pr,R as Vf,S as Hx,U as bt,V as Lt,W as Gx,X as Uf,Y as Pa,Z as Id,_ as Bn,$ as Pd,a0 as Wf,a1 as qx,a2 as bu,a3 as Jx,a4 as Yx,a5 as Kf,a6 as Qx,a7 as Xx,a8 as Hf,a9 as Ad,aa as ol,ab as Zx,ac as Il,ad as qr,ae as Dd,af as Uo,ag as eb,ah as tb,ai as Ys,aj as Gf,ak as qf,al as Jf,am as Lr,an as li,ao as sb,ap as Yf,aq as ys,ar as hs,as as be,at as ms,au as ps,av as Ra,aw as nb,ax as rb,ay as wo,az as yn,aA as Qf,aB as Xf,aC as Pl,aD as ab,aE as Zf,aF as yu,aG as vu,aH as un,aI as Bt,aJ as fs,aK as ib,aL as ob,aM as lb,aN as cb,aO as db,aP as ub,aQ as mb,aR as Ns,aS as Us,aT as pb,aU as fb,aV as Ss,aW as hb,aX as gb,aY as xb,aZ as bb,a_ as jr,a$ as lo,b0 as yb,b1 as Vs,b2 as Al,b3 as Za,b4 as ci,b5 as di,b6 as wu,b7 as ui,b8 as vb,b9 as os,ba as ls,bb as us,bc as cs,bd as Tt,be as wb,bf as Fa,bg as jb,bh as Zr,bi as Td,bj as Dl,bk as Nb,bl as Md,bm as Sb,bn as kb,bo as Ed,bp as Cb,bq as tn,br as co,bs as Nr,bt as Ib,bu as Pb,bv as ql,bw as Tl,bx as Rd,by as Fd,bz as Ml,bA as Tn,bB as Od,bC as Oa,bD as ll,bE as cl,bF as mi,bG as eh,bH as Ab,bI as Cr,bJ as Db,bK as ju,bL as dl,bM as El,bN as th,bO as Tb,bP as Mb,bQ as uo,bR as Eb,bS as Ld,bT as Rb,bU as ei,bV as Zi,bW as sh,bX as pi,bY as nh,bZ as Fb,b_ as Ob,b$ as $d,c0 as oa,c1 as si,c2 as Aa,c3 as Rl,c4 as mo,c5 as po,c6 as Hc,c7 as rh,c8 as _d,c9 as ah,ca as eo,cb as Lb,cc as $b,cd as _b,ce as Bb,cf as zb,cg as ni,ch as Jl,ci as Nu,cj as Vb,ck as Ub,cl as Wb,cm as Kb,cn as Fl,co as Ja,cp as Yl,cq as Hb,cr as Su,cs as Yr,ct as Gb,cu as ku,cv as Cu,cw as Iu,cx as Pu,cy as Wo,cz as Au,cA as qb,cB as Ql,cC as Jb,cD as Yb,cE as Qb,cF as Xb,cG as Zb,cH as ey,cI as ty,cJ as Xl,cK as Du,cL as sy,cM as ny,cN as ry,cO as ay,cP as iy,cQ as Zl,cR as oy,cS as Tu,cT as _i,cU as ly,cV as ih,cW as cy,cX as Ya,cY as dy,cZ as Mu,c_ as uy,c$ as oh,d0 as jo,d1 as Ui,d2 as my,d3 as lh,d4 as py,d5 as fy,d6 as Eu,d7 as Ru,d8 as ch,d9 as dh,da as ec,db as No,dc as hy,dd as gy,de as xy,df as by,dg as uh,dh as mh,di as ph,dj as Gc,dk as Bd,dl as yy,dm as ws,dn as to,dp as fi,dq as ri,dr as Fu,ds as Un,dt as vy,du as Wi,dv as wy,dw as fh,dx as jy,dy as Ny,dz as qc,dA as Sy,dB as Ou,dC as ky,dD as Cy,dE as Iy,dF as zd,dG as hh,dH as Py,dI as Ay,dJ as Dy,dK as Ty,dL as Lu,dM as My,dN as Ey,dO as Ry,dP as Fy,dQ as tc,dR as Oy,dS as Ly,dT as $y,dU as _y,dV as By,dW as zy,dX as Vy,dY as Uy,dZ as Wy,d_ as Ky,d$ as Hy,e0 as Gy,e1 as $u,e2 as qy,e3 as Jy,e4 as gh,e5 as Yy,e6 as Qy,e7 as Xy,e8 as Zy,e9 as ea,ea as ev,eb as _u,ec as tv,ed as Ko,ee as Ho,ef as sv,eg as nv,eh as rv,ei as av,ej as iv,ek as Bu,el as ov,em as zu,en as lv,eo as cv,ep as dv,eq as Vu,er as Uu,es as Wu,et as uv,eu as xh,ev as bh,ew as mv,ex as pv,ey as fv,ez as hv,eA as gv,eB as xv,eC as bv,eD as yv,eE as vv,eF as wv,eG as jv}from"./modelPrefsAutoSave-D4IOtl1d.js";import{J as Nv}from"./JsonTreeView-YQcDxcEK.js";const Sv=({transform:t})=>({...t,y:0}),kv=t=>{const e=st.c(18),{id:n,children:r,className:a}=t;let i;e[0]!==n?(i={id:n},e[0]=n,e[1]=i):i=e[1];const{attributes:o,listeners:c,setNodeRef:d,transform:p,transition:m,isDragging:u}=Sl(i);let f;e[2]!==p?(f=kl.Transform.toString(p),e[2]=p,e[3]=f):f=e[3];let b;e[4]!==f||e[5]!==m?(b={transform:f,transition:m},e[4]=f,e[5]=m,e[6]=b):b=e[6];const h=u&&"opacity-50";let v;e[7]!==a||e[8]!==h?(v=xe("h-full rounded-md",a,h),e[7]=a,e[8]=h,e[9]=v):v=e[9];let x;return e[10]!==o||e[11]!==r||e[12]!==n||e[13]!==c||e[14]!==d||e[15]!==b||e[16]!==v?(x=s.jsx("div",{ref:d,"data-sortable-tab-id":n,style:b,className:v,...o,...c,children:r}),e[10]=o,e[11]=r,e[12]=n,e[13]=c,e[14]=d,e[15]=b,e[16]=v,e[17]=x):x=e[17],x},Cv=t=>{const e=st.c(6),{id:n,children:r,className:a}=t;let i;e[0]!==a?(i=xe("h-full",a),e[0]=a,e[1]=i):i=e[1];let o;return e[2]!==r||e[3]!==n||e[4]!==i?(o=s.jsx("div",{className:i,"data-sortable-tab-id":n,children:r}),e[2]=r,e[3]=n,e[4]=i,e[5]=o):o=e[5],o},$r=t=>{const e=st.c(121),{items:n,activeId:r,onSelect:a,onClose:i,onReorder:o,layoutMode:c,variant:d,activePillInsetClassName:p,activePillButtonClassName:m,inactiveTabsIconOnly:u,iconOnlyActiveTab:f,animateActivePill:b,activePillLowercase:h,className:v}=t,x=c===void 0?"scrollable":c,g=d===void 0?"default":d,w=u===void 0?!1:u,y=f===void 0?!1:f,C=h===void 0?!0:h,{t:k}=dt(),j=Re(Iv),{isTablet:S}=nn(),I=j||S,M=l.useRef(null);let P;e[0]===Symbol.for("react.memo_cache_sentinel")?(P={left:!1,right:!1},e[0]=P):P=e[0];const[A,N]=l.useState(P);let E;e[1]!==n?(E=n.map(Pv),e[1]=n,e[2]=E):E=e[2];const T=E,R=x==="scrollable",V=g==="default",_=g==="active-pill",U=g==="animated",B=_||U,z=V,K=B||z,F=_&&R,G=B,Q=b??U,te=typeof o=="function",Z=te?kv:Cv;let fe;e[3]===Symbol.for("react.memo_cache_sentinel")?(fe=new Map,e[3]=fe):fe=e[3];const ue=l.useRef(fe),[W,q]=l.useState(null);let J;e[4]===Symbol.for("react.memo_cache_sentinel")?(J={activationConstraint:{distance:8}},e[4]=J):J=e[4];const ne=Ji(ti(Yi,J)),ee=Av;let he;e[5]===Symbol.for("react.memo_cache_sentinel")?(he=(nt,Ne)=>{if(Ne){ue.current.set(nt,Ne);return}ue.current.delete(nt)},e[5]=he):he=e[5];const ke=he;let oe;e[6]!==r||e[7]!==K?(oe=()=>{if(!K||!r){q(Dv);return}const nt=M.current,Ne=ue.current.get(r);if(!nt||!Ne){q(Tv);return}let Ke=0,Ve=0,qe=Ne;for(;qe&&qe!==nt;)Ke=Ke+qe.offsetLeft,Ve=Ve+qe.offsetTop,qe=qe.offsetParent;const lt={left:Ke,top:Ve,width:Ne.offsetWidth,height:Ne.offsetHeight};q(He=>ee(He,lt)?He:lt)},e[6]=r,e[7]=K,e[8]=oe):oe=e[8];const ge=oe;let me;e[9]!==R?(me=()=>{if(!R){N({left:!1,right:!1});return}const nt=M.current;if(!nt){N({left:!1,right:!1});return}N({left:nt.scrollLeft>2,right:nt.scrollLeft+nt.clientWidth<nt.scrollWidth-2})},e[9]=R,e[10]=me):me=e[10];const ye=me;let ie;e[11]!==R||e[12]!==ye?(ie=()=>{if(!R){N({left:!1,right:!1});return}const nt=M.current;if(!nt)return;ye(),nt.addEventListener("scroll",ye,{passive:!0});const Ne=new ResizeObserver(ye);return Ne.observe(nt),()=>{nt.removeEventListener("scroll",ye),Ne.disconnect()}},e[11]=R,e[12]=ye,e[13]=ie):ie=e[13];let ve;e[14]!==R||e[15]!==n.length||e[16]!==ye?(ve=[R,n.length,ye],e[14]=R,e[15]=n.length,e[16]=ye,e[17]=ve):ve=e[17],l.useEffect(ie,ve);let X;e[18]!==r||e[19]!==ge||e[20]!==K?(X=()=>{if(!K){q(null);return}ge();const nt=M.current;if(!nt)return;const Ne=new ResizeObserver(ge);if(Ne.observe(nt),r){const Ke=ue.current.get(r);Ke&&Ne.observe(Ke)}return()=>{Ne.disconnect()}},e[18]=r,e[19]=ge,e[20]=K,e[21]=X):X=e[21];let Se;e[22]!==r||e[23]!==n.length||e[24]!==ge||e[25]!==K?(Se=[r,n.length,ge,K],e[22]=r,e[23]=n.length,e[24]=ge,e[25]=K,e[26]=Se):Se=e[26],l.useEffect(X,Se);let Ae;e[27]!==ge?(Ae=()=>{ge()},e[27]=ge,e[28]=Ae):Ae=e[28],l.useLayoutEffect(Ae);let pe;e[29]!==r||e[30]!==R||e[31]!==ye?(pe=()=>{if(!R||!r)return;const nt=M.current;if(!nt)return;const Ne=window.requestAnimationFrame(()=>{const Ke=typeof window.CSS?.escape=="function"?window.CSS.escape(r):r.replace(/"/g,'\\"'),Ve=nt.querySelector(`[data-sortable-tab-id="${Ke}"]`);Ve&&(Ve.scrollIntoView({block:"nearest",inline:"nearest"}),ye())});return()=>{window.cancelAnimationFrame(Ne)}},e[29]=r,e[30]=R,e[31]=ye,e[32]=pe):pe=e[32];let we;e[33]!==r||e[34]!==R||e[35]!==n.length||e[36]!==ye?(we=[r,R,n.length,ye],e[33]=r,e[34]=R,e[35]=n.length,e[36]=ye,e[37]=we):we=e[37],l.useEffect(pe,we);let Ie;e[38]!==o?(Ie=nt=>{if(!o)return;const{active:Ne,over:Ke}=nt;!Ke||Ne.id===Ke.id||o(String(Ne.id),String(Ke.id))},e[38]=o,e[39]=Ie):Ie=e[39];const Y=Ie;let re;e[40]!==v?(re=xe("relative flex h-full min-w-0 flex-1",v),e[40]=v,e[41]=re):re=e[41];let Pe;e[42]!==R||e[43]!==A||e[44]!==B?(Pe=R&&A.left?s.jsx("div",{className:xe("pointer-events-none absolute inset-y-0 left-0 z-20 bg-gradient-to-r to-transparent",B?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,e[42]=R,e[43]=A,e[44]=B,e[45]=Pe):Pe=e[45];let ce;e[46]!==R||e[47]!==A||e[48]!==B?(ce=R&&A.right?s.jsx("div",{className:xe("pointer-events-none absolute inset-y-0 right-0 z-20 bg-gradient-to-l to-transparent",B?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,e[46]=R,e[47]=A,e[48]=B,e[49]=ce):ce=e[49];const Ce=B?"items-center overflow-x-hidden overflow-y-hidden":"items-stretch",Te=B&&"@container/pill-tabs",$e=B&&"pill-tabs__track",De=B&&(p??"gap-0.5 py-0.5"),de=z&&"items-center overflow-y-hidden",O=G&&"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",L=R?"overflow-x-auto scrollbar-none":"overflow-x-hidden";let $;e[50]!==Ce||e[51]!==Te||e[52]!==$e||e[53]!==De||e[54]!==de||e[55]!==O||e[56]!==L?($=xe("relative flex h-full min-w-0 flex-1",Ce,Te,$e,De,de,O,L),e[50]=Ce,e[51]=Te,e[52]=$e,e[53]=De,e[54]=de,e[55]=O,e[56]=L,e[57]=$):$=e[57];let je;e[58]!==R?(je=R?{scrollbarWidth:"none",msOverflowStyle:"none"}:void 0,e[58]=R,e[59]=je):je=e[59];let ae;e[60]!==k?(ae=k("sortableTabsStrip.aria.tabs"),e[60]=k,e[61]=ae):ae=e[61];let _e;e[62]!==W||e[63]!==Q||e[64]!==B?(_e=B&&W?s.jsx("div",{className:xe("pointer-events-none absolute left-0 top-0 z-0 rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] bg-[var(--surface-elevated)]","border border-border/60"),style:{transform:`translate3d(${W.left}px, ${W.top}px, 0)`,width:`${W.width}px`,height:`${W.height}px`,transition:Q?"transform 300ms cubic-bezier(0.65, 0, 0.35, 1), width 300ms cubic-bezier(0.65, 0, 0.35, 1), height 300ms cubic-bezier(0.65, 0, 0.35, 1)":void 0}}):null,e[62]=W,e[63]=Q,e[64]=B,e[65]=_e):_e=e[65];let le;e[66]!==W||e[67]!==z?(le=z&&W?s.jsx("div",{className:"pointer-events-none absolute left-0 -bottom-px z-10 h-[3px] rounded-t-[2px] bg-[var(--primary-base)]",style:{transform:`translate3d(${W.left}px, 0, 0)`,width:`${W.width}px`},"aria-hidden":!0}):null,e[66]=W,e[67]=z,e[68]=le):le=e[68];let Me;if(e[69]!==Z||e[70]!==r||e[71]!==m||e[72]!==C||e[73]!==I||e[74]!==y||e[75]!==w||e[76]!==_||e[77]!==j||e[78]!==R||e[79]!==n||e[80]!==i||e[81]!==a||e[82]!==F||e[83]!==B){let nt;e[85]!==Z||e[86]!==r||e[87]!==m||e[88]!==C||e[89]!==I||e[90]!==y||e[91]!==w||e[92]!==_||e[93]!==j||e[94]!==R||e[95]!==i||e[96]!==a||e[97]!==F||e[98]!==B?(nt=Ne=>{const Ke=Ne.id===r,Ve=w&&B&&!Ke&&!!Ne.icon,qe=!Ve,lt=!!Ne.icon&&(!y||Ke),He=w&&B&&Ke&&!R&&!F,ze=Ne.closable!==!1&&!!i,et=ze&&!!Ne.icon,yt=R||F?void 0:B?He?"flex-none basis-auto":j?"flex-1 basis-0 min-w-0":"flex-1 basis-0 min-w-fit":"min-w-0 flex-1 basis-0",Rt=ze?ht=>{ht.button===1&&(ht.preventDefault(),ht.stopPropagation(),i?.(Ne.id))}:void 0,kt=ze?Mv:void 0;return s.jsx(Z,{id:Ne.id,className:yt,children:s.jsxs("div",{ref:ht=>ke(Ne.id,ht),onAuxClick:Rt,onMouseDown:kt,className:xe("group flex h-full min-w-0 flex-nowrap items-center",R||F?"shrink-0":B?"w-full":"w-full min-w-0",B?"relative z-10 bg-transparent":Ke?"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":Ke,"aria-label":Ve?Ne.title??Ne.label:void 0,onClick:()=>a(Ne.id),className:xe(B?"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",B&&C?"lowercase":null,B&&(Ve?"gap-0":"gap-1.5"),B?F?"shrink-0 whitespace-nowrap px-3 text-center":R?"max-w-56 shrink-0 px-3 text-center":Ve?"px-2 !min-w-0 text-center":He?"shrink-0 whitespace-nowrap px-3 text-center":"px-3 text-center":R?"max-w-56 justify-start truncate px-3 text-left":"w-full justify-center truncate px-3 text-center",B?m??(_?j?"h-[38px]":"h-[31px]":"h-7"):null,B?Ke?"text-foreground":"text-muted-foreground hover:text-foreground":null,B?"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:Ne.title??Ne.label,children:B?s.jsxs(s.Fragment,{children:[lt?s.jsxs("span",{className:"relative flex h-4 w-4 shrink-0 items-center justify-center",children:[s.jsx("span",{className:xe("flex items-center justify-center transition-opacity",et&&(I?"opacity-0":"group-hover:opacity-0")),children:Ne.icon}),et?s.jsx("span",{role:"button",tabIndex:-1,className:xe("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:Ev,onClick:ht=>{ht.stopPropagation(),i?.(Ne.id)},"aria-label":Ne.closeLabel??`Close ${Ne.label} tab`,title:Ne.closeLabel??`Close ${Ne.label} tab`,children:s.jsx(D,{name:"close",className:"h-3.5 w-3.5"})}):null]}):null,qe?s.jsx("span",{className:"animated-tabs__label truncate",children:Ne.label}):null]}):s.jsxs("span",{className:xe("flex min-w-0 flex-nowrap items-center gap-1.5",!R&&"justify-center"),children:[lt?s.jsxs("span",{className:xe("relative flex h-4 w-4 shrink-0 items-center justify-center transition-colors duration-200 ease-out",Ke?"text-[var(--primary-base)]":"text-muted-foreground"),children:[s.jsx("span",{className:xe("flex items-center justify-center transition-opacity",et&&(I?"opacity-0":"group-hover:opacity-0")),children:Ne.icon}),et?s.jsx("span",{role:"button",tabIndex:-1,className:xe("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:Rv,onClick:ht=>{ht.stopPropagation(),i?.(Ne.id)},"aria-label":Ne.closeLabel??`Close ${Ne.label} tab`,title:Ne.closeLabel??`Close ${Ne.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:Ne.label})]})}),ze&&!et?s.jsx("button",{type:"button",onPointerDown:Fv,onClick:ht=>{ht.stopPropagation(),i?.(Ne.id)},className:xe("relative z-20 inline-flex !min-h-0 !min-w-0 items-center justify-center transition-opacity",B?"-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",B?Ke?"text-muted-foreground hover:bg-transparent hover:text-foreground":"text-muted-foreground opacity-0 hover:bg-transparent hover:text-foreground group-hover:opacity-100":Ke?"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":Ne.closeLabel??`Close ${Ne.label} tab`,title:Ne.closeLabel??`Close ${Ne.label} tab`,children:s.jsx(D,{name:"close",className:"h-3 w-3"})}):null]})},Ne.id)},e[85]=Z,e[86]=r,e[87]=m,e[88]=C,e[89]=I,e[90]=y,e[91]=w,e[92]=_,e[93]=j,e[94]=R,e[95]=i,e[96]=a,e[97]=F,e[98]=B,e[99]=nt):nt=e[99],Me=n.map(nt),e[69]=Z,e[70]=r,e[71]=m,e[72]=C,e[73]=I,e[74]=y,e[75]=w,e[76]=_,e[77]=j,e[78]=R,e[79]=n,e[80]=i,e[81]=a,e[82]=F,e[83]=B,e[84]=Me}else Me=e[84];let Ge;e[100]!==$||e[101]!==je||e[102]!==ae||e[103]!==_e||e[104]!==le||e[105]!==Me?(Ge=s.jsxs("div",{ref:M,className:$,style:je,role:"tablist","aria-label":ae,children:[_e,le,Me]}),e[100]=$,e[101]=je,e[102]=ae,e[103]=_e,e[104]=le,e[105]=Me,e[106]=Ge):Ge=e[106];let at;e[107]!==re||e[108]!==Pe||e[109]!==ce||e[110]!==Ge?(at=s.jsxs("div",{className:re,children:[Pe,ce,Ge]}),e[107]=re,e[108]=Pe,e[109]=ce,e[110]=Ge,e[111]=at):at=e[111];const Ye=at;if(!te)return Ye;let Xe;e[112]===Symbol.for("react.memo_cache_sentinel")?(Xe=[Sv],e[112]=Xe):Xe=e[112];let ut;e[113]!==T||e[114]!==Ye?(ut=s.jsx(rl,{items:T,strategy:Qg,children:Ye}),e[113]=T,e[114]=Ye,e[115]=ut):ut=e[115];let rt;e[116]===Symbol.for("react.memo_cache_sentinel")?(rt=s.jsx(al,{dropAnimation:null}),e[116]=rt):rt=e[116];let it;return e[117]!==Y||e[118]!==ne||e[119]!==ut?(it=s.jsxs(Qi,{sensors:ne,collisionDetection:Xi,onDragEnd:Y,modifiers:Xe,children:[ut,rt]}),e[117]=Y,e[118]=ne,e[119]=ut,e[120]=it):it=e[120],it};function Iv(t){return t.isMobile}function Pv(t){return t.id}function Av(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 Dv(t){return t===null?t:null}function Tv(t){return t===null?t:null}function Mv(t){t.button===1&&t.preventDefault()}function Ev(t){t.stopPropagation()}function Rv(t){t.stopPropagation()}function Fv(t){t.stopPropagation()}function Ku(t){const e=st.c(14);let n,r,a,i;e[0]!==t?({size:a,className:n,style:i,...r}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=a,e[4]=i):(n=e[1],r=e[2],a=e[3],i=e[4]);const o=typeof a=="number"?`${a}px`:a,c=typeof a=="number"?`${a}px`:a;let d;e[5]!==i||e[6]!==o||e[7]!==c?(d={width:o,height:c,...i},e[5]=i,e[6]=o,e[7]=c,e[8]=d):d=e[8];let p;e[9]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsx("path",{d:"M112,148a12,12,0,0,0-12,12v19L69.17,148.2A4,4,0,0,1,68,145.37V97.94a36,36,0,1,0-24,0v47.43a27.81,27.81,0,0,0,8.2,19.8L83,196H64a12,12,0,0,0,0,24h48a12,12,0,0,0,12-12V160A12,12,0,0,0,112,148ZM56,52A12,12,0,1,1,44,64,12,12,0,0,1,56,52ZM212,158.06V110.63a27.81,27.81,0,0,0-8.2-19.8L173,60h19a12,12,0,0,0,0-24H144a12,12,0,0,0-12,12V96a12,12,0,0,0,24,0V77l30.83,30.83a4,4,0,0,1,1.17,2.83v47.43a36,36,0,1,0,24,0ZM200,204a12,12,0,1,1,12-12A12,12,0,0,1,200,204Z"}),e[9]=p):p=e[9];let m;return e[10]!==n||e[11]!==r||e[12]!==d?(m=s.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 256 256",fill:"currentColor",className:n,style:d,...r,children:p}),e[10]=n,e[11]=r,e[12]=d,e[13]=m):m=e[13],m}const Br=[{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"}];Br.reduce((t,e)=>(t[e.id]=e,t),{});const Ov=t=>typeof t!="number"||!Number.isFinite(t)?null:Math.max(0,Math.min(100,Math.round(t))),Lv=t=>typeof t!="number"||!Number.isFinite(t)?"-":`${Math.round(t)}%`,so=(t,e)=>t??Lv(e),Vd=(t,e)=>{if(!t)return e??"";try{const n=new Date(t);if(!Number.isFinite(n.getTime()))return e??"";const r=new Date;return n.toDateString()===r.toDateString()?n.toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"}):n.toLocaleString(void 0,{month:"short",day:"numeric",weekday:"short",hour:"numeric",minute:"2-digit"})}catch{return e??""}},yh=t=>t===null?"safe":t>=80?"critical":t>=50?"warn":"safe",Ud=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,$v=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},no=(t,e,n,r)=>{let a=n;if(a===null&&r&&(a=$v(r)),t===null||e===null||a===null||a<=0)return null;const i=Date.now(),o=Math.max(0,(e-i)/1e3),c=Math.max(0,Math.min(a,a-o)),d=Math.max(0,Math.min(1,c/a)),p=t/100,m=t>=100&&o>0;let u;d>.01?u=Math.min(999,p/d*100):u=t;let f;m?f="exhausted":p<=d?f="on-track":u<=130?f="slightly-fast":f="too-fast";const b=a>=120*3600,h=b?86400:3600,v=b?"d":"h",x=a/h,g=Math.max(c/h,x*.01),w=t/g,y=Number.isFinite(w)?`${Math.min(999.9,Math.max(0,w)).toFixed(1)}%/${v}`:"-",C=u>100?`+${Math.round(u)}%`:`${Math.round(u)}%`;let k=null;const j=a/86400;return j>=7&&(k=100/j),{elapsedRatio:d,usageRatio:p,predictedFinalPercent:u,remainingSeconds:o,isExhausted:m,elapsedSeconds:c,totalSeconds:a,status:f,paceRateText:y,predictText:C,dailyAllocationPercent:k}},_v=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)"}},Hu=t=>{const e=Math.max(0,Math.floor(t)),n=Math.floor(e/60),r=Math.floor(n/60),a=Math.floor(r/24),i=r%24,o=n%60;return a>0?`${a}d ${i}h`:r>0?`${r}h`:n===0?"<1m":`${o}m`},Jr=t=>Math.min(100,Math.max(0,t*100));function ul(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 Bv=[{id:"gemini-auth",label:"Gemini",matcher:t=>t.startsWith("gemini/"),order:1},{id:"antigravity-auth",label:"Antigravity",matcher:t=>t.startsWith("antigravity/"),order:2}],vh={google:Bv};function wh(t,e){const n=vh[e]??[];for(const r of n)if(r.matcher(t))return r;return null}function jh(t){return vh[t]??[]}function Nh(t){return[...t].sort((e,n)=>e.order-n.order)}function zv(t,e){const n=new Map;for(const r of Object.keys(t)){const i=wh(r,e)?.id??null;n.has(i)||n.set(i,[]),n.get(i).push(r)}return n}function Vv(t,e,n){const r=new Map;for(const a of t){const i=e(a),c=wh(i,n)?.id??null;r.has(c)||r.set(c,[]),r.get(c).push(a)}return r}function Uv(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 Wd=6e4,Gu=t=>{const e=Br.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))):Wd,a=t?.usageDisplayMode==="remaining"?"remaining":"usage",i=Array.isArray(t?.usageDropdownProviders)?t?.usageDropdownProviders:null,o=i?i.filter(u=>typeof u=="string"&&e.includes(u)):e,c={},d=t?.usageSelectedModels;if(d&&typeof d=="object")for(const[u,f]of Object.entries(d))Array.isArray(f)&&(c[u]=f.filter(b=>typeof b=="string"));const p={},m=t?.usageExpandedFamilies;if(m&&typeof m=="object")for(const[u,f]of Object.entries(m))Array.isArray(f)&&(p[u]=f.filter(b=>typeof b=="string"));return{autoRefresh:n,refreshIntervalMs:r,displayMode:a,dropdownProviderIds:o,selectedModels:c,expandedFamilies:p}},Wv=async()=>{const t=Xn()?.settings;if(t)try{const n=(await t.load())?.settings;return Gu(n??null)}catch{}if(!on()){const e=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(e.ok){const n=await e.json().catch(()=>null);return Gu(n)}}return{autoRefresh:!1,refreshIntervalMs:Wd,displayMode:"usage",dropdownProviderIds:Br.map(e=>e.id),selectedModels:{},expandedFamilies:{}}},Os=Zn()(bi((t,e)=>({results:[],selectedProviderId:null,isLoading:!1,isFetchingProvider:{},lastUpdated:null,error:null,autoRefresh:!1,refreshIntervalMs:Wd,displayMode:"usage",dropdownProviderIds:Br.map(n=>n.id),selectedModels:{},expandedFamilies:{},loadSettings:async()=>{try{const n=await Wv();t(n)}catch(n){console.warn("Failed to load usage settings:",n)}},fetchAllQuotas:async()=>{t({isLoading:!0,error:null});const n=Br.map(r=>r.id);try{await Promise.all(n.map(r=>e().fetchProviderQuota(r))),t({isLoading:!1,lastUpdated:Date.now()})}catch(r){const a=r instanceof Error?r.message:"Failed to fetch quotas";t({isLoading:!1,error:a})}},fetchProviderQuota:async n=>{t(r=>({isFetchingProvider:{...r.isFetchingProvider,[n]:!0}}));try{const r=await fetch(`/api/quota/${encodeURIComponent(n)}`),a=await r.json().catch(()=>null);if(!r.ok)throw new Error(a?.error||"Failed to fetch quota");const i=a;t(o=>{const c=o.results.filter(d=>d.providerId!==n);return c.push(i),{results:c,error:null}})}catch(r){const a=r instanceof Error?r.message:"Failed to fetch quota",i={providerId:n,providerName:n,ok:!1,configured:!1,error:a,usage:null,fetchedAt:Date.now()};t(o=>{const c=o.results.filter(d=>d.providerId!==n);return c.push(i),{results:c,error:a}})}finally{t(r=>({isFetchingProvider:{...r.isFetchingProvider,[n]:!1}}))}},setSelectedProvider:n=>t({selectedProviderId:n}),setAutoRefresh:n=>t({autoRefresh:n}),setRefreshInterval:n=>{const r=Math.max(3e4,Math.min(3e5,Math.round(n)));t({refreshIntervalMs:r})},setDisplayMode:n=>t({displayMode:n}),setDropdownProviderIds:n=>t({dropdownProviderIds:n}),setSelectedModels:(n,r)=>{t(a=>({selectedModels:{...a.selectedModels,[n]:r}}))},toggleModelSelected:(n,r)=>{t(a=>{const i=a.selectedModels[n]??[],c=i.includes(r)?i.filter(d=>d!==r):[...i,r];return{selectedModels:{...a.selectedModels,[n]:c}}})},setExpandedFamilies:(n,r)=>{t(a=>({expandedFamilies:{...a.expandedFamilies,[n]:r}})),Is({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}}}),Is({usageExpandedFamilies:e().expandedFamilies})},applyDefaultSelections:(n,r)=>{if((e().selectedModels[n]?.length??0)>0)return;const i=Uv(n,r);i.length!==0&&(t(o=>({selectedModels:{...o.selectedModels,[n]:i}})),Is({usageSelectedModels:e().selectedModels}))}}),{name:"quota-store"})),Sh=()=>{const t=st.c(5),e=Os(Kv),n=Os(Hv),r=Os(Gv);let a,i;t[0]!==e||t[1]!==r||t[2]!==n?(a=()=>{if(!e)return;const o=window.setInterval(()=>{r()},n);return()=>window.clearInterval(o)},i=[e,n,r],t[0]=e,t[1]=r,t[2]=n,t[3]=a,t[4]=i):(a=t[3],i=t[4]),l.useEffect(a,i)};function Kv(t){return t.autoRefresh}function Hv(t){return t.refreshIntervalMs}function Gv(t){return t.fetchAllQuotas}const ml=Oe.forwardRef((t,e)=>{const n=st.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=xe("peer inline-flex shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-none transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[checked]:bg-primary data-[unchecked]:bg-[var(--interactive-border)]",r),n[3]=r,n[4]=i):i=n[4];let o;n[5]===Symbol.for("react.memo_cache_sentinel")?(o={width:"36px",height:"20px",minWidth:"36px",minHeight:"20px"},n[5]=o):o=n[5];let c;n[6]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(Xg,{className:xe("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(Zg,{className:i,style:o,...a,ref:e,children:c}),n[7]=a,n[8]=e,n[9]=i,n[10]=d):d=n[10],d});ml.displayName="Switch";const So=()=>{try{const e=Ps.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const n=sn.getDirectory();if(n?.trim())return n.trim()}catch(t){console.warn("[McpConfigStore] Error resolving config directory:",t)}return null},qu=t=>t?Object.entries(t).map(([e,n])=>({key:e,value:n})):[],Ju=t=>{const e=t.filter(n=>n.key.trim());if(e.length!==0)return Object.fromEntries(e.map(n=>[n.key.trim(),n.value]))},ko=t=>typeof t!="string"?void 0:t.trim()||void 0,sc=800,qv=5e3,Jv="__default__",Jc=new Map,nc=new Map,kh=t=>t?.trim()||Jv,rc=t=>{Jc.delete(kh(t))},ro=Zn()(bi(oo((t,e)=>({mcpServers:[],selectedMcpName:null,isLoading:!1,mcpDraft:null,setSelectedMcp:n=>t({selectedMcpName:n}),setMcpDraft:n=>t({mcpDraft:n}),loadMcpConfigs:async n=>{const r=So(),a=kh(r),i=Date.now(),o=Jc.get(a)??0,c=e().mcpServers.length>0;if(!n?.force&&c&&i-o<qv)return!0;const d=nc.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}),Jc.set(a,Date.now()),!0}catch(m){return console.error("[McpConfigStore] Failed to load MCP configs:",m),t({isLoading:!1}),!1}})();nc.set(a,p);try{return await p}finally{nc.delete(a)}},createMcp:async n=>{Kl("Creating MCP server configuration…");let r=!1;try{const a=Yu(n),i=So(),o=i?`?directory=${encodeURIComponent(i)}`:"",c=await fetch(`/api/config/mcp/${encodeURIComponent(n.name)}${o}`,{method:"POST",headers:{"Content-Type":"application/json",...i?{"x-opencode-directory":i}:{}},body:JSON.stringify(a)}),d=await c.json().catch(()=>null);if(!c.ok)throw new Error(d?.error||"Failed to create MCP server");return rc(i),d?.requiresReload?(r=!0,await Hl({message:d.message,delayMs:d.reloadDelayMs??sc,scopes:["all"]}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:d?.reloadFailed===!0,message:d?.message,warning:d?.warning}):(await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:d?.reloadFailed===!0,message:d?.message,warning:d?.warning})}catch(a){return console.error("[McpConfigStore] Failed to create MCP:",a),{ok:!1}}finally{r||Gl()}},updateMcp:async(n,r)=>{Kl("Updating MCP server configuration…");let a=!1;try{const i=Yu(r),o=So(),c=o?`?directory=${encodeURIComponent(o)}`:"",d=await fetch(`/api/config/mcp/${encodeURIComponent(n)}${c}`,{method:"PATCH",headers:{"Content-Type":"application/json",...o?{"x-opencode-directory":o}:{}},body:JSON.stringify(i)}),p=await d.json().catch(()=>null);if(!d.ok)throw new Error(p?.error||"Failed to update MCP server");return rc(o),p?.requiresReload?(a=!0,await Hl({message:p.message,delayMs:p.reloadDelayMs??sc,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||Gl()}},deleteMcp:async n=>{Kl("Deleting MCP server configuration…");let r=!1;try{const a=So(),i=a?`?directory=${encodeURIComponent(a)}`:"",o=await fetch(`/api/config/mcp/${encodeURIComponent(n)}${i}`,{method:"DELETE",headers:a?{"x-opencode-directory":a}:void 0}),c=await o.json().catch(()=>null);if(!o.ok)throw new Error(c?.error||"Failed to delete MCP server");return rc(a),c?.requiresReload&&(r=!0,await Hl({message:c.message,delayMs:c.reloadDelayMs??sc,scopes:["all"]})),e().selectedMcpName===n&&t({selectedMcpName:null}),await e().loadMcpConfigs({force:!0}),{ok:!0,reloadFailed:c?.reloadFailed===!0,message:c?.message,warning:c?.warning}}catch(a){return console.error("[McpConfigStore] Failed to delete MCP:",a),{ok:!1}}finally{r||Gl()}},getMcpByName:n=>e().mcpServers.find(r=>r.name===n)}),{name:"mcp-config-store",storage:Cl(()=>vr()),partialize:t=>({selectedMcpName:t.selectedMcpName})}),{name:"mcp-config-store"}));function Yu(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=Ju(t.environment)??{}),t.headers!==void 0&&(e.headers=Ju(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:ko(t.oauthClientId),clientSecret:ko(t.oauthClientSecret),scope:ko(t.oauthScope),redirectUri:ko(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 Yv={},Qv={},Gr=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},Ha=t=>Gr(t)??"__global__",ha=t=>{const e=Gr(t);return e?sn.getScopedApiClient(e):sn.getApiClient()},bn=Zn()(bi((t,e)=>({byDirectory:{},diagnosticsByDirectory:{},loadingKeys:{},lastErrorKeys:{},getStatusForDirectory:n=>{const r=Ha(n??zs.getState().currentDirectory);return e().byDirectory[r]??Yv},getDiagnosticForDirectory:n=>{const r=Ha(n??zs.getState().currentDirectory);return e().diagnosticsByDirectory[r]??Qv},getErrorForDirectory:n=>{const r=Ha(n??zs.getState().currentDirectory);return e().lastErrorKeys[r]??null},refresh:async n=>{const r=Gr(n?.directory??zs.getState().currentDirectory),a=Ha(r);n?.silent||t(i=>({loadingKeys:{...i.loadingKeys,[a]:!0},lastErrorKeys:{...i.lastErrorKeys,[a]:null}}));try{const c=(await ha(r).mcp.status()).data??{};t(d=>({byDirectory:{...d.byDirectory,[a]:c},diagnosticsByDirectory:{...d.diagnosticsByDirectory,[a]:Object.fromEntries(Object.entries(d.diagnosticsByDirectory[a]??{}).filter(([p])=>!c[p]))},loadingKeys:{...d.loadingKeys,[a]:!1},lastErrorKeys:{...d.lastErrorKeys,[a]:null}}))}catch(i){const o=i instanceof Error?i.message:"Failed to load MCP status";t(c=>({loadingKeys:{...c.loadingKeys,[a]:!1},lastErrorKeys:{...c.lastErrorKeys,[a]:o}}))}},connect:async(n,r)=>{const a=Gr(r??zs.getState().currentDirectory),i=Ha(a),o=ha(a);try{await o.mcp.connect({name:n},{throwOnError:!0})}catch(c){const d=c instanceof Error?c.message:"Connection failed";throw t(p=>({diagnosticsByDirectory:{...p.diagnosticsByDirectory,[i]:{...p.diagnosticsByDirectory[i]??{},[n]:{status:"failed",error:d}}}})),c}await e().refresh({directory:a,silent:!0})},disconnect:async(n,r)=>{const a=Gr(r??zs.getState().currentDirectory);await ha(a).mcp.disconnect({name:n},{throwOnError:!0}),await e().refresh({directory:a,silent:!0})},startAuth:async(n,r)=>{const a=Gr(r??zs.getState().currentDirectory),c=(await ha(a).mcp.auth.start({name:n},{throwOnError:!0})).data?.authorizationUrl;if(!c)throw new Error("Authorization URL was not returned");return c},completeAuth:async(n,r,a)=>{const i=Gr(a??zs.getState().currentDirectory);await ha(i).mcp.auth.callback({name:n,code:r},{throwOnError:!0}),await e().refresh({directory:i,silent:!0})},clearAuth:async(n,r)=>{const a=Gr(r??zs.getState().currentDirectory);await ha(a).mcp.auth.remove({name:n},{throwOnError:!0}),await e().refresh({directory:a,silent:!0})},testConnection:async(n,r)=>{const a=Gr(r??zs.getState().currentDirectory),i=Ha(a),o=ha(a),d=e().getStatusForDirectory(a)[n]?.status==="connected";let p,m;try{await o.mcp.connect({name:n},{throwOnError:!0})}catch(b){p=b instanceof Error?b.message:"Connection failed",t(h=>({diagnosticsByDirectory:{...h.diagnosticsByDirectory,[i]:{...h.diagnosticsByDirectory[i]??{},[n]:{status:"failed",error:p??"Connection failed"}}}}))}await e().refresh({directory:a,silent:!0});const u=e().getStatusForDirectory(a)[n],f=u;if(!d&&u?.status==="connected"){try{await o.mcp.disconnect({name:n},{throwOnError:!0})}catch(b){m=`Connection test succeeded, but cleanup disconnect failed: ${b instanceof Error?b.message:"Disconnect failed"}`}await e().refresh({directory:a,silent:!0})}return{status:f??e().getStatusForDirectory(a)[n],error:p,warning:m}}}))),Xv=(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}},Zv=t=>{switch(t?.status){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"default"}},Ch=({active:t,className:e})=>{const{t:n}=dt(),a=zs(g=>g.currentDirectory)??null,i=bn(g=>g.getStatusForDirectory(a)),o=bn(g=>g.refresh),c=bn(g=>g.connect),d=bn(g=>g.disconnect),p=ro(g=>g.mcpServers),m=ro(g=>g.loadMcpConfigs),[u,f]=l.useState(!1),[b,h]=l.useState(null);l.useEffect(()=>{o({directory:a,silent:!0})},[o,a]),l.useEffect(()=>{m({force:!0})},[m]),l.useEffect(()=>{t&&Promise.all([o({directory:a,silent:!0}),m({force:!0})])},[t,o,a,m]);const v=l.useMemo(()=>{const g=new Set(Object.keys(i));for(const w of p)w?.name&&g.add(w.name);return Array.from(g).sort((w,y)=>w.localeCompare(y))},[p,i]),x=l.useCallback(g=>{if(g?.preventDefault(),u)return;f(!0);const w=new Promise(y=>setTimeout(y,500));Promise.all([o({directory:a}),w]).finally(()=>{f(!1)})},[u,o,a]);return s.jsxs("div",{className:xe("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:xe("h-4 w-4",u&&"animate-spin")})})]})}),s.jsxs("div",{className:"max-h-64 overflow-y-auto py-2",children:[v.map(g=>{const w=i[g],y=Zv(w),C=w?.status==="connected",k=b===g,j=Xv(w,n);return s.jsxs("div",{className:"flex items-center justify-between gap-2 px-4 py-1.5 rounded-lg hover:bg-interactive-hover/50",children:[s.jsx("div",{className:"min-w-0 flex-1",children:s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("span",{className:xe("h-2 w-2 rounded-full flex-shrink-0",y==="success"&&"bg-status-success",y==="error"&&"bg-status-error",y==="warning"&&"bg-status-warning",y==="default"&&"bg-muted-foreground/40"),"aria-label":j})}),s.jsx(At,{side:"left",children:s.jsx("p",{children:j})})]}),s.jsx("span",{className:"typography-ui-label truncate",children:g})]})}),s.jsx(ml,{checked:C,disabled:k,className:"data-[checked]:bg-status-info",onCheckedChange:async S=>{h(g);try{S?await c(g,a):await d(g,a)}finally{h(null)}}})]},g)}),v.length===0&&s.jsx("div",{className:"px-4 py-5 typography-ui-label text-muted-foreground text-center",children:n("mcpDropdown.empty.configureInConfig")})]})]})},ao=t=>{const e=st.c(20),{percent:n,tonePercent:r,className:a,expectedMarkerPercent:i}=t;let o;e[0]!==n?(o=Ov(n)??0,e[0]=n,e[1]=o):o=e[1];const c=o,d=r??n;let p;e[2]!==d?(p=yh(d),e[2]=d,e[3]=p):p=e[3];const m=p,u=i!=null?Math.max(0,Math.min(100,i)):null;let f;e[4]!==m?(f=m==="critical"?{backgroundColor:"var(--status-error)"}:m==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"},e[4]=m,e[5]=f):f=e[5];const b=f;let h;e[6]!==a?(h=xe("relative h-2.5 rounded-full bg-[var(--interactive-border)] overflow-hidden",a),e[6]=a,e[7]=h):h=e[7];const v=`${c}%`;let x;e[8]!==b||e[9]!==v?(x={...b,width:v},e[8]=b,e[9]=v,e[10]=x):x=e[10];let g;e[11]!==c||e[12]!==x?(g=s.jsx("div",{className:"h-full transition-all duration-300",style:x,role:"progressbar","aria-valuenow":c,"aria-valuemin":0,"aria-valuemax":100}),e[11]=c,e[12]=x,e[13]=g):g=e[13];let w;e[14]!==u?(w=u!=null&&u>0&&u<100&&s.jsx("div",{className:"absolute top-0 h-full w-0.5 bg-foreground",style:{left:`${u}%`},title:`Expected usage if spread evenly: ${Math.round(u)}% of quota`,"aria-hidden":"true"}),e[14]=u,e[15]=w):w=e[15];let y;return e[16]!==h||e[17]!==g||e[18]!==w?(y=s.jsxs("div",{className:h,children:[g,w]}),e[16]=h,e[17]=g,e[18]=w,e[19]=y):y=e[19],y},io=t=>{const e=st.c(67),{paceInfo:n,className:r,compact:a}=t,i=a===void 0?!1:a,{t:o}=dt();let c;e[0]!==n.status?(c=_v(n.status),e[0]=n.status,e[1]=c):c=e[1];const d=c;let p;e:{switch(n.status){case"on-track":{let S;e[2]!==o?(S=o("settings.usage.pace.status.onTrack"),e[2]=o,e[3]=S):S=e[3],p=S;break e}case"slightly-fast":{let S;e[4]!==o?(S=o("settings.usage.pace.status.slightlyFast"),e[4]=o,e[5]=S):S=e[5],p=S;break e}case"too-fast":{let S;e[6]!==o?(S=o("settings.usage.pace.status.tooFast"),e[6]=o,e[7]=S):S=e[7],p=S;break e}case"exhausted":{let S;e[8]!==o?(S=o("settings.usage.pace.status.usedUp"),e[8]=o,e[9]=S):S=e[9],p=S;break e}}p=void 0}const m=p;let u;e[10]!==n.predictText||e[11]!==o?(u=o("settings.usage.pace.predictionTooltip",{prediction:n.predictText}),e[10]=n.predictText,e[11]=o,e[12]=u):u=e[12];const f=u;if(i){let S;e[13]!==r?(S=xe("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 M;e[17]!==m||e[18]!==I?(M=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]=M):M=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]!==o?(N=n.isExhausted?s.jsx(s.Fragment,{children:o("settings.usage.pace.wait",{duration:Hu(n.remainingSeconds)})}):s.jsx(s.Fragment,{children:o("settings.usage.pace.prediction",{prediction:n.predictText})}),e[22]=n.isExhausted,e[23]=n.predictText,e[24]=n.remainingSeconds,e[25]=o,e[26]=N):N=e[26];let 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 T;return e[31]!==E||e[32]!==S||e[33]!==M?(T=s.jsxs("div",{className:S,children:[M,E]}),e[31]=E,e[32]=S,e[33]=M,e[34]=T):T=e[34],T}let b;e[35]!==r?(b=xe("flex items-center justify-between gap-2",r),e[35]=r,e[36]=b):b=e[36];let h;e[37]!==n.isExhausted||e[38]!==n.paceRateText||e[39]!==o?(h=!n.isExhausted&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:o("settings.usage.pace.rate",{rate:n.paceRateText})}),e[37]=n.isExhausted,e[38]=n.paceRateText,e[39]=o,e[40]=h):h=e[40];let v;e[41]!==h?(v=s.jsx("div",{className:"flex items-center gap-1.5",children:h}),e[41]=h,e[42]=v):v=e[42];let x;e[43]!==d?(x={color:d},e[43]=d,e[44]=x):x=e[44];let g;e[45]!==n.isExhausted||e[46]!==n.predictText||e[47]!==n.remainingSeconds||e[48]!==f||e[49]!==m||e[50]!==o?(g=n.isExhausted?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"font-medium",children:m}),s.jsx("span",{className:"text-muted-foreground",children:o("settings.usage.pace.waitSeparator")}),s.jsx("span",{className:"font-medium",children:Hu(n.remainingSeconds)})]}):s.jsxs("span",{title:f,children:[s.jsx("span",{className:"text-muted-foreground",children:o("settings.usage.pace.predictionLabel")}),s.jsx("span",{className:"font-medium",children:n.predictText})]}),e[45]=n.isExhausted,e[46]=n.predictText,e[47]=n.remainingSeconds,e[48]=f,e[49]=m,e[50]=o,e[51]=g):g=e[51];let w;e[52]!==x||e[53]!==g?(w=s.jsx("span",{className:"typography-micro tabular-nums",style:x,children:g}),e[52]=x,e[53]=g,e[54]=w):w=e[54];let y;e[55]!==d?(y={backgroundColor:d},e[55]=d,e[56]=y):y=e[56];let 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]!==w||e[61]!==C?(k=s.jsxs("div",{className:"flex items-center gap-1.5",children:[w,C]}),e[60]=w,e[61]=C,e[62]=k):k=e[62];let j;return e[63]!==k||e[64]!==b||e[65]!==v?(j=s.jsxs("div",{className:b,children:[v,k]}),e[63]=k,e[64]=b,e[65]=v,e[66]=j):j=e[66],j},fr=ex,kr=t=>{const e=st.c(14);let n,r,a,i;e[0]!==t?({className:a,asChild:n,children:r,...i}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=a,e[4]=i):(n=e[1],r=e[2],a=e[3],i=e[4]);let o;e[5]!==n||e[6]!==r?(o=n&&Oe.isValidElement(r)?{render:r}:{children:r},e[5]=n,e[6]=r,e[7]=o):o=e[7];const c=o;let d;e[8]!==a?(d=xe("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(tx,{className:d,...i,...c}),e[10]=i,e[11]=c,e[12]=d,e[13]=p):p=e[13],p},hr=t=>{const e=st.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=xe("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(sx,{className:a,...r}),e[5]=r,e[6]=a,e[7]=i):i=e[7],i},la=[{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"}],Yc="finder",Qc=new Set(["finder","terminal"]),Xc=t=>t?la.find(e=>e.id===t)??null:null,ac=()=>la.filter(t=>Qc.has(t.id)).map(t=>({...t})),e1=()=>{if(typeof window>"u")return Yc;const t=window.localStorage.getItem("openInAppId");return t&&Xc(t)?t:Yc};let ic=!1,Ga=!1,na=!1,ra=0,Ki=null;const Qu=()=>{Ki&&(clearTimeout(Ki),Ki=null)},Fr=Zn()((t,e)=>({selectedAppId:e1(),availableApps:ac(),hasLoadedApps:!1,isCacheStale:!1,isScanning:!1,initialize:()=>{if(ic||typeof window>"u")return;ic=!0;const n=(d,p=!0)=>{if(!Array.isArray(d)||d.length===0){t({availableApps:ac(),hasLoadedApps:p});return}const m=new Set(d.map(h=>h.name)),u=new Map(d.map(h=>[h.name,h.iconDataUrl??void 0])),b=la.filter(h=>m.has(h.appName)||Qc.has(h.id)).map(h=>({...h,iconDataUrl:u.get(h.appName)}));t({availableApps:b,hasLoadedApps:!0})},r=async d=>{if(!Ea()||!Qr()||Ga||e().hasLoadedApps&&!d)return;const m=la.map(u=>u.appName);Qu(),Ga=!0,na=!1,t({isScanning:!0});try{const{apps:u,success:f,hasCache:b,isCacheStale:h}=await hu(m,d),v=f&&!b&&u.length===0&&ra<3;if(t({isCacheStale:b?h:!1}),n(u,f?!v:!1),f){if(v){const g=[800,1600,3200][ra]??3200;ra+=1,na=!0,Ki=setTimeout(()=>{r()},g);return}ra=0,na=!1;return}if(ra<3){const g=[1e3,3e3,7e3][ra]??7e3;ra+=1,na=!0,Ki=setTimeout(()=>{r()},g)}}finally{Ga=!1,na||t({isScanning:!1})}};r();const a=d=>{const p=d.detail,m=p&&typeof p.openInAppId=="string"&&p.openInAppId.length>0&&Xc(p.openInAppId)?p.openInAppId:null;m&&(window.localStorage.setItem("openInAppId",m),t({selectedAppId:m}))},i=()=>{r()},o=d=>{const p=d.detail;Array.isArray(p)&&(ra=3,na=!1,t({isScanning:!1,isCacheStale:!1}),n(p))};window.addEventListener("openchamber:settings-synced",a),window.addEventListener("openchamber:app-ready",i),window.addEventListener("openchamber:installed-apps-updated",o),window.__openchamberAppReady&&r(),window.setTimeout(()=>{e().hasLoadedApps||r()},5e3)},loadInstalledApps:async n=>{if(ic||e().initialize(),!Ea()||!Qr()||Ga||e().hasLoadedApps&&!n)return;const a=la.map(i=>i.appName);Qu(),n&&t({hasLoadedApps:!1}),Ga=!0,na=!1,t({isScanning:!0});try{const{apps:i,hasCache:o,isCacheStale:c}=await hu(a,n),d=new Set(i.map(f=>f.name)),p=new Map(i.map(f=>[f.name,f.iconDataUrl??void 0])),u=la.filter(f=>d.has(f.appName)||Qc.has(f.id)).map(f=>({...f,iconDataUrl:p.get(f.appName)}));t({availableApps:u.length>0?u:ac(),hasLoadedApps:u.length>0,isCacheStale:o?c:!1})}finally{Ga=!1,na||t({isScanning:!1})}},selectApp:async n=>{Xc(n)&&(t({selectedAppId:n}),typeof window<"u"&&window.localStorage.setItem("openInAppId",n),await Is({openInAppId:n}))}})),t1="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",s1="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",oc=t=>({...t,fallbackIconDataUrl:t.id==="finder"?t1:t.id==="terminal"?s1:void 0}),Xu=t=>{const e=st.c(8),{label:n,iconDataUrl:r,fallbackIconDataUrl:a}=t,[i,o]=l.useState(!1);let c;e[0]!==n?(c=n.trim().slice(0,1).toUpperCase()||"?",e[0]=n,e[1]=c):c=e[1];const d=c,p=r||a;if(p&&!i){let f;e[2]===Symbol.for("react.memo_cache_sentinel")?(f=()=>o(!0),e[2]=f):f=e[2];let b;return e[3]!==p?(b=s.jsx("img",{src:p,alt:"",className:"h-4 w-4 rounded-sm",onError:f}),e[3]=p,e[4]=b):b=e[4],b}let m;e[5]===Symbol.for("react.memo_cache_sentinel")?(m=xe("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},n1=t=>{const e=st.c(75),{directory:n,className:r}=t,{t:a}=dt(),i=Fr(r1),o=Fr(a1),c=Fr(i1),d=Fr(o1),p=Fr(l1),m=Fr(c1),u=Fr(d1);let f,b;e[0]!==p?(f=()=>{p()},b=[p],e[0]=p,e[1]=f,e[2]=b):(f=e[1],b=e[2]),l.useEffect(f,b);const h=Ea()&&Qr();let v;e:{let W;e[3]!==o||e[4]!==i?(W=o.find(ne=>ne.id===i)??o.find(u1)??o[0]??la[0],e[3]=o,e[4]=i,e[5]=W):W=e[5];const q=W;if(q){let ne;e[6]!==q?(ne=oc(q),e[6]=q,e[7]=ne):ne=e[7],v=ne;break e}let J;e[8]===Symbol.for("react.memo_cache_sentinel")?(J=oc(la[0]),e[8]=J):J=e[8],v=J}const x=v;if(!h||!n||o.length===0)return null;let g;e[9]!==n?(g=async W=>{await _x(n,W.id,W.appName)||await il(n,W.appName)},e[9]=n,e[10]=g):g=e[10];const w=g;let y;e[11]!==w||e[12]!==u?(y=async W=>{await u(W.id),await w(W)},e[11]=w,e[12]=u,e[13]=y):y=e[13];const C=y;let k;e[14]!==n||e[15]!==a?(k=async()=>{(await In(n)).ok&&H.success(a("openInApp.toast.pathCopied"))},e[14]=n,e[15]=a,e[16]=k):k=e[16];const j=k;let S;e[17]!==r?(S=xe("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]!==w||e[20]!==x?(I=()=>{w(x)},e[19]=w,e[20]=x,e[21]=I):I=e[21];const M=d&&"animate-pulse";let P;e[22]!==M?(P=xe("inline-flex h-full items-center px-2.5 typography-ui-label font-medium","text-foreground hover:bg-interactive-hover transition-colors",M),e[22]=M,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(Xu,{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 T;e[36]===Symbol.for("react.memo_cache_sentinel")?(T=xe("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]=T):T=e[36];let R;e[37]!==a?(R=a("openInApp.actions.chooseAppAria"),e[37]=a,e[38]=R):R=e[38];let V;e[39]===Symbol.for("react.memo_cache_sentinel")?(V=s.jsx(D,{name:"arrow-down-s",className:"h-4 w-4"}),e[39]=V):V=e[39];let _;e[40]!==R?(_=s.jsx(As,{asChild:!0,children:s.jsx("button",{type:"button",className:T,"aria-label":R,children:V})}),e[40]=R,e[41]=_):_=e[41];let U;e[42]!==j?(U=()=>{j()},e[42]=j,e[43]=U):U=e[43];let B;e[44]===Symbol.for("react.memo_cache_sentinel")?(B=s.jsx(D,{name:"file-copy",className:"h-4 w-4"}),e[44]=B):B=e[44];let z;e[45]!==a?(z=a("openInApp.actions.copyPath"),e[45]=a,e[46]=z):z=e[46];let K;e[47]!==z?(K=s.jsx("span",{className:"typography-ui-label text-foreground",children:z}),e[47]=z,e[48]=K):K=e[48];let F;e[49]!==U||e[50]!==K?(F=s.jsxs($t,{className:"flex items-center gap-2",onClick:U,children:[B,K]}),e[49]=U,e[50]=K,e[51]=F):F=e[51];let G;e[52]===Symbol.for("react.memo_cache_sentinel")?(G=s.jsx(Gn,{}),e[52]=G):G=e[52];let Q;if(e[53]!==o||e[54]!==C||e[55]!==x.id){let W;e[57]!==C||e[58]!==x.id?(W=q=>{const J=oc(q);return s.jsxs($t,{className:"flex items-center gap-2",onClick:()=>{C(q)},children:[s.jsx(Xu,{label:q.label,iconDataUrl:q.iconDataUrl,fallbackIconDataUrl:J.fallbackIconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:q.label}),x.id===q.id?s.jsx(D,{name:"check",className:"ml-auto h-4 w-4 text-primary"}):null]},q.id)},e[57]=C,e[58]=x.id,e[59]=W):W=e[59],Q=o.map(W),e[53]=o,e[54]=C,e[55]=x.id,e[56]=Q}else Q=e[56];let te;e[60]!==c||e[61]!==m||e[62]!==a?(te=c?s.jsxs($t,{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]=te):te=e[63];let Z;e[64]!==F||e[65]!==Q||e[66]!==te?(Z=s.jsxs(Ds,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[F,G,Q,te]}),e[64]=F,e[65]=Q,e[66]=te,e[67]=Z):Z=e[67];let fe;e[68]!==_||e[69]!==Z?(fe=s.jsxs(Ts,{children:[_,Z]}),e[68]=_,e[69]=Z,e[70]=fe):fe=e[70];let ue;return e[71]!==E||e[72]!==fe||e[73]!==S?(ue=s.jsxs("div",{className:S,children:[E,fe]}),e[71]=E,e[72]=fe,e[73]=S,e[74]=ue):ue=e[74],ue};function r1(t){return t.selectedAppId}function a1(t){return t.availableApps}function i1(t){return t.isCacheStale}function o1(t){return t.isScanning}function l1(t){return t.initialize}function c1(t){return t.loadInstalledApps}function d1(t){return t.selectApp}function u1(t){return t.id===Yc}const m1=1e6,p1="terminal-store";let Zu=!1;const lc=t=>typeof t=="object"&&t!==null,f1=t=>{const e=/^tab-(\d+)$/.exec(t);if(!e)return null;const n=Number(e[1]);return Number.isFinite(n)?n:null};function $n(t){let e=t.trim();for(;e.length>1&&e.endsWith("/");)e=e.slice(0,-1);return e}const cc=(t,e)=>({id:t,terminalSessionId:null,lifecycle:"idle",label:e,iconKey:null,bufferChunks:[],bufferLength:0,isConnecting:!1,createdAt:Date.now(),previewUrl:null,previewAutoOpened:!1,previewUrlLocked:!1}),Ih=/\x1b\[[0-9;]*m/g,h1=/(https?:\/\/(?:localhost|127\.0\.0\.1|0\.0\.0\.0|\[(?:::1|::)\])(?::\d{2,5})?(?:\/[\w\-./~%!$&'()*+,;=:@?#[\]]*)?)/i,g1=new Set([".",",",";",":","!","?"]),x1=t=>{let e=t;for(;e.length>0;){const n=e[e.length-1];if(n===")"||n==="]"||n==="}"||n===">"){const r=n===")"?"(":n==="]"?"[":n==="}"?"{":"<",a=e.slice(0,-1),i=(a.match(new RegExp(`\\${r}`,"g"))||[]).length,o=(a.match(new RegExp(`\\${n}`,"g"))||[]).length;if(i>o)break;e=a;continue}if(g1.has(n)){e=e.slice(0,-1);continue}break}return e},b1=t=>{if(!t)return null;const n=t.replace(Ih,"").match(h1);if(!n?.[1])return null;let r=x1(n[1]);return r=r.replace("0.0.0.0","127.0.0.1"),r=r.replace("[::1]","127.0.0.1"),r=r.replace("[::]","127.0.0.1"),r},y1=t=>{if(!t)return null;const n=t.replace(Ih,"").match(/Serving HTTP on .*? port (\d{2,5})/i);if(!n?.[1])return null;const r=Number.parseInt(n[1],10);return!Number.isFinite(r)||r<=0||r>65535?null:`http://127.0.0.1:${r}/`},dc=t=>({tabs:[t],activeTabId:t.id}),Er=(t,e)=>t.tabs.findIndex(n=>n.id===e),rn=Zn()(bi(oo((t,e)=>({sessions:new Map,projectActionRuns:{},nextChunkId:1,nextTabId:1,hasHydrated:typeof window>"u",ensureDirectory:n=>{const r=$n(n);r&&t(a=>{if(a.sessions.has(r))return a;const i=new Map(a.sessions),o=`tab-${a.nextTabId}`,c=cc(o,"Terminal");return i.set(r,dc(c)),{sessions:i,nextTabId:a.nextTabId+1}})},getDirectoryState:n=>{const r=$n(n);return e().sessions.get(r)},getActiveTab:n=>{const r=$n(n),a=e().sessions.get(r);if(!a)return;const i=a.activeTabId;return i?a.tabs.find(o=>o.id===i)??a.tabs[0]:a.tabs[0]},createTab:n=>{const r=$n(n);if(!r)return"tab-invalid";const a=`tab-${e().nextTabId}`;return t(i=>{const o=new Map(i.sessions),c=o.get(r),d=i.nextTabId+1,m=`Terminal ${(c?.tabs.length??0)+1}`,u=cc(a,m);return c?o.set(r,{...c,tabs:[...c.tabs,u]}):o.set(r,dc(u)),{sessions:o,nextTabId:d}}),a},setActiveTab:(n,r)=>{const a=$n(n);t(i=>{const o=new Map(i.sessions),c=o.get(a);return!c||c.activeTabId===r||Er(c,r)<0?i:(o.set(a,{...c,activeTabId:r}),{sessions:o})})},setTabLabel:(n,r,a)=>{const i=$n(n),o=a.trim();o&&t(c=>{const d=new Map(c.sessions),p=d.get(i);if(!p)return c;const m=Er(p,r);if(m<0||p.tabs[m]?.label===o)return c;const u=[...p.tabs];return u[m]={...u[m],label:o},d.set(i,{...p,tabs:u}),{sessions:d}})},setTabIconKey:(n,r,a)=>{const i=$n(n);t(o=>{const c=new Map(o.sessions),d=c.get(i);if(!d)return o;const p=Er(d,r);if(p<0)return o;const m=a?.trim()||null;if(d.tabs[p]?.iconKey===m)return o;const u=[...d.tabs];return u[p]={...u[p],iconKey:m},c.set(i,{...d,tabs:u}),{sessions:c}})},closeTab:async(n,r)=>{const a=$n(n),c=e().sessions.get(a)?.tabs.find(d=>d.id===r)?.terminalSessionId??null;if(c)try{await Ox(c)}catch{}t(d=>{const p=new Map(d.sessions),m=p.get(a);if(!m)return d;const u=Er(m,r);if(u<0)return d;const f=m.tabs.filter(x=>x.id!==r),b=Object.fromEntries(Object.entries(d.projectActionRuns).filter(([,x])=>!(x.directory===a&&x.tabId===r))),h=Object.keys(b).length!==Object.keys(d.projectActionRuns).length;if(f.length===0){const x=`tab-${d.nextTabId}`,g=cc(x,"Terminal");return p.set(a,dc(g)),{sessions:p,nextTabId:d.nextTabId+1,...h?{projectActionRuns:b}:{}}}let v=m.activeTabId;return m.activeTabId===r&&(v=f[Math.min(u,f.length-1)]?.id??f[0]?.id??null),p.set(a,{...m,tabs:f,activeTabId:v}),{sessions:p,...h?{projectActionRuns:b}:{}}})},setTabSessionId:(n,r,a)=>{const i=$n(n);t(o=>{const c=new Map(o.sessions),d=c.get(i);if(!d)return o;const p=Er(d,r);if(p<0)return o;const m=d.tabs[p],u=a!==null&&m.terminalSessionId!==a,f=a?"running":m.terminalSessionId?"exited":m.lifecycle,b={...m,terminalSessionId:a,lifecycle:f,isConnecting:!1,...u?{bufferChunks:[],bufferLength:0}:{}},h=[...d.tabs];return h[p]=b,c.set(i,{...d,tabs:h}),{sessions:c}})},setTabLifecycle:(n,r,a)=>{const i=$n(n);t(o=>{const c=new Map(o.sessions),d=c.get(i);if(!d)return o;const p=Er(d,r);if(p<0)return o;const m=[...d.tabs];return m[p]={...m[p],lifecycle:a,isConnecting:!1},c.set(i,{...d,tabs:m}),{sessions:c}})},setConnecting:(n,r,a)=>{const i=$n(n);t(o=>{const c=new Map(o.sessions),d=c.get(i);if(!d)return o;const p=Er(d,r);if(p<0)return o;const m=[...d.tabs];return m[p]={...m[p],isConnecting:a},c.set(i,{...d,tabs:m}),{sessions:c}})},appendToBuffer:(n,r,a)=>{if(!a)return;const i=$n(n);t(o=>{const c=new Map(o.sessions),d=c.get(i);if(!d)return o;const p=Er(d,r);if(p<0)return o;const m=d.tabs[p],u=o.nextChunkId,f={id:u,data:a},b=[...m.bufferChunks,f];let h=m.bufferLength+a.length;for(;h>m1&&b.length>1;){const w=b.shift();if(!w)break;h-=w.data.length}const v=m.previewUrlLocked?null:b1(a)??y1(a),x=!!(v&&v!==m.previewUrl),g=[...d.tabs];return g[p]={...m,bufferChunks:b,bufferLength:h,...x?{previewUrl:v,previewAutoOpened:!1}:null},c.set(i,{...d,tabs:g}),{sessions:c,nextChunkId:u+1}})},setTabPreviewUrl:(n,r,a,i={})=>{const o=$n(n);t(c=>{const d=new Map(c.sessions),p=d.get(o);if(!p)return c;const m=Er(p,r);if(m<0)return c;const u=p.tabs[m],f=i.autoOpened??u.previewAutoOpened,b=i.locked??u.previewUrlLocked;if(u.previewUrl===a&&u.previewAutoOpened===f&&u.previewUrlLocked===b)return c;const h=[...p.tabs];return h[m]={...u,previewUrl:a,previewAutoOpened:f,previewUrlLocked:b},d.set(o,{...p,tabs:h}),{sessions:d}})},markPreviewAutoOpened:(n,r)=>{const a=$n(n);t(i=>{const o=new Map(i.sessions),c=o.get(a);if(!c)return i;const d=Er(c,r);if(d<0)return i;const p=c.tabs[d];if(!p.previewUrl||p.previewAutoOpened)return i;const m=[...c.tabs];return m[d]={...p,previewAutoOpened:!0},o.set(a,{...c,tabs:m}),{sessions:o}})},setProjectActionRun:n=>{t(r=>{const a=r.projectActionRuns[n.key];return a&&a.directory===n.directory&&a.actionId===n.actionId&&a.tabId===n.tabId&&a.sessionId===n.sessionId&&a.status===n.status?r:{projectActionRuns:{...r.projectActionRuns,[n.key]:n}}})},updateProjectActionRunStatus:(n,r)=>{t(a=>{const i=a.projectActionRuns[n];return!i||i.status===r?a:{projectActionRuns:{...a.projectActionRuns,[n]:{...i,status:r}}}})},removeProjectActionRun:n=>{t(r=>{if(!r.projectActionRuns[n])return r;const a={...r.projectActionRuns};return delete a[n],{projectActionRuns:a}})},clearBuffer:(n,r)=>{const a=$n(n);t(i=>{const o=new Map(i.sessions),c=o.get(a);if(!c)return i;const d=Er(c,r);if(d<0)return i;const p=[...c.tabs];return p[d]={...p[d],bufferChunks:[],bufferLength:0},o.set(a,{...c,tabs:p}),{sessions:o}})},removeDirectory:n=>{const r=$n(n);t(a=>{const i=new Map(a.sessions);i.delete(r);const o=Object.fromEntries(Object.entries(a.projectActionRuns).filter(([,c])=>c.directory!==r));return{sessions:i,projectActionRuns:o}})},clearAll:()=>{t({sessions:new Map,projectActionRuns:{},nextChunkId:1,nextTabId:1})}}),{name:p1,storage:Cl(()=>zf()),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(!lc(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"||!lc(p))continue;const m=Array.isArray(p.tabs)?p.tabs:[],u=[];for(const h of m){if(!lc(h))continue;const v=typeof h.id=="string"?h.id:null;if(!v)continue;const x=f1(v);x!==null&&(a=Math.max(a,x));const g=typeof h.terminalSessionId=="string"||h.terminalSessionId===null?h.terminalSessionId:null,w=h.lifecycle,y=w==="idle"||w==="running"||w==="exited"?w:g?"running":"idle";u.push({id:v,label:typeof h.label=="string"?h.label:"Terminal",iconKey:typeof h.iconKey=="string"?h.iconKey:null,terminalSessionId:g,lifecycle:y,createdAt:typeof h.createdAt=="number"?h.createdAt:Date.now(),bufferChunks:[],bufferLength:0,isConnecting:!1,previewUrl:null,previewAutoOpened:!1,previewUrlLocked:!1})}if(u.length===0)continue;const f=typeof p.activeTabId=="string"?p.activeTabId:null,b=f?u.some(h=>h.id===f):!1;r.set(d,{tabs:u,activeTabId:b?f:u[0].id})}const i=typeof t.nextTabId=="number"&&Number.isFinite(t.nextTabId)?t.nextTabId:1,o=Math.max(e.nextTabId,i,a+1);return{...e,sessions:r,nextChunkId:1,nextTabId:o,hasHydrated:!0}}})));if(typeof window<"u"&&!Zu){Zu=!0;const t=rn.persist,e=()=>{rn.getState().hasHydrated||rn.setState({hasHydrated:!0})};t?.hasHydrated?.()?e():t?.onFinishHydration?t.onFinishHydration(e):e()}const em=(t,e)=>e.updatedAtMs-t.updatedAtMs,qs=Zn((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([Ux(),xu()]),a={};for(const i of r.sort(em))a[i.id]=i;e().listenerReady||await Wx(i=>{t(o=>({statusesById:{...o.statusesById,[i.id]:i}}))}),t({instances:n.instances,statusesById:a,isLoading:!1,initialized:!0,listenerReady:!0})}catch(n){t({isLoading:!1,error:n instanceof Error?n.message:String(n)})}}},loadImports:async()=>{if(!e().isImportsLoading){t({isImportsLoading:!0,error:null});try{const n=await Vx();t({importCandidates:n,isImportsLoading:!1})}catch(n){t({isImportsLoading:!1,error:n instanceof Error?n.message:String(n)})}}},refreshStatuses:async()=>{try{const n=await xu(),r={};for(const a of n.sort(em))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=Kx(n,r);a&&a.trim()&&(i.nickname=a.trim()),await e().upsertInstance(i)},removeInstance:async n=>{await gu(n).catch(()=>{});const r=e().instances.filter(a=>a.id!==n);await e().setInstances(r),t(a=>{const i={...a.statusesById};return delete i[n],{statusesById:i}})},connect:async n=>{t({error:null});try{await Bx(n),await e().refreshStatuses()}catch(r){throw t({error:r instanceof Error?r.message:String(r)}),r}},disconnect:async n=>{t({error:null});try{await gu(n),await e().refreshStatuses()}catch(r){throw t({error:r instanceof Error?r.message:String(r)}),r}},retry:async n=>{await e().connect(n)},getStatus:n=>e().statusesById[n]||null,clearError:()=>t({error:null})})),Ph=[{key:"play",label:"Play",Icon:"play"},{key:"build",label:"Build",Icon:"hammer"},{key:"lint",label:"Lint",Icon:"checkbox-circle"},{key:"terminal",label:"Terminal",Icon:"terminal-box"},{key:"tools",label:"Tools",Icon:"tools"},{key:"bug",label:"Bug",Icon:"bug"},{key:"flask",label:"Flask",Icon:"flask"},{key:"rocket",label:"Rocket",Icon:"rocket"},{key:"code",label:"Code",Icon:"code"},{key:"server",label:"Server",Icon:"server"},{key:"branch",label:"Branch",Icon:"git-branch"},{key:"search",label:"Search",Icon:"search"},{key:"settings",label:"Settings",Icon:"settings-3"},{key:"brain",label:"Brain",Icon:"brain-ai-3"},{key:"stack",label:"Stack",Icon:"stack"},{key:"robot",label:"Robot",Icon:"robot-2"},{key:"command",label:"Command",Icon:"command"},{key:"file",label:"File",Icon:"file-text"}],Go=Object.fromEntries(Ph.map(t=>[t.key,t.Icon])),Zc="openchamber:project-actions-updated",Ah=t=>{const e=(t||"").trim().replace(/\\/g,"/");return e?e==="/"?"/":e.length>1?e.replace(/\/+$/,""):e:""},aa=(t,e)=>`${Ah(t)}::${e}`,v1=t=>{const e=t.trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},tm=t=>{if(typeof t!="number"||!Number.isFinite(t))return null;const e=Math.round(t);return e<1||e>65535?null:e},w1=(t,e)=>{if(!e.enabled||e.type!=="local")return null;const n=tm(e.localPort),r=tm(e.remotePort);if(!n||!r)return null;const a=v1(e.localHost||t.localForward.bindHost||"127.0.0.1"),i=(e.remoteHost||"127.0.0.1").trim(),o=(t.nickname||t.id||"instance").trim();return{id:`${t.id}::${e.id}`,label:`${o} - ${a}:${n} -> ${i}:${r}`,url:`http://${a}:${n}`}},Dh=t=>{const e=[];for(const n of t)if(!(!n?.id||!Array.isArray(n.portForwards)))for(const r of n.portForwards){const a=w1(n,r);a&&e.push(a)}return e},j1=(t,e)=>{const n=(t||"").trim();return n&&Dh(e).find(i=>i.id===n)?.url||null},N1=[{pattern:/^dev(:.*)?$/i},{pattern:/^start(:.*)?$/i},{pattern:/^preview(:.*)?$/i},{pattern:/^serve(:.*)?$/i},{pattern:/^develop(:.*)?$/i}],S1=["dev","start","preview","serve"];async function k1(t,e,n){if(!t)return null;const r=P1(e);if(r)return{command:r.command,label:r.name||"Start Preview",actionId:r.id};if(n){const a=A1(n);if(a){const i=await D1(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 C1(t)){const a=await I1(),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 C1(t){const e=`${t}/index.html`,n=await pl(e);return typeof n=="string"&&n.trim().length>0}async function I1(){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 P1(t){for(const e of t){const n=`${e.name} ${e.command}`.toLowerCase();if(S1.some(a=>n.includes(a)))return e}return null}function A1(t){for(const{pattern:e}of N1)for(const n of Object.keys(t))if(e.test(n))return n;return null}async function D1(t){const e=await pl(`${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 pl(`${t}/${r}`);if(typeof i=="string"&&i.trim().length>0)return a}return"npm"}async function pl(t){const e=Xn()?.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 T1(t){try{const e=await pl(`${t}/package.json`);return e==null?null:JSON.parse(e).scripts||null}catch{return null}}const M1=t=>new Promise(e=>{window.setTimeout(e,t)}),E1="\x1B",R1=new RegExp(`${E1}\\[[0-9;?]*[ -/]*[@-~]`,"g"),F1=/https?:\/\/[^\s<>'"`]+/gi,or="__openchamber_auto_discover_preview__",O1=15e3,L1=t=>{let e="";for(let n=0;n<t.length;n+=1){const r=t.charCodeAt(n);r>=0&&r<=8||r===11||r===12||r>=14&&r<=31||r===127||(e+=t[n])}return e},$1=t=>{const e=(t||"").trim();if(!e)return null;const n=/^https?:\/\//i.test(e)?e:`http://${e}`;try{const r=new URL(n);return r.protocol!=="http:"&&r.protocol!=="https:"?null:r.toString()}catch{return null}},_1=t=>{const n=t.replace(R1,"").match(F1);if(!n||n.length===0)return null;const r=n.map(i=>i.replace(/[),.;]+$/,"")).filter(Boolean);if(r.length===0)return null;const a=[];for(const i of r)try{const o=new URL(i);o.port&&o.port.length>0&&a.push({raw:i,parsed:o})}catch{}if(a.length>0){const i=o=>{const{parsed:c}=o,d=c.hostname.toLowerCase(),p=d==="localhost"||d==="127.0.0.1"||d==="0.0.0.0"||d==="::1",m=c.pathname||"/",u=m.split("/").filter(Boolean).length,f=m==="/"||m==="",b=!!(c.search||c.hash);let h=0;return p&&(h+=50),f&&(h+=30),h-=Math.min(u*5,20),b&&(h-=10),h};return a.sort((o,c)=>i(c)-i(o)),a[0]?.parsed.origin??a[0]?.raw??null}return r[0]??null},sm=({projectRef:t,directory:e,className:n,compact:r=!1,allowMobile:a=!1})=>{const{t:i}=dt(),{terminal:o,runtime:c}=Rn(),{isMobile:d}=nn(),p=l.useMemo(()=>vn(),[]),m=qs(ce=>ce.instances),u=qs(ce=>ce.load),f=Re(ce=>ce.setBottomTerminalOpen),b=Re(ce=>ce.setActiveMainTab),h=Re(ce=>ce.setSettingsPage),v=Re(ce=>ce.setSettingsDialogOpen),x=Re(ce=>ce.setSettingsProjectsSelectedId),g=Re(ce=>ce.openContextPreview),w=rn(ce=>ce.sessions),y=rn(ce=>ce.ensureDirectory),C=rn(ce=>ce.setTabLabel),k=rn(ce=>ce.setTabIconKey),j=rn(ce=>ce.setActiveTab),S=rn(ce=>ce.setConnecting),I=rn(ce=>ce.setTabSessionId),M=rn(ce=>ce.setTabPreviewUrl),P=rn(ce=>ce.projectActionRuns),A=rn(ce=>ce.setProjectActionRun),N=rn(ce=>ce.updateProjectActionRunStatus),E=rn(ce=>ce.removeProjectActionRun),[T,R]=l.useState([]),[V,_]=l.useState(null),[U,B]=l.useState(!1),z=l.useRef({}),K=l.useRef({}),F=l.useRef({}),G=l.useRef({}),Q=l.useRef(0),te=t?.id??null,Z=t?.path??"",fe=l.useMemo(()=>te?{id:te,path:Z}:null,[te,Z]);l.useEffect(()=>{p&&u().catch(()=>{})},[p,u]);const ue=l.useCallback(async ce=>{await qn(ce)},[]),W=l.useCallback(async()=>{if(!fe)return;const ce=Q.current+1;Q.current=ce,B(!0);try{const Ce=await Kc(fe);if(Q.current!==ce)return;const Te=Ce.actions;R(Te),_($e=>$e===or||$e&&Te.some(De=>De.id===$e)?$e:null)}catch{if(Q.current!==ce)return}finally{Q.current===ce&&B(!1)}},[fe]),q=l.useMemo(()=>Ah(e||fe?.path||""),[e,fe?.path]),J=l.useMemo(()=>V?T.find(ce=>ce.id===V)??null:null,[T,V]),ne=l.useMemo(()=>({id:or,name:i("projectActions.actions.autoDiscover"),command:"",icon:"search",autoOpenUrl:!0}),[i]),ee=!d,he=l.useMemo(()=>ee?[ne,...T]:T,[T,ne,ee]);l.useEffect(()=>{W()},[W]),l.useEffect(()=>{if(typeof window>"u")return;const ce=Ce=>{const Te=Ce.detail;te&&(Te?.projectId&&Te.projectId!==te||W())};return window.addEventListener(Zc,ce),()=>{window.removeEventListener(Zc,ce)}},[W,te]),l.useEffect(()=>{V&&(V===or&&ee||T.some(ce=>ce.id===V)||_(null))},[T,ee,V]),l.useEffect(()=>{for(const[ce,Ce]of Object.entries(P)){const $e=w.get(Ce.directory)?.tabs.find(De=>De.id===Ce.tabId);(!$e||$e.terminalSessionId!==Ce.sessionId)&&E(ce)}},[P,E,w]),l.useEffect(()=>{for(const[ce,Ce]of Object.entries(P)){const Te=K.current[ce]??{lastSeenChunkId:null,openedUrl:!1,tail:"",openInPreview:!1};K.current[ce]=Te;const $e=he.find(_e=>_e.id===Ce.actionId);if(!$e)continue;const de=w.get(Ce.directory)?.tabs.find(_e=>_e.id===Ce.tabId);if(!de||!Array.isArray(de.bufferChunks)||de.bufferChunks.length===0)continue;const O=de.bufferChunks.filter(_e=>Te.lastSeenChunkId===null?!0:_e.id>Te.lastSeenChunkId);if(O.length===0)continue;const L=O.map(_e=>_e.data).join(""),$=`${Te.tail}${L}`,je=!Te.openedUrl&&$e.autoOpenUrl===!0?_1($):null,ae=O[O.length-1]?.id??Te.lastSeenChunkId;if(Te.lastSeenChunkId=ae,Te.tail=$.slice(-512),je)if(Te.openedUrl=!0,Te.openInPreview){const _e=P[ce];_e&&(M(_e.directory,_e.tabId,je,{locked:!1,autoOpened:!1}),_e.status==="waiting-for-preview"&&N(ce,"running"),window.clearTimeout(G.current[ce]),delete G.current[ce],g(_e.directory,je))}else ue(je),H.success(i("projectActions.toast.openedUrlFromOutput"));K.current[ce]=Te}for(const ce of Object.keys(K.current))P[ce]||(delete K.current[ce],window.clearTimeout(G.current[ce]),delete G.current[ce])},[he,g,ue,P,M,i,w,N]);const ke=l.useCallback(async(ce,Ce={})=>{if(!q)throw new Error(i("projectActions.error.noActiveDirectory"));const Te=aa(q,ce.id);y(q);const $e=rn.getState(),De=$e.getDirectoryState(q);let de=z.current[Te]||null;const O=de?!!De?.tabs.some(je=>je.id===de):!1;(!de||!O)&&(de=$e.createTab(q),z.current[Te]=de),C(q,de,`Action: ${ce.name}`),k(q,de,ce.icon||"play"),Ce.revealTerminal!==!1&&(j(q,de),f(!0),b("terminal"));const $=rn.getState().getDirectoryState(q)?.tabs.find(je=>je.id===de);return{key:Te,tabId:de,sessionId:$?.terminalSessionId??null}},[y,q,b,j,f,k,C,i]),oe=l.useCallback(async ce=>{if(c.isVSCode||!a&&d)return;if(!q){H.error(i("projectActions.error.noActiveDirectoryForAction"));return}const Ce=aa(q,ce.id),Te=P[Ce];if(!(Te&&Te.status==="running"))try{const $e=ce.id===or?await(async()=>{const[Ge,at]=await Promise.all([Kc({id:fe?.id??"",path:q}),T1(q)]),Ye=await k1(q,Ge.actions,at);if(!Ye)throw new Error(i("contextPanel.preview.noDevServer"));return{id:or,name:i("projectActions.actions.autoDiscover"),command:Ye.command,icon:"search",autoOpenUrl:!0,openUrl:Ye.previewUrlHint||""}})():ce,De=$e.autoOpenUrl===!0&&($e.openUrl||"").trim().length>0,{key:de,tabId:O,sessionId:L}=await ke($e,{revealTerminal:!De&&ce.id!==or});let $=L,je=!1;if(!$){S(q,O,!0);try{$=(await o.createSession({cwd:q})).sessionId,je=!0,I(q,O,$)}finally{S(q,O,!1)}}if(!$)throw new Error(i("projectActions.error.failedToCreateTerminalSession"));je&&await M1(350),$e.id===or&&(F.current[de]?.(),S(q,O,!0),F.current[de]=Lx($,Ge=>{Ge.type==="data"&&typeof Ge.data=="string"&&Ge.data.length>0&&rn.getState().appendToBuffer(q,O,Ge.data),Ge.type==="exit"&&(rn.getState().setTabLifecycle(q,O,"exited"),rn.getState().setConnecting(q,O,!1),rn.getState().removeProjectActionRun(de),delete K.current[de],F.current[de]?.(),delete F.current[de],window.clearTimeout(G.current[de]),delete G.current[de])},()=>{rn.getState().setConnecting(q,O,!1)},{maxRetries:60,initialRetryDelay:250,maxRetryDelay:2e3,connectionTimeout:5e3}));const ae=$e.autoOpenUrl===!0&&p&&($e.desktopOpenSshForward||"").trim().length>0,_e=$e.autoOpenUrl?$1($e.openUrl):null,le=$e.autoOpenUrl&&p?j1($e.desktopOpenSshForward,m):null;A({key:de,directory:q,actionId:$e.id,tabId:O,sessionId:$,status:$e.id===or&&!_e?"waiting-for-preview":"running"}),window.clearTimeout(G.current[de]),delete G.current[de],$e.id===or&&!_e&&(G.current[de]=window.setTimeout(()=>{rn.getState().updateProjectActionRunStatus(de,"running"),delete G.current[de]},O1)),le?(M(q,O,null,{locked:!0}),ue(le),H.success(i("projectActions.toast.openedForwardedUrl"))):_e?(M(q,O,_e,{locked:!0,autoOpened:!0}),g(q,_e),H.success(i("projectActions.toast.openedActionUrl"))):De?(M(q,O,null,{locked:!0}),H.error(i("projectActions.error.invalidCustomUrlFormat"))):ae?(M(q,O,null,{locked:!0}),H.error(i("projectActions.error.selectedDesktopSshForwardUnavailable"))):M(q,O,null,{locked:!1,autoOpened:!1}),K.current[de]={lastSeenChunkId:null,openedUrl:!!le||!!_e||De,tail:"",openInPreview:$e.id===or};const Me=L1($e.command.trim().replace(/\r\n|\r/g,`
3
+ `));await o.sendInput($,`${Me}\r`)}catch($e){E(Ce),delete K.current[Ce],F.current[Ce]?.(),delete F.current[Ce],window.clearTimeout(G.current[Ce]),delete G.current[Ce],H.error($e instanceof Error?$e.message:i("projectActions.error.failedToRunAction"))}},[m,ke,a,d,p,q,ue,g,P,c.isVSCode,E,S,A,M,I,fe?.id,i,o]),ge=l.useCallback(async ce=>{const Ce=aa(q,ce.id),Te=P[Ce];if(!Te)return;N(Ce,"stopping");try{await o.sendInput(Te.sessionId,"")}catch{}if(await new Promise(de=>{window.setTimeout(de,1e3)}),rn.getState().getDirectoryState(Te.directory)?.tabs.find(de=>de.id===Te.tabId)?.terminalSessionId===Te.sessionId){if(typeof o.forceKill=="function")try{await o.forceKill({sessionId:Te.sessionId})}catch{}else try{await o.close(Te.sessionId)}catch{}I(Te.directory,Te.tabId,null)}E(Ce),delete K.current[Ce],F.current[Ce]?.(),delete F.current[Ce],window.clearTimeout(G.current[Ce]),delete G.current[Ce]},[q,P,E,I,o,N]),me=l.useCallback(()=>{const ce=J??he[0];if(!ce)return;const Ce=aa(q,ce.id),Te=P[Ce];if(Te?.status!=="stopping"){if(Te){ge(ce);return}oe(ce)}},[he,q,oe,P,J,ge]),ye=l.useCallback((ce,Ce=!1)=>{if(_(ce.id),!Ce){oe(ce);return}const Te=aa(q,ce.id),$e=P[Te];if($e?.status!=="stopping"){if($e){ge(ce);return}oe(ce)}},[q,oe,P,ge]),ie=l.useCallback(()=>{fe?.id&&(x(fe.id),h("projects"),v(!0))},[v,h,x,fe?.id]);if(c.isVSCode||!a&&d||!fe||!q)return null;const ve=J??he[0]??null;if(!ve)return null;const X=ve.icon||"play",Se=ve.id===or?"search":Go[X]||"play",Ae=aa(q,ve.id),pe=P[Ae],we=pe?.status==="stopping",Ie=pe?.status==="waiting-for-preview",Y=pe?w.get(pe.directory)?.tabs.find(ce=>ce.id===pe.tabId)?.previewUrl??null:null,re=!!(pe&&Y),Pe=()=>{!pe||!Y||g(pe.directory,Y)};return r?s.jsxs("div",{className:"inline-flex items-center",children:[s.jsx("button",{type:"button",disabled:U||we,className:xe("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:me,"aria-label":pe?i("projectActions.actions.stopNamedAria",{name:ve.name}):i("projectActions.actions.runNamedAria",{name:ve.name}),children:we||Ie?s.jsx(D,{name:"loader-4",className:"h-5 w-5 animate-spin text-[var(--status-warning)]"}):pe?s.jsx(D,{name:"stop",className:"h-5 w-5 text-[var(--status-warning)]"}):s.jsx(D,{name:Se,className:"h-5 w-5"})}),re?s.jsxs(Ct,{children:[s.jsx(It,{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:Pe,children:s.jsx(D,{name:"global",className:"h-4 w-4"})})}),s.jsx(At,{sideOffset:6,children:i("projectActions.actions.openPreview")})]}):null,s.jsxs(Ts,{children:[s.jsx(As,{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(Ds,{align:"end",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs($t,{className:"flex items-center gap-2",onClick:ie,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(Gn,{}),he.map(ce=>{const Ce=ce.icon||"play",Te=ce.id===or?"search":Go[Ce]||"play",$e=aa(q,ce.id),De=P[$e],de=!!De,O=De?.status==="stopping";return s.jsxs($t,{className:"flex items-center gap-2",onClick:()=>{ye(ce,!0)},children:[s.jsx(D,{name:Te,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:ce.name}),O||De?.status==="waiting-for-preview"?s.jsx(D,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):de?s.jsx(D,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},ce.id)})]})]})]}):s.jsxs("div",{className:xe("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:me,disabled:U||we,className:xe("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":pe?i("projectActions.actions.stopNamedAria",{name:ve.name}):i("projectActions.actions.runNamedAria",{name:ve.name}),children:s.jsx("span",{className:"inline-flex h-4 w-4 shrink-0 items-center justify-center",children:we||Ie?s.jsx(D,{name:"loader-4",className:"h-4 w-4 animate-spin text-[var(--status-warning)]"}):pe?s.jsx(D,{name:"stop",className:"h-4 w-4 text-[var(--status-warning)]"}):s.jsx(D,{name:Se,className:"h-4 w-4"})})}),re?s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Pe,className:xe(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(At,{sideOffset:6,children:i("projectActions.actions.openPreview")})]}):null,s.jsxs(Ts,{children:[s.jsx(As,{asChild:!0,children:s.jsx("button",{type:"button",className:xe(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(Ds,{align:"start",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs($t,{className:"flex items-center gap-2",onClick:ie,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(Gn,{}),he.map(ce=>{const Ce=ce.icon||"play",Te=ce.id===or?"search":Go[Ce]||"play",$e=aa(q,ce.id),De=P[$e],de=!!De,O=De?.status==="stopping";return s.jsxs($t,{className:"flex items-center gap-2",onClick:()=>{ye(ce,!0)},children:[s.jsx(D,{name:Te,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:ce.name}),O||De?.status==="waiting-for-preview"?s.jsx(D,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):de?s.jsx(D,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},ce.id)})]})]})]})},Ol="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",B1="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",Pi=l.memo(function(e){const n=st.c(13),{visible:r,title:a,ariaLabel:i,onClick:o,className:c,Icon:d,iconClassName:p}=e;if(!(r===void 0?!0:r))return null;const u=c??Ol,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 h;n[3]!==i||n[4]!==o||n[5]!==u||n[6]!==b?(h=s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:o,"aria-label":i,className:u,children:b})}),n[3]=i,n[4]=o,n[5]=u,n[6]=b,n[7]=h):h=n[7];let v;n[8]!==a?(v=s.jsx(At,{children:s.jsx("p",{children:a})}),n[8]=a,n[9]=v):v=n[9];let x;return n[10]!==h||n[11]!==v?(x=s.jsxs(Ct,{children:[h,v]}),n[10]=h,n[11]=v,n[12]=x):x=n[12],x}),z1=l.memo(function(e){const n=st.c(42),{isMobile:r,githubAuthStatus:a,githubAccounts:i,githubAvatarUrl:o,githubLogin:c,isSwitchingGitHubAccount:d,handleGitHubAccountSwitch:p}=e,{t:m}=dt();if(!a?.connected||r)return null;if(i.length>1){let h;n[0]===Symbol.for("react.memo_cache_sentinel")?(h=xe(Ol,"h-7 w-7 overflow-hidden rounded-full border border-border/60 bg-muted/80 p-0"),n[0]=h):h=n[0];let v;n[1]!==c||n[2]!==m?(v=c?m("header.github.connectedWithLogin",{login:c}):m("header.github.connected"),n[1]=c,n[2]=m,n[3]=v):v=n[3];let x;n[4]!==o||n[5]!==c||n[6]!==m?(x=o?s.jsx("img",{src:o,alt:c?m("header.github.avatarWithLogin",{login:c}):m("header.github.avatar"),className:"h-full w-full object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx(D,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"}),n[4]=o,n[5]=c,n[6]=m,n[7]=x):x=n[7];let g;n[8]!==d||n[9]!==v||n[10]!==x?(g=s.jsx(As,{asChild:!0,children:s.jsx("button",{type:"button",className:h,title:v,disabled:d,children:x})}),n[8]=d,n[9]=v,n[10]=x,n[11]=g):g=n[11];let w;n[12]!==m?(w=m("header.github.accountsTitle"),n[12]=m,n[13]=w):w=n[13];let y;n[14]!==w?(y=s.jsx(Vf,{className:"typography-ui-header font-semibold text-foreground",children:w}),n[14]=w,n[15]=y):y=n[15];let C;n[16]===Symbol.for("react.memo_cache_sentinel")?(C=s.jsx(Gn,{}),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=M=>{const P=M.user,A=!!M.current;return s.jsxs($t,{className:"gap-2",disabled:A||d,onSelect:()=>{A||p(M.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]},M.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 j;n[26]!==y||n[27]!==k?(j=s.jsxs(Ds,{align:"end",className:"w-64",children:[y,C,k]}),n[26]=y,n[27]=k,n[28]=j):j=n[28];let S;return n[29]!==g||n[30]!==j?(S=s.jsxs(Ts,{children:[g,j]}),n[29]=g,n[30]=j,n[31]=S):S=n[31],S}let u;n[32]!==c||n[33]!==m?(u=c?m("header.github.connectedWithLogin",{login:c}):m("header.github.connected"),n[32]=c,n[33]=m,n[34]=u):u=n[34];let f;n[35]!==o||n[36]!==c||n[37]!==m?(f=o?s.jsx("img",{src:o,alt:c?m("header.github.avatarWithLogin",{login:c}):m("header.github.avatar"),className:"h-full w-full object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx(D,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"}),n[35]=o,n[36]=c,n[37]=m,n[38]=f):f=n[38];let b;return n[39]!==u||n[40]!==f?(b=s.jsx("div",{className:"app-region-no-drag flex h-7 w-7 items-center justify-center overflow-hidden rounded-full border border-border/60 bg-muted/80",title:u,children:f}),n[39]=u,n[40]=f,n[41]=b):b=n[41],b}),V1=l.memo(function(e){const n=st.c(76),{isDesktopApp:r,currentInstanceLabel:a,compactCurrentInstanceLabel:i,isDesktopServicesOpen:o,setIsDesktopServicesOpen:c,refreshCurrentInstanceLabel:d,desktopServicesTab:p,setDesktopServicesTab:m,quotaResultsLength:u,fetchAllQuotas:f,servicesTabItems:b,quotaLastUpdated:h,quotaDisplayMode:v,quotaDisplayTabItems:x,handleDisplayModeChange:g,handleUsageRefresh:w,isQuotaLoading:y,isUsageRefreshSpinning:C,hasRateLimits:k,rateLimitGroups:j,expandedFamilies:S,toggleFamilyExpanded:I,shortcutLabel:M,showDevShutdown:P,isDevShutdownInFlight:A,onDevShutdown:N}=e,{t:E}=dt();let T;n[0]!==p||n[1]!==f||n[2]!==u||n[3]!==d||n[4]!==c?(T=ne=>{c(ne),ne&&(d(),p==="usage"&&u===0&&f())},n[0]=p,n[1]=f,n[2]=u,n[3]=d,n[4]=c,n[5]=T):T=n[5];let R;n[6]!==a||n[7]!==r||n[8]!==E?(R=r?E("header.services.openWithCurrent",{current:a}):E("header.services.open"),n[6]=a,n[7]=r,n[8]=E,n[9]=R):R=n[9];const V=r?"w-auto max-w-[14rem] justify-start gap-1.5 px-2.5":"h-8 w-8";let _;n[10]!==V?(_=xe(Ol,V),n[10]=V,n[11]=_):_=n[11];let U;n[12]===Symbol.for("react.memo_cache_sentinel")?(U=s.jsx(D,{name:"stack",className:"h-[18px] w-[18px]"}),n[12]=U):U=n[12];let B;n[13]!==i||n[14]!==r?(B=r?s.jsx("span",{className:"truncate typography-ui-label font-medium text-foreground",children:i}):null,n[13]=i,n[14]=r,n[15]=B):B=n[15];let z;n[16]!==R||n[17]!==_||n[18]!==B?(z=s.jsx(It,{asChild:!0,children:s.jsx(As,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":R,className:_,children:[U,B]})})}),n[16]=R,n[17]=_,n[18]=B,n[19]=z):z=n[19];let K;n[20]!==a||n[21]!==r||n[22]!==M||n[23]!==E?(K=r?E("header.services.tooltip.currentInstanceWithShortcuts",{current:a,toggle:M("toggle_services_menu"),nextTab:M("cycle_services_tab")}):E("header.services.tooltip.servicesWithShortcuts",{toggle:M("toggle_services_menu"),nextTab:M("cycle_services_tab")}),n[20]=a,n[21]=r,n[22]=M,n[23]=E,n[24]=K):K=n[24];let F;n[25]!==K?(F=s.jsx(At,{children:s.jsx("p",{children:K})}),n[25]=K,n[26]=F):F=n[26];let G;n[27]!==z||n[28]!==F?(G=s.jsxs(Ct,{children:[z,F]}),n[27]=z,n[28]=F,n[29]=G):G=n[29];let Q;n[30]!==f||n[31]!==u||n[32]!==m?(Q=ne=>{const ee=ne;m(ee),ee==="usage"&&u===0&&f()},n[30]=f,n[31]=u,n[32]=m,n[33]=Q):Q=n[33];let te;n[34]!==p||n[35]!==b||n[36]!==Q?(te=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($r,{items:b,activeId:p,onSelect:Q,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]=Q,n[37]=te):te=n[37];let Z;n[38]!==p||n[39]!==r||n[40]!==o||n[41]!==c?(Z=r&&p==="instance"?s.jsx(Hx,{embedded:!0,open:o&&p==="instance",onOpenChange:K1,onHostSwitched:()=>c(!1)}):null,n[38]=p,n[39]=r,n[40]=o,n[41]=c,n[42]=Z):Z=n[42];let fe;n[43]!==p||n[44]!==o?(fe=p==="mcp"?s.jsx(Ch,{active:o&&p==="mcp"}):null,n[43]=p,n[44]=o,n[45]=fe):fe=n[45];let ue;n[46]!==p||n[47]!==S||n[48]!==g||n[49]!==w||n[50]!==k||n[51]!==y||n[52]!==C||n[53]!==v||n[54]!==x||n[55]!==h||n[56]!==j||n[57]!==E||n[58]!==I?(ue=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:Th(h)})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("div",{className:"h-7 w-[10.5rem]",children:s.jsx($r,{items:x,activeId:v,onSelect:ne=>{g(ne)},layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",className:"h-full"})}),s.jsx("button",{type:"button",className:xe("inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors","hover:text-foreground hover:bg-interactive-hover","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),onClick:w,disabled:y||C,"aria-label":E("header.services.refreshRateLimitsAria"),children:s.jsx(D,{name:"refresh",className:xe("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:j.map((ne,ee)=>{const he=S[ne.providerId]??[];return s.jsxs(l.Fragment,{children:[ee>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(pr,{providerId:ne.providerId,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:ne.providerName})]}),ne.entries.length===0&&(!ne.modelFamilies||ne.modelFamilies.length===0)?s.jsx("div",{className:"px-4 pb-2",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:ne.error??E("header.services.noRateLimitsReported")})}):s.jsxs("div",{className:"space-y-3 px-4 pb-2",children:[ne.entries.map(ke=>{const[oe,ge]=ke,me=v==="remaining"?ge.remainingPercent:ge.usedPercent,ye=no(ge.usedPercent,ge.resetAt,ge.windowSeconds,oe),ie=ye?.dailyAllocationPercent!=null?v==="remaining"?100-Jr(ye.elapsedRatio):Jr(ye.elapsedRatio):null,ve=so(ge.valueLabel,me),X=Vd(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:Ud(oe)}),X?s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:X}):null]}),s.jsx("span",{className:"typography-ui-label tabular-nums text-foreground",children:ve==="-"?"":ve})]}),s.jsx(ao,{percent:me,tonePercent:ge.usedPercent,className:"h-1.5",expectedMarkerPercent:ie}),ye?s.jsx(io,{paceInfo:ye,compact:!0}):null]},`${ne.providerId}-${oe}`)}),ne.modelFamilies&&ne.modelFamilies.length>0?s.jsx("div",{className:"space-y-0.5",children:ne.modelFamilies.map(ke=>{const oe=ke.familyId??"other",ge=he.includes(oe);return s.jsxs(fr,{open:ge,onOpenChange:()=>I(ne.providerId,oe),children:[s.jsxs(kr,{className:"flex w-full items-center justify-between rounded-md px-1 py-1.5 text-left hover:bg-[var(--interactive-hover)]/50 transition-colors",children:[s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:ke.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(hr,{children:s.jsx("div",{className:"space-y-2.5 pb-1 pl-1 pt-1",children:ke.models.map(me=>{const[ye,ie]=me,ve=v==="remaining"?ie.remainingPercent:ie.usedPercent,X=no(ie.usedPercent,ie.resetAt,ie.windowSeconds),Se=X?.dailyAllocationPercent!=null?v==="remaining"?100-Jr(X.elapsedRatio):Jr(X.elapsedRatio):null,Ae=so(ie.valueLabel,ve);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:ul(ye)}),s.jsx("span",{className:"typography-ui-label tabular-nums text-foreground",children:Ae==="-"?"":Ae})]}),s.jsx(ao,{percent:ve,tonePercent:ie.usedPercent,className:"h-1.5",expectedMarkerPercent:Se}),X?s.jsx(io,{paceInfo:X,compact:!0}):null]},`${ne.providerId}-${ye}`)})})})]},oe)})}):null]})]},ne.providerId)})})]}):null,n[46]=p,n[47]=S,n[48]=g,n[49]=w,n[50]=k,n[51]=y,n[52]=C,n[53]=v,n[54]=x,n[55]=h,n[56]=j,n[57]=E,n[58]=I,n[59]=ue):ue=n[59];let W;n[60]!==A||n[61]!==N||n[62]!==P||n[63]!==E?(W=P?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"mx-4 my-2 border-t border-[var(--interactive-border)]"}),s.jsx("div",{className:"px-2 pb-2",children:s.jsx($t,{disabled:A,onSelect:()=>{N()},children:E("header.services.shutdownDev")})})]}):null,n[60]=A,n[61]=N,n[62]=P,n[63]=E,n[64]=W):W=n[64];let q;n[65]!==te||n[66]!==Z||n[67]!==fe||n[68]!==ue||n[69]!==W?(q=s.jsxs(Ds,{align:"end",className:"w-[min(27rem,calc(100vw-2rem))] max-h-[75vh] overflow-y-auto bg-[var(--surface-elevated)] p-0",children:[te,Z,fe,ue,W]}),n[65]=te,n[66]=Z,n[67]=fe,n[68]=ue,n[69]=W,n[70]=q):q=n[70];let J;return n[71]!==o||n[72]!==T||n[73]!==G||n[74]!==q?(J=s.jsxs(Ts,{open:o,onOpenChange:T,children:[G,q]}),n[71]=o,n[72]=T,n[73]=G,n[74]=q,n[75]=J):J=n[75],J}),U1=(t,e)=>t===e?!0:!t||!e?!1:t.totalTokens===e.totalTokens&&t.percentage===e.percentage&&t.contextLimit===e.contextLimit&&(t.outputLimit??0)===(e.outputLimit??0)&&(t.normalizedOutput??0)===(e.normalizedOutput??0)&&t.thresholdLimit===e.thresholdLimit&&(t.lastMessageId??"")===(e.lastMessageId??""),W1=t=>{const e=t.trim();if(!e)return"";const n=e.split(/\s+/).filter(Boolean);if(n.length>=2){const r=n[0],a=n[1].slice(0,3),i=`${r} ${a}`.trim();return n.length>2||i.length<e.length?`${i}...`:i}return e.length>12?`${e.slice(0,9).trimEnd()}...`:e},Th=t=>{if(!t)return"-";try{return new Date(t).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"})}catch{return"-"}},lr=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},Co=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,nm=({onToggleLeftDrawer:t,onToggleRightDrawer:e,leftDrawerOpen:n,rightDrawerOpen:r})=>{const{t:a}=dt(),i=Re(Be=>Be.setSessionSwitcherOpen),o=Re(Be=>Be.toggleSidebar),c=Re(Be=>Be.toggleBottomTerminal),d=Re(Be=>Be.toggleRightSidebar),p=Re(Be=>Be.openContextOverview),m=Re(Be=>Be.openContextPlan),u=Re(Be=>Be.openContextBrowser),f=Re(Be=>Be.closeContextPanel),b=Re(Be=>Be.contextPanelByDirectory),h=Re(Be=>Be.activeMainTab),v=Re(Be=>Be.setActiveMainTab),x=Re(Be=>Be.shortcutOverrides),g=bt(Be=>Be.getCurrentModel),w=Rn(),[y,C]=l.useState(!1),k=Lt(Be=>Be.getContextUsage),j=Lt(Be=>!!Be.newSessionDraft?.open),S=Lt(Be=>Be.currentSessionId),I=Gx(S??""),M=Uf(S??null),P=Pa(Be=>Be.activeSessions),A=Id(),N=Ps(Be=>Be.activeProjectId?Be.projects.find(Dt=>Dt.id===Be.activeProjectId)??null:null),E=l.useMemo(()=>{if(!N)return null;const Be=N.label?.trim();if(Be)return Be;const Dt=N.path.split(/[\\/]/).filter(Boolean);return Dt[Dt.length-1]??null},[N]),T=Os(Be=>Be.results),R=Os(Be=>Be.fetchAllQuotas),V=Os(Be=>Be.isLoading),_=Os(Be=>Be.lastUpdated),U=Os(Be=>Be.displayMode),B=Os(Be=>Be.dropdownProviderIds),z=Os(Be=>Be.loadSettings),K=Os(Be=>Be.setDisplayMode),{isMobile:F}=nn(),G=Bn(Be=>Be.status),Q=Bn(Be=>Be.setStatus),te=l.useRef(null),[Z,fe]=l.useState(()=>typeof window>"u"?!1:vn()),ue=l.useMemo(()=>Pd(),[]),W=Wf(),[q,J]=l.useState(!1),ne=l.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),ee=l.useMemo(()=>{if(typeof window>"u")return null;const Be=window.__OPENCHAMBER_MACOS_MAJOR__;if(typeof Be=="number"&&Number.isFinite(Be)&&Be>0)return Be;if(typeof navigator>"u")return null;const Dt=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!Dt)return null;const Yt=Number.parseInt(Dt[1],10),Qt=Number.parseInt(Dt[2],10);return Number.isNaN(Yt)?null:Yt===10?Qt:Yt},[]);Oe.useEffect(()=>{typeof window>"u"||fe(vn())},[]);const he=g(),ke=he&&typeof he.limit=="object"&&he.limit!==null?he.limit:null,oe=ke&&typeof ke.context=="number"?ke.context:0,ge=ke&&typeof ke.output=="number"?ke.output:0,me=k(oe,ge),[ye,ie]=l.useState(null),ve=!S||I;Oe.useEffect(()=>{if(!S){ie(Be=>Be===null?Be:null);return}if(me&&me.totalTokens>0){ie(Be=>U1(Be,me)?Be:me);return}ve&&ie(Be=>Be===null?Be:null)},[me,S,ve]);const X=Re(Be=>Be.isSessionSwitcherOpen),Se=G?.connected?G.user?.avatarUrl??null:null,Ae=G?.connected?G.user?.login??null:null,pe=G?.accounts??[],[we,Ie]=l.useState(!1),[Y,re]=l.useState(!1),[Pe,ce]=l.useState(!1),[Ce,Te]=l.useState(!1),[$e,De]=l.useState("Local"),de=l.useMemo(()=>W1($e),[$e]),[O,L]=l.useState(Z?"instance":"usage"),[$,je]=l.useState("usage");Oe.useEffect(()=>{!Z&&O==="instance"&&L("usage")},[O,Z]);const ae=l.useMemo(()=>on(),[]),_e=!ae&&h==="chat"&&!!ye&&ye.totalTokens>0,le=ye&&ye.contextLimit>0?Math.min(999,ye.totalTokens/ye.contextLimit*100):0,Me=l.useCallback(async()=>{if(!(typeof window>"u"||!Z))try{const Be=await qx(),Dt=window.location.href,Yt=window.__OPENCHAMBER_LOCAL_ORIGIN__||window.location.origin;if(bu(Dt,Yt)){De("Local");return}const Qt=Be.hosts.find(vs=>bu(Dt,vs.url));if(Qt?.label?.trim()){De(Jx(Qt.label.trim()));return}De("Instance")}catch{De("Local")}},[Z]);Oe.useEffect(()=>{Me()},[Me]),Sh();const Ge=Os(Be=>Be.selectedModels),at=Os(Be=>Be.expandedFamilies),Ye=Os(Be=>Be.toggleFamilyExpanded),Xe=l.useMemo(()=>{const Be=[];for(const Dt of Br){if(!B.includes(Dt.id))continue;const Yt=T.find(_s=>_s.providerId===Dt.id),Qt=Yt?.usage?.windows??{},vs=Yt?.usage?.models,Rs=Object.entries(Qt),Cs={providerId:Dt.id,providerName:Dt.name,entries:Rs,error:Yt&&!Yt.ok&&Yt.configured?Yt.error:void 0};if(vs&&Object.keys(vs).length>0){const _s=Ge[Dt.id]??[],Qs=_s.length>0,Fn=zv(vs,Dt.id),gr=jh(Dt.id),zr=Nh(gr);Cs.modelFamilies=[];for(const wn of zr){const zn=Fn.get(wn.id)??[];if(zn.length===0)continue;const sr=Qs?zn.filter(nr=>_s.includes(nr)):zn;if(sr.length===0)continue;const gn=[];for(const nr of sr){const Vr=vs[nr];if(Vr?.windows){const Ar=Object.entries(Vr.windows);Ar.length>0&&gn.push([nr,Ar[0][1]])}}gn.length>0&&Cs.modelFamilies.push({familyId:wn.id,familyLabel:wn.label,models:gn})}const Pr=Fn.get(null)??[],Nn=Qs?Pr.filter(wn=>_s.includes(wn)):Pr;if(Nn.length>0){const wn=[];for(const zn of Nn){const sr=vs[zn];if(sr?.windows){const gn=Object.entries(sr.windows);gn.length>0&&wn.push([zn,gn[0][1]])}}wn.length>0&&Cs.modelFamilies.push({familyId:null,familyLabel:a("header.services.modelFamily.other"),models:wn})}}(Rs.length>0||Cs.modelFamilies&&Cs.modelFamilies.length>0||Cs.error)&&Be.push(Cs)}return Be},[B,T,Ge,a]),ut=Xe.length>0;l.useEffect(()=>{z()},[z]);const rt=l.useCallback(async Be=>{K(Be);try{await Is({usageDisplayMode:Be})}catch(Dt){console.warn("Failed to update usage display mode:",Dt)}},[K]),it=l.useCallback(()=>{if(Ce)return;Te(!0);const Be=new Promise(Dt=>setTimeout(Dt,500));Promise.all([R(),Be]).finally(()=>{Te(!1)})},[R,Ce]),nt=l.useMemo(()=>S?A.find(Be=>Be.id===S)??P.find(Be=>Be.id===S)??M??Yx().find(Be=>Be.id===S)??null:null,[S,M,P,A]),Ne=l.useRef(null),[Ke,Ve]=l.useState(0);l.useEffect(()=>{if(!S){Ne.current&&(Ne.current=null,Ve(Qt=>Qt+1));return}if(nt){Ne.current={sessionId:S,session:nt,expiresAt:Date.now()+2e3};return}const Be=Ne.current;if(!Be||Be.sessionId!==S)return;const Dt=Be.expiresAt-Date.now();if(Dt<=0){Ne.current=null,Ve(Qt=>Qt+1);return}const Yt=window.setTimeout(()=>{Ne.current?.sessionId===S&&(Ne.current=null),Ve(Qt=>Qt+1)},Dt);return()=>{window.clearTimeout(Yt)}},[S,nt]);const qe=(()=>{if(nt)return nt;if(!S)return null;const Be=Ne.current;return Be&&Be.sessionId===S&&Be.expiresAt>Date.now()?Be.session:null})(),lt=Lt(Be=>S?Be.worktreeMetadata.get(S)?.path??"":""),He=Lt(Be=>S?Be.worktreeMetadata.get(S)?.branch?.trim()??null:null),ze=Kf(Be=>S?Be.getAttachment(S):void 0),et=l.useMemo(()=>ze?Qx(ze):null,[ze]),yt=l.useMemo(()=>ze?ze.legacy?"legacy":ze.degraded?"degraded":ze.worktreeStatus==="missing"?"missing":ze.worktreeStatus==="invalid"?"invalid":ze.attentionReason?"attention":null:null,[ze]),Rt=l.useMemo(()=>lr(lt||""),[lt]),kt=l.useMemo(()=>{const Be=typeof qe?.directory=="string"?qe.directory:"";return lr(Be||"")},[qe?.directory]),ht=Lt(Be=>Be.newSessionDraft?.open?lr(Be.newSessionDraft.bootstrapPendingDirectory??Be.newSessionDraft.directoryOverride??""):""),vt=l.useMemo(()=>Rt||kt||ht,[ht,kt,Rt]),ns=Lt(Be=>{const Dt=lr(Rt||kt||"");if(!Dt)return null;for(const Yt of Be.availableWorktreesByProject.values()){const vs=Yt.find(Rs=>lr(Rs.path)===Dt)?.branch?.trim();if(vs)return vs}return null}),Kt=Xx(vt||null)||He||ns,mt=l.useMemo(()=>{if(!S)return E??"OpenChamber";const Be=qe?.title?.trim();return Be&&Be.length>0?Be:"Untitled Session"},[E,qe?.title,S]),Et=l.useMemo(()=>Hf(qe?.summary),[qe?.summary]),rs=l.useMemo(()=>Et||{additions:0,deletions:0},[Et]),gs=rs.additions>0||rs.deletions>0,xs=l.useMemo(()=>lr(vt||N?.path||""),[N?.path,vt]),bs=l.useMemo(()=>N?{id:N.id,path:N.path}:null,[N]),Wt=l.useRef(null);l.useEffect(()=>{!bs||!xs||(Wt.current={projectRef:bs,directory:xs})},[xs,bs]);const We=l.useMemo(()=>bs&&xs?{projectRef:bs,directory:xs}:Wt.current,[xs,bs]),St=Ad(Be=>Be.planModeEnabled),qt=Lt(Be=>Be.isSessionPlanAvailable),wt=St&&S?qt(S):!1,es=wt,ds=l.useRef("");l.useEffect(()=>{if(!St){Re.getState().activeMainTab==="plan"&&Re.getState().setActiveMainTab("chat");return}if(!S)return;const Be=`${S||"none"}:${kt||"none"}:${qe?.time?.created||0}:${qe?.slug||"none"}`;ds.current!==Be&&(ds.current=Be),!wt&&Re.getState().activeMainTab==="plan"&&Re.getState().setActiveMainTab("chat")},[St,wt,qe?.slug,qe?.time?.created,S,kt]);const Ms=l.useCallback(async Be=>{if(!(!Be||we)){Ie(!0);try{const Dt=w.github?await w.github.authActivate(Be):await(async()=>{const Yt=await fetch("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:Be})}),Qt=await Yt.json().catch(()=>null);if(!Yt.ok||!Qt)throw new Error(Qt?.error||Yt.statusText);return Qt})();Q(Dt)}catch(Dt){console.error("Failed to switch GitHub account:",Dt)}finally{Ie(!1)}}},[we,w.github,Q]),as=l.useCallback(()=>{if(typeof document>"u")return;const Be=document.activeElement;if(!Be)return;const Dt=Be.tagName;(Dt==="INPUT"||Dt==="TEXTAREA"||Dt==="SELECT"||Be.isContentEditable)&&Be.blur()},[]),$s=l.useCallback(()=>{if(F){as(),i(!X);return}o()},[as,F,X,i,o]),Ls=l.useCallback(()=>{ol("desktop_open_draft_mini_chat_window",{directory:lr(vt||N?.path||""),projectId:N?.id??null}).catch(Be=>{console.warn("[header] failed to open draft mini chat window",Be)})},[N?.id,N?.path,vt]),ln=l.useCallback(()=>{if(j){Ls();return}S&&ol("desktop_open_session_mini_chat_window",{sessionId:S,directory:lr(vt||N?.path||"")}).catch(Be=>{console.warn("[header] failed to open session mini chat window",Be)})},[N?.path,S,Ls,j,vt]),Xs=l.useCallback(()=>{const Be=lr(vt||"");if(!Be)return;const Dt=b[Be];if(Co(Dt)==="context"){f(Be);return}p(Be)},[f,b,p,vt]),Vt=l.useMemo(()=>{const Be=lr(vt||"");if(!Be)return!1;const Dt=b[Be];return Co(Dt)==="context"},[b,vt]),Ut=l.useCallback(()=>{const Be=lr(vt||"");if(!Be)return;const Dt=b[Be];if(Co(Dt)==="plan"){f(Be);return}m(Be)},[f,b,m,vt]),se=l.useCallback(()=>{const Be=lr(vt||"");Be&&u(Be)},[u,vt]),xt=l.useMemo(()=>{const Be=lr(vt||"");if(!Be)return!1;const Dt=b[Be];return Co(Dt)==="plan"},[b,vt]),Je=Ol,_t=B1,Gt=l.useMemo(()=>Z&&ne&&!q||W?"pl-[5.5rem]":"pl-3",[Z,q,ne,W]);Oe.useEffect(()=>{if(!Z||!ne){J(!1);return}let Be=!1,Dt=null;const Yt=async()=>{try{const{getCurrentWindow:vs}=await Sr(async()=>{const{getCurrentWindow:_s}=await import("./vendor-.bun-BIr1wmDP.js").then(Qs=>Qs.bJ);return{getCurrentWindow:_s}},__vite__mapDeps([0,1])),Cs=await vs().isFullscreen();Be||J(Cs)}catch{Be||J(!1)}},Qt=async()=>{try{const{getCurrentWindow:vs}=await Sr(async()=>{const{getCurrentWindow:Cs}=await import("./vendor-.bun-BIr1wmDP.js").then(_s=>_s.bJ);return{getCurrentWindow:Cs}},__vite__mapDeps([0,1]));Dt=await vs().onResized(()=>{Yt()})}catch{}};return Yt(),Qt(),()=>{Be=!0,Dt&&Dt()}},[Z,ne]);const is=l.useMemo(()=>!Z||!ne||ee===null?"":ee>=26?"h-12":ee<=15?"h-14":"",[Z,ne,ee]),Ue=l.useMemo(()=>{if(!(Z||ae))return{paddingLeft:W?"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))"}},[Z,W,ae]),gt=l.useCallback(()=>{if(typeof document>"u")return;const Be=te.current?.getBoundingClientRect().height;Be&&document.documentElement.style.setProperty("--oc-header-height",`${Be}px`)},[]);Oe.useEffect(()=>{if(typeof window>"u")return;gt();const Be=te.current;if(!Be||typeof ResizeObserver>"u")return()=>{};let Dt=0;const Yt=()=>{Dt||(Dt=requestAnimationFrame(()=>{Dt=0,gt()}))},Qt=new ResizeObserver(Yt);return Qt.observe(Be),window.addEventListener("resize",Yt),window.addEventListener("orientationchange",Yt),()=>{Dt&&cancelAnimationFrame(Dt),Qt.disconnect(),window.removeEventListener("resize",Yt),window.removeEventListener("orientationchange",Yt)}},[gt]),Oe.useEffect(()=>{gt()},[gt,F,is]);const Pt=l.useCallback(async Be=>{const Dt=Be.target;Dt.closest(".app-region-no-drag")||Dt.closest("button, a, input, select, textarea")||Be.button===0&&Z&&await Zx()},[Z]),Mt=l.useMemo(()=>{if(F){const Be=[{id:"chat",label:a("layout.mainTab.chat"),icon:"chat-4"}];return es&&Be.push({id:"plan",label:a("layout.mainTab.plan"),icon:"file-text"}),Be.push({id:"diff",label:a("layout.mainTab.diff"),icon:"diff"},{id:"files",label:a("layout.mainTab.files"),icon:"folder-6"},{id:"terminal",label:a("layout.mainTab.terminal"),icon:"terminal-box"}),Be}return[]},[F,es,a]),ts=l.useCallback(Be=>Il(qr(Be,x)),[x]);Oe.useEffect(()=>{!F&&(h==="git"||h==="terminal"||h==="diff"||h==="files")&&v("chat")},[h,F,v]);const Ot=l.useMemo(()=>{const Be=[];return Z&&Be.push({value:"instance",label:a("layout.services.instance"),icon:"server"}),Be.push({value:"usage",label:a("layout.services.usage"),icon:"timer"},{value:"mcp",label:"MCP",icon:"plug-2"}),Be},[Z,a]),ks=l.useMemo(()=>Ot.map(Be=>({id:Be.value,label:Be.label,icon:s.jsx(D,{name:Be.icon,className:"h-3.5 w-3.5"})})),[Ot]),Zs=l.useMemo(()=>{if(typeof window>"u"||Z||ae)return!1;const Be=window.location.hostname;return Be==="localhost"||Be==="127.0.0.1"||Be==="::1"},[Z,ae]),Hs=l.useCallback(async()=>{if(y)return;C(!0),ce(!1);const Be=[];let Dt=!1;try{try{for(const[,Yt]of rn.getState().sessions.entries())for(const Qt of Yt.tabs)Qt.previewUrl&&Be.push(Qt.previewUrl)}catch{}try{await $x({})}catch{}try{(await fetch("/api/system/dev-shutdown",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({previewUrls:Be})})).ok?Dt=!0:Dt=(await fetch("/api/system/shutdown",{method:"POST"})).ok}catch{}}finally{Dt||C(!1)}},[y,ce]),ss=l.useMemo(()=>[{value:"usage",label:a("header.services.used")},{value:"remaining",label:a("header.services.remaining")}],[a]),Es=l.useMemo(()=>ss.map(Be=>({id:Be.value,label:Be.label})),[ss]),Pn=l.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]);Oe.useEffect(()=>{const Be=Dt=>{if(Dd(Dt)&&!Dt.shiftKey&&!Dt.altKey){const Yt=parseInt(Dt.key,10);Yt>=1&&Yt<=Mt.length&&(Dt.preventDefault(),v(Mt[Yt-1].id))}};return window.addEventListener("keydown",Be),()=>window.removeEventListener("keydown",Be)},[Mt,v]),Oe.useEffect(()=>{const Be=Dt=>{const Yt=qr("toggle_services_menu",x);if(Uo(Dt,Yt)){Dt.preventDefault(),Pe?ce(!1):(ce(!0),Me(),O==="usage"&&T.length===0&&R());return}const Qt=qr("cycle_services_tab",x);if(Uo(Dt,Qt)){Dt.preventDefault();const Rs=Ot.map(Fn=>Fn.value);if(Rs.length===0)return;const Cs=Rs.indexOf(O),_s=Cs===-1?0:(Cs+1)%Rs.length,Qs=Rs[_s];L(Qs),ce(!0),Me(),Qs==="usage"&&T.length===0&&R();return}const vs=qr("toggle_context_plan",x);Uo(Dt,vs)&&(Dt.preventDefault(),Ut())};return window.addEventListener("keydown",Be),()=>window.removeEventListener("keydown",Be)},[x,Pe,O,Ot,T.length,R,Me,Ut]);const an=Be=>{const Dt=h===Be.id,Yt=Be.icon==="diff",Qt=Yt?null:Be.icon,vs=Be.id==="chat",Rs=_s=>Yt?s.jsx(Ku,{size:_s}):Qt?s.jsx(D,{name:Qt,className:`h-${_s/4} w-${_s/4}`}):null,Cs=s.jsxs("button",{type:"button",onClick:()=>v(Be.id),className:xe("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",vs&&!F&&"min-w-[100px] justify-center"),"aria-label":Be.label,"aria-selected":Dt,role:"tab",children:[F?Rs(20):s.jsxs(s.Fragment,{children:[Rs(16),s.jsx("span",{className:"header-tab-label",children:Be.label})]}),Be.badge!==void 0&&Be.badge>0&&s.jsx("span",{className:"header-tab-badge typography-micro text-status-info font-medium",children:Be.badge})]});return s.jsx(l.Fragment,{children:Cs},Be.id)},Ir=s.jsxs(s.Fragment,{children:[es&&s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":a("header.actions.openPlanAria"),onClick:Ut,className:xe(Je,xt&&"bg-[var(--interactive-hover)]"),children:s.jsx(D,{name:"file-text",className:"h-[18px] w-[18px]"})})}),s.jsx(At,{children:s.jsx("p",{children:a("header.actions.planWithShortcut",{shortcut:ts("toggle_context_plan")})})})]}),s.jsx(n1,{directory:xs,className:"mr-1"}),s.jsx(V1,{isDesktopApp:Z,currentInstanceLabel:$e,compactCurrentInstanceLabel:de,isDesktopServicesOpen:Pe,setIsDesktopServicesOpen:ce,refreshCurrentInstanceLabel:Me,desktopServicesTab:O,setDesktopServicesTab:L,quotaResultsLength:T.length,fetchAllQuotas:R,servicesTabItems:ks,quotaLastUpdated:_,quotaDisplayMode:U,quotaDisplayTabItems:Es,handleDisplayModeChange:rt,handleUsageRefresh:it,isQuotaLoading:V,isUsageRefreshSpinning:Ce,hasRateLimits:ut,rateLimitGroups:Xe,expandedFamilies:at,toggleFamilyExpanded:Ye,shortcutLabel:ts,showDevShutdown:Zs,isDevShutdownInFlight:y,onDevShutdown:Hs}),s.jsx(Pi,{title:a("header.actions.terminalPanelWithShortcut",{shortcut:ts("toggle_terminal")}),ariaLabel:a("header.actions.toggleTerminalPanelAria"),onClick:c,Icon:"terminal-box"}),ue?s.jsx(Pi,{title:a("contextPanel.browser.open"),ariaLabel:a("contextPanel.browser.open"),onClick:se,Icon:"global"}):null,s.jsx(Pi,{title:a("header.actions.rightSidebarWithShortcut",{shortcut:ts("toggle_right_sidebar")}),ariaLabel:a("header.actions.toggleRightSidebarAria"),onClick:d,Icon:"layout-right"}),s.jsx(z1,{isMobile:F,githubAuthStatus:G,githubAccounts:pe,githubAvatarUrl:Se,githubLogin:Ae,isSwitchingGitHubAccount:we,handleGitHubAccountSwitch:Ms})]}),er=ue&&(j||!!S),Js=()=>s.jsxs("div",{onMouseDown:Pt,className:xe("app-region-drag relative flex h-12 select-none items-center pr-3",Gt,is),style:Ue,role:"tablist","aria-label":a("header.navigation.mainAria"),children:[s.jsx(Pi,{title:a("header.actions.openSessionsWithShortcut",{shortcut:ts("toggle_sidebar")}),ariaLabel:a("header.actions.openSessionsAria"),onClick:$s,className:`${Je} shrink-0`,Icon:"layout-left"}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center pl-3",children:[We&&s.jsx(sm,{projectRef:We.projectRef,directory:We.directory,className:"mr-2"}),s.jsx(eb,{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:j?a("sessions.switcher.draftTitle"):mt}),E||Kt||!j&&(gs||yt)?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,Kt?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:Kt})]}):null,!j&&gs?s.jsxs("span",{className:"inline-flex flex-shrink-0 items-center gap-0 text-[0.92em]",children:[s.jsxs("span",{className:"text-status-success/80",children:["+",rs.additions]}),s.jsx("span",{className:"text-muted-foreground/60",children:"/"}),s.jsxs("span",{className:"text-status-error/65",children:["-",rs.deletions]})]}):null,!j&&yt?s.jsxs("span",{className:xe("inline-flex min-w-0 items-center gap-0.5",yt==="attention"||yt==="invalid"||yt==="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]})}),Mt.length>0&&s.jsx("div",{className:"flex items-center gap-1 rounded-lg bg-[var(--surface-muted)]/50 p-1",children:Mt.map(Be=>an(Be))}),s.jsx("div",{className:"flex-1"}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[_e&&ye?s.jsx(tb,{totalTokens:ye.totalTokens,percentage:le,colorPercentage:ye.percentage,contextLimit:ye.contextLimit,outputLimit:ye.outputLimit??0,size:"compact",hideIcon:!0,showPercentIcon:!0,onClick:Xs,pressed:Vt,className:er?"":"mr-3.5",valueClassName:"typography-ui-label font-medium leading-none text-foreground",percentIconClassName:"h-5 w-5"}):null,s.jsx(Pi,{visible:er,title:a(j?"header.actions.newMiniChat":"header.actions.openSessionMiniChat"),ariaLabel:a(j?"header.actions.newMiniChatAria":"header.actions.openSessionMiniChatAria"),onClick:ln,className:xe(Je,_e?"mr-3.5":"mr-1"),Icon:"picture-in-picture-2"}),Ir]})]})]}),An=()=>s.jsxs("div",{className:"app-region-drag relative flex items-center gap-2 px-3 py-2 select-none",children:[s.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[t?s.jsx("button",{type:"button",onClick:t,className:xe(_t,n&&"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"})}):X?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:$s,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"})}),X&&s.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:a("header.sessions.title")})]}),!X&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"app-region-no-drag flex min-w-0 flex-1 items-center",children:s.jsx("div",{className:"flex min-w-0 flex-1 overflow-x-auto overflow-y-hidden scrollbar-hidden touch-pan-x overscroll-x-contain",children:s.jsx("div",{className:"flex w-max items-center gap-1 pr-1",children:s.jsx("div",{className:"flex items-center gap-0.5 rounded-lg bg-[var(--surface-muted)]/50 p-0.5",role:"tablist","aria-label":a("header.navigation.mainAria"),children:Mt.map(Be=>{const Dt=h===Be.id,Yt=Be.icon==="diff",Qt=Yt?null:Be.icon;return s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>{F&&as(),v(Be.id)},"aria-label":Be.label,"aria-selected":Dt,role:"tab",className:xe(_t,"relative rounded-lg",Dt&&"bg-interactive-selection text-interactive-selection-foreground"),children:[Yt?s.jsx(Ku,{className:"h-5 w-5"}):Qt?s.jsx(D,{name:Qt,className:"h-5 w-5"}):null,Be.badge!==void 0&&Be.badge>0&&s.jsx("span",{className:"absolute -top-1 -right-1 text-[10px] font-semibold text-primary",children:Be.badge}),Be.showDot&&s.jsx("span",{className:"absolute top-1.5 right-1.5 h-2 w-2 rounded-full bg-primary","aria-label":a("header.changes.availableAria")})]})}),s.jsx(At,{children:s.jsx("p",{children:Be.label})})]},Be.id)})})})})}),s.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[We&&s.jsx(sm,{projectRef:We.projectRef,directory:We.directory,compact:!0,allowMobile:!0,className:"h-9"}),s.jsxs(Ts,{open:Y,onOpenChange:Be=>{re(Be),Be&&T.length===0&&R()},children:[s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(As,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":a("header.services.viewAria"),className:_t,children:s.jsx(D,{name:"stack",className:"h-5 w-5"})})})}),s.jsx(At,{children:s.jsx("p",{children:a("header.services.title")})})]}),s.jsx(Ds,{align:"end",sideOffset:0,className:"h-dvh w-[100vw] max-h-none rounded-none border-0 p-0 overflow-hidden",children:s.jsxs("div",{className:"flex h-full flex-col bg-[var(--surface-elevated)]",children:[s.jsx("div",{className:"sticky top-0 z-20 bg-[var(--surface-elevated)] px-2 py-px",children:s.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-0",children:[s.jsx("div",{className:"h-10 min-w-0 flex-1",children:s.jsx($r,{items:Pn,activeId:$,onSelect:Be=>{const Dt=Be;je(Dt),Dt==="usage"&&T.length===0&&R()},layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",activePillButtonClassName:"h-8",className:"h-full"})}),s.jsx("button",{type:"button",onClick:()=>re(!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"})})]})}),$==="mcp"&&s.jsx(Ch,{active:Y&&$==="mcp"}),$==="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:Th(_)})]}),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:()=>rt("usage"),className:xe("typography-ui-label px-1 pb-0.5 transition-colors",U==="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:()=>rt("remaining"),className:xe("typography-ui-label px-1 pb-0.5 transition-colors",U==="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:xe("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:it,disabled:V||Ce,"aria-label":a("header.services.refreshRateLimitsAria"),children:s.jsx(D,{name:"refresh",className:xe("h-4 w-4",Ce&&"animate-spin")})})]})]})}),!ut&&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:Xe.map((Be,Dt)=>s.jsxs(l.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(pr,{providerId:Be.providerId,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:Be.providerName})]}),Be.entries.length===0&&(!Be.modelFamilies||Be.modelFamilies.length===0)?s.jsx("div",{className:"px-4 pb-2",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:Be.error??a("header.services.noRateLimitsReported")})}):s.jsxs("div",{className:"space-y-3 px-4 pb-2",children:[Be.entries.map(([Yt,Qt])=>{const vs=U==="remaining"?Qt.remainingPercent:Qt.usedPercent,Rs=no(Qt.usedPercent,Qt.resetAt,Qt.windowSeconds,Yt),Cs=Rs?.dailyAllocationPercent!=null?U==="remaining"?100-Jr(Rs.elapsedRatio):Jr(Rs.elapsedRatio):null,_s=so(Qt.valueLabel,vs),Qs=Vd(Qt.resetAt,Qt.resetAfterFormatted??Qt.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:Ud(Yt)}),Qs?s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:Qs}):null]}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:_s==="-"?"":_s})]}),s.jsx(ao,{percent:vs,tonePercent:Qt.usedPercent,className:"h-1.5",expectedMarkerPercent:Cs}),Rs?s.jsx(io,{paceInfo:Rs,compact:!0}):null]},`${Be.providerId}-${Yt}`)}),Be.modelFamilies&&Be.modelFamilies.length>0&&s.jsx("div",{className:"space-y-0.5",children:Be.modelFamilies.map(Yt=>{const vs=(at[Be.providerId]??[]).includes(Yt.familyId??"other");return s.jsxs(fr,{open:vs,onOpenChange:()=>Ye(Be.providerId,Yt.familyId??"other"),children:[s.jsxs(kr,{className:"flex w-full items-center justify-between rounded-md px-1 py-1.5 text-left hover:bg-[var(--interactive-hover)]/50 transition-colors",children:[s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:Yt.familyLabel}),vs?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(hr,{children:s.jsx("div",{className:"space-y-2.5 pb-1 pl-1 pt-1",children:Yt.models.map(([Rs,Cs])=>{const _s=U==="remaining"?Cs.remainingPercent:Cs.usedPercent,Qs=no(Cs.usedPercent,Cs.resetAt,Cs.windowSeconds),Fn=Qs?.dailyAllocationPercent!=null?U==="remaining"?100-Jr(Qs.elapsedRatio):Jr(Qs.elapsedRatio):null,gr=so(Cs.valueLabel,_s);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:ul(Rs)}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:gr==="-"?"":gr})]}),s.jsx(ao,{percent:_s,tonePercent:Cs.usedPercent,className:"h-1.5",expectedMarkerPercent:Fn}),Qs?s.jsx(io,{paceInfo:Qs,compact:!0}):null]},`${Be.providerId}-${Rs}`)})})})]},Yt.familyId??"other")})})]})]},Be.providerId))})]})]})})]}),e?s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:e,className:xe(_t,"relative",r&&"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(At,{children:s.jsx("p",{children:r?"Close git sidebar":"Open git sidebar"})})]}):null]})]})]}),tr=xe("header-safe-area relative z-10",F?"border-b border-border/50 bg-background":"bg-sidebar");return s.jsx("header",{ref:te,className:tr,style:{"--padding-scale":"1"},children:F?An():Js()})};function K1(){}const rm=180,am=640,H1=110,G1=t=>{const e=st.c(44),{isOpen:n,isMobile:r,children:a}=t,{t:i}=dt(),o=Re(q1),c=Re(J1),d=Re(Y1),p=Re(Q1),[m,u]=l.useState(null),[f,b]=l.useState(!1),h=l.useRef(null),v=l.useRef(0),x=l.useRef(o||300),g=Math.min(am,Math.max(rm,o||300));let w,y;e[0]!==n?(w=()=>{n||(u(null),b(!1))},y=[n],e[0]=n,e[1]=w,e[2]=y):(w=e[1],y=e[2]),l.useEffect(w,y);let C,k;e[3]!==c||e[4]!==r||e[5]!==n?(C=()=>{if(r||!n||!c)return;const Q=()=>{const fe=h.current?.parentElement?.getBoundingClientRect().height;if(!fe||fe<=0)return;const ue=Math.max(0,Math.round(fe));u(W=>W===ue?W:ue)};Q();const te=h.current?.parentElement;if(!te)return;const Z=new ResizeObserver(Q);return Z.observe(te),()=>{Z.disconnect()}},k=[c,r,n],e[3]=c,e[4]=r,e[5]=n,e[6]=C,e[7]=k):(C=e[6],k=e[7]),l.useEffect(C,k);let j,S;if(e[8]!==c||e[9]!==r||e[10]!==f||e[11]!==d||e[12]!==p?(j=()=>{if(r||!f||c)return;const Q=Z=>{const fe=v.current-Z.clientY,ue=Math.min(am,Math.max(rm,x.current+fe));d(ue)},te=()=>{b(!1),Re.getState().bottomTerminalHeight<=H1&&p(!1)};return window.addEventListener("pointermove",Q),window.addEventListener("pointerup",te,{once:!0}),()=>{window.removeEventListener("pointermove",Q),window.removeEventListener("pointerup",te)}},S=[c,r,f,d,p],e[8]=c,e[9]=r,e[10]=f,e[11]=d,e[12]=p,e[13]=j,e[14]=S):(j=e[13],S=e[14]),l.useEffect(j,S),r)return null;const I=n?c?Math.max(0,m??g):g:0,M=n&&c;let P;e[15]!==I||e[16]!==c||e[17]!==n?(P=Q=>{!n||c||(b(!0),v.current=Q.clientY,x.current=I,Q.preventDefault())},e[15]=I,e[16]=c,e[17]=n,e[18]=P):P=e[18];const A=P,N=M?"absolute inset-x-0 bottom-0 z-40":"relative",E=f?"transition-none":"transition-[height] duration-300 ease-in-out",T=(!n||M)&&"border-t-0";let R;e[19]!==T||e[20]!==N||e[21]!==E?(R=xe("flex overflow-hidden border-t border-border bg-sidebar",N,E,T),e[19]=T,e[20]=N,e[21]=E,e[22]=R):R=e[22];let V;e[23]!==I||e[24]!==M?(V=M?{top:0}:{height:`${I}px`,minHeight:`${I}px`,maxHeight:`${I}px`},e[23]=I,e[24]=M,e[25]=V):V=e[25];const _=!n||!c&&I===0;let U;e[26]!==A||e[27]!==c||e[28]!==n||e[29]!==f||e[30]!==i?(U=n&&!c&&s.jsx("div",{className:xe("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]=U):U=e[31];const B=!n&&"pointer-events-none select-none opacity-0";let z;e[32]!==B?(z=xe("relative z-10 flex h-full min-h-0 w-full flex-col transition-opacity duration-300 ease-in-out",B),e[32]=B,e[33]=z):z=e[33];const K=!n;let F;e[34]!==a||e[35]!==z||e[36]!==K?(F=s.jsx("div",{className:z,"aria-hidden":K,children:a}),e[34]=a,e[35]=z,e[36]=K,e[37]=F):F=e[37];let G;return e[38]!==R||e[39]!==V||e[40]!==_||e[41]!==U||e[42]!==F?(G=s.jsxs("section",{ref:h,className:R,style:V,"aria-hidden":_,children:[U,F]}),e[38]=R,e[39]=V,e[40]=_,e[41]=U,e[42]=F,e[43]=G):G=e[43],G};function q1(t){return t.bottomTerminalHeight}function J1(t){return t.isBottomTerminalExpanded}function Y1(t){return t.setBottomTerminalHeight}function Q1(t){return t.setBottomTerminalOpen}const ed=280,im=280,om=500,X1=({isOpen:t,isMobile:e,children:n,className:r})=>{const{t:a}=dt(),i=Re(j=>j.sidebarWidth),o=Re(j=>j.setSidebarWidth),[c,d]=l.useState(!1),p=l.useRef(0),m=l.useRef(i||ed),u=l.useRef(null),f=l.useRef(null),b=l.useRef(null),h=l.useCallback(j=>Math.min(om,Math.max(im,j)),[]),v=l.useCallback(j=>{const S=b.current;S&&(S.style.width=`${j}px`,S.style.minWidth=`${j}px`,S.style.maxWidth=`${j}px`,S.style.setProperty("--oc-left-sidebar-width",`${j}px`))},[]);if(l.useEffect(()=>{e&&c&&d(!1)},[e,c]),l.useEffect(()=>{c||(u.current=null,f.current=null)},[c]),e)return null;const x=Math.min(om,Math.max(im,i||ed)),g=t?x:0,w=j=>{if(t){try{j.currentTarget.setPointerCapture(j.pointerId)}catch{}f.current=j.pointerId,d(!0),p.current=j.clientX,m.current=g,u.current=g,v(g),j.preventDefault()}},y=j=>{if(e||!c||f.current!==j.pointerId)return;const S=j.clientX-p.current,I=h(m.current+S);u.current!==I&&(u.current=I,v(I))},C=j=>{if(f.current!==j.pointerId||e)return;try{j.currentTarget.releasePointerCapture(j.pointerId)}catch{}const S=h(u.current??g);f.current=null,u.current=null,d(!1),o(S)},k=c?u.current??g:g;return s.jsxs("aside",{ref:b,className:xe("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||g===0,children:[t&&s.jsx("div",{className:xe("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:w,onPointerMove:y,onPointerUp:C,onPointerCancel:C,role:"separator","aria-orientation":"vertical","aria-label":a("sidebar.resize.leftPanelAria")}),s.jsx("div",{className:xe("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(Ys,{children:n})})})]})},td=420,lm=360,cm=860,Z1=({isOpen:t,children:e,className:n})=>{const{t:r}=dt(),a=Re(k=>k.rightSidebarWidth),i=Re(k=>k.setRightSidebarWidth),[o,c]=l.useState(!1),d=l.useRef(0),p=l.useRef(a||td),m=l.useRef(null),u=l.useRef(null),f=l.useRef(null),b=l.useCallback(k=>Math.min(cm,Math.max(lm,k)),[]),h=l.useCallback(k=>{const j=f.current;j&&(j.style.width=`${k}px`,j.style.minWidth=`${k}px`,j.style.maxWidth=`${k}px`,j.style.setProperty("--oc-right-sidebar-width",`${k}px`))},[]),v=Math.min(cm,Math.max(lm,a||td)),x=t?v:0,g=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,h(x),k.preventDefault()}},w=k=>{if(!o||u.current!==k.pointerId)return;const j=d.current-k.clientX,S=b(p.current+j);m.current!==S&&(m.current=S,h(S))},y=k=>{if(u.current!==k.pointerId)return;try{k.currentTarget.releasePointerCapture(k.pointerId)}catch{}const j=b(m.current??x);u.current=null,m.current=null,c(!1),i(j)};l.useEffect(()=>{o||(m.current=null,u.current=null)},[o]);const C=o?m.current??x:x;return s.jsxs("aside",{ref:f,className:xe("relative flex h-full overflow-hidden border-l border-border/40 will-change-[width] motion-reduce:transition-none","bg-sidebar",!t&&"border-l-0",n),style:{width:`${C}px`,minWidth:`${C}px`,maxWidth:`${C}px`,"--oc-right-sidebar-width":`${o?C:v}px`,overflowX:"clip",transitionProperty:o?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!t||x===0,children:[t&&s.jsx("div",{className:xe("absolute left-0 top-0 z-20 h-full w-[3px] cursor-col-resize hover:bg-[var(--interactive-border)]/80 transition-colors",o&&"bg-[var(--interactive-border)]"),onPointerDown:g,onPointerMove:w,onPointerUp:y,onPointerCancel:y,role:"separator","aria-orientation":"vertical","aria-label":r("sidebar.resize.rightPanelAria")}),s.jsx("div",{className:xe("relative z-10 flex h-full min-h-0 shrink-0 flex-col transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",o&&"pointer-events-none",!t&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-right-sidebar-width)"},"aria-hidden":!t,children:t?e:null})]})},fo=t=>{const e=st.c(128),{providerId:n,modelId:r,onChange:a,className:i,allowedProviderIds:o,placeholder:c}=t,{t:d}=dt(),{isReady:p,isUnavailable:m}=Gf(),u=bt(ew),f=bt(tw),b=Re(sw),h=Re(nw),v=Re(rw),x=Re(aw),g=Re(iw),{favoriteModelsList:w,recentModelsList:y}=qf(),{isMobile:C}=nn(),k=b||C,[j,S]=l.useState(!1),[I,M]=l.useState(!1),[P,A]=l.useState("");let N;e[0]===Symbol.for("react.memo_cache_sentinel")?(N=()=>{S(!1),M(!1),A("")},e[0]=N):N=e[0];const E=N;let T;e[1]!==g||e[2]!==a?(T=Ce=>{a(Ce.providerID,Ce.modelID),g(Ce.providerID,Ce.modelID),E()},e[1]=g,e[2]=a,e[3]=T):T=e[3];const R=T;let V;e[4]!==a?(V=()=>{a("",""),E()},e[4]=a,e[5]=V):V=e[5];const _=V;let U;e[6]!==d?(U=d("settings.agents.modelSelector.searchPlaceholder"),e[6]=d,e[7]=U):U=e[7];let B;e[8]!==d?(B=d("settings.agents.modelSelector.state.noModelsFound"),e[8]=d,e[9]=B):B=e[9];let z;e[10]!==d?(z=d("settings.agents.modelSelector.section.favorites"),e[10]=d,e[11]=z):z=e[11];let K;e[12]!==d?(K=d("settings.agents.modelSelector.section.recent"),e[12]=d,e[13]=K):K=e[13];let F;e[14]!==d?(F=d("settings.agents.modelSelector.keyboardHints"),e[14]=d,e[15]=F):F=e[15];let G;e[16]!==c||e[17]!==d?(G=c||d("settings.agents.modelSelector.notSelected"),e[16]=c,e[17]=d,e[18]=G):G=e[18];let Q;e[19]!==d?(Q=d("settings.agents.modelSelector.actions.favorite"),e[19]=d,e[20]=Q):Q=e[20];let te;e[21]!==d?(te=d("settings.agents.modelSelector.actions.unfavorite"),e[21]=d,e[22]=te):te=e[22];let Z;e[23]!==d?(Z=d("chat.modelControls.capabilities"),e[23]=d,e[24]=Z):Z=e[24];let fe;e[25]!==d?(fe=d("chat.modelControls.capability.toolCalling"),e[25]=d,e[26]=fe):fe=e[26];let ue;e[27]!==d?(ue=d("chat.modelControls.capability.reasoning"),e[27]=d,e[28]=ue):ue=e[28];let W;e[29]!==d?(W=d("chat.modelControls.input"),e[29]=d,e[30]=W):W=e[30];let q;e[31]!==d?(q=d("chat.modelControls.output"),e[31]=d,e[32]=q):q=e[32];let J;e[33]!==d?(J=d("chat.modelControls.costPerMillion"),e[33]=d,e[34]=J):J=e[34];let ne;e[35]!==Q||e[36]!==te||e[37]!==Z||e[38]!==fe||e[39]!==ue||e[40]!==W||e[41]!==q||e[42]!==J||e[43]!==U||e[44]!==B||e[45]!==z||e[46]!==K||e[47]!==F||e[48]!==G?(ne={searchPlaceholder:U,noResults:B,favorites:z,recent:K,keyboardHint:F,notSelected:G,favorite:Q,unfavorite:te,capabilities:Z,capabilityToolCalling:fe,capabilityReasoning:ue,input:W,output:q,costPerMillion:J},e[35]=Q,e[36]=te,e[37]=Z,e[38]=fe,e[39]=ue,e[40]=W,e[41]=q,e[42]=J,e[43]=U,e[44]=B,e[45]=z,e[46]=K,e[47]=F,e[48]=G,e[49]=ne):ne=e[49];const ee=ne;let he;e[50]!==r||e[51]!==n?(he=n&&r?{providerID:n,modelID:r}:null,e[50]=r,e[51]=n,e[52]=he):he=e[52];const ke=he;let oe;e[53]!==r||e[54]!==c||e[55]!==n||e[56]!==d?(oe=n&&r?`${n}/${r}`:c||d("settings.agents.modelSelector.notSelected"),e[53]=r,e[54]=c,e[55]=n,e[56]=d,e[57]=oe):oe=e[57];const ge=oe,me=k?j:I;let ye;e[58]!==x?(ye=Ce=>x(Ce.providerID,Ce.modelID),e[58]=x,e[59]=ye):ye=e[59];let ie;e[60]!==v?(ie=Ce=>v(Ce.providerID,Ce.modelID),e[60]=v,e[61]=ie):ie=e[61];let ve;e[62]!==o||e[63]!==w||e[64]!==R||e[65]!==_||e[66]!==h||e[67]!==ee||e[68]!==f||e[69]!==u||e[70]!==y||e[71]!==P||e[72]!==ke||e[73]!==me||e[74]!==ye||e[75]!==ie?(ve=s.jsx(Jf,{providers:u,favoriteModels:w,recentModels:y,modelsMetadata:f,searchQuery:P,onSearchQueryChange:A,onSelect:R,labels:ee,selectedModel:ke,hiddenModels:h,allowedProviderIds:o,includeNotSelected:!0,onSelectNone:_,onEscape:E,tooltipsEnabled:me,isFavorite:ye,onToggleFavorite:ie}),e[62]=o,e[63]=w,e[64]=R,e[65]=_,e[66]=h,e[67]=ee,e[68]=f,e[69]=u,e[70]=y,e[71]=P,e[72]=ke,e[73]=me,e[74]=ye,e[75]=ie,e[76]=ve):ve=e[76];const X=ve;if(k){let Ce;e[77]!==p?(Ce=p?()=>S(!0):void 0,e[77]=p,e[78]=Ce):Ce=e[78];const Te=!p,$e=!p&&"opacity-60 cursor-not-allowed";let De;e[79]!==i||e[80]!==$e?(De=xe("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",$e,i),e[79]=i,e[80]=$e,e[81]=De):De=e[81];let de;e[82]!==p||e[83]!==m||e[84]!==n||e[85]!==d?(de=p?n?s.jsx(pr,{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]=de):de=e[86];let O;e[87]!==p||e[88]!==ge?(O=p?s.jsx("span",{className:"typography-meta font-medium text-foreground truncate",children:ge}):null,e[87]=p,e[88]=ge,e[89]=O):O=e[89];let L;e[90]!==de||e[91]!==O?(L=s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[de,O]}),e[90]=de,e[91]=O,e[92]=L):L=e[92];let $;e[93]===Symbol.for("react.memo_cache_sentinel")?($=s.jsx(D,{name:"arrow-down-s",className:"h-3 w-3 flex-shrink-0 text-muted-foreground"}),e[93]=$):$=e[93];let je;e[94]!==Ce||e[95]!==Te||e[96]!==De||e[97]!==L?(je=s.jsxs("button",{type:"button",onClick:Ce,disabled:Te,className:De,children:[L,$]}),e[94]=Ce,e[95]=Te,e[96]=De,e[97]=L,e[98]=je):je=e[98];let ae;e[99]!==d?(ae=d("settings.agents.modelSelector.title"),e[99]=d,e[100]=ae):ae=e[100];let _e;e[101]!==j||e[102]!==X||e[103]!==ae?(_e=s.jsx(Lr,{open:j,onClose:E,title:ae,children:X}),e[101]=j,e[102]=X,e[103]=ae,e[104]=_e):_e=e[104];let le;return e[105]!==je||e[106]!==_e?(le=s.jsxs(s.Fragment,{children:[je,_e]}),e[105]=je,e[106]=_e,e[107]=le):le=e[107],le}const Se=p&&I,Ae=p?M:void 0,pe=!p&&"opacity-60 cursor-not-allowed";let we;e[108]!==i||e[109]!==pe?(we=xe("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",pe,i),e[108]=i,e[109]=pe,e[110]=we):we=e[110];let Ie;e[111]!==p||e[112]!==m||e[113]!==n||e[114]!==d||e[115]!==ge?(Ie=p?s.jsxs(s.Fragment,{children:[n?s.jsx(pr,{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]=Ie):Ie=e[116];let Y;e[117]===Symbol.for("react.memo_cache_sentinel")?(Y=s.jsx(D,{name:"arrow-down-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/50"}),e[117]=Y):Y=e[117];let re;e[118]!==we||e[119]!==Ie?(re=s.jsx(As,{asChild:!0,children:s.jsxs("div",{className:we,children:[Ie,Y]})}),e[118]=we,e[119]=Ie,e[120]=re):re=e[120];let Pe;e[121]!==X?(Pe=s.jsx(Ds,{className:"w-[min(380px,calc(100vw-2rem))] p-0 flex flex-col",align:"start",children:X}),e[121]=X,e[122]=Pe):Pe=e[122];let ce;return e[123]!==Se||e[124]!==Ae||e[125]!==re||e[126]!==Pe?(ce=s.jsxs(Ts,{open:Se,onOpenChange:Ae,children:[re,Pe]}),e[123]=Se,e[124]=Ae,e[125]=re,e[126]=Pe,e[127]=ce):ce=e[127],ce};function ew(t){return t.providers}function tw(t){return t.modelsMetadata}function sw(t){return t.isMobile}function nw(t){return t.hiddenModels}function rw(t){return t.toggleFavoriteModel}function aw(t){return t.isFavoriteModel}function iw(t){return t.addRecentModel}const Ll=t=>{const e=st.c(34),{agentName:n,onChange:r,className:a,filter:i}=t,{t:o}=dt(),{isReady:c,isUnavailable:d}=Gf(),p=bt(ow),m=li(lw),u=li(cw),f=bt(dw);let b;e:{if(Array.isArray(p)&&p.length>0){b=p;break e}let _;e[0]!==m?(_=Array.isArray(m)?m:[],e[0]=m,e[1]=_):_=e[1],b=_}const h=b;let v;if(e[2]!==i||e[3]!==h){const _=sb(h);v=i?_.filter(i):_,e[2]=i,e[3]=h,e[4]=v}else v=e[4];const x=v,g=Re(uw),{isMobile:w}=nn(),y=g||w,[C,k]=l.useState(!1);let j,S;e[5]!==u||e[6]!==f||e[7]!==h.length?(j=()=>{h.length>0||(f(),u())},S=[h.length,f,u],e[5]=u,e[6]=f,e[7]=h.length,e[8]=j,e[9]=S):(j=e[8],S=e[9]),l.useEffect(j,S);let I;e[10]===Symbol.for("react.memo_cache_sentinel")?(I=()=>k(!1),e[10]=I):I=e[10];const M=I;let P;e[11]!==r?(P=_=>{r(_)},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]!==o?(N=()=>y?s.jsx(Lr,{open:C,onClose:M,title:o("settings.commands.agentSelector.title"),children:s.jsxs("div",{className:"space-y-1",children:[s.jsxs("button",{type:"button",className:xe("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(""),M()},children:[s.jsx("span",{className:xe("typography-meta",n?"text-muted-foreground":"font-medium"),children:o("settings.commands.agentSelector.notSelected")}),!n&&s.jsx("div",{className:"h-2 w-2 rounded-full bg-primary"})]}),x.map(_=>{const U=_.name===n;return s.jsxs("button",{type:"button",className:xe("flex w-full items-center justify-between rounded-lg border border-border/40 bg-background/95 px-2 py-1.5 text-left",U?"bg-primary/10 text-primary":"text-foreground"),onClick:()=>{A(_.name),M()},children:[s.jsxs("div",{className:"flex flex-col",children:[s.jsx("span",{className:"typography-meta font-medium",children:_.name}),_.description&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:_.description})]}),U&&s.jsx("div",{className:"h-2 w-2 rounded-full bg-primary"})]},_.name)})]})}):null,e[13]=n,e[14]=x,e[15]=A,e[16]=y,e[17]=C,e[18]=o,e[19]=N):N=e[19];const E=N;let T;e[20]!==n||e[21]!==x||e[22]!==a||e[23]!==A||e[24]!==y||e[25]!==c||e[26]!==d||e[27]!==o?(T=y?s.jsxs("button",{type:"button",onClick:c?()=>k(!0):void 0,disabled:!c,className:xe("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||o("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:o(d?"common.unavailable":"common.loading")})]})}),s.jsx(D,{name:"arrow-down-s",className:"h-3 w-3 text-muted-foreground"})]}):c?s.jsxs(Ts,{children:[s.jsx(As,{asChild:!0,children:s.jsxs("div",{className:xe("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||o("settings.commands.agentSelector.notSelected")}),s.jsx(D,{name:"arrow-down-s",className:"h-3 w-3 flex-shrink-0 text-muted-foreground"})]})}),s.jsxs(Ds,{className:"max-w-[300px]",children:[s.jsx($t,{className:"typography-meta",onSelect:()=>A(""),children:s.jsx("span",{className:"text-muted-foreground",children:o("settings.commands.agentSelector.notSelected")})}),x.map(_=>s.jsx($t,{className:"typography-meta",onSelect:()=>A(_.name),children:s.jsx("span",{className:"font-medium",children:_.name})},_.name))]})]}):s.jsxs("div",{className:xe("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:o(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]=o,e[28]=T):T=e[28];let R;e[29]!==E?(R=E(),e[29]=E,e[30]=R):R=e[30];let V;return e[31]!==T||e[32]!==R?(V=s.jsxs(s.Fragment,{children:[T,R]}),e[31]=T,e[32]=R,e[33]=V):V=e[33],V};function ow(t){return t.agents}function lw(t){return t.agents}function cw(t){return t.loadAgents}function dw(t){return t.loadAgents}function uw(t){return t.isMobile}const dm=t=>({providerID:t.providerID,modelID:t.modelID,variant:t.variant,agent:t.agent}),mw=t=>{const e=st.c(38),{value:n,options:r,disabled:a,onChange:i}=t,{t:o}=dt();let c;e[0]!==o||e[1]!==n?(c=n||o("rightSidebar.contextNotesTodo.sendDialog.variant.default"),e[0]=o,e[1]=n,e[2]=c):c=e[2];const d=c,p=a?"cursor-not-allowed opacity-60":"cursor-pointer hover:bg-interactive-hover/30";let m;e[3]!==p?(m=xe("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 h=b;if(a)return h;let v;e[11]!==h?(v=s.jsx(As,{asChild:!0,children:h}),e[11]=h,e[12]=v):v=e[12];let x;e[13]!==i?(x=()=>i(""),e[13]=i,e[14]=x):x=e[14];const g=!n&&"text-primary";let w;e[15]!==g?(w=xe("font-medium",g),e[15]=g,e[16]=w):w=e[16];let y;e[17]!==o?(y=o("rightSidebar.contextNotesTodo.sendDialog.variant.default"),e[17]=o,e[18]=y):y=e[18];let C;e[19]!==w||e[20]!==y?(C=s.jsx("span",{className:w,children:y}),e[19]=w,e[20]=y,e[21]=C):C=e[21];let k;e[22]!==C||e[23]!==x?(k=s.jsx($t,{className:"typography-meta",onSelect:x,children:C}),e[22]=C,e[23]=x,e[24]=k):k=e[24];let j;if(e[25]!==i||e[26]!==r||e[27]!==n){let M;e[29]!==i||e[30]!==n?(M=P=>s.jsx($t,{className:"typography-meta",onSelect:()=>i(P),children:s.jsx("span",{className:xe("font-medium capitalize",n===P&&"text-primary"),children:P})},P),e[29]=i,e[30]=n,e[31]=M):M=e[31],j=r.map(M),e[25]=i,e[26]=r,e[27]=n,e[28]=j}else j=e[28];let S;e[32]!==k||e[33]!==j?(S=s.jsxs(Ds,{align:"start",className:"max-w-[220px]",children:[k,j]}),e[32]=k,e[33]=j,e[34]=S):S=e[34];let I;return e[35]!==S||e[36]!==v?(I=s.jsxs(Ts,{children:[v,S]}),e[35]=S,e[36]=v,e[37]=I):I=e[37],I};function Mh(t){const e=st.c(99),{t:n}=dt(),{open:r,onOpenChange:a,target:i,projectDirectory:o,submitting:c,onConfirm:d}=t,p=c===void 0?!1:c,m=bt(jw),u=bt(ww),f=li(vw),b=bt(yw),h=bt(bw),v=bt(xw),x=bt(gw),g=bt(hw);let w;e[0]!==g||e[1]!==v||e[2]!==h||e[3]!==x?(w=()=>dm({providerID:h,modelID:v,variant:x,agent:g}),e[0]=g,e[1]=v,e[2]=h,e[3]=x,e[4]=w):w=e[4];const[y,C]=l.useState(w);let k,j;e[5]!==f||e[6]!==u||e[7]!==m||e[8]!==r||e[9]!==o?(k=()=>{r&&(m({directory:o}),u({directory:o}),f())},j=[r,m,u,f,o],e[5]=f,e[6]=u,e[7]=m,e[8]=r,e[9]=o,e[10]=k,e[11]=j):(k=e[10],j=e[11]),l.useEffect(k,j);let S,I;e[12]!==g||e[13]!==v||e[14]!==h||e[15]!==x||e[16]!==r?(S=()=>{r&&C(dm({providerID:h,modelID:v,variant:x,agent:g}))},I=[r,h,v,x,g],e[12]=g,e[13]=v,e[14]=h,e[15]=x,e[16]=r,e[17]=S,e[18]=I):(S=e[17],I=e[18]),l.useEffect(S,I);let M,P;e[19]!==y.modelID||e[20]!==y.providerID||e[21]!==r||e[22]!==b?(M=()=>{if(!r||b.length===0)return;const we=b.find(Pe=>Pe.id===y.providerID)??b[0],Ie=Array.isArray(we?.models)?we.models:[],Y=Ie.some(Pe=>Pe.id===y.modelID),re=Ie[0]?.id??"";we?.id===y.providerID&&Y||C(Pe=>({...Pe,providerID:we?.id??"",modelID:Y?Pe.modelID:re,variant:""}))},P=[r,b,y.providerID,y.modelID],e[19]=y.modelID,e[20]=y.providerID,e[21]=r,e[22]=b,e[23]=M,e[24]=P):(M=e[23],P=e[24]),l.useEffect(M,P);const A=fw;let N;if(e[25]!==y.modelID||e[26]!==y.providerID||e[27]!==b){let we;e[29]!==y.providerID?(we=Y=>Y.id===y.providerID,e[29]=y.providerID,e[30]=we):we=e[30],N=b.find(we)?.models?.find(Y=>Y.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 T;e[31]!==E?(T=E?.variants?Object.keys(E.variants):[],e[31]=E,e[32]=T):T=e[32];const R=T,V=R.length>0;let _,U;e[33]!==y.variant||e[34]!==V?(_=()=>{V||!y.variant||C(pw)},U=[V,y.variant],e[33]=y.variant,e[34]=V,e[35]=_,e[36]=U):(_=e[35],U=e[36]),l.useEffect(_,U);let B;e[37]!==y.modelID||e[38]!==y.providerID?(B=y.providerID.trim().length>0&&y.modelID.trim().length>0,e[37]=y.modelID,e[38]=y.providerID,e[39]=B):B=e[39];const z=B;let K;e[40]!==z||e[41]!==y||e[42]!==d||e[43]!==p?(K=()=>{!z||p||d(y)},e[40]=z,e[41]=y,e[42]=d,e[43]=p,e[44]=K):K=e[44];const F=K;let G,Q;e[45]!==F||e[46]!==r?(G=()=>{if(!r)return;const we=Ie=>{(Ie.metaKey||Ie.ctrlKey)&&Ie.key==="Enter"&&(Ie.preventDefault(),F())};return window.addEventListener("keydown",we),()=>window.removeEventListener("keydown",we)},Q=[r,F],e[45]=F,e[46]=r,e[47]=G,e[48]=Q):(G=e[47],Q=e[48]),l.useEffect(G,Q);let te;e[49]!==n||e[50]!==i?(te=n(i==="worktree"?"rightSidebar.contextNotesTodo.sendDialog.title.newWorktree":"rightSidebar.contextNotesTodo.sendDialog.title.newSession"),e[49]=n,e[50]=i,e[51]=te):te=e[51];const Z=te;let fe;e[52]!==a||e[53]!==p?(fe=we=>{p||a(we)},e[52]=a,e[53]=p,e[54]=fe):fe=e[54];let ue;e[55]!==Z?(ue=s.jsx(ys,{children:s.jsx(hs,{children:Z})}),e[55]=Z,e[56]=ue):ue=e[56];let W;e[57]===Symbol.for("react.memo_cache_sentinel")?(W=(we,Ie)=>{C(Y=>({...Y,providerID:we,modelID:Ie,variant:""}))},e[57]=W):W=e[57];let q;e[58]!==y.modelID||e[59]!==y.providerID?(q=s.jsx(fo,{providerId:y.providerID,modelId:y.modelID,onChange:W}),e[58]=y.modelID,e[59]=y.providerID,e[60]=q):q=e[60];const J=!V;let ne;e[61]===Symbol.for("react.memo_cache_sentinel")?(ne=we=>C(Ie=>({...Ie,variant:we})),e[61]=ne):ne=e[61];let ee;e[62]!==y.variant||e[63]!==J||e[64]!==R?(ee=s.jsx(mw,{value:y.variant,options:R,disabled:J,onChange:ne}),e[62]=y.variant,e[63]=J,e[64]=R,e[65]=ee):ee=e[65];let he;e[66]===Symbol.for("react.memo_cache_sentinel")?(he=we=>C(Ie=>({...Ie,agent:we})),e[66]=he):he=e[66];let ke;e[67]!==y.agent?(ke=s.jsx(Ll,{agentName:y.agent,filter:A,onChange:he}),e[67]=y.agent,e[68]=ke):ke=e[68];let oe;e[69]!==q||e[70]!==ee||e[71]!==ke?(oe=s.jsxs("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-2",children:[q,ee,ke]}),e[69]=q,e[70]=ee,e[71]=ke,e[72]=oe):oe=e[72];let ge;e[73]!==a?(ge=()=>a(!1),e[73]=a,e[74]=ge):ge=e[74];let me;e[75]!==n?(me=n("rightSidebar.contextNotesTodo.sendDialog.actions.cancel"),e[75]=n,e[76]=me):me=e[76];let ye;e[77]!==p||e[78]!==ge||e[79]!==me?(ye=s.jsx(be,{variant:"ghost",size:"sm",onClick:ge,disabled:p,children:me}),e[77]=p,e[78]=ge,e[79]=me,e[80]=ye):ye=e[80];const ie=!z||p;let ve;e[81]!==p||e[82]!==n?(ve=n(p?"rightSidebar.contextNotesTodo.sendDialog.actions.sending":"rightSidebar.contextNotesTodo.sendDialog.actions.send"),e[81]=p,e[82]=n,e[83]=ve):ve=e[83];let X;e[84]!==F||e[85]!==ie||e[86]!==ve?(X=s.jsx(be,{size:"sm",onClick:F,disabled:ie,children:ve}),e[84]=F,e[85]=ie,e[86]=ve,e[87]=X):X=e[87];let Se;e[88]!==ye||e[89]!==X?(Se=s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[ye,X]}),e[88]=ye,e[89]=X,e[90]=Se):Se=e[90];let Ae;e[91]!==ue||e[92]!==oe||e[93]!==Se?(Ae=s.jsxs(ms,{className:"max-w-lg",children:[ue,oe,Se]}),e[91]=ue,e[92]=oe,e[93]=Se,e[94]=Ae):Ae=e[94];let pe;return e[95]!==r||e[96]!==fe||e[97]!==Ae?(pe=s.jsx(ps,{open:r,onOpenChange:fe,children:Ae}),e[95]=r,e[96]=fe,e[97]=Ae,e[98]=pe):pe=e[98],pe}function pw(t){return{...t,variant:""}}function fw(t){return Yf(t.mode)}function hw(t){return t.currentAgentName||""}function gw(t){return t.currentVariant||""}function xw(t){return t.currentModelId}function bw(t){return t.currentProviderId}function yw(t){return t.providers}function vw(t){return t.loadAgents}function ww(t){return t.loadAgents}function jw(t){return t.loadProviders}const sd=5,Eh=15,qo=t=>{const e=Math.sqrt(t/100),n=12*e,r=24*e;return Math.ceil(n+r+1)},Nw=(t,e)=>{const n=qo(e);return Math.max(n*sd,Math.min(n*Eh,n*t))},Sw=async(t,e)=>{const n=await ib(t.path);return{...t,title:n?.title||t.path.split("/").pop()||e}},kw=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`todo_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,Cw=t=>{const e=st.c(20),{id:n,children:r}=t;let a;e[0]!==n?(a={id:n},e[0]=n,e[1]=a):a=e[1];const{attributes:i,listeners:o,setNodeRef:c,setActivatorNodeRef:d,transform:p,transition:m,isDragging:u}=Sl(a);let f;e[2]!==p?(f=kl.Transform.toString(p),e[2]=p,e[3]=f):f=e[3];let b;e[4]!==f||e[5]!==m?(b={transform:f,transition:m},e[4]=f,e[5]=m,e[6]=b):b=e[6];const h=u&&"opacity-60";let v;e[7]!==h?(v=xe(h),e[7]=h,e[8]=v):v=e[8];let x;e[9]!==i||e[10]!==r||e[11]!==u||e[12]!==o||e[13]!==d?(x=r({attributes:i,listeners:o,setActivatorNodeRef:d,isDragging:u}),e[9]=i,e[10]=r,e[11]=u,e[12]=o,e[13]=d,e[14]=x):x=e[14];let g;return e[15]!==c||e[16]!==b||e[17]!==v||e[18]!==x?(g=s.jsx("li",{ref:c,style:b,className:v,children:x}),e[15]=c,e[16]=b,e[17]=v,e[18]=x,e[19]=g):g=e[19],g},Iw=({projectRef:t,projectLabel:e,canCreateWorktree:n=!1,onActionComplete:r,className:a})=>{const{t:i}=dt(),[o,c]=l.useState(!1),[d,p]=l.useState(""),[m,u]=l.useState([]),[f,b]=l.useState(""),[h,v]=l.useState(null),[x,g]=l.useState(()=>new Set),[w,y]=l.useState([]),[C,k]=l.useState(null),[j,S]=l.useState(!1),[I,M]=l.useState(0),P=l.useRef(!1),A=l.useRef(""),N=Re(O=>O.todoPanelHeight),E=Re(O=>O.setTodoPanelHeight),T=Re(O=>O.notesPanelHeight),R=Re(O=>O.setNotesPanelHeight),[V,_]=l.useState(!1),U=l.useRef(0),B=l.useRef(N),z=Lt(O=>O.currentSessionId),K=Lt(O=>O.createSession),F=Lt(O=>O.initializeNewOpenChamberSession),G=Lt(O=>O.sendMessage),Q=Lt(O=>O.setCurrentSession),te=Ra(O=>O.setPendingInputText),Z=zs(O=>O.currentDirectory),fe=Re(O=>O.openContextPanelTab),ue=Re(O=>O.setActiveMainTab),W=Re(O=>O.setSessionSwitcherOpen),q=Re(O=>O.padding),J=l.useCallback(async(O,L)=>{if(!t)return!1;const $=await nb(t,{notes:O,todos:L});return $||H.error(i("rightSidebar.contextNotesTodo.toast.saveNotesFailed")),$},[t,i]);l.useEffect(()=>{if(!t){p(""),u([]),y([]),b(""),g(new Set);return}let O=!1;return c(!0),(async()=>{try{const L=await rb(t),$=await Promise.all(L.plans.map(je=>Sw(je,i("rightSidebar.contextNotesTodo.plan.defaultTitle"))));if(O)return;p(L.notes),u(L.todos),y($),A.current=L.notes,P.current=!0,b(""),g(new Set)}catch{O||(H.error(i("rightSidebar.contextNotesTodo.toast.loadNotesFailed")),p(""),u([]),y([]),A.current="",P.current=!0)}finally{O||c(!1)}})(),()=>{O=!0}},[I,t,i]),l.useEffect(()=>{if(!t)return;const O=L=>{const $=L.detail;$?.projectId&&$.projectId!==t.id||M(je=>je+1)};return window.addEventListener("openchamber:project-plan-saved",O),window.addEventListener("openchamber:project-notes-updated",O),()=>{window.removeEventListener("openchamber:project-plan-saved",O),window.removeEventListener("openchamber:project-notes-updated",O)}},[t]),l.useEffect(()=>{if(m.length<7)return;const O=Nw(m.length,q),L=qo(q)*sd;(N<L||N>O)&&E(O)},[m.length,q,N,E]),l.useEffect(()=>{if(!V)return;const O=$=>{const je=$.clientY-U.current,ae=Math.min(qo(q)*Eh,Math.max(qo(q)*sd,B.current+je));E(ae)},L=()=>{_(!1)};return window.addEventListener("pointermove",O),window.addEventListener("pointerup",L,{once:!0}),window.addEventListener("pointercancel",L,{once:!0}),()=>{window.removeEventListener("pointermove",O),window.removeEventListener("pointerup",L),window.removeEventListener("pointercancel",L)}},[V,q,E]);const ne=l.useCallback(O=>{_(!0),U.current=O.clientY,B.current=N,O.preventDefault()},[N]),ee=l.useCallback(()=>{A.current=d,J(d,m)},[d,J,m]);l.useEffect(()=>{if(!t||!P.current||d===A.current)return;const O=window.setTimeout(()=>{A.current=d,J(d,m)},400);return()=>{window.clearTimeout(O)}},[d,J,t,m]);const he=l.useCallback(()=>{const O=f.trim();if(!O)return;const L=[...m,{id:kw(),text:O.slice(0,wo),completed:!1,createdAt:Date.now()}];u(L),b(""),J(d,L)},[f,d,J,m]),ke=l.useCallback(O=>{g(L=>{const $=new Set(L);return $.has(O)?$.delete(O):$.add(O),$})},[]),oe=l.useCallback((O,L)=>{const $=m.map(je=>je.id===O?{...je,completed:L}:je);u($),J(d,$)},[d,J,m]),ge=l.useCallback(O=>{const L=m.filter($=>$.id!==O);u(L),J(d,L)},[d,J,m]),me=l.useCallback(()=>{const O=m.filter(L=>!L.completed);O.length!==m.length&&(u(O),J(d,O))},[d,J,m]),ye=l.useCallback(O=>{const{active:L,over:$}=O;if(!$||L.id===$.id)return;const je=m.findIndex(le=>le.id===L.id),ae=m.findIndex(le=>le.id===$.id);if(je===-1||ae===-1)return;const _e=Mf(m,je,ae);u(_e),J(d,_e)},[d,J,m]),ie=Ji(ti(Yi,{activationConstraint:{distance:8}})),ve=f.slice(0,wo),X=m.reduce((O,L)=>O+(L.completed?1:0),0),Se=l.useCallback(()=>{ue("chat"),W(!1)},[ue,W]),Ae=l.useCallback((O,L)=>{!t||h||k({kind:"session",todoId:O,todoText:L})},[t,h]),pe=l.useCallback(O=>{if(!z){H.error(i("rightSidebar.contextNotesTodo.toast.noActiveSession"));return}Se();const L=`\`\`\`md
4
+ ${O}
5
+ \`\`\``;te(L,"append"),H.success(i("rightSidebar.contextNotesTodo.toast.sentToCurrentSession")),r?.()},[z,r,Se,te,i]),we=l.useCallback((O,L)=>{if(!(!t||h)){if(!n){H.error(i("rightSidebar.contextNotesTodo.toast.worktreeRequiresGitRepo"));return}k({kind:"worktree",todoId:O,todoText:L})}},[n,t,h,i]),Ie=l.useCallback(async O=>{if(!t||!C)return;const L=await yn("plan.todo.visible",{todo_text:C.todoText}),je=[{synthetic:!0,text:await yn("plan.todo.instructions",{todo_text:C.todoText})}];S(!0),v(C.todoId);try{Se();let ae=null,_e=t.path;if(C.kind==="worktree"){if(!n){H.error(i("rightSidebar.contextNotesTodo.toast.worktreeRequiresGitRepo"));return}const Me=await Qf(t.path,Xf());if(!Me?.id)return;ae=Me.id,_e=null}else{const Me=await K(void 0,t.path,null);if(!Me?.id){H.error(i("rightSidebar.contextNotesTodo.toast.createSessionFailed"));return}ae=Me.id,_e=Me.directory??t.path,F(Me.id,bt.getState().agents??[])}if(!ae)return;const le=Pl.getState();le.saveSessionModelSelection(ae,O.providerID,O.modelID),O.agent.trim()&&(le.saveSessionAgentSelection(ae,O.agent),le.saveAgentModelForSession(ae,O.agent,O.providerID,O.modelID),le.saveAgentModelVariantForSession(ae,O.agent,O.providerID,O.modelID,O.variant||void 0)),Q(ae,_e),await G(L,O.providerID,O.modelID,O.agent.trim()||void 0,void 0,void 0,je,O.variant||void 0),H.success(C.kind==="worktree"?i("rightSidebar.contextNotesTodo.toast.sentToNewWorktreeSession"):i("rightSidebar.contextNotesTodo.toast.sentToNewSession")),k(null),r?.()}catch(ae){const _e=ae instanceof Error?ae.message:void 0;H.error(i("rightSidebar.contextNotesTodo.toast.sendTodoFailed"),_e?{description:_e}:void 0)}finally{S(!1),v(null)}},[n,K,F,r,C,t,Se,G,Q,i]),Y=l.useRef(null),[re,Pe]=l.useState(!1),[ce,Ce]=l.useState(null),Te=l.useCallback(async O=>{if(!(!t||ce)){Ce(O);try{if(!await ab(t,O)){H.error(i("rightSidebar.contextNotesTodo.toast.deletePlanFailed"));return}y($=>$.filter(je=>je.id!==O)),window.dispatchEvent(new CustomEvent("openchamber:project-plan-saved",{detail:{projectId:t.id}}))}finally{Ce(null)}}},[ce,t,i]),$e=l.useCallback(async()=>{if(!t||re)return;const O=await Zf({defaultPath:t.path,filters:[{name:"Plan files",extensions:["md","markdown","txt"]},{name:"All files",extensions:["*"]}]});if(O.success&&O.path){Pe(!0);try{const L=new URLSearchParams({path:O.path,allowOutsideWorkspace:"true"}),$=await fetch(`/api/fs/read?${L.toString()}`,{cache:"no-store"});if(!$.ok){H.error(i("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"));return}const je=await $.text();if(!je.trim()){H.error(i("rightSidebar.contextNotesTodo.toast.planFileEmpty"));return}const ae=O.path.split("/").pop()?.replace(/\.(md|markdown|txt)$/i,"").trim()||"";if(!await yu(t,je,ae)){H.error(i("rightSidebar.contextNotesTodo.toast.importPlanFailed"));return}window.dispatchEvent(new CustomEvent("openchamber:project-plan-saved",{detail:{projectId:t.id}})),H.success(i("rightSidebar.contextNotesTodo.toast.planImported"))}catch(L){const $=L instanceof Error?L.message:void 0;H.error(i("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"),$?{description:$}:void 0)}finally{Pe(!1)}}else O.error==="Native file picker not available"&&Y.current?.click()},[re,t,i]),De=l.useCallback(async O=>{if(!(!t||!O)){Pe(!0);try{const L=await O.text();if(!L.trim()){H.error(i("rightSidebar.contextNotesTodo.toast.planFileEmpty"));return}const $=O.name.replace(/\.(md|markdown|txt)$/i,"").trim();if(!await yu(t,L,$)){H.error(i("rightSidebar.contextNotesTodo.toast.importPlanFailed"));return}window.dispatchEvent(new CustomEvent("openchamber:project-plan-saved",{detail:{projectId:t.id}})),H.success(i("rightSidebar.contextNotesTodo.toast.planImported"))}catch(L){const $=L instanceof Error?L.message:void 0;H.error(i("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"),$?{description:$}:void 0)}finally{Pe(!1)}}},[t,i]),de=l.useCallback(O=>{const L=t?.path?.trim(),$=Z?.trim()||L;$&&fe($,{mode:"plan",targetPath:O.path,dedupeKey:O.path,label:O.title})},[Z,fe,t]);return t?s.jsxs("div",{className:xe("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,"/",vu]})]}),s.jsx(un,{value:d,onChange:O=>p(O.target.value.slice(0,vu)),onBlur:ee,placeholder:i("rightSidebar.contextNotesTodo.notes.placeholder"),resizedHeight:T,onResizeHeightChange:R,useScrollShadow:!0,scrollShadowSize:56,disabled:o})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-label font-semibold text-foreground",children:i("rightSidebar.contextNotesTodo.todo.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:m.length===1?i("rightSidebar.contextNotesTodo.todo.itemsSingle",{count:m.length}):i("rightSidebar.contextNotesTodo.todo.itemsPlural",{count:m.length})}),s.jsx("button",{type:"button",onClick:me,disabled:o||X===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:[ve.length,"/",wo]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Bt,{value:ve,onChange:O=>b(O.target.value.slice(0,wo)),onKeyDown:O=>{O.key==="Enter"&&(O.preventDefault(),he())},placeholder:i("rightSidebar.contextNotesTodo.todo.inputPlaceholder"),disabled:o,className:"h-8"}),s.jsx("button",{type:"button",onClick:he,disabled:o||ve.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:xe("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(Qi,{sensors:ie,collisionDetection:Xi,onDragEnd:ye,children:s.jsx(rl,{items:m.map(O=>O.id),strategy:Vc,children:s.jsx("ul",{className:"divide-y divide-border/50",children:m.map(O=>{const L=x.has(O.id);return s.jsx(Cw,{id:O.id,children:$=>s.jsxs("div",{className:"flex items-start gap-1.5 px-2.5 py-1.5",children:[s.jsx("button",{type:"button",ref:$.setActivatorNodeRef,...$.attributes,...$.listeners,onClick:je=>{je.preventDefault(),je.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:O.text}),title:i("rightSidebar.contextNotesTodo.todo.actions.reorder",{text:O.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(fs,{checked:O.completed,onChange:je=>oe(O.id,je),ariaLabel:i("rightSidebar.contextNotesTodo.todo.actions.markComplete",{text:O.text})})}),s.jsx("button",{type:"button",onClick:()=>ke(O.id),className:xe("block min-h-6 min-w-0 flex-1 bg-transparent p-0 text-left typography-ui-label leading-6 text-foreground",L?"whitespace-normal break-words":"overflow-hidden text-ellipsis whitespace-nowrap","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",O.completed&&"text-muted-foreground line-through"),title:L?void 0:O.text,"aria-label":L?i("rightSidebar.contextNotesTodo.todo.actions.collapse",{text:O.text}):i("rightSidebar.contextNotesTodo.todo.actions.expand",{text:O.text}),children:O.text}),s.jsxs("div",{className:"flex h-6 items-center gap-0.5",children:[s.jsx("button",{type:"button",onClick:()=>ge(O.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:O.text}),title:i("rightSidebar.contextNotesTodo.todo.actions.delete",{text:O.text}),children:s.jsx(D,{name:"delete-bin",className:"h-3.5 w-3.5"})}),s.jsxs(Ts,{children:[s.jsx(As,{asChild:!0,children:s.jsx("button",{type:"button",disabled:h===O.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:O.text}),title:i("rightSidebar.contextNotesTodo.todo.actions.send",{text:O.text}),children:s.jsx(D,{name:"send-plane",className:"h-3.5 w-3.5"})})}),s.jsxs(Ds,{align:"end",className:"w-56",children:[s.jsx($t,{onClick:()=>pe(O.text),children:i("rightSidebar.contextNotesTodo.todo.sendMenu.currentSession")}),s.jsx($t,{onClick:()=>Ae(O.id,O.text),children:i("rightSidebar.contextNotesTodo.todo.sendMenu.newSession")}),s.jsx($t,{onClick:()=>{we(O.id,O.text)},disabled:!n,children:i("rightSidebar.contextNotesTodo.todo.sendMenu.newWorktreeSession")})]})]})]})]})},O.id)})})})})}),m.length>=7&&s.jsx("div",{className:xe("h-[3px] w-full cursor-row-resize hover:bg-[var(--interactive-border)]/80 transition-colors",V&&"bg-[var(--interactive-border)]"),onPointerDown:ne,role:"separator","aria-orientation":"horizontal","aria-label":i("rightSidebar.contextNotesTodo.todo.resizeAria")})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-label font-semibold text-foreground",children:i("rightSidebar.contextNotesTodo.plans.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:w.length===1?i("rightSidebar.contextNotesTodo.plans.filesSingle",{count:w.length}):i("rightSidebar.contextNotesTodo.plans.filesPlural",{count:w.length})})]}),s.jsx("input",{ref:Y,type:"file",accept:".md,.markdown,.txt,text/markdown,text/plain",className:"hidden",onChange:O=>{const L=O.target.files?.[0]??null;De(L),O.currentTarget.value=""}}),s.jsx("button",{type:"button",onClick:$e,disabled:!t||re,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:w.length===0?s.jsx("p",{className:"px-3 py-3 typography-meta text-muted-foreground",children:i("rightSidebar.contextNotesTodo.plans.empty")}):s.jsx("ul",{className:"divide-y divide-border/50",children:w.map(O=>s.jsxs("li",{className:"flex items-center gap-1.5 px-2.5 py-1.5",children:[s.jsxs("button",{type:"button",onClick:()=>de(O),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:O.title}),s.jsx("span",{className:"flex-shrink-0 typography-micro text-muted-foreground",children:new Date(O.createdAt).toLocaleDateString()})]}),s.jsx("button",{type:"button",onClick:()=>{Te(O.id)},disabled:ce===O.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:O.title}),children:s.jsx(D,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},O.id))})})]}),s.jsx(Mh,{open:C!==null,onOpenChange:O=>{!O&&!j&&k(null)},target:C?.kind??"session",projectDirectory:t?.path??null,submitting:j,onConfirm:Ie})]}):s.jsx("div",{className:xe("w-full min-w-0 p-3",a),children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:i("rightSidebar.contextNotesTodo.empty.selectProject")})})},Rh=12,Pw=[{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"}],Aw=t=>{const e=st.c(18),{isActive:n,burstKey:r,className:a,durationMs:i,bursts:o,onComplete:c}=t,d=r===void 0?0:r,p=i===void 0?900:i,m=o===void 0?Pw:o,u=Oe.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]),Oe.useEffect(f,b);let h;e[4]===Symbol.for("react.memo_cache_sentinel")?(h=Array.from({length:Rh},Dw),e[4]=h):h=e[4];const v=h;if(!n)return null;let x;e[5]!==a?(x=xe("fireworks-overlay pointer-events-none",a),e[5]=a,e[6]=x):x=e[6];let g;if(e[7]!==d||e[8]!==m||e[9]!==p){let y;e[11]!==d||e[12]!==p?(y=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((j,S)=>{const I=j.x*C.radius,M=j.y*C.radius,P={"--translate-x":`${I}px`,"--translate-y":`${M}px`,"--particle-delay":`${j.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],g=m.map(y),e[7]=d,e[8]=m,e[9]=p,e[10]=g}else g=e[10];let w;return e[14]!==d||e[15]!==x||e[16]!==g?(w=s.jsx("div",{className:x,"aria-hidden":"true","data-burst-key":d,children:g}),e[14]=d,e[15]=x,e[16]=g,e[17]=w):w=e[17],w};function Dw(t,e){const n=Math.PI*2*e/Rh;return{x:Math.cos(n),y:Math.sin(n),delay:e*18}}const Tw=t=>{const e=st.c(13);let n;e[0]!==t?(n={},e[0]=t,e[1]=n):n=e[1];const{durationMs:r}=n,a=r===void 0?3400:r;let i;e[2]===Symbol.for("react.memo_cache_sentinel")?(i={isActive:!1,cycle:0},e[2]=i):i=e[2];const[o,c]=Oe.useState(i),d=Oe.useRef(null);let p;e[3]===Symbol.for("react.memo_cache_sentinel")?(p=()=>{d.current&&(window.clearTimeout(d.current),d.current=null)},e[3]=p):p=e[3];const m=p;let u;e[4]===Symbol.for("react.memo_cache_sentinel")?(u=()=>{m(),c(Mw)},e[4]=u):u=e[4];const f=u;let b;e[5]!==a?(b=()=>{m(),c(Ew),d.current=window.setTimeout(()=>{c(Rw),d.current=null},a)},e[5]=a,e[6]=b):b=e[6];const h=b;let v,x;e[7]===Symbol.for("react.memo_cache_sentinel")?(v=()=>()=>m(),x=[m],e[7]=v,e[8]=x):(v=e[7],x=e[8]),Oe.useEffect(v,x);let g;return e[9]!==o.cycle||e[10]!==o.isActive||e[11]!==h?(g={isActive:o.isActive,burstKey:o.cycle,triggerFireworks:h,dismissFireworks:f},e[9]=o.cycle,e[10]=o.isActive,e[11]=h,e[12]=g):g=e[12],g};function Mw(t){return t.isActive?{...t,isActive:!1}:t}function Ew(t){return{isActive:!0,cycle:t.cycle+1}}function Rw(t){return t.isActive?{...t,isActive:!1}:t}const Fh=l.createContext(void 0),Fw=t=>{const e=st.c(10),{children:n}=t,{isActive:r,burstKey:a,triggerFireworks:i,dismissFireworks:o}=Tw();let c;e[0]!==o||e[1]!==i?(c={triggerFireworks:i,dismissFireworks:o},e[0]=o,e[1]=i,e[2]=c):c=e[2];const d=c;let p;e[3]!==a||e[4]!==r?(p=s.jsx(Aw,{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(Fh.Provider,{value:d,children:[n,p]}),e[6]=n,e[7]=p,e[8]=d,e[9]=m):m=e[9],m},Ow=()=>{const t=l.useContext(Fh);if(!t)throw new Error("useFireworksCelebration must be used within FireworksProvider");return t},Wn=Zn()(bi(oo((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 mb();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 ub();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 db();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=Xn()?.settings;if(a)try{const o=(await a.load())?.settings||{};r=n(o.defaultGitIdentityId)}catch{}}if(r===null)try{const a=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(a.ok){const i=await a.json().catch(()=>null);r=n(i?.defaultGitIdentityId)}}catch{}return t({defaultGitIdentityId:r}),!0}catch(r){return console.error("Failed to load default git identity setting:",r),!1}},setDefaultGitIdentityId:async n=>{try{const r=typeof n=="string"?n.trim():"",a=r.length>0?r:"";return await Is({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 cb(r),await e().loadProfiles(),!0}catch(r){return console.error("Failed to create git identity profile:",r),!1}},updateProfile:async(n,r)=>{try{const a=e().profiles.find(o=>o.id===n);if(!a)throw new Error("Profile not found");const i={...a,...r};return await lb(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 ob(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:Cl(()=>vr()),partialize:t=>({selectedProfileId:t.selectedProfileId})}),{name:"git-identities-store"}));typeof window<"u"&&(window.__zustand_git_identities_store__=Wn);function La(t){const e=st.c(12);let n,r,a;e[0]!==t?({className:n,style:a,...r}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=a):(n=e[1],r=e[2],a=e[3]);let i;e[4]!==a?(i={color:"var(--surface-elevated-foreground)",...a},e[4]=a,e[5]=i):i=e[5];let o;e[6]!==n?(o=xe("flex h-full w-full flex-col overflow-hidden rounded-xl",n),e[6]=n,e[7]=o):o=e[7];let c;return e[8]!==r||e[9]!==i||e[10]!==o?(c=s.jsx(za,{"data-slot":"command",style:i,className:o,...r}),e[8]=r,e[9]=i,e[10]=o,e[11]=c):c=e[11],c}const da=Oe.forwardRef((t,e)=>{const n=st.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 o;n[4]!==r?(o=xe("placeholder:text-muted-foreground flex h-8 w-full rounded-lg bg-transparent py-2 typography-meta outline-none focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50",r),n[4]=r,n[5]=o):o=n[5];let c;return n[6]!==a||n[7]!==e||n[8]!==o?(c=s.jsxs("div",{"data-slot":"command-input-wrapper",className:"flex h-8 items-center gap-2 border-b px-3",children:[i,s.jsx(za.Input,{ref:e,"data-slot":"command-input",className:o,...a})]}),n[6]=a,n[7]=e,n[8]=o,n[9]=c):c=n[9],c});da.displayName="CommandInput";function $a(t){const e=st.c(14);let n,r,a,i,o;e[0]!==t?({className:r,children:n,scrollbarClassName:o,disableHorizontal:a,...i}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=a,e[4]=i,e[5]=o):(n=e[1],r=e[2],a=e[3],i=e[4],o=e[5]);let c;e[6]!==r?(c=xe("scroll-py-1 overflow-x-hidden h-full min-h-0",r),e[6]=r,e[7]=c):c=e[7];const d=o??"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",p=a??!0;let m;return e[8]!==n||e[9]!==i||e[10]!==c||e[11]!==d||e[12]!==p?(m=s.jsx(Ns,{as:za.List,"data-slot":"command-list",outerClassName:"max-h-[min(600px,calc(100vh-10rem))] overflow-x-hidden p-0 w-full h-full min-h-0",className:c,scrollbarClassName:d,disableHorizontal:p,...i,children:n}),e[8]=n,e[9]=i,e[10]=c,e[11]=d,e[12]=p,e[13]=m):m=e[13],m}function _a(t){const e=st.c(4);let n;e[0]!==t?({...n}=t,e[0]=t,e[1]=n):n=e[1];let r;return e[2]!==n?(r=s.jsx(za.Empty,{"data-slot":"command-empty",className:"py-6 text-center typography-ui-label",...n}),e[2]=n,e[3]=r):r=e[3],r}function Mn(t){const e=st.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=xe("text-foreground [&_[cmdk-group-heading]]:text-muted-foreground overflow-hidden p-1 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:typography-meta [&_[cmdk-group-heading]]:font-medium",n),e[3]=n,e[4]=a):a=e[4];let i;return e[5]!==r||e[6]!==a?(i=s.jsx(za.Group,{"data-slot":"command-group",className:a,...r}),e[5]=r,e[6]=a,e[7]=i):i=e[7],i}function Ca(t){const e=st.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=xe("bg-border -mx-1 h-px",n),e[3]=n,e[4]=a):a=e[4];let i;return e[5]!==r||e[6]!==a?(i=s.jsx(za.Separator,{"data-slot":"command-separator",className:a,...r}),e[5]=r,e[6]=a,e[7]=i):i=e[7],i}function jn(t){const e=st.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=xe("data-[selected=true]:bg-interactive-selection data-[selected=true]:text-interactive-selection-foreground data-[highlighted]:bg-interactive-hover hover:bg-interactive-hover [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 typography-meta outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",n),e[3]=n,e[4]=a):a=e[4];let i;return e[5]!==r||e[6]!==a?(i=s.jsx(za.Item,{"data-slot":"command-item",className:a,...r}),e[5]=r,e[6]=a,e[7]=i):i=e[7],i}function Lw(t){const e=st.c(12);let n,r,a,i;if(e[0]!==t){const{className:c,...d}=t,p=_w,m=typeof d.children=="string"?d.children:"",u=m?m.split("+").map($w).filter(Boolean):[];n="command-shortcut",e[5]!==c?(r=xe("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(Oe.Fragment,{children:[b>0&&s.jsx("span",{className:"opacity-60 text-xs",children:"+"}),p(f)]},`${f}-${b}`)):d.children,e[0]=t,e[1]=n,e[2]=r,e[3]=a,e[4]=i}else n=e[1],r=e[2],a=e[3],i=e[4];let o;return e[7]!==n||e[8]!==r||e[9]!==a||e[10]!==i?(o=s.jsx("span",{"data-slot":n,className:r,...a,children:i}),e[7]=n,e[8]=r,e[9]=a,e[10]=i,e[11]=o):o=e[11],o}function $w(t){return t.trim()}function _w(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 nd=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},Bw=t=>{const e=nd(t);if(!e)return null;const r=e.indexOf("/.git/worktrees/");return r>0&&e.slice(0,r)||null};function zw(t,e,n){const r=st.c(5),[a,i]=l.useState();let o,c;return r[0]!==n||r[1]!==t||r[2]!==e?(o=()=>{if(e){i(void 0);return}if(!t){i(void 0);return}i(void 0);let d=!1;return(async()=>{const[p,m]=await Promise.all([Us("git rev-parse --absolute-git-dir",t),Us("git rev-parse --show-toplevel",t)]);if(d||!p.success||!m.success)return;const u=nd((p.stdout||"").trim()),f=Bw(u);if(!f)return;const b=nd((m.stdout||"").trim());if(!b||b===f)return;const h=n||"",v=b.split("/").filter(Boolean).pop()||b;i({source:"sdk",path:b,projectDirectory:f,branch:h,label:h||v,name:v,worktreeRoot:b,worktreeStatus:"ready",headState:h?"branch":"unborn",worktreeSource:"existing"})})(),()=>{d=!0}},c=[t,e,n],r[0]=n,r[1]=t,r[2]=e,r[3]=o,r[4]=c):(o=r[3],c=r[4]),l.useEffect(o,c),e??a}const Kn=t=>{const e=t.trim();return e?`'${e.replace(/'/g,"'\\''")}'`:"''"},hi=t=>(t||"").split(/\r?\n/).map(e=>e.trim()).filter(Boolean),Xr=t=>!!t.success,$l=t=>(t.stdout||"").trim(),Da=t=>(t.stderr||"").trim();async function Vw(t){const n=((await Us("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 Uw(t){const e=`refs/heads/${t.targetBranch}`,n=new Set(t.excludePaths),a=(await Vw(t.repoRoot)).filter(o=>o.branchRef===e).map(o=>o.path).filter(o=>o&&!n.has(o)),i=[];for(const o of a){const c=await Us("git status --porcelain",o);$l(c)||i.push(o)}return i}async function Oh(t,e){for(const n of e)await Us("git reset --hard",n).catch(()=>{})}async function Ww(t,e){const n=e.trim();if(!n||n==="HEAD")return"HEAD";const r=await Us(`git show-ref --verify --quiet ${Kn(`refs/heads/${n}`)}`,t);if(Xr(r))return n;if(n.startsWith("remotes/")){const o=n.slice(8).split("/"),c=o[0]||"origin",d=o.slice(1).join("/");if(d)return await Us(`git branch --track ${Kn(d)} ${Kn(`${c}/${d}`)}`,t),d}const a=await Us(`git show-ref --verify --quiet ${Kn(`refs/remotes/origin/${n}`)}`,t);return Xr(a)&&await Us(`git branch --track ${Kn(n)} ${Kn(`origin/${n}`)}`,t),n}async function Ai(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 Ww(e,r),i=await Us(`git cherry ${Kn(a)} ${Kn(n)}`,e),o=hi(i.stdout),c=new Set;for(const u of o){const f=u.match(/^\+\s+([0-9a-f]{7,40})\b/i);f&&c.add(f[1])}const d=await Us(`git rev-list --reverse ${Kn(`${a}..${n}`)}`,e),m=hi(d.stdout).filter(u=>c.has(u));return{repoRoot:e,sourceBranch:n,targetBranch:a,commits:m}}async function Kw(t,e){const n=await Us('mkdir -p "$HOME/.config/openchamber/tmp"',t);if(!Xr(n))throw new Error(Da(n)||"Failed to create temp directory parent");const r=await Us('mktemp -d "$HOME/.config/openchamber/tmp/oc-integrate-XXXXXX"',t),a=$l(r);if(!a)throw new Error(Da(r)||"Failed to create temp directory");const i=await Us(`git worktree add --force ${Kn(a)} ${Kn(e)}`,t);if(!Xr(i))throw new Error(Da(i)||"Failed to create temp worktree");return a}async function fl(t,e){await Us(`git worktree remove --force ${Kn(e)}`,t).catch(()=>{}),await Us("git worktree prune",t).catch(()=>{})}async function Hw(t){const e=await Us("git rev-parse --abbrev-ref --symbolic-full-name @{u}",t),n=$l(e);if(!n)return;await Us("git fetch",t);const r=await Us(`git merge --ff-only ${Kn(n)}`,t);if(!Xr(r))throw new Error(Da(r)||"Fast-forward failed")}async function hl(t){const e=await Us("git status --porcelain",t),n=await Us("git diff --name-only --diff-filter=U",t),r=await Us("git diff",t),a=await Us("git show --no-patch --pretty=fuller CHERRY_PICK_HEAD",t),i=await Us("git show CHERRY_PICK_HEAD",t);return{statusPorcelain:e.stdout||"",unmergedFiles:hi(n.stdout),diff:r.stdout||r.stderr||"",currentPatchMeta:a.stdout||a.stderr||"",currentPatch:i.stdout||i.stderr||""}}async function Gw(t){return hl(t)}async function qw(t){const e=await Us("git rev-parse --verify --quiet CHERRY_PICK_HEAD",t);return Xr(e)}async function Jw(t){if(t.commits.length===0)return{kind:"noop",reason:"No commits to move"};const e=await Kw(t.repoRoot,t.targetBranch);let n=[];try{await Hw(e);const r=await Us("git status --porcelain",e);if($l(r))throw new Error("Target branch has local changes; abort integration and retry");const a=await Uw({repoRoot:t.repoRoot,targetBranch:t.targetBranch,excludePaths:[e]}).catch(()=>[]);for(n=[...t.commits];n.length>0;){const i=n[0],o=await Us(`git cherry-pick ${Kn(i)}`,e);if(Xr(o)){n.shift();continue}const c=await Us("git diff --name-only --diff-filter=U",e);if(hi(c.stdout).length>0){const p=await hl(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(Da(o)||"Cherry-pick failed")}return await fl(t.repoRoot,e),await Oh(t.repoRoot,a).catch(()=>{}),{kind:"success",moved:t.commits.length}}catch(r){throw await fl(t.repoRoot,e).catch(()=>{}),r}}async function Yw(t){await Us("git cherry-pick --abort",t.tempWorktreePath).catch(()=>{}),await fl(t.repoRoot,t.tempWorktreePath)}async function Qw(t){const e=await Us("git cherry-pick --continue",t.tempWorktreePath);if(!Xr(e)){const i=await Us("git diff --name-only --diff-filter=U",t.tempWorktreePath);if(hi(i.stdout).length>0){const c=await hl(t.tempWorktreePath);return{kind:"conflict",state:t,details:c}}throw new Error(Da(e)||"Cherry-pick continue failed")}const n=t.tempWorktreePath,r=[...t.remainingCommits];r.length>0&&r[0]===t.currentCommit&&r.shift();const a=[...r];for(;a.length>0;){const i=a[0],o=await Us(`git cherry-pick ${Kn(i)}`,n);if(Xr(o)){a.shift();continue}const c=await Us("git diff --name-only --diff-filter=U",n);if(hi(c.stdout).length>0){const p=await hl(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(Da(o)||"Cherry-pick failed")}return await fl(t.repoRoot,t.tempWorktreePath),await Oh(t.repoRoot,t.cleanTargetWorktrees).catch(()=>{}),{kind:"success",moved:t.remainingCommits.length}}const Xw=({repoRoot:t,sourceBranch:e,worktreeMetadata:n,localBranches:r,defaultTargetBranch:a,refreshKey:i,onRefresh:o})=>{const{t:c}=dt(),d=Lt(B=>B.currentSessionId),p=Re(B=>B.setActiveMainTab),[m,u]=Oe.useState(!1),f=Oe.useRef(null),[b,h]=Oe.useState(a);Oe.useEffect(()=>{h(a)},[a]),Oe.useEffect(()=>{if(m){const B=setTimeout(()=>{f.current?.focus()},0);return()=>clearTimeout(B)}},[m]);const v=!!(t&&e&&b&&b!=="HEAD"&&e!==b),[x,g]=Oe.useState({kind:"idle"}),[w,y]=Oe.useState(!1),[C,k]=Oe.useState([]),j=Oe.useMemo(()=>d?`openchamber.integrate.conflict:${d}`:null,[d]);Oe.useEffect(()=>{if(!j||typeof window>"u")return;const B=window.localStorage.getItem(j);if(!B)return;let z=!1;try{const K=JSON.parse(B);if(!K?.tempWorktreePath||K.repoRoot!==t){window.localStorage.removeItem(j);return}(async()=>{const F=await qw(K.tempWorktreePath).catch(()=>!1);if(z)return;if(!F){window.localStorage.removeItem(j);return}const G=await Gw(K.tempWorktreePath).catch(()=>null);z||G&&g({kind:"conflict",state:K,details:G})})()}catch{window.localStorage.removeItem(j)}return()=>{z=!0}},[j,t]),Oe.useEffect(()=>{if(!v){g({kind:"idle"});return}let B=!1;return g({kind:"loading"}),(async()=>{try{const z=await Ai({repoRoot:t,sourceBranch:e,targetBranch:b});if(B)return;if(g({kind:"ready",plan:z}),z.commits.length>0){const G=z.commits.slice(-50).reverse().map(fe=>JSON.stringify(fe)).join(" "),te=((await Us(`git show -s --format=%H%x09%h%x09%s ${G}`,t)).stdout||"").split(/\r?\n/).filter(Boolean),Z=[];for(const fe of te){const[ue,W,q]=fe.split(" ");!ue||!W||Z.push({sha:ue,short:W,subject:q||""})}B||(k(Z),y(!1))}else B||(k([]),y(!1))}catch{B||g({kind:"idle"})}})(),()=>{B=!0}},[v,t,e,b,i]);const S=Oe.useCallback(B=>{d&&Lt.getState().setWorktreeMetadata(d,{...n,createdFromBranch:B})},[d,n]),I=Lt(B=>B.openNewSessionDraft),M=Oe.useCallback(async B=>{const z=await yn("git.integrate.cherrypick.resolve.visible",{current_commit:B.state.currentCommit,target_branch:B.state.targetBranch}),K=await yn("git.integrate.cherrypick.resolve.instructions",{repo_root:B.state.repoRoot,temp_worktree_path:B.state.tempWorktreePath,source_branch:B.state.sourceBranch,target_branch:B.state.targetBranch,current_commit:B.state.currentCommit}),F=`Cherry-pick conflict context (JSON)
6
+ ${JSON.stringify({repoRoot:B.state.repoRoot,tempWorktreePath:B.state.tempWorktreePath,sourceBranch:B.state.sourceBranch,targetBranch:B.state.targetBranch,currentCommit:B.state.currentCommit,remainingCommits:B.state.remainingCommits,statusPorcelain:B.details.statusPorcelain,unmergedFiles:B.details.unmergedFiles,currentPatchMeta:B.details.currentPatchMeta,currentPatch:B.details.currentPatch,diff:B.details.diff},null,2)}`;return{visibleText:z,instructionsText:K,payloadText:F}},[]),P=Ra(B=>B.setPendingInputText),A=Ra(B=>B.setPendingSyntheticParts),N=Oe.useCallback(async(B,z)=>{const K=await M(B);if(z){I({directoryOverride:B.state.tempWorktreePath,initialPrompt:K.visibleText,syntheticParts:[{text:K.instructionsText,synthetic:!0},{text:K.payloadText,synthetic:!0}]}),p("chat");return}if(!d){H.error(c("gitView.integrate.noActiveSession"),{description:c("gitView.integrate.noActiveSessionDescription")});return}P(K.visibleText,"replace"),A([{text:K.instructionsText,synthetic:!0},{text:K.payloadText,synthetic:!0}]),p("chat")},[d,p,M,I,P,A,c]),E=Oe.useCallback(async()=>{if(x.kind==="ready"){if(x.plan.commits.length===0){H.message(c("gitView.integrate.noCommitsToMoveToast"));return}g({kind:"running",plan:x.plan});try{const B=await Jw(x.plan);if(B.kind==="success"){H.success(c("gitView.integrate.commitsMovedToast"),{description:B.moved===1?c("gitView.integrate.commitsMovedDescriptionSingle",{count:B.moved,branch:x.plan.targetBranch}):c("gitView.integrate.commitsMovedDescriptionPlural",{count:B.moved,branch:x.plan.targetBranch})});const z=await Ai(x.plan);g({kind:"ready",plan:z}),o?.();return}B.kind==="conflict"&&(H.error(c("gitView.integrate.cherryPickConflictToast"),{description:c("gitView.integrate.cherryPickConflictDescription")}),g({kind:"conflict",state:B.state,details:B.details}),j&&typeof window<"u"&&window.localStorage.setItem(j,JSON.stringify(B.state)))}catch(B){const z=B instanceof Error?B.message:String(B);H.error(c("gitView.integrate.failedToMoveToast"),{description:z});const K=await Ai({repoRoot:t,sourceBranch:e,targetBranch:b}).catch(()=>null);g(K?{kind:"ready",plan:K}:{kind:"idle"})}}},[x,o,t,e,b,j,c]),T=Oe.useCallback(async()=>{if(x.kind==="conflict")try{await Yw(x.state),H.message(c("gitView.integrate.cherryPickAbortedToast")),j&&typeof window<"u"&&window.localStorage.removeItem(j)}finally{const B=await Ai({repoRoot:t,sourceBranch:e,targetBranch:b}).catch(()=>null);g(B?{kind:"ready",plan:B}:{kind:"idle"})}},[x,t,e,b,j,c]),R=Oe.useCallback(async()=>{if(x.kind==="conflict")try{const B=await Qw(x.state);if(B.kind==="success"){H.success(c("gitView.integrate.cherryPickFinishedToast"));const z=await Ai({repoRoot:t,sourceBranch:e,targetBranch:b}).catch(()=>null);g(z?{kind:"ready",plan:z}:{kind:"idle"}),j&&typeof window<"u"&&window.localStorage.removeItem(j),o?.();return}B.kind==="conflict"&&(g({kind:"conflict",state:B.state,details:B.details}),j&&typeof window<"u"&&window.localStorage.setItem(j,JSON.stringify(B.state)))}catch(B){const z=B instanceof Error?B.message:String(B);H.error(c("gitView.integrate.cherryPickContinueFailedToast"),{description:z})}},[x,t,e,b,o,j,c]);return!t||!e?null:s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[s.jsxs("div",{className:"px-0 py-3 border-b border-border/40 flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(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(Ts,{open:m,onOpenChange:u,children:[s.jsx(As,{asChild:!0,children:s.jsxs(be,{variant:"outline",size:"sm",className:"gap-1.5",children:[c("gitView.integrate.target"),s.jsx("span",{className:"max-w-[160px] truncate font-mono text-xs text-muted-foreground",children:b}),s.jsx(D,{name:"arrow-down-s",className:"size-4 opacity-60"})]})}),s.jsx(Ds,{align:"end",className:"w-72 p-0 max-h-[var(--available-height)] flex flex-col overflow-hidden",children:s.jsxs(La,{className:"h-full min-h-0",children:[s.jsx(da,{ref:f,placeholder:c("gitView.branch.searchPlaceholder"),onKeyDown:B=>B.stopPropagation()}),s.jsxs($a,{className:"h-full min-h-0",scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[s.jsx(_a,{children:c("gitView.branch.empty")}),s.jsx(Mn,{heading:c("gitView.branch.localBranches"),children:r.map(B=>s.jsx(jn,{value:B,onSelect:()=>{h(B),S(B),u(!1)},children:B},B))})]})]})})]}),x.kind==="ready"?s.jsx(be,{size:"sm",onClick:()=>{E()},disabled:!v||x.plan.commits.length===0,children:c("gitView.integrate.move")}):x.kind==="loading"?s.jsx(be,{size:"sm",variant:"outline",disabled:!0,children:c("gitView.integrate.checking")}):x.kind==="running"?s.jsx(be,{size:"sm",variant:"outline",disabled:!0,children:c("gitView.integrate.moving")}):null]}),x.kind==="ready"&&x.plan.commits.length===0&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:c("gitView.integrate.noCommitsToMove")}),x.kind==="ready"&&x.plan.commits.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"typography-meta text-foreground",children:[c("gitView.integrate.commitsToMove"),s.jsxs("span",{className:"text-muted-foreground",children:[" (",x.plan.commits.length,")"]})]}),C.length>0&&x.plan.commits.length>5&&s.jsx("button",{type:"button",onClick:()=>y(B=>!B),className:"typography-micro text-muted-foreground hover:text-foreground",children:c(w?"gitView.integrate.showLess":"gitView.integrate.showAll")})]}),s.jsxs("div",{className:"space-y-1",children:[(w?C:C.slice(0,5)).map(B=>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:B.short}),s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:B.subject||B.sha})]},B.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(B=>s.jsx("span",{className:"font-mono text-xs px-2 py-0.5 rounded bg-muted/40 text-muted-foreground",children:B},B)),x.details.unmergedFiles.length>6&&s.jsx("span",{className:"text-xs text-muted-foreground",children:c("gitView.integrate.moreFiles",{count:x.details.unmergedFiles.length-6})})]}),s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsx(be,{size:"sm",variant:"ghost",className:"typography-meta",onClick:()=>{T()},children:c("gitView.operation.abort")}),s.jsxs(be,{size:"sm",variant:"secondary",className:"typography-meta gap-1",disabled:!d,onClick:()=>{N({state:x.state,details:x.details},!1)},children:[s.jsx(D,{name:"sparkling",className:"size-3.5"}),c("gitView.integrate.currentSession")]}),s.jsxs(be,{size:"sm",variant:"secondary",className:"typography-meta gap-1",onClick:()=>{N({state:x.state,details:x.details},!0)},children:[s.jsx(D,{name:"sparkling",className:"size-3.5"}),c("gitView.integrate.newSession")]}),s.jsx(be,{size:"sm",className:"typography-meta",onClick:()=>{R()},children:c("gitView.operation.continue")})]})]})]})]})},Zw=t=>t.trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._/-]/g,"-").replace(/-+/g,"-").replace(/\/{2,}/g,"/").replace(/\/-+/g,"/").replace(/-+\//g,"/").replace(/^[-/]+/,"").replace(/[-/]+$/,""),ej=({currentBranch:t,localBranches:e,remoteBranches:n,branchInfo:r,onCheckout:a,onCreate:i,remotes:o=[],disabled:c=!1})=>{const{t:d}=dt(),[p,m]=l.useState(!1),[u,f]=l.useState(""),[b,h]=l.useState(!1),[v,x]=l.useState(!1),[g,w]=l.useState(""),[y,C]=l.useState(!1),k=l.useRef(null),j=l.useCallback(_=>{_.stopPropagation()},[]),S=o.length>1,I=l.useMemo(()=>Zw(g),[g]),M=l.useMemo(()=>{const _=u.toLowerCase();return _?e.filter(U=>U.toLowerCase().includes(_)):e},[u,e]),P=l.useMemo(()=>{const _=u.toLowerCase();return _?n.filter(U=>U.toLowerCase().includes(_)):n},[u,n]),A=_=>{if(_===t){m(!1);return}a(_),m(!1),f("")},N=()=>{h(!0),setTimeout(()=>k.current?.focus(),50)},E=async()=>{if(!(!I||y)){if(S){x(!0);return}C(!0);try{await i(I,o[0]),w(""),h(!1),m(!1)}finally{C(!1)}}},T=async _=>{if(!(!I||y)){C(!0);try{await i(I,_),w(""),h(!1),x(!1),m(!1)}finally{C(!1)}}},R=()=>{x(!1)},V=()=>{w(""),h(!1),x(!1)};return l.useEffect(()=>{p||(f(""),h(!1),x(!1),w(""))},[p]),s.jsxs(Ts,{open:p,onOpenChange:m,children:[s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(As,{asChild:!0,children:s.jsxs(be,{variant:"ghost",size:"sm",className:"h-8 min-w-0 max-w-full justify-start gap-1.5 px-2 py-1",disabled:c,children:[s.jsx(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(At,{sideOffset:8,children:d("gitView.branch.currentBranchTooltip")})]}),s.jsx(Ds,{align:"start",className:"w-72 p-0 max-h-[60vh] flex flex-col",children:s.jsxs(La,{className:"h-full min-h-0",children:[s.jsx(da,{placeholder:d("gitView.branch.searchPlaceholder"),value:u,onValueChange:f,onKeyDown:j}),s.jsxs($a,{scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[s.jsx(_a,{children:d("gitView.branch.empty")}),s.jsx(Mn,{children:v?s.jsxs("div",{className:"px-2 py-1.5",children:[s.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[s.jsx("button",{type:"button",onClick:R,disabled:y,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:s.jsx(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:o.map(_=>s.jsxs("button",{type:"button",onClick:()=>T(_),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,_.name]}),s.jsx("span",{className:"typography-micro text-muted-foreground truncate max-w-full",children:_.pushUrl})]},_.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:g,onChange:_=>w(_.target.value),onClick:_=>_.stopPropagation(),onKeyDown:_=>{j(_),_.key==="Enter"?(_.preventDefault(),E()):_.key==="Escape"&&(_.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(jn,{onSelect:N,children:[s.jsx(D,{name:"add",className:"size-4"}),s.jsx("span",{children:d("gitView.branch.create")})]})}),s.jsx(Ca,{}),s.jsxs(Mn,{heading:d("gitView.branch.localBranches"),children:[M.map(_=>s.jsxs(jn,{onSelect:()=>A(_),children:[s.jsxs("span",{className:"flex flex-1 flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:_}),(r?.[_]?.ahead||r?.[_]?.behind)&&s.jsxs("span",{className:"typography-micro text-muted-foreground",children:[r[_].ahead||0," ahead ·"," ",r[_].behind||0," behind"]})]}),t===_&&s.jsx("span",{className:"typography-micro text-primary",children:d("gitView.branch.currentBadge")})]},`local-${_}`)),M.length===0&&s.jsx(jn,{disabled:!0,className:"justify-center",children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:d("gitView.branch.noLocalBranches")})})]}),s.jsx(Ca,{}),s.jsxs(Mn,{heading:d("gitView.branch.remoteBranches"),children:[P.map(_=>s.jsx(jn,{onSelect:()=>A(_),children:s.jsx("span",{className:"typography-ui-label text-foreground",children:_})},`remote-${_}`)),P.length===0&&s.jsx(jn,{disabled:!0,className:"justify-center",children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:d("gitView.branch.noRemoteBranches")})})]})]})]})})]})},tj=t=>t.trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._/-]/g,"-").replace(/-+/g,"-").replace(/\/{2,}/g,"/").replace(/\/-+/g,"/").replace(/-+\//g,"/").replace(/^[-/]+/,"").replace(/[-/]+$/,""),sj=({currentBranch:t,onRename:e,showEditButton:n=!0})=>{const{t:r}=dt(),[a,i]=l.useState(!1),[o,c]=l.useState(t||""),[d,p]=l.useState(!1),m=l.useRef(null),u=()=>{!t||!e||(c(t),i(!0),setTimeout(()=>m.current?.focus(),0))},f=async()=>{if(!t||!e||!o.trim())return;const v=tj(o);if(v===t){i(!1);return}p(!0);try{await e(t,v),i(!1),c("")}finally{p(!1)}},b=()=>{i(!1),c("")},h=v=>{v.key==="Enter"?(v.preventDefault(),f()):v.key==="Escape"&&(v.preventDefault(),b())};return a?s.jsx("div",{className:"flex items-center gap-2 rounded-md bg-primary/12 px-2 py-1 h-8",children:s.jsxs("form",{className:"flex w-full items-center gap-2",onSubmit:v=>{v.preventDefault(),f()},children:[s.jsx(D,{name:"git-branch",className:"size-4 text-primary"}),s.jsx("input",{ref:m,value:o,onChange:v=>c(v.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",placeholder:r("gitView.branch.namePlaceholder"),onKeyDown:h,autoFocus:!0}),s.jsx("button",{type:"submit",disabled:d,"aria-label":r(d?"gitView.branch.renameSaving":"gitView.branch.renameSave"),title:r(d?"gitView.branch.renameSaving":"gitView.branch.renameSave"),className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:d?s.jsx(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(be,{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"})})]})]})},nj=t=>{const e=st.c(41),{syncAction:n,remotes:r,onFetch:a,onSync:i,onRemoveRemote:o,disabled:c,removingRemoteName:d,aheadCount:p,behindCount:m,trackingRemoteName:u,hasUncommittedChanges:f}=t,b=r===void 0?[]:r,h=d===void 0?null:d,v=p===void 0?0:p,x=m===void 0?0:m,g=f===void 0?!1:f,{t:w}=dt(),y=l.useRef(!1),C=!!h,k=b.find(me=>me.name===u)??b[0],j=x>0&&g,S=c||n!==null||C||!k||j,I=c||n!==null||C||b.length===0,M=v>0||x>0;let P;e[0]!==w?(P=w("gitView.sync.sync"),e[0]=w,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 T=E.join(" "),R=j?w("gitView.sync.commitOrStashTooltip"):k?M?w("gitView.sync.syncChangesTooltip",{ahead:v,behind:x}):w("gitView.sync.syncChanges"):w("gitView.sync.noRemoteTooltip"),V=()=>{k&&i(k)},_="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 U;e[6]===Symbol.for("react.memo_cache_sentinel")?(U=xe("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]=U):U=e[6];let B;e[7]!==w?(B=w("gitView.sync.syncChanges"),e[7]=w,e[8]=B):B=e[8];let z;e[9]!==n?(z=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]=z):z=e[10];let K;e[11]!==T?(K=s.jsx("span",{className:"whitespace-nowrap tabular-nums",children:T}),e[11]=T,e[12]=K):K=e[12];let F;e[13]!==V||e[14]!==S||e[15]!==B||e[16]!==z||e[17]!==K?(F=s.jsx(It,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:V,disabled:S,className:U,"aria-label":B,children:[z,K]})}),e[13]=V,e[14]=S,e[15]=B,e[16]=z,e[17]=K,e[18]=F):F=e[18];let G;e[19]!==R?(G=s.jsx(At,{sideOffset:8,children:R}),e[19]=R,e[20]=G):G=e[20];let Q;e[21]!==F||e[22]!==G?(Q=s.jsxs(Ct,{children:[F,G]}),e[21]=F,e[22]=G,e[23]=Q):Q=e[23];const te=Ts;let Z;e[24]===Symbol.for("react.memo_cache_sentinel")?(Z=xe("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]=Z):Z=e[24];let fe;e[25]!==w?(fe=w("gitView.sync.moreActionsAria"),e[25]=w,e[26]=fe):fe=e[26];let ue;e[27]===Symbol.for("react.memo_cache_sentinel")?(ue=s.jsx(D,{name:"arrow-down-s",className:"size-4"}),e[27]=ue):ue=e[27];let W;e[28]!==I||e[29]!==fe?(W=s.jsx(As,{asChild:!0,children:s.jsx("button",{type:"button",className:Z,disabled:I,"aria-label":fe,children:ue})}),e[28]=I,e[29]=fe,e[30]=W):W=e[30];const q=Ds,J="start",ne=-40,ee="w-[min(360px,calc(100vw-2rem))] max-h-[320px] overflow-y-auto",he=b.map(me=>s.jsx($t,{onSelect:ye=>{if(y.current){ye.preventDefault(),y.current=!1;return}a(me)},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:w("gitView.sync.fetchFromRemote",{name:me.name})}),s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:me.fetchUrl})]})}),o&&me.name!==u?s.jsx(be,{type:"button",variant:"destructive",size:"xs",className:"h-6 w-6 px-0",disabled:n!==null||C,onPointerDown:ye=>{y.current=!0,ye.preventDefault(),ye.stopPropagation()},onClick:ye=>{y.current=!0,ye.preventDefault(),ye.stopPropagation(),o(me)},"aria-label":w("gitView.header.removeRemoteAria",{name:me.name}),title:w("gitView.header.removeRemoteTitle",{name:me.name}),children:h===me.name?s.jsx(D,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(D,{name:"close",className:"size-3.5"})}):null]})},me.name));let ke;e[31]!==q||e[32]!==he?(ke=s.jsx(q,{align:J,alignOffset:ne,className:ee,children:he}),e[31]=q,e[32]=he,e[33]=ke):ke=e[33];let oe;e[34]!==te||e[35]!==W||e[36]!==ke?(oe=s.jsxs(te,{children:[W,ke]}),e[34]=te,e[35]=W,e[36]=ke,e[37]=oe):oe=e[37];let ge;return e[38]!==Q||e[39]!==oe?(ge=s.jsxs("div",{className:_,children:[Q,oe]}),e[38]=Q,e[39]=oe,e[40]=ge):ge=e[40],ge},rj={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart",user:"user-3"},aj={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 Lh(t){return t&&aj[t]||"var(--primary)"}const um=t=>{const e=st.c(8),{icon:n,className:r,colorToken:a}=t,i=rj[n??"branch"]??"user-3";let o;e[0]!==a?(o=Lh(a),e[0]=a,e[1]=o):o=e[1];let c;e[2]!==o?(c={color:o},e[2]=o,e[3]=c):c=e[3];let d;return e[4]!==r||e[5]!==i||e[6]!==c?(d=s.jsx(D,{name:i,className:r,style:c}),e[4]=r,e[5]=i,e[6]=c,e[7]=d):d=e[7],d},$h=t=>{const e=st.c(35),{activeProfile:n,identities:r,onSelect:a,isApplying:i,iconOnly:o}=t,c=o===void 0?!1:o,{t:d}=dt(),p=i||r.length===0,m=n?.color;let u;e[0]!==m?(u=Lh(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(um,{icon:n?.icon,colorToken:n?.color,className:"size-4"}),e[4]=n?.color,e[5]=n?.icon,e[6]=i,e[7]=b):b=e[7];let h;e[8]!==n?.name||e[9]!==c||e[10]!==d?(h=!c&&s.jsx("span",{className:"git-identity-label min-w-0 flex-1 truncate text-left",children:n?.name||d("gitView.header.noIdentity")}),e[8]=n?.name,e[9]=c,e[10]=d,e[11]=h):h=e[11];let v;e[12]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx(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]!==h?(x=s.jsx(It,{asChild:!0,children:s.jsx(As,{asChild:!0,children:s.jsxs(be,{variant:"ghost",size:"sm",className:"h-8 min-w-0 max-w-[15rem] justify-start gap-1.5 px-2 py-1 typography-ui-label",style:f,disabled:p,children:[b,h,v]})})}),e[13]=p,e[14]=f,e[15]=b,e[16]=h,e[17]=x):x=e[17];let g;e[18]!==d?(g=d("gitView.header.identityTooltip"),e[18]=d,e[19]=g):g=e[19];let w;e[20]!==g?(w=s.jsx(At,{sideOffset:8,children:g}),e[20]=g,e[21]=w):w=e[21];let y;e[22]!==w||e[23]!==x?(y=s.jsxs(Ct,{children:[x,w]}),e[22]=w,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($t,{onSelect:()=>a(S),children:s.jsxs("span",{className:"flex items-center gap-2",children:[s.jsx(um,{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(Ds,{align:"end",className:"w-64",children:C}),e[30]=C,e[31]=k):k=e[31];let j;return e[32]!==y||e[33]!==k?(j=s.jsxs(Ts,{children:[y,k]}),e[32]=y,e[33]=k,e[34]=j):j=e[34],j},ij=t=>{const e=st.c(48),{status:n,localBranches:r,remoteBranches:a,branchInfo:i,syncAction:o,remotes:c,onFetch:d,onSync:p,onRemoveRemote:m,removingRemoteName:u,onCheckoutBranch:f,onCreateBranch:b,onRenameBranch:h,activeIdentityProfile:v,availableIdentities:x,onSelectIdentity:g,isApplyingIdentity:w,isWorktreeMode:y,onOpenHistory:C,actionTabItems:k,activeActionTab:j,onSelectActionTab:S}=t,{t:I}=dt();if(!n)return null;let M;e[0]!==C||e[1]!==I?(M=C?s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(be,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0",onClick:C,children:s.jsx(D,{name:"history",className:"size-4"})})}),s.jsx(At,{sideOffset:8,children:I("gitView.history.title")})]}):null,e[0]=C,e[1]=I,e[2]=M):M=e[2];let P;e[3]!==M?(P=s.jsx("div",{className:"flex items-center gap-1 shrink-0",children:M}),e[3]=M,e[4]=P):P=e[4];const A=P,N=!n;let E;e[5]!==n.tracking?(E=n.tracking?.split("/")[0],e[5]=n.tracking,e[6]=E):E=e[6];const T=(n.files?.length??0)>0;let R;e[7]!==d||e[8]!==m||e[9]!==p||e[10]!==c||e[11]!==u||e[12]!==n.ahead||e[13]!==n.behind||e[14]!==o||e[15]!==N||e[16]!==E||e[17]!==T?(R=s.jsx(nj,{syncAction:o,remotes:c,onFetch:d,onSync:p,onRemoveRemote:m,removingRemoteName:u,disabled:N,iconOnly:!0,aheadCount:n.ahead,behindCount:n.behind,trackingRemoteName:E,hasUncommittedChanges:T}),e[7]=d,e[8]=m,e[9]=p,e[10]=c,e[11]=u,e[12]=n.ahead,e[13]=n.behind,e[14]=o,e[15]=N,e[16]=E,e[17]=T,e[18]=R):R=e[18];const V=R;let _;e[19]!==v||e[20]!==x||e[21]!==w||e[22]!==g?(_=s.jsx($h,{activeProfile:v,identities:x,onSelect:g,isApplying:w,iconOnly:!0}),e[19]=v,e[20]=x,e[21]=w,e[22]=g,e[23]=_):_=e[23];const U=_;let B;e[24]!==i||e[25]!==y||e[26]!==r||e[27]!==f||e[28]!==b||e[29]!==h||e[30]!==a||e[31]!==c||e[32]!==n.current?(B=s.jsx("div",{className:"min-w-0 flex-1",children:y?s.jsx(sj,{currentBranch:n.current,onRename:h}):s.jsx(ej,{currentBranch:n.current,localBranches:r,remoteBranches:a,branchInfo:i,onCheckout:f,onCreate:b,remotes:c})}),e[24]=i,e[25]=y,e[26]=r,e[27]=f,e[28]=b,e[29]=h,e[30]=a,e[31]=c,e[32]=n.current,e[33]=B):B=e[33];let z;e[34]!==U||e[35]!==A?(z=s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[A,U]}),e[34]=U,e[35]=A,e[36]=z):z=e[36];let K;e[37]!==B||e[38]!==z?(K=s.jsxs("div",{className:"flex items-center justify-between gap-2 min-w-0",children:[B,z]}),e[37]=B,e[38]=z,e[39]=K):K=e[39];let F;e[40]!==k||e[41]!==j||e[42]!==S||e[43]!==V?(F=k&&j&&S?s.jsxs("div",{className:"mt-3 flex h-8 min-w-0 items-center gap-2",children:[s.jsx("div",{className:"min-w-0 flex-1",children:s.jsx($r,{items:k,activeId:j,onSelect:S,layoutMode:"fit",variant:"active-pill",iconOnlyActiveTab:!0,activePillButtonClassName:"h-7",className:"h-full"})}),s.jsx("div",{className:"shrink-0",children:V})]}):null,e[40]=k,e[41]=j,e[42]=S,e[43]=V,e[44]=F):F=e[44];let G;return e[45]!==K||e[46]!==F?(G=s.jsxs("header",{className:"@container/git-header px-3 py-2 bg-transparent",children:[K,F]}),e[45]=K,e[46]=F,e[47]=G):G=e[47],G},oj=({open:t,onOpenChange:e,directory:n,hasUncommittedChanges:r,uncommittedFileCount:a,onChanged:i})=>{const{t:o}=dt(),[c,d]=l.useState([]),[p,m]=l.useState(!1),[u,f]=l.useState(""),[b,h]=l.useState(""),[v,x]=l.useState(null),[g,w]=l.useState({}),y=l.useCallback(async()=>{if(n){m(!0);try{const M=await pb(n);d(M.stashes),w({})}catch(M){H.error(M instanceof Error?M.message:o("gitView.stashes.toast.loadFailed"))}finally{m(!1)}}},[n,o]);l.useEffect(()=>{t&&y()},[y,t]),l.useEffect(()=>{if(!t||!n||c.length===0)return;let M=!1;const P=c.map(A=>A.ref);return fb(n,P).then(A=>{M||w(A.counts)}).catch(()=>{}),()=>{M=!0}},[n,t,c]);const C=l.useMemo(()=>{const M=u.trim().toLowerCase();return M?c.filter(P=>`${P.ref} ${P.message} ${P.relativeTime}`.toLowerCase().includes(M)):c},[u,c]),k=l.useCallback(async()=>{await y(),await i?.()},[y,i]),j=async()=>{if(!(!n||v)){x("create");try{(await hb(n,{message:b.trim()||void 0})).created?(H.success(o("gitView.stashes.toast.created")),h("")):H.info(o("gitView.stashes.toast.noChanges")),await k()}catch(M){H.error(M instanceof Error?M.message:o("gitView.stashes.toast.createFailed"))}finally{x(null)}}},S=async(M,P)=>{if(!(!n||v)&&!(P==="drop"&&!window.confirm(o("gitView.stashes.confirm.drop",{ref:M.ref})))){x(`${P}:${M.ref}`);try{P==="apply"&&await gb(n,{ref:M.ref}),P==="pop"&&await xb(n,{ref:M.ref}),P==="drop"&&await bb(n,{ref:M.ref});const A=P==="apply"?"gitView.stashes.toast.applySuccess":P==="pop"?"gitView.stashes.toast.popSuccess":"gitView.stashes.toast.dropSuccess";H.success(o(A)),await k()}catch(A){const N=P==="apply"?"gitView.stashes.toast.applyFailed":P==="pop"?"gitView.stashes.toast.popFailed":"gitView.stashes.toast.dropFailed";H.error(A instanceof Error?A.message:o(N)),await k()}finally{x(null)}}},I=v!==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(ys,{children:[s.jsxs(hs,{className:"flex items-center gap-2",children:[s.jsx(D,{name:"archive-stack",className:"h-5 w-5"}),o("gitView.stashes.title")]}),s.jsx(Ss,{children:o("gitView.stashes.description")})]}),s.jsxs("div",{className:"mt-2 rounded-lg border border-border/60 bg-[var(--surface-elevated)] p-3",children:[s.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[s.jsx(Bt,{value:b,onChange:M=>h(M.target.value),placeholder:o("gitView.stashes.messagePlaceholder"),disabled:I||!r,className:"flex-1"}),s.jsxs(be,{onClick:j,disabled:!r||I||!n,children:[v==="create"?s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(D,{name:"inbox-archive",className:"size-4"}),o("gitView.stashes.actions.stashCurrentWithCount",{count:a})]})]}),s.jsx("p",{className:"typography-meta mt-2 text-muted-foreground",children:o("gitView.stashes.includeUntrackedHint")})]}),s.jsxs("div",{className:"relative mt-2",children:[s.jsx(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:u,onChange:M=>f(M.target.value),placeholder:o("gitView.stashes.searchPlaceholder"),className:"pl-9"})]}),s.jsx("div",{className:"flex-1 overflow-y-auto",children:p?s.jsx("div",{className:"flex items-center justify-center py-10 text-muted-foreground",children:s.jsx(D,{name:"loader-4",className:"size-5 animate-spin"})}):C.length===0?s.jsx("div",{className:"py-8 text-center text-muted-foreground",children:o(u?"gitView.stashes.empty.search":"gitView.stashes.empty.list")}):C.map((M,P)=>s.jsxs("div",{className:"group flex items-center gap-2 rounded py-1.5 transition-colors hover:bg-interactive-hover/30",children:[s.jsxs("div",{className:"min-w-0 flex-1 pl-2",children:[s.jsx("p",{className:"typography-small truncate text-foreground",children:M.message||o("gitView.stashes.untitled")}),s.jsxs("p",{className:"typography-meta truncate text-muted-foreground",children:[s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("span",{children:P===0&&!u.trim()?o("gitView.stashes.latestLabel"):o("gitView.stashes.itemNumber",{number:P+1})})}),s.jsx(At,{sideOffset:6,children:M.ref})]})," · ",M.relativeTime," · ",typeof g[M.ref]=="number"?o("gitView.stashes.fileCount",{count:g[M.ref]}):o("gitView.stashes.fileCountLoading")]})]}),s.jsxs("div",{className:"mr-2 flex shrink-0 items-center gap-1 opacity-100 sm:opacity-0 sm:group-hover:opacity-100",children:[s.jsx(uc,{label:o("gitView.stashes.actions.apply"),loading:v===`apply:${M.ref}`,onClick:()=>S(M,"apply"),disabled:I,children:s.jsx(D,{name:"inbox-unarchive",className:"size-4"})}),s.jsx(uc,{label:o("gitView.stashes.actions.pop"),loading:v===`pop:${M.ref}`,onClick:()=>S(M,"pop"),disabled:I,children:s.jsx(D,{name:"inbox-unarchive-fill",className:"size-4"})}),s.jsx(uc,{label:o("gitView.stashes.actions.drop"),loading:v===`drop:${M.ref}`,onClick:()=>S(M,"drop"),disabled:I,destructive:!0,children:s.jsx(D,{name:"delete-bin",className:"size-4"})})]})]},M.ref))})]})})},uc=t=>{const e=st.c(17),{label:n,loading:r,disabled:a,destructive:i,onClick:o,children:c}=t,d=r||void 0,p=i?"text-[var(--status-error)] hover:text-[var(--status-error)]":"text-muted-foreground hover:text-foreground";let m;e[0]!==p?(m=xe("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]!==o||e[8]!==d||e[9]!==m||e[10]!==u?(f=s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":n,"aria-busy":d,className:m,onClick:o,disabled:a,children:u})}),e[5]=a,e[6]=n,e[7]=o,e[8]=d,e[9]=m,e[10]=u,e[11]=f):f=e[11];let b;e[12]!==n?(b=s.jsx(At,{sideOffset:6,children:n}),e[12]=n,e[13]=b):b=e[13];let h;return e[14]!==f||e[15]!==b?(h=s.jsxs(Ct,{children:[f,b]}),e[14]=f,e[15]=b,e[16]=h):h=e[16],h},_h={"?":{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"}},lj=_h.M;function cj(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 dj(t){const e=cj(t);return _h[e]??lj}const mm=l.memo(function(e){const n=st.c(71),{file:r,checked:a,onToggle:i,onViewDiff:o,onRevert:c,isReverting:d,stats:p,rowPaddingClassName:m,indentPx:u}=e,f=u===void 0?0:u;let b;n[0]!==r?(b=dj(r),n[0]=r,n[1]=b):b=n[1];const h=b,{t:v}=dt(),x=h.description,g=p?.insertions??0,w=p?.deletions??0;let y;n[2]!==i||n[3]!==o?(y=W=>{W.key===" "?(W.preventDefault(),i()):W.key==="Enter"&&(W.preventDefault(),o())},n[2]=i,n[3]=o,n[4]=y):y=n[4];const C=y;let k;n[5]!==c?(k=W=>{W.preventDefault(),W.stopPropagation(),c()},n[5]=c,n[6]=k):k=n[6];const j=k,S=`group flex items-center gap-2 py-1.5 hover:bg-sidebar/40 cursor-pointer ${m??"px-3"}`;let I;n[7]!==f?(I=f>0?{paddingLeft:`${f}px`}:void 0,n[7]=f,n[8]=I):I=n[8];let M;n[9]!==i?(M=()=>i(),n[9]=i,n[10]=M):M=n[10];let P;n[11]!==r.path||n[12]!==v?(P=v("gitView.changes.selectFileAria",{path:r.path}),n[11]=r.path,n[12]=v,n[13]=P):P=n[13];let A;n[14]!==a||n[15]!==M||n[16]!==P?(A=s.jsx("div",{className:"flex size-5 shrink-0 items-center justify-center",onClick:uj,children:s.jsx(fs,{size:"sm",checked:a,onChange:M,ariaLabel:P})}),n[14]=a,n[15]=M,n[16]=P,n[17]=A):A=n[17];let N;n[18]!==h.color?(N={color:h.color},n[18]=h.color,n[19]=N):N=n[19];let E;n[20]!==h.code||n[21]!==x||n[22]!==N?(E=s.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:N,title:x,"aria-label":x,children:h.code}),n[20]=h.code,n[21]=x,n[22]=N,n[23]=E):E=n[23];let T;n[24]!==r.path?(T=s.jsx(jr,{filePath:r.path,className:"h-3.5 w-3.5 shrink-0"}),n[24]=r.path,n[25]=T):T=n[25];let R;if(n[26]!==r.path){e:{const W=r.path.lastIndexOf("/");if(W===-1){let oe;n[28]===Symbol.for("react.memo_cache_sentinel")?(oe={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},n[28]=oe):oe=n[28],R=s.jsx("span",{className:"flex-1 min-w-0 truncate typography-ui-label text-foreground",style:oe,title:r.path,children:r.path});break e}const q=r.path.slice(0,W),J=r.path.slice(W);let ne;n[29]===Symbol.for("react.memo_cache_sentinel")?(ne={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},n[29]=ne):ne=n[29];let ee;n[30]===Symbol.for("react.memo_cache_sentinel")?(ee=s.jsx("span",{className:"text-muted-foreground",children:"/"}),n[30]=ee):ee=n[30];const he=s.jsx("span",{className:"text-foreground",children:J.slice(1)});let ke;n[31]!==he?(ke=s.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[ee,he]}),n[31]=he,n[32]=ke):ke=n[32],R=s.jsxs("span",{className:"flex-1 min-w-0 flex items-baseline overflow-hidden",title:r.path,children:[s.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:ne,children:q}),ke]})}n[26]=r.path,n[27]=R}else R=n[27];let V;n[33]===Symbol.for("react.memo_cache_sentinel")?(V={color:"var(--status-success)"},n[33]=V):V=n[33];let _;n[34]!==g?(_=s.jsxs("span",{style:V,children:["+",g]}),n[34]=g,n[35]=_):_=n[35];let U,B;n[36]===Symbol.for("react.memo_cache_sentinel")?(U=s.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),B={color:"var(--status-error)"},n[36]=U,n[37]=B):(U=n[36],B=n[37]);let z;n[38]!==w?(z=s.jsxs("span",{style:B,children:["-",w]}),n[38]=w,n[39]=z):z=n[39];let K;n[40]!==_||n[41]!==z?(K=s.jsxs("span",{className:"shrink-0 typography-micro",children:[_,U,z]}),n[40]=_,n[41]=z,n[42]=K):K=n[42];let F;n[43]!==r.path||n[44]!==v?(F=v("gitView.changes.revertFileAria",{path:r.path}),n[43]=r.path,n[44]=v,n[45]=F):F=n[45];let G;n[46]!==d?(G=d?s.jsx(D,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(D,{name:"arrow-go-back",className:"size-3.5"}),n[46]=d,n[47]=G):G=n[47];let Q;n[48]!==j||n[49]!==d||n[50]!==F||n[51]!==G?(Q=s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:j,disabled:d,className:"flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50","aria-label":F,children:G})}),n[48]=j,n[49]=d,n[50]=F,n[51]=G,n[52]=Q):Q=n[52];let te;n[53]!==v?(te=v("gitView.changes.revertFileTooltip"),n[53]=v,n[54]=te):te=n[54];let Z;n[55]!==te?(Z=s.jsx(At,{sideOffset:8,children:te}),n[55]=te,n[56]=Z):Z=n[56];let fe;n[57]!==Q||n[58]!==Z?(fe=s.jsxs(Ct,{children:[Q,Z]}),n[57]=Q,n[58]=Z,n[59]=fe):fe=n[59];let ue;return n[60]!==C||n[61]!==o||n[62]!==E||n[63]!==T||n[64]!==R||n[65]!==K||n[66]!==fe||n[67]!==S||n[68]!==I||n[69]!==A?(ue=s.jsxs("div",{className:S,role:"button",tabIndex:0,onClick:o,onKeyDown:C,style:I,children:[A,E,T,R,K,fe]}),n[60]=C,n[61]=o,n[62]=E,n[63]=T,n[64]=R,n[65]=K,n[66]=fe,n[67]=S,n[68]=I,n[69]=A,n[70]=ue):ue=n[70],ue});function uj(t){t.stopPropagation()}const mj=1e3,pj=34,pm=14,Bh=t=>t.replace(/\\/g,"/").replace(/^\/+/,"").trim(),fm=(t,e)=>({id:`dir:${t}`,path:t,name:e,children:new Map,directFiles:[],files:[]}),fj=t=>{const e=fm("","");for(const n of t){const r=Bh(n.path);if(!r)continue;const i=r.split("/").filter(Boolean).slice(0,-1);let o=e;if(o.files.push(n),i.length>0){let c="";for(const d of i){c=c?`${c}/${d}`:d;const p=o.children.get(d);if(p){p.files.push(n),o=p;continue}const m=fm(c,d);m.files.push(n),o.children.set(d,m),o=m}}o.directFiles.push(n)}return e},hj=(t,e)=>{const n=[],r=(a,i)=>{const o=Array.from(a.children.values()).sort((d,p)=>d.path.localeCompare(p.path));for(const d of o)n.push({key:d.id,kind:"directory",depth:i,directory:d}),e.has(d.path)&&r(d,i+1);const c=[...a.directFiles].sort((d,p)=>d.path.localeCompare(p.path));for(const d of c)n.push({key:`file:${Bh(d.path)}`,kind:"file",depth:i,file:d})};return r(t,0),n},hm=(t,e)=>{if(t.files.length===0)return"none";let n=0;for(const r of t.files)e.has(r.path)&&(n+=1);return n===0?"none":n===t.files.length?"all":"partial"},gj=({changeEntries:t,selectedPaths:e,diffStats:n,revertingPaths:r,onToggleFile:a,onSelectAll:i,onClearSelection:o,onRevertAll:c,onViewDiff:d,onRevertFile:p,isRevertingAll:m=!1,maxListHeightClassName:u,onVisiblePathsChange:f,onOpenStashes:b})=>{const{t:h}=dt(),v=l.useRef(null),g=Re(ue=>ue.gitChangesViewMode)==="tree",w=e.size,y=t.length,[C,k]=l.useState(!1),j=l.useMemo(()=>fj(t),[t]),[S,I]=l.useState(new Set),M=l.useMemo(()=>Array.from(j.children.values()).map(ue=>ue.path),[j]);l.useEffect(()=>{g&&I(ue=>{const W=new Set,q=new Set(M);return ue.forEach(J=>{if(J.includes("/")){W.add(J);return}q.has(J)&&W.add(J)}),M.forEach(J=>W.add(J)),W})},[g,M]);const P=l.useMemo(()=>hj(j,S),[S,j]),A=l.useMemo(()=>g?P:t,[t,g,P]),N=A.length,E=N>=mj,T=w>0,R=y>0&&w===y,V=T&&!R,_=Ef({count:N,getScrollElement:()=>v.current,estimateSize:()=>pj,overscan:10,enabled:E});l.useEffect(()=>{if(!E)return;const ue=v.current;if(!ue)return;const W=new ResizeObserver(()=>{_.measure()});return W.observe(ue),()=>W.disconnect()},[E,_]);const U=_.getTotalSize(),B=l.useMemo(()=>E&&U>=0?_.getVirtualItems():[],[E,_,U]);l.useEffect(()=>{if(!f)return;if(N===0){f([]);return}const ue=W=>{if(!g)return W.path;const q=W;return q.kind==="file"?q.file.path:null};if(!E){f(A.slice(0,Math.min(30,N)).map(W=>ue(W)).filter(W=>!!W));return}f(B.map(W=>A[W.index]).map(W=>W?ue(W):null).filter(W=>!!W))},[g,f,N,A,E,B]);const z="flex flex-col flex-1 min-h-0",K="flex items-center justify-between gap-2 px-0 py-3 border-b border-border/40",F=`flex-1 min-h-0 pr-0 ${u??""}`.trim(),G="pl-0 pr-2",Q=l.useCallback(ue=>{I(W=>{const q=new Set(W);return q.has(ue)?q.delete(ue):q.add(ue),q})},[]),te=l.useCallback(ue=>{const q=hm(ue,e)!=="all";for(const J of ue.files){const ne=e.has(J.path);(q&&!ne||!q&&ne)&&a(J.path)}},[a,e]),Z=l.useCallback(ue=>{if(!g){const ee=ue;return s.jsx(mm,{file:ee,checked:e.has(ee.path),stats:n?.[ee.path],onToggle:()=>a(ee.path),onViewDiff:()=>d(ee.path),onRevert:()=>p(ee.path),isReverting:r.has(ee.path)||m,rowPaddingClassName:G})}const W=ue;if(W.kind==="file"){const ee=W.file;return s.jsx(mm,{file:ee,checked:e.has(ee.path),stats:n?.[ee.path],onToggle:()=>a(ee.path),onViewDiff:()=>d(ee.path),onRevert:()=>p(ee.path),isReverting:r.has(ee.path)||m,rowPaddingClassName:G,indentPx:W.depth*pm})}const q=W.directory,J=S.has(q.path),ne=hm(q,e);return s.jsxs("div",{className:xe("group flex items-center gap-2 py-1.5 hover:bg-sidebar/40",G),style:{paddingLeft:`${W.depth*pm}px`},children:[s.jsx("div",{className:"flex size-5 shrink-0 items-center justify-center",children:s.jsx(fs,{size:"sm",checked:ne==="all",indeterminate:ne==="partial",onChange:()=>te(q),ariaLabel:h("gitView.changes.toggleDirectorySelectionAria",{path:q.path})})}),s.jsxs("button",{type:"button",onClick:()=>Q(q.path),className:"flex min-w-0 flex-1 items-center gap-2 rounded text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":J?h("gitView.changes.collapseDirectoryAria",{path:q.path}):h("gitView.changes.expandDirectoryAria",{path:q.path}),children:[J?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:q.path,children:q.name}),s.jsx("span",{className:"ml-auto shrink-0 typography-micro text-muted-foreground",children:q.files.length})]})]})},[n,S,m,g,p,a,d,r,G,e,h,Q,te]),fe=l.useCallback(async()=>{!c||m||t.length===0||(await c(t.map(ue=>ue.path)),k(!1))},[t,m,c]);return s.jsxs(s.Fragment,{children:[s.jsxs("section",{className:z,children:[s.jsxs("header",{className:K,children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:h("gitView.changes.title")}),y>0?s.jsxs("div",{className:xe("inline-flex h-6 items-center gap-1 rounded px-1.5",m&&"cursor-not-allowed opacity-50"),children:[s.jsx(fs,{size:"sm",checked:T,indeterminate:V,disabled:m,onChange:()=>R?o():i(),ariaLabel:h(R?"gitView.changes.clearSelectionAria":"gitView.changes.selectAllAria")}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[w,"/",y]})]}):null,b?s.jsx(be,{type:"button",variant:"ghost",size:"xs",className:"h-6 px-1.5",onClick:b,"aria-label":h("gitView.stashes.title"),title:h("gitView.stashes.title"),children:s.jsx(D,{name:"archive-stack",className:"size-4"})}):null]}),s.jsx("div",{className:"flex items-center gap-2 pr-1",children:y>0&&c?s.jsx(be,{variant:"destructive",size:"xs",onClick:()=>k(!0),disabled:m,children:h("gitView.changes.revertAll")}):null})]}),s.jsxs("div",{className:xe("relative flex flex-col min-h-0 w-full overflow-hidden",F),children:[s.jsx(lo,{ref:v,className:"overlay-scrollbar-target overlay-scrollbar-container flex-1 min-h-0 w-full overflow-y-auto overflow-x-hidden",children:E?s.jsx("div",{className:"relative w-full",style:{height:`${_.getTotalSize()}px`},children:B.map(ue=>{const W=A[ue.index];if(!W)return null;const q=g?W.key:`file:${W.path}`;return s.jsx("div",{ref:_.measureElement,"data-index":ue.index,className:xe("absolute left-0 top-0 w-full",ue.index>0&&"before:pointer-events-none before:absolute before:left-0 before:right-2 before:top-0 before:border-t before:border-border/60"),style:{transform:`translateY(${ue.start}px)`},children:Z(W)},q)})}):s.jsx("div",{role:"list","aria-label":h("gitView.changes.changedFilesAria"),children:A.map((ue,W)=>s.jsx("div",{className:xe("relative",W>0&&"before:pointer-events-none before:absolute before:left-0 before:right-2 before:top-0 before:border-t before:border-border/60"),children:Z(ue)},g?ue.key:`file:${ue.path}`))})}),s.jsx(yb,{containerRef:v,disableHorizontal:!0})]})]}),s.jsx(ps,{open:C,onOpenChange:ue=>{m||k(ue)},children:s.jsxs(ms,{className:"max-w-md",children:[s.jsxs(ys,{children:[s.jsx(hs,{children:h("gitView.changes.revertAllDialogTitle")}),s.jsx(Ss,{children:y===1?h("gitView.changes.revertAllDescriptionSingle",{count:y}):h("gitView.changes.revertAllDescriptionPlural",{count:y})})]}),s.jsxs(Vs,{children:[s.jsx(be,{variant:"outline",size:"sm",onClick:()=>k(!1),disabled:m,children:h("gitView.common.cancel")}),s.jsx(be,{variant:"destructive",size:"sm",onClick:()=>{fe()},disabled:m,children:h(m?"gitView.changes.reverting":"gitView.changes.revertAll")})]})]})})]})},mc=38,Io=200,xj=t=>{const e=st.c(20),{value:n,onChange:r,placeholder:a,disabled:i,hasTouchInput:o,isMobile:c}=t,d=i===void 0?!1:i,p=o===void 0?!1:o,m=c===void 0?!1:c,{t:u}=dt(),f=l.useRef(null),b=Re(bj);let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=()=>{const M=f.current;if(!M)return;const P=document.activeElement===M,A=()=>{M.style.height=`${mc}px`;const E=M.scrollHeight,T=Math.min(Math.max(E,mc),Io);M.style.height=`${T}px`,M.style.overflowY=E>Io?"auto":"hidden",E>Io&&!P&&(M.scrollTop=M.scrollHeight)};A();const N=window.requestAnimationFrame(A);return()=>{window.cancelAnimationFrame(N)}},e[0]=h):h=e[0];let v;e[1]!==n?(v=[n],e[1]=n,e[2]=v):v=e[2],l.useLayoutEffect(h,v);let x;e[3]!==r?(x=M=>r(M.target.value),e[3]=r,e[4]=x):x=e[4];let g;e[5]!==a||e[6]!==u?(g=a??u("gitView.commit.messagePlaceholder"),e[5]=a,e[6]=u,e[7]=g):g=e[7];const w=p?"on":"off",y=p?"sentences":"off",C=m||b,k=d&&"opacity-50";let j;e[8]!==k?(j=xe("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]=j):j=e[9];let S;e[10]===Symbol.for("react.memo_cache_sentinel")?(S={minHeight:mc,maxHeight:Io},e[10]=S):S=e[10];let I;return e[11]!==d||e[12]!==C||e[13]!==j||e[14]!==x||e[15]!==g||e[16]!==w||e[17]!==y||e[18]!==n?(I=s.jsx("textarea",{ref:f,value:n,onChange:x,placeholder:g,rows:1,disabled:d,autoCorrect:w,autoCapitalize:y,spellCheck:C,className:j,style:S}),e[11]=d,e[12]=C,e[13]=j,e[14]=x,e[15]=g,e[16]=w,e[17]=y,e[18]=n,e[19]=I):I=e[19],I};function bj(t){return t.inputSpellcheckEnabled}const yj=t=>{const e=st.c(30),{highlights:n,onInsert:r}=t,{t:a}=dt();if(n.length===0)return null;let i;e[0]!==n||e[1]!==r?(i=()=>{r(n)},e[0]=n,e[1]=r,e[2]=i):i=e[2];const o=i;let c;e[3]!==a?(c=a("gitView.commit.aiHighlights.title"),e[3]=a,e[4]=c):c=e[4];let d;e[5]!==c?(d=s.jsx("p",{className:"typography-micro text-muted-foreground",children:c}),e[5]=c,e[6]=d):d=e[6];let p;e[7]!==a?(p=a("gitView.commit.aiHighlights.insertAria"),e[7]=a,e[8]=p):p=e[8];let m;e[9]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(D,{name:"arrow-down",className:"size-4"}),e[9]=m):m=e[9];let u;e[10]!==o||e[11]!==p?(u=s.jsx(It,{asChild:!0,children:s.jsx(be,{variant:"ghost",size:"icon",className:"size-6",onClick:o,"aria-label":p,children:m})}),e[10]=o,e[11]=p,e[12]=u):u=e[12];let f;e[13]!==a?(f=a("gitView.commit.aiHighlights.insertTooltip"),e[13]=a,e[14]=f):f=e[14];let b;e[15]!==f?(b=s.jsx(At,{sideOffset:8,children:f}),e[15]=f,e[16]=b):b=e[16];let h;e[17]!==u||e[18]!==b?(h=s.jsxs(Ct,{children:[u,b]}),e[17]=u,e[18]=b,e[19]=h):h=e[19];let v;e[20]!==d||e[21]!==h?(v=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[d,h]}),e[20]=d,e[21]=h,e[22]=v):v=e[22];let x;e[23]!==n?(x=n.map(vj),e[23]=n,e[24]=x):x=e[24];let g;e[25]!==x?(g=s.jsx("ul",{className:"space-y-1",children:x}),e[25]=x,e[26]=g):g=e[26];let w;return e[27]!==v||e[28]!==g?(w=s.jsxs("div",{className:"space-y-2 rounded-xl border border-border/60 bg-transparent px-3 py-2",children:[v,g]}),e[27]=v,e[28]=g,e[29]=w):w=e[29],w};function vj(t,e){return s.jsx("li",{className:"typography-meta text-foreground",children:t},`${t}-${e}`)}const wj=t=>{const e=st.c(72),{selectedCount:n,commitMessage:r,onCommitMessageChange:a,generatedHighlights:i,onInsertHighlights:o,onGenerateMessage:c,isGeneratingMessage:d,onCommit:p,onCommitAndPush:m,commitAction:u,gitmojiEnabled:f,onOpenGitmojiPicker:b}=t,{t:h}=dt(),v=n>0;let x;e[0]!==u||e[1]!==r||e[2]!==v?(x=r.trim()&&v&&u===null,e[0]=u,e[1]=r,e[2]=v,e[3]=x):x=e[3];const g=x,{isMobile:w,hasTouchInput:y}=nn();let C;e[4]!==h?(C=h("gitView.commit.title"),e[4]=h,e[5]=C):C=e[5];let k;e[6]!==C?(k=s.jsx("div",{className:"flex w-full items-center justify-between px-0 pt-2 pb-1",children:s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:C})}),e[6]=C,e[7]=k):k=e[7];let j;e[8]!==v||e[9]!==h?(j=v?null:s.jsx("p",{className:"typography-meta text-muted-foreground",children:h("gitView.commit.selectFilesHint")}),e[8]=v,e[9]=h,e[10]=j):j=e[10];let S;e[11]!==i||e[12]!==o?(S=s.jsx(yj,{highlights:i,onInsert:o}),e[11]=i,e[12]=o,e[13]=S):S=e[13];let I;e[14]!==h?(I=h("gitView.commit.messagePlaceholder"),e[14]=h,e[15]=I):I=e[15];const M=u!==null;let P;e[16]!==r||e[17]!==y||e[18]!==w||e[19]!==a||e[20]!==I||e[21]!==M?(P=s.jsx(xj,{value:r,onChange:a,placeholder:I,disabled:M,hasTouchInput:y,isMobile:w}),e[16]=r,e[17]=y,e[18]=w,e[19]=a,e[20]=I,e[21]=M,e[22]=P):P=e[22];let A;e[23]!==f||e[24]!==b||e[25]!==h?(A=f&&s.jsxs(be,{variant:"outline",size:"sm",onClick:b,className:"w-fit",type:"button",children:[s.jsx(D,{name:"emotion-happy",className:"size-4"}),h("gitView.commit.addGitmoji")]}),e[23]=f,e[24]=b,e[25]=h,e[26]=A):A=e[26];const N=d||u!==null||n===0;let E;e[27]!==h?(E=h("gitView.commit.generateAria"),e[27]=h,e[28]=E):E=e[28];let T;e[29]!==d?(T=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[29]=d,e[30]=T):T=e[30];let R;e[31]!==h?(R=h("gitView.commit.generate"),e[31]=h,e[32]=R):R=e[32];let V;e[33]!==R?(V=s.jsx("span",{className:"commit-actions__label",children:R}),e[33]=R,e[34]=V):V=e[34];let _;e[35]!==c||e[36]!==N||e[37]!==E||e[38]!==T||e[39]!==V?(_=s.jsxs(be,{variant:"outline",size:"sm",onClick:c,disabled:N,type:"button","aria-label":E,className:"commit-actions__btn",children:[T,V]}),e[35]=c,e[36]=N,e[37]=E,e[38]=T,e[39]=V,e[40]=_):_=e[40];let U;e[41]===Symbol.for("react.memo_cache_sentinel")?(U=s.jsx("div",{className:"flex-1"}),e[41]=U):U=e[41];const B=!g||d;let z;e[42]!==h?(z=h("gitView.commit.commitAria"),e[42]=h,e[43]=z):z=e[43];let K;e[44]!==u||e[45]!==h?(K=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:h("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:h("gitView.commit.commit")})]}),e[44]=u,e[45]=h,e[46]=K):K=e[46];let F;e[47]!==p||e[48]!==B||e[49]!==z||e[50]!==K?(F=s.jsx(be,{size:"sm",variant:"outline",onClick:p,disabled:B,className:"commit-actions__btn whitespace-nowrap","aria-label":z,children:K}),e[47]=p,e[48]=B,e[49]=z,e[50]=K,e[51]=F):F=e[51];let G;e[52]!==g||e[53]!==u||e[54]!==d||e[55]!==w||e[56]!==m||e[57]!==h?(G=w?s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(be,{variant:"default",size:"sm",onClick:()=>m(),disabled:!g||d,className:"h-7 w-7 p-0","aria-label":h("gitView.commit.pushAria"),children:u==="commitAndPush"?s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(D,{name:"arrow-up",className:"size-3.5"})})}),s.jsx(At,{side:"top",children:s.jsx("p",{children:h("gitView.commit.push")})})]}):s.jsx(be,{size:"sm",variant:"default",onClick:()=>m(),disabled:!g||d,className:"commit-actions__btn","aria-label":h("gitView.commit.pushAria"),children:u==="commitAndPush"?s.jsxs(s.Fragment,{children:[s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"commit-actions__label commit-actions__label--push",children:h("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:h("gitView.commit.push")})]})}),e[52]=g,e[53]=u,e[54]=d,e[55]=w,e[56]=m,e[57]=h,e[58]=G):G=e[58];let Q;e[59]!==_||e[60]!==F||e[61]!==G?(Q=s.jsxs("div",{className:"@container/commit-actions flex items-center gap-2 min-w-0",children:[_,U,F,G]}),e[59]=_,e[60]=F,e[61]=G,e[62]=Q):Q=e[62];let te;e[63]!==Q||e[64]!==j||e[65]!==S||e[66]!==P||e[67]!==A?(te=s.jsxs("div",{className:"flex flex-col gap-3 px-0 pt-1 pb-3",children:[j,S,P,A,Q]}),e[63]=Q,e[64]=j,e[65]=S,e[66]=P,e[67]=A,e[68]=te):te=e[68];let Z;return e[69]!==te||e[70]!==k?(Z=s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[k,te]}),e[69]=te,e[70]=k,e[71]=Z):Z=e[71],Z},jj=t=>{const e=st.c(16),{onOpenStashes:n}=t,{t:r}=dt();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 o;e[3]!==i?(o=s.jsx("p",{className:"typography-ui-label font-semibold text-foreground mb-1",children:i}),e[3]=i,e[4]=o):o=e[4];let c;e[5]!==r?(c=r("gitView.empty.cleanDescription"),e[5]=r,e[6]=c):c=e[6];let d;e[7]!==c?(d=s.jsx("p",{className:"typography-meta text-muted-foreground mb-4",children:c}),e[7]=c,e[8]=d):d=e[8];let p;e[9]!==n||e[10]!==r?(p=n?s.jsxs(be,{type:"button",variant:"outline",size:"sm",onClick:n,className:"gap-1.5",children:[s.jsx(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]!==o||e[13]!==d||e[14]!==p?(m=s.jsxs("div",{className:"flex flex-col items-center justify-center py-10 px-4 text-center",children:[a,o,d,p]}),e[12]=o,e[13]=d,e[14]=p,e[15]=m):m=e[15],m};function zh(t){const e=st.c(63),{draft:n,onEdit:r,onDelete:a,className:i,maxWidth:o}=t,{t:c}=dt(),p=Al()?.currentTheme,[m,u]=Oe.useState(!1),f=typeof n.text=="string"?n.text:"";let b;e[0]!==f?(b=f.length>150||f.split(`
7
+ `).length>3,e[0]=f,e[1]=b):b=e[1];const h=b;let v;e[2]!==i?(v=xe("rounded-lg border shadow-none w-full max-w-[min(100%,calc(var(--oc-context-panel-width,100vw)-var(--oc-editor-gutter-width,0px)))] overflow-hidden transition-all duration-200",i),e[2]=i,e[3]=v):v=e[3];const x=p?.colors?.surface?.elevated,g=p?.colors?.interactive?.border,w=o?`${Math.max(200,Math.floor(o))}px`:void 0;let y;e[4]!==x||e[5]!==g||e[6]!==w?(y={backgroundColor:x,borderColor:g,maxWidth:w},e[4]=x,e[5]=g,e[6]=w,e[7]=y):y=e[7];let 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 j;e[11]!==n.endLine||e[12]!==n.startLine||e[13]!==c?(j=c("inlineComment.range.lines",{start:n.startLine,end:n.endLine}),e[11]=n.endLine,e[12]=n.startLine,e[13]=c,e[14]=j):j=e[14];let S;e[15]!==j?(S=s.jsx("span",{children:j}),e[15]=j,e[16]=S):S=e[16];let 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 M;e[19]!==S||e[20]!==I||e[21]!==C?(M=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]=M):M=e[22];const P=m||!h,A=!m&&h&&"line-clamp-3";let N;e[23]!==A?(N=xe("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 T;e[28]!==h||e[29]!==m||e[30]!==c?(T=h&&s.jsx(kr,{asChild:!0,children:s.jsx(be,{variant:"ghost",size:"sm",className:"h-6 px-0 mt-1 text-xs text-muted-foreground hover:text-foreground w-full justify-start",children:m?s.jsxs(s.Fragment,{children:[s.jsx(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]=h,e[29]=m,e[30]=c,e[31]=T):T=e[31];let R;e[32]===Symbol.for("react.memo_cache_sentinel")?(R=s.jsx(hr,{}),e[32]=R):R=e[32];let V;e[33]!==P||e[34]!==E||e[35]!==T?(V=s.jsxs(fr,{open:P,onOpenChange:u,children:[E,T,R]}),e[33]=P,e[34]=E,e[35]=T,e[36]=V):V=e[36];let _;e[37]!==M||e[38]!==V?(_=s.jsxs("div",{className:"flex-1 min-w-0",children:[M,V]}),e[37]=M,e[38]=V,e[39]=_):_=e[39];let U;e[40]===Symbol.for("react.memo_cache_sentinel")?(U=s.jsx(As,{asChild:!0,children:s.jsx(be,{variant:"ghost",size:"icon",className:"h-6 w-6 -mr-1 text-muted-foreground hover:text-foreground",children:s.jsx(D,{name:"more",className:"size-4"})})}),e[40]=U):U=e[40];let B;e[41]===Symbol.for("react.memo_cache_sentinel")?(B=s.jsx(D,{name:"edit",className:"size-4 mr-2"}),e[41]=B):B=e[41];let z;e[42]!==c?(z=c("inlineComment.actions.editComment"),e[42]=c,e[43]=z):z=e[43];let K;e[44]!==r||e[45]!==z?(K=s.jsxs($t,{onClick:r,children:[B,z]}),e[44]=r,e[45]=z,e[46]=K):K=e[46];let F;e[47]===Symbol.for("react.memo_cache_sentinel")?(F=s.jsx(D,{name:"delete-bin",className:"size-4 mr-2"}),e[47]=F):F=e[47];let G;e[48]!==c?(G=c("inlineComment.actions.deleteComment"),e[48]=c,e[49]=G):G=e[49];let Q;e[50]!==a||e[51]!==G?(Q=s.jsxs($t,{onClick:a,className:"text-destructive",children:[F,G]}),e[50]=a,e[51]=G,e[52]=Q):Q=e[52];let te;e[53]!==K||e[54]!==Q?(te=s.jsxs(Ts,{children:[U,s.jsxs(Ds,{align:"end",children:[K,Q]})]}),e[53]=K,e[54]=Q,e[55]=te):te=e[55];let Z;e[56]!==_||e[57]!==te?(Z=s.jsxs("div",{className:"flex items-start justify-between gap-2 p-3",children:[_,te]}),e[56]=_,e[57]=te,e[58]=Z):Z=e[58];let fe;return e[59]!==v||e[60]!==Z||e[61]!==y?(fe=s.jsx("div",{className:v,style:y,"data-comment-card":"true",children:Z}),e[59]=v,e[60]=Z,e[61]=y,e[62]=fe):fe=e[62],fe}function gl(t){const e=st.c(57),{initialText:n,onSave:r,onCancel:a,fileLabel:i,lineRange:o,isEditing:c,className:d,maxWidth:p}=t,m=n===void 0?"":n,u=c===void 0?!1:c,{t:f}=dt(),h=Al()?.currentTheme,{isMobile:v}=nn(),[x,g]=l.useState(m),w=Oe.useRef(null),y=Oe.useRef(o);let C,k;e[0]!==o?(C=()=>{o&&(y.current=o)},k=[o],e[0]=o,e[1]=C,e[2]=k):(C=e[1],k=e[2]),Oe.useEffect(C,k);const j=Aj,S=j(o);let I,M;e[3]!==v?(I=()=>{const ye=w.current;if(!ye)return;const ie=ye.closest(".overlay-scrollbar-container"),ve=ie?.scrollTop??window.scrollY,X=ie?.scrollLeft??window.scrollX;if(v){ye.scrollIntoView({behavior:"auto",block:"nearest"});try{ye.focus({preventScroll:!0})}catch{ye.focus()}return}try{ye.focus({preventScroll:!0})}catch{ye.focus()}const Se=ye.value.length;try{ye.setSelectionRange(Se,Se)}catch{}requestAnimationFrame(()=>{ie?(ie.scrollTop=ve,ie.scrollLeft=X):window.scrollTo({top:ve,left:X})})},M=[v],e[3]=v,e[4]=I,e[5]=M):(I=e[4],M=e[5]),Oe.useEffect(I,M);let P;e[6]!==a||e[7]!==r||e[8]!==x?(P=ye=>{(ye.metaKey||ye.ctrlKey)&&ye.key==="Enter"?(ye.preventDefault(),x.trim()&&r(x,j(y.current))):ye.key==="Escape"&&(ye.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=ye=>{ye.stopPropagation(),x.trim()&&r(x,j(y.current))},e[10]=r,e[11]=x,e[12]=N):N=e[12];const E=N;let T;e[13]!==d?(T=xe("rounded-lg border shadow-none w-full max-w-[min(100%,calc(var(--oc-context-panel-width,100vw)-var(--oc-editor-gutter-width,0px)))] overflow-hidden animate-in fade-in zoom-in-95 duration-200",d),e[13]=d,e[14]=T):T=e[14];const R=h?.colors?.surface?.elevated,V=h?.colors?.interactive?.border,_=p?`${Math.max(200,Math.floor(p))}px`:void 0;let U;e[15]!==R||e[16]!==V||e[17]!==_?(U={backgroundColor:R,borderColor:V,maxWidth:_},e[15]=R,e[16]=V,e[17]=_,e[18]=U):U=e[18];const B="true",z=Pj,K=Ij,F="p-3",G=(i||o)&&s.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground mb-2",children:[i&&s.jsx("span",{className:"truncate max-w-[200px]",children:i}),i&&o&&s.jsx("span",{children:"•"}),S&&s.jsx("span",{children:f("inlineComment.range.lines",{start:S.start,end:S.end})})]});let Q;e[19]===Symbol.for("react.memo_cache_sentinel")?(Q=ye=>g(ye.target.value),e[19]=Q):Q=e[19];let te;e[20]!==f?(te=f("inlineComment.input.placeholder"),e[20]=f,e[21]=te):te=e[21];let Z;e[22]!==A||e[23]!==te||e[24]!==x?(Z=s.jsx(un,{simple:!0,ref:w,value:x,onChange:Q,onKeyDown:A,placeholder:te,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]=te,e[24]=x,e[25]=Z):Z=e[25];let fe;e[26]!==f?(fe=f("inlineComment.actions.cancel"),e[26]=f,e[27]=fe):fe=e[27];let ue;e[28]!==a||e[29]!==fe?(ue=s.jsx(be,{variant:"ghost",size:"sm",onClick:a,onPointerDown:Cj,onTouchStart:kj,className:"h-8 text-muted-foreground hover:text-foreground",children:fe}),e[28]=a,e[29]=fe,e[30]=ue):ue=e[30];let W;e[31]!==x?(W=x.trim(),e[31]=x,e[32]=W):W=e[32];const q=!W,J=h?.colors?.status?.success,ne=h?.colors?.status?.successForeground;let ee;e[33]!==J||e[34]!==ne?(ee={backgroundColor:J,color:ne},e[33]=J,e[34]=ne,e[35]=ee):ee=e[35];let he;e[36]!==u||e[37]!==f?(he=f(u?"inlineComment.actions.save":"inlineComment.actions.comment"),e[36]=u,e[37]=f,e[38]=he):he=e[38];let ke;e[39]!==E||e[40]!==q||e[41]!==ee||e[42]!==he?(ke=s.jsx(be,{size:"sm",onClick:E,onPointerDown:Sj,onTouchStart:Nj,disabled:q,className:"h-8 min-w-[80px]",style:ee,children:he}),e[39]=E,e[40]=q,e[41]=ee,e[42]=he,e[43]=ke):ke=e[43];let oe;e[44]!==ue||e[45]!==ke?(oe=s.jsxs("div",{className:"flex items-center justify-end gap-2 mt-3",children:[ue,ke]}),e[44]=ue,e[45]=ke,e[46]=oe):oe=e[46];let ge;e[47]!==G||e[48]!==Z||e[49]!==oe?(ge=s.jsxs("div",{className:F,children:[G,Z,oe]}),e[47]=G,e[48]=Z,e[49]=oe,e[50]=ge):ge=e[50];let me;return e[51]!==U||e[52]!==z||e[53]!==K||e[54]!==ge||e[55]!==T?(me=s.jsx("div",{className:T,style:U,"data-comment-input":B,onPointerDown:z,onTouchStart:K,children:ge}),e[51]=U,e[52]=z,e[53]=K,e[54]=ge,e[55]=T,e[56]=me):me=e[56],me}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){return t.stopPropagation()}function Pj(t){return t.stopPropagation()}function Aj(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 Dj=t=>{const e=Math.min(t.startLine,t.endLine),n=Math.max(t.startLine,t.endLine);return{...t,startLine:e,endLine:n}},xl=t=>{const e=Math.min(t.start,t.end),n=Math.max(t.start,t.end);return{...t,start:e,end:n}};function Kd(t){const e=st.c(40),{t:n}=dt(),{source:r,fileLabel:a,language:i,getCodeForRange:o,toStoreRange:c,fromDraftRange:d}=t,p=Lt(Oj),m=Lt(Fj),u=Za(Rj),f=Za(Ej),b=Za(Mj),h=Za(Tj),[v,x]=l.useState(null),[g,w]=l.useState(""),[y,C]=l.useState(null),k=p??(m?"draft":null);let j;e:{if(!k||!a){let F;e[0]===Symbol.for("react.memo_cache_sentinel")?(F=[],e[0]=F):F=e[0],j=F;break e}let B;e[1]!==h||e[2]!==k?(B=h[k]??[],e[1]=h,e[2]=k,e[3]=B):B=e[3];const z=B;let K;if(e[4]!==a||e[5]!==z||e[6]!==r){let F;e[8]!==a||e[9]!==r?(F=G=>G.source===r&&G.fileLabel===a,e[8]=a,e[9]=r,e[10]=F):F=e[10],K=z.filter(F),e[4]=a,e[5]=z,e[6]=r,e[7]=K}else K=e[7];j=K}const S=j;let I;e[11]===Symbol.for("react.memo_cache_sentinel")?(I=()=>{x(null),w(""),C(null)},e[11]=I):I=e[11];const M=I;let P;e[12]===Symbol.for("react.memo_cache_sentinel")?(P=()=>{M()},e[12]=P):P=e[12];const A=P;let N;e[13]!==d?(N=B=>{const z=xl(d(B));x(z),w(B.text),C(B.id)},e[13]=d,e[14]=N):N=e[14];const E=N;let T;e[15]!==y||e[16]!==b?(T=B=>{b(B.sessionKey,B.id),y===B.id&&M()},e[15]=y,e[16]=b,e[17]=T):T=e[17];const R=T;let V;e[18]!==u||e[19]!==y||e[20]!==a||e[21]!==o||e[22]!==i||e[23]!==v||e[24]!==k||e[25]!==r||e[26]!==n||e[27]!==c||e[28]!==f?(V=(B,z)=>{const K=z??v,F=B.trim();if(!K||!F||!a)return;if(!k){H.error(n("inlineComment.toast.selectSessionToSave"));return}const G=xl(K),Q=Dj(c(G)),te=o(G);y?f(k,y,{fileLabel:a,startLine:Q.startLine,endLine:Q.endLine,side:Q.side,code:te,language:i,text:F}):u({sessionKey:k,source:r,fileLabel:a,startLine:Q.startLine,endLine:Q.endLine,side:Q.side,code:te,language:i,text:F}),M()},e[18]=u,e[19]=y,e[20]=a,e[21]=o,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 _=V;let U;return e[30]!==g||e[31]!==R||e[32]!==S||e[33]!==y||e[34]!==d||e[35]!==_||e[36]!==v||e[37]!==k||e[38]!==E?(U={sessionKey:k,drafts:S,selection:v,setSelection:x,commentText:g,setCommentText:w,editingDraftId:y,setEditingDraftId:C,reset:M,cancel:A,startEdit:E,deleteDraft:R,saveComment:_,fromDraftRange:d},e[30]=g,e[31]=R,e[32]=S,e[33]=y,e[34]=d,e[35]=_,e[36]=v,e[37]=k,e[38]=E,e[39]=U):U=e[39],U}function Tj(t){return t.drafts}function Mj(t){return t.removeDraft}function Ej(t){return t.updateDraft}function Rj(t){return t.addDraft}function Fj(t){return t.newSessionDraft?.open}function Oj(t){return t.currentSessionId}function Vh(t){const{drafts:e,editingDraftId:n,commentText:r,selection:a,isDragging:i,fileLabel:o,newWidgetId:c,mapDraftToRange:d,onSave:p,onCancel:m,onEdit:u,onDelete:f}=t,b=[];for(const h of e){const v=d(h);if(h.id===n){b.push({afterLine:v.end,id:`edit-${h.id}`,content:s.jsx(gl,{initialText:r,fileLabel:o,lineRange:v,isEditing:!0,onSave:p,onCancel:m},`edit-${h.id}`)});continue}b.push({afterLine:v.end,id:`card-${h.id}`,content:s.jsx(zh,{draft:h,onEdit:()=>u(h),onDelete:()=>f(h)},`card-${h.id}`)})}if(a&&!n&&!i){const h={...a,start:Math.min(a.start,a.end),end:Math.max(a.start,a.end)};b.push({afterLine:h.end,id:c,content:s.jsx(gl,{initialText:r,fileLabel:o,lineRange:h,isEditing:!1,onSave:p,onCancel:m},c)})}return b}const Jo=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}`},Lj=t=>{const{drafts:e,editingDraftId:n,selection:r}=t,a=[];for(const i of e){if(!Number.isFinite(i.endLine))continue;const o=Math.max(1,Math.floor(i.endLine)),c=i.side==="original"?"deletions":"additions";a.push({lineNumber:o,side:c,metadata:{type:i.id===n?"edit":"saved",draft:i}})}return r&&!n&&a.push({lineNumber:Math.max(r.start,r.end),side:r.side??"additions",metadata:{type:"new",selection:r}}),a};function $j(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 gm(t){if(!(!t||t<=0))return Math.max(200,Math.floor(t))}function _j(t){const{diffRootRef:e,drafts:n,selection:r,editingDraftId:a,commentText:i,fileLabel:o,onSave:c,onCancel:d,onEdit:p,onDelete:m}=t,[u,f]=l.useState(0),[b,h]=l.useState(null),v=l.useMemo(()=>!r||a?null:Jo({type:"new",selection:r}),[a,r]),x=l.useMemo(()=>{const y=n.map(C=>Jo({type:C.id===a?"edit":"saved",draft:C}));return v&&y.push(v),y},[n,a,v]),g=l.useCallback(y=>{const C=e.current;if(!C)return null;const k=C.querySelector("diffs-container");if(!(k instanceof HTMLElement))return null;const j=k.querySelector(`[data-annotation-id="${y}"]`);if(j instanceof HTMLElement)return j;const S=k.shadowRoot;return S?S.querySelector(`[data-annotation-id="${y}"]`):null},[e]);l.useEffect(()=>{if(x.length===0)return;let y=!1,C=0;const k=12,j=()=>{y||x.every(I=>!!g(I))||C>=k||(C+=1,requestAnimationFrame(()=>{y||(f(I=>I+1),j())}))};return j(),()=>{y=!0}},[x,g]),l.useEffect(()=>{const y=e.current;if(!y)return;const C=()=>{const j=getComputedStyle(y),S=$j(j.getPropertyValue("--oc-context-panel-width")),I=y.getBoundingClientRect(),M=S??I.width;h(M>0?M:null)};C();const k=new ResizeObserver(()=>{C()});return k.observe(y),window.addEventListener("resize",C),()=>{k.disconnect(),window.removeEventListener("resize",C)}},[e]);const w=l.useCallback(y=>{const k=e.current?.getBoundingClientRect(),j=y.closest("[data-annotation-content]"),S=j instanceof HTMLElement?j.getBoundingClientRect():y.getBoundingClientRect(),I=[S.width];k&&I.push(k.right-S.left);const M=I.filter(P=>Number.isFinite(P)&&P>0);return M.length>0?gm(Math.min(...M)):gm(b)},[e,b]);return s.jsxs(s.Fragment,{children:[n.map(y=>{const C=Jo({type:y.id===a?"edit":"saved",draft:y}),k=g(C);if(!k)return null;const j=w(k);return y.id===a?Vo.createPortal(s.jsx(gl,{initialText:i,fileLabel:o,lineRange:{start:y.startLine,end:y.endLine,side:y.side==="original"?"deletions":"additions"},isEditing:!0,onSave:c,onCancel:d,maxWidth:j}),k,`draft-edit-${y.id}`):Vo.createPortal(s.jsx(zh,{draft:y,onEdit:()=>p(y),onDelete:()=>m(y),maxWidth:j}),k,`draft-card-${y.id}`)}),r&&!a&&v&&(()=>{const y=g(v);if(!y)return null;const C=w(y);return Vo.createPortal(s.jsx(gl,{initialText:i,fileLabel:o,lineRange:r,isEditing:!1,onSave:c,onCancel:d,maxWidth:C}),y,v)})()]})}function Bj(){return new Worker(nx,{type:"module"})}const zj=["typescript","javascript","tsx","jsx","json","markdown"],rd={unified:{poolSize:1,totalASTLRUCacheSize:24,lineDiffType:"none"},split:{poolSize:2,totalASTLRUCacheSize:56,lineDiffType:"word-alt"}};let xm,bm;const ym=t=>{const e=rd[t],n=new rx({workerFactory:Bj,poolSize:e.poolSize,totalASTLRUCacheSize:e.totalASTLRUCacheSize},{theme:{light:"pierre-light",dark:"pierre-dark"},langs:zj,lineDiffType:e.lineDiffType,preferredHighlighter:"shiki-wasm"});return n.initialize(),n},Vj=t=>{if(!(typeof window>"u"))return t==="split"?(bm??=ym("split"),bm):(xm??=ym("unified"),xm)},Uj=t=>{const e=st.c(7),{children:n,renderTheme:r}=t,a=ad("unified"),i=ad("split");let o,c;e[0]!==r||e[1]!==i||e[2]!==a?(o=()=>{a&&a.setRenderOptions({theme:r,lineDiffType:rd.unified.lineDiffType}),i&&i.setRenderOptions({theme:r,lineDiffType:rd.split.lineDiffType})},c=[r,i,a],e[0]=r,e[1]=i,e[2]=a,e[3]=o,e[4]=c):(o=e[3],c=e[4]),Oe.useEffect(o,c);let d;return e[5]!==n?(d=s.jsx(s.Fragment,{children:n}),e[5]=n,e[6]=d):d=e[6],d},Wj=t=>{const e=st.c(11),{children:n}=t,r=Al();let a,i;if(e[0]!==r?.availableThemes||e[1]!==r?.darkThemeId||e[2]!==r?.lightThemeId){const p=ci(!1),m=ci(!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,di(i),di(a),e[0]=r?.availableThemes,e[1]=r?.darkThemeId,e[2]=r?.lightThemeId,e[3]=a,e[4]=i}else a=e[3],i=e[4];let o;e[5]!==a.metadata.id||e[6]!==i.metadata.id?(o={light:i.metadata.id,dark:a.metadata.id},e[5]=a.metadata.id,e[6]=i.metadata.id,e[7]=o):o=e[7];const c=o;let d;return e[8]!==n||e[9]!==c?(d=s.jsx(Uj,{renderTheme:c,children:n}),e[8]=n,e[9]=c,e[10]=d):d=e[10],d},ad=t=>{const e=st.c(2),n=t===void 0?"unified":t;let r;return e[0]!==n?(r=Vj(n),e[0]=n,e[1]=r):r=e[1],r},Kj=5e5,Hj=`
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 Gj(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 vm(t){const e=t.length>400?`${t.slice(0,200)}${t.slice(-200)}`:t;return`${t.length}:${Gj(e)}`}const qj=(t,e,n)=>{const i=(n.side==="deletions"?t:e).split(`
37
+ `),o=Math.min(n.start,n.end),c=Math.max(n.start,n.end),d=Math.max(1,o),p=Math.min(i.length,c);return d>p?"":i.slice(d-1,p).join(`
38
+ `)},Jj=(t,e)=>t===e?!0:!t||!e?!1:t.start===e.start&&t.end===e.end&&t.side===e.side,Po=new WeakMap,Yj={lineHeight:24,hunkSeparatorHeight:24,fileGap:0};function Qj(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 Xj(t){if(typeof document>"u")return null;const e=Qj(t);let n=Po.get(e.key);if(!n){const a=new ox;a.setup(e.root,e.content),n={virtualizer:a,refs:0},Po.set(e.key,n)}n.refs+=1;let r=!1;return{virtualizer:n.virtualizer,release:()=>{if(r)return;r=!0;const a=Po.get(e.key);a&&(a.refs-=1,!(a.refs>0)&&(a.virtualizer.cleanUp(),Po.delete(e.key)))}}}const Hd=({original:t,modified:e,language:n,fileName:r,renderSideBySide:a,wrapLines:i,layout:o="fill"})=>{const c=Al(),d=c?.currentTheme.metadata.variant==="dark",p=c?.availableThemes.find(J=>J.metadata.id===c.lightThemeId)??ci(!1),m=c?.availableThemes.find(J=>J.metadata.id===c.darkThemeId)??ci(!0),{isMobile:u}=nn(),f=Kd({source:"diff",fileLabel:r||"unknown",language:n,getCodeForRange:J=>qj(t,e,J),toStoreRange:J=>({startLine:J.start,endLine:J.end,side:J.side==="deletions"?"original":"modified"}),fromDraftRange:J=>({start:J.startLine,end:J.endLine,side:J.side==="original"?"deletions":"additions"})}),{drafts:b,selection:h,setSelection:v,commentText:x,setCommentText:g,editingDraftId:w,saveComment:y,cancel:C,startEdit:k,deleteDraft:j}=f,S=Oe.useRef(null),I=Oe.useRef(null),M=Oe.useRef(!1),P=Oe.useRef(null);Oe.useEffect(()=>{S.current=h},[h]),Oe.useEffect(()=>{I.current=w},[w]);const A=Oe.useCallback(J=>{if(M.current)return;const ne=S.current;if(u&&ne&&J&&J.side===ne.side){const ee=Math.min(ne.start,J.start),he=Math.max(ne.end,J.end);v({...J,start:ee,end:he})}else v(J);J&&(I.current||g(""))},[u,g,v]),N=Oe.useCallback(()=>{C()},[C]),E=Oe.useCallback(J=>{const ne=document.createElement("div");ne.style.position="relative";const ee=Jo(J.metadata);return ne.dataset.annotationId=ee,ne.dataset.annotationSide=J.side,ne.dataset.annotationLine=String(J.lineNumber),ne},[]),T=Oe.useCallback((J,ne)=>{y(J,ne??h??void 0)},[y,h]),R=Oe.useCallback(J=>{v(J);const ne=z.current;if(ne)try{M.current=!0,ne.setSelectedLines(J),P.current=J}catch{}finally{M.current=!1}},[v]),V=Oe.useCallback(J=>{const ne=J.closest("[data-line-type]")?.getAttribute("data-line-type")??J.getAttribute("data-line-type");if(ne==="change-deletion")return"deletions";if(ne==="change-addition")return"additions";const ee=J.getAttribute("data-column-side")??J.getAttribute("data-side")??J.closest("[data-column-side]")?.getAttribute("data-column-side");if(ee==="deletions"||ee==="left"||ee==="original")return"deletions";if(ee==="additions"||ee==="right"||ee==="modified")return"additions";const he=J.closest("[data-line-type]");if(he instanceof HTMLElement){const ke=he.getBoundingClientRect(),oe=J.getBoundingClientRect(),ge=ke.left+ke.width/2;return oe.left+oe.width/2<ge?"deletions":"additions"}return"additions"},[]);di(p),di(m);const _=`${p.metadata.id}:${m.metadata.id}:${d?"dark":"light"}`,U=Oe.useRef(null),B=Oe.useRef(null),z=Oe.useRef(null),K=Oe.useRef(null),[,F]=l.useReducer(J=>J+1,0),G=ad(a?"split":"unified"),Q=Oe.useMemo(()=>wu(p),[p]),te=Oe.useMemo(()=>wu(m),[m]);l.useLayoutEffect(()=>{const J=U.current;if(!J)return;const ne=J.querySelector("diffs-container");if(!ne)return;const ee=d?te:Q,he=(pe,we)=>pe.colors?.[we],ke=he(Q,"terminal.ansiGreen"),oe=he(Q,"terminal.ansiRed"),ge=he(Q,"terminal.ansiBlue"),me=he(te,"terminal.ansiGreen"),ye=he(te,"terminal.ansiRed"),ie=he(te,"terminal.ansiBlue");ne.style.setProperty("--shiki-light",Q.fg),ne.style.setProperty("--shiki-light-bg",Q.bg),ke&&ne.style.setProperty("--shiki-light-addition-color",ke),oe&&ne.style.setProperty("--shiki-light-deletion-color",oe),ge&&ne.style.setProperty("--shiki-light-modified-color",ge),ne.style.setProperty("--shiki-dark",te.fg),ne.style.setProperty("--shiki-dark-bg",te.bg),me&&ne.style.setProperty("--shiki-dark-addition-color",me),ye&&ne.style.setProperty("--shiki-dark-deletion-color",ye),ie&&ne.style.setProperty("--shiki-dark-modified-color",ie),ne.style.setProperty("--diffs-bg",ee.bg),ne.style.setProperty("--diffs-fg",ee.fg);const ve=d?me:ke,X=d?ye:oe,Se=d?ie:ge;ve&&ne.style.setProperty("--diffs-addition-color-override",ve),X&&ne.style.setProperty("--diffs-deletion-color-override",X),Se&&ne.style.setProperty("--diffs-modified-color-override",Se);const Ae=ne.shadowRoot?.querySelector("pre");Ae&&(Ae.style.setProperty("--shiki-light",Q.fg),Ae.style.setProperty("--shiki-light-bg",Q.bg),ke&&Ae.style.setProperty("--shiki-light-addition-color",ke),oe&&Ae.style.setProperty("--shiki-light-deletion-color",oe),ge&&Ae.style.setProperty("--shiki-light-modified-color",ge),Ae.style.setProperty("--shiki-dark",te.fg),Ae.style.setProperty("--shiki-dark-bg",te.bg),me&&Ae.style.setProperty("--shiki-dark-addition-color",me),ye&&Ae.style.setProperty("--shiki-dark-deletion-color",ye),ie&&Ae.style.setProperty("--shiki-dark-modified-color",ie),Ae.style.setProperty("--diffs-bg",ee.bg),Ae.style.setProperty("--diffs-fg",ee.fg),ve&&Ae.style.setProperty("--diffs-addition-color-override",ve),X&&Ae.style.setProperty("--diffs-deletion-color-override",X),Se&&Ae.style.setProperty("--diffs-modified-color-override",Se))},[te,_,d,Q]);const Z=Oe.useMemo(()=>Math.max(t.length,e.length)>Kj,[t.length,e.length]),fe=Oe.useMemo(()=>({theme:{dark:m.metadata.id,light:p.metadata.id},themeType:d?"dark":"light",diffStyle:a?"split":"unified",diffIndicators:"none",hunkSeparators:"line-info-basic",lineDiffType:"none",maxLineDiffLength:Z?0:1e3,maxLineLengthForHighlighting:Z?1:1e3,expansionLineCount:20,overflow:i?"wrap":"scroll",disableFileHeader:!0,enableLineSelection:!0,enableHoverUtility:!1,onLineSelected:A,unsafeCSS:Hj,renderAnnotation:E}),[m.metadata.id,d,Z,p.metadata.id,a,i,A,E]),ue=Oe.useMemo(()=>Lj({drafts:b,editingDraftId:w,selection:h}),[w,b,h]),W=Oe.useRef(ue);if(Oe.useEffect(()=>{W.current=ue},[ue]),Oe.useEffect(()=>{if(typeof window>"u")return;const J=B.current;if(!J||!G)return;z.current?.cleanUp(),z.current=null,K.current?.release(),K.current=null,J.innerHTML="";const ne=Xj(J);K.current=ne;const ee=ne?new ax(fe,ne.virtualizer,Yj,G):new ix(fe,G);z.current=ee,P.current=null;const he={name:r||"",contents:t,lang:n,cacheKey:`old:${_}:${r}:${vm(t)}`},ke={name:r||"",contents:e,lang:n,cacheKey:`new:${_}:${r}:${vm(e)}`};return ee.render({oldFile:he,newFile:ke,lineAnnotations:W.current,containerWrapper:J}),requestAnimationFrame(()=>{F()}),()=>{ee.cleanUp(),z.current===ee&&(z.current=null),ne?.release(),ne&&K.current===ne&&(K.current=null),J.innerHTML=""}},[_,r,n,e,fe,t,G]),Oe.useEffect(()=>{const J=z.current;if(J){try{J.setLineAnnotations(ue)}catch(ne){console.error("Failed to apply diff line annotations",ne);try{J.setLineAnnotations([])}catch{}}requestAnimationFrame(()=>{if(z.current===J){try{J.rerender()}catch{}F()}})}},[ue]),Oe.useEffect(()=>{const J=z.current;if(!J||h!==null)return;const ne=P.current;if(!Jj(h,ne))try{M.current=!0,J.setSelectedLines(h),P.current=h}catch{}finally{M.current=!1}},[h]),Oe.useEffect(()=>{const J=B.current;if(!J)return;let ne=null,ee=()=>{};const he=()=>{const oe=J.querySelector("diffs-container")?.shadowRoot;if(!oe){ne=requestAnimationFrame(he);return}const ge=me=>{if(!(me instanceof MouseEvent)||me.button!==0||!(me.target instanceof Element))return;const ye=me.target.closest("[data-column-number]");if(!(ye instanceof HTMLElement))return;const ie=ye.getAttribute("data-column-number"),ve=ie?parseInt(ie,10):NaN;if(Number.isNaN(ve))return;const X=V(ye);A({start:ve,end:ve,side:X}),me.preventDefault(),me.stopPropagation()};oe.addEventListener("click",ge,!0),ee=()=>{oe.removeEventListener("click",ge,!0)}};return he(),()=>{ne!==null&&cancelAnimationFrame(ne),ee()}},[_,r,A,V]),Oe.useEffect(()=>{const J=B.current;if(!J)return;let ne=null,ee=null;const ke=setTimeout(()=>{const oe=J.querySelector("diffs-container");if(!(oe instanceof HTMLElement))return;const ge=oe.shadowRoot;ne=new MutationObserver(()=>{ee&&cancelAnimationFrame(ee),ee=requestAnimationFrame(()=>{F(),ee=null})}),ne.observe(oe,{childList:!0,subtree:!0}),ge&&ne.observe(ge,{childList:!0,subtree:!0})},100);return()=>{clearTimeout(ke),ee&&cancelAnimationFrame(ee),ne?.disconnect()}},[_,r]),typeof window>"u")return null;const q=s.jsx(_j,{diffRootRef:U,drafts:b,selection:h,editingDraftId:w,commentText:x,fileLabel:r?.split("/").pop()??"",onSave:T,onCancel:N,onEdit:J=>{R({start:J.startLine,end:J.endLine,side:J.side==="original"?"deletions":"additions"}),k(J)},onDelete:j});return o==="fill"?s.jsx("div",{className:xe("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(Ns,{outerClassName:"pierre-diff-wrapper size-full",disableHorizontal:!1,fillContainer:!0,"data-diff-virtual-content":!0,children:s.jsx("div",{ref:U,className:"size-full relative",children:s.jsx("div",{ref:B,className:"size-full"})})}),q]})}):s.jsxs("div",{className:xe("relative","w-full"),children:[s.jsx("div",{ref:U,className:"pierre-diff-wrapper w-full overflow-x-auto overflow-y-visible relative",children:s.jsx("div",{ref:B,className:"w-full"})}),q]})},wm=15e3,jm=500,Nm=12,Sm=8*1024*1024,km=t=>typeof t=="string"?0:(t.original?.length??0)+(t.modified?.length??0),Cm=t=>{if(t.size<=Nm){let a=0;for(const i of t.values())a+=km(i);if(a<=Sm)return t}const e=Array.from(t.entries()).reverse(),n=new Map;let r=0;for(const[a,i]of e){if(n.size>=Nm)continue;const o=km(i);r+o>Sm&&n.size>0||(n.set(a,i),r+=o)}return new Map(Array.from(n.entries()).reverse())};function Im(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 Zj(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 e0=l.memo(t=>{const e=st.c(71),{entry:n,isExpanded:r,onToggle:a,files:i,isLoadingFiles:o,onCopyHash:c,directory:d}=t,{t:p}=dt();let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m=new Set,e[0]=m):m=e[0];const[u,f]=l.useState(m);let b;e[1]===Symbol.for("react.memo_cache_sentinel")?(b=new Map,e[1]=b):b=e[1];const[h,v]=l.useState(b);let x;e[2]===Symbol.for("react.memo_cache_sentinel")?(x=new Set,e[2]=x):x=e[2];const[g,w]=l.useState(x);let y;e[3]!==d||e[4]!==n.hash?(y=async J=>{const ne=J.path;if(!d){v(ee=>new Map(ee).set(ne,"error"));return}v(ee=>Cm(new Map(ee).set(ne,"loading")));try{const ee=vb(d,n.hash,J.path,!1),he=new Promise(t0),ke=await Promise.race([ee,he]);v(oe=>Cm(new Map(oe).set(ne,ke)))}catch{v(ee=>new Map(ee).set(ne,"error"))}},e[3]=d,e[4]=n.hash,e[5]=y):y=e[5];const C=y;let k;e[6]!==h||e[7]!==g||e[8]!==C||e[9]!==u?(k=async J=>{const ne=J.path;if(J.changeType==="R"||J.isBinary){f(oe=>{const ge=new Set(oe);return ge.has(ne)?ge.delete(ne):ge.add(ne),ge});return}const ee=h.get(ne);if(u.has(ne)&&ee&&ee!=="error"){f(oe=>{const ge=new Set(oe);return ge.delete(ne),ge});return}f(oe=>{const ge=new Set(oe);return ge.add(ne),ge}),!(ee&&ee!=="error"||J.insertions+J.deletions>jm&&!g.has(ne))&&await C(J)},e[6]=h,e[7]=g,e[8]=C,e[9]=u,e[10]=k):k=e[10];const j=k,S=r?"bg-sidebar/90":"hover:bg-sidebar/40";let I;e[11]!==S?(I=xe("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 M;e[13]===Symbol.for("react.memo_cache_sentinel")?(M=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]=M):M=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=Im(n.date),e[19]=n.date,e[20]=E):E=e[20];let T;e[21]!==n.date?(T=Im(n.date),e[21]=n.date,e[22]=T):T=e[22];let R;e[23]!==E||e[24]!==T?(R=s.jsx("span",{className:"truncate min-w-0",title:E,children:T}),e[23]=E,e[24]=T,e[25]=R):R=e[25];let V;e[26]!==A||e[27]!==R?(V=s.jsxs("div",{className:"flex items-center gap-1 min-w-0 truncate",children:[A,N,R]}),e[26]=A,e[27]=R,e[28]=V):V=e[28];let _;e[29]===Symbol.for("react.memo_cache_sentinel")?(_=s.jsx("span",{className:"shrink-0",children:"·"}),e[29]=_):_=e[29];let U;e[30]!==n.hash?(U=n.hash.slice(0,8),e[30]=n.hash,e[31]=U):U=e[31];let B;e[32]!==U?(B=s.jsx("code",{className:"shrink-0 font-mono",children:U}),e[32]=U,e[33]=B):B=e[33];let z;e[34]!==n.hash||e[35]!==c?(z=J=>{J.stopPropagation(),c(n.hash)},e[34]=n.hash,e[35]=c,e[36]=z):z=e[36];let K;e[37]===Symbol.for("react.memo_cache_sentinel")?(K=s.jsx(D,{name:"file-copy",className:"size-3"}),e[37]=K):K=e[37];let F;e[38]!==z?(F=s.jsx(It,{asChild:!0,children:s.jsx(be,{variant:"ghost",size:"sm",className:"h-5 px-1 shrink-0",onClick:z,children:K})}),e[38]=z,e[39]=F):F=e[39];let G;e[40]!==p?(G=p("gitView.history.copySha"),e[40]=p,e[41]=G):G=e[41];let Q;e[42]!==G?(Q=s.jsx(At,{sideOffset:8,children:G}),e[42]=G,e[43]=Q):Q=e[43];let te;e[44]!==F||e[45]!==Q?(te=s.jsxs(Ct,{children:[F,Q]}),e[44]=F,e[45]=Q,e[46]=te):te=e[46];let Z;e[47]!==V||e[48]!==B||e[49]!==te?(Z=s.jsxs("div",{className:"flex items-center gap-1 typography-meta text-muted-foreground",children:[V,_,B,te]}),e[47]=V,e[48]=B,e[49]=te,e[50]=Z):Z=e[50];let fe;e[51]!==Z||e[52]!==P?(fe=s.jsxs("div",{className:"min-w-0 flex-1",children:[P,Z]}),e[51]=Z,e[52]=P,e[53]=fe):fe=e[53];let ue;e[54]!==a||e[55]!==fe||e[56]!==I?(ue=s.jsxs("button",{type:"button",onClick:a,className:I,children:[M,fe]}),e[54]=a,e[55]=fe,e[56]=I,e[57]=ue):ue=e[57];let W;e[58]!==h||e[59]!==i||e[60]!==g||e[61]!==r||e[62]!==o||e[63]!==C||e[64]!==u||e[65]!==p||e[66]!==j?(W=r&&s.jsx("div",{className:"px-3 pb-2 pl-8 border-t border-border/40",children:o?s.jsxs("div",{className:"flex items-center gap-2 py-2",children:[s.jsx(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(J=>s.jsxs("li",{children:[s.jsxs("button",{type:"button",onClick:()=>j(J),className:xe("w-full flex items-center gap-2 typography-micro text-left cursor-pointer transition-colors rounded px-1",u.has(J.path)?"bg-sidebar/90":"hover:bg-sidebar/40"),children:[s.jsx("span",{className:xe("font-semibold w-3 text-center shrink-0",Zj(J.changeType)),children:J.changeType}),s.jsx("span",{className:"truncate text-foreground min-w-0",title:J.path,children:J.path}),!J.isBinary&&s.jsxs("span",{className:"shrink-0",children:[s.jsxs("span",{style:{color:"var(--status-success)"},children:["+",J.insertions]}),s.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),s.jsxs("span",{style:{color:"var(--status-error)"},children:["-",J.deletions]})]}),J.isBinary&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:p("gitView.history.binary")}),s.jsx(D,{name:u.has(J.path)?"arrow-down-s":"arrow-right-s",className:"size-3 shrink-0 text-muted-foreground"})]}),u.has(J.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:J.changeType==="R"?s.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:p("gitView.history.renamedNoDiff")}):J.isBinary?s.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:p("gitView.history.binaryNoDiff")}):(()=>{const ne=J.insertions+J.deletions;if(!g.has(J.path)&&ne>jm)return s.jsxs("div",{className:"flex flex-col items-start gap-1 px-3 py-2 text-sm text-muted-foreground",children:[s.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:p("gitView.history.largeDiffTitle",{count:ne})}),s.jsx("div",{className:"typography-meta text-muted-foreground",children:p("gitView.history.largeDiffDescription")}),s.jsx(be,{type:"button",variant:"ghost",size:"xs",className:"h-6 px-0 text-primary hover:bg-transparent hover:underline",onClick:()=>{w(he=>new Set(he).add(J.path)),C(J)},children:p("gitView.history.renderDiffAnyway")})]});const ee=h.get(J.path);return ee==="loading"||ee===void 0?s.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:p("gitView.history.loadingDiff")}):ee==="error"?s.jsx("button",{type:"button",onClick:()=>j(J),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(Hd,{original:ee.original,modified:ee.modified,language:ui(J.path)||"",fileName:J.path,renderSideBySide:!1,layout:"inline"})})()})]},J.path))})}),e[58]=h,e[59]=i,e[60]=g,e[61]=r,e[62]=o,e[63]=C,e[64]=u,e[65]=p,e[66]=j,e[67]=W):W=e[67];let q;return e[68]!==ue||e[69]!==W?(q=s.jsxs("li",{children:[ue,W]}),e[68]=ue,e[69]=W,e[70]=q):q=e[70],q});function t0(t,e){setTimeout(()=>e(new Error(`Timed out after ${wm}ms`)),wm)}const s0=[{labelKey:"gitView.history.logSize25",value:25},{labelKey:"gitView.history.logSize50",value:50},{labelKey:"gitView.history.logSize100",value:100}],n0=t=>{const e=st.c(56),{log:n,isLogLoading:r,logMaxCount:a,onLogMaxCountChange:i,expandedCommitHashes:o,onToggleCommit:c,commitFilesMap:d,loadingCommitHashes:p,onCopyHash:m,directory:u,showHeader:f,contentMaxHeightClassName:b,branchDivider:h}=t,v=f===void 0?!0:f,x=b===void 0?"max-h-[50vh]":b,g=h===void 0?null:h,{t:w}=dt(),[y,C]=l.useState(!0);if(!n)return null;const k=g!==null&&g.insertBeforeIndex>0&&g.insertBeforeIndex<n.all.length,j=g!==null&&g.insertBeforeIndex===n.all.length,S=k||j;let I;e[0]!==g||e[1]!==k||e[2]!==j||e[3]!==n.all?(I=k?n.all.slice(0,g.insertBeforeIndex):j?n.all:[],e[0]=g,e[1]=k,e[2]=j,e[3]=n.all,e[4]=I):I=e[4];const M=I;let P;if(e[5]!==g||e[6]!==d||e[7]!==x||e[8]!==u||e[9]!==o||e[10]!==k||e[11]!==S||e[12]!==p||e[13]!==n.all||e[14]!==m||e[15]!==c||e[16]!==w||e[17]!==M){const z=k?n.all.slice(g.insertBeforeIndex):[];let K;e[19]!==g?.direction?(K=g?.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]=g?.direction,e[20]=K):K=e[20];const F=K;let G;e[21]!==d||e[22]!==u||e[23]!==o||e[24]!==p||e[25]!==m||e[26]!==c?(G=te=>s.jsx("ul",{className:"divide-y divide-border/60",children:te.map(Z=>s.jsx(e0,{entry:Z,isExpanded:o.has(Z.hash),onToggle:()=>c(Z.hash),files:d.get(Z.hash)??[],isLoadingFiles:p.has(Z.hash),onCopyHash:m,directory:u},Z.hash))}),e[21]=d,e[22]=u,e[23]=o,e[24]=p,e[25]=m,e[26]=c,e[27]=G):G=e[27];const Q=G;P=s.jsx(Ns,{outerClassName:`min-h-0 ${x}`,className:"h-full w-full",children:n.all.length===0?s.jsx("div",{className:"flex h-full items-center justify-center p-4",children:s.jsx("p",{className:"typography-ui-label text-muted-foreground",children:w("gitView.history.noCommits")})}):S&&g?s.jsxs("div",{className:"flex flex-col gap-0",children:[M.length>0?s.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:Q(M)}):null,s.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5","aria-hidden":!0,children:[s.jsx("span",{className:"h-px flex-1 bg-border/60"}),s.jsxs("span",{className:"inline-flex max-w-[80%] items-center gap-1 typography-micro text-muted-foreground",children:[s.jsx("span",{className:"truncate",title:g.branchName,children:g.branchName}),F]}),s.jsx("span",{className:"h-px flex-1 bg-border/60"})]}),z.length>0?s.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:Q(z)}):null]}):Q(n.all)}),e[5]=g,e[6]=d,e[7]=x,e[8]=u,e[9]=o,e[10]=k,e[11]=S,e[12]=p,e[13]=n.all,e[14]=m,e[15]=c,e[16]=w,e[17]=M,e[18]=P}else P=e[18];const A=P;if(!v){if(S){let K;return e[28]!==A?(K=s.jsx("section",{className:"h-full min-h-0",children:A}),e[28]=A,e[29]=K):K=e[29],K}let z;return e[30]!==A?(z=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]=z):z=e[31],z}let N;e[32]!==w?(N=w("gitView.history.title"),e[32]=w,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 T;e[36]!==r||e[37]!==y||e[38]!==a||e[39]!==i||e[40]!==w?(T=y&&s.jsx("div",{onClick:r0,onPointerDown:a0,children:s.jsxs(os,{value:String(a),onValueChange:z=>i(Number(z)),disabled:r,children:[s.jsx(ls,{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:w("gitView.history.commitsPlaceholder")})}),s.jsx(cs,{children:s0.map(z=>s.jsx(Tt,{value:String(z.value),children:w(z.labelKey)},z.value))})]})}),e[36]=r,e[37]=y,e[38]=a,e[39]=i,e[40]=w,e[41]=T):T=e[41];let R;e[42]!==y?(R=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]=R):R=e[43];let V;e[44]!==T||e[45]!==R?(V=s.jsxs("div",{className:"flex items-center gap-2",children:[T,R]}),e[44]=T,e[45]=R,e[46]=V):V=e[46];let _;e[47]!==V||e[48]!==E?(_=s.jsxs(kr,{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]=_):_=e[49];let U;e[50]!==A?(U=s.jsx(hr,{children:A}),e[50]=A,e[51]=U):U=e[51];let B;return e[52]!==y||e[53]!==_||e[54]!==U?(B=s.jsxs(fr,{open:y,onOpenChange:C,className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[_,U]}),e[52]=y,e[53]=_,e[54]=U,e[55]=B):B=e[55],B};function r0(t){return t.stopPropagation()}function a0(t){return t.stopPropagation()}const i0=9e4,o0=15e3,l0=5*6e4,c0=[2e3,5e3],d0=6e4,u0=2*6e4,m0=5*6e4,p0=720*6e4,f0="openchamber.github-pr-status",h0=t=>t==="closed"||t==="merged",g0=t=>{const e=t?.checks;return e?e.state==="pending"||e.pending>0:!1},Hi=(t,e,n)=>`${t}::${e}`,Ao=new Map,Do=new Map,Di=new Set,Pm=new Map,Bi=()=>({status:null,isLoading:!1,error:null,isInitialStatusResolved:!1,lastRefreshAt:0,lastDiscoveryPollAt:0,watchers:0,params:null,identity:null,resolvedRemoteName:null}),bl=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,Gd=t=>{const e=bl(t);return!e?.directory||!e.branch?null:`${e.directory}::${e.branch}`},Uh=(t,e)=>Object.entries(t).filter(([,n])=>Gd(n)===e).map(([n])=>n),x0=(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}}},To=t=>!t?.params?.canShow||!t.params.github?.prStatus?null:{...t.params,remoteName:t.params.remoteName??t.resolvedRemoteName??t.identity?.remoteName??null},b0=(t,e,n)=>{const r=Uh(t,e),a=r.map(d=>To(t[d])).filter(d=>!!d);if(a.length===0)return null;const i=To(t[n]);if(i&&Gd(t[n])===e)return i;const o=r.map(d=>t[d]).find(d=>!!(d?.resolvedRemoteName&&To(d)));if(o)return To(o);const c=a.find(d=>!!d.remoteName);return c||(a[0]??null)},y0=t=>({status:t.status,isInitialStatusResolved:t.isInitialStatusResolved,lastRefreshAt:t.lastRefreshAt,lastDiscoveryPollAt:t.lastDiscoveryPollAt,identity:bl(t),resolvedRemoteName:t.resolvedRemoteName??t.status?.resolvedRemoteName??null}),v0=t=>({...Bi(),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}),mr=Zn()(oo((t,e)=>({entries:{},activeRequestCount:0,totalRequestCount:0,ensureEntry:n=>{t(r=>r.entries[n]?r:{entries:{...r.entries,[n]:Bi()}})},setParams:(n,r)=>{t(a=>{const i=a.entries[n]??Bi();return{entries:{...a.entries,[n]:x0(i,r)}}})},startWatching:n=>{if(t(i=>{const o=i.entries[n]??Bi();return{entries:{...i.entries,[n]:{...o,watchers:o.watchers+1}}}}),Ao.has(n))return;const r=i=>{const o=window.setTimeout(()=>{if(typeof document<"u"&&document.visibilityState!=="visible")return;const d=e().entries[n];!d||d.watchers<=0||d.status?.pr||e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0})},i),c=Do.get(n)??[];c.push(o),Do.set(n,c)};e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0}),c0.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<l0)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(h0(i.status?.pr?.state))return;const c=Date.now()-i.lastRefreshAt,d=g0(i.status)?d0:i.status?.checks&&i.status.checks.state!=="pending"?m0:u0;c<d||e().refresh(n,{force:!0,onlyExistingPr:!0,silent:!0,markInitialResolved:!0})},o0);Ao.set(n,a)},stopWatching:n=>{t(o=>{const c=o.entries[n];if(!c)return o;const d=Math.max(0,c.watchers-1);return{entries:{...o.entries,[n]:{...c,watchers:d}}}});const r=e().entries[n];if(r&&r.watchers>0)return;const a=Ao.get(n);typeof a=="number"&&window.clearInterval(a),Ao.delete(n);const i=Do.get(n);i&&i.length>0&&i.forEach(o=>{window.clearTimeout(o)}),Do.delete(n)},refresh:async(n,r)=>{const a=e(),i=a.entries[n],o=Gd(i);if(!i||!o)return;const c=Uh(a.entries,o),d=c.some(u=>!!a.entries[u]?.status?.pr);if(r?.onlyExistingPr&&!d)return;const p=Pm.get(o)??0;if(!r?.force&&Date.now()-p<i0||Di.has(o))return;const m=b0(a.entries,o,n);if(m){if(Di.add(o),Pm.set(o,Date.now()),t(u=>{const f={...u.entries};return c.forEach(b=>{const h=f[b];h&&(f[b]={...h,lastRefreshAt:Date.now(),isLoading:r?.silent?h.isLoading:!0,error:null})}),{entries:f}}),m.githubAuthChecked&&m.githubConnected===!1){t(u=>{const f={...u.entries};return c.forEach(b=>{const h=f[b];h&&(f[b]={...h,status:{connected:!1},error:null,isLoading:r?.silent?h.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?h.isInitialStatusResolved:!0})}),{entries:f}}),Di.delete(o);return}if(!m.github?.prStatus){t(u=>{const f={...u.entries};return c.forEach(b=>{const h=f[b];h&&(f[b]={...h,status:null,error:"GitHub runtime API unavailable",isLoading:r?.silent?h.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?h.isInitialStatusResolved:!0})}),{entries:f}}),Di.delete(o);return}try{t(f=>({...f,activeRequestCount:f.activeRequestCount+1,totalRequestCount:f.totalRequestCount+1}));const u=await m.github.prStatus(m.directory,m.branch,m.remoteName??void 0,{force:r?.force});t(f=>{const b={...f.entries};return c.forEach(h=>{const v=b[h];if(!v)return;const x=v.status?.pr,g=u.pr,y=!!(g&&x&&g.number===x.number&&(!g.body||!g.body.trim())&&typeof x.body=="string"&&x.body.trim().length>0)&&g&&x?.body?{...u,pr:{...g,body:x.body}}:u,C=y.resolvedRemoteName??v.resolvedRemoteName??m.remoteName??null,k=bl(v)??{directory:m.directory,branch:m.branch,remoteName:m.remoteName??null};b[h]={...v,status:y,error:null,isLoading:r?.silent?v.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?v.isInitialStatusResolved:!0,resolvedRemoteName:C,identity:{...k,remoteName:C??k.remoteName??null}}}),{entries:b}})}catch(u){const f=u instanceof Error?u.message:String(u);t(b=>{const h={...b.entries};return c.forEach(v=>{const x=h[v];x&&(h[v]={...x,error:f||"Failed to load PR status",isLoading:r?.silent?x.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?x.isInitialStatusResolved:!0})}),{entries:h}})}finally{Di.delete(o),t(u=>({...u,activeRequestCount:Math.max(0,u.activeRequestCount-1)}))}}},refreshTargets:async(n,r)=>{const a=Array.from(new Set(n.map(i=>{const o=i.directory.trim(),c=i.branch.trim();return!o||!c?null:Hi(o,c,i.remoteName??null)}).filter(i=>!!i)));await Promise.all(a.map(i=>e().refresh(i,r)))},updateStatus:(n,r)=>{t(a=>{const i=a.entries[n]??Bi();return{entries:{...a.entries,[n]:{...i,status:r(i.status)}}}})}}),{name:f0,storage:Cl(()=>vr()),partialize:t=>({entries:Object.fromEntries(Object.entries(t.entries).filter(([,e])=>{const n=bl(e);if(!n?.directory||!n.branch)return!1;const r=Math.max(e.lastRefreshAt,e.lastDiscoveryPollAt);return r===0||Date.now()-r<p0}).map(([e,n])=>[e,y0(n)]))}),merge:(t,e)=>{const n=t?.entries??{};return{...e,entries:Object.fromEntries(Object.entries(n).map(([a,i])=>[a,v0(i)]))}}})),w0=t=>{const e=t?.pr;if(!e)return null;if(e.state==="merged")return"merged";if(e.state==="closed")return"closed";if(e.draft)return"draft";const n=t?.checks?.state==="failure",r=typeof e.mergeableState=="string"?e.mergeableState:"",a=e.mergeable===!1||r==="blocked"||r==="dirty";return n||a?"blocked":"open"},j0=t=>{const e=w0(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}},N0=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 pc=new Map,Am=new Map;const S0=t=>{const e=st.c(2);let n;return e[0]!==t?(n=r=>{const a=new Map,i=new Map;for(const o of t){const c=r.entries[o];if(!c)continue;const d=j0(c);if(!d)continue;const p=N0(d);a.set(o,p),i.set(o,d)}if(a.size===pc.size){let o=!0;for(const[c,d]of a)if(pc.get(c)!==d){o=!1;break}if(o)return Am}return pc=a,Am=i,i},e[0]=t,e[1]=n):n=e[1],mr(n)},k0=t=>{switch(t){case"success":return"bg-[color:var(--status-success)]";case"failure":return"bg-[color:var(--status-error)]";case"pending":return"bg-[color:var(--status-warning)]";default:return"bg-muted-foreground/40"}},C0=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"},I0=[2e3,5e3],Dm=t=>t.replace(/^refs\/heads\//,"").replace(/[-_]+/g," ").replace(/\s+/g," ").trim().replace(/\b\w/g,e=>e.toUpperCase()),ia=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):""},P0=(t,e)=>{const n=ia(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},A0=(t,e)=>`${t}::${e}`,qd=t=>{const e=String(t||"").trim();if(!e)return"";const n=e.indexOf("/");return n<=0?"":e.slice(0,n).trim()},fc=(t,e)=>{if(t.length===0)return null;const n=String(e.selectedRemoteName||"").trim();if(n){const i=t.find(o=>o.name===n);if(i)return i}const r=qd(e.trackingBranch);if(r){const i=r==="origin"?t.find(c=>c.name==="upstream"):null;if(i)return i;const o=t.find(c=>c.name===r);if(o)return o}const a=t.find(i=>i.name==="origin");return a||(t[0]??null)},D0=t=>t.startsWith("pr-"),T0=(t,e)=>{const n=qd(e),r=new Map(t.map(o=>[o.name,o])),a=[],i=o=>{o&&(a.some(c=>c.name===o.name)||a.push(o))};return n&&i(r.get(n)),i(r.get("upstream")),i(r.get("origin")),t.filter(o=>!D0(o.name)).forEach(o=>i(o)),t.forEach(o=>i(o)),a},hc=new Map,gc=qn;function M0(t,e){const[n,r]=l.useState(null),[a,i]=l.useState([]),o=l.useRef(null);return l.useEffect(()=>{r(null),i([])},[t]),l.useEffect(()=>{if(!t||!e?.repoUpstream||o.current===t)return;o.current=t;let c=!1;return(async()=>{try{const d=await e.repoUpstream(t);if(c||!d?.isFork||!d.upstream||(r(d.upstream),!e.repoBranches))return;try{const p=await e.repoBranches(d.upstream.owner,d.upstream.repo);c||i(p)}catch{}}catch{}})(),()=>{c=!0}},[t,e]),{detectedUpstream:n,upstreamBranches:a}}const E0=({directory:t,branch:e,baseBranch:n,trackingBranch:r,remotes:a=[],remoteBranches:i=[],onGeneratedDescription:o})=>{const{t:c}=dt(),{github:d}=Rn(),p=Bn(Ue=>Ue.status),m=Bn(Ue=>Ue.hasChecked),u=Re(Ue=>Ue.setSettingsDialogOpen),f=Re(Ue=>Ue.setSettingsPage),b=Re(Ue=>Ue.setActiveMainTab),h=Lt(Ue=>Ue.currentSessionId),{isMobile:v,hasTouchInput:x}=nn(),g=l.useCallback(()=>{f("github"),u(!0)},[u,f]),w=l.useMemo(()=>A0(t,e),[t,e]),y=l.useMemo(()=>hc.get(w)??null,[w]),C=mr(Ue=>Ue.ensureEntry),k=mr(Ue=>Ue.setParams),j=mr(Ue=>Ue.startWatching),S=mr(Ue=>Ue.stopWatching),I=mr(Ue=>Ue.refresh),M=mr(Ue=>Ue.updateStatus),[P,A]=l.useState(()=>y?.title??Dm(e)),[N,E]=l.useState(()=>y?.body??""),[T,R]=l.useState(()=>y?.draft??!1),[V,_]=l.useState(()=>y?.additionalContext??""),[U,B]=l.useState(()=>{const Ue=typeof y?.targetBaseBranch=="string"?ia(y.targetBaseBranch):"";return Ue||ia(n)}),[z,K]=l.useState("squash"),[F,G]=l.useState(!1),[Q,te]=l.useState(!1),[Z,fe]=l.useState(!1),[ue,W]=l.useState(!1),[q,J]=l.useState(!1),[ne,ee]=l.useState(!1),[he,ke]=l.useState(null),[oe,ge]=l.useState(""),[me,ye]=l.useState(""),[ie,ve]=l.useState(!1),[X,Se]=l.useState(!1),[Ae,pe]=l.useState(()=>fc(a,{selectedRemoteName:y?.selectedRemoteName,trackingBranch:r})),[we,Ie]=l.useState(!1),{detectedUpstream:Y,upstreamBranches:re}=M0(t,d);l.useEffect(()=>{Ie(!1)},[t]);const Pe=a.some(Ue=>Ue.name==="upstream"),Ce=!!(t&&e&&n&&(e!==n||(Pe||Y!==null))),Te=l.useMemo(()=>Hi(t,e),[t,e]),$e=mr(Ue=>Ue.entries[Te]),De=$e?.isLoading??!1,de=$e?.status??null,O=$e?.error??null,L=$e?.isInitialStatusResolved??!1,$=l.useMemo(()=>{const Ue=we?null:Ae?.name?.trim()||null,gt=new Set;for(const ts of i){const Ot=P0(ts,Ue);!Ot||Ot==="HEAD"||gt.add(Ot)}if(we)for(const ts of re)ts&&ts!=="HEAD"&&gt.add(ts);const Pt=ia(n);Pt&&Pt!=="HEAD"&&gt.add(Pt);const Mt=ia(U);return Mt&&Mt!=="HEAD"&&gt.add(Mt),Array.from(gt).sort((ts,Ot)=>ts.localeCompare(Ot))},[n,i,Ae?.name,U,re,we]);l.useEffect(()=>{if(a.length===0){Ae&&pe(null);return}(!Ae||!a.some(Ue=>Ue.name===Ae.name))&&pe(fc(a,{selectedRemoteName:y?.selectedRemoteName,trackingBranch:r}))},[y?.selectedRemoteName,a,Ae,r]),l.useEffect(()=>{const Ue=ia(n);if(!U&&Ue){B(Ue);return}if($.length!==0&&!$.includes(U)){const gt=$.includes(Ue)?Ue:$[0];gt&&B(gt)}},[$,n,U]);const[je,ae]=l.useState(!1),[_e,le]=l.useState(null),[Me,Ge]=l.useState(!1),[at,Ye]=l.useState(new Set),[Xe,ut]=l.useState(!1),[rt,it]=l.useState(null),[nt,Ne]=l.useState(!1),Ke=l.useRef(new Set),Ve=l.useRef(null),qe=l.useRef(!1),lt=l.useRef(new Set),He=l.useRef([]);l.useEffect(()=>{Y&&!Pe&&Ie(!0)},[Y,Pe]),l.useEffect(()=>{we&&Y?.defaultBranch&&B(Y.defaultBranch)},[we,Y?.defaultBranch]);const ze=de?.pr??null,et=ze?`${t}#${ze.number}`:null,yt=!!(et&&he===et);l.useEffect(()=>{if(!d?.prContext||!ze||typeof ze.body=="string"&&ze.body.length>0)return;const Ue=`${t}#${ze.number}`;if(Ke.current.has(Ue))return;Ke.current.add(Ue),ke(Ue);let gt=!1;return d.prContext(t,ze.number,{includeDiff:!1,includeCheckDetails:!1}).then(Pt=>{if(gt)return;const Mt=Pt?.pr;Mt&&M(Te,ts=>!ts?.pr||ts.pr.number!==ze.number?ts:{...ts,pr:{...ts.pr,body:Mt.body||""}})}).catch(()=>{}).finally(()=>{gt||ke(Pt=>Pt===Ue?null:Pt)}),()=>{gt=!0}},[t,d,ze,Te,M]),l.useEffect(()=>{if(!ze){ee(!1),ge(""),ye(""),Ve.current=null;return}const Ue=Ve.current!==null&&Ve.current!==ze.number;Ue&&ee(!1),(!ne||Ue)&&(ge(ze.title||""),ye(ze.body||"")),Ve.current=ze.number},[ne,ze]);const Rt=l.useCallback(async()=>{if(!d?.prContext){H.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(ze){ae(!0),Ye(new Set),Ge(!0);try{const Ue=await d.prContext(t,ze.number,{includeDiff:!1,includeCheckDetails:!0});le(Ue)}catch(Ue){const gt=Ue instanceof Error?Ue.message:String(Ue);H.error(c("gitView.pr.toast.loadCheckDetailsFailed"),{description:gt})}finally{Ge(!1)}}},[t,d,ze,c]),kt=l.useCallback(async()=>{if(!d?.prContext){H.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(ze){ut(!0),Ne(!0);try{const Ue=await d.prContext(t,ze.number,{includeDiff:!1,includeCheckDetails:!1});it(Ue)}catch(Ue){const gt=Ue instanceof Error?Ue.message:String(Ue);H.error(c("gitView.pr.toast.loadCommentsFailed"),{description:gt})}finally{Ne(!1)}}},[t,d,ze,c]),ht=l.useCallback(Ue=>{if(!Ue)return"";const gt=Date.parse(Ue);return Number.isFinite(gt)?new Date(gt).toLocaleString():Ue},[]),vt=l.useMemo(()=>{const Ue=p?.user?.login;return typeof Ue=="string"?Ue.trim():""},[p]),ns=l.useMemo(()=>"[&_a[href*='oc-self-mention=1']]:!text-[var(--primary-base)] [&_a[href*='oc-self-mention=1']]:font-semibold [&_a[href*='oc-self-mention=1']]:!no-underline [&_a[href*='oc-self-mention=1']:hover]:!text-[var(--primary-hover)]",[]),zt=l.useCallback(Ue=>{const gt=vt.toLowerCase(),Pt=/(^|[^\w`])@([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,38}))/g;return Ue.replace(Pt,(Mt,ts,Ot)=>{const ks=`@${Ot}`,Zs=Ot.toLowerCase();return`${ts}[${ks}](https://github.com/${Zs}${gt&&Zs===gt?"?oc-self-mention=1":""})`})},[vt]),Kt=l.useMemo(()=>{const Ue=(rt?.issueComments??[]).map(Mt=>({id:`issue-${Mt.id}`,body:Mt.body||"",authorName:Mt.author?.name||Mt.author?.login||c("gitView.pr.comments.unknownAuthor"),authorLogin:Mt.author?.login||null,avatarUrl:Mt.author?.avatarUrl||null,createdAt:Mt.createdAt,context:c("gitView.pr.comments.generalContext"),path:null,line:null})),gt=(rt?.reviewComments??[]).map(Mt=>({id:`review-${Mt.id}`,body:Mt.body||"",authorName:Mt.author?.name||Mt.author?.login||c("gitView.pr.comments.unknownAuthor"),authorLogin:Mt.author?.login||null,avatarUrl:Mt.author?.avatarUrl||null,createdAt:Mt.createdAt,context:c("gitView.pr.comments.reviewContext"),path:Mt.path||null,line:Mt.line??null})),Pt=[...Ue,...gt];return Pt.sort((Mt,ts)=>{const Ot=Mt.createdAt?Date.parse(Mt.createdAt):0,ks=ts.createdAt?Date.parse(ts.createdAt):0,Zs=Number.isFinite(Ot)?Ot:0,Hs=Number.isFinite(ks)?ks:0;return Zs-Hs}),Pt},[rt,c]),mt=l.useCallback(()=>{if(!h)return H.error(c("gitView.pr.toast.noActiveSession"),{description:c("gitView.pr.toast.noActiveSessionDescription")}),null;const{currentProviderId:Ue,currentModelId:gt,currentAgentName:Pt,currentVariant:Mt}=bt.getState(),ts=Pl.getState().lastUsedProvider,Ot=Ue||ts?.providerID,ks=gt||ts?.modelID;return!Ot||!ks?(H.error(c("gitView.pr.toast.noModelSelected")),null):{sessionId:h,providerID:Ot,modelID:ks,currentAgentName:Pt??null,currentVariant:Mt??null}},[h,c]),Et=l.useCallback((Ue,gt,Pt,Mt)=>{Lt.getState().sendMessage(gt,Ue.providerID,Ue.modelID,Ue.currentAgentName??void 0,void 0,void 0,[{text:Pt,synthetic:!0},{text:Mt,synthetic:!0}],Ue.currentVariant??void 0).catch(ts=>{const Ot=ts instanceof Error?ts.message:String(ts);H.error(c("gitView.pr.toast.sendMessageFailed"),{description:Ot})})},[c]),rs=l.useCallback(Ue=>{const gt=Ue.status||"unknown",Pt=Ue.conclusion??void 0,Mt=Pt?`${gt} / ${Pt}`:gt,ts=Ue.app?.name||Ue.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:Ue.name}),s.jsx("div",{className:"typography-micro text-muted-foreground truncate",children:ts?`${ts} · ${Mt}`:Mt})]}),Ue.detailsUrl?s.jsx(be,{variant:"outline",size:"sm",asChild:!0,className:"flex-shrink-0",children:s.jsxs("a",{href:Ue.detailsUrl,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(D,{name:"external-link",className:"size-4"}),"Open"]})}):null]}),Ue.output?.title?s.jsx("div",{className:"typography-micro text-foreground",children:Ue.output.title}):null,Ue.output?.summary?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap",children:Ue.output.summary}):null,Ue.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:Ue.output.text}):null,Array.isArray(Ue.annotations)&&Ue.annotations.length>0?s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"typography-micro text-muted-foreground",children:["Failed annotations",Ue.annotations.length>20?` (showing 20/${Ue.annotations.length})`:""]}),s.jsx("div",{className:"space-y-1",children:Ue.annotations.slice(0,20).map((Ot,ks)=>s.jsxs("div",{className:"rounded border border-[var(--status-error-border)] bg-[var(--status-error-background)]/40 px-2 py-2",children:[s.jsxs("div",{className:"typography-micro text-[var(--status-error)]",children:[Ot.title||Ot.level||"Issue",Ot.path?` · ${Ot.path}`:"",typeof Ot.startLine=="number"?`:${Ot.startLine}`:"",typeof Ot.endLine=="number"&&Ot.endLine!==Ot.startLine?`-${Ot.endLine}`:""]}),s.jsx("div",{className:"typography-micro text-foreground whitespace-pre-wrap mt-1",children:Ot.message}),Ot.rawDetails?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap mt-1",children:Ot.rawDetails}):null]},`${Ot.path||"file"}:${Ot.startLine||ks}:${ks}`))})]}):null,Ue.job?.steps&&Ue.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:Ue.job.steps.map((Ot,ks)=>{const Zs=(Ot.conclusion||"").toLowerCase(),Hs=Zs&&!["success","neutral","skipped"].includes(Zs),ss=`${Ue.id??"run"}:${Ue.job?.jobId??"job"}:${Ot.number??ks}:${Ot.name}`,Es=at.has(ss);return Hs?s.jsxs(fr,{open:Es,children:[s.jsxs("button",{type:"button",onClick:()=>{Ye(Pn=>{const an=new Set(Pn);return an.has(ss)?an.delete(ss):an.add(ss),an})},className:"typography-micro flex w-full items-center gap-2 rounded px-2 py-1 text-left "+(Hs?"bg-destructive/10 text-destructive":"text-muted-foreground"),children:[Es?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:Ot.name}),Ot.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:Ot.conclusion}):null]}),s.jsx(hr,{children:s.jsxs("div",{className:"ml-6 mt-1 rounded border border-border/40 bg-transparent px-2 py-2 typography-micro text-muted-foreground space-y-1",children:[typeof Ot.number=="number"?s.jsxs("div",{children:[c("gitView.pr.checks.stepLabel"),": ",Ot.number]}):null,Ot.status?s.jsxs("div",{children:[c("gitView.pr.checks.statusLabel"),": ",Ot.status]}):null,Ot.conclusion?s.jsxs("div",{children:[c("gitView.pr.checks.conclusionLabel"),": ",Ot.conclusion]}):null,Ot.startedAt?s.jsxs("div",{children:[c("gitView.pr.checks.startedLabel"),": ",ht(Ot.startedAt)]}):null,Ot.completedAt?s.jsxs("div",{children:[c("gitView.pr.checks.completedLabel"),": ",ht(Ot.completedAt)]}):null]})})]},ss):s.jsxs("div",{className:"typography-micro flex w-full items-center gap-2 rounded px-2 py-1 text-muted-foreground",children:[s.jsx("span",{className:"truncate",children:Ot.name}),Ot.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:Ot.conclusion}):null]},ss)})})]}):null]})},[at,ht,c]),gs=l.useCallback(async()=>{if(b("chat"),!d?.prContext){H.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!ze)return;const Ue=mt();if(Ue)try{const gt=await d.prContext(t,ze.number,{includeDiff:!1,includeCheckDetails:!0}),Mt=(gt.checkRuns??[]).filter(Hs=>{const ss=typeof Hs.conclusion=="string"?Hs.conclusion.toLowerCase():"";return ss?!["success","neutral","skipped"].includes(ss):!1});if(Mt.length===0){H.message(c("gitView.pr.toast.noFailedChecks"));return}const ts=await yn("github.pr.checks.review.visible"),Ot=await yn("github.pr.checks.review.instructions"),ks=Mt.flatMap(Hs=>(Array.isArray(Hs.annotations)?Hs.annotations:[]).map(Es=>({run:Hs.name,level:Es.level,title:Es.title,path:Es.path,startLine:Es.startLine,endLine:Es.endLine,message:Es.message,rawDetails:Es.rawDetails}))),Zs=`GitHub PR failed checks (JSON)
39
+ ${JSON.stringify({repo:gt.repo??null,pr:gt.pr??null,failedChecks:Mt,failedAnnotations:ks},null,2)}`;Et(Ue,ts,Ot,Zs)}catch(gt){const Pt=gt instanceof Error?gt.message:String(gt);H.error(c("gitView.pr.toast.loadChecksFailed"),{description:Pt})}},[t,Et,d,ze,mt,b,c]),xs=l.useCallback(async()=>{if(b("chat"),!d?.prContext){H.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!ze)return;const Ue=mt();if(Ue)try{const gt=await d.prContext(t,ze.number,{includeDiff:!1,includeCheckDetails:!1}),Pt=gt.issueComments??[],Mt=gt.reviewComments??[];if(Pt.length+Mt.length===0){H.message(c("gitView.pr.toast.noPrComments"));return}const Ot=await yn("github.pr.comments.review.visible"),ks=await yn("github.pr.comments.review.instructions"),Zs=`GitHub PR comments (JSON)
40
+ ${JSON.stringify({repo:gt.repo??null,pr:gt.pr??null,issueComments:Pt,reviewComments:Mt},null,2)}`;Et(Ue,Ot,ks,Zs)}catch(gt){const Pt=gt instanceof Error?gt.message:String(gt);H.error(c("gitView.pr.toast.loadPrCommentsFailed"),{description:Pt})}},[t,Et,d,ze,mt,b,c]),bs=l.useCallback(async Ue=>{ut(!1),b("chat");const gt=mt();if(!gt)return;const Pt=await yn("github.pr.comment.single.visible"),Mt=await yn("github.pr.comment.single.instructions"),ts=`GitHub PR comment (JSON)
41
+ ${JSON.stringify({repo:rt?.repo??null,pr:rt?.pr??ze??null,comment:Ue},null,2)}`;Et(gt,Pt,Mt,ts)},[rt,Et,ze,mt,b]),Wt=l.useCallback(async Ue=>{await I(Te,Ue)},[Te,I]),We=l.useCallback(()=>{He.current.forEach(Ue=>{window.clearTimeout(Ue)}),He.current=I0.map(Ue=>window.setTimeout(()=>{Wt({force:!0,silent:!0,markInitialResolved:!0})},Ue))},[Wt]);l.useEffect(()=>{if(!d?.prStatus||!Ce||a.length<=1||qe.current||de?.pr)return;const Ue=`${w}::${Ae?.name??""}`;if(lt.current.has(Ue))return;lt.current.add(Ue);const gt=T0(a,r).filter(ts=>ts.name!==Ae?.name);if(gt.length===0)return;let Pt=!1;return(async()=>{for(const ts of gt){if(Pt)return;try{if(!(await d.prStatus(t,e,ts.name))?.pr)continue;if(Pt)return;pe(ks=>ks?.name===ts.name?ks:ts);return}catch{}}})(),()=>{Pt=!0}},[e,Ce,t,d,a,Ae?.name,w,de?.pr,r]),l.useEffect(()=>{C(Te),k(Te,{directory:t,branch:e,remoteName:Ae?.name??null,canShow:Ce,github:d,githubAuthChecked:m,githubConnected:p?.connected??null})},[e,Ce,t,C,d,m,p?.connected,Te,Ae?.name,k]),l.useEffect(()=>(j(Te),()=>{S(Te)}),[Te,j,S]),l.useEffect(()=>{const Ue=hc.get(w)??null;A(Ue?.title??Dm(e)),E(Ue?.body??""),R(Ue?.draft??!1),B(Ue?.targetBaseBranch?ia(Ue.targetBaseBranch):ia(n));const gt=fc(a,{selectedRemoteName:Ue?.selectedRemoteName,trackingBranch:r});pe(Pt=>Pt?.name===gt?.name?Pt:gt)},[n,e,a,w,r]),l.useEffect(()=>{Wt({markInitialResolved:!0})},[Te,Wt]),l.useEffect(()=>{!Ce||!Ae?.name||Wt({force:!0,silent:!0,markInitialResolved:!0})},[Ce,Wt,Ae?.name]),l.useEffect(()=>{const Ue=de?.resolvedRemoteName?.trim();if(!Ue||qe.current)return;const gt=a.find(Pt=>Pt.name===Ue);gt&&pe(Pt=>Pt?.name===gt.name?Pt:gt)},[a,de?.resolvedRemoteName]),l.useEffect(()=>{const Ue=de?.pr?.state==="closed"||de?.pr?.state==="merged",gt=$e?.lastRefreshAt??0,Pt=Date.now()-gt>6e4,Mt=!Ue&&Pt,ts=()=>{Mt&&Wt({force:!0,silent:!0})},Ot=()=>{document.visibilityState==="visible"&&Mt&&Wt({force:!0,silent:!0})};return window.addEventListener("focus",ts),document.addEventListener("visibilitychange",Ot),()=>{window.removeEventListener("focus",ts),document.removeEventListener("visibilitychange",Ot)}},[Wt,de?.pr?.state,$e?.lastRefreshAt]),l.useEffect(()=>{m&&p?.connected===!1&&Wt({force:!0,silent:!0,markInitialResolved:!0})},[m,p,Wt]),l.useEffect(()=>{!t||!e||hc.set(w,{title:P,body:N,draft:T,additionalContext:V,targetBaseBranch:U,selectedRemoteName:Ae?.name})},[w,P,N,T,V,U,Ae?.name,t,e]),l.useEffect(()=>{const Ue=He.current;return()=>{Ue.forEach(gt=>{window.clearTimeout(gt)}),He.current=[]}},[]);const St=l.useCallback(async()=>{if(!F&&t){G(!0);try{const gt={base:we&&Y?.defaultBranchSha?Y.defaultBranchSha:U,head:e};V&&(gt.context=V);const Pt=await wb(t,gt);Pt.title?.trim()&&A(Pt.title.trim()),Pt.body?.trim()&&E(Pt.body.trim()),o?.()}catch(Ue){const gt=Ue instanceof Error?Ue.message:String(Ue);H.error(c("gitView.pr.toast.generateDescriptionFailed"),{description:gt})}finally{G(!1)}}},[V,e,Y?.defaultBranchSha,t,F,o,U,c,we]),qt=l.useCallback(async()=>{if(!d?.prCreate){H.error(c("gitView.pr.toast.githubApiUnavailable"));return}const Ue=P.trim();if(!Ue){H.error(c("gitView.pr.toast.titleRequired"));return}const gt=U.trim();if(!gt){H.error(c("gitView.pr.toast.baseBranchRequired"));return}if(!we&&gt===e){H.error(c("gitView.pr.toast.baseMustDifferFromHead"));return}te(!0);try{const Pt=qd(r),Mt=we&&Y,ts=await d.prCreate({directory:t,title:Ue,head:e,base:gt,...N.trim()?{body:N}:{},draft:T,...Mt?{targetRepo:{owner:Y.owner,repo:Y.repo},headRemote:"origin"}:{...Ae?{remote:Ae.name}:{},...Pt&&Pt!==Ae?.name?{headRemote:Pt}:{}}});H.success(c("gitView.pr.toast.prCreated")),M(Te,Ot=>Ot&&{...Ot,pr:ts}),await Wt({force:!0}),We()}catch(Pt){const Mt=Pt instanceof Error?Pt.message:String(Pt);H.error(c("gitView.pr.toast.createPrFailed"),{description:Mt})}finally{te(!1)}},[N,e,Y,t,T,d,Te,Wt,We,Ae,U,P,r,M,we,c]),wt=l.useCallback(async Ue=>{if(!d?.prMerge){H.error(c("gitView.pr.toast.githubApiUnavailable"));return}W(!0);try{const gt=await d.prMerge({directory:t,number:Ue.number,method:z});gt.merged?H.success(c("gitView.pr.toast.prMerged")):H.message(c("gitView.pr.toast.prNotMerged"),{description:gt.message||c("gitView.pr.notMergeable")}),await Wt({force:!0}),We()}catch(gt){const Pt=gt instanceof Error?gt.message:String(gt);H.error(c("gitView.pr.toast.mergeFailed"),{description:Pt}),Ue.url&&gc(Ue.url)}finally{W(!1)}},[t,d,z,Wt,We,c]),es=l.useCallback(async Ue=>{if(!d?.prReady){H.error(c("gitView.pr.toast.githubApiUnavailable"));return}J(!0);try{await d.prReady({directory:t,number:Ue.number}),H.success(c("gitView.pr.toast.markedReady")),await Wt({force:!0}),We()}catch(gt){const Pt=gt instanceof Error?gt.message:String(gt);H.error(c("gitView.pr.toast.markReadyFailed"),{description:Pt}),Ue.url&&gc(Ue.url)}finally{J(!1)}},[t,d,Wt,We,c]),ds=l.useCallback(async Ue=>{if(!d?.prUpdate){H.error(c("gitView.pr.toast.githubApiUnavailable"));return}const gt=oe.trim();if(!gt){H.error(c("gitView.pr.toast.titleRequired"));return}fe(!0);try{const Pt=await d.prUpdate({directory:t,number:Ue.number,title:gt,body:me});M(Te,Mt=>Mt&&{...Mt,pr:{...Mt.pr??Ue,...Pt}}),ee(!1),H.success(c("gitView.pr.toast.prUpdated")),await Wt({force:!0}),We()}catch(Pt){const Mt=Pt instanceof Error?Pt.message:String(Pt);H.error(c("gitView.pr.toast.updatePrFailed"),{description:Mt})}finally{fe(!1)}},[t,me,oe,d,Te,Wt,We,M,c]);if(!Ce)return s.jsx("section",{className:"border-0 bg-transparent rounded-none",children:s.jsxs("div",{className:"space-y-1 pt-3",children:[s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:c("gitView.pullRequest.title")}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pullRequest.availableOnFeatureBranches")})]})});const Ms=de?.repo?.url||null,as=we&&Y?.url?Y.url:Ms,$s=de?.checks??null,Ls=!!de?.canMerge,ln=!!de?.connected,Xs=m&&de?.connected===!1,Vt=C0(de),Ut=Vt?`var(--pr-${Vt})`:"var(--status-info)",se=Vt==="draft"?"git-pr-draft":Vt==="merged"?"git-merge":Vt==="closed"?"git-close-pull-request":"git-pull-request",xt=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(" · "):"",Je=$s?$s.total>0?`${$s.success}/${$s.total} ${c("gitView.pr.checks.label")}`:`${$s.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(Ct,{children:[s.jsx(It,{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:()=>{gc(ze.url)},"aria-label":c("gitView.pr.actions.openOnGitHubAria"),children:s.jsx(D,{name:se,className:"size-4 shrink-0",style:{color:Ut}})})}),s.jsx(At,{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:[De?s.jsx(D,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}):null,s.jsxs(Ct,{children:[s.jsx(It,{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:De,onClick:()=>{Wt({force:!0})},"aria-label":c("gitView.pr.actions.refreshAria"),children:s.jsx(D,{name:"refresh",className:"size-3.5 text-muted-foreground"})})}),s.jsx(At,{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:Ut},children:xt}),$s?s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx("span",{className:`h-2 w-2 rounded-full ${k0($s.state)}`}),Je]}):null,r&&Ae&&r.split("/")[0]!==Ae.name?s.jsxs("span",{className:"min-w-0 truncate",children:[r.split("/")[0]," → ",Ae.name]}):null]}):null]}),s.jsxs("div",{className:"flex flex-col gap-3 py-3",children:[Xs?s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-meta text-muted-foreground",children:c("gitView.pr.githubNotConnected")}),s.jsx(be,{variant:"outline",size:"sm",onClick:g,className:"w-fit",children:c("gitView.pr.actions.openSettings")})]}):null,O?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:O}),as?s.jsx(be,{variant:"outline",size:"sm",asChild:!0,className:"w-fit",children:s.jsxs("a",{href:as,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(D,{name:"external-link",className:"size-4"}),"Open Repo"]})}):null]}):null,!ze&&!L&&!O&&!Xs?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:[ne?s.jsxs("div",{className:"space-y-2",children:[s.jsx(Bt,{value:oe,onChange:Ue=>ge(Ue.target.value),placeholder:c("gitView.pr.placeholder.title"),autoCorrect:x?"on":"off",autoCapitalize:x?"sentences":"off",spellCheck:x}),s.jsx(un,{value:me,onChange:Ue=>ye(Ue.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(Fa,{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(yt?"gitView.pr.loadingDescription":"gitView.pr.noDescription")})]}),Ls&&ze.draft?s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.draftMustBeReady")}):null,Ls?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"?ne?s.jsxs(s.Fragment,{children:[s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(be,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>{ee(!1),ge(ze.title||""),ye(ze.body||"")},disabled:Z,"aria-label":c("gitView.pr.actions.cancelEditingAria"),children:s.jsx(D,{name:"close",className:"size-4"})})}),s.jsx(At,{children:s.jsx("p",{children:c("gitView.pr.actions.cancelEditing")})})]}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(be,{size:"sm",className:"h-7 w-7 px-0",onClick:()=>ds(ze),disabled:Z||!oe.trim(),"aria-label":c("gitView.pr.actions.savePrAria"),children:Z?s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(D,{name:"check",className:"size-4"})})}),s.jsx(At,{children:s.jsx("p",{children:c("gitView.pr.actions.savePr")})})]})]}):s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(be,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>ee(!0),"aria-label":c("gitView.pr.actions.editPrAria"),children:s.jsx(D,{name:"edit",className:"size-4"})})}),s.jsx(At,{children:s.jsx("p",{children:c("gitView.pr.actions.editPr")})})]}):null,$s?s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(be,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:Rt,disabled:Me,"aria-label":c("gitView.pr.actions.openChecksAria"),children:Me?s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(D,{name:"information",className:"size-4"})})}),s.jsx(At,{children:s.jsx("p",{children:c("gitView.pr.actions.openChecks")})})]}):null,$s?.failure?s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(be,{variant:"outline",size:"sm",className:"h-7 w-7 px-0 border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",onClick:gs,"aria-label":c("gitView.pr.actions.resolveFailedChecksAria"),children:s.jsx(D,{name:"error-warning",className:"size-4"})})}),s.jsx(At,{children:s.jsx("p",{children:c("gitView.pr.actions.resolveFailedChecks")})})]}):null,s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(be,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:kt,"aria-label":c("gitView.pr.actions.openCommentsAria"),children:s.jsx(D,{name:"chat-4",className:"size-4"})})}),s.jsx(At,{children:s.jsx("p",{children:c("gitView.pr.actions.openComments")})})]}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(be,{variant:"outline",size:"sm",className:"h-7 w-7 px-0 border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",onClick:xs,"aria-label":c("gitView.pr.actions.shareCommentsAria"),children:s.jsx(D,{name:"ai-generate-2",className:"size-4"})})}),s.jsx(At,{children:s.jsx("p",{children:c("gitView.pr.actions.shareComments")})})]}),Ls&&ze.draft&&ze.state==="open"?s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(be,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>es(ze),disabled:q||ue||Z||ne,"aria-label":c("gitView.pr.actions.markReadyAria"),children:q?s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(D,{name:"checkbox-circle",className:"size-4"})})}),s.jsx(At,{children:s.jsx("p",{children:c("gitView.pr.actions.markReady")})})]}):null]}),s.jsx("div",{className:"ml-auto flex items-center gap-2",children:Ls?s.jsxs(s.Fragment,{children:[s.jsxs(os,{value:z,onValueChange:Ue=>K(Ue),disabled:ue||ze.state!=="open",children:[s.jsx(ls,{size:"lg",className:"h-7 w-auto min-w-0",children:s.jsx(us,{})}),s.jsxs(cs,{children:[s.jsx(Tt,{value:"squash",children:c("gitView.pr.mergeMethod.squash")}),s.jsx(Tt,{value:"merge",children:c("gitView.pr.mergeMethod.merge")}),s.jsx(Tt,{value:"rebase",children:c("gitView.pr.mergeMethod.rebase")})]})]}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(be,{size:"sm",className:"h-7 w-7 px-0",onClick:()=>wt(ze),disabled:ue||q||ze.state!=="open"||ze.draft||Z||ne,"aria-label":c("gitView.pr.actions.mergePrAria"),children:ue?s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(D,{name:"git-merge",className:"size-4"})})}),s.jsx(At,{children:s.jsx("p",{children:c("gitView.pr.actions.mergePr")})})]})]}):null})]})]})}):s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:c("gitView.pr.createTitle")}),s.jsxs("div",{className:"typography-micro text-muted-foreground truncate",children:[e," ",s.jsx("span",{className:"opacity-60",children:"(local)"})," → ",U," ",s.jsxs("span",{className:"opacity-60",children:["(",we&&Y?"upstream":"remote",")"]})]})]}),as?s.jsx(be,{variant:"outline",size:"sm",asChild:!0,children:s.jsxs("a",{href:as,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:Ue=>A(Ue.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")}),$.length>0?s.jsxs(os,{value:U,onValueChange:B,children:[s.jsx(ls,{className:"h-9",children:s.jsx(us,{placeholder:c("gitView.pr.placeholder.selectBaseBranch")})}),s.jsx(cs,{children:$.map(Ue=>s.jsx(Tt,{value:Ue,children:Ue},Ue))})]}):s.jsx(Bt,{value:U,onChange:Ue=>B(Ue.target.value),placeholder:c("gitView.pr.placeholder.main")})]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.field.description")}),s.jsx(un,{value:N,onChange:Ue=>E(Ue.target.value),className:"min-h-[110px]",placeholder:c("gitView.pr.placeholder.whatChanged"),autoCorrect:x?"on":"off",autoCapitalize:x?"sentences":"off",spellCheck:x})]}),s.jsxs("div",{className:"flex items-center gap-2 cursor-pointer",role:"button",tabIndex:0,"aria-pressed":T,onClick:()=>R(Ue=>!Ue),onKeyDown:Ue=>{(Ue.key===" "||Ue.key==="Enter")&&(Ue.preventDefault(),R(gt=>!gt))},children:[s.jsx(fs,{size:"sm",checked:T,onChange:Ue=>R(Ue),ariaLabel:c("gitView.pr.actions.toggleDraftAria")}),s.jsx("span",{className:"typography-ui-label text-foreground select-none",children:c("gitView.pr.field.draft")})]}),v?s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.additionalContext.optional")}),s.jsx(be,{variant:"outline",size:"sm",onClick:()=>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(fr,{open:ie,onOpenChange:ve,children:[s.jsxs(kr,{className:"flex w-full items-center justify-between rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-3 py-2 hover:bg-[var(--interactive-hover)]",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.additionalContext.optional")}),s.jsx("span",{className:"typography-micro text-[var(--primary-base)]",children:ie?c("gitView.pr.actions.hide"):V.trim()?c("gitView.pr.actions.edit"):c("gitView.pr.actions.add")})]}),s.jsx(hr,{children:s.jsxs("div",{className:"mt-2 space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:[s.jsx(un,{value:V,onChange:Ue=>_(Ue.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(Lr,{open:X,onClose:()=>Se(!1),title:c("gitView.pr.additionalContext.title"),footer:s.jsx(be,{size:"sm",onClick:()=>Se(!1),className:"w-full",children:c("gitView.common.done")}),children:s.jsxs("div",{className:"space-y-3",children:[s.jsx(un,{value:V,onChange:Ue=>_(Ue.target.value),className:"min-h-[200px] bg-transparent",placeholder:c("gitView.pr.placeholder.additionalContext"),autoFocus:!0}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.additionalContext.hint")})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(be,{variant:"outline",size:"sm",onClick:St,disabled:F||Q,children:[F?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(be,{size:"sm",className:"min-w-[7.5rem] justify-center gap-2",onClick:qt,disabled:Q||!ln||!U.trim()||!we&&U.trim()===e,children:[s.jsx("span",{className:"inline-flex size-4 items-center justify-center",children:Q?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:je,onOpenChange:ae,children:s.jsxs(ms,{className:"max-w-2xl max-h-[70vh] flex flex-col min-h-0",children:[s.jsxs(ys,{children:[s.jsxs(hs,{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(Ss,{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:[Me?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,Me?null:s.jsx("div",{className:"space-y-3",children:Array.isArray(_e?.checkRuns)&&_e?.checkRuns.length>0?_e.checkRuns.map((Ue,gt)=>{const Pt=`${Ue.id??"run"}:${Ue.job?.jobId??"job"}:${Ue.name}:${gt}`;return s.jsx("div",{className:"p-1",children:rs(Ue)},Pt)}):s.jsx("div",{className:"text-center text-muted-foreground py-8",children:c("gitView.pr.checkDetails.empty")})})]})]})}),s.jsx(ps,{open:Xe,onOpenChange:ut,children:s.jsxs(ms,{className:"max-w-2xl max-h-[82vh] min-h-[38rem] flex flex-col gap-2",children:[s.jsx(ys,{children:s.jsxs(hs,{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(lo,{className:"mt-2 max-h-[66vh] overflow-y-auto overlay-scrollbar-target overlay-scrollbar-container",children:[nt?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,nt?null:s.jsx("div",{className:"space-y-4",children:Kt.length>0?s.jsx("div",{className:"relative pl-3",children:s.jsx("div",{children:Kt.map((Ue,gt)=>{const Pt=(Ue.authorName||"?").charAt(0).toUpperCase(),Mt=gt===Kt.length-1;return s.jsxs("div",{className:"relative pl-10 pb-5 last:pb-0",children:[Mt?null:s.jsx("div",{className:"absolute left-4 top-[2.375rem] bottom-[0.375rem] w-px bg-border/60"}),s.jsx("div",{className:"absolute left-0 top-0 z-10 flex size-8 items-center justify-center overflow-hidden rounded-full border border-border/60 bg-surface-elevated text-xs text-muted-foreground",children:Ue.avatarUrl?s.jsx("img",{src:Ue.avatarUrl,alt:Ue.authorName,className:"h-full w-full object-cover"}):s.jsx("span",{children:Pt})}),s.jsxs("div",{className:"rounded-lg bg-surface-elevated px-3 pt-0 pb-3 space-y-2",children:[s.jsxs("div",{className:"flex flex-col items-start gap-1 typography-micro text-muted-foreground sm:flex-row sm:flex-wrap sm:items-center sm:gap-x-1 sm:gap-y-1",children:[s.jsxs("span",{className:"text-foreground whitespace-nowrap",children:[Ue.authorName,Ue.authorLogin&&Ue.authorLogin!==Ue.authorName?` · @${Ue.authorLogin}`:""]}),Ue.createdAt?s.jsx("span",{className:"whitespace-nowrap",children:ht(Ue.createdAt)}):null,s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsxs(be,{variant:"ghost",size:"sm",className:"h-6 px-0 has-[>svg]:px-0 sm:px-2 sm:has-[>svg]:px-2.5 text-[var(--status-success)] hover:bg-[var(--status-success-background)] hover:text-[var(--status-success)] justify-start",onClick:()=>{bs(Ue)},"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(At,{children:s.jsx("p",{children:c("gitView.pr.actions.sendCommentToAgent")})})]})]}),s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[Ue.context,Ue.path?` · ${Ue.path}`:"",Ue.line?`:${Ue.line}`:""]}),s.jsx(Fa,{content:zt(Ue.body),className:["typography-markdown-body text-foreground break-words [&_a]:no-underline [&_a:hover]:no-underline",ns].filter(Boolean).join(" ")})]})]},Ue.id)})})}):s.jsx("div",{className:"text-center text-muted-foreground py-8",children:c("gitView.pr.comments.empty")})})]})]})})]})},R0=t=>{const e=st.c(150),{open:n,onOpenChange:r,conflictFiles:a,directory:i,operation:o,onAbort:c,onClearState:d}=t;let p;e[0]!==a?(p=a===void 0?[]:a,e[0]=a,e[1]=p):p=e[1];const m=p,{t:u}=dt(),f=Lt(F0),b=Lt(O0),h=Ra(L0),v=Ra($0),x=Re(_0),[g,w]=l.useState(!1),[y,C]=l.useState(null),[k,j]=l.useState(null);let S,I;e[2]!==i||e[3]!==n||e[4]!==u?(S=()=>{!n||!i||(w(!0),j(null),C(null),jb(i).then(Ie=>{C(Ie)}).catch(Ie=>{const Y=Ie instanceof Error?Ie.message:u("gitView.conflict.loadFailed");j(Y)}).finally(()=>{w(!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]),l.useEffect(S,I);let M;e[7]!==y||e[8]!==i||e[9]!==o?(M=async()=>{if(!y)return null;const Ie=o==="merge"?"merge":"rebase",Y=y.headInfo||(o==="merge"?"MERGE_HEAD":"REBASE_HEAD"),re=o==="merge"?"git commit --no-edit":"git rebase --continue",Pe=await yn("git.conflict.resolve.visible",{operation_label:Ie,head_ref:Y}),ce=await yn("git.conflict.resolve.instructions",{operation_label:Ie,directory:i,operation:o,head_info:y.headInfo||"N/A",continue_cmd:re}),Ce=`${Ie} 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:Pe,instructionsText:ce,payloadText:Ce}},e[7]=y,e[8]=i,e[9]=o,e[10]=M):M=e[10];const P=M;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 T=E;let R;e[17]!==P||e[18]!==b||e[19]!==d||e[20]!==r||e[21]!==x||e[22]!==h||e[23]!==v||e[24]!==u?(R=async()=>{const Ie=await P();if(!Ie){H.error(u("gitView.conflict.noDetailsAvailable"));return}if(!b){H.error(u("gitView.conflict.noActiveSession"),{description:u("gitView.conflict.noActiveSessionDescription")});return}h(Ie.visibleText,"replace"),v([{text:Ie.instructionsText,synthetic:!0},{text:Ie.payloadText,synthetic:!0}]),x("chat"),d?.(),r(!1)},e[17]=P,e[18]=b,e[19]=d,e[20]=r,e[21]=x,e[22]=h,e[23]=v,e[24]=u,e[25]=R):R=e[25];const V=R;let _;e[26]!==P||e[27]!==i||e[28]!==d||e[29]!==r||e[30]!==f||e[31]!==x||e[32]!==u?(_=async()=>{const Ie=await P();if(!Ie){H.error(u("gitView.conflict.noDetailsAvailable"));return}f({directoryOverride:i,initialPrompt:Ie.visibleText,syntheticParts:[{text:Ie.instructionsText,synthetic:!0},{text:Ie.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]=_):_=e[33];const U=_;let B,z,K,F,G,Q,te,Z,fe,ue,W,q,J,ne,ee,he,ke,oe,ge,me,ye,ie;if(e[34]!==y||e[35]!==m||e[36]!==b||e[37]!==N||e[38]!==T||e[39]!==V||e[40]!==U||e[41]!==g||e[42]!==k||e[43]!==r||e[44]!==n||e[45]!==o||e[46]!==u){const Ie=u(o==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),Y=y?.unmergedFiles||m;K=ps,ye=n,ie=r,z=ms,me="max-w-md w-[calc(100vw-2rem)]",ne="flex flex-col gap-4 overflow-hidden";let re;e[69]===Symbol.for("react.memo_cache_sentinel")?(re=s.jsx(D,{name:"alert",className:"size-5 shrink-0 text-[var(--status-warning)]"}),e[69]=re):re=e[69];const Pe=s.jsxs("div",{className:"flex items-center gap-2",children:[re,s.jsx(hs,{children:u("gitView.conflict.detectedTitle",{operation:Ie})})]});let ce;e[70]!==o||e[71]!==u?(ce=u("gitView.conflict.detectedDescription",{operation:o}),e[70]=o,e[71]=u,e[72]=ce):ce=e[72];let Ce;e[73]!==ce?(Ce=s.jsx(Ss,{children:ce}),e[73]=ce,e[74]=Ce):Ce=e[74],e[75]!==Pe||e[76]!==Ce?(ee=s.jsxs(ys,{children:[Pe,Ce]}),e[75]=Pe,e[76]=Ce,e[77]=ee):ee=e[77],e[78]!==g||e[79]!==u?(he=g&&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]=g,e[79]=u,e[80]=he):he=e[80],e[81]!==k||e[82]!==u?(ke=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]=ke):ke=e[83],e[84]!==Y||e[85]!==u?(oe=Y.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:Y.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:Y.map(B0)})})]}),e[84]=Y,e[85]=u,e[86]=oe):oe=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],W="flex flex-col gap-2 pt-2";let Te;e[90]!==U?(Te=()=>{U()},e[90]=U,e[91]=Te):Te=e[91];const $e=g||!y;let De;e[92]!==g?(De=g?s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(D,{name:"add",className:"size-4"}),e[92]=g,e[93]=De):De=e[93];let de;e[94]!==u?(de=u("gitView.conflict.resolveNewSession"),e[94]=u,e[95]=de):de=e[95],e[96]!==Te||e[97]!==$e||e[98]!==De||e[99]!==de?(q=s.jsxs(be,{variant:"default",onClick:Te,disabled:$e,className:"w-full gap-2",children:[De,de]}),e[96]=Te,e[97]=$e,e[98]=De,e[99]=de,e[100]=q):q=e[100];let O;e[101]!==V?(O=()=>{V()},e[101]=V,e[102]=O):O=e[102];const L=g||!y||!b;let $;e[103]!==g?($=g?s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(D,{name:"chat-1",className:"size-4"}),e[103]=g,e[104]=$):$=e[104];let je;e[105]!==u?(je=u("gitView.conflict.resolveCurrentSession"),e[105]=u,e[106]=je):je=e[106],e[107]!==O||e[108]!==L||e[109]!==$||e[110]!==je?(J=s.jsxs(be,{variant:"outline",onClick:O,disabled:L,className:"w-full gap-2",children:[$,je]}),e[107]=O,e[108]=L,e[109]=$,e[110]=je,e[111]=J):J=e[111],fe="flex gap-2 pt-1";let ae;e[112]!==u?(ae=u("gitView.conflict.continueLater"),e[112]=u,e[113]=ae):ae=e[113],e[114]!==T||e[115]!==ae?(ue=s.jsx(be,{variant:"ghost",size:"sm",onClick:T,className:"flex-1",children:ae}),e[114]=T,e[115]=ae,e[116]=ue):ue=e[116],B=be,F="destructive",G="sm",Q=N,te="flex-1",Z=u("gitView.conflict.abortOperation",{operation:Ie}),e[34]=y,e[35]=m,e[36]=b,e[37]=N,e[38]=T,e[39]=V,e[40]=U,e[41]=g,e[42]=k,e[43]=r,e[44]=n,e[45]=o,e[46]=u,e[47]=B,e[48]=z,e[49]=K,e[50]=F,e[51]=G,e[52]=Q,e[53]=te,e[54]=Z,e[55]=fe,e[56]=ue,e[57]=W,e[58]=q,e[59]=J,e[60]=ne,e[61]=ee,e[62]=he,e[63]=ke,e[64]=oe,e[65]=ge,e[66]=me,e[67]=ye,e[68]=ie}else B=e[47],z=e[48],K=e[49],F=e[50],G=e[51],Q=e[52],te=e[53],Z=e[54],fe=e[55],ue=e[56],W=e[57],q=e[58],J=e[59],ne=e[60],ee=e[61],he=e[62],ke=e[63],oe=e[64],ge=e[65],me=e[66],ye=e[67],ie=e[68];let ve;e[117]!==B||e[118]!==F||e[119]!==G||e[120]!==Q||e[121]!==te||e[122]!==Z?(ve=s.jsx(B,{variant:F,size:G,onClick:Q,className:te,children:Z}),e[117]=B,e[118]=F,e[119]=G,e[120]=Q,e[121]=te,e[122]=Z,e[123]=ve):ve=e[123];let X;e[124]!==fe||e[125]!==ue||e[126]!==ve?(X=s.jsxs("div",{className:fe,children:[ue,ve]}),e[124]=fe,e[125]=ue,e[126]=ve,e[127]=X):X=e[127];let Se;e[128]!==W||e[129]!==q||e[130]!==J||e[131]!==X?(Se=s.jsxs("div",{className:W,children:[q,J,X]}),e[128]=W,e[129]=q,e[130]=J,e[131]=X,e[132]=Se):Se=e[132];let Ae;e[133]!==ne||e[134]!==ee||e[135]!==he||e[136]!==ke||e[137]!==oe||e[138]!==ge||e[139]!==Se?(Ae=s.jsxs("div",{className:ne,children:[ee,he,ke,oe,ge,Se]}),e[133]=ne,e[134]=ee,e[135]=he,e[136]=ke,e[137]=oe,e[138]=ge,e[139]=Se,e[140]=Ae):Ae=e[140];let pe;e[141]!==z||e[142]!==me||e[143]!==Ae?(pe=s.jsx(z,{className:me,children:Ae}),e[141]=z,e[142]=me,e[143]=Ae,e[144]=pe):pe=e[144];let we;return e[145]!==K||e[146]!==ye||e[147]!==ie||e[148]!==pe?(we=s.jsx(K,{open:ye,onOpenChange:ie,children:pe}),e[145]=K,e[146]=ye,e[147]=ie,e[148]=pe,e[149]=we):we=e[149],we};function F0(t){return t.openNewSessionDraft}function O0(t){return t.currentSessionId}function L0(t){return t.setPendingInputText}function $0(t){return t.setPendingSyntheticParts}function _0(t){return t.setActiveMainTab}function B0(t){return s.jsx("li",{className:"typography-micro text-foreground font-mono truncate block",title:t,children:t},t)}const z0=({open:t,onOpenChange:e,operation:n,targetBranch:r,onConfirm:a})=>{const{t:i}=dt(),[o,c]=l.useState(!0),[d,p]=l.useState(!1),m=i(n==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),u=async()=>{p(!0);try{await a(o),e(!1)}catch(b){const h=b instanceof Error?b.message:`Failed to ${n}`;H.error(h)}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(ys,{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(hs,{children:i("gitView.stash.title")})]}),s.jsx(Ss,{children:i("gitView.stash.description",{operation:n})})]}),s.jsxs("div",{className:"py-2",children:[s.jsx("p",{className:"typography-meta text-muted-foreground mb-3",children:i("gitView.stash.thisWill")}),s.jsxs("ol",{className:"list-decimal list-inside space-y-1 typography-meta text-foreground",children:[s.jsx("li",{children:i("gitView.stash.stepStash")}),s.jsxs("li",{children:[i(n==="merge"?"gitView.operation.merge":"gitView.operation.rebase")," ",i(n==="merge"?"gitView.stash.mergeWith":"gitView.stash.rebaseOnto")," ",s.jsx("span",{className:"font-mono text-primary",children:r})]}),o&&s.jsx("li",{children:i("gitView.stash.stepRestore")})]})]}),s.jsxs("div",{className:"flex items-center gap-2 py-2",children:[s.jsx(fs,{checked:o,onChange:c,disabled:d,ariaLabel:i("gitView.stash.restoreAria")}),s.jsx("span",{className:"typography-ui-label text-foreground cursor-pointer select-none",onClick:()=>!d&&c(!o),children:i("gitView.stash.restoreAfterOperation",{operation:n})})]}),s.jsxs(Vs,{className:"gap-2",children:[s.jsx(be,{variant:"ghost",size:"sm",onClick:f,disabled:d,children:i("gitView.common.cancel")}),s.jsx(be,{variant:"default",size:"sm",onClick:u,disabled:d,className:"gap-1.5",children:d?s.jsxs(s.Fragment,{children:[s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}),i("gitView.common.processing")]}):i("gitView.stash.confirmButton",{operation:m})})]})]})})},V0=({mergeInProgress:t,rebaseInProgress:e,onContinue:n,onAbort:r,onResolveWithAI:a,hasUnresolvedConflicts:i=!1,isLoading:o=!1})=>{const{t:c}=dt(),[d,p]=l.useState(null),m=t&&t.head,u=e&&(e.headName||e.onto),f=m?"merge":u?"rebase":null;if(!f)return null;const b=async()=>{p("continue");try{await n()}finally{p(null)}},h=async()=>{p("abort");try{await r()}finally{p(null)}},v=d!==null,x=c(f==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),g=f==="merge"?"git-merge":"git-branch";let w="";return t?w=t.message?c("gitView.operation.mergingMessage",{message:t.message}):c("gitView.operation.mergeInProgressWithHead",{head:t.head}):e&&(w=e.headName?c("gitView.operation.rebasingOnto",{headName:e.headName,onto:e.onto||""}):c("gitView.operation.rebaseInProgress")),s.jsx("div",{className:"bg-[var(--status-warning-bg)] border border-[var(--status-warning)] rounded-lg p-3 mx-3 mt-3",children:s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsxs("div",{className:"flex items-start gap-2 min-w-0",children:[s.jsx(D,{name:g,className:"size-4 text-[var(--status-warning)] shrink-0"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:"typography-label text-[var(--status-warning)]",children:c("gitView.operation.inProgressTitle",{operation:x})}),w&&s.jsx("p",{className:"typography-micro text-muted-foreground truncate",children:w})]})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i&&a&&s.jsxs(be,{variant:"outline",size:"sm",onClick:a,disabled:v||o,className:"gap-1.5",children:[s.jsx(D,{name:"sparkling",className:"size-4"}),c("gitView.operation.resolveWithAi")]}),d!=="continue"&&s.jsxs(be,{variant:"ghost",size:"sm",onClick:h,disabled:v||o,className:"gap-1.5",children:[d==="abort"?s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(D,{name:"close",className:"size-4"}),c("gitView.operation.abort")]}),!i&&s.jsxs(be,{variant:"default",size:"sm",onClick:b,disabled:v||o,className:"gap-1.5",children:[d==="continue"?s.jsx(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")})]})})},U0=t=>{const e=st.c(104),{currentBranch:n,localBranches:r,remoteBranches:a,onMerge:i,onRebase:o,disabled:c,isOperating:d,operationLogs:p,onOperationComplete:m,mode:u,defaultTargetBranch:f}=t,b=c===void 0?!1:c,h=d===void 0?!1:d,v=p===void 0?[]:p,x=u===void 0?"dialog":u,{t:g}=dt(),[w,y]=l.useState(!1),[C,k]=l.useState("merge"),[j,S]=l.useState(null),[I,M]=l.useState(!1),[P,A]=l.useState(""),N=l.useRef(null),E=l.useRef(null),T=b||h,R=n||g("gitView.branch.currentBranchFallback"),V=v.length>0&&v.every(W0),_=v.some(K0);let U;e[0]===Symbol.for("react.memo_cache_sentinel")?(U=()=>{E.current&&(E.current.scrollTop=E.current.scrollHeight)},e[0]=U):U=e[0],l.useEffect(U,[v]);let B;if(e[1]!==P||e[2]!==n||e[3]!==r||e[4]!==a){e:{const O=P.toLowerCase();let L;e[6]!==a?(L=new Set(a.map(H0).filter(Boolean)),e[6]=a,e[7]=L):L=e[7];const $=L;let je;e[8]!==n||e[9]!==$?(je=_e=>_e!==n&&!$.has(_e),e[8]=n,e[9]=$,e[10]=je):je=e[10];const ae=r.filter(je);if(!O){B=ae;break e}B=ae.filter(_e=>_e.toLowerCase().includes(O))}e[1]=P,e[2]=n,e[3]=r,e[4]=a,e[5]=B}else B=e[5];const z=B;let K;if(e[11]!==P||e[12]!==a){e:{const O=P.toLowerCase();if(!O){K=a;break e}K=a.filter(L=>L.toLowerCase().includes(O))}e[11]=P,e[12]=a,e[13]=K}else K=e[13];const F=K;let G;e[14]!==f||e[15]!==r||e[16]!==a?(G=()=>f&&(a.includes(f)||r.includes(f))?f:null,e[14]=f,e[15]=r,e[16]=a,e[17]=G):G=e[17];const Q=G;let te;e[18]!==Q||e[19]!==y?(te=()=>{y(!0),S(Q()),k("merge"),A("")},e[18]=Q,e[19]=y,e[20]=te):te=e[20];const Z=te;let fe;e[21]===Symbol.for("react.memo_cache_sentinel")?(fe=O=>{S(O),M(!1),A("")},e[21]=fe):fe=e[21];const ue=fe;let W;e[22]!==i||e[23]!==o||e[24]!==C||e[25]!==j?(W=()=>{j&&(C==="merge"?i(j):o(j))},e[22]=i,e[23]=o,e[24]=C,e[25]=j,e[26]=W):W=e[26];const q=W;let J;e[27]!==h||e[28]!==y?(J=()=>{h||(S(null),k("merge"),A(""),y(!1))},e[27]=h,e[28]=y,e[29]=J):J=e[29];const ne=J,ee=()=>{h&&!V||(V&&m?.(),S(null),k("merge"),A(""),y(!1))};let he,ke;e[30]!==I?(he=()=>{I||A("")},ke=[I],e[30]=I,e[31]=he,e[32]=ke):(he=e[31],ke=e[32]),l.useEffect(he,ke);let oe,ge;e[33]!==x||e[34]!==Q||e[35]!==j?(oe=()=>{x!=="inline"||j||S(Q())},ge=[x,Q,j],e[33]=x,e[34]=Q,e[35]=j,e[36]=oe,e[37]=ge):(oe=e[36],ge=e[37]),l.useEffect(oe,ge);const ie=h?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(G0)})}),V?x==="dialog"?s.jsx(Vs,{children:s.jsx(be,{variant:"default",size:"sm",onClick:ee,children:g(_?"gitView.common.close":"gitView.common.done")})}):s.jsx("div",{className:"flex justify-end",children:s.jsx(be,{variant:"default",size:"sm",onClick:ee,children:g(_?"gitView.common.close":"gitView.common.done")})}):null]}):s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:g("gitView.branch.operation")}),s.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[s.jsxs("button",{type:"button",onClick:()=>k("merge"),className:xe("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:xe("size-4",C==="merge"?"text-primary":"text-muted-foreground")}),s.jsx("span",{className:xe("typography-ui-label",C==="merge"?"text-foreground":"text-muted-foreground"),children:g("gitView.operation.merge")})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:g("gitView.branch.mergeDescription")})]}),s.jsxs("button",{type:"button",onClick:()=>k("rebase"),className:xe("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:xe("size-4",C==="rebase"?"text-primary":"text-muted-foreground")}),s.jsx("span",{className:xe("typography-ui-label",C==="rebase"?"text-foreground":"text-muted-foreground"),children:g("gitView.operation.rebase")})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:g("gitView.branch.rebaseDescription")})]})]})]}),s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:C==="merge"?g("gitView.branch.branchToMergeInto",{branch:R}):g("gitView.branch.branchToRebaseOnto")}),s.jsxs(Ts,{open:I,onOpenChange:M,modal:!1,children:[s.jsx(As,{asChild:!0,children:s.jsxs(be,{variant:"outline",size:"lg",className:"w-full justify-between",children:[s.jsx("span",{className:xe("truncate",!j&&"text-muted-foreground"),children:j||g("gitView.branch.selectBranch")}),s.jsx(D,{name:"arrow-down-s",className:"size-4 opacity-60 shrink-0"})]})}),s.jsx(Ds,{align:"start",sideOffset:6,className:"w-[var(--anchor-width)] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden",children:s.jsxs(La,{className:"h-full min-h-0",children:[s.jsx(da,{ref:N,placeholder:g("gitView.branch.searchPlaceholder"),value:P,onValueChange:A,onKeyDown:q0}),s.jsxs($a,{className:"h-full min-h-0",disableHorizontal:!0,children:[s.jsx(_a,{children:g("gitView.branch.empty")}),z.length>0&&s.jsx(Mn,{heading:g("gitView.branch.localBranches"),children:z.map(O=>s.jsx(jn,{onSelect:()=>ue(O),children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:O})},`local-${O}`))}),z.length>0&&F.length>0?s.jsx(Ca,{}):null,F.length>0&&s.jsx(Mn,{heading:g("gitView.branch.remoteBranches"),children:F.map(O=>s.jsx(jn,{onSelect:()=>ue(O),children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:O})},`remote-${O}`))})]})]})})]})]}),j?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:[g("gitView.branch.summaryMergePrefix")," ",s.jsx("span",{className:"font-mono text-foreground",children:j})," ",g("gitView.branch.summaryMergeInfix")," ",s.jsx("span",{className:"font-mono text-foreground",children:R})]}):s.jsxs(s.Fragment,{children:[g("gitView.branch.summaryRebasePrefix")," ",s.jsx("span",{className:"font-mono text-foreground",children:R})," ",g("gitView.branch.summaryRebaseInfix")," ",s.jsx("span",{className:"font-mono text-foreground",children:j})]})})}):null,x==="dialog"?s.jsxs(Vs,{className:"gap-2 pt-1",children:[s.jsx(be,{variant:"ghost",size:"sm",onClick:ne,children:g("gitView.common.cancel")}),s.jsx(be,{variant:"default",size:"sm",onClick:q,disabled:!j,className:"gap-1.5",children:C==="merge"?s.jsxs(s.Fragment,{children:[s.jsx(D,{name:"git-merge",className:"size-4"}),g("gitView.operation.merge")]}):s.jsxs(s.Fragment,{children:[s.jsx(D,{name:"git-branch",className:"size-4"}),g("gitView.operation.rebase")]})})]}):s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsx(be,{variant:"destructive",size:"sm",onClick:ne,disabled:T,children:g("gitView.common.reset")}),s.jsx("div",{className:"flex-1"}),s.jsx(be,{variant:"default",size:"sm",onClick:q,disabled:T||!j,children:g(C==="merge"?"gitView.operation.merge":"gitView.operation.rebase")})]})]});if(x==="inline"){let O;e[38]!==g?(O=g("gitView.branch.updateTitle"),e[38]=g,e[39]=O):O=e[39];let L;e[40]!==O?(L=s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:O}),e[40]=O,e[41]=L):L=e[41];let $;e[42]!==g?($=g("gitView.branch.updateDescriptionPrefix"),e[42]=g,e[43]=$):$=e[43];let je;e[44]!==R?(je=s.jsx("span",{className:"font-mono text-foreground",children:R}),e[44]=R,e[45]=je):je=e[45];let ae;e[46]!==$||e[47]!==je?(ae=s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[$," ",je,"."]}),e[46]=$,e[47]=je,e[48]=ae):ae=e[48];let _e;e[49]!==L||e[50]!==ae?(_e=s.jsx("header",{className:"border-b border-border/40 px-0 py-3",children:s.jsxs("div",{className:"space-y-1",children:[L,ae]})}),e[49]=L,e[50]=ae,e[51]=_e):_e=e[51];let le;e[52]!==ie?(le=s.jsx("div",{className:"pt-3",children:ie}),e[52]=ie,e[53]=le):le=e[53];let Me;return e[54]!==_e||e[55]!==le?(Me=s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[_e,le]}),e[54]=_e,e[55]=le,e[56]=Me):Me=e[56],Me}let ve;e[57]!==h?(ve=h?s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(D,{name:"git-merge",className:"size-4"}),e[57]=h,e[58]=ve):ve=e[58];let X;e[59]!==g?(X=g("gitView.branch.mergeRebase"),e[59]=g,e[60]=X):X=e[60];let Se;e[61]!==X?(Se=s.jsx("span",{children:X}),e[61]=X,e[62]=Se):Se=e[62];let Ae;e[63]!==Z||e[64]!==T||e[65]!==ve||e[66]!==Se?(Ae=s.jsx(It,{asChild:!0,children:s.jsxs(be,{variant:"outline",size:"sm",className:"gap-1.5",onClick:Z,disabled:T,children:[ve,Se]})}),e[63]=Z,e[64]=T,e[65]=ve,e[66]=Se,e[67]=Ae):Ae=e[67];let pe;e[68]!==g?(pe=g("gitView.branch.mergeRebaseTooltip"),e[68]=g,e[69]=pe):pe=e[69];let we;e[70]!==pe?(we=s.jsx(At,{sideOffset:8,children:pe}),e[70]=pe,e[71]=we):we=e[71];let Ie;e[72]!==Ae||e[73]!==we?(Ie=s.jsxs(Ct,{children:[Ae,we]}),e[72]=Ae,e[73]=we,e[74]=Ie):Ie=e[74];let Y;e[75]!==ee||e[76]!==y?(Y=O=>{O?y(!0):ee()},e[75]=ee,e[76]=y,e[77]=Y):Y=e[77];let re;e[78]!==g?(re=g("gitView.branch.updateTitle"),e[78]=g,e[79]=re):re=e[79];let Pe;e[80]!==re?(Pe=s.jsx(hs,{children:re}),e[80]=re,e[81]=Pe):Pe=e[81];let ce;e[82]!==_||e[83]!==h||e[84]!==C||e[85]!==V||e[86]!==g||e[87]!==R?(ce=h?g(V?_?"gitView.branch.operationFailed":"gitView.branch.operationCompleted":C==="merge"?"gitView.branch.mergingInProgress":"gitView.branch.rebasingInProgress"):s.jsxs(s.Fragment,{children:[g("gitView.branch.dialogDescriptionPrefix")," ",s.jsx("span",{className:"font-mono text-foreground",children:R}),"."]}),e[82]=_,e[83]=h,e[84]=C,e[85]=V,e[86]=g,e[87]=R,e[88]=ce):ce=e[88];let Ce;e[89]!==ce?(Ce=s.jsx(Ss,{children:ce}),e[89]=ce,e[90]=Ce):Ce=e[90];let Te;e[91]!==Pe||e[92]!==Ce?(Te=s.jsxs(ys,{children:[Pe,Ce]}),e[91]=Pe,e[92]=Ce,e[93]=Te):Te=e[93];let $e;e[94]!==ie||e[95]!==Te?($e=s.jsxs(ms,{className:"max-w-md",children:[Te,ie]}),e[94]=ie,e[95]=Te,e[96]=$e):$e=e[96];let De;e[97]!==w||e[98]!==Y||e[99]!==$e?(De=s.jsx(ps,{open:w,onOpenChange:Y,children:$e}),e[97]=w,e[98]=Y,e[99]=$e,e[100]=De):De=e[100];let de;return e[101]!==Ie||e[102]!==De?(de=s.jsxs(s.Fragment,{children:[Ie,De]}),e[101]=Ie,e[102]=De,e[103]=de):de=e[103],de};function W0(t){return t.status==="done"||t.status==="error"}function K0(t){return t.status==="error"}function H0(t){return t.slice(t.indexOf("/")+1)}function G0(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:xe("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 q0(t){return t.stopPropagation()}const Tm="oc.git.actionTab",J0=t=>t==="commit"||t==="branch"||t==="pr",Wh="gitmojiCache",Y0=1e3*60*60*24*7,Kh="1",Q0=40,X0=20,Z0="https://raw.githubusercontent.com/carloscuesta/gitmoji/master/packages/gitmojis/src/gitmojis.json",Mm={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:"},Hh=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(Wh);if(!t)return null;const e=JSON.parse(t);return!e||e.version!==Kh||typeof e.fetchedAt!="number"||!Array.isArray(e.gitmojis)?null:{gitmojis:e.gitmojis.filter(Hh),fetchedAt:e.fetchedAt,version:e.version}}catch{return null}},tN=t=>{if(!(typeof window>"u"))try{const e={gitmojis:t,fetchedAt:Date.now(),version:Kh};localStorage.setItem(Wh,JSON.stringify(e))}catch{return}},sN=t=>Date.now()-t.fetchedAt<Y0,nN=(t,e)=>{const n=t.toLowerCase(),r=/^([a-z]+)(?:\(.*\))?!?:/,a=n.match(r);if(a){const c=a[1],d=Mm[c];if(d)return e.find(p=>p.code===d)||null}const i=n.split(" ")[0],o=Mm[i];return o&&e.find(c=>c.code===o)||null},Em=new Map,ga=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),Gh=()=>{const{t}=dt(),{git:e}=Rn(),n=Zr(),[r,a]=l.useState(null),[i,o]=l.useState(!1),c=Lt(Le=>Le.currentSessionId),d=Lt(Le=>Le.newSessionDraft),p=Lt(Le=>Le.setDraftBootstrapPendingDirectory),m=Lt(Le=>Le.worktreeMetadata),u=Lt(Le=>Le.availableWorktrees),f=ga(n),b=l.useMemo(()=>{if(!f)return;const Le=u.find(Qe=>ga(Qe.path)===f);if(Le)return Le;for(const Qe of m.values())if(ga(Qe.path)===f)return Qe},[u,f,m]),h=l.useMemo(()=>{if(c)return m.get(c)??b;if(d?.open)return b},[c,b,d?.open,m]),{profiles:v,globalIdentity:x,defaultGitIdentityId:g,loadProfiles:w,loadGlobalIdentity:y,loadDefaultGitIdentityId:C}=Wn(Jn(Le=>({profiles:Le.profiles,globalIdentity:Le.globalIdentity,defaultGitIdentityId:Le.defaultGitIdentityId,loadProfiles:Le.loadProfiles,loadGlobalIdentity:Le.loadGlobalIdentity,loadDefaultGitIdentityId:Le.loadDefaultGitIdentityId}))),k=Td(n??null),j=Dl(n??null),S=Kf(Le=>c?Le.getAttachment(c):void 0),I=S?Nb(S):[],M=S&&!S.degraded&&!S.legacy?S.worktreeRoot??void 0:void 0,P=zw(n,h,j?.current??void 0),A=Md(n??null),N=Sb(n??null),E=kb(n??null),T=Ed(n??null),R=Cb(n??null),V=tn(Le=>Le.setActiveDirectory),_=tn(Le=>Le.fetchAll),U=tn(Le=>Le.ensureAll),B=tn(Le=>Le.fetchStatus),z=tn(Le=>Le.fetchBranches),K=tn(Le=>Le.fetchLog),F=tn(Le=>Le.fetchIdentity),G=tn(Le=>Le.prefetchDiffs),Q=tn(Le=>Le.setLogMaxCount),te=Re(Le=>Le.isMobile),Z=Re(Le=>Le.openContextDiff),fe=Re(Le=>Le.navigateToDiff),ue=Re(Le=>Le.setRightSidebarOpen),W=l.useRef(null);l.useEffect(()=>{if(!n){a(null),o(!1);return}let Le=!1,Qe=null;const tt=async()=>{try{const ct=await Pb(n);if(Le)return;a(ct.status),ct.status==="pending"&&(Qe=window.setTimeout(()=>{tt()},500))}catch{Le||a(null)}};return tt(),()=>{Le=!0,Qe!==null&&window.clearTimeout(Qe)}},[n]),l.useEffect(()=>{const Le=W.current;W.current=r,!(!n||!e)&&(Le==="pending"&&r==="ready"&&(o(!0),_(n,e).finally(()=>{window.setTimeout(()=>{o(!1)},1200)})),r==="failed"&&(p(null),o(!1)))},[n,_,e,p,r]);const q=ga(d?.bootstrapPendingDirectory??null),J=!!(n&&q&&q===ga(n)),ee=!!(n&&(r==="pending"||J))||i,he=l.useMemo(()=>n?Em.get(n)??null:null,[n]),ke=bt(Le=>Le.settingsGitmojiEnabled),[oe,ge]=l.useState(null);l.useEffect(()=>{const Le=M||P?.projectDirectory;if(!Le){ge(null);return}let Qe=!1;return co(Le).then(tt=>{if(Qe)return;const ct=tt.trim();ge(ct&&ct!=="HEAD"?ct:null)}).catch(()=>{Qe||ge(null)}),()=>{Qe=!0}},[M,P?.projectDirectory]);const[me,ye]=l.useState(he?.commitMessage??""),[ie,ve]=l.useState([]),[X,Se]=l.useState(!1),Ae=l.useRef(null),[pe,we]=l.useState(null),[Ie,Y]=l.useState(!1),[re,Pe]=l.useState(null),[ce,Ce]=l.useState(25),[Te,$e]=l.useState(!1),{triggerFireworks:De}=Ow(),de=l.useRef(new Map),O=l.useRef(0),L=l.useCallback(()=>{O.current+=1,$e(!0)},[]),$=l.useCallback(()=>{O.current=Math.max(0,O.current-1),O.current===0&&$e(!1)},[]),[je,ae]=l.useState(()=>new Set(he?.selectedPaths??[])),[_e,le]=l.useState(!1),[Me,Ge]=l.useState(new Set),[at,Ye]=l.useState(!1),[Xe,ut]=l.useState(0),[rt,it]=l.useState(!1),[nt,Ne]=l.useState(he?.generatedHighlights??[]),Ke=l.useCallback(()=>{const Le=Ae.current;Le&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{Le.scrollTo({top:Le.scrollHeight,behavior:"smooth"})})})},[]),Ve=M||P?.projectDirectory||null,qe=j?.current||null,lt=l.useMemo(()=>{const Le=j?.tracking;return Le?Le.startsWith("origin/"):!0},[j?.tracking]),He=l.useMemo(()=>{const Le=P?.createdFromBranch,Qe=typeof Le=="string"?Le.trim():"",tt=typeof j?.current=="string"?j.current.trim():"",ct=typeof oe=="string"?oe.trim():"";return Qe?Qe===tt&&Qe.startsWith("opencode/")&&ct.length>0&&ct!==Qe?ct:Qe:ct||tt||"HEAD"},[P?.createdFromBranch,j,oe]),ze=l.useCallback(()=>{Ne([])},[]),[et,yt]=l.useState(new Set),[Rt,kt]=l.useState(new Map),[ht,vt]=l.useState(new Set),[ns,zt]=l.useState(null),[Kt,mt]=l.useState(null),[Et,rs]=l.useState([]),[gs,xs]=l.useState(""),[bs,Wt]=l.useState(!1),We=l.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]),[St,qt]=l.useState(()=>{if(typeof window>"u")return"commit";const Le=window.localStorage.getItem(Tm);return Le==="worktree"?"branch":J0(Le)?Le:"commit"}),[wt,es]=l.useState([]),[ds,Ms]=l.useState(null),[as,$s]=l.useState(null),[Ls,ln]=l.useState([]),[Xs,Vt]=l.useState(!1),[Ut,se]=l.useState([]),[xt,Je]=l.useState("merge"),_t=l.useMemo(()=>c?`openchamber.conflict:${c}`:null,[c]),Gt=l.useCallback((Le,Qe,tt)=>{if(!_t||typeof window>"u")return;const ct={directory:Le,conflictFiles:Qe,operation:tt};window.localStorage.setItem(_t,JSON.stringify(ct))},[_t]),is=l.useCallback(()=>{!_t||typeof window>"u"||window.localStorage.removeItem(_t)},[_t]);l.useEffect(()=>{typeof window>"u"||window.localStorage.setItem(Tm,St)},[St]),l.useEffect(()=>{if(!_t||typeof window>"u"||!n)return;const Le=window.localStorage.getItem(_t);if(Le)try{const Qe=JSON.parse(Le);if(Qe.directory!==n){window.localStorage.removeItem(_t);return}se(Qe.conflictFiles??[]),Je(Qe.operation??"merge"),Vt(!0)}catch{window.localStorage.removeItem(_t)}},[_t,n]);const[Ue,gt]=l.useState(!1),[Pt,Mt]=l.useState("merge"),[ts,Ot]=l.useState(""),ks=l.useCallback(Le=>{In(Le).then(Qe=>{if(Qe.ok){H.success(t("gitView.toast.commitHashCopied"));return}H.error(t("gitView.toast.copyFailed"))})},[t]),Zs=l.useCallback(Le=>{yt(Qe=>{const tt=new Set(Qe);return tt.has(Le)?tt.delete(Le):tt.add(Le),tt})},[]);l.useEffect(()=>{if(!n||!e)return;const Le=Array.from(et).filter(Qe=>!Rt.has(Qe)&&!ht.has(Qe));if(Le.length!==0){vt(Qe=>{const tt=new Set(Qe);for(const ct of Le)tt.add(ct);return tt});for(const Qe of Le)e.getCommitFiles(n,Qe).then(tt=>{kt(ct=>new Map(ct).set(Qe,tt.files))}).catch(tt=>{console.error("Failed to fetch commit files:",tt),kt(ct=>new Map(ct).set(Qe,[]))}).finally(()=>{vt(tt=>{const ct=new Set(tt);return ct.delete(Qe),ct})})}},[et,n,e,Rt,ht]),l.useEffect(()=>{n&&Em.set(n,{directory:n,selectedPaths:Array.from(je),commitMessage:me,generatedHighlights:nt})},[me,n,je,nt]),l.useEffect(()=>{w(),y(),C()},[w,y,C]),l.useEffect(()=>{if(!n||!e?.getRemoteUrl){mt(null);return}e.getRemoteUrl(n).then(mt).catch(()=>mt(null))},[n,e]);const Hs=l.useCallback(async()=>{if(!n||!e?.getRemotes){es([]);return}try{const Le=await e.getRemotes(n);es(Le)}catch{es([])}},[n,e]);l.useEffect(()=>{Hs()},[Hs]),l.useEffect(()=>{if(!ke){rs([]);return}let Le=!1;const Qe=eN();return Qe&&(rs(Qe.gitmojis),sN(Qe))?()=>{Le=!0}:((async()=>{try{const ct=await fetch(Z0);if(!ct.ok)throw new Error(`Failed to load gitmojis: ${ct.statusText}`);const Ft=await ct.json(),Xt=Array.isArray(Ft.gitmojis)?Ft.gitmojis.filter(Hh):[];Le||(rs(Xt),tN(Xt))}catch(ct){Le||console.warn("Failed to load gitmoji list:",ct)}})(),()=>{Le=!0})},[ke]),l.useEffect(()=>{n&&(V(n),U(n,e))},[n,V,U,e]),l.useEffect(()=>{if(n)return Nr.onGitRefreshHint(Le=>{ga(Le.directory)===ga(n)&&B(n,e)})},[n,B,e]);const ss=l.useCallback(async(Le=!0)=>{if(n)try{await Promise.all([B(n,e),z(n,e)])}catch(Qe){if(Le){const tt=Qe instanceof Error?Qe.message:t("gitView.toast.refreshRepositoryFailed");H.error(tt)}}},[n,e,B,z,t]),Es=l.useCallback(async()=>{n&&await K(n,e,ce)},[n,e,K,ce]),Pn=l.useCallback(async()=>{n&&await F(n,e)},[n,e,F]);l.useEffect(()=>{if(!n||!e?.hasLocalIdentity||k!==!0)return;const Le=typeof g=="string"?g.trim():"";if(!Le||Le==="global"||de.current.get(n)===Le)return;let tt=!1;return(async()=>{try{const Ft=await e.hasLocalIdentity?.(n);if(tt||Ft===!0)return;L(),await e.setGitIdentity(n,Le),de.current.set(n,Le),await Pn()}catch(Ft){console.warn("Failed to auto-apply default git identity:",Ft)}finally{tt||$()}})(),()=>{tt=!0}},[L,n,g,$,e,k,Pn]);const an=l.useMemo(()=>{if(!j)return[];const Le=j.files??[],Qe=new Map;for(const tt of Le)Qe.set(tt.path,tt);return Array.from(Qe.values()).sort((tt,ct)=>tt.path.localeCompare(ct.path))},[j]);l.useEffect(()=>{if(!n||an.length===0)return;const Le=[],Qe=new Set,tt=Ft=>{!Ft||Qe.has(Ft)||(Qe.add(Ft),Le.push(Ft))};if(Array.from(je).forEach(tt),ie.forEach(tt),an.slice(0,X0).forEach(Ft=>tt(Ft.path)),Le.length===0)return;const ct=window.setTimeout(()=>{G(n,e,Le,{maxFiles:Q0})},120);return()=>{window.clearTimeout(ct)}},[an,n,e,G,je,ie]),l.useEffect(()=>{if(!j||an.length===0){ae(new Set),le(!1);return}ae(Le=>{const Qe=new Set,tt=Le??new Set;for(const ct of an)tt.has(ct.path)?Qe.add(ct.path):_e||Qe.add(ct.path);return Qe})},[j,an,_e]);const Ir=async(Le,Qe)=>{if(n){we(Le);try{const tt=ct=>{const Ft=`${ct.name}/`,Xt=j?.tracking?.startsWith(Ft)?j.tracking.slice(Ft.length):void 0;return{remote:ct.name,branch:Xt,rebase:!0}};if(Le==="fetch"){if(!Qe)throw new Error("No remote available for fetch");await e.gitFetch(n,{remote:Qe.name}),H.success(t("gitView.toast.fetchedFromRemote",{name:Qe.name}))}else if(Le==="pull"){if(!Qe)throw new Error("No remote available for pull");const ct=await e.gitPull(n,tt(Qe));H.success(ct.files.length===1?t("gitView.toast.pulledFilesSingle",{count:ct.files.length,name:Qe.name}):t("gitView.toast.pulledFilesPlural",{count:ct.files.length,name:Qe.name}))}else if(Le==="push")await e.gitPush(n),H.success(t("gitView.toast.pushedToUpstream"));else if(Le==="sync"){if(!Qe)throw new Error("No remote available for sync");let ct=0,Ft=!1;await e.gitFetch(n,{remote:Qe.name});const Xt=await e.getGitStatus(n);if((Xt.behind??0)>0){if((Xt.files?.length??0)>0){H.error(t("gitView.toast.commitOrStashBeforeSync"));return}ct=(await e.gitPull(n,tt(Qe))).files.length}((await e.getGitStatus(n)).ahead??0)>0&&(await e.gitPush(n),Ft=!0),ct>0&&Ft?H.success(ct===1?t("gitView.toast.syncedPulledSingleAndPushed",{count:ct,name:Qe.name}):t("gitView.toast.syncedPulledPluralAndPushed",{count:ct,name:Qe.name})):ct>0?H.success(ct===1?t("gitView.toast.pulledFilesSingle",{count:ct,name:Qe.name}):t("gitView.toast.pulledFilesPlural",{count:ct,name:Qe.name})):Ft?H.success(t("gitView.toast.pushedToUpstream")):H.success(t("gitView.toast.alreadyUpToDate"))}await ss(!1),await Es()}catch(tt){const ct=tt instanceof Error?tt.message:t("gitView.toast.syncActionFailed",{action:Le==="sync"?t("gitView.sync.syncChanges"):Le==="pull"?t("gitView.sync.pull"):Le});H.error(ct)}finally{we(null)}}},er=l.useCallback(async Le=>{if(!n)return;const Qe=Le.name.trim();if(!Qe){H.error(t("gitView.toast.remoteNameRequired"));return}if(Qe==="origin"){H.error(t("gitView.toast.cannotRemoveOriginRemote"));return}Ms(Qe);try{await e.removeRemote(n,{remote:Qe}),H.success(t("gitView.toast.removedRemote",{name:Qe})),await Promise.all([ss(!1),Hs()])}catch(tt){const ct=tt instanceof Error?tt.message:`Failed to remove ${Qe}`;H.error(ct)}finally{Ms(null)}},[n,e,Hs,ss,t]),Js=async(Le={})=>{if(!n)return;if(!me.trim()){H.error(t("gitView.toast.enterCommitMessage"));return}const Qe=Array.from(je).sort();if(Qe.length===0){H.error(t("gitView.toast.selectFileToCommit"));return}const tt=Le.pushAfter?"commitAndPush":"commit";Pe(tt);try{if(await e.createGitCommit(n,me.trim(),{files:Qe}),H.success(t("gitView.toast.commitCreated")),ye(""),ae(new Set),le(!1),ze(),await ss(),Le.pushAfter){we("sync");const ct=j?.tracking?.split("/")[0],Ft=Cs.find(Tr=>Tr.name===ct)??Cs[0];if(!Ft)throw new Error("No remote available for sync");const Xt=`${Ft.name}/`,Ws=j?.tracking?.startsWith(Xt)?j.tracking.slice(Xt.length):void 0;let Bs=0,On=!1;await e.gitFetch(n,{remote:Ft.name}),((await e.getGitStatus(n)).behind??0)>0&&(Bs=(await e.gitPull(n,{remote:Ft.name,branch:Ws,rebase:!0})).files.length),((await e.getGitStatus(n)).ahead??0)>0&&(await e.gitPush(n),On=!0),Bs>0&&On?H.success(Bs===1?t("gitView.toast.syncedPulledSingleAndPushed",{count:Bs,name:Ft.name}):t("gitView.toast.syncedPulledPluralAndPushed",{count:Bs,name:Ft.name})):Bs>0?H.success(Bs===1?t("gitView.toast.pulledFilesSingle",{count:Bs,name:Ft.name}):t("gitView.toast.pulledFilesPlural",{count:Bs,name:Ft.name})):On?H.success(t("gitView.toast.pushedToUpstream")):H.success(t("gitView.toast.alreadyUpToDate")),De(),await ss(!1)}else await ss(!1);await Es(),ut(ct=>ct+1)}catch(ct){const Ft=ct instanceof Error?ct.message:t("gitView.toast.createCommitFailed");H.error(Ft)}finally{Pe(null),Le.pushAfter&&we(null)}},An=l.useCallback(async()=>{if(n){if(je.size===0){H.error(t("gitView.toast.selectFileToDescribe"));return}console.error("[git-generation][browser] generate button clicked",{directory:n,selectedFiles:je.size}),it(!0);try{const{message:Le}=await Ib(n,Array.from(je)),Qe=Le.subject?.trim()??"",tt=Array.isArray(Le.highlights)?Le.highlights:[];if(Qe){let ct=Qe;if(ke&&Et.length>0){const Ft=nN(Qe,Et);if(Ft){const{code:Xt,emoji:Ws}=Ft;!Qe.startsWith(Xt)&&!Qe.startsWith(Ws)&&(ct=`${Xt} ${Qe}`)}}ye(ct)}Ne(tt),Ke()}catch(Le){console.error("[git-generation][browser] GitView generate handler failed",{message:Le instanceof Error?Le.message:String(Le),error:Le});const Qe=Le instanceof Error?Le.message:t("gitView.toast.generateCommitMessageFailed");H.error(Qe)}finally{it(!1)}}},[n,je,ke,Et,Ke,t]),tr=Le=>Le.reason==="attention"?`${Le.attentionReason} in progress`:Le.reason==="missing"?"worktree is missing":"worktree is invalid",Be=async(Le,Qe)=>{if(!n||!j)return;const tt=ql(S);if(tt.length>0){H.error(t("gitView.toast.cannotCreateBranch",{reason:tr(tt[0])}));return}const ct=j.current??null,Ft=Qe?.name??"origin";try{await e.createBranch(n,Le,ct??"HEAD"),H.success(t("gitView.toast.createdBranch",{name:Le})),await e.checkoutBranch(n,Le);let Xt=!1;try{await e.gitPush(n,{remote:Ft,branch:Le,options:["--set-upstream"]}),Xt=!0}catch(Ws){const Bs=Ws instanceof Error?Ws.message:`Unable to push new branch to ${Ft}.`;H.warning(t("gitView.toast.branchCreatedLocally"),{description:s.jsxs("span",{className:"text-foreground/80 dark:text-foreground/70",children:["Upstream setup failed: ",Bs]})})}await ss(),await Es(),Xt&&H.success(t("gitView.toast.upstreamSet",{branch:Le,remote:Ft}))}catch(Xt){const Ws=Xt instanceof Error?Xt.message:t("gitView.toast.createBranchFailed");throw H.error(Ws),Xt}},Dt=async(Le,Qe)=>{if(!n)return;const tt=ql(S);if(tt.length>0){H.error(t("gitView.toast.cannotRenameBranch",{reason:tr(tt[0])}));return}try{await e.renameBranch(n,Le,Qe),H.success(t("gitView.toast.renamedBranch",{oldName:Le,newName:Qe})),await ss(),await Es()}catch(ct){const Ft=ct instanceof Error?ct.message:t("gitView.toast.renameBranchFailed",{oldName:Le,newName:Qe});H.error(Ft)}},Yt=async Le=>{if(!n)return;const Qe=ql(S);if(Qe.length>0){H.error(t("gitView.toast.cannotCheckout",{reason:tr(Qe[0])}));return}const tt=Le.replace(/^remotes\//,"");if(j?.current!==tt)try{await e.checkoutBranch(n,tt),H.success(t("gitView.toast.checkedOut",{name:tt})),await ss(),await Es()}catch(ct){const Ft=ct instanceof Error?ct.message:t("gitView.toast.checkoutFailed",{name:tt});H.error(Ft)}},Qt=async Le=>{if(n){L();try{await e.setGitIdentity(n,Le.id),H.success(t("gitView.toast.appliedIdentity",{name:Le.name})),await Pn()}catch(Qe){const tt=Qe instanceof Error?Qe.message:t("gitView.toast.applyIdentityFailed");H.error(tt)}finally{$()}}},vs=l.useMemo(()=>A?.all?A.all.filter(Le=>!Le.startsWith("remotes/")).sort():[],[A]),Rs=l.useMemo(()=>A?.all?A.all.filter(Le=>Le.startsWith("remotes/")).map(Le=>Le.replace(/^remotes\//,"")).sort():[],[A]),Cs=l.useMemo(()=>{if(wt.length>0)return wt;const Le=new Set,Qe=j?.tracking?.trim();Qe&&Qe.includes("/")&&Le.add(Qe.split("/")[0]);for(const tt of Rs){const ct=tt.indexOf("/");ct>0&&Le.add(tt.slice(0,ct))}return Le.size===0&&Kt&&Le.add("origin"),Array.from(Le).map(tt=>({name:tt,fetchUrl:Kt??"",pushUrl:Kt??""}))},[wt,Rs,Kt,j?.tracking]),_s=l.useMemo(()=>{const Le=new Set(Cs.map(Ft=>Ft.name)),Qe=Ft=>{if(!Ft)return"";let Xt=Ft.trim();if(!Xt||Xt==="HEAD")return"";if(vs.includes(Xt))return Xt;Xt.startsWith("refs/heads/")&&(Xt=Xt.slice(11)),Xt.startsWith("heads/")&&(Xt=Xt.slice(6)),Xt.startsWith("remotes/")&&(Xt=Xt.slice(8));const Ws=Xt.indexOf("/");if(Ws>0){const Bs=Xt.slice(0,Ws);if(Le.has(Bs)){const On=Xt.slice(Ws+1).trim();On&&(Xt=On)}}return Xt},tt=Qe(typeof P?.createdFromBranch=="string"?P.createdFromBranch:"");if(tt)return tt;const ct=Qe(typeof oe=="string"?oe:"");return ct||(vs.includes("main")?"main":vs.includes("master")?"master":vs.includes("develop")?"develop":"main")},[Cs,vs,oe,P?.createdFromBranch]),Qs=l.useMemo(()=>Cs.map(tt=>tt.name).map(tt=>`${tt}/${_s}`).find(tt=>Rs.includes(tt))??_s,[_s,Cs,Rs]),Fn=l.useMemo(()=>{const Le=new Map;x&&Le.set(x.id,x);let Qe=null;if(Kt)try{let tt=Kt.trim();tt.startsWith("git@")&&(tt=`https://${tt.slice(4).replace(":","/")}`),tt.endsWith(".git")&&(tt=tt.slice(0,-4));const ct=new URL(tt);Qe=ct.hostname+ct.pathname}catch{}for(const tt of v){if(tt.authType!=="token"){Le.set(tt.id,tt);continue}const ct=tt.host;if(!ct){Le.set(tt.id,tt);continue}if(!ct.includes("/")){Le.set(tt.id,tt);continue}Qe&&Qe===ct&&Le.set(tt.id,tt)}return Array.from(Le.values())},[v,x,Kt]),gr=l.useMemo(()=>{if(E?.userName&&E?.userEmail){const Le=v.find(Qe=>Qe.userName===E.userName&&Qe.userEmail===E.userEmail);return Le||(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]),zr=je.size,Pr=T||pe!==null||re!==null,Nn=j?.current??null,wn=!!(P&&Ve&&qe&&lt),zn=!!(n&&Nn),sr=!!Nn,gn=wn&&Ve&&qe&&P?{repoRoot:Ve,sourceBranch:qe,worktreeMetadata:P}:null,nr=l.useMemo(()=>!zn||!n||!Nn?null:{directory:n,branch:Nn},[zn,Nn,n]);l.useEffect(()=>{if(!n||!e||!N?.all?.length||!Nn||!_s||Nn===_s){zt(null);return}let Le=!1;return(async()=>{try{const tt=await e.getGitLog(n,{from:_s,to:"HEAD",maxCount:ce});if(Le)return;const ct=new Set((tt?.all??[]).map(Xt=>Xt.hash).filter(Xt=>typeof Xt=="string"&&Xt.length>0));if(ct.size===0){zt(null);return}const Ft=N.all.findIndex(Xt=>!ct.has(Xt.hash));if(Ft===0){zt(null);return}if(Ft===-1){zt({insertBeforeIndex:N.all.length,branchName:Nn,direction:"up"});return}zt({insertBeforeIndex:Ft,branchName:Nn,direction:"up"})}catch{Le||zt(null)}})(),()=>{Le=!0}},[_s,Nn,n,e,N,ce]);const Vr=Le=>{ae(Qe=>{const tt=new Set(Qe);return tt.has(Le)?tt.delete(Le):tt.add(Le),tt}),le(!0)},Ar=()=>{const Le=new Set(an.map(Qe=>Qe.path));ae(Le),le(!0)},rr=()=>{ae(new Set),le(!0)},ua=l.useCallback(async Le=>{if(n){Ge(Qe=>{const tt=new Set(Qe);return tt.add(Le),tt});try{await e.revertGitFile(n,Le),H.success(t("gitView.toast.revertedFile",{path:Le})),await ss(!1)}catch(Qe){const tt=Qe instanceof Error?Qe.message:t("gitView.toast.revertFailed");H.error(tt)}finally{Ge(Qe=>{const tt=new Set(Qe);return tt.delete(Le),tt})}}},[n,ss,e,t]),Sn=l.useCallback(async Le=>{if(!n||Le.length===0||at)return;const Qe=Array.from(new Set(Le));Ye(!0),Ge(ct=>{const Ft=new Set(ct);return Qe.forEach(Xt=>Ft.add(Xt)),Ft});const tt=[];try{if(await Promise.all(Qe.map(async ct=>{try{await e.revertGitFile(n,ct)}catch(Ft){tt.push({path:ct,message:Ft instanceof Error?Ft.message:t("gitView.toast.revertFailed")})}})),await ss(!1),tt.length===0)H.success(Qe.length===1?t("gitView.toast.revertedFilesSingle",{count:Qe.length}):t("gitView.toast.revertedFilesPlural",{count:Qe.length}));else if(tt.length===Qe.length)H.error(tt[0]?.message||t("gitView.toast.revertFailed"));else{const ct=Qe.length-tt.length;H.warning(ct===1?t("gitView.toast.revertedSomeSingle",{success:ct,failed:tt.length}):t("gitView.toast.revertedSomePlural",{success:ct,failed:tt.length}))}}finally{Ge(ct=>{const Ft=new Set(ct);return Qe.forEach(Xt=>Ft.delete(Xt)),Ft}),Ye(!1)}},[n,e,at,ss,t]),ma=l.useCallback(Le=>{if(Le.length===0)return;const Qe=Le.map(tt=>tt.trim()).filter(Boolean);if(Qe.length===0){ze();return}ye(tt=>{const ct=tt.trim(),Ft=ct.length>0?`
43
+
44
+ `:"";return`${ct}${Ft}${Qe.join(`
45
+ `)}`.trim()}),ze()},[ze]),ar=l.useCallback((Le,Qe)=>{const tt=Qe||Le;ye(ct=>{const Ft=ct.trimStart();return Ft.startsWith(Le)||Qe&&Ft.startsWith(Qe)?ct:`${tt.endsWith(" ")?tt:`${tt} `}${ct}`.trimStart()}),xs(""),Se(!1)},[]),pa=l.useCallback(Le=>{Ce(Le),n&&(Q(n,Le),K(n,e,Le))},[n,Q,K,e]),Ur=l.useCallback(Le=>{const Qe=Le instanceof Error?Le.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")},[]),ir=l.useCallback((Le,Qe)=>{ln(tt=>[...tt,{message:Le,status:Qe,timestamp:Date.now()}])},[]),xn=l.useCallback((Le,Qe)=>{ln(tt=>{if(tt.length===0)return tt;const ct=[...tt];return ct[ct.length-1]={...ct[ct.length-1],status:Le,...Qe?{message:Qe}:{}},ct})},[]),cn=l.useCallback(()=>{ln([])},[]),_r=l.useCallback(()=>{ln([]),$s(null)},[]),dn=l.useCallback(Le=>{const Qe=Le.trim(),tt=new Set(Cs.map(Ft=>Ft.name)),ct=Qe.indexOf("/");if(ct>0){const Ft=Qe.slice(0,ct),Xt=Qe.slice(ct+1);if(tt.has(Ft)&&Xt)return{branch:Qe,remote:Ft,remoteBranch:Xt}}for(const Ft of Cs){const Xt=`${Ft.name}/${Qe}`;if(Rs.includes(Xt))return{branch:Xt,remote:Ft.name,remoteBranch:Qe}}return{branch:Qe,remote:null,remoteBranch:null}},[Cs,Rs]),Dr=l.useCallback(async Le=>{if(!n)return;$s("merge"),cn();const Qe=j?.current,tt=dn(Le);try{tt.remote&&tt.remoteBranch&&(ir(`Fetching ${tt.remote}/${tt.remoteBranch}...`,"running"),await e.gitFetch(n,{remote:tt.remote,branch:tt.remoteBranch}),xn("done",`Fetched ${tt.remote}/${tt.remoteBranch}`)),ir(`Merging ${tt.branch} into ${Qe}...`,"running");const ct=await e.merge(n,{branch:tt.branch});ct.conflict?(xn("error","Merge conflicts detected"),se(ct.conflictFiles??[]),Je("merge"),Vt(!0),Gt(n,ct.conflictFiles??[],"merge")):(xn("done",`Merged ${tt.branch} into ${Qe}`),is(),ir("Refreshing repository status...","running"),await ss(),await Es(),xn("done","Repository status updated"))}catch(ct){if(Ur(ct))xn("error","Uncommitted changes detected"),Mt("merge"),Ot(tt.branch),gt(!0);else{const Ft=ct instanceof Error?ct.message:`Failed to merge ${tt.branch}`;xn("error",Ft)}}},[n,e,j,dn,ss,Es,Ur,Gt,is,ir,xn,cn]),Wr=l.useCallback(async Le=>{if(!n)return;$s("rebase"),cn();const Qe=j?.current,tt=dn(Le);try{tt.remote&&tt.remoteBranch&&(ir(`Fetching ${tt.remote}/${tt.remoteBranch}...`,"running"),await e.gitFetch(n,{remote:tt.remote,branch:tt.remoteBranch}),xn("done",`Fetched ${tt.remote}/${tt.remoteBranch}`)),ir(`Rebasing ${Qe} onto ${tt.branch}...`,"running");const ct=await e.rebase(n,{onto:tt.branch});ct.conflict?(xn("error","Rebase conflicts detected"),se(ct.conflictFiles??[]),Je("rebase"),Vt(!0),Gt(n,ct.conflictFiles??[],"rebase")):(xn("done",`Rebased ${Qe} onto ${tt.branch}`),is(),ir("Refreshing repository status...","running"),await ss(),await Es(),xn("done","Repository status updated"))}catch(ct){if(Ur(ct))xn("error","Uncommitted changes detected"),Mt("rebase"),Ot(tt.branch),gt(!0);else{const Ft=ct instanceof Error?ct.message:`Failed to rebase onto ${tt.branch}`;xn("error",Ft)}}},[n,e,j,dn,ss,Es,Ur,Gt,is,ir,xn,cn]),Va=l.useCallback(async()=>{if(n)try{xt==="merge"?(await e.abortMerge(n),H.success(t("gitView.toast.mergeAborted"))):(await e.abortRebase(n),H.success(t("gitView.toast.rebaseAborted"))),is(),await ss(),await Es()}catch(Le){const Qe=Le instanceof Error?Le.message:`Failed to abort ${xt}`;H.error(Qe)}},[n,e,xt,ss,Es,is,t]),xr=l.useMemo(()=>j?.files?j.files.some(Le=>Le.index==="U"||Le.working_dir==="U"||Le.index==="A"&&Le.working_dir==="A"||Le.index==="D"&&Le.working_dir==="D"):!1,[j?.files]),Ua=l.useCallback(async()=>{if(n)try{const Le=!!j?.mergeInProgress?.head,Qe=!!(j?.rebaseInProgress?.headName||j?.rebaseInProgress?.onto);if(Le){const tt=await e.continueMerge(n);tt.conflict?(se(tt.conflictFiles??[]),Je("merge"),Vt(!0),Gt(n,tt.conflictFiles??[],"merge"),H.error(t("gitView.toast.mergeConflictsDetected"))):(is(),H.success(t("gitView.toast.mergeCompleted")),await ss(),await Es())}else if(Qe){const tt=await e.continueRebase(n);tt.conflict?(se(tt.conflictFiles??[]),Je("rebase"),Vt(!0),Gt(n,tt.conflictFiles??[],"rebase"),H.error(t("gitView.toast.rebaseConflictsDetected"))):(is(),H.success(t("gitView.toast.rebaseStepCompleted")),await ss(),await Es())}}catch(Le){const Qe=Le instanceof Error?Le.message:t("gitView.toast.continueOperationFailed");H.error(Qe)}},[n,e,j,ss,Es,Gt,is,t]),fn=l.useCallback(async()=>{if(n)try{!!j?.mergeInProgress?.head?(await e.abortMerge(n),H.success(t("gitView.toast.mergeAborted"))):(await e.abortRebase(n),H.success(t("gitView.toast.rebaseAborted"))),is(),await ss(),await Es()}catch(Le){const Qe=Le instanceof Error?Le.message:t("gitView.toast.abortOperationFailed");H.error(Qe)}},[n,e,j,ss,Es,is,t]),wi=l.useCallback(()=>{if(!n)return;const Qe=!!j?.mergeInProgress?.head?"merge":"rebase",tt=j?.files?.filter(ct=>ct.index==="U"||ct.working_dir==="U").map(ct=>ct.path)??[];tt.length>0&&se(tt),Je(Qe),Vt(!0)},[n,j]),go=l.useCallback(async Le=>{if(!n)return;const Qe=j?.current,tt=Pt,ct=ts;try{await e.stash(n,{message:`Auto-stash before ${tt} with ${ct}`,includeUntracked:!0})}catch(Ws){const Bs=Ws instanceof Error?Ws.message:"Failed to stash changes";H.error(Bs);return}let Ft=!1,Xt=!1;try{if(tt==="merge"){const Ws=await e.merge(n,{branch:ct});Ws.conflict?(Xt=!0,se(Ws.conflictFiles??[]),Je("merge"),Vt(!0)):(Ft=!0,H.success(t("gitView.toast.mergedIntoBranch",{branch:ct,currentBranch:Qe||""})))}else{const Ws=await e.rebase(n,{onto:ct});Ws.conflict?(Xt=!0,se(Ws.conflictFiles??[]),Je("rebase"),Vt(!0)):(Ft=!0,H.success(t("gitView.toast.rebasedOntoBranch",{currentBranch:Qe||"",branch:ct})))}if(Le&&Ft)try{await e.stashPop(n),H.success(t("gitView.toast.stashedRestored"))}catch(Ws){const Bs=Ws instanceof Error?Ws.message:t("gitView.toast.restoreStashFailed");H.error(Bs)}else Le&&Xt&&H.info(t("gitView.toast.restoreStashManually"));await ss(),await Es()}catch(Ws){if(Le)try{await e.stashPop(n)}catch{}throw Ws}},[n,e,j,Pt,ts,ss,Es,t]);return n?T&&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?ee?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:xe("flex h-full flex-col overflow-hidden","bg-sidebar"),children:[s.jsx(ij,{status:j,localBranches:vs,remoteBranches:Rs,branchInfo:A?.branches,syncAction:pe,remotes:Cs,onFetch:Le=>Ir("fetch",Le),onSync:Le=>Ir("sync",Le),onRemoveRemote:er,removingRemoteName:ds,onCheckoutBranch:Yt,onCreateBranch:Be,onRenameBranch:Dt,activeIdentityProfile:gr,availableIdentities:Fn,onSelectIdentity:Qt,isApplyingIdentity:Te,isWorktreeMode:!!P,onOpenHistory:()=>Wt(!0),actionTabItems:We,activeActionTab:St,onSelectActionTab:Le=>qt(Le)}),n&&(j?.mergeInProgress?.head||j?.rebaseInProgress?.headName||j?.rebaseInProgress?.onto)&&s.jsx(V0,{mergeInProgress:j?.mergeInProgress,rebaseInProgress:j?.rebaseInProgress,onContinue:Ua,onAbort:fn,onResolveWithAI:wi,hasUnresolvedConflicts:xr,isLoading:T}),s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:s.jsx("div",{className:"h-full min-h-0 flex flex-col",children:s.jsx("div",{className:xe("min-w-0 min-h-0 h-full flex flex-col","bg-sidebar"),children:s.jsxs(Ns,{as:lo,ref:Ae,outerClassName:"flex-1 min-h-0",className:xe("px-4","pt-1 pb-4"),disableHorizontal:!0,preventOverscroll:!0,children:[St==="commit"?s.jsx("div",{className:"space-y-4",children:(an?.length??0)>0?s.jsxs(s.Fragment,{children:[s.jsx(gj,{maxListHeightClassName:"max-h-[40vh]",changeEntries:an,onVisiblePathsChange:ve,selectedPaths:je,diffStats:j?.diffStats,revertingPaths:Me,onToggleFile:Vr,onSelectAll:Ar,onClearSelection:rr,onRevertAll:Sn,onViewDiff:Le=>{if(n&&!te){Z(n,Le);return}fe(Le),te&&ue(!1)},onRevertFile:ua,isRevertingAll:at,onOpenStashes:()=>Y(!0)}),s.jsx(wj,{selectedCount:zr,commitMessage:me,onCommitMessageChange:ye,generatedHighlights:nt,onInsertHighlights:ma,onGenerateMessage:An,isGeneratingMessage:rt,onCommit:()=>Js({pushAfter:!1}),onCommitAndPush:()=>Js({pushAfter:!0}),commitAction:re,gitmojiEnabled:ke,onOpenGitmojiPicker:()=>Se(!0)})]}):s.jsx(jj,{onOpenStashes:()=>Y(!0)})}):null,St==="branch"?s.jsx("div",{className:"space-y-4",children:sr?s.jsxs(s.Fragment,{children:[s.jsx(U0,{mode:"inline",currentBranch:j?.current,localBranches:vs,remoteBranches:Rs,defaultTargetBranch:Qs,onMerge:Dr,onRebase:Wr,disabled:Pr,isOperating:as!==null,operationLogs:Ls,onOperationComplete:_r}),gn?s.jsx(Xw,{repoRoot:gn.repoRoot,sourceBranch:gn.sourceBranch,worktreeMetadata:gn.worktreeMetadata,localBranches:vs,defaultTargetBranch:He,refreshKey:Xe,onRefresh:()=>{n&&(B(n,e),z(n,e),K(n,e,ce))}},gn.worktreeMetadata.path):null]}):s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("gitView.branch.actionsUnavailable")})}):null,St==="pr"?s.jsx("div",{className:"space-y-4",children:nr?s.jsx(E0,{directory:nr.directory,branch:nr.branch,baseBranch:_s,trackingBranch:j?.tracking??void 0,remotes:wt,remoteBranches:Rs,onGeneratedDescription:Ke}):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:bs,onOpenChange:Wt,children:s.jsxs(ms,{className:"max-w-5xl h-[90vh] max-h-[90vh] flex flex-col overflow-hidden",children:[s.jsxs(ys,{children:[s.jsx(hs,{children:t("gitView.history.title")}),s.jsx(Ss,{children:t("gitView.history.dialogDescription")})]}),s.jsx("div",{className:"flex-1 min-h-0",children:s.jsx(n0,{log:N,isLogLoading:R,logMaxCount:ce,onLogMaxCountChange:pa,expandedCommitHashes:et,onToggleCommit:Zs,commitFilesMap:Rt,loadingCommitHashes:ht,onCopyHash:ks,directory:n??void 0,showHeader:!1,contentMaxHeightClassName:"h-full max-h-none",branchDivider:ns})})]})}),s.jsx(oj,{open:Ie,onOpenChange:Y,directory:n,hasUncommittedChanges:(j?.files?.length??0)>0,uncommittedFileCount:j?.files?.length??0,onChanged:async()=>{await ss(!1),await Es()}}),s.jsx(ps,{open:X,onOpenChange:Se,children:s.jsxs(ms,{className:"max-w-md p-0 overflow-hidden",children:[s.jsx(ys,{className:"px-4 pt-4",children:s.jsx(hs,{children:t("gitView.gitmoji.title")})}),s.jsxs(La,{className:"h-[420px]",children:[s.jsx(da,{placeholder:t("gitView.gitmoji.searchPlaceholder"),value:gs,onValueChange:xs}),s.jsxs($a,{children:[s.jsx(_a,{children:t("gitView.gitmoji.empty")}),s.jsx(Mn,{children:(Et.length===0?[]:Et.filter(Le=>{const Qe=gs.trim().toLowerCase();return Qe?Le.emoji.includes(Qe)||Le.code.toLowerCase().includes(Qe)||Le.description.toLowerCase().includes(Qe):!0})).map(Le=>s.jsxs(jn,{onSelect:()=>ar(Le.emoji,Le.code),children:[s.jsx("span",{className:"text-lg",children:Le.emoji}),s.jsx("span",{className:"typography-ui-label text-foreground",children:Le.code}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:Le.description})]},Le.code))})]})]})]})}),n&&s.jsx(R0,{open:Xs,onOpenChange:Vt,conflictFiles:Ut,directory:n,operation:xt,onAbort:Va,onClearState:is}),s.jsx(z0,{open:Ue,onOpenChange:gt,operation:Pt,targetBranch:ts,onConfirm:go})]}):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")})})},rN=Object.freeze(Object.defineProperty({__proto__:null,GitView:Gh},Symbol.toStringTag,{value:"Module"})),id=5e3,aN=(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},iN=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"},oN=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()},Jd=async(t,e)=>{try{const n=await oN(t,e);return aN(n,id)>id?{ok:!1,reason:"too-large"}:{ok:!0}}catch(n){return{ok:!1,reason:iN(n)}}},Yd=t=>t==="too-large"?`File is too large to open (>${id.toLocaleString()} lines)`:t==="missing"?"File not found":"Failed to open file",lN=t=>t.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),_n=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=_n(e),r=_n(t).replace(/\/+$/,"");return n===r?".":!r||!n.startsWith(`${r}/`)?n:n.slice(r.length+1)},cN=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),dN=new Set(["node_modules"]),uN=t=>dN.has(t),mN=t=>{const e=_n(t);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},Jh=(t,e)=>s.jsx(jr,{filePath:t,extension:e}),pN=t=>{const e=st.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},fN=t=>{const e=st.c(63),{node:n,root:r,isExpanded:a,isActive:i,status:o,badge:c,permissions:d,downloadFile:p,contextMenuPath:m,setContextMenuPath:u,onSelect:f,onToggle:b,onRevealPath:h,onOpenDialog:v}=t,{t:x}=dt(),g=n.type==="directory",{canRename:w,canCreateFile:y,canCreateFolder:C,canDelete:k,canReveal:j}=d;let S;e[0]!==y||e[1]!==C||e[2]!==k||e[3]!==w||e[4]!==j||e[5]!==n.path||e[6]!==u?(S=Q=>{!w&&!y&&!C&&!k&&!j||(Q?.preventDefault(),u(n.path))},e[0]=y,e[1]=C,e[2]=k,e[3]=w,e[4]=j,e[5]=n.path,e[6]=u,e[7]=S):S=e[7];const I=S;let M;e[8]!==g||e[9]!==n||e[10]!==f||e[11]!==b?(M=()=>{g?b(n.path):f(n)},e[8]=g,e[9]=n,e[10]=f,e[11]=b,e[12]=M):M=e[12];const P=M;let A;e[13]!==n.path||e[14]!==u?(A=Q=>{Q.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=Q=>{const te=qh(r,n.path);!te||te==="."||(Q.dataTransfer.setData("application/x-openchamber-file-path",te),Q.dataTransfer.effectAllowed="copy")},e[16]=n.path,e[17]=r,e[18]=E):E=e[18];const T=E,R=i?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let V;e[19]!==R?(V=xe("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",R,"cursor-grab active:cursor-grabbing"),e[19]=R,e[20]=V):V=e[20];let _;e[21]!==g||e[22]!==a||e[23]!==n.extension||e[24]!==n.path?(_=g?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]=g,e[22]=a,e[23]=n.extension,e[24]=n.path,e[25]=_):_=e[25];let U;e[26]!==n.name||e[27]!==n.path?(U=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]=U):U=e[28];let B;e[29]!==g||e[30]!==o?(B=!g&&o&&s.jsx(pN,{status:o}),e[29]=g,e[30]=o,e[31]=B):B=e[31];let z;e[32]!==c||e[33]!==g?(z=g&&c&&s.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[c.modified>0&&s.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",c.modified]}),c.added>0&&s.jsxs("span",{className:"text-[var(--status-success)]",children:["+",c.added]})]}),e[32]=c,e[33]=g,e[34]=z):z=e[34];let K;e[35]!==I||e[36]!==T||e[37]!==P||e[38]!==z||e[39]!==V||e[40]!==_||e[41]!==U||e[42]!==B?(K=s.jsxs("button",{type:"button",onClick:P,onContextMenu:I,draggable:!0,onDragStart:T,className:V,children:[_,U,B,z]}),e[35]=I,e[36]=T,e[37]=P,e[38]=z,e[39]=V,e[40]=_,e[41]=U,e[42]=B,e[43]=K):K=e[43];let F;e[44]!==y||e[45]!==C||e[46]!==k||e[47]!==w||e[48]!==j||e[49]!==m||e[50]!==p||e[51]!==N||e[52]!==g||e[53]!==n||e[54]!==v||e[55]!==h||e[56]!==u||e[57]!==x?(F=(w||y||C||k||j)&&s.jsx("div",{className:"absolute right-1 top-1/2 -translate-y-1/2 opacity-0 focus-within:opacity-100 group-hover:opacity-100",children:s.jsxs(Ts,{open:m===n.path,onOpenChange:Q=>u(Q?n.path:null),children:[s.jsx(As,{asChild:!0,children:s.jsx(be,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:N,children:s.jsx(D,{name:"more-2-fill",className:"h-4 w-4"})})}),s.jsxs(Ds,{align:"end",side:"bottom",onCloseAutoFocus:()=>u(null),children:[w&&s.jsxs($t,{onClick:Q=>{Q.stopPropagation(),v("rename",n)},children:[s.jsx(D,{name:"edit",className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.rename")]}),s.jsxs($t,{onClick:Q=>{Q.stopPropagation(),In(n.path).then(te=>{if(te.ok){H.success(x("sidebarFilesTree.toast.pathCopied"));return}H.error(x("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(D,{name:"file-copy",className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.copyPath")]}),!g&&p&&s.jsxs($t,{onClick:Q=>{Q.stopPropagation(),p(n.path)},children:[s.jsx(D,{name:"download",className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.save")]}),j&&s.jsxs($t,{onClick:Q=>{Q.stopPropagation(),h(n.path)},children:[s.jsx(D,{name:"folder-received",className:"mr-2 h-4 w-4"})," ",x(Od())]}),g&&(y||C)&&s.jsxs(s.Fragment,{children:[s.jsx(Gn,{}),y&&s.jsxs($t,{onClick:Q=>{Q.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($t,{onClick:Q=>{Q.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(Gn,{}),s.jsxs($t,{onClick:Q=>{Q.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]=w,e[48]=j,e[49]=m,e[50]=p,e[51]=N,e[52]=g,e[53]=n,e[54]=v,e[55]=h,e[56]=u,e[57]=x,e[58]=F):F=e[58];let G;return e[59]!==I||e[60]!==K||e[61]!==F?(G=s.jsxs("div",{className:"group relative flex items-center",onContextMenu:I,children:[K,F]}),e[59]=I,e[60]=K,e[61]=F,e[62]=G):G=e[62],G},hN=()=>{const t=st.c(240),{t:e}=dt(),{files:n,runtime:r}=Rn(),a=Zr()??"";let i;t[0]!==a?(i=_n(a.trim()),t[0]=a,t[1]=i):i=t[1];const o=i,c=Tl(),d=Rd(),p=Fd(gN),m=Re(xN),u=Dl(a),[f,b]=l.useState(""),h=Ml(f,200),v=l.useRef(null);let x;t[2]===Symbol.for("react.memo_cache_sentinel")?(x=[],t[2]=x):x=t[2];const[g,w]=l.useState(x),[y,C]=l.useState(!1);let k;t[3]===Symbol.for("react.memo_cache_sentinel")?(k={},t[3]=k):k=t[3];const[j,S]=l.useState(k);let I;t[4]===Symbol.for("react.memo_cache_sentinel")?(I=new Set,t[4]=I):I=t[4];const M=l.useRef(I);let P;t[5]===Symbol.for("react.memo_cache_sentinel")?(P=new Set,t[5]=P):P=t[5];const A=l.useRef(P);let N;t[6]===Symbol.for("react.memo_cache_sentinel")?(N=[],t[6]=N):N=t[6];const E=N;let T;t[7]===Symbol.for("react.memo_cache_sentinel")?(T=[],t[7]=T):T=t[7];const R=T;let V;t[8]!==o?(V=Vt=>o?Vt.byRoot[o]?.expandedPaths??E:E,t[8]=o,t[9]=V):V=t[9];const _=Tn(V);let U;t[10]!==o?(U=Vt=>o?Vt.byRoot[o]?.selectedPath??null:null,t[10]=o,t[11]=U):U=t[11];const B=Tn(U),z=Tn(bN),K=Tn(yN),F=Tn(vN),G=Tn(wN);let Q;t[12]!==o?(Q=Vt=>o?Vt.contextPanelByDirectory[o]?.tabs??R:R,t[12]=o,t[13]=Q):Q=t[13];const te=Re(Q);let Z;t[14]!==te?(Z=new Set(te.map(jN).filter(NN).map(SN)),t[14]=te,t[15]=Z):Z=t[15];const fe=Z,[ue,W]=l.useState(null),[q,J]=l.useState(null),[ne,ee]=l.useState(null),[he,ke]=l.useState(""),[oe,ge]=l.useState(!1),me=!!n.writeFile,ye=!!n.createDirectory,ie=!!n.rename,ve=!!n.delete,X=!!n.revealPath;let Se;t[16]!==me||t[17]!==ye||t[18]!==ve||t[19]!==ie||t[20]!==X?(Se={canRename:ie,canCreateFile:me,canCreateFolder:ye,canDelete:ve,canReveal:X},t[16]=me,t[17]=ye,t[18]=ve,t[19]=ie,t[20]=X,t[21]=Se):Se=t[21];const Ae=Se;let pe;t[22]!==n||t[23]!==e?(pe=Vt=>{n.revealPath&&n.revealPath(Vt).catch(()=>{H.error(e("sidebarFilesTree.toast.revealFailed"))})},t[22]=n,t[23]=e,t[24]=pe):pe=t[24];const we=pe;let Ie;t[25]===Symbol.for("react.memo_cache_sentinel")?(Ie=(Vt,Ut)=>{J(Vt),ee(Ut),ke(Vt==="rename"&&Ut.name||""),ge(!1)},t[25]=Ie):Ie=t[25];const Y=Ie;let re;t[26]!==d||t[27]!==c?(re=(Vt,Ut)=>{const se=Ut.filter(kN).filter(xt=>c||!xt.name.startsWith(".")).filter(xt=>d||!uN(xt.name)).map(xt=>{const Je=xt.name,_t=_n(xt.path||""),Gt=_t?cN(_t)?_t:_n(`${Vt}/${_t}`):_n(`${Vt}/${Je}`),is=xt.isDirectory?"directory":"file",Ue=is==="file"&&Je.includes(".")?Je.split(".").pop()?.toLowerCase():void 0;return{name:Je,path:Gt,type:is,extension:Ue}});return lN(se)},t[26]=d,t[27]=c,t[28]=re):re=t[28];const Pe=re;let ce;t[29]!==n||t[30]!==Pe||t[31]!==r.isDesktop||t[32]!==d?(ce=async Vt=>{const Ut=_n(Vt.trim());if(!Ut||M.current.has(Ut)||A.current.has(Ut))return;A.current=new Set(A.current),A.current.add(Ut);const se=!d;await(r.isDesktop?n.listDirectory(Ut,{respectGitignore:se}).then(IN):sn.listLocalDirectory(Ut,{respectGitignore:se}).then(AN)).then(Je=>{const _t=Pe(Ut,Je);M.current=new Set(M.current),M.current.add(Ut),S(Gt=>({...Gt,[Ut]:_t}))}).catch(()=>{S(Je=>({...Je,[Ut]:Je[Ut]??[]}))}).finally(()=>{A.current=new Set(A.current),A.current.delete(Ut)})},t[29]=n,t[30]=Pe,t[31]=r.isDesktop,t[32]=d,t[33]=ce):ce=t[33];const Ce=ce;let Te;t[34]!==Ce||t[35]!==o?(Te=async()=>{o&&(M.current=new Set,A.current=new Set,S(DN),await Ce(o))},t[34]=Ce,t[35]=o,t[36]=Te):Te=t[36];const $e=Te;let De;t[37]!==Ce||t[38]!==$e?(De=async Vt=>{if(!Vt){await $e();return}const Ut=_n(Vt);M.current=new Set(M.current),M.current.delete(Ut),A.current=new Set(A.current),A.current.delete(Ut),await Ce(Ut)},t[37]=Ce,t[38]=$e,t[39]=De):De=t[39];const de=De;let O;t[40]!==Ce||t[41]!==o?(O=()=>{o&&(M.current=new Set,A.current=new Set,S(TN),Ce(o))},t[40]=Ce,t[41]=o,t[42]=O):O=t[42];let L;t[43]!==Ce||t[44]!==o||t[45]!==d||t[46]!==c?(L=[Ce,o,c,d],t[43]=Ce,t[44]=o,t[45]=d,t[46]=c,t[47]=L):L=t[47],l.useEffect(O,L);let $,je;t[48]!==_||t[49]!==Ce||t[50]!==o?($=()=>{if(!o||_.length===0)return;const Vt=_.map(MN).filter(se=>!!se&&se!==o&&se.startsWith(`${o}/`)&&!M.current.has(se)&&!A.current.has(se)).sort(EN);if(Vt.length===0)return;let Ut=!1;return(async()=>{for(let se=0;se<Vt.length&&!Ut;se=se+3,se){const xt=Vt.slice(se,se+3);await Promise.all(xt.map(Je=>Ce(Je)))}})(),()=>{Ut=!0}},je=[_,Ce,o],t[48]=_,t[49]=Ce,t[50]=o,t[51]=$,t[52]=je):($=t[51],je=t[52]),l.useEffect($,je);let ae,_e;t[53]!==a||t[54]!==h||t[55]!==p||t[56]!==d||t[57]!==c?(ae=()=>{if(!a){w([]),C(!1);return}const Vt=h.trim();if(!Vt){w([]),C(!1);return}let Ut=!1;return C(!0),p(a,Vt,150,{includeHidden:c,respectGitignore:!d,type:"file"}).then(se=>{if(Ut)return;const Je=se.filter(_t=>d||!mN(_t.path)).map(RN);w(Je)}).catch(()=>{Ut||w([])}).finally(()=>{Ut||C(!1)}),()=>{Ut=!0}},_e=[a,h,p,c,d],t[53]=a,t[54]=h,t[55]=p,t[56]=d,t[57]=c,t[58]=ae,t[59]=_e):(ae=t[58],_e=t[59]),l.useEffect(ae,_e);let le;t[60]!==u||t[61]!==fe||t[62]!==o?(le=Vt=>{if(fe.has(Vt))return"open";if(u?.files){const Ut=Vt.startsWith(o+"/")?Vt.slice(o.length+1):Vt,se=u.files.find(xt=>xt.path===Ut);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]=fe,t[62]=o,t[63]=le):le=t[63];const Me=le;let Ge;t[64]!==u||t[65]!==o?(Ge=Vt=>{if(!u?.files)return null;const Ut=Vt.startsWith(o+"/")?Vt.slice(o.length+1):Vt,se=Ut?`${Ut}/`:"";let xt=0,Je=0;for(const _t of u.files)_t.path.startsWith(se)&&((_t.index==="M"||_t.working_dir==="M")&&xt++,(_t.index==="A"||_t.working_dir==="?")&&Je++);return xt+Je>0?{modified:xt,added:Je}:null},t[64]=u,t[65]=o,t[66]=Ge):Ge=t[66];const at=Ge;let Ye;t[67]!==K||t[68]!==n||t[69]!==m||t[70]!==o||t[71]!==z?(Ye=async Vt=>{if(!o)return;const Ut=await Jd(n,Vt.path);if(!Ut.ok){H.error(Yd(Ut.reason));return}z(o,Vt.path),K(o,Vt.path),m(o,Vt.path)},t[67]=K,t[68]=n,t[69]=m,t[70]=o,t[71]=z,t[72]=Ye):Ye=t[72];const Xe=Ye;let ut;t[73]!==Ce||t[74]!==o||t[75]!==G?(ut=async Vt=>{const Ut=_n(Vt);o&&(G(o,Ut),M.current.has(Ut)||await Ce(Ut))},t[73]=Ce,t[74]=o,t[75]=G,t[76]=ut):ut=t[76];const rt=ut;let it;t[77]!==q||t[78]!==ne||t[79]!==he||t[80]!==n||t[81]!==de||t[82]!==F||t[83]!==o||t[84]!==B||t[85]!==z||t[86]!==e?(it=async Vt=>{if(Vt?.preventDefault(),!ne||!q)return;ge(!0);const Ut=()=>ge(!1),se=()=>J(null);if(q==="createFile"){if(!he.trim()){H.error(e("sidebarFilesTree.toast.filenameRequired")),Ut();return}if(!n.writeFile){H.error(e("sidebarFilesTree.toast.writeNotSupported")),Ut();return}const xt=ne.path,Je=xt?`${xt}/`:"",_t=_n(`${Je}${he.trim()}`);await n.writeFile(_t,"").then(async Gt=>{Gt.success&&(H.success(e("sidebarFilesTree.toast.fileCreated")),await de(xt)),se()}).catch(()=>H.error(e("sidebarFilesTree.toast.operationFailed"))).finally(Ut);return}if(q==="createFolder"){if(!he.trim()){H.error(e("sidebarFilesTree.toast.folderNameRequired")),Ut();return}const xt=ne.path,Je=xt?`${xt}/`:"",_t=_n(`${Je}${he.trim()}`);await n.createDirectory(_t).then(async Gt=>{Gt.success&&(H.success(e("sidebarFilesTree.toast.folderCreated")),await de(xt)),se()}).catch(()=>H.error(e("sidebarFilesTree.toast.operationFailed"))).finally(Ut);return}if(q==="rename"){if(!he.trim()){H.error(e("sidebarFilesTree.toast.nameRequired")),Ut();return}if(!n.rename){H.error(e("sidebarFilesTree.toast.renameNotSupported")),Ut();return}const xt=ne.path,Je=xt.split("/").slice(0,-1).join("/"),_t=Je?`${Je}/`:"",Gt=_n(`${_t}${he.trim()}`);await n.rename(xt,Gt).then(async is=>{is.success&&(H.success(e("sidebarFilesTree.toast.renamedSuccessfully")),await de(Je),o&&F(o,xt),(B===xt||B&&B.startsWith(`${xt}/`))&&z(o,null)),se()}).catch(()=>H.error(e("sidebarFilesTree.toast.operationFailed"))).finally(Ut);return}if(q==="delete"){if(!n.delete){H.error(e("sidebarFilesTree.toast.deleteNotSupported")),Ut();return}const xt=ne.path,Je=xt.split("/").slice(0,-1).join("/");await n.delete(xt).then(async _t=>{_t.success&&(H.success(e("sidebarFilesTree.toast.deletedSuccessfully")),await de(Je),o&&F(o,xt),(B===xt||B&&B.startsWith(xt+"/"))&&z(o,null)),se()}).catch(()=>H.error(e("sidebarFilesTree.toast.operationFailed"))).finally(Ut);return}Ut()},t[77]=q,t[78]=ne,t[79]=he,t[80]=n,t[81]=de,t[82]=F,t[83]=o,t[84]=B,t[85]=z,t[86]=e,t[87]=it):it=t[87];const nt=it;let Ne,Ke,Ve,qe,lt,He,ze;if(t[88]!==me||t[89]!==ye||t[90]!==j||t[91]!==ue||t[92]!==a||t[93]!==_||t[94]!==Ae||t[95]!==n.downloadFile||t[96]!==Me||t[97]!==at||t[98]!==Xe||t[99]!==we||t[100]!==$e||t[101]!==o||t[102]!==f||t[103]!==g||t[104]!==y||t[105]!==B||t[106]!==e||t[107]!==rt){let Vt=function(ks,Zs){const Hs=j[ks]??[];return Hs.map((ss,Es)=>{const Pn=ss.type==="directory",an=Pn&&_.includes(ss.path),Ir=B===ss.path,er=Es===Hs.length-1;return s.jsxs("li",{className:"relative",children:[Zs>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),er&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-sidebar/50"})]}),s.jsx(fN,{node:ss,root:o,isExpanded:an,isActive:Ir,status:Pn?void 0:Me(ss.path),badge:Pn?at(ss.path):void 0,permissions:Ae,downloadFile:n.downloadFile,contextMenuPath:ue,setContextMenuPath:W,onSelect:Xe,onToggle:rt,onRevealPath:we,onOpenDialog:Y}),Pn&&an&&s.jsx("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:Vt(ss.path,Zs+1)})]},ss.path)})};const Ut=!!(o&&j[o]);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 xt;t[116]===Symbol.for("react.memo_cache_sentinel")?(xt=ks=>b(ks.target.value),t[116]=xt):xt=t[116];let Je;t[117]!==e?(Je=e("sidebarFilesTree.search.placeholder"),t[117]=e,t[118]=Je):Je=t[118];let _t;t[119]!==f||t[120]!==Je?(_t=s.jsx(Bt,{ref:v,value:f,onChange:xt,placeholder:Je,className:"h-8 pl-8 pr-8 typography-meta"}),t[119]=f,t[120]=Je,t[121]=_t):_t=t[121];let Gt;t[122]!==f||t[123]!==e?(Gt=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]=Gt):Gt=t[124];let is;t[125]!==_t||t[126]!==Gt?(is=s.jsxs("div",{className:"relative min-w-0 flex-1",children:[se,_t,Gt]}),t[125]=_t,t[126]=Gt,t[127]=is):is=t[127];let Ue;t[128]!==me||t[129]!==a||t[130]!==e?(Ue=me&&s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>Y("createFile",{path:a,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:e("sidebarFilesTree.actions.newFileTitle"),children:s.jsx(D,{name:"file-add",className:"h-4 w-4"})}),t[128]=me,t[129]=a,t[130]=e,t[131]=Ue):Ue=t[131];let gt;t[132]!==ye||t[133]!==a||t[134]!==e?(gt=ye&&s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>Y("createFolder",{path:a,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:e("sidebarFilesTree.actions.newFolderTitle"),children:s.jsx(D,{name:"folder-add",className:"h-4 w-4"})}),t[132]=ye,t[133]=a,t[134]=e,t[135]=gt):gt=t[135];let Pt;t[136]!==$e?(Pt=()=>{$e()},t[136]=$e,t[137]=Pt):Pt=t[137];let Mt;t[138]!==e?(Mt=e("sidebarFilesTree.actions.refreshTitle"),t[138]=e,t[139]=Mt):Mt=t[139];let ts;t[140]===Symbol.for("react.memo_cache_sentinel")?(ts=s.jsx(D,{name:"refresh",className:"h-4 w-4"}),t[140]=ts):ts=t[140];let Ot;t[141]!==Pt||t[142]!==Mt?(Ot=s.jsx(be,{variant:"ghost",size:"sm",onClick:Pt,className:"h-8 w-8 p-0 flex-shrink-0",title:Mt,children:ts}),t[141]=Pt,t[142]=Mt,t[143]=Ot):Ot=t[143],t[144]!==is||t[145]!==Ue||t[146]!==gt||t[147]!==Ot?(ze=s.jsxs("div",{className:"flex items-center gap-2 border-b border-border/40 px-3 py-2",children:[is,Ue,gt,Ot]}),t[144]=is,t[145]=Ue,t[146]=gt,t[147]=Ot,t[148]=ze):ze=t[148],Ne=Ns,qe="flex-1 min-h-0",lt="p-2",Ke="flex flex-col",Ve=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")]}):g.length>0?g.map(ks=>{const Zs=B===ks.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>Xe(ks),draggable:!0,onDragStart:Hs=>{const ss=ks.relativePath||qh(o??"",ks.path);!ss||ss==="."||(Hs.dataTransfer.setData("application/x-openchamber-file-path",ss),Hs.dataTransfer.effectAllowed="copy")},className:xe("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",Zs?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),title:ks.path,children:[Jh(ks.path,ks.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},children:ks.relativePath??ks.path})]})},ks.path)}):Ut&&o?Vt(o,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:e("sidebarFilesTree.state.loading")}),t[88]=me,t[89]=ye,t[90]=j,t[91]=ue,t[92]=a,t[93]=_,t[94]=Ae,t[95]=n.downloadFile,t[96]=Me,t[97]=at,t[98]=Xe,t[99]=we,t[100]=$e,t[101]=o,t[102]=f,t[103]=g,t[104]=y,t[105]=B,t[106]=e,t[107]=rt,t[108]=Ne,t[109]=Ke,t[110]=Ve,t[111]=qe,t[112]=lt,t[113]=He,t[114]=ze}else Ne=t[108],Ke=t[109],Ve=t[110],qe=t[111],lt=t[112],He=t[113],ze=t[114];let et;t[149]!==Ke||t[150]!==Ve?(et=s.jsx("ul",{className:Ke,children:Ve}),t[149]=Ke,t[150]=Ve,t[151]=et):et=t[151];let yt;t[152]!==Ne||t[153]!==qe||t[154]!==lt||t[155]!==et?(yt=s.jsx(Ne,{outerClassName:qe,className:lt,children:et}),t[152]=Ne,t[153]=qe,t[154]=lt,t[155]=et,t[156]=yt):yt=t[156];const Rt=!!q;let kt;t[157]===Symbol.for("react.memo_cache_sentinel")?(kt=Vt=>!Vt&&J(null),t[157]=kt):kt=t[157];let ht;t[158]!==q||t[159]!==e?(ht=q==="createFile"&&e("sidebarFilesTree.dialog.createFile.title"),t[158]=q,t[159]=e,t[160]=ht):ht=t[160];let vt;t[161]!==q||t[162]!==e?(vt=q==="createFolder"&&e("sidebarFilesTree.dialog.createFolder.title"),t[161]=q,t[162]=e,t[163]=vt):vt=t[163];let ns;t[164]!==q||t[165]!==e?(ns=q==="rename"&&e("sidebarFilesTree.dialog.rename.title"),t[164]=q,t[165]=e,t[166]=ns):ns=t[166];let zt;t[167]!==q||t[168]!==e?(zt=q==="delete"&&e("sidebarFilesTree.dialog.delete.title"),t[167]=q,t[168]=e,t[169]=zt):zt=t[169];let Kt;t[170]!==ht||t[171]!==vt||t[172]!==ns||t[173]!==zt?(Kt=s.jsxs(hs,{children:[ht,vt,ns,zt]}),t[170]=ht,t[171]=vt,t[172]=ns,t[173]=zt,t[174]=Kt):Kt=t[174];let mt;t[175]!==q||t[176]!==ne?.path||t[177]!==e?(mt=q==="createFile"&&e("sidebarFilesTree.dialog.createFile.description",{path:ne?.path??e("sidebarFilesTree.dialog.rootFallback")}),t[175]=q,t[176]=ne?.path,t[177]=e,t[178]=mt):mt=t[178];let Et;t[179]!==q||t[180]!==ne?.path||t[181]!==e?(Et=q==="createFolder"&&e("sidebarFilesTree.dialog.createFolder.description",{path:ne?.path??e("sidebarFilesTree.dialog.rootFallback")}),t[179]=q,t[180]=ne?.path,t[181]=e,t[182]=Et):Et=t[182];let rs;t[183]!==q||t[184]!==ne?.name||t[185]!==e?(rs=q==="rename"&&e("sidebarFilesTree.dialog.rename.description",{name:ne?.name??""}),t[183]=q,t[184]=ne?.name,t[185]=e,t[186]=rs):rs=t[186];let gs;t[187]!==q||t[188]!==ne?.name||t[189]!==e?(gs=q==="delete"&&e("sidebarFilesTree.dialog.delete.description",{name:ne?.name??""}),t[187]=q,t[188]=ne?.name,t[189]=e,t[190]=gs):gs=t[190];let xs;t[191]!==mt||t[192]!==Et||t[193]!==rs||t[194]!==gs?(xs=s.jsxs(Ss,{children:[mt,Et,rs,gs]}),t[191]=mt,t[192]=Et,t[193]=rs,t[194]=gs,t[195]=xs):xs=t[195];let bs;t[196]!==Kt||t[197]!==xs?(bs=s.jsxs(ys,{children:[Kt,xs]}),t[196]=Kt,t[197]=xs,t[198]=bs):bs=t[198];let Wt;t[199]!==q||t[200]!==he||t[201]!==nt||t[202]!==e?(Wt=q!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(Bt,{value:he,onChange:Vt=>ke(Vt.target.value),placeholder:e(q==="rename"?"sidebarFilesTree.dialog.rename.placeholder":"sidebarFilesTree.dialog.namePlaceholder"),onKeyDown:Vt=>{Vt.key==="Enter"&&nt()},autoFocus:!0})}),t[199]=q,t[200]=he,t[201]=nt,t[202]=e,t[203]=Wt):Wt=t[203];let We;t[204]===Symbol.for("react.memo_cache_sentinel")?(We=()=>J(null),t[204]=We):We=t[204];let St;t[205]!==e?(St=e("sidebarFilesTree.dialog.cancel"),t[205]=e,t[206]=St):St=t[206];let qt;t[207]!==oe||t[208]!==St?(qt=s.jsx(be,{variant:"outline",onClick:We,disabled:oe,children:St}),t[207]=oe,t[208]=St,t[209]=qt):qt=t[209];const wt=q==="delete"?"destructive":"default";let es;t[210]!==nt?(es=()=>{nt()},t[210]=nt,t[211]=es):es=t[211];let ds;t[212]!==q||t[213]!==he||t[214]!==oe?(ds=oe||q!=="delete"&&!he.trim(),t[212]=q,t[213]=he,t[214]=oe,t[215]=ds):ds=t[215];let Ms;t[216]!==q||t[217]!==oe||t[218]!==e?(Ms=oe?s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}):e(q==="delete"?"sidebarFilesTree.dialog.delete.confirm":"sidebarFilesTree.dialog.confirm"),t[216]=q,t[217]=oe,t[218]=e,t[219]=Ms):Ms=t[219];let as;t[220]!==wt||t[221]!==es||t[222]!==ds||t[223]!==Ms?(as=s.jsx(be,{variant:wt,onClick:es,disabled:ds,children:Ms}),t[220]=wt,t[221]=es,t[222]=ds,t[223]=Ms,t[224]=as):as=t[224];let $s;t[225]!==qt||t[226]!==as?($s=s.jsxs(Vs,{children:[qt,as]}),t[225]=qt,t[226]=as,t[227]=$s):$s=t[227];let Ls;t[228]!==bs||t[229]!==Wt||t[230]!==$s?(Ls=s.jsxs(ms,{children:[bs,Wt,$s]}),t[228]=bs,t[229]=Wt,t[230]=$s,t[231]=Ls):Ls=t[231];let ln;t[232]!==Rt||t[233]!==Ls?(ln=s.jsx(ps,{open:Rt,onOpenChange:kt,children:Ls}),t[232]=Rt,t[233]=Ls,t[234]=ln):ln=t[234];let Xs;return t[235]!==He||t[236]!==ze||t[237]!==yt||t[238]!==ln?(Xs=s.jsxs("section",{className:He,children:[ze,yt,ln]}),t[235]=He,t[236]=ze,t[237]=yt,t[238]=ln,t[239]=Xs):Xs=t[239],Xs};function gN(t){return t.searchFiles}function xN(t){return t.openContextFile}function bN(t){return t.setSelectedPath}function yN(t){return t.addOpenPath}function vN(t){return t.removeOpenPathsByPrefix}function wN(t){return t.toggleExpandedPath}function jN(t){return t.mode==="file"?t.targetPath:null}function NN(t){return typeof t=="string"&&t.length>0}function SN(t){return _n(t)}function kN(t){return t&&typeof t.name=="string"&&t.name.length>0}function CN(t){return{name:t.name,path:t.path,isDirectory:t.isDirectory}}function IN(t){return t.entries.map(CN)}function PN(t){return{name:t.name,path:t.path,isDirectory:t.isDirectory}}function AN(t){return t.map(PN)}function DN(t){return Object.keys(t).length===0?t:{}}function TN(t){return Object.keys(t).length===0?t:{}}function MN(t){return _n(t)}function EN(t,e){return t.split("/").length-e.split("/").length}function RN(t){return{name:t.name,path:_n(t.path),type:"file",extension:t.extension,relativePath:t.relativePath}}function FN(t,e){const n=st.c(6),{git:r}=Rn(),a=tn(ON);let i,o;n[0]!==t||n[1]!==a||n[2]!==r||n[3]!==e?(i=()=>{if(!t||!r||!e)return;a(t,r);const c=setInterval(()=>{typeof document<"u"&&document.hidden||a(t,r)},1e4);return()=>clearInterval(c)},o=[t,r,e,a],n[0]=t,n[1]=a,n[2]=r,n[3]=e,n[4]=i,n[5]=o):(i=n[4],o=n[5]),l.useEffect(i,o)}function ON(t){return t.ensureStatus}const LN=()=>{const t=st.c(17),e=Ps(_N),n=Ps(BN),r=zs(zN),a=tn(VN);let i;e:{if(e){let h;t[0]!==e||t[1]!==n?(h=n.find(v=>v.id===e)??n[0]??null,t[0]=e,t[1]=n,t[2]=h):h=t[2],i=h;break e}i=n[0]??null}const o=i;let c;e:{if(!o){c=null;break e}let h;t[3]!==o.id||t[4]!==o.path?(h={id:o.id,path:o.path},t[3]=o.id,t[4]=o.path,t[5]=h):h=t[5],c=h}const d=c;let p;e:{if(!o){p=null;break e}let h;t[6]!==o.label||t[7]!==o.path||t[8]!==r?(h=o.label?.trim()||Oa(o.path,r)||o.path,t[6]=o.label,t[7]=o.path,t[8]=r,t[9]=h):h=t[9],p=h}const m=p;let u;e:{if(!o){u=!1;break e}let h;t[10]!==o.path||t[11]!==a?(h=a.get(o.path)?.isGitRepo,t[10]=o.path,t[11]=a,t[12]=h):h=t[12],u=h===!0}const f=u;let b;return t[13]!==f||t[14]!==m||t[15]!==d?(b=s.jsx("div",{className:"h-full min-h-0 overflow-auto bg-sidebar",children:s.jsx(Iw,{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=st.c(38),{t:e}=dt(),n=Re(UN),r=Re(WN),a=Re(KN),i=Zr();FN(i,a);let o;t[0]!==e?(o=e("layout.rightSidebar.git"),t[0]=e,t[1]=o):o=t[1];let c;t[2]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(D,{name:"git-branch",className:"h-3.5 w-3.5"}),t[2]=c):c=t[2];let d;t[3]!==o?(d={id:"git",label:o,icon:c},t[3]=o,t[4]=d):d=t[4];let p;t[5]!==e?(p=e("layout.rightSidebar.files"),t[5]=e,t[6]=p):p=t[6];let m;t[7]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(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:"booklet",className:"h-3.5 w-3.5"}),t[12]=b):b=t[12];let h;t[13]!==f?(h={id:"context",label:f,icon:b},t[13]=f,t[14]=h):h=t[14];let v;t[15]!==d||t[16]!==u||t[17]!==h?(v=[d,u,h],t[15]=d,t[16]=u,t[17]=h,t[18]=v):v=t[18];const x=v;let g;t[19]!==r?(g=I=>r(I),t[19]=r,t[20]=g):g=t[20];let w;t[21]!==n||t[22]!==g||t[23]!==x?(w=s.jsx("div",{className:"h-9 bg-sidebar pt-1 px-2",children:s.jsx($r,{items:x,activeId:n,onSelect:g,layoutMode:"fit",variant:"active-pill",className:"h-full"})}),t[21]=n,t[22]=g,t[23]=x,t[24]=w):w=t[24];let y;t[25]!==n?(y=n==="git"&&s.jsx(Gh,{}),t[25]=n,t[26]=y):y=t[26];let C;t[27]!==n?(C=n==="files"&&s.jsx(hN,{}),t[27]=n,t[28]=C):C=t[28];let k;t[29]!==n?(k=n==="context"&&s.jsx(LN,{}),t[29]=n,t[30]=k):k=t[30];let j;t[31]!==y||t[32]!==C||t[33]!==k?(j=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]=j):j=t[34];let S;return t[35]!==w||t[36]!==j?(S=s.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden bg-sidebar",children:[w,j]}),t[35]=w,t[36]=j,t[37]=S):S=t[37],S};function _N(t){return t.activeProjectId}function BN(t){return t.projects}function zN(t){return t.homeDirectory}function VN(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,od=15e3,Rm=500,GN=t=>t<=6?t:t<=12?6:t<=25?4:2,Yh=l.memo(()=>{const t=st.c(4),{t:e}=dt();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}),Qh={"?":{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=Qh.M,Yo=[{value:"single",labelKey:"diffView.mode.single.label",descriptionKey:"diffView.mode.single.description"},{value:"stacked",labelKey:"diffView.mode.stacked.label",descriptionKey:"diffView.mode.stacked.description"}],JN=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"},Xh=t=>{const e=JN(t);return Qh[e]??qN},YN=t=>{const{index:e,working_dir:n}=t;return e==="A"||n==="A"||e==="?"||n==="?"},QN=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),XN=(t,e)=>{const n=t.replace(/\\/g,"/").replace(/\/+$/g,""),r=e.replace(/\\/g,"/");if(QN(r))return r;const a=r.replace(/^\/+/,"");return n?`${n}/${a}`:a},Fm=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),Om=(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},ZN=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},yl=(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]})},e2=l.memo(t=>{const e=st.c(29),{changedFiles:n,selectedFile:r,selectedFileEntry:a,onSelectFile:i,isMobile:o,showModeSelector:c,mode:d,onModeChange:p}=t,m=c===void 0?!1:c,{t:u}=dt();let f;e[0]!==o?(f=S=>{if(!o)return S;const I=S.lastIndexOf("/");return I>=0?S.slice(I+1):S},e[0]=o,e[1]=f):f=e[1];const b=f;if(n.length===0)return null;let h;e[2]!==b||e[3]!==a||e[4]!==u?(h=a?s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[s.jsx(jr,{filePath:a.path,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",children:b(a.path)}),yl(a.insertions,a.deletions)]}):s.jsx("span",{className:"text-muted-foreground",children:u("diffView.selector.selectFile")}),e[2]=b,e[3]=a,e[4]=u,e[5]=h):h=e[5];let v;e[6]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx(D,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[6]=v):v=e[6];let x;e[7]!==h?(x=s.jsx(As,{asChild:!0,children:s.jsxs("button",{className:"flex h-7 items-center gap-2 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground outline-none hover:bg-interactive-hover hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring",children:[h,v]})}),e[7]=h,e[8]=x):x=e[8];let g;e[9]!==d||e[10]!==p||e[11]!==m||e[12]!==u?(g=m&&d&&p?s.jsxs(s.Fragment,{children:[s.jsx(Vf,{className:"typography-meta text-muted-foreground",children:u("diffView.selector.viewMode")}),s.jsx(ll,{value:d,onValueChange:S=>p(S),children:Yo.map(S=>s.jsx(cl,{value:S.value,className:"items-center",children:s.jsx("span",{className:"typography-meta text-foreground",children:u(S.labelKey)})},S.value))}),s.jsx(Gn,{})]}):null,e[9]=d,e[10]=p,e[11]=m,e[12]=u,e[13]=g):g=e[13];const w=r??"";let y;if(e[14]!==n||e[15]!==b){let S;e[17]!==b?(S=I=>s.jsx(cl,{value:I.path,children:s.jsxs("div",{className:"flex w-full min-w-0 items-center gap-3",children:[s.jsx(jr,{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:yl(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]!==w||e[21]!==y?(C=s.jsx(ll,{value:w,onValueChange:i,children:y}),e[19]=i,e[20]=w,e[21]=y,e[22]=C):C=e[22];let k;e[23]!==g||e[24]!==C?(k=s.jsxs(Ds,{className:"max-h-[70vh] min-w-[320px] overflow-y-auto",children:[g,C]}),e[23]=g,e[24]=C,e[25]=k):k=e[25];let j;return e[26]!==k||e[27]!==x?(j=s.jsxs(Ts,{children:[x,k]}),e[26]=k,e[27]=x,e[28]=j):j=e[28],j}),t2=l.memo(t=>{const e=st.c(31),{mode:n,onModeChange:r}=t,{t:a}=dt();let i,o,c,d,p,m;if(e[0]!==n||e[1]!==a){const y=Yo.find(C=>C.value===n)??Yo[0];o=Ts,i=As,m=!0,p="flex h-7 items-center gap-2 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground outline-none hover:bg-interactive-hover hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring",c="min-w-0 truncate typography-meta",d=a(y.labelKey),e[0]=n,e[1]=a,e[2]=i,e[3]=o,e[4]=c,e[5]=d,e[6]=p,e[7]=m}else i=e[2],o=e[3],c=e[4],d=e[5],p=e[6],m=e[7];let u;e[8]!==c||e[9]!==d?(u=s.jsx("span",{className:c,children:d}),e[8]=c,e[9]=d,e[10]=u):u=e[10];let f;e[11]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx(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 h;e[15]!==i||e[16]!==m||e[17]!==b?(h=s.jsx(i,{asChild:m,children:b}),e[15]=i,e[16]=m,e[17]=b,e[18]=h):h=e[18];let v;e[19]!==r?(v=y=>r(y),e[19]=r,e[20]=v):v=e[20];let x;e[21]!==a?(x=Yo.map(y=>s.jsx(cl,{value:y.value,children:s.jsx("span",{className:"typography-meta text-foreground",children:a(y.labelKey)})},y.value)),e[21]=a,e[22]=x):x=e[22];let g;e[23]!==n||e[24]!==x||e[25]!==v?(g=s.jsx(Ds,{className:"min-w-[140px]",children:s.jsx(ll,{value:n,onValueChange:v,children:x})}),e[23]=n,e[24]=x,e[25]=v,e[26]=g):g=e[26];let w;return e[27]!==o||e[28]!==g||e[29]!==h?(w=s.jsxs(o,{children:[h,g]}),e[27]=o,e[28]=g,e[29]=h,e[30]=w):w=e[30],w}),s2=l.memo(t=>{const e=st.c(11),{changedFiles:n,selectedFile:r,onSelectFile:a}=t,{t:i}=dt();if(n.length===0)return null;let o;if(e[0]!==n||e[1]!==a||e[2]!==r||e[3]!==i){let d;e[5]!==a||e[6]!==r||e[7]!==i?(d=p=>{const m=Xh(p),u=r===p.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>a(p.path),className:xe("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left transition-colors",u?"bg-interactive-selection text-interactive-selection-foreground":"text-muted-foreground hover:bg-interactive-hover hover:text-foreground"),children:[s.jsx(jr,{filePath:p.path,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:{color:m.color},title:i(m.descriptionKey),"aria-label":i(m.descriptionKey),children:m.code}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},title:p.path,children:p.path}),yl(p.insertions,p.deletions)]})},p.path)},e[5]=a,e[6]=r,e[7]=i,e[8]=d):d=e[8],o=n.map(d),e[0]=n,e[1]=a,e[2]=r,e[3]=i,e[4]=o}else o=e[4];let c;return e[9]!==o?(c=s.jsx(Ns,{outerClassName:"flex-1 min-h-0",className:"px-2 py-2",children:s.jsx("ul",{className:"flex flex-col gap-1",children:o})}),e[9]=o,e[10]=c):c=e[10],c}),n2=l.memo(t=>{const e=st.c(21),{filePath:n,diff:r,isVisible:a,renderSideBySide:i}=t,{t:o}=dt(),c=r.original.length>0,d=r.modified.length>0;if(!a){let v;return e[0]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx("div",{className:"absolute inset-0 hidden"}),e[0]=v):v=e[0],v}const p=i?"flex flex-row gap-6 items-start justify-center h-full":"flex flex-col gap-4 items-center",m=i?"flex flex-col items-center gap-2 flex-1 min-w-0 h-full":"flex flex-col items-center gap-2";let u;e[1]===Symbol.for("react.memo_cache_sentinel")?(u={contain:"size layout"},e[1]=u):u=e[1];let f;e[2]!==r.original||e[3]!==n||e[4]!==c||e[5]!==m||e[6]!==i||e[7]!==o?(f=c&&s.jsxs("div",{className:m,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:o("diffView.image.original")}),s.jsx("img",{src:r.original,alt:o("diffView.image.originalAlt",{path:n}),className:i?"max-w-full max-h-[calc(100%-2rem)] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[2]=r.original,e[3]=n,e[4]=c,e[5]=m,e[6]=i,e[7]=o,e[8]=f):f=e[8];let b;e[9]!==r.modified||e[10]!==n||e[11]!==d||e[12]!==c||e[13]!==m||e[14]!==i||e[15]!==o?(b=d&&s.jsxs("div",{className:m,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:o(c?"diffView.image.modified":"diffView.image.new")}),s.jsx("img",{src:r.modified,alt:o("diffView.image.modifiedAlt",{path:n}),className:i?"max-w-full max-h-[calc(100%-2rem)] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[9]=r.modified,e[10]=n,e[11]=d,e[12]=c,e[13]=m,e[14]=i,e[15]=o,e[16]=b):b=e[16];let h;return e[17]!==p||e[18]!==f||e[19]!==b?(h=s.jsx("div",{className:"absolute inset-0 overflow-auto p-4",style:u,children:s.jsxs("div",{className:p,children:[f,b]})}),e[17]=p,e[18]=f,e[19]=b,e[20]=h):h=e[20],h}),r2=l.memo(t=>{const e=st.c(20),{filePath:n,diff:r,renderSideBySide:a}=t,{t:i}=dt(),o=r.original.length>0,c=r.modified.length>0,d=a?"flex flex-row gap-6 items-start justify-center":"flex flex-col gap-4 items-center",p=a?"flex flex-col items-center gap-2 flex-1 min-w-0":"flex flex-col items-center gap-2";let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m={contain:"layout"},e[0]=m):m=e[0];let u;e[1]!==r.original||e[2]!==n||e[3]!==o||e[4]!==p||e[5]!==a||e[6]!==i?(u=o&&s.jsxs("div",{className:p,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:i("diffView.image.original")}),s.jsx("img",{src:r.original,alt:i("diffView.image.originalAlt",{path:n}),className:a?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[1]=r.original,e[2]=n,e[3]=o,e[4]=p,e[5]=a,e[6]=i,e[7]=u):u=e[7];let f;e[8]!==r.modified||e[9]!==n||e[10]!==c||e[11]!==o||e[12]!==p||e[13]!==a||e[14]!==i?(f=c&&s.jsxs("div",{className:p,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:i(o?"diffView.image.modified":"diffView.image.new")}),s.jsx("img",{src:r.modified,alt:i("diffView.image.modifiedAlt",{path:n}),className:a?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[8]=r.modified,e[9]=n,e[10]=c,e[11]=o,e[12]=p,e[13]=a,e[14]=i,e[15]=f):f=e[15];let b;return e[16]!==d||e[17]!==u||e[18]!==f?(b=s.jsx("div",{className:"w-full overflow-auto p-4",style:m,children:s.jsxs("div",{className:d,children:[u,f]})}),e[16]=d,e[17]=u,e[18]=f,e[19]=b):b=e[19],b}),a2=l.memo(t=>{const e=st.c(15),{filePath:n,diff:r,renderSideBySide:a,wrapLines:i}=t;let o;e[0]!==n?(o=ui(n)||"text",e[0]=n,e[1]=o):o=e[1];const c=o;if(r.isBinary){let m;return e[2]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(Yh,{}),e[2]=m):m=e[2],m}if(mi(n)){let m;return e[3]!==r||e[4]!==n||e[5]!==a?(m=s.jsx(r2,{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(Hd,{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}),i2=l.memo(t=>{const e=st.c(15),{filePath:n,diff:r,isVisible:a,renderSideBySide:i,wrapLines:o}=t;let c;e[0]!==n?(c=ui(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(Yh,{}),e[2]=m):m=e[2],m}if(!a)return null;if(mi(n)){let m;return e[3]!==r||e[4]!==n||e[5]!==a||e[6]!==i?(m=s.jsx(n2,{filePath:n,diff:r,isVisible:a,renderSideBySide:i}),e[3]=r,e[4]=n,e[5]=a,e[6]=i,e[7]=m):m=e[7],m}let p;return e[8]!==r.modified||e[9]!==r.original||e[10]!==n||e[11]!==d||e[12]!==i||e[13]!==o?(p=s.jsx(Ns,{outerClassName:"absolute inset-0",disableHorizontal:!1,observeMutations:!1,preventOverscroll:!0,"data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:s.jsx(Hd,{original:r.original,modified:r.modified,language:d,fileName:n,renderSideBySide:i,wrapLines:o,layout:"inline"})}),e[8]=r.modified,e[9]=r.original,e[10]=n,e[11]=d,e[12]=i,e[13]=o,e[14]=p):p=e[14],p}),o2=l.memo(t=>{const e=st.c(122),{directory:n,file:r,layout:a,wrapLines:i,scrollRootRef:o,isSelected:c,onSelect:d,registerSectionRef:p,defaultCollapsed:m,expandRequestPath:u,expandRequestNonce:f,showOpenInEditorAction:b,isOpeningInEditor:h,onOpenInEditor:v}=t,x=m===void 0?!1:m,g=u===void 0?null:u,w=f===void 0?0:f,y=b===void 0?!1:b,C=h===void 0?!1:h,{t:k}=dt(),{git:j}=Rn();let S;e[0]!==n||e[1]!==r.path?(S=Xe=>Xe.directories.get(n)?.diffCache.get(r.path)??null,e[0]=n,e[1]=r.path,e[2]=S):S=e[2];const I=tn(S),M=tn(c2),P=Re(d2),[A,N]=l.useState(!x),[E,T]=l.useState(!1),[R,V]=l.useState(0),[_,U]=l.useState(null),[B,z]=l.useState(!1),[K,F]=l.useState(!1),G=l.useRef(null),Q=l.useRef(null);let te;e[3]!==r?(te=Xh(r),e[3]=r,e[4]=te):te=e[4];const Z=te,fe=a==="side-by-side";let ue;e:{if(!I){ue=null;break e}let Xe;e[5]!==I.isBinary||e[6]!==I.modified||e[7]!==I.original?(Xe={original:I.original,modified:I.modified,isBinary:I.isBinary},e[5]=I.isBinary,e[6]=I.modified,e[7]=I.original,e[8]=Xe):Xe=e[8],ue=Xe}const W=ue;let q;e[9]!==r.path||e[10]!==p?(q=Xe=>{Q.current=Xe,p(r.path,Xe)},e[9]=r.path,e[10]=p,e[11]=q):q=e[11];const J=q;let ne;e[12]===Symbol.for("react.memo_cache_sentinel")?(ne=Xe=>{N(Xe),Xe&&T(!0)},e[12]=ne):ne=e[12];const ee=ne;let he;e[13]!==r.path||e[14]!==d?(he=()=>{d(r.path)},e[13]=r.path,e[14]=d,e[15]=he):he=e[15];const ke=he;let oe,ge;e[16]!==E||e[17]!==A||e[18]!==o?(oe=()=>{if(!A||E)return;const Xe=Q.current;if(!Xe)return;if(!o.current||typeof IntersectionObserver>"u"){T(!0);return}const ut=new IntersectionObserver(rt=>{rt.some(u2)&&(T(!0),ut.disconnect())},{root:o.current,rootMargin:"200px 0px",threshold:.1});return ut.observe(Xe),()=>ut.disconnect()},ge=[E,A,o],e[16]=E,e[17]=A,e[18]=o,e[19]=oe,e[20]=ge):(oe=e[19],ge=e[20]),l.useEffect(oe,ge);let me,ye;e[21]!==w||e[22]!==g||e[23]!==r.path?(me=()=>{w<=0||g!==r.path||(N(!0),T(!0))},ye=[w,g,r.path],e[21]=w,e[22]=g,e[23]=r.path,e[24]=me,e[25]=ye):(me=e[24],ye=e[25]),l.useEffect(me,ye);let ie,ve;e[26]!==W||e[27]!==R||e[28]!==n||e[29]!==r.path||e[30]!==j||e[31]!==E||e[32]!==A||e[33]!==M?(ie=()=>{if(!A||!E)return;if(!n||W){G.current=null,z(!1);return}const Xe=`${n}::${r.path}::${R}`;if(G.current===Xe)return;G.current=Xe,U(null),z(!0);let ut=!1;const rt=j.getGitFileDiff(n,{path:r.path}),it=new Promise(m2);return Promise.race([rt,it]).then(nt=>{ut||(M(n,r.path,{original:nt.original??"",modified:nt.modified??"",isBinary:nt.isBinary}),z(!1))}).catch(nt=>{if(ut)return;const Ne=nt instanceof Error?nt.message:String(nt);U(Ne),z(!1)}),()=>{ut=!0,G.current===Xe&&(G.current=null)}},ve=[n,W,R,r.path,j,E,A,M],e[26]=W,e[27]=R,e[28]=n,e[29]=r.path,e[30]=j,e[31]=E,e[32]=A,e[33]=M,e[34]=ie,e[35]=ve):(ie=e[34],ve=e[35]),l.useEffect(ie,ve);let X;e[36]!==ke||e[37]!==A?(X=()=>{ee(!A),ke()},e[36]=ke,e[37]=A,e[38]=X):X=e[38];const Se=X,Ae=A?"rounded-b-none":"rounded-b-xl",pe=c?"ring-1 ring-inset ring-[var(--interactive-selection)]":null;let we;e[39]!==Ae||e[40]!==pe?(we=xe("group/header relative flex w-full items-center gap-2 px-3 py-1.5 rounded-t-xl border border-border/60 overflow-hidden","bg-background",Ae,"text-muted-foreground hover:text-foreground",pe),e[39]=Ae,e[40]=pe,e[41]=we):we=e[41];let Ie;e[42]===Symbol.for("react.memo_cache_sentinel")?(Ie=s.jsx("div",{className:"absolute inset-0 pointer-events-none group-hover/header:bg-interactive-hover"}),e[42]=Ie):Ie=e[42];let Y;e[43]!==A?(Y=s.jsx("span",{className:"flex size-5 items-center justify-center opacity-70 group-hover/header:opacity-100",children:A?s.jsx(D,{name:"arrow-down-s",className:"size-4"}):s.jsx(D,{name:"arrow-right-s",className:"size-4"})}),e[43]=A,e[44]=Y):Y=e[44];let re;e[45]!==Z.color?(re={color:Z.color},e[45]=Z.color,e[46]=re):re=e[46];let Pe;e[47]!==Z.descriptionKey||e[48]!==k?(Pe=k(Z.descriptionKey),e[47]=Z.descriptionKey,e[48]=k,e[49]=Pe):Pe=e[49];let ce;e[50]!==Z.descriptionKey||e[51]!==k?(ce=k(Z.descriptionKey),e[50]=Z.descriptionKey,e[51]=k,e[52]=ce):ce=e[52];let Ce;e[53]!==Z.code||e[54]!==re||e[55]!==Pe||e[56]!==ce?(Ce=s.jsx("span",{className:"typography-micro font-semibold leading-none w-4 text-center uppercase",style:re,title:Pe,"aria-label":ce,children:Z.code}),e[53]=Z.code,e[54]=re,e[55]=Pe,e[56]=ce,e[57]=Ce):Ce=e[57];const Te=r.path;let $e;e[58]!==r.path?($e=s.jsx(jr,{filePath:r.path,className:"h-3.5 w-3.5 flex-shrink-0 align-middle"}),e[58]=r.path,e[59]=$e):$e=e[59];let De;if(e[60]!==r.path){e:{const Xe=r.path.lastIndexOf("/");if(Xe===-1){let qe;e[62]===Symbol.for("react.memo_cache_sentinel")?(qe={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},e[62]=qe):qe=e[62],De=s.jsx("span",{className:"block min-w-0 truncate typography-ui-label text-foreground",style:qe,children:r.path});break e}const ut=r.path.slice(0,Xe),rt=r.path.slice(Xe+1);let it;e[63]===Symbol.for("react.memo_cache_sentinel")?(it={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},e[63]=it):it=e[63];let nt;e[64]!==ut?(nt=s.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:it,children:ut}),e[64]=ut,e[65]=nt):nt=e[65];let Ne;e[66]===Symbol.for("react.memo_cache_sentinel")?(Ne=s.jsx("span",{className:"text-muted-foreground",children:"/"}),e[66]=Ne):Ne=e[66];let Ke;e[67]!==rt?(Ke=s.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[Ne,s.jsx("span",{className:"text-foreground",children:rt})]}),e[67]=rt,e[68]=Ke):Ke=e[68];let Ve;e[69]!==nt||e[70]!==Ke?(Ve=s.jsxs("span",{className:"flex min-w-0 items-baseline overflow-hidden",children:[nt,Ke]}),e[69]=nt,e[70]=Ke,e[71]=Ve):Ve=e[71],De=Ve}e[60]=r.path,e[61]=De}else De=e[61];let de;e[72]!==$e||e[73]!==De?(de=s.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[$e,De]}),e[72]=$e,e[73]=De,e[74]=de):de=e[74];let O;e[75]!==r.path||e[76]!==de?(O=s.jsx("span",{className:"min-w-0 flex-1 overflow-hidden typography-ui-label",title:Te,children:de}),e[75]=r.path,e[76]=de,e[77]=O):O=e[77];let L;e[78]!==Y||e[79]!==Ce||e[80]!==O?(L=s.jsxs("div",{className:"relative flex min-w-0 flex-1 items-center gap-2",children:[Y,Ce,O]}),e[78]=Y,e[79]=Ce,e[80]=O,e[81]=L):L=e[81];let $;e[82]!==r.deletions||e[83]!==r.insertions?($=yl(r.insertions,r.deletions),e[82]=r.deletions,e[83]=r.insertions,e[84]=$):$=e[84];let je;e[85]!==W||e[86]!==r.path||e[87]!==C||e[88]!==v||e[89]!==y||e[90]!==k?(je=y&&v?s.jsx(be,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",title:k("diffView.actions.openFileInEditorAtChange"),onClick:Xe=>{Xe.stopPropagation(),v(r.path,W)},disabled:C,children:C?s.jsx(D,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(D,{name:"edit",className:"size-3.5"})}):null,e[85]=W,e[86]=r.path,e[87]=C,e[88]=v,e[89]=y,e[90]=k,e[91]=je):je=e[91];const ae=fe?"side-by-side":"unified";let _e;e[92]!==r.path||e[93]!==P?(_e=Xe=>{const ut=Xe==="side-by-side"?"side-by-side":"inline";P(r.path,ut)},e[92]=r.path,e[93]=P,e[94]=_e):_e=e[94];let le;e[95]!==ae||e[96]!==_e?(le=s.jsx(eh,{mode:ae,onModeChange:_e,className:"opacity-70"}),e[95]=ae,e[96]=_e,e[97]=le):le=e[97];let Me;e[98]!==$||e[99]!==je||e[100]!==le?(Me=s.jsxs("div",{className:"relative flex items-center gap-2",children:[$,je,le]}),e[98]=$,e[99]=je,e[100]=le,e[101]=Me):Me=e[101];let Ge;e[102]!==Se||e[103]!==we||e[104]!==L||e[105]!==Me?(Ge=s.jsx("div",{className:"sticky top-0 z-10 bg-background",children:s.jsxs("button",{type:"button",onClick:Se,className:we,children:[Ie,L,Me]})}),e[102]=Se,e[103]=we,e[104]=L,e[105]=Me,e[106]=Ge):Ge=e[106];let at;e[107]!==W||e[108]!==_||e[109]!==r.deletions||e[110]!==r.insertions||e[111]!==r.path||e[112]!==K||e[113]!==A||e[114]!==B||e[115]!==fe||e[116]!==i?(at=A&&s.jsxs("div",{className:"relative border border-t-0 border-border/60 bg-background rounded-b-xl overflow-hidden",children:[_?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:_}),s.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>V(p2),children:"Retry"})]}):null,B&&!W&&!_?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,W&&!K&&r.insertions+r.deletions>Rm?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:()=>F(!0),children:"Render anyway"})]}):null,W&&(K||r.insertions+r.deletions<=Rm)?s.jsx(a2,{filePath:r.path,diff:W,renderSideBySide:fe,wrapLines:i}):null]}),e[107]=W,e[108]=_,e[109]=r.deletions,e[110]=r.insertions,e[111]=r.path,e[112]=K,e[113]=A,e[114]=B,e[115]=fe,e[116]=i,e[117]=at):at=e[117];let Ye;return e[118]!==J||e[119]!==Ge||e[120]!==at?(Ye=s.jsxs("div",{ref:J,className:"scroll-mt-4",children:[Ge,at]}),e[118]=J,e[119]=Ge,e[120]=at,e[121]=Ye):Ye=e[121],Ye}),Zh=({hideStackedFileSidebar:t=!1,stackedDefaultCollapsedAll:e=!1,hideFileSelector:n=!1,pinSelectedFileHeaderToTopOnNavigate:r=!1,showOpenInEditorAction:a=!1})=>{const{t:i}=dt(),{git:o,files:c}=Rn(),d=Zr(),{screenWidth:p,isMobile:m}=nn(),u=Td(d??null),f=Dl(d??null),b=Ed(d??null),h=tn(L=>L.setActiveDirectory),v=tn(L=>L.ensureStatus),x=tn(L=>L.fetchStatus),g=tn(L=>L.setDiff),[w,y]=l.useState(null),[C,k]=l.useState(null),[j,S]=l.useState(0),[I,M]=l.useState(null),[P,A]=l.useState(0),[N,E]=l.useState(null),T=l.useRef(null),R=Re(L=>L.pendingDiffFile),V=Re(L=>L.setPendingDiffFile),_=Re(L=>L.diffLayoutPreference),U=Re(L=>L.diffFileLayout),B=Re(L=>L.setDiffFileLayout),z=Re(L=>L.diffWrapLines),K=Re(L=>L.setDiffWrapLines),F=Re(L=>L.diffViewMode),G=Re(L=>L.setDiffViewMode),Q=Re(L=>L.openContextFileAtLine),te=z,Z=F==="stacked",fe=m||p<=768,ue=!t&&!fe&&p>=1024,W=l.useRef(null),q=l.useRef(new Map),J=l.useRef(null),ne=l.useRef(null),ee=l.useRef(!1);l.useEffect(()=>{if(!r||!Z||!I)return;const L=W.current;if(!L)return;let $=null,je=!1,ae=0;const _e=Date.now()+1200;let le=0;const Me=()=>{je||(je=!0,M(null))},Ge=()=>{Me()},at=()=>{if(le>0){le-=1;return}Me()};window.addEventListener("wheel",Ge,{passive:!0,capture:!0}),window.addEventListener("touchstart",Ge,{passive:!0,capture:!0}),window.addEventListener("pointerdown",Ge,{capture:!0}),window.addEventListener("keydown",Ge,{capture:!0}),L.addEventListener("scroll",at,{passive:!0});const Ye=()=>{if(je||Date.now()>_e){Me();return}const Xe=W.current,ut=q.current.get(I);if(!Xe||!ut){Me();return}const rt=Xe.getBoundingClientRect(),nt=ut.getBoundingClientRect().top-rt.top;if(Math.abs(nt)<=1){if(ae+=1,ae>=2){Me();return}}else{ae=0;const Ne=Math.max(0,Xe.scrollHeight-Xe.clientHeight),Ke=Math.min(Ne,Math.max(0,Xe.scrollTop+nt));if(Math.abs(Ke-Xe.scrollTop)<=.5){Me();return}le+=1,Xe.scrollTop=Ke}$=window.requestAnimationFrame(Ye)};return $=window.requestAnimationFrame(Ye),()=>{je=!0,$!==null&&window.cancelAnimationFrame($),window.removeEventListener("wheel",Ge,!0),window.removeEventListener("touchstart",Ge,!0),window.removeEventListener("pointerdown",Ge,!0),window.removeEventListener("keydown",Ge,!0),L.removeEventListener("scroll",at)}},[Z,r,I]);const he=l.useMemo(()=>{if(!f?.files)return[];const L=f.diffStats??{};return f.files.map($=>({...$,insertions:L[$.path]?.insertions??0,deletions:L[$.path]?.deletions??0,isNew:YN($)})).sort(($,je)=>$.path.localeCompare(je.path))},[f]),ke=l.useMemo(()=>w?he.find(L=>L.path===w)??null:null,[he,w]),oe=l.useCallback(L=>{const $=U[L.path];if($)return $;if(_==="inline")return"inline";if(_==="side-by-side")return"side-by-side";const je=p<HN;return L.isNew||je?"inline":"side-by-side"},[U,_,p]),ge=l.useMemo(()=>ke?oe(ke):null,[oe,ke]);l.useEffect(()=>{d&&(h(d),v(d,o))},[d,h,v,o]),l.useEffect(()=>{if(d)return Nr.onGitRefreshHint(L=>{Fm(L.directory)===Fm(d)&&x(d,o)})},[d,x,o]),l.useEffect(()=>{R&&(y(R),V(null),Z&&(ee.current=!0,J.current=R,k(R),S(L=>L+1)))},[Z,R,V]),l.useEffect(()=>{!w&&!R&&he.length>0&&y(he[0].path)},[he,w,R]),l.useEffect(()=>{w&&he.length>0&&(he.some($=>$.path===w)||y(he[0]?.path??null))},[he,w]);const me=l.useCallback((L,$)=>{const je=q.current;$?je.set(L,$):je.delete(L)},[]),ye=l.useCallback(L=>{const $=q.current.get(L),je=W.current;if(!$||!je)return{ok:!1,aligned:!1,didMove:!1,atScrollLimit:!1,delta:0};const ae=je.getBoundingClientRect(),le=$.getBoundingClientRect().top-ae.top,Me=Math.max(0,je.scrollHeight-je.clientHeight),Ge=je.scrollTop+le,at=Math.min(Me,Math.max(0,Ge)),Ye=Math.abs(at-je.scrollTop)>.5;je.scrollTop=at;const Xe=Math.abs(le)<=1,ut=at<=.5||at>=Me-.5;return{ok:!0,aligned:Xe,didMove:Ye,atScrollLimit:ut,delta:le}},[]);l.useEffect(()=>{if(!Z){J.current=null,ee.current=!1,ne.current!==null&&(window.cancelAnimationFrame(ne.current),ne.current=null);return}if(!J.current)return;let $=0;const je=120;let ae=!1,_e=0,le=!1,Me=0;const Ge=Date.now()+2e3,at=()=>{le||(le=!0,window.removeEventListener("wheel",Xe,!0),window.removeEventListener("touchstart",Xe,!0),window.removeEventListener("pointerdown",Xe,!0),window.removeEventListener("keydown",Xe,!0),rt?.removeEventListener("scroll",ut))},Ye=()=>{ae||(ae=!0,at(),J.current=null,ee.current=!1,ne.current!==null&&(window.cancelAnimationFrame(ne.current),ne.current=null))},Xe=()=>{Ye()},ut=()=>{if(_e>0){_e-=1;return}Ye()},rt=W.current;window.addEventListener("wheel",Xe,{passive:!0,capture:!0}),window.addEventListener("touchstart",Xe,{passive:!0,capture:!0}),window.addEventListener("pointerdown",Xe,{capture:!0}),window.addEventListener("keydown",Xe,{capture:!0}),rt?.addEventListener("scroll",ut,{passive:!0});const it=()=>{if(Date.now()>Ge){Ye(),ne.current=null;return}if(ae){ne.current=null;return}const nt=J.current;if(!nt){Ye(),ne.current=null;return}_e+=1;const Ne=ye(nt);if(!Ne.ok){_e=Math.max(0,_e-1),$+=1,$<je?ne.current=window.requestAnimationFrame(it):(Ye(),ne.current=null);return}if(!Ne.aligned){if($+=1,Ne.didMove){if(Me=0,$<je){ne.current=window.requestAnimationFrame(it);return}}else if(Me+=1,Me<6&&(Ne.atScrollLimit||Math.abs(Ne.delta)>1)){ne.current=window.requestAnimationFrame(it);return}}r&&ee.current&&M(nt),Ye()};return ne.current=window.requestAnimationFrame(it),()=>{ae=!0,at(),ne.current!==null&&(window.cancelAnimationFrame(ne.current),ne.current=null)}},[Z,r,ye,w,j]);const ie=l.useCallback(L=>{y(L)},[]),ve=l.useCallback(L=>{if(ne.current!==null&&(window.cancelAnimationFrame(ne.current),ne.current=null),J.current=null,y(L),!Z){ee.current=!1;return}ee.current=!0,J.current=L,ye(L)},[Z,ye]),X=l.useCallback(L=>{G(L),L==="stacked"&&w&&(ye(w).aligned||(J.current=w))},[ye,w,G]),Se=l.useCallback(L=>{const $=L==="side-by-side"?"side-by-side":"inline";if(Z){he.forEach(je=>{B(je.path,$)});return}ke&&B(ke.path,$)},[he,Z,ke,B]),Ae=(ge??"side-by-side")==="side-by-side",pe=!n&&(!Z||!ue),we=tn(l.useCallback(L=>!d||!w?null:L.directories.get(d)?.diffCache.get(w)??null,[d,w])),Ie=l.useMemo(()=>we?{original:we.original,modified:we.modified,isBinary:we.isBinary}:null,[we]),[Y,re]=l.useState(null),Pe=l.useCallback(async(L,$)=>{if(!(!d||!L)){re(L);try{let je=null;if($&&!$.isBinary&&!mi(L)&&(je=Om($.original,$.modified)),je===null)try{const Ge=await o.getGitDiff(d,{path:L,contextLines:3});je=ZN(Ge.diff)}catch{je=null}let ae=$;if(je===null||!ae){const Ge=await o.getGitFileDiff(d,{path:L});ae={original:Ge.original??"",modified:Ge.modified??"",isBinary:Ge.isBinary},g(d,L,ae)}const _e=je??(ae.isBinary||mi(L)?1:Om(ae.original,ae.modified)),le=XN(d,L),Me=await Jd(c,le);if(!Me.ok){H.error(Yd(Me.reason));return}Q(d,le,_e,1)}finally{re(je=>je===L?null:je)}}},[d,c,o,Q,g]),ce=l.useCallback(async()=>{w&&await Pe(w,Ie)},[Pe,Ie,w]),Ce=!!(w&&Y===w),Te=!!we,$e=!Z&&!!w&&!Te;l.useEffect(()=>{if(Z)return;if(E(null),!d||!w){T.current=null;return}if(we){T.current=null;return}const L=`${d}::${w}::${P}`;if(T.current===L)return;T.current=L;let $=!1;const je=o.getGitFileDiff(d,{path:w}),ae=od,_e=new Promise((le,Me)=>{setTimeout(()=>Me(new Error(`Timed out after ${ae}ms`)),ae)});return Promise.race([je,_e]).then(le=>{$||g(d,w,{original:le.original??"",modified:le.modified??"",isBinary:le.isBinary})}).catch(le=>{if($)return;const Me=le instanceof Error?le.message:String(le);E(Me)}),()=>{$=!0,T.current===L&&(T.current=null)}},[d,Z,w,we,o,g,P]);const De=()=>!d||!w||!Ie?null:s.jsx(i2,{filePath:w,diff:Ie,isVisible:!0,renderSideBySide:Ae,wrapLines:te},w),de=()=>{if(!d)return null;const L=GN(he.length);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:i("diffView.section.files")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:he.length})]}),s.jsx(s2,{changedFiles:he,selectedFile:w,onSelectFile:ve})]}),s.jsx(Ns,{ref:W,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(($,je)=>s.jsx(o2,{directory:d,file:$,layout:oe($),wrapLines:te,scrollRootRef:W,isSelected:$.path===w,onSelect:ie,registerSectionRef:me,defaultCollapsed:e?!0:je>=L,expandRequestPath:C,expandRequestNonce:j,showOpenInEditorAction:a,isOpeningInEditor:Y===$.path,onOpenInEditor:(ae,_e)=>{Pe(ae,_e)}},$.path))})})]})},O=()=>d?b&&!f?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"}),i("diffView.state.loadingRepositoryStatus")]}):u===!1?s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:i("diffView.state.notGitRepository")}):he.length===0?s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:i("diffView.state.cleanWorkingTree")}):Z?de():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:[De(),$e&&!Te&&s.jsx("div",{className:"absolute inset-0 flex items-center justify-center gap-2 text-sm text-muted-foreground",children:N?s.jsxs("div",{className:"flex flex-col items-center gap-2",children:[s.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:i("diffView.state.failedToLoadDiff")}),s.jsx("div",{className:"typography-meta text-muted-foreground max-w-[32rem] text-center",children:N}),s.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>{E(null),A(L=>L+1)},children:i("diffView.actions.retry")})]}):s.jsxs(s.Fragment,{children:[s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}),i("diffView.state.loadingDiff")]})})]}):s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:i("diffView.state.selectSessionDirectory")});return s.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background",children:[s.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 bg-background",children:[!m&&s.jsxs("div",{className:"flex items-center gap-1 rounded-md px-2 py-1 text-muted-foreground shrink-0",children:[s.jsx(D,{name:"git-commit",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:b&&!f?i("diffView.state.loadingChanges"):he.length===1?i("diffView.summary.changedFilesSingle",{count:he.length}):i("diffView.summary.changedFilesPlural",{count:he.length})})]}),!fe&&s.jsx(t2,{mode:F,onModeChange:X}),pe&&s.jsx(e2,{changedFiles:he,selectedFile:w,selectedFileEntry:ke,onSelectFile:ve,isMobile:fe,showModeSelector:fe,mode:F,onModeChange:X}),s.jsx("div",{className:"flex-1"}),ke&&s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>K(!z),className:xe("h-5 w-5 p-0 transition-opacity",te?"text-foreground opacity-100":"text-muted-foreground opacity-60 hover:opacity-100"),title:i(te?"diffView.actions.disableLineWrap":"diffView.actions.enableLineWrap"),children:s.jsx(D,{name:"text-wrap",className:"size-4"})}),a&&ke&&!Z&&s.jsx(be,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",onClick:()=>{ce()},disabled:Ce,title:i("diffView.actions.openFileAtFirstChangedLine"),children:Ce?s.jsx(D,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(D,{name:"edit",className:"size-3.5"})}),ke&&ge&&s.jsx(eh,{mode:ge==="side-by-side"?"side-by-side":"unified",onModeChange:Se})]}),O()]})},l2=()=>{const t=st.c(6),{git:e}=Rn(),n=Zr(),r=tn(f2),a=tn(h2),i=Ab(n??null);let o,c;return t[0]!==n||t[1]!==a||t[2]!==e||t[3]!==r?(o=()=>{n&&(r(n),a(n,e))},c=[n,r,a,e],t[0]=n,t[1]=a,t[2]=e,t[3]=r,t[4]=o,t[5]=c):(o=t[4],c=t[5]),l.useEffect(o,c),i};function c2(t){return t.setDiff}function d2(t){return t.setDiffFileLayout}function u2(t){return t.isIntersecting}function m2(t,e){setTimeout(()=>e(new Error(`Timed out after ${od}ms`)),od)}function p2(t){return t+1}function f2(t){return t.setActiveDirectory}function h2(t){return t.ensureStatus}const g2=Object.freeze(Object.defineProperty({__proto__:null,DiffView:Zh,useDiffFileCount:l2},Symbol.toStringTag,{value:"Module"})),x2={next:"Next match",prev:"Previous match",select:"Select all matches",replace:"Replace",replaceAll:"Replace all",close:"Close"},b2={case:"Match case",re:"Regular expression",word:"Match whole word"};function y2(t){const e=t.querySelector(".cm-search");if(e){for(const[n,r]of Object.entries(x2)){const a=e.querySelector(`button[name="${n}"]`);a&&!a.title&&(a.title=r)}for(const[n,r]of Object.entries(b2)){const i=e.querySelector(`input[name="${n}"]`)?.parentElement;i&&!i.title&&(i.title=r)}}}const Lm=new yi,$m=new yi,_m=new yi,Bm=new yi,zm=new yi,Vm=new yi,Um=t=>t,xc=xx,v2=bx,w2=yx;class j2 extends vx{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 Wm=(t,e)=>!t||t.length===0?[]:gx.define({create(n){const r=new Rf,a=[...t].sort((i,o)=>i.afterLine-o.afterLine);for(const i of a){const o=n.doc.lines;if(i.afterLine>o)continue;const c=n.doc.line(i.afterLine);r.add(c.to,c.to,Ff.widget({widget:new j2(i.id,e),block:!0,side:1}))}return r.finish()},update(n,r){return n.map(r.changes)},provide:n=>Hn.decorations.from(n)}),Km=t=>{if(!t)return[];const e=Math.max(1,t.start),n=Math.max(e,t.end);return hx.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 Rf;for(let i=e;i<=n&&i<=r.state.doc.lines;i+=1){const o=r.state.doc.line(i);a.add(o.from,o.from,Ff.line({class:"oc-cm-selected-line"}))}return a.finish()}},{decorations:r=>r.decorations})};function ld({value:t,onChange:e,extensions:n,className:r,readOnly:a,lineNumbersConfig:i,highlightLines:o,onViewReady:c,onViewDestroy:d,blockWidgets:p,enableSearch:m,searchOpen:u,onSearchOpenChange:f}){const b=l.useRef(null),h=l.useRef(null),v=l.useRef(t),x=l.useRef(e),g=l.useRef(c),w=l.useRef(d),y=l.useRef(f),C=l.useRef(p),k=l.useRef(new Map),[j,S]=l.useState([]),I=l.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,T)=>{const R=A[T];return E.id===R.id&&E.content===R.content&&E.container===R.container})?N:A)},[]),M=l.useCallback(P=>{const A=b.current,N=P??h.current;if(!A||!N)return;const E=N.dom.querySelector(".cm-gutters"),T=E instanceof HTMLElement?E.getBoundingClientRect().width:0;A.style.setProperty("--oc-editor-gutter-width",`${T}px`)},[]);return l.useEffect(()=>{v.current=t},[t]),l.useEffect(()=>{x.current=e},[e]),l.useEffect(()=>{g.current=c,w.current=d},[c,d]),l.useEffect(()=>{y.current=f},[f]),l.useEffect(()=>{C.current=p,I(p)},[p,I]),l.useEffect(()=>{if(!b.current)return;const P=(()=>{if(typeof document>"u")return null;const N=document.querySelector('meta[name="csp-nonce"]')?.getAttribute("content");if(N)return N;const E=window.__OPENCHAMBER_CSP_NONCE__;return typeof E=="string"&&E.length>0?E:null})(),A=lx.create({doc:v.current,extensions:[...P?[Hn.cspNonce.of(P)]:[],cx({fixed:!0}),Lm.of(cu(i)),dx(),ux.of(" "),Ul.of([mx,...px,...fx]),Hn.updateListener.of(N=>{M(N.view),(N.viewportChanged||N.geometryChanged)&&I(C.current);const E=du(N.startState),T=du(N.state);if(E!==T&&y.current?.(T),!N.docChanged)return;const R=N.state.doc.toString();v.current=R,x.current(R),I(C.current)}),$m.of(Hn.editable.of(!a)),_m.of(n??[]),Bm.of(Km(o)),zm.of(Wm(p,k.current)),Vm.of(m?[uu({top:!0}),Ul.of(Um(mu))]:[])]});return h.current=new Hn({state:A,parent:b.current}),xc(h.current,h.current.state.doc.length,200),h.current.requestMeasure(),requestAnimationFrame(()=>{M(h.current),I(C.current)}),h.current&&g.current?.(h.current),()=>{w.current?.(),h.current?.destroy(),h.current=null,S([])}},[C,M,I]),l.useEffect(()=>{const P=h.current;P&&(P.dispatch({effects:[Lm.reconfigure(cu(i)),$m.reconfigure(Hn.editable.of(!a)),_m.reconfigure(n??[]),Bm.reconfigure(Km(o)),zm.reconfigure(Wm(p,k.current)),Vm.reconfigure(m?[uu({top:!0}),Ul.of(Um(mu))]:[])]}),xc(P,P.state.doc.length,200),P.requestMeasure(),requestAnimationFrame(()=>{M(P),I(C.current)}))},[n,o,i,a,p,m,M,I]),l.useEffect(()=>{const P=h.current;!P||m===!1||(u?(v2(P),requestAnimationFrame(()=>{y2(P.dom)})):w2(P))},[u,m]),l.useEffect(()=>{const P=h.current;if(!P)return;const A=P.state.doc.toString();A!==t&&(P.dispatch({changes:{from:0,to:A.length,insert:t}}),xc(P,P.state.doc.length,300),P.requestMeasure(),requestAnimationFrame(()=>M(P)))},[t,M]),s.jsxs(s.Fragment,{children:[s.jsx("div",{ref:b,className:xe("h-full w-full","[&_.cm-editor]:h-full [&_.cm-editor]:w-full","[&_.cm-scroller]:font-mono [&_.cm-scroller]:text-[var(--text-code)] [&_.cm-scroller]:leading-6","[&_.cm-lineNumbers]:text-[var(--tools-edit-line-number)]",r)}),j.map(P=>Vo.createPortal(P.content,P.container,P.id))]})}const N2=(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)},Hm=(t,e)=>{const n=t.state.doc.lineAt(e.main.head);return{lineNumber:n.number,character:e.main.head-n.from+1,selection:e}},Gm=(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:wx.cursor(i),effects:Hn.scrollIntoView(i,{y:"center"})})};function S2({open:t,onOpenChange:e,view:n,variant:r="overlay"}){const{t:a}=dt(),[i,o]=l.useState(""),c=l.useRef(null),d=l.useRef(!1),p=l.useRef(null),m=l.useRef(null),u=l.useMemo(()=>N2(i,n),[i,n]);l.useEffect(()=>{!t||!n||(d.current=!1,c.current=Hm(n,n.state.selection),o(""))},[t,n]),l.useEffect(()=>{t&&window.requestAnimationFrame(()=>{m.current?.focus(),m.current?.select()})},[t]),l.useEffect(()=>{if(!(!t||!n||!c.current)){if(u===null){const{selection:x}=c.current;n.dispatch({selection:x,effects:Hn.scrollIntoView(x.main.from,{y:"center"})});return}Gm(n,u,c.current.character)}},[u,t,n]);const f=l.useCallback(()=>{if(!n||d.current||!c.current)return;const{selection:x}=c.current;n.dispatch({selection:x,effects:Hn.scrollIntoView(x.main.from,{y:"center"})})},[n]),b=l.useCallback(x=>{x||f(),e(x)},[e,f]),h=l.useCallback(()=>{!n||u===null||!c.current||(d.current=!0,Gm(n,u,c.current.character),e(!1),n.focus())},[u,e,n]);l.useEffect(()=>{if(!t)return;const x=w=>{const y=p.current,C=w.target;!y||!(C instanceof Node)||y.contains(C)||b(!1)},g=w=>{w.key==="Escape"&&(w.preventDefault(),b(!1))};return document.addEventListener("pointerdown",x,!0),document.addEventListener("keydown",g,!0),()=>{document.removeEventListener("pointerdown",x,!0),document.removeEventListener("keydown",g,!0)}},[b,t,r]);const v=l.useMemo(()=>{if(!n)return a("goToLineDialog.helper.editorUnavailable");if(u===null){const x=c.current??Hm(n,n.state.selection);return a("goToLineDialog.helper.currentLineRange",{current:x.lineNumber,max:n.state.doc.lines})}return a("goToLineDialog.helper.goToLine",{line:u})},[u,a,n]);return r==="inline"?t?s.jsxs("div",{ref:p,className:"ml-1 flex h-6 items-center gap-1",children:[s.jsx(Bt,{ref:m,type:"number",min:1,step:1,inputMode:"numeric",value:i,onChange:x=>o(x.target.value),onKeyDown:x=>{x.key==="Enter"&&(x.preventDefault(),h())},placeholder:a("goToLineDialog.field.linePlaceholderShort"),className:"h-6 w-20 rounded-md border-border/70 bg-transparent px-2 typography-meta"}),s.jsx(be,{variant:"outline",size:"xs",onClick:h,disabled:!n||u===null,className:"h-6 px-2",children:a("goToLineDialog.actions.go")})]}):null:s.jsx("div",{ref:p,className:xe("absolute left-3 top-3 z-40 w-[min(32rem,calc(100%-1.5rem))] rounded-xl border border-[var(--interactive-border)] bg-[color:color-mix(in_srgb,var(--surface-elevated)_94%,transparent)] p-2.5 shadow-lg backdrop-blur-sm transition-all",t?"pointer-events-auto translate-y-0 opacity-100":"pointer-events-none -translate-y-1 opacity-0"),children:s.jsxs("div",{className:"min-w-0",children:[s.jsx(Bt,{ref:m,type:"number",min:1,step:1,inputMode:"numeric",value:i,onChange:x=>o(x.target.value),onKeyDown:x=>{x.key==="Enter"&&(x.preventDefault(),h())},placeholder:a("goToLineDialog.field.linePlaceholder"),className:"h-8 w-full rounded-md border-border/70 bg-background/60 typography-ui-label"}),s.jsx("div",{className:"mt-2 rounded-md bg-primary/15 px-3 py-1.5 typography-ui-label text-foreground/95",children:v})]})})}const cd=t=>{const e=st.c(11),{currentMode:n,onToggle:r}=t,a=n==="preview",i=a?"Switch to edit mode":"Switch to preview mode",o=a?"Edit":"Preview";let c;e[0]!==a?(c=a?s.jsx(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(It,{asChild:!0,children:s.jsx(be,{variant:"ghost",size:"sm",onClick:r,"aria-label":i,className:"h-5 w-5 p-0",children:c})}),e[2]=i,e[3]=r,e[4]=c,e[5]=d):d=e[5];let p;e[6]!==o?(p=s.jsx(At,{sideOffset:8,children:o}),e[6]=o,e[7]=p):p=e[7];let m;return e[8]!==d||e[9]!==p?(m=s.jsxs(Ct,{children:[d,p]}),e[8]=d,e[9]=p,e[10]=m):m=e[10],m},dd=jx.define(Nx);function k2(t){const e=t.trim().toLowerCase();switch(e){case"bash":case"sh":case"zsh":case"shell":case"shellsession":case"console":return dd;case"json":case"jsonc":case"json5":return $f().language;case"js":case"javascript":return Xa().language;case"jsx":return Xa({jsx:!0}).language;case"ts":case"typescript":return Xa({typescript:!0}).language;case"tsx":return Xa({typescript:!0,jsx:!0}).language;case"html":return Uc().language;case"css":return Lf().language;case"py":case"python":return Of().language;case"heex":case"eex":case"leex":return Uc().language;default:return _f.matchLanguageName(Bf,e,!0)}}const eg=t=>t.split("/").pop()?.toLowerCase()??"",C2=t=>{const e=eg(t);return e?_f.matchFilename(Bf,e):null},I2=()=>$i(Wc.define([{tag:[ot.heading1,ot.heading2,ot.heading3,ot.heading4,ot.heading5,ot.heading6],fontWeight:"600"},{tag:ot.strong,fontWeight:"600"},{tag:ot.emphasis,fontStyle:"italic"},{tag:ot.strikethrough,textDecoration:"line-through"},{tag:[ot.link,ot.url],color:"var(--markdown-link, currentColor)",textDecoration:"underline"},{tag:ot.monospace,color:"var(--markdown-inline-code, currentColor)",backgroundColor:"var(--markdown-inline-code-bg, transparent)"},{tag:ot.quote,color:"var(--markdown-blockquote, currentColor)",fontStyle:"italic"},{tag:ot.list,color:"color-mix(in srgb, var(--muted-foreground) 40%, var(--foreground) 60%)"},{tag:ot.heading,color:"var(--markdown-heading1, currentColor)"}]));function tg(t){const e=t.toLowerCase();switch(eg(e)){case"makefile":case"gnumakefile":return dd}const r=e.lastIndexOf("."),a=r>=0?e.slice(r+1):"";switch(a){case"ts":case"tsx":case"mts":case"cts":return Xa({typescript:!0,jsx:a==="tsx"});case"js":case"jsx":case"mjs":case"cjs":return Xa({typescript:!1,jsx:a==="jsx"});case"json":case"jsonc":case"json5":case"jsonl":case"ndjson":case"geojson":return $f();case"css":case"scss":case"sass":case"less":return Lf();case"html":case"htm":return Uc();case"md":case"mdx":case"markdown":case"mdown":case"mkd":return[Sx({codeLanguages:k2}),I2()];case"sh":case"bash":case"zsh":case"fish":case"env":return dd;case"py":case"pyw":case"pyi":return Of();default:return null}}async function P2(t){const e=C2(t);if(!e)return null;if(e.support)return e.support;try{return await e.load()}catch{return null}}function ud(t){const e=t.metadata.variant==="dark",n=t.config?.fonts?.mono||"monospace",r=t.colors.syntax.highlights||{},a=t.colors.syntax.tokens||{},i=Hn.theme({"&":{backgroundColor:"var(--background)",color:t.colors.syntax.base.foreground,fontSize:"var(--text-code)",lineHeight:"1.5rem",position:"relative"},".cm-scroller":{fontFamily:n,backgroundColor:"var(--background)"},".cm-comment":{color:t.colors.syntax.base.comment},".cm-keyword":{color:t.colors.syntax.base.keyword},".cm-string":{color:t.colors.syntax.base.string},".cm-string-2":{color:a.stringEscape||t.colors.syntax.base.string},".cm-number":{color:t.colors.syntax.base.number},".cm-operator":{color:t.colors.syntax.base.operator},".cm-punctuation":{color:a.punctuation||t.colors.syntax.base.comment},".cm-atom":{color:a.boolean||t.colors.syntax.base.number},".cm-builtin":{color:a.functionCall||t.colors.syntax.base.function},".cm-def":{color:a.variableGlobal||t.colors.syntax.base.variable},".cm-attribute":{color:a.variableOther||a.variableProperty||t.colors.syntax.base.operator},".cm-meta":{color:t.colors.syntax.base.comment},".cm-property":{color:a.variableProperty||t.colors.syntax.base.keyword},".cm-variable":{color:t.colors.syntax.base.variable},".cm-variable-2":{color:a.variableOther||t.colors.syntax.base.function},".cm-variable-3":{color:a.variableGlobal||t.colors.syntax.base.type},".cm-tag":{color:a.tag||t.colors.syntax.base.keyword},".cm-link":{color:a.url||t.colors.syntax.base.keyword,textDecoration:"underline"},".cm-content":{caretColor:t.colors.interactive.cursor},".cm-cursor, .cm-dropCursor":{borderLeftColor:t.colors.interactive.cursor},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, ::selection":{backgroundColor:t.colors.interactive.selection},".cm-gutters":{backgroundColor:"var(--background)",color:r.lineNumber||t.colors.syntax.base.comment,borderRight:`1px solid ${t.colors.interactive.border}`,position:"sticky",paddingRight:"8px",left:0,zIndex:2,boxShadow:"0 0 0 var(--background)"},".cm-gutter":{backgroundColor:"var(--background)"},".cm-gutterElement":{backgroundColor:"var(--background)"},".cm-lineNumbers":{backgroundColor:"var(--background)"},".cm-lineNumbers .cm-gutterElement":{paddingLeft:"8px",paddingRight:"8px",minWidth:"42px"},".cm-activeLineGutter":{color:r.lineNumberActive||t.colors.syntax.base.foreground},".cm-activeLine":{backgroundColor:t.colors.surface.overlay},".cm-panels":{backgroundColor:"transparent",color:t.colors.surface.foreground,position:"absolute",top:"0",right:"0",left:"auto",width:"auto",zIndex:10,pointerEvents:"none"},".cm-panels-top":{borderBottom:"none",position:"absolute",top:"6px",right:"14px",left:"auto",width:"auto"},".cm-panel.cm-search":{pointerEvents:"auto",padding:"4px",backgroundColor:`color-mix(in srgb, ${t.colors.surface.elevated} 85%, transparent)`,border:`1px solid ${t.colors.interactive.border}`,borderRadius:"10px",boxShadow:`0 2px 8px color-mix(in srgb, ${t.colors.surface.background} 60%, transparent)`,width:"auto",minWidth:"360px",maxWidth:"480px"},".cm-search":{display:"flex",flexWrap:"wrap",alignItems:"center",gap:"0",width:"100%",color:t.colors.surface.foreground,fontFamily:"inherit",fontSize:"13px",lineHeight:"1"},".cm-search br":{display:"none"},".cm-search .cm-textfield":{appearance:"none",height:"26px",margin:0,padding:"0 8px",borderRadius:"6px !important",border:`1px solid ${t.colors.interactive.border}`,backgroundColor:t.colors.surface.background,color:t.colors.surface.foreground,fontFamily:"inherit",fontSize:"12px",lineHeight:"1",outline:"none",transition:"border-color 150ms ease"},".cm-search .cm-textfield::placeholder":{color:t.colors.surface.mutedForeground,opacity:1},".cm-search .cm-textfield:focus":{borderColor:t.colors.primary.base},'.cm-search .cm-textfield[name="search"]':{order:1,flex:"1 1 120px",maxWidth:"calc(100% - 142px)",minWidth:"100px"},".cm-search label":{order:2,display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:0,marginLeft:"1px",padding:0,borderRadius:"4px",border:"1px solid transparent",backgroundColor:"transparent",color:"transparent",cursor:"pointer",userSelect:"none",fontSize:"1px",lineHeight:"0",overflow:"hidden",position:"relative",transition:"background-color 120ms ease, border-color 120ms ease"},".cm-search label:hover":{backgroundColor:t.colors.interactive.hover},'.cm-search label:has(input[type="checkbox"]:checked)':{backgroundColor:t.colors.interactive.hover,borderColor:t.colors.interactive.border},'.cm-search [type="checkbox"]':{appearance:"none",WebkitAppearance:"none",width:"0",height:"0",margin:"0",padding:"0",border:"none",position:"absolute",opacity:"0",pointerEvents:"none"},".cm-search label::after":{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",fontSize:"13px",fontWeight:"600",lineHeight:"1",fontFamily:"inherit",color:t.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search label:hover::after":{color:t.colors.surface.foreground},'.cm-search label:has(input[type="checkbox"]:checked)::after':{color:t.colors.surface.foreground},'.cm-search label:has(input[name="case"])::after':{content:'"Aa"',fontSize:"12px",letterSpacing:"-0.5px"},'.cm-search label:has(input[name="re"])::after':{content:'".*"',fontSize:"13px",fontFamily:"monospace"},'.cm-search label:has(input[name="word"])::after':{content:'"ab"',fontSize:"12px",textDecoration:"underline",textUnderlineOffset:"2px"},".cm-search .cm-search-message":{order:3,color:t.colors.surface.mutedForeground,backgroundColor:"transparent",border:"none",borderRadius:"0",padding:"0 6px",fontSize:"11px",whiteSpace:"nowrap",lineHeight:"26px"},".cm-search .cm-button":{appearance:"none",WebkitAppearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:0,marginLeft:"1px",padding:0,borderRadius:"4px",border:"none",backgroundColor:"transparent",backgroundImage:"none",color:"transparent",cursor:"pointer",fontSize:"1px",fontWeight:"400",lineHeight:"0",overflow:"hidden",position:"relative",boxShadow:"none",transition:"background-color 120ms ease"},".cm-search .cm-button::after":{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",fontSize:"15px",lineHeight:"1",color:t.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search .cm-button:hover":{backgroundColor:t.colors.interactive.hover},".cm-search .cm-button:hover::after":{color:t.colors.surface.foreground},".cm-search .cm-button:active":{backgroundColor:t.colors.interactive.active},".cm-search .cm-button:focus-visible":{outline:"none",boxShadow:`0 0 0 1px ${t.colors.interactive.focusRing}`},".cm-search .cm-button:disabled":{opacity:.4,cursor:"default",pointerEvents:"none"},'.cm-search .cm-button[name="prev"]':{order:21,marginTop:"2px"},'.cm-search .cm-button[name="prev"]::after':{content:'"↑"'},'.cm-search .cm-button[name="next"]':{order:22,marginTop:"2px"},'.cm-search .cm-button[name="next"]::after':{content:'"↓"'},'.cm-search .cm-button[name="select"]':{order:23,marginTop:"2px"},'.cm-search .cm-button[name="select"]::after':{content:'"≡"',fontSize:"17px"},'.cm-panel.cm-search button[name="close"]':{order:5,appearance:"none",WebkitAppearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:"0 0 0 auto",padding:"0",borderRadius:"4px",border:"none",backgroundColor:"transparent",backgroundImage:"none",color:t.colors.surface.mutedForeground,cursor:"pointer",fontSize:"16px",lineHeight:"1",boxShadow:"none",position:"relative",overflow:"visible",transition:"background-color 120ms ease, color 120ms ease"},'.cm-panel.cm-search button[name="close"]:hover':{backgroundColor:t.colors.interactive.hover,color:t.colors.surface.foreground},'.cm-search .cm-button[name="replace"]':{order:24,marginTop:"2px"},'.cm-search .cm-button[name="replace"]::after':{content:'"⇄"'},'.cm-search .cm-button[name="replaceAll"], .cm-search .cm-button[name="replace-all"]':{order:25,marginTop:"2px"},'.cm-search .cm-button[name="replaceAll"]::after, .cm-search .cm-button[name="replace-all"]::after':{content:'"⇉"'},'.cm-search .cm-textfield[name="replace"]':{order:20,flex:"1 1 100%",maxWidth:"calc(100% - 142px)",minWidth:"80px",marginTop:"2px"},".cm-searchMatch":{backgroundColor:t.colors.status.infoBackground,boxShadow:`inset 0 0 0 1px ${t.colors.status.infoBorder}`,borderRadius:"2px"},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:t.colors.interactive.selection,color:t.colors.interactive.selectionForeground,boxShadow:`inset 0 0 0 1px ${t.colors.interactive.borderFocus}`},"&.cm-focused":{outline:"none"}},{dark:e}),o=Wc.define([{tag:[ot.comment,ot.docComment,ot.meta,ot.documentMeta],class:"cm-comment"},{tag:[ot.keyword,ot.controlKeyword,ot.moduleKeyword,ot.definitionKeyword,ot.modifier],class:"cm-keyword"},{tag:[ot.operatorKeyword,ot.operator,ot.derefOperator,ot.updateOperator,ot.definitionOperator,ot.typeOperator,ot.controlOperator,ot.logicOperator,ot.bitwiseOperator,ot.arithmeticOperator,ot.compareOperator],class:"cm-operator"},{tag:[ot.punctuation,ot.separator,ot.bracket,ot.paren,ot.brace,ot.squareBracket,ot.angleBracket],class:"cm-punctuation"},{tag:[ot.string,ot.regexp,ot.attributeValue,ot.special(ot.string),ot.monospace],class:"cm-string"},{tag:ot.escape,class:"cm-string-2"},{tag:[ot.number,ot.bool,ot.atom,ot.null,ot.self],class:"cm-number"},{tag:[ot.function(ot.variableName),ot.function(ot.definition(ot.variableName)),ot.function(ot.propertyName),ot.standard(ot.variableName),ot.special(ot.variableName)],class:"cm-builtin"},{tag:ot.definition(ot.variableName),class:"cm-def"},{tag:[ot.variableName,ot.local(ot.variableName),ot.constant(ot.variableName),ot.literal],class:"cm-variable"},{tag:ot.propertyName,class:"cm-property"},{tag:ot.attributeName,class:"cm-attribute"},{tag:[ot.className,ot.typeName,ot.namespace],class:"cm-variable-3"},{tag:[ot.tagName,ot.labelName,ot.annotation,ot.macroName],class:"cm-tag"},{tag:ot.link,class:"cm-link"},{tag:[ot.heading,ot.heading1,ot.heading2,ot.heading3,ot.heading4,ot.heading5,ot.heading6],class:"cm-keyword"}]),c=Wc.define([{tag:[ot.comment,ot.docComment,ot.meta,ot.documentMeta],color:t.colors.syntax.base.comment},{tag:[ot.keyword,ot.controlKeyword,ot.moduleKeyword,ot.definitionKeyword,ot.modifier],color:t.colors.syntax.base.keyword},{tag:[ot.operatorKeyword,ot.operator,ot.derefOperator,ot.updateOperator,ot.definitionOperator,ot.typeOperator,ot.controlOperator,ot.logicOperator,ot.bitwiseOperator,ot.arithmeticOperator,ot.compareOperator],color:t.colors.syntax.base.operator},{tag:[ot.string,ot.regexp,ot.attributeValue,ot.special(ot.string),ot.monospace],color:t.colors.syntax.base.string},{tag:ot.escape,color:a.stringEscape||t.colors.syntax.base.string},{tag:[ot.number,ot.bool,ot.atom,ot.null,ot.self],color:t.colors.syntax.base.number},{tag:[ot.function(ot.variableName),ot.function(ot.definition(ot.variableName)),ot.function(ot.propertyName),ot.standard(ot.variableName),ot.special(ot.variableName)],color:t.colors.syntax.base.function},{tag:ot.definition(ot.variableName),color:a.variableGlobal||t.colors.syntax.base.variable},{tag:[ot.variableName,ot.local(ot.variableName),ot.constant(ot.variableName),ot.literal],color:t.colors.syntax.base.variable},{tag:ot.propertyName,color:a.variableProperty||t.colors.syntax.base.variable},{tag:ot.attributeName,color:a.variableOther||t.colors.syntax.base.variable},{tag:[ot.className,ot.typeName,ot.namespace],color:t.colors.syntax.base.type},{tag:[ot.tagName,ot.labelName,ot.annotation,ot.macroName],color:a.tag||t.colors.syntax.base.keyword},{tag:ot.link,color:a.url||t.colors.syntax.base.function,textDecoration:"underline"},{tag:[ot.punctuation,ot.separator,ot.bracket,ot.paren,ot.brace,ot.squareBracket,ot.angleBracket],color:a.punctuation||t.colors.syntax.base.comment}]);return[i,$i(kx,{fallback:!0}),$i(Cx),$i(o),$i(c)]}const A2=t=>{const e=pn(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=st.c(8),{label:n,iconDataUrl:r}=t,[a,i]=l.useState(!1);let o;e[0]!==n?(o=n.trim().slice(0,1).toUpperCase()||"?",e[0]=n,e[1]=o):o=e[1];const c=o;if(r&&!a){let m;e[2]===Symbol.for("react.memo_cache_sentinel")?(m=()=>i(!0),e[2]=m):m=e[2];let u;return e[3]!==r?(u=s.jsx("img",{src:r,alt:"",className:"size-4 rounded-sm",onError:m}),e[3]=r,e[4]=u):u=e[4],u}let d;e[5]===Symbol.for("react.memo_cache_sentinel")?(d=xe("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)),pn=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),qm=t=>/^[A-Za-z]:\//.test(t)?t.toLowerCase():t,vl=(t,e)=>{const n=pn(e),r=pn(t);if(!n||!r)return!1;const a=qm(n),i=qm(r);return i===a||i.startsWith(`${a}/`)},Jm=(t,e)=>{const n=pn(e),r=pn(t);if(!vl(r,n))return[];const i=r.slice(n.length).replace(/^\//,"").split("/"),o=[];let c=n;for(let d=0;d<i.length-1;d++)c=c?`${c}/${i[d]}`:i[d],o.push(c);return o},md=(t,e)=>{if(!e)return"";const n=pn(e);if(!t||!vl(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=st.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},F2=t=>E2.has(t),O2=t=>{const e=pn(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")},Ti=2e5,sg="openchamber:files:auto-save-enabled",$2=()=>{if(typeof window>"u")return!0;try{return window.localStorage.getItem(sg)!=="false"}catch{return!0}},ng=(t,e)=>s.jsx(jr,{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"},bc=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="html"||e==="htm"},z2=t=>{const e=st.c(62),{node:n,root:r,isExpanded:a,isActive:i,isMobile:o,alwaysShowActions:c,status:d,badge:p,permissions:m,downloadFile:u,contextMenuPath:f,setContextMenuPath:b,onSelect:h,onToggle:v,onRevealPath:x,onOpenDialog:g}=t,{t:w}=dt(),y=n.type==="directory",{canRename:C,canCreateFile:k,canCreateFolder:j,canDelete:S,canReveal:I}=m;let M;e[0]!==k||e[1]!==j||e[2]!==S||e[3]!==C||e[4]!==I||e[5]!==n.path||e[6]!==b?(M=Z=>{!C&&!k&&!j&&!S&&!I||(Z?.preventDefault(),b(n.path))},e[0]=k,e[1]=j,e[2]=S,e[3]=C,e[4]=I,e[5]=n.path,e[6]=b,e[7]=M):M=e[7];const P=M;let A;e[8]!==y||e[9]!==n||e[10]!==h||e[11]!==v?(A=()=>{y?v(n.path):h(n)},e[8]=y,e[9]=n,e[10]=h,e[11]=v,e[12]=A):A=e[12];const N=A;let E;e[13]!==n.path||e[14]!==b?(E=Z=>{Z.stopPropagation(),b(n.path)},e[13]=n.path,e[14]=b,e[15]=E):E=e[15];const T=E,R=o?void 0:P,V=o?void 0:P,_=i?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let U;e[16]!==_?(U=xe("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",_),e[16]=_,e[17]=U):U=e[17];let B;e[18]!==y||e[19]!==a||e[20]!==n.extension||e[21]!==n.path?(B=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"}):ng(n.path,n.extension),e[18]=y,e[19]=a,e[20]=n.extension,e[21]=n.path,e[22]=B):B=e[22];let z;e[23]!==n.name||e[24]!==n.path?(z=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]=z):z=e[25];let K;e[26]!==y||e[27]!==d?(K=!y&&d&&s.jsx(R2,{status:d}),e[26]=y,e[27]=d,e[28]=K):K=e[28];let F;e[29]!==p||e[30]!==y?(F=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]=F):F=e[31];let G;e[32]!==N||e[33]!==K||e[34]!==F||e[35]!==V||e[36]!==U||e[37]!==B||e[38]!==z?(G=s.jsxs("button",{type:"button",onClick:N,onContextMenu:V,className:U,children:[B,z,K,F]}),e[32]=N,e[33]=K,e[34]=F,e[35]=V,e[36]=U,e[37]=B,e[38]=z,e[39]=G):G=e[39];let Q;e[40]!==c||e[41]!==k||e[42]!==j||e[43]!==S||e[44]!==C||e[45]!==I||e[46]!==f||e[47]!==u||e[48]!==T||e[49]!==y||e[50]!==o||e[51]!==n||e[52]!==g||e[53]!==x||e[54]!==r||e[55]!==b||e[56]!==w?(Q=(C||k||j||S||I)&&s.jsx("div",{className:xe("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(Ts,{open:f===n.path,onOpenChange:Z=>b(Z?n.path:null),children:[s.jsx(As,{asChild:!0,children:s.jsx(be,{variant:"ghost",size:"icon",className:"size-6",onClick:T,children:s.jsx(D,{name:"more-2-fill",className:"size-4"})})}),s.jsxs(Ds,{align:"end",side:"bottom",onCloseAutoFocus:()=>b(null),children:[C&&s.jsxs($t,{onClick:Z=>{Z.stopPropagation(),g("rename",n)},children:[s.jsx(D,{name:"edit",className:"mr-2 size-4"})," ",w("sidebarFilesTree.menu.rename")]}),s.jsxs($t,{onClick:Z=>{Z.stopPropagation(),In(n.path).then(fe=>{if(fe.ok){H.success(w("sidebarFilesTree.toast.pathCopied"));return}H.error(w("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(D,{name:"file-copy",className:"mr-2 size-4"})," ",w("sidebarFilesTree.menu.copyPath")]}),s.jsxs($t,{onClick:Z=>{Z.stopPropagation();const fe=md(r,n.path)||n.path;In(fe).then(ue=>{if(ue.ok){H.success(w("filesView.toast.relativePathCopied"));return}H.error(w("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(D,{name:"file-copy-2",className:"mr-2 size-4"})," ",w("filesView.tree.menu.copyRelativePath")]}),!y&&u&&s.jsxs($t,{onClick:Z=>{Z.stopPropagation(),u(n.path)},children:[s.jsx(D,{name:"download",className:"mr-2 size-4"})," ",w("sidebarFilesTree.menu.save")]}),I&&s.jsxs($t,{onClick:Z=>{Z.stopPropagation(),x(n.path)},children:[s.jsx(D,{name:"folder-received",className:"mr-2 size-4"})," ",w(Od())]}),y&&(k||j)&&s.jsxs(s.Fragment,{children:[s.jsx(Gn,{}),k&&s.jsxs($t,{onClick:Z=>{Z.stopPropagation(),g("createFile",n)},children:[s.jsx(D,{name:"file-add",className:"mr-2 size-4"})," ",w("sidebarFilesTree.menu.newFile")]}),j&&s.jsxs($t,{onClick:Z=>{Z.stopPropagation(),g("createFolder",n)},children:[s.jsx(D,{name:"folder-add",className:"mr-2 size-4"})," ",w("sidebarFilesTree.menu.newFolder")]})]}),S&&s.jsxs(s.Fragment,{children:[s.jsx(Gn,{}),s.jsxs($t,{onClick:Z=>{Z.stopPropagation(),g("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(D,{name:"delete-bin",className:"mr-2 size-4"})," ",w("sidebarFilesTree.menu.delete")]})]})]})]})}),e[40]=c,e[41]=k,e[42]=j,e[43]=S,e[44]=C,e[45]=I,e[46]=f,e[47]=u,e[48]=T,e[49]=y,e[50]=o,e[51]=n,e[52]=g,e[53]=x,e[54]=r,e[55]=b,e[56]=w,e[57]=Q):Q=e[57];let te;return e[58]!==G||e[59]!==Q||e[60]!==R?(te=s.jsxs("div",{className:"group relative flex items-center",onContextMenu:R,children:[G,Q]}),e[58]=G,e[59]=Q,e[60]=R,e[61]=te):te=e[61],te},V2=t=>{const e=st.c(83),{activeDialog:n,dialogData:r,dialogInputValue:a,onDialogInputChange:i,isDialogSubmitting:o,onDialogSubmit:c,onClose:d,inputRef:p}=t,{t:m}=dt(),u=!!n;let f;e[0]!==d?(f=B=>!B&&d(),e[0]=d,e[1]=f):f=e[1];let b;e[2]!==n||e[3]!==m?(b=n==="createFile"&&m("filesView.dialog.createFile.title"),e[2]=n,e[3]=m,e[4]=b):b=e[4];let h;e[5]!==n||e[6]!==m?(h=n==="createFolder"&&m("filesView.dialog.createFolder.title"),e[5]=n,e[6]=m,e[7]=h):h=e[7];let v;e[8]!==n||e[9]!==m?(v=n==="rename"&&m("filesView.dialog.rename.title"),e[8]=n,e[9]=m,e[10]=v):v=e[10];let x;e[11]!==n||e[12]!==m?(x=n==="delete"&&m("filesView.dialog.delete.title"),e[11]=n,e[12]=m,e[13]=x):x=e[13];let g;e[14]!==b||e[15]!==h||e[16]!==v||e[17]!==x?(g=s.jsxs(hs,{children:[b,h,v,x]}),e[14]=b,e[15]=h,e[16]=v,e[17]=x,e[18]=g):g=e[18];let w;e[19]!==n||e[20]!==r?.path||e[21]!==m?(w=n==="createFile"&&m("filesView.dialog.createFile.description",{path:r?.path??m("filesView.dialog.rootFallback")}),e[19]=n,e[20]=r?.path,e[21]=m,e[22]=w):w=e[22];let y;e[23]!==n||e[24]!==r?.path||e[25]!==m?(y=n==="createFolder"&&m("filesView.dialog.createFolder.description",{path:r?.path??m("filesView.dialog.rootFallback")}),e[23]=n,e[24]=r?.path,e[25]=m,e[26]=y):y=e[26];let 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 j;e[35]!==C||e[36]!==k||e[37]!==w||e[38]!==y?(j=s.jsxs(Ss,{children:[w,y,C,k]}),e[35]=C,e[36]=k,e[37]=w,e[38]=y,e[39]=j):j=e[39];let S;e[40]!==j||e[41]!==g?(S=s.jsxs(ys,{children:[g,j]}),e[40]=j,e[41]=g,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:B=>i(B.target.value),placeholder:m(n==="rename"?"filesView.dialog.rename.placeholder":"filesView.dialog.namePlaceholder"),onKeyDown:B=>{B.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 M;e[50]!==m?(M=m("filesView.dialog.cancel"),e[50]=m,e[51]=M):M=e[51];let P;e[52]!==o||e[53]!==d||e[54]!==M?(P=s.jsx(be,{variant:"outline",onClick:d,disabled:o,children:M}),e[52]=o,e[53]=d,e[54]=M,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]!==o?(E=o||n!=="delete"&&!a.trim(),e[58]=n,e[59]=a,e[60]=o,e[61]=E):E=e[61];let T;e[62]!==n||e[63]!==o||e[64]!==m?(T=o?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]=o,e[64]=m,e[65]=T):T=e[65];let R;e[66]!==A||e[67]!==N||e[68]!==E||e[69]!==T?(R=s.jsx(be,{variant:A,onClick:N,disabled:E,children:T}),e[66]=A,e[67]=N,e[68]=E,e[69]=T,e[70]=R):R=e[70];let V;e[71]!==P||e[72]!==R?(V=s.jsxs(Vs,{children:[P,R]}),e[71]=P,e[72]=R,e[73]=V):V=e[73];let _;e[74]!==p||e[75]!==S||e[76]!==I||e[77]!==V?(_=s.jsxs(ms,{initialFocus:p,children:[S,I,V]}),e[74]=p,e[75]=S,e[76]=I,e[77]=V,e[78]=_):_=e[78];let U;return e[79]!==u||e[80]!==f||e[81]!==_?(U=s.jsx(ps,{open:u,onOpenChange:f,children:_}),e[79]=u,e[80]=f,e[81]=_,e[82]=U):U=e[82],U},rg=({mode:t="full"})=>{const{t:e}=dt(),{files:n,runtime:r}=Rn(),{currentTheme:a,availableThemes:i,lightThemeId:o,darkThemeId:c}=Cr(),{isMobile:d,isTablet:p,screenWidth:m}=nn(),u=d||p,f=Tl(),b=Rd(),h=Zr()??"",v=pn(h.trim()),x=d||t!=="editor-only",g=t==="editor-only"&&!d,w=Fd(Ee=>Ee.searchFiles),y=Dl(h),[C,k]=l.useState(""),j=Ml(C,200),S=l.useRef(null),[I,M]=l.useState(!1),[P,A]=l.useState(!0),[N,E]=l.useState(!1),[T,R]=l.useState(!1),[V,_]=l.useState(!1),U=l.useRef(null),B=l.useRef(0),z=l.useCallback(Ee=>{B.current=Math.max(0,B.current+(Ee?1:-1))},[]),K=l.useCallback(Ee=>Ee instanceof Element?Ee.closest('[data-slot="dropdown-menu-content"], [data-slot="dropdown-menu-item"]')!==null:!1,[]);l.useEffect(()=>{if(!V)return;const Ee=Ze=>{B.current>0||K(Ze.target)||U.current&&!U.current.contains(Ze.target)&&_(!1)};return document.addEventListener("mousedown",Ee),()=>document.removeEventListener("mousedown",Ee)},[K,V]);const[F,G]=l.useState("edit"),[Q,te]=l.useState("edit"),[Z,fe]=l.useState("tree"),[ue,W]=l.useState("edit"),q=l.useRef({}),J=l.useRef({}),ne=l.useRef({}),ee=l.useMemo(()=>i.find(Ee=>Ee.metadata.id===o)??ci(!1),[i,o]),he=l.useMemo(()=>i.find(Ee=>Ee.metadata.id===c)??ci(!0),[i,c]);l.useEffect(()=>{di(ee),di(he)},[ee,he]);const ke=l.useMemo(()=>[],[]),oe=Tn(Ee=>v?Ee.byRoot[v]?.openPaths??ke:ke),ge=Tn(Ee=>v?Ee.byRoot[v]?.selectedPath??null:null),me=Tn(Ee=>v?Ee.byRoot[v]?.expandedPaths??ke:ke),ye=Tn(Ee=>Ee.addOpenPath),ie=Tn(Ee=>Ee.removeOpenPath),ve=Tn(Ee=>Ee.removeOpenPathsByPrefix),X=Tn(Ee=>Ee.setSelectedPath),Se=Tn(Ee=>Ee.toggleExpandedPath),Ae=Tn(Ee=>Ee.expandPaths),pe=l.useCallback(Ee=>{const Ze=pn(Ee),ft=Ze.split("/"),jt=ft[ft.length-1]||Ze,Ht=jt.includes(".")?jt.split(".").pop()?.toLowerCase():void 0;return{name:jt,path:Ze,type:"file",extension:Ht}},[]),we=l.useMemo(()=>oe.map(pe),[oe,pe]),Ie=l.useMemo(()=>ge??oe[0]??null,[oe,ge]),Y=l.useMemo(()=>Ie?pe(Ie):null,[Ie,pe]),re=Y?.path??"",Pe=!!(v&&re&&!vl(re,v)),ce=l.useMemo(()=>({allowOutsideWorkspace:t==="editor-only"&&Pe}),[t,Pe]),Ce=l.useRef(null),[Te,$e]=l.useState({left:!1,right:!1}),De=l.useCallback(()=>{const Ee=Ce.current;Ee&&$e({left:Ee.scrollLeft>2,right:Ee.scrollLeft+Ee.clientWidth<Ee.scrollWidth-2})},[]),de=l.useRef(De);de.current=De,l.useEffect(()=>{const Ee=Ce.current;if(!Ee)return;const Ze=()=>de.current();Ze(),Ee.addEventListener("scroll",Ze,{passive:!0});const ft=new ResizeObserver(Ze);return ft.observe(Ee),()=>{Ee.removeEventListener("scroll",Ze),ft.disconnect()}},[we.length]);const[O,L]=l.useState({}),$=l.useRef(new Set),je=l.useRef(new Set),ae=l.useRef(new Map),_e=l.useRef(0),[le,Me]=l.useState([]),[Ge,at]=l.useState(!1),[Ye,Xe]=l.useState(""),[ut,rt]=l.useState(!1),[it,nt]=l.useState(null),[Ne,Ke]=l.useState(""),[Ve,qe]=l.useState(null),[lt,He]=l.useState(""),[ze,et]=l.useState(!1),yt=l.useRef(null),Rt=l.useRef(null),kt=l.useRef(null),ht=l.useRef(0),[vt,ns]=l.useState("idle"),[zt,Kt]=l.useState($2),[mt,Et]=l.useState(!1),rs=l.useRef(null),gs=l.useRef(null),xs=l.useRef(null),bs=l.useRef(!1),Wt=l.useRef(null),We=l.useRef(null),St=l.useRef(null),qt=l.useRef(null),[wt,es]=l.useState(0),ds=l.useRef(null),Ms=l.useRef({key:"",attempts:0});l.useEffect(()=>()=>{ds.current!==null&&typeof window<"u"&&(window.cancelAnimationFrame(ds.current),ds.current=null)},[]);const[as,$s]=l.useState(null),[Ls,ln]=l.useState(null),[Xs,Vt]=l.useState(""),[Ut,se]=l.useState(!1),[xt,Je]=l.useState(null),[_t,Gt]=l.useState(!1),[is,Ue]=l.useState(!1),[gt,Pt]=l.useState(!1),Mt=!!n.writeFile,ts=!!n.createDirectory,Ot=!!n.rename,ks=!!n.delete,Zs=!!n.revealPath,Hs=Fr(Ee=>Ee.availableApps),ss=Fr(Ee=>Ee.isCacheStale),Es=Fr(Ee=>Ee.initialize),Pn=Fr(Ee=>Ee.loadInstalledApps);l.useEffect(()=>{Es()},[Es]);const an=l.useCallback(Ee=>{n.revealPath&&n.revealPath(Ee).catch(()=>{H.error(e("sidebarFilesTree.toast.revealFailed"))})},[n,e]),Ir=l.useCallback(async Ee=>{if(!Y?.path||await Db(Y.path,Ee.id,Ee.appName)||await il(Y.path,Ee.appName))return;const jt=A2(Y.path)||v;jt&&await il(jt,Ee.appName)||H.error(e("filesView.toast.openInAppFailed",{app:Ee.appName}))},[v,Y?.path,e]),er=l.useCallback((Ee,Ze)=>{$s(Ee),ln(Ze),Vt(Ee==="rename"&&Ze.name||""),se(!1)},[]),[Js,An]=l.useState(null),tr=l.useRef(!1),Be=l.useRef(null),[Dt,Yt]=l.useState(!1),Qt=Re(Ee=>Ee.setMainTabGuard),vs=Re(Ee=>Ee.pendingFileNavigation),Rs=Re(Ee=>Ee.setPendingFileNavigation),Cs=Re(Ee=>Ee.pendingFileFocusPath),_s=Re(Ee=>Ee.setPendingFileFocusPath),Qs=Re(Ee=>Ee.shortcutOverrides),Fn=bt(Ee=>Ee.settingsDefaultFileViewerPreview);l.useEffect(()=>{const Ee=()=>{tr.current=!1,Be.current=null,Yt(!1)};return document.addEventListener("mouseup",Ee),()=>document.removeEventListener("mouseup",Ee)},[]),l.useEffect(()=>()=>{Wt.current!==null&&window.clearTimeout(Wt.current),We.current!==null&&window.clearTimeout(We.current)},[]);const gr=l.useCallback((Ee,Ze)=>{const ft=Ee.split(`
48
+ `),jt=Math.max(1,Ze.start),Ht=Math.min(ft.length,Ze.end);return jt>Ht?"":ft.slice(jt-1,Ht).join(`
49
+ `)},[]),zr=Kd({source:"file",fileLabel:Y?.path??null,language:Y?.path&&ui(Y.path)||"text",getCodeForRange:Ee=>gr(Ye,xl(Ee)),toStoreRange:Ee=>({startLine:Ee.start,endLine:Ee.end}),fromDraftRange:Ee=>({start:Ee.startLine,end:Ee.endLine})}),{drafts:Pr,commentText:Nn,editingDraftId:wn,setSelection:zn,saveComment:sr,cancel:gn,reset:nr,startEdit:Vr,deleteDraft:Ar}=zr;l.useEffect(()=>{An(null),nr(),Qt(null),He(""),et(!1)},[Y?.path,nr,Qt]),l.useEffect(()=>{zn(Js)},[Js,zn]),l.useEffect(()=>{if(!Js&&!wn)return;const Ee=ft=>{const jt=ft.target;jt.closest('[data-comment-input="true"]')||jt.closest('[data-comment-card="true"]')||jt.closest(".cm-gutterElement")||jt.closest("[data-sonner-toast]")||jt.closest("[data-sonner-toaster]")||(An(null),gn())},Ze=setTimeout(()=>{document.addEventListener("click",Ee)},100);return()=>{clearTimeout(Ze),document.removeEventListener("click",Ee)}},[gn,wn,Js]);const rr=l.useCallback((Ee,Ze)=>{const ft=Ze??Js??void 0;Ze&&An(Ze),sr(Ee,ft),An(null)},[Js,sr]),ua=l.useCallback((Ee,Ze)=>{const ft=[];for(const jt of Ze){if(!(jt&&typeof jt.name=="string"&&jt.name.length>0)||!f&&jt.name.startsWith(".")||!b&&F2(jt.name))continue;const Ht=jt.name,Zt=pn(jt.path||""),Fs=Zt?M2(Zt)?Zt:pn(`${Ee}/${Zt}`):pn(`${Ee}/${Ht}`),Gs=jt.isDirectory?"directory":"file",Ln=Gs==="file"&&Ht.includes(".")?Ht.split(".").pop()?.toLowerCase():void 0;ft.push({name:Ht,path:Fs,type:Gs,extension:Ln})}return T2(ft)},[b,f]),Sn=l.useCallback(async Ee=>{const Ze=pn(Ee.trim());if(!Ze||$.current.has(Ze)||je.current.has(Ze))return;je.current=new Set(je.current),je.current.add(Ze);const ft=_e.current+1;_e.current=ft,ae.current=new Map(ae.current),ae.current.set(Ze,ft);const jt=()=>ae.current.get(Ze)===ft,Ht=!b;await(r.isDesktop?n.listDirectory(Ze,{respectGitignore:Ht}).then(Fs=>Fs.entries.map(Gs=>({name:Gs.name,path:Gs.path,isDirectory:Gs.isDirectory}))):sn.listLocalDirectory(Ze,{respectGitignore:Ht}).then(Fs=>Fs.map(Gs=>({name:Gs.name,path:Gs.path,isDirectory:Gs.isDirectory})))).then(Fs=>{if(!jt())return;const Gs=ua(Ze,Fs);$.current=new Set($.current),$.current.add(Ze),L(Ln=>({...Ln,[Ze]:Gs}))}).catch(()=>{jt()&&L(Fs=>({...Fs,[Ze]:Fs[Ze]??[]}))}).finally(()=>{jt()&&(ae.current=new Map(ae.current),ae.current.delete(Ze),je.current=new Set(je.current),je.current.delete(Ze))})},[n,ua,r.isDesktop,b]),ma=l.useCallback(async()=>{v&&($.current=new Set,je.current=new Set,ae.current=new Map,L(Ee=>Object.keys(Ee).length===0?Ee:{}),await Sn(v))},[Sn,v]),ar=l.useCallback(async Ee=>{if(!Ee){await ma();return}const Ze=pn(Ee);$.current=new Set($.current),$.current.delete(Ze),je.current=new Set(je.current),je.current.delete(Ze),await Sn(Ze)},[Sn,ma]),pa=l.useRef(""),Ur=l.useRef("");l.useEffect(()=>{if(!v)return;const Ee=`${v}|h${f?"1":"0"}|g${b?"1":"0"}`,Ze=pa.current!==v,ft=Ur.current!==Ee;!Ze&&!ft||(Ze&&(pa.current=v,Xe(""),nt(null),Ke(""),qe(null),M(!1)),ft&&(Ur.current=Ee,$.current=new Set,je.current=new Set,ae.current=new Map,L(jt=>Object.keys(jt).length===0?jt:{}),Sn(v)))},[Sn,v,b,f]),l.useEffect(()=>{if(!n.listDirectory)return;const Ee=()=>{if(!document.hidden&&me.length>0)for(const Ze of me)ar(Ze)};return document.addEventListener("visibilitychange",Ee),()=>document.removeEventListener("visibilitychange",Ee)},[me,n.listDirectory,ar]),l.useEffect(()=>{if(!n.listDirectory||me.length===0)return;const Ee=setInterval(()=>{if(!document.hidden)for(const Ze of me)ar(Ze)},8e3);return()=>clearInterval(Ee)},[me,n.listDirectory,ar]);const ir=l.useCallback(async Ee=>{if(Ee?.preventDefault(),!Ls||!as)return;se(!0);const Ze=()=>{$s(null)},ft=Ht=>{H.error(Ht)},jt=()=>{se(!1)};if(as==="createFile"){if(!Xs.trim()){ft(e("sidebarFilesTree.toast.filenameRequired")),jt();return}if(!n.writeFile){ft(e("sidebarFilesTree.toast.writeNotSupported")),jt();return}const Ht=Ls.path,Zt=Ht?`${Ht}/`:"",Fs=pn(`${Zt}${Xs.trim()}`);await n.writeFile(Fs,"").then(async Gs=>{Gs.success&&(H.success(e("sidebarFilesTree.toast.fileCreated")),await ar(Ht)),Ze()}).catch(()=>ft(e("sidebarFilesTree.toast.operationFailed"))).finally(jt);return}if(as==="createFolder"){if(!Xs.trim()){ft(e("sidebarFilesTree.toast.folderNameRequired")),jt();return}const Ht=Ls.path,Zt=Ht?`${Ht}/`:"",Fs=pn(`${Zt}${Xs.trim()}`);await n.createDirectory(Fs).then(async Gs=>{Gs.success&&(H.success(e("sidebarFilesTree.toast.folderCreated")),await ar(Ht)),Ze()}).catch(()=>ft(e("sidebarFilesTree.toast.operationFailed"))).finally(jt);return}if(as==="rename"){if(!Xs.trim()){ft(e("sidebarFilesTree.toast.nameRequired")),jt();return}if(!n.rename){ft(e("sidebarFilesTree.toast.renameNotSupported")),jt();return}const Ht=Ls.path,Zt=Ht.split("/").slice(0,-1).join("/"),Fs=Zt?`${Zt}/`:"",Gs=pn(`${Fs}${Xs.trim()}`);await n.rename(Ht,Gs).then(async Ln=>{Ln.success&&(H.success(e("sidebarFilesTree.toast.renamedSuccessfully")),await ar(Zt),v&&ve(v,Ht),(Y?.path===Ht||Y?.path.startsWith(`${Ht}/`))&&(v&&X(v,null),Xe(""),nt(null),Ke(""),qe(null),d&&M(!1))),Ze()}).catch(()=>ft(e("sidebarFilesTree.toast.operationFailed"))).finally(jt);return}if(as==="delete"){if(!n.delete){ft(e("sidebarFilesTree.toast.deleteNotSupported")),jt();return}const Ht=Ls.path,Zt=Ht.split("/").slice(0,-1).join("/");await n.delete(Ht).then(async Fs=>{Fs.success&&(H.success(e("sidebarFilesTree.toast.deletedSuccessfully")),await ar(Zt),v&&ve(v,Ht),(Y?.path===Ht||Y?.path.startsWith(`${Ht}/`))&&(v&&X(v,null),Xe(""),nt(null),Ke(""),qe(null),d&&M(!1))),Ze()}).catch(()=>ft(e("sidebarFilesTree.toast.operationFailed"))).finally(jt);return}jt()},[as,Ls,Xs,n,ar,d,ve,v,Y?.path,X,e]);l.useEffect(()=>{if(!h){Me([]),at(!1);return}const Ee=j.trim();if(!Ee){Me([]),at(!1);return}let Ze=!1;return at(!0),w(h,Ee,150,{includeHidden:f,respectGitignore:!b,type:"file"}).then(ft=>{if(Ze)return;const Ht=ft.filter(Zt=>b||!O2(Zt.path)).map(Zt=>({name:Zt.name,path:pn(Zt.path),type:"file",extension:Zt.extension,relativePath:Zt.relativePath}));Me(Ht)}).catch(()=>{Ze||Me([])}).finally(()=>{Ze||at(!1)}),()=>{Ze=!0}},[h,j,w,f,b]);const xn=l.useCallback(async(Ee,Ze)=>{if(n.readFile)return(await n.readFile(Ee,Ze)).content??"";const ft=new URLSearchParams({path:Ee});Ze?.allowOutsideWorkspace&&ft.set("allowOutsideWorkspace","true"),Ze?.optional&&ft.set("optional","true");const jt=await fetch(`/api/fs/read?${ft.toString()}`,{cache:Ze?.optional?"no-store":"default"});if(!jt.ok){const Ht=await jt.json().catch(()=>({error:jt.statusText}));throw new Error(Ht.error||e("filesView.error.readFileFailed"))}return jt.text()},[n,e]),cn=l.useCallback(async(Ee,Ze)=>{if(n.statFile){const ft=await n.statFile(Ee,Ze);return{path:ft.path,size:ft.size,mtimeMs:ft.mtimeMs}}return null},[n]),_r=l.useMemo(()=>Ye.length>Ti?`${Ye.slice(0,Ti)}
50
+
51
+ … truncated …`:Ye,[Ye]),dn=lt!==_r,Dr=l.useCallback(async()=>{if(!Y||!n.writeFile)return H.error(e("filesView.toast.savingNotSupported")),!1;if(!dn)return!0;et(!0);try{return(await n.writeFile(Y.path,lt))?.success?(Xe(lt),cn(Y.path).then(Ze=>{Ze&&(kt.current=Ze)}).catch(()=>{}),!0):(H.error(e("filesView.toast.writeFileFailed")),!1)}catch(Ee){return H.error(Ee instanceof Error?Ee.message:e("filesView.toast.saveFailed")),!1}finally{et(!1)}},[lt,n,dn,cn,Y,e]);l.useEffect(()=>{if(!dn){Qt(null);return}const Ee=Ze=>bs.current?(bs.current=!1,!0):(Et(!0),gs.current=Ze,!1);return Qt(Ee),()=>{Re.getState().mainTabGuard===Ee&&Qt(null)}},[dn,Qt]),l.useEffect(()=>{try{window.localStorage.setItem(sg,zt?"true":"false")}catch{}},[zt]),l.useEffect(()=>{zt||(ns("idle"),Rt.current&&(clearTimeout(Rt.current),Rt.current=null))},[zt]);const Wr=1500;l.useEffect(()=>{const Ee=!!(Y&&n.writeFile);if(!(!zt||!dn||!Ee||ze))return Rt.current=setTimeout(()=>{Dr().then(Ze=>{Ze&&(ns("saved"),setTimeout(()=>ns("idle"),2e3))})},Wr),()=>{Rt.current&&(clearTimeout(Rt.current),Rt.current=null)}},[zt,lt,dn,Y,n.writeFile,ze,Dr]),l.useEffect(()=>{ns("idle")},[Y?.path]),l.useEffect(()=>{const Ee=Ze=>{Dd(Ze)&&(Ze.key.toLowerCase()==="s"?(Ze.preventDefault(),Rt.current&&(clearTimeout(Rt.current),Rt.current=null),ze||Dr().then(ft=>{ft&&(ns("saved"),setTimeout(()=>ns("idle"),2e3))})):Ze.key.toLowerCase()==="f"&&(Ze.preventDefault(),R(!0)))};return window.addEventListener("keydown",Ee),()=>window.removeEventListener("keydown",Ee)},[ze,Dr]);const Va=l.useCallback(async Ee=>{const Ze=ht.current+1;ht.current=Ze;const ft=()=>{if(!v)return!1;const Fs=Tn.getState().byRoot[v],Gs=Fs?.selectedPath??Fs?.openPaths[0]??null;return ht.current===Ze&&Gs===Ee.path};nt(null),Ke(""),qe(null);const jt=mi(Ee.path),Ht=Ee.path.toLowerCase().endsWith(".svg");if(d&&M(!0),r.isDesktop&&jt&&!Ht){Xe(""),He(""),rt(!0);return}if(!r.isDesktop&&jt&&!Ht){Xe(""),He(""),qe(Ee.path),rt(!1);return}rt(!0);const Zt={allowOutsideWorkspace:t==="editor-only"&&!!v&&!vl(Ee.path,v)};await xn(Ee.path,Zt).then(Fs=>{ft()&&(Xe(Fs),He(Fs.length>Ti?`${Fs.slice(0,Ti)}
52
+
53
+ … truncated …`:Fs),qe(Ee.path),cn(Ee.path,Zt).then(Gs=>{Gs&&ft()&&(kt.current=Gs)}).catch(()=>{}))}).catch(Fs=>{if(ft()){if(L2(Fs)){if(rt(!1),v&&X(v,null),nt(null),Xe(""),He(""),qe(null),kt.current=null,C.trim().length>0&&k(""),d&&M(!1),v){const Ln=[...Jm(Ee.path,v),Ee.path];Ln.length>0&&Ae(v,Ln);for(const vo of Ln)$.current.has(vo)||Sn(vo)}return}Xe(""),He(""),nt(Fs instanceof Error?Fs.message:e("filesView.error.readFileFailed")),kt.current=null}}).finally(()=>{ft()&&rt(!1)})},[Ae,d,Sn,t,xn,cn,v,r.isDesktop,C,X,e]),xr=l.useCallback(async(Ee,Ze)=>{if(!v)return;const ft=Jm(Ee,v),jt=Ze?[...ft,Ee]:ft;jt.length>0&&Ae(v,jt);const Ht=jt.map(Zt=>{if(!$.current.has(Zt))return Sn(Zt)}).filter(Boolean);await Promise.all(Ht)},[Ae,Sn,v]),Ua=l.useCallback((Ee,Ze)=>{const ft=Ze.findIndex(jt=>jt.path===Ee);return ft===-1||Ze.length<=1?null:Ze[ft+1]??Ze[ft-1]??null},[]),fn=l.useCallback(async Ee=>{if(bs.current)bs.current=!1;else if(dn){Et(!0),rs.current=Ee;return}v&&(X(v,Ee.path),ye(v,Ee.path),xr(Ee.path,!1)),nt(null),Ke(""),Xe(""),He(""),qe(null),d&&M(!0)},[ye,xr,dn,d,v,X]);l.useEffect(()=>{Y?.path&&xr(Y.path,!1)},[xr,Y?.path]),l.useEffect(()=>{if(!Y){ht.current+=1,rt(!1);return}Ve!==Y.path&&Va(Y)},[Va,Ve,Y]);const wi=l.useRef(dn);wi.current=dn,l.useEffect(()=>{if(!Y?.path||Ve!==Y.path)return;let Ee=!1;const Ze=window.setInterval(()=>{document.hidden||cn(Y.path,ce).then(ft=>{if(Ee||!ft)return;const jt=kt.current;if(!jt||jt.path!==Y.path){kt.current=ft;return}const Ht=ft.mtimeMs!==void 0&&jt.mtimeMs!==void 0&&ft.mtimeMs!==jt.mtimeMs,Zt=ft.size!==jt.size;!Ht&&!Zt||wi.current||(kt.current=ft,qe(null))}).catch(()=>{})},2e3);return()=>{Ee=!0,window.clearInterval(Ze)}},[Ve,cn,Y?.path,ce]);const go=l.useCallback(()=>{const Ee=rs.current,Ze=gs.current,ft=xs.current;if(rs.current=null,gs.current=null,xs.current=null,bs.current=!0,Et(!1),He(_r),ft){v&&ie(v,ft),Y?.path===ft&&(Ee?fn(Ee):(v&&X(v,null),Xe(""),nt(null),Ke(""),qe(null),d&&M(!1)));return}if(Ee){fn(Ee);return}Ze&&(Qt(null),Re.getState().setActiveMainTab(Ze))},[_r,fn,d,ie,v,Y?.path,Qt,X]),Le=l.useCallback(async()=>{const Ee=rs.current,Ze=gs.current,ft=xs.current;if(!await Dr()){bs.current=!1;return}if(rs.current=null,gs.current=null,xs.current=null,bs.current=!0,Et(!1),ft){v&&ie(v,ft),Y?.path===ft&&(Ee?await fn(Ee):(v&&X(v,null),Xe(""),nt(null),Ke(""),qe(null),d&&M(!1)));return}if(Ee){await fn(Ee);return}Ze&&(Qt(null),Re.getState().setActiveMainTab(Ze))},[fn,d,ie,v,Dr,Y?.path,Qt,X]),Qe=l.useCallback(Ee=>{const Ze=Y?.path===Ee,ft=Ua(Ee,we);if(Ze&&dn){Et(!0),rs.current=ft,xs.current=Ee;return}if(v&&ie(v,Ee),!!Ze){if(ft){fn(ft);return}v&&X(v,null),Xe(""),nt(null),Ke(""),qe(null),d&&M(!1)}},[Ua,fn,dn,d,we,ie,v,Y?.path,X]),tt=l.useCallback(Ee=>{if(oe.includes(Ee))return"open";if(y?.files){const Ze=Ee.startsWith(v+"/")?Ee.slice(v.length+1):Ee,ft=y.files.find(jt=>jt.path===Ze);if(ft){if(ft.index==="A"||ft.working_dir==="?")return"git-added";if(ft.index==="D")return"git-deleted";if(ft.index==="M"||ft.working_dir==="M")return"git-modified"}}return null},[oe,y,v]),ct=l.useCallback(Ee=>{if(!y?.files)return null;const Ze=Ee.startsWith(v+"/")?Ee.slice(v.length+1):Ee,ft=Ze?`${Ze}/`:"";let jt=0,Ht=0;for(const Zt of y.files)Zt.path.startsWith(ft)&&((Zt.index==="M"||Zt.working_dir==="M")&&jt++,(Zt.index==="A"||Zt.working_dir==="?")&&Ht++);return jt+Ht>0?{modified:jt,added:Ht}:null},[y,v]),Ft=l.useCallback(async Ee=>{const Ze=pn(Ee);v&&(Se(v,Ze),$.current.has(Ze)||await Sn(Ze))},[Sn,v,Se]),Xt=l.useMemo(()=>({canRename:Ot,canCreateFile:Mt,canCreateFolder:ts,canDelete:ks,canReveal:Zs}),[Ot,Mt,ts,ks,Zs]);function Ws(Ee,Ze){const ft=O[Ee]??[];return ft.map((jt,Ht)=>{const Zt=jt.type==="directory",Fs=Zt&&me.includes(jt.path),Gs=Y?.path===jt.path,Ln=Ht===ft.length-1;return s.jsxs("li",{className:"relative",children:[Ze>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),Ln&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-background"})]}),s.jsx(z2,{node:jt,root:v,isExpanded:Fs,isActive:Gs,isMobile:d,alwaysShowActions:u,status:Zt?void 0:tt(jt.path),badge:Zt?ct(jt.path):void 0,permissions:Xt,downloadFile:n.downloadFile,contextMenuPath:xt,setContextMenuPath:Je,onSelect:fn,onToggle:Ft,onRevealPath:an,onOpenDialog:er}),Zt&&Fs&&s.jsx("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:Ws(jt.path,Ze+1)})]},jt.path)})}const Bs=!!(Y?.path&&mi(Y.path)),On=!!(Y?.path&&Y.path.toLowerCase().endsWith(".svg")),ta=l.useMemo(()=>pn(vs?.path??""),[vs?.path]),Ks=!!(vs&&ta&&re&&re===ta&&!ut&&!it&&!Bs),Tr=l.useMemo(()=>md(v,re),[re,v]),ji=!!(Y&&(!Bs||On)&&Ye.length>0),Bl=!!(Y&&Tr.length>0),Yn=!!(Y&&!Pe&&!Bs&&n.writeFile&&Ye.length<=Ti),Mr=!!(Y?.path&&_2(Y.path)),hn=!!(Y?.path&&B2(Y.path)),Ni=!!(Y?.path&&bc(Y.path)),Si=!!(Y&&!Bs)&&!Mr&&!(Ni&&ue==="preview"),Wa=l.useMemo(()=>re?tg(re):null,[re]),[xo,sa]=l.useState(null);l.useEffect(()=>{let Ee=!1;const Ze=Y?.path;if(!Ze||Wa){sa(null);return}return sa(null),P2(Ze).then(ft=>{Ee||sa(ft)}),()=>{Ee=!0}},[Y?.path,Wa]),l.useEffect(()=>{!Yn&&F==="edit"&&G("view")},[Yn,F]);const Ka="openchamber:files:md-viewer-mode",bo="openchamber:files:html-viewer-mode",yo="openchamber:files:json-viewer-mode";l.useEffect(()=>{const Ee=Y?.path;if(!Ee)return;const Ze=Fn?"view":"edit";G(q.current[Ee]??Ze);let ft=Fn?"preview":"edit";try{const Zt=localStorage.getItem(Ka);(Zt==="preview"||Zt==="edit")&&(ft=Zt)}catch{}te(J.current[Ee]??ft);let jt=Fn?"preview":"edit";try{const Zt=localStorage.getItem(bo);(Zt==="preview"||Zt==="edit")&&(jt=Zt)}catch{}W(ne.current[Ee]??jt);let Ht=Fn?"tree":"text";try{const Zt=localStorage.getItem(yo);(Zt==="tree"||Zt==="text")&&(Ht=Zt)}catch{}fe(Ht)},[Y?.path,Fn]);const Fe=l.useCallback(Ee=>{const Ze=Y?.path;Ze&&(q.current[Ze]=Ee),G(Ee)},[Y?.path]),Nt=l.useCallback(Ee=>{const Ze=Y?.path;Ze&&(J.current[Ze]=Ee),te(Ee);try{localStorage.setItem(Ka,Ee)}catch{}},[Y?.path]),pt=l.useCallback(()=>Q,[Q]),Jt=l.useCallback(Ee=>{fe(Ee);try{localStorage.setItem(yo,Ee)}catch{}},[]),js=l.useCallback(Ee=>{const Ze=Y?.path;Ze&&(ne.current[Ze]=Ee),W(Ee);try{localStorage.setItem(bo,Ee)}catch{}},[Y?.path]),en=l.useCallback(()=>ue,[ue]);l.useEffect(()=>{if(!vs||!v)return;const Ee=()=>{typeof window>"u"||ds.current===null&&(ds.current=window.requestAnimationFrame(()=>{ds.current=null,es(Kr=>Kr+1)}))},Ze=(Kr,fa)=>{if(Kr.state.doc.length!==fa.length)return!1;if(fa.length===0)return!0;const Vl=Math.min(128,fa.length);if(Kr.state.sliceDoc(0,Vl)!==fa.slice(0,Vl))return!1;const lu=Math.max(0,fa.length-Vl);return Kr.state.sliceDoc(lu,fa.length)===fa.slice(lu)},ft=pn(vs.path);if(!ft){Rs(null),Ms.current={key:"",attempts:0};return}const jt=`${ft}:${vs.line}:${vs.column??1}`;if(Ms.current.key!==jt&&(Ms.current={key:jt,attempts:0}),Y?.path!==ft){if(mt)return;fn(pe(ft));return}if(ut||Ve!==ft)return;if(it||Bs){Rs(null),Ms.current={key:"",attempts:0};return}if(!Yn)return;if(F!=="edit"){G("edit");return}const Ht=St.current;if(!Ht){Ee();return}if(!Ze(Ht,lt)){Ee();return}const Zt=Math.max(1,Math.min(vs.line,Ht.state.doc.lines)),Fs=Ht.state.doc.line(Zt),Gs=Math.max(1,vs.column||1),Ln=Math.max(0,Fs.to-Fs.from),vo=Math.min(Ln,Gs-1),Ii=Fs.from+vo;if(!(Ht.state.selection.main.head===Ii)||Ms.current.attempts===0){Ms.current.attempts+=1,Ht.dispatch({selection:{anchor:Ii},effects:Hn.scrollIntoView(Ii,{y:"center"})}),Ht.focus(),Ee();return}typeof window<"u"&&window.requestAnimationFrame(()=>{const Kr=St.current;Kr&&(Kr.dispatch({selection:{anchor:Ii},effects:Hn.scrollIntoView(Ii,{y:"center"})}),Kr.focus())}),Rs(null),Ms.current={key:"",attempts:0}},[Yn,mt,lt,wt,it,ut,Bs,Ve,fn,vs,v,Y?.path,Rs,F,pe]),l.useEffect(()=>{if(!Cs||!v)return;const Ee=pn(Cs);if(!Ee){_s(null);return}if(Y?.path!==Ee){if(mt)return;fn(pe(Ee));return}if(!(ut||Ve!==Ee||it||Bs)){if(Yn&&F==="edit"){const Ze=St.current;if(!Ze)return;Ze.focus()}_s(null)}},[Yn,mt,it,ut,fn,Bs,Ve,Cs,v,Y?.path,_s,F,pe]);const mn=l.useCallback(Ee=>{if(!d||!Ee||!Ee.hasFocus||typeof window>"u")return;const Ze=window.visualViewport;if(!Ze)return;const ft=document.documentElement.clientHeight||window.innerHeight;if(Math.max(0,ft-(Ze.offsetTop+Ze.height))<=0)return;const Ht=Ee.state.selection.main.head,Zt=Ee.coordsAtPos(Ht);if(!Zt)return;const Fs=Math.round(Ze.offsetTop+Ze.height),Ln=Zt.bottom+20-Fs;Ln<=0||(Ee.scrollDOM.scrollTop+=Ln)},[d]);l.useEffect(()=>{if(!d||typeof window>"u")return;const Ee=()=>{window.requestAnimationFrame(()=>{mn(St.current)})},Ze=window.visualViewport;return Ze?.addEventListener("resize",Ee),Ze?.addEventListener("scroll",Ee,{passive:!0}),document.addEventListener("selectionchange",Ee),()=>{Ze?.removeEventListener("resize",Ee),Ze?.removeEventListener("scroll",Ee),document.removeEventListener("selectionchange",Ee)}},[d,mn]),l.useEffect(()=>{if(!Yn||F!=="edit"||d)return;const Ee=qr("open_go_to_line",Qs),Ze=ft=>{const jt=ft.target;if(jt?.closest('[role="dialog"]'))return;const Ht=!!jt?.closest(".cm-editor");jt?.closest('input, textarea, [contenteditable="true"], [role="textbox"]')&&!Ht||!document.activeElement?.closest(".cm-editor")||Uo(ft,Ee)&&(ft.preventDefault(),Pt(!0))};return window.addEventListener("keydown",Ze),()=>window.removeEventListener("keydown",Ze)},[Yn,d,Qs,F]);const br=l.useMemo(()=>{if(!Y?.path)return[ud(a)];const Ee=[ud(a)],Ze=Wa??xo;return Ze&&Ee.push(Ze),P&&Ee.push(Hn.lineWrapping),d&&Ee.push(Hn.updateListener.of(ft=>{ft.view.hasFocus&&(ft.selectionSet||ft.focusChanged||ft.viewportChanged||ft.geometryChanged)&&window.requestAnimationFrame(()=>{mn(ft.view)})})),Ee},[a,Y?.path,Wa,xo,P,d,mn]),Qn=l.useMemo(()=>({light:ee.metadata.id,dark:he.metadata.id}),[ee.metadata.id,he.metadata.id]),kn=Y?.path&&Bs?r.isDesktop?On?`data:${ju(Y.path)};utf8,${encodeURIComponent(Ye)}`:Ne:On?`data:${ju(Y.path)};utf8,${encodeURIComponent(Ye)}`:`/api/fs/raw?${new URLSearchParams({path:Y.path,...ce.allowOutsideWorkspace?{allowOutsideWorkspace:"true"}:{}}).toString()}`:"";l.useEffect(()=>{let Ee=!1;return(async()=>{if(!r.isDesktop||!Y?.path||!Bs||On){Ke("");return}nt(null),await(n.readFileBinary?n.readFileBinary(Y.path,ce).then(jt=>jt.dataUrl):Promise.resolve(Px(Y.path,"asset"))).then(jt=>{Ee||(Ke(jt),qe(Y.path))}).catch(jt=>{Ee||(Ke(""),nt(jt instanceof Error?jt.message:e("filesView.error.readFileFailed")),qe(null))}).finally(()=>{Ee||rt(!1)})})(),()=>{Ee=!0}},[n,Bs,On,r.isDesktop,Y?.path,ce,e]);const Cn=l.useCallback(()=>$s(null),[]),ki=l.useMemo(()=>Vh({drafts:Pr,editingDraftId:wn,commentText:Nn,selection:Js,isDragging:Dt,fileLabel:Y?.path??"",newWidgetId:"files-new-comment-input",mapDraftToRange:Ee=>({start:Ee.startLine,end:Ee.endLine}),onSave:rr,onCancel:()=>{An(null),gn()},onEdit:Ee=>{Vr(Ee),An({start:Ee.startLine,end:Ee.endLine})},onDelete:Ar}),[gn,Nn,Ar,wn,Pr,rr,Dt,Js,Y?.path,Vr]),Ci=l.useCallback((Ee,Ze)=>s.jsx("div",{className:"h-full",children:s.jsx(Ix,{file:{name:Ee.name,contents:Ze,lang:ui(Ee.path)||void 0},options:{disableFileHeader:!0,overflow:P?"wrap":"scroll",theme:Qn,themeType:a.metadata.variant==="dark"?"dark":"light"},className:"block h-full w-full",style:{height:"100%"}})}),[a.metadata.variant,Qn,P]),iu=({exitFullscreenOnly:Ee=!1}={})=>Y?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:[Yn&&F==="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")]}):zt&&vt==="saved"&&!dn?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")]}):dn?s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>{Dr()},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(zt?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:`${dl()}+S`}),"aria-label":e("filesView.editor.saveAria",{shortcut:`${dl()}+S`}),children:s.jsx(D,{name:"save-3",className:"size-4"})}):null,s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>Kt(Ze=>!Ze),className:xe("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",zt?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(zt?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),"aria-label":e(zt?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),children:zt?s.jsx(D,{name:"file-check-fill",className:"size-4"}):s.jsx(D,{name:"file-check",className:"size-4"})})]}),s.jsxs(Ts,{onOpenChange:z,children:[s.jsx(As,{asChild:!0,children:s.jsx(be,{variant:"ghost",size:"sm",className:"size-6 p-0 text-foreground opacity-100 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.openInDesktopApp"),"aria-label":e("filesView.editor.openInDesktopApp"),children:s.jsx(D,{name:"file-transfer",className:"size-4"})})}),s.jsxs(Ds,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[Hs.map(Ze=>s.jsxs($t,{className:"flex items-center gap-2",onClick:()=>{Ir(Ze)},children:[s.jsx(D2,{label:Ze.label,iconDataUrl:Ze.iconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:Ze.label})]},Ze.id)),ss?s.jsxs($t,{className:"flex items-center gap-2",onClick:()=>{Pn(!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]})]}),!Bs&&s.jsxs(s.Fragment,{children:[s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>A(!P),className:xe("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"})}),F==="edit"&&s.jsxs(s.Fragment,{children:[s.jsx(be,{variant:"ghost",size:"sm",onClick:Ze=>{R(!T),Ze.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"})}),s.jsx(be,{variant:"ghost",size:"sm",onClick:Ze=>{Pt(ft=>!ft),Ze.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(S2,{open:gt,onOpenChange:Pt,view:St.current,variant:"inline"})]})]}),Si&&Yn&&!hn&&!Ni&&s.jsx(cd,{currentMode:F==="view"?"preview":"edit",onToggle:()=>{Fe(F==="view"?"edit":"view")}}),(Mr||bc(Y?.path??""))&&s.jsx(cd,{currentMode:Mr?pt():en(),onToggle:()=>{bc(Y?.path??"")?js(en()==="preview"?"edit":"preview"):Nt(pt()==="preview"?"edit":"preview")}}),hn&&s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>Jt(Z==="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(Z==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),children:Z==="tree"?s.jsx(D,{name:"code-sslash",className:"size-4"}):s.jsx(D,{name:"node-tree",className:"size-4"})}),ji&&s.jsx(be,{variant:"ghost",size:"sm",onClick:async()=>{(await In(Ye)).ok?(Gt(!0),Wt.current!==null&&window.clearTimeout(Wt.current),Wt.current=window.setTimeout(()=>{Gt(!1)},1200)):H.error(e("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.copyFileContents"),"aria-label":e("filesView.editor.copyFileContents"),children:_t?s.jsx(D,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(D,{name:"clipboard",className:"size-4"})}),Bl&&s.jsx(be,{variant:"ghost",size:"sm",onClick:async()=>{(await In(Tr)).ok?(Ue(!0),We.current!==null&&window.clearTimeout(We.current),We.current=window.setTimeout(()=>{Ue(!1)},1200)):H.error(e("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.copyFilePathTitle",{path:Tr}),"aria-label":e("filesView.editor.copyFilePathTitle",{path:Tr}),children:is?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&&s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>{const Ze=n.downloadFile;Ze&&Ze(Y.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?s.jsx(be,{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"&&s.jsx(be,{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"})})]}):null,zl=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||Et(!0)},children:s.jsxs(ms,{showCloseButton:!1,className:"max-w-md",children:[s.jsxs(ys,{children:[s.jsx(hs,{children:e("filesView.unsaved.title")}),s.jsx(Ss,{children:e("filesView.unsaved.description")})]}),s.jsxs(Vs,{children:[s.jsx(be,{variant:"outline",onClick:()=>{Le()},disabled:ze,className:"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)] hover:bg-[rgb(var(--status-success)/0.2)]",children:e("filesView.unsaved.saveChanges")}),s.jsx(be,{variant:"destructive",onClick:go,children:e("filesView.unsaved.discard")})]})]})}),s.jsx("div",{className:xe("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:()=>M(!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?Y?s.jsxs(Ts,{children:[s.jsx(As,{asChild:!0,children:s.jsxs("button",{type:"button",className:"inline-flex min-w-0 max-w-full items-center gap-1 text-left typography-ui-label font-medium","aria-label":e("filesView.editor.openFilesAria"),children:[s.jsx(jr,{filePath:Y.path,extension:Y.extension,className:"size-3.5 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:Y.name}),s.jsx(D,{name:"arrow-down-s",className:"size-4 flex-shrink-0 text-muted-foreground"})]})}),s.jsx(Ds,{align:"start",className:"min-w-[16rem]",children:we.map(Ee=>{const Ze=Y?.path===Ee.path;return s.jsxs($t,{onSelect:ft=>{if(ft.target.closest("[data-close-open-file]")){ft.preventDefault();return}Ze||fn(Ee)},className:xe("flex items-center justify-between gap-2",Ze&&"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]"),children:[s.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2 truncate",children:[s.jsx(jr,{filePath:Ee.path,extension:Ee.extension,className:"size-3.5 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:Ee.name})]}),s.jsx("button",{type:"button","data-close-open-file":!0,onPointerDown:ft=>{ft.preventDefault(),ft.stopPropagation()},onClick:ft=>{ft.preventDefault(),ft.stopPropagation(),Qe(Ee.path)},className:"inline-flex size-6 items-center justify-center rounded-md text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]","aria-label":e("filesView.editor.closeFileAria",{name: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")}):we.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:Ce,className:"flex min-w-0 items-center gap-1 overflow-x-auto scrollbar-none",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:we.map(Ee=>{const Ze=Y?.path===Ee.path;return s.jsxs("div",{title:md(v,Ee.path),className:xe("group inline-flex items-center gap-1 rounded-md border px-2 py-1 typography-ui-label transition-colors whitespace-nowrap",Ze?"bg-[var(--interactive-selection)] border-[var(--primary-muted)] text-[var(--interactive-selection-foreground)]":"bg-transparent border-[var(--interactive-border)] text-[var(--surface-muted-foreground)] hover:bg-[var(--interactive-hover)] hover:text-[var(--surface-foreground)]"),children:[s.jsx(jr,{filePath:Ee.path,extension:Ee.extension,className:"size-3.5 flex-shrink-0"}),s.jsx("button",{type:"button",onClick:()=>{Ze||fn(Ee)},className:"max-w-[12rem] truncate text-left",children:Ee.name}),s.jsx("button",{type:"button",onClick:ft=>{ft.stopPropagation(),Qe(Ee.path)},className:xe("rounded-sm p-0.5 text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]",!Ze&&!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:[Y&&!T&&s.jsx("div",{ref:U,className:"absolute right-3 top-3 z-30",onMouseEnter:()=>_(!0),onMouseLeave:()=>{B.current>0||_(!1)},children:V?iu():s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>_(!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(Ns,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:Y?ut?g?s.jsx("div",{className:"p-3"}):s.jsxs("div",{className:"p-3 flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.loading")]}):it?s.jsx("div",{className:"p-3 typography-ui text-[color:var(--status-error)]",children:it}):Bs?s.jsx("div",{className:"flex h-full items-center justify-center p-3",children:s.jsx("img",{src:kn,alt:Y?.name??e("filesView.editor.imageAltFallback"),className:"max-w-full max-h-[70vh] object-contain rounded-md border border-border/30 bg-primary/10"})}):Y&&hn&&Z==="tree"?s.jsx(Ys,{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(Nv,{jsonString:Ye,maxHeight:"100%",initiallyExpandedDepth:2})})}):Y&&Mr&&pt()==="preview"?s.jsxs("div",{className:"h-full overflow-auto p-3",children:[Ye.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(Ye.length/1024)})}),s.jsx(Ys,{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(Fa,{content:Ye,className:"typography-markdown-body",stripFrontmatter:!0})})]}):Y&&Ni&&ue==="preview"?s.jsx("div",{className:"h-full overflow-hidden",children:s.jsx("iframe",{srcDoc:(()=>{const Ee=Y.path.substring(0,Y.path.lastIndexOf("/")+1);if(!Ee)return Ye;const Ze=`<base href="${r.isDesktop,Ee}">`;return Ye.replace(/<head([^>]*)>/i,`<head$1>${Ze}`)})(),className:"w-full h-full border-none",sandbox:"allow-scripts allow-same-origin allow-forms",title:e("filesView.editor.htmlPreviewTitle")})}):Y&&Si&&F==="view"?Ci(Y,lt):s.jsxs("div",{className:xe("relative h-full",Ks&&"overflow-hidden"),ref:qt,children:[s.jsx("div",{className:xe("h-full",Ks&&"invisible"),children:s.jsx(ld,{value:lt,onChange:He,readOnly:!Yn,extensions:br,className:"h-full",blockWidgets:ki,onViewReady:Ee=>{St.current=Ee,es(Ze=>Ze+1),window.requestAnimationFrame(()=>{mn(Ee)})},onViewDestroy:()=>{St.current&&(St.current=null),es(Ee=>Ee+1)},enableSearch:!0,searchOpen:T,onSearchOpenChange:R,highlightLines:Js?{start:Math.min(Js.start,Js.end),end:Math.max(Js.start,Js.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(Ee,Ze,ft)=>{if(!(ft instanceof MouseEvent)||ft.button!==0)return!1;ft.preventDefault();const jt=Ee.state.doc.lineAt(Ze.from).number;if(d&&Js&&!ft.shiftKey){const Ht=Math.min(Js.start,Js.end,jt),Zt=Math.max(Js.start,Js.end,jt);return An({start:Ht,end:Zt}),tr.current=!1,Be.current=null,Yt(!1),!0}if(tr.current=!0,Be.current=jt,Yt(!0),Js&&ft.shiftKey){const Ht=Math.min(Js.start,jt),Zt=Math.max(Js.end,jt);An({start:Ht,end:Zt})}else An({start:jt,end:jt});return!0},mouseover:(Ee,Ze,ft)=>{if(!(ft instanceof MouseEvent)||ft.buttons!==1||!tr.current||Be.current===null)return!1;const jt=Ee.state.doc.lineAt(Ze.from).number,Ht=Math.min(Be.current,jt),Zt=Math.max(Be.current,jt);return An({start:Ht,end:Zt}),Yt(!0),!1},mouseup:()=>(tr.current=!1,Be.current=null,Yt(!1),!1)}}})}),Ks&&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&&O[v]),ou=s.jsxs("section",{className:xe("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:xe("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.jsx(be,{variant:"ghost",size:"sm",onClick:()=>er("createFile",{path:h,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFileTitle"),children:s.jsx(D,{name:"file-add",className:"size-4"})}),s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>er("createFolder",{path:h,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFolderTitle"),children:s.jsx(D,{name:"folder-add",className:"size-4"})}),s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>{ma()},className:"size-8 p-0 flex-shrink-0",children:s.jsx(D,{name:"refresh",className:"size-4"})})]})}),s.jsx(Ns,{outerClassName:"flex-1 min-h-0",className:xe("py-2",d?"px-3":"px-2"),children:s.jsx("ul",{className:"flex flex-col",children:Ge?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")]}):le.length>0?le.map(Ee=>{const Ze=Y?.path===Ee.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>{fn(Ee)},className:xe("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors",Ze?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),children:[ng(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?Ws(v,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:e("filesView.state.loading")})})})]}),Yg=t==="full"&&N&&Y&&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:iu({exitFullscreenOnly:!0})}),s.jsx(Ns,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:ut?g?s.jsx("div",{className:"p-4"}):s.jsxs("div",{className:"p-4 flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(D,{name:"loader-4",className:"size-4 animate-spin"}),"Loading…"]}):it?s.jsx("div",{className:"p-4 typography-ui text-[color:var(--status-error)]",children:it}):Bs?s.jsx("div",{className:"flex h-full items-center justify-center p-4",children:s.jsx("img",{src:kn,alt:Y.name,className:"max-w-full max-h-full object-contain rounded-md border border-border/30 bg-primary/10"})}):Mr&&pt()==="preview"?s.jsxs("div",{className:"h-full overflow-auto p-4",children:[Ye.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(Ye.length/1024)})}),s.jsx(Ys,{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(Fa,{content:Ye,className:"typography-markdown-body",stripFrontmatter:!0})})]}):Si&&F==="view"?Ci(Y,lt):s.jsxs("div",{className:xe("relative h-full",Ks&&"overflow-hidden"),children:[s.jsx("div",{className:xe("h-full",Ks&&"invisible"),children:s.jsx(ld,{value:lt,onChange:He,readOnly:!Yn,extensions:br,className:"h-full",onViewReady:Ee=>{St.current=Ee,window.requestAnimationFrame(()=>{mn(Ee)})},onViewDestroy:()=>{St.current&&(St.current=null)}})}),Ks&&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(V2,{activeDialog:as,dialogData:Ls,dialogInputValue:Xs,onDialogInputChange:Vt,isDialogSubmitting:Ut,onDialogSubmit:ir,onClose:Cn,inputRef:yt}),Yg,d?I?zl:ou: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:zl})}):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:ou}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden rounded-xl border border-border/60 bg-background",children:zl})]})]})},U2=Object.freeze(Object.defineProperty({__proto__:null,FilesView:rg},Symbol.toStringTag,{value:"Module"})),Or=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},yc=(t,e)=>{const n=Or(t),r=e.replace(/\\/g,"/").replace(/^\/+/,"").replace(/\/+$/,"");return!n||n==="/"?`/${r}`:`${n}/${r}`},W2=(t,e,n)=>yc(yc(yc(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=Or(e.currentDirectory),r=Or(e.homeDirectory),a=Or(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=Or(t.trim());if(!r)return null;const a=n?e.find(o=>o.id===n)??null:null;if(a?.path){const o=Or(a.path);if(r===o||r.startsWith(`${o}/`))return{id:a.id,path:a.path}}const i=e.filter(o=>{const c=Or(o.path);return r===c||r.startsWith(`${c}/`)}).sort((o,c)=>Or(c.path).length-Or(o.path).length)[0];return i?{id:i.id,path:i.path}:null},ag=({targetPath:t=null})=>{const{t:e}=dt(),n=Lt(de=>de.currentSessionId),r=Lt(de=>de.createSession),a=Lt(de=>de.initializeNewOpenChamberSession),i=Lt(de=>de.sendMessage),o=Lt(de=>de.setCurrentSession),c=El(),d=zs(de=>de.homeDirectory),p=Ad(de=>de.planModeEnabled),m=Ps(de=>de.projects),u=Ps(de=>de.activeProjectId),f=tn(de=>de.directories),b=Zr()??"",h=Re(de=>de.setActiveMainTab),v=Re(de=>de.setSessionSwitcherOpen),x=Rn(),{isMobile:g}=nn(),{currentTheme:w}=Cr();l.useMemo(()=>th(w),[w]);const y=l.useMemo(()=>n?c.find(de=>de.id===n)??null:null,[n,c]),C=l.useMemo(()=>{const de=typeof y?.directory=="string"?y.directory:"";return Or(de||"")},[y?.directory]),k=l.useMemo(()=>Or(b||C),[b,C]),j=l.useMemo(()=>q2(k,m,u),[u,k,m]),S=l.useMemo(()=>j?f.get(j.path)?.isGitRepo===!0:!1,[j,f]),[I,M]=l.useState(null),[P,A]=l.useState(!1),[N,E]=l.useState(null),T=l.useMemo(()=>!N||!C||!d?N:G2(N,{currentDirectory:C,homeDirectory:d}),[N,C,d]),[R,V]=l.useState(""),[_,U]=l.useState(null),B=l.useMemo(()=>T&&T.split("/").pop()||e("planView.file.defaultName"),[T,e]),z=l.useMemo(()=>R.trim()&&Tb(R).title||e("planView.title.default"),[R,e]),K=l.useMemo(()=>z.trim()||e("planView.title.default"),[z,e]),[F,G]=l.useState(!1),[Q,te]=l.useState(!1),[Z,fe]=l.useState("edit"),ue=l.useRef(null),[W,q]=l.useState(null),J=l.useRef(null),ne=l.useRef(null),ee="openchamber:plan:md-viewer-mode";l.useEffect(()=>{try{const de=localStorage.getItem(ee);if(!de)return;const O=JSON.parse(de);(O==="preview"||O==="edit")&&fe(O)}catch{}},[]);const he=l.useCallback(de=>{fe(de);try{localStorage.setItem(ee,JSON.stringify(de))}catch{}},[]),ke=l.useRef(!1),oe=l.useRef(null),[ge,me]=l.useState(!1);l.useEffect(()=>{const de=()=>{ke.current=!1,oe.current=null,me(!1)};return document.addEventListener("mouseup",de),()=>document.removeEventListener("mouseup",de)},[]);const ye=l.useCallback((de,O)=>{const L=de.split(`
54
+ `),$=Math.max(1,O.start),je=Math.min(L.length,O.end);return $>je?"":L.slice($-1,je).join(`
55
+ `)},[]),ie=Kd({source:"plan",fileLabel:B,language:N&&ui(N)||"markdown",getCodeForRange:de=>ye(R,xl(de)),toStoreRange:de=>({startLine:de.start,endLine:de.end}),fromDraftRange:de=>({start:de.startLine,end:de.endLine})}),{drafts:ve,commentText:X,editingDraftId:Se,setSelection:Ae,saveComment:pe,cancel:we,reset:Ie,startEdit:Y,deleteDraft:re}=ie;l.useEffect(()=>{q(null),Ie()},[R,Ie]),l.useEffect(()=>{Ae(W)},[W,Ae]);const Pe=l.useCallback(()=>{q(null),we()},[we]),ce=l.useCallback((de,O)=>{O&&q(O),pe(de,O??W??void 0),q(null)},[W,pe]);l.useEffect(()=>{if(!W)return;const de=L=>{const $=L.target;$.closest('[data-comment-card="true"]')||$.closest('[data-comment-input="true"]')||$.closest(".oc-block-widget")||$.closest(".cm-gutterElement")||$.closest("[data-sonner-toast]")||$.closest("[data-sonner-toaster]")||(q(null),we())},O=window.setTimeout(()=>{document.addEventListener("click",de)},100);return()=>{window.clearTimeout(O),document.removeEventListener("click",de)}},[we,Se,g,W]);const Ce=l.useMemo(()=>{const de=[ud(w)],O=tg(N||"plan.md");return O&&de.push(O),de.push(Hn.lineWrapping),de},[w,N]);l.useEffect(()=>{if(!p&&!t){E(null),V(""),G(!1);return}let de=!1;const O=async $=>{if(x.files?.readFile)return(await x.files.readFile($))?.content??"";const je=Xn()?.files;if(je?.readFile)return(await je.readFile($,{optional:!0}))?.content??"";const ae=await fetch(`/api/fs/read?path=${encodeURIComponent($)}&optional=true`,{cache:"no-store"});if(!ae.ok)throw new Error(`Failed to read plan file (${ae.status})`);return ae.text()};return(async()=>{if(E(null),V(""),U(null),t){G(!0);try{const $=await O(t);if(de)return;E(t),V($)}catch{if(de)return;E(null),V("")}finally{de||G(!1)}return}if(!y?.slug||!y?.time?.created||!C){E(null),V("");return}G(!0);try{const $=W2(C,y.time.created,y.slug),je=H2(K2(y.time.created,y.slug),d||null);let ae=null,_e=null;try{_e=await O($),ae=$}catch{}if(!ae)try{_e=await O(je),ae=je}catch{}if(de)return;if(!ae||_e===null){E(null),V("");return}E(ae),V(_e)}catch{if(de)return;E(null),V("")}finally{de||G(!1)}})(),()=>{de=!0}},[d,p,x.files,C,y?.slug,y?.time?.created,t]),l.useEffect(()=>{if(!N){U(null);return}const de=window.setTimeout(async()=>{U(null);try{if(x.files?.writeFile){if(!(await x.files.writeFile(N,R))?.success)throw new Error(e("planView.error.writeFailed"))}else{const O=await fetch("/api/fs/write",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:N,content:R})});if(!O.ok)throw new Error(e("planView.error.writePlanFileFailed",{status:O.status}))}}catch(O){U(O instanceof Error?O.message:e("planView.error.saveFailed"))}},350);return()=>{window.clearTimeout(de)}},[R,N,x.files,e]),l.useEffect(()=>()=>{ue.current!==null&&window.clearTimeout(ue.current)},[]);const Te=l.useCallback(()=>{h("chat"),v(!1)},[h,v]),$e=l.useCallback(async de=>{if(!j||!I)return;const O=await yn(I.action==="improve"?"plan.improve.visible":"plan.implement.visible",{plan_title:K}),$=[{synthetic:!0,text:await yn(I.action==="improve"?"plan.improve.instructions":"plan.implement.instructions",{plan_title:K,plan_path:N??""})}];A(!0);try{Te();let je=null,ae=j.path;if(I.target==="worktree"){if(!S)return;const le=await Qf(j.path,Xf());if(!le?.id)return;je=le.id,ae=null}else{const le=await r(void 0,j.path,null);if(!le?.id)return;je=le.id,ae=le.directory??j.path,a(le.id,bt.getState().agents??[])}if(!je)return;const _e=Pl.getState();_e.saveSessionModelSelection(je,de.providerID,de.modelID),de.agent.trim()&&(_e.saveSessionAgentSelection(je,de.agent),_e.saveAgentModelForSession(je,de.agent,de.providerID,de.modelID),_e.saveAgentModelVariantForSession(je,de.agent,de.providerID,de.modelID,de.variant||void 0)),o(je,ae),await i(O,de.providerID,de.modelID,de.agent.trim()||void 0,void 0,void 0,$,de.variant||void 0),M(null)}finally{A(!1)}},[S,r,j,a,I,N,Te,i,K,o]),De=l.useMemo(()=>Vh({drafts:ve,editingDraftId:Se,commentText:X,selection:W,isDragging:ge,fileLabel:B,newWidgetId:"plan-new-comment-input",mapDraftToRange:de=>({start:de.startLine,end:de.endLine}),onSave:ce,onCancel:Pe,onEdit:de=>{Y(de),q({start:de.startLine,end:de.endLine})},onDelete:re}),[X,re,Se,Pe,ce,ge,W,ve,B,Y]);return s.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden bg-background",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2 border-b border-border/40 px-3 py-1.5 flex-shrink-0",children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"typography-ui-label font-medium truncate",children:z}),_?s.jsx("div",{className:"typography-micro text-[color:var(--status-error)] truncate",title:_,children:e("planView.error.saveFailed")}):null]}),N?s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs(Ts,{children:[s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(As,{asChild:!0,children:s.jsx(be,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0","aria-label":e("planView.actions.improvePlanAria"),disabled:!R.trim(),children:s.jsx(D,{name:"loop-right-ai",className:"size-4"})})})}),s.jsx(At,{sideOffset:8,children:e("planView.actions.improve")})]}),s.jsxs(Ds,{align:"end",children:[s.jsx($t,{onClick:()=>M({action:"improve",target:"session"}),children:e("planView.actions.sendToNewSession")}),s.jsx($t,{onClick:()=>M({action:"improve",target:"worktree"}),disabled:!S,children:e("planView.actions.sendToNewWorktreeSession")})]})]}),s.jsxs(Ts,{children:[s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(As,{asChild:!0,children:s.jsx(be,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0","aria-label":e("planView.actions.implementPlanAria"),disabled:!R.trim(),children:s.jsx(D,{name:"code-ai",className:"size-4"})})})}),s.jsx(At,{sideOffset:8,children:e("planView.actions.implement")})]}),s.jsxs(Ds,{align:"end",children:[s.jsx($t,{onClick:()=>M({action:"implement",target:"session"}),children:e("planView.actions.sendToNewSession")}),s.jsx($t,{onClick:()=>M({action:"implement",target:"worktree"}),disabled:!S,children:e("planView.actions.sendToNewWorktreeSession")})]})]}),s.jsx(cd,{currentMode:Z,onToggle:()=>he(Z==="preview"?"edit":"preview")}),s.jsx(be,{variant:"ghost",size:"sm",onClick:async()=>{(await In(R)).ok&&(te(!0),ue.current!==null&&window.clearTimeout(ue.current),ue.current=window.setTimeout(()=>{te(!1)},1200))},className:"h-5 w-5 p-0",title:e("planView.actions.copyPlanContents"),"aria-label":e("planView.actions.copyPlanContents"),children:Q?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(Mh,{open:I!==null,onOpenChange:de=>{!de&&!P&&M(null)},target:I?.target??"session",projectDirectory:j?.path??null,submitting:P,onConfirm:$e}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 relative",children:s.jsx(Ns,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:F?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:Z==="preview"?s.jsx("div",{className:"h-full overflow-auto p-3",children:s.jsx(Ys,{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(Fa,{content:R,className:"typography-markdown-body"})})}):s.jsx("div",{className:"relative h-full",ref:ne,children:s.jsx(ld,{value:R,onChange:V,readOnly:!1,className:"h-full",extensions:Ce,onViewReady:de=>{J.current=de},onViewDestroy:()=>{J.current=null},blockWidgets:De,highlightLines:W?{start:Math.min(W.start,W.end),end:Math.max(W.start,W.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(de,O,L)=>{if(!(L instanceof MouseEvent)||L.button!==0)return!1;L.preventDefault();const $=de.state.doc.lineAt(O.from).number;if(g&&W&&!L.shiftKey){const je=Math.min(W.start,W.end,$),ae=Math.max(W.start,W.end,$);return q({start:je,end:ae}),ke.current=!1,oe.current=null,me(!1),!0}if(ke.current=!0,oe.current=$,me(!0),W&&L.shiftKey){const je=Math.min(W.start,$),ae=Math.max(W.end,$);q({start:je,end:ae})}else q({start:$,end:$});return!0},mouseover:(de,O,L)=>{if(!(L instanceof MouseEvent)||L.buttons!==1||!ke.current||oe.current===null)return!1;const $=de.state.doc.lineAt(O.from).number,je=Math.min(oe.current,$),ae=Math.max(oe.current,$);return q({start:je,end:ae}),me(!0),!1},mouseup:()=>(ke.current=!1,oe.current=null,me(!1),!1)}}})})})})})})]})},J2=Object.freeze(Object.defineProperty({__proto__:null,PlanView:ag},Symbol.toStringTag,{value:"Module"})),pd={input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:0},Qo={user:0,assistant:0,tool:0,other:0},wa=t=>typeof t!="number"||!Number.isFinite(t)||t<0?0:t,Ym=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{...pd,total:wa(n)};if(!n||typeof n!="object")return pd;const r=n,a=wa(r.input),i=wa(r.output),o=wa(r.reasoning),c=wa(r.cache?.read),d=wa(r.cache?.write);return{input:a,output:i,reasoning:o,cacheRead:c,cacheWrite:d,total:a+i+o+c+d}},Y2=(...t)=>{for(const e of t)if(typeof e=="string"&&e.trim().length>0)return e;return""},cr=t=>typeof t=="string"?t.length:typeof t=="number"||typeof t=="boolean"?String(t).length:Array.isArray(t)?t.reduce((e,n)=>e+cr(n),0):t&&typeof t=="object"?Object.values(t).reduce((e,n)=>e+cr(n),0):0,Q2=(t,e)=>{const n=t,r=typeof n.type=="string"?n.type:"";if(r==="reasoning")return{...Qo,assistant:cr(n.text)+cr(n.content)};const a=Y2(n.text,n.content,n.value,n.source?.value,n.source?.text?.value);return r==="tool"||e==="tool"?{user:0,assistant:0,tool:cr(n.input)+cr(n.output)+cr(n.error)+cr(n.call?.input)+cr(n.call?.output)+cr(n.call?.error)+cr(n.raw)+Math.round(cr(n.metadata)*.25)+Math.round(cr(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}},Qm=(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=uo(t.info);return e.isUser?"user":e.role==="assistant"?"assistant":e.role==="tool"?"tool":"other"},Z2=(t,e)=>{if(t.length===0)return{...Qo};const n=t.reduce((r,a)=>{const i=X2(a);let o={...Qo};for(const c of a.parts)o=Qm(o,Q2(c,i));return Qm(r,o)},{...Qo});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)}},Qa=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=st.c(199),{t:e}=dt(),{currentTheme:n}=Cr();let r;t[0]!==n?(r=th(n),t[0]=n,t[1]=r):r=t[1];const a=r;let i;t[2]===Symbol.for("react.memo_cache_sentinel")?(i={},t[2]=i):i=t[2];const[o,c]=l.useState(i),[d,p]=l.useState(null),m=l.useRef(null),u=Lt(iS),f=El(),b=Mb(u??""),h=bt(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],l.useEffect(v,x);let g,w;t[6]===Symbol.for("react.memo_cache_sentinel")?(g=()=>()=>{m.current!==null&&(window.clearTimeout(m.current),m.current=null)},w=[],t[6]=g,t[7]=w):(g=t[6],w=t[7]),l.useEffect(g,w);let y;t[8]===Symbol.for("react.memo_cache_sentinel")?(y=async(ht,vt)=>{(await In(vt)).ok?(p(ht),m.current!==null&&window.clearTimeout(m.current),m.current=window.setTimeout(()=>{p(zt=>zt===ht?null:zt),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 j=k;let S,I,M,P,A;if(t[12]!==h||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 vt=null;for(let zt=S.length-1;zt>=0;zt=zt-1,zt){const Kt=S[zt];if(Ym(Kt).total>0){vt=Kt;break}}M=vt?Ym(vt):pd,P=S.reduce(uS,0);const ns=vt?.info??null;I=rS(h,ns?.providerID||"",ns?.modelID||""),t[12]=h,t[13]=b,t[14]=S,t[15]=I,t[16]=M,t[17]=P,t[18]=A}else S=t[14],I=t[15],M=t[16],P=t[17],A=t[18];const N=I,E=N.contextLimit,T=E&&E>0?Math.min(999,M.total/E*100):0;let R;if(t[21]!==b){const ht=[...b].reverse().find(mS)?.info?.system||"";R=Z2(b,ht),t[21]=b,t[22]=R}else R=t[22];const V=R,_=V.user,U=V.assistant,B=V.tool,z=Math.max(0,M.input-_-U-B),K=_+U+B+z,F=b[0]?.info?.time?.created,G=b.length>0?b[b.length-1]?.info?.time?.created:null;let Q;t[23]!==j?.title||t[24]!==e?(Q=j?.title||e("contextSidebar.session.untitled"),t[23]=j?.title,t[24]=e,t[25]=Q):Q=t[25];const te=j?.time?.created??F??null,Z=G??j?.time?.created??null;let fe;t[26]!==U||t[27]!==z||t[28]!==B||t[29]!==_?(fe={user:_,assistant:U,tool:B,other:z},t[26]=U,t[27]=z,t[28]=B,t[29]=_,t[30]=fe):fe=t[30];let ue;t[31]!==S.length||t[32]!==K||t[33]!==E||t[34]!==N||t[35]!==b.length||t[36]!==Q||t[37]!==te||t[38]!==Z||t[39]!==fe||t[40]!==M||t[41]!==P||t[42]!==T||t[43]!==A.length?(ue={sessionTitle:Q,messagesCount:b.length,userMessagesCount:A.length,assistantMessagesCount:S.length,createdAt:te,lastActivityAt:Z,providerModel:N,tokenBreakdown:M,usagePercent:T,totalAssistantCost:P,contextLimit:E,breakdown:fe,breakdownTotal:K},t[31]=S.length,t[32]=K,t[33]=E,t[34]=N,t[35]=b.length,t[36]=Q,t[37]=te,t[38]=Z,t[39]=fe,t[40]=M,t[41]=P,t[42]=T,t[43]=A.length,t[44]=ue):ue=t[44];const W=ue;if(!u){let ht;t[45]!==e?(ht=e("contextSidebar.empty.openSession"),t[45]=e,t[46]=ht):ht=t[46];let vt;return t[47]!==ht?(vt=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]=vt):vt=t[48],vt}let q;t[49]!==e?(q=e("contextSidebar.breakdown.user"),t[49]=e,t[50]=q):q=t[50];let J;t[51]!==q||t[52]!==W.breakdown.user?(J={key:"user",label:q,value:W.breakdown.user,color:"var(--status-success)"},t[51]=q,t[52]=W.breakdown.user,t[53]=J):J=t[53];let ne;t[54]!==e?(ne=e("contextSidebar.breakdown.assistant"),t[54]=e,t[55]=ne):ne=t[55];let ee;t[56]!==ne||t[57]!==W.breakdown.assistant?(ee={key:"assistant",label:ne,value:W.breakdown.assistant,color:"var(--primary-base)"},t[56]=ne,t[57]=W.breakdown.assistant,t[58]=ee):ee=t[58];let he;t[59]!==e?(he=e("contextSidebar.breakdown.toolCalls"),t[59]=e,t[60]=he):he=t[60];let ke;t[61]!==he||t[62]!==W.breakdown.tool?(ke={key:"tool",label:he,value:W.breakdown.tool,color:"var(--status-warning)"},t[61]=he,t[62]=W.breakdown.tool,t[63]=ke):ke=t[63];let oe;t[64]!==e?(oe=e("contextSidebar.breakdown.other"),t[64]=e,t[65]=oe):oe=t[65];let ge;t[66]!==oe||t[67]!==W.breakdown.other?(ge={key:"other",label:oe,value:W.breakdown.other,color:"var(--surface-muted-foreground)"},t[66]=oe,t[67]=W.breakdown.other,t[68]=ge):ge=t[68];let me;t[69]!==J||t[70]!==ee||t[71]!==ke||t[72]!==ge?(me=[J,ee,ke,ge],t[69]=J,t[70]=ee,t[71]=ke,t[72]=ge,t[73]=me):me=t[73];const ye=me;let ie;t[74]!==W.sessionTitle?(ie=s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:W.sessionTitle}),t[74]=W.sessionTitle,t[75]=ie):ie=t[75];let ve;t[76]!==W.providerModel.modelName||t[77]!==W.providerModel.providerName?(ve=s.jsxs("span",{children:[W.providerModel.providerName," / ",W.providerModel.modelName]}),t[76]=W.providerModel.modelName,t[77]=W.providerModel.providerName,t[78]=ve):ve=t[78];let X;t[79]!==W.createdAt?(X=W.createdAt&&s.jsxs(s.Fragment,{children:[s.jsx("span",{children:"·"}),s.jsx("span",{children:tS(W.createdAt)})]}),t[79]=W.createdAt,t[80]=X):X=t[80];let Se;t[81]!==ve||t[82]!==X?(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:[ve,X]}),t[81]=ve,t[82]=X,t[83]=Se):Se=t[83];let Ae;t[84]!==ie||t[85]!==Se?(Ae=s.jsxs("div",{className:"mb-6",children:[ie,Se]}),t[84]=ie,t[85]=Se,t[86]=Ae):Ae=t[86];let pe;t[87]!==e?(pe=e("contextSidebar.section.context"),t[87]=e,t[88]=pe):pe=t[88];let we;t[89]!==pe?(we=s.jsx("span",{className:"typography-micro text-muted-foreground",children:pe}),t[89]=pe,t[90]=we):we=t[90];let Ie;t[91]!==W.tokenBreakdown.total?(Ie=Qa(W.tokenBreakdown.total),t[91]=W.tokenBreakdown.total,t[92]=Ie):Ie=t[92];let Y;t[93]!==W.contextLimit?(Y=W.contextLimit?` / ${Qa(W.contextLimit)}`:"",t[93]=W.contextLimit,t[94]=Y):Y=t[94];let re;t[95]!==Ie||t[96]!==Y?(re=s.jsxs("span",{className:"typography-micro tabular-nums text-muted-foreground/70",children:[Ie,Y]}),t[95]=Ie,t[96]=Y,t[97]=re):re=t[97];let Pe;t[98]!==we||t[99]!==re?(Pe=s.jsxs("div",{className:"flex items-baseline justify-between",children:[we,re]}),t[98]=we,t[99]=re,t[100]=Pe):Pe=t[100];let ce;t[101]!==W.usagePercent?(ce=W.usagePercent>0&&s.jsx("div",{className:"rounded-full transition-all duration-300",style:{width:`${Math.max(.5,W.usagePercent)}%`,backgroundColor:W.usagePercent>80?"var(--status-warning)":"var(--primary-base)"}}),t[101]=W.usagePercent,t[102]=ce):ce=t[102];let Ce;t[103]!==ce?(Ce=s.jsx("div",{className:"mt-2.5 flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:ce}),t[103]=ce,t[104]=Ce):Ce=t[104];let Te;t[105]!==e||t[106]!==W.usagePercent?(Te=e("contextSidebar.context.percentUsed",{percent:W.usagePercent.toFixed(1)}),t[105]=e,t[106]=W.usagePercent,t[107]=Te):Te=t[107];let $e;t[108]!==Te?($e=s.jsx("div",{className:"mt-1.5 typography-micro font-medium tabular-nums text-foreground/80",children:Te}),t[108]=Te,t[109]=$e):$e=t[109];let De;t[110]!==Pe||t[111]!==Ce||t[112]!==$e?(De=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[Pe,Ce,$e]}),t[110]=Pe,t[111]=Ce,t[112]=$e,t[113]=De):De=t[113];let de;t[114]!==e?(de=e("contextSidebar.stats.messages"),t[114]=e,t[115]=de):de=t[115];let O;t[116]!==W.messagesCount?(O=Qa(W.messagesCount),t[116]=W.messagesCount,t[117]=O):O=t[117];let L;t[118]!==de||t[119]!==O?(L={label:de,value:O},t[118]=de,t[119]=O,t[120]=L):L=t[120];let $;t[121]!==e?($=e("contextSidebar.stats.user"),t[121]=e,t[122]=$):$=t[122];let je;t[123]!==W.userMessagesCount?(je=Qa(W.userMessagesCount),t[123]=W.userMessagesCount,t[124]=je):je=t[124];let ae;t[125]!==$||t[126]!==je?(ae={label:$,value:je},t[125]=$,t[126]=je,t[127]=ae):ae=t[127];let _e;t[128]!==e?(_e=e("contextSidebar.stats.assistant"),t[128]=e,t[129]=_e):_e=t[129];let le;t[130]!==W.assistantMessagesCount?(le=Qa(W.assistantMessagesCount),t[130]=W.assistantMessagesCount,t[131]=le):le=t[131];let Me;t[132]!==_e||t[133]!==le?(Me={label:_e,value:le},t[132]=_e,t[133]=le,t[134]=Me):Me=t[134];let Ge;t[135]!==e?(Ge=e("contextSidebar.stats.cost"),t[135]=e,t[136]=Ge):Ge=t[136];let at;t[137]!==W.totalAssistantCost?(at=eS(W.totalAssistantCost),t[137]=W.totalAssistantCost,t[138]=at):at=t[138];let Ye;t[139]!==Ge||t[140]!==at?(Ye={label:Ge,value:at},t[139]=Ge,t[140]=at,t[141]=Ye):Ye=t[141];let Xe;t[142]!==L||t[143]!==ae||t[144]!==Me||t[145]!==Ye?(Xe=[L,ae,Me,Ye],t[142]=L,t[143]=ae,t[144]=Me,t[145]=Ye,t[146]=Xe):Xe=t[146];const ut=Xe;let rt;t[147]!==ut?(rt=s.jsx("div",{className:"mb-5 grid grid-cols-2 gap-2",children:ut.map(pS)}),t[147]=ut,t[148]=rt):rt=t[148];let it;t[149]!==e?(it=e("contextSidebar.section.lastAssistantMessage"),t[149]=e,t[150]=it):it=t[150];let nt;t[151]!==it?(nt=s.jsx("div",{className:"typography-micro text-muted-foreground",children:it}),t[151]=it,t[152]=nt):nt=t[152];let Ne;t[153]!==e||t[154]!==W.tokenBreakdown.cacheRead||t[155]!==W.tokenBreakdown.cacheWrite||t[156]!==W.tokenBreakdown.input||t[157]!==W.tokenBreakdown.output||t[158]!==W.tokenBreakdown.reasoning?(Ne=s.jsx("div",{className:"mt-2.5 grid grid-cols-3 gap-x-4 gap-y-2.5",children:[{label:e("contextSidebar.tokens.input"),value:W.tokenBreakdown.input},{label:e("contextSidebar.tokens.output"),value:W.tokenBreakdown.output},{label:e("contextSidebar.tokens.reasoning"),value:W.tokenBreakdown.reasoning},{label:e("contextSidebar.tokens.cacheRead"),value:W.tokenBreakdown.cacheRead},{label:e("contextSidebar.tokens.cacheWrite"),value:W.tokenBreakdown.cacheWrite}].map(fS)}),t[153]=e,t[154]=W.tokenBreakdown.cacheRead,t[155]=W.tokenBreakdown.cacheWrite,t[156]=W.tokenBreakdown.input,t[157]=W.tokenBreakdown.output,t[158]=W.tokenBreakdown.reasoning,t[159]=Ne):Ne=t[159];let Ke;t[160]!==nt||t[161]!==Ne?(Ke=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[nt,Ne]}),t[160]=nt,t[161]=Ne,t[162]=Ke):Ke=t[162];let Ve;t[163]!==ye||t[164]!==W.breakdownTotal?(Ve=s.jsx("div",{className:"flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:ye.map(ht=>ht.value<=0||W.breakdownTotal<=0?null:s.jsx("div",{style:{width:`${ht.value/W.breakdownTotal*100}%`,backgroundColor:ht.color}},ht.key))}),t[163]=ye,t[164]=W.breakdownTotal,t[165]=Ve):Ve=t[165];let qe;t[166]!==ye||t[167]!==W.breakdownTotal?(qe=s.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-x-4 gap-y-1",children:ye.map(ht=>{const vt=W.breakdownTotal>0?ht.value/W.breakdownTotal*100:0;return s.jsxs("div",{className:"inline-flex items-center gap-1.5",children:[s.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{backgroundColor:ht.color}}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70",children:[ht.label," ",s.jsxs("span",{className:"tabular-nums",children:[vt.toFixed(0),"%"]})]})]},ht.key)})}),t[166]=ye,t[167]=W.breakdownTotal,t[168]=qe):qe=t[168];let lt;t[169]!==Ve||t[170]!==qe?(lt=s.jsxs("div",{className:"mb-6",children:[Ve,qe]}),t[169]=Ve,t[170]=qe,t[171]=lt):lt=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]!==o||t[178]!==b||t[179]!==a||t[180]!==e){let ht;t[182]!==d||t[183]!==o||t[184]!==a||t[185]!==e?(ht=vt=>{const ns=uo(vt.info).role,zt=o[vt.info.id]===!0,Kt=d===vt.info.id,mt=vt.info.time?.created??null,Et=zt?JSON.stringify({info:vt.info,parts:vt.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":zt,onClick:()=>{c(rs=>({...rs,[vt.info.id]:rs[vt.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(ns)}),s.jsx("span",{className:"min-w-0 truncate typography-micro text-muted-foreground",children:vt.info.id})]}),s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:sS(mt)})]})}),zt&&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:rs=>{rs.stopPropagation(),C(vt.info.id,Et)},"aria-label":e(Kt?"contextSidebar.actions.copied":"contextSidebar.actions.copyJson"),title:e(Kt?"contextSidebar.actions.copied":"contextSidebar.actions.copy"),children:Kt?s.jsx(D,{name:"check",className:"size-3.5"}):s.jsx(D,{name:"file-copy",className:"size-3.5"})})}),s.jsx(Ax,{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:Et})]})})]},vt.info.id)},t[182]=d,t[183]=o,t[184]=a,t[185]=e,t[186]=ht):ht=t[186],et=[...b].reverse().map(ht),t[176]=d,t[177]=o,t[178]=b,t[179]=a,t[180]=e,t[181]=et}else et=t[181];let yt;t[187]!==et?(yt=s.jsx("div",{className:"mt-2.5 space-y-1",children:et}),t[187]=et,t[188]=yt):yt=t[188];let Rt;t[189]!==ze||t[190]!==yt?(Rt=s.jsxs("div",{children:[ze,yt]}),t[189]=ze,t[190]=yt,t[191]=Rt):Rt=t[191];let kt;return t[192]!==Ae||t[193]!==De||t[194]!==rt||t[195]!==Ke||t[196]!==lt||t[197]!==Rt?(kt=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:[Ae,De,rt,Ke,lt,Rt]})}),t[192]=Ae,t[193]=De,t[194]=rt,t[195]=Ke,t[196]=lt,t[197]=Rt,t[198]=kt):kt=t[198],kt};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 uo(t.info).role==="assistant"}function dS(t){return uo(t.info).isUser}function uS(t,e){const n=wa(e.info.cost);return t+n}function mS(t){return uo(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:Qa(t.value)})]},t.label)}const hS=360,gS=1400,ig=600,xS=24,Xm=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",fd=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"},og=({pageUrl:t,viewport:e,devicePixelRatio:n,target:r,screenshotAttached:a,intro:i})=>{const o=r.text.trim(),c=Object.entries(r.attributes).map(([b,h])=>`${b}="${h}"`).join(" "),d=r.computedStyle,p=r.bounds,m=r.center,u=i.replace(/[.:]+$/g,""),f=r.ancestry.map(b=>b.selectorPart).join(" > ");return[`${u}:`,`Page: ${t||"preview"}`,`Viewport: ${e.width}x${e.height}, DPR ${n}`,`Screenshot: ${a?"attached":"not attached"}`,`Element: ${r.tag}`,o?`Text: ${o}`:null,`- Selector: ${r.selector}`,`- Path: ${r.path}`,f?`- Ancestry: ${f}`:null,c?`- Attributes: ${c}`:null,`- Bounds: x=${Math.round(p.x)}, y=${Math.round(p.y)}, width=${Math.round(p.width)}, height=${Math.round(p.height)}`,`- Center: x=${Math.round(m.x)}, y=${Math.round(m.y)}`,`Styles: display=${d.display}; position=${d.position}; font=${d.fontWeight} ${d.fontSize} / ${d.lineHeight} ${d.fontFamily}; color=${d.color}; background=${d.backgroundColor}; z-index=${d.zIndex}`].filter(b=>typeof b=="string").join(`
56
+ `)},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 o=Math.max(1,i.naturalWidth||a.width||Math.floor(r.width)),c=Math.max(1,i.naturalHeight||a.height||Math.floor(r.height)),p=Math.min(1,1200/o),m=document.createElement("canvas");m.width=Math.floor(o*p),m.height=Math.floor(c*p);const u=m.getContext("2d");if(!u)return null;u.scale(p,p),u.drawImage(i,0,0,o,c);const f=o/Math.max(1,r.width),b=c/Math.max(1,r.height);u.fillStyle="rgba(37, 99, 235, 0.28)",u.strokeStyle="rgb(37, 99, 235)",u.lineWidth=Math.max(2,2*f),u.fillRect(e.bounds.x*f,e.bounds.y*b,e.bounds.width*f,e.bounds.height*b),u.strokeRect(e.bounds.x*f,e.bounds.y*b,e.bounds.width*f,e.bounds.height*b);const h=await new Promise(v=>m.toBlob(v,"image/jpeg",.82));return h?new File([h],`preview-annotation-${Date.now()}.jpg`,{type:"image/jpeg"}):null}catch(r){return console.warn("[preview] failed to capture annotation screenshot:",r),null}return null},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},Zm=t=>Number.isFinite(t)?Math.min(gS,Math.max(hS,Math.round(t))):ig,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 jS(t.mode,e)},kS=t=>{if(t.mode==="file")return t.targetPath?s.jsx(jr,{filePath:t.targetPath,className:"h-3.5 w-3.5"}):void 0;if(t.mode==="diff")return s.jsx(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
+ });`,vc=`(() => {
141
+ if (typeof window.__openchamberDesktopBrowserCancelInspect === 'function') {
142
+ window.__openchamberDesktopBrowserCancelInspect();
143
+ return;
144
+ }
145
+ const overlay = document.getElementById('__openchamber_desktop_browser_overlay');
146
+ if (overlay) overlay.remove();
147
+ })()`,wc=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 o=new Image;await new Promise((x,g)=>{o.onload=()=>x(),o.onerror=()=>g(new Error("Failed to load desktop browser screenshot")),o.src=`data:image/jpeg;base64,${t}`});const c=Math.max(1,o.naturalWidth||e),d=Math.max(1,o.naturalHeight||n),m=Math.min(1,1200/c),u=document.createElement("canvas");u.width=Math.floor(c*m),u.height=Math.floor(d*m);const f=u.getContext("2d");if(!f)return null;f.scale(m,m),f.drawImage(o,0,0,c,d);const b=c/Math.max(1,r||c),h=d/Math.max(1,a||d);f.fillStyle="rgba(37, 99, 235, 0.14)",f.strokeStyle="rgb(37, 99, 235)",f.lineWidth=Math.max(2,2*b),f.fillRect(i.bounds.x*b,i.bounds.y*h,i.bounds.width*b,i.bounds.height*h),f.strokeRect(i.bounds.x*b,i.bounds.y*h,i.bounds.width*b,i.bounds.height*h);const v=await new Promise(x=>u.toBlob(x,"image/jpeg",.82));return v?new File([v],`browser-annotation-${Date.now()}.jpg`,{type:"image/jpeg"}):null}catch{return null}},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)}...`,Na=new Map,TS=3e4,MS=t=>{const e=Na.get(t);return e?e.expiresAt-Date.now()<=TS?(Na.delete(t),null):e:null},ES=({rawUrl:t,onNavigate:e})=>{const{t:n}=dt(),{currentTheme:r}=Cr(),[a,i]=l.useReducer(oe=>oe+1,0),[o,c]=l.useReducer(oe=>oe+1,0),[d,p]=l.useState({status:"idle"}),m=l.useRef(null),u=l.useRef(1),[f,b]=l.useState(!1),[h,v]=l.useState(!1),[x,g]=l.useState("all"),[w,y]=l.useState([]),[C,k]=l.useState(!1),[j,S]=l.useState(null),I=Lt(oe=>oe.currentSessionId),M=Lt(oe=>oe.newSessionDraft?.open),P=Za(oe=>oe.addDraft),A=Ra(oe=>oe.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,T=N?N.hostname==="0.0.0.0"?new URL(N.toString().replace("0.0.0.0","127.0.0.1")):N:null,R=T?T.toString():"",V=r.metadata.variant;l.useEffect(()=>{if(!R||!E){p({status:"idle"});return}const oe=MS(R);if(oe){p({status:"ready",proxyBasePath:oe.proxyBasePath,expiresAt:oe.expiresAt});return}let ge=!1;return p({status:"loading"}),(async()=>{try{const me=await fetch("/api/preview/targets",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({url:R})});if(!me.ok){Na.delete(R);const X=await me.json().catch(()=>({})),Se=typeof X?.error=="string"?X.error:`HTTP ${me.status}`;ge||p({status:"error",message:Se});return}const ye=await me.json(),ie=typeof ye.proxyBasePath=="string"?ye.proxyBasePath:"",ve=typeof ye.expiresAt=="number"?ye.expiresAt:0;if(!ie){Na.delete(R),ge||p({status:"error",message:n("contextPanel.preview.proxyError")});return}Na.set(R,{proxyBasePath:ie,expiresAt:ve}),ge||p({status:"ready",proxyBasePath:ie,expiresAt:ve})}catch(me){if(Na.delete(R),!ge){const ye=me instanceof Error?me.message:String(me);p({status:"error",message:ye})}}})(),()=>{ge=!0}},[E,o,n,R]);const _=T&&(T.protocol==="http:"||T.protocol==="https:")?T.toString():"",U=E&&d.status==="ready"&&T?(()=>{const oe=T.pathname||"/",ge=new URLSearchParams(T.search);ge.set("ocPreview",String(a));const me=ge.toString(),ye=T.hash||"";return`${d.proxyBasePath}${oe}${me?`?${me}`:""}${ye}`})():"",B=E?U:_,z=B||_,K=E&&(d.status==="loading"||d.status==="idle"),F=E&&d.status==="error",G=l.useCallback(oe=>{const ge=I??(M?"draft":null);if(!ge){H.error(n("contextPanel.preview.inspect.attachNoSession"));return}const me=t||B||"",ye=typeof window<"u"?{width:window.innerWidth,height:window.innerHeight}:{width:0,height:0},ie=typeof window<"u"?window.devicePixelRatio:1;(async()=>{let ve=!1;try{const X=m.current,Se=X?await yS(X,oe):null;Se&&(await A(Se),ve=!0)}catch{ve=!1}P({sessionKey:ge,source:"preview-annotation",fileLabel:me||"preview",startLine:1,endLine:1,code:og({pageUrl:me,viewport:ye,devicePixelRatio:ie,target:oe,screenshotAttached:ve,intro:n("contextPanel.preview.inspect.attachAnnotation")}),language:"markdown",text:""}),H.success(n("contextPanel.preview.inspect.attached"))})()},[A,P,I,B,M,t,n]);l.useEffect(()=>{b(!1),y([]),v(!1),g("all"),k(!1),S(null),u.current=1},[B]),l.useEffect(()=>{const oe=m.current?.contentWindow;!f||!oe||oe.postMessage({source:"openchamber-preview-parent",version:1,type:"set-inspect-mode",enabled:C},window.location.origin)},[f,C]),l.useEffect(()=>{const oe=m.current?.contentWindow;!f||!oe||oe.postMessage({source:"openchamber-preview-parent",version:1,type:"set-color-scheme",scheme:V},window.location.origin)},[f,V]),l.useEffect(()=>{if(!C||typeof window>"u")return;const oe=ge=>{ge.key==="Escape"&&(ge.preventDefault(),ge.stopImmediatePropagation(),k(!1))};return window.addEventListener("keydown",oe,!0),()=>window.removeEventListener("keydown",oe,!0)},[C]),l.useEffect(()=>{if(!E||typeof window>"u")return;const oe=ye=>{if(typeof ye=="string")return ye;if(ye==null)return"";try{return JSON.stringify(ye)}catch{return String(ye)}},ge=ye=>{const ie=u.current;u.current+=1,y(ve=>{const X=[...ve,{...ye,id:ie}];return X.length>Xm?X.slice(X.length-Xm):X})},me=ye=>{if(ye.source!==m.current?.contentWindow)return;const ie=ye.data;if(!(!ie||ie.source!=="openchamber-preview-bridge"||ie.version!==1)){if(ie.type==="ready"){b(!0);return}if(ie.type==="console"){const ve=ie.level==="error"||ie.level==="warn"||ie.level==="info"||ie.level==="debug"?ie.level:"log",X=Array.isArray(ie.args)?ie.args.map(oe).filter(Boolean):[];ge({level:ve,message:X.join(" "),ts:typeof ie.ts=="number"?ie.ts:Date.now()});return}if(ie.type==="runtime-error"){const ve=oe(ie.filename),X=typeof ie.line=="number"?ie.line:null,Se=typeof ie.column=="number"?ie.column:null,Ae=ve?`${ve}${X!==null?`:${X}${Se!==null?`:${Se}`:""}`:""}`:"",pe=oe(ie.stack);ge({level:"runtime",message:oe(ie.message)||n("contextPanel.preview.console.runtimeError"),details:[Ae,pe].filter(Boolean).join(`
148
+ `),ts:typeof ie.ts=="number"?ie.ts:Date.now()});return}if(ie.type==="resource-error"){const ve=oe(ie.tag)||"resource",X=oe(ie.url);ge({level:"resource",message:X?`${ve}: ${X}`:ve,details:oe(ie.outerHTML),ts:typeof ie.ts=="number"?ie.ts:Date.now()});return}if(ie.type==="hover"){S(fd(ie.target)?ie.target:null);return}if(ie.type==="select"&&fd(ie.target)){S(ie.target),k(!1),G(ie.target);return}if(ie.type==="navigate-preview"){const ve=typeof ie.url=="string"?ie.url:"",X=ie.navigation==="external"?"external":"proxy";if(ve&&X==="external"){qn(ve);return}ve&&e(ve)}}};return window.addEventListener("message",me),()=>{window.removeEventListener("message",me)}},[G,E,e,n]);const Q=w.filter(oe=>oe.level==="error"||oe.level==="runtime"||oe.level==="resource").length,te=w.filter(oe=>bS(oe,x)),Z=l.useCallback(()=>{const oe=[`Preview URL: ${t||B||""}`,`Events: ${w.length}`,""].join(`
149
+ `),ge=w.map(me=>{const ye=new Date(me.ts).toISOString(),ie=me.details?`
150
+ ${me.details}`:"";return`[${ye}] [${me.level}] ${me.message}${ie}`}).join(`
151
+ `);In(`${oe}${ge}`).then(me=>{me.ok?H.success(n("contextPanel.preview.console.copied")):H.error(n("contextPanel.preview.console.copyFailed"))})},[w,B,t,n]),fe=l.useCallback(()=>{const oe=I??(M?"draft":null);if(!oe){H.error(n("contextPanel.preview.console.attachNoSession"));return}const ge=[`Preview URL: ${t||B||""}`,`Events: ${w.length}`,""].join(`
152
+ `),me=w.map(ye=>{const ie=new Date(ye.ts).toISOString(),ve=ye.details?`
153
+ ${ye.details}`:"";return`[${ie}] [${ye.level}] ${ye.message}${ve}`}).join(`
154
+ `);P({sessionKey:oe,source:"preview-console",fileLabel:t||B||"preview",startLine:1,endLine:Math.max(1,w.length),code:`${ge}${me}`,language:"text",text:n("contextPanel.preview.console.attachAnnotation")}),H.success(n("contextPanel.preview.console.attached"))},[P,w,I,B,M,t,n]),[ue,W]=l.useState("unknown"),q=l.useRef(0),J=l.useRef(0),ne=15e3;l.useEffect(()=>{if(!U){W("unknown"),q.current=0,J.current=0;return}let oe=!1;return q.current||(q.current=Date.now(),J.current=0),W("unknown"),(async()=>{const me=await(async()=>{try{return await fetch(U,{method:"GET",credentials:"include",cache:"no-store",redirect:"manual"})}catch{return null}})();if(oe)return;if(!me){W("unreachable");return}if(me.status===403||me.status===404){Na.delete(R),p({status:"loading"}),c();return}if(me.status!==502){W("reachable");return}const ye=q.current||Date.now();if(Date.now()-ye<ne){W("starting"),J.current+=1;const ve=J.current,X=Math.min(2e3,250*Math.pow(2,Math.min(4,ve)));setTimeout(()=>{oe||i()},X).unref?.();return}W("unreachable")})(),()=>{oe=!0}},[U,a,R]);const ee=E&&d.status==="ready"&&(ue==="unknown"||ue==="starting"),he=E&&d.status==="ready"&&ue==="unreachable",ke=l.useCallback(oe=>{if(!E||d.status!=="ready"||typeof window>"u")return;const ge=oe.currentTarget.contentWindow;if(ge)try{const me=ge.location;if(me.origin!==window.location.origin||me.pathname.startsWith(d.proxyBasePath))return;const ye=`${d.proxyBasePath}${me.pathname}${me.search}${me.hash}`;ge.location.replace(ye)}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:z||t,children:z||t||n("contextPanel.preview.empty")}),s.jsx(be,{type:"button",size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>i(),title:n("contextPanel.preview.actions.reload"),"aria-label":n("contextPanel.preview.actions.reload"),disabled:!B,children:s.jsx(D,{name:"refresh",className:"h-3.5 w-3.5"})}),s.jsx(be,{type:"button",size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{_&&qn(_)},title:n("contextPanel.preview.actions.openExternal"),"aria-label":n("contextPanel.preview.actions.openExternal"),disabled:!_,children:s.jsx(D,{name:"external-link",className:"h-3.5 w-3.5"})}),E?s.jsx(be,{type:"button",size:"sm",variant:C?"secondary":"ghost",className:"h-7 gap-1 px-2",onClick:()=>k(oe=>!oe),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(be,{type:"button",size:"sm",variant:h?"secondary":"ghost",className:"h-7 gap-1 px-2",onClick:()=>v(oe=>!oe),title:n(f?"contextPanel.preview.console.open":"contextPanel.preview.console.waiting"),"aria-label":n(f?"contextPanel.preview.console.open":"contextPanel.preview.console.waiting"),disabled:!f&&w.length===0,children:[s.jsx(D,{name:"terminal-box",className:"h-3.5 w-3.5"}),Q>0?s.jsx("span",{className:"typography-micro text-status-error",children:Q}):null]}):null]}),s.jsxs("div",{className:"relative min-h-0 flex-1 bg-background",children:[ee?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")})]}):he?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center text-sm text-muted-foreground",children:[s.jsx("div",{children:n("contextPanel.preview.upstreamUnreachable")}),s.jsx("div",{className:"text-xs opacity-70",children:n("contextPanel.preview.upstreamUnreachableHint")}),s.jsx(be,{type:"button",size:"sm",variant:"outline",onClick:()=>i(),children:n("contextPanel.preview.actions.retry")})]}):B&&(!E||ue==="reachable")?s.jsxs("div",{className:"relative h-full w-full",children:[s.jsx("iframe",{ref:m,src:B,title:n("contextPanel.preview.iframeTitle"),className:"h-full w-full border-0",style:{colorScheme:V},onLoad:ke,sandbox:E?"allow-scripts allow-same-origin allow-forms allow-popups allow-downloads":"allow-scripts allow-forms"},`${B}:${a}`),C&&j?s.jsx("div",{className:"pointer-events-none absolute rounded-sm border-2 border-[var(--interactive-focus-ring)] bg-[var(--interactive-focus-ring)]/35",style:{left:j.bounds.x,top:j.bounds.y,width:j.bounds.width,height:j.bounds.height},children:s.jsxs("div",{className:"absolute -top-6 left-0 max-w-64 truncate rounded bg-[var(--surface-elevated)] px-2 py-0.5 typography-micro text-foreground shadow",children:[j.tag,j.text?` · ${j.text}`:""]})}):null]}):K?s.jsx("div",{className:"flex h-full items-center justify-center px-6 text-sm text-muted-foreground",children:n("contextPanel.preview.loading")}):F?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 px-6 text-sm text-muted-foreground",children:[s.jsx("div",{children:n("contextPanel.preview.proxyError")}),d.status==="error"?s.jsx("div",{className:"text-center text-xs opacity-70",children:d.message}):null]}):s.jsx("div",{className:"flex h-full items-center justify-center px-6 text-sm text-muted-foreground",children:n("contextPanel.preview.invalidUrl")}),h?s.jsxs("div",{className:"absolute inset-x-3 bottom-3 z-10 max-h-[45%] overflow-hidden rounded-xl border border-border/70 bg-[var(--surface-elevated)] shadow-lg",children:[s.jsxs("div",{className:"flex items-center justify-between border-b border-border/50 px-3 py-2",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:n("contextPanel.preview.console.title")}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(be,{type:"button",size:"xs",variant:"ghost",onClick:fe,disabled:w.length===0,children:n("contextPanel.preview.console.attach")}),s.jsx(be,{type:"button",size:"xs",variant:"ghost",onClick:Z,disabled:w.length===0,children:n("contextPanel.preview.console.copy")}),s.jsx(be,{type:"button",size:"xs",variant:"ghost",onClick:()=>y([]),disabled:w.length===0,children:n("contextPanel.preview.console.clear")})]})]}),s.jsx("div",{className:"flex items-center gap-1 border-b border-border/30 px-3 py-1.5",children:["all","errors","warnings","logs"].map(oe=>s.jsx(be,{type:"button",size:"xs",variant:x===oe?"secondary":"ghost",onClick:()=>g(oe),children:n(oe==="all"?"contextPanel.preview.console.filter.all":oe==="errors"?"contextPanel.preview.console.filter.errors":oe==="warnings"?"contextPanel.preview.console.filter.warnings":"contextPanel.preview.console.filter.logs")},oe))}),s.jsx("div",{className:"max-h-64 overflow-auto p-2 typography-code text-xs",children:w.length===0?s.jsx("div",{className:"px-2 py-3 text-muted-foreground",children:n("contextPanel.preview.console.empty")}):te.length===0?s.jsx("div",{className:"px-2 py-3 text-muted-foreground",children:n("contextPanel.preview.console.noFilteredEvents")}):te.map(oe=>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:xe("shrink-0 uppercase",oe.level==="error"||oe.level==="runtime"||oe.level==="resource"?"text-status-error":oe.level==="warn"?"text-status-warning":"text-muted-foreground"),children:oe.level}),s.jsx("span",{className:"min-w-0 break-words text-foreground",children:oe.message})]})},oe.id))})]}):null]})]})},RS=({initialUrl:t,directory:e,tabID:n})=>{const{t:r}=dt(),a=l.useRef(null),i=Re(M=>M.setContextPanelTabTargetPath),o=wc(t),c=o!=="about:blank"?o:"",[d,p]=l.useState(c),[m,u]=l.useState(c),[f,b]=l.useState(!1),[h,v]=l.useState(!0),x=l.useRef(null),g=h,w=l.useCallback(M=>{!M||M==="about:blank"||!e||!n||i(e,n,M)},[e,n,i]),y=Lt(M=>M.currentSessionId),C=Lt(M=>M.newSessionDraft?.open),k=Za(M=>M.addDraft),j=Ra(M=>M.addAttachedFile);l.useEffect(()=>{const M=a.current;if(!M)return;const P=()=>{try{const R=M.getURL();R&&R!=="about:blank"&&(u(R),p(R),w(R))}catch{}},A=R=>{const V=R.detail;typeof V?.url=="string"&&V.url&&(u(V.url),p(V.url),w(V.url))},N=()=>{x.current&&clearTimeout(x.current),x.current=setTimeout(()=>v(!0),200)},E=()=>{x.current&&clearTimeout(x.current),v(!1),P()},T=R=>{const V=R.detail;if(V?.disposition==="new-window"||V?.disposition==="foreground-tab"||V?.disposition==="background-tab"){R.preventDefault();const _=a.current;typeof _?.loadURL=="function"&&V.url&&_.loadURL(V.url)}};M.addEventListener("did-navigate",A),M.addEventListener("did-navigate-in-page",A),M.addEventListener("did-start-loading",N),M.addEventListener("did-stop-loading",E),M.addEventListener("new-window",T);try{M.isLoading()||(v(!1),P())}catch{}return()=>{x.current&&clearTimeout(x.current),M.removeEventListener("did-navigate",A),M.removeEventListener("did-navigate-in-page",A),M.removeEventListener("did-start-loading",N),M.removeEventListener("did-stop-loading",E),M.removeEventListener("new-window",T)}},[w]),l.useEffect(()=>{const M=setTimeout(()=>v(!1),3e4);return()=>clearTimeout(M)},[]),l.useEffect(()=>{if(!f)return;const M=P=>{if(P.key!=="Escape")return;P.preventDefault(),P.stopImmediatePropagation(),b(!1);const A=a.current;try{A?.executeJavaScript?.(vc).catch(()=>{})}catch{}};return window.addEventListener("keydown",M,!0),()=>window.removeEventListener("keydown",M,!0)},[f]),l.useEffect(()=>{const M=a.current;return()=>{try{const P=M?.getURL?.();P&&P!=="about:blank"&&i(e,n,P)}catch{}try{M?.executeJavaScript?.(vc).catch(()=>{})}catch{}}},[e,n,i]);const S=l.useCallback(M=>{const P=a.current;if(typeof P?.loadURL!="function")return;const A=wc(M);try{P.loadURL(A)}catch{}},[]),I=l.useCallback(()=>{const M=a.current;if(M){if(f){b(!1);try{M.executeJavaScript?.(vc).catch(()=>{})}catch{}return}b(!0),M.executeJavaScript?.(IS,!0).then(async P=>{if(b(!1),!P||!fd(P))return;const A=y??(C?"draft":null);if(!A){H.error(r("contextPanel.preview.inspect.attachNoSession"));return}const N=typeof M.getWebContentsId=="function"?M.getWebContentsId():null;if(N==null)return;const E=await Eb("desktop_browser_capture_page",{webContentsId:N}),T=await M.executeJavaScript?.("({ width: window.innerWidth, height: window.innerHeight })",!0).catch(()=>null),R=Number.isFinite(T?.width)?T.width:E.width,V=Number.isFinite(T?.height)?T.height:E.height,_=await PS(E.base64,E.width,E.height,R,V,P),U=!!_;_&&await j(_),k({sessionKey:A,source:"preview-annotation",fileLabel:m||"browser",startLine:1,endLine:1,code:og({pageUrl:m,viewport:{width:R,height:V},devicePixelRatio:window.devicePixelRatio||1,target:P,screenshotAttached:U,intro:r("contextPanel.preview.inspect.attachAnnotationWithScreenshot")}),language:"markdown",text:""}),H.success(r("contextPanel.preview.inspect.attached"))}).catch(()=>b(!1))}},[j,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(be,{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(be,{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(be,{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:M=>{M.preventDefault(),S(d)},children:s.jsx("input",{value:d,onChange:M=>p(M.target.value),className:"h-7 w-full rounded-md border border-border/50 bg-[var(--surface-elevated)] px-2 typography-micro text-foreground outline-none focus:border-[var(--interactive-focus-ring)]","aria-label":r("contextPanel.browser.addressAria")})}),s.jsx(be,{type:"button",variant:f?"secondary":"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:I,title:r("contextPanel.preview.inspect.toggle"),"aria-label":r("contextPanel.preview.inspect.toggle"),children:s.jsx(D,{name:"cursor",className:"h-3.5 w-3.5"})}),s.jsx(be,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{qn(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:wc(t),partition:"persist:openchamber-browser",style:{width:"100%",height:"100%",border:"none"}}),(!m||m==="about:blank")&&!h?s.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-6 bg-background p-6 text-center",children:[s.jsx(Ld,{width:140,height:140,className:"opacity-20"}),s.jsx("span",{className:"typography-ui-header text-muted-foreground",children:r("contextPanel.browser.empty")})]}):null,g?s.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/70 typography-micro text-muted-foreground",children:r("common.loading")}):null]})]})},FS=()=>{const{t}=dt(),e=Zr()??"",n=l.useMemo(()=>vS(e),[e]),r=Re(ee=>n?ee.contextPanelByDirectory[n]:void 0),a=Re(ee=>ee.closeContextPanel),i=Re(ee=>ee.closeContextPanelTab),o=Re(ee=>ee.toggleContextPanelExpanded),c=Re(ee=>ee.setContextPanelWidth),d=Re(ee=>ee.setActiveContextPanelTab),p=Re(ee=>ee.reorderContextPanelTabs),m=Re(ee=>ee.setPendingDiffFile),u=Tn(ee=>ee.setSelectedPath),f=Re(ee=>ee.openContextPreview),{themeMode:b,lightThemeId:h,darkThemeId:v,currentTheme:x}=Cr(),g=l.useMemo(()=>r?.tabs??[],[r?.tabs]),w=g.find(ee=>ee.id===r?.activeTabId)??g[g.length-1]??null,y=!!(r?.isOpen&&w),C=!!(y&&r?.expanded),k=Zm(r?.width??ig),[j,S]=l.useState(!1),I=l.useRef(0),M=l.useRef(k),P=l.useRef(null),A=l.useRef(null),N=l.useRef(null),E=l.useRef(new Map),T=l.useRef(!1);l.useEffect(()=>{if(!y||T.current){T.current=y;return}const ee=window.requestAnimationFrame(()=>{N.current?.focus({preventScroll:!0})});return T.current=!0,()=>window.cancelAnimationFrame(ee)},[y]);const R=l.useCallback(ee=>{const he=N.current;he&&he.style.setProperty("--oc-context-panel-width",`${ee}px`)},[]),V=l.useCallback(ee=>{if(!(!y||C||!n)){try{ee.currentTarget.setPointerCapture(ee.pointerId)}catch{}A.current=ee.pointerId,S(!0),I.current=ee.clientX,M.current=k,P.current=k,R(k),ee.preventDefault()}},[R,n,C,y,k]),_=l.useCallback(ee=>{if(!j||A.current!==ee.pointerId)return;const he=I.current-ee.clientX,ke=Zm(M.current+he);P.current!==ke&&(P.current=ke,R(ke))},[R,j]),U=l.useCallback(ee=>{if(A.current!==ee.pointerId||!n)return;try{ee.currentTarget.releasePointerCapture(ee.pointerId)}catch{}const he=P.current??k;S(!1),A.current=null,P.current=null,c(n,he)},[n,c,k]);l.useEffect(()=>{j||(P.current=null)},[j]);const B=l.useCallback(()=>{n&&a(n)},[a,n]),z=l.useCallback(()=>{n&&o(n)},[n,o]),K=l.useCallback(ee=>{ee.key==="Escape"&&(ee.preventDefault(),ee.stopPropagation(),B())},[B]);l.useEffect(()=>{if(!(!n||!w)){if(w.mode==="file"&&w.targetPath){u(n,w.targetPath);return}w.mode==="diff"&&w.targetPath&&m(w.targetPath)}},[w,n,m,u]);const F=w?.mode==="chat"?w.id:null,G=l.useCallback(()=>{if(typeof window>"u")return;const ee={themeMode:b,lightThemeId:h,darkThemeId:v,currentTheme:x};for(const he of E.current.values()){const ke=he.contentWindow;if(!ke)continue;const oe=ke.__openchamberApplyThemeSync;if(typeof oe=="function")try{oe(ee);continue}catch{}ke.postMessage({type:"openchamber:theme-sync",payload:ee},window.location.origin)}},[x,v,h,b]),Q=l.useCallback(()=>{if(!(typeof window>"u"))for(const[ee,he]of E.current.entries()){const ke=he.contentWindow;if(!ke)continue;const oe={visible:F===ee},ge=ke.__openchamberSetEmbeddedVisibility;if(typeof ge=="function")try{ge(oe);continue}catch{}ke.postMessage({type:"openchamber:embedded-visibility",payload:oe},window.location.origin)}},[F]);l.useLayoutEffect(()=>{g.some(he=>he.mode==="chat")&&(G(),Q())},[v,h,Q,G,g,b]);const te=l.useMemo(()=>g.map(ee=>{const he=SS(ee,t),ke=DS(he,xS),oe=wS(ee.targetPath,e);return{id:ee.id,label:ke,icon:kS(ee),title:oe?`${he}: ${oe}`:he,closeLabel:t("contextPanel.tab.closeTabAria",{label:ke})}}),[e,t,g]),Z=w?.mode==="diff"?s.jsx(Zh,{hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!0,hideFileSelector:!0,pinSelectedFileHeaderToTopOnNavigate:!0,showOpenInEditorAction:!0}):w?.mode==="context"?s.jsx(aS,{}):w?.mode==="plan"?s.jsx(ag,{targetPath:w.targetPath}):w?.mode==="preview"?s.jsx(ES,{rawUrl:w.targetPath??"",onNavigate:ee=>f(e,ee)}):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")})]}),fe=l.useMemo(()=>g.filter(ee=>ee.mode==="chat"),[g]),ue=l.useMemo(()=>g.filter(ee=>ee.mode==="browser"),[g]),W=l.useMemo(()=>g.some(ee=>ee.mode==="file"),[g]),q=w?.mode==="file",J=s.jsxs("header",{className:"flex h-10 items-stretch border-b border-transparent",children:[s.jsx($r,{items:te,activeId:w?.id??null,onSelect:ee=>{n&&d(n,ee)},onClose:ee=>{n&&i(n,ee)},onReorder:(ee,he)=>{n&&p(n,ee,he)},layoutMode:"scrollable",variant:"default"}),s.jsxs("div",{className:"flex items-center gap-1 px-1.5",children:[s.jsx(be,{type:"button",variant:"ghost",size:"sm",onClick:z,className:"h-7 w-7 p-0",title:t(C?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),"aria-label":t(C?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),children:C?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(be,{type:"button",variant:"ghost",size:"sm",onClick:B,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(!y)return null;const ne=C?{"--oc-context-panel-width":"100%",width:"100%",minWidth:"100%",maxWidth:"100%"}:{width:"var(--oc-context-panel-width)",minWidth:"var(--oc-context-panel-width)",maxWidth:"var(--oc-context-panel-width)","--oc-context-panel-width":`${j?P.current??k:k}px`};return s.jsxs("aside",{ref:N,"data-context-panel":"true",tabIndex:-1,className:xe("flex min-h-0 flex-col overflow-hidden bg-background",!C&&"border-l border-border/40",C?"absolute inset-0 z-20 min-w-0":"relative h-full flex-shrink-0",j?"transition-none":"transition-[width] duration-200 ease-in-out"),onKeyDownCapture:K,style:ne,children:[!C&&s.jsx("div",{className:xe("absolute left-0 top-0 z-20 h-full w-[3px] cursor-col-resize transition-colors hover:bg-[var(--interactive-border)]/80",j&&"bg-[var(--interactive-border)]"),onPointerDown:V,onPointerMove:_,onPointerUp:U,onPointerCancel:U,role:"separator","aria-orientation":"vertical","aria-label":t("contextPanel.actions.resizePanelAria")}),J,s.jsxs("div",{className:xe("relative min-h-0 flex-1 overflow-hidden",j&&"pointer-events-none"),children:[W?s.jsx("div",{className:xe("absolute inset-0",q?"block":"hidden"),children:s.jsx(rg,{mode:"editor-only"})}):null,fe.map(ee=>{const he=CS(ee.dedupeKey);if(!he)return null;const ke=AS(he,n||null,ee.readOnly);return ke?s.jsx("iframe",{ref:oe=>{if(!oe){E.current.delete(ee.id);return}E.current.set(ee.id,oe)},src:ke,title:t("contextPanel.iframe.sessionChatTitle",{sessionID:he}),className:xe("absolute inset-0 h-full w-full border-0 bg-background",F===ee.id?"block":"hidden"),onLoad:()=>{G(),Q()}},ee.id):null}),ue.map(ee=>s.jsx("div",{className:xe("absolute inset-0",w?.mode!=="browser"&&"hidden"),children:s.jsx(RS,{initialUrl:ee.targetPath??"",directory:n,tabID:ee.id})},ee.id)),w?.mode!=="chat"&&!q&&w?.mode!=="browser"?Z:null]})]})},Qd=[{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 zi(t){const e=t.trim().toLowerCase();return Qd.find(n=>n.slug===e)??null}function lg(t){const e=(t??"").trim().toLowerCase();if(!e)return"home";const n=OS[e];if(n)return n;const r=zi(e);return r?r.slug:"home"}const cg=t=>t.replace(/[-_]/g," ").replace(/\b\w/g,e=>e.toUpperCase()),ho=t=>{const e=st.c(39),{className:n}=t,{t:r}=dt(),a=Ps(LS),i=Ps($S),o=Ps(_S),c=on();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 T;e[2]!==i||e[3]!==p?(T=p.find(R=>R.id===i)??p[0],e[2]=i,e[3]=p,e[4]=T):T=e[4],m=T}const u=m;if(c||p.length===0)return null;let f;e[5]!==u||e[6]!==r?(f=u?.label&&u.label.trim().length>0?u.label:u?.path.split("/").filter(Boolean).pop()||u?.path||r("settings.shared.projectSelector.fallbackProject"),e[5]=u,e[6]=r,e[7]=f):f=e[7];const b=f;let h;e[8]!==b?(h=cg(b),e[8]=b,e[9]=h):h=e[9];const v=h;let x;e[10]!==n?(x=xe(n),e[10]=n,e[11]=x):x=e[11];let g;e[12]!==r?(g=r("settings.shared.projectSelector.switchProjectAria"),e[12]=r,e[13]=g):g=e[13];let w;e[14]!==r?(w=r("settings.shared.projectSelector.switchProjectTitle"),e[14]=r,e[15]=w):w=e[15];let y,C;e[16]===Symbol.for("react.memo_cache_sentinel")?(y=xe("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 j;e[20]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(D,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[20]=j):j=e[20];let S;e[21]!==k||e[22]!==g||e[23]!==w?(S=s.jsx(As,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":g,title:w,className:y,children:[C,k,j]})}),e[21]=k,e[22]=g,e[23]=w,e[24]=S):S=e[24];const I=u?.id??"";let M;e[25]!==o?(M=T=>{T&&o(T)},e[25]=o,e[26]=M):M=e[26];let P;e[27]!==p?(P=p.map(zS),e[27]=p,e[28]=P):P=e[28];let A;e[29]!==I||e[30]!==M||e[31]!==P?(A=s.jsx(Ds,{align:"start",className:"w-auto",children:s.jsx(ll,{value:I,onValueChange:M,children:P})}),e[29]=I,e[30]=M,e[31]=P,e[32]=A):A=e[32];let N;e[33]!==S||e[34]!==A?(N=s.jsxs(Ts,{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 zS(t){const e=t.label?.trim()?t.label.trim():t.path.split("/").filter(Boolean).pop()||t.path,n=cg(e);return s.jsx(cl,{value:t.id,children:s.jsx("span",{className:"min-w-0 truncate typography-ui",children:n})},t.id)}function VS(t,e){return`opencode:sidebar-group:${t}:${e}`}const hd=t=>{const e=st.c(33),{label:n,count:r,storageKey:a,defaultExpanded:i,children:o}=t,c=i===void 0?!0:i;let d;e[0]!==n||e[1]!==a?(d=VS(a,n),e[0]=n,e[1]=a,e[2]=d):d=e[2];const p=d,m=l.useId();let u;e[3]!==c||e[4]!==p?(u=()=>{try{const A=localStorage.getItem(p);if(A!==null)return A==="true"}catch{}return c},e[3]=c,e[4]=p,e[5]=u):u=e[5];const[f,b]=Oe.useState(u);let h,v;e[6]!==f||e[7]!==p?(h=()=>{try{localStorage.setItem(p,String(f))}catch{}},v=[p,f],e[6]=f,e[7]=p,e[8]=h,e[9]=v):(h=e[8],v=e[9]),Oe.useEffect(h,v);let x;e[10]===Symbol.for("react.memo_cache_sentinel")?(x=()=>b(US),e[10]=x):x=e[10];let g;e[11]===Symbol.for("react.memo_cache_sentinel")?(g=xe("flex w-full items-center gap-1 rounded-md px-2 py-1 text-left","text-xs font-semibold uppercase tracking-wide text-muted-foreground","hover:bg-[var(--interactive-hover)] transition-colors duration-150","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50"),e[11]=g):g=e[11];const w=!f&&"-rotate-90";let y;e[12]!==w?(y=xe("h-3.5 w-3.5 flex-shrink-0 transition-transform duration-200",w),e[12]=w,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 j;e[18]!==r?(j=s.jsx("span",{className:"ml-1 tabular-nums opacity-60",children:r}),e[18]=r,e[19]=j):j=e[19];let S;e[20]!==m||e[21]!==f||e[22]!==C||e[23]!==k||e[24]!==j?(S=s.jsxs("button",{type:"button",onClick:x,"aria-expanded":f,"aria-controls":m,className:g,children:[C,k,j]}),e[20]=m,e[21]=f,e[22]=C,e[23]=k,e[24]=j,e[25]=S):S=e[25];const I=!f;let M;e[26]!==o||e[27]!==m||e[28]!==I?(M=s.jsx("div",{id:m,hidden:I,className:"mt-0.5 space-y-0.5 ml-2 pl-3 border-l-2 border-[var(--interactive-border)]",children:o}),e[26]=o,e[27]=m,e[28]=I,e[29]=M):M=e[29];let P;return e[30]!==S||e[31]!==M?(P=s.jsxs("div",{children:[S,M]}),e[30]=S,e[31]=M,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())},ep=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 o=Object.keys(i);if(o.length===1&&o[0]==="*"){r[a]=i["*"];continue}r[a]=i}return Object.keys(r).length>0?r:void 0},HS=({onItemSelect:t})=>{const{t:e}=dt(),[n,r]=l.useState(null),[a,i]=l.useState(""),[o,c]=l.useState(null),[d,p]=l.useState(null),[m,u]=l.useState(!1),[f,b]=l.useState(null),{selectedAgentName:h,agents:v,setSelectedAgent:x,setAgentDraft:g,createAgent:w,deleteAgent:y,loadAgents:C}=li(Jn(z=>({selectedAgentName:z.selectedAgentName,agents:z.agents,setSelectedAgent:z.setSelectedAgent,setAgentDraft:z.setAgentDraft,createAgent:z.createAgent,deleteAgent:z.deleteAgent,loadAgents:z.loadAgents})));l.useEffect(()=>{C()},[C]);const k="bg-background",j=()=>{const z="new-agent";let K=z,F=1;for(;v.some(G=>G.name===K);)K=`${z}-${F}`,F++;g({name:K,scope:"user"}),x(K),t?.()},S=async z=>{if(ei(z)){H.error(e("settings.agents.sidebar.toast.builtInCannotDelete"));return}c(z),p("delete")},I=async z=>{ei(z)&&(c(z),p("reset"))},M=()=>{c(null),p(null)},P=async()=>{if(!o||!d)return;u(!0),await y(o.name)?(d==="delete"?H.success(e("settings.agents.sidebar.toast.agentDeleted",{name:o.name})):H.success(e("settings.agents.sidebar.toast.agentReset",{name:o.name})),M()):d==="delete"?H.error(e("settings.agents.sidebar.toast.deleteFailed")):H.error(e("settings.agents.sidebar.toast.resetFailed")),u(!1)},A=z=>{const K=z.name;let F=1,G=`${K}-copy`;for(;v.some(fe=>fe.name===G);)F++,G=`${K}-copy-${F}`;const Q=z,te=z.model?.providerID&&z.model?.modelID?`${z.model.providerID}/${z.model.modelID}`:null,Z=z;g({name:G,scope:Q.scope||"user",description:z.description,model:te,temperature:z.temperature,top_p:z.topP,prompt:z.prompt,mode:z.mode,permission:ep(z.permission),disable:Z.disable}),x(G)},N=z=>{i(z.name),r(z)},E=async()=>{if(!n)return;const z=a.trim().replace(/\s+/g,"-");if(!z){H.error(e("settings.agents.sidebar.toast.agentNameRequired"));return}if(z===n.name){r(null);return}if(v.some(Q=>Q.name===z)){H.error(e("settings.agents.sidebar.toast.agentExists"));return}const K=n.model?.providerID&&n.model?.modelID?`${n.model.providerID}/${n.model.modelID}`:null,F=n;await w({name:z,description:n.description,model:K,temperature:n.temperature,top_p:n.topP,prompt:n.prompt,mode:n.mode,permission:ep(n.permission),disable:F.disable,scope:F.scope})?await y(n.name)?(H.success(`Agent renamed to "${z}"`),x(z)):H.error(e("settings.agents.sidebar.toast.removeOldAfterRenameFailed")):H.error(e("settings.agents.sidebar.toast.renameFailed")),r(null)},T=z=>{switch(z){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}},R=v.filter(z=>!Rb(z)),V=R.filter(ei),_=R.filter(z=>!ei(z)),{groupedCustomAgents:U,ungroupedCustomAgents:B}=Oe.useMemo(()=>{const z={},K=[];for(const G of _){const Q=G;Q.group?(z[Q.group]||(z[Q.group]=[]),z[Q.group].push(G)):K.push(G)}return{groupedCustomAgents:Object.keys(z).sort((G,Q)=>G.localeCompare(Q)).map(G=>({name:G,agents:z[G]})),ungroupedCustomAgents:K}},[_]);return s.jsxs("div",{className:xe("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(ho,{className:"mb-3"}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.agents.sidebar.total",{count:R.length})}),s.jsx(be,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:j,children:s.jsx(D,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(Ns,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:R.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(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(z=>s.jsx(jc,{agent:z,isSelected:h===z.name,onSelect:()=>{x(z.name),t?.()},onReset:()=>I(z),onDuplicate:()=>A(z),getAgentModeIcon:T,isMenuOpen:f===z.name,onMenuOpenChange:K=>b(K?z.name:null)},z.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:e("settings.agents.sidebar.section.custom")}),U.map(({name:z,agents:K})=>s.jsx(hd,{label:z,count:K.length,storageKey:"agents",children:K.map(F=>s.jsx(jc,{agent:F,isSelected:h===F.name,onSelect:()=>{x(F.name),t?.()},onRename:()=>N(F),onDelete:()=>S(F),onDuplicate:()=>A(F),getAgentModeIcon:T,isMenuOpen:f===F.name,onMenuOpenChange:G=>b(G?F.name:null)},F.name))},z)),B.map(z=>s.jsx(jc,{agent:z,isSelected:h===z.name,onSelect:()=>{x(z.name),t?.()},onRename:()=>N(z),onDelete:()=>S(z),onDuplicate:()=>A(z),getAgentModeIcon:T,isMenuOpen:f===z.name,onMenuOpenChange:K=>b(K?z.name:null)},z.name))]})]})}),s.jsx(ps,{open:o!==null&&d!==null,onOpenChange:z=>{!z&&!m&&M()},children:s.jsxs(ms,{className:"max-w-md",children:[s.jsxs(ys,{children:[s.jsx(hs,{children:e(d==="delete"?"settings.agents.sidebar.dialog.deleteTitle":"settings.agents.sidebar.dialog.resetTitle")}),s.jsx(Ss,{children:d==="delete"?e("settings.agents.sidebar.dialog.deleteDescription",{name:o?.name??""}):e("settings.agents.sidebar.dialog.resetDescription",{name:o?.name??""})})]}),s.jsxs(Vs,{children:[s.jsx(be,{size:"sm",variant:"ghost",onClick:M,disabled:m,children:e("settings.common.actions.cancel")}),s.jsx(be,{size:"sm",onClick:P,disabled:m,children:e(d==="delete"?"settings.common.actions.delete":"settings.common.actions.reset")})]})]})}),s.jsx(ps,{open:n!==null,onOpenChange:z=>!z&&r(null),children:s.jsxs(ms,{children:[s.jsxs(ys,{children:[s.jsx(hs,{children:e("settings.agents.sidebar.renameDialog.title")}),s.jsx(Ss,{children:e("settings.agents.sidebar.renameDialog.description",{name:n?.name??""})})]}),s.jsx(Bt,{value:a,onChange:z=>i(z.target.value),placeholder:e("settings.agents.sidebar.renameDialog.placeholder"),className:"text-foreground placeholder:text-muted-foreground",onKeyDown:z=>{z.key==="Enter"&&E()}}),s.jsxs(Vs,{children:[s.jsx(be,{size:"sm",variant:"ghost",onClick:()=>r(null),children:e("settings.common.actions.cancel")}),s.jsx(be,{size:"sm",onClick:E,children:e("settings.common.actions.rename")})]})]})})]})},jc=t=>{const e=st.c(58),{agent:n,isSelected:r,onSelect:a,onDelete:i,onReset:o,onRename:c,onDuplicate:d,getAgentModeIcon:p,isMenuOpen:m,onMenuOpenChange:u}=t,{t:f}=dt(),b=n;let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=Zi(),e[0]=h):h=e[0];const v=h,x=r?"bg-interactive-selection":"hover:bg-interactive-hover";let g;e[1]!==x?(g=xe("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",x),e[1]=x,e[2]=g):g=e[2];let w;e[3]!==u?(w=v?void 0:K=>{K.preventDefault(),u(!0)},e[3]=u,e[4]=w):w=e[4];let y;e[5]!==n.name?(y=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n.name}),e[5]=n.name,e[6]=y):y=e[6];let 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||ei(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:ei(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 j;e[14]!==y||e[15]!==C||e[16]!==k?(j=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]=j):j=e[17];let S;e[18]!==n.description?(S=n.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n.description}),e[18]=n.description,e[19]=S):S=e[19];let I;e[20]!==a||e[21]!==j||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:[j,S]}),e[20]=a,e[21]=j,e[22]=S,e[23]=I):I=e[23];let M;e[24]===Symbol.for("react.memo_cache_sentinel")?(M=s.jsx(As,{asChild:!0,children:s.jsx(be,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(D,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[24]=M):M=e[24];let P;e[25]!==c||e[26]!==f?(P=c&&s.jsxs($t,{onClick:K=>{K.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=K=>{K.stopPropagation(),d()},e[28]=d,e[29]=A):A=e[29];let N;e[30]===Symbol.for("react.memo_cache_sentinel")?(N=s.jsx(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 T;e[33]!==A||e[34]!==E?(T=s.jsxs($t,{onClick:A,children:[N,E]}),e[33]=A,e[34]=E,e[35]=T):T=e[35];let R;e[36]!==o||e[37]!==f?(R=o&&s.jsxs($t,{onClick:K=>{K.stopPropagation(),o()},children:[s.jsx(D,{name:"restart",className:"h-4 w-4 mr-px"}),f("settings.common.actions.reset")]}),e[36]=o,e[37]=f,e[38]=R):R=e[38];let V;e[39]!==i||e[40]!==f?(V=i&&s.jsxs($t,{onClick:K=>{K.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 _;e[42]!==P||e[43]!==T||e[44]!==R||e[45]!==V?(_=s.jsxs(Ds,{align:"end",className:"w-fit min-w-20",children:[P,T,R,V]}),e[42]=P,e[43]=T,e[44]=R,e[45]=V,e[46]=_):_=e[46];let U;e[47]!==m||e[48]!==u||e[49]!==_?(U=s.jsxs(Ts,{open:m,onOpenChange:u,children:[M,_]}),e[47]=m,e[48]=u,e[49]=_,e[50]=U):U=e[50];let B;e[51]!==I||e[52]!==U?(B=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[I,U]}),e[51]=I,e[52]=U,e[53]=B):B=e[53];let z;return e[54]!==B||e[55]!==g||e[56]!==w?(z=s.jsx("div",{className:g,onContextMenu:w,children:B}),e[54]=B,e[55]=g,e[56]=w,e[57]=z):z=e[57],z};function tp(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 sp(t,e){const n=GS(e);return n<=0?t:Number(t.toFixed(n))}const En=Oe.forwardRef((t,e)=>{const n=st.c(125);let r,a,i,o,c,d,p,m,u,f,b,h,v;n[0]!==t?({value:v,onValueChange:p,min:u,max:f,step:b,className:r,containerClassName:a,onBlur:c,disabled:i,fallbackValue:o,onClear:d,emptyLabel:h,...m}=t,n[0]=t,n[1]=r,n[2]=a,n[3]=i,n[4]=o,n[5]=c,n[6]=d,n[7]=p,n[8]=m,n[9]=u,n[10]=f,n[11]=b,n[12]=h,n[13]=v):(r=n[1],a=n[2],i=n[3],o=n[4],c=n[5],d=n[6],p=n[7],m=n[8],u=n[9],f=n[10],b=n[11],h=n[12],v=n[13]);const x=u===void 0?-1/0:u,g=f===void 0?1/0:f,w=b===void 0?1:b,y=h===void 0?"—":h,{t:C}=dt();let k;n[14]!==v?(k=()=>v===void 0?"":String(v),n[14]=v,n[15]=k):k=n[15];const[j,S]=Oe.useState(k),{isMobile:I}=nn(),M=Oe.useRef(!1),P=Oe.useRef(null);let A;n[16]===Symbol.for("react.memo_cache_sentinel")?(A=()=>{if(typeof document>"u"||typeof window>"u")return;P.current?.();const Ie=Pe=>{Pe.preventDefault(),Pe.stopPropagation(),Pe.stopImmediatePropagation?.(),P.current?.()},Y=window.setTimeout(()=>{P.current?.()},700),re=()=>{window.clearTimeout(Y),document.removeEventListener("click",Ie,!0),P.current=null};P.current=re,document.addEventListener("click",Ie,!0)},n[16]=A):A=n[16];const N=A;let E,T;n[17]===Symbol.for("react.memo_cache_sentinel")?(E=()=>()=>{P.current?.()},T=[],n[17]=E,n[18]=T):(E=n[17],T=n[18]),Oe.useEffect(E,T);let R,V;n[19]!==v?(V=()=>{S(v===void 0?"":String(v))},R=[v],n[19]=v,n[20]=R,n[21]=V):(R=n[20],V=n[21]),Oe.useEffect(V,R);let _;e:{if(v!==void 0){_=v;break e}if(o!==void 0){_=o;break e}if(Number.isFinite(x)){_=x;break e}_=0}const U=_;let B;n[22]!==g||n[23]!==x||n[24]!==p||n[25]!==w?(B=Ie=>{const Y=tp(Ie,x,g);p(sp(Y,w))},n[22]=g,n[23]=x,n[24]=p,n[25]=w,n[26]=B):B=n[26];const z=B;let K;n[27]!==z||n[28]!==d?(K=Ie=>{const Y=Ie.target.value;if(S(Y),Y.trim()===""){d?.();return}const re=Number(Y);Number.isFinite(re)&&z(re)},n[27]=z,n[28]=d,n[29]=K):K=n[29];const F=K;let G;n[30]!==j||n[31]!==g||n[32]!==x||n[33]!==c||n[34]!==d||n[35]!==p||n[36]!==w||n[37]!==v?(G=Ie=>{if(j.trim()===""){d||S(v===void 0?"":String(v)),c?.(Ie);return}const Y=Number(j);if(!Number.isFinite(Y))S(v===void 0?"":String(v));else{const re=tp(Y,x,g),Pe=sp(re,w);Pe!==v&&p(Pe),S(String(Pe))}c?.(Ie)},n[30]=j,n[31]=g,n[32]=x,n[33]=c,n[34]=d,n[35]=p,n[36]=w,n[37]=v,n[38]=G):G=n[38];const Q=G,te=!!(i||U>=g),Z=!!(i||U<=x);let fe;n[39]!==U||n[40]!==z||n[41]!==Z||n[42]!==w?(fe=()=>{Z||z(U-w)},n[39]=U,n[40]=z,n[41]=Z,n[42]=w,n[43]=fe):fe=n[43];const ue=fe;let W;n[44]!==U||n[45]!==z||n[46]!==te||n[47]!==w?(W=()=>{te||z(U+w)},n[44]=U,n[45]=z,n[46]=te,n[47]=w,n[48]=W):W=n[48];const q=W;let J;if(n[49]!==r||n[50]!==a||n[51]!==Z||n[52]!==j||n[53]!==y||n[54]!==ue||n[55]!==q||n[56]!==te||n[57]!==I||n[58]!==C||n[59]!==v){J=Symbol.for("react.early_return_sentinel");e:{const Ie=re=>Pe=>{Pe.preventDefault(),Pe.stopPropagation(),M.current=!0,N(),re()},Y=re=>Pe=>{if(M.current){M.current=!1,Pe.preventDefault(),Pe.stopPropagation();return}re()};if(I){let re;n[61]!==a?(re=xe("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]=re):re=n[62];let Pe;n[63]!==C?(Pe=C("numberInput.actions.decreaseAria"),n[63]=C,n[64]=Pe):Pe=n[64];const ce=Ie(ue),Ce=Y(ue),Te=!Z&&"active:bg-interactive-hover";let $e;n[65]!==Te?($e=xe("grid h-full min-h-0 w-9 place-items-center overflow-x-hidden overflow-y-hidden border-r border-border p-0 leading-none touch-none","text-muted-foreground","disabled:pointer-events-none disabled:opacity-50",Te),n[65]=Te,n[66]=$e):$e=n[66];let De;n[67]===Symbol.for("react.memo_cache_sentinel")?(De=s.jsx(D,{name:"subtract",className:"block h-4 w-4"}),n[67]=De):De=n[67];const de=s.jsx("button",{type:"button","aria-label":Pe,disabled:Z,onTouchStart:ce,onClick:Ce,className:$e,children:De});let O;n[68]!==r?(O=xe("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]=O):O=n[69];const L=v===void 0?y:j;let $;n[70]!==O||n[71]!==L?($=s.jsx("div",{className:O,"aria-live":"polite",children:L}),n[70]=O,n[71]=L,n[72]=$):$=n[72];let je;n[73]!==C?(je=C("numberInput.actions.increaseAria"),n[73]=C,n[74]=je):je=n[74];const ae=Ie(q),_e=Y(q),le=!te&&"active:bg-interactive-hover";let Me;n[75]!==le?(Me=xe("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",le),n[75]=le,n[76]=Me):Me=n[76];let Ge;n[77]===Symbol.for("react.memo_cache_sentinel")?(Ge=s.jsx(D,{name:"add",className:"block h-4 w-4"}),n[77]=Ge):Ge=n[77];const at=s.jsx("button",{type:"button","aria-label":je,disabled:te,onTouchStart:ae,onClick:_e,className:Me,children:Ge});let Ye;n[78]!==re||n[79]!==de||n[80]!==$||n[81]!==at?(Ye=s.jsxs("div",{className:re,children:[de,$,at]}),n[78]=re,n[79]=de,n[80]=$,n[81]=at,n[82]=Ye):Ye=n[82],J=Ye;break e}}n[49]=r,n[50]=a,n[51]=Z,n[52]=j,n[53]=y,n[54]=ue,n[55]=q,n[56]=te,n[57]=I,n[58]=C,n[59]=v,n[60]=J}else J=n[60];if(J!==Symbol.for("react.early_return_sentinel"))return J;let ne;n[83]!==a?(ne=xe("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]=ne):ne=n[84];let ee;n[85]!==C?(ee=C("numberInput.actions.decreaseAria"),n[85]=C,n[86]=ee):ee=n[86];let he;n[87]!==U||n[88]!==z||n[89]!==w?(he=()=>z(U-w),n[87]=U,n[88]=z,n[89]=w,n[90]=he):he=n[90];let ke,oe;n[91]===Symbol.for("react.memo_cache_sentinel")?(ke=xe("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"),oe=s.jsx(D,{name:"subtract",className:"block h-3.5 w-3.5"}),n[91]=ke,n[92]=oe):(ke=n[91],oe=n[92]);let ge;n[93]!==Z||n[94]!==ee||n[95]!==he?(ge=s.jsx("button",{type:"button","aria-label":ee,disabled:Z,onClick:he,className:ke,children:oe}),n[93]=Z,n[94]=ee,n[95]=he,n[96]=ge):ge=n[96];const me=m.inputMode??"numeric";let ye;n[97]!==r?(ye=xe("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]=ye):ye=n[98];let ie;n[99]!==i||n[100]!==j||n[101]!==Q||n[102]!==F||n[103]!==m||n[104]!==e||n[105]!==me||n[106]!==ye?(ie=s.jsx("input",{...m,ref:e,type:"text",inputMode:me,value:j,onChange:F,onBlur:Q,disabled:i,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",className:ye}),n[99]=i,n[100]=j,n[101]=Q,n[102]=F,n[103]=m,n[104]=e,n[105]=me,n[106]=ye,n[107]=ie):ie=n[107];let ve;n[108]!==C?(ve=C("numberInput.actions.increaseAria"),n[108]=C,n[109]=ve):ve=n[109];let X;n[110]!==U||n[111]!==z||n[112]!==w?(X=()=>z(U+w),n[110]=U,n[111]=z,n[112]=w,n[113]=X):X=n[113];let Se,Ae;n[114]===Symbol.for("react.memo_cache_sentinel")?(Se=xe("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"),Ae=s.jsx(D,{name:"add",className:"block h-3.5 w-3.5"}),n[114]=Se,n[115]=Ae):(Se=n[114],Ae=n[115]);let pe;n[116]!==te||n[117]!==ve||n[118]!==X?(pe=s.jsx("button",{type:"button","aria-label":ve,disabled:te,onClick:X,className:Se,children:Ae}),n[116]=te,n[117]=ve,n[118]=X,n[119]=pe):pe=n[119];let we;return n[120]!==ne||n[121]!==ge||n[122]!==ie||n[123]!==pe?(we=s.jsxs("div",{className:ne,children:[ge,ie,pe]}),n[120]=ne,n[121]=ge,n[122]=ie,n[123]=pe,n[124]=we):we=n[124],we});En.displayName="NumberInput";const np=["*","read","edit","glob","grep","list","bash","task","skill","lsp","todoread","todowrite","webfetch","websearch","codesearch","external_directory","doom_loop","question","plan_enter","plan_exit"],Xo=t=>t==="allow"||t==="ask"||t==="deny",Sa=(t,e)=>`${t}::${e}`,Ba=t=>{const e=new Map;for(const n of t)!n.permission||n.permission==="invalid"||n.pattern&&Xo(n.action)&&e.set(Sa(n.permission,n.pattern),{permission:n.permission,pattern:n.pattern,action:n.action});return Array.from(e.values())},Mo=t=>{const e=new Map;for(const n of Ba(t))e.set(Sa(n.permission,n.pattern),n);return e},rp=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=rp(Ba(t)),r=rp(Ba(e));return n.length!==r.length?!1:n.every((a,i)=>{const o=r[i];return a.permission===o.permission&&a.pattern===o.pattern&&a.action===o.action})},JS=t=>t.find(n=>n.permission==="*"&&n.pattern==="*")?.action??"allow",YS=(t,e)=>Ba(t).filter(n=>!(n.permission==="*"&&n.pattern==="*")).filter(n=>n.pattern!=="*"||n.action!==e),QS=t=>{if(Xo(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(Xo(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))Xo(i)&&e.push({permission:n,pattern:a,action:i})}return e},XS=(t,e)=>{const n=Ba(e),r={};for(const i of n)(r[i.permission]||={})[i.pattern]=i.action;const a={"*":t};for(const[i,o]of Object.entries(r))if(i!=="*"){if(Object.keys(o).length===1&&o["*"]){a[i]=o["*"];continue}a[i]=o}return a},ZS=()=>{const{t}=dt(),{isMobile:e}=nn(),{selectedAgentName:n,getAgentByName:r,createAgent:a,updateAgent:i,agents:o,agentDraft:c,setAgentDraft:d}=li(Jn(re=>({selectedAgentName:re.selectedAgentName,getAgentByName:re.getAgentByName,createAgent:re.createAgent,updateAgent:re.updateAgent,agents:re.agents,agentDraft:re.agentDraft,setAgentDraft:re.setAgentDraft}))),p=n?r(n):null,m=!!(c&&c.name===n&&!p),[u,f]=l.useState(""),[b,h]=l.useState("user"),[v,x]=l.useState(""),[g,w]=l.useState("subagent"),[y,C]=l.useState(""),[k,j]=l.useState(void 0),[S,I]=l.useState(void 0),[M,P]=l.useState(""),[A,N]=l.useState("allow"),[E,T]=l.useState([]),[R,V]=l.useState([]),[_,U]=l.useState(""),[B,z]=l.useState("*"),[K,F]=l.useState(!1),[G,Q]=l.useState(!1),te=l.useRef(null),Z=zs(re=>re.currentDirectory??null),[fe,ue]=l.useState([]),W=sh(re=>re.permission);l.useEffect(()=>{let re=!1;return(async()=>{const ce=await sn.listToolIds({directory:Z});if(re)return;const Ce=new Set(["write","patch","multiedit"]),Te=ce.map($e=>typeof $e=="string"?$e.trim():"").filter(Boolean).filter($e=>$e!=="*").filter($e=>$e!=="invalid").filter($e=>!Ce.has($e));ue(Array.from(new Set(Te)).sort(($e,De)=>$e.localeCompare(De)))})(),()=>{re=!0}},[Z]);const q=l.useMemo(()=>{const re=new Set;for(const Pe of o){const ce=Ba(Array.isArray(Pe.permission)?Pe.permission:[]);for(const Ce of ce)Ce.permission&&Ce.permission!=="*"&&Ce.permission!=="invalid"&&re.add(Ce.permission)}for(const Pe of Object.values(W))for(const ce of Pe){const Ce=ce.permission?.trim();Ce&&Ce!=="invalid"&&re.add(Ce)}for(const Pe of fe)re.add(Pe);return Array.from(re).sort((Pe,ce)=>Pe.localeCompare(ce))},[o,W,fe]),J=l.useMemo(()=>Mo(E),[E]),ne=l.useMemo(()=>Mo(R),[R]),ee=l.useCallback(re=>ne.get(Sa(re,"*"))?.action,[ne]),he=l.useCallback(re=>R.filter(Pe=>Pe.permission===re&&Pe.pattern!=="*").sort((Pe,ce)=>Pe.pattern.localeCompare(ce.pattern)),[R]),ke=l.useMemo(()=>{const re=new Set;for(const Pe of np)re.add(Pe);for(const Pe of q)re.add(Pe);return Array.from(re).sort((Pe,ce)=>Pe.localeCompare(ce))},[q]),oe=l.useCallback(re=>{const Pe=re==="*"?A:ee(re)??A,ce=he(re),Ce=!1,Te=ce.reduce((De,de)=>(De[de.action]=(De[de.action]??0)+1,De),{allow:0,ask:0,deny:0}),$e=["allow","ask","deny"].filter(De=>Te[De]>0).map(De=>`${Te[De]} ${De}`).join(", ");return{defaultAction:Pe,patternRulesCount:ce.length,patternSummary:$e,hasDefaultHint:Ce}},[he,ee,A]),ge=l.useCallback(re=>t(re==="allow"?"settings.common.permission.allow":re==="deny"?"settings.common.permission.deny":"settings.common.permission.ask"),[t]),me=l.useCallback(re=>re==="global"?t("settings.common.scope.global"):ge(re),[ge,t]),ye=l.useMemo(()=>{const re=new Set;for(const Pe of np)re.add(Pe);for(const Pe of q)re.add(Pe);return Array.from(re).sort((Pe,ce)=>Pe.localeCompare(ce))},[q]),ie=l.useCallback((re,Pe,ce)=>{V(Ce=>{const Te=Mo(Ce);return Te.set(Sa(re,Pe),{permission:re,pattern:Pe,action:ce}),Array.from(Te.values())})},[]),ve=l.useCallback((re,Pe)=>{V(ce=>{const Ce=Mo(ce);return Ce.delete(Sa(re,Pe)),Array.from(Ce.values())})},[]),X=l.useCallback((re,Pe)=>{const ce=J.get(Sa(re,Pe));if(ce){ie(re,Pe,ce.action);return}ve(re,Pe)},[J,ve,ie]),Se=l.useCallback((re,Pe,ce)=>{ie(re,Pe,ce)},[ie]),Ae=l.useCallback(re=>{N(re),V(Pe=>Pe.filter(ce=>!(ce.pattern==="*"&&ce.action===re)))},[]),pe=l.useCallback(re=>{const Pe=_.trim();if(!Pe){H.error(t("settings.agents.page.toast.permissionNameRequired"));return}const ce=B.trim()||"*";if(Pe==="*"&&ce==="*"){Ae(re),U(""),z("*");return}ce==="*"&&Pe!=="*"&&re===A?ve(Pe,"*"):ie(Pe,ce,re),U(""),z("*")},[A,_,B,ve,Ae,t,ie]),we=l.useCallback(re=>re==="*"?t("settings.agents.page.permissions.defaultLabel"):re==="webfetch"?"WebFetch":re==="websearch"?"WebSearch":re==="codesearch"?"CodeSearch":re==="doom_loop"?"Doom Loop":re==="external_directory"?"External Directory":re==="todowrite"?"TodoWrite":re==="todoread"?"TodoRead":re.split(/[_-]+/g).filter(Boolean).map(Pe=>Pe.charAt(0).toUpperCase()+Pe.slice(1)).join(" "),[t]);l.useEffect(()=>{U(""),z("*");const re=Pe=>{const ce=Ba(Pe),Ce=JS(ce),Te=YS(ce,Ce);return N(Ce),T(Te),V(Te),{global:Ce,rules:Te}};if(m&&c){const Pe=c.name||"",ce=c.scope||"user",Ce=c.description||"",Te=c.mode||"subagent",$e=c.model||"",De=c.temperature,de=c.top_p,O=c.prompt||"";f(Pe),h(ce),x(Ce),w(Te),C($e),j(De),I(de),P(O);const L=QS(c.permission),$=re(L);te.current={draftName:Pe,draftScope:ce,description:Ce,mode:Te,model:$e,temperature:De,topP:de,prompt:O,globalPermission:$.global,permissionRules:$.rules};return}if(p&&n===p.name){const Pe=p.description||"",ce=p.mode||"subagent",Ce=p.model?.providerID&&p.model?.modelID?`${p.model.providerID}/${p.model.modelID}`:"",Te=p.temperature,$e=p.topP,De=p.prompt||"";x(Pe),w(ce),C(Ce),j(Te),I($e),P(De);const de=re(Array.isArray(p.permission)?p.permission:[]);te.current={draftName:"",draftScope:"user",description:Pe,mode:ce,model:Ce,temperature:Te,topP:$e,prompt:De,globalPermission:de.global,permissionRules:de.rules}}},[c,m,p,n]);const Ie=l.useMemo(()=>{const re=te.current;return re?!!(m&&(u!==re.draftName||b!==re.draftScope)||v!==re.description||g!==re.mode||y!==re.model||k!==re.temperature||S!==re.topP||M!==re.prompt||A!==re.globalPermission||!qS(R,re.permissionRules)):!1},[v,u,b,A,m,g,y,R,M,k,S]),Y=async()=>{const re=m?u.trim().replace(/\s+/g,"-"):n?.trim();if(!re){H.error(t("settings.agents.sidebar.toast.agentNameRequired"));return}if(m&&o.some(Pe=>Pe.name===re)){H.error(t("settings.agents.sidebar.toast.agentExists"));return}Q(!0);try{const Pe=y.trim(),ce=XS(A,R),Ce={name:re,description:v.trim()||void 0,mode:g,model:Pe===""?null:Pe,temperature:k,top_p:S,prompt:M.trim()||void 0,permission:ce,scope:m?b:void 0};let Te;m?(Te=await a(Ce),Te&&d(null)):Te=await i(re,Ce),Te?H.success(t(m?"settings.agents.page.toast.created":"settings.agents.page.toast.updated")):H.error(t(m?"settings.agents.page.toast.createFailed":"settings.agents.page.toast.updateFailed"))}catch(Pe){console.error("Error saving agent:",Pe);const ce=Pe instanceof Error&&Pe.message?Pe.message:t("settings.agents.page.toast.saveUnexpectedError");H.error(ce)}finally{Q(!1)}};return n?s.jsx(Ns,{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:re=>f(re.target.value),placeholder:t("settings.agents.page.field.agentNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(os,{value:b,onValueChange:re=>h(re),children:[s.jsx(ls,{className:"w-fit min-w-[100px]",children:s.jsx(us,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(cs,{align:"end",children:[s.jsx(Tt,{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(Tt,{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(un,{value:v,onChange:re=>x(re.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(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:t("settings.agents.page.field.modeTooltip")})]})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[s.jsx(be,{variant:"chip",size:"xs","aria-pressed":g==="primary",onClick:()=>w("primary"),className:"!font-normal",children:t("settings.agents.page.mode.primary")}),s.jsx(be,{variant:"chip",size:"xs","aria-pressed":g==="subagent",onClick:()=>w("subagent"),className:"!font-normal",children:t("settings.agents.page.mode.subagent")}),s.jsx(be,{variant:"chip",size:"xs","aria-pressed":g==="all",onClick:()=>w("all"),className:"!font-normal",children:t("settings.agents.page.mode.all")})]})]})})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.agents.page.section.modelParameters")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.agents.page.field.overrideModel")})}),s.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:s.jsx(fo,{providerId:pi(y)?.providerId??"",modelId:pi(y)?.modelId??"",onChange:(re,Pe)=>{C(re&&Pe?`${re}/${Pe}`:"")}})})]}),s.jsxs("div",{className:xe("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsxs("div",{className:xe("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(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:t("settings.agents.page.field.temperatureTooltip")})]})]}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.agents.page.field.temperatureRange")})]}),s.jsxs("div",{className:xe("flex items-center gap-2",e?"w-full":"w-fit"),children:[s.jsx(En,{value:k,fallbackValue:.7,onValueChange:j,onClear:()=>j(void 0),min:0,max:2,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),k!==void 0&&s.jsx(be,{size:"sm",type:"button",variant:"ghost",onClick:()=>j(void 0),className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":t("settings.agents.page.field.clearTemperatureAria"),title:t("settings.common.actions.clear"),children:s.jsx(D,{name:"close",className:"h-3.5 w-3.5"})})]})]}),s.jsxs("div",{className:xe("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsxs("div",{className:xe("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(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:t("settings.agents.page.field.topPTooltip")})]})]}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.agents.page.field.topPRange")})]}),s.jsxs("div",{className:xe("flex items-center gap-2",e?"w-full":"w-fit"),children:[s.jsx(En,{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(be,{size:"sm",type:"button",variant:"ghost",onClick:()=>I(void 0),className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":t("settings.agents.page.field.clearTopPAria"),title:t("settings.common.actions.clear"),children:s.jsx(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(un,{value:M,onChange:re=>P(re.target.value),placeholder:t("settings.agents.page.field.systemPromptPlaceholder"),rows:8,className:"w-full font-mono typography-meta min-h-[120px] max-h-[60vh] bg-transparent resize-y"})})]}),s.jsxs("div",{className:"mb-2",children:[s.jsxs("div",{className:"mb-1 px-1 flex items-center justify-between gap-4",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.agents.page.section.toolPermissions")}),s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>F(re=>!re),children:t(K?"settings.agents.page.permissions.hideEditor":"settings.agents.page.permissions.advancedEditor")})]}),K?s.jsxs("div",{className:"space-y-6 px-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-4 py-1.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.agents.page.permissions.globalDefault")}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono",children:"*"})]}),s.jsxs(os,{value:A,onValueChange:re=>Ae(re),children:[s.jsx(ls,{className:"w-[100px]",children:s.jsx(us,{children:ge(A)})}),s.jsxs(cs,{children:[s.jsx(Tt,{value:"allow",children:t("settings.common.permission.allow")}),s.jsx(Tt,{value:"ask",children:t("settings.common.permission.ask")}),s.jsx(Tt,{value:"deny",children:t("settings.common.permission.deny")})]})]})]}),s.jsx("div",{className:"space-y-4",children:ke.filter(re=>re!=="*").map(re=>{const Pe=we(re),{defaultAction:ce,patternRulesCount:Ce}=oe(re),Te=ee(re),$e=Te??"global",De=he(re),de=["allow","ask","deny"].filter(O=>O!==A);return s.jsxs("div",{className:"border-t border-[var(--surface-subtle)] pt-2",children:[s.jsxs("div",{className:"flex items-center justify-between py-1",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:Pe}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono",children:re})]}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:Ce>0?t("settings.agents.page.permissions.globalSummary",{summary:ce}):ce})]}),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(be,{size:"sm",variant:"ghost",onClick:()=>X(re,"*"),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(os,{value:$e,onValueChange:O=>{if(O==="global"){ve(re,"*");return}ie(re,"*",O)},children:[s.jsx(ls,{className:"w-[90px]",children:s.jsx(us,{children:me($e)})}),s.jsxs(cs,{children:[s.jsx(Tt,{value:"global",children:t("settings.common.scope.global")}),de.map(O=>s.jsx(Tt,{value:O,className:"capitalize",children:ge(O)},O))]})]})]}),De.map(O=>{const L=Sa(O.permission,O.pattern),$=J.get(L),je=!$,ae=!!($&&$.action!==O.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:O.pattern}),je&&s.jsx("span",{className:"typography-micro text-[var(--status-success)]",children:t("settings.common.badge.new")}),ae&&s.jsx("span",{className:"typography-micro text-[var(--status-warning)]",children:t("settings.common.badge.modified")}),(je||ae)&&s.jsx(be,{size:"sm",variant:"ghost",onClick:()=>je?ve(O.permission,O.pattern):X(O.permission,O.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(os,{value:O.action,onValueChange:_e=>Se(O.permission,O.pattern,_e),children:[s.jsx(ls,{className:"w-[90px]",children:s.jsx(us,{children:ge(O.action)})}),s.jsxs(cs,{children:[s.jsx(Tt,{value:"allow",children:t("settings.common.permission.allow")}),s.jsx(Tt,{value:"ask",children:t("settings.common.permission.ask")}),s.jsx(Tt,{value:"deny",children:t("settings.common.permission.deny")})]})]})]},L)})]})]},re)})}),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(os,{value:_,onValueChange:U,children:[s.jsx(ls,{className:"w-full sm:w-[160px]",children:_?s.jsx("span",{className:"truncate",children:we(_)}):s.jsx("span",{className:"text-muted-foreground",children:t("settings.agents.page.permissions.permissionPlaceholder")})}),s.jsx(cs,{children:ye.map(re=>s.jsx(Tt,{value:re,children:s.jsx("div",{className:"flex items-center justify-between gap-2 w-full",children:s.jsx("span",{children:we(re)})})},re))})]}),s.jsx(Bt,{value:B,onChange:re=>z(re.target.value),placeholder:t("settings.agents.page.permissions.patternPlaceholder"),className:"h-7 flex-1 font-mono text-xs"}),s.jsxs("div",{className:"flex gap-1",children:[s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>pe("allow"),children:t("settings.common.permission.allow")}),s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>pe("ask"),children:t("settings.common.permission.ask")}),s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>pe("deny"),children:t("settings.common.permission.deny")})]})]})]})]}):s.jsx("section",{className:"px-2 pb-2 pt-0 space-y-0",children:ke.map((re,Pe)=>{const{defaultAction:ce,patternRulesCount:Ce,patternSummary:Te,hasDefaultHint:$e}=oe(re),De=we(re),de=$e?`${ce} (env blocked)`:ce;return s.jsxs("div",{className:xe("flex flex-col gap-1 py-1.5 sm:flex-row sm:items-center sm:justify-between sm:gap-8",Pe>0&&"border-t border-[var(--surface-subtle)]"),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:De}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono hidden sm:inline-block",children:re})]}),s.jsxs("div",{className:"flex items-center gap-3",children:[Ce>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:de})}):s.jsx("span",{className:xe("typography-micro capitalize px-1.5 py-0.5 rounded",de==="allow"?"text-[var(--status-success)] bg-[var(--status-success)]/10":de==="deny"?"text-[var(--status-error)] bg-[var(--status-error)]/10":"text-[var(--status-warning)] bg-[var(--status-warning)]/10"),children:de}),Ce>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})})]})]},re)})})]}),s.jsx("div",{className:"px-2 py-1",children:s.jsx(be,{onClick:Y,disabled:G||!Ie,size:"xs",className:"!font-normal",children:t(G?"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,Eo={prompt:"",responseStyleEnabled:!1,responseStylePreset:"concise",responseStyleCustomInstructions:""},sk=(t,e)=>t==="custom"?e:Ob(t),nk=t=>t==="custom"?"custom":nh(t)?t:"concise",ap={concise:"settings.behavior.page.responseStyle.option.concise",detailed:"settings.behavior.page.responseStyle.option.detailed",mentor:"settings.behavior.page.responseStyle.option.mentor",pushback:"settings.behavior.page.responseStyle.option.pushback",noFiller:"settings.behavior.page.responseStyle.option.noFiller",matchEnergy:"settings.behavior.page.responseStyle.option.matchEnergy",warmPeer:"settings.behavior.page.responseStyle.option.warmPeer"},ip=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}=dt(),[e,n]=l.useState(""),[r,a]=l.useState(Eo.responseStyleEnabled),[i,o]=l.useState(Eo.responseStylePreset),[c,d]=l.useState(Eo.responseStyleCustomInstructions),[p,m]=l.useState(!0),[u,f]=l.useState(!1),[b,h]=l.useState(""),v=l.useRef(null);l.useEffect(()=>{const y=new AbortController;return(async()=>{try{const[k,j]=await Promise.all([fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},signal:y.signal}),fetch("/api/behavior/agents-md",{method:"GET",headers:{Accept:"application/json"},signal:y.signal})]);let S=Eo;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()&&j.ok){const I=await j.json();typeof I.content=="string"&&(S={...S,prompt:I.content})}n(S.prompt),a(S.responseStyleEnabled),o(S.responseStylePreset),d(S.responseStyleCustomInstructions),h(S.prompt),v.current={enabled:S.responseStyleEnabled,preset:S.responseStylePreset,custom:S.responseStyleCustomInstructions}}catch(k){k.name!=="AbortError"&&console.warn("Failed to load behavior settings:",k)}finally{m(!1)}})(),()=>y.abort()},[]),l.useEffect(()=>{if(p)return;const y=v.current;if(y&&y.enabled===r&&y.preset===i&&y.custom===c)return;const C={enabled:r,preset:i,custom:c},k=setTimeout(async()=>{try{await ip({responseStyleEnabled:C.enabled,responseStylePreset:C.preset,responseStyleCustomInstructions:C.custom},t("settings.behavior.page.toast.saveFailed")),v.current=C}catch(j){const S=j instanceof Error?j.message:t("settings.behavior.page.toast.saveFailed");H.error(S)}},400);return()=>clearTimeout(k)},[r,i,c,p,t]);const x=sk(i,c),g=e!==b,w=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 ip({globalBehaviorPrompt:y},t("settings.behavior.page.toast.saveFailed")),n(y),h(y),H.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");H.error(C)}finally{f(!1)}};return s.jsx(Ns,{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(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"font-medium text-foreground",children:t("settings.behavior.page.warning.title")}),s.jsx("p",{children:t("settings.behavior.page.warning.description",{path:ek})})]})})]})]})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsx(un,{value:e,onChange:y=>n(y.target.value),placeholder:t("settings.behavior.page.field.systemPromptPlaceholder"),rows:12,disabled:p,outerClassName:"min-h-[160px] max-h-[70vh]",className:"w-full font-mono typography-meta bg-transparent"}),s.jsx(be,{onClick:w,disabled:u||!g||p,size:"xs",className:"!font-normal",children:t(u?"settings.common.actions.saving":"settings.common.actions.saveChanges")})]})]}),s.jsxs("div",{children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.behavior.page.section.responseStyle")}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:t("settings.behavior.page.responseStyle.tooltip")})]})]})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsxs("label",{className:"flex items-center gap-2 typography-ui-label text-foreground",children:[s.jsx(fs,{checked:r,onChange:a,disabled:p,ariaLabel:t("settings.behavior.page.responseStyle.enableAria")}),t("settings.behavior.page.responseStyle.enable")]}),s.jsxs(os,{value:i,onValueChange:y=>o(y),disabled:p||!r,children:[s.jsx(ls,{className:"w-full sm:w-56",size:"lg",children:s.jsx(us,{children:y=>y==="custom"?t("settings.behavior.page.responseStyle.option.custom"):nh(y)?t(ap[y]):null})}),s.jsxs(cs,{children:[Fb.map(y=>s.jsx(Tt,{value:y,children:t(ap[y])},y)),s.jsx(Tt,{value:"custom",children:t("settings.behavior.page.responseStyle.option.custom")})]})]}),s.jsx(un,{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=st.c(169),{onItemSelect:n}=t,{t:r}=dt(),[a,i]=l.useState(null),[o,c]=l.useState(""),[d,p]=l.useState(null),[m,u]=l.useState(null),[f,b]=l.useState(!1),[h,v]=l.useState(null),{selectedCommandName:x,commands:g,setSelectedCommand:w,setCommandDraft:y,createCommand:C,deleteCommand:k,loadCommands:j}=$d(Jn(ik)),S=oa(ok),I=oa(lk);let M,P;e[0]!==j||e[1]!==I?(M=()=>{j(),I()},P=[j,I],e[0]=j,e[1]=I,e[2]=M,e[3]=P):(M=e[2],P=e[3]),l.useEffect(M,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]!==g||e[7]!==N){let Ve;e[9]!==N?(Ve=qe=>!N.has(qe.name),e[9]=N,e[10]=Ve):Ve=e[10],E=g.filter(Ve),e[6]=g,e[7]=N,e[8]=E}else E=e[8];const T=E;let R,V;e[11]!==x||e[12]!==w||e[13]!==N?(R=()=>{x&&N.has(x)&&w(null)},V=[x,w,N],e[11]=x,e[12]=w,e[13]=N,e[14]=R,e[15]=V):(R=e[14],V=e[15]),l.useEffect(R,V);let _;e[16]!==g||e[17]!==n||e[18]!==y||e[19]!==w?(_=()=>{let Ve="new-command",qe=1;for(;g.some(lt=>lt.name===Ve);)Ve=`new-command-${qe}`,qe++;y({name:Ve,scope:"user"}),w(Ve),n?.()},e[16]=g,e[17]=n,e[18]=y,e[19]=w,e[20]=_):_=e[20];const U=_;let B;e[21]!==r?(B=async Ve=>{if(si(Ve)){H.error(r("settings.commands.sidebar.toast.builtInCannotDelete"));return}p(Ve),u("delete")},e[21]=r,e[22]=B):B=e[22];const z=B;let K;e[23]===Symbol.for("react.memo_cache_sentinel")?(K=async Ve=>{si(Ve)&&(p(Ve),u("reset"))},e[23]=K):K=e[23];const F=K;let G;e[24]===Symbol.for("react.memo_cache_sentinel")?(G=()=>{p(null),u(null)},e[24]=G):G=e[24];const Q=G;let te;e[25]!==d||e[26]!==m||e[27]!==k||e[28]!==r?(te=async()=>{if(!d||!m)return;b(!0),await k(d.name)?(m==="delete"?H.success(r("settings.commands.sidebar.toast.commandDeleted",{name:d.name})):H.success(r("settings.commands.sidebar.toast.commandReset",{name:d.name})),Q()):m==="delete"?H.error(r("settings.commands.sidebar.toast.deleteFailed")):H.error(r("settings.commands.sidebar.toast.resetFailed")),b(!1)},e[25]=d,e[26]=m,e[27]=k,e[28]=r,e[29]=te):te=e[29];const Z=te;let fe;e[30]!==g||e[31]!==y||e[32]!==w?(fe=Ve=>{const qe=Ve.name;let lt=1,He=`${qe}-copy`;for(;g.some(ze=>ze.name===He);)lt++,He=`${qe}-copy-${lt}`;y({name:He,scope:Ve.scope||"user",description:Ve.description,template:Ve.template,agent:Ve.agent,model:Ve.model}),w(He)},e[30]=g,e[31]=y,e[32]=w,e[33]=fe):fe=e[33];const ue=fe;let W;e[34]===Symbol.for("react.memo_cache_sentinel")?(W=Ve=>{c(Ve.name),i(Ve)},e[34]=W):W=e[34];const q=W;let J;e[35]!==g||e[36]!==C||e[37]!==k||e[38]!==a||e[39]!==o||e[40]!==w||e[41]!==r?(J=async()=>{if(!a)return;const Ve=o.trim().replace(/\s+/g,"-");if(!Ve){H.error(r("settings.commands.sidebar.toast.commandNameRequired"));return}if(Ve===a.name){i(null);return}if(g.some(lt=>lt.name===Ve)){H.error(r("settings.commands.sidebar.toast.commandExists"));return}await C({name:Ve,description:a.description,template:a.template,agent:a.agent,model:a.model})?await k(a.name)?(H.success(`Command renamed to "${Ve}"`),w(Ve)):H.error(r("settings.commands.sidebar.toast.removeOldAfterRenameFailed")):H.error(r("settings.commands.sidebar.toast.renameFailed")),i(null)},e[35]=g,e[36]=C,e[37]=k,e[38]=a,e[39]=o,e[40]=w,e[41]=r,e[42]=J):J=e[42];const ne=J;let ee,he,ke,oe,ge,me;if(e[43]!==T||e[44]!==U||e[45]!==z||e[46]!==ue||e[47]!==n||e[48]!==h||e[49]!==x||e[50]!==w||e[51]!==r){const Ve=T.filter(si),qe=T.filter(dk);e[58]===Symbol.for("react.memo_cache_sentinel")?(ge=xe("flex h-full flex-col","bg-background"),e[58]=ge):ge=e[58];let lt;e[59]!==r?(lt=r("settings.commands.sidebar.title"),e[59]=r,e[60]=lt):lt=e[60];let He;e[61]!==lt?(He=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:lt}),e[61]=lt,e[62]=He):He=e[62];let ze;e[63]===Symbol.for("react.memo_cache_sentinel")?(ze=s.jsx(ho,{className:"mb-3"}),e[63]=ze):ze=e[63];let et;e[64]!==T.length||e[65]!==r?(et=r("settings.commands.sidebar.total",{count:T.length}),e[64]=T.length,e[65]=r,e[66]=et):et=e[66];let yt;e[67]!==et?(yt=s.jsx("span",{className:"typography-meta text-muted-foreground",children:et}),e[67]=et,e[68]=yt):yt=e[68];let Rt;e[69]===Symbol.for("react.memo_cache_sentinel")?(Rt=s.jsx(D,{name:"add",className:"h-3.5 w-3.5"}),e[69]=Rt):Rt=e[69];let kt;e[70]!==U?(kt=s.jsx(be,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:U,children:Rt}),e[70]=U,e[71]=kt):kt=e[71];let ht;e[72]!==yt||e[73]!==kt?(ht=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[yt,kt]}),e[72]=yt,e[73]=kt,e[74]=ht):ht=e[74],e[75]!==He||e[76]!==ht?(me=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[He,ze,ht]}),e[75]=He,e[76]=ht,e[77]=me):me=e[77],ee=Ns,he="flex-1 min-h-0",ke="space-y-1 px-3 py-2",oe=T.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:[Ve.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")}),[...Ve].sort(uk).map(vt=>s.jsx(op,{command:vt,isSelected:x===vt.name,onSelect:()=>{w(vt.name),n?.()},onReset:()=>F(vt),onDuplicate:()=>ue(vt),isMenuOpen:h===vt.name,onMenuOpenChange:ns=>v(ns?vt.name:null)},vt.name))]}),qe.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")}),[...qe].sort(mk).map(vt=>s.jsx(op,{command:vt,isSelected:x===vt.name,onSelect:()=>{w(vt.name),n?.()},onRename:()=>q(vt),onDelete:()=>z(vt),onDuplicate:()=>ue(vt),isMenuOpen:h===vt.name,onMenuOpenChange:ns=>v(ns?vt.name:null)},vt.name))]})]}),e[43]=T,e[44]=U,e[45]=z,e[46]=ue,e[47]=n,e[48]=h,e[49]=x,e[50]=w,e[51]=r,e[52]=ee,e[53]=he,e[54]=ke,e[55]=oe,e[56]=ge,e[57]=me}else ee=e[52],he=e[53],ke=e[54],oe=e[55],ge=e[56],me=e[57];let ye;e[78]!==ee||e[79]!==he||e[80]!==ke||e[81]!==oe?(ye=s.jsx(ee,{outerClassName:he,className:ke,children:oe}),e[78]=ee,e[79]=he,e[80]=ke,e[81]=oe,e[82]=ye):ye=e[82];const ie=d!==null&&m!==null;let ve;e[83]!==f?(ve=Ve=>{!Ve&&!f&&Q()},e[83]=f,e[84]=ve):ve=e[84];let X;e[85]!==m||e[86]!==r?(X=r(m==="delete"?"settings.commands.sidebar.dialog.deleteTitle":"settings.commands.sidebar.dialog.resetTitle"),e[85]=m,e[86]=r,e[87]=X):X=e[87];let Se;e[88]!==X?(Se=s.jsx(hs,{children:X}),e[88]=X,e[89]=Se):Se=e[89];let Ae;e[90]!==d?.name||e[91]!==m||e[92]!==r?(Ae=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]=Ae):Ae=e[93];let pe;e[94]!==Ae?(pe=s.jsx(Ss,{children:Ae}),e[94]=Ae,e[95]=pe):pe=e[95];let we;e[96]!==Se||e[97]!==pe?(we=s.jsxs(ys,{children:[Se,pe]}),e[96]=Se,e[97]=pe,e[98]=we):we=e[98];let Ie;e[99]!==r?(Ie=r("settings.common.actions.cancel"),e[99]=r,e[100]=Ie):Ie=e[100];let Y;e[101]!==f||e[102]!==Ie?(Y=s.jsx(be,{size:"sm",variant:"ghost",onClick:Q,disabled:f,children:Ie}),e[101]=f,e[102]=Ie,e[103]=Y):Y=e[103];let re;e[104]!==m||e[105]!==r?(re=r(m==="delete"?"settings.common.actions.delete":"settings.common.actions.reset"),e[104]=m,e[105]=r,e[106]=re):re=e[106];let Pe;e[107]!==Z||e[108]!==f||e[109]!==re?(Pe=s.jsx(be,{size:"sm",onClick:Z,disabled:f,children:re}),e[107]=Z,e[108]=f,e[109]=re,e[110]=Pe):Pe=e[110];let ce;e[111]!==Y||e[112]!==Pe?(ce=s.jsxs(Vs,{children:[Y,Pe]}),e[111]=Y,e[112]=Pe,e[113]=ce):ce=e[113];let Ce;e[114]!==we||e[115]!==ce?(Ce=s.jsxs(ms,{className:"max-w-md",children:[we,ce]}),e[114]=we,e[115]=ce,e[116]=Ce):Ce=e[116];let Te;e[117]!==ie||e[118]!==ve||e[119]!==Ce?(Te=s.jsx(ps,{open:ie,onOpenChange:ve,children:Ce}),e[117]=ie,e[118]=ve,e[119]=Ce,e[120]=Te):Te=e[120];const $e=a!==null;let De;e[121]===Symbol.for("react.memo_cache_sentinel")?(De=Ve=>!Ve&&i(null),e[121]=De):De=e[121];let de;e[122]!==r?(de=r("settings.commands.sidebar.renameDialog.title"),e[122]=r,e[123]=de):de=e[123];let O;e[124]!==de?(O=s.jsx(hs,{children:de}),e[124]=de,e[125]=O):O=e[125];const L=a?.name??"";let $;e[126]!==r||e[127]!==L?($=r("settings.commands.sidebar.renameDialog.description",{name:L}),e[126]=r,e[127]=L,e[128]=$):$=e[128];let je;e[129]!==$?(je=s.jsx(Ss,{children:$}),e[129]=$,e[130]=je):je=e[130];let ae;e[131]!==O||e[132]!==je?(ae=s.jsxs(ys,{children:[O,je]}),e[131]=O,e[132]=je,e[133]=ae):ae=e[133];let _e;e[134]===Symbol.for("react.memo_cache_sentinel")?(_e=Ve=>c(Ve.target.value),e[134]=_e):_e=e[134];let le;e[135]!==r?(le=r("settings.commands.sidebar.renameDialog.placeholder"),e[135]=r,e[136]=le):le=e[136];let Me;e[137]!==ne?(Me=Ve=>{Ve.key==="Enter"&&ne()},e[137]=ne,e[138]=Me):Me=e[138];let Ge;e[139]!==o||e[140]!==le||e[141]!==Me?(Ge=s.jsx(Bt,{value:o,onChange:_e,placeholder:le,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:Me}),e[139]=o,e[140]=le,e[141]=Me,e[142]=Ge):Ge=e[142];let at;e[143]===Symbol.for("react.memo_cache_sentinel")?(at=()=>i(null),e[143]=at):at=e[143];let Ye;e[144]!==r?(Ye=r("settings.common.actions.cancel"),e[144]=r,e[145]=Ye):Ye=e[145];let Xe;e[146]!==Ye?(Xe=s.jsx(be,{size:"sm",variant:"ghost",onClick:at,children:Ye}),e[146]=Ye,e[147]=Xe):Xe=e[147];let ut;e[148]!==r?(ut=r("settings.common.actions.rename"),e[148]=r,e[149]=ut):ut=e[149];let rt;e[150]!==ne||e[151]!==ut?(rt=s.jsx(be,{size:"sm",onClick:ne,children:ut}),e[150]=ne,e[151]=ut,e[152]=rt):rt=e[152];let it;e[153]!==Xe||e[154]!==rt?(it=s.jsxs(Vs,{children:[Xe,rt]}),e[153]=Xe,e[154]=rt,e[155]=it):it=e[155];let nt;e[156]!==ae||e[157]!==Ge||e[158]!==it?(nt=s.jsxs(ms,{children:[ae,Ge,it]}),e[156]=ae,e[157]=Ge,e[158]=it,e[159]=nt):nt=e[159];let Ne;e[160]!==$e||e[161]!==nt?(Ne=s.jsx(ps,{open:$e,onOpenChange:De,children:nt}),e[160]=$e,e[161]=nt,e[162]=Ne):Ne=e[162];let Ke;return e[163]!==ge||e[164]!==me||e[165]!==ye||e[166]!==Te||e[167]!==Ne?(Ke=s.jsxs("div",{className:ge,children:[me,ye,Te,Ne]}),e[163]=ge,e[164]=me,e[165]=ye,e[166]=Te,e[167]=Ne,e[168]=Ke):Ke=e[168],Ke},op=t=>{const e=st.c(53),{command:n,isSelected:r,onSelect:a,onDelete:i,onReset:o,onRename:c,onDuplicate:d,isMenuOpen:p,onMenuOpenChange:m}=t,{t:u}=dt();let f;e[0]===Symbol.for("react.memo_cache_sentinel")?(f=Zi(),e[0]=f):f=e[0];const b=f,h=r?"bg-interactive-selection":"hover:bg-interactive-hover";let v;e[1]!==h?(v=xe("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",h),e[1]=h,e[2]=v):v=e[2];let x;e[3]!==m?(x=b?void 0:U=>{U.preventDefault(),m(!0)},e[3]=m,e[4]=x):x=e[4];let g;e[5]!==n.name?(g=s.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["/",n.name]}),e[5]=n.name,e[6]=g):g=e[6];let w;e[7]!==n||e[8]!==u?(w=(n.scope||si(n))&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:si(n)?u("settings.agents.sidebar.badge.system"):n.scope}),e[7]=n,e[8]=u,e[9]=w):w=e[9];let y;e[10]!==g||e[11]!==w?(y=s.jsxs("div",{className:"flex items-center gap-2",children:[g,w]}),e[10]=g,e[11]=w,e[12]=y):y=e[12];let 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 j;e[19]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(As,{asChild:!0,children:s.jsx(be,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(D,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[19]=j):j=e[19];let S;e[20]!==c||e[21]!==u?(S=c&&s.jsxs($t,{onClick:U=>{U.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=U=>{U.stopPropagation(),d()},e[23]=d,e[24]=I):I=e[24];let M;e[25]===Symbol.for("react.memo_cache_sentinel")?(M=s.jsx(D,{name:"file-copy",className:"h-4 w-4 mr-px"}),e[25]=M):M=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($t,{onClick:I,children:[M,P]}),e[28]=I,e[29]=P,e[30]=A):A=e[30];let N;e[31]!==o||e[32]!==u?(N=o&&s.jsxs($t,{onClick:U=>{U.stopPropagation(),o()},children:[s.jsx(D,{name:"restart",className:"h-4 w-4 mr-px"}),u("settings.common.actions.reset")]}),e[31]=o,e[32]=u,e[33]=N):N=e[33];let E;e[34]!==i||e[35]!==u?(E=i&&s.jsxs($t,{onClick:U=>{U.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 T;e[37]!==S||e[38]!==A||e[39]!==N||e[40]!==E?(T=s.jsxs(Ds,{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]=T):T=e[41];let R;e[42]!==p||e[43]!==m||e[44]!==T?(R=s.jsxs(Ts,{open:p,onOpenChange:m,children:[j,T]}),e[42]=p,e[43]=m,e[44]=T,e[45]=R):R=e[45];let V;e[46]!==R||e[47]!==k?(V=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[k,R]}),e[46]=R,e[47]=k,e[48]=V):V=e[48];let _;return e[49]!==V||e[50]!==v||e[51]!==x?(_=s.jsx("div",{className:v,onContextMenu:x,children:V}),e[49]=V,e[50]=v,e[51]=x,e[52]=_):_=e[52],_};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!si(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}=dt(),{selectedCommandName:e,getCommandByName:n,createCommand:r,updateCommand:a,commands:i,commandDraft:o,setCommandDraft:c}=$d(Jn(A=>({selectedCommandName:A.selectedCommandName,getCommandByName:A.getCommandByName,createCommand:A.createCommand,updateCommand:A.updateCommand,commands:A.commands,commandDraft:A.commandDraft,setCommandDraft:A.setCommandDraft}))),d=e?n(e):null,p=!!(o&&o.name===e&&!d),[m,u]=l.useState(""),[f,b]=l.useState("user"),[h,v]=l.useState(""),[x,g]=l.useState(""),[w,y]=l.useState(""),[C,k]=l.useState(""),[j,S]=l.useState(!1),I=l.useRef(null);l.useEffect(()=>{if(p&&o){const A=o.name||"",N=o.scope||"user",E=o.description||"",T=o.agent||"",R=o.model||"",V=o.template||"";u(A),b(N),v(E),g(T),y(R),k(V),I.current={draftName:A,draftScope:N,description:E,agent:T,model:R,template:V}}else if(d){const A=d.description||"",N=d.agent||"",E=d.model||"",T=d.template||"";v(A),g(N),y(E),k(T),I.current={draftName:"",draftScope:"user",description:A,agent:N,model:E,template:T}}},[d,p,e,i,o]);const M=l.useMemo(()=>{const A=I.current;return A?!!(p&&(m!==A.draftName||f!==A.draftScope)||h!==A.description||x!==A.agent||w!==A.model||C!==A.template):!1},[x,h,m,f,p,w,C]),P=async()=>{const A=p?m.trim().replace(/\s+/g,"-"):e?.trim();if(!A){H.error(t("settings.commands.sidebar.toast.commandNameRequired"));return}if(!C.trim()){H.error(t("settings.commands.page.toast.templateRequired"));return}if(p&&i.some(N=>N.name===A)){H.error(t("settings.commands.sidebar.toast.commandExists"));return}S(!0);try{const N=x.trim(),E=w.trim(),T=C.trim(),R={name:A,description:h.trim()||void 0,agent:N===""?null:N,model:E===""?null:E,template:T,scope:p?f:void 0};let V;p?(V=await r(R),V&&c(null)):V=await a(A,R),V?H.success(t(p?"settings.commands.page.toast.created":"settings.commands.page.toast.updated")):H.error(t(p?"settings.commands.page.toast.createFailed":"settings.commands.page.toast.updateFailed"))}catch(N){console.error("Error saving command:",N),H.error(t("settings.commands.page.toast.saveUnexpectedError"))}finally{S(!1)}};return e?s.jsx(Ns,{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(os,{value:f,onValueChange:A=>b(A),children:[s.jsx(ls,{className:"w-fit min-w-[100px]",children:s.jsx(us,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(cs,{align:"end",children:[s.jsx(Tt,{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(Tt,{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(un,{value:h,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(Ll,{agentName:x,onChange:A=>g(A)})})]}),s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.agents.page.field.overrideModel")})}),s.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:s.jsx(fo,{providerId:pi(w)?.providerId??"",modelId:pi(w)?.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(un,{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(be,{onClick:P,disabled:j||!M,size:"xs",className:"!font-normal",children:t(j?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(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")})]})})},lp=t=>{switch(t){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"idle"}},cp=t=>{const e=st.c(5),{tone:n,enabled:r}=t;if(!r){let o;return e[0]===Symbol.for("react.memo_cache_sentinel")?(o=s.jsx("span",{className:"inline-block h-2 w-2 rounded-full bg-muted-foreground/30 flex-shrink-0"}),e[0]=o):o=e[0],o}let a;e[1]!==n?(a=xe("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=st.c(116),{onItemSelect:n}=t,{t:r}=dt(),{mcpServers:a,selectedMcpName:i,setSelectedMcp:o,setMcpDraft:c,loadMcpConfigs:d,deleteMcp:p}=ro(Jn(hk)),m=zs(gk);let u;e[0]!==m?(u=de=>de.getStatusForDirectory(m??null),e[0]=m,e[1]=u):u=e[1];const f=bn(u),b=bn(xk),h=bn(bk),[v,x]=l.useState(null),[g,w]=l.useState(!1),[y,C]=l.useState(null),[k,j]=l.useState(!1);let S;e[2]!==a?(S=a.filter(yk),e[2]=a,e[3]=S):S=e[3];const I=S;let M;e[4]!==a?(M=a.filter(vk),e[4]=a,e[5]=M):M=e[5];const P=M;let A,N;e[6]!==d?(A=()=>{d()},N=[d],e[6]=d,e[7]=A,e[8]=N):(A=e[7],N=e[8]),l.useEffect(A,N);let E;e[9]!==m||e[10]!==h||e[11]!==k||e[12]!==b?(E=()=>{if(k)return;j(!0);const de=new Promise(wk);Promise.all([b({directory:m,silent:!0}),de]).then(()=>{const O=h(m);O&&H.error(O)}).finally(()=>{j(!1)})},e[9]=m,e[10]=h,e[11]=k,e[12]=b,e[13]=E):E=e[13];const T=E;let R;e[14]!==a||e[15]!==n||e[16]!==c||e[17]!==o?(R=()=>{let de="new-mcp-server",O=1;for(;a.some($=>$.name===de);)de=`new-mcp-server-${O}`,O++;c({name:de,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),o(de),n?.()},e[14]=a,e[15]=n,e[16]=c,e[17]=o,e[18]=R):R=e[18];const V=R;let _;e[19]!==p||e[20]!==v||e[21]!==r?(_=async()=>{if(!v)return;w(!0);const de=await p(v.name);de.ok?de.reloadFailed?H.warning(de.message||`MCP server "${v.name}" deleted, but OpenCode reload failed`,{description:de.warning||r("settings.mcp.sidebar.toast.refreshListIfStale")}):H.success(de.message||r("settings.mcp.sidebar.toast.serverDeleted",{name:v.name})):H.error(r("settings.mcp.sidebar.toast.deleteFailed")),x(null),w(!1)},e[19]=p,e[20]=v,e[21]=r,e[22]=_):_=e[22];const U=_;let B;e[23]===Symbol.for("react.memo_cache_sentinel")?(B=xe("flex h-full flex-col","bg-background"),e[23]=B):B=e[23];let z;e[24]!==r?(z=r("settings.mcp.sidebar.title"),e[24]=r,e[25]=z):z=e[25];let K;e[26]!==z?(K=s.jsx("h2",{className:"text-base font-semibold text-foreground",children:z}),e[26]=z,e[27]=K):K=e[27];let F;e[28]!==r?(F=r("settings.mcp.sidebar.actions.refreshStatusAria"),e[28]=r,e[29]=F):F=e[29];let G;e[30]!==r?(G=r("settings.mcp.sidebar.actions.refreshStatusTitle"),e[30]=r,e[31]=G):G=e[31];const Q=k&&"animate-spin";let te;e[32]!==Q?(te=xe("h-4 w-4",Q),e[32]=Q,e[33]=te):te=e[33];let Z;e[34]!==te?(Z=s.jsx(D,{name:"refresh",className:te}),e[34]=te,e[35]=Z):Z=e[35];let fe;e[36]!==T||e[37]!==k||e[38]!==F||e[39]!==G||e[40]!==Z?(fe=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:T,"aria-label":F,title:G,children:Z}),e[36]=T,e[37]=k,e[38]=F,e[39]=G,e[40]=Z,e[41]=fe):fe=e[41];let ue;e[42]!==K||e[43]!==fe?(ue=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[K,fe]}),e[42]=K,e[43]=fe,e[44]=ue):ue=e[44];let W;e[45]===Symbol.for("react.memo_cache_sentinel")?(W=s.jsx(ho,{className:"mb-3"}),e[45]=W):W=e[45];let q;e[46]!==a.length||e[47]!==r?(q=r("settings.mcp.sidebar.total",{count:a.length}),e[46]=a.length,e[47]=r,e[48]=q):q=e[48];let J;e[49]!==q?(J=s.jsx("span",{className:"typography-meta text-muted-foreground",children:q}),e[49]=q,e[50]=J):J=e[50];let ne;e[51]!==r?(ne=r("settings.mcp.sidebar.actions.addServerTitle"),e[51]=r,e[52]=ne):ne=e[52];let ee;e[53]===Symbol.for("react.memo_cache_sentinel")?(ee=s.jsx(D,{name:"add",className:"h-3.5 w-3.5"}),e[53]=ee):ee=e[53];let he;e[54]!==V||e[55]!==ne?(he=s.jsx(be,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:V,title:ne,children:ee}),e[54]=V,e[55]=ne,e[56]=he):he=e[56];let ke;e[57]!==J||e[58]!==he?(ke=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[J,he]}),e[57]=J,e[58]=he,e[59]=ke):ke=e[59];let oe;e[60]!==ue||e[61]!==ke?(oe=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[ue,W,ke]}),e[60]=ue,e[61]=ke,e[62]=oe):oe=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]!==o||e[71]!==r||e[72]!==P?(ge=s.jsx(Ns,{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(de=>{const O=f[de.name],L=lp(O?.status),$=i===de.name,je=Zi();return s.jsxs("div",{className:xe("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",$?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:je?void 0:ae=>{ae.preventDefault(),C(de.name)},children:[s.jsxs("button",{onClick:()=>{o(de.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(cp,{tone:L,enabled:de.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:de.name}),s.jsx("span",{title:de.type==="local"?r("settings.mcp.sidebar.serverType.localTitle"):r("settings.mcp.sidebar.serverType.remoteTitle"),children:de.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:de.type==="local"?de.command?.join(" ")??"":de.url??""})]}),s.jsxs(Ts,{open:y===de.name,onOpenChange:ae=>C(ae?de.name:null),children:[s.jsx(As,{asChild:!0,children:s.jsx(be,{size:"xs",variant:"ghost",className:"flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(D,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Ds,{align:"end",className:"w-fit min-w-20",children:s.jsxs($t,{onClick:ae=>{ae.stopPropagation(),x(de)},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")]})})]})]},de.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(de=>{const O=f[de.name],L=lp(O?.status),$=i===de.name,je=Zi();return s.jsxs("div",{className:xe("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",$?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:je?void 0:ae=>{ae.preventDefault(),C(de.name)},children:[s.jsxs("button",{onClick:()=>{o(de.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(cp,{tone:L,enabled:de.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:de.name}),s.jsx("span",{title:de.type==="local"?r("settings.mcp.sidebar.serverType.localTitle"):r("settings.mcp.sidebar.serverType.remoteTitle"),children:de.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:de.type==="local"?de.command?.join(" ")??"":de.url??""})]}),s.jsxs(Ts,{open:y===de.name,onOpenChange:ae=>C(ae?de.name:null),children:[s.jsx(As,{asChild:!0,children:s.jsx(be,{size:"xs",variant:"ghost",className:"flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(D,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Ds,{align:"end",className:"w-fit min-w-20",children:s.jsxs($t,{onClick:ae=>{ae.stopPropagation(),x(de)},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")]})})]})]},de.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]=o,e[71]=r,e[72]=P,e[73]=ge):ge=e[73];const me=v!==null;let ye;e[74]!==g?(ye=de=>{!de&&!g&&x(null)},e[74]=g,e[75]=ye):ye=e[75];let ie;e[76]!==r?(ie=r("settings.mcp.sidebar.deleteDialog.title"),e[76]=r,e[77]=ie):ie=e[77];let ve;e[78]!==ie?(ve=s.jsx(hs,{children:ie}),e[78]=ie,e[79]=ve):ve=e[79];const X=v?.name||"";let Se;e[80]!==r||e[81]!==X?(Se=r("settings.mcp.sidebar.deleteDialog.descriptionPrefix",{name:X}),e[80]=r,e[81]=X,e[82]=Se):Se=e[82];let Ae;e[83]===Symbol.for("react.memo_cache_sentinel")?(Ae=s.jsx("code",{className:"text-foreground",children:"opencode.json"}),e[83]=Ae):Ae=e[83];let pe;e[84]!==Se?(pe=s.jsxs(Ss,{children:[Se," ",Ae,"."]}),e[84]=Se,e[85]=pe):pe=e[85];let we;e[86]!==ve||e[87]!==pe?(we=s.jsxs(ys,{children:[ve,pe]}),e[86]=ve,e[87]=pe,e[88]=we):we=e[88];let Ie;e[89]===Symbol.for("react.memo_cache_sentinel")?(Ie=()=>x(null),e[89]=Ie):Ie=e[89];let Y;e[90]!==r?(Y=r("settings.common.actions.cancel"),e[90]=r,e[91]=Y):Y=e[91];let re;e[92]!==g||e[93]!==Y?(re=s.jsx(be,{size:"sm",variant:"ghost",onClick:Ie,disabled:g,children:Y}),e[92]=g,e[93]=Y,e[94]=re):re=e[94];let Pe;e[95]!==g||e[96]!==r?(Pe=r(g?"settings.mcp.sidebar.actions.deleting":"settings.common.actions.delete"),e[95]=g,e[96]=r,e[97]=Pe):Pe=e[97];let ce;e[98]!==U||e[99]!==g||e[100]!==Pe?(ce=s.jsx(be,{size:"sm",onClick:U,disabled:g,children:Pe}),e[98]=U,e[99]=g,e[100]=Pe,e[101]=ce):ce=e[101];let Ce;e[102]!==re||e[103]!==ce?(Ce=s.jsxs(Vs,{children:[re,ce]}),e[102]=re,e[103]=ce,e[104]=Ce):Ce=e[104];let Te;e[105]!==we||e[106]!==Ce?(Te=s.jsxs(ms,{className:"max-w-md",children:[we,Ce]}),e[105]=we,e[106]=Ce,e[107]=Te):Te=e[107];let $e;e[108]!==me||e[109]!==ye||e[110]!==Te?($e=s.jsx(ps,{open:me,onOpenChange:ye,children:Te}),e[108]=me,e[109]=ye,e[110]=Te,e[111]=$e):$e=e[111];let De;return e[112]!==oe||e[113]!==ge||e[114]!==$e?(De=s.jsxs("div",{className:B,children:[oe,ge,$e]}),e[112]=oe,e[113]=ge,e[114]=$e,e[115]=De):De=e[115],De};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 ca(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Mi(t){return Array.isArray(t)&&t.every(e=>typeof e=="string")}function xa(t,e){return e!==void 0?{ok:!1,error:t,parsed:e}:{ok:!1,error:t}}function Nc(t,e,n){const r=jk(n),a=typeof n.url=="string"?n.url.trim():"",i=dp(n,"env","environment"),o=dp(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:o,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(Mi(e)&&Mi(n))return[...e,...n];if(Mi(e))return e;if(typeof e=="string"&&e.trim()){const r=e.trim().split(/\s+/);return Mi(n)?[...r,...n]:r}return Mi(n)?n:[]}function dp(t,...e){for(const n of e){const r=t[n];if(!ca(r))continue;const a=Object.entries(r).filter(([i,o])=>i&&typeof o=="string");if(a.length>0)return a.map(([i,o])=>({key:i,value:String(o)}))}return[]}function Nk(t){if(t.oauth===!1||t.oauth===null||t.oauth===void 0||!ca(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(ca(e)){const r=Object.keys(e);if(r.length===1){const a=r[0],i=e[a];if(ca(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"&&ca(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 o=t.trim();if(!o)return xa("No JSON content provided");n=JSON.parse(o)}catch(o){return xa(o instanceof Error?`Invalid JSON: ${o.message}`:"Invalid JSON")}if(!ca(n))return xa("Expected a JSON object, not an array or primitive");const r=n,a=r.mcpServers;if(ca(a)){const o=Object.keys(a);if(o.length===0)return xa("mcpServers object is empty",n);if(o.length>1)return xa("Paste one server at a time. Found "+o.length+" servers in mcpServers",n);const c=o[0],d=a[c];return ca(d)?Nc(c,Sc(d),d):xa("Server entry is not a valid object",n)}const i=Ck(r);if(i)return Nc(i.name,Sc(i.entry),i.entry);if(ug(r)){const o=Sc(r),c=typeof r.name=="string"&&r.name.trim()?r.name.trim():e?.fallbackName;return Nc(c,o,r)}return xa("No recognizable MCP server configuration found in JSON",n)}function Sc(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}},Xd=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 o=t[i];if(o==="'"&&!a){r=!r;continue}if(o==='"'&&!r){a=!a;continue}if((o===" "||o===" ")&&!r&&!a){n&&(e.push(n),n="");continue}n+=o}return n&&e.push(n),e}function 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:Xd(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:o})=>{const[c,d]=l.useState(()=>t.join(`
157
+ `)),p=l.useRef(t);l.useEffect(()=>{JSON.stringify(p.current)!==JSON.stringify(t)&&(p.current=t,d(t.join(`
158
+ `)))},[t]);const m=f=>{const b=f.split(`
159
+ `).filter(h=>h.trim().length>0);e(b)},u=async()=>{try{const b=(await navigator.clipboard.readText()).trim(),h=b.includes(`
160
+ `)?b.split(`
161
+ `).filter(v=>v.trim()):Tk(b);d(h.join(`
162
+ `)),e(h),H.success(a(h.length))}catch{H.error(i)}};return s.jsxs("div",{className:"space-y-2","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",children:[s.jsx("div",{className:"flex items-center justify-end gap-2",children:s.jsxs(be,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:u,type:"button",title:n,children:[s.jsx(D,{name:"clipboard",className:"h-3 w-3"}),r]})}),s.jsx(un,{value:c,onChange:f=>{d(f.target.value),m(f.target.value)},onBlur:()=>{const f=c.split(`
163
+ `).map(b=>b.trimEnd()).join(`
164
+ `);d(f),m(f)},placeholder:`npx
165
+ -y
166
+ @modelcontextprotocol/server-postgres
167
+ postgresql://user:pass@host/db`,rows:Math.max(4,t.length+1),className:"font-mono typography-meta resize-y min-h-[80px]",spellCheck:!1}),t.length>0&&s.jsxs("details",{className:"group",children:[s.jsx("summary",{className:"typography-micro text-muted-foreground/60 cursor-pointer select-none hover:text-muted-foreground",children:o(t.length)}),s.jsx("div",{className:"mt-1 rounded-md bg-[var(--surface-elevated)] px-3 py-2 overflow-x-auto",children:s.jsx("code",{className:"typography-micro text-foreground/80 whitespace-pre",children:t.map((f,b)=>s.jsxs("span",{className:"block",children:[s.jsxs("span",{className:"text-muted-foreground select-none mr-2",children:["[",b,"]"]}),f]},b))})})]})]})},Rk=t=>t.toUpperCase().replace(/[^A-Z0-9_]/g,"_"),up=({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:o="Paste KEY=VALUE lines from clipboard",noPairsFoundError:c,importSuccess:d,clipboardReadFailed:p,keyLabel:m,valueLabel:u,valuePlaceholder:f,hideValueTitle:b,showValueTitle:h,addVariable:v,plainTextWarning:x,removeVariableAria:g})=>{const[w,y]=l.useState(new Set),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})},j=(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 T=E.trim();if(!T||T.startsWith("#"))continue;const R=T.indexOf("=");if(R===-1)continue;const V=T.slice(0,R).trim();let _=T.slice(R+1).trim();(_.startsWith('"')&&_.endsWith('"')||_.startsWith("'")&&_.endsWith("'"))&&(_=_.slice(1,-1)),V&&A.push({key:V,value:_})}if(A.length===0){H.error(c);return}const N=[...t];for(const E of A){const T=N.findIndex(R=>R.key===E.key);T!==-1?N[T]=E:N.push(E)}e(N),H.success(d(A.length))}catch{H.error(p)}},M=t.some(P=>P.value.length>0);return s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("span",{className:"typography-micro text-muted-foreground w-32 shrink-0",children:m}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:u})]}),s.jsxs(be,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:I,type:"button",title:o,children:[s.jsx(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=>j(A,"key",n(N.target.value)),placeholder:r,className:a,"data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),s.jsxs("div",{className:"relative flex-1 flex items-center",children:[s.jsx(Bt,{type:w.has(A)?"text":"password",value:P.value,onChange:N=>j(A,"value",N.target.value),placeholder:f,className:"font-mono typography-meta pr-8 w-full",autoComplete:"new-password","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),s.jsx("button",{type:"button",onClick:()=>S(A),className:"absolute right-2 text-muted-foreground/60 hover:text-muted-foreground",title:w.has(A)?b:h,children:w.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(be,{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":g,children:s.jsx(D,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},A))}),s.jsxs(be,{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]}),M&&s.jsx("p",{className:"typography-micro text-muted-foreground/60",children:x})]})},mp=t=>{const e=st.c(14),{status:n,enabled:r,getStatusLabel:a,variant:i}=t,o=i===void 0?"compact":i;if(!r||!n)return null;let c,d;if(e[0]!==a||e[1]!==n||e[2]!==o){d=Symbol.for("react.early_return_sentinel");e:{const f={connected:{text:"text-[var(--status-success)]",bg:"bg-[var(--status-success)]/10"},failed:{text:"text-[var(--status-error)]",bg:"bg-[var(--status-error)]/10"},needs_auth:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"},needs_client_registration:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"}}[n]??{text:"text-muted-foreground",bg:""};if(o==="pill"){const b=xe("typography-micro font-medium rounded-full px-2 py-0.5",f.text,f.bg);let h;e[5]!==a||e[6]!==n?(h=a(n),e[5]=a,e[6]=n,e[7]=h):h=e[7],d=s.jsxs("span",{className:b,children:["● ",h]});break e}c=xe("typography-micro font-medium",f.text)}e[0]=a,e[1]=n,e[2]=o,e[3]=c,e[4]=d}else c=e[3],d=e[4];if(d!==Symbol.for("react.early_return_sentinel"))return d;let p;e[8]!==a||e[9]!==n?(p=a(n),e[8]=a,e[9]=n,e[10]=p):p=e[10];let m;return e[11]!==c||e[12]!==p?(m=s.jsxs("span",{className:c,children:["● ",p]}),e[11]=c,e[12]=p,e[13]=m):m=e[13],m},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),pp=(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},Ei=async t=>{typeof t!="string"||!t.trim()||await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(t.trim())}`,{method:"DELETE"}).catch(()=>{})},kc=(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}`},zk=()=>{const{t}=dt(),e=l.useCallback((We,St)=>t(We,St),[t]),{selectedMcpName:n,mcpServers:r,mcpDraft:a,setMcpDraft:i,setSelectedMcp:o,getMcpByName:c,createMcp:d,updateMcp:p,deleteMcp:m}=ro(Jn(We=>({selectedMcpName:We.selectedMcpName,mcpServers:We.mcpServers,mcpDraft:We.mcpDraft,setMcpDraft:We.setMcpDraft,setSelectedMcp:We.setSelectedMcp,getMcpByName:We.getMcpByName,createMcp:We.createMcp,updateMcp:We.updateMcp,deleteMcp:We.deleteMcp}))),u=zs(We=>We.currentDirectory),f=l.useMemo(()=>on(),[]),b=bn(We=>We.getStatusForDirectory(u??null)),h=bn(We=>We.getDiagnosticForDirectory(u??null)),v=bn(We=>We.refresh),x=bn(We=>We.connect),g=bn(We=>We.disconnect),w=bn(We=>We.startAuth),y=bn(We=>We.completeAuth),C=bn(We=>We.clearAuth),k=bn(We=>We.testConnection),j=n?c(n):null,S=!!(a&&a.name===n&&!j),[I,M]=l.useState(""),[P,A]=l.useState("user"),[N,E]=l.useState("local"),[T,R]=l.useState([]),[V,_]=l.useState(""),[U,B]=l.useState([]),[z,K]=l.useState([]),[F,G]=l.useState(!0),[Q,te]=l.useState(""),[Z,fe]=l.useState(""),[ue,W]=l.useState(""),[q,J]=l.useState(""),[ne,ee]=l.useState(""),[he,ke]=l.useState(!0),[oe,ge]=l.useState(!1),[me,ye]=l.useState(!1),[ie,ve]=l.useState(!1),[X,Se]=l.useState(!1),[Ae,pe]=l.useState(!1),[we,Ie]=l.useState(!1),[Y,re]=l.useState(!1),[Pe,ce]=l.useState(!1),[Ce,Te]=l.useState(null),[$e,De]=l.useState(null),[de,O]=l.useState(""),[L,$]=l.useState(!1),je=l.useRef(0),ae=l.useRef(!1),[_e,le]=l.useState(!1),[Me,Ge]=l.useState(!1),[at,Ye]=l.useState(""),[Xe,ut]=l.useState(null),rt=l.useMemo(()=>Bk(n,u),[u,n]),it=l.useRef(rt),nt=l.useRef(null),Ne=l.useCallback(()=>{Te(null),De(null),O(""),$(!1),je.current=0,ce(!1),pe(!1),Ie(!1),ae.current=!1},[]),Ke=l.useCallback(()=>{Ye(""),ut(null),Ge(!0)},[]),Ve=l.useCallback(async()=>{try{const We=await navigator.clipboard.readText();Ye(We),ut(null)}catch{H.error(t("settings.mcp.page.toast.clipboardReadFailed"))}},[t]),qe=l.useCallback(()=>{const We=Ik(at,{fallbackName:I});if(!We.ok){ut(We.error);return}const qt=Pk(We,{name:I,scope:P,type:N,command:T,url:V,environment:U,headers:z,oauthEnabled:F,oauthClientId:Q,oauthClientSecret:Z,oauthScope:ue,oauthRedirectUri:q,timeout:ne,enabled:he},{isNewServer:S});M(qt.name),E(qt.type),R(qt.command??[]),_(qt.url??""),B(qt.environment??[]),K(qt.headers??[]),G(qt.oauthEnabled??!1),te(qt.oauthClientId??""),fe(qt.oauthClientSecret??""),W(qt.oauthScope??""),J(qt.oauthRedirectUri??""),ee(qt.timeout??""),ke(qt.enabled??!0),Ge(!1),Ye(""),ut(null),H.success(t("settings.mcp.page.toast.configImported"))},[at,I,P,N,T,V,U,z,F,Q,Z,ue,q,ne,he,S,t]);l.useEffect(()=>{if(S&&a){M(a.name),A(a.scope||"user"),E(a.type),R(a.command),_(a.url),B(a.environment),K(a.headers),G(a.oauthEnabled),te(a.oauthClientId),fe(a.oauthClientSecret),W(a.oauthScope),J(a.oauthRedirectUri),ee(a.timeout),ke(a.enabled),le(!1),nt.current={mcpType:a.type,command:a.command,url:a.url,envEntries:a.environment,headerEntries:a.headers,oauthEnabled:a.oauthEnabled,oauthClientId:a.oauthClientId,oauthClientSecret:a.oauthClientSecret,oauthScope:a.oauthScope,oauthRedirectUri:a.oauthRedirectUri,timeout:a.timeout,enabled:a.enabled};return}if(j){A(j.scope==="project"?"project":"user");const We=qu(j.environment),St=j.type==="remote"?j:null,qt=qu(St?.headers),wt=St?.oauth,es=wt&&typeof wt=="object"?wt:null,ds=wt!==!1,Ms=j.type,as=Ms==="local"?j.command??[]:[],$s=Ms==="remote"?j.url??"":"",Ls=typeof St?.timeout=="number"&&Number.isFinite(St.timeout)?String(St.timeout):"";E(Ms),R(as),_($s),B(We),K(qt),G(ds),te(ds?es?.clientId??"":""),fe(ds?es?.clientSecret??"":""),W(ds?es?.scope??"":""),J(ds?es?.redirectUri??"":""),ee(Ls),ke(j.enabled),le(!1),nt.current={mcpType:Ms,command:as,url:$s,envEntries:We,headerEntries:qt,oauthEnabled:ds,oauthClientId:ds?es?.clientId??"":"",oauthClientSecret:ds?es?.clientSecret??"":"",oauthScope:ds?es?.scope??"":"",oauthRedirectUri:ds?es?.redirectUri??"":"",timeout:Ls,enabled:j.enabled}}},[j,S,a]);const lt=l.useMemo(()=>{const We=nt.current;return We?N!==We.mcpType||he!==We.enabled||JSON.stringify(T)!==JSON.stringify(We.command)||V!==We.url||JSON.stringify(U)!==JSON.stringify(We.envEntries)||JSON.stringify(z)!==JSON.stringify(We.headerEntries)||F!==We.oauthEnabled||Q!==We.oauthClientId||Z!==We.oauthClientSecret||ue!==We.oauthScope||q!==We.oauthRedirectUri||ne!==We.timeout:!1},[N,T,V,U,z,F,Q,Z,ue,q,ne,he]),He=async()=>{const We=S?I.trim():n??"";if(!We){H.error(t("settings.mcp.page.toast.nameRequired"));return}if(S&&r.some(qt=>qt.name===We)){H.error(t("settings.mcp.page.toast.serverNameExists"));return}if(N==="local"&&T.filter(Boolean).length===0){H.error(t("settings.mcp.page.toast.localCommandRequired"));return}if(N==="remote"&&!V.trim()){H.error(t("settings.mcp.page.toast.remoteUrlRequired"));return}const St={name:We,scope:P,type:N,command:T,url:V,environment:U,headers:z,oauthEnabled:F,oauthClientId:Q,oauthClientSecret:Z,oauthScope:ue,oauthRedirectUri:q,timeout:ne,enabled:he};ge(!0);try{const qt=S?await d(St):await p(We,St);qt.ok?(await Ei($e),Ne(),S&&(i(null),o(We)),await v({directory:u,silent:!0}),qt.reloadFailed?H.warning(qt.message||t(S?"settings.mcp.page.toast.serverCreatedReloadFailed":"settings.mcp.page.toast.savedReloadFailed"),{description:qt.warning||t("settings.mcp.page.toast.retryRefreshHint")}):H.success(qt.message||t(S?"settings.mcp.page.toast.serverCreatedReloading":"settings.mcp.page.toast.savedReloading"))):H.error(t("settings.mcp.page.toast.saveFailed"))}catch(qt){H.error(qt instanceof Error?qt.message:t("settings.mcp.page.toast.unexpectedError"))}finally{ge(!1)}},ze=async()=>{if(!n)return;ve(!0);const We=await m(n);We.ok?(await Ei($e),Ne(),We.reloadFailed?H.warning(We.message||t("settings.mcp.page.toast.serverDeletedReloadFailed",{name:n}),{description:We.warning||t("settings.mcp.page.toast.refreshListIfStale")}):H.success(We.message||t("settings.mcp.page.toast.serverDeleted",{name:n})),ye(!1)):H.error(t("settings.mcp.page.toast.deleteFailed")),ve(!1)},et=async()=>{if(n){Se(!0);try{if(b[n]?.status==="connected")await g(n,u),H.success(t("settings.mcp.page.toast.disconnected"));else{await x(n,u),await v({directory:u,silent:!0});const St=bn.getState().getStatusForDirectory(u??null)[n];St?.status==="connected"?H.success(t("settings.mcp.page.toast.connected")):St?.status==="needs_auth"?H.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):St?.status==="needs_client_registration"?H.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):St?.status==="failed"?H.error(St.error||t("settings.mcp.page.toast.connectionFailed")):H.message(t("settings.mcp.page.toast.connectionAttemptFinished"));return}await v({directory:u,silent:!0})}catch(We){H.error(We instanceof Error?We.message:t("settings.mcp.page.toast.connectionFailed"))}finally{Se(!1)}}},yt=l.useCallback(()=>S?(H.error(t("settings.mcp.page.toast.createServerBeforeLiveActions")),!1):lt?(H.error(t("settings.mcp.page.toast.saveBeforeLiveActions")),!1):!0,[lt,S,t]),Rt=l.useCallback(async(We=!1)=>{try{await v({directory:u,silent:We})}catch(St){We||H.error(St instanceof Error?St.message:t("settings.mcp.page.toast.refreshStatusFailed"))}},[u,v,t]);l.useEffect(()=>{Rt(!0)},[Rt]),l.useEffect(()=>{it.current=rt,Se(!1),re(!1),Ne()},[Ne,rt]);const kt=l.useCallback(async()=>{if(!n||N!=="remote"||!yt())return;pe(!0);const We=rt;let St=null;try{const qt=bn.getState().getStatusForDirectory(u??null)[n]?.status;ae.current=qt==="needs_auth"||qt==="needs_client_registration";const wt=pp(n,u);if(!wt)throw new Error(t("settings.mcp.page.toast.oauthRedirectUrlBuildFailed"));if(!q.trim()&&!f){const as=await p(n,{oauthEnabled:F,oauthClientId:Q,oauthClientSecret:Z,oauthScope:ue,oauthRedirectUri:wt});if(!as.ok)throw new Error(t("settings.mcp.page.toast.oauthBrowserCallbackSaveFailed"));if(as.reloadFailed)throw new Error(as.warning||as.message||t("settings.mcp.page.toast.openCodeReloadFailedAfterCallbackSave"));if(it.current!==We)return;J(wt),nt.current=nt.current?{...nt.current,oauthRedirectUri:wt}:nt.current}const es=await w(n,u),ds=Xd(new URL(es).searchParams);if(ds&&(St=ds,await $k({state:ds,name:n,directory:u})),it.current!==We)return;Te(es),De(ds??null),$(!0),je.current=0;const Ms=await qn(es);if(it.current!==We)return;Ms?H.message(t(f?"settings.mcp.page.toast.completeAuthorizationInBrowserWithPaste":"settings.mcp.page.toast.completeAuthorizationInBrowser")):H.error(t("settings.mcp.page.toast.openAuthorizationUrlFailed"))}catch(qt){await Ei(St),it.current===We&&H.error(kc(qt,t("settings.mcp.page.toast.authorizationStartFailed"),e))}finally{it.current===We&&pe(!1)}},[u,f,N,Q,Z,F,q,ue,yt,rt,n,w,t,e,p]),ht=l.useCallback(async()=>{if(!n||!yt())return;Ie(!0);const We=rt;try{if(await C(n,u),it.current!==We)return;Te(null),De(null),O(""),$(!1),je.current=0,await Ei($e),H.success(t("settings.mcp.page.toast.savedAuthorizationRemoved"))}catch(St){it.current===We&&H.error(kc(St,t("settings.mcp.page.toast.clearAuthorizationFailed"),e))}finally{it.current===We&&Ie(!1)}},[$e,C,u,yt,rt,n,t,e]),vt=l.useCallback(async()=>{if(!Ce)return;if((await In(Ce)).ok){H.success(t("settings.mcp.page.toast.authorizationUrlCopied"));return}H.error(t("settings.mcp.page.toast.authorizationUrlCopyFailed"))},[Ce,t]),ns=l.useCallback(async()=>{const We=Mk(de);if(!We.code){H.error(t("settings.mcp.page.toast.pasteCallbackOrCodeFirst"));return}const St=We.stateKey?await _k(We.stateKey):null,qt=We.context??St,wt=qt?.name??n,es=qt?.directory??u;if(!wt){H.error(t("settings.mcp.page.toast.missingServerDetails"));return}if(!qt&&!yt())return;ce(!0);const ds=rt;try{if(await y(wt,We.code,es),await Ei(We.stateKey??$e),it.current!==ds)return;O(""),Te(null),De(null),$(!1),je.current=0,H.success(wt===n?t("settings.mcp.page.toast.authorizationCompleted"):t("settings.mcp.page.toast.authorizationCompletedFor",{name:wt}))}catch(Ms){it.current===ds&&H.error(kc(Ms,t("settings.mcp.page.toast.authorizationCompleteFailed"),e))}finally{it.current===ds&&ce(!1)}},[de,$e,y,u,yt,rt,n,t,e]),zt=l.useCallback(async()=>{if(!(!n||!yt())){if(!he){H.error(t("settings.mcp.page.toast.enableServerBeforeTest"));return}re(!0);try{const We=await k(n,u),St=We.status?.status;We.warning?H.warning(We.warning):St==="connected"?H.success(t("settings.mcp.page.toast.connectionTestSucceeded")):St==="needs_auth"?H.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):St==="needs_client_registration"?H.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):St==="failed"?H.error(We.status?.error||We.error||t("settings.mcp.page.toast.connectionTestFailed")):We.error?H.error(We.error):H.message(t("settings.mcp.page.toast.connectionTestFinished"))}catch(We){H.error(We instanceof Error?We.message:t("settings.mcp.page.toast.connectionTestFailed"))}finally{re(!1)}}},[u,he,yt,n,t,k]);if(l.useEffect(()=>{if(!L||!n)return;const We=window.setInterval(()=>{(async()=>{je.current+=1,await v({directory:u,silent:!0});const St=bn.getState().getStatusForDirectory(u??null)[n];if(St){if(ae.current&&St.status!=="needs_auth"&&St.status!=="needs_client_registration"){$(!1),je.current=0,ae.current=!1,Te(null),O(""),St.status==="connected"&&H.success(t("settings.mcp.page.toast.authorizationCompleted"));return}if(!ae.current&&St.status==="failed"){$(!1),je.current=0,ae.current=!1,H.error(St.error||t("settings.mcp.page.toast.authorizationFailed"));return}je.current>=30&&($(!1),je.current=0,ae.current=!1,H.message(t("settings.mcp.page.toast.authorizationStillInProgress")))}})()},2e3);return()=>{window.clearInterval(We)}},[u,L,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 Kt=b[n],mt=n?h[n]:void 0,Et=Kt??mt,rs=Kt?.status==="connected",gs=Kt?.status==="needs_auth"||Kt?.status==="needs_client_registration",xs=f?null:pp(n,u),bs=Fk(Et?.status,e,Et&&"error"in Et?Et.error:void 0),Wt=We=>{switch(We){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 We}};return s.jsxs(Ns,{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(mp,{status:Et?.status,enabled:he,getStatusLabel:Wt,variant:"pill"})]}),s.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:S?t("settings.mcp.page.header.configureNewServer"):t("settings.mcp.page.header.transport",{type:t(N==="local"?"settings.mcp.page.transport.local":"settings.mcp.page.transport.remote")})}),!S&&s.jsxs(s.Fragment,{children:[s.jsx(be,{variant:rs?"outline":"default",size:"xs",className:"!font-normal",onClick:et,disabled:X||!he,children:t(X?"settings.mcp.page.actions.working":rs?"settings.mcp.page.actions.disconnect":"settings.mcp.page.actions.connect")}),N==="remote"&&s.jsxs(s.Fragment,{children:[s.jsx(be,{variant:gs?"default":"outline",size:"xs",className:"!font-normal",onClick:()=>{kt()},disabled:Ae||!he,children:t(Ae?"settings.mcp.page.actions.starting":gs?"settings.mcp.page.actions.authorize":"settings.mcp.page.actions.reauthorize")}),s.jsx(be,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{ht()},disabled:we||!he,children:t(we?"settings.mcp.page.actions.clearing":"settings.mcp.page.actions.clearAuth")})]}),rs&&s.jsx(be,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{zt()},disabled:Y||!he,children:t(Y?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.test")})]})]})]})}),!S&&Lk(Et?.status,Ce,gs,L)&&s.jsx("div",{className:"mb-6 px-2",children:s.jsxs("div",{className:xe("rounded-lg border p-3",Ok(Et?.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(mp,{status:Et?.status,enabled:he,getStatusLabel:Wt})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:bs}),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:!rs&&s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{zt()},disabled:Y||!he,children:t(Y?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.testConnection")})}),Ce&&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:Ce}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{qn(Ce)},children:[s.jsx(D,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.openInBrowser")]}),s.jsxs(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{vt()},children:[s.jsx(D,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.copyLink")]})]})]})}),N==="remote"&&(gs||L||Ce)&&s.jsx("div",{className:"rounded-md border border-[var(--interactive-border)] bg-[var(--surface-background)] px-3 py-3",children:s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:t("settings.mcp.page.auth.manualFallbackTitle")}),s.jsx("p",{className:"mt-1 typography-micro text-muted-foreground",children:t("settings.mcp.page.auth.manualFallbackDescription")})]}),s.jsx(un,{value:de,onChange:We=>O(We.target.value),placeholder:t("settings.mcp.page.auth.callbackInputPlaceholder"),rows:3,className:"font-mono typography-meta resize-y","data-bwignore":"true","data-1p-ignore":"true",spellCheck:!1}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ns()},disabled:Pe,children:t(Pe?"settings.mcp.page.actions.completing":"settings.mcp.page.actions.completeAuthorization")})})]})})]}),L&&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:We=>M(We.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(os,{value:P,onValueChange:We=>A(We),children:[s.jsx(ls,{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(cs,{align:"end",children:[s.jsx(Tt,{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(Tt,{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(be,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:Ke,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":he,onClick:()=>ke(!he),onKeyDown:We=>{(We.key===" "||We.key==="Enter")&&(We.preventDefault(),ke(!he))},children:[s.jsx(fs,{checked:he,onChange:ke,ariaLabel:t("settings.mcp.page.server.enableAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.mcp.page.server.enable")})]}),s.jsx("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:s.jsxs("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.mcp.page.server.transportMode")}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[s.jsx(be,{variant:"chip",size:"xs","aria-pressed":N==="local",onClick:()=>E("local"),className:"!font-normal",children:t("settings.mcp.page.transport.local")}),s.jsx(be,{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:T,onChange:R,pasteCommandTitle:t("settings.mcp.page.connection.pasteCommandTitle"),pasteCommandLabel:t("settings.mcp.page.connection.pasteCommand"),pasteSuccess:We=>t("settings.mcp.page.toast.pastedArgumentsCount",{count:We}),clipboardReadFailed:t("settings.mcp.page.toast.clipboardReadFailed"),preview:We=>t("settings.mcp.page.connection.previewArgs",{count:We})}):s.jsx(Bt,{value:V,onChange:We=>_(We.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(fr,{open:_e,onOpenChange:le,children:[s.jsxs(kr,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:t("settings.mcp.page.advanced.configure")}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",t(F?"settings.mcp.page.advanced.autoDetect":"settings.mcp.page.advanced.custom")," · ",z.length," ",t("settings.mcp.page.advanced.headers"),ne?` · ${ne}ms`:"",")"]})]}),_e?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(hr,{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:ne,onChange:We=>ee(We.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"),z.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",z.length,")"]})]}),s.jsx(up,{value:z,onChange:K,keyTransform:We=>We.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:We=>t("settings.mcp.page.toast.importedVariablesCount",{count:We}),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":F,onClick:()=>G(!F),onKeyDown:We=>{(We.key===" "||We.key==="Enter")&&(We.preventDefault(),G(!F))},children:[s.jsx(fs,{checked:F,onChange:G,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:Q,onChange:We=>te(We.target.value),placeholder:t("settings.mcp.page.advanced.oauthClientIdPlaceholder"),className:"font-mono typography-meta",disabled:!F,"data-bwignore":"true","data-1p-ignore":"true"}),s.jsx(Bt,{value:Z,onChange:We=>fe(We.target.value),placeholder:t("settings.mcp.page.advanced.oauthClientSecretPlaceholder"),className:"font-mono typography-meta",disabled:!F,"data-bwignore":"true","data-1p-ignore":"true"}),s.jsx(Bt,{value:ue,onChange:We=>W(We.target.value),placeholder:t("settings.mcp.page.advanced.oauthScopesPlaceholder"),className:"font-mono typography-meta",disabled:!F,"data-bwignore":"true","data-1p-ignore":"true"}),s.jsx(Bt,{value:q,onChange:We=>J(We.target.value),placeholder:t("settings.mcp.page.advanced.oauthRedirectUriPlaceholder"),className:"font-mono typography-meta",disabled:!F,"data-bwignore":"true","data-1p-ignore":"true"})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("settings.mcp.page.advanced.oauthHint")}),xs&&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:xs})]})]})]})})]})})]}),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"),U.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",U.length,")"]})]})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:U.length===0?s.jsxs(be,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:()=>B([{key:"",value:""}]),children:[s.jsx(D,{name:"add",className:"h-3.5 w-3.5"}),t("settings.mcp.page.env.addEnvironmentVariable")]}):s.jsx(up,{value:U,onChange:B,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:We=>t("settings.mcp.page.toast.importedVariablesCount",{count:We}),clipboardReadFailed:t("settings.mcp.page.toast.clipboardReadFailed"),keyLabel:t("settings.mcp.page.env.key"),valueLabel:t("settings.mcp.page.env.value"),valuePlaceholder:t("settings.mcp.page.env.valuePlaceholder"),hideValueTitle:t("settings.mcp.page.env.hide"),showValueTitle:t("settings.mcp.page.env.show"),addVariable:t("settings.mcp.page.env.addVariable"),plainTextWarning:t("settings.mcp.page.env.plainTextWarning"),removeVariableAria:t("settings.mcp.page.env.removeVariableAria")})})]}),s.jsxs("div",{className:"flex items-center gap-2 px-2 py-1",children:[s.jsx(be,{onClick:He,disabled:oe||!lt&&!S,size:"xs",className:"!font-normal",children:t(oe?"settings.common.actions.saving":S?"settings.common.actions.create":"settings.common.actions.saveChanges")}),!S&&s.jsx(be,{variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>ye(!0),children:t("settings.common.actions.delete")})]})]}),s.jsx(ps,{open:Me,onOpenChange:We=>{We||(Ge(!1),Ye(""),ut(null))},children:s.jsxs(ms,{className:"max-w-md",children:[s.jsxs(ys,{children:[s.jsx(hs,{children:t("settings.mcp.page.importDialog.title")}),s.jsx(Ss,{children:t("settings.mcp.page.importDialog.description")})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsx(un,{value:at,onChange:We=>{Ye(We.target.value),ut(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"}),Xe&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:Xe}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:s.jsxs(be,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:Ve,type:"button",children:[s.jsx(D,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.importDialog.pasteFromClipboard")]})})]}),s.jsxs(Vs,{children:[s.jsx(be,{variant:"outline",onClick:()=>{Ge(!1),Ye(""),ut(null)},className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(be,{onClick:qe,disabled:!at.trim(),size:"sm",children:t("settings.common.actions.import")})]})]})}),s.jsx(ps,{open:me,onOpenChange:We=>{!We&&!ie&&ye(!1)},children:s.jsxs(ms,{className:"max-w-md",children:[s.jsxs(ys,{children:[s.jsx(hs,{children:t("settings.mcp.page.deleteDialog.title",{name:n??""})}),s.jsxs(Ss,{children:[t("settings.mcp.page.deleteDialog.descriptionPrefix")," ",s.jsx("code",{className:"text-foreground",children:"opencode.json"}),"."," ",t("settings.mcp.page.deleteDialog.descriptionSuffix")]})]}),s.jsxs(Vs,{children:[s.jsx(be,{variant:"outline",onClick:()=>ye(!1),disabled:ie,className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(be,{variant:"destructive",size:"sm",onClick:ze,disabled:ie,children:t(ie?"settings.mcp.page.actions.deleting":"settings.common.actions.delete")})]})]})})]})},Vk=t=>{const e=st.c(150),{onItemSelect:n}=t,{t:r}=dt(),[a,i]=l.useState(null),[o,c]=l.useState(""),[d,p]=l.useState(null),[m,u]=l.useState(!1),[f,b]=l.useState(null),{selectedSkillName:h,skills:v,setSelectedSkill:x,setSkillDraft:g,createSkill:w,deleteSkill:y,getSkillDetail:C}=oa(Jn(Uk));let k;e[0]!==n||e[1]!==x||e[2]!==g||e[3]!==v?(k=()=>{let Ve="new-skill",qe=1;for(;v.some(lt=>lt.name===Ve);)Ve=`new-skill-${qe}`,qe++;g({name:Ve,scope:"user",source:"opencode",description:""}),x(Ve),n?.()},e[0]=n,e[1]=x,e[2]=g,e[3]=v,e[4]=k):k=e[4];const j=k;let S;e[5]===Symbol.for("react.memo_cache_sentinel")?(S=async Ve=>{p(Ve)},e[5]=S):S=e[5];const I=S;let M;e[6]!==d||e[7]!==y||e[8]!==r?(M=async()=>{if(!d)return;u(!0),await y(d.name)?(H.success(r("settings.skills.sidebar.toast.skillDeleted",{name:d.name})),p(null)):H.error(r("settings.skills.sidebar.toast.deleteSkillFailed")),u(!1)},e[6]=d,e[7]=y,e[8]=r,e[9]=M):M=e[9];const P=M;let A;e[10]!==C||e[11]!==x||e[12]!==g||e[13]!==v||e[14]!==r?(A=async Ve=>{const qe=Ve.name;let lt=1,He=`${qe}-copy`;for(;v.some(et=>et.name===He);)lt++,He=`${qe}-copy-${lt}`;const ze=await C(Ve.name);if(!ze){H.error(r("settings.skills.sidebar.toast.duplicateLoadFailed"));return}g({name:He,scope:Ve.scope||"user",source:Ve.source||"opencode",description:(ze.sources.md.fields.includes("description"),""),instructions:""}),x(He)},e[10]=C,e[11]=x,e[12]=g,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=Ve=>{c(Ve.name),i(Ve)},e[16]=E):E=e[16];const T=E;let R;e[17]!==w||e[18]!==y||e[19]!==C||e[20]!==a||e[21]!==o||e[22]!==x||e[23]!==v||e[24]!==r?(R=async()=>{if(!a)return;const Ve=o.trim().replace(/\s+/g,"-").toLowerCase();if(!Ve){H.error(r("settings.skills.page.toast.skillNameRequired"));return}if(Ve===a.name){i(null);return}if(v.some(He=>He.name===Ve)){H.error(r("settings.skills.page.toast.skillExists"));return}if(!await C(a.name)){H.error(r("settings.skills.sidebar.toast.renameLoadFailed")),i(null);return}await w({name:Ve,description:"Renamed skill",scope:a.scope,source:a.source})?await y(a.name)?(H.success(`Skill renamed to "${Ve}"`),x(Ve)):H.error(r("settings.skills.sidebar.toast.removeOldAfterRenameFailed")):H.error(r("settings.skills.sidebar.toast.renameFailed")),i(null)},e[17]=w,e[18]=y,e[19]=C,e[20]=a,e[21]=o,e[22]=x,e[23]=v,e[24]=r,e[25]=R):R=e[25];const V=R;let _;e[26]!==v?(_=v.filter(Wk),e[26]=v,e[27]=_):_=e[27];const U=_;let B;e[28]!==v?(B=v.filter(Kk),e[28]=v,e[29]=B):B=e[29];const z=B;let K;e[30]===Symbol.for("react.memo_cache_sentinel")?(K=function(qe){const lt={},He=[];for(const et of qe)et.group?(lt[et.group]||(lt[et.group]=[]),lt[et.group].push(et)):He.push(et);const ze=Object.keys(lt).sort(Hk).map(et=>({name:et,skills:[...lt[et]].sort(Gk)}));return He.sort(qk),{sortedGroups:ze,ungrouped:He}},e[30]=K):K=e[30];const F=K;let G;e[31]!==U?(G=F(U),e[31]=U,e[32]=G):G=e[32];const Q=G;let te;e[33]!==z?(te=F(z),e[33]=z,e[34]=te):te=e[34];const Z=te;let fe;e[35]===Symbol.for("react.memo_cache_sentinel")?(fe=xe("flex h-full flex-col","bg-background"),e[35]=fe):fe=e[35];let ue;e[36]!==r?(ue=r("settings.skills.sidebar.title"),e[36]=r,e[37]=ue):ue=e[37];let W;e[38]!==ue?(W=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:ue}),e[38]=ue,e[39]=W):W=e[39];let q;e[40]===Symbol.for("react.memo_cache_sentinel")?(q=s.jsx(ho,{className:"mb-3"}),e[40]=q):q=e[40];let J;e[41]!==v.length||e[42]!==r?(J=r("settings.skills.sidebar.total",{count:v.length}),e[41]=v.length,e[42]=r,e[43]=J):J=e[43];let ne;e[44]!==J?(ne=s.jsx("span",{className:"typography-meta text-muted-foreground",children:J}),e[44]=J,e[45]=ne):ne=e[45];let ee;e[46]===Symbol.for("react.memo_cache_sentinel")?(ee=s.jsx(D,{name:"add",className:"h-3.5 w-3.5"}),e[46]=ee):ee=e[46];let he;e[47]!==j?(he=s.jsx(be,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:j,children:ee}),e[47]=j,e[48]=he):he=e[48];let ke;e[49]!==ne||e[50]!==he?(ke=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[ne,he]}),e[49]=ne,e[50]=he,e[51]=ke):ke=e[51];let oe;e[52]!==W||e[53]!==ke?(oe=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[W,q,ke]}),e[52]=W,e[53]=ke,e[54]=oe):oe=e[54];let ge;e[55]!==Q||e[56]!==Z||e[57]!==N||e[58]!==n||e[59]!==f||e[60]!==U||e[61]!==h||e[62]!==x||e[63]!==v.length||e[64]!==r||e[65]!==z?(ge=s.jsx(Ns,{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:[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:r("settings.skills.sidebar.section.project")}),Q.sortedGroups.map(Ve=>{const{name:qe,skills:lt}=Ve;return s.jsx(hd,{label:qe,count:lt.length,storageKey:"project-skills",children:lt.map(He=>s.jsx(Ro,{skill:He,isSelected:h===He.name,onSelect:()=>{x(He.name),n?.()},onRename:()=>T(He),onDelete:()=>I(He),onDuplicate:()=>N(He),isMenuOpen:f===He.name,onMenuOpenChange:ze=>b(ze?He.name:null)},He.name))},qe)}),Q.ungrouped.map(Ve=>s.jsx(Ro,{skill:Ve,isSelected:h===Ve.name,onSelect:()=>{x(Ve.name),n?.()},onRename:()=>T(Ve),onDelete:()=>I(Ve),onDuplicate:()=>N(Ve),isMenuOpen:f===Ve.name,onMenuOpenChange:qe=>b(qe?Ve.name:null)},Ve.name))]}),z.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:r("settings.skills.sidebar.section.user")}),Z.sortedGroups.map(Ve=>{const{name:qe,skills:lt}=Ve;return s.jsx(hd,{label:qe,count:lt.length,storageKey:"user-skills",children:lt.map(He=>s.jsx(Ro,{skill:He,isSelected:h===He.name,onSelect:()=>{x(He.name),n?.()},onRename:()=>T(He),onDelete:()=>I(He),onDuplicate:()=>N(He),isMenuOpen:f===He.name,onMenuOpenChange:ze=>b(ze?He.name:null)},He.name))},qe)}),Z.ungrouped.map(Ve=>s.jsx(Ro,{skill:Ve,isSelected:h===Ve.name,onSelect:()=>{x(Ve.name),n?.()},onRename:()=>T(Ve),onDelete:()=>I(Ve),onDuplicate:()=>N(Ve),isMenuOpen:f===Ve.name,onMenuOpenChange:qe=>b(qe?Ve.name:null)},Ve.name))]})]})}),e[55]=Q,e[56]=Z,e[57]=N,e[58]=n,e[59]=f,e[60]=U,e[61]=h,e[62]=x,e[63]=v.length,e[64]=r,e[65]=z,e[66]=ge):ge=e[66];const me=d!==null;let ye;e[67]!==m?(ye=Ve=>{!Ve&&!m&&p(null)},e[67]=m,e[68]=ye):ye=e[68];let ie;e[69]!==r?(ie=r("settings.skills.sidebar.deleteDialog.title"),e[69]=r,e[70]=ie):ie=e[70];let ve;e[71]!==ie?(ve=s.jsx(hs,{children:ie}),e[71]=ie,e[72]=ve):ve=e[72];const X=d?.name??"";let Se;e[73]!==r||e[74]!==X?(Se=r("settings.skills.sidebar.deleteDialog.description",{name:X}),e[73]=r,e[74]=X,e[75]=Se):Se=e[75];let Ae;e[76]!==Se?(Ae=s.jsx(Ss,{children:Se}),e[76]=Se,e[77]=Ae):Ae=e[77];let pe;e[78]!==ve||e[79]!==Ae?(pe=s.jsxs(ys,{children:[ve,Ae]}),e[78]=ve,e[79]=Ae,e[80]=pe):pe=e[80];let we;e[81]===Symbol.for("react.memo_cache_sentinel")?(we=()=>p(null),e[81]=we):we=e[81];let Ie;e[82]!==r?(Ie=r("settings.common.actions.cancel"),e[82]=r,e[83]=Ie):Ie=e[83];let Y;e[84]!==m||e[85]!==Ie?(Y=s.jsx(be,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:we,disabled:m,children:Ie}),e[84]=m,e[85]=Ie,e[86]=Y):Y=e[86];let re;e[87]!==r?(re=r("settings.common.actions.delete"),e[87]=r,e[88]=re):re=e[88];let Pe;e[89]!==P||e[90]!==m||e[91]!==re?(Pe=s.jsx(be,{size:"sm",onClick:P,disabled:m,children:re}),e[89]=P,e[90]=m,e[91]=re,e[92]=Pe):Pe=e[92];let ce;e[93]!==Y||e[94]!==Pe?(ce=s.jsxs(Vs,{children:[Y,Pe]}),e[93]=Y,e[94]=Pe,e[95]=ce):ce=e[95];let Ce;e[96]!==pe||e[97]!==ce?(Ce=s.jsxs(ms,{className:"max-w-md",children:[pe,ce]}),e[96]=pe,e[97]=ce,e[98]=Ce):Ce=e[98];let Te;e[99]!==me||e[100]!==ye||e[101]!==Ce?(Te=s.jsx(ps,{open:me,onOpenChange:ye,children:Ce}),e[99]=me,e[100]=ye,e[101]=Ce,e[102]=Te):Te=e[102];const $e=a!==null;let De;e[103]===Symbol.for("react.memo_cache_sentinel")?(De=Ve=>!Ve&&i(null),e[103]=De):De=e[103];let de;e[104]!==r?(de=r("settings.skills.sidebar.renameDialog.title"),e[104]=r,e[105]=de):de=e[105];let O;e[106]!==de?(O=s.jsx(hs,{children:de}),e[106]=de,e[107]=O):O=e[107];const L=a?.name??"";let $;e[108]!==r||e[109]!==L?($=r("settings.skills.sidebar.renameDialog.description",{name:L}),e[108]=r,e[109]=L,e[110]=$):$=e[110];let je;e[111]!==$?(je=s.jsx(Ss,{children:$}),e[111]=$,e[112]=je):je=e[112];let ae;e[113]!==O||e[114]!==je?(ae=s.jsxs(ys,{children:[O,je]}),e[113]=O,e[114]=je,e[115]=ae):ae=e[115];let _e;e[116]===Symbol.for("react.memo_cache_sentinel")?(_e=Ve=>c(Ve.target.value),e[116]=_e):_e=e[116];let le;e[117]!==r?(le=r("settings.skills.sidebar.renameDialog.placeholder"),e[117]=r,e[118]=le):le=e[118];let Me;e[119]!==V?(Me=Ve=>{Ve.key==="Enter"&&V()},e[119]=V,e[120]=Me):Me=e[120];let Ge;e[121]!==o||e[122]!==le||e[123]!==Me?(Ge=s.jsx(Bt,{value:o,onChange:_e,placeholder:le,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:Me}),e[121]=o,e[122]=le,e[123]=Me,e[124]=Ge):Ge=e[124];let at;e[125]===Symbol.for("react.memo_cache_sentinel")?(at=()=>i(null),e[125]=at):at=e[125];let Ye;e[126]!==r?(Ye=r("settings.common.actions.cancel"),e[126]=r,e[127]=Ye):Ye=e[127];let Xe;e[128]!==Ye?(Xe=s.jsx(be,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:at,children:Ye}),e[128]=Ye,e[129]=Xe):Xe=e[129];let ut;e[130]!==r?(ut=r("settings.common.actions.rename"),e[130]=r,e[131]=ut):ut=e[131];let rt;e[132]!==V||e[133]!==ut?(rt=s.jsx(be,{size:"sm",onClick:V,children:ut}),e[132]=V,e[133]=ut,e[134]=rt):rt=e[134];let it;e[135]!==Xe||e[136]!==rt?(it=s.jsxs(Vs,{children:[Xe,rt]}),e[135]=Xe,e[136]=rt,e[137]=it):it=e[137];let nt;e[138]!==ae||e[139]!==Ge||e[140]!==it?(nt=s.jsxs(ms,{children:[ae,Ge,it]}),e[138]=ae,e[139]=Ge,e[140]=it,e[141]=nt):nt=e[141];let Ne;e[142]!==$e||e[143]!==nt?(Ne=s.jsx(ps,{open:$e,onOpenChange:De,children:nt}),e[142]=$e,e[143]=nt,e[144]=Ne):Ne=e[144];let Ke;return e[145]!==oe||e[146]!==ge||e[147]!==Te||e[148]!==Ne?(Ke=s.jsxs("div",{className:fe,children:[oe,ge,Te,Ne]}),e[145]=oe,e[146]=ge,e[147]=Te,e[148]=Ne,e[149]=Ke):Ke=e[149],Ke},Ro=t=>{const e=st.c(61),{skill:n,isSelected:r,onSelect:a,onDelete:i,onRename:o,onDuplicate:c,isMenuOpen:d,onMenuOpenChange:p}=t,{t:m}=dt();let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u=Zi(),e[0]=u):u=e[0];const f=u;let b;e[1]!==n.source||e[2]!==m?(b=n.source==="claude"?m("settings.skills.sidebar.badge.claude"):n.source==="agents"?m("settings.skills.sidebar.badge.agents"):m("settings.skills.sidebar.badge.opencode"),e[1]=n.source,e[2]=m,e[3]=b):b=e[3];const h=b,v=r?"bg-interactive-selection":"hover:bg-interactive-hover";let x;e[4]!==v?(x=xe("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",v),e[4]=v,e[5]=x):x=e[5];let g;e[6]!==p?(g=f?void 0:Q=>{Q.preventDefault(),p(!0)},e[6]=p,e[7]=g):g=e[7];let w;e[8]!==n.name?(w=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n.name}),e[8]=n.name,e[9]=w):w=e[9];let y;e[10]!==n.scope?(y=s.jsx("span",{className:"typography-micro text-muted-foreground bg-[var(--surface-muted)] px-1 rounded flex-shrink-0 leading-none pb-px border border-[var(--interactive-border)]/50",children:n.scope}),e[10]=n.scope,e[11]=y):y=e[11];let C;e[12]!==h?(C=s.jsx("span",{className:"typography-micro text-muted-foreground bg-[var(--surface-muted)] px-1 rounded flex-shrink-0 leading-none pb-px border border-[var(--interactive-border)]/50",children:h}),e[12]=h,e[13]=C):C=e[13];let k;e[14]!==w||e[15]!==y||e[16]!==C?(k=s.jsxs("div",{className:"flex items-center gap-1.5",children:[w,y,C]}),e[14]=w,e[15]=y,e[16]=C,e[17]=k):k=e[17];let j;e[18]!==a||e[19]!==k?(j=s.jsx("button",{onClick:a,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:k}),e[18]=a,e[19]=k,e[20]=j):j=e[20];let S;e[21]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsx(As,{asChild:!0,children:s.jsx(be,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(D,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[21]=S):S=e[21];let I;e[22]!==o?(I=Q=>{Q.stopPropagation(),o()},e[22]=o,e[23]=I):I=e[23];let M;e[24]===Symbol.for("react.memo_cache_sentinel")?(M=s.jsx(D,{name:"edit",className:"h-4 w-4 mr-px"}),e[24]=M):M=e[24];let P;e[25]!==m?(P=m("settings.common.actions.rename"),e[25]=m,e[26]=P):P=e[26];let A;e[27]!==I||e[28]!==P?(A=s.jsxs($t,{onClick:I,children:[M,P]}),e[27]=I,e[28]=P,e[29]=A):A=e[29];let N;e[30]!==c?(N=Q=>{Q.stopPropagation(),c()},e[30]=c,e[31]=N):N=e[31];let E;e[32]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx(D,{name:"file-copy",className:"h-4 w-4 mr-px"}),e[32]=E):E=e[32];let T;e[33]!==m?(T=m("settings.common.actions.duplicate"),e[33]=m,e[34]=T):T=e[34];let R;e[35]!==N||e[36]!==T?(R=s.jsxs($t,{onClick:N,children:[E,T]}),e[35]=N,e[36]=T,e[37]=R):R=e[37];let V;e[38]!==i?(V=Q=>{Q.stopPropagation(),i()},e[38]=i,e[39]=V):V=e[39];let _;e[40]===Symbol.for("react.memo_cache_sentinel")?(_=s.jsx(D,{name:"delete-bin",className:"h-4 w-4 mr-px"}),e[40]=_):_=e[40];let U;e[41]!==m?(U=m("settings.common.actions.delete"),e[41]=m,e[42]=U):U=e[42];let B;e[43]!==V||e[44]!==U?(B=s.jsxs($t,{onClick:V,className:"text-destructive focus:text-destructive",children:[_,U]}),e[43]=V,e[44]=U,e[45]=B):B=e[45];let z;e[46]!==A||e[47]!==R||e[48]!==B?(z=s.jsxs(Ds,{align:"end",className:"w-fit min-w-20",children:[A,R,B]}),e[46]=A,e[47]=R,e[48]=B,e[49]=z):z=e[49];let K;e[50]!==d||e[51]!==p||e[52]!==z?(K=s.jsxs(Ts,{open:d,onOpenChange:p,children:[S,z]}),e[50]=d,e[51]=p,e[52]=z,e[53]=K):K=e[53];let F;e[54]!==j||e[55]!==K?(F=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[j,K]}),e[54]=j,e[55]=K,e[56]=F):F=e[56];let G;return e[57]!==F||e[58]!==x||e[59]!==g?(G=s.jsx("div",{className:x,onContextMenu:g,children:F}),e[57]=F,e[58]=x,e[59]=g,e[60]=G):G=e[60],G};function Uk(t){return{selectedSkillName:t.selectedSkillName,skills:t.skills,setSelectedSkill:t.setSelectedSkill,setSkillDraft:t.setSkillDraft,createSkill:t.createSkill,deleteSkill:t.deleteSkill,getSkillDetail:t.getSkillDetail}}function Wk(t){return t.scope==="project"}function Kk(t){return t.scope==="user"}function Hk(t,e){return t.localeCompare(e)}function Gk(t,e){return t.name.localeCompare(e.name)}function qk(t,e){return t.name.localeCompare(e.name)}const Jk=()=>`custom:${Date.now()}-${Math.random().toString(16).slice(2)}`,Yk=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},Qk=async()=>{try{const t=Xn()?.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}},Xk=t=>{const e=st.c(158),{open:n,onOpenChange:r}=t,{t:a}=dt(),i=Aa(Zk),o=Aa(e3),c=Aa(t3),d=Wn(s3),p=Wn(n3),[m,u]=l.useState(""),[f,b]=l.useState(""),[h,v]=l.useState("");let x;e[0]===Symbol.for("react.memo_cache_sentinel")?(x=[],e[0]=x):x=e[0];const[g,w]=l.useState(x),[y,C]=l.useState(null),[k,j]=l.useState(!1);let S;e[1]===Symbol.for("react.memo_cache_sentinel")?(S=[],e[1]=S):S=e[1];const[I,M]=l.useState(S),[P,A]=l.useState(null),N=l.useRef(0);let E;e[2]===Symbol.for("react.memo_cache_sentinel")?(E=Ne=>{N.current=N.current+1,j(!1),C(null),Ne?.clearIdentity&&(M([]),A(null))},e[2]=E):E=e[2];const T=E;let R,V;e[3]!==p||e[4]!==n?(R=()=>{n&&(N.current=N.current+1,u(""),b(""),v(""),C(null),j(!1),M([]),A(null),p(),(async()=>{const Ne=await Qk(),Ke=Array.isArray(Ne?.skillCatalogs)?Ne?.skillCatalogs:[];w(Ke||[])})())},V=[n,p],e[3]=p,e[4]=n,e[5]=R,e[6]=V):(R=e[5],V=e[6]),l.useEffect(R,V);let _;e[7]!==f?(_=f.trim(),e[7]=f,e[8]=_):_=e[8];const U=_;let B;e[9]!==h?(B=h.trim(),e[9]=h,e[10]=B):B=e[10];const z=B;let K;if(e[11]!==g||e[12]!==U||e[13]!==z){let Ne;e[15]!==U||e[16]!==z?(Ne=Ke=>{const Ve=(Ke.source||"").trim(),qe=(Ke.subpath||"").trim();return Ve===U&&qe===z},e[15]=U,e[16]=z,e[17]=Ne):Ne=e[17],K=g.some(Ne),e[11]=g,e[12]=U,e[13]=z,e[14]=K}else K=e[14];const F=K;let G;e[18]!==d||e[19]!==P||e[20]!==m||e[21]!==i||e[22]!==f||e[23]!==h||e[24]!==a?(G=async()=>{const Ne=f.trim();if(!Ne){H.error(a("settings.skills.catalog.add.toast.repositoryRequired"));return}m.trim()||u(Yk(Ne)),j(!1),C(null);const Ke=N.current+1;N.current=Ke;const Ve=await i({source:Ne,subpath:h.trim()||void 0,gitIdentityId:P||void 0});if(N.current!==Ke)return;if(!Ve.ok){if(Ve.error?.kind==="authRequired"){if(on()){H.error(a("settings.skills.catalog.shared.toast.privateRepoNotSupportedVsCode"));return}const lt=Ve.error.identities||[];if(M(lt),!P&&lt.length>0){const He=d&&d!=="global"&&lt.some(ze=>ze.id===d)?d:lt[0].id;A(He)}H.error(a("settings.skills.catalog.add.toast.authenticationRequiredScan"));return}H.error(Ve.error?.message||a("settings.skills.catalog.add.toast.scanFailed"));return}const qe=Ve.items?.length||0;if(C(qe),qe===0){H.error(a("settings.skills.catalog.add.toast.noSkillsFound")),j(!1);return}M([]),j(!0),H.success(a("settings.skills.catalog.shared.toast.foundSkills",{count:qe}))},e[18]=d,e[19]=P,e[20]=m,e[21]=i,e[22]=f,e[23]=h,e[24]=a,e[25]=G):G=e[25];const Q=G;let te;e[26]!==g||e[27]!==P||e[28]!==F||e[29]!==m||e[30]!==o||e[31]!==r||e[32]!==k||e[33]!==f||e[34]!==h||e[35]!==a?(te=async()=>{const Ne=m.trim(),Ke=f.trim(),Ve=h.trim();if(!Ne){H.error(a("settings.skills.catalog.add.toast.catalogNameRequired"));return}if(!Ke){H.error(a("settings.skills.catalog.add.toast.repositoryRequired"));return}if(!k){H.error(a("settings.skills.catalog.add.toast.scanBeforeAdd"));return}if(F){H.error(a("settings.skills.catalog.add.toast.catalogAlreadyExists"));return}const qe={id:Jk(),label:Ne,source:Ke,...Ve?{subpath:Ve}:{},...P?{gitIdentityId:P}:{}},lt=[...g,qe];try{await Is({skillCatalogs:lt}),w(lt),H.success(a("settings.skills.catalog.add.toast.catalogAdded")),await o({refresh:!0}),r(!1)}catch(He){const ze=He;H.error(ze instanceof Error?ze.message:a("settings.skills.catalog.add.toast.saveFailed"))}},e[26]=g,e[27]=P,e[28]=F,e[29]=m,e[30]=o,e[31]=r,e[32]=k,e[33]=f,e[34]=h,e[35]=a,e[36]=te):te=e[36];const Z=te;let fe;e[37]!==a?(fe=a("settings.skills.catalog.add.title"),e[37]=a,e[38]=fe):fe=e[38];let ue;e[39]!==fe?(ue=s.jsx(hs,{children:fe}),e[39]=fe,e[40]=ue):ue=e[40];let W;e[41]!==a?(W=a("settings.skills.catalog.add.descriptionPrefix"),e[41]=a,e[42]=W):W=e[42];let q;e[43]===Symbol.for("react.memo_cache_sentinel")?(q=s.jsx("code",{className:"font-mono",children:"SKILL.md"}),e[43]=q):q=e[43];let J;e[44]!==a?(J=a("settings.skills.catalog.add.descriptionSuffix"),e[44]=a,e[45]=J):J=e[45];let ne;e[46]!==W||e[47]!==J?(ne=s.jsxs(Ss,{children:[W," ",q,J]}),e[46]=W,e[47]=J,e[48]=ne):ne=e[48];let ee;e[49]!==ue||e[50]!==ne?(ee=s.jsxs(ys,{children:[ue,ne]}),e[49]=ue,e[50]=ne,e[51]=ee):ee=e[51];let he;e[52]!==a?(he=a("settings.skills.catalog.add.field.catalogName"),e[52]=a,e[53]=he):he=e[53];let ke;e[54]!==he?(ke=s.jsx("label",{className:"typography-ui-label text-foreground",children:he}),e[54]=he,e[55]=ke):ke=e[55];let oe;e[56]===Symbol.for("react.memo_cache_sentinel")?(oe=Ne=>u(Ne.target.value),e[56]=oe):oe=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 me;e[59]!==m||e[60]!==ge?(me=s.jsx(Bt,{value:m,onChange:oe,placeholder:ge}),e[59]=m,e[60]=ge,e[61]=me):me=e[61];let ye;e[62]!==ke||e[63]!==me?(ye=s.jsxs("div",{className:"space-y-2",children:[ke,me]}),e[62]=ke,e[63]=me,e[64]=ye):ye=e[64];let ie;e[65]!==a?(ie=a("settings.skills.catalog.add.field.repository"),e[65]=a,e[66]=ie):ie=e[66];let ve;e[67]!==ie?(ve=s.jsx("label",{className:"typography-ui-label text-foreground",children:ie}),e[67]=ie,e[68]=ve):ve=e[68];let X;e[69]===Symbol.for("react.memo_cache_sentinel")?(X=Ne=>{b(Ne.target.value),T({clearIdentity:!0})},e[69]=X):X=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 Ae;e[72]!==f||e[73]!==Se?(Ae=s.jsx(Bt,{value:f,onChange:X,placeholder:Se}),e[72]=f,e[73]=Se,e[74]=Ae):Ae=e[74];let pe;e[75]!==a?(pe=a("settings.skills.catalog.add.field.repositoryHint"),e[75]=a,e[76]=pe):pe=e[76];let we;e[77]!==pe?(we=s.jsx("p",{className:"typography-micro text-muted-foreground",children:pe}),e[77]=pe,e[78]=we):we=e[78];let Ie;e[79]!==ve||e[80]!==Ae||e[81]!==we?(Ie=s.jsxs("div",{className:"space-y-2",children:[ve,Ae,we]}),e[79]=ve,e[80]=Ae,e[81]=we,e[82]=Ie):Ie=e[82];let Y;e[83]!==a?(Y=a("settings.skills.catalog.add.field.optionalSubpath"),e[83]=a,e[84]=Y):Y=e[84];let re;e[85]!==Y?(re=s.jsx("label",{className:"typography-ui-label text-foreground",children:Y}),e[85]=Y,e[86]=re):re=e[86];let Pe;e[87]===Symbol.for("react.memo_cache_sentinel")?(Pe=Ne=>{v(Ne.target.value),T({clearIdentity:!0})},e[87]=Pe):Pe=e[87];let ce;e[88]!==a?(ce=a("settings.skills.catalog.shared.field.subpathPlaceholder"),e[88]=a,e[89]=ce):ce=e[89];let Ce;e[90]!==h||e[91]!==ce?(Ce=s.jsx(Bt,{value:h,onChange:Pe,placeholder:ce}),e[90]=h,e[91]=ce,e[92]=Ce):Ce=e[92];let Te;e[93]!==re||e[94]!==Ce?(Te=s.jsxs("div",{className:"space-y-2",children:[re,Ce]}),e[93]=re,e[94]=Ce,e[95]=Te):Te=e[95];let $e;e[96]!==P||e[97]!==I||e[98]!==a?($e=I.length>0&&!on()?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(os,{value:P||"",onValueChange:Ne=>{A(Ne),T()},children:[s.jsx(ls,{className:"w-fit",children:s.jsx("span",{children:I.find(Ne=>Ne.id===P)?.name||a("settings.skills.catalog.shared.auth.chooseIdentity")})}),s.jsx(cs,{align:"start",children:I.map(r3)})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:a("settings.skills.catalog.shared.auth.footerHint")})]}):null,e[96]=P,e[97]=I,e[98]=a,e[99]=$e):$e=e[99];let De;e[100]!==y||e[101]!==a?(De=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]=De):De=e[102];let de;e[103]!==F||e[104]!==a?(de=F?s.jsx("div",{className:"typography-meta text-muted-foreground",children:a("settings.skills.catalog.add.duplicateMessage")}):null,e[103]=F,e[104]=a,e[105]=de):de=e[105];let O;e[106]!==ye||e[107]!==Ie||e[108]!==Te||e[109]!==$e||e[110]!==De||e[111]!==de?(O=s.jsxs("div",{className:"space-y-4",children:[ye,Ie,Te,$e,De,de]}),e[106]=ye,e[107]=Ie,e[108]=Te,e[109]=$e,e[110]=De,e[111]=de,e[112]=O):O=e[112];let L;e[113]!==r?(L=()=>r(!1),e[113]=r,e[114]=L):L=e[114];let $;e[115]!==a?($=a("settings.common.actions.cancel"),e[115]=a,e[116]=$):$=e[116];let je;e[117]!==L||e[118]!==$?(je=s.jsx(be,{size:"sm",variant:"ghost",onClick:L,children:$}),e[117]=L,e[118]=$,e[119]=je):je=e[119];let ae;e[120]!==Q?(ae=()=>{Q()},e[120]=Q,e[121]=ae):ae=e[121];let _e;e[122]!==c||e[123]!==f?(_e=c||!f.trim(),e[122]=c,e[123]=f,e[124]=_e):_e=e[124];let le;e[125]===Symbol.for("react.memo_cache_sentinel")?(le=s.jsx(D,{name:"git-repository",className:"h-4 w-4"}),e[125]=le):le=e[125];let Me;e[126]!==c||e[127]!==a?(Me=a(c?"settings.skills.catalog.shared.actions.scanning":"settings.skills.catalog.shared.actions.scan"),e[126]=c,e[127]=a,e[128]=Me):Me=e[128];let Ge;e[129]!==ae||e[130]!==_e||e[131]!==Me?(Ge=s.jsxs(be,{size:"sm",className:"gap-2",variant:"ghost",onClick:ae,disabled:_e,children:[le,Me]}),e[129]=ae,e[130]=_e,e[131]=Me,e[132]=Ge):Ge=e[132];let at;e[133]!==Z?(at=()=>{Z()},e[133]=Z,e[134]=at):at=e[134];let Ye;e[135]!==F||e[136]!==m||e[137]!==k||e[138]!==f?(Ye=!k||F||!m.trim()||!f.trim(),e[135]=F,e[136]=m,e[137]=k,e[138]=f,e[139]=Ye):Ye=e[139];let Xe;e[140]!==a?(Xe=a("settings.skills.catalog.add.actions.addCatalog"),e[140]=a,e[141]=Xe):Xe=e[141];let ut;e[142]!==at||e[143]!==Ye||e[144]!==Xe?(ut=s.jsx(be,{size:"sm",onClick:at,disabled:Ye,children:Xe}),e[142]=at,e[143]=Ye,e[144]=Xe,e[145]=ut):ut=e[145];let rt;e[146]!==je||e[147]!==Ge||e[148]!==ut?(rt=s.jsxs(Vs,{children:[je,Ge,ut]}),e[146]=je,e[147]=Ge,e[148]=ut,e[149]=rt):rt=e[149];let it;e[150]!==ee||e[151]!==O||e[152]!==rt?(it=s.jsxs(ms,{className:"max-w-xl",children:[ee,O,rt]}),e[150]=ee,e[151]=O,e[152]=rt,e[153]=it):it=e[153];let nt;return e[154]!==r||e[155]!==n||e[156]!==it?(nt=s.jsx(ps,{open:n,onOpenChange:r,children:it}),e[154]=r,e[155]=n,e[156]=it,e[157]=nt):nt=e[157],nt};function Zk(t){return t.scanRepo}function e3(t){return t.loadCatalog}function t3(t){return t.isScanning}function s3(t){return t.defaultGitIdentityId}function n3(t){return t.loadDefaultGitIdentityId}function r3(t){return s.jsx(Tt,{value:t.id,children:t.name},t.id)}const a3=t=>{const e=st.c(85),{open:n,onOpenChange:r,conflicts:a,onConfirm:i}=t,{t:o}=dt();let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c={},e[0]=c):c=e[0];const[d,p]=l.useState(c);let m,u;e[1]!==a||e[2]!==n?(m=()=>{if(!n)return;const ue={};for(const W of a)ue[W.skillName]="skip";p(ue)},u=[n,a],e[1]=a,e[2]=n,e[3]=m,e[4]=u):(m=e[3],u=e[4]),l.useEffect(m,u);let f;e[5]!==a?(f=ue=>{const W={};for(const q of a)W[q.skillName]=ue;p(W)},e[5]=a,e[6]=f):f=e[6];const b=f;let h;e[7]!==a||e[8]!==d?(h=a.length>0&&a.every(ue=>d[ue.skillName]),e[7]=a,e[8]=d,e[9]=h):h=e[9];const v=h;let x;e[10]!==o?(x=o("settings.skills.catalog.conflicts.title"),e[10]=o,e[11]=x):x=e[11];let g;e[12]!==x?(g=s.jsx(hs,{children:x}),e[12]=x,e[13]=g):g=e[13];let w;e[14]!==o?(w=o("settings.skills.catalog.conflicts.description"),e[14]=o,e[15]=w):w=e[15];let y;e[16]!==w?(y=s.jsx(Ss,{children:w}),e[16]=w,e[17]=y):y=e[17];let C;e[18]!==g||e[19]!==y?(C=s.jsxs(ys,{children:[g,y]}),e[18]=g,e[19]=y,e[20]=C):C=e[20];let k;e[21]!==a.length||e[22]!==o?(k=o("settings.skills.catalog.conflicts.count",{count:a.length}),e[21]=a.length,e[22]=o,e[23]=k):k=e[23];let j;e[24]!==k?(j=s.jsx("span",{className:"typography-meta text-muted-foreground",children:k}),e[24]=k,e[25]=j):j=e[25];let S;e[26]!==b?(S=()=>b("skip"),e[26]=b,e[27]=S):S=e[27];let I;e[28]!==o?(I=o("settings.skills.catalog.conflicts.actions.skipAll"),e[28]=o,e[29]=I):I=e[29];let M;e[30]!==S||e[31]!==I?(M=s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:S,children:I}),e[30]=S,e[31]=I,e[32]=M):M=e[32];let P;e[33]!==b?(P=()=>b("overwrite"),e[33]=b,e[34]=P):P=e[34];let A;e[35]!==o?(A=o("settings.skills.catalog.conflicts.actions.overwriteAll"),e[35]=o,e[36]=A):A=e[36];let N;e[37]!==P||e[38]!==A?(N=s.jsx(be,{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]!==M||e[41]!==N?(E=s.jsxs("div",{className:"flex items-center gap-2",children:[M,N]}),e[40]=M,e[41]=N,e[42]=E):E=e[42];let T;e[43]!==j||e[44]!==E?(T=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[j,E]}),e[43]=j,e[44]=E,e[45]=T):T=e[45];let R;if(e[46]!==a||e[47]!==d||e[48]!==o){let ue;e[50]!==d||e[51]!==o?(ue=W=>s.jsxs("div",{className:"flex items-center justify-between gap-3 py-1.5",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label truncate",children:W.skillName}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:o("settings.skills.catalog.conflicts.installedIn",{scope:W.scope==="project"?o("settings.skills.catalog.conflicts.scope.project"):o("settings.skills.catalog.conflicts.scope.user"),source:W.source==="agents"?o("settings.skills.catalog.conflicts.source.agents"):o("settings.skills.catalog.conflicts.source.opencode")})})]}),s.jsxs(os,{value:d[W.skillName]||"skip",onValueChange:q=>p(J=>({...J,[W.skillName]:q})),children:[s.jsx(ls,{className:"w-fit",children:s.jsx("span",{className:"capitalize",children:(d[W.skillName]||"skip")==="overwrite"?o("settings.skills.catalog.conflicts.decision.overwrite"):o("settings.skills.catalog.conflicts.decision.skip")})}),s.jsxs(cs,{align:"end",children:[s.jsx(Tt,{value:"skip",className:"pr-2 [&>span:first-child]:hidden",children:o("settings.skills.catalog.conflicts.decision.skip")}),s.jsx(Tt,{value:"overwrite",className:"pr-2 [&>span:first-child]:hidden",children:o("settings.skills.catalog.conflicts.decision.overwrite")})]})]})]},W.skillName),e[50]=d,e[51]=o,e[52]=ue):ue=e[52],R=a.map(ue),e[46]=a,e[47]=d,e[48]=o,e[49]=R}else R=e[49];let V;e[53]!==R?(V=s.jsx("div",{className:"space-y-2",children:R}),e[53]=R,e[54]=V):V=e[54];let _;e[55]!==T||e[56]!==V?(_=s.jsxs("div",{className:"space-y-3",children:[T,V]}),e[55]=T,e[56]=V,e[57]=_):_=e[57];let U;e[58]!==r?(U=()=>r(!1),e[58]=r,e[59]=U):U=e[59];let B;e[60]!==o?(B=o("settings.common.actions.cancel"),e[60]=o,e[61]=B):B=e[61];let z;e[62]!==U||e[63]!==B?(z=s.jsx(be,{size:"sm",variant:"ghost",onClick:U,children:B}),e[62]=U,e[63]=B,e[64]=z):z=e[64];let K;e[65]!==d||e[66]!==i?(K=()=>i(d),e[65]=d,e[66]=i,e[67]=K):K=e[67];const F=!v;let G;e[68]!==o?(G=o("settings.skills.catalog.conflicts.actions.continue"),e[68]=o,e[69]=G):G=e[69];let Q;e[70]!==K||e[71]!==F||e[72]!==G?(Q=s.jsx(be,{size:"sm",onClick:K,disabled:F,children:G}),e[70]=K,e[71]=F,e[72]=G,e[73]=Q):Q=e[73];let te;e[74]!==z||e[75]!==Q?(te=s.jsxs(Vs,{children:[z,Q]}),e[74]=z,e[75]=Q,e[76]=te):te=e[76];let Z;e[77]!==C||e[78]!==_||e[79]!==te?(Z=s.jsxs(ms,{className:"max-w-2xl",children:[C,_,te]}),e[77]=C,e[78]=_,e[79]=te,e[80]=Z):Z=e[80];let fe;return e[81]!==r||e[82]!==n||e[83]!==Z?(fe=s.jsx(ps,{open:n,onOpenChange:r,children:Z}),e[81]=r,e[82]=n,e[83]=Z,e[84]=fe):fe=e[84],fe},Zd=[{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 Gi(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=Zd.find(n=>n.value===t);return e?{scope:e.scope,source:e.source}:{scope:"user",source:"opencode"}}const i3=t=>{const e=st.c(124),{open:n,onOpenChange:r,item:a}=t,{t:i}=dt(),o=Aa(o3),c=Aa(l3),[d,p]=l.useState("user"),[m,u]=l.useState("opencode"),f=Ps(c3),b=Ps(d3),[h,v]=l.useState(null),[x,g]=l.useState(!1);let w;e[0]===Symbol.for("react.memo_cache_sentinel")?(w=[],e[0]=w):w=e[0];const[y,C]=l.useState(w),[k,j]=l.useState(null);let S,I;e[1]!==b||e[2]!==n?(S=()=>{n&&(p("user"),u("opencode"),v(b),g(!1),C([]),j(null))},I=[n,b],e[1]=b,e[2]=n,e[3]=S,e[4]=I):(S=e[3],I=e[4]),l.useEffect(S,I);let M;e[5]!==i?(M=De=>{switch(De){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]=M):M=e[6];const P=M;let A;e[7]!==i?(A=De=>{switch(De){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(h&&f.some(De=>De.id===h)){E=h;break e}if(b&&f.some(De=>De.id===b)){E=b;break e}E=f[0]?.id??null}const T=E;let R;e:{if(d!=="project"){R=null;break e}const De=T;if(!De){R=null;break e}let de;if(e[9]!==De||e[10]!==f){let L;e[12]!==De?(L=$=>$.id===De,e[12]=De,e[13]=L):L=e[13],de=f.find(L),e[9]=De,e[10]=f,e[11]=de}else de=e[11];R=de?.path??null}const V=R;let _;e[14]!==o||e[15]!==a||e[16]!==r||e[17]!==i?(_=async De=>{const de={skillDir:De.skillDir};a?.clawdhub&&(de.clawdhub={slug:a.clawdhub.slug,version:a.clawdhub.version});const O=await o({source:De.source,subpath:De.subpath,gitIdentityId:a?.gitIdentityId,scope:De.scope,targetSource:De.targetSource,selections:[de],conflictPolicy:"prompt",conflictDecisions:De.conflictDecisions},{directory:De.directoryOverride??null});if(O.ok){H.success(i("settings.skills.catalog.installSkill.toast.installed")),r(!1);return}if(O.error?.kind==="conflicts"){j({source:De.source,subpath:De.subpath,scope:De.scope,targetSource:De.targetSource,skillDir:De.skillDir,directoryOverride:De.directoryOverride??null}),C(O.error.conflicts),g(!0);return}if(O.error?.kind==="authRequired"){H.error(O.error.message||i("settings.skills.catalog.installSkill.toast.authRequired"));return}H.error(O.error?.message||i("settings.skills.catalog.installSkill.toast.installFailed"))},e[14]=o,e[15]=a,e[16]=r,e[17]=i,e[18]=_):_=e[18];const U=_;if(!a)return null;let B;e[19]!==i?(B=i("settings.skills.catalog.installSkill.title"),e[19]=i,e[20]=B):B=e[20];let z;e[21]!==B?(z=s.jsx(hs,{children:B}),e[21]=B,e[22]=z):z=e[22];let K;e[23]!==i?(K=i("settings.skills.catalog.installSkill.descriptionPrefix"),e[23]=i,e[24]=K):K=e[24];let F;e[25]!==a.skillName?(F=s.jsx("span",{className:"font-semibold text-foreground",children:a.skillName}),e[25]=a.skillName,e[26]=F):F=e[26];let G;e[27]!==i?(G=i("settings.skills.catalog.installSkill.descriptionSuffix"),e[27]=i,e[28]=G):G=e[28];let Q;e[29]!==K||e[30]!==F||e[31]!==G?(Q=s.jsxs(Ss,{children:[K," ",F," ",G]}),e[29]=K,e[30]=F,e[31]=G,e[32]=Q):Q=e[32];let te;e[33]!==z||e[34]!==Q?(te=s.jsxs(ys,{children:[z,Q]}),e[33]=z,e[34]=Q,e[35]=te):te=e[35];let Z;e[36]!==i?(Z=i("settings.skills.catalog.installSkill.field.destination"),e[36]=i,e[37]=Z):Z=e[37];let fe;e[38]!==Z?(fe=s.jsx("span",{className:"typography-ui-label text-foreground",children:Z}),e[38]=Z,e[39]=fe):fe=e[39];let ue;e[40]!==d||e[41]!==m?(ue=Gi(d,m),e[40]=d,e[41]=m,e[42]=ue):ue=e[42];let W;e[43]===Symbol.for("react.memo_cache_sentinel")?(W=De=>{const de=fg(De);p(de.scope),u(de.source==="agents"?"agents":"opencode")},e[43]=W):W=e[43];let q;e[44]!==d?(q=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]=q):q=e[45];let J;e[46]!==m?(J=m==="agents"?s.jsx(D,{name:"robot-2",className:"h-3.5 w-3.5"}):null,e[46]=m,e[47]=J):J=e[47];let ne;e[48]!==P||e[49]!==d||e[50]!==m?(ne=P(Gi(d,m)),e[48]=P,e[49]=d,e[50]=m,e[51]=ne):ne=e[51];let ee;e[52]!==ne?(ee=s.jsx("span",{children:ne}),e[52]=ne,e[53]=ee):ee=e[53];let he;e[54]!==q||e[55]!==J||e[56]!==ee?(he=s.jsxs(ls,{className:"w-fit gap-1.5",children:[q,J,ee]}),e[54]=q,e[55]=J,e[56]=ee,e[57]=he):he=e[57];let ke;e[58]!==N||e[59]!==P?(ke=Zd.map(De=>s.jsx(Tt,{value:De.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:[De.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"}),De.source==="agents"?s.jsx(D,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:P(De.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-5",children:N(De.value)})]})},De.value)),e[58]=N,e[59]=P,e[60]=ke):ke=e[60];let oe;e[61]!==ke?(oe=s.jsx(cs,{align:"start",children:ke}),e[61]=ke,e[62]=oe):oe=e[62];let ge;e[63]!==ue||e[64]!==he||e[65]!==oe?(ge=s.jsxs(os,{value:ue,onValueChange:W,children:[he,oe]}),e[63]=ue,e[64]=he,e[65]=oe,e[66]=ge):ge=e[66];let me;e[67]!==fe||e[68]!==ge?(me=s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[fe,ge]}),e[67]=fe,e[68]=ge,e[69]=me):me=e[69];let ye;e[70]!==f||e[71]!==T||e[72]!==d||e[73]!==i?(ye=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(os,{value:T??"",onValueChange:De=>v(De),disabled:f.length===1,children:[s.jsx(ls,{className:"w-fit",children:s.jsx(us,{placeholder:i("settings.skills.catalog.installSkill.field.chooseProjectPlaceholder")})}),s.jsx(cs,{align:"start",children:f.map(u3)})]})]}),e[70]=f,e[71]=T,e[72]=d,e[73]=i,e[74]=ye):ye=e[74];let ie;e[75]!==a.warnings?(ie=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]=ie):ie=e[76];let ve;e[77]!==me||e[78]!==ye||e[79]!==ie?(ve=s.jsxs("div",{className:"mt-2 space-y-3",children:[me,ye,ie]}),e[77]=me,e[78]=ye,e[79]=ie,e[80]=ve):ve=e[80];let X;e[81]!==r?(X=()=>r(!1),e[81]=r,e[82]=X):X=e[82];let Se;e[83]!==i?(Se=i("settings.common.actions.cancel"),e[83]=i,e[84]=Se):Se=e[84];let Ae;e[85]!==X||e[86]!==Se?(Ae=s.jsx(be,{size:"sm",variant:"ghost",onClick:X,children:Se}),e[85]=X,e[86]=Se,e[87]=Ae):Ae=e[87];const pe=c||!a.installable||d==="project"&&!V;let we;e[88]!==V||e[89]!==U||e[90]!==a.repoSource||e[91]!==a.repoSubpath||e[92]!==a.skillDir||e[93]!==d||e[94]!==m?(we=()=>{U({source:a.repoSource,subpath:a.repoSubpath,scope:d,targetSource:m,skillDir:a.skillDir,directoryOverride:V})},e[88]=V,e[89]=U,e[90]=a.repoSource,e[91]=a.repoSubpath,e[92]=a.skillDir,e[93]=d,e[94]=m,e[95]=we):we=e[95];let Ie;e[96]!==c||e[97]!==i?(Ie=i(c?"settings.skills.catalog.installSkill.actions.installing":"settings.skills.catalog.installSkill.actions.install"),e[96]=c,e[97]=i,e[98]=Ie):Ie=e[98];let Y;e[99]!==pe||e[100]!==we||e[101]!==Ie?(Y=s.jsx(be,{size:"sm",disabled:pe,onClick:we,children:Ie}),e[99]=pe,e[100]=we,e[101]=Ie,e[102]=Y):Y=e[102];let re;e[103]!==Ae||e[104]!==Y?(re=s.jsxs(Vs,{children:[Ae,Y]}),e[103]=Ae,e[104]=Y,e[105]=re):re=e[105];let Pe;e[106]!==te||e[107]!==ve||e[108]!==re?(Pe=s.jsxs(ms,{className:"max-w-md",children:[te,ve,re]}),e[106]=te,e[107]=ve,e[108]=re,e[109]=Pe):Pe=e[109];let ce;e[110]!==r||e[111]!==n||e[112]!==Pe?(ce=s.jsx(ps,{open:n,onOpenChange:r,children:Pe}),e[110]=r,e[111]=n,e[112]=Pe,e[113]=ce):ce=e[113];let Ce;e[114]!==k||e[115]!==U?(Ce=De=>{k&&(U({source:k.source,subpath:k.subpath,scope:k.scope,targetSource:k.targetSource,skillDir:k.skillDir,conflictDecisions:De,directoryOverride:k.directoryOverride??null}),g(!1))},e[114]=k,e[115]=U,e[116]=Ce):Ce=e[116];let Te;e[117]!==y||e[118]!==x||e[119]!==Ce?(Te=s.jsx(a3,{open:x,onOpenChange:g,conflicts:y,onConfirm:Ce}),e[117]=y,e[118]=x,e[119]=Ce,e[120]=Te):Te=e[120];let $e;return e[121]!==ce||e[122]!==Te?($e=s.jsxs(s.Fragment,{children:[ce,Te]}),e[121]=ce,e[122]=Te,e[123]=$e):$e=e[123],$e};function o3(t){return t.installSkills}function l3(t){return t.isInstalling}function c3(t){return t.projects}function d3(t){return t.activeProjectId}function u3(t){return s.jsx(Tt,{value:t.id,children:t.label||t.path},t.id)}const m3=async()=>{try{const t=Xn()?.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}},p3=({mode:t,onModeChange:e,showModeTabs:n=!0})=>{const{t:r}=dt(),{sources:a,itemsBySource:i,selectedSourceId:o,setSelectedSource:c,loadCatalog:d,loadSource:p,loadMoreClawdHub:m,isLoadingCatalog:u,isLoadingSource:f,isLoadingMore:b,loadedSourceIds:h,clawdhubHasMoreBySource:v,lastCatalogError:x}=Aa(Jn(z=>({sources:z.sources,itemsBySource:z.itemsBySource,selectedSourceId:z.selectedSourceId,setSelectedSource:z.setSelectedSource,loadCatalog:z.loadCatalog,loadSource:z.loadSource,loadMoreClawdHub:z.loadMoreClawdHub,isLoadingCatalog:z.isLoadingCatalog,isLoadingSource:z.isLoadingSource,isLoadingMore:z.isLoadingMore,loadedSourceIds:z.loadedSourceIds,clawdhubHasMoreBySource:z.clawdhubHasMoreBySource,lastCatalogError:z.lastCatalogError}))),[g,w]=l.useState(""),[y,C]=l.useState(!1),[k,j]=l.useState(!1),[S,I]=l.useState(null),[M,P]=l.useState(!1),[A,N]=l.useState(!1);l.useEffect(()=>{d()},[d]),l.useEffect(()=>{o&&(h[o]||p(o))},[o,h,p]);const E=l.useMemo(()=>o?i[o]||[]:[],[i,o]),T=l.useMemo(()=>{const z=g.trim().toLowerCase();return z?E.filter(K=>{const F=K.skillName.toLowerCase(),G=(K.description||"").toLowerCase(),Q=(K.frontmatterName||"").toLowerCase();return F.includes(z)||G.includes(z)||Q.includes(z)}):E},[E,g]),R=l.useMemo(()=>a.find(z=>z.id===o)||null,[a,o]),V=!!(o&&o.startsWith("custom:")),_=R?.source==="clawdhub:registry"||R?.sourceType==="clawdhub",U=!!(o&&(v[o]??!0)),B=async()=>{if(!(!o||!V)){P(!0);try{const z=await m3(),F=(Array.isArray(z?.skillCatalogs)?z?.skillCatalogs:[]).filter(G=>G.id!==o);await Is({skillCatalogs:F}),await d({refresh:!0}),N(!1)}finally{P(!1)}}};return s.jsx(Ns,{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($r,{items:[{id:"manual",label:r("settings.skills.catalog.page.mode.manual")},{id:"external",label:r("settings.skills.catalog.page.mode.external")}],activeId:t,onSelect:z=>e(z),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(os,{value:o||"",onValueChange:z=>c(z),children:[s.jsx(ls,{className:"w-fit",children:s.jsx(us,{placeholder:r("settings.skills.catalog.page.field.selectSourcePlaceholder"),children:R?.label})}),s.jsx(cs,{align:"start",children:a.map(z=>s.jsx(Tt,{value:z.id,children:z.label},z.id))})]}),s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>{o?p(o,{refresh:!0}):d({refresh:!0})},disabled:u||f,title:r("settings.skills.catalog.page.actions.refreshTitle"),children:s.jsx(D,{name:"refresh",className:xe("h-3.5 w-3.5",(u||f)&&"animate-spin")})}),V&&s.jsx(be,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0 text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>N(!0),disabled:M,title:r("settings.skills.catalog.page.actions.removeCatalogTitle"),children:s.jsx(D,{name:"delete-bin",className:"h-3.5 w-3.5"})}),s.jsxs(be,{size:"xs",className:"!font-normal gap-1",onClick:()=>C(!0),children:[s.jsx(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:g,onChange:z=>w(z.target.value),placeholder:r("settings.skills.catalog.shared.field.searchSkillsPlaceholder"),className:"h-7 pl-8 w-full sm:w-64"})]}),s.jsx("span",{className:"typography-meta text-muted-foreground mt-1 block",children:u?r("settings.skills.catalog.page.loading.catalog"):r("settings.skills.catalog.page.foundCount",{count:T.length})})]})]})]}),x&&s.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-4 py-3",children:[s.jsx("div",{className:"typography-ui-label font-medium text-[var(--status-error)]",children:r("settings.skills.catalog.page.error.catalogTitle")}),s.jsx("div",{className:"typography-meta text-[var(--status-error)]/80 mt-1",children:x.message})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("section",{className:"px-2 pb-2 pt-0",children:T.length===0&&!f?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-body",children:r("settings.skills.catalog.page.empty.noSkillsTitle")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:r("settings.skills.catalog.page.empty.noSkillsDescription")})]}):f?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx(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:T.map(z=>{const K=z.installed?.isInstalled,F=z.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:z.skillName}),K&&s.jsx("span",{className:"typography-micro text-[var(--status-success)] bg-[var(--status-success)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:r("settings.skills.catalog.page.badge.installed",{scope:F||r("settings.skills.catalog.page.badge.unknown")})}),!z.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")})]}),z.description?s.jsx("div",{className:"typography-meta text-muted-foreground mt-0.5 line-clamp-2",children:z.description}):s.jsx("div",{className:"typography-meta text-muted-foreground/50 mt-0.5 italic",children:r("settings.skills.catalog.shared.noDescription")}),z.clawdhub&&s.jsxs("div",{className:"typography-micro text-muted-foreground mt-1.5 flex items-center gap-3",children:[z.clawdhub.owner&&s.jsxs("span",{children:[r("settings.skills.catalog.page.byOwnerPrefix")," ",s.jsx("span",{className:"font-medium text-foreground/80",children:z.clawdhub.owner})]}),s.jsxs("span",{className:"flex items-center gap-1",children:[s.jsx(D,{name:"download",className:"h-3 w-3"}),z.clawdhub.downloads?.toLocaleString()??0]}),(z.clawdhub.stars??0)>0&&s.jsxs("span",{className:"flex items-center gap-1",children:[s.jsx(D,{name:"star",className:"h-3 w-3"}),z.clawdhub.stars]}),s.jsxs("span",{className:"bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:["v",z.clawdhub.version]})]}),z.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:z.warnings.join(" · ")}):null]}),s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal shrink-0",disabled:!z.installable,onClick:()=>{I(z),j(!0)},children:r("settings.skills.catalog.shared.actions.install")})]})},`${z.sourceId}:${z.skillDir}`)})})}),_&&U&&!f&&T.length>0&&s.jsx("div",{className:"flex justify-center mt-2 px-2",children:s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{m()},disabled:b,children:r(b?"settings.skills.catalog.page.loading.more":"settings.skills.catalog.page.actions.loadMoreSkills")})})]}),s.jsx(Xk,{open:y,onOpenChange:C}),s.jsx(i3,{open:k,onOpenChange:j,item:S}),s.jsx(ps,{open:A,onOpenChange:z=>{M||N(z)},children:s.jsxs(ms,{className:"max-w-md",children:[s.jsxs(ys,{children:[s.jsx(hs,{children:r("settings.skills.catalog.page.removeDialog.title")}),s.jsx(Ss,{children:r("settings.skills.catalog.page.removeDialog.description")})]}),s.jsxs(Vs,{children:[s.jsx(be,{size:"sm",variant:"ghost",onClick:()=>N(!1),disabled:M,children:r("settings.common.actions.cancel")}),s.jsx(be,{size:"sm",variant:"destructive",onClick:()=>{B()},disabled:M,children:r("settings.skills.catalog.page.actions.removeCatalog")})]})]})})]})})},f3=()=>{const t=st.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(p3,{mode:"external",onModeChange:g3,showModeTabs:!1}),t[0]=e):e=t[0],e},h3=()=>{const{t}=dt(),{selectedSkillName:e,getSkillByName:n,getSkillDetail:r,createSkill:a,updateSkill:i,skills:o,skillDraft:c,setSkillDraft:d,setSelectedSkill:p}=oa(Jn(pe=>({selectedSkillName:pe.selectedSkillName,getSkillByName:pe.getSkillByName,getSkillDetail:pe.getSkillDetail,createSkill:pe.createSkill,updateSkill:pe.updateSkill,skills:pe.skills,skillDraft:pe.skillDraft,setSkillDraft:pe.setSkillDraft,setSelectedSkill:pe.setSelectedSkill}))),m=e?n(e):null,u=!!(c&&c.name===e&&!m),f=!!(e&&!m&&!c);l.useEffect(()=>{f&&p(null)},[f,p]);const[b,h]=l.useState(""),[v,x]=l.useState("user"),[g,w]=l.useState("opencode"),[y,C]=l.useState(""),[k,j]=l.useState(""),[S,I]=l.useState([]),[M,P]=l.useState([]),[A,N]=l.useState(!1),[E,T]=l.useState(!1),[R,V]=l.useState(""),[_,U]=l.useState(""),[B,z]=l.useState(!1),[K,F]=l.useState(""),[G,Q]=l.useState(""),[te,Z]=l.useState(null),[fe,ue]=l.useState(!1),[W,q]=l.useState(""),[J,ne]=l.useState(null),[ee,he]=l.useState(!1),ke=u?b.trim()!==""||y.trim()!==""||k.trim()!==""||M.length>0:y!==R||k!==_,oe=te?G!==W:K.trim()!=="",ge=l.useCallback(pe=>{switch(pe){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]),me=l.useCallback(pe=>{switch(pe){case"project-opencode":return t("settings.skills.location.option.projectOpencode.description");case"user-claude":return t("settings.skills.location.option.userClaude.description");case"project-claude":return t("settings.skills.location.option.projectClaude.description");case"user-agents":return t("settings.skills.location.option.userAgents.description");case"project-agents":return t("settings.skills.location.option.projectAgents.description");default:return t("settings.skills.location.option.userOpencode.description")}},[t]);l.useEffect(()=>{(async()=>{if(u&&c)h(c.name||""),x(c.scope||"user"),w(c.source==="agents"?"agents":"opencode"),C(c.description||""),j(c.instructions||""),V(""),U(""),I([]),P(c.pendingFiles||[]);else if(e&&m){T(!0);try{const we=await r(e);if(we){const Ie=we.sources.md;C(Ie.description||""),j(Ie.instructions||""),V(Ie.description||""),U(Ie.instructions||""),I(Ie.supportingFiles||[])}}catch(we){console.error("Failed to load skill details:",we)}finally{T(!1)}}})()},[m,u,e,o,c,r]);const ye=async()=>{const pe=u?b.trim().replace(/\s+/g,"-").toLowerCase():e?.trim();if(!pe){H.error(t("settings.skills.page.toast.skillNameRequired"));return}if(!/^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/.test(pe)||pe.length>64){H.error(t("settings.skills.page.toast.invalidSkillName"));return}if(!y.trim()){H.error(t("settings.skills.page.toast.descriptionRequired"));return}if(u&&o.some(we=>we.name===pe)){H.error(t("settings.skills.page.toast.skillExists"));return}N(!0);try{const we={name:pe,description:y.trim(),instructions:k.trim()||void 0,scope:u?v:void 0,source:u?g:void 0,targetPath:u?void 0:m?.path,supportingFiles:u&&M.length>0?M:void 0};let Ie;u?(Ie=await a(we),Ie&&(d(null),P([]),p(pe))):(Ie=await i(pe,we),Ie&&(V(y.trim()),U(k.trim()))),Ie?H.success(t(u?"settings.skills.page.toast.skillCreated":"settings.skills.page.toast.skillUpdated")):H.error(t(u?"settings.skills.page.toast.createSkillFailed":"settings.skills.page.toast.updateSkillFailed"))}catch(we){console.error("Error saving skill:",we),H.error(t("settings.skills.page.toast.saveUnexpectedError"))}finally{N(!1)}},ie=()=>{Z(null),F(""),Q(""),q(""),z(!0)},ve=async pe=>{if(Z(pe),F(pe),u){const Ie=M.find(Y=>Y.path===pe)?.content||"";Q(Ie),q(Ie),z(!0);return}if(e){ue(!0),z(!0);try{const{readSupportingFile:we}=oa.getState(),Ie=await we(e,pe);Q(Ie||""),q(Ie||"")}catch{H.error(t("settings.skills.page.toast.loadFileContentFailed")),Q(""),q("")}finally{ue(!1)}}},X=async()=>{if(!K.trim()){H.error(t("settings.skills.page.toast.fileNameRequired"));return}const pe=K.trim(),we=te!==null;if(u){if(we)P(re=>re.map(Pe=>Pe.path===te?{path:pe,content:G}:Pe)),H.success(t("settings.skills.page.toast.fileUpdated",{path:pe}));else{if(M.some(re=>re.path===pe)){H.error(t("settings.skills.page.toast.fileExists"));return}P(re=>[...re,{path:pe,content:G}]),H.success(t("settings.skills.page.toast.fileAdded",{path:pe}))}z(!1),Z(null);return}if(!e){H.error(t("settings.skills.page.toast.noSkillSelected"));return}const{writeSupportingFile:Ie}=oa.getState();if(await Ie(e,pe,G)){H.success(we?t("settings.skills.page.toast.fileUpdated",{path:pe}):t("settings.skills.page.toast.fileCreated",{path:pe})),z(!1),Z(null);const re=await r(e);re&&I(re.sources.md.supportingFiles||[])}else H.error(t(we?"settings.skills.page.toast.updateFileFailed":"settings.skills.page.toast.createFileFailed"))},Se=pe=>{if(u){P(we=>we.filter(Ie=>Ie.path!==pe)),H.success(t("settings.skills.page.toast.fileRemoved",{path:pe}));return}e&&ne(pe)},Ae=async()=>{if(!J||!e)return;he(!0);const{deleteSupportingFile:pe}=oa.getState();if(await pe(e,J)){H.success(t("settings.skills.page.toast.fileDeleted",{path:J}));const Ie=await r(e);Ie&&I(Ie.sources.md.supportingFiles||[]),ne(null)}else H.error(t("settings.skills.page.toast.deleteFileFailed"));he(!1)};return!e&&!c||f?s.jsx("div",{className:"flex h-full items-center justify-center px-4",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(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")})]})}):E?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(Ns,{outerClassName:"h-full",className:"w-full",children:[s.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[s.jsx("div",{className:"mb-4",children:s.jsxs("div",{className:"min-w-0",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate flex items-center gap-2",children:u?t("settings.skills.page.title.newSkill"):e}),s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:m?t("settings.skills.page.subtitle.skillLocation",{location:ge(Gi(m.scope,m.source))}):t("settings.skills.page.subtitle.newSkill")})]})}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.skills.page.section.basicInformation")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[u&&s.jsxs("div",{className:"py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.skills.page.field.skillNameLocation")}),s.jsx("span",{className:"typography-meta text-muted-foreground ml-2",children:t("settings.skills.page.field.skillNameHint")}),s.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[s.jsx(Bt,{value:b,onChange:pe=>h(pe.target.value.toLowerCase().replace(/\s+/g,"-")),placeholder:t("settings.skills.page.field.skillNamePlaceholder"),className:"h-7 w-40 px-2"}),s.jsxs(os,{value:Gi(v,g),onValueChange:pe=>{const we=fg(pe);x(we.scope),w(we.source==="agents"?"agents":"opencode")},children:[s.jsxs(ls,{className:"w-fit gap-1.5",children:[v==="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"}),g==="agents"?s.jsx(D,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:ge(Gi(v,g))})]}),s.jsx(cs,{align:"start",children:Zd.map(pe=>s.jsx(Tt,{value:pe.value,children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[pe.scope==="user"?s.jsx(D,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(D,{name:"folder",className:"h-3.5 w-3.5"}),pe.source==="agents"?s.jsx(D,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:ge(pe.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-6",children:me(pe.value)})]})},pe.value))})]})]})]}),s.jsxs("div",{className:"py-1.5",children:[s.jsxs("span",{className:"typography-ui-label text-foreground",children:[t("settings.common.field.description")," ",s.jsx("span",{className:"text-[var(--status-error)]",children:"*"})]}),s.jsx("span",{className:"typography-meta text-muted-foreground ml-2",children:t("settings.skills.page.field.descriptionHint")}),s.jsx("div",{className:"mt-1.5",children:s.jsx(un,{value:y,onChange:pe=>C(pe.target.value),placeholder:t("settings.skills.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] max-h-32 bg-transparent"})})]})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.skills.page.section.instructions")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsx(un,{value:k,onChange:pe=>j(pe.target.value),placeholder:t("settings.skills.page.field.instructionsPlaceholder"),className:"min-h-[220px] max-h-[60vh] font-mono typography-meta"})})]}),s.jsxs("div",{className:"mb-2",children:[s.jsxs("div",{className:"mb-1 px-1 flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.skills.page.section.supportingFiles")}),s.jsxs(be,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:ie,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 pe=u?M:S;return pe.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:pe.map(we=>s.jsxs("div",{className:"flex items-center gap-2 py-1.5 cursor-pointer group",onClick:()=>ve(we.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:we.path}),u&&s.jsx("span",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:t("settings.skills.page.badge.pending")}),s.jsx(be,{size:"sm",variant:"ghost",className:"h-5 w-5 px-0 flex-shrink-0 text-muted-foreground hover:text-[var(--status-error)] opacity-0 group-hover:opacity-100 transition-opacity",onClick:Ie=>{Ie.stopPropagation(),Se(we.path)},children:s.jsx(D,{name:"delete-bin",className:"h-3 w-3"})})]},we.path))})})()})]}),s.jsx("div",{className:"px-2 py-1",children:s.jsx(be,{onClick:ye,disabled:A||!ke,size:"xs",className:"!font-normal",children:t(A?"settings.common.actions.saving":u?"settings.skills.page.actions.createSkill":"settings.common.actions.saveChanges")})})]}),s.jsx(ps,{open:J!==null,onOpenChange:pe=>{!pe&&!ee&&ne(null)},children:s.jsxs(ms,{className:"max-w-md",children:[s.jsxs(ys,{children:[s.jsx(hs,{children:t("settings.skills.page.deleteFileDialog.title")}),s.jsx(Ss,{children:t("settings.skills.page.deleteFileDialog.description",{path:J??""})})]}),s.jsxs(Vs,{children:[s.jsx(be,{size:"sm",variant:"ghost",onClick:()=>ne(null),disabled:ee,children:t("settings.common.actions.cancel")}),s.jsx(be,{size:"sm",variant:"destructive",onClick:Ae,disabled:ee,children:t("settings.common.actions.delete")})]})]})}),s.jsx(ps,{open:B,onOpenChange:pe=>{z(pe),pe||Z(null)},children:s.jsxs(ms,{className:"max-w-3xl max-h-[85vh] flex flex-col",children:[s.jsxs(ys,{className:"flex-shrink-0",children:[s.jsx(hs,{children:t(te?"settings.skills.page.fileDialog.titleEdit":"settings.skills.page.fileDialog.titleAdd")}),s.jsx(Ss,{children:t(te?"settings.skills.page.fileDialog.descriptionEdit":"settings.skills.page.fileDialog.descriptionAdd")})]}),fe?s.jsx("div",{className:"flex-1 flex items-center justify-center py-8",children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.skills.page.loading.fileContent")})}):s.jsxs("div",{className:"space-y-4 flex-1 min-h-0 flex flex-col pt-2",children:[s.jsxs("div",{className:"space-y-2 flex-shrink-0",children:[s.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:t("settings.skills.page.fileDialog.field.filePath")}),s.jsx(Bt,{value:K,onChange:pe=>F(pe.target.value),placeholder:t("settings.skills.page.fileDialog.field.filePathPlaceholder"),className:"text-foreground placeholder:text-muted-foreground focus-visible:ring-[var(--primary-base)]",disabled:te!==null}),!te&&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(un,{value:G,onChange:pe=>Q(pe.target.value),placeholder:t("settings.skills.page.fileDialog.field.contentPlaceholder"),outerClassName:"h-[45vh] min-h-[250px] max-h-[55vh]",className:"h-full min-h-0 font-mono typography-meta"})]})]}),s.jsxs(Vs,{className:"mt-4",children:[s.jsx(be,{size:"sm",variant:"ghost",onClick:()=>{z(!1),Z(null)},children:t("settings.common.actions.cancel")}),s.jsx(be,{size:"sm",onClick:X,disabled:fe||!oe,children:t(te?"settings.common.actions.saveChanges":"settings.skills.page.actions.createFile")})]})]})})]})},fp=t=>{const e=st.c(2),{view:n}=t,r=n===void 0?"installed":n;let a;return e[0]!==r?(a=r==="catalog"?s.jsx(f3,{}):s.jsx(h3,{}),e[0]=r,e[1]=a):a=e[1],a};function g3(){}const hg=t=>{const e=st.c(26),{header:n,footer:r,children:a,className:i,variant:o}=t,c=o===void 0?"sidebar":o,d=on(),p=l.useRef(null),[m,u]=l.useState(!1),[f,b]=l.useState(!1),h=c==="background"||d?"bg-background":"bg-sidebar",v=h==="bg-background"?"var(--surface-background)":"var(--surface-muted)";let x;e[0]===Symbol.for("react.memo_cache_sentinel")?(x=()=>{const N=p.current;if(!N){u(!1),b(!1);return}if(!(N.scrollHeight>N.clientHeight+1)){u(!1),b(!1);return}u(N.scrollTop>1),b(N.scrollTop+N.clientHeight<N.scrollHeight-1)},e[0]=x):x=e[0];const g=x;let w;e[1]===Symbol.for("react.memo_cache_sentinel")?(w=()=>{g()},e[1]=w):w=e[1];let y;e[2]!==a?(y=[a,g],e[2]=a,e[3]=y):y=e[3],l.useEffect(w,y);let C,k;e[4]===Symbol.for("react.memo_cache_sentinel")?(C=()=>{const N=p.current;if(!N)return;const E=()=>g();return N.addEventListener("scroll",E,{passive:!0}),()=>N.removeEventListener("scroll",E)},k=[g],e[4]=C,e[5]=k):(C=e[4],k=e[5]),l.useEffect(C,k);let j;e[6]!==h||e[7]!==i?(j=xe("flex h-full flex-col",h,i),e[6]=h,e[7]=i,e[8]=j):j=e[8];let S;e[9]!==a?(S=s.jsx(Ns,{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 M;e[14]!==v||e[15]!==f?(M=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]=M):M=e[16];let P;e[17]!==M||e[18]!==S||e[19]!==I?(P=s.jsxs("div",{className:"relative flex flex-1 min-h-0 flex-col",children:[S,I,M]}),e[17]=M,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]!==j?(A=s.jsxs("div",{className:j,children:[n,P,r]}),e[21]=r,e[22]=n,e[23]=P,e[24]=j,e[25]=A):A=e[25],A},gg=t=>{const e=st.c(23),{title:n,metadata:r,selected:a,onSelect:i,icon:o,actions:c,className:d}=t,p=a===void 0?!1:a,m=c&&c.length>0,u=p?"bg-interactive-selection":"hover:bg-interactive-hover";let f;e[0]!==d||e[1]!==u?(f=xe("group relative flex items-center rounded-md px-1.5 py-0.5 transition-all duration-200",u,d),e[0]=d,e[1]=u,e[2]=f):f=e[2];let b;e[3]!==n?(b=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n}),e[3]=n,e[4]=b):b=e[4];let h;e[5]!==o||e[6]!==b?(h=s.jsxs("div",{className:"flex items-center gap-1.5",children:[o,b]}),e[5]=o,e[6]=b,e[7]=h):h=e[7];let v;e[8]!==r?(v=r&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:r}),e[8]=r,e[9]=v):v=e[9];let x;e[10]!==i||e[11]!==h||e[12]!==v?(x=s.jsxs("button",{onClick:i,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[h,v]}),e[10]=i,e[11]=h,e[12]=v,e[13]=x):x=e[13];let g;e[14]!==c||e[15]!==m?(g=m&&s.jsxs(Ts,{children:[s.jsx(As,{asChild:!0,children:s.jsx(be,{size:"icon",variant:"ghost",className:"h-6 w-6 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(D,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Ds,{align:"end",className:"w-fit min-w-20",children:c.map(x3)})]}),e[14]=c,e[15]=m,e[16]=g):g=e[16];let w;e[17]!==x||e[18]!==g?(w=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[x,g]}),e[17]=x,e[18]=g,e[19]=w):w=e[19];let y;return e[20]!==f||e[21]!==w?(y=s.jsx("div",{className:f,children:w}),e[20]=f,e[21]=w,e[22]=y):y=e[22],y};function x3(t){const e=t.icon;return s.jsxs($t,{onClick:n=>{n.stopPropagation(),t.onClick()},className:xe(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 b3=t=>{const e=st.c(41),{onItemSelect:n}=t,{t:r}=dt(),a=Ps(y3),i=Re(v3),o=Re(w3),{currentTheme:c}=Cr();let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=new Set,e[0]=d):d=e[0];const[p,m]=l.useState(d);let u;e[1]===Symbol.for("react.memo_cache_sentinel")?(u=on(),e[1]=u):u=e[1];const f=u,b=j3;let h,v;e[2]!==a||e[3]!==i||e[4]!==o?(h=()=>{if(a.length===0){i!==null&&o(null);return}i&&a.some(P=>P.id===i)||o(a[0].id)},v=[a,i,o],e[2]=a,e[3]=i,e[4]=o,e[5]=h,e[6]=v):(h=e[5],v=e[6]),l.useEffect(h,v);let x;e[7]===Symbol.for("react.memo_cache_sentinel")?(x=xe("border-b px-3","pt-4 pb-3"),e[7]=x):x=e[7];let g;e[8]!==r?(g=r("settings.page.projects.title"),e[8]=r,e[9]=g):g=e[9];let w;e[10]!==g?(w=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:g}),e[10]=g,e[11]=w):w=e[11];let y;e[12]!==a.length||e[13]!==r?(y=r("settings.projects.sidebar.total",{count:a.length}),e[12]=a.length,e[13]=r,e[14]=y):y=e[14];let 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(be,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:b,"aria-label":r("settings.projects.sidebar.actions.addProject"),children:s.jsx(D,{name:"add",className:"size-4"})}),e[17]=r,e[18]=k):k=e[18];let j;e[19]!==k||e[20]!==C?(j=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[C,k]}),e[19]=k,e[20]=C,e[21]=j):j=e[21];let S;e[22]!==j||e[23]!==w?(S=s.jsxs("div",{className:x,children:[w,j]}),e[22]=j,e[23]=w,e[24]=S):S=e[24];let I;if(e[25]!==p||e[26]!==c||e[27]!==n||e[28]!==a||e[29]!==i||e[30]!==o){let P;e[32]!==p||e[33]!==c||e[34]!==n||e[35]!==i||e[36]!==o?(P=A=>{const N=A.id===i,E=A.icon?Rl[A.icon]:null,T=`${A.id}:${A.iconImage?.updatedAt??0}`,R=p.has(T)?null:mo(A,{themeVariant:c.metadata.variant,iconColor:c.colors.surface.foreground}),V=A.color?po[A.color]??null:null,_=R?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:R,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>{m(U=>{if(U.has(T))return U;const B=new Set(U);return B.add(T),B})}})}):E?s.jsx(D,{name:E,className:xe("h-4 w-4",N?"text-foreground":"text-muted-foreground/70"),style:V?{color:V}:void 0}):s.jsx(D,{name:"folder",className:xe("h-4 w-4",N?"text-foreground":"text-muted-foreground/70"),style:V?{color:V}:void 0});return s.jsx(gg,{title:A.label||A.path,icon:_,selected:N,onSelect:()=>{o(A.id),n?.()}},A.id)},e[32]=p,e[33]=c,e[34]=n,e[35]=i,e[36]=o,e[37]=P):P=e[37],I=a.map(P),e[25]=p,e[26]=c,e[27]=n,e[28]=a,e[29]=i,e[30]=o,e[31]=I}else I=e[31];let M;return e[38]!==S||e[39]!==I?(M=s.jsx(hg,{variant:"background",header:S,children:I}),e[38]=S,e[39]=I,e[40]=M):M=e[40],M};function y3(t){return t.projects}function v3(t){return t.settingsProjectsSelectedId}function w3(t){return t.setSettingsProjectsSelectedId}function j3(){Nr.requestDirectoryDialog()}const N3=({projectRef:t=null})=>{const{t:e}=dt(),{isMobile:n,isTablet:r}=nn(),a=n||r,i=Ps(E=>E.getActiveProject()),o=t?.path??i?.path??null,c=Lt(E=>E.getWorktreeMetadata),d=El(),p=zs(E=>E.homeDirectory),[m,u]=l.useState([]),[f,b]=l.useState(!1),[h,v]=l.useState(null),[x,g]=l.useState([]),[w,y]=l.useState(!1),C=l.useMemo(()=>t?.id&&t?.path?{id:t.id,path:t.path}:!i?.id||!o?null:{id:i.id,path:o},[i?.id,o,t?.id,t?.path]),k=l.useCallback(async()=>{if(!(!C||h===!1))try{const E=await Hc(C);g(E)}catch{}},[C,h]);l.useEffect(()=>{if(!o)return;let E=!1;return v(null),(async()=>{try{const T=await rh(o);if(E)return;v(T)}catch{}})(),()=>{E=!0}},[o]),l.useEffect(()=>{if(!C){g([]),y(!1);return}if(h===!1){g([]),y(!1);return}let E=!1;return y(!0),g([]),(async()=>{try{const T=await Hc(C);if(E)return;g(T)}catch{}finally{E||y(!1)}})(),()=>{E=!0}},[C,h]),l.useEffect(()=>{if(!C)return;let E=!1;return b(!0),(async()=>{try{const T=await _d(C);E||u(T.length>0?T:[""])}catch{E||u([""])}finally{E||b(!1)}})(),()=>{E=!0}},[C]);const j=l.useCallback((E,T)=>{u(R=>{const V=[...R];return V[E]=T,V})},[]),S=l.useCallback(()=>{u(E=>[...E,""])},[]),I=l.useCallback(async E=>{if(!C)return;const T=E.filter(R=>R.trim().length>0);await ah(C,T)},[C]),M=l.useCallback(E=>{u(T=>{const R=T.filter((V,_)=>_!==E);return I(R),R.length>0?R:[""]})},[I]),P=l.useCallback(()=>{I(m)},[I,m]),A=l.useCallback(E=>{const T=F=>F.replace(/\\/g,"/").replace(/\/+$/,""),R=T(E.path),V=d.filter(F=>{const G=c(F.id);if(G?.path&&T(G.path)===R)return!0;const Q=F.directory;return!!(Q&&T(Q)===R)}),_=new Set(V.map(F=>F.id)),U=F=>{const G=d.filter(te=>{const Z=te.parentID;return Z&&F.has(Z)});if(G.length===0)return[];const Q=new Set(G.map(te=>te.id));return[...G,...U(Q)]},B=U(_),z=new Set,K=[...V,...B].filter(F=>z.has(F.id)?!1:(z.add(F.id),!0));Nr.requestDelete({sessions:K,mode:"worktree",worktree:E})},[d,c]),N=l.useMemo(()=>d.map(E=>E.id).join(","),[d]);return l.useEffect(()=>{h&&o&&k()},[N,h,o,k]),o?h===!1?s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.worktrees.state.gitOnly")}):s.jsxs("div",{className:"max-w-[44rem] space-y-5",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-normal text-foreground",children:e("settings.openchamber.worktrees.setup.title")}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsxs(At,{sideOffset:8,className:"max-w-xs",children:[e("settings.openchamber.worktrees.setup.tooltipPrefix")," ",s.jsx("code",{className:"font-mono text-xs bg-sidebar-accent/50 px-1 rounded",children:"$ROOT_PROJECT_PATH"})," ",e("settings.openchamber.worktrees.setup.tooltipSuffix")]})]})]})}),f?s.jsx("p",{className:"typography-meta text-muted-foreground px-1",children:e("settings.openchamber.worktrees.setup.loading")}):s.jsxs("div",{className:"space-y-2 px-1",children:[m.map((E,T)=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(Bt,{value:E,onChange:R=>j(T,R.target.value),onBlur:P,placeholder:e("settings.openchamber.worktrees.setup.commandPlaceholder"),className:"h-7 w-[30rem] max-w-full font-mono text-xs"}),s.jsx("button",{type:"button",onClick:()=>{M(T)},className:"flex-shrink-0 flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("settings.openchamber.worktrees.setup.removeCommandAria"),children:s.jsx(D,{name:"close",className:"h-4 w-4"})})]},T)),s.jsxs(be,{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(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:e("settings.openchamber.worktrees.list.tooltip")})]})]})}),w?s.jsx("p",{className:"typography-meta text-muted-foreground px-1",children:e("settings.openchamber.worktrees.list.loading")}):x.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground/70 px-1",children:e("settings.openchamber.worktrees.list.empty")}):s.jsx("div",{className:"space-y-1 px-1 max-w-[32.5rem]",children:x.map(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:eo(E.path,p)})]}),s.jsx("button",{type:"button",onClick:()=>A(E),className:xe("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")})},S3=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`action_${Date.now()}_${Math.random().toString(36).slice(2,7)}`,k3=()=>({id:S3(),name:"",command:"",icon:"play"}),C3=({projectRef:t})=>{const{t:e}=dt(),n=l.useMemo(()=>vn(),[]),r=qs(S=>S.instances),a=qs(S=>S.load),[i,o]=l.useState([]),[c,d]=l.useState(!1),[p,m]=l.useState(!1),[u,f]=l.useState(null),[b,h]=l.useState({});l.useEffect(()=>{n&&a().catch(()=>{})},[n,a]),l.useEffect(()=>{let S=!1;return d(!0),(async()=>{try{const I=await Kc(t);if(S)return;o(I.actions),f(JSON.stringify({actions:I.actions}))}catch{if(S)return;o([]),f(JSON.stringify({actions:[]}))}finally{S||d(!1)}})(),()=>{S=!0}},[t]);const v=l.useMemo(()=>n?Dh(r):[],[r,n]),x=l.useMemo(()=>i.some(I=>I.name.trim().length===0||I.command.trim().length===0)?e("settings.projects.actions.validation.fillNameAndCommand"):null,[i,e]),g=l.useMemo(()=>u===null?!1:u!==JSON.stringify({actions:i}),[i,u]),w=l.useCallback(()=>{const S=k3();o(I=>[...I,S]),h(I=>({...I,[S.id]:!0}))},[]),y=l.useCallback(S=>{o(I=>I.filter(M=>M.id!==S)),h(I=>{const M={...I};return delete M[S],M})},[]),C=l.useCallback((S,I)=>{o(M=>M.map(P=>P.id===S?I(P):P))},[]),k=l.useCallback(async()=>{if(x){H.error(x);return}m(!0);try{if(!await Lb(t,{actions:i,primaryActionId:null})){H.error(e("settings.projects.actions.toast.saveFailed"));return}f(JSON.stringify({actions:i})),typeof window<"u"&&window.dispatchEvent(new CustomEvent(Zc,{detail:{projectId:t.id}})),H.success(e("settings.projects.actions.toast.saved"))}catch{H.error(e("settings.projects.actions.toast.saveFailed"))}finally{m(!1)}},[i,t,e,x]),j=!p&&!c&&g&&!x;return s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 flex items-start justify-between gap-2",children:[s.jsxs("div",{children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:e("settings.projects.actions.title")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.description")})]}),s.jsxs(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:w,children:[s.jsx(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",M=Go[I]||"play",P=b[S.id]??!1,A=S.name.trim()||e("settings.projects.actions.state.untitled");return s.jsxs(fr,{open:P,onOpenChange:N=>{h(E=>({...E,[S.id]:N}))},className:xe("py-1.5"),children:[s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs(kr,{className:"group flex-1 justify-start gap-2 rounded-md px-0 pr-1 py-1 hover:bg-[var(--interactive-hover)] focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",children:[P?s.jsx(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:M,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(be,{type:"button",variant:"ghost",size:"xs",className:"!font-normal h-7 w-7 px-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>y(S.id),children:s.jsx(D,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),s.jsx(hr,{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(Ts,{children:[s.jsx(As,{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:M,className:"h-4 w-4"})})}),s.jsx(Ds,{align:"start",className:"w-56 p-2",children:s.jsx("div",{className:"grid grid-cols-6 gap-1",children:Ph.map(N=>{const E=N.Icon,T=(S.icon||"play")===N.key;return s.jsx("button",{type:"button",onClick:()=>C(S.id,R=>({...R,icon:N.key})),className:xe("inline-flex h-8 w-8 items-center justify-center rounded-md border border-transparent text-foreground hover:bg-[var(--interactive-hover)]",T&&"border-[var(--primary-base)] bg-[var(--primary-base)]/10 text-[var(--primary-base)]"),"aria-label":e("settings.projects.actions.field.iconAria",{icon:N.label}),children:s.jsx(D,{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(un,{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(fs,{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(Ct,{children:[s.jsx(It,{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(At,{sideOffset:8,className:"max-w-xs",children:e("settings.projects.actions.field.overrideUrlTooltip")})]})]}),n?s.jsxs("div",{className:"mt-2",children:[s.jsx("p",{className:"typography-meta mb-0.5 text-muted-foreground",children:e("settings.projects.actions.field.desktopSshForward")}),v.length>0?s.jsxs(os,{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(ls,{className:"h-7 w-full max-w-[30rem]",children:s.jsx(us,{placeholder:e("settings.projects.actions.field.useOutputManualUrl")})}),s.jsxs(cs,{children:[s.jsx(Tt,{value:"__none__",children:e("settings.projects.actions.field.useOutputManualUrl")}),v.map(N=>s.jsx(Tt,{value:N.id,children:N.label},N.id))]})]}):s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.state.noDesktopSshForwards")})]}):null]}):null]})]})})]},S.id)})}),s.jsxs("div",{className:"pt-3",children:[x?s.jsx("p",{className:"typography-meta mb-2 text-[var(--status-warning)]",children:x}):null,s.jsx(be,{type:"button",size:"xs",className:"!font-normal",onClick:k,disabled:!j,children:e(p?"settings.common.actions.saving":"settings.projects.actions.actions.save")})]})]})]})},I3=()=>{const t=st.c(201),{t:e}=dt(),n=Ps(P3),r=Ps(A3),a=Ps(D3),i=Ps(T3),o=Ps(M3),c=Re(E3),d=Re(R3),{currentTheme:p}=Cr();let m;e:{if(!c){m=null;break e}let wt;t[0]!==n||t[1]!==c?(wt=n.find(es=>es.id===c)??null,t[0]=n,t[1]=c,t[2]=wt):wt=t[2],m=wt}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(wt=>wt.id===c)||d(n[0].id)},b=[n,c,d],t[3]=n,t[4]=c,t[5]=d,t[6]=f,t[7]=b):(f=t[6],b=t[7]),l.useEffect(f,b);const[h,v]=l.useState(""),[x,g]=l.useState(null),[w,y]=l.useState(null),[C,k]=l.useState(null),[j,S]=l.useState(!1),[I,M]=l.useState(!1),[P,A]=l.useState(!1),[N,E]=l.useState(!1),[T,R]=l.useState(null),[V,_]=l.useState(null),[U,B]=l.useState(!1),z=l.useRef(null);let K;t[8]===Symbol.for("react.memo_cache_sentinel")?(K=()=>{R(null),_(F3)},t[8]=K):K=t[8];const F=K;let G;e:{if(!u){G=null;break e}let wt;t[9]!==u.id||t[10]!==u.path?(wt={id:u.id,path:u.path},t[9]=u.id,t[10]=u.path,t[11]=wt):wt=t[11],G=wt}const Q=G;let te,Z;t[12]!==u?(te=()=>{if(!u){v(""),g(null),y(null),k(null);return}v(u.label??""),g(u.icon??null),y(u.color??null),k(u.iconBackground??null),E(!1),F(),B(!1)},Z=[u,F],t[12]=u,t[13]=te,t[14]=Z):(te=t[13],Z=t[14]),l.useEffect(te,Z);let fe,ue;t[15]===Symbol.for("react.memo_cache_sentinel")?(fe=()=>()=>{F()},ue=[F],t[15]=fe,t[16]=ue):(fe=t[15],ue=t[16]),l.useEffect(fe,ue);let W;t[17]!==w||t[18]!==x||t[19]!==C||t[20]!==h||t[21]!==N||t[22]!==T||t[23]!==u?(W=!!u&&(h.trim()!==(u?.label??"").trim()||x!==(u?.icon??null)||w!==(u?.color??null)||C!==(u?.iconBackground??null)||N||!!T),t[17]=w,t[18]=x,t[19]=C,t[20]=h,t[21]=N,t[22]=T,t[23]=u,t[24]=W):W=t[24];const q=W;let J;t[25]!==w||t[26]!==x||t[27]!==C||t[28]!==h||t[29]!==N||t[30]!==T||t[31]!==i||t[32]!==u||t[33]!==e||t[34]!==r||t[35]!==a?(J=async()=>{if(!u)return;if(T){S(!0);const es=await a(u.id,T);if(S(!1),!es.ok){H.error(es.error||e("settings.projects.page.toast.uploadIconFailed"));return}H.success(e("settings.projects.page.toast.iconUpdated")),F(),E(!1)}const wt=N&&!!u.iconImage;if(wt){M(!0);const es=await i(u.id);if(M(!1),!es.ok){H.error(es.error||e("settings.projects.page.toast.removeIconFailed"));return}H.success(e("settings.projects.page.toast.iconRemoved")),E(!1),k(null)}r(u.id,{label:h.trim(),icon:x,color:w,iconBackground:wt?null:C})},t[25]=w,t[26]=x,t[27]=C,t[28]=h,t[29]=N,t[30]=T,t[31]=i,t[32]=u,t[33]=e,t[34]=r,t[35]=a,t[36]=J):J=t[36];const ne=J,ee=w?po[w]??null:null,he=!!u?.iconImage,ke=!!(T&&V),oe=u?.iconImage?.source==="custom",ge=he&&!N||ke,me=ge;let ye;t[37]!==p||t[38]!==ke||t[39]!==he||t[40]!==N||t[41]!==V||t[42]!==U||t[43]!==u?(ye=U?null:ke?V:u&&he&&!N?mo(u,{themeVariant:p.metadata.variant,iconColor:p.colors.surface.foreground}):null,t[37]=p,t[38]=ke,t[39]=he,t[40]=N,t[41]=V,t[42]=U,t[43]=u,t[44]=ye):ye=t[44];const ie=ye;let ve;t[45]!==j||t[46]!==u?(ve=wt=>{!u||!wt||j||(E(!1),B(!1),R(wt),_(es=>(es&&URL.revokeObjectURL(es),URL.createObjectURL(wt))))},t[45]=j,t[46]=u,t[47]=ve):ve=t[47];const X=ve;let Se;t[48]!==ke||t[49]!==me||t[50]!==he||t[51]!==I||t[52]!==u?(Se=()=>{!u||!me||I||(ke&&F(),E(!!he),B(!1))},t[48]=ke,t[49]=me,t[50]=he,t[51]=I,t[52]=u,t[53]=Se):Se=t[53];const Ae=Se;let pe;t[54]!==o||t[55]!==P||t[56]!==u||t[57]!==e?(pe=async()=>{!u||P||(F(),E(!1),B(!1),A(!0),o(u.id).then(wt=>{if(!wt.ok){H.error(wt.error||e("settings.projects.page.toast.discoverIconFailed"));return}if(wt.skipped){H.success(e("settings.projects.page.toast.customIconAlreadySet"));return}H.success(e("settings.projects.page.toast.iconDiscovered"))}).finally(()=>{A(!1)}))},t[54]=o,t[55]=P,t[56]=u,t[57]=e,t[58]=pe):pe=t[58];const we=pe;if(!u){let wt;t[59]!==e?(wt=e("settings.projects.page.empty.noProjects"),t[59]=e,t[60]=wt):wt=t[60];let es;return t[61]!==wt?(es=s.jsx(Ns,{outerClassName:"h-full",className:"w-full",children:s.jsx("div",{className:"mx-auto w-full max-w-4xl p-3 sm:p-6 sm:pt-8",children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:wt})})}),t[61]=wt,t[62]=es):es=t[62],es}let Ie;t[63]!==u.label||t[64]!==e?(Ie=u.label??e("settings.projects.page.title.default"),t[63]=u.label,t[64]=e,t[65]=Ie):Ie=t[65];let Y;t[66]!==Ie?(Y=s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:Ie}),t[66]=Ie,t[67]=Y):Y=t[67];let re;t[68]!==u.path?(re=s.jsx("p",{className:"typography-meta text-muted-foreground truncate",title:u.path,children:u.path}),t[68]=u.path,t[69]=re):re=t[69];let Pe;t[70]!==Y||t[71]!==re?(Pe=s.jsx("div",{className:"mb-4 flex items-center justify-between gap-4",children:s.jsxs("div",{className:"min-w-0",children:[Y,re]})}),t[70]=Y,t[71]=re,t[72]=Pe):Pe=t[72];let ce;t[73]!==e?(ce=e("settings.projects.page.field.projectName"),t[73]=e,t[74]=ce):ce=t[74];let Ce;t[75]!==ce?(Ce=s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:ce})}),t[75]=ce,t[76]=Ce):Ce=t[76];let Te;t[77]===Symbol.for("react.memo_cache_sentinel")?(Te=wt=>v(wt.target.value),t[77]=Te):Te=t[77];let $e;t[78]!==e?($e=e("settings.projects.page.field.projectNamePlaceholder"),t[78]=e,t[79]=$e):$e=t[79];let De;t[80]!==h||t[81]!==$e?(De=s.jsx("div",{className:"mt-1.5 flex min-w-0 items-center gap-2",children:s.jsx(Bt,{value:h,onChange:Te,placeholder:$e,className:"h-7 min-w-0 w-full sm:max-w-[19rem]"})}),t[80]=h,t[81]=$e,t[82]=De):De=t[82];let de;t[83]!==Ce||t[84]!==De?(de=s.jsxs("div",{className:"py-1.5",children:[Ce,De]}),t[83]=Ce,t[84]=De,t[85]=de):de=t[85];let O;t[86]!==e?(O=e("settings.projects.page.field.accentColor"),t[86]=e,t[87]=O):O=t[87];let L;t[88]!==O?(L=s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:O})}),t[88]=O,t[89]=L):L=t[89];let $;t[90]===Symbol.for("react.memo_cache_sentinel")?($=()=>y(null),t[90]=$):$=t[90];const je=w===null?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-border/40 hover:border-border hover:bg-[var(--surface-muted)]";let ae;t[91]!==je?(ae=xe("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",je),t[91]=je,t[92]=ae):ae=t[92];let _e;t[93]!==e?(_e=e("settings.projects.page.field.none"),t[93]=e,t[94]=_e):_e=t[94];let le;t[95]===Symbol.for("react.memo_cache_sentinel")?(le=s.jsx(D,{name:"close",className:"h-4 w-4 text-muted-foreground"}),t[95]=le):le=t[95];let Me;t[96]!==ae||t[97]!==_e?(Me=s.jsx("button",{type:"button",onClick:$,className:ae,title:_e,children:le}),t[96]=ae,t[97]=_e,t[98]=Me):Me=t[98];let Ge;t[99]!==w?(Ge=$b.map(wt=>s.jsx("button",{type:"button",onClick:()=>y(wt.key),className:xe("h-7 w-7 rounded-md border transition-colors",w===wt.key?"border-2 border-foreground ring-1 ring-[var(--primary-base)]/40":"border-transparent hover:border-border/70"),style:{backgroundColor:wt.cssVar},title:wt.label},wt.key)),t[99]=w,t[100]=Ge):Ge=t[100];let at;t[101]!==Me||t[102]!==Ge?(at=s.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-2",children:[Me,Ge]}),t[101]=Me,t[102]=Ge,t[103]=at):at=t[103];let Ye;t[104]!==L||t[105]!==at?(Ye=s.jsxs("div",{className:"py-1.5",children:[L,at]}),t[104]=L,t[105]=at,t[106]=Ye):Ye=t[106];let Xe;t[107]!==e?(Xe=e("settings.projects.page.field.projectIcon"),t[107]=e,t[108]=Xe):Xe=t[108];let ut;t[109]!==Xe?(ut=s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:Xe})}),t[109]=Xe,t[110]=ut):ut=t[110];let rt;t[111]!==X?(rt=s.jsx("input",{ref:z,type:"file",accept:"image/png,image/jpeg,image/svg+xml,.png,.jpg,.jpeg,.svg",className:"hidden",onChange:wt=>{const es=wt.target.files?.[0]??null;X(es),wt.currentTarget.value=""}}),t[111]=X,t[112]=rt):rt=t[112];let it;t[113]===Symbol.for("react.memo_cache_sentinel")?(it=()=>g(null),t[113]=it):it=t[113];const nt=x===null?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-border/40 hover:border-border hover:bg-[var(--surface-muted)]";let Ne;t[114]!==nt?(Ne=xe("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",nt),t[114]=nt,t[115]=Ne):Ne=t[115];let Ke;t[116]!==e?(Ke=e("settings.projects.page.field.none"),t[116]=e,t[117]=Ke):Ke=t[117];let Ve;t[118]===Symbol.for("react.memo_cache_sentinel")?(Ve=s.jsx(D,{name:"close",className:"h-4 w-4 text-muted-foreground"}),t[118]=Ve):Ve=t[118];let qe;t[119]!==Ne||t[120]!==Ke?(qe=s.jsx("button",{type:"button",onClick:it,className:Ne,title:Ke,children:Ve}),t[119]=Ne,t[120]=Ke,t[121]=qe):qe=t[121];let lt;t[122]!==ee||t[123]!==x?(lt=_b.map(wt=>{const es=wt.Icon;return s.jsx("button",{type:"button",onClick:()=>g(wt.key),className:xe("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",x===wt.key?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-transparent hover:border-border hover:bg-[var(--surface-muted)]"),title:wt.label,children:s.jsx(D,{name:es,className:"w-4 h-4",style:ee&&x===wt.key?{color:ee}:void 0})},wt.key)}),t[122]=ee,t[123]=x,t[124]=lt):lt=t[124];let He;t[125]!==qe||t[126]!==lt?(He=s.jsxs("div",{className:"mt-1.5 flex max-w-[22rem] flex-wrap items-center gap-2",children:[qe,lt]}),t[125]=qe,t[126]=lt,t[127]=He):He=t[127];let ze;t[128]!==ge||t[129]!==C||t[130]!==ie||t[131]!==e?(ze=ge&&ie&&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:ie,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>B(!0)})})})]}),t[128]=ge,t[129]=C,t[130]=ie,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:wt=>k(wt.target.value),className:"h-7 w-9 cursor-pointer rounded border border-border bg-transparent p-1","aria-label":e("settings.projects.page.field.projectIconBackgroundAria")}),s.jsx(Bt,{value:C??"",onChange:wt=>k(wt.target.value),placeholder:"#000000",className:"h-7 w-[8rem]"}),s.jsx(be,{type:"button",size:"xs",variant:"outline",onClick:()=>k(null),className:"h-7 w-7 p-0","aria-label":e("settings.projects.page.field.clearIconBackgroundAria"),title:e("settings.projects.page.field.clearBackground"),disabled:!C,children:s.jsx(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 yt;t[137]!==we||t[138]!==oe||t[139]!==P||t[140]!==j||t[141]!==e?(yt=!oe&&s.jsxs(s.Fragment,{children:[s.jsx(be,{size:"xs",className:"h-6 !font-normal",onClick:()=>z.current?.click(),disabled:j,children:e(j?"settings.projects.page.actions.uploading":"settings.projects.page.actions.uploadIcon")}),s.jsx(be,{size:"xs",className:"h-6 !font-normal",variant:"outline",onClick:()=>{we()},disabled:P,children:e(P?"settings.projects.page.actions.discovering":"settings.projects.page.actions.discoverFavicon")})]}),t[137]=we,t[138]=oe,t[139]=P,t[140]=j,t[141]=e,t[142]=yt):yt=t[142];let Rt;t[143]!==Ae||t[144]!==me||t[145]!==I||t[146]!==e?(Rt=me&&s.jsx(be,{size:"xs",className:"!font-normal",variant:"outline",onClick:()=>{Ae()},disabled:I,children:e(I?"settings.projects.page.actions.removing":"settings.projects.page.actions.removeProjectIcon")}),t[143]=Ae,t[144]=me,t[145]=I,t[146]=e,t[147]=Rt):Rt=t[147];let kt;t[148]!==I||t[149]!==N||t[150]!==e?(kt=N&&s.jsx(be,{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]=kt):kt=t[151];let ht;t[152]!==yt||t[153]!==Rt||t[154]!==kt?(ht=s.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[yt,Rt,kt]}),t[152]=yt,t[153]=Rt,t[154]=kt,t[155]=ht):ht=t[155];let vt;t[156]!==ut||t[157]!==rt||t[158]!==He||t[159]!==ze||t[160]!==et||t[161]!==ht?(vt=s.jsxs("div",{className:"py-1.5",children:[ut,rt,He,ze,et,ht]}),t[156]=ut,t[157]=rt,t[158]=He,t[159]=ze,t[160]=et,t[161]=ht,t[162]=vt):vt=t[162];let ns;t[163]!==de||t[164]!==Ye||t[165]!==vt?(ns=s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[de,Ye,vt]}),t[163]=de,t[164]=Ye,t[165]=vt,t[166]=ns):ns=t[166];let zt;t[167]!==q||t[168]!==I||t[169]!==j||t[170]!==h?(zt=!q||h.trim().length===0||j||I,t[167]=q,t[168]=I,t[169]=j,t[170]=h,t[171]=zt):zt=t[171];let Kt;t[172]!==e?(Kt=e("settings.common.actions.saveChanges"),t[172]=e,t[173]=Kt):Kt=t[173];let mt;t[174]!==ne||t[175]!==zt||t[176]!==Kt?(mt=s.jsx("div",{className:"mt-0.5 px-2 py-1",children:s.jsx(be,{onClick:ne,disabled:zt,size:"xs",className:"!font-normal",children:Kt})}),t[174]=ne,t[175]=zt,t[176]=Kt,t[177]=mt):mt=t[177];let Et;t[178]!==ns||t[179]!==mt?(Et=s.jsxs("div",{className:"mb-8",children:[ns,mt]}),t[178]=ns,t[179]=mt,t[180]=Et):Et=t[180];let rs;t[181]!==Q?(rs=Q&&s.jsx(C3,{projectRef:Q}),t[181]=Q,t[182]=rs):rs=t[182];let gs;t[183]!==rs?(gs=s.jsx("div",{className:"mb-8",children:s.jsx("section",{className:"px-2 pb-2 pt-0",children:rs})}),t[183]=rs,t[184]=gs):gs=t[184];let xs;t[185]!==e?(xs=e("settings.projects.page.section.worktree"),t[185]=e,t[186]=xs):xs=t[186];let bs;t[187]!==xs?(bs=s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:xs})}),t[187]=xs,t[188]=bs):bs=t[188];let Wt;t[189]!==Q?(Wt=Q&&s.jsx(N3,{projectRef:Q}),t[189]=Q,t[190]=Wt):Wt=t[190];let We;t[191]!==Wt?(We=s.jsx("section",{className:"px-2 pb-2 pt-0",children:Wt}),t[191]=Wt,t[192]=We):We=t[192];let St;t[193]!==bs||t[194]!==We?(St=s.jsxs("div",{className:"mb-8",children:[bs,We]}),t[193]=bs,t[194]=We,t[195]=St):St=t[195];let qt;return t[196]!==Pe||t[197]!==Et||t[198]!==gs||t[199]!==St?(qt=s.jsx(Ns,{outerClassName:"h-full",className:"w-full bg-background",children:s.jsxs("div",{className:"mx-auto w-full max-w-4xl p-3 sm:p-6 sm:pt-8",children:[Pe,Et,gs,St]})}),t[196]=Pe,t[197]=Et,t[198]=gs,t[199]=St,t[200]=qt):qt=t[200],qt};function P3(t){return t.projects}function A3(t){return t.updateProjectMeta}function D3(t){return t.uploadProjectIcon}function T3(t){return t.removeProjectIcon}function M3(t){return t.discoverProjectIcon}function E3(t){return t.settingsProjectsSelectedId}function R3(t){return t.setSettingsProjectsSelectedId}function F3(t){return t&&URL.revokeObjectURL(t),null}const O3=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`,L3=()=>Math.floor(2e4+Math.random()*3e4),$3=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")},_3=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"}},B3=({onItemSelect:t})=>{const{t:e}=dt(),n=qs(g=>g.instances),r=qs(g=>g.statusesById),a=qs(g=>g.isLoading),i=qs(g=>g.load),o=qs(g=>g.loadImports),c=qs(g=>g.createFromCommand),d=qs(g=>g.connect),p=qs(g=>g.disconnect),m=qs(g=>g.retry),u=qs(g=>g.removeInstance),f=qs(g=>g.upsertInstance),b=Re(g=>g.settingsRemoteInstancesSelectedId),h=Re(g=>g.setSettingsRemoteInstancesSelectedId);l.useEffect(()=>{i(),o()},[i,o]),l.useEffect(()=>{if(!a){if(n.length===0){b!==null&&h(null);return}b&&n.some(g=>g.id===b)||h(n[0].id)}},[n,a,b,h]);const v=l.useCallback(async()=>{const g=O3();try{await c(g,"ssh user@example.com",e("settings.remoteInstances.sidebar.newSshInstanceName")),h(g),t?.()}catch(w){H.error(e("settings.remoteInstances.sidebar.toast.createFailed"),{description:w instanceof Error?w.message:String(w)})}},[c,t,h,e]),x=l.useCallback(async g=>{try{await d(g.id);return}catch(w){if(!$3(w)||!window.confirm(e("settings.remoteInstances.sidebar.confirm.localPortInUseRetry")))throw w;const C={...g,localForward:{...g.localForward,preferredLocalPort:L3()}};await f(C),await d(C.id),H.success(e("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[d,e,f]);return s.jsx(hg,{variant:"background",header:s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:e("settings.remoteInstances.sidebar.title")}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.remoteInstances.sidebar.total",{count:n.length})}),s.jsx(be,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:()=>{v()},"aria-label":e("settings.remoteInstances.sidebar.actions.addSshInstance"),children:s.jsx(D,{name:"add",className:"size-4"})})]})]}),children:n.map(g=>{const w=r[g.id],y=g.id===b,C=g.nickname?.trim()||g.sshParsed?.destination||g.id,k=`${e(_3(w?.phase))}${w?.localUrl?` · ${w.localUrl}`:""}`,j=w?.phase==="ready",S=w?.phase==="error"||w?.phase==="degraded";return s.jsx(gg,{title:C,metadata:k,selected:y,onSelect:()=>{h(g.id),t?.()},actions:[{label:e(j?"settings.remoteInstances.sidebar.actions.disconnect":"settings.remoteInstances.sidebar.actions.connect"),icon:j?"stop":"plug-2",onClick:()=>{(j?p(g.id):x(g)).catch(M=>{H.error(e(j?"settings.remoteInstances.sidebar.toast.disconnectFailed":"settings.remoteInstances.sidebar.toast.connectFailed"),{description:M instanceof Error?M.message:String(M)})})}},{label:e("settings.remoteInstances.sidebar.actions.retry"),icon:"refresh",onClick:()=>{S&&m(g.id).catch(I=>{H.error(e("settings.remoteInstances.sidebar.toast.retryFailed"),{description:I instanceof Error?I.message:String(I)})})}},{label:e("settings.remoteInstances.sidebar.actions.remove"),icon:"delete-bin",destructive:!0,onClick:()=>{u(g.id).then(()=>{if(b===g.id){const I=n.find(M=>M.id!==g.id);h(I?.id||null)}}).catch(I=>{H.error(e("settings.remoteInstances.sidebar.toast.removeFailed"),{description:I instanceof Error?I.message:String(I)})})}}]},g.id)})})},hp=t=>{const e=st.c(10),{children:n,className:r,outerClassName:a}=t;let i;e[0]!==a?(i=xe("h-full",a),e[0]=a,e[1]=i):i=e[1];let o;e[2]!==r?(o=xe("mx-auto max-w-3xl space-y-6 p-3 sm:p-6 sm:pt-8",r),e[2]=r,e[3]=o):o=e[3];let c;e[4]!==n||e[5]!==o?(c=s.jsx("div",{className:o,children:n}),e[4]=n,e[5]=o,e[6]=c):c=e[6];let d;return e[7]!==i||e[8]!==c?(d=s.jsx(Ns,{outerClassName:i,className:"w-full",children:c}),e[7]=i,e[8]=c,e[9]=d):d=e[9],d},gd=()=>Math.floor(2e4+Math.random()*3e4),z3=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")},V3=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"}},U3=new Set(["config_resolved","auth_check","master_connecting","remote_probe","installing","updating","server_detecting","server_starting","forwarding"]),xg=t=>!!(t&&U3.has(t)),W3=t=>t==="ready"?"bg-[var(--status-success)] animate-pulse":t==="error"?"bg-[var(--status-error)] animate-pulse":t==="degraded"||xg(t)?"bg-[var(--status-warning)] animate-pulse":"bg-muted-foreground/40",K3=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}`,H3=()=>({id:`forward-${Date.now()}-${Math.random().toString(16).slice(2)}`,enabled:!0,type:"local",localHost:"127.0.0.1",localPort:gd(),remoteHost:"127.0.0.1",remotePort:80}),G3=t=>t.trim().replace(/\*/g,"host").replace(/\?/g,"x")||"user@host",Hr=t=>{const e=st.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(It,{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 o;e[3]!==r?(o=s.jsxs(Ct,{children:[i,s.jsx(At,{sideOffset:8,className:"max-w-xs",children:s.jsx("div",{className:"typography-meta text-foreground",children:r})})]}),e[3]=r,e[4]=o):o=e[4];let c;return e[5]!==a||e[6]!==o?(c=s.jsxs("span",{className:"inline-flex items-center gap-1 typography-meta text-muted-foreground",children:[a,o]}),e[5]=a,e[6]=o,e[7]=c):c=e[7],c},q3=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"}},gp=(t,e)=>{const n=(t||"").trim();return`${!n||n==="127.0.0.1"||n==="::1"?"localhost":n}:${e||0}`},J3=t=>{const e=(t||"").trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},Y3=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}`},Q3=t=>{const e=t.trim();if(e)try{window.location.assign(e)}catch{window.location.href=e}},X3=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}},Z3=()=>{const{t}=dt(),e=qs(O=>O.instances),n=qs(O=>O.statusesById),r=qs(O=>O.importCandidates),a=qs(O=>O.isImportsLoading),i=qs(O=>O.isSaving),o=qs(O=>O.error),c=qs(O=>O.load),d=qs(O=>O.loadImports),p=qs(O=>O.refreshStatuses),m=qs(O=>O.upsertInstance),u=qs(O=>O.createFromCommand),f=qs(O=>O.removeInstance),b=qs(O=>O.connect),h=qs(O=>O.disconnect),v=qs(O=>O.retry),x=Re(O=>O.settingsRemoteInstancesSelectedId),g=Re(O=>O.setSettingsRemoteInstancesSelectedId),w=l.useMemo(()=>x&&e.find(O=>O.id===x)||null,[e,x]),[y,C]=l.useState(null),[k,j]=l.useState(!1),[S,I]=l.useState(!1),[M,P]=l.useState(null),[A,N]=l.useState([]),[E,T]=l.useState(null),[R,V]=l.useState(""),[_,U]=l.useState(!1),[B,z]=l.useState({}),[K,F]=l.useState(!1),[G,Q]=l.useState(!1),[te,Z]=l.useState(()=>Date.now());l.useEffect(()=>{c(),d()},[c,d]),l.useEffect(()=>{C(w)},[w]),l.useEffect(()=>{if(!x)return;const O=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||p()},2e3);return()=>{window.clearInterval(O)}},[p,x]),l.useEffect(()=>{let O=null,L=Date.now();const $=()=>{const ae=Date.now();ae-L>=1e3&&(Z(ae),L=ae),O=requestAnimationFrame($)};(typeof document>"u"||document.visibilityState==="visible")&&(O=requestAnimationFrame($));const je=()=>{document.visibilityState==="visible"&&O===null?O=requestAnimationFrame($):document.visibilityState!=="visible"&&O!==null&&(cancelAnimationFrame(O),O=null)};return document.addEventListener("visibilitychange",je),()=>{document.removeEventListener("visibilitychange",je),O!==null&&cancelAnimationFrame(O)}},[]);const fe=x?n[x]:null,ue=fe?.phase,W=ue==="ready",q=ue==="degraded",J=xg(ue),ee=W||(J||q),he=fe?Math.max(0,te-fe.updatedAtMs):0,ke=q&&he>12e3,oe=l.useMemo(()=>!y||!w?!1:JSON.stringify(y)!==JSON.stringify(w),[y,w]),ge=l.useCallback(O=>{C(L=>L&&O(L))},[]),me=l.useCallback(async()=>{if(!y)return;const O=X3(y);if(!O.sshCommand.trim()){H.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}if(!(O.localForward.bindHost==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces")))){if(O.auth.sshPassword?.enabled&&O.auth.sshPassword.value?.trim()&&O.auth.sshPassword.store!=="settings"){const L=window.confirm(t("settings.remoteInstances.page.confirm.storeSshPasswordPlaintext"));O.auth.sshPassword.store=L?"settings":"never",L||(O.auth.sshPassword.value=void 0)}if(O.auth.openchamberPassword?.enabled&&O.auth.openchamberPassword.value?.trim()&&O.auth.openchamberPassword.store!=="settings"){const L=window.confirm(t("settings.remoteInstances.page.confirm.storeUiPasswordPlaintext"));O.auth.openchamberPassword.store=L?"settings":"never",L||(O.auth.openchamberPassword.value=void 0)}try{await m(O),H.success(t("settings.remoteInstances.page.toast.instanceSaved"))}catch(L){H.error(t("settings.remoteInstances.page.toast.saveFailed"),{description:L instanceof Error?L.message:String(L)})}}},[y,t,m]),ye=l.useCallback(async(O,L)=>{const $=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{return await u($,`ssh ${L}`,O),g($),H.success(t("settings.remoteInstances.page.toast.instanceCreated")),!0}catch(je){return H.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:je instanceof Error?je.message:String(je)}),!1}},[u,g,t]),ie=l.useCallback(()=>{_||(T(null),V(""))},[_]),ve=l.useCallback((O,L)=>{if(L){T(O),V(G3(O));return}ye(O,O)},[ye]),X=l.useCallback(async()=>{const O=E,L=R.trim();if(O){if(!L){H.error(t("settings.remoteInstances.page.toast.destinationRequired"));return}U(!0);try{await ye(O,L)&&(T(null),V(""))}finally{U(!1)}}},[ye,R,E,t]),Se=l.useCallback(async()=>{if(w)try{await b(w.id);return}catch(O){if(!z3(O)||!window.confirm(t("settings.remoteInstances.sidebar.confirm.localPortInUseRetry")))throw O;const $={...w,localForward:{...w.localForward,preferredLocalPort:gd()}};await m($),await b($.id),H.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[b,w,t,m]),Ae=l.useCallback(async O=>(await Bb(O,600)).map($=>Y3($)),[]),pe=l.useCallback(async()=>{if(y){j(!0),I(!0),P(null);try{const O=await Ae(y.id);N(O)}catch(O){N([]),P(O instanceof Error?O.message:String(O))}finally{I(!1)}}},[y,Ae]);l.useEffect(()=>{if(!k||!y)return;let O=!1;const L=async()=>{try{const je=await Ae(y.id);O||(N(je),P(null))}catch(je){O||P(je instanceof Error?je.message:String(je))}};L();const $=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||L()},1e3);return()=>{O=!0,window.clearInterval($)}},[y,k,Ae]);const we=l.useMemo(()=>A.join(`
176
+ `),[A]),Ie=l.useCallback(()=>{if(!we.trim()){H.error(t("settings.remoteInstances.page.toast.noLogsToCopy"));return}In(we).then(O=>{O.ok&&H.success(t("settings.remoteInstances.page.toast.logsCopied"))})},[we,t]),Y=l.useCallback(async()=>{if(y)try{await zb(y.id),N([]),H.success(t("settings.remoteInstances.page.toast.logsCleared"))}catch(O){H.error(t("settings.remoteInstances.page.toast.clearLogsFailed"),{description:O instanceof Error?O.message:String(O)})}},[y,t]),re=l.useCallback(async()=>{if(!fe?.localUrl){H.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}const O=fe.localUrl.trim();if(!O){H.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}Q3(O)},[fe?.localUrl,t]),Pe=l.useCallback(()=>{if(!y)return;F(!0),(ee?h(y.id):Se()).catch(L=>{const $=ee?W?"settings.remoteInstances.page.toast.disconnectFailed":"settings.remoteInstances.page.toast.cancelConnectionFailed":"settings.remoteInstances.page.toast.connectFailed";H.error(t($),{description:L instanceof Error?L.message:String(L)})}).finally(()=>{F(!1)})},[ee,Se,h,y,W,t]),ce=l.useCallback(()=>{if(!y||J)return;Q(!0),(q?h(y.id).then(()=>Se()):v(y.id)).catch(L=>{H.error(t("settings.remoteInstances.page.toast.retryFailed"),{description:L instanceof Error?L.message:String(L)})}).finally(()=>{Q(!1)})},[Se,h,y,J,q,v,t]),Ce=t(J?"settings.remoteInstances.page.actions.connecting":q?ke?"settings.remoteInstances.page.actions.reconnectNow":"settings.remoteInstances.page.actions.reconnecting":"settings.remoteInstances.sidebar.actions.retry"),Te=!K&&!G&&(ue==="error"||ue==="idle"||!ue||q&&ke)&&!J,$e=t(W?"settings.remoteInstances.sidebar.actions.disconnect":ee?"settings.remoteInstances.page.actions.cancel":"settings.remoteInstances.sidebar.actions.connect");if(!y)return s.jsxs(hp,{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(O=>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:[O.host,O.pattern?` ${t("settings.remoteInstances.page.import.patternSuffix")}`:""]}),s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[O.source," config"]})]}),s.jsx(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ve(O.host,O.pattern)},children:t("settings.remoteInstances.page.actions.create")})]},`${O.source}:${O.host}`))})})]}),s.jsx(ps,{open:!!E,onOpenChange:O=>{O||ie()},children:s.jsxs(ms,{className:"sm:max-w-md",children:[s.jsxs(ys,{children:[s.jsx(hs,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Ss,{children:E?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:E}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:O=>{O.preventDefault(),X()},children:[s.jsx(Bt,{value:R,onChange:O=>V(O.target.value),placeholder:t("settings.remoteInstances.page.patternDialog.destinationPlaceholder"),autoFocus:!0}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsx(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:ie,disabled:_,children:t("settings.common.actions.cancel")}),s.jsx(be,{type:"submit",size:"xs",className:"!font-normal",disabled:_,children:t("settings.remoteInstances.page.actions.create")})]})]})]})})]});const De=y.remoteOpenchamber.mode==="managed",de=y.nickname?.trim()||y.sshParsed?.destination||y.id;return s.jsxs(hp,{children:[s.jsxs("div",{className:"mb-6 px-1",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:de}),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 ${W3(ue)}`}),s.jsx("span",{children:t(V3(ue))}),fe?.localUrl?s.jsx("span",{className:"font-mono text-foreground/80",children:fe.localUrl}):null,ke?s.jsx("span",{children:t("settings.remoteInstances.page.status.reconnectStale")}):null]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.section.actions")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.section.actionsDescription")})]}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(be,{type:"button",variant:ee?"outline":"default",size:"xs",className:"!font-normal",onClick:Pe,disabled:K||G,children:[ee?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"}),$e]}),s.jsxs(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:ce,disabled:!Te,children:[s.jsx(D,{name:"refresh",className:`h-3.5 w-3.5 ${J||q&&!ke?"animate-spin":""}`}),Ce]}),s.jsxs(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{pe()},children:[s.jsx(D,{name:"terminal-window",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.logs")]}),s.jsxs(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal text-[var(--status-error)] border-[var(--status-error)]/30 hover:text-[var(--status-error)]",onClick:()=>{window.confirm(t("settings.remoteInstances.page.confirm.removeInstance"))&&f(y.id).then(()=>{g(null),H.success(t("settings.remoteInstances.page.toast.instanceRemoved"))}).catch(L=>{H.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:L instanceof Error?L.message:String(L)})})},children:[s.jsx(D,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.remove")]})]}),fe?.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:fe.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:O=>ge(L=>({...L,sshCommand:O.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:O=>ge(L=>({...L,nickname:O.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(En,{containerClassName:"w-fit",min:5,max:240,step:1,className:"w-16 tabular-nums",value:y.connectionTimeoutSec,onValueChange:O=>{ge(L=>({...L,connectionTimeoutSec:Number.isFinite(O)?O:L.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(Hr,{label:t("settings.remoteInstances.page.field.mode"),hint:t("settings.remoteInstances.page.field.modeHint")})}),s.jsxs(os,{value:y.remoteOpenchamber.mode,onValueChange:O=>ge(L=>({...L,remoteOpenchamber:{...L.remoteOpenchamber,mode:O==="external"?"external":"managed"}})),children:[s.jsx(ls,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(us,{placeholder:t("settings.remoteInstances.page.field.modePlaceholder")})}),s.jsxs(cs,{children:[s.jsx(Tt,{value:"managed",children:t("settings.remoteInstances.page.field.modeManaged")}),s.jsx(Tt,{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(Hr,{label:t("settings.remoteInstances.page.field.preferredRemotePort"),hint:t("settings.remoteInstances.page.field.preferredRemotePortHint")})}),s.jsx(En,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-20 tabular-nums",value:y.remoteOpenchamber.preferredPort,onValueChange:O=>{ge(L=>({...L,remoteOpenchamber:{...L.remoteOpenchamber,preferredPort:Number.isFinite(O)&&O>0?O:void 0}}))},onClear:()=>{ge(O=>({...O,remoteOpenchamber:{...O.remoteOpenchamber,preferredPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]}),De?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(Hr,{label:t("settings.remoteInstances.page.field.installMethod"),hint:t("settings.remoteInstances.page.field.installMethodHint")})}),s.jsxs(os,{value:y.remoteOpenchamber.installMethod,onValueChange:O=>ge(L=>({...L,remoteOpenchamber:{...L.remoteOpenchamber,installMethod:O==="npm"||O==="download_release"||O==="upload_bundle"?O:"bun"}})),children:[s.jsx(ls,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(us,{placeholder:t("settings.remoteInstances.page.field.selectInstallMethodPlaceholder")})}),s.jsxs(cs,{children:[s.jsx(Tt,{value:"bun",children:"bun"}),s.jsx(Tt,{value:"npm",children:"npm"}),s.jsx(Tt,{value:"download_release",children:t("settings.remoteInstances.page.field.installMethodDownloadRelease")}),s.jsx(Tt,{value:"upload_bundle",children:t("settings.remoteInstances.page.field.installMethodUploadBundle")})]})]})]}):null,De?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(Hr,{label:t("settings.remoteInstances.page.field.keepServerRunning"),hint:t("settings.remoteInstances.page.field.keepServerRunningHint")})}),s.jsx("div",{className:"flex w-full items-center gap-2 md:max-w-xs",children:s.jsx(ml,{checked:y.remoteOpenchamber.keepRunning,onCheckedChange:O=>ge(L=>({...L,remoteOpenchamber:{...L.remoteOpenchamber,keepRunning:O}}))})})]}):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(Hr,{label:t("settings.remoteInstances.page.field.bindHost"),hint:t("settings.remoteInstances.page.field.bindHostHint")})}),s.jsxs(os,{value:y.localForward.bindHost,onValueChange:O=>{O==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces"))||ge(L=>({...L,localForward:{...L.localForward,bindHost:O==="localhost"||O==="0.0.0.0"?O:"127.0.0.1"}}))},children:[s.jsx(ls,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(us,{placeholder:t("settings.remoteInstances.page.field.selectBindHostPlaceholder")})}),s.jsxs(cs,{children:[s.jsx(Tt,{value:"127.0.0.1",children:"127.0.0.1"}),s.jsx(Tt,{value:"localhost",children:"localhost"}),s.jsx(Tt,{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(Hr,{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(En,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-20 tabular-nums",value:y.localForward.preferredLocalPort,onValueChange:O=>{ge(L=>({...L,localForward:{...L.localForward,preferredLocalPort:Number.isFinite(O)&&O>0?O:void 0}}))},onClear:()=>{ge(O=>({...O,localForward:{...O.localForward,preferredLocalPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")}),s.jsx(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal h-7 w-7 px-0",title:t("settings.remoteInstances.page.actions.pickRandomPort"),onClick:()=>ge(O=>({...O,localForward:{...O.localForward,preferredLocalPort:gd()}})),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:O=>ge(L=>({...L,auth:{...L.auth,sshPassword:{enabled:O.target.value.trim().length>0,value:O.target.value,store:L.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:O=>ge(L=>({...L,auth:{...L.auth,openchamberPassword:{enabled:O.target.value.trim().length>0,value:O.target.value,store:L.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((O,L)=>{const $=rt=>{ge(it=>({...it,portForwards:it.portForwards.map((nt,Ne)=>Ne===L?rt(nt):nt)}))},je=O.type==="remote"?"Local target":"Local listen",ae=O.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.",_e=O.type==="remote"?"Remote listen":"Remote target",le=O.type==="remote"?"Remote host and port where SSH creates the -R listener.":"Remote host and port that receives traffic from local -L listener.",Me=gp(O.localHost||"localhost",O.localPort),Ge=gp(O.remoteHost||"localhost",O.remotePort),at=O.type==="local"&&typeof O.localPort=="number"&&O.localPort>0,Ye=at?`http://${J3(O.localHost)}:${O.localPort}`:"",Xe=!!B[O.id],ut=O.type==="local"?t("settings.remoteInstances.page.forwardType.local"):O.type==="remote"?t("settings.remoteInstances.page.forwardType.remote"):t("settings.remoteInstances.page.forwardType.dynamic");return s.jsxs(fr,{open:Xe,onOpenChange:rt=>{z(it=>({...it,[O.id]:rt}))},className:`${L>0?"border-t border-[var(--surface-subtle)]":""} py-2`,children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("div",{className:"min-w-0 flex items-center gap-2",children:s.jsxs(kr,{className:"flex items-center gap-2 group",children:[s.jsx(D,{name:"arrow-down-s",className:`h-4 w-4 text-muted-foreground transition-transform ${Xe?"rotate-180":""}`}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:K3(O)}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:ut})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ml,{checked:O.enabled,onCheckedChange:rt=>$(it=>({...it,enabled:rt})),"aria-label":t("settings.remoteInstances.page.actions.enableForwardAria")}),s.jsx(be,{type:"button",variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0 text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>ge(rt=>({...rt,portForwards:rt.portForwards.filter(it=>it.id!==O.id)})),children:s.jsx(D,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),s.jsx(hr,{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(q3(O.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(Hr,{label:t("settings.remoteInstances.page.field.forwardType"),hint:t("settings.remoteInstances.page.field.forwardTypeHint")})}),s.jsxs(os,{value:O.type,onValueChange:rt=>$(it=>({...it,type:rt==="dynamic"||rt==="remote"?rt:"local"})),children:[s.jsx(ls,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(us,{placeholder:t("settings.remoteInstances.page.field.typePlaceholder")})}),s.jsxs(cs,{children:[s.jsx(Tt,{value:"local",children:t("settings.remoteInstances.page.forwardType.local")}),s.jsx(Tt,{value:"remote",children:t("settings.remoteInstances.page.forwardType.remote")}),s.jsx(Tt,{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(Hr,{label:je,hint:ae})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Bt,{className:"h-7 w-32",value:O.localHost||"127.0.0.1",onChange:rt=>$(it=>({...it,localHost:rt.target.value})),placeholder:t("settings.remoteInstances.page.field.localHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(En,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-16 tabular-nums",value:O.localPort,onValueChange:rt=>{$(it=>({...it,localPort:Number.isFinite(rt)&&rt>0?rt:void 0}))},onClear:()=>{$(rt=>({...rt,localPort:void 0}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]})]}),O.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(Hr,{label:_e,hint:le})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Bt,{className:"h-7 w-32",value:O.remoteHost||"",onChange:rt=>$(it=>({...it,remoteHost:rt.target.value})),placeholder:t("settings.remoteInstances.page.field.remoteHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(En,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-16 tabular-nums",value:O.remotePort,onValueChange:rt=>{$(it=>({...it,remotePort:Number.isFinite(rt)&&rt>0?rt:void 0}))},onClear:()=>{$(rt=>({...rt,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:O.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:Me}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.localSocks5")})]}):O.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:Ge}),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:Me}),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:Me}),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:Ge}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")})]})}),at?s.jsxs(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{qn(Ye).then(rt=>{rt||H.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]})]})})]},O.id)}),s.jsxs(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal mt-1",onClick:()=>{const O=H3();ge(L=>({...L,portForwards:[...L.portForwards,O]})),z(L=>({...L,[O.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((O,L)=>s.jsxs("div",{className:`flex items-center justify-between gap-2 px-1 py-2 ${L>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:[O.host,O.pattern?" (pattern)":""]}),s.jsx("div",{className:"typography-micro text-muted-foreground truncate",children:O.sshCommand})]}),s.jsx(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ve(O.host,O.pattern)},children:t("settings.common.actions.import")})]},`${O.source}:${O.host}`))})})]}),s.jsx("div",{className:"sticky bottom-0 z-10 -mx-3 sm:-mx-6 bg-[var(--surface-background)] border-t border-[var(--interactive-border)] px-3 sm:px-6 py-3",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(be,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{me()},disabled:!oe||i,children:t("settings.common.actions.saveChanges")}),fe?.localUrl?s.jsxs(s.Fragment,{children:[s.jsxs(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{In(fe.localUrl||"").then(O=>{O.ok&&H.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(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{re()},children:[s.jsx(D,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.open")]})]}):null,o?s.jsx("div",{className:"ml-auto typography-meta text-[var(--status-error)]",children:o}):null]})}),s.jsx(ps,{open:k,onOpenChange:j,children:s.jsxs(ms,{className:"sm:max-w-2xl",children:[s.jsxs(ys,{children:[s.jsx(hs,{children:t("settings.remoteInstances.page.logsDialog.title")}),s.jsx(Ss,{children:y?.nickname?.trim()||y?.sshParsed?.destination||y?.id||t("settings.remoteInstances.page.logsDialog.selectedInstanceFallback")})]}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsxs(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Ie,disabled:S||!we.trim(),children:[s.jsx(D,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.common.actions.copyAll")]}),s.jsxs(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Y()},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")}):M?s.jsx("div",{className:"typography-meta text-[var(--status-error)]",children:M}):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(`
177
+ `):t("settings.remoteInstances.page.logsDialog.empty")})]})}),s.jsx(ps,{open:!!E,onOpenChange:O=>{O||ie()},children:s.jsxs(ms,{className:"sm:max-w-md",children:[s.jsxs(ys,{children:[s.jsx(hs,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Ss,{children:E?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:E}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:O=>{O.preventDefault(),X()},children:[s.jsx(Bt,{value:R,onChange:O=>V(O.target.value),placeholder:t("settings.remoteInstances.page.patternDialog.destinationPlaceholder"),autoFocus:!0}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsx(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:ie,disabled:_,children:t("settings.common.actions.cancel")}),s.jsx(be,{type:"submit",size:"xs",className:"!font-normal",disabled:_,children:t("settings.common.actions.create")})]})]})]})})]})},e5="__add_provider__",t5=()=>{const t=sn.getDirectory();return typeof t=="string"&&t.trim().length>0?t.trim():null},s5=({onItemSelect:t})=>{const{t:e}=dt(),n=bt(f=>f.providers),r=bt(f=>f.selectedProviderId),a=bt(f=>f.setSelectedProvider),i=Ps(f=>f.activeProjectId),[o,c]=l.useState({}),d=l.useMemo(()=>t5(),[i]);l.useEffect(()=>{if(n.length===0){c({});return}let f=!1;return(async()=>{const h=n.map(async v=>{try{const x=d?`?directory=${encodeURIComponent(d)}`:"",g=await fetch(`/api/provider/${encodeURIComponent(v.id)}/source${x}`,{method:"GET",headers:{Accept:"application/json"}});if(!g.ok)return;const w=await g.json().catch(()=>null),y=w?.sources??w?.data?.sources;if(!y||f)return;c(C=>({...C,[v.id]:y}))}catch{}});await Promise.all(h)})(),()=>{f=!0}},[d,n]);const p="bg-background",m=l.useMemo(()=>n.filter(f=>!!o[f.id]?.project?.exists),[n,o]),u=l.useMemo(()=>n.filter(f=>!o[f.id]?.project?.exists),[n,o]);return s.jsxs("div",{className:xe("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(ho,{className:"mb-3"}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.providers.sidebar.total",{count:n.length})}),s.jsx(be,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:()=>{a(e5),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(Ns,{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(xp,{provider:f,selectedProviderId:r,onSelect:()=>{a(f.id),t?.()}},f.id))]}),m.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:xe("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(xp,{provider:f,selectedProviderId:r,onSelect:()=>{a(f.id),t?.()}},f.id))]})]})})]})},xp=t=>{const e=st.c(17),{provider:n,selectedProviderId:r,onSelect:a}=t,i=Array.isArray(n.models)?n.models.length:0,o=n.id===r,c=n.id,d=o?"bg-interactive-selection":"hover:bg-interactive-hover";let p;e[0]!==d?(p=xe("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(pr,{providerId:n.id,className:"h-4 w-4 flex-shrink-0"}),e[2]=n.id,e[3]=m):m=e[3];const u=n.name||n.id;let f;e[4]!==u?(f=s.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:u}),e[4]=u,e[5]=f):f=e[5];let b;e[6]!==i?(b=s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:i}),e[6]=i,e[7]=b):b=e[7];let h;e[8]!==a||e[9]!==m||e[10]!==f||e[11]!==b?(h=s.jsxs("button",{type:"button",onClick:a,className:"flex min-w-0 flex-1 items-center gap-2 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[m,f,b]}),e[8]=a,e[9]=m,e[10]=f,e[11]=b,e[12]=h):h=e[12];let v;return e[13]!==n.id||e[14]!==p||e[15]!==h?(v=s.jsx("div",{className:p,children:h},c),e[13]=n.id,e[14]=p,e[15]=h,e[16]=v):v=e[16],v},n5=new Intl.NumberFormat("en-US",{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}),bp=t=>{if(typeof t!="number"||Number.isNaN(t))return null;if(t===0)return"0";const e=n5.format(t);return e.endsWith(".0")?e.slice(0,-2):e},Fo="__add_provider__",gi=t=>typeof t=="object"&&t!==null,yp=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()},r5=t=>{if(!gi(t))return{};const e={};for(const[n,r]of Object.entries(t))Array.isArray(r)&&(e[n]=r.filter(a=>gi(a)));return e},a5=t=>{if(typeof t=="string")return{id:t};if(!gi(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}},i5=t=>{let e=[];Array.isArray(t)?e=t:gi(t)&&(Array.isArray(t.all)?e=t.all:Array.isArray(t.providers)&&(e=t.providers));const n=e.map(a=>a5(a)).filter(a=>!!a),r=new Set;return n.filter(a=>r.has(a.id)?!1:(r.add(a.id),!0))},o5=()=>{const{t}=dt(),e=bt(ie=>ie.providers),n=bt(ie=>ie.selectedProviderId),r=bt(ie=>ie.setSelectedProvider),a=bt(ie=>ie.getModelMetadata),i=Re(ie=>ie.hiddenModels),o=Re(ie=>ie.toggleHiddenModel),c=Re(ie=>ie.hideAllModels),d=Re(ie=>ie.showAllModels),[p,m]=l.useState({}),[u,f]=l.useState(!1),[b,h]=l.useState({}),[v,x]=l.useState(null),[g,w]=l.useState(""),[y,C]=l.useState(null),[k,j]=l.useState({}),[S,I]=l.useState({}),[M,P]=l.useState([]),[A,N]=l.useState(!1),[E,T]=l.useState(null),[R,V]=l.useState(""),[_,U]=l.useState(""),[B,z]=l.useState(!1),[K,F]=l.useState({}),[G,Q]=l.useState(!1);l.useEffect(()=>{!n&&e.length>0&&r(e[0].id)},[e,n,r]),l.useEffect(()=>{let ie=!0;return(async()=>{f(!0);try{const X=await fetch("/api/provider/auth",{method:"GET",headers:{Accept:"application/json"}});if(!X.ok)throw new Error(`Auth methods request failed (${X.status})`);const Se=await X.json().catch(()=>({}));if(!ie)return;m(r5(Se))}catch(X){if(!ie)return;console.error("Failed to load provider auth methods:",X),H.error(t("settings.providers.page.toast.authMethodsLoadFailed"))}finally{ie&&f(!1)}})(),()=>{ie=!1}},[t]),l.useEffect(()=>{let ie=!0;return(async()=>{N(!0),T(null);try{const X=await fetch("/api/provider",{method:"GET",headers:{Accept:"application/json"}});if(!X.ok)throw new Error(`Provider list request failed (${X.status})`);const Se=await X.json().catch(()=>({}));if(!ie)return;P(i5(Se))}catch(X){if(!ie)return;console.error("Failed to load available providers:",X),T(t("settings.providers.page.state.unableToLoadProviderList"))}finally{ie&&N(!1)}})(),()=>{ie=!1}},[t]);const te=l.useMemo(()=>new Set(e.map(ie=>ie.id)),[e]),Z=l.useMemo(()=>M.filter(ie=>!te.has(ie.id)).sort((ie,ve)=>{const X=(ie.name||ie.id).toLowerCase(),Se=(ve.name||ve.id).toLowerCase();return X.localeCompare(Se)}),[M,te]);l.useEffect(()=>{n===Fo&&R&&!Z.some(ie=>ie.id===R)&&V("")},[n,R,Z]),l.useEffect(()=>{if(n===Fo){Q(!0);return}Q(!1)},[n,t]),l.useEffect(()=>{if(!n||n===Fo)return;let ie=!1;return(async()=>{try{const X=await fetch(`/api/provider/${encodeURIComponent(n)}/source`,{method:"GET",headers:{Accept:"application/json"}}),Se=await X.json().catch(()=>null);if(!X.ok)throw new Error(Se?.error||t("settings.providers.page.toast.providerSourcesLoadFailed"));const Ae=Se?.sources??Se?.data?.sources;!ie&&Ae&&F(pe=>({...pe,[n]:Ae}))}catch(X){ie||console.error("Failed to load provider sources:",X)}})(),()=>{ie=!0}},[n,t]);const fe=e.find(ie=>ie.id===n),ue=n?K[n]:void 0,W=async ie=>{const ve=b[ie]?.trim()??"";if(!ve){H.error(t("settings.providers.page.toast.apiKeyRequired"));return}const X=`api:${ie}`;x(X);try{const Se=await fetch(`/api/auth/${encodeURIComponent(ie)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"api",key:ve})}),Ae=await Se.json().catch(()=>null);if(!Se.ok){const pe=Ae?.error||t("settings.providers.page.toast.apiKeySaveFailed");throw new Error(pe)}H.success(t("settings.providers.page.toast.apiKeySaved")),h(pe=>({...pe,[ie]:""})),await ni({scopes:["providers"],mode:"active"}),r(ie)}catch(Se){console.error("Failed to save API key:",Se),H.error(t("settings.providers.page.toast.apiKeySaveFailed"))}finally{x(null)}},q=async(ie,ve)=>{const X=`oauth:${ie}:${ve}`;x(X);try{const Se=await fetch(`/api/provider/${encodeURIComponent(ie)}/oauth/authorize`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({method:ve})}),Ae=await Se.json().catch(()=>null);if(!Se.ok){const ce=Ae?.error||t("settings.providers.page.toast.oauthStartFailed");throw new Error(ce)}const pe=gi(Ae)?Ae:{},we=gi(pe.data)?pe.data:pe,Ie=typeof we.url=="string"&&we.url||typeof we.verification_uri_complete=="string"&&we.verification_uri_complete||typeof we.verification_uri=="string"&&we.verification_uri||void 0,Y=typeof we.instructions=="string"&&we.instructions||typeof we.message=="string"&&we.message||void 0,re=typeof we.user_code=="string"&&we.user_code||typeof we.code=="string"&&we.code||typeof we.userCode=="string"&&we.userCode||void 0;if(!Ie&&!Y&&!re)throw new Error(t("settings.providers.page.toast.oauthDetailsMissing"));const Pe=`${ie}:${ve}`;I(ce=>({...ce,[Pe]:{url:Ie,instructions:Y,userCode:re}})),Ie&&qn(Ie),C({providerId:ie,methodIndex:ve}),H.message(t("settings.providers.page.toast.completeOAuthInBrowser"))}catch(Se){console.error("Failed to start OAuth flow:",Se),H.error(t("settings.providers.page.toast.oauthStartFailed"))}finally{x(null)}},J=async(ie,ve)=>{const X=`${ie}:${ve}`,Se=k[X]?.trim(),Ae=`oauth-complete:${ie}:${ve}`;x(Ae);try{const pe={method:ve};Se&&(pe.code=Se);const we=await fetch(`/api/provider/${encodeURIComponent(ie)}/oauth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(pe)}),Ie=await we.json().catch(()=>null);if(!we.ok){const Y=Ie?.error||t("settings.providers.page.toast.oauthCompleteFailed");throw new Error(Y)}H.success(t("settings.providers.page.toast.oauthCompleted")),j(Y=>({...Y,[X]:""})),C(null),await ni({scopes:["providers"],mode:"active"}),r(ie)}catch(pe){console.error("Failed to complete OAuth flow:",pe),H.error(t("settings.providers.page.toast.oauthCompleteFailed"))}finally{x(null)}},ne=async ie=>{const ve=await In(ie);if(ve.ok){H.success(t("settings.providers.page.toast.oauthLinkCopied"));return}console.error("Failed to copy OAuth link:",ve.error),H.error(t("settings.providers.page.toast.oauthLinkCopyFailed"))},ee=async ie=>{const ve=await In(ie);if(ve.ok){H.success(t("settings.providers.page.toast.deviceCodeCopied"));return}console.error("Failed to copy device code:",ve.error),H.error(t("settings.providers.page.toast.deviceCodeCopyFailed"))},he=async ie=>{const ve=`disconnect:${ie}`;x(ve);try{const X=await fetch(`/api/provider/${encodeURIComponent(ie)}/auth?scope=all`,{method:"DELETE",headers:{"Content-Type":"application/json"}}),Se=await X.json().catch(()=>null);if(!X.ok){const Ae=Se?.error||t("settings.providers.page.toast.providerDisconnectFailed");throw new Error(Ae)}H.success(t("settings.providers.page.toast.providerDisconnected")),await ni({scopes:["providers"],mode:"active"})}catch(X){console.error("Failed to disconnect provider:",X),H.error(t("settings.providers.page.toast.providerDisconnectFailed"))}finally{x(null)}},ke=n===Fo;if(!ke&&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(ke)return s.jsx(Ns,{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}):Z.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.connect.allProvidersConnected")}):s.jsxs(Ts,{open:B,onOpenChange:ie=>{z(ie),ie||U("")},children:[s.jsx(As,{asChild:!0,children:s.jsxs("button",{type:"button",className:xe("flex items-center justify-between gap-2 rounded-lg border border-input bg-transparent px-2 py-2 typography-ui-label whitespace-nowrap shadow-none outline-none hover:bg-interactive-hover h-6 w-fit"),children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[R?s.jsx(pr,{providerId:R,className:"h-3.5 w-3.5 flex-shrink-0"}):null,s.jsx("span",{className:xe("truncate typography-ui-label font-normal",R?"text-foreground":"text-muted-foreground"),children:R?Z.find(ie=>ie.id===R)?.name||R: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(Ds,{align:"start",className:"w-[280px] p-0",onCloseAutoFocus:ie=>ie.preventDefault(),children:[s.jsxs("div",{className:"flex items-center gap-2 border-b border-[var(--surface-subtle)] px-3 py-2",onKeyDown:ie=>ie.stopPropagation(),children:[s.jsx(D,{name:"search",className:"h-4 w-4 text-muted-foreground"}),s.jsx("input",{type:"text",value:_,onChange:ie=>U(ie.target.value),onKeyDown:ie=>ie.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(Ns,{outerClassName:"max-h-[240px]",className:"p-1",children:(()=>{const ie=Z.filter(ve=>{const X=_.toLowerCase();return(ve.name||ve.id).toLowerCase().includes(X)||ve.id.toLowerCase().includes(X)});return ie.length===0?s.jsx("p",{className:"py-4 text-center typography-meta text-muted-foreground",children:t("settings.providers.page.connect.noProvidersFound")}):ie.map(ve=>s.jsxs($t,{onSelect:()=>{V(ve.id),z(!1),U("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(pr,{providerId:ve.id,className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:ve.name||ve.id})]}),R===ve.id&&s.jsx(D,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},ve.id))})()})]})]})]})})]}),R&&s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h2",{className:"typography-ui-header font-medium text-foreground",children:t("settings.providers.page.auth.title")})}),u?s.jsx("p",{className:"typography-meta text-muted-foreground px-2",children:t("settings.providers.page.auth.loadingMethods")}):s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-4",children:[s.jsxs("div",{className:"py-1.5",children:[s.jsxs("label",{className:"typography-ui-label text-foreground flex items-center gap-1.5",children:[t("settings.providers.page.auth.apiKeyLabel"),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:t("settings.providers.page.auth.apiKeyTooltip")})]})]}),s.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-2 mt-1.5",children:[s.jsx(Bt,{type:"password",value:b[R]??"",onChange:ie=>h(ve=>({...ve,[R]:ie.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(be,{size:"xs",className:"!font-normal shrink-0",onClick:()=>W(R),disabled:v===`api:${R}`,children:v===`api:${R}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}),(()=>{const ve=(p[R]??[]).filter(X=>yp(X)==="oauth");return ve.length===0?null:s.jsx("div",{className:"space-y-4 border-t border-[var(--surface-subtle)] pt-2",children:ve.map((X,Se)=>{const Ae=X.label||X.name||t("settings.providers.page.auth.oauthMethodFallback",{index:String(Se+1)}),pe=`${R}:${Se}`,we=y?.providerId===R&&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:Ae}),(X.description||X.help)&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:String(X.description||X.help)})]}),s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>q(R,Se),disabled:v===`oauth:${R}:${Se}`,children:t("settings.providers.page.actions.connect")})]}),S[pe]?.instructions&&s.jsx("p",{className:"typography-meta text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-2 py-1.5 rounded",children:S[pe]?.instructions}),S[pe]?.userCode&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Bt,{value:S[pe]?.userCode,readOnly:!0,className:"font-mono text-center tracking-widest"}),s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ee(S[pe]?.userCode??""),children:t("settings.providers.page.actions.copyCode")})]}),S[pe]?.url&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Bt,{value:S[pe]?.url,readOnly:!0,className:"text-xs text-muted-foreground"}),s.jsxs("div",{className:"flex gap-1 shrink-0",children:[s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>qn(S[pe]?.url??""),children:t("settings.providers.page.actions.open")}),s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ne(S[pe]?.url??""),children:t("settings.providers.page.actions.copy")})]})]}),we&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Bt,{value:k[pe]??"",onChange:Ie=>j(Y=>({...Y,[pe]:Ie.target.value})),placeholder:t("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs"}),s.jsx(be,{size:"xs",className:"!font-normal",onClick:()=>J(R,Se),disabled:v===`oauth-complete:${R}:${Se}`,children:v===`oauth-complete:${R}:${Se}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.complete")})]})]},`${R}-${Ae}`)})})})()]})]})]})});if(!fe)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 oe=Array.isArray(fe.models)?fe.models:[],me=(p[fe.id]??[]).filter(ie=>yp(ie)==="oauth"),ye=oe.filter(ie=>{const ve=typeof ie?.name=="string"?ie.name:"",X=typeof ie?.id=="string"?ie.id:"",Se=g.trim().toLowerCase();return Se?ve.toLowerCase().includes(Se)||X.toLowerCase().includes(Se):!0});return s.jsx(Ns,{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(pr,{providerId:fe.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:fe.name||fe.id}),s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:s.jsx("span",{className:"font-mono",children:fe.id})})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 px-1 flex items-center justify-between gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.providers.page.auth.title")}),s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Q(ie=>!ie),children:t(G?"settings.providers.page.actions.hide":"settings.providers.page.actions.reconnect")})]}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:G?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(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:t("settings.providers.page.auth.apiKeyTooltip")})]})]}),s.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-2 mt-1.5",children:[s.jsx(Bt,{type:"password",value:b[fe.id]??"",onChange:ie=>h(ve=>({...ve,[fe.id]:ie.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(be,{size:"xs",className:"!font-normal shrink-0",onClick:()=>W(fe.id),disabled:v===`api:${fe.id}`,children:v===`api:${fe.id}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}),me.length>0&&s.jsx("div",{className:"space-y-4 border-t border-[var(--surface-subtle)] pt-2",children:me.map((ie,ve)=>{const X=ie.label||ie.name||t("settings.providers.page.auth.oauthMethodFallback",{index:String(ve+1)}),Se=`${fe.id}:${ve}`,Ae=y?.providerId===fe.id&&y?.methodIndex===ve;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:X}),(ie.description||ie.help)&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:String(ie.description||ie.help)})]}),s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>q(fe.id,ve),disabled:v===`oauth:${fe.id}:${ve}`,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(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ee(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(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>qn(S[Se]?.url??""),children:t("settings.providers.page.actions.open")}),s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ne(S[Se]?.url??""),children:t("settings.providers.page.actions.copy")})]})]}),Ae&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Bt,{value:k[Se]??"",onChange:pe=>j(we=>({...we,[Se]:pe.target.value})),placeholder:t("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs"}),s.jsx(be,{size:"xs",className:"!font-normal",onClick:()=>J(fe.id,ve),disabled:v===`oauth-complete:${fe.id}:${ve}`,children:v===`oauth-complete:${fe.id}:${ve}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.complete")})]})]},`${fe.id}-${X}`)})})]}):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:ue&&(ue.auth.exists||ue.user.exists||ue.project.exists||ue.custom?.exists)?s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[t("settings.providers.page.connectionDetails.configuredIn")," ",[ue.auth.exists?t("settings.providers.page.connectionDetails.source.authCredentials"):null,ue.user.exists?t("settings.providers.page.connectionDetails.source.userConfig"):null,ue.project.exists?t("settings.providers.page.connectionDetails.source.projectConfig"):null,ue.custom?.exists?t("settings.providers.page.connectionDetails.source.customConfig"):null].filter(Boolean).join(", ")]}):s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.connectionDetails.noActiveSource")})}),s.jsx(be,{variant:"ghost",size:"xs",className:"!font-normal text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>he(fe.id),disabled:v===`disconnect:${fe.id}`,children:v===`disconnect:${fe.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"),oe.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",oe.length,")"]})]}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const ie=oe.map(ve=>typeof ve?.id=="string"?ve.id:"").filter(ve=>ve.length>0);c(fe.id,ie)},children:t("settings.providers.page.actions.hideAll")}),s.jsx(be,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>d(fe.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:g,onChange:ie=>w(ie.target.value),placeholder:t("settings.providers.page.models.filterPlaceholder"),className:"h-7 pl-8 w-full"})]}),ye.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:ye.map(ie=>{const ve=typeof ie?.id=="string"?ie.id:"",X=typeof ie?.name=="string"?ie.name:ve,Se=ve?a(fe.id,ve):void 0,Ae=i.some(Y=>Y.providerID===fe.id&&Y.modelID===ve),pe=bp(Se?.limit?.context),we=bp(Se?.limit?.output),Ie=[];return Se?.tool_call&&Ie.push({key:"tools",icon:"tools",label:t("settings.providers.page.models.capability.toolCalling")}),Se?.reasoning&&Ie.push({key:"reasoning",icon:"brain-ai-3",label:t("settings.providers.page.models.capability.reasoning")}),Se?.attachment&&Ie.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:xe("flex items-center gap-3",Ae&&"opacity-50"),children:[s.jsx("span",{className:"typography-meta font-medium text-foreground truncate flex-1 min-w-0",children:X}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[(pe||we)&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex-shrink-0 bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:[pe?`${pe} ${t("settings.providers.page.models.tokenBadge.context")}`:"",pe&&we?" · ":"",we?`${we} ${t("settings.providers.page.models.tokenBadge.output")}`:""]}),Ie.length>0&&s.jsx("div",{className:"flex items-center gap-1 flex-shrink-0",children:Ie.map(({key:Y,icon:re,label:Pe})=>s.jsx("span",{className:"flex h-5 w-5 rounded items-center justify-center text-muted-foreground bg-[var(--surface-muted)]",title:Pe,"aria-label":Pe,children:s.jsx(D,{name:re,className:"h-3 w-3"})},Y))}),s.jsx("button",{type:"button",onClick:()=>o(fe.id,ve),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(Ae?"settings.providers.page.models.actions.showModelInSelectors":"settings.providers.page.models.actions.hideModelFromSelectors"),"aria-label":t(Ae?"settings.providers.page.models.actions.showModel":"settings.providers.page.models.actions.hideModel"),children:Ae?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"})})]})]})},ve)})})]})]})]})})},l5=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)},c5=t=>{const e=st.c(106),{onItemSelect:n}=t,{t:r}=dt(),a=Os(d5),i=Os(u5),o=Os(m5),c=Os(p5),d=Os(f5),p=Os(h5),m=Os(g5),u=Os(x5),f=Os(b5),b=Os(y5),h=Os(v5),v=Os(w5);let x,g;e[0]!==v?(x=()=>{v()},g=[v],e[0]=v,e[1]=x,e[2]=g):(x=e[1],g=e[2]),l.useEffect(x,g);const w=j5;let y;e[3]!==f?(y=re=>{f(re),w({usageAutoRefresh:re})},e[3]=f,e[4]=y):y=e[4];const C=y;let k;e[5]!==b?(k=re=>{const Pe=Number(re);Number.isFinite(Pe)&&(b(Pe),w({usageRefreshIntervalMs:Pe}))},e[5]=b,e[6]=k):k=e[6];const j=k;let S;e[7]!==h?(S=re=>{re!=="usage"&&re!=="remaining"||(h(re),w({usageDisplayMode:re}))},e[7]=h,e[8]=S):S=e[8];const I=S;let M;e[9]===Symbol.for("react.memo_cache_sentinel")?(M=xe("flex h-full flex-col","bg-background"),e[9]=M):M=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:Br.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 T;e[18]!==r?(T=r("settings.usage.sidebar.actions.toggleAutoRefreshAria"),e[18]=r,e[19]=T):T=e[19];let R;e[20]!==C||e[21]!==T||e[22]!==p?(R=s.jsx(It,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(fs,{checked:p,onChange:C,ariaLabel:T})})}),e[20]=C,e[21]=T,e[22]=p,e[23]=R):R=e[23];let V;e[24]!==r?(V=r("settings.usage.sidebar.tooltip.autoRefresh"),e[24]=r,e[25]=V):V=e[25];let _;e[26]!==V?(_=s.jsx(At,{side:"bottom",children:V}),e[26]=V,e[27]=_):_=e[27];let U;e[28]!==R||e[29]!==_?(U=s.jsxs(Ct,{children:[R,_]}),e[28]=R,e[29]=_,e[30]=U):U=e[30];const B=String(m),z=!p;let K;e[31]!==r?(K=r("settings.usage.sidebar.field.intervalPlaceholder"),e[31]=r,e[32]=K):K=e[32];let F;e[33]!==K?(F=s.jsx(ls,{className:"w-fit",children:s.jsx(us,{placeholder:K})}),e[33]=K,e[34]=F):F=e[34];let G;e[35]===Symbol.for("react.memo_cache_sentinel")?(G=s.jsxs(cs,{children:[s.jsx(Tt,{value:"30000",children:"30s"}),s.jsx(Tt,{value:"60000",children:"1m"}),s.jsx(Tt,{value:"300000",children:"5m"})]}),e[35]=G):G=e[35];let Q;e[36]!==j||e[37]!==B||e[38]!==z||e[39]!==F?(Q=s.jsxs(os,{value:B,onValueChange:j,disabled:z,children:[F,G]}),e[36]=j,e[37]=B,e[38]=z,e[39]=F,e[40]=Q):Q=e[40];let te;e[41]!==c?(te=()=>c(),e[41]=c,e[42]=te):te=e[42];let Z;e[43]!==r?(Z=r("settings.usage.sidebar.actions.refreshAria"),e[43]=r,e[44]=Z):Z=e[44];let fe;e[45]!==r?(fe=r("settings.usage.sidebar.actions.refreshTitle"),e[45]=r,e[46]=fe):fe=e[46];const ue=d&&"animate-spin";let W;e[47]!==ue?(W=xe("h-3.5 w-3.5",ue),e[47]=ue,e[48]=W):W=e[48];let q;e[49]!==W?(q=s.jsx(D,{name:"refresh",className:W}),e[49]=W,e[50]=q):q=e[50];let J;e[51]!==d||e[52]!==te||e[53]!==Z||e[54]!==fe||e[55]!==q?(J=s.jsx(be,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 text-muted-foreground",onClick:te,"aria-label":Z,title:fe,disabled:d,children:q}),e[51]=d,e[52]=te,e[53]=Z,e[54]=fe,e[55]=q,e[56]=J):J=e[56];let ne;e[57]!==U||e[58]!==Q||e[59]!==J?(ne=s.jsxs("div",{className:"flex items-center gap-2",children:[U,Q,J]}),e[57]=U,e[58]=Q,e[59]=J,e[60]=ne):ne=e[60];let ee;e[61]!==E||e[62]!==ne?(ee=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[E,ne]}),e[61]=E,e[62]=ne,e[63]=ee):ee=e[63];let he;e[64]!==r?(he=r("settings.usage.sidebar.field.display"),e[64]=r,e[65]=he):he=e[65];let ke;e[66]!==he?(ke=s.jsx("span",{className:"typography-micro text-muted-foreground",children:he}),e[66]=he,e[67]=ke):ke=e[67];let oe;e[68]!==r?(oe=r("settings.usage.sidebar.field.displayModePlaceholder"),e[68]=r,e[69]=oe):oe=e[69];let ge;e[70]!==oe?(ge=s.jsx(ls,{className:"w-fit",children:s.jsx(us,{placeholder:oe})}),e[70]=oe,e[71]=ge):ge=e[71];let me;e[72]!==r?(me=r("settings.usage.sidebar.field.displayModeUsage"),e[72]=r,e[73]=me):me=e[73];let ye;e[74]!==me?(ye=s.jsx(Tt,{value:"usage",children:me}),e[74]=me,e[75]=ye):ye=e[75];let ie;e[76]!==r?(ie=r("settings.usage.sidebar.field.displayModeRemaining"),e[76]=r,e[77]=ie):ie=e[77];let ve;e[78]!==ie?(ve=s.jsx(Tt,{value:"remaining",children:ie}),e[78]=ie,e[79]=ve):ve=e[79];let X;e[80]!==ye||e[81]!==ve?(X=s.jsxs(cs,{children:[ye,ve]}),e[80]=ye,e[81]=ve,e[82]=X):X=e[82];let Se;e[83]!==I||e[84]!==ge||e[85]!==X||e[86]!==u?(Se=s.jsxs(os,{value:u,onValueChange:I,children:[ge,X]}),e[83]=I,e[84]=ge,e[85]=X,e[86]=u,e[87]=Se):Se=e[87];let Ae;e[88]!==ke||e[89]!==Se?(Ae=s.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[ke,Se]}),e[88]=ke,e[89]=Se,e[90]=Ae):Ae=e[90];let pe;e[91]!==ee||e[92]!==Ae||e[93]!==A?(pe=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[A,ee,Ae]}),e[91]=ee,e[92]=Ae,e[93]=A,e[94]=pe):pe=e[94];let we;e[95]!==n||e[96]!==a||e[97]!==i||e[98]!==o||e[99]!==r?(we=Br.map(re=>{const Pe=a.find(de=>de.providerId===re.id),ce=l5(Pe?.usage),Ce=yh(ce),Te=re.id===i,$e=Pe?.configured??!1,De=$e?Ce==="critical"?{backgroundColor:"var(--status-error)"}:Ce==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"}:{backgroundColor:"var(--surface-muted-foreground)",opacity:.4};return s.jsx("div",{className:xe("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:()=>{o(re.id),n?.()},className:"flex min-w-0 flex-1 items-center gap-2 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[s.jsx("span",{className:"h-2.5 w-2.5 rounded-full flex-shrink-0",style:De}),s.jsx(pr,{providerId:re.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:re.name}),!$e&&s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:r("settings.usage.sidebar.status.notSet")})]})},re.id)}),e[95]=n,e[96]=a,e[97]=i,e[98]=o,e[99]=r,e[100]=we):we=e[100];let Ie;e[101]!==we?(Ie=s.jsx(Ns,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:we}),e[101]=we,e[102]=Ie):Ie=e[102];let Y;return e[103]!==pe||e[104]!==Ie?(Y=s.jsxs("div",{className:M,children:[pe,Ie]}),e[103]=pe,e[104]=Ie,e[105]=Y):Y=e[105],Y};function d5(t){return t.results}function u5(t){return t.selectedProviderId}function m5(t){return t.setSelectedProvider}function p5(t){return t.fetchAllQuotas}function f5(t){return t.isLoading}function h5(t){return t.autoRefresh}function g5(t){return t.refreshIntervalMs}function x5(t){return t.displayMode}function b5(t){return t.setAutoRefresh}function y5(t){return t.setRefreshInterval}function v5(t){return t.setDisplayMode}function w5(t){return t.loadSettings}async function j5(t){try{await Is(t)}catch(e){console.warn("Failed to save usage settings:",e)}}const Cc=t=>{const e=st.c(52),{title:n,window:r,subtitle:a,showToggle:i,toggleEnabled:o,onToggle:c}=t,d=i===void 0?!1:i,p=o===void 0?!1:o,m=Os(N5),u=m==="remaining"?r.remainingPercent:r.usedPercent,f=m==="remaining"?"remaining":"used";let b;e[0]!==u||e[1]!==r.valueLabel?(b=so(r.valueLabel,u),e[0]=u,e[1]=r.valueLabel,e[2]=b):b=e[2];const h=b,v=r.resetAfterFormatted??r.resetAtFormatted;let x;e[3]!==v||e[4]!==r.resetAt?(x=Vd(r.resetAt,v),e[3]=v,e[4]=r.resetAt,e[5]=x):x=e[5];const g=x;let w;e[6]!==n?(w=Ud(n),e[6]=n,e[7]=w):w=e[7];const y=w;let C;e[8]!==n||e[9]!==r.resetAt||e[10]!==r.usedPercent||e[11]!==r.windowSeconds?(C=no(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 j;e:{if(!k||k.dailyAllocationPercent===null){j=null;break e}const Q=Jr(k.elapsedRatio);j=m==="remaining"?100-Q:Q}const S=j;let I;e[13]!==c||e[14]!==d||e[15]!==p?(I=d&&s.jsx(fs,{checked:p,onChange:Q=>c?.(Q),ariaLabel:"Show in dropdown"}),e[13]=c,e[14]=d,e[15]=p,e[16]=I):I=e[16];let M;e[17]!==y?(M=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:y}),e[17]=y,e[18]=M):M=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]!==M||e[22]!==P?(A=s.jsxs("div",{className:"min-w-0 flex flex-col",children:[M,P]}),e[21]=M,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=h==="-"?"":h;let T;e[27]!==E?(T=s.jsx("div",{className:"typography-ui-label text-foreground tabular-nums flex items-center justify-end",children:E}),e[27]=E,e[28]=T):T=e[28];let R;e[29]!==N||e[30]!==T?(R=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[N,T]}),e[29]=N,e[30]=T,e[31]=R):R=e[31];let V;e[32]!==u||e[33]!==S||e[34]!==r.usedPercent?(V=s.jsx(ao,{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 _=g?`Resets ${g}`:"";let U;e[36]!==_?(U=s.jsx("span",{className:"typography-micro text-muted-foreground",children:_}),e[36]=_,e[37]=U):U=e[37];let B;e[38]!==f?(B=s.jsx("span",{className:"typography-micro text-muted-foreground",children:f}),e[38]=f,e[39]=B):B=e[39];let z;e[40]!==U||e[41]!==B?(z=s.jsxs("div",{className:"mt-1 flex items-center justify-between",children:[U,B]}),e[40]=U,e[41]=B,e[42]=z):z=e[42];let K;e[43]!==V||e[44]!==z?(K=s.jsxs("div",{className:"mt-2.5",children:[V,z]}),e[43]=V,e[44]=z,e[45]=K):K=e[45];let F;e[46]!==k?(F=k&&s.jsx("div",{className:"mt-1.5",children:s.jsx(io,{paceInfo:k})}),e[46]=k,e[47]=F):F=e[47];let G;return e[48]!==R||e[49]!==K||e[50]!==F?(G=s.jsxs("div",{className:"py-3",children:[R,K,F]}),e[48]=R,e[49]=K,e[50]=F,e[51]=G):G=e[51],G};function N5(t){return t.displayMode}const S5=t=>{if(!t)return"-";try{return new Date(t).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"})}catch{return"-"}},k5=()=>{const{t}=dt(),e=Os(N=>N.results),n=Os(N=>N.selectedProviderId),r=Os(N=>N.setSelectedProvider),a=Os(N=>N.loadSettings),i=Os(N=>N.fetchAllQuotas),o=Os(N=>N.isLoading),c=Os(N=>N.lastUpdated),d=Os(N=>N.error),p=Os(N=>N.dropdownProviderIds),m=Os(N=>N.setDropdownProviderIds),u=Os(N=>N.selectedModels),f=Os(N=>N.toggleModelSelected),b=Os(N=>N.applyDefaultSelections);Sh(),l.useEffect(()=>{a(),i()},[a,i]),l.useEffect(()=>{if(n||e.length===0)return;const N=e.find(E=>E.configured)?.providerId;r(N??Br[0]?.id??null)},[e,n,r]);const h=e.find(N=>N.providerId===n)??null,x=Br.find(N=>N.id===n)?.name??n??t("settings.usage.sidebar.title"),g=h?.usage,w=n?p.includes(n):!1,y=l.useCallback(N=>{if(!n)return;const E=N?Array.from(new Set([...p,n])):p.filter(T=>T!==n);m(E),Is({usageDropdownProviders:E})},[p,n,m]),C=l.useMemo(()=>g?.models?Object.entries(g.models).map(([N,E])=>({name:N,windows:E})).filter(N=>Object.keys(N.windows.windows).length>0):[],[g?.models]);l.useEffect(()=>{n&&C.length>0&&b(n,C.map(N=>N.name))},[n,C,b]);const k=l.useMemo(()=>!n||C.length===0?new Map:Vv(C,N=>N.name,n),[C,n]),j=l.useMemo(()=>{if(!n)return[];const N=jh(n);return Nh(N)},[n]),[S,I]=l.useState(()=>({})),M=l.useCallback(N=>{I(E=>({...E,[N]:!E[N]}))},[]),P=l.useCallback(N=>{if(!n)return;f(n,N);const E=u[n]??[],R=E.includes(N)?E.filter(_=>_!==N):[...E,N],V={...u,[n]:R};Is({usageSelectedModels:V})},[n,u,f]),A=n?u[n]??[]:[];return n?s.jsx(Ns,{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(pr,{providerId:n,className:"h-5 w-5 shrink-0"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:t("settings.usage.page.header.providerUsage",{provider:x})}),s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:o?s.jsx("span",{className:"animate-pulse",children:t("settings.usage.page.header.refreshing")}):t("settings.usage.page.header.lastUpdated",{time:S5(c)})})]})]}),s.jsx("div",{className:"mb-8 px-2",children:s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":w,onClick:()=>y(!w),onKeyDown:N=>{(N.key===" "||N.key==="Enter")&&(N.preventDefault(),y(!w))},children:[s.jsx(fs,{checked:w,onChange:y,ariaLabel:t("settings.usage.page.options.showInHeaderAria")}),s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.usage.page.options.showInHeader")}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:t("settings.usage.page.options.showInHeaderTooltip")})]})]})]})}),!h&&s.jsx("div",{className:"mb-8 px-2",children:s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.usage.page.state.noData")})}),d&&s.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-4 py-3",children:[s.jsx("p",{className:"typography-ui-label font-medium text-[var(--status-error)]",children:t("settings.usage.page.state.refreshFailedTitle")}),s.jsx("p",{className:"typography-meta text-[var(--status-error)]/80 mt-1",children:d})]}),h&&!h.configured&&s.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] px-4 py-3",children:[s.jsx("p",{className:"typography-ui-label font-medium text-[var(--status-warning)]",children:t("settings.usage.page.state.providerNotConfiguredTitle")}),s.jsx("p",{className:"typography-meta text-[var(--status-warning)]/80 mt-1",children:t("settings.usage.page.state.providerNotConfiguredDescription")})]}),g?.windows&&Object.keys(g.windows).length>0&&s.jsx("div",{className:"mb-8",children:s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:Object.entries(g.windows).map(([N,E])=>s.jsx(Cc,{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:[j.map(N=>{const E=k.get(N.id)??[];if(E.length===0)return null;const T=S[N.id]??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(fr,{open:!T,onOpenChange:()=>M(N.id),children:[s.jsxs(kr,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:N.label}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",E.length,")"]})]}),T?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(hr,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:E.map(R=>{const V=Object.entries(R.windows.windows);if(V.length===0)return null;const[_,U]=V[0],B=A.includes(R.name);return s.jsx(Cc,{title:_,subtitle:ul(R.name),window:U,showToggle:!0,toggleEnabled:B,onToggle:()=>P(R.name)},R.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(fr,{open:!E,onOpenChange:()=>M("other"),children:[s.jsxs(kr,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:t("settings.usage.page.section.otherModels")}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",N.length,")"]})]}),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(hr,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:N.map(T=>{const R=Object.entries(T.windows.windows);if(R.length===0)return null;const[V,_]=R[0],U=A.includes(T.name);return s.jsx(Cc,{title:V,subtitle:ul(T.name),window:_,showToggle:!0,toggleEnabled:U,onToggle:()=>P(T.name)},T.name)})})})]})})})()]})]}),h?.configured&&g&&Object.keys(g.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")})})},C5="git.commit.generate",xd=Zn(t=>({selectedPromptId:C5,setSelectedPromptId:e=>{t(n=>n.selectedPromptId===e?n:{selectedPromptId:e})}})),I5=t=>{const e=st.c(23),{onItemSelect:n}=t,{t:r}=dt(),a=xd(P5),i=xd(A5);let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o={groupKey:"settings.magicPrompts.sidebar.group.git",items:[{id:"git.commit.generate",titleKey:"settings.magicPrompts.sidebar.item.gitCommitGenerate"},{id:"git.pr.generate",titleKey:"settings.magicPrompts.sidebar.item.gitPrGenerate"},{id:"git.conflict.resolve",titleKey:"settings.magicPrompts.sidebar.item.gitConflictResolve"},{id:"git.integrate.cherrypick.resolve",titleKey:"settings.magicPrompts.sidebar.item.gitCherrypickConflictResolve"}]},e[0]=o):o=e[0];let c;e[1]===Symbol.for("react.memo_cache_sentinel")?(c={groupKey:"settings.magicPrompts.sidebar.group.github",items:[{id:"github.pr.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrReview"},{id:"github.issue.review",titleKey:"settings.magicPrompts.sidebar.item.githubIssueReview"},{id:"github.pr.checks.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrFailedChecksReview"},{id:"github.pr.comments.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrCommentsReview"},{id:"github.pr.comment.single",titleKey:"settings.magicPrompts.sidebar.item.githubSinglePrCommentReview"}]},e[1]=c):c=e[1];let d;e[2]===Symbol.for("react.memo_cache_sentinel")?(d={groupKey:"settings.magicPrompts.sidebar.group.planning",items:[{id:"plan.todo",titleKey:"settings.magicPrompts.sidebar.item.planTodo"},{id:"plan.improve",titleKey:"settings.magicPrompts.sidebar.item.planImprove"},{id:"plan.implement",titleKey:"settings.magicPrompts.sidebar.item.planImplement"}]},e[2]=d):d=e[2];let p;e[3]===Symbol.for("react.memo_cache_sentinel")?(p=[o,c,d,{groupKey:"settings.magicPrompts.sidebar.group.session",items:[{id:"session.summary",titleKey:"settings.magicPrompts.sidebar.item.sessionSummary"},{id:"session.review",titleKey:"settings.magicPrompts.sidebar.item.sessionWorkspaceReview"},{id:"session.fusion",titleKey:"settings.magicPrompts.sidebar.item.sessionFusion"}]}],e[3]=p):p=e[3];const m=p;let u;e[4]!==r?(u=r("settings.magicPrompts.sidebar.title"),e[4]=r,e[5]=u):u=e[5];let f;e[6]!==u?(f=s.jsx("h2",{className:"text-base font-semibold text-foreground",children:u}),e[6]=u,e[7]=f):f=e[7];let b;e[8]!==r?(b=r("settings.magicPrompts.sidebar.description"),e[8]=r,e[9]=b):b=e[9];let h;e[10]!==b?(h=s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:b}),e[10]=b,e[11]=h):h=e[11];let v;e[12]!==f||e[13]!==h?(v=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[f,h]}),e[12]=f,e[13]=h,e[14]=v):v=e[14];let x;e[15]!==n||e[16]!==a||e[17]!==i||e[18]!==r?(x=s.jsx(Ns,{outerClassName:"flex-1 min-h-0",className:"space-y-3 px-3 py-2 overflow-x-hidden",children:m.map(w=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro px-1 text-muted-foreground",children:r(w.groupKey)}),w.items.map(y=>{const C=a===y.id;return s.jsx("button",{type:"button",onClick:()=>{i(y.id),n?.()},className:xe("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)})]},w.groupKey))}),e[15]=n,e[16]=a,e[17]=i,e[18]=r,e[19]=x):x=e[19];let g;return e[20]!==x||e[21]!==v?(g=s.jsxs("div",{className:"flex h-full flex-col bg-background",children:[v,x]}),e[20]=x,e[21]=v,e[22]=g):g=e[22],g};function P5(t){return t.selectedPromptId}function A5(t){return t.setSelectedPromptId}const vp={"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"}]}},wp=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),jp=t=>t.endsWith(".visible"),D5=()=>{const{t}=dt(),e=l.useCallback(j=>t(j),[t]),n=xd(j=>j.selectedPromptId),[r,a]=l.useState(!0),[i,o]=l.useState({}),[c,d]=l.useState({}),[p,m]=l.useState({}),[u,f]=l.useState({}),[b,h]=l.useState(!1);l.useEffect(()=>{let j=!0;return(async()=>{a(!0);try{const I=await Kb();if(!j)return;o(I)}catch(I){console.warn("Failed to load magic prompts:",I),H.error(t("settings.magicPrompts.page.toast.loadFailed"))}finally{j&&a(!1)}})(),()=>{j=!1}},[t]);const v=vp[n]??vp["git.commit.generate"],x=l.useCallback(j=>wp(i,j)?i[j]:Jl(j),[i]),g=l.useCallback(j=>c[j]??x(j),[c,x]),w=l.useCallback((j,S)=>{d(I=>I[j]===S?I:{...I,[j]:S})},[]),y=l.useCallback(async j=>{const S=g(j);if(jp(j)&&S.trim().length===0){H.error(t("settings.magicPrompts.page.toast.visiblePromptRequired"));return}m(I=>({...I,[j]:!0}));try{const I=S===Jl(j)?await Nu(j):await Vb(j,S);o(I.overrides),H.success(t("settings.magicPrompts.page.toast.saved"))}catch(I){const M=I instanceof Error?I.message:String(I);H.error(t("settings.magicPrompts.page.toast.saveFailed"),{description:M})}finally{m(I=>({...I,[j]:!1}))}},[g,t]),C=l.useCallback(async j=>{f(S=>({...S,[j]:!0}));try{const S=await Nu(j);o(S.overrides),d(I=>({...I,[j]:Jl(j)})),H.success(t("settings.magicPrompts.page.toast.resetSuccess"))}catch(S){const I=S instanceof Error?S.message:String(S);H.error(t("settings.magicPrompts.page.toast.resetFailed"),{description:I})}finally{f(S=>({...S,[j]:!1}))}},[t]),k=l.useCallback(async()=>{h(!0);try{const j=await Ub();o(j.overrides),d({}),H.success(t("settings.magicPrompts.page.toast.resetAllSuccess"))}catch(j){const S=j instanceof Error?j.message:String(j);H.error(t("settings.magicPrompts.page.toast.resetAllFailed"),{description:S})}finally{h(!1)}},[t]);return r?s.jsxs("div",{className:"py-6 px-6 flex items-center gap-2 text-muted-foreground",children:[s.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-current animate-busy-pulse","aria-label":t("settings.magicPrompts.page.loading.aria")}),s.jsx("span",{className:"typography-ui",children:t("settings.magicPrompts.page.loading.text")})]}):s.jsx("div",{className:"h-full overflow-auto",children:s.jsxs("div",{className:"mx-auto w-full max-w-4xl px-6 py-6 space-y-4",children:[s.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[s.jsx("div",{className:"space-y-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground",children:e(v.titleKey)}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:e(v.descriptionKey)})]})]})}),s.jsx(be,{variant:"outline",size:"sm",onClick:()=>{k()},disabled:b||Object.keys(i).length===0,children:t(b?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetAllOverrides")})]}),v.blocks.map((j,S)=>{const I=Wb(j.id),M=x(j.id),P=g(j.id),A=wp(i,j.id),N=P!==M,E=jp(j.id)&&P.trim().length===0,T=p[j.id]===!0,R=u[j.id]===!0;return s.jsxs("section",{className:S>0?"space-y-3 pt-5 border-t border-border":"space-y-3",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-label text-foreground",children:e(j.titleKey)}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:I.description})]})]}),I.placeholders&&I.placeholders.length>0&&s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[t("settings.magicPrompts.page.placeholdersLabel")," ",I.placeholders.map(V=>`{{${V.key}}}`).join(", ")]})]}),s.jsx(un,{value:P,onChange:V=>w(j.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(be,{variant:"outline",size:"sm",onClick:()=>{C(j.id)},disabled:!A||T||R,children:t(R?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetToDefault")}),s.jsx(be,{size:"sm",onClick:()=>{y(j.id)},disabled:!N||T||R||E,children:t(T?"settings.common.actions.saving":"settings.magicPrompts.page.actions.save")})]})]})]},j.id)})]})})},T5=t=>{const e=st.c(87),{onItemSelect:n}=t,{t:r}=dt(),[a,i]=l.useState(null),[o,c]=l.useState(null),{selectedSnippetName:d,snippets:p,setSelectedSnippet:m,setSnippetDraft:u,deleteSnippet:f,loadSnippets:b}=Fl(Jn(M5));let h,v;e[0]!==b?(h=()=>{b()},v=[b],e[0]=b,e[1]=h,e[2]=v):(h=e[1],v=e[2]),l.useEffect(h,v);let x;e[3]!==n||e[4]!==m||e[5]!==u||e[6]!==p?(x=async()=>{const ke=new Set(p.map(E5));let oe="new-snippet",ge=1;for(;ke.has(oe);)oe=`new-snippet-${ge++}`;u({name:oe,scope:"global"}),m(oe),n?.()},e[3]=n,e[4]=m,e[5]=u,e[6]=p,e[7]=x):x=e[7];const g=x;let w;e[8]!==a||e[9]!==f||e[10]!==r?(w=async()=>{if(!a)return;await f(a.name)?(H.success(r("settings.snippets.sidebar.toast.deleted")),i(null)):H.error(r("settings.snippets.sidebar.toast.deleteFailed"))},e[8]=a,e[9]=f,e[10]=r,e[11]=w):w=e[11];const y=w;let C;e[12]!==p?(C=[...p].sort(R5),e[12]=p,e[13]=C):C=e[13];const k=C;let j;e[14]===Symbol.for("react.memo_cache_sentinel")?(j=xe("flex h-full flex-col","bg-background"),e[14]=j):j=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 M;e[19]!==p.length||e[20]!==r?(M=r("settings.snippets.sidebar.total",{count:p.length}),e[19]=p.length,e[20]=r,e[21]=M):M=e[21];let P;e[22]!==M?(P=s.jsx("span",{className:"typography-meta text-muted-foreground",children:M}),e[22]=M,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]!==g||e[28]!==A?(E=s.jsx(be,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:g,"aria-label":A,children:N}),e[27]=g,e[28]=A,e[29]=E):E=e[29];let T;e[30]!==P||e[31]!==E?(T=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[P,E]}),e[30]=P,e[31]=E,e[32]=T):T=e[32];let R;e[33]!==T||e[34]!==I?(R=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[I,T]}),e[33]=T,e[34]=I,e[35]=R):R=e[35];let V;if(e[36]!==n||e[37]!==o||e[38]!==d||e[39]!==m||e[40]!==k||e[41]!==r){let ke;e[43]!==n||e[44]!==o||e[45]!==d||e[46]!==m||e[47]!==r?(ke=oe=>s.jsxs("div",{className:xe("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",d===oe.name?"bg-interactive-selection":"hover:bg-interactive-hover"),children:[s.jsxs("button",{onClick:()=>{m(oe.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:["#",oe.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.${oe.source}`)})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:oe.description||oe.content.replace(/\s+/g," ").substring(0,80)})]}),s.jsxs(Ts,{open:o===oe.name,onOpenChange:ge=>c(ge?oe.name:null),children:[s.jsx(As,{asChild:!0,children:s.jsx(be,{size:"sm",variant:"ghost",className:"h-6 w-6 px-0 flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100","aria-label":r("settings.snippets.sidebar.actions.more",{name:oe.name}),children:s.jsx(D,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Ds,{align:"end",className:"w-fit min-w-20",children:s.jsxs($t,{onClick:ge=>{ge.stopPropagation(),i(oe)},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")]})})]})]},`${oe.source}:${oe.filePath}`),e[43]=n,e[44]=o,e[45]=d,e[46]=m,e[47]=r,e[48]=ke):ke=e[48],V=k.map(ke),e[36]=n,e[37]=o,e[38]=d,e[39]=m,e[40]=k,e[41]=r,e[42]=V}else V=e[42];let _;e[49]!==V?(_=s.jsx(Ns,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2",children:V}),e[49]=V,e[50]=_):_=e[50];const U=a!==null;let B;e[51]===Symbol.for("react.memo_cache_sentinel")?(B=ke=>{ke||i(null)},e[51]=B):B=e[51];let z;e[52]!==r?(z=r("settings.snippets.sidebar.dialog.deleteTitle"),e[52]=r,e[53]=z):z=e[53];let K;e[54]!==z?(K=s.jsx(hs,{children:z}),e[54]=z,e[55]=K):K=e[55];const F=a?.name??"";let G;e[56]!==r||e[57]!==F?(G=r("settings.snippets.sidebar.dialog.deleteDescription",{name:F}),e[56]=r,e[57]=F,e[58]=G):G=e[58];let Q;e[59]!==G?(Q=s.jsx(Ss,{children:G}),e[59]=G,e[60]=Q):Q=e[60];let te;e[61]!==K||e[62]!==Q?(te=s.jsxs(ys,{children:[K,Q]}),e[61]=K,e[62]=Q,e[63]=te):te=e[63];let Z;e[64]===Symbol.for("react.memo_cache_sentinel")?(Z=()=>i(null),e[64]=Z):Z=e[64];let fe;e[65]!==r?(fe=r("settings.common.actions.cancel"),e[65]=r,e[66]=fe):fe=e[66];let ue;e[67]!==fe?(ue=s.jsx(be,{size:"sm",variant:"ghost",onClick:Z,children:fe}),e[67]=fe,e[68]=ue):ue=e[68];let W;e[69]!==r?(W=r("settings.common.actions.delete"),e[69]=r,e[70]=W):W=e[70];let q;e[71]!==y||e[72]!==W?(q=s.jsx(be,{size:"sm",onClick:y,children:W}),e[71]=y,e[72]=W,e[73]=q):q=e[73];let J;e[74]!==ue||e[75]!==q?(J=s.jsxs(Vs,{children:[ue,q]}),e[74]=ue,e[75]=q,e[76]=J):J=e[76];let ne;e[77]!==te||e[78]!==J?(ne=s.jsxs(ms,{className:"max-w-md",children:[te,J]}),e[77]=te,e[78]=J,e[79]=ne):ne=e[79];let ee;e[80]!==U||e[81]!==ne?(ee=s.jsx(ps,{open:U,onOpenChange:B,children:ne}),e[80]=U,e[81]=ne,e[82]=ee):ee=e[82];let he;return e[83]!==R||e[84]!==_||e[85]!==ee?(he=s.jsxs("div",{className:j,children:[R,_,ee]}),e[83]=R,e[84]=_,e[85]=ee,e[86]=he):he=e[86],he};function M5(t){return{selectedSnippetName:t.selectedSnippetName,snippets:t.snippets,setSelectedSnippet:t.setSelectedSnippet,setSnippetDraft:t.setSnippetDraft,deleteSnippet:t.deleteSnippet,loadSnippets:t.loadSnippets}}function E5(t){return t.name}function R5(t,e){return t.name.localeCompare(e.name)}const F5=()=>{const{t}=dt(),{selectedSnippetName:e,snippets:n,snippetDraft:r,setSnippetDraft:a,updateSnippet:i,createSnippet:o}=Fl(Jn(I=>({selectedSnippetName:I.selectedSnippetName,snippets:I.snippets,snippetDraft:I.snippetDraft,setSnippetDraft:I.setSnippetDraft,updateSnippet:I.updateSnippet,createSnippet:I.createSnippet}))),c=l.useMemo(()=>e?n.find(I=>I.name===e||I.aliases.includes(e))??null:null,[e,n]),d=!!(r&&r.name===e&&!c),[p,m]=l.useState(""),[u,f]=l.useState("global"),[b,h]=l.useState(""),[v,x]=l.useState(""),[g,w]=l.useState(""),[y,C]=l.useState(!1),k=l.useRef(null);l.useEffect(()=>{if(d&&r){const I={draftName:r.name||"",draftScope:r.scope||"global",description:r.description||"",aliases:(r.aliases||[]).join(", "),content:r.content||""};m(I.draftName),f(I.draftScope),h(I.description),x(I.aliases),w(I.content),k.current=I}else if(c){const I={draftName:"",draftScope:"global",description:c.description??"",aliases:c.aliases.join(", "),content:c.content};h(I.description),x(I.aliases),w(I.content),k.current=I}},[c,d,e,r]);const j=l.useMemo(()=>{const I=k.current;return I?d&&p!==I.draftName||d&&u!==I.draftScope?!0:b!==I.description||v!==I.aliases||g!==I.content:!1},[v,g,b,p,u,d]),S=async()=>{const I=d?p.trim().replace(/\s+/g,"-"):e?.trim();if(!I){H.error(t("settings.snippets.page.toast.nameRequired"));return}if(!g.trim()){H.error(t("settings.snippets.page.toast.contentRequired"));return}const M=v.split(",").map(P=>P.trim()).filter(Boolean);C(!0);try{if(!(d?await o(I,g,{aliases:M,description:b,scope:u}):await i(I,{content:g,aliases:M,description:b}))){H.error(t("settings.snippets.page.toast.saveFailed"));return}H.success(t("settings.snippets.page.toast.saved")),d&&a(null)}finally{C(!1)}};return e?s.jsx(Ns,{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(os,{value:u,onValueChange:I=>f(I),children:[s.jsx(ls,{className:"w-fit min-w-[100px]",children:s.jsx(us,{})}),s.jsxs(cs,{align:"end",children:[s.jsx(Tt,{value:"global",children:t("settings.common.scope.global")}),s.jsx(Tt,{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=>h(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(un,{value:g,onChange:I=>w(I.target.value),placeholder:t("settings.snippets.page.field.contentPlaceholder"),rows:12,className:"mt-1.5 w-full font-mono typography-meta min-h-[160px] max-h-[60vh] bg-transparent"}),s.jsx("p",{className:"mt-2 typography-meta text-muted-foreground",children:t("settings.snippets.page.hint")})]}),s.jsx("div",{className:"px-2 py-1",children:s.jsx(be,{onClick:S,disabled:y||!j,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")})]})})},bg=()=>{const{t}=dt(),e=bt(u=>u.settingsGitmojiEnabled),n=bt(u=>u.setSettingsGitmojiEnabled),r=Rd(),a=Re(u=>u.gitChangesViewMode),i=Re(u=>u.setGitChangesViewMode),[o,c]=l.useState(!0),d=l.useMemo(()=>[{id:"flat",label:t("settings.openchamber.git.option.flatList")},{id:"tree",label:t("settings.openchamber.git.option.treeView")}],[t]);l.useEffect(()=>{(async()=>{try{let f=null;if(!f){const b=Xn()?.settings;if(b)try{const v=(await b.load())?.settings;v&&(f={gitmojiEnabled:typeof v.gitmojiEnabled=="boolean"?v.gitmojiEnabled:void 0,gitChangesViewMode:v.gitChangesViewMode==="flat"||v.gitChangesViewMode==="tree"?v.gitChangesViewMode:void 0})}catch{}}if(!f){const b=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});b.ok&&(f=await b.json())}f&&(typeof f.gitmojiEnabled=="boolean"&&n(f.gitmojiEnabled),(f.gitChangesViewMode==="flat"||f.gitChangesViewMode==="tree")&&i(f.gitChangesViewMode))}catch(f){console.warn("Failed to load git settings:",f)}finally{c(!1)}})()},[i,n]);const p=l.useCallback(async u=>{n(u);try{await Is({gitmojiEnabled:u})}catch(f){console.warn("Failed to save gitmoji setting:",f)}},[n]),m=l.useCallback(u=>{u!==a&&(i(u),Is({gitChangesViewMode:u}))},[a,i]);return o?null:s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.openchamber.git.title")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[s.jsxs("div",{className:"pt-1 pb-1",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:t("settings.openchamber.git.changesViewTitle")}),s.jsx("div",{role:"radiogroup","aria-label":t("settings.openchamber.git.changesViewAria"),className:"mt-0.5 space-y-0",children:d.map(u=>{const f=a===u.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":f,onClick:()=>{m(u.id)},onKeyDown:b=>{(b.key===" "||b.key==="Enter")&&(b.preventDefault(),m(u.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Ja,{checked:f,onChange:()=>{m(u.id)},ariaLabel:t("settings.openchamber.git.optionAria",{option:u.label})}),s.jsx("span",{className:f?"typography-ui-label font-normal text-foreground":"typography-ui-label font-normal text-foreground/50",children:u.label})]},u.id)})})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":e,onClick:()=>{p(!e)},onKeyDown:u=>{(u.key===" "||u.key==="Enter")&&(u.preventDefault(),p(!e))},children:[s.jsx(fs,{checked:e,onChange:u=>{p(u)},ariaLabel:t("settings.openchamber.git.enableGitmojiAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.git.enableGitmoji")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":r,onClick:()=>Yl(!r),onKeyDown:u=>{(u.key===" "||u.key==="Enter")&&(u.preventDefault(),Yl(!r))},children:[s.jsx(fs,{checked:r,onChange:Yl,ariaLabel:t("settings.openchamber.git.showGitignoredAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.git.showGitignored")})]})]})]})},yg=()=>{const{t}=dt(),{isMobile:e}=nn(),n=Xn()?.github,r=Bn(I=>I.status),a=Bn(I=>I.isLoading),i=Bn(I=>I.hasChecked),o=Bn(I=>I.refreshStatus),c=Bn(I=>I.setStatus),d=l.useCallback(async I=>{await qn(I)},[]),[p,m]=l.useState(!1),[u,f]=l.useState(null),[b,h]=l.useState(null),v=l.useRef(null),x=l.useCallback(()=>{v.current!=null&&(window.clearInterval(v.current),v.current=null),h(null)},[]);l.useEffect(()=>((async()=>{try{i||await o(n)}catch(I){console.warn("Failed to load GitHub auth status:",I)}})(),()=>{x()}),[i,o,n,x]);const g=l.useCallback(async()=>{m(!0);try{const I=n?await n.authStart():await(async()=>{const 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),h(Math.max(1,I.interval)*1e3);const M=I.verificationUriComplete||I.verificationUri;d(M)}catch(I){console.error("Failed to start GitHub connect:",I),H.error(t("settings.github.page.toast.startConnectFailed"))}finally{m(!1)}},[d,n,t]),w=l.useCallback(async I=>{if(n)return n.authComplete(I);const M=await fetch("/api/github/auth/complete",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({deviceCode:I})}),P=await M.json().catch(()=>null);if(!M.ok||!P)throw new Error(P?.error||M.statusText);return P},[n]);l.useEffect(()=>{if(!(!u?.deviceCode||!b)&&v.current==null)return v.current=window.setInterval(()=>{(async()=>{try{const I=await w(u.deviceCode);if(I.connected){H.success(t("settings.github.page.toast.connected")),f(null),x(),await o(n,{force:!0});return}I.status==="slow_down"&&h(M=>M?M+5e3:5e3),(I.status==="expired_token"||I.status==="access_denied")&&(H.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,w,o,n,x,t]);const y=l.useCallback(async()=>{m(!0);try{if(x(),f(null),n)await n.authDisconnect();else{const I=await fetch("/api/github/auth",{method:"DELETE",headers:{Accept:"application/json"}});if(!I.ok)throw new Error(I.statusText)}H.success(t("settings.github.page.toast.disconnected")),await o(n,{force:!0})}catch(I){console.error("Failed to disconnect GitHub:",I),H.error(t("settings.github.page.toast.disconnectFailed"))}finally{m(!1)}},[o,n,x,t]),C=l.useCallback(async I=>{if(I){m(!0);try{const M=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(M),H.success(t("settings.github.page.toast.accountSwitched"))}catch(M){console.error("Failed to switch GitHub account:",M),H.error(t("settings.github.page.toast.accountSwitchFailed"))}finally{m(!1)}}},[n,c,t]);if(a)return null;const k=!!r?.connected,j=r?.user,S=r?.accounts??[];return s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-3 px-1 flex items-start justify-between gap-4",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:"GitHub"}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:t("settings.github.page.tooltip.connectAccount")})]})]})}),s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[k?s.jsxs("div",{className:xe("px-4 py-3",e?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[s.jsxs("div",{className:xe("flex min-w-0 items-center gap-4",e?"w-full":void 0),children:[j?.avatarUrl?s.jsx("img",{src:j.avatarUrl,alt:j.login?t("settings.github.page.avatarAlt.withLogin",{login:j.login}):t("settings.github.page.avatarAlt.fallback"),className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:j?.name?.trim()||j?.login||"GitHub"}),s.jsxs("div",{className:xe("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:j?.login||t("settings.github.page.label.unknownUser")}),j?.email&&s.jsx("span",{className:"opacity-50",children:"•"}),j?.email&&s.jsx("span",{children:j.email})]}),r?.scope&&s.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:t("settings.github.page.label.scopes",{value:r.scope})})]})]}),s.jsx(be,{size:"sm",variant:"outline",onClick:y,disabled:p,className:xe("text-[var(--status-error)] hover:text-[var(--status-error)]",e?"w-full":void 0),children:t("settings.github.page.actions.disconnect")})]}):s.jsxs("div",{className:"flex items-center justify-between gap-4 px-4 py-4",children:[s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.github.page.status.notConnected")})}),s.jsx(be,{size:"sm",variant:"default",onClick:g,disabled:p,children:t("settings.github.page.actions.connect")})]}),S.length>1&&s.jsxs("div",{className:"mt-2 border-t border-[var(--surface-subtle)] pt-2 px-2 pb-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground mb-2 px-1",children:t("settings.github.page.label.otherAccounts")}),s.jsx("div",{className:"space-y-1",children:S.map(I=>{const M=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:[M?.avatarUrl?s.jsx("img",{src:M.avatarUrl,alt:M.login?t("settings.github.page.avatarAlt.withLogin",{login:M.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:M?.name?.trim()||M?.login||"GitHub"}),M?.login&&s.jsx("span",{className:"typography-micro text-muted-foreground truncate font-mono",children:M.login})]})]}),P?s.jsx("span",{className:"typography-micro text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-1.5 py-0.5 rounded",children:t("settings.github.page.status.active")}):s.jsx(be,{size:"sm",variant:"ghost",onClick:()=>C(I.id),disabled:p,children:t("settings.github.page.actions.switchTo")})]},I.id)})})]})]}),k&&s.jsx("div",{className:"mt-2 px-2 pb-2",children:s.jsx(be,{size:"sm",variant:"outline",onClick:g,disabled:p,className:xe(e?"w-full":void 0),children:t("settings.github.page.actions.addAccount")})}),u&&s.jsxs("div",{className:"mt-4 rounded-lg bg-[var(--surface-elevated)]/70 p-4 border border-[var(--interactive-border)]",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("h4",{className:"typography-ui-label text-foreground",children:t("settings.github.page.flow.title")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.github.page.flow.description")})]}),s.jsxs("div",{className:"flex items-center justify-between gap-3 mt-4",children:[s.jsx("div",{className:"font-mono text-xl tracking-widest text-foreground bg-[var(--surface-muted)] px-3 py-1.5 rounded-md border border-[var(--interactive-border)]",children:u.userCode}),s.jsx(be,{size:"sm",asChild:!0,children:s.jsx("a",{href:u.verificationUriComplete||u.verificationUri,target:"_blank",rel:"noopener noreferrer",children:t("settings.github.page.actions.openGithub")})})]}),s.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[s.jsx("span",{className:"typography-micro text-muted-foreground animate-pulse",children:t("settings.github.page.flow.waiting")}),s.jsx(be,{size:"sm",variant:"ghost",disabled:p,onClick:()=>{x(),f(null)},children:t("settings.common.actions.cancel")})]})]})]})},Np=[{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)"}],O5=[{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"}],L5=({open:t,onOpenChange:e,profileId:n,importData:r})=>{const{t:a}=dt(),i=Wn(F=>F.getProfileById),o=Wn(F=>F.createProfile),c=Wn(F=>F.updateProfile),d=Wn(F=>F.deleteProfile),p=l.useMemo(()=>n&&n!=="new"&&!r?i(n):null,[n,i,r]),m=n==="new"||r!=null,u=n==="global",[f,b]=l.useState(""),[h,v]=l.useState(""),[x,g]=l.useState(""),[w,y]=l.useState("ssh"),[C,k]=l.useState(""),[j,S]=l.useState(""),[I,M]=l.useState("keyword"),[P,A]=l.useState("branch"),[N,E]=l.useState(!1),[T,R]=l.useState(!1),[V,_]=l.useState(!1);l.useEffect(()=>{if(t){if(r){const F=r.host.split("/"),G=F.length>=3?F[F.length-1]:r.host;b(G),v(r.username),g(""),y("token"),k(""),S(r.host),M("string"),A("code")}else if(m)b(""),v(""),g(""),y("ssh"),k(""),S(""),M("keyword"),A("branch");else if(p)b(p.name),v(p.userName),g(p.userEmail),y(p.authType||"ssh"),k(p.sshKey||""),S(p.host||""),M(p.color||"keyword"),A(p.icon||"branch");else if(u){const F=i("global");F&&(b(F.name),v(F.userName),g(F.userEmail),y(F.authType||"ssh"),k(F.sshKey||""),S(F.host||""),M(F.color||"keyword"),A(F.icon||"branch"))}}},[t,n,p,m,r,u,i]);const U=async()=>{if(!h.trim()||!x.trim()){H.error(a("settings.gitIdentities.editor.toast.userNameEmailRequired"));return}if(w==="token"&&!j.trim()){H.error(a("settings.gitIdentities.editor.toast.hostRequiredForToken"));return}E(!0);try{const F={name:f.trim()||h.trim(),userName:h.trim(),userEmail:x.trim(),authType:w,sshKey:w==="ssh"&&C.trim()||null,host:w==="token"&&j.trim()||null,color:I,icon:P};let G;if(m)G=await o(F);else if(n)G=await c(n,F);else return;G?(H.success(a(m?"settings.gitIdentities.editor.toast.profileCreated":"settings.gitIdentities.editor.toast.profileUpdated")),e(!1)):H.error(a(m?"settings.gitIdentities.editor.toast.createProfileFailed":"settings.gitIdentities.editor.toast.updateProfileFailed"))}catch(F){console.error("Error saving profile:",F),H.error(a("settings.gitIdentities.editor.toast.saveUnexpectedError"))}finally{E(!1)}},B=async()=>{if(!(!n||m)){_(!0);try{await d(n)?(H.success(a("settings.gitIdentities.editor.toast.profileDeleted")),R(!1),e(!1)):H.error(a("settings.gitIdentities.editor.toast.deleteProfileFailed"))}catch(F){console.error("Error deleting profile:",F),H.error(a("settings.gitIdentities.editor.toast.deleteUnexpectedError"))}finally{_(!1)}}},z=l.useMemo(()=>Np.find(G=>G.key===I)?.cssVar||"var(--syntax-keyword)",[I]),K=r?a("settings.gitIdentities.editor.title.importCredential"):m?a("settings.gitIdentities.editor.title.newIdentity"):u?a("settings.gitIdentities.editor.title.globalIdentity"):p?.name||a("settings.gitIdentities.editor.title.editIdentity");return s.jsxs(s.Fragment,{children:[s.jsx(ps,{open:t,onOpenChange:e,children:s.jsxs(ms,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[s.jsxs(ys,{children:[s.jsx(hs,{children:K}),s.jsx(Ss,{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:F=>b(F.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:Np.map(F=>s.jsx("button",{type:"button",onClick:()=>M(F.key),className:xe("w-6 h-6 rounded-md border-2 transition-all cursor-pointer",I===F.key?"border-foreground scale-110":"border-transparent hover:border-border"),style:{backgroundColor:F.cssVar},title:F.label},F.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:O5.map(F=>{const G=F.Icon;return s.jsx("button",{type:"button",onClick:()=>A(F.key),className:xe("w-7 h-7 rounded-md border-2 transition-all flex items-center justify-center cursor-pointer",P===F.key?"border-[var(--interactive-border)] bg-[var(--surface-muted)]":"border-transparent hover:border-[var(--interactive-border)] hover:bg-[var(--surface-muted)]/50"),title:F.label,children:s.jsx(D,{name:G,className:"w-3.5 h-3.5",style:{color:P===F.key?z:"var(--surface-muted-foreground)"}})},F.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(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:a("settings.gitIdentities.editor.field.userNameTooltip")})]})]}),s.jsx(Bt,{value:h,onChange:F=>v(F.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(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:a("settings.gitIdentities.editor.field.emailAddressTooltip")})]})]}),s.jsx(Bt,{type:"email",value:x,onChange:F=>g(F.target.value),placeholder:a("settings.gitIdentities.editor.field.emailAddressPlaceholder"),required:!u,readOnly:u,disabled:u,className:"h-8"})]})]}),!u&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"border-t border-border/40"}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.gitIdentities.editor.field.authMethod")}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs(be,{size:"sm",type:"button",variant:"chip","aria-pressed":w==="ssh",onClick:()=>y("ssh"),children:[s.jsx(D,{name:"lock-2",className:"w-3.5 h-3.5 mr-1"})," SSH"]}),s.jsxs(be,{size:"sm",type:"button",variant:"chip","aria-pressed":w==="token",onClick:()=>y("token"),children:[s.jsx(D,{name:"key",className:"w-3.5 h-3.5 mr-1"})," ",a("settings.gitIdentities.editor.field.authToken")]})]})]}),w==="ssh"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:a("settings.gitIdentities.editor.field.sshKeyPath")}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:a("settings.gitIdentities.editor.field.sshKeyPathTooltip")})]})]}),s.jsx(Bt,{value:C,onChange:F=>k(F.target.value),placeholder:a("settings.gitIdentities.editor.field.sshKeyPathPlaceholder"),className:"h-8 font-mono text-xs"})]}),w==="token"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:a("settings.gitIdentities.editor.field.host")}),s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:a("settings.gitIdentities.editor.field.hostTooltip")})]})]}),s.jsx(Bt,{value:j,onChange:F=>S(F.target.value),placeholder:a("settings.gitIdentities.editor.field.hostPlaceholder"),required:!0,className:"h-8 font-mono text-xs"})]})]})]})]}),s.jsxs(Vs,{className:"gap-2",children:[!u&&!m&&s.jsxs(be,{variant:"outline",size:"sm",onClick:()=>R(!0),className:"text-[var(--status-error)] hover:text-[var(--status-error)] border-[var(--status-error)]/30 hover:bg-[var(--status-error)]/10 mr-auto",children:[s.jsx(D,{name:"delete-bin",className:"w-3.5 h-3.5 mr-1"})," ",a("settings.common.actions.delete")]}),s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>e(!1),className:"text-foreground hover:bg-interactive-hover hover:text-foreground",children:a(u?"settings.gitIdentities.editor.actions.close":"settings.common.actions.cancel")}),!u&&s.jsx(be,{size:"sm",onClick:U,disabled:N,children:a(N?"settings.common.actions.saving":m?"settings.gitIdentities.editor.actions.create":"settings.gitIdentities.editor.actions.save")})]})]})}),s.jsx(ps,{open:T,onOpenChange:F=>{V||R(F)},children:s.jsxs(ms,{className:"max-w-md",children:[s.jsxs(ys,{children:[s.jsx(hs,{children:a("settings.gitIdentities.page.deleteDialog.title")}),s.jsx(Ss,{children:a("settings.gitIdentities.page.deleteDialog.description",{name:p?.name||f})})]}),s.jsxs(Vs,{children:[s.jsx(be,{variant:"ghost",onClick:()=>R(!1),disabled:V,children:a("settings.common.actions.cancel")}),s.jsx(be,{size:"sm",variant:"destructive",onClick:()=>{B()},disabled:V,children:a("settings.common.actions.delete")})]})]})})]})},$5={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart"},_5={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)"},B5=()=>{const t=st.c(116),{t:e}=dt(),{profiles:n,globalIdentity:r,defaultGitIdentityId:a,deleteProfile:i,loadProfiles:o,loadGlobalIdentity:c,loadDiscoveredCredentials:d,loadDefaultGitIdentityId:p,setDefaultGitIdentityId:m,getUnimportedCredentials:u}=Wn(Jn(V5)),[f,b]=l.useState(!1),[h,v]=l.useState(null),[x,g]=l.useState(null),[w,y]=l.useState(null),[C,k]=l.useState(!1);let j,S;t[0]!==p||t[1]!==d||t[2]!==c||t[3]!==o?(j=()=>{o(),c(),d(),p()},S=[o,c,d,p],t[0]=p,t[1]=d,t[2]=c,t[3]=o,t[4]=j,t[5]=S):(j=t[4],S=t[5]),l.useEffect(j,S);let I,M,P,A,N,E,T,R,V,_,U,B,z;if(t[6]!==a||t[7]!==w||t[8]!==i||t[9]!==u||t[10]!==r||t[11]!==n||t[12]!==m||t[13]!==e){const pe=u();let we;t[27]===Symbol.for("react.memo_cache_sentinel")?(we=(O,L)=>{v(O),g(L??null),b(!0)},t[27]=we):we=t[27];const Ie=we;let Y;t[28]!==a||t[29]!==m||t[30]!==e?(Y=async O=>{const L=a===O?null:O;if(!await m(L)){H.error(e("settings.gitIdentities.page.toast.updateDefaultFailed"));return}H.success(e(L?"settings.gitIdentities.page.toast.defaultUpdated":"settings.gitIdentities.page.toast.defaultUnset"))},t[28]=a,t[29]=m,t[30]=e,t[31]=Y):Y=t[31];const re=Y;let Pe;t[32]!==w||t[33]!==i||t[34]!==e?(Pe=async()=>{if(!w)return;k(!0),await i(w.id)?(H.success(e("settings.gitIdentities.page.toast.profileDeleted",{name:w.name})),y(null)):H.error(e("settings.gitIdentities.page.toast.deleteProfileFailed")),k(!1)},t[32]=w,t[33]=i,t[34]=e,t[35]=Pe):Pe=t[35],M=Pe,I=Ns,A="h-full",N="w-full bg-background",z="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(yg,{}),t[36]=P):P=t[36],U="border-t border-border/40 pt-6";let ce;t[37]!==e?(ce=e("settings.gitIdentities.page.section.title"),t[37]=e,t[38]=ce):ce=t[38];let Ce;t[39]!==ce?(Ce=s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:ce})}),t[39]=ce,t[40]=Ce):Ce=t[40];let Te,$e;t[41]===Symbol.for("react.memo_cache_sentinel")?(Te=()=>Ie("new"),$e=s.jsx(D,{name:"add",className:"w-3.5 h-3.5 mr-1"}),t[41]=Te,t[42]=$e):(Te=t[41],$e=t[42]);let De;t[43]!==e?(De=e("settings.common.badge.new"),t[43]=e,t[44]=De):De=t[44];let de;t[45]!==De?(de=s.jsxs(be,{size:"sm",variant:"outline",onClick:Te,children:[$e," ",De]}),t[45]=De,t[46]=de):de=t[46],t[47]!==Ce||t[48]!==de?(B=s.jsxs("div",{className:"mb-3 px-1 flex items-start justify-between gap-4",children:[Ce,de]}),t[47]=Ce,t[48]=de,t[49]=B):B=t[49],E="rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",T=r&&s.jsx(Sp,{profile:r,isDefault:a==="global",onEdit:()=>Ie("global"),onToggleDefault:()=>re("global"),isReadOnly:!0,hasBorder:n.length>0||pe.length>0}),R=n.map((O,L)=>s.jsx(Sp,{profile:O,isDefault:a===O.id,onEdit:()=>Ie(O.id),onToggleDefault:()=>re(O.id),onDelete:()=>y(O),hasBorder:L<n.length-1||pe.length>0},O.id)),V=!r&&n.length===0&&pe.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")})]}),_=pe.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")})}),pe.map((O,L)=>s.jsx(z5,{credential:O,onImport:()=>Ie("new",{host:O.host,username:O.username}),hasBorder:L<pe.length-1},`${O.host}-${O.username}`))]}),t[6]=a,t[7]=w,t[8]=i,t[9]=u,t[10]=r,t[11]=n,t[12]=m,t[13]=e,t[14]=I,t[15]=M,t[16]=P,t[17]=A,t[18]=N,t[19]=E,t[20]=T,t[21]=R,t[22]=V,t[23]=_,t[24]=U,t[25]=B,t[26]=z}else I=t[14],M=t[15],P=t[16],A=t[17],N=t[18],E=t[19],T=t[20],R=t[21],V=t[22],_=t[23],U=t[24],B=t[25],z=t[26];let K;t[50]!==E||t[51]!==T||t[52]!==R||t[53]!==V||t[54]!==_?(K=s.jsxs("div",{className:E,children:[T,R,V,_]}),t[50]=E,t[51]=T,t[52]=R,t[53]=V,t[54]=_,t[55]=K):K=t[55];let F;t[56]!==K||t[57]!==U||t[58]!==B?(F=s.jsxs("div",{className:U,children:[B,K]}),t[56]=K,t[57]=U,t[58]=B,t[59]=F):F=t[59];let G;t[60]===Symbol.for("react.memo_cache_sentinel")?(G=s.jsx(bg,{}),t[60]=G):G=t[60];let Q;t[61]!==P||t[62]!==F||t[63]!==z?(Q=s.jsxs("div",{className:z,children:[P,F,G]}),t[61]=P,t[62]=F,t[63]=z,t[64]=Q):Q=t[64];let te;t[65]!==I||t[66]!==A||t[67]!==N||t[68]!==Q?(te=s.jsx(I,{outerClassName:A,className:N,children:Q}),t[65]=I,t[66]=A,t[67]=N,t[68]=Q,t[69]=te):te=t[69];let Z;t[70]!==x||t[71]!==f||t[72]!==h?(Z=s.jsx(L5,{open:f,onOpenChange:b,profileId:h,importData:x}),t[70]=x,t[71]=f,t[72]=h,t[73]=Z):Z=t[73];const fe=w!==null;let ue;t[74]!==C?(ue=pe=>{C||pe||y(null)},t[74]=C,t[75]=ue):ue=t[75];let W;t[76]!==e?(W=e("settings.gitIdentities.page.deleteDialog.title"),t[76]=e,t[77]=W):W=t[77];let q;t[78]!==W?(q=s.jsx(hs,{children:W}),t[78]=W,t[79]=q):q=t[79];const J=w?.name??"";let ne;t[80]!==e||t[81]!==J?(ne=e("settings.gitIdentities.page.deleteDialog.description",{name:J}),t[80]=e,t[81]=J,t[82]=ne):ne=t[82];let ee;t[83]!==ne?(ee=s.jsx(Ss,{children:ne}),t[83]=ne,t[84]=ee):ee=t[84];let he;t[85]!==q||t[86]!==ee?(he=s.jsxs(ys,{children:[q,ee]}),t[85]=q,t[86]=ee,t[87]=he):he=t[87];let ke;t[88]===Symbol.for("react.memo_cache_sentinel")?(ke=()=>y(null),t[88]=ke):ke=t[88];let oe;t[89]!==e?(oe=e("settings.common.actions.cancel"),t[89]=e,t[90]=oe):oe=t[90];let ge;t[91]!==C||t[92]!==oe?(ge=s.jsx(be,{variant:"ghost",onClick:ke,disabled:C,children:oe}),t[91]=C,t[92]=oe,t[93]=ge):ge=t[93];let me;t[94]!==M?(me=()=>{M()},t[94]=M,t[95]=me):me=t[95];let ye;t[96]!==e?(ye=e("settings.common.actions.delete"),t[96]=e,t[97]=ye):ye=t[97];let ie;t[98]!==C||t[99]!==me||t[100]!==ye?(ie=s.jsx(be,{size:"sm",variant:"destructive",onClick:me,disabled:C,children:ye}),t[98]=C,t[99]=me,t[100]=ye,t[101]=ie):ie=t[101];let ve;t[102]!==ge||t[103]!==ie?(ve=s.jsxs(Vs,{children:[ge,ie]}),t[102]=ge,t[103]=ie,t[104]=ve):ve=t[104];let X;t[105]!==he||t[106]!==ve?(X=s.jsxs(ms,{className:"max-w-md",children:[he,ve]}),t[105]=he,t[106]=ve,t[107]=X):X=t[107];let Se;t[108]!==fe||t[109]!==ue||t[110]!==X?(Se=s.jsx(ps,{open:fe,onOpenChange:ue,children:X}),t[108]=fe,t[109]=ue,t[110]=X,t[111]=Se):Se=t[111];let Ae;return t[112]!==te||t[113]!==Z||t[114]!==Se?(Ae=s.jsxs(s.Fragment,{children:[te,Z,Se]}),t[112]=te,t[113]=Z,t[114]=Se,t[115]=Ae):Ae=t[115],Ae},Sp=t=>{const e=st.c(54),{profile:n,isDefault:r,onEdit:a,onToggleDefault:i,onDelete:o,isReadOnly:c,hasBorder:d}=t,{t:p}=dt(),m=$5[n.icon||"branch"]||"git-branch",u=_5[n.color||""],f=n.authType||"ssh",b=d&&"border-b border-[var(--surface-subtle)]";let h;e[0]!==b?(h=xe("group flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30 cursor-pointer",b),e[0]=b,e[1]=h):h=e[1];let v;e[2]!==a?(v=U=>{(U.key==="Enter"||U.key===" ")&&a()},e[2]=a,e[3]=v):v=e[3];let x;e[4]!==u?(x={color:u},e[4]=u,e[5]=x):x=e[5];let g;e[6]!==m||e[7]!==x?(g=s.jsx(D,{name:m,className:"w-4 h-4 shrink-0",style:x}),e[6]=m,e[7]=x,e[8]=g):g=e[8];let w;e[9]!==n.name?(w=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:n.name}),e[9]=n.name,e[10]=w):w=e[10];let y;e[11]!==f?(y=s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:f}),e[11]=f,e[12]=y):y=e[12];let C;e[13]!==r||e[14]!==p?(C=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]=C):C=e[15];let k;e[16]!==c||e[17]!==p?(k=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]=k):k=e[18];let j;e[19]!==w||e[20]!==y||e[21]!==C||e[22]!==k?(j=s.jsxs("div",{className:"flex items-center gap-1.5",children:[w,y,C,k]}),e[19]=w,e[20]=y,e[21]=C,e[22]=k,e[23]=j):j=e[23];const S=f==="token"&&n.host?n.host:n.userEmail;let I;e[24]!==S?(I=s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:S}),e[24]=S,e[25]=I):I=e[25];let M;e[26]!==j||e[27]!==I?(M=s.jsxs("div",{className:"min-w-0",children:[j,I]}),e[26]=j,e[27]=I,e[28]=M):M=e[28];let P;e[29]!==M||e[30]!==g?(P=s.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[g,M]}),e[29]=M,e[30]=g,e[31]=P):P=e[31];let A;e[32]===Symbol.for("react.memo_cache_sentinel")?(A=s.jsx(As,{asChild:!0,children:s.jsx(be,{size:"icon",variant:"ghost",className:"h-6 w-6 shrink-0 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",onClick:U5,children:s.jsx(D,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[32]=A):A=e[32];let N;e[33]!==i?(N=U=>{U.stopPropagation(),i()},e[33]=i,e[34]=N):N=e[34];let E;e[35]!==r||e[36]!==p?(E=p(r?"settings.gitIdentities.page.actions.unsetDefault":"settings.gitIdentities.page.actions.setAsDefault"),e[35]=r,e[36]=p,e[37]=E):E=e[37];let T;e[38]!==N||e[39]!==E?(T=s.jsx($t,{onClick:N,children:E}),e[38]=N,e[39]=E,e[40]=T):T=e[40];let R;e[41]!==c||e[42]!==o||e[43]!==p?(R=!c&&o&&s.jsxs($t,{onClick:U=>{U.stopPropagation(),o()},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]=o,e[43]=p,e[44]=R):R=e[44];let V;e[45]!==T||e[46]!==R?(V=s.jsxs(Ts,{children:[A,s.jsxs(Ds,{align:"end",className:"w-fit min-w-28",children:[T,R]})]}),e[45]=T,e[46]=R,e[47]=V):V=e[47];let _;return e[48]!==a||e[49]!==P||e[50]!==h||e[51]!==V||e[52]!==v?(_=s.jsxs("div",{className:h,onClick:a,role:"button",tabIndex:0,onKeyDown:v,children:[P,V]}),e[48]=a,e[49]=P,e[50]=h,e[51]=V,e[52]=v,e[53]=_):_=e[53],_},z5=t=>{const e=st.c(21),{credential:n,onImport:r,hasBorder:a}=t,{t:i}=dt();let o;e[0]!==n.host?(o=n.host.split("/"),e[0]=n.host,e[1]=o):o=e[1];const c=o,d=c.length>=3?c[c.length-1]:n.host,p=n.host.includes("/"),m=a&&"border-b border-[var(--surface-subtle)]";let u;e[2]!==m?(u=xe("flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30",m),e[2]=m,e[3]=u):u=e[3];let f;e[4]!==d?(f=s.jsx("span",{className:"typography-ui-label text-foreground truncate block",children:d}),e[4]=d,e[5]=f):f=e[5];const b=p?n.host:n.username;let h;e[6]!==b?(h=s.jsx("span",{className:"typography-micro text-muted-foreground/60 truncate block leading-tight",children:b}),e[6]=b,e[7]=h):h=e[7];let v;e[8]!==f||e[9]!==h?(v=s.jsxs("div",{className:"min-w-0",children:[f,h]}),e[8]=f,e[9]=h,e[10]=v):v=e[10];let x;e[11]===Symbol.for("react.memo_cache_sentinel")?(x=s.jsx(D,{name:"download",className:"h-3 w-3"}),e[11]=x):x=e[11];let g;e[12]!==i?(g=i("settings.gitIdentities.page.actions.import"),e[12]=i,e[13]=g):g=e[13];let w;e[14]!==r||e[15]!==g?(w=s.jsxs(be,{size:"sm",variant:"ghost",onClick:r,className:"gap-1 shrink-0",children:[x,g]}),e[14]=r,e[15]=g,e[16]=w):w=e[16];let y;return e[17]!==w||e[18]!==u||e[19]!==v?(y=s.jsxs("div",{className:u,children:[v,w]}),e[17]=w,e[18]=u,e[19]=v,e[20]=y):y=e[20],y};function V5(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 U5(t){return t.stopPropagation()}const vg=()=>{const t=Hb();return{displayMode:t,installed:t!=="browser",browserTab:t==="browser"}},wg=()=>{const t=st.c(2),[e,n]=l.useState(W5);let r,a;return t[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const i=[window.matchMedia("(display-mode: standalone)"),window.matchMedia("(display-mode: minimal-ui)"),window.matchMedia("(display-mode: fullscreen)"),window.matchMedia("(display-mode: window-controls-overlay)")],o=()=>{n(vg())};o();for(const c of i)typeof c.addEventListener=="function"?c.addEventListener("change",o):typeof c.addListener=="function"&&c.addListener(o);return window.addEventListener("appinstalled",o),window.addEventListener("focus",o),()=>{for(const c of i)typeof c.removeEventListener=="function"?c.removeEventListener("change",o):typeof c.removeListener=="function"&&c.removeListener(o);window.removeEventListener("appinstalled",o),window.removeEventListener("focus",o)}},a=[],t[0]=r,t[1]=a):(r=t[0],a=t[1]),l.useEffect(r,a),e};function W5(){return vg()}const K5=[{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"}],H5=[{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"}],G5=[{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"}],q5=[{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"}],Ri="OpenChamber - AI Coding Assistant",kp=[{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"}],Cp=[{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"}],Ic=t=>t==="portrait"||t==="landscape"?t:"system",J5=[{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"}],Y5=[{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"}],Ip=[{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"}],Q5=[{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"}],Pp=[{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"}],Ap=[{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"}],X5=t=>t==="markdown"?"markdown":"plain",eu=({visibleSettings:t})=>{const{locale:e,locales:n,setLocale:r,label:a,t:i}=dt(),o=l.useCallback(se=>i(se),[i]),{isMobile:c}=nn(),{browserTab:d}=wg(),p=Tl(),m=Re(se=>se.showReasoningTraces),u=Re(se=>se.setShowReasoningTraces),f=Re(se=>se.collapsibleThinkingBlocks),b=Re(se=>se.setCollapsibleThinkingBlocks),h=Re(se=>se.mermaidRenderingMode),v=Re(se=>se.setMermaidRenderingMode),x=Re(se=>se.userMessageRenderingMode),g=Re(se=>se.setUserMessageRenderingMode),w=Re(se=>se.stickyUserHeader),y=Re(se=>se.setStickyUserHeader),C=Re(se=>se.wideChatLayoutEnabled),k=Re(se=>se.setWideChatLayoutEnabled),j=Re(se=>se.chatRenderMode),S=Re(se=>se.setChatRenderMode),I=Re(se=>se.activityRenderMode),M=Re(se=>se.setActivityRenderMode),P=Re(se=>se.fontSize),A=Re(se=>se.setFontSize),N=Re(se=>se.terminalFontSize),E=Re(se=>se.setTerminalFontSize),T=Re(se=>se.uiFont),R=Re(se=>se.setUiFont),V=Re(se=>se.monoFont),_=Re(se=>se.setMonoFont),U=Re(se=>se.padding),B=Re(se=>se.setPadding),z=Re(se=>se.inputBarOffset),K=Re(se=>se.setInputBarOffset),F=Re(se=>se.mobileKeyboardMode),G=Re(se=>se.setMobileKeyboardMode),Q=Re(se=>se.diffLayoutPreference),te=Re(se=>se.setDiffLayoutPreference),Z=Re(se=>se.diffViewMode),fe=Re(se=>se.setDiffViewMode),ue=Re(se=>se.showTerminalQuickKeysOnDesktop),W=Re(se=>se.setShowTerminalQuickKeysOnDesktop),q=Su(se=>se.queueModeEnabled),J=Su(se=>se.setQueueMode),ne=Re(se=>se.persistChatDraft),ee=Re(se=>se.setPersistChatDraft),he=Re(se=>se.inputSpellcheckEnabled),ke=Re(se=>se.setInputSpellcheckEnabled),oe=Re(se=>se.showToolFileIcons),ge=Re(se=>se.setShowToolFileIcons),me=Re(se=>se.showExpandedBashTools),ye=Re(se=>se.setShowExpandedBashTools),ie=Re(se=>se.showExpandedEditTools),ve=Re(se=>se.setShowExpandedEditTools),X=Re(se=>se.timeFormatPreference),Se=Re(se=>se.setTimeFormatPreference),Ae=Re(se=>se.weekStartPreference),pe=Re(se=>se.setWeekStartPreference),we=Re(se=>se.showSplitAssistantMessageActions),Ie=Re(se=>se.setShowSplitAssistantMessageActions),Y=Re(se=>se.showMobileSessionStatusBar),re=Re(se=>se.setShowMobileSessionStatusBar),Pe=bt(se=>se.settingsMessageStreamTransport),ce=bt(se=>se.setSettingsMessageStreamTransport),Ce=Re(se=>se.isSettingsDialogOpen),{themeMode:Te,setThemeMode:$e,availableThemes:De,customThemesLoading:de,reloadCustomThemes:O,lightThemeId:L,darkThemeId:$,setLightThemePreference:je,setDarkThemePreference:ae}=Cr(),[_e,le]=l.useState(!1),[Me,Ge]=l.useState(0),at=Re(se=>se.reportUsage),Ye=Re(se=>se.setReportUsage),Xe=l.useCallback(se=>{Ye(se),Is({reportUsage:se})},[Ye]),ut=Ce&&(t?t.includes("chatRenderMode"):!0);l.useEffect(()=>{if(!ut)return;let se=null,xt=Date.now();const Je=()=>{const Gt=Date.now();Gt-xt>=420&&(Ge(is=>(is+1)%24),xt=Gt),se=requestAnimationFrame(Je)};(typeof document>"u"||document.visibilityState==="visible")&&(se=requestAnimationFrame(Je));const _t=()=>{document.visibilityState==="visible"&&se===null?se=requestAnimationFrame(Je):document.visibilityState!=="visible"&&se!==null&&(cancelAnimationFrame(se),se=null)};return document.addEventListener("visibilitychange",_t),()=>{document.removeEventListener("visibilitychange",_t),se!==null&&cancelAnimationFrame(se)}},[ut]);const rt=l.useCallback(se=>{g(se),Is({userMessageRenderingMode:se})},[g]),it=l.useCallback(se=>{y(se),Is({stickyUserHeader:se})},[y]),nt=l.useCallback(se=>{k(se),Is({wideChatLayoutEnabled:se})},[k]),Ne=l.useCallback(se=>{Ie(se),Is({showSplitAssistantMessageActions:se})},[Ie]),Ke=l.useCallback(se=>{ke(se),Is({inputSpellcheckEnabled:se})},[ke]),Ve=l.useCallback(se=>{S(se),Is({chatRenderMode:se})},[S]),qe=l.useCallback(se=>{ce(se),Is({messageStreamTransport:se})},[ce]),lt=l.useCallback(se=>{M(se),Is({activityRenderMode:se})},[M]),He=l.useCallback(se=>{v(se),Is({mermaidRenderingMode:se})},[v]),ze=l.useCallback(se=>{ge(se),Is({showToolFileIcons:se})},[ge]),et=l.useCallback(se=>{ye(se),Is({showExpandedBashTools:se})},[ye]),yt=l.useCallback(se=>{ve(se),Is({showExpandedEditTools:se})},[ve]),Rt=l.useCallback(se=>{Se(se),Is({timeFormatPreference:se})},[Se]),kt=l.useCallback(se=>{pe(se),Is({weekStartPreference:se})},[pe]),ht=l.useMemo(()=>De.filter(se=>se.metadata.variant==="light").sort((se,xt)=>se.metadata.name.localeCompare(xt.metadata.name)),[De]),vt=l.useMemo(()=>De.filter(se=>se.metadata.variant==="dark").sort((se,xt)=>se.metadata.name.localeCompare(xt.metadata.name)),[De]),ns=l.useMemo(()=>ht.find(se=>se.metadata.id===L)??ht[0],[ht,L]),zt=l.useMemo(()=>vt.find(se=>se.metadata.id===$)??vt[0],[vt,$]),Kt=l.useCallback((se,xt)=>{const Je=xt==="dark"?" Dark":" Light";return se.endsWith(Je)?se.slice(0,-Je.length):se},[]),mt=se=>t?t.includes(se):!0,Et=on(),rs=mt("theme")&&!Et,gs=mt("theme")||mt("timeFormat")||mt("weekStart"),xs=Et?gs:mt("theme")||mt("pwaInstallName")||mt("pwaOrientation")||mt("timeFormat")||mt("weekStart"),bs=mt("fontSize")||mt("terminalFontSize")||mt("spacing")||mt("inputBarOffset"),Wt=mt("terminalQuickKeys")&&!c,We=mt("mermaidRendering")||mt("userMessageRendering")||mt("chatRenderMode")||mt("messageTransport")||mt("activityRenderMode")&&j==="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"),St=mt("pwaInstallName")&&Yr()&&d&&!vn()&&!Et,qt=mt("pwaOrientation")&&Yr()&&!vn()&&!Et,wt=mt("mobileKeyboardMode")&&Yr()&&!vn()&&!Et&&Gb(),[es,ds]=l.useState(""),[Ms,as]=l.useState("system"),$s=l.useMemo(()=>{const se=Pp.find(xt=>xt.id===X);return o(se?.labelKey??"settings.openchamber.visual.option.timeFormat.auto.label")},[X,o]),Ls=l.useMemo(()=>{const se=Ap.find(xt=>xt.id===Ae);return o(se?.labelKey??"settings.openchamber.visual.option.weekStart.auto.label")},[Ae,o]),ln=l.useMemo(()=>{const se=kp.find(xt=>xt.id===Ms);return se?o(se.labelKey):void 0},[Ms,o]),Xs=l.useMemo(()=>{const se=Cp.find(xt=>xt.id===F);return se?o(se.labelKey):void 0},[F,o]),Vt=l.useCallback(async se=>{if(typeof window>"u")return;const xt=window,_t=se.trim().replace(/\s+/g," ").slice(0,64);if(await Is({pwaAppName:_t}),typeof xt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__=="function"){const Gt=xt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__(_t);ds(Gt);return}ds(_t||Ri),xt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]),Ut=l.useCallback(async se=>{if(typeof window>"u")return;const xt=window,Je=Ic(se);if(await Is({pwaOrientation:Je}),typeof xt.__OPENCHAMBER_SET_PWA_ORIENTATION__=="function"){const _t=xt.__OPENCHAMBER_SET_PWA_ORIENTATION__(Je);as(_t);return}as(Je),xt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]);return l.useEffect(()=>{if(typeof window>"u"||!St&&!qt&&!wt)return;let se=!1;return(async()=>{try{const Je=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},cache:"no-store"});if(!Je.ok){se||ds(Ri);return}const _t=await Je.json().catch(()=>({})),is=(typeof _t?.pwaAppName=="string"?_t.pwaAppName:"").trim().replace(/\s+/g," ").slice(0,64),Ue=Ic(_t?.pwaOrientation),gt=Au(_t?.mobileKeyboardMode);se||(St&&ds(is||Ri),qt&&as(Ue),wt&&G(gt))}catch{se||(St&&ds(Ri),qt&&as("system"),wt&&G("native"))}})(),()=>{se=!0}},[G,wt,St,qt]),s.jsxs("div",{className:"space-y-8",children:[xs&&s.jsxs("div",{className:"mb-8 space-y-6",children:[rs&&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:K5.map(se=>s.jsx(be,{variant:"chip",size:"xs","aria-pressed":Te===se.value,className:"!font-normal",onClick:()=>$e(se.value),children:o(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(os,{value:ns?.metadata.id??"",onValueChange:je,children:[s.jsx(ls,{"aria-label":i("settings.openchamber.visual.field.selectLightThemeAria"),className:"w-fit",children:s.jsx(us,{placeholder:i("settings.openchamber.visual.field.selectThemePlaceholder"),children:ns?Kt(ns.metadata.name,"light"):void 0})}),s.jsx(cs,{children:ht.map(se=>s.jsx(Tt,{value:se.metadata.id,children:Kt(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(os,{value:zt?.metadata.id??"",onValueChange:ae,children:[s.jsx(ls,{"aria-label":i("settings.openchamber.visual.field.selectDarkThemeAria"),className:"w-fit",children:s.jsx(us,{placeholder:i("settings.openchamber.visual.field.selectThemePlaceholder"),children:zt?Kt(zt.metadata.name,"dark"):void 0})}),s.jsx(cs,{children:vt.map(se=>s.jsx(Tt,{value:se.metadata.id,children:Kt(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:de||_e,onClick:()=>{const se=Date.now();le(!0),O().finally(()=>{const xt=Date.now()-se;if(xt<500){window.setTimeout(()=>{le(!1)},500-xt);return}le(!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(_e?"settings.openchamber.visual.actions.reloadingThemes":"settings.openchamber.visual.actions.reloadThemes")}),s.jsxs(Ct,{children:[s.jsx(It,{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(At,{sideOffset:8,children:i("settings.openchamber.visual.field.themeImportInfoTooltip")})]})]})]}),gs&&s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.localization")}),s.jsxs("div",{className:"grid grid-cols-1 gap-2 py-1.5 md:grid-cols-[14rem_auto] md:gap-x-8 md:gap-y-2",children:[s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:i("settings.appearance.language.label")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.appearance.language.description")})]}),s.jsxs(os,{value:e,onValueChange:se=>r(se),children:[s.jsx(ls,{"aria-label":i("settings.appearance.language.select"),className:"w-fit",children:s.jsx(us,{children:a(e)})}),s.jsx(cs,{children:n.map(se=>s.jsx(Tt,{value:se,children:a(se)},se))})]})]}),!Et&&(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(os,{value:X,onValueChange:se=>Rt(se),children:[s.jsx(ls,{"aria-label":i("settings.openchamber.visual.field.selectTimeFormatAria"),className:"w-fit",children:s.jsx(us,{children:$s})}),s.jsx(cs,{children:Pp.map(se=>s.jsx(Tt,{value:se.id,children:o(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(os,{value:Ae,onValueChange:se=>kt(se),children:[s.jsx(ls,{"aria-label":i("settings.openchamber.visual.field.selectWeekStartAria"),className:"w-fit",children:s.jsx(us,{children:Ls})}),s.jsx(cs,{children:Ap.map(se=>s.jsx(Tt,{value:se.id,children:o(se.labelKey)},se.id))})]})]})]})]}),(St||qt||wt)&&s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[St&&s.jsxs("div",{className:"py-1.5 space-y-1.5",children:[s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.installAppName")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.openchamber.visual.field.installAppNameHint")})]}),s.jsxs("div",{className:"flex w-full max-w-[28rem] items-center gap-2",children:[s.jsx(Bt,{value:es,onChange:se=>{ds(se.target.value)},onBlur:()=>{Vt(es)},onKeyDown:se=>{se.key==="Enter"&&(se.preventDefault(),Vt(es))},className:"h-7",maxLength:64,"aria-label":i("settings.openchamber.visual.field.pwaInstallAppNameAria")}),s.jsx(be,{size:"sm",type:"button",variant:"ghost",onClick:()=>{ds(Ri),Vt("")},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"})})]})]}),qt&&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(os,{value:Ms,onValueChange:se=>{const xt=Ic(se);as(xt),Ut(xt)},children:[s.jsx(ls,{"aria-label":i("settings.openchamber.visual.field.pwaInstallOrientationAria"),className:"w-full",children:s.jsx(us,{placeholder:i("settings.openchamber.visual.field.selectOrientationPlaceholder"),children:ln})}),s.jsx(cs,{children:kp.map(se=>s.jsx(Tt,{value:se.id,children:o(se.labelKey)},se.id))})]}),s.jsx(be,{size:"sm",type:"button",variant:"ghost",onClick:()=>{as("system"),Ut("system")},disabled:Ms==="system",className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetInstallOrientationAria"),title:i("settings.common.actions.reset"),children:s.jsx(D,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),wt&&s.jsxs("div",{className:"py-1.5 space-y-1.5",children:[s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.mobileKeyboardMode")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.openchamber.visual.field.mobileKeyboardModeHint")})]}),s.jsxs("div",{className:"flex w-full max-w-[18rem] items-center gap-2",children:[s.jsxs(os,{value:F,onValueChange:se=>{const xt=Au(se);G(xt),Is({mobileKeyboardMode:xt})},children:[s.jsx(ls,{"aria-label":i("settings.openchamber.visual.field.mobileKeyboardModeAria"),className:"w-full",children:s.jsx(us,{placeholder:i("settings.openchamber.visual.field.selectMobileKeyboardModePlaceholder"),children:Xs})}),s.jsx(cs,{children:Cp.map(se=>s.jsx(Tt,{value:se.id,children:o(se.labelKey)},se.id))})]}),s.jsx(be,{size:"sm",type:"button",variant:"ghost",onClick:()=>{G("native"),Is({mobileKeyboardMode:"native"})},disabled:F==="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"})})]})]})]})]}),bs&&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(os,{value:T,onValueChange:se=>R(se),children:[s.jsx(ls,{"aria-label":i("settings.openchamber.visual.field.selectInterfaceFontAria"),className:"w-[13rem]",children:s.jsx(us,{children:ku.find(se=>se.id===T)?.label})}),s.jsx(cs,{children:ku.map(se=>s.jsx(Tt,{value:se.id,children:s.jsx("span",{style:{fontFamily:se.stack},children:se.label})},se.id))})]}),s.jsx(be,{size:"sm",type:"button",variant:"ghost",onClick:()=>R(Cu),disabled:T===Cu,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:xe("py-1",c?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsx("div",{className:xe("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:xe("flex items-center gap-2",c?"w-full":"w-fit"),children:[s.jsxs(os,{value:V,onValueChange:se=>_(se),children:[s.jsx(ls,{"aria-label":i("settings.openchamber.visual.field.selectCodeFontAria"),className:"w-[13rem]",children:s.jsx(us,{children:Iu.find(se=>se.id===V)?.label})}),s.jsx(cs,{children:Iu.map(se=>s.jsx(Tt,{value:se.id,children:s.jsx("span",{style:{fontFamily:se.stack},children:se.label})},se.id))})]}),s.jsx(be,{size:"sm",type:"button",variant:"ghost",onClick:()=>_(Pu),disabled:V===Pu,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(En,{value:P,onValueChange:A,min:50,max:200,step:5,"aria-label":i("settings.openchamber.visual.field.fontSizePercentageAria"),className:"w-16"}),s.jsx(be,{size:"sm",type:"button",variant:"ghost",onClick:()=>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:xe("py-1",c?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsx("div",{className:xe("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:xe("flex items-center gap-2",c?"w-full":"w-fit"),children:[s.jsx(En,{value:N,onValueChange:E,min:9,max:52,step:1,className:"w-16"}),s.jsx(be,{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:xe("py-1",c?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsx("div",{className:xe("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:xe("flex items-center gap-2",c?"w-full":"w-fit"),children:[s.jsx(En,{value:U,onValueChange:B,min:50,max:200,step:5,className:"w-16"}),s.jsx(be,{size:"sm",type:"button",variant:"ghost",onClick:()=>B(100),disabled:U===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:xe("py-1",c?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsx("div",{className:xe("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(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:i("settings.openchamber.visual.field.inputBarOffsetTooltip")})]})]})}),s.jsxs("div",{className:xe("flex items-center gap-2",c?"w-full":"w-fit"),children:[s.jsx(En,{value:z,onValueChange:K,min:0,max:100,step:5,className:"w-16"}),s.jsx(be,{size:"sm",type:"button",variant:"ghost",onClick:()=>K(0),disabled:z===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"})})]})]})]})]})}),Wt&&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":ue,onClick:()=>W(!ue),onKeyDown:se=>{(se.key===" "||se.key==="Enter")&&(se.preventDefault(),W(!ue))},children:[s.jsx(fs,{checked:ue,onChange:W,ariaLabel:i("settings.openchamber.visual.field.terminalQuickKeysAria")}),s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.terminalQuickKeys")}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:i("settings.openchamber.visual.field.terminalQuickKeysTooltip")})]})]})]})]})}),We&&s.jsxs("div",{className:"space-y-3",children:[(mt("userMessageRendering")||mt("mermaidRendering")||mt("chatRenderMode")||mt("messageTransport")||mt("activityRenderMode")&&j==="sorted"||mt("diffLayout")&&!Et)&&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:Y5.map(se=>{const xt=j===se.id,Je=Me%12;return s.jsxs("button",{type:"button",onClick:()=>Ve(se.id),"aria-pressed":xt,className:xe("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",xt?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[s.jsx("span",{className:xe("typography-ui-label",xt?"text-foreground":"text-muted-foreground"),children:o(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(_t=>{const Gt=_t*3+1,is=Je-Gt+1,Ue=is<=0?0:is===1?42:is===2?68:92,gt=Ue>0;return s.jsxs("div",{className:xe("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",gt?"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:`${Ue}%`}})]},_t)})}):s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(_t=>{const Gt=Je>=(_t+1)*3;return s.jsxs("div",{className:xe("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",Gt?"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%"}})]},_t)})})})]},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:Ip.map(se=>s.jsx(be,{variant:"chip",size:"xs","aria-pressed":Pe===se.id,className:"!font-normal",onClick:()=>qe(se.id),children:o(se.labelKey)},se.id))}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:(()=>{const se=Ip.find(xt=>xt.id===Pe);return se?.descriptionKey?o(se.descriptionKey):""})()})]})]}),mt("activityRenderMode")&&j==="sorted"&&s.jsxs("section",{className:"p-2 md:col-span-2",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.activityDefault")}),s.jsx("div",{role:"radiogroup","aria-label":i("settings.openchamber.visual.section.activityDefaultAria"),className:"mt-0.5 space-y-0",children:Q5.map(se=>{const xt=I===se.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":xt,onClick:()=>lt(se.id),onKeyDown:Je=>{(Je.key===" "||Je.key==="Enter")&&(Je.preventDefault(),lt(se.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Ja,{checked:xt,onChange:()=>lt(se.id),ariaLabel:i("settings.openchamber.visual.field.activityDefaultModeAria",{option:o(se.labelKey)})}),s.jsx("span",{className:xe("typography-ui-label font-normal",xt?"text-foreground":"text-foreground/50"),children:o(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":me,onClick:()=>et(!me),onKeyDown:se=>{(se.key===" "||se.key==="Enter")&&(se.preventDefault(),et(!me))},children:[s.jsx(fs,{checked:me,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":ie,onClick:()=>yt(!ie),onKeyDown:se=>{(se.key===" "||se.key==="Enter")&&(se.preventDefault(),yt(!ie))},children:[s.jsx(fs,{checked:ie,onChange:yt,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:J5.map(se=>{const xt=X5(x)===se.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":xt,onClick:()=>rt(se.id),onKeyDown:Je=>{(Je.key===" "||Je.key==="Enter")&&(Je.preventDefault(),rt(se.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Ja,{checked:xt,onChange:()=>rt(se.id),ariaLabel:i("settings.openchamber.visual.field.userMessageRenderingAria",{option:o(se.labelKey)})}),s.jsx("span",{className:xe("typography-ui-label font-normal",xt?"text-foreground":"text-foreground/50"),children:o(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:q5.map(se=>{const xt=h===se.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":xt,onClick:()=>He(se.id),onKeyDown:Je=>{(Je.key===" "||Je.key==="Enter")&&(Je.preventDefault(),He(se.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Ja,{checked:xt,onChange:()=>He(se.id),ariaLabel:i("settings.openchamber.visual.field.mermaidRenderingAria",{option:o(se.labelKey)})}),s.jsx("span",{className:xe("typography-ui-label font-normal",xt?"text-foreground":"text-foreground/50"),children:o(se.labelKey)})]},se.id)})})]}),mt("diffLayout")&&!Et&&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:H5.map(se=>{const xt=Q===se.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":xt,onClick:()=>te(se.id),onKeyDown:Je=>{(Je.key===" "||Je.key==="Enter")&&(Je.preventDefault(),te(se.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Ja,{checked:xt,onChange:()=>te(se.id),ariaLabel:i("settings.openchamber.visual.field.diffLayoutAria",{option:o(se.labelKey)})}),s.jsx("span",{className:xe("typography-ui-label font-normal",xt?"text-foreground":"text-foreground/50"),children:o(se.labelKey)})]},se.id)})})]}),mt("diffLayout")&&!Et&&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:G5.map(se=>{const xt=Z===se.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":xt,onClick:()=>fe(se.id),onKeyDown:Je=>{(Je.key===" "||Je.key==="Enter")&&(Je.preventDefault(),fe(se.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Ja,{checked:xt,onChange:()=>fe(se.id),ariaLabel:i("settings.openchamber.visual.field.diffViewModeAria",{option:o(se.labelKey)})}),s.jsx("span",{className:xe("typography-ui-label font-normal",xt?"text-foreground":"text-foreground/50"),children:o(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(fs,{checked:m,onChange:u,ariaLabel:i("settings.openchamber.visual.field.showReasoningTracesAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showReasoningTraces")})]}),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(fs,{checked:f,onChange:b,ariaLabel:i("settings.openchamber.visual.field.collapsibleThinkingBlocksAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.collapsibleThinkingBlocks")})]}),mt("stickyUserHeader")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":w,onClick:()=>it(!w),onKeyDown:se=>{(se.key===" "||se.key==="Enter")&&(se.preventDefault(),it(!w))},children:[s.jsx(fs,{checked:w,onChange:it,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:()=>nt(!C),onKeyDown:se=>{(se.key===" "||se.key==="Enter")&&(se.preventDefault(),nt(!C))},children:[s.jsx(fs,{checked:C,onChange:nt,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":we,onClick:()=>Ne(!we),onKeyDown:se=>{(se.key===" "||se.key==="Enter")&&(se.preventDefault(),Ne(!we))},children:[s.jsx(fs,{checked:we,onChange:Ne,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(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(D,{name:"information",className:"h-3.5 w-3.5 cursor-help text-muted-foreground/60"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:i("settings.openchamber.visual.field.showSplitAssistantMessageActionsTooltip")})]})]})]}),mt("showToolFileIcons")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":oe,onClick:()=>ze(!oe),onKeyDown:se=>{(se.key===" "||se.key==="Enter")&&(se.preventDefault(),ze(!oe))},children:[s.jsx(fs,{checked:oe,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":Y,onClick:()=>re(!Y),onKeyDown:se=>{(se.key===" "||se.key==="Enter")&&(se.preventDefault(),re(!Y))},children:[s.jsx(fs,{checked:Y,onChange:re,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")&&!on()&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":p,onClick:()=>Wo(!p),onKeyDown:se=>{(se.key===" "||se.key==="Enter")&&(se.preventDefault(),Wo(!p))},children:[s.jsx(fs,{checked:p,onChange:Wo,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":q,onClick:()=>J(!q),onKeyDown:se=>{(se.key===" "||se.key==="Enter")&&(se.preventDefault(),J(!q))},children:[s.jsx(fs,{checked:q,onChange:J,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(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:i("settings.openchamber.visual.field.queueMessagesByDefaultTooltip",{modifier:dl()})})]})]})]}),mt("persistDraft")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":ne,onClick:()=>ee(!ne),onKeyDown:se=>{(se.key===" "||se.key==="Enter")&&(se.preventDefault(),ee(!ne))},children:[s.jsx(fs,{checked:ne,onChange:ee,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":he,onClick:()=>Ke(!he),onKeyDown:se=>{(se.key===" "||se.key==="Enter")&&(se.preventDefault(),Ke(!he))},children:[s.jsx(fs,{checked:he,onChange:Ke,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(fs,{checked:at,onChange:Xe,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":at,onClick:()=>Xe(!at),onKeyDown:se=>{(se.key===" "||se.key==="Enter")&&(se.preventDefault(),Xe(!at))},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 Z5(){if(typeof window>"u")return"unknown";try{const{deviceType:t}=Qb();return t}catch{return"unknown"}}function eC(){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 tC(){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 sC(t){const e=Re.getState().reportUsage,n=new URLSearchParams({reportUsage:e?"true":"false"});return n.set("deviceClass",Z5()),n.set("arch",eC()),n.set("platform",tC()),t==="desktop"?(n.set("appType",Yb()?"desktop-electron":"desktop-tauri"),n.set("instanceMode",Qr()?"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 Pc(t,e){try{const n=sC(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 nC(){return Ea()?Qr()?"desktop":"web":on()?"vscode":Yr()?"web":null}const Dp={checking:!1,available:!1,downloading:!1,downloaded:!1,info:null,progress:null,error:null,runtimeType:null,lastChecked:null,nextCheckInSec:null},Ta=Zn()((t,e)=>({...Dp,checkForUpdates:async()=>{const n=nC();if(!n)return null;t({checking:!0,error:null,runtimeType:n});try{let r=null,a=null;if(n==="desktop"){let i=await Ql();t({checking:!1,available:i?.available??!1,info:i,lastChecked:Date.now(),nextCheckInSec:null});const o=await Pc("desktop",i?.currentVersion);if(a=o?.nextSuggestedCheckInSec??null,o?.available&&!i?.available){const c=await Ql();c&&(i=c)}if(o){const c={...i??{available:!1,currentVersion:o.currentVersion??"unknown"},...o,currentVersion:i?.currentVersion??o.currentVersion??"unknown",available:o.available};t({available:c.available,info:c,nextCheckInSec:a})}else t({nextCheckInSec:a});return a}else n==="web"?(r=await Pc("web"),a=r?.nextSuggestedCheckInSec??null):n==="vscode"&&(a=(await Pc("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 Ql();if(!a?.available)throw new Error("Update detected, but desktop package is not ready yet. Retry in a moment.");if(t(o=>({info:o.info?{...o.info,...a,body:o.info.body||a.body,available:o.info.available}:a})),!await Jb(o=>{t({progress:o})}))throw new Error("Desktop update only works on Local instance");t({downloading:!1,downloaded:!0})}catch(a){t({downloading:!1,error:a instanceof Error?a.message:"Failed to download update"})}}},restartToUpdate:async()=>{const{downloaded:n,runtimeType:r}=e();if(!(r!=="desktop"||!n))try{if(!await qb())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(Dp)}})),Tp="https://github.com/btriapitsyn/openchamber/releases";function rC(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 aC(t){return t.replace(/^## \[[^\]]+\] - \d{4}-\d{2}-\d{2}\s*\n?/,"").trim()}function Mp(t){return t.replace(/(^|[^a-zA-Z0-9])@([a-zA-Z0-9-]+)/g,"$1[@$2](https://github.com/$2)")}function iC(t,e){const n=t.split(".").map(a=>Number.parseInt(a,10)),r=e.split(".").map(a=>Number.parseInt(a,10));for(let a=0;a<3;a+=1){const i=Number.isFinite(n[a])?n[a]:0,o=Number.isFinite(r[a])?r[a]:0;if(i!==o)return o-i}return 0}function oC(t){const e=/^## \[(\d+\.\d+\.\d+)\] - (\d{4}-\d{2}-\d{2})\s*$/gm,n=[];let r;for(;(r=e.exec(t))!==null;)n.push({version:r[1]??"",date:r[2]??"",start:r.index});return n.length===0?[]:n.map((a,i)=>{const o=n[i+1]?.start??t.length,c=t.slice(a.start,o).trim();return{version:a.version,date:a.date,start:a.start,end:o,raw:c}})}const Ep=2e3,lC=600*1e3;async function cC(){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 dC(){try{return(await fetch("/health",{method:"GET",headers:{Accept:"application/json"}})).ok}catch{return!1}}async function uC(t,e=Math.ceil(lC/Ep),n=Ep){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 dC())return!0}catch{}await new Promise(a=>setTimeout(a,n))}return!1}const bd=({open:t,onOpenChange:e,info:n,downloading:r,downloaded:a,progress:i,error:o,onDownload:c,onRestart:d,runtimeType:p="desktop"})=>{const{t:m}=dt(),[u,f]=Oe.useState(!1),[b,h]=Oe.useState("idle"),[v,x]=Oe.useState(null),g=n?.version?`${Tp}/tag/v${n.version}`:Tp,w=i?.total?Math.round(i.downloaded/i.total*100):0,y=p==="web",C=n?.updateCommand||"openchamber update";Oe.useEffect(()=>{t||(h("idle"),x(null))},[t]);const k=async()=>{(await In(C)).ok&&(f(!0),setTimeout(()=>f(!1),2e3))},j=Oe.useCallback(async P=>{await qn(P)},[]),S=Oe.useCallback(async()=>{h("updating"),x(null);const P=await cC();if(!P.success){h("error"),x(P.error||m("updateDialog.error.updateFailed"));return}P.autoRestart&&(h("restarting"),await new Promise(N=>setTimeout(N,2e3))),h("reconnecting"),await uC(n?.currentVersion)?window.location.reload():(h("error"),x(m("updateDialog.error.takingLonger")))},[n?.currentVersion,m]),I=b!=="idle"&&b!=="error",M=Oe.useMemo(()=>{if(!n?.body)return null;const P=n.body.trim();if(!P)return null;const A=oC(P);if(A.length===0)return{kind:"raw",title:m("updateDialog.changelog.title"),content:Mp(P)};const N=[...A].sort((E,T)=>iC(E.version,T.version));return{kind:"sections",title:m("updateDialog.changelog.title"),sections:N.map(E=>({version:E.version,dateLabel:rC(E.date),content:Mp(aC(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(hs,{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")})]}),M&&!I&&s.jsx("div",{className:"rounded-lg border border-[var(--surface-subtle)] bg-[var(--surface-elevated)]/20 overflow-hidden",children:s.jsx(Ns,{className:"max-h-[400px] p-0",fillContainer:!1,children:M.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(),j(N.href))},children:s.jsx(Fa,{content:M.content,disableLinkSafety:!0})}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:M.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(),j(E.href))},children:s.jsx(Fa,{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:xe("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:[w,"%"]})]}),s.jsx("div",{className:"h-1.5 bg-[var(--surface-subtle)] rounded-full overflow-hidden",children:s.jsx("div",{className:"h-full bg-[var(--primary-base)] transition-all duration-300",style:{width:`${w}%`}})})]}),(o||v)&&s.jsx("div",{className:"p-3 mt-4 bg-[var(--status-error-background)] border border-[var(--status-error-border)] rounded-lg",children:s.jsx("p",{className:"text-sm text-[var(--status-error)]",children:o||v})})]}),s.jsxs("div",{className:"mt-4 flex items-center justify-between gap-4",children:[s.jsxs("a",{href:g,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground transition-colors shrink-0",children:[s.jsx(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")]})]})]})]})})},Rp="https://github.com/btriapitsyn/openchamber",mC=800,pC=()=>{const t=st.c(103),{t:e}=dt(),[n,r]=l.useState(!1),[a,i]=l.useState(!1),o=Ta(Jn(fC)),{isMobile:c}=nn(),d=o.info?.currentVersion||"unknown",p=l.useRef(!1);let m,u;t[0]!==a||t[1]!==e||t[2]!==o.available||t[3]!==o.checking||t[4]!==o.error?(m=()=>{if(o.checking)i(!0),p.current=!0;else if(a){const U=setTimeout(()=>{i(!1),p.current&&!o.available&&!o.error&&(H.success(e("settings.openchamber.about.toast.latestVersion")),p.current=!1)},mC);return()=>clearTimeout(U)}},u=[e,o.checking,a,o.available,o.error],t[0]=a,t[1]=e,t[2]=o.available,t[3]=o.checking,t[4]=o.error,t[5]=m,t[6]=u):(m=t[5],u=t[6]),l.useEffect(m,u);const f=o.checking||a;if(c){let U;t[7]!==d?(U=s.jsxs("span",{className:"typography-meta text-muted-foreground",children:["v",d]}),t[7]=d,t[8]=U):U=t[8];let B;t[9]!==f||t[10]!==e||t[11]!==o?(B=!o.available&&!o.error&&s.jsx("button",{onClick:()=>o.checkForUpdates(),disabled:f,className:xe("typography-meta text-muted-foreground/60 hover:text-muted-foreground disabled:cursor-default",f&&"animate-pulse [animation-duration:1s]"),children:e("settings.openchamber.about.actions.checkUpdates")}),t[9]=f,t[10]=e,t[11]=o,t[12]=B):B=t[12];let z;t[13]!==f||t[14]!==e||t[15]!==o.available?(z=!f&&o.available&&s.jsxs("button",{onClick:()=>r(!0),className:"flex items-center gap-1 typography-meta text-[var(--primary-base)] hover:underline",children:[s.jsx(D,{name:"download",className:"h-3.5 w-3.5"}),e("settings.openchamber.about.actions.update")]}),t[13]=f,t[14]=e,t[15]=o.available,t[16]=z):z=t[16];let K;t[17]!==U||t[18]!==B||t[19]!==z?(K=s.jsxs("div",{className:"flex items-center justify-between",children:[U,B,z]}),t[17]=U,t[18]=B,t[19]=z,t[20]=K):K=t[20];let F;t[21]!==o.error?(F=o.error&&s.jsx("p",{className:"typography-micro text-[var(--status-error)] truncate",children:o.error}),t[21]=o.error,t[22]=F):F=t[22];let G;t[23]===Symbol.for("react.memo_cache_sentinel")?(G=s.jsxs("a",{href:Rp,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]=G):G=t[23];let Q;t[24]===Symbol.for("react.memo_cache_sentinel")?(Q=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]=Q):Q=t[24];let te;t[25]===Symbol.for("react.memo_cache_sentinel")?(te=s.jsxs("div",{className:"flex items-center gap-3",children:[G,Q,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]=te):te=t[25];let Z;t[26]!==n||t[27]!==o.downloadUpdate||t[28]!==o.downloaded||t[29]!==o.downloading||t[30]!==o.error||t[31]!==o.info||t[32]!==o.progress||t[33]!==o.restartToUpdate||t[34]!==o.runtimeType?(Z=s.jsx(bd,{open:n,onOpenChange:r,info:o.info,downloading:o.downloading,downloaded:o.downloaded,progress:o.progress,error:o.error,onDownload:o.downloadUpdate,onRestart:o.restartToUpdate,runtimeType:o.runtimeType}),t[26]=n,t[27]=o.downloadUpdate,t[28]=o.downloaded,t[29]=o.downloading,t[30]=o.error,t[31]=o.info,t[32]=o.progress,t[33]=o.restartToUpdate,t[34]=o.runtimeType,t[35]=Z):Z=t[35];let fe;return t[36]!==Z||t[37]!==K||t[38]!==F?(fe=s.jsxs("div",{className:"w-full space-y-2",children:[K,F,te,Z]}),t[36]=Z,t[37]=K,t[38]=F,t[39]=fe):fe=t[39],fe}let b;t[40]!==e?(b=e("settings.openchamber.about.title"),t[40]=e,t[41]=b):b=t[41];let h;t[42]!==b?(h=s.jsx("div",{className:"mb-3 px-1",children:s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:b})}),t[42]=b,t[43]=h):h=t[43];let v;t[44]!==e?(v=e("settings.openchamber.about.field.version"),t[44]=e,t[45]=v):v=t[45];let x;t[46]!==v?(x=s.jsx("span",{className:"typography-ui-label text-foreground",children:v}),t[46]=v,t[47]=x):x=t[47];let g;t[48]!==d?(g=s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:d}),t[48]=d,t[49]=g):g=t[49];let w;t[50]!==x||t[51]!==g?(w=s.jsxs("div",{className:"flex min-w-0 flex-col",children:[x,g]}),t[50]=x,t[51]=g,t[52]=w):w=t[52];let y;t[53]!==e||t[54]!==o.checking?(y=o.checking&&s.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[s.jsx(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]=o.checking,t[55]=y):y=t[55];let C;t[56]!==e||t[57]!==o.available||t[58]!==o.checking||t[59]!==o.info?.version?(C=!o.checking&&o.available&&s.jsxs(be,{size:"sm",variant:"default",onClick:()=>r(!0),children:[s.jsx(D,{name:"download",className:"h-4 w-4 mr-1"}),e("settings.openchamber.about.actions.updateToVersion",{version:o.info?.version||""})]}),t[56]=e,t[57]=o.available,t[58]=o.checking,t[59]=o.info?.version,t[60]=C):C=t[60];let k;t[61]!==e||t[62]!==o.available||t[63]!==o.checking||t[64]!==o.error?(k=!o.checking&&!o.available&&!o.error&&s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.about.state.upToDate")}),t[61]=e,t[62]=o.available,t[63]=o.checking,t[64]=o.error,t[65]=k):k=t[65];let j;t[66]!==o?(j=()=>o.checkForUpdates(),t[66]=o,t[67]=j):j=t[67];const S=o.checking;let I;t[68]!==e?(I=e("settings.openchamber.about.actions.checkForUpdates"),t[68]=e,t[69]=I):I=t[69];let M;t[70]!==j||t[71]!==I||t[72]!==o.checking?(M=s.jsx(be,{size:"sm",variant:"outline",onClick:j,disabled:S,children:I}),t[70]=j,t[71]=I,t[72]=o.checking,t[73]=M):M=t[73];let P;t[74]!==k||t[75]!==M||t[76]!==y||t[77]!==C?(P=s.jsxs("div",{className:"flex items-center gap-3",children:[y,C,k,M]}),t[74]=k,t[75]=M,t[76]=y,t[77]=C,t[78]=P):P=t[78];let A;t[79]!==P||t[80]!==w?(A=s.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4 px-4 py-3 border-b border-[var(--surface-subtle)]",children:[w,P]}),t[79]=P,t[80]=w,t[81]=A):A=t[81];let N;t[82]!==o.error?(N=o.error&&s.jsx("div",{className:"px-3 py-2 border-b border-[var(--surface-subtle)]",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:o.error})}),t[82]=o.error,t[83]=N):N=t[83];let E;t[84]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsxs("a",{href:Rp,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 T;t[85]===Symbol.for("react.memo_cache_sentinel")?(T=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]=T):T=t[85];let R;t[86]!==A||t[87]!==N?(R=s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[A,N,T]}),t[86]=A,t[87]=N,t[88]=R):R=t[88];let V;t[89]!==n||t[90]!==o.downloadUpdate||t[91]!==o.downloaded||t[92]!==o.downloading||t[93]!==o.error||t[94]!==o.info||t[95]!==o.progress||t[96]!==o.restartToUpdate||t[97]!==o.runtimeType?(V=s.jsx(bd,{open:n,onOpenChange:r,info:o.info,downloading:o.downloading,downloaded:o.downloaded,progress:o.progress,error:o.error,onDownload:o.downloadUpdate,onRestart:o.restartToUpdate,runtimeType:o.runtimeType}),t[89]=n,t[90]=o.downloadUpdate,t[91]=o.downloaded,t[92]=o.downloading,t[93]=o.error,t[94]=o.info,t[95]=o.progress,t[96]=o.restartToUpdate,t[97]=o.runtimeType,t[98]=V):V=t[98];let _;return t[99]!==R||t[100]!==V||t[101]!==h?(_=s.jsxs("div",{className:"mb-8",children:[h,R,V]}),t[99]=R,t[100]=V,t[101]=h,t[102]=_):_=t[102],_};function fC(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 hC=1,gC=365,Fp=30,xC=[{value:"archive",labelKey:"settings.openchamber.sessionRetention.action.archive"},{value:"delete",labelKey:"settings.openchamber.sessionRetention.action.delete"}],jg=()=>{const t=st.c(113),{t:e}=dt(),n=Re(bC),r=Re(yC),a=Re(vC),i=Re(wC),o=Re(jC),c=Re(NC);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}=Xb(d),b=p.length;let h;t[1]!==u||t[2]!==e?(h=async()=>{const X=await u({force:!0});if(X.completedIds.length===0&&X.failedIds.length===0){H.message(X.action==="archive"?e("settings.openchamber.sessionRetention.toast.noneEligibleArchive"):e("settings.openchamber.sessionRetention.toast.noneEligibleDelete"));return}X.completedIds.length>0&&H.success(X.action==="archive"?e("settings.openchamber.sessionRetention.toast.archivedCount",{count:X.completedIds.length}):e("settings.openchamber.sessionRetention.toast.deletedCount",{count:X.completedIds.length})),X.failedIds.length>0&&H.error(X.action==="archive"?e("settings.openchamber.sessionRetention.toast.failedArchiveCount",{count:X.failedIds.length}):e("settings.openchamber.sessionRetention.toast.failedDeleteCount",{count:X.failedIds.length}))},t[1]=u,t[2]=e,t[3]=h):h=t[3];const v=h;let x;t[4]!==e?(x=e("settings.openchamber.sessionRetention.title"),t[4]=e,t[5]=x):x=t[5];let g;t[6]!==x?(g=s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:x}),t[6]=x,t[7]=g):g=t[7];let w;t[8]===Symbol.for("react.memo_cache_sentinel")?(w=s.jsx(It,{asChild:!0,children:s.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t[8]=w):w=t[8];let y;t[9]!==e?(y=e("settings.openchamber.sessionRetention.tooltip"),t[9]=e,t[10]=y):y=t[10];let C;t[11]!==y?(C=s.jsxs(Ct,{children:[w,s.jsx(At,{sideOffset:8,className:"max-w-xs",children:y})]}),t[11]=y,t[12]=C):C=t[12];let k;t[13]!==g||t[14]!==C?(k=s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[g,C]})}),t[13]=g,t[14]=C,t[15]=k):k=t[15];let j,S;t[16]!==n||t[17]!==i?(j=()=>i(!n),S=X=>{(X.key===" "||X.key==="Enter")&&(X.preventDefault(),i(!n))},t[16]=n,t[17]=i,t[18]=j,t[19]=S):(j=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 M;t[22]!==n||t[23]!==i||t[24]!==I?(M=s.jsx(fs,{checked:n,onChange:i,ariaLabel:I}),t[22]=n,t[23]=i,t[24]=I,t[25]=M):M=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]!==M||t[32]!==A||t[33]!==j||t[34]!==S?(N=s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":n,onClick:j,onKeyDown:S,children:[M,A]}),t[30]=n,t[31]=M,t[32]=A,t[33]=j,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 T;t[38]!==E?(T=s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:E})}),t[38]=E,t[39]=T):T=t[39];let R;t[40]!==e?(R=e("settings.openchamber.sessionRetention.field.retentionPeriodAria"),t[40]=e,t[41]=R):R=t[41];let V;t[42]!==r||t[43]!==o||t[44]!==R?(V=s.jsx(En,{value:r,onValueChange:o,min:hC,max:gC,step:1,"aria-label":R,className:"w-20 tabular-nums"}),t[42]=r,t[43]=o,t[44]=R,t[45]=V):V=t[45];let _;t[46]!==e?(_=e("settings.openchamber.sessionRetention.field.days"),t[46]=e,t[47]=_):_=t[47];let U;t[48]!==_?(U=s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:_}),t[48]=_,t[49]=U):U=t[49];let B;t[50]!==o?(B=()=>o(Fp),t[50]=o,t[51]=B):B=t[51];const z=r===Fp;let K;t[52]!==e?(K=e("settings.openchamber.sessionRetention.actions.resetRetentionAria"),t[52]=e,t[53]=K):K=t[53];let F;t[54]!==e?(F=e("settings.common.actions.reset"),t[54]=e,t[55]=F):F=t[55];let G;t[56]===Symbol.for("react.memo_cache_sentinel")?(G=s.jsx(D,{name:"restart",className:"h-3.5 w-3.5"}),t[56]=G):G=t[56];let Q;t[57]!==B||t[58]!==z||t[59]!==K||t[60]!==F?(Q=s.jsx(be,{size:"sm",type:"button",variant:"ghost",onClick:B,disabled:z,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":K,title:F,children:G}),t[57]=B,t[58]=z,t[59]=K,t[60]=F,t[61]=Q):Q=t[61];let te;t[62]!==V||t[63]!==U||t[64]!==Q?(te=s.jsxs("div",{className:"flex items-center gap-2 sm:w-fit",children:[V,U,Q]}),t[62]=V,t[63]=U,t[64]=Q,t[65]=te):te=t[65];let Z;t[66]!==T||t[67]!==te?(Z=s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[T,te]}),t[66]=T,t[67]=te,t[68]=Z):Z=t[68];let fe;t[69]!==e?(fe=e("settings.openchamber.sessionRetention.field.whenSessionsExpire"),t[69]=e,t[70]=fe):fe=t[70];let ue;t[71]!==fe?(ue=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:fe})}),t[71]=fe,t[72]=ue):ue=t[72];let W;t[73]!==a||t[74]!==c||t[75]!==e?(W=xC.map(X=>s.jsx(be,{type:"button",variant:"chip",size:"xs","aria-pressed":a===X.value,className:"!font-normal",onClick:()=>c(X.value),children:e(X.labelKey)},X.value)),t[73]=a,t[74]=c,t[75]=e,t[76]=W):W=t[76];let q;t[77]!==W?(q=s.jsx("div",{className:"flex flex-wrap items-center gap-1 sm:w-fit",children:W}),t[77]=W,t[78]=q):q=t[78];let J;t[79]!==ue||t[80]!==q?(J=s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[ue,q]}),t[79]=ue,t[80]=q,t[81]=J):J=t[81];let ne;t[82]!==N||t[83]!==Z||t[84]!==J?(ne=s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[N,Z,J]}),t[82]=N,t[83]=Z,t[84]=J,t[85]=ne):ne=t[85];let ee;t[86]!==e?(ee=e("settings.openchamber.sessionRetention.manualCleanup.title"),t[86]=e,t[87]=ee):ee=t[87];let he;t[88]!==ee?(he=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:ee})}),t[88]=ee,t[89]=he):he=t[89];let ke;t[90]!==m||t[91]!==e?(ke=e(m?"settings.openchamber.sessionRetention.actions.cleaningUp":"settings.openchamber.sessionRetention.actions.runCleanupNow"),t[90]=m,t[91]=e,t[92]=ke):ke=t[92];let oe;t[93]!==v||t[94]!==m||t[95]!==ke?(oe=s.jsx("div",{className:"flex items-center gap-2 sm:w-fit",children:s.jsx(be,{type:"button",variant:"outline",size:"xs",onClick:v,disabled:m,className:"!font-normal",children:ke})}),t[93]=v,t[94]=m,t[95]=ke,t[96]=oe):oe=t[96];let ge;t[97]!==he||t[98]!==oe?(ge=s.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-8",children:[he,oe]}),t[97]=he,t[98]=oe,t[99]=ge):ge=t[99];let me;t[100]!==f||t[101]!==b||t[102]!==e?(me=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]=me):me=t[103];let ye;t[104]!==me?(ye=s.jsx("p",{className:"typography-meta text-muted-foreground",children:me}),t[104]=me,t[105]=ye):ye=t[105];let ie;t[106]!==ge||t[107]!==ye?(ie=s.jsxs("div",{className:"mt-1 px-2 py-1.5 space-y-1",children:[ge,ye]}),t[106]=ge,t[107]=ye,t[108]=ie):ie=t[108];let ve;return t[109]!==ne||t[110]!==ie||t[111]!==k?(ve=s.jsxs("div",{className:"mb-8",children:[k,ne,ie]}),t[109]=ne,t[110]=ie,t[111]=k,t[112]=ve):ve=t[112],ve};function bC(t){return t.autoDeleteEnabled}function yC(t){return t.autoDeleteAfterDays}function vC(t){return t.sessionRetentionAction}function wC(t){return t.setAutoDeleteEnabled}function jC(t){return t.setAutoDeleteAfterDays}function NC(t){return t.setSessionRetentionAction}const Op=(t,e)=>!t||!Number.isFinite(t)?e:new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"}).format(t),Ng=()=>{const{t}=dt(),[e,n]=l.useState(!1),[r,a]=l.useState(!0),[i,o]=l.useState(!1),[c,d]=l.useState(null),[p,m]=l.useState(!1),[u,f]=l.useState([]),[b,h]=l.useState(Zb),[v,x]=l.useState(""),g=l.useMemo(()=>ey(),[]),w=l.useCallback(async()=>{a(!0),x("");try{const j=await ty();f(j)}catch(j){const S=j instanceof Error?j.message:t("settings.openchamber.passkeys.toast.loadFailed");x(S)}finally{a(!1)}},[t]);l.useEffect(()=>{let j=!1;return(async()=>{try{if(!g.supported){j||(n(!1),a(!1));return}j||n(!0)}catch{j||n(!1)}if(!j){const S=await Xl();if(h(S),!S.enabled){f([]),a(!1);return}await w()}})(),()=>{j=!0,Du()}},[w,g.supported]);const y=l.useCallback(async()=>{if(!b.enabled){const j=t("settings.openchamber.passkeys.toast.enableUiPasswordFirst");x(j),H.message(j);return}if(!e){x(g.reason),H.message(g.reason);return}if(i){Du(),o(!1);return}x(""),o(!0);try{await sy(),h(await Xl()),await w(),H.success(t("settings.openchamber.passkeys.toast.added"))}catch(j){if(ny(j)){H.message(t("settings.openchamber.passkeys.toast.setupCanceled"));return}const S=j instanceof Error?j.message:t("settings.openchamber.passkeys.toast.addFailed");x(S),H.error(S)}finally{o(!1)}},[i,w,b.enabled,g.reason,e,t]),C=l.useCallback(async j=>{d(j),x("");try{await ry(j),h(await Xl()),await w(),H.success(t("settings.openchamber.passkeys.toast.removed"))}catch(S){const I=S instanceof Error?S.message:t("settings.openchamber.passkeys.toast.removeFailed");x(I),H.error(I)}finally{d(null)}},[w,t]),k=l.useCallback(async()=>{m(!0),x("");try{await ay(),window.location.reload()}catch(j){const S=j instanceof Error?j.message:t("settings.openchamber.passkeys.toast.clearAuthFailed");x(S),H.error(S),m(!1)}},[t]);return s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.openchamber.passkeys.title")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.passkeys.field.currentDevice")})}),s.jsxs("div",{className:"flex items-center gap-2 sm:w-fit",children:[s.jsx(be,{type:"button",variant:i?"secondary":"outline",size:"xs",onClick:()=>{y()},disabled:r||p,className:"!font-normal",children:t(i?"settings.openchamber.passkeys.actions.cancelSetup":"settings.openchamber.passkeys.actions.add")}),s.jsx(be,{type:"button",variant:"ghost",size:"xs",onClick:()=>{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:g.reason}),r?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.loading")}):u.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.passkeys.state.noneSaved")}):s.jsx("div",{className:"space-y-1 pt-1",children:u.map(j=>s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:j.label})}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:j.lastUsedAt?t("settings.openchamber.passkeys.item.lastUsed",{time:Op(j.lastUsedAt,t("settings.openchamber.passkeys.time.neverUsed"))}):t("settings.openchamber.passkeys.item.added",{time:Op(j.createdAt,t("settings.openchamber.passkeys.time.neverUsed"))})}),s.jsx(be,{type:"button",variant:"ghost",size:"xs",onClick:()=>{C(j.id)},disabled:c===j.id,className:"!font-normal text-muted-foreground hover:text-foreground",children:c===j.id?t("settings.openchamber.passkeys.actions.removing"):t("settings.common.actions.delete")})]})]},j.id))})]}),v&&s.jsx("div",{className:"mt-1 px-2 py-1.5",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:v})})]})},SC=t=>{const e=pi(t);return e||{providerId:"",modelId:""}},Sg=()=>{const{t}=dt(),e=bt(T=>T.setProvider),n=bt(T=>T.setModel),r=bt(T=>T.setAgent),a=bt(T=>T.setCurrentVariant),i=bt(T=>T.setSettingsDefaultModel),o=bt(T=>T.setSettingsDefaultVariant),c=bt(T=>T.setSettingsDefaultAgent),d=bt(T=>T.setSettingsDefaultFileViewerPreview),p=bt(T=>T.settingsDefaultFileViewerPreview),m=Re(T=>T.showDeletionDialog),u=Re(T=>T.setShowDeletionDialog),f=bt(T=>T.providers),[b,h]=l.useState(),[v,x]=l.useState(),[g,w]=l.useState(),[y,C]=l.useState(!0),k=l.useMemo(()=>SC(b),[b]);l.useEffect(()=>{(async()=>{try{let R=null;if(!R){const V=Xn()?.settings;if(V)try{const U=(await V.load())?.settings;U&&(R={defaultModel:typeof U.defaultModel=="string"?U.defaultModel:void 0,defaultVariant:typeof U.defaultVariant=="string"?U.defaultVariant:void 0,defaultAgent:typeof U.defaultAgent=="string"?U.defaultAgent:void 0})}catch{}}if(!R){const V=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});V.ok&&(R=await V.json())}if(R){const V=typeof R.defaultModel=="string"&&R.defaultModel.trim().length>0?R.defaultModel.trim():void 0,_=typeof R.defaultVariant=="string"&&R.defaultVariant.trim().length>0?R.defaultVariant.trim():void 0,U=typeof R.defaultAgent=="string"&&R.defaultAgent.trim().length>0?R.defaultAgent.trim():void 0;V!==void 0&&h(V),_!==void 0&&x(_),U!==void 0&&w(U)}}catch(R){console.warn("Failed to load defaults settings:",R)}finally{C(!1)}})()},[]);const j=l.useCallback(async(T,R)=>{const V=T&&R?`${T}/${R}`:void 0;h(V),x(void 0),o(void 0),a(void 0),i(V),T&&R&&f.find(U=>U.id===T)&&(e(T),n(R));try{await Is({defaultModel:V??"",defaultVariant:""});const _=await fetch("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({defaultModel:V})});_.ok||console.warn("Failed to save default model to server:",_.status,_.statusText)}catch(_){console.warn("Failed to save default model:",_)}},[f,a,n,e,i,o]),S="__default__",I=l.useCallback(T=>T===S?t("settings.openchamber.defaults.option.default"):T.charAt(0).toUpperCase()+T.slice(1),[t]),M=l.useCallback(async T=>{const R=T===S?void 0:T||void 0;x(R),o(R),a(R);try{await Is({defaultVariant:R??""})}catch(V){console.warn("Failed to save default variant:",V)}},[a,o]),P=l.useCallback(async T=>{const R=T||void 0;w(R),c(R),T&&r(T);try{await Is({defaultAgent:R??""})}catch(V){console.warn("Failed to save default agent:",V)}},[r,c]),A=l.useCallback(()=>{const T=!p;d(T),Is({defaultFileViewerPreview:T}).catch(console.warn)},[p,d]),N=l.useMemo(()=>{if(!k.providerId||!k.modelId)return[];const V=f.find(_=>_.id===k.providerId)?.models.find(_=>_.id===k.modelId)?.variants;return V?Object.keys(V):[]},[k.modelId,k.providerId,f]),E=N.length>0;return l.useEffect(()=>{!E&&v&&(x(void 0),o(void 0),a(void 0),Is({defaultVariant:""}).catch(()=>{}))},[v,a,o,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")}),g&&s.jsxs(s.Fragment,{children:[" / ",s.jsx("span",{className:"text-foreground",children:g})]})]}),s.jsxs("div",{className:xe("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(fo,{providerId:k.providerId,modelId:k.modelId,onChange:j})})]}),s.jsxs("div",{className:"flex flex-col gap-2 py-1 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.defaults.field.defaultThinking")})}),s.jsx("div",{className:"flex items-center gap-2 sm:w-fit",children:s.jsxs(os,{value:v??S,onValueChange:M,disabled:!E,children:[s.jsx(ls,{className:"w-fit min-w-[120px]",children:s.jsx(us,{placeholder:t("settings.openchamber.defaults.field.thinkingPlaceholder"),children:I(v??S)})}),s.jsxs(cs,{children:[s.jsx(Tt,{value:S,children:t("settings.openchamber.defaults.option.default")}),N.map(T=>s.jsx(Tt,{value:T,children:I(T)},T))]})]})})]}),s.jsxs("div",{className:"flex flex-col gap-2 py-1 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.defaults.field.defaultAgent")})}),s.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:s.jsx(Ll,{agentName:g||"",onChange:P})})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1",role:"button",tabIndex:0,"aria-pressed":m,onClick:()=>u(!m),onKeyDown:T=>{(T.key===" "||T.key==="Enter")&&(T.preventDefault(),u(!m))},children:[s.jsx(fs,{checked:m,onChange:u,ariaLabel:t("settings.openchamber.defaults.field.showDeletionDialogAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.defaults.field.showDeletionDialog")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1",role:"button",tabIndex:0,"aria-pressed":p,onClick:A,onKeyDown:T=>{(T.key===" "||T.key==="Enter")&&(T.preventDefault(),A())},children:[s.jsx(fs,{checked:p,onChange:d,ariaLabel:t("settings.openchamber.defaults.field.openFilesPreviewAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.defaults.field.openFilesPreview")})]})]})]})},Lp={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"}},kC={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"},CC=()=>{const{t}=dt(),e=l.useMemo(()=>vn(),[]),n=l.useMemo(()=>on(),[]),r=!e&&!n,a=Re(F=>F.nativeNotificationsEnabled),i=Re(F=>F.setNativeNotificationsEnabled),o=Re(F=>F.notificationMode),c=Re(F=>F.setNotificationMode),d=Re(F=>F.notifyOnSubtasks),p=Re(F=>F.setNotifyOnSubtasks),m=Re(F=>F.notifyOnCompletion),u=Re(F=>F.setNotifyOnCompletion),f=Re(F=>F.notifyOnError),b=Re(F=>F.setNotifyOnError),h=Re(F=>F.notifyOnQuestion),v=Re(F=>F.setNotifyOnQuestion),x=Re(F=>F.notificationTemplates),g=Re(F=>F.setNotificationTemplates),[w,y]=l.useState("default"),[C,k]=l.useState(!1),[j,S]=l.useState(!1),[I,M]=l.useState(!1);l.useEffect(()=>{if(!r){k(!1),S(!1);return}typeof Notification<"u"&&y(Notification.permission);const F=typeof window<"u"&&"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window;k(F),(async()=>{if(!F){S(!1);return}try{const Q=await navigator.serviceWorker.getRegistration();if(!Q){S(!1);return}const te=await Q.pushManager.getSubscription();S(!!te)}catch{S(!1)}})()},[r]);const P=async F=>{if(e){i(F);return}if(!r){i(F);return}if(F&&typeof Notification<"u"&&Notification.permission==="default")try{const G=await Notification.requestPermission();y(G),G==="granted"?i(!0):H.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.description")})}catch(G){console.error("Failed to request notification permission:",G),H.error(t("settings.notifications.page.toast.requestPermissionFailed"))}else i(!!(F&&w==="granted"))},A=e||n||r&&typeof Notification<"u"&&Notification.permission==="granted",N=(F,G,Q)=>{g({...x,[F]:{...x[F],[G]:Q}})},E=F=>{const G="=".repeat((4-F.length%4)%4),Q=(F+G).replace(/-/g,"+").replace(/_/g,"/"),te=atob(Q),Z=new Uint8Array(te.length);for(let fe=0;fe<te.length;fe+=1)Z[fe]=te.charCodeAt(fe);return Z},T=async(F,G,Q)=>{let te=null;const Z=new Promise((fe,ue)=>{te=setTimeout(()=>{ue(new Error(Q))},G)});try{return await Promise.race([F,Z])}finally{te&&clearTimeout(te)}},R=async F=>{if(F.active)return;const G=F.installing||F.waiting;G&&G.state!=="activated"&&await T(new Promise(Q=>{const te=()=>{G.state==="activated"&&(G.removeEventListener("statechange",te),Q())};G.addEventListener("statechange",te),te()}),15e3,"Service worker activation timed out")},V=async()=>{if(typeof navigator.serviceWorker.register!="function")throw new Error("navigator.serviceWorker.register unavailable");const F=[{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 G=null;for(const Q of F)try{const te=Q.opts?navigator.serviceWorker.register("/sw.js",Q.opts):navigator.serviceWorker.register("/sw.js");return await T(te,1e4,`Service worker registration timed out (${Q.label})`)}catch(te){G=te}throw G instanceof Error?G:new Error("Service worker registration failed")},_=async()=>{if(!("serviceWorker"in navigator))throw new Error("Service worker not supported");const F=await navigator.serviceWorker.getRegistration();if(F)return F;const G=await V();try{await G.update()}catch{}return await R(G),G},U=F=>{const G=F,Q=[`type=${typeof F}`,`toString=${String(F)}`,`name=${String(G?.name??"")}`,`message=${String(G?.message??"")}`];let te="";try{te=JSON.stringify(F)}catch{}return{summary:Q.filter(Boolean).join(" | "),json:te,stack:typeof G?.stack=="string"?G.stack:""}},B=async()=>{const F=Xn();if(!F?.notifications){H.error(t("settings.notifications.page.toast.notificationsApiUnavailable"));return}try{await F.notifications.notifyAgentCompletion({title:t("settings.notifications.page.testNotification.title"),body:t("settings.notifications.page.testNotification.body"),tag:"openchamber-test"})?H.success(t("settings.notifications.page.toast.testNotificationSent")):H.error(t("settings.notifications.page.toast.testNotificationFailed"))}catch(G){console.error("Test notification failed:",G),H.error(t("settings.notifications.page.toast.testNotificationFailed"))}},z=async()=>{if(!C){H.error(t("settings.notifications.page.toast.pushUnsupported"));return}const F=Xn();if(!F?.push){H.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}M(!0);try{if(typeof Notification<"u"&&Notification.permission==="default"){const q=await Notification.requestPermission();if(y(q),q!=="granted"){H.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}}if(typeof Notification<"u"&&Notification.permission!=="granted"){H.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}const G=await F.push.getVapidPublicKey();if(!G?.publicKey){H.error(t("settings.notifications.page.toast.pushKeyLoadFailed"));return}const Q=await _();await R(Q);const te=await Q.pushManager.getSubscription();if(!("pushManager"in Q)||!Q.pushManager)throw new Error("PushManager unavailable (requires installed PWA + iOS 16.4+)");const fe=(te??await T(Q.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:E(G.publicKey)}),15e3,"Push subscription timed out")).toJSON(),ue=fe.keys;if(!fe.endpoint||!ue?.p256dh||!ue.auth)throw new Error("Push subscription missing keys");if(!(await T(F.push.subscribe({endpoint:fe.endpoint,keys:{p256dh:ue.p256dh,auth:ue.auth},origin:typeof window<"u"?window.location.origin:void 0}),15e3,"Push subscribe request timed out"))?.ok){H.error(t("settings.notifications.page.toast.enableBackgroundFailed"));return}S(!0),H.success(t("settings.notifications.page.toast.backgroundEnabled"))}catch(G){console.error("[Push] Enable failed:",G);const Q=U(G);H.error(t("settings.notifications.page.toast.enableBackgroundFailed"),{description:Q.summary})}finally{M(!1)}},K=async()=>{if(!C){S(!1);return}const F=Xn();if(!F?.push){H.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}M(!0);try{const Q=await(await _()).pushManager.getSubscription();if(!Q){S(!1);return}const te=Q.endpoint;await Q.unsubscribe(),await F.push.unsubscribe({endpoint:te}),S(!1),H.success(t("settings.notifications.page.toast.backgroundDisabled"))}finally{M(!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:F=>{(F.key===" "||F.key==="Enter")&&(F.preventDefault(),P(!(a&&A)))},children:[s.jsx(fs,{checked:a&&A,onChange:F=>{P(F)},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":o==="always",onClick:()=>c(o==="always"?"hidden-only":"always"),onKeyDown:F=>{(F.key===" "||F.key==="Enter")&&(F.preventDefault(),c(o==="always"?"hidden-only":"always"))},children:[s.jsx(fs,{checked:o==="always",onChange:F=>c(F?"always":"hidden-only"),ariaLabel:t("settings.notifications.page.delivery.focusedAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.delivery.focusedLabel")})]}),s.jsx("div",{className:"py-2",children:s.jsx(be,{type:"button",variant:"outline",size:"sm",onClick:()=>{B()},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")}),w==="denied"&&s.jsx("p",{className:"typography-meta text-[var(--status-error)] mt-1",children:t("settings.notifications.page.delivery.permissionDenied")}),w==="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:F=>{(F.key===" "||F.key==="Enter")&&(F.preventDefault(),u(!m))},children:[s.jsx(fs,{checked:m,onChange:u,ariaLabel:t("settings.notifications.page.events.completionAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.events.completionLabel")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":d,onClick:()=>p(!d),onKeyDown:F=>{(F.key===" "||F.key==="Enter")&&(F.preventDefault(),p(!d))},children:[s.jsx(fs,{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:F=>{(F.key===" "||F.key==="Enter")&&(F.preventDefault(),b(!f))},children:[s.jsx(fs,{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":h,onClick:()=>v(!h),onKeyDown:F=>{(F.key===" "||F.key==="Enter")&&(F.preventDefault(),v(!h))},children:[s.jsx(fs,{checked:h,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(F=>s.jsxs("section",{className:"p-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground font-normal capitalize block",children:t(kC[F])}),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[F].title,onChange:G=>N(F,"title",G.target.value),className:"h-7",placeholder:t(Lp[F].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[F].message,onChange:G=>N(F,"message",G.target.value),className:"h-7",placeholder:t(Lp[F].messageKey)})]})]})]},F))})]})]}),r&&s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.notifications.page.push.title")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsxs("div",{className:"flex items-start gap-2 py-1.5",children:[s.jsx(fs,{checked:C?j:!1,disabled:!C||I,onChange:F=>{F?z():K()},ariaLabel:t("settings.notifications.page.push.enableAria")}),s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:xe("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")})})]})})]})]})},Vn=t=>{if(!t)return;t.pause();const{src:e}=t;e.startsWith("blob:")&&URL.revokeObjectURL(e),t.removeAttribute("src"),t.load()},IC=[{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:"Українська"}],PC=t=>{const e=st.c(45),{modelId:n}=t,{t:r}=dt();let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=_i.getModelStatus(),e[0]=a):a=e[0];const[i,o]=Oe.useState(a),[c,d]=Oe.useState(!1);let p,m;e[1]===Symbol.for("react.memo_cache_sentinel")?(p=()=>{const j=S=>o(S);return _i.onModelStatusChange=j,TC},m=[],e[1]=p,e[2]=m):(p=e[1],m=e[2]),Oe.useEffect(p,m);const u=_i.getCurrentModelId(),f=i.state==="downloading"||i.state==="loading";let b,h;e[3]!==i.state?(b=()=>{i.state!=="downloading"&&i.state!=="loading"&&d(!1)},h=[i.state],e[3]=i.state,e[4]=b,e[5]=h):(b=e[4],h=e[5]),Oe.useEffect(b,h);let v;e[6]!==n?(v=async()=>{d(!0);try{await _i.loadModel(n)}catch{}},e[6]=n,e[7]=v):v=e[7];const x=v;if(i.state==="ready"&&u===n){let j;e[8]!==r?(j=r("settings.voice.page.stt.wasmLoaded"),e[8]=r,e[9]=j):j=e[9];let S;return e[10]!==j?(S=s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("span",{className:"typography-ui-compact text-green-600 dark:text-green-400",children:j})}),e[10]=j,e[11]=S):S=e[11],S}if(f){let j;e[12]!==i.progress||e[13]!==i.state?(j=i.state==="downloading"?Math.round(i.progress):void 0,e[12]=i.progress,e[13]=i.state,e[14]=j):j=e[14];const S=j;let 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 M=S!==void 0?` (${S}%)`:"";let P;return e[18]!==I||e[19]!==M?(P=s.jsx("div",{className:"flex items-center gap-2",children:s.jsxs("span",{className:"typography-ui-compact text-muted-foreground",children:[I,M]})}),e[18]=I,e[19]=M,e[20]=P):P=e[20],P}if(i.state==="error"){let j;e[21]!==i.error?(j=s.jsx("span",{className:"typography-ui-compact text-destructive",children:i.error}),e[21]=i.error,e[22]=j):j=e[22];let S;e[23]!==r?(S=r("settings.voice.page.stt.wasmRetry"),e[23]=r,e[24]=S):S=e[24];let I;e[25]!==x||e[26]!==c||e[27]!==S?(I=s.jsx(be,{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 M;return e[29]!==j||e[30]!==I?(M=s.jsxs("div",{className:"flex items-center gap-2",children:[j,I]}),e[29]=j,e[30]=I,e[31]=M):M=e[31],M}let g;e[32]!==r?(g=r("settings.voice.page.stt.wasmNotLoaded"),e[32]=r,e[33]=g):g=e[33];let w;e[34]!==g?(w=s.jsx("span",{className:"typography-ui-compact text-muted-foreground",children:g}),e[34]=g,e[35]=w):w=e[35];let y;e[36]!==r?(y=r("settings.voice.page.stt.wasmDownload"),e[36]=r,e[37]=y):y=e[37];let C;e[38]!==x||e[39]!==c||e[40]!==y?(C=s.jsx(be,{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]!==w?(k=s.jsxs("div",{className:"flex items-center gap-2",children:[w,C]}),e[42]=C,e[43]=w,e[44]=k):k=e[44],k},AC=[{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"}],DC=()=>{const{t}=dt(),{isMobile:e}=nn(),{isSupported:n,language:r,setLanguage:a}=iy(),i=bt($=>$.voiceProvider),o=bt($=>$.setVoiceProvider),c=bt($=>$.speechRate),d=bt($=>$.setSpeechRate),p=bt($=>$.speechPitch),m=bt($=>$.setSpeechPitch),u=bt($=>$.speechVolume),f=bt($=>$.setSpeechVolume),b=bt($=>$.sayVoice),h=bt($=>$.setSayVoice),v=bt($=>$.browserVoice),x=bt($=>$.setBrowserVoice),g=bt($=>$.openaiVoice),w=bt($=>$.setOpenaiVoice),y=bt($=>$.openaiApiKey),C=bt($=>$.setOpenaiApiKey),k=bt($=>$.openaiCompatibleUrl),j=bt($=>$.setOpenaiCompatibleUrl),S=bt($=>$.openaiCompatibleVoice),I=bt($=>$.setOpenaiCompatibleVoice),M=bt($=>$.openaiCompatibleTtsModel),P=bt($=>$.setOpenaiCompatibleTtsModel),A=bt($=>$.showMessageTTSButtons),N=bt($=>$.sttProvider),E=bt($=>$.setSttProvider),T=bt($=>$.sttServerUrl),R=bt($=>$.setSttServerUrl),V=bt($=>$.sttModel),_=bt($=>$.setSttModel),U=bt($=>$.wasmSttModel),B=bt($=>$.setWasmSttModel),z=bt($=>$.sttLanguage),K=bt($=>$.setSttLanguage),F=bt($=>$.sttSilenceThresholdDb),G=bt($=>$.setSttSilenceThresholdDb),Q=bt($=>$.sttSilenceHoldMs),te=bt($=>$.setSttSilenceHoldMs),Z=bt($=>$.sttTranscribeOnStop),fe=bt($=>$.setSttTranscribeOnStop),ue=bt($=>$.setShowMessageTTSButtons),W=bt($=>$.voiceModeEnabled),q=bt($=>$.setVoiceModeEnabled),[J,ne]=Oe.useState(!1),[ee,he]=Oe.useState([]),[ke,oe]=Oe.useState(!1),[ge,me]=Oe.useState(null),[ye,ie]=Oe.useState(!1),[ve,X]=Oe.useState(!1),[Se,Ae]=Oe.useState(null),[pe,we]=Oe.useState(!1),[Ie,Y]=Oe.useState(null),[re,Pe]=Oe.useState([]),[ce,Ce]=Oe.useState(!1);Oe.useEffect(()=>((async()=>{const je=await Zl.waitForVoices();Pe(je)})(),"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=()=>{Pe(window.speechSynthesis.getVoices())}),()=>{"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=null)}),[]);const Te=Oe.useMemo(()=>re.filter($=>$.lang).sort(($,je)=>{const ae=$.lang.startsWith("en"),_e=je.lang.startsWith("en");if(ae&&!_e)return-1;if(!ae&&_e)return 1;const le=$.lang.localeCompare(je.lang);return le!==0?le:$.name.localeCompare(je.name)}),[re]),$e=Oe.useCallback(()=>{if(ce){Zl.cancelSpeech(),Ce(!1);return}const $=re.find(le=>le.name===v),je=$?.name??t("settings.voice.page.preview.browserVoiceFallback"),ae=t("settings.voice.page.preview.voiceLine",{voiceName:je});Ce(!0);const _e=new SpeechSynthesisUtterance(ae);_e.rate=c,_e.pitch=p,_e.volume=u,$&&(_e.voice=$,_e.lang=$.lang),_e.onend=()=>Ce(!1),_e.onerror=()=>Ce(!1),window.speechSynthesis.cancel(),window.speechSynthesis.speak(_e)},[v,re,c,p,u,ce,t]);Oe.useEffect(()=>()=>{ce&&Zl.cancelSpeech()},[ce]),Oe.useEffect(()=>{if(!W||i!=="openai"&&i!=="openai-compatible"){ie(y.trim().length>0);return}(async()=>{try{const _e=(await(await fetch("/api/tts/status")).json()).available,le=y.trim().length>0;ie(_e||le)}catch{ie(y.trim().length>0)}})()},[y,W,i]),Oe.useEffect(()=>{if(!W){ne(!1),he([]);return}fetch("/api/tts/say/status").then($=>$.json()).then($=>{if(ne($.available),$.voices){const je=$.voices.filter((ae,_e,le)=>le.findIndex(Me=>Me.name===ae.name)===_e).sort((ae,_e)=>ae.name.localeCompare(_e.name));he(je)}}).catch(()=>{ne(!1)})},[W]);const De=Oe.useCallback(async()=>{if(ge){Vn(ge),me(null),oe(!1);return}oe(!0);let $=null;try{const je=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(!je.ok)throw new Error("Preview failed");const ae=await je.blob(),_e=URL.createObjectURL(ae);$=new Audio(_e),$.onended=()=>{Vn($),me(null),oe(!1)},$.onerror=()=>{Vn($),me(null),oe(!1)},me($),await $.play()}catch{Vn($),me(null),oe(!1)}},[b,c,ge,t]);Oe.useEffect(()=>()=>{Vn(ge)},[ge]);const de=Oe.useCallback(async()=>{if(Se){Vn(Se),Ae(null),X(!1);return}X(!0);let $=null;try{const je=await fetch("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:g}),voice:g,speed:c,apiKey:y||void 0})});if(!je.ok){const le=await je.json().catch(()=>({error:"Unknown error"}));throw new Error(le.error||`HTTP ${je.status}`)}const ae=await je.blob(),_e=URL.createObjectURL(ae);$=new Audio(_e),$.onended=()=>{Vn($),Ae(null),X(!1)},$.onerror=()=>{Vn($),Ae(null),X(!1)},Ae($),await $.play()}catch{Vn($),Ae(null),X(!1)}},[g,c,Se,y,t]);Oe.useEffect(()=>()=>{Vn(Se)},[Se]);const O=Oe.useCallback(async()=>{if(Ie){Vn(Ie),Y(null),we(!1);return}if(!k.trim())return;we(!0);let $=null;try{const je=await fetch("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.customServerLine"),voice:S,model:M||void 0,speed:c,baseURL:k})});if(!je.ok){const le=await je.json().catch(()=>({error:"Unknown error"}));throw new Error(le.error||`HTTP ${je.status}`)}const ae=await je.blob(),_e=URL.createObjectURL(ae);$=new Audio(_e),$.onended=()=>{Vn($),Y(null),we(!1)},$.onerror=()=>{Vn($),Y(null),we(!1)},Y($),await $.play()}catch{Vn($),Y(null),we(!1)}},[k,S,M,c,Ie,t]);Oe.useEffect(()=>()=>{Vn(Ie)},[Ie]);const L="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":W,onClick:()=>q(!W),onKeyDown:$=>{($.key===" "||$.key==="Enter")&&($.preventDefault(),q(!W))},children:[s.jsx(fs,{checked:W,onChange:q,ariaLabel:t("settings.voice.page.field.enableVoiceModeAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.enableVoiceMode")})]}),W&&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(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:s.jsxs("ul",{className:"space-y-1",children:[s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.browser")})," ",t("settings.voice.page.tooltip.browser")]}),s.jsxs("li",{children:[s.jsx("strong",{children:"OpenAI:"})," ",t("settings.voice.page.tooltip.openai")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.custom")})," ",t("settings.voice.page.tooltip.custom")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.say")})," ",t("settings.voice.page.tooltip.say")]})]})})]})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[s.jsx(be,{variant:"chip",size:"xs","aria-pressed":i==="browser",onClick:()=>o("browser"),className:"!font-normal",children:t("settings.voice.page.provider.browser")}),s.jsx(be,{variant:"chip",size:"xs","aria-pressed":i==="openai",onClick:()=>o("openai"),className:"!font-normal",children:"OpenAI"}),s.jsx(be,{variant:"chip",size:"xs","aria-pressed":i==="openai-compatible",onClick:()=>o("openai-compatible"),className:"!font-normal",children:t("settings.voice.page.provider.custom")}),J&&s.jsxs(be,{variant:"chip",size:"xs","aria-pressed":i==="say",onClick:()=>o("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:xe("typography-ui-label text-foreground",!ye&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.apiKey")}),s.jsx("span",{className:xe("typography-meta ml-2",ye?"text-muted-foreground":"text-[var(--status-error)]/80"),children:t(ye&&!y?"settings.voice.page.field.apiKeyHintUsingConfig":ye?"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:$=>C($.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:xe("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:$=>j($.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:()=>j(""),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:M,onChange:$=>P($.target.value),placeholder:"speaches-ai/Kokoro-82M-v1.0-ONNX",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})})]}),s.jsxs("div",{children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.voice")}),s.jsx("span",{className:"typography-meta ml-2 text-muted-foreground",children:t("settings.voice.page.field.voiceIdentifierHint")}),s.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[s.jsx("div",{className:"relative max-w-xs flex-1",children:s.jsx("input",{type:"text",value:S,onChange:$=>I($.target.value),placeholder:"af_sky",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})}),s.jsx(be,{size:"xs",variant:"ghost",onClick:O,title:t("settings.voice.page.actions.preview"),disabled:!k.trim(),children:pe?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"&&ye&&s.jsxs(s.Fragment,{children:[s.jsxs(os,{value:g,onValueChange:w,children:[s.jsx(ls,{className:"w-fit",children:s.jsx(us,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(cs,{children:AC.map($=>s.jsx(Tt,{value:$.value,children:$.label},$.value))})]}),s.jsx(be,{size:"xs",variant:"ghost",onClick:de,title:t("settings.voice.page.actions.preview"),children:ve?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"&&J&&ee.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(os,{value:b,onValueChange:h,children:[s.jsx(ls,{className:"w-fit",children:s.jsx(us,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(cs,{children:ee.map($=>s.jsx(Tt,{value:$.name,children:$.name},$.name))})]}),s.jsx(be,{size:"xs",variant:"ghost",onClick:De,title:t("settings.voice.page.actions.preview"),children:ke?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"&&Te.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(os,{value:v||"$auto",onValueChange:$=>x($==="$auto"?"":$),children:[s.jsx(ls,{className:"w-fit max-w-[200px]",children:s.jsx(us,{placeholder:t("settings.voice.page.field.auto")})}),s.jsxs(cs,{children:[s.jsx(Tt,{value:"$auto",children:t("settings.voice.page.field.auto")}),Te.map($=>s.jsxs(Tt,{value:$.name,children:[$.name," (",$.lang,")"]},$.name))]})]}),s.jsx(be,{size:"xs",variant:"ghost",onClick:$e,title:t("settings.voice.page.actions.preview"),children:ce?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:$=>d(Number($.target.value)),disabled:!n,className:L}),s.jsx(En,{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:$=>m(Number($.target.value)),disabled:!n,className:L}),s.jsx(En,{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:$=>f(Number($.target.value)),disabled:!n,className:L}),e?s.jsx(En,{value:Math.round(u*100),onValueChange:$=>f($/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(os,{value:r,onValueChange:a,disabled:!n,children:[s.jsx(ls,{className:"w-fit",children:s.jsx(us,{placeholder:t("settings.voice.page.field.selectLanguagePlaceholder")})}),s.jsx(cs,{children:IC.map($=>s.jsx(Tt,{value:$.value,children:$.label},$.value))})]})})]})]})]})]}),W&&s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.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(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:s.jsxs("ul",{className:"space-y-1",children:[s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.browser")})," ",t("settings.voice.page.tooltip.sttBrowser")]}),s.jsxs("li",{children:[s.jsx("strong",{children:t("settings.voice.page.provider.server")})," ",t("settings.voice.page.tooltip.sttServer")]})]})})]})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[s.jsx(be,{variant:"chip",size:"xs","aria-pressed":N==="browser",onClick:()=>E("browser"),className:"!font-normal",children:t("settings.voice.page.provider.browser")}),s.jsx(be,{variant:"chip",size:"xs","aria-pressed":N==="server",onClick:()=>E("server"),className:"!font-normal",children:t("settings.voice.page.provider.server")}),s.jsx(be,{variant:"chip",size:"xs","aria-pressed":N==="wasm",onClick:()=>E("wasm"),className:"!font-normal",children:t("settings.voice.page.provider.wasm")})]})]})}),N==="server"&&s.jsxs("div",{className:"py-1.5 space-y-2",children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":Z,onClick:()=>fe(!Z),onKeyDown:$=>{($.key===" "||$.key==="Enter")&&($.preventDefault(),fe(!Z))},children:[s.jsx(fs,{checked:Z,onChange:fe,ariaLabel:t("settings.voice.page.field.transcribeOnStopAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.transcribeOnStop")})]}),!oy.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:xe("typography-ui-label text-foreground",!T.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx("span",{className:"typography-meta ml-2 text-muted-foreground",children:t("settings.voice.page.field.sttServerUrlHint")}),s.jsxs("div",{className:"relative mt-1.5 max-w-xs",children:[s.jsx("input",{type:"text",value:T,onChange:$=>R($.target.value),placeholder:"http://localhost:8001/v1",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),T&&s.jsx("button",{type:"button",onClick:()=>R(""),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:V,onChange:$=>_($.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:$=>K($.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:F,onChange:$=>G(Number($.target.value)),className:L}),s.jsxs("span",{className:"typography-ui-label text-foreground tabular-nums min-w-[3.5rem] text-right",children:[F," 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:Q,onChange:$=>te(Number($.target.value)),className:L}),s.jsx(En,{value:Q,onValueChange:te,min:500,max:3e3,step:100,className:"w-20 tabular-nums"}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.voice.page.field.millisecondsUnit")})]})]})]}),N==="wasm"&&s.jsxs("div",{className:"py-1.5 space-y-2",children:[s.jsxs("div",{children:[s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:t("settings.voice.page.stt.wasmModel")}),s.jsxs(os,{value:U,onValueChange:B,children:[s.jsx(ls,{className:"mt-0.5",children:s.jsx(us,{placeholder:t("settings.voice.page.stt.wasmModel")})}),s.jsx(cs,{children:Tu.map($=>s.jsx(Tt,{value:$.id,children:s.jsxs("div",{className:"flex flex-col",children:[s.jsx("span",{children:$.name}),s.jsxs("span",{className:"typography-ui-compact text-muted-foreground",children:[$.size," · ",$.languages]})]})},$.id))})]}),s.jsx("p",{className:"typography-ui-compact text-muted-foreground mt-0.5",children:Tu.find($=>$.id===U)?.description})]}),s.jsx(PC,{modelId:U})]})]})]}),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":A,onClick:()=>ue(!A),onKeyDown:$=>{($.key===" "||$.key==="Enter")&&($.preventDefault(),ue(!A))},children:[s.jsx(fs,{checked:A,onChange:ue,ariaLabel:t("settings.voice.page.field.messageReadAloudButtonAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.messageReadAloudButton")})]})}),W&&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 TC(){_i.onModelStatusChange=null}const Ac=[{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}],Dc=[{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}],MC="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/get-started/create-remote-tunnel/",EC="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/do-more-with-tunnels/local-management/configuration-file/",$p=[{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"}],RC=[".yml",".yaml",".json"],FC="settings.openchamber.tunnel.error.invalidConfigExtension",Fi=t=>{const e=t.trim().toLowerCase();return RC.some(n=>e.endsWith(n))},kg=t=>t==="cloudflare"?"Cloudflare":t,_p=t=>{const e=st.c(11),{provider:n}=t;let r;e[0]!==n?(r=kg(n),e[0]=n,e[1]=r):r=e[1];const a=r,o=n==="cloudflare"?"text-[var(--status-warning)]":"text-muted-foreground";let c;e[2]!==o?(c=xe("size-4 shrink-0",o),e[2]=o,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},ba=t=>t==="quick"?"quick":t==="managed-remote"?"managed-remote":t==="managed-local"?"managed-local":"quick",Bp=(t,e,n)=>t.find(a=>a.ms===e)?.value||n,zp=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`},OC=t=>new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"}),Zo=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()}},LC=t=>{if(!Array.isArray(t))return[];const e=new Set,n=new Set,r=[];for(const a of t){if(!a||typeof a!="object")continue;const i=a,o=typeof i.id=="string"?i.id.trim():"",c=typeof i.name=="string"?i.name.trim():"",d=Zo(typeof i.hostname=="string"?i.hostname:"");!o||!c||!d||e.has(o)||n.has(d)||(e.add(o),n.add(d),r.push({id:o,name:c,hostname:d}))}return r},$C=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2,10)}`,_C=()=>{const{t}=dt(),e=l.useCallback(Ne=>t(Ne),[t]),[n,r]=l.useState("checking"),[a,i]=l.useState(null),[o,c]=l.useState(null),[d,p]=l.useState(null),[m,u]=l.useState(null),[f,b]=l.useState(null),[h,v]=l.useState(!1),[x,g]=l.useState(!1),[w,y]=l.useState(!1),[C,k]=l.useState("cloudflare"),[j,S]=l.useState([]),[I,M]=l.useState("quick"),[P,A]=l.useState(null),[N,E]=l.useState([]),[T,R]=l.useState({}),[V,_]=l.useState(""),[U,B]=l.useState({}),[z,K]=l.useState(new Set),[F,G]=l.useState(!1),[Q,te]=l.useState(""),[Z,fe]=l.useState(""),[ue,W]=l.useState(""),[q,J]=l.useState(1800*1e3),[ne,ee]=l.useState(480*60*1e3),[he,ke]=l.useState(""),[oe,ge]=l.useState([]),[me,ye]=l.useState(()=>Date.now()),[ie,ve]=l.useState(null),X=t(FC),Se=l.useRef(null),Ae=l.useMemo(()=>P?!Fi(P):!1,[P]),pe=l.useMemo(()=>N.find(Ne=>Ne.id===V)||N[0]||null,[N,V]),we=l.useMemo(()=>oe.map(Ne=>{const Ke=Ne.expiresAt<=me,Ve=Ne.status==="active"&&!Ke,qe=Ve?zp(Ne.expiresAt-me):Ne.inactiveReason==="expired"||Ke?"expired":"inactive",lt=qe==="expired"?t("settings.openchamber.tunnel.state.expired"):Ne.inactiveReason==="tunnel-revoked"?t("settings.openchamber.tunnel.state.revoked"):t("settings.openchamber.tunnel.state.inactive"),He=ba(Ne.mode);return{...Ne,isActive:Ve,mode:He,remainingTextForSession:qe,inactiveLabel:lt}}),[me,oe,t]),Ie=l.useMemo(()=>a?.connectUrl?a.bootstrapExpiresAt===null?!0:a.bootstrapExpiresAt>me:!1,[me,a?.bootstrapExpiresAt,a?.connectUrl]),Y=l.useMemo(()=>!a||n!=="active"&&n!=="stopping"?!1:o===I,[o,n,a,I]),re=l.useMemo(()=>!a||n!=="active"||!o?!1:o!==I,[o,n,a,I]),Pe=l.useMemo(()=>{if(typeof ie=="number"&&Number.isFinite(ie)&&ie>0)return ie;if(typeof window>"u")return null;const Ne=Number(window.location.port);return Number.isFinite(Ne)&&Ne>0?Ne:null},[ie]),ce=l.useCallback(async Ne=>{await qn(Ne)},[]),Ce=l.useCallback(async Ne=>{try{const[Ke,Ve,qe,lt]=await Promise.all([fetch("/api/openchamber/tunnel/check",{signal:Ne}),fetch("/api/openchamber/tunnel/status",{signal:Ne}),fetch("/api/config/settings",{signal:Ne,headers:{Accept:"application/json"}}),fetch("/api/openchamber/tunnel/providers",{signal:Ne})]),He=await Ke.json(),ze=await Ve.json(),et=qe.ok?await qe.json():{},yt=lt.ok?await lt.json():{},Rt=ze.ttlConfig?.bootstrapTtlMs??(et?.tunnelBootstrapTtlMs===null?null:typeof et?.tunnelBootstrapTtlMs=="number"?et.tunnelBootstrapTtlMs:1800*1e3),kt=typeof ze.ttlConfig?.sessionTtlMs=="number"?ze.ttlConfig.sessionTtlMs:typeof et?.tunnelSessionTtlMs=="number"?et.tunnelSessionTtlMs:480*60*1e3,ht=ba(ze.mode??et?.tunnelMode),vt=typeof et?.tunnelProvider=="string"&&et.tunnelProvider.trim().length>0?et.tunnelProvider.trim().toLowerCase():"cloudflare",ns=typeof et?.managedLocalTunnelConfigPath=="string"&&et.managedLocalTunnelConfigPath.trim()||null,zt=LC(ze?.managedRemoteTunnelPresets),Kt=typeof ze.managedRemoteTunnelHostname=="string"?ze.managedRemoteTunnelHostname:"",mt=zt.length>0?zt:Kt?[{id:`legacy-${Zo(Kt)}`,name:Kt,hostname:Zo(Kt)}]:[],Et=mt[0]?.id||"";if(J(Rt),ee(kt),k(vt),S(Array.isArray(yt?.providers)?yt.providers:[]),M(ht),A(ns),E(mt),_(Et),ge(Array.isArray(ze.activeSessions)?ze.activeSessions:[]),c(ze.activeTunnelMode?ba(ze.activeTunnelMode):ze.active&&ze.mode?ba(ze.mode):null),K(new Set(Array.isArray(ze.managedRemoteTunnelTokenPresetIds)?ze.managedRemoteTunnelTokenPresetIds:[])),ve(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{Ne.aborted||(r("error"),u(t("settings.openchamber.tunnel.toast.checkAvailabilityFailed")))}},[t]);l.useEffect(()=>{const Ne=new AbortController;return Ce(Ne.signal),()=>Ne.abort()},[Ce]),l.useEffect(()=>{if(!a?.connectUrl){p(null);return}let Ne=!1;return Dx.toDataURL(a.connectUrl,{width:256,margin:2,color:{dark:"#000000",light:"#ffffff"}}).then(Ke=>{Ne||p(Ke)}).catch(()=>{Ne||p(null)}),()=>{Ne=!0}},[a?.connectUrl]),l.useEffect(()=>{if(!a?.bootstrapExpiresAt){ke(t("settings.openchamber.tunnel.state.noExpiry"));return}let Ne=null,Ke=Date.now();const Ve=()=>{const He=a.bootstrapExpiresAt?a.bootstrapExpiresAt-Date.now():0;He<=0?ke(t("settings.openchamber.tunnel.state.expired")):ke(zp(He))},qe=()=>{const He=Date.now();He-Ke>=1e3&&(Ve(),Ke=He),Ne=requestAnimationFrame(qe)};Ve(),(typeof document>"u"||document.visibilityState==="visible")&&(Ne=requestAnimationFrame(qe));const lt=()=>{document.visibilityState==="visible"&&Ne===null?Ne=requestAnimationFrame(qe):document.visibilityState!=="visible"&&Ne!==null&&(cancelAnimationFrame(Ne),Ne=null)};return document.addEventListener("visibilitychange",lt),()=>{document.removeEventListener("visibilitychange",lt),Ne!==null&&cancelAnimationFrame(Ne)}},[t,a?.bootstrapExpiresAt]),l.useEffect(()=>{let Ne=null,Ke=Date.now();const Ve=()=>{const lt=Date.now();lt-Ke>=1e3&&(ye(lt),Ke=lt),Ne=requestAnimationFrame(Ve)};(typeof document>"u"||document.visibilityState==="visible")&&(Ne=requestAnimationFrame(Ve));const qe=()=>{document.visibilityState==="visible"&&Ne===null?Ne=requestAnimationFrame(Ve):document.visibilityState!=="visible"&&Ne!==null&&(cancelAnimationFrame(Ne),Ne=null)};return document.addEventListener("visibilitychange",qe),()=>{document.removeEventListener("visibilitychange",qe),Ne!==null&&cancelAnimationFrame(Ne)}},[]),l.useEffect(()=>{if(n==="starting"||n==="stopping"||n==="checking")return;let Ne=!1;const Ke=async()=>{try{const qe=await fetch("/api/openchamber/tunnel/status");if(!qe.ok||Ne)return;const lt=await qe.json();if(Ne)return;ge(Array.isArray(lt.activeSessions)?lt.activeSessions:[]),K(new Set(Array.isArray(lt.managedRemoteTunnelTokenPresetIds)?lt.managedRemoteTunnelTokenPresetIds:[])),ve(typeof lt.localPort=="number"?lt.localPort:null)}catch{}},Ve=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||Ke()},5e3);return()=>{Ne=!0,window.clearInterval(Ve)}},[n]);const Te=l.useCallback(async Ne=>{y(!0);try{await Is(Ne),Object.prototype.hasOwnProperty.call(Ne,"tunnelMode")&&Ne.tunnelMode&&M(Ne.tunnelMode),Object.prototype.hasOwnProperty.call(Ne,"tunnelProvider")&&typeof Ne.tunnelProvider=="string"&&k(Ne.tunnelProvider),Object.prototype.hasOwnProperty.call(Ne,"managedLocalTunnelConfigPath")&&A(Ne.managedLocalTunnelConfigPath??null),Object.prototype.hasOwnProperty.call(Ne,"managedRemoteTunnelPresets")&&Ne.managedRemoteTunnelPresets&&E(Ne.managedRemoteTunnelPresets)}catch{H.error(t("settings.openchamber.tunnel.toast.saveSettingsFailed"))}finally{y(!1)}},[t]),$e=l.useCallback(async(Ne,Ke)=>{g(!0);try{await Is({tunnelBootstrapTtlMs:Ne,tunnelSessionTtlMs:Ke})}catch{H.error(t("settings.openchamber.tunnel.toast.saveTtlFailed"))}finally{g(!1)}},[t]),De=l.useCallback(async Ne=>{const Ke=Ne.token.trim();if(Ke)try{const Ve={...U,[Ne.presetId]:Ke};await Is({managedRemoteTunnelPresetTokens:Ve}),K(qe=>{const lt=new Set(qe);return lt.add(Ne.presetId),lt})}catch{H.error(t("settings.openchamber.tunnel.toast.saveTokenFailed"))}},[U,t]),de=l.useCallback(async Ne=>{b(null),u(null),await Te({tunnelProvider:Ne})},[Te]),O=l.useCallback(async()=>{const Ne=await Zf({filters:[{name:"Config",extensions:["yml","yaml","json"]}]});if(Ne.success&&typeof Ne.path=="string"&&Ne.path.trim().length>0){const Ke=Ne.path.trim();if(!Fi(Ke)){H.error(X);return}A(Ke),await Te({managedLocalTunnelConfigPath:Ke});return}Se.current?.click()},[X,Te]),L=l.useCallback(Ne=>{const Ke=Ne.trim();A(Ke.length>0?Ke:null)},[]),$=l.useCallback(async()=>{if(P&&!Fi(P)){H.error(X);return}await Te({managedLocalTunnelConfigPath:P})},[X,P,Te]),je=l.useCallback(async()=>{A(null),await Te({managedLocalTunnelConfigPath:null})},[Te]),ae=l.useCallback(async Ne=>{const Ke=Ne.target.files?.[0];if(!Ke)return;const Ve=Ke.name.trim();if(Ve.length!==0){if(!Fi(Ve)){H.error(X);return}A(Ve),await Te({managedLocalTunnelConfigPath:Ve}),Ne.target.value=""}},[X,Te]),_e=l.useCallback(async()=>{if(u(null),b(null),I==="managed-local"&&P&&!Fi(P)){u(X),H.error(X);return}r("starting");try{let Ne="",Ke="";if(I==="managed-remote"){if(!pe){r("idle"),b(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst")),H.error(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst"));return}Ne=pe.hostname,Ke=(U[pe.id]||"").trim(),await Te({tunnelMode:"managed-remote",managedRemoteTunnelPresets:N})}const Ve=await fetch("/api/openchamber/tunnel/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:C,mode:I,...I==="managed-remote"&&pe?{managedRemoteTunnelPresetId:pe.id,managedRemoteTunnelPresetName:pe.name}:{},...I==="managed-remote"&&Ne?{managedRemoteTunnelHostname:Ne}:{},...I==="managed-remote"&&Ke?{managedRemoteTunnelToken:Ke}:{},...I==="managed-local"&&P?{configPath:P}:{}})}),qe=await Ve.json();if(!Ve.ok||!qe.ok){if(I==="managed-remote"&&typeof qe.error=="string"&&qe.error.includes("Managed remote tunnel token is required")){r("idle"),b(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequiredBeforeStarting")),H.error(t("settings.openchamber.tunnel.toast.addManagedRemoteTokenBeforeStarting"));return}r("error"),u(qe.error||t("settings.openchamber.tunnel.toast.startFailed")),H.error(qe.error||t("settings.openchamber.tunnel.toast.startFailed"));return}const lt=typeof qe.url=="string"?qe.url:"";if(!lt){r("error"),u(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl")),H.error(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl"));return}if(i({url:lt,connectUrl:typeof qe.connectUrl=="string"?qe.connectUrl:null,bootstrapExpiresAt:typeof qe.bootstrapExpiresAt=="number"?qe.bootstrapExpiresAt:null}),c(qe.activeTunnelMode?ba(qe.activeTunnelMode):qe.mode?ba(qe.mode):I),ge(Array.isArray(qe.activeSessions)?qe.activeSessions:[]),Array.isArray(qe.managedRemoteTunnelTokenPresetIds)&&K(new Set(qe.managedRemoteTunnelTokenPresetIds)),typeof qe.localPort=="number"&&ve(qe.localPort),typeof qe.mode=="string"&&M(ba(qe.mode)),r("active"),qe.replacedTunnel){const He=typeof qe.revokedBootstrapCount=="number"?qe.revokedBootstrapCount:0,ze=typeof qe.invalidatedSessionCount=="number"?qe.invalidatedSessionCount:0;He===1&&ze===1?H.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleSingle")):He===1?H.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleManySessions",{invalidatedSessionCount:ze})):ze===1?H.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyLinksSingleSession",{revokedBootstrapCount:He})):H.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyMany",{revokedBootstrapCount:He,invalidatedSessionCount:ze}))}else H.success(t("settings.openchamber.tunnel.toast.linkReady"))}catch{r("error"),u(t("settings.openchamber.tunnel.toast.startFailed")),H.error(t("settings.openchamber.tunnel.toast.startFailed"))}},[X,N,Te,pe,U,t,C,I,P]),le=l.useCallback(async()=>{r("stopping");try{await fetch("/api/openchamber/tunnel/stop",{method:"POST"});const Ne=await fetch("/api/openchamber/tunnel/status");if(Ne.ok){const Ke=await Ne.json();ge(Array.isArray(Ke.activeSessions)?Ke.activeSessions:[]),K(new Set(Array.isArray(Ke.managedRemoteTunnelTokenPresetIds)?Ke.managedRemoteTunnelTokenPresetIds:[])),ve(typeof Ke.localPort=="number"?Ke.localPort:null)}i(null),c(null),p(null),r("idle"),H.success(t("settings.openchamber.tunnel.toast.stopped"))}catch{r("error"),u(t("settings.openchamber.tunnel.toast.stopFailed")),H.error(t("settings.openchamber.tunnel.toast.stopFailed"))}},[t]),Me=l.useCallback(async()=>{if(a?.connectUrl)try{await navigator.clipboard.writeText(a.connectUrl),v(!0),H.success(t("settings.openchamber.tunnel.toast.connectLinkCopied")),setTimeout(()=>v(!1),2e3)}catch{H.error(t("settings.openchamber.tunnel.toast.copyUrlFailed"))}},[t,a?.connectUrl]),Ge=l.useCallback(async Ne=>{const Ke=Ac.find(Ve=>Ve.value===Ne);Ke&&(J(Ke.ms),await $e(Ke.ms,ne))},[$e,ne]),at=l.useCallback(async Ne=>{const Ke=Dc.find(Ve=>Ve.value===Ne);!Ke||Ke.ms===null||(ee(Ke.ms),await $e(q,Ke.ms))},[q,$e]),Ye=l.useCallback(async Ne=>{b(null),u(null),n!=="active"&&n!=="stopping"&&n!=="starting"&&r("idle"),await Te({tunnelMode:Ne,managedRemoteTunnelPresets:N})},[N,Te,n]),Xe=l.useCallback(async(Ne,Ke)=>{try{await Is({managedRemoteTunnelPresets:Ke})}catch{H.error(t("settings.openchamber.tunnel.toast.saveSelectedManagedRemoteFailed"))}},[t]),ut=l.useCallback(Ne=>{const Ke=N.find(Ve=>Ve.id===Ne);Ke&&(_(Ke.id),b(null),Xe(Ke,N))},[N,Xe]),rt=l.useCallback(async()=>{const Ne=Q.trim(),Ke=Zo(Z),Ve=ue.trim();if(!Ne){H.error(t("settings.openchamber.tunnel.toast.tunnelNameRequired"));return}if(!Ke){H.error(t("settings.openchamber.tunnel.toast.managedRemoteHostnameRequired"));return}if(!Ve){H.error(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequired"));return}if(N.some(He=>He.hostname===Ke)){H.error(t("settings.openchamber.tunnel.toast.hostnameAlreadyExists"));return}const qe={id:$C(),name:Ne,hostname:Ke},lt=[...N,qe];E(lt),_(qe.id),R(He=>({...He,[qe.id]:!0})),B(He=>({...He,[qe.id]:Ve})),b(null),G(!1),te(""),fe(""),W(""),await Te({tunnelMode:"managed-remote",managedRemoteTunnelPresets:lt,managedRemoteTunnelPresetTokens:{...U,[qe.id]:Ve}}),await De({presetId:qe.id,presetName:qe.name,hostname:qe.hostname,token:Ve}),H.success(t("settings.openchamber.tunnel.toast.managedRemoteSaved"))},[N,Z,Q,ue,De,Te,U,t]),it=l.useCallback(async Ne=>{const Ke=N.find(ze=>ze.id===Ne);if(!Ke)return;const Ve=N.filter(ze=>ze.id!==Ke.id),qe=Ve[0]?.id||"",lt=V===Ke.id?qe:V,He=Object.fromEntries(Object.entries(U).filter(([ze,et])=>ze!==Ke.id&&et.trim().length>0));E(Ve),_(lt),R(ze=>{const et={...ze};return delete et[Ke.id],et}),B(ze=>{const et={...ze};return delete et[Ke.id],et}),K(ze=>{const et=new Set(ze);return et.delete(Ke.id),et}),b(null),await Te({managedRemoteTunnelPresets:Ve,managedRemoteTunnelPresetTokens:He}),H.success(t("settings.openchamber.tunnel.toast.managedRemoteRemoved"))},[N,Te,V,U,t]),nt="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")})]}),we.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:we.map(Ne=>{const Ke=Ne.mode==="quick",Ve=Ne.mode==="managed-remote",qe=Ke?"border-[var(--status-warning-border)] bg-[var(--status-warning-background)] text-[var(--status-warning)]":Ve?"border-[var(--status-info-border)] bg-[var(--status-info-background)] text-[var(--status-info)]":"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",lt=Ne.isActive?Ke?"text-[var(--status-warning)]":Ve?"text-[var(--status-info)]":"text-[var(--status-success)]":"text-muted-foreground/50",He=t(Ke?"settings.openchamber.tunnel.badge.quick":Ve?"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:xe("size-2.5 shrink-0",lt)}),s.jsx("span",{className:xe("typography-micro rounded border px-1.5 py-0.5 uppercase",qe),children:He}),s.jsx("span",{className:"typography-meta text-muted-foreground/80",children:t("settings.openchamber.tunnel.session.redeemedAt",{time:OC(Ne.createdAt)})}),s.jsx("span",{className:"typography-meta text-foreground",children:Ne.isActive?t("settings.openchamber.tunnel.session.expiresIn",{remaining:Ne.remainingTextForSession}):Ne.inactiveLabel===t("settings.openchamber.tunnel.state.inactive")?t("settings.openchamber.tunnel.state.inactive"):t("settings.openchamber.tunnel.session.inactiveWithReason",{reason:Ne.inactiveLabel})})]},Ne.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(os,{value:C,onValueChange:Ne=>{de(Ne)},disabled:w||n==="starting"||n==="stopping",children:[s.jsx(ls,{className:"max-w-[16rem]",children:s.jsx(us,{placeholder:t("settings.openchamber.tunnel.field.providerPlaceholder"),children:kg(C)})}),s.jsxs(cs,{children:[j.length>0?j.map(Ne=>s.jsx(Tt,{value:Ne.provider,children:s.jsx(_p,{provider:Ne.provider})},Ne.provider)):s.jsx(Tt,{value:"cloudflare",children:s.jsx(_p,{provider:"cloudflare"})}),s.jsx(Tt,{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:$p.map(Ne=>s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(be,{variant:"chip",size:"xs","aria-pressed":I===Ne.value,className:"!font-normal",onClick:()=>{Ye(Ne.value)},disabled:w||n==="starting"||n==="stopping",children:e(Ne.labelKey)})}),s.jsx(At,{sideOffset:8,className:"max-w-xs",children:e(Ne.tooltipKey)})]},Ne.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(os,{value:Bp(Ac,q,"1800000"),onValueChange:Ne=>{Ge(Ne)},disabled:x||w||n==="starting"||n==="stopping",children:[s.jsx(ls,{className:"max-w-[11rem] min-w-0",children:s.jsx(us,{className:"truncate"})}),s.jsx(cs,{children:Ac.map(Ne=>s.jsx(Tt,{value:Ne.value,children:Ne.label},Ne.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(os,{value:Bp(Dc,ne,"28800000"),onValueChange:Ne=>{at(Ne)},disabled:x||w||n==="starting"||n==="stopping",children:[s.jsx(ls,{className:"max-w-[11rem] min-w-0",children:s.jsx(us,{className:"truncate"})}),s.jsx(cs,{children:Dc.map(Ne=>s.jsx(Tt,{value:Ne.value,children:Ne.label},Ne.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 Pe=="number"&&s.jsx("div",{className:"rounded-md border border-[var(--status-info-border)] bg-[var(--status-info-background)]/35 px-2 py-1.5",children:s.jsxs("p",{className:"typography-meta text-[var(--status-info)]",children:[t("settings.openchamber.tunnel.note.cloudflareConnectorTarget")," ",s.jsxs("code",{children:["http://localhost:",Pe]})]})}),s.jsxs("div",{className:"mb-1 flex items-center justify-between gap-3",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.tunnel.section.savedManagedRemoteTunnels")}),s.jsxs(be,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>G(Ne=>!Ne),disabled:n==="starting"||n==="stopping"||w,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((Ne,Ke)=>{const Ve=U[Ne.id]||"",qe=z.has(Ne.id),lt=T[Ne.id]??!1;return s.jsx("div",{className:xe(Ke<N.length-1&&"border-b border-[var(--surface-subtle)]"),children:s.jsxs(fr,{open:lt,onOpenChange:He=>{R(ze=>({...ze,[Ne.id]:He})),He&&ut(Ne.id)},className:"py-1.5",children:[s.jsxs("div",{className:"flex items-start gap-2 px-3",children:[s.jsxs(kr,{type:"button",className:"group flex-1 justify-start gap-2 rounded-md px-0 py-1 pr-1 text-left hover:bg-[var(--interactive-hover)]",disabled:n==="starting"||n==="stopping"||w,children:[lt?s.jsx(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:Ne.name})]}),s.jsx(be,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:text-[var(--status-error)]","aria-label":t("settings.openchamber.tunnel.actions.removePresetAria",{name:Ne.name}),onClick:()=>{it(Ne.id)},disabled:n==="starting"||n==="stopping"||w,children:s.jsx(D,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),s.jsx(hr,{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:Ne.hostname})]}),s.jsx(Bt,{type:"password",value:Ve,onChange:He=>{const ze=He.target.value;b(null),B(et=>({...et,[Ne.id]:ze}))},onBlur:He=>{const ze=He.currentTarget.value.trim();ze&&De({presetId:Ne.id,presetName:Ne.name,hostname:Ne.hostname,token:ze})},placeholder:t(qe?"settings.openchamber.tunnel.field.savedTokenAvailablePlaceholder":"settings.openchamber.tunnel.field.pasteTokenPlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"}),s.jsx("div",{className:"flex items-center justify-end",children:s.jsx(be,{variant:"ghost",size:"xs",className:"!font-normal",disabled:n==="starting"||n==="stopping"||Ve.trim().length===0,onClick:()=>{De({presetId:Ne.id,presetName:Ne.name,hostname:Ne.hostname,token:Ve})},children:t("settings.openchamber.tunnel.actions.saveToken")})})]})})]})},Ne.id)})}):s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.openchamber.tunnel.empty.noManagedRemoteTunnels")}),F&&s.jsxs("div",{className:"space-y-2 rounded-md border border-[var(--surface-subtle)] p-2",children:[s.jsx(Bt,{value:Q,onChange:Ne=>te(Ne.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetNamePlaceholder"),className:"h-7",disabled:w||n==="starting"||n==="stopping"}),s.jsx(Bt,{value:Z,onChange:Ne=>fe(Ne.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetHostnamePlaceholder"),className:"h-7",disabled:w||n==="starting"||n==="stopping"}),s.jsx(Bt,{type:"password",value:ue,onChange:Ne=>W(Ne.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetTokenPlaceholder"),className:"h-7",disabled:w||n==="starting"||n==="stopping"}),typeof Pe=="number"&&s.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[t("settings.openchamber.tunnel.note.cloudflareConnectorTargetUse")," ",s.jsxs("code",{children:["http://localhost:",Pe]}),"."]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(be,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{rt()},disabled:w||n==="starting"||n==="stopping",children:t("settings.common.actions.saveChanges")}),s.jsx(be,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{G(!1),te(""),fe(""),W("")},disabled:w||n==="starting"||n==="stopping",children:t("settings.common.actions.cancel")})]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:t("settings.openchamber.tunnel.note.tokensSavedPerTunnel")}),s.jsxs(Ct,{children:[s.jsx(It,{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(At,{sideOffset:8,className:"max-w-xs",children:t("settings.openchamber.tunnel.tooltip.tokensSavedPath")})]})]}),!pe&&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:Ne=>{ae(Ne)}}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Bt,{value:P||"",onChange:Ne=>{L(Ne.target.value)},onBlur:()=>{$()},placeholder:t("settings.openchamber.tunnel.field.configurationFilePlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"||w}),s.jsx(be,{variant:"outline",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.browseConfigFileAria"),onClick:()=>{O()},disabled:n==="starting"||n==="stopping"||w,children:s.jsx(D,{name:"folder",className:"size-3.5"})}),P&&s.jsx(be,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.clearConfigFileAria"),onClick:()=>{je()},disabled:n==="starting"||n==="stopping"||w,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")}),Ae&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:X})]})}),!Y&&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:()=>{ce(MC)},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:()=>{ce(EC)},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($p.find(Ne=>Ne.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(os,{value:V||(N[0]?.id??""),onValueChange:Ne=>{ut(Ne)},disabled:w||n==="starting"||n==="stopping"||N.length<=1,children:[s.jsx(ls,{children:s.jsx(us,{placeholder:t("settings.openchamber.tunnel.field.selectSavedTunnelPlaceholder"),children:pe?.name})}),s.jsx(cs,{fitContent:!0,children:N.map(Ne=>s.jsx(Tt,{value:Ne.id,children:Ne.name},Ne.id))})]})]}),re&&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(be,{size:"sm",variant:"outline",onClick:_e,disabled:n==="starting"||w||I==="managed-remote"&&!pe||I==="managed-local"&&Ae,className:xe(nt,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")})]})]}),Y&&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})]}),Ie&&a.connectUrl&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta mb-1 text-muted-foreground/70",children:t("settings.openchamber.tunnel.field.connectLink")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("code",{className:"typography-code flex-1 truncate rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:a.connectUrl}),s.jsxs(be,{size:"sm",variant:"ghost",onClick:Me,className:"shrink-0 gap-1.5",children:[h?s.jsx(D,{name:"check",className:"size-3.5 text-[var(--status-success)]"}):s.jsx(D,{name:"file-copy",className:"size-3.5"}),t(h?"settings.openchamber.tunnel.actions.copied":"settings.common.actions.copyAll")]})]}),s.jsxs("p",{className:"typography-meta mt-1 text-muted-foreground/70",children:[t("settings.openchamber.tunnel.field.expires"),": ",a.bootstrapExpiresAt?he:t("settings.openchamber.tunnel.state.never")]})]}),s.jsxs("div",{className:"flex flex-col items-center gap-2 rounded-lg border border-border/50 bg-[var(--surface-elevated)] p-4",children:[d?s.jsx("img",{src:d,alt:t("settings.openchamber.tunnel.field.connectQrAlt"),className:"size-48"}):s.jsx("div",{className:"size-48 rounded bg-muted/30"}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.tunnel.note.scanQrToConnect")})]})]})]}),s.jsx("div",{className:"pt-1",children:s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(be,{size:"sm",variant:"outline",onClick:_e,disabled:n==="stopping"||w||I==="managed-local"&&Ae,className:nt,children:[s.jsx(D,{name:"restart",className:"size-3.5"}),t("settings.openchamber.tunnel.actions.newConnectLink")]}),s.jsx(be,{size:"sm",variant:"ghost",onClick:le,disabled:n==="stopping"||w,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(be,{size:"sm",variant:"ghost",onClick:_e,children:t("settings.openchamber.tunnel.actions.retry")})]})]})},Cg=()=>{const{t}=dt(),[e,n]=Oe.useState(""),[r,a]=Oe.useState(!0),[i,o]=Oe.useState(!1),c=Re(u=>u.showOpenCodeUpdateNotifications),d=Re(u=>u.setShowOpenCodeUpdateNotifications);Oe.useEffect(()=>{let u=!1;return(async()=>{try{const f=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!f.ok)return;const b=await f.json().catch(()=>null);if(u||!b)return;const h=typeof b.opencodeBinary=="string"?b.opencodeBinary.trim():"";n(h)}catch{}finally{u||a(!1)}})(),()=>{u=!0}},[]);const p=Oe.useCallback(async()=>{if(typeof window>"u"||!vn()||!Ea())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=Oe.useCallback(async()=>{o(!0);try{await Is({opencodeBinary:e.trim()}),await ni({message:t("settings.openchamber.opencodeCli.actions.restartingOpenCode"),mode:"projects",scopes:["all"]})}finally{o(!1)}},[t,e]);return s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.openchamber.opencodeCli.title")}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsxs(At,{sideOffset:8,className:"max-w-xs",children:[t("settings.openchamber.opencodeCli.tooltipPrefix")," ",s.jsx("code",{className:"font-mono text-xs",children:"opencode"}),t("settings.openchamber.opencodeCli.tooltipSuffix")]})]})]})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-3",children:[s.jsx("div",{className:"flex min-w-0 flex-col shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.opencodeCli.field.binaryPath")})}),s.jsxs("div",{className:"flex min-w-0 items-center gap-2 sm:w-[20rem]",children:[s.jsx(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(be,{type:"button",variant:"outline",size:"xs",onClick:p,disabled:r||i||!vn()||!Ea(),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(fs,{checked:c,onChange:d,ariaLabel:t("settings.openchamber.opencodeCli.field.showUpdateNotificationsAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.opencodeCli.field.showUpdateNotifications")})]}),s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(be,{type:"button",size:"xs",onClick:m,disabled:r||i,className:"shrink-0 !font-normal",children:t(i?"settings.common.actions.saving":"settings.openchamber.opencodeCli.actions.saveAndReload")})})]})]})},Ig=()=>{const{t}=dt(),e=vn()&&Qr(),[n,r]=Oe.useState(!1),[a,i]=Oe.useState(!1),[o,c]=Oe.useState(!0),[d,p]=Oe.useState(!1),[m,u]=Oe.useState(null),[f,b]=Oe.useState(null);Oe.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 j=k?.desktopLanAccessEnabled===!0;r(j),i(j),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]),Oe.useEffect(()=>{if(!e||!a){b(null);return}let y=!1;return(async()=>{const C=await ly();y||b(C)})(),()=>{y=!0}},[a,e]);const h=a!==n,v=Oe.useMemo(()=>{if(typeof window>"u")return null;const y=Number(window.location.port);return Number.isFinite(y)&&y>0?y:null},[]),x=a&&f&&v?`http://${f}:${v}`:null,g=Oe.useCallback(()=>{i(y=>!y)},[]),w=Oe.useCallback(async()=>{if(h){p(!0),u(null);try{if(!(await fetch("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({desktopLanAccessEnabled:a})})).ok)throw new Error(t("settings.openchamber.desktopNetwork.error.saveFailed"));if(r(a),!await ih())throw new Error(t("settings.openchamber.desktopNetwork.error.savedRestartFailed"))}catch(y){u(y instanceof Error?y.message:t("settings.openchamber.desktopNetwork.error.saveFailed")),p(!1)}}},[a,h,t]);return e?s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.openchamber.desktopNetwork.title")})}),s.jsxs("section",{className:"space-y-2 px-2 pb-2 pt-0",children:[s.jsxs("div",{className:"group flex cursor-pointer items-start gap-2 py-1.5",role:"button",tabIndex:0,onClick:g,onKeyDown:y=>{(y.key==="Enter"||y.key===" ")&&(y.preventDefault(),g())},children:[s.jsx(fs,{checked:a,onChange:g,ariaLabel:t("settings.openchamber.desktopNetwork.field.allowLanAccessAria"),disabled:o||d}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.desktopNetwork.field.allowLanAccess")}),s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:t("settings.openchamber.desktopNetwork.field.allowLanAccessDescription")}),s.jsx("div",{className:"typography-micro text-[var(--status-warning)]/85",children:t("settings.openchamber.desktopNetwork.field.warning")})]})]}),m?s.jsx("div",{className:"px-2 typography-micro text-[var(--status-error)]",children:m}):null,x?s.jsxs("div",{className:"px-2 typography-micro text-muted-foreground/80",children:[t(h&&!n?"settings.openchamber.desktopNetwork.hint.openAfterRestart":"settings.openchamber.desktopNetwork.hint.openNow"),s.jsx("span",{className:"font-mono text-foreground",children:x})]}):null,s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(be,{type:"button",size:"xs",onClick:w,disabled:o||d||!h,className:"shrink-0 !font-normal",children:t(d?"settings.common.actions.saving":"settings.openchamber.desktopNetwork.actions.saveAndRestart")})})]})]}):null},BC=new Set(["shift","control","alt","meta"]),zC=t=>{if(BC.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=dy(t.key);return n?(e.push(n),Ya(e.join("+"))):null},VC=()=>{const t=st.c(58),{t:e}=dt();let n;t[0]!==e?(n=ue=>e(ue),t[0]=e,t[1]=n):n=t[1];const r=n,a=Re(UC),i=Re(WC),o=Re(KC),c=Re(HC);let d;t[2]===Symbol.for("react.memo_cache_sentinel")?(d=cy(),t[2]=d):d=t[2];const p=d;let m;t[3]!==r?(m=(ue,W)=>{const q=`settings.openchamber.keyboardShortcuts.action.${ue}.label`,J=r(q);return J===q?W:J},t[3]=r,t[4]=m):m=t[4];const u=m,[f,b]=l.useState(null);let h;t[5]===Symbol.for("react.memo_cache_sentinel")?(h={},t[5]=h):h=t[5];const[v,x]=l.useState(h),[g,w]=l.useState(""),[y,C]=l.useState(""),[k,j]=l.useState(null);let S;t[6]!==a?(S=(ue,W)=>{const q=Ya(W);for(const J of p){if(J.id===ue)continue;const ne=qr(J.id,a);if(Ya(ne)===q)return J.id}return null},t[6]=a,t[7]=S):S=t[7];const I=S;let M;t[8]!==I||t[9]!==i||t[10]!==e?(M=(ue,W)=>{const q=Ya(W),J=I(ue,q);if(J){j({actionId:ue,combo:q,conflictActionId:J}),w("");return}i(ue,q),j(null),w(""),C(Mu(q)?e("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut"):""),x(ne=>{const ee={...ne};return delete ee[ue],ee})},t[8]=I,t[9]=i,t[10]=e,t[11]=M):M=t[11];const P=M;let A;t[12]!==k||t[13]!==i||t[14]!==e?(A=()=>{k&&(i(k.conflictActionId,uy),i(k.actionId,k.combo),j(null),w(""),C(Mu(k.combo)?e("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut"):""),x(ue=>{const W={...ue};return delete W[k.actionId],W}))},t[12]=k,t[13]=i,t[14]=e,t[15]=A):A=t[15];const N=A;let E;t[16]!==o?(E=ue=>{o(ue),x(W=>{const q={...W};return delete q[ue],q}),j(null),w(""),C("")},t[16]=o,t[17]=E):E=t[17];const T=E;let R;t[18]!==e?(R=e("settings.openchamber.keyboardShortcuts.title"),t[18]=e,t[19]=R):R=t[19];let V;t[20]!==R?(V=s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:R}),t[20]=R,t[21]=V):V=t[21];let _;t[22]!==c?(_=()=>{c(),x({}),j(null),w(""),C("")},t[22]=c,t[23]=_):_=t[23];let U;t[24]!==e?(U=e("settings.openchamber.keyboardShortcuts.actions.resetAll"),t[24]=e,t[25]=U):U=t[25];let B;t[26]!==_||t[27]!==U?(B=s.jsx(be,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:_,children:U}),t[26]=_,t[27]=U,t[28]=B):B=t[28];let z;t[29]===Symbol.for("react.memo_cache_sentinel")?(z=s.jsx(It,{asChild:!0,children:s.jsx(D,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t[29]=z):z=t[29];let K;t[30]!==e?(K=e("settings.openchamber.keyboardShortcuts.tooltip"),t[30]=e,t[31]=K):K=t[31];let F;t[32]!==K?(F=s.jsxs(Ct,{children:[z,s.jsx(At,{sideOffset:8,className:"max-w-xs",children:K})]}),t[32]=K,t[33]=F):F=t[33];let G;t[34]!==B||t[35]!==F||t[36]!==V?(G=s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[V,B,F]})}),t[34]=B,t[35]=F,t[36]=V,t[37]=G):G=t[37];let Q;t[38]!==N||t[39]!==g||t[40]!==k||t[41]!==e||t[42]!==y?(Q=(g||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(be,{type:"button",size:"xs",className:"!font-normal",onClick:N,children:e("settings.openchamber.keyboardShortcuts.actions.overwrite")}),s.jsx(be,{type:"button",size:"xs",className:"!font-normal",variant:"ghost",onClick:()=>j(null),children:e("settings.common.actions.cancel")})]})]}),g&&s.jsx("div",{className:"rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] p-3 typography-meta text-foreground",children:g}),y&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3 typography-meta text-foreground",children:y})]}),t[38]=N,t[39]=g,t[40]=k,t[41]=e,t[42]=y,t[43]=Q):Q=t[43];let te;t[44]!==u||t[45]!==f||t[46]!==v||t[47]!==T||t[48]!==P||t[49]!==a||t[50]!==e?(te=p.map((ue,W)=>{const q=qr(ue.id,a),J=v[ue.id],ne=J??q,ee=typeof J=="string"&&Ya(J)!==Ya(q);return s.jsxs("div",{className:xe("flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",W>0&&"border-t border-[var(--surface-subtle)]"),children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:u(ue.id,ue.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===ue.id?e("settings.openchamber.keyboardShortcuts.field.pressKeys"):Il(ne),onFocus:()=>{b(ue.id),w("")},onBlur:()=>{f===ue.id&&b(null)},onKeyDown:he=>{if(he.preventDefault(),he.stopPropagation(),he.key==="Escape"){b(null);return}const ke=zC(he);ke&&(x(oe=>({...oe,[ue.id]:ke})),b(null),j(null),w(""))},className:"h-7 w-40 min-w-0 typography-ui-label text-center"}),s.jsx(be,{type:"button",variant:"secondary",size:"xs",className:"!font-normal",onClick:()=>{const he=v[ue.id];if(!he){w(e("settings.openchamber.keyboardShortcuts.error.captureFirst"));return}P(ue.id,he)},disabled:!ee,children:e("settings.common.actions.saveChanges")}),s.jsx(be,{type:"button",size:"xs",className:"!font-normal",variant:"ghost",onClick:()=>T(ue.id),children:e("settings.common.actions.reset")})]})]},ue.id)}),t[44]=u,t[45]=f,t[46]=v,t[47]=T,t[48]=P,t[49]=a,t[50]=e,t[51]=te):te=t[51];let Z;t[52]!==te?(Z=s.jsx("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:te}),t[52]=te,t[53]=Z):Z=t[53];let fe;return t[54]!==G||t[55]!==Q||t[56]!==Z?(fe=s.jsxs("div",{className:"mb-8",children:[G,Q,Z]}),t[54]=G,t[55]=Q,t[56]=Z,t[57]=fe):fe=t[57],fe};function UC(t){return t.shortcutOverrides}function WC(t){return t.setShortcutOverride}function KC(t){return t.clearShortcutOverride}function HC(t){return t.resetAllShortcutOverrides}const GC=t=>{const e=st.c(20),{section:n}=t,{isMobile:r}=nn();let a;e[0]!==r?(a=r&&Yr(),e[0]=r,e[1]=a):a=e[1];const i=a;let o;e[2]===Symbol.for("react.memo_cache_sentinel")?(o=on(),e[2]=o):o=e[2];const c=o;let d;e[3]===Symbol.for("react.memo_cache_sentinel")?(d=vn()&&Qr(),e[3]=d):d=e[3];const p=d;if(!n){let h;e[4]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(eu,{}),e[4]=h):h=e[4];let v,x,g;e[5]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Sg,{})}),x=!c&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Cg,{})}),g=p&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Ig,{})}),e[5]=v,e[6]=x,e[7]=g):(v=e[5],x=e[6],g=e[7]);let w;e[8]===Symbol.for("react.memo_cache_sentinel")?(w=s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(jg,{})}),e[8]=w):w=e[8];let y;e[9]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Ng,{})}),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(pC,{})}),e[10]=i,e[11]=C):C=e[11];let k;return e[12]!==C?(k=s.jsx(Ns,{outerClassName:"h-full",className:"w-full",children:s.jsxs("div",{className:"openchamber-page-body mx-auto max-w-3xl space-y-3 p-3 sm:space-y-6 sm:p-6 sm:pt-8",children:[h,v,x,g,w,y,C]})}),e[12]=C,e[13]=k):k=e[13],k}let m;e[14]!==n?(m=()=>{switch(n){case"visual":return s.jsx(JC,{});case"chat":return s.jsx(YC,{});case"sessions":return s.jsx(QC,{});case"shortcuts":return s.jsx(qC,{});case"git":return s.jsx(XC,{});case"github":return s.jsx(ZC,{});case"notifications":return s.jsx(e4,{});case"voice":return s.jsx(t4,{});case"tunnel":return s.jsx(s4,{});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(Ns,{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},qC=()=>{const t=st.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(VC,{}),t[0]=e):e=t[0],e},JC=()=>{const t=st.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=on(),t[0]=e):e=t[0];const n=e;let r;return t[1]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(eu,{visibleSettings:["theme","pwaInstallName","pwaOrientation","mobileKeyboardMode","timeFormat","weekStart","fontSize","terminalFontSize","spacing","inputBarOffset",...n?[]:["terminalQuickKeys"],"reportUsage"]}),t[1]=r):r=t[1],r},YC=()=>{const t=st.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(eu,{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},QC=()=>{const t=st.c(7);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=on(),t[0]=e):e=t[0];const n=e;let r;t[1]===Symbol.for("react.memo_cache_sentinel")?(r=vn()&&Qr(),t[1]=r):r=t[1];const a=r;let i,o,c;t[2]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx(Sg,{}),o=!n&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Cg,{})}),c=a&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Ig,{})}),t[2]=i,t[3]=o,t[4]=c):(i=t[2],o=t[3],c=t[4]);let d;t[5]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(jg,{})}),t[5]=d):d=t[5];let p;return t[6]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsxs("div",{className:"space-y-6",children:[i,o,c,d,s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Ng,{})})]}),t[6]=p):p=t[6],p},XC=()=>{const t=st.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx("div",{className:"space-y-6",children:s.jsx(bg,{})}),t[0]=e):e=t[0],e},ZC=()=>{const t=st.c(1);if(on())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(yg,{}),t[0]=e):e=t[0],e},e4=()=>{const t=st.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(CC,{}),t[0]=e):e=t[0],e},t4=()=>{const t=st.c(1);if(on())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(DC,{}),t[0]=e):e=t[0],e},s4=()=>{const t=st.c(1);if(on())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(_C,{}),t[0]=e):e=t[0],e},yd=176,vd=280,Vp=8;function Tc(t){return Math.min(vd,Math.max(yd,t))}const n4=["appearance","chat","notifications","sessions","shortcuts","git","magic-prompts","snippets","projects","remote-instances","agents","behavior","commands","mcp","providers","usage","skills.installed","skills.catalog","voice","tunnel"],r4={icon:"chat-thread"};function a4(t){const e=on(),n=!t&&Yr();return{isVSCode:e,isWeb:n,isDesktop:t}}function Up(t,e){return t.isAvailable?t.isAvailable(e):!0}function tu(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 r4.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 Mc=t=>{const e=st.c(95),{onOpen:n}=t,{t:r}=dt();let a;e[0]!==r?(a=r("settings.view.home.title"),e[0]=r,e[1]=a):a=e[1];let i;e[2]!==a?(i=s.jsx("h1",{className:"typography-ui-header font-semibold text-foreground",children:a}),e[2]=a,e[3]=i):i=e[3];let o;e[4]!==r?(o=r("settings.view.home.description"),e[4]=r,e[5]=o):o=e[5];let c;e[6]!==o?(c=s.jsx("p",{className:"typography-ui text-muted-foreground",children:o}),e[6]=o,e[7]=c):c=e[7];let d;e[8]!==i||e[9]!==c?(d=s.jsxs("div",{className:"space-y-1",children:[i,c]}),e[8]=i,e[9]=c,e[10]=d):d=e[10];let p;e[11]!==n?(p=()=>n("providers"),e[11]=n,e[12]=p):p=e[12];let m;e[13]===Symbol.for("react.memo_cache_sentinel")?(m=xe("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[13]=m):m=e[13];let u;e[14]!==r?(u=r("settings.view.home.cards.providers.title"),e[14]=r,e[15]=u):u=e[15];let f;e[16]!==u?(f=s.jsx("div",{className:"typography-ui-label text-foreground",children:u}),e[16]=u,e[17]=f):f=e[17];let b;e[18]!==r?(b=r("settings.view.home.cards.providers.description"),e[18]=r,e[19]=b):b=e[19];let h;e[20]!==b?(h=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:b}),e[20]=b,e[21]=h):h=e[21];let v;e[22]!==h||e[23]!==p||e[24]!==f?(v=s.jsxs("button",{type:"button",onClick:p,className:m,children:[f,h]}),e[22]=h,e[23]=p,e[24]=f,e[25]=v):v=e[25];let x;e[26]!==n?(x=()=>n("agents"),e[26]=n,e[27]=x):x=e[27];let g;e[28]===Symbol.for("react.memo_cache_sentinel")?(g=xe("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[28]=g):g=e[28];let w;e[29]!==r?(w=r("settings.view.home.cards.agents.title"),e[29]=r,e[30]=w):w=e[30];let y;e[31]!==w?(y=s.jsx("div",{className:"typography-ui-label text-foreground",children:w}),e[31]=w,e[32]=y):y=e[32];let 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 j;e[37]!==x||e[38]!==y||e[39]!==k?(j=s.jsxs("button",{type:"button",onClick:x,className:g,children:[y,k]}),e[37]=x,e[38]=y,e[39]=k,e[40]=j):j=e[40];let S;e[41]!==n?(S=()=>n("skills.catalog"),e[41]=n,e[42]=S):S=e[42];let I;e[43]===Symbol.for("react.memo_cache_sentinel")?(I=xe("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 M;e[44]!==r?(M=r("settings.view.home.cards.skillsCatalog.title"),e[44]=r,e[45]=M):M=e[45];let P;e[46]!==M?(P=s.jsx("div",{className:"typography-ui-label text-foreground",children:M}),e[46]=M,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 T;e[56]!==n?(T=()=>n("mcp"),e[56]=n,e[57]=T):T=e[57];let R;e[58]===Symbol.for("react.memo_cache_sentinel")?(R=xe("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[58]=R):R=e[58];let V;e[59]!==r?(V=r("settings.view.home.cards.mcp.title"),e[59]=r,e[60]=V):V=e[60];let _;e[61]!==V?(_=s.jsx("div",{className:"typography-ui-label text-foreground",children:V}),e[61]=V,e[62]=_):_=e[62];let U;e[63]!==r?(U=r("settings.view.home.cards.mcp.description"),e[63]=r,e[64]=U):U=e[64];let B;e[65]!==U?(B=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:U}),e[65]=U,e[66]=B):B=e[66];let z;e[67]!==T||e[68]!==_||e[69]!==B?(z=s.jsxs("button",{type:"button",onClick:T,className:R,children:[_,B]}),e[67]=T,e[68]=_,e[69]=B,e[70]=z):z=e[70];let K;e[71]!==n?(K=()=>n("usage"),e[71]=n,e[72]=K):K=e[72];let F;e[73]===Symbol.for("react.memo_cache_sentinel")?(F=xe("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[73]=F):F=e[73];let G;e[74]!==r?(G=r("settings.view.home.cards.usage.title"),e[74]=r,e[75]=G):G=e[75];let Q;e[76]!==G?(Q=s.jsx("div",{className:"typography-ui-label text-foreground",children:G}),e[76]=G,e[77]=Q):Q=e[77];let te;e[78]!==r?(te=r("settings.view.home.cards.usage.description"),e[78]=r,e[79]=te):te=e[79];let Z;e[80]!==te?(Z=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:te}),e[80]=te,e[81]=Z):Z=e[81];let fe;e[82]!==K||e[83]!==Q||e[84]!==Z?(fe=s.jsxs("button",{type:"button",onClick:K,className:F,children:[Q,Z]}),e[82]=K,e[83]=Q,e[84]=Z,e[85]=fe):fe=e[85];let ue;e[86]!==v||e[87]!==j||e[88]!==E||e[89]!==z||e[90]!==fe?(ue=s.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[v,j,E,z,fe]}),e[86]=v,e[87]=j,e[88]=E,e[89]=z,e[90]=fe,e[91]=ue):ue=e[91];let W;return e[92]!==ue||e[93]!==d?(W=s.jsx("div",{className:"h-full overflow-auto",children:s.jsxs("div",{className:"mx-auto w-full max-w-3xl px-6 py-6 space-y-6",children:[d,ue]})}),e[92]=ue,e[93]=d,e[94]=W):W=e[94],W},i4=t=>{const e=st.c(104),{onClose:n,forceMobile:r,isWindowed:a}=t,{t:i}=dt(),o=nn(),c=r??o.isMobile,d=Re(o4),p=Re(l4),m=Re(c4);let u;e[0]!==d?(u=lg(d),e[0]=d,e[1]=u):u=e[1];const f=u,[b,h]=l.useState("nav"),v=l.useRef(null),[x,g]=l.useState(216),[w,y]=l.useState(!1),[C,k]=l.useState(!1),j=l.useRef(0),S=l.useRef(x),I=l.useRef(null);let M;e[2]===Symbol.for("react.memo_cache_sentinel")?(M=vn(),e[2]=M):M=e[2];const P=M;let A;e[3]===Symbol.for("react.memo_cache_sentinel")?(A=a4(P),e[3]=A):A=e[3];const N=A;let E;if(e[4]!==c){let De;e[6]===Symbol.for("react.memo_cache_sentinel")?(De=O=>Up(O,N),e[6]=De):De=e[6];let de;e[7]===Symbol.for("react.memo_cache_sentinel")?(de=O=>!(N.isVSCode&&O.slug==="projects"),e[7]=de):de=e[7],E=Qd.filter(d4).filter(De).filter(de).filter(O=>!(c&&O.slug==="shortcuts")),e[4]=c,e[5]=E}else E=e[5];const T=E;let R;e[8]===Symbol.for("react.memo_cache_sentinel")?(R=new Map(n4.map(u4)),e[8]=R):R=e[8];const V=R;let _;if(e[9]!==T){let De;e[11]===Symbol.for("react.memo_cache_sentinel")?(De=(de,O)=>(V.get(de.slug)??999)-(V.get(O.slug)??999),e[11]=De):De=e[11],_=T.slice().sort(De),e[9]=T,e[10]=_}else _=e[10];const U=_,B=Ps(m4);let z,K;e[12]!==w?(z=()=>{if(typeof window>"u")return;const De=()=>{if(!w){const de=Tc(Math.floor(window.innerWidth*.12));g(de)}};return window.addEventListener("resize",De),()=>window.removeEventListener("resize",De)},K=[w],e[12]=w,e[13]=z,e[14]=K):(z=e[13],K=e[14]),l.useEffect(z,K);let F,G;e[15]!==C?(G=()=>{if(!C)return;const De=O=>{const L=O.clientX-j.current,$=Tc(S.current+L);g($),y(!0)},de=()=>k(!1);return window.addEventListener("pointermove",De),window.addEventListener("pointerup",de,{once:!0}),()=>{window.removeEventListener("pointermove",De),window.removeEventListener("pointerup",de)}},F=[C],e[15]=C,e[16]=F,e[17]=G):(F=e[16],G=e[17]),l.useEffect(G,F);let Q;e[18]!==x?(Q=De=>{k(!0),j.current=De.clientX,S.current=x,De.preventDefault()},e[18]=x,e[19]=Q):Q=e[19];const te=Q;let Z;e[20]!==x?(Z=De=>{const de=De.shiftKey?Vp*4:Vp;let O;e:switch(De.key){case"ArrowLeft":{O=x-de;break e}case"ArrowRight":{O=x+de;break e}case"Home":{O=yd;break e}case"End":{O=vd;break e}default:return}De.preventDefault(),g(Tc(O)),y(!0)},e[20]=x,e[21]=Z):Z=e[21];const fe=Z;let ue;e[22]!==p||e[23]!==a||e[24]!==f?(ue=()=>{if(!(!p&&!N.isVSCode&&!a)){if(f==="agents"){li.getState().loadAgents();return}if(f==="commands"){$d.getState().loadCommands();return}if(f==="mcp"){ro.getState().loadMcpConfigs();return}(f==="skills.installed"||f==="skills.catalog")&&(oa.getState().loadSkills(),Aa.getState().loadCatalog()),f==="snippets"&&Fl.getState().loadSnippets()}},e[22]=p,e[23]=a,e[24]=f,e[25]=ue):ue=e[25];let W;e[26]!==B||e[27]!==p||e[28]!==a||e[29]!==f?(W=[B,p,a,N.isVSCode,f],e[26]=B,e[27]=p,e[28]=a,e[29]=f,e[30]=W):W=e[30],l.useEffect(ue,W);let q;e[31]!==c||e[32]!==m?(q=De=>{if(m(De),v.current=De,!c)return;const de=zi(De);if(!de||de.slug==="home"){h("nav");return}h(de.kind==="split"?"page-sidebar":"page-content")},e[31]=c,e[32]=m,e[33]=q):q=e[33];const J=q;let ne;e[34]!==f?(ne=zi(f),e[34]=f,e[35]=ne):ne=e[35];const ee=ne;let he;e[36]===Symbol.for("react.memo_cache_sentinel")?(he={appearance:"visual",chat:"chat",shortcuts:"shortcuts",sessions:"sessions",notifications:"notifications",voice:"voice",tunnel:"tunnel"},e[36]=he):he=e[36];const ke=he;let oe;e[37]!==i?(oe=De=>{switch(De){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]=oe):oe=e[38];const ge=oe;let me;e[39]!==i?(me=()=>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]=me):me=e[40];const ye=me,ie=p4;let ve;e[41]!==J||e[42]!==ye?(ve=De=>{const de=zi(De);if(de&&!Up(de,N))return ye();switch(De){case"home":return s.jsx(Mc,{onOpen:J});case"projects":return s.jsx(I3,{});case"remote-instances":return s.jsx(Z3,{});case"agents":return s.jsx(ZS,{});case"behavior":return s.jsx(rk,{});case"commands":return s.jsx(pk,{});case"mcp":return s.jsx(zk,{});case"skills.installed":return s.jsx(fp,{view:"installed"});case"skills.catalog":return s.jsx(fp,{view:"catalog"});case"providers":return s.jsx(o5,{});case"usage":return s.jsx(k5,{});case"magic-prompts":return s.jsx(D5,{});case"snippets":return s.jsx(F5,{});case"git":return s.jsx(B5,{});case"appearance":case"chat":case"shortcuts":case"sessions":case"notifications":case"voice":case"tunnel":{const O=ke[De]??"visual";return s.jsx(GC,{section:O})}default:return s.jsx(Mc,{onOpen:J})}},e[41]=J,e[42]=ye,e[43]=ve):ve=e[43];const X=ve;let Se,Ae;e[44]!==c||e[45]!==b||e[46]!==f?(Se=()=>{if(!c||b!=="nav"||f==="home"||v.current===f)return;const De=zi(f);!De||De.slug==="home"||(v.current=f,h(De.kind==="split"?"page-sidebar":"page-content"))},Ae=[c,b,f],e[44]=c,e[45]=b,e[46]=f,e[47]=Se,e[48]=Ae):(Se=e[47],Ae=e[48]),l.useEffect(Se,Ae);const pe=c&&b!=="nav";let we,Ie,Y,re,Pe,ce,Ce;if(e[49]!==ee||e[50]!==ge||e[51]!==c||e[52]!==a||e[53]!==b||e[54]!==n||e[55]!==J||e[56]!==X||e[57]!==f||e[58]!==pe||e[59]!==U||e[60]!==i){const De=dl();let de;e[68]===Symbol.for("react.memo_cache_sentinel")?(de=()=>{h("nav")},e[68]=de):de=e[68];const O=de;let L;e[69]===Symbol.for("react.memo_cache_sentinel")?(L=()=>{h("page-sidebar")},e[69]=L):L=e[69];const $=L;let je;e[70]!==ge||e[71]!==J||e[72]!==f||e[73]!==U||e[74]!==i?(je=()=>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:U.map(le=>{const Me=f===le.slug,Ge=tu(le.slug);return Ge?s.jsx(Ct,{children:s.jsx(It,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>J(le.slug),"aria-current":Me?"page":void 0,className:xe("flex h-8 items-center gap-2 rounded-md px-2 overflow-hidden",Me?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:[s.jsx(D,{name:Ge,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(le.slug)}),(le.slug==="voice"||le.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")})]})]})})},le.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(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsxs("button",{type:"button",className:xe("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:f4,children:[s.jsx(D,{name:"restart",className:"h-4 w-4 shrink-0"}),s.jsx("span",{children:i("settings.view.actions.reloadOpenCode")})]})}),s.jsx(At,{children:i("settings.view.actions.reloadOpenCodeTooltip")})]})})})]}),e[70]=ge,e[71]=J,e[72]=f,e[73]=U,e[74]=i,e[75]=je):je=e[75],Y=je;let ae;e[76]!==ee||e[77]!==b||e[78]!==X||e[79]!==Y||e[80]!==f?(ae=()=>{if(b==="nav")return s.jsx("div",{className:xe("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(Ys,{children:Y()})})});if(!ee)return s.jsx("div",{className:"flex-1 bg-background"});if(b==="page-sidebar"){if(ee.kind!=="split"){const Me=X(f);return s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:s.jsx(Ys,{children:Me})})}return s.jsx("div",{className:xe("flex-1 min-h-0 overflow-hidden",N.isVSCode?"bg-background":"bg-sidebar"),children:s.jsx(Ys,{children:ie(f,{onItemSelect:()=>h("page-content")})})})}const le=X(f);return s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:s.jsx(Ys,{children:le})})},e[76]=ee,e[77]=b,e[78]=X,e[79]=Y,e[80]=f,e[81]=ae):ae=e[81],Ie=ae;let _e;e[82]!==ee||e[83]!==J||e[84]!==X||e[85]!==f?(_e=()=>!ee||f==="home"?s.jsx(Mc,{onOpen:J}):ee.kind==="split"?s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden",children:[s.jsx("div",{className:xe("w-[264px] min-w-[264px] border-r",N.isVSCode?"bg-background":"bg-sidebar"),style:{borderColor:"var(--interactive-border)"},children:s.jsx(Ys,{children:ie(f,{})})}),s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:s.jsx(Ys,{children:X(f)})})]}):s.jsx("div",{className:"h-full min-h-0 overflow-hidden bg-background",children:s.jsx(Ys,{children:X(f)})}),e[82]=ee,e[83]=J,e[84]=X,e[85]=f,e[86]=_e):_e=e[86],we=_e,re=I,Pe="true",e[87]===Symbol.for("react.memo_cache_sentinel")?(ce=xe("relative flex h-full min-h-0 flex-col overflow-hidden bg-background"),e[87]=ce):ce=e[87],Ce=c?s.jsxs("div",{className:xe("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:pe?O:n,"aria-label":i(pe?"settings.view.actions.backToSettings":"settings.view.actions.closeSettings"),className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(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"):ee?ge(ee.slug):i("settings.view.home.title")}),b==="page-content"&&ee?.kind==="split"&&s.jsx("button",{type:"button",onClick:$,"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:De}),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:[pe&&s.jsx("div",{className:xe("absolute left-3 z-50",a?"top-2":"top-3"),children:s.jsx("button",{type:"button",onClick:O,"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:xe("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:De}),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"})})})]}),e[49]=ee,e[50]=ge,e[51]=c,e[52]=a,e[53]=b,e[54]=n,e[55]=J,e[56]=X,e[57]=f,e[58]=pe,e[59]=U,e[60]=i,e[61]=we,e[62]=Ie,e[63]=Y,e[64]=re,e[65]=Pe,e[66]=ce,e[67]=Ce}else we=e[61],Ie=e[62],Y=e[63],re=e[64],Pe=e[65],ce=e[66],Ce=e[67];let Te;e[88]!==te||e[89]!==fe||e[90]!==c||e[91]!==C||e[92]!==x||e[93]!==we||e[94]!==Ie||e[95]!==Y||e[96]!==i?(Te=s.jsx("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:c?Ie():s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:xe("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:xe("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:te,onKeyDown:fe,role:"separator","aria-orientation":"vertical","aria-valuemin":yd,"aria-valuemax":vd,"aria-valuenow":x,"aria-label":i("settings.view.actions.resizeNavigation")}),s.jsx(Ys,{children:Y()})]}),s.jsx("div",{className:"flex-1 overflow-hidden bg-background",children:we()})]})}),e[88]=te,e[89]=fe,e[90]=c,e[91]=C,e[92]=x,e[93]=we,e[94]=Ie,e[95]=Y,e[96]=i,e[97]=Te):Te=e[97];let $e;return e[98]!==re||e[99]!==Pe||e[100]!==ce||e[101]!==Ce||e[102]!==Te?($e=s.jsxs("div",{ref:re,"data-settings-view":Pe,className:ce,children:[Ce,Te]}),e[98]=re,e[99]=Pe,e[100]=ce,e[101]=Ce,e[102]=Te,e[103]=$e):$e=e[103],$e};function o4(t){return t.settingsPage}function l4(t){return t.isSettingsDialogOpen}function c4(t){return t.setSettingsPage}function d4(t){return t.slug!=="home"}function u4(t,e){return[t,e]}function m4(t){return t.activeProjectId}function p4(t,e){switch(t){case"projects":return s.jsx(b3,{onItemSelect:e.onItemSelect});case"remote-instances":return s.jsx(B3,{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(Vk,{onItemSelect:e.onItemSelect});case"providers":return s.jsx(s5,{onItemSelect:e.onItemSelect});case"usage":return s.jsx(c5,{onItemSelect:e.onItemSelect});case"magic-prompts":return s.jsx(I5,{onItemSelect:e.onItemSelect});case"snippets":return s.jsx(T5,{onItemSelect:e.onItemSelect});default:return null}}function f4(){ni({message:"Restarting OpenCode…",mode:"projects",scopes:["all"]})}const h4=Object.freeze(Object.defineProperty({__proto__:null,SettingsView:i4,getSettingsNavIcon:tu},Symbol.toStringTag,{value:"Module"})),wd=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},g4=()=>{const t=st.c(162),{t:e}=dt(),n=Re(x4),r=Re(b4),a=Re(y4),i=Re(v4),o=Re(w4),c=Re(j4),d=Re(N4),p=Re(S4),m=Re(k4),u=Re(C4),f=Re(I4),b=Re(P4),h=Lt(A4),v=Lt(D4),x=Pa(T4),g=zs(M4),w=Ps(E4),y=Zr(),C=Fd(R4),{files:k,git:j}=Rn(),S=tn(F4),{isMobile:I}=nn();let M;t[0]!==y?(M=y?wd(y):null,t[0]=y,t[1]=M):M=t[1];const P=M,[A,N]=l.useState(""),E=Ml(A,200);let T;t[2]!==E?(T=E.trim(),t[2]=E,t[3]=T):T=t[3];const R=T;let V;t[4]!==A?(V=A.trim(),t[4]=A,t[5]=V):V=t[5];const _=V;let U,B;t[6]!==n?(U=()=>{n&&N("")},B=[n],t[6]=n,t[7]=U,t[8]=B):(U=t[7],B=t[8]),l.useEffect(U,B);let z,K;t[9]!==x||t[10]!==S||t[11]!==j||t[12]!==n?(z=()=>{if(!n||!j)return;const He=setTimeout(()=>{const ze=new Set;for(const et of x){const yt=Ui(et);!yt||ze.has(yt)||(ze.add(yt),S(yt,j))}},0);return()=>clearTimeout(He)},K=[n,x,j,S],t[9]=x,t[10]=S,t[11]=j,t[12]=n,t[13]=z,t[14]=K):(z=t[13],K=t[14]),l.useEffect(z,K);let F;t[15]!==r?(F=()=>r(!1),t[15]=r,t[16]=F):F=t[16];const G=F;let Q;t[17]!==G?(Q=He=>()=>{G(),He()},t[17]=G,t[18]=Q):Q=t[18];const te=Q;let Z;t[19]!==w?.id||t[20]!==w?.path||t[21]!==g||t[22]!==I||t[23]!==u||t[24]!==h||t[25]!==te||t[26]!==a||t[27]!==c||t[28]!==i||t[29]!==e||t[30]!==m||t[31]!==p||t[32]!==d?(Z=()=>{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:te(()=>{a("chat"),c(!1),h()})},{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:te(O4)},{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:te(L4)},{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:te(()=>{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:te(()=>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:te(()=>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:te(()=>{g&&u(g)})},{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:te(()=>i(!0))}];return Pd()&&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:te(()=>{ol("desktop_open_draft_mini_chat_window",{directory:wd(g||w?.path||""),projectId:w?.id??null}).catch($4)})}),He},t[19]=w?.id,t[20]=w?.path,t[21]=g,t[22]=I,t[23]=u,t[24]=h,t[25]=te,t[26]=a,t[27]=c,t[28]=i,t[29]=e,t[30]=m,t[31]=p,t[32]=d,t[33]=Z):Z=t[33],w?.id,w?.path;let fe;t[34]!==Z?(fe=Z(),t[34]=Z,t[35]=fe):fe=t[35];const ue=fe;let W;t[36]===Symbol.for("react.memo_cache_sentinel")?(W=vn(),t[36]=W):W=t[36];const q=W;let J;t[37]===Symbol.for("react.memo_cache_sentinel")?(J={isVSCode:on(),isWeb:!q&&Yr(),isDesktop:q},t[37]=J):J=t[37];const ne=J;let ee;if(t[38]!==te||t[39]!==i||t[40]!==o){let He;t[42]===Symbol.for("react.memo_cache_sentinel")?(He=ze=>ze.isAvailable?ze.isAvailable(ne):!0,t[42]=He):He=t[42],ee=Qd.filter(_4).filter(He).map(ze=>{const et=tu(ze.slug)??"settings-3",yt=(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} ${yt}`,onSelect:te(()=>{o(ze.slug),i(!0)})}}),t[38]=te,t[39]=i,t[40]=o,t[41]=ee}else ee=t[41];const he=ee,ke=B4;let oe;if(t[43]!==x){let He;t[45]===Symbol.for("react.memo_cache_sentinel")?(He=(ze,et)=>ke(et)-ke(ze),t[45]=He):He=t[45],oe=[...x].sort(He),t[43]=x,t[44]=oe}else oe=t[44];const ge=oe,me=oh(),ye=Lt(z4);let ie;t[46]!==me||t[47]!==ye?(ie=(He,ze)=>{const et=ye.get(He);return et?.branch?et.branch.trim()||null:ze&&me.get(ze)?.trim()||null},t[46]=me,t[47]=ye,t[48]=ie):ie=t[48];const ve=ie;let X;t[49]===Symbol.for("react.memo_cache_sentinel")?(X=[],t[49]=X):X=t[49];const[Se,Ae]=l.useState(X),[pe,we]=l.useState(!1);let Ie,Y;t[50]!==P||t[51]!==n||t[52]!==C||t[53]!==R?(Ie=()=>{if(!n){Ae([]),we(!1);return}if(!P||R.length===0){Ae([]),we(!1);return}let He=!1;return we(!0),C(P,R,10,{type:"file"}).then(ze=>{He||Ae(ze.map(V4))}).catch(()=>{He||Ae([])}).finally(()=>{He||we(!1)}),()=>{He=!0}},Y=[n,P,R,C],t[50]=P,t[51]=n,t[52]=C,t[53]=R,t[54]=Ie,t[55]=Y):(Ie=t[54],Y=t[55]),l.useEffect(Ie,Y);const re=_.length>0;let Pe;e:{if(!re){let ze;t[56]!==ue?(ze=ue.map(U4),t[56]=ue,t[57]=ze):ze=t[57],Pe=ze;break e}let He;t[58]!==ue||t[59]!==_?(He=jo(ue,_,W4,{limit:7,noFuzzy:!0}),t[58]=ue,t[59]=_,t[60]=He):He=t[60],Pe=He}const ce=Pe;let Ce;e:{if(!re){let ze;t[61]===Symbol.for("react.memo_cache_sentinel")?(ze=[],t[61]=ze):ze=t[61],Ce=ze;break e}let He;t[62]!==_||t[63]!==he?(He=jo(he,_,K4,{limit:7,noFuzzy:!0}),t[62]=_,t[63]=he,t[64]=He):He=t[64],Ce=He}const Te=Ce;let $e;e:{if(!re){let ze;t[65]!==ge?(ze=ge.slice(0,5).map(H4),t[65]=ge,t[66]=ze):ze=t[66],$e=ze;break e}let He;t[67]!==_||t[68]!==ge?(He=jo(ge,_,G4,{limit:7,threshold:.2}),t[67]=_,t[68]=ge,t[69]=He):He=t[69],$e=He}const De=$e;let de;e:{if(!re||Se.length===0){let ze;t[70]===Symbol.for("react.memo_cache_sentinel")?(ze=[],t[70]=ze):ze=t[70],de=ze;break e}let He;t[71]!==Se||t[72]!==_?(He=jo(Se,_,q4,{limit:10,threshold:.4}),t[71]=Se,t[72]=_,t[73]=He):He=t[73],de=He}const O=de;let L,$,je,ae,_e,le,Me,Ge,at,Ye,Xe,ut,rt,it,nt;if(t[74]!==ve||t[75]!==G||t[76]!==P||t[77]!==k||t[78]!==re||t[79]!==n||t[80]!==f||t[81]!==A||t[82]!==ce||t[83]!==O||t[84]!==De||t[85]!==Te||t[86]!==r||t[87]!==v||t[88]!==b||t[89]!==e){const He=ce.map(J4),ze=Te.map(Y4),et=De.map(Q4);nt=re?O.map(X4):[];let yt;e:{if(!re){yt=["commands","sessions"];break e}const Wt=Z4,We=[{key:"commands",score:Wt(ce)},{key:"settings",score:Wt(Te)},{key:"sessions",score:Wt(De)},{key:"files",score:Wt(O)}];We.sort(e6),yt=We.map(t6)}const Rt=yt;let kt;t[105]!==G||t[106]!==v?(kt=Wt=>{G(),v(Wt.id,Ui(Wt))},t[105]=G,t[106]=v,t[107]=kt):kt=t[107];const ht=kt;let vt;t[108]!==G||t[109]!==P||t[110]!==k||t[111]!==f?(vt=async Wt=>{if(!P)return;const We=await Jd(k,Wt);if(!We.ok){H.error(Yd(We.reason));return}f(P,Wt),G()},t[108]=G,t[109]=P,t[110]=k,t[111]=f,t[112]=vt):vt=t[112];const ns=vt;let zt;t[113]!==b?(zt=Wt=>Il(qr(Wt,b)),t[113]=b,t[114]=zt):zt=t[114];const Kt=zt;ae=ps,ut=n,rt=r;let mt;t[115]!==e?(mt=e("commandPalette.title"),t[115]=e,t[116]=mt):mt=t[116];let Et;t[117]!==mt?(Et=s.jsx(hs,{children:mt}),t[117]=mt,t[118]=Et):Et=t[118];let rs;t[119]!==e?(rs=e("commandPalette.description"),t[119]=e,t[120]=rs):rs=t[120];let gs;t[121]!==rs?(gs=s.jsx(Ss,{children:rs}),t[121]=rs,t[122]=gs):gs=t[122],t[123]!==Et||t[124]!==gs?(it=s.jsxs(ys,{className:"sr-only",children:[Et,gs]}),t[123]=Et,t[124]=gs,t[125]=it):it=t[125],je=ms,Ye="overflow-hidden p-0",Xe=!0,$=La,Me=!1,Ge="[&_[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 xs;t[126]!==e?(xs=e("commandPalette.input.placeholder"),t[126]=e,t[127]=xs):xs=t[127],t[128]!==A||t[129]!==xs?(at=s.jsx(da,{value:A,onValueChange:N,placeholder:xs}),t[128]=A,t[129]=xs,t[130]=at):at=t[130],L=$a;let bs;t[131]!==e?(bs=e("commandPalette.empty.noResults"),t[131]=e,t[132]=bs):bs=t[132],t[133]!==bs?(_e=s.jsx(_a,{children:bs}),t[133]=bs,t[134]=_e):_e=t[134],le=Rt.map(Wt=>Wt==="commands"&&He.length>0?s.jsx(Mn,{children:He.map(We=>s.jsxs(jn,{value:We.id,onSelect:We.onSelect,children:[We.icon,s.jsx("span",{children:We.title}),We.shortcutId?s.jsx(Lw,{children:Kt(We.shortcutId)}):null]},We.id))},"commands"):Wt==="settings"&&ze.length>0?s.jsx(Mn,{children:ze.map(s6)},"settings"):Wt==="sessions"&&et.length>0?s.jsx(Mn,{children:et.map(We=>{const St=We.title||e("commandPalette.session.untitled"),qt=Ui(We),wt=ve(We.id,qt);return s.jsxs(jn,{value:`session:${We.id}`,onSelect:()=>ht(We),children:[s.jsx(D,{name:"chat-ai-3",className:"mr-2 h-4 w-4"}),s.jsx("span",{className:"truncate",children:St}),wt?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:wt})]}):null]},We.id)})},"sessions"):Wt==="files"&&nt.length>0?s.jsx(Mn,{children:nt.map(We=>{const St=my(We.relativePath||We.name,{maxLength:80});return s.jsxs(jn,{value:`file:${We.path}`,onSelect:()=>{ns(We.path)},children:[s.jsx(jr,{filePath:We.path,className:"mr-2 size-4 shrink-0"}),s.jsx("span",{className:"truncate","aria-label":We.relativePath,children:St})]},`file:${We.path}`)})},"files"):null),t[74]=ve,t[75]=G,t[76]=P,t[77]=k,t[78]=re,t[79]=n,t[80]=f,t[81]=A,t[82]=ce,t[83]=O,t[84]=De,t[85]=Te,t[86]=r,t[87]=v,t[88]=b,t[89]=e,t[90]=L,t[91]=$,t[92]=je,t[93]=ae,t[94]=_e,t[95]=le,t[96]=Me,t[97]=Ge,t[98]=at,t[99]=Ye,t[100]=Xe,t[101]=ut,t[102]=rt,t[103]=it,t[104]=nt}else L=t[90],$=t[91],je=t[92],ae=t[93],_e=t[94],le=t[95],Me=t[96],Ge=t[97],at=t[98],Ye=t[99],Xe=t[100],ut=t[101],rt=t[102],it=t[103],nt=t[104];let Ne;t[135]!==re||t[136]!==pe||t[137]!==e||t[138]!==nt?(Ne=re&&pe&&nt.length===0?s.jsx("div",{className:"px-3 py-2 typography-meta text-muted-foreground",children:e("commandPalette.empty.searchingFiles")}):null,t[135]=re,t[136]=pe,t[137]=e,t[138]=nt,t[139]=Ne):Ne=t[139];let Ke;t[140]!==L||t[141]!==_e||t[142]!==le||t[143]!==Ne?(Ke=s.jsxs(L,{children:[_e,le,Ne]}),t[140]=L,t[141]=_e,t[142]=le,t[143]=Ne,t[144]=Ke):Ke=t[144];let Ve;t[145]!==$||t[146]!==Me||t[147]!==Ge||t[148]!==at||t[149]!==Ke?(Ve=s.jsxs($,{shouldFilter:Me,className:Ge,children:[at,Ke]}),t[145]=$,t[146]=Me,t[147]=Ge,t[148]=at,t[149]=Ke,t[150]=Ve):Ve=t[150];let qe;t[151]!==je||t[152]!==Ye||t[153]!==Xe||t[154]!==Ve?(qe=s.jsx(je,{className:Ye,showCloseButton:Xe,children:Ve}),t[151]=je,t[152]=Ye,t[153]=Xe,t[154]=Ve,t[155]=qe):qe=t[155];let lt;return t[156]!==ae||t[157]!==ut||t[158]!==rt||t[159]!==it||t[160]!==qe?(lt=s.jsxs(ae,{open:ut,onOpenChange:rt,children:[it,qe]}),t[156]=ae,t[157]=ut,t[158]=rt,t[159]=it,t[160]=qe,t[161]=lt):lt=t[161],lt};function x4(t){return t.isCommandPaletteOpen}function b4(t){return t.setCommandPaletteOpen}function y4(t){return t.setActiveMainTab}function v4(t){return t.setSettingsDialogOpen}function w4(t){return t.setSettingsPage}function j4(t){return t.setSessionSwitcherOpen}function N4(t){return t.toggleSidebar}function S4(t){return t.toggleRightSidebar}function k4(t){return t.toggleBottomTerminal}function C4(t){return t.openContextOverview}function I4(t){return t.openContextFile}function P4(t){return t.shortcutOverrides}function A4(t){return t.openNewSessionDraft}function D4(t){return t.setCurrentSession}function T4(t){return t.activeSessions}function M4(t){return t.currentDirectory}function E4(t){return t.getActiveProject()}function R4(t){return t.searchFiles}function F4(t){return t.ensureStatus}function O4(){lh()}function L4(){Nr.requestDirectoryDialog()}function $4(t){console.warn("[command-palette] failed to open draft mini chat window",t)}function _4(t){return t.slug!=="home"}function B4(t){return(typeof t.time?.updated=="number"?t.time.updated:0)||(typeof t.time?.created=="number"?t.time.created:0)}function z4(t){return t.worktreeMetadata}function V4(t){return{path:wd(t.path),name:t.name,relativePath:t.relativePath}}function U4(t){return{item:t,score:0}}function W4(t){return t.searchText}function K4(t){return t.searchText}function H4(t){return{item:t,score:0}}function G4(t){return t.title||""}function q4(t){return t.name}function J4(t){return t.item}function Y4(t){return t.item}function Q4(t){return t.item}function X4(t){return t.item}function Z4(t){return t.length?t[0].score:1/0}function e6(t,e){return t.score-e.score}function t6(t){return t.key}function s6(t){return s.jsxs(jn,{value:t.id,onSelect:t.onSelect,children:[t.icon,s.jsx("span",{children:t.title})]},t.id)}const Wp=(t,e,n)=>fy(t)?Il(qr(t,n)):e,n6=()=>{const t=st.c(68),{t:e}=dt(),n=Re(r6),r=Re(a6),a=Re(i6);let i;t[0]===Symbol.for("react.memo_cache_sentinel")?(i=py(),t[0]=i):i=t[0];const o=i;let c,d,p,m,u,f,b,h,v;if(t[1]!==n||t[2]!==r||t[3]!==a||t[4]!==e){const R=[{categoryKey:"helpDialog.section.navigationCommands",items:[{id:"open_command_palette",descriptionKey:"helpDialog.item.openCommandPalette",icon:"command",keys:""},{id:"open_help",descriptionKey:"helpDialog.item.showKeyboardShortcuts",icon:"question",keys:""},{id:"toggle_sidebar",descriptionKey:"helpDialog.item.toggleSessionSidebar",icon:"layout-left",keys:""},{id:"cycle_agent",keys:"",descriptionKey:"helpDialog.item.cycleAgent",icon:"ai-agent"},{id:"open_model_selector",descriptionKey:"helpDialog.item.openModelSelector",icon:"ai-generate-2",keys:""},{keys:["↑↓"],descriptionKey:"helpDialog.item.navigateModels",icon:"ai-generate-2"},{keys:["←→"],descriptionKey:"helpDialog.item.adjustThinkingMode",icon:"brain-ai-3"},{id:"cycle_thinking_variant",descriptionKey:"helpDialog.item.cycleThinkingVariant",icon:"brain-ai-3",keys:""},{keys:[`Shift + Alt + ${o} + N`],descriptionKey:"helpDialog.item.newWindow",icon:"window"}]},{categoryKey:"helpDialog.section.sessionManagement",items:[{id:"new_chat",descriptionKey:"helpDialog.item.createNewSession",icon:"add",keys:""},{id:"new_chat_worktree",descriptionKey:"helpDialog.item.createNewWorktreeDraft",icon:"git-branch",keys:""},{id:"focus_input",descriptionKey:"helpDialog.item.focusChatInput",icon:"text",keys:""},{id:"abort_run",descriptionKey:"helpDialog.item.abortActiveRun",icon:"close-circle",keys:""}]},{categoryKey:"helpDialog.section.panels",items:[{id:"toggle_right_sidebar",descriptionKey:"helpDialog.item.toggleRightSidebar",icon:"layout-right",keys:""},{id:"open_right_sidebar_git",descriptionKey:"helpDialog.item.openRightSidebarGitTab",icon:"git-branch",keys:""},{id:"open_right_sidebar_files",descriptionKey:"helpDialog.item.openRightSidebarFilesTab",icon:"layout-right",keys:""},{id:"cycle_right_sidebar_tab",descriptionKey:"helpDialog.item.cycleRightSidebarTab",icon:"layout-right",keys:""},{id:"toggle_terminal",descriptionKey:"helpDialog.item.toggleTerminalDock",icon:"window",keys:""},{id:"toggle_terminal_expanded",descriptionKey:"helpDialog.item.toggleTerminalExpanded",icon:"window",keys:""},{id:"toggle_context_plan",descriptionKey:"helpDialog.item.togglePlanContextPanel",icon:"time",keys:""}]},{categoryKey:"helpDialog.section.interface",items:[{id:"cycle_theme",descriptionKey:"helpDialog.item.cycleTheme",icon:"palette",keys:""},{keys:[`${o} + 1...9`],descriptionKey:"helpDialog.item.switchProject",icon:"layout-left"},{id:"toggle_services_menu",descriptionKey:"helpDialog.item.toggleServicesMenu",icon:"stack",keys:""},{id:"cycle_services_tab",descriptionKey:"helpDialog.item.cycleServicesTab",icon:"stack",keys:""},{id:"open_settings",descriptionKey:"helpDialog.item.openSettings",icon:"settings-3",keys:""}]}];d=ps,h=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 _;t[15]!==e?(_=e("helpDialog.title"),t[15]=e,t[16]=_):_=t[16];let U;t[17]!==_?(U=s.jsxs(hs,{className:"flex items-center gap-2",children:[V,_]}),t[17]=_,t[18]=U):U=t[18];let B;t[19]!==e?(B=e("helpDialog.description"),t[19]=e,t[20]=B):B=t[20];let z;t[21]!==B?(z=s.jsx(Ss,{children:B}),t[21]=B,t[22]=z):z=t[22],t[23]!==U||t[24]!==z?(b=s.jsxs(ys,{children:[U,z]}),t[23]=U,t[24]=z,t[25]=b):b=t[25],u="flex-1 overflow-y-auto mt-3 pr-1",p="space-y-4",m=R.map(K=>s.jsxs("div",{children:[s.jsx("h3",{className:"typography-meta font-semibold text-muted-foreground uppercase tracking-wider mb-2",children:e(K.categoryKey)}),s.jsx("div",{className:"space-y-1",children:K.items.map(F=>{const G=F.id?Wp(F.id,Array.isArray(F.keys)?F.keys[0]:F.keys,a):Array.isArray(F.keys)?F.keys:F.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:[F.icon&&s.jsx(D,{name:F.icon,className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"typography-meta",children:e(F.descriptionKey)})]}),s.jsx("div",{className:"flex items-center gap-1",children:(Array.isArray(G)?G:[G]).map((Q,te)=>s.jsxs(l.Fragment,{children:[te>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:Q})]},`${Q}-${te}`))})]},F.id||F.descriptionKey)})})]},K.categoryKey)),t[1]=n,t[2]=r,t[3]=a,t[4]=e,t[5]=c,t[6]=d,t[7]=p,t[8]=m,t[9]=u,t[10]=f,t[11]=b,t[12]=h,t[13]=v}else c=t[5],d=t[6],p=t[7],m=t[8],u=t[9],f=t[10],b=t[11],h=t[12],v=t[13];let x;t[26]!==p||t[27]!==m?(x=s.jsx("div",{className:p,children:m}),t[26]=p,t[27]=m,t[28]=x):x=t[28];let g;t[29]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(D,{name:"question",className:"h-3.5 w-3.5 text-muted-foreground mt-0.5"}),t[29]=g):g=t[29];let w;t[30]!==e?(w=e("helpDialog.proTips.title"),t[30]=e,t[31]=w):w=t[31];let y;t[32]!==w?(y=s.jsx("p",{className:"font-medium mb-1",children:w}),t[32]=w,t[33]=y):y=t[33];let C;t[34]!==a||t[35]!==e?(C=e("helpDialog.proTips.commandPalette",{shortcut:Wp("open_command_palette",`${o} P`,a)}),t[34]=a,t[35]=e,t[36]=C):C=t[36];let k;t[37]!==C?(k=s.jsxs("li",{children:["• ",C]}),t[37]=C,t[38]=k):k=t[38];let j;t[39]!==e?(j=e("helpDialog.proTips.recentSessions"),t[39]=e,t[40]=j):j=t[40];let S;t[41]!==j?(S=s.jsxs("li",{children:["• ",j]}),t[41]=j,t[42]=S):S=t[42];let I;t[43]!==e?(I=e("helpDialog.proTips.themeCycling"),t[43]=e,t[44]=I):I=t[44];let M;t[45]!==I?(M=s.jsxs("li",{children:["• ",I]}),t[45]=I,t[46]=M):M=t[46];let P;t[47]!==k||t[48]!==S||t[49]!==M?(P=s.jsxs("ul",{className:"space-y-0.5 typography-meta",children:[k,S,M]}),t[47]=k,t[48]=S,t[49]=M,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:[g,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 T;return t[63]!==d||t[64]!==E||t[65]!==h||t[66]!==v?(T=s.jsx(d,{open:h,onOpenChange:v,children:E}),t[63]=d,t[64]=E,t[65]=h,t[66]=v,t[67]=T):T=t[67],T};function r6(t){return t.isHelpDialogOpen}function a6(t){return t.setHelpDialogOpen}function i6(t){return t.shortcutOverrides}const o6=()=>{const t=st.c(32),{t:e}=dt(),n=Re(l6),r=Re(c6),a=Re(d6);let i;t[0]!==a||t[1]!==e?(i=async()=>{if(!a)return;if((await In(a)).ok){H.success(e("openCodeStatusDialog.toast.copiedTitle"),{description:e("openCodeStatusDialog.toast.copiedDescription")});return}H.error(e("openCodeStatusDialog.toast.copyFailed"))},t[0]=a,t[1]=e,t[2]=i):i=t[2];const o=i;let c;t[3]!==e?(c=e("openCodeStatusDialog.title"),t[3]=e,t[4]=c):c=t[4];let d;t[5]!==c?(d=s.jsx(hs,{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(Ss,{children:p}),t[9]=p,t[10]=m):m=t[10];let u;t[11]!==d||t[12]!==m?(u=s.jsxs(ys,{children:[d,m]}),t[11]=d,t[12]=m,t[13]=u):u=t[13];let f;t[14]!==e?(f=e("openCodeStatusDialog.actions.copy"),t[14]=e,t[15]=f):f=t[15];let b;t[16]!==o||t[17]!==f?(b=s.jsx("div",{className:"flex items-center justify-end",children:s.jsx("button",{type:"button",onClick:o,className:"app-region-no-drag inline-flex h-9 items-center justify-center rounded-md px-3 typography-ui-label font-medium text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:f})}),t[16]=o,t[17]=f,t[18]=b):b=t[18];let h;t[19]!==a||t[20]!==e?(h=a||e("openCodeStatusDialog.empty.noData"),t[19]=a,t[20]=e,t[21]=h):h=t[21];let v;t[22]!==h?(v=s.jsx("pre",{className:"max-h-[60vh] overflow-auto rounded-lg bg-surface-muted p-4 typography-code text-foreground whitespace-pre-wrap",children:h}),t[22]=h,t[23]=v):v=t[23];let x;t[24]!==u||t[25]!==b||t[26]!==v?(x=s.jsxs(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 g;return t[28]!==n||t[29]!==r||t[30]!==x?(g=s.jsx(ps,{open:n,onOpenChange:r,children:x}),t[28]=n,t[29]=r,t[30]=x,t[31]=g):g=t[31],g};function l6(t){return t.isOpenCodeStatusDialogOpen}function c6(t){return t.setOpenCodeStatusDialogOpen}function d6(t){return t.openCodeStatusText}const u6=180,Kp=600,m6=1,p6=6,f6=({currentSessionId:t,sortedSessions:e,recentSessionIds:n=[],ensureSessionRenderable:r})=>{const a=l.useRef(new Map),i=l.useRef([]),o=l.useRef(new Set),c=l.useMemo(()=>on(),[]),d=l.useCallback(()=>{if(!(c||typeof window>"u"))for(;o.current.size<m6&&i.current.length>0;){const m=i.current.shift();if(!m)break;Lt.getState().currentSessionId!==m&&(Eu(m).renderable||(o.current.add(m),r(m).catch(()=>{}).finally(()=>{o.current.delete(m),d()})))}},[r,c]),p=l.useCallback(m=>{if(c||!m||m===t||typeof window>"u"||Eu(m).renderable||o.current.has(m)||i.current.includes(m))return;i.current.length>=p6&&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()},u6);a.current.set(m,f)},[t,c,d]);l.useEffect(()=>{if(c||!t||e.length===0)return;const m=window.setTimeout(()=>{const u=e.findIndex(f=>f.id===t);u<0||(p(e[u-1]?.id),p(e[u+1]?.id))},Kp);return()=>window.clearTimeout(m)},[t,c,p,e]),l.useEffect(()=>{if(c||!t||n.length===0)return;const m=window.setTimeout(()=>{const u=n.indexOf(t);u<0||(p(n[u-1]),p(n[u+1]))},Kp);return()=>window.clearTimeout(m)},[t,c,n,p]),l.useEffect(()=>{const m=a.current;return()=>{m.forEach(u=>{clearTimeout(u)}),m.clear(),i.current=[]}},[])};function Hp(t){const{localBranches:e,remoteBranches:n,query:r}=t,a=r.trim();if(!a)return{matching:[],otherLocal:e,otherRemote:n};const i=Ru(e,a,m=>m),o=Ru(n,a,m=>m),c=[],d=i.other,p=o.other;for(const m of i.matching)c.push({label:m,value:m,source:"local"});for(const m of o.matching)c.push({label:m,value:`remotes/${m}`,source:"remote"});return c.sort((m,u)=>{const f=m.label.localeCompare(u.label,void 0,{sensitivity:"accent"});return f!==0?f:m.source!==u.source?m.source.localeCompare(u.source):m.value.localeCompare(u.value)}),{matching:c,otherLocal:d,otherRemote:p}}function h6({open:t,onOpenChange:e,onSelect:n}){const{t:r}=dt(),a=Re(me=>me.isMobile),{github:i}=Rn(),o=Bn(me=>me.status),c=Bn(me=>me.hasChecked),d=Re(me=>me.setSettingsDialogOpen),p=Re(me=>me.setSettingsPage),m=Ps(me=>me.getActiveProject()),u=m?.path??null,f=Oe.useMemo(()=>u&&m?{id:m.id,path:u}:null,[m,u]),[b,h]=Oe.useState("issues"),[v,x]=Oe.useState(""),[g,w]=Oe.useState([]),[y,C]=Oe.useState([]),[k,j]=Oe.useState(!1),[S,I]=Oe.useState(!1),[M,P]=Oe.useState(null),[A,N]=Oe.useState(null),[E,T]=Oe.useState(null),[R,V]=Oe.useState(!1),[_,U]=Oe.useState(new Map),[B,z]=Oe.useState(1),[K,F]=Oe.useState(!1),G=Oe.useCallback(async()=>{if(!(!u||!i)&&!(c&&o?.connected===!1)){j(!0),P(null),z(1),F(!1);try{if(b==="issues"&&i.issuesList){const me=await i.issuesList(u,{page:1});me.connected===!1?(P(r("session.githubIntegration.error.notConnected")),w([])):(w(me.issues??[]),z(me.page??1),F(!!me.hasMore))}else if(b==="prs"&&i.prsList){const me=await i.prsList(u,{page:1});me.connected===!1?(P(r("session.githubIntegration.error.notConnected")),C([])):(C(me.prs??[]),z(me.page??1),F(!!me.hasMore))}}catch(me){P(me instanceof Error?me.message:r("session.githubIntegration.error.loadDataFailed"))}finally{j(!1)}}},[u,i,c,o,b,r]),Q=Oe.useCallback(async()=>{if(!(!u||!i)&&!(k||S)&&K){I(!0);try{const me=B+1;if(b==="issues"&&i.issuesList){const ye=await i.issuesList(u,{page:me});ye.connected!==!1&&(w(ie=>[...ie,...ye.issues??[]]),z(ye.page??me),F(!!ye.hasMore))}else if(b==="prs"&&i.prsList){const ye=await i.prsList(u,{page:me});ye.connected!==!1&&(C(ie=>[...ie,...ye.prs??[]]),z(ye.page??me),F(!!ye.hasMore))}}catch{}finally{I(!1)}}},[u,i,b,B,K,k,S]);Oe.useEffect(()=>{if(!t){h("issues"),x(""),w([]),C([]),N(null),T(null),V(!1),P(null),U(new Map),z(1),F(!1);return}G()},[t,G]);const te=Oe.useCallback(async me=>{if(!(!f||!me)&&!_.has(me))try{const ie=(await ch(f,{mode:"new",branchName:me,worktreeName:me})).errors.find(ve=>ve.code==="branch_in_use");U(ve=>new Map(ve).set(me,{isValid:!ie,error:ie?r(ie.code==="branch_exists"?"session.githubIntegration.validation.branchAlreadyExists":"session.githubIntegration.validation.branchAlreadyCheckedOut"):null}))}catch{U(ye=>new Map(ye).set(me,{isValid:!1,error:r("session.githubIntegration.validation.failed")}))}},[f,_,r]);Oe.useEffect(()=>{!t||b!=="prs"||y.forEach(me=>{me.head&&te(me.head)})},[t,b,y,te]);const Z=Oe.useMemo(()=>{const me=v.trim().toLowerCase();return me?g.filter(ye=>String(ye.number)===me.replace(/^#/,"")?!0:ye.title.toLowerCase().includes(me)):g},[g,v]),fe=Oe.useMemo(()=>{const me=v.trim().toLowerCase();return me?y.filter(ye=>String(ye.number)===me.replace(/^#/,"")?!0:ye.title.toLowerCase().includes(me)):y},[y,v]),ue=c&&o?.connected===!0,W=()=>{p("github"),d(!0)},q=me=>{N(me),T(null)},J=me=>{T(me),N(null)},ne=()=>{A?n({type:"issue",item:A}):E&&n({type:"pr",item:E,includeDiff:R}),e(!1)},ee=()=>{N(null),T(null),V(!1)},he=A||E&&_.get(E.head??"")?.isValid!==!1,ke=me=>me.head?_.get(me.head)?.isValid===!1:!0,oe=s.jsx(s.Fragment,{children:ue?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:me=>x(me.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"})}),M&&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:M})]})}),!k&&!M&&b==="issues"&&s.jsxs("div",{className:"space-y-0.5 min-h-full",children:[Z.length>0?Z.map(me=>s.jsx("button",{onClick:()=>q(me),className:xe("w-full text-left px-2 py-1.5 rounded transition-colors",A?.number===me.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:["#",me.number]}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("span",{className:"typography-small line-clamp-2",children:me.title}),me.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:[me.sourceRepo.owner,"/",me.sourceRepo.repo]}):null]})]})},`${me.sourceRepo?.owner??""}-${me.sourceRepo?.repo??""}-${me.number}`)):s.jsx("div",{className:"flex items-center justify-center h-[300px] text-center typography-small text-muted-foreground",children:r("session.githubIntegration.empty.noIssuesFound")}),K&&!S&&s.jsx("div",{className:"flex justify-center pt-2",children:s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>{Q()},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&&!M&&b==="prs"&&s.jsxs("div",{className:"space-y-0.5 min-h-full",children:[fe.length>0?fe.map(me=>{const ye=ke(me),ie=me.head?_.get(me.head):void 0;return s.jsx("button",{onClick:()=>!ye&&J(me),disabled:ye,className:xe("w-full text-left px-2 py-1.5 rounded transition-colors",E?.number===me.number?"bg-interactive-selection text-interactive-selection-foreground":ye?"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:["#",me.number]}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("span",{className:"typography-small line-clamp-1",children:me.title}),s.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[s.jsxs("span",{className:"typography-micro text-muted-foreground",children:[me.head," → ",me.base]}),me.sourceRepo?.source==="upstream"?s.jsxs("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info",children:[me.sourceRepo.owner,"/",me.sourceRepo.repo]}):null,ye&&ie?.error&&s.jsx("span",{className:"typography-micro text-destructive",children:ie.error})]})]})]})},`${me.sourceRepo?.owner??""}-${me.sourceRepo?.repo??""}-${me.number}`)}):s.jsx("div",{className:"flex items-center justify-center h-[300px] text-center typography-small text-muted-foreground",children:r("session.githubIntegration.empty.noPullRequestsFound")}),K&&!S&&s.jsx("div",{className:"flex justify-center pt-2",children:s.jsx(be,{variant:"ghost",size:"sm",onClick:()=>{Q()},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(be,{onClick:W,size:"sm",children:r("session.githubIntegration.connect.action")})]})}),ge=s.jsxs("div",{className:xe("w-full",a?"flex flex-col gap-2":"flex flex-row items-center"),children:[s.jsxs("div",{className:xe("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:ee,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(fs,{checked:R,onChange:me=>V(me),ariaLabel:r("session.githubIntegration.includeDiffAria")}),s.jsx("span",{className:"typography-small text-foreground",children:r("session.githubIntegration.includeDiff")})]})]}),s.jsxs("div",{className:xe("flex gap-2",a?"w-full order-2":"justify-end"),children:[s.jsx(be,{variant:"outline",size:"sm",onClick:()=>e(!1),className:xe(a&&"flex-1"),children:r("session.githubIntegration.actions.cancel")}),s.jsx(be,{size:"sm",onClick:ne,disabled:!he,className:xe(a&&"flex-1"),children:r("session.githubIntegration.actions.select")})]})]});return s.jsx(s.Fragment,{children:a?s.jsx(Lr,{open:t,title:r("session.githubIntegration.title"),onClose:()=>e(!1),footer:ue?ge:void 0,renderHeader:me=>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")}),me]}),s.jsx("div",{className:"w-full",children:s.jsx($r,{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:ye=>{h(ye),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:ee,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:oe}):s.jsx(ps,{open:t,onOpenChange:e,children:s.jsxs(ms,{className:"max-w-2xl max-h-[70vh] flex flex-col",children:[s.jsx(ys,{className:"flex flex-row items-center justify-between",children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsxs(hs,{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($r,{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:me=>{h(me),x("")},variant:"active-pill",layoutMode:"fit"})})]})}),oe,s.jsx(Vs,{className:"mt-1",children:ge})]})})})}const Vi=t=>t.trim().replace(/^refs\/heads\//,"").replace(/^heads\//,"").replace(/\s+/g,"-").replace(/^\/+|\/+$/g,""),Dn=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),Gp="oc:lastWorktreeSourceBranch",g6=t=>String(t).trim().toLowerCase().replace(/[^a-z0-9._-]+/g,"-").replace(/-+/g,"-").replace(/^-+|-+$/g,"")||"pr-head",qp=(t,e,n)=>{const r=Vi(t.head||"");if(!r)throw new Error("PR head branch is missing");if(e.includes(r))return{existingBranch:r,setUpstream:void 0,upstreamRemote:void 0,upstreamBranch:void 0,ensureRemoteName:void 0,ensureRemoteUrl:void 0,sourceLabel:r};const a=n.find(p=>{const m=p.indexOf("/");return m<=0||m>=p.length-1?!1:p.slice(m+1)===r});if(a){const p=a.indexOf("/"),m=a.slice(0,p);return{existingBranch:`remotes/${a}`,setUpstream:!0,upstreamRemote:m,upstreamBranch:r,ensureRemoteName:void 0,ensureRemoteUrl:void 0,sourceLabel:`${m}/${r}`}}const i=String(t.headLabel||"").split(":")[0]?.trim(),o=t.headRepo?.owner||i||"pr-head",c=`pr-${g6(o)}`,d=t.headRepo?.sshUrl||t.headRepo?.cloneUrl||"";if(!d)throw new Error("PR head repository URL is unavailable");return{existingBranch:`remotes/${c}/${r}`,setUpstream:!0,upstreamRemote:c,upstreamBranch:r,ensureRemoteName:c,ensureRemoteUrl:d,sourceLabel:`${c}/${r}`}},x6=t=>{const e={repo:t.repo??null,issue:t.issue,comments:t.comments};return`GitHub issue context (JSON)
178
+ ${JSON.stringify(e,null,2)}`},b6=t=>`GitHub pull request context (JSON)
179
+ ${JSON.stringify(t,null,2)}`;function y6({open:t,onOpenChange:e,onWorktreeCreated:n}){const{t:r}=dt(),{github:a,git:i}=Rn(),o=Re(le=>le.isMobile),c=Bn(le=>le.status),d=Bn(le=>le.hasChecked),p=Ps(le=>le.getActiveProject()),m=p?.path??null,u=Oe.useMemo(()=>m&&p?{id:p.id,path:m}:null,[p,m]),[f,b]=Oe.useState("new-branch"),[h,v]=Oe.useState({branchName:"",worktreeName:"",isSyncingWorktreeName:!0,sourceBranch:"",linkedIssue:null,linkedPr:null,includePrDiff:!1}),[x,g]=Oe.useState({selectedBranch:"",worktreeName:""}),w=Md(m),y=dh(m),C=tn(le=>le.fetchBranches),k=Oe.useMemo(()=>w?.all?w.all.filter(le=>!le.startsWith("remotes/")).sort():[],[w]),j=Oe.useMemo(()=>w?.all?w.all.filter(le=>le.startsWith("remotes/")).map(le=>le.replace(/^remotes\//,"")).sort():[],[w]),S=Lt(le=>le.availableWorktreesByProject),I=Oe.useMemo(()=>{if(!m)return new Set;const le=S.get(m)??[];return new Set(le.map(Me=>Me.name))},[S,m]),M=Oe.useCallback((le=10)=>{for(let Me=0;Me<le;Me++){const Ge=ec();if(!I.has(Ge))return Ge}return`${ec()}-${Date.now().toString(36).slice(-4)}`},[I]),[P,A]=Oe.useState(!1),[N,E]=Oe.useState(!1),[T,R]=Oe.useState(!1),[V,_]=Oe.useState(!1),[U,B]=Oe.useState(!1),[z,K]=Oe.useState(""),[F,G]=Oe.useState(""),Q=Oe.useRef(null),te=Oe.useRef(null),Z=Oe.useRef(null),fe=Oe.useRef(null),ue=Oe.useCallback(le=>{le.stopPropagation()},[]),W=Oe.useCallback(le=>{let Me=le;for(;Me&&Me!==document.body;){const{overflowY:Ge}=window.getComputedStyle(Me);if((Ge==="auto"||Ge==="scroll")&&Me.scrollHeight>Me.clientHeight)return Me;Me=Me.parentElement}return null},[]),q=Oe.useCallback(le=>{le&&(le.scrollTop=0)},[]),J=Oe.useCallback(le=>{const Me=le.current?.querySelector('[data-slot="command-list"]')??null;q(Me)},[q]),ne=Oe.useCallback(le=>{const Me=W(le.current);q(Me)},[W,q]),ee=Oe.useMemo(()=>Hp({localBranches:k,remoteBranches:j,query:z}),[k,j,z]),he=Oe.useMemo(()=>Hp({localBranches:k,remoteBranches:j,query:F}),[k,j,F]),ke=z.trim().length>0,oe=F.trim().length>0,ge=ee.matching.length>0,me=he.matching.length>0,ye=!!(m&&i),ie=Oe.useCallback(()=>{!m||!i||C(m,i)},[m,i,C]);Oe.useEffect(()=>{!N&&!V&&K("")},[N,V]),Oe.useEffect(()=>{!T&&!U&&G("")},[T,U]),Oe.useEffect(()=>{N&&J(Q),V&&ne(Z)},[N,V,z,J,ne]),Oe.useEffect(()=>{T&&J(te),U&&ne(fe)},[T,U,F,J,ne]);const[ve,X]=Oe.useState({isValidating:!1,branchError:null,worktreeError:null,touched:!1}),[Se,Ae]=Oe.useState(!1),[pe,we]=Oe.useState(null),Ie=Oe.useCallback(()=>{const le=bt.getState(),Me=le.getVisibleAgents();if(le.settingsDefaultAgent){const Ge=Me.find(at=>at.name===le.settingsDefaultAgent);if(Ge)return Ge.name}return Me.find(Ge=>Ge.name==="build")?.name||Me[0]?.name},[]),Y=Oe.useCallback(()=>{const le=bt.getState(),Me=le.settingsDefaultModel;if(!Me)return null;const Ge=pi(Me);if(!Ge)return null;const{providerId:at,modelId:Ye}=Ge;return le.getModelMetadata(at,Ye)?{providerID:at,modelID:Ye}:null},[]),re=Oe.useCallback((le,Me)=>{const Ge=bt.getState(),at=Ge.settingsDefaultVariant;if(!at)return;const ut=Ge.providers.find(rt=>rt.id===le)?.models.find(rt=>rt.id===Me)?.variants;if(ut&&Object.prototype.hasOwnProperty.call(ut,at))return at},[]),Pe=Oe.useCallback(le=>{const Me=bt.getState();try{No.getState().saveSessionModelSelection(le.sessionId,le.providerID,le.modelID)}catch{}if(le.agentName){try{Me.setAgent(le.agentName)}catch{}try{No.getState().saveSessionAgentSelection(le.sessionId,le.agentName)}catch{}try{No.getState().saveAgentModelForSession(le.sessionId,le.agentName,le.providerID,le.modelID)}catch{}if(le.variant!==void 0){try{Me.setCurrentVariant(le.variant)}catch{}try{No.getState().saveAgentModelVariantForSession(le.sessionId,le.agentName,le.providerID,le.modelID,le.variant)}catch{}}}},[]),ce=Oe.useCallback(async le=>{if(!m||!a)return;const Me=bt.getState(),Ge=Pl.getState().lastUsedProvider,at=Y(),Ye=at?.providerID||Me.currentProviderId||Ge?.providerID,Xe=at?.modelID||Me.currentModelId||Ge?.modelID,ut=Ie()||Me.currentAgentName||void 0;if(!Ye||!Xe){H.error(r("session.newWorktree.error.noModelSelected"));return}const rt=re(Ye,Xe);if(Pe({sessionId:le.sessionId,providerID:Ye,modelID:Xe,agentName:ut,variant:rt}),le.issue){if(!a.issueGet||!a.issueComments)return;const it=await a.issueGet(m,le.issue.number);if(it.connected===!1||!it.repo||!it.issue)throw new Error("Failed to load issue context");const nt=await a.issueComments(m,le.issue.number);if(nt.connected===!1)throw new Error("Failed to load issue comments");const Ne=await yn("github.issue.review.visible",{issue_number:String(le.issue.number)}),Ke=await yn("github.issue.review.instructions"),Ve=x6({repo:it.repo,issue:it.issue,comments:nt.comments??[]});await sn.sendMessage({id:le.sessionId,providerID:Ye,modelID:Xe,agent:ut,variant:rt,text:Ne,additionalParts:[{text:Ke,synthetic:!0},{text:Ve,synthetic:!0}]}),H.success(r("session.newWorktree.toast.sessionFromIssue"));return}if(le.pr){if(!a.prContext)return;const it=await a.prContext(m,le.pr.number,{includeDiff:le.includeDiff,includeCheckDetails:!1});if(it.connected===!1||!it.repo||!it.pr)throw new Error("Failed to load PR context");const nt=await yn("github.pr.review.visible",{pr_number:String(le.pr.number)}),Ne=await yn("github.pr.review.instructions"),Ke=b6(it);await sn.sendMessage({id:le.sessionId,providerID:Ye,modelID:Xe,agent:ut,variant:rt,text:nt,additionalParts:[{text:Ne,synthetic:!0},{text:Ke,synthetic:!0}]}),H.success(r("session.newWorktree.toast.sessionFromPr"))}},[Pe,a,m,Ie,Y,re,r]),Ce=f==="new-branch"?h:x;Oe.useEffect(()=>{if(!w?.all||!m||h.sourceBranch)return;(async()=>{try{const Me=await co(m).catch(()=>null),Ge=localStorage.getItem(Gp),at=Ge&&w.all?.includes(Ge)?Ge:Me&&w.all?.includes(Me)?Me:w.all?.includes("main")?"main":w.all?.includes("master")?"master":w.all?.[0]||"";at&&v(Ye=>({...Ye,sourceBranch:at}))}catch{}})()},[w,m,h.sourceBranch]),Oe.useEffect(()=>{if(!t)return;b("new-branch"),g({selectedBranch:"",worktreeName:""}),E(!1),R(!1),_(!1),B(!1),K(""),G(""),X({isValidating:!1,branchError:null,worktreeError:null,touched:!1});const le=M();v({branchName:le,worktreeName:le,isSyncingWorktreeName:!0,sourceBranch:"",linkedIssue:null,linkedPr:null,includePrDiff:!1})},[t,M]),Oe.useEffect(()=>{if(f!=="new-branch"||!h.isSyncingWorktreeName)return;const le=Vi(h.branchName),Me=Dn(le);v(Ge=>({...Ge,worktreeName:Me}))},[f,h.branchName,h.isSyncingWorktreeName]);const Te=Oe.useCallback(async()=>{if(!u||!ve.touched||Se)return;pe&&pe.abort();const le=new AbortController;we(le),X(Me=>({...Me,isValidating:!0}));try{const Me=f==="new-branch"?h.branchName:x.selectedBranch,Ge=Ce.worktreeName,at=Vi(Me),Ye=Dn(Ge);let Xe=null,ut=null;if(at||(Xe=r("session.newWorktree.error.branchNameRequired")),Ye||(ut=r("session.newWorktree.error.worktreeDirectoryRequired")),at&&Ye){const rt=f==="new-branch"?h.linkedPr:null,it=rt?qp(rt,k,j):null,nt=await ch(u,{mode:f==="existing-branch"||it?"existing":"new",branchName:at,worktreeName:Ye,existingBranch:it?.existingBranch??(f==="existing-branch"?at:void 0),...it?.ensureRemoteName?{ensureRemoteName:it.ensureRemoteName}:{},...it?.ensureRemoteUrl?{ensureRemoteUrl:it.ensureRemoteUrl}:{}});if(le.signal.aborted)return;nt.ok||nt.errors.forEach(Ne=>{if(Ne.code==="worktree_exists"){ut=ut??Ne.message;return}Ne.code.startsWith("branch_")&&(Xe=Xe??Ne.message)})}le.signal.aborted||X(rt=>({...rt,isValidating:!1,branchError:Xe,worktreeError:ut}))}catch{le.signal.aborted||X(Me=>({...Me,isValidating:!1}))}},[u,f,h.branchName,h.linkedPr,x.selectedBranch,Ce.worktreeName,k,j,ve.touched,pe,Se,r]),$e=f==="new-branch"?h.branchName:x.selectedBranch;Oe.useEffect(()=>{if(!t||!u||!ve.touched||Se)return;const le=setTimeout(()=>{Te()},300);return()=>clearTimeout(le)},[Ce.worktreeName,$e,t,u,Te,ve.touched,Se]);const De=async()=>{if(!u||!m){H.error(r("session.newWorktree.error.noActiveProject"));return}X(Ye=>({...Ye,touched:!0}));const le=f==="new-branch"?h.branchName:x.selectedBranch,Me=Ce.worktreeName,Ge=Vi(le),at=Dn(Me);if(!Ge){H.error(r("session.newWorktree.error.branchNameRequired"));return}if(!at){H.error(r("session.newWorktree.error.worktreeDirectoryRequired"));return}pe&&(pe.abort(),we(null)),X(Ye=>({...Ye,isValidating:!1,branchError:null,worktreeError:null})),Ae(!0);try{const Ye=await _d(u),Xe=f==="new-branch"?h.linkedPr:null,ut=h.sourceBranch;let rt="";const it=(()=>{if(Xe){const He=qp(Xe,k,j);return rt=He.sourceLabel,{preferredName:Ge||at,mode:"existing",branchName:Ge,worktreeName:at,existingBranch:He.existingBranch,setupCommands:Ye,setUpstream:He.setUpstream,upstreamRemote:He.upstreamRemote,upstreamBranch:He.upstreamBranch,...He.ensureRemoteName?{ensureRemoteName:He.ensureRemoteName}:{},...He.ensureRemoteUrl?{ensureRemoteUrl:He.ensureRemoteUrl}:{}}}return rt=f==="new-branch"?ut:"",{preferredName:Ge||at,mode:f==="existing-branch"?"existing":"new",branchName:f==="existing-branch"?void 0:Ge,worktreeName:at,existingBranch:f==="existing-branch"?Ge:void 0,setupCommands:Ye,...ut&&f==="new-branch"?{startRef:ut}:{}}})(),nt=await hy(m,it),Ne=await gy(u,nt),Ke=f==="new-branch"?h.linkedIssue:null,Ve=f==="new-branch"?h.linkedPr:null,qe=f==="new-branch"?h.includePrDiff:!1;let lt=null;if(Ke||Ve){const He=Ke?`#${Ke.number} ${Ke.title}`.trim():Ve?`#${Ve.number} ${Ve.title}`.trim():r("session.newWorktree.newSessionTitle"),ze=await xy(He,Ne.path,null);if(!ze?.id)throw new Error("Failed to create session");lt=ze.id,by(ze.id,He).catch(()=>{});try{Lt.getState().initializeNewOpenChamberSession(ze.id,bt.getState().agents)}catch{}}h.sourceBranch&&f==="new-branch"&&!h.linkedPr&&localStorage.setItem(Gp,h.sourceBranch),H.success(r("session.newWorktree.toast.worktreeCreated"),{description:r("session.newWorktree.toast.worktreeCreatedDescription",{target:`${Ne.branch||Ne.name}${rt?` ${r("session.newWorktree.fromSource",{source:rt})}`:""}`})}),e(!1),lt?(n?.(Ne.path,{sessionId:lt}),ce({sessionId:lt,issue:Ke,pr:Ve,includeDiff:qe}).catch(He=>{const ze=He instanceof Error?He.message:r("session.newWorktree.error.sendGitHubContextFailed");H.error(r("session.newWorktree.error.sendGitHubContextFailed"),{description:ze})})):n?.(Ne.path)}catch(Ye){const Xe=Ye instanceof Error?Ye.message:r("session.newWorktree.error.createWorktreeFailed");H.error(r("session.newWorktree.error.createWorktreeFailed"),{description:Xe})}finally{Ae(!1)}},de=le=>{b(le),X(Me=>({...Me,touched:!1,branchError:null,worktreeError:null}))},O=le=>{if(!le){v(Me=>({...Me,linkedIssue:null,linkedPr:null,includePrDiff:!1,branchName:""}));return}if(le.type==="issue"){const Me=le.item,Ge=`issue-${Me.number}-${ec()}`;v(at=>({...at,linkedIssue:Me,linkedPr:null,includePrDiff:!1,branchName:Ge,worktreeName:Dn(Ge),isSyncingWorktreeName:!0}))}else if(le.type==="pr"){const Me=le.item;v(Ge=>({...Ge,linkedPr:Me,linkedIssue:null,includePrDiff:le.includeDiff??!1,branchName:Me.head,worktreeName:Dn(Me.head),isSyncingWorktreeName:!0}))}},L=d&&c?.connected===!0,je=(f==="existing-branch"?!!x.selectedBranch&&!!x.worktreeName&&!ve.branchError&&!ve.worktreeError:!!Vi(h.branchName)&&!!h.worktreeName&&!ve.branchError&&!ve.worktreeError)&&!Se,ae=()=>{v(le=>({...le,linkedIssue:null,linkedPr:null,branchName:"",includePrDiff:!1,isSyncingWorktreeName:!0}))},_e=s.jsxs("div",{className:xe("flex gap-2",o?"flex-col w-full":"flex-row items-center"),children:[s.jsx("div",{className:xe("flex items-center gap-1.5 text-destructive",o?"w-full justify-center order-first":"mr-auto"),children:ve.touched&&(ve.branchError||ve.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:ve.branchError||ve.worktreeError})]})}),s.jsxs("div",{className:xe("flex gap-2",o&&"w-full"),children:[s.jsx(be,{variant:"outline",size:"sm",onClick:()=>e(!1),disabled:Se,className:xe(o&&"flex-1"),children:r("session.newWorktree.actions.cancel")}),s.jsxs(be,{size:"sm",onClick:De,disabled:!je||Se,className:xe("gap-1.5",o&&"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:[o?s.jsxs(Lr,{open:t,title:r("session.newWorktree.title"),onClose:()=>e(!1),footer:_e,children:[s.jsx("div",{className:"w-full mb-4",children:s.jsx($r,{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:le=>de(le),variant:"active-pill",layoutMode:"fit",className:"w-full"})}),s.jsxs("div",{className:"space-y-6",children:[f==="existing-branch"?s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.selectBranch")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(be,{variant:"outline",size:"sm",onClick:()=>_(!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(be,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0 shrink-0",onClick:ie,disabled:!ye||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(Lr,{open:V,title:r("session.newWorktree.selectBranch"),onClose:()=>_(!1),children:s.jsxs("div",{className:"space-y-4",ref:Z,children:[s.jsx(Bt,{value:z,onChange:le=>K(le.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&&j.length===0?s.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noBranchesFound")}):s.jsxs("div",{className:"space-y-4",children:[ke&&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:ee.matching.map(le=>s.jsx("button",{onClick:()=>{g(Me=>({...Me,selectedBranch:le.value,worktreeName:Dn(le.label)})),X(Me=>({...Me,touched:!0})),_(!1)},className:xe("w-full text-left px-3 py-2.5 rounded-md transition-colors",x.selectedBranch===le.value?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:le.label})},`${le.source}-${le.value}`))})]}),ke&&!ge&&s.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),ee.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(ke?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches")}),s.jsx("div",{className:"space-y-1",children:ee.otherLocal.map(le=>s.jsx("button",{onClick:()=>{g(Me=>({...Me,selectedBranch:le,worktreeName:Dn(le)})),X(Me=>({...Me,touched:!0})),_(!1)},className:xe("w-full text-left px-3 py-2.5 rounded-md transition-colors",x.selectedBranch===le?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:le})},le))})]}),ee.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(ke?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches")}),s.jsx("div",{className:"space-y-1",children:ee.otherRemote.map(le=>s.jsx("button",{onClick:()=>{g(Me=>({...Me,selectedBranch:`remotes/${le}`,worktreeName:Dn(le)})),X(Me=>({...Me,touched:!0})),_(!1)},className:xe("w-full text-left px-3 py-2.5 rounded-md transition-colors",x.selectedBranch===`remotes/${le}`?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:le})},`remotes/${le}`))})]})]})]})})]}):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"&&L&&s.jsxs(be,{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"}),h.linkedIssue||h.linkedPr?r("session.newWorktree.actions.change"):r("session.newWorktree.actions.startFromGitHubIssuePr")]})]}),s.jsx(Bt,{value:h.branchName,onChange:le=>{v(Me=>({...Me,branchName:le.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>X(le=>({...le,touched:!0})),placeholder:r("session.newWorktree.branchNamePlaceholder"),disabled:!!h.linkedPr,className:xe("h-8",ve.touched&&ve.branchError&&"border-destructive",h.linkedPr&&"bg-muted text-muted-foreground")}),h.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(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:h.linkedPr.head})})]}),h.linkedIssue&&!h.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:h.linkedIssue.number,title:h.linkedIssue.title})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("label",{className:"typography-ui-label text-foreground font-semibold",children:r("session.newWorktree.worktreeDirectory")}),f!=="existing-branch"&&s.jsxs("button",{onClick:()=>{const le=Dn(f==="new-branch"?h.branchName:"");v(Me=>({...Me,worktreeName:le,isSyncingWorktreeName:!0}))},disabled:!h.branchName||h.worktreeName===Dn(h.branchName),className:xe("flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded",h.worktreeName===Dn(h.branchName)||!h.branchName?"text-muted-foreground/40 cursor-not-allowed":"text-muted-foreground hover:text-foreground hover:bg-muted"),title:r("session.newWorktree.resetToMatchBranchName"),children:[s.jsx(D,{name:"refresh",className:"h-3 w-3"}),s.jsx("span",{children:r("session.newWorktree.actions.reset")})]})]}),s.jsx(Bt,{value:Ce.worktreeName,onChange:le=>{f==="new-branch"?v(Me=>({...Me,worktreeName:le.target.value,isSyncingWorktreeName:!1})):g(Me=>({...Me,worktreeName:le.target.value}))},onBlur:()=>X(le=>({...le,touched:!0})),placeholder:r("session.newWorktree.worktreeDirectoryPlaceholder"),className:xe("h-8",ve.touched&&ve.worktreeError&&"border-destructive")})]}),f==="new-branch"&&!h.linkedPr&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.sourceBranch")}),s.jsxs(be,{variant:"outline",size:"sm",onClick:()=>B(!0),className:"w-full justify-between h-9",children:[s.jsx("span",{className:h.sourceBranch?"text-foreground":"text-muted-foreground",children:h.sourceBranch||r("session.newWorktree.selectSourceBranchPlaceholder")}),s.jsx(D,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"})]}),h.sourceBranch&&s.jsx("div",{className:"typography-micro text-muted-foreground",children:r("session.newWorktree.newBranchFromSource",{source:h.sourceBranch})}),s.jsx(Lr,{open:U,title:r("session.newWorktree.selectSourceBranch"),onClose:()=>B(!1),children:s.jsxs("div",{className:"space-y-4",ref:fe,children:[s.jsx(Bt,{value:F,onChange:le=>G(le.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&&j.length===0?s.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noBranchesFound")}):s.jsxs("div",{className:"space-y-4",children:[oe&&me&&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:he.matching.map(le=>s.jsx("button",{onClick:()=>{v(Me=>({...Me,sourceBranch:le.value})),B(!1)},className:xe("w-full text-left px-3 py-2.5 rounded-md transition-colors",h.sourceBranch===le.value?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:le.label})},`${le.source}-${le.value}`))})]}),oe&&!me&&s.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),he.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(oe?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches")}),s.jsx("div",{className:"space-y-1",children:he.otherLocal.map(le=>s.jsx("button",{onClick:()=>{v(Me=>({...Me,sourceBranch:le})),B(!1)},className:xe("w-full text-left px-3 py-2.5 rounded-md transition-colors",h.sourceBranch===le?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:le})},le))})]}),he.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(oe?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches")}),s.jsx("div",{className:"space-y-1",children:he.otherRemote.map(le=>s.jsx("button",{onClick:()=>{v(Me=>({...Me,sourceBranch:`remotes/${le}`})),B(!1)},className:xe("w-full text-left px-3 py-2.5 rounded-md transition-colors",h.sourceBranch===`remotes/${le}`?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:le})},`remotes/${le}`))})]})]})]})})]}),(h.linkedIssue||h.linkedPr)&&f==="new-branch"&&s.jsxs("div",{className:"mt-2 px-2 py-1.5 rounded bg-muted/30",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(D,{name:"github",className:"h-3.5 w-3.5 text-status-success shrink-0"}),h.linkedIssue&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.issueNumber",{number:h.linkedIssue.number})}),h.linkedPr&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.prNumber",{number:h.linkedPr.number})}),s.jsx("span",{className:"typography-micro text-foreground truncate flex-1",children:h.linkedIssue?.title||h.linkedPr?.title}),s.jsx("a",{href:h.linkedIssue?.url||h.linkedPr?.url,target:"_blank",rel:"noopener noreferrer",className:"text-muted-foreground hover:text-foreground shrink-0",onClick:le=>le.stopPropagation(),children:s.jsx(D,{name:"external-link",className:"h-3 w-3"})}),s.jsx("button",{onClick:ae,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"})})]}),h.linkedPr&&s.jsxs("div",{className:"flex items-center gap-2 mt-0.5 pl-5",children:[s.jsxs("span",{className:"typography-micro text-muted-foreground",children:[h.linkedPr.head," → ",h.linkedPr.base]}),h.includePrDiff&&s.jsx("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success",children:r("session.newWorktree.includeDiffBadge")})]})]})]})]}):s.jsx(ps,{open:t,onOpenChange:e,children:s.jsxs(ms,{className:"max-w-lg max-h-[80vh] flex flex-col",children:[s.jsx(ys,{className:"flex flex-row items-center justify-between",children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsxs(hs,{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($r,{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:le=>de(le),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(Ts,{open:N,onOpenChange:E,children:[s.jsx(As,{asChild:!0,children:s.jsxs(be,{variant:"outline",size:"sm",className:"h-9 min-w-[220px] max-w-full justify-between gap-2",children:[s.jsx("span",{className:xe("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(Ds,{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:Q,children:s.jsxs(La,{shouldFilter:!1,children:[s.jsx(da,{placeholder:r("session.newWorktree.searchBranches"),value:z,onValueChange:K,onKeyDown:ue}),s.jsx($a,{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&&j.length===0?s.jsx(_a,{children:r("session.newWorktree.noBranchesFound")}):s.jsxs(s.Fragment,{children:[ke&&ge&&s.jsx(Mn,{heading:r("session.newWorktree.matchingBranches"),children:ee.matching.map(le=>s.jsx(jn,{value:le.value,onSelect:()=>{g(Me=>({...Me,selectedBranch:le.value,worktreeName:Dn(le.label)})),X(Me=>({...Me,touched:!0})),E(!1)},children:s.jsx("span",{className:"typography-small break-all",children:le.label})},`${le.source}-${le.value}`))}),ke&&!ge&&s.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),ee.otherLocal.length>0&&s.jsxs(s.Fragment,{children:[ke&&s.jsx(Ca,{}),s.jsx(Mn,{heading:r(ke?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches"),children:ee.otherLocal.map(le=>s.jsx(jn,{value:le,onSelect:()=>{g(Me=>({...Me,selectedBranch:le,worktreeName:Dn(le)})),X(Me=>({...Me,touched:!0})),E(!1)},children:s.jsx("span",{className:"typography-small break-all",children:le})},`local-${le}`))})]}),ee.otherRemote.length>0&&s.jsxs(s.Fragment,{children:[(ee.otherLocal.length>0||ke)&&s.jsx(Ca,{}),s.jsx(Mn,{heading:r(ke?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches"),children:ee.otherRemote.map(le=>s.jsx(jn,{value:`remotes/${le}`,onSelect:()=>{g(Me=>({...Me,selectedBranch:`remotes/${le}`,worktreeName:Dn(le)})),X(Me=>({...Me,touched:!0})),E(!1)},children:s.jsx("span",{className:"typography-small break-all",children:le})},`remote-${le}`))})]})]})})]})})]}),s.jsx(be,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0 shrink-0",onClick:ie,disabled:!ye||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"&&L&&s.jsxs(be,{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"}),h.linkedIssue||h.linkedPr?r("session.newWorktree.actions.change"):r("session.newWorktree.actions.startFromGitHubIssuePr")]})]}),s.jsx(Bt,{value:h.branchName,onChange:le=>{v(Me=>({...Me,branchName:le.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>X(le=>({...le,touched:!0})),placeholder:r("session.newWorktree.branchNamePlaceholder"),disabled:!!h.linkedPr,className:xe("h-8",ve.touched&&ve.branchError&&"border-destructive",h.linkedPr&&"bg-muted text-muted-foreground")}),h.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(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:h.linkedPr.head})})]}),h.linkedIssue&&!h.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:h.linkedIssue.number,title:h.linkedIssue.title})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("label",{className:"typography-ui-label text-foreground font-semibold",children:r("session.newWorktree.worktreeDirectory")}),f!=="existing-branch"&&s.jsxs("button",{onClick:()=>{const le=Dn(f==="new-branch"?h.branchName:"");v(Me=>({...Me,worktreeName:le,isSyncingWorktreeName:!0}))},disabled:!h.branchName||h.worktreeName===Dn(h.branchName),className:xe("flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded",h.worktreeName===Dn(h.branchName)||!h.branchName?"text-muted-foreground/40 cursor-not-allowed":"text-muted-foreground hover:text-foreground hover:bg-muted"),title:r("session.newWorktree.resetToMatchBranchName"),children:[s.jsx(D,{name:"refresh",className:"h-3 w-3"}),s.jsx("span",{children:r("session.newWorktree.actions.reset")})]})]}),s.jsx(Bt,{value:Ce.worktreeName,onChange:le=>{f==="new-branch"?v(Me=>({...Me,worktreeName:le.target.value,isSyncingWorktreeName:!1})):g(Me=>({...Me,worktreeName:le.target.value}))},onBlur:()=>X(le=>({...le,touched:!0})),placeholder:r("session.newWorktree.worktreeDirectoryPlaceholder"),className:xe("h-8",ve.touched&&ve.worktreeError&&"border-destructive")})]}),f==="new-branch"&&!h.linkedPr&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.sourceBranch")}),s.jsxs(Ts,{open:T,onOpenChange:R,children:[s.jsx(As,{asChild:!0,children:s.jsxs(be,{variant:"outline",size:"sm",className:"h-9 min-w-[220px] max-w-full justify-between gap-2",children:[s.jsx("span",{className:xe("truncate",h.sourceBranch?"text-foreground":"text-muted-foreground"),children:h.sourceBranch||r("session.newWorktree.selectSourceBranchPlaceholder")}),s.jsx(D,{name:"arrow-down-s",className:"h-4 w-4 shrink-0 text-muted-foreground"})]})}),s.jsx(Ds,{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:te,children:s.jsxs(La,{shouldFilter:!1,children:[s.jsx(da,{placeholder:r("session.newWorktree.searchBranches"),value:F,onValueChange:G,onKeyDown:ue}),s.jsx($a,{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&&j.length===0?s.jsx(_a,{children:r("session.newWorktree.noBranchesFound")}):s.jsxs(s.Fragment,{children:[oe&&me&&s.jsx(Mn,{heading:r("session.newWorktree.matchingBranches"),children:he.matching.map(le=>s.jsx(jn,{value:le.value,onSelect:()=>{v(Me=>({...Me,sourceBranch:le.value})),R(!1)},children:s.jsx("span",{className:"typography-small break-all",children:le.label})},`${le.source}-${le.value}`))}),oe&&!me&&s.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),he.otherLocal.length>0&&s.jsxs(s.Fragment,{children:[oe&&s.jsx(Ca,{}),s.jsx(Mn,{heading:r(oe?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches"),children:he.otherLocal.map(le=>s.jsx(jn,{value:le,onSelect:()=>{v(Me=>({...Me,sourceBranch:le})),R(!1)},children:s.jsx("span",{className:"typography-small break-all",children:le})},`local-${le}`))})]}),he.otherRemote.length>0&&s.jsxs(s.Fragment,{children:[(he.otherLocal.length>0||oe)&&s.jsx(Ca,{}),s.jsx(Mn,{heading:r(oe?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches"),children:he.otherRemote.map(le=>s.jsx(jn,{value:`remotes/${le}`,onSelect:()=>{v(Me=>({...Me,sourceBranch:`remotes/${le}`})),R(!1)},children:s.jsx("span",{className:"typography-small break-all",children:le})},`remote-${le}`))})]})]})})]})})]}),h.sourceBranch&&s.jsx("div",{className:"typography-micro text-muted-foreground",children:r("session.newWorktree.newBranchFromSource",{source:h.sourceBranch})})]}),(h.linkedIssue||h.linkedPr)&&f==="new-branch"&&s.jsxs("div",{className:"mt-2 px-2 py-1.5 rounded bg-muted/30",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(D,{name:"github",className:"h-3.5 w-3.5 text-status-success shrink-0"}),h.linkedIssue&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.issueNumber",{number:h.linkedIssue.number})}),h.linkedPr&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.prNumber",{number:h.linkedPr.number})}),s.jsx("span",{className:"typography-micro text-foreground truncate flex-1",children:h.linkedIssue?.title||h.linkedPr?.title}),s.jsx("a",{href:h.linkedIssue?.url||h.linkedPr?.url,target:"_blank",rel:"noopener noreferrer",className:"text-muted-foreground hover:text-foreground shrink-0",onClick:le=>le.stopPropagation(),children:s.jsx(D,{name:"external-link",className:"h-3 w-3"})}),s.jsx("button",{onClick:ae,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"})})]}),h.linkedPr&&s.jsxs("div",{className:"flex items-center gap-2 mt-0.5 pl-5",children:[s.jsxs("span",{className:"typography-micro text-muted-foreground",children:[h.linkedPr.head," → ",h.linkedPr.base]}),h.includePrDiff&&s.jsx("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success",children:r("session.newWorktree.includeDiffBadge")})]})]})]}),s.jsxs(Vs,{className:"mt-1 flex items-center justify-between",children:[s.jsx("div",{className:"flex items-center gap-1.5 text-destructive",children:ve.touched&&(ve.branchError||ve.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:ve.branchError||ve.worktreeError})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(be,{variant:"outline",size:"sm",onClick:()=>e(!1),disabled:Se,children:r("session.newWorktree.actions.cancel")}),s.jsxs(be,{size:"sm",onClick:De,disabled:!je||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(h6,{open:P,onOpenChange:A,onSelect:O})]})}let ai=null,ii=null,el=null,wl=0;const Ma=new Set,v6=3e4,w6=45e3,Pg=()=>{el&&(clearTimeout(el),el=null)},Ag=()=>{if(ii||Ma.size===0)return;const t=Math.min(1e3*Math.pow(2,Math.min(wl,5)),v6);ii=setTimeout(()=>{ii=null,wl+=1,Dg()},t)},jl=()=>{Pg(),ai&&ai.close(),ai=null},Jp=()=>{Pg(),Ma.size!==0&&(el=setTimeout(()=>{jl(),Ag()},w6))},j6=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}},N6=t=>{if(t.type==="openchamber:event-stream-ready"){wl=0;return}if(t.type==="openchamber:heartbeat"||t.type!=="openchamber:scheduled-task-ran")return;const e=t.properties&&typeof t.properties=="object"?t.properties:null,n=typeof e?.projectId=="string"?e.projectId:"",r=typeof e?.taskId=="string"?e.taskId:"",a=typeof e?.ranAt=="number"?e.ranAt:Date.now(),i=e?.status,o=i==="running"||i==="error"?i:"success";if(!n||!r)return;const c={type:"scheduled-task-ran",projectId:n,taskId:r,ranAt:a,status:o,...typeof e?.sessionId=="string"&&e.sessionId.length>0?{sessionId:e.sessionId}:{}};for(const d of Ma)d(c)},Dg=()=>{if(typeof window>"u"||Ma.size===0||typeof EventSource!="function"||ai&&ai.readyState!==EventSource.CLOSED)return;jl();const t=new EventSource("/api/openchamber/events");t.onopen=()=>{Jp()},t.onmessage=e=>{Jp();const n=j6(e.data);n&&N6(n)},t.onerror=()=>{jl(),Ag()},ai=t},Tg=t=>(Ma.add(t),Dg(),()=>{Ma.delete(t),Ma.size===0&&(ii&&(clearTimeout(ii),ii=null),wl=0,jl())}),_l=async(t,e)=>{try{const n=await t.json();if(n&&typeof n.error=="string"&&n.error.trim().length>0)return n.error}catch{return e}return e},xi=t=>{const e=typeof t=="string"?t.trim():"";if(!e)throw new Error("projectId is required");return e},S6=async t=>{const e=xi(t),n=await fetch(`/api/projects/${encodeURIComponent(e)}/scheduled-tasks`);if(!n.ok)throw new Error(await _l(n,"Failed to load scheduled tasks"));const r=await n.json().catch(()=>null);return!r||!Array.isArray(r.tasks)?[]:r.tasks},Yp=async(t,e)=>{const n=xi(t),r=await fetch(`/api/projects/${encodeURIComponent(n)}/scheduled-tasks`,{method:"PUT",headers:{"content-type":"application/json",accept:"application/json"},body:JSON.stringify({task:e})});if(!r.ok)throw new Error(await _l(r,"Failed to save scheduled task"));const a=await r.json().catch(()=>null);return!a||!Array.isArray(a.tasks)?[]:a.tasks},k6=async(t,e)=>{const n=xi(t),r=xi(e),a=await fetch(`/api/projects/${encodeURIComponent(n)}/scheduled-tasks/${encodeURIComponent(r)}`,{method:"DELETE",headers:{accept:"application/json"}});if(!a.ok)throw new Error(await _l(a,"Failed to delete scheduled task"));const i=await a.json().catch(()=>null);return!i||!Array.isArray(i.tasks)?[]:i.tasks},C6=async(t,e)=>{const n=xi(t),r=xi(e),a=await fetch(`/api/projects/${encodeURIComponent(n)}/scheduled-tasks/${encodeURIComponent(r)}/run`,{method:"POST",headers:{accept:"application/json"}});if(!a.ok)throw new Error(await _l(a,"Failed to run scheduled task"));const i=await a.json().catch(()=>null);return{sessionId:typeof i?.sessionId=="string"&&i.sessionId.length>0?i.sessionId:void 0}},Mg=[0,1,2,3,4,5,6],Qp=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"],Xp=()=>{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}`},tl=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},Zp=t=>{const e=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${e}-${n}-${r}`},I6=(t,e,n)=>{const r=tl(t);return r?new Intl.DateTimeFormat(n,{month:"short",day:"numeric",year:"numeric"}).format(r):e},ef=(t,e)=>new Date(t.getFullYear(),t.getMonth()+e,1),P6=(t,e)=>{const n=t.getFullYear(),r=t.getMonth(),o=(new Date(n,r,1).getDay()-e+7)%7,c=new Date(n,r+1,0).getDate(),d=new Date(n,r,0).getDate(),p=[];for(let m=0;m<42;m+=1){const u=m-o+1;if(u<=0){const f=d+u;p.push({date:new Date(n,r-1,f),inCurrentMonth:!1});continue}if(u>c){p.push({date:new Date(n,r+1,u-c),inCurrentMonth:!1});continue}p.push({date:new Date(n,r,u),inCurrentMonth:!0})}return p},A6=t=>{const e=/^([01]\d|2[0-3]):([0-5]\d)$/.exec(t);if(!e)return{hour24:"00",hour12:"12",minute:"00",meridiem:"AM"};const n=Number(e[1]),r=e[2],a=n>=12?"PM":"AM",i=n%12===0?12:n%12;return{hour24:String(n).padStart(2,"0"),hour12:String(i).padStart(2,"0"),minute:r,meridiem:a}},ya=(t,e,n)=>{const r=Number(t),a=Number(e),i=Number.isFinite(r)?Math.min(12,Math.max(1,r)):12,o=Number.isFinite(a)?Math.min(59,Math.max(0,a)):0;let c=i%12;return n==="PM"&&(c+=12),`${String(c).padStart(2,"0")}:${String(o).padStart(2,"0")}`},vi=(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"},tf=t=>/^(0[1-9]|1[0-2])$/.test(t)?t:vi(t,{min:1,max:12}),Oo=t=>/^[0-5][0-9]$/.test(t)?t:vi(t,{max:59}),D6=(t,e)=>vi(String(Number.parseInt(t,10)+e),{min:1,max:12,loop:!0}),sf=(t,e)=>vi(String(Number.parseInt(t,10)+e),{min:0,max:59,loop:!0}),T6=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}},M6=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}},E6=t=>{const e=new Intl.DateTimeFormat(t,{weekday:"short"}),n=new Date(2023,0,1);return Mg.map(r=>e.format(new Date(n.getFullYear(),n.getMonth(),n.getDate()+r)))},R6=(t,e)=>[...t.slice(e),...t.slice(0,e)],yr=t=>{const e=st.c(6),{htmlFor:n,required:r,children:a}=t;let i;e[0]!==r?(i=r&&s.jsx("span",{className:"ml-0.5 text-destructive",children:"*"}),e[0]=r,e[1]=i):i=e[1];let o;return e[2]!==a||e[3]!==n||e[4]!==i?(o=s.jsx("div",{className:"flex items-center gap-1.5",children:s.jsxs("label",{htmlFor:n,className:"typography-meta font-medium text-foreground",children:[a,i]})}),e[2]=a,e[3]=n,e[4]=i,e[5]=o):o=e[5],o},nf=t=>{const e=st.c(84),{value:n,onChange:r,use24Hour:a,hourAriaLabel:i,minuteAriaLabel:o,periodAriaLabel:c,amLabel:d,pmLabel:p}=t;let m;e[0]!==n?(m=A6(n),e[0]=n,e[1]=m):m=e[1];const u=m,f=Oe.useRef(null),b=Oe.useRef(null),[h,v]=Oe.useState(null),[x,g]=Oe.useState(null),w=Oe.useRef(null),y=Oe.useRef(null);let C;e[2]===Symbol.for("react.memo_cache_sentinel")?(C=X=>{w.current=X,v(X)},e[2]=C):C=e[2];const k=C;let j;e[3]===Symbol.for("react.memo_cache_sentinel")?(j=X=>{y.current=X,g(X)},e[3]=j):j=e[3];const S=j,I=B6,M=z6,P=V6;let A;e[4]!==r||e[5]!==u.meridiem||e[6]!==u.minute||e[7]!==a?(A=X=>{const Se=X.replace(/\D/g,"").slice(0,2);k(Se),Se.length===2&&(r(a?P(I(Se),u.minute):ya(tf(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 X=w.current;if(X!==null&&(k(null),X.length!==0)){if(a){r(P(I(X.padStart(2,"0")),u.minute));return}r(ya(tf(X.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 T=E;let R;e[14]!==r||e[15]!==u.hour12||e[16]!==u.hour24||e[17]!==u.meridiem||e[18]!==a?(R=X=>{const Se=X.replace(/\D/g,"").slice(0,2);S(Se),Se.length===2&&(r(a?P(u.hour24,Oo(Se)):ya(u.hour12,Oo(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]=R):R=e[19];const V=R;let _;e[20]!==r||e[21]!==u.hour12||e[22]!==u.hour24||e[23]!==u.meridiem||e[24]!==a?(_=()=>{const X=y.current;X!==null&&(S(null),X.length!==0&&r(a?P(u.hour24,Oo(X.padStart(2,"0"))):ya(u.hour12,Oo(X.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]=_):_=e[25];const U=_;let B;e[26]!==r||e[27]!==u.hour12||e[28]!==u.hour24||e[29]!==u.meridiem||e[30]!==u.minute||e[31]!==a?(B=X=>r(a?P(M(u.hour24,X),u.minute):ya(D6(u.hour12,X),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]=B):B=e[32];const z=B;let K;e[33]!==r||e[34]!==u.hour12||e[35]!==u.hour24||e[36]!==u.meridiem||e[37]!==u.minute||e[38]!==a?(K=X=>r(a?P(u.hour24,sf(u.minute,X)):ya(u.hour12,sf(u.minute,X),u.meridiem)),e[33]=r,e[34]=u.hour12,e[35]=u.hour24,e[36]=u.meridiem,e[37]=u.minute,e[38]=a,e[39]=K):K=e[39];const F=K;let G;e[40]!==r||e[41]!==u.hour12||e[42]!==u.meridiem||e[43]!==u.minute?(G=X=>{X!==u.meridiem&&r(ya(u.hour12,u.minute,X))},e[40]=r,e[41]=u.hour12,e[42]=u.meridiem,e[43]=u.minute,e[44]=G):G=e[44];const Q=G;let te;e[45]!==T||e[46]!==z?(te=X=>{if(X.key==="ArrowRight"){X.preventDefault(),T(),b.current?.focus();return}(X.key==="ArrowUp"||X.key==="ArrowDown")&&(X.preventDefault(),k(null),z(X.key==="ArrowUp"?1:-1))},e[45]=T,e[46]=z,e[47]=te):te=e[47];const Z=te;let fe;e[48]!==U||e[49]!==F?(fe=X=>{if(X.key==="ArrowLeft"&&(X.currentTarget.selectionStart??0)===0){X.preventDefault(),U(),f.current?.focus();return}(X.key==="ArrowUp"||X.key==="ArrowDown")&&(X.preventDefault(),S(null),F(X.key==="ArrowUp"?1:-1))},e[48]=U,e[49]=F,e[50]=fe):fe=e[50];const ue=fe,W=a?"px-2":"pl-2 pr-1";let q;e[51]!==W?(q=xe("inline-flex h-9 w-fit items-center gap-1 rounded-md border border-border bg-background focus-within:ring-1 focus-within:ring-interactive-focusRing focus-within:border-interactive-focusRing",W),e[51]=W,e[52]=q):q=e[52];const J=h??(a?u.hour24:u.hour12);let ne;e[53]!==N?(ne=X=>N(X.target.value),e[53]=N,e[54]=ne):ne=e[54];let ee;e[55]===Symbol.for("react.memo_cache_sentinel")?(ee=()=>k(""),e[55]=ee):ee=e[55];let he;e[56]!==T||e[57]!==i||e[58]!==Z||e[59]!==J||e[60]!==ne?(he=s.jsx("input",{ref:f,inputMode:"numeric",value:J,onChange:ne,onKeyDown:Z,onFocus:ee,onBlur:T,maxLength:2,"aria-label":i,className:"h-7 w-7 shrink-0 rounded-sm bg-transparent text-center font-mono text-sm tabular-nums text-foreground outline-none caret-transparent focus:bg-interactive-hover"}),e[56]=T,e[57]=i,e[58]=Z,e[59]=J,e[60]=ne,e[61]=he):he=e[61];let ke;e[62]===Symbol.for("react.memo_cache_sentinel")?(ke=s.jsx("span",{className:"font-mono text-sm text-muted-foreground",children:":"}),e[62]=ke):ke=e[62];const oe=x??u.minute;let ge;e[63]!==V?(ge=X=>V(X.target.value),e[63]=V,e[64]=ge):ge=e[64];let me;e[65]===Symbol.for("react.memo_cache_sentinel")?(me=()=>S(""),e[65]=me):me=e[65];let ye;e[66]!==U||e[67]!==o||e[68]!==ue||e[69]!==oe||e[70]!==ge?(ye=s.jsx("input",{ref:b,inputMode:"numeric",value:oe,onChange:ge,onKeyDown:ue,onFocus:me,onBlur:U,maxLength:2,"aria-label":o,className:"h-7 w-7 shrink-0 rounded-sm bg-transparent text-center font-mono text-sm tabular-nums text-foreground outline-none caret-transparent focus:bg-interactive-hover"}),e[66]=U,e[67]=o,e[68]=ue,e[69]=oe,e[70]=ge,e[71]=ye):ye=e[71];let ie;e[72]!==d||e[73]!==u.meridiem||e[74]!==c||e[75]!==p||e[76]!==Q||e[77]!==a?(ie=a?null:s.jsxs(os,{value:u.meridiem,onValueChange:X=>Q(X),children:[s.jsx(ls,{"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(cs,{children:[s.jsx(Tt,{value:"AM",children:d}),s.jsx(Tt,{value:"PM",children:p})]})]}),e[72]=d,e[73]=u.meridiem,e[74]=c,e[75]=p,e[76]=Q,e[77]=a,e[78]=ie):ie=e[78];let ve;return e[79]!==q||e[80]!==he||e[81]!==ye||e[82]!==ie?(ve=s.jsxs("div",{className:q,children:[he,ke,ye,ie]}),e[79]=q,e[80]=he,e[81]=ye,e[82]=ie,e[83]=ve):ve=e[83],ve},rf=t=>new Date(t.getFullYear(),t.getMonth(),1),F6=()=>{const t=new Date;return new Date(t.getFullYear(),t.getMonth(),t.getDate())},af=(t,e)=>t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth()&&t.getDate()===e.getDate(),O6=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"]},of=(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:O6(t),onceDate:typeof t.schedule.date=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(t.schedule.date)?t.schedule.date:Xp(),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:Xp(),onceTime:"09:00",weekdays:[1],timezone:n},execution:{prompt:"",providerID:e.providerID,modelID:e.modelID,variant:e.variant,agent:e.agent}}},L6=(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")},$6=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 _6(t){const{open:e,task:n,onOpenChange:r,onSave:a}=t,{t:i,locale:o}=dt(),c=bt(L=>L.loadProviders),d=bt(L=>L.loadAgents),p=bt(L=>L.providers),m=bt(L=>L.currentProviderId),u=bt(L=>L.currentModelId),f=bt(L=>L.currentVariant||""),b=bt(L=>L.currentAgentName||""),h=Re(L=>L.timeFormatPreference),v=Re(L=>L.weekStartPreference),x=Re(L=>L.isMobile),[g,w]=Oe.useState(()=>of(n,{providerID:m,modelID:u,variant:f,agent:b})),[y,C]=Oe.useState(!1),[k,j]=Oe.useState(!1),[S,I]=Oe.useState(!1),[M,P]=Oe.useState(""),[A,N]=Oe.useState(!1),[E,T]=Oe.useState(""),[R,V]=Oe.useState(!1),[_,U]=Oe.useState(""),[B,z]=Oe.useState(()=>{const L=tl(n?.schedule?.date||"")||new Date;return new Date(L.getFullYear(),L.getMonth(),1)}),K=Oe.useRef(null),F=Oe.useRef(null),G=Oe.useRef(null),Q=Oe.useRef(null),te=Oe.useRef(null),Z=Oe.useMemo(()=>M6(o),[o]),fe=Oe.useMemo(()=>T6(o),[o]),ue=Oe.useMemo(()=>h==="24h"?!0:h==="12h"?!1:Z,[h,Z]),W=Oe.useMemo(()=>v==="sunday"?0:v==="monday"?1:fe,[v,fe]),q=Oe.useMemo(()=>{const L=E6(o);return R6(Mg.map($=>({value:$,label:L[$]||""})),W)},[o,W]);Oe.useEffect(()=>{e&&(c(),d())},[e,c,d]),Oe.useEffect(()=>{if(!e)return;w(of(n,{providerID:m,modelID:u,variant:f,agent:b}));const L=tl(n?.schedule?.date||"")||new Date;z(new Date(L.getFullYear(),L.getMonth(),1)),j(!1),N(!1),I(!1),T(""),P("")},[e,n,m,u,f,b]),Oe.useEffect(()=>{if(!k)return;const L=$=>{K.current&&!K.current.contains($.target)&&j(!1)};return document.addEventListener("mousedown",L),()=>{document.removeEventListener("mousedown",L)}},[k]);const J=Oe.useMemo(()=>{const $=p.find(je=>je.id===g.execution.providerID)?.models?.find(je=>je.id===g.execution.modelID);return $?.variants?Object.keys($.variants):[]},[p,g.execution.providerID,g.execution.modelID]),ne=J.length>0,ee=Oe.useMemo(()=>!ne||!g.execution.variant?"__default":J.includes(g.execution.variant)?g.execution.variant:"__default",[g.execution.variant,ne,J]);Oe.useEffect(()=>{ne||!g.execution.variant||w(L=>({...L,execution:{...L.execution,variant:""}}))},[ne,g.execution.variant]);const he=Oe.useCallback((L,$)=>{w(je=>{const ae=new Set(je.schedule.weekdays);return $?ae.add(L):ae.delete(L),{...je,schedule:{...je.schedule,weekdays:Array.from(ae).sort((_e,le)=>_e-le)}}})},[]),ke=Oe.useCallback((L,$)=>{w(je=>{const ae=je.schedule.times.slice();return ae[L]=$,{...je,schedule:{...je.schedule,times:ae}}})},[]),oe=Oe.useCallback(L=>{w($=>{const je=$.schedule.times.filter((ae,_e)=>_e!==L);return{...$,schedule:{...$.schedule,times:je.length>0?je:["09:00"]}}})},[]),ge=Oe.useCallback(()=>{w(L=>({...L,schedule:{...L.schedule,times:[...L.schedule.times,"12:00"]}}))},[]),me=Oe.useMemo(()=>F6(),[]),ye=Oe.useMemo(()=>rf(me),[me]),ie=Oe.useMemo(()=>{const L=tl(g.schedule.onceDate);return L?af(L,me)?i("sessions.scheduledTasks.editor.date.today"):new Intl.DateTimeFormat(o,{weekday:"short"}).format(L):null},[g.schedule.onceDate,o,i,me]),ve=Oe.useMemo(()=>rf(B).getTime()<=ye.getTime(),[B,ye]),X=Oe.useMemo(()=>q.map(L=>L.label),[q]),Se=Oe.useCallback(L=>{w($=>({...$,schedule:{...$.schedule,onceDate:L}}))},[]),Ae=Oe.useCallback((L,$)=>{if(L.startsWith("/")){const le=L.indexOf(" "),Me=L.indexOf(`
180
+ `),Ge=Math.min(le===-1?L.length:le,Me===-1?L.length:Me);if($<=Ge&&le===-1){T(L.substring(1,Ge)),N(!0),I(!1),V(!1);return}}N(!1);const je=L.substring(0,$),ae=je.lastIndexOf("#");if(ae!==-1){const le=ae>0?je[ae-1]:null,Me=je.substring(ae+1);if((!le||/\s/.test(le))&&!Me.includes(" ")&&!Me.includes(`
181
+ `)){U(Me),V(!0),I(!1);return}}V(!1);const _e=je.lastIndexOf("@");if(_e!==-1){const le=_e>0?je[_e-1]:null,Me=je.substring(_e+1);(!le||/\s/.test(le))&&!Me.includes(" ")&&!Me.includes(`
182
+ `)?(P(Me),I(!0)):I(!1);return}I(!1)},[]),pe=Oe.useCallback(L=>{w($=>({...$,execution:{...$.execution,prompt:L}}))},[]),we=Oe.useCallback(L=>{const $=g.execution.prompt,ae=F.current?.selectionStart??$.length,le=$.substring(0,ae).lastIndexOf("@"),Me=L.relativePath&&L.relativePath.trim().length>0?L.relativePath.trim():L.path||L.name,Ge=le!==-1?le:ae,at=`${$.substring(0,Ge)}@${Me} ${$.substring(ae)}`,Ye=Ge+Me.length+2;pe(at),I(!1),P(""),requestAnimationFrame(()=>{const Xe=F.current;Xe&&(Xe.selectionStart=Ye,Xe.selectionEnd=Ye,Xe.focus()),Ae(at,Ye)})},[g.execution.prompt,pe,Ae]),Ie=Oe.useCallback(L=>{const $=g.execution.prompt,ae=F.current?.selectionStart??$.length,le=$.substring(0,ae).lastIndexOf("@"),Me=le!==-1?le:ae,Ge=`${$.substring(0,Me)}@${L} ${$.substring(ae)}`,at=Me+L.length+2;pe(Ge),I(!1),P(""),requestAnimationFrame(()=>{const Ye=F.current;Ye&&(Ye.selectionStart=at,Ye.selectionEnd=at,Ye.focus()),Ae(Ge,at)})},[g.execution.prompt,pe,Ae]),Y=Oe.useCallback(L=>{const $=`/${L.name} `;pe($),N(!1),T(""),V(!1),requestAnimationFrame(()=>{const je=F.current;je&&(je.focus(),je.selectionStart=je.value.length,je.selectionEnd=je.value.length),Ae($,$.length)})},[pe,Ae]),re=Oe.useCallback((L,$)=>{const je=g.execution.prompt,_e=F.current?.selectionStart??je.length,Me=je.substring(0,_e).lastIndexOf("#"),Ge=Me!==-1?Me:_e,at=`${je.substring(0,Ge)}#${$} ${je.substring(_e)}`,Ye=Ge+$.length+2;pe(at),V(!1),U(""),requestAnimationFrame(()=>{const Xe=F.current;Xe&&(Xe.selectionStart=Ye,Xe.selectionEnd=Ye,Xe.focus()),Ae(at,Ye)})},[g.execution.prompt,pe,Ae]),Pe=Oe.useCallback(L=>{if(A&&Q.current&&(L.key==="Enter"||L.key==="ArrowUp"||L.key==="ArrowDown"||L.key==="Escape"||L.key==="Tab")){L.preventDefault(),Q.current.handleKeyDown(L.key);return}S&&G.current&&(L.key==="Enter"||L.key==="ArrowUp"||L.key==="ArrowDown"||L.key==="Escape"||L.key==="Tab")&&(L.preventDefault(),G.current.handleKeyDown(L.key)),R&&te.current&&(L.key==="Enter"||L.key==="ArrowUp"||L.key==="ArrowDown"||L.key==="Escape"||L.key==="Tab")&&(L.preventDefault(),te.current.handleKeyDown(L.key))},[A,S,R]),ce=Oe.useCallback(async()=>{const L=L6(g,i);if(L){H.error(L);return}const $=$6(g.schedule.times),je={...g.id?{id:g.id}:{},name:g.name.trim(),enabled:g.enabled,schedule:{kind:g.schedule.kind,timezone:g.schedule.timezone.trim(),...g.schedule.kind==="once"?{date:g.schedule.onceDate,time:g.schedule.onceTime}:{times:$,...g.schedule.kind==="weekly"?{weekdays:g.schedule.weekdays}:{}}},execution:{prompt:g.execution.prompt,providerID:g.execution.providerID,modelID:g.execution.modelID,...g.execution.variant.trim()?{variant:g.execution.variant.trim()}:{},...g.execution.agent.trim()?{agent:g.execution.agent.trim()}:{}},...g.state?{state:g.state}:{}};C(!0);try{await a(je),r(!1)}catch(ae){H.error(ae instanceof Error?ae.message:i("sessions.scheduledTasks.editor.toast.saveFailed"))}finally{C(!1)}},[g,r,a,i]),Ce=Oe.useId(),Te=Oe.useCallback(()=>typeof document>"u"?!1:!!document.querySelector('[data-slot="dropdown-menu-content"], [data-slot="select-content"]'),[]),$e=i(n?"sessions.scheduledTasks.editor.title.edit":"sessions.scheduledTasks.editor.title.new"),De=i("sessions.scheduledTasks.editor.description"),de=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(yr,{htmlFor:"sched-name",required:!0,children:i("sessions.scheduledTasks.editor.taskName.label")}),s.jsx(Bt,{id:"sched-name",value:g.name,onChange:L=>w($=>({...$,name:L.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(yr,{children:i("sessions.scheduledTasks.editor.scheduleType.label")}),s.jsxs(os,{value:g.schedule.kind,onValueChange:L=>{w($=>({...$,schedule:{...$.schedule,kind:L}}))},children:[s.jsx(ls,{className:"w-fit max-w-full",children:s.jsx(us,{children:L=>i(L==="daily"?"sessions.scheduledTasks.editor.scheduleType.daily":L==="weekly"?"sessions.scheduledTasks.editor.scheduleType.weekly":"sessions.scheduledTasks.editor.scheduleType.once")})}),s.jsxs(cs,{children:[s.jsx(Tt,{value:"daily",children:i("sessions.scheduledTasks.editor.scheduleType.daily")}),s.jsx(Tt,{value:"weekly",children:i("sessions.scheduledTasks.editor.scheduleType.weekly")}),s.jsx(Tt,{value:"once",children:i("sessions.scheduledTasks.editor.scheduleType.once")})]})]})]})]}),g.schedule.kind==="once"?s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex flex-col gap-1",ref:K,children:[s.jsx(yr,{children:i("sessions.scheduledTasks.editor.date.label")}),s.jsxs("div",{className:"relative",children:[s.jsxs("button",{type:"button",className:"inline-flex h-9 w-fit max-w-full items-center justify-between gap-2 rounded-md border border-border bg-background px-3 text-left hover:bg-interactive-hover",onClick:()=>j(L=>!L),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:I6(g.schedule.onceDate,i("sessions.scheduledTasks.editor.date.placeholder"),o)})]}),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:()=>z(L=>ef(L,-1)),"aria-label":i("sessions.scheduledTasks.editor.date.previousMonth"),disabled:ve,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(o,{month:"long",year:"numeric"}).format(B)}),s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-interactive-hover",onClick:()=>z(L=>ef(L,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:X.map((L,$)=>s.jsx("div",{className:"py-1 text-center typography-micro text-muted-foreground",children:L},`${L}-${$}`))}),s.jsx("div",{className:"grid grid-cols-7 gap-1",children:P6(B,W).map(({date:L,inCurrentMonth:$})=>{const je=Zp(L),ae=je===g.schedule.onceDate,_e=af(L,me),le=L.getTime()<me.getTime(),Me=ae?"bg-interactive-selection text-interactive-selection-foreground":le?"text-muted-foreground/40":$?"text-foreground hover:bg-interactive-hover":"text-muted-foreground/60 hover:bg-interactive-hover";return s.jsx("button",{type:"button",onClick:()=>{le||(Se(je),j(!1))},disabled:le,className:["h-8 rounded-md typography-ui-label",Me,_e&&!ae?"ring-1 ring-inset ring-interactive-focusRing bg-interactive-hover/50":"",le?"cursor-not-allowed opacity-45":""].join(" "),children:L.getDate()},je)})}),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:ie||""}),s.jsx(be,{type:"button",size:"xs",variant:"ghost",onClick:()=>{Se(Zp(me)),z(new Date(me.getFullYear(),me.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(yr,{children:i("sessions.scheduledTasks.editor.time.label")}),s.jsx(nf,{value:g.schedule.onceTime,use24Hour:ue,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:L=>w($=>({...$,schedule:{...$.schedule,onceTime:L}}))}),s.jsxs("div",{className:"mt-2 flex flex-col gap-1",children:[s.jsx(yr,{children:i("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(os,{value:g.schedule.timezone,onValueChange:L=>{w($=>({...$,schedule:{...$.schedule,timezone:L}}))},children:[s.jsx(ls,{className:"w-fit max-w-full",children:s.jsx(us,{})}),s.jsx(cs,{children:Qp.map(L=>s.jsx(Tt,{value:L,children:L},L))})]})]})]})]}):s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[g.schedule.kind==="weekly"?s.jsxs("div",{className:"flex flex-col gap-1 sm:col-span-2",children:[s.jsx(yr,{children:i("sessions.scheduledTasks.editor.weekdays.label")}),s.jsx("div",{className:"flex flex-wrap gap-x-3 gap-y-2",children:q.map(L=>{const $=g.schedule.weekdays.includes(L.value);return s.jsxs("div",{className:["group inline-flex items-center gap-1.5 px-0.5 py-0.5 typography-meta",$?"text-foreground":"text-muted-foreground"].join(" "),children:[s.jsx(fs,{checked:$,onChange:je=>he(L.value,je),ariaLabel:L.label}),s.jsx("button",{type:"button",onClick:()=>he(L.value,!$),className:"group-hover:text-foreground",children:L.label})]},L.value)})})]}):null,s.jsxs("div",{className:"flex flex-col gap-2",children:[s.jsx(yr,{children:i("sessions.scheduledTasks.editor.times.label")}),s.jsx("div",{className:"flex flex-col gap-2",children:g.schedule.times.map((L,$)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(nf,{value:L,use24Hour:ue,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:je=>ke($,je)}),g.schedule.times.length>1?s.jsx(be,{type:"button",size:"icon",variant:"ghost",onClick:()=>oe($),"aria-label":i("sessions.scheduledTasks.editor.times.removeAria"),children:s.jsx(D,{name:"close",className:"h-4 w-4"})}):null]},$))}),s.jsx("div",{children:s.jsxs(be,{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(yr,{children:i("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(os,{value:g.schedule.timezone,onValueChange:L=>{w($=>({...$,schedule:{...$.schedule,timezone:L}}))},children:[s.jsx(ls,{className:"w-fit max-w-full",children:s.jsx(us,{})}),s.jsx(cs,{children:Qp.map(L=>s.jsx(Tt,{value:L,children:L},L))})]})]})]}),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(yr,{required:!0,children:i("sessions.scheduledTasks.editor.model.label")}),s.jsx(fo,{providerId:g.execution.providerID,modelId:g.execution.modelID,onChange:(L,$)=>{w(je=>({...je,execution:{...je.execution,providerID:L,modelID:$,variant:""}}))}})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(yr,{children:i("sessions.scheduledTasks.editor.thinkingLevel.label")}),s.jsxs(os,{value:ee,disabled:!ne,onValueChange:L=>{w($=>({...$,execution:{...$.execution,variant:L==="__default"?"":L}}))},children:[s.jsx(ls,{className:"w-fit max-w-full",children:s.jsx(us,{children:L=>L==="__default"?i("sessions.scheduledTasks.editor.thinkingLevel.default"):L})}),s.jsxs(cs,{children:[s.jsx(Tt,{value:"__default",children:i("sessions.scheduledTasks.editor.thinkingLevel.default")}),J.map(L=>s.jsx(Tt,{value:L,children:L},L))]})]})]})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(yr,{children:i("sessions.scheduledTasks.editor.agent.label")}),s.jsx(Ll,{agentName:g.execution.agent,filter:L=>Yf(L.mode),onChange:L=>w($=>({...$,execution:{...$.execution,agent:L}}))})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(yr,{htmlFor:"sched-prompt",required:!0,children:i("sessions.scheduledTasks.editor.prompt.label")}),s.jsxs("div",{className:"relative",children:[s.jsx(un,{id:"sched-prompt",ref:F,value:g.execution.prompt,onChange:L=>{const $=L.target.value;pe($);const je=L.target.selectionStart??$.length;Ae($,je)},onKeyDown:Pe,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(uh,{ref:Q,searchQuery:E,onCommandSelect:Y,onClose:()=>N(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,S?s.jsx(mh,{ref:G,searchQuery:M,onFileSelect:we,onAgentSelect:Ie,onClose:()=>I(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,R?s.jsx(ph,{ref:te,searchQuery:_,onSnippetSelect:re,onClose:()=>V(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null]})]})]}),O=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("label",{className:"inline-flex items-center gap-2",children:[s.jsx(fs,{checked:g.enabled,onChange:L=>w($=>({...$,enabled:L})),ariaLabel:i("sessions.scheduledTasks.editor.enabled.aria")}),s.jsx("span",{className:"typography-meta",children:i("sessions.scheduledTasks.editor.enabled.label")})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(be,{type:"button",variant:"ghost",size:"sm",onClick:()=>r(!1),disabled:y,children:i("sessions.scheduledTasks.editor.actions.cancel")}),s.jsx(be,{type:"button",size:"sm",onClick:ce,disabled:y,children:i(y?"sessions.scheduledTasks.editor.actions.saving":"sessions.scheduledTasks.editor.actions.save")})]})]});return x?s.jsx(Lr,{open:e,title:$e,onClose:()=>r(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:L=>s.jsxs("div",{className:"flex flex-col gap-1 border-b border-border/40 px-3 py-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("h2",{className:"typography-ui-label font-semibold text-foreground",children:$e}),L]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:De})]}),footer:O,children:de}):s.jsx(ps,{open:e,onOpenChange:L=>{!L&&Te()||r(L)},children:s.jsxs(ms,{"aria-describedby":Ce,className:"!max-w-[720px] w-[90vw] h-[680px] max-h-[85vh] gap-0 p-0 overflow-hidden",children:[s.jsx(Ss,{id:Ce,className:"sr-only",children:De}),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(hs,{className:"typography-ui-label font-medium text-foreground",children:$e}),s.jsx("p",{className:"typography-meta mt-0.5 text-muted-foreground",children:De})]})}),s.jsx(lo,{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:de})}),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:O})})]})})}function B6(t){return vi(t,{min:0,max:23})}function z6(t,e){return vi(String(Number.parseInt(t,10)+e),{min:0,max:23,loop:!0})}function V6(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 U6=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))},W6=(t,e)=>{const n=U6(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||""})},K6=t=>!t||!Number.isFinite(t)?"":new Date(t).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"}),lf=(t,e)=>{if(!t||!Number.isFinite(t))return"";const n=t-Date.now(),r=Math.abs(n),a=6e4,i=60*a,o=24*i,c=n>=0;if(r<a)return e(c?"sessions.scheduledTasks.dialog.relativeTime.inLessThanOneMinute":"sessions.scheduledTasks.dialog.relativeTime.justNow");if(r<i){const u=Math.round(r/a);return c?e("sessions.scheduledTasks.dialog.relativeTime.inMinutes",{count:u}):e("sessions.scheduledTasks.dialog.relativeTime.minutesAgo",{count:u})}if(r<o){const u=Math.floor(r/i),f=Math.round(r%i/a),b=f>0?`${u}h ${f}m`:`${u}h`;return c?e("sessions.scheduledTasks.dialog.relativeTime.inDuration",{duration:b}):e("sessions.scheduledTasks.dialog.relativeTime.durationAgo",{duration:b})}const d=Math.floor(r/o),p=Math.round(r%o/i),m=p>0?`${d}d ${p}h`:`${d}d`;return c?e("sessions.scheduledTasks.dialog.relativeTime.inDuration",{duration:m}):e("sessions.scheduledTasks.dialog.relativeTime.durationAgo",{duration:m})},H6={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"}},G6=t=>({color:`var(--status-${t})`,backgroundColor:`var(--status-${t}-background)`,borderColor:`var(--status-${t}-border)`});function q6(){const{t}=dt(),e=Re(T=>T.isScheduledTasksDialogOpen),n=Re(T=>T.setScheduledTasksDialogOpen),r=Re(T=>T.isMobile),a=Ps(T=>T.projects),i=Ps(T=>T.getActiveProject()),o=zs(T=>T.homeDirectory),{currentTheme:c}=Cr(),[d,p]=Oe.useState(""),[m,u]=Oe.useState([]),[f,b]=Oe.useState(!0),[h,v]=Oe.useState(!1),[x,g]=Oe.useState(null),[w,y]=Oe.useState(null),C=Oe.useMemo(()=>a.find(T=>T.id===d)||null,[a,d]),k=Oe.useCallback(T=>{const R=T.label?.trim()||Oa(T.path,o||void 0),V=mo({id:T.id,iconImage:T.iconImage??null},{themeVariant:c.metadata.variant,iconColor:c.colors.surface.foreground}),_=T.icon?Rl[T.icon]:null,U=T.color?po[T.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:T.iconBackground?{backgroundColor:T.iconBackground}:void 0,children:s.jsx("img",{src:V,alt:"",className:"h-full w-full object-contain",draggable:!1})}):_?s.jsx(D,{name:_,className:"h-3.5 w-3.5 shrink-0",style:U?{color:U}:void 0}):s.jsx(D,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:U?{color:U}:void 0}),s.jsx("span",{className:"truncate",children:R})]})},[o,c.metadata.variant,c.colors.surface.foreground]),j=Oe.useCallback(async(T,R)=>{if(!T){u([]);return}R?.silent||b(!0);try{const V=await S6(T);V.sort((_,U)=>{if(_.enabled!==U.enabled)return _.enabled?-1:1;const B=_.name.localeCompare(U.name);return B!==0?B:(_.state?.nextRunAt||Number.MAX_SAFE_INTEGER)-(U.state?.nextRunAt||Number.MAX_SAFE_INTEGER)}),u(V)}catch(V){H.error(V instanceof Error?V.message:t("sessions.scheduledTasks.dialog.toast.loadFailed")),R?.silent||u([])}finally{R?.silent||b(!1)}},[t]);Oe.useEffect(()=>{if(!e)return;const T=i?.id||a[0]?.id||"";p(T),T?j(T):(u([]),b(!1))},[e,i,a,j]),Oe.useEffect(()=>{if(!e)return;let T=null;const R=Tg(V=>{V.type==="scheduled-task-ran"&&V.projectId===d&&(T&&clearTimeout(T),T=setTimeout(()=>{j(d,{silent:!0})},400))});return()=>{T&&clearTimeout(T),R()}},[e,d,j]);const S=Oe.useCallback(async T=>{if(!d)throw new Error(t("sessions.scheduledTasks.dialog.error.chooseProjectFirst"));await Yp(d,T),await j(d),H.success(t("sessions.scheduledTasks.dialog.toast.saved"))},[d,j,t]),I=Oe.useCallback(async(T,R)=>{if(d){y(T.id),u(V=>V.map(_=>_.id===T.id?{..._,enabled:R}:_));try{await Yp(d,{...T,enabled:R}),await j(d,{silent:!0})}catch(V){H.error(V instanceof Error?V.message:t("sessions.scheduledTasks.dialog.toast.updateFailed")),await j(d,{silent:!0})}finally{y(null)}}},[d,j,t]),M=Oe.useCallback(async T=>{if(!(!d||!window.confirm(t("sessions.scheduledTasks.dialog.confirm.deleteTask",{taskName:T.name})))){y(T.id);try{await k6(d,T.id),await j(d,{silent:!0}),H.success(t("sessions.scheduledTasks.dialog.toast.deleted"))}catch(V){H.error(V instanceof Error?V.message:t("sessions.scheduledTasks.dialog.toast.deleteFailed"))}finally{y(null)}}},[d,j,t]),P=Oe.useCallback(async T=>{if(d){y(T.id);try{await C6(d,T.id),await Promise.all([j(d,{silent:!0}),Gc()]),H.success(t("sessions.scheduledTasks.dialog.toast.started"))}catch(R){H.error(R instanceof Error?R.message:t("sessions.scheduledTasks.dialog.toast.runFailed"))}finally{y(null)}}},[d,j,t]),A=s.jsxs("div",{className:"flex flex-col items-start gap-1",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("sessions.scheduledTasks.dialog.project.label")}),s.jsxs(os,{value:d||"__none",onValueChange:T=>{const R=T==="__none"?"":T;p(R),R?j(R):u([])},children:[s.jsx(ls,{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(cs,{children:[a.length===0?s.jsx(Tt,{value:"__none",children:t("sessions.scheduledTasks.dialog.project.empty")}):null,a.map(T=>s.jsx(Tt,{value:T.id,children:k(T)},T.id))]})]})]}),N=()=>{g(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(be,{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(T=>{const R=w===T.id,V=T.state?.lastStatus||"idle",_=H6[V],U=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"),B=T.state?.nextRunAt,z=T.state?.lastRunAt;return s.jsxs("div",{className:xe("rounded-lg border border-border p-4 transition-opacity",!T.enabled&&"opacity-60"),children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-header truncate font-semibold text-foreground",children:T.name}),s.jsx("div",{className:"typography-micro truncate text-muted-foreground",children:W6(T,t)})]}),s.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-x-5 gap-y-1 typography-micro text-muted-foreground",children:[s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(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")}),B?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"text-foreground",children:lf(B,t)}),s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:K6(B)})]}):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")]}):z?s.jsxs(s.Fragment,{children:[_.tone!=="muted"?s.jsxs("span",{className:"inline-flex items-center gap-1",style:{color:`var(--status-${_.tone})`},children:[s.jsx(D,{name:_.Icon,className:"h-3.5 w-3.5"}),U]}):null,s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:lf(z,t)})]}):s.jsx("span",{children:t("sessions.scheduledTasks.dialog.lastRun.never")})]})]}),T.state?.lastError?s.jsxs("div",{className:"mt-3 flex items-start gap-2 rounded-md border p-2 typography-micro",style:G6("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:T.state.lastError})]}):null,s.jsxs("div",{className:"mt-4 flex flex-wrap items-center justify-between gap-2",children:[s.jsxs("label",{className:xe("inline-flex cursor-pointer items-center gap-2 typography-micro font-medium",T.enabled?"text-foreground":"text-muted-foreground",R&&"cursor-not-allowed opacity-50"),children:[s.jsx(fs,{checked:T.enabled,onChange:K=>{I(T,K)},ariaLabel:T.enabled?t("sessions.scheduledTasks.dialog.taskToggle.pauseAria",{taskName:T.name}):t("sessions.scheduledTasks.dialog.taskToggle.enableAria",{taskName:T.name}),disabled:R}),T.enabled?t("sessions.scheduledTasks.dialog.taskToggle.enabled"):t("sessions.scheduledTasks.dialog.taskToggle.paused")]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[s.jsxs(be,{variant:"outline",size:"sm",onClick:()=>{P(T)},disabled:R,children:[s.jsx(D,{name:"play",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.runNow")]}),s.jsxs(be,{variant:"outline",size:"sm",onClick:()=>{g(T),v(!0)},disabled:R,"aria-label":t("sessions.scheduledTasks.dialog.actions.editAria",{taskName:T.name}),children:[s.jsx(D,{name:"edit-2",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.edit")]}),s.jsx(be,{variant:"destructive",size:"sm",onClick:()=>{M(T)},disabled:R,"aria-label":t("sessions.scheduledTasks.dialog.actions.deleteAria",{taskName:T.name}),children:s.jsx(D,{name:"delete-bin",className:"h-4 w-4"})})]})]})]},T.id)})})})]});return s.jsxs(s.Fragment,{children:[r?s.jsx(Lr,{open:e,title:t("sessions.scheduledTasks.dialog.title"),onClose:()=>n(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:T=>s.jsxs("div",{className:"flex flex-col gap-1 border-b border-border/40 px-3 py-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("h2",{className:"typography-ui-label font-semibold text-foreground",children:t("sessions.scheduledTasks.dialog.title")}),T]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("sessions.scheduledTasks.dialog.description")})]}),footer:s.jsxs(be,{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(ys,{children:[s.jsx(hs,{children:t("sessions.scheduledTasks.dialog.title")}),s.jsx(Ss,{children:t("sessions.scheduledTasks.dialog.description")})]}),E]})}),s.jsx(_6,{open:h,task:x,onOpenChange:v,onSave:S})]})}const J6=(t,e)=>{const n=e.isVSCode?[]:e.availableWorktreesByProject.get(t.normalizedPath)??[],r=new Set([t.normalizedPath,...n.map(c=>ws(c.path)??c.path).filter(c=>!!c)]),i=(c=>c.filter(d=>to(d,t.normalizedPath,r)))(e.archivedSessions),o=e.sessions.filter(c=>c.time?.archived||ws(c.directory??null)?!1:to(c,t.normalizedPath,r));return fi([...i,...o])},Y6=t=>{const e=st.c(12),{normalizedProjects:n,sessions:r,archivedSessions:a,availableWorktreesByProject:i,isVSCode:o,isSessionsLoading:c,foldersMap:d,createFolder:p,addSessionToFolder:m,cleanupSessions:u}=t;let f,b;e[0]!==m||e[1]!==a||e[2]!==i||e[3]!==u||e[4]!==p||e[5]!==d||e[6]!==c||e[7]!==o||e[8]!==n||e[9]!==r?(f=()=>{c||n.forEach(h=>{const v=Bd(h.normalizedPath),x=J6(h,{sessions:r,archivedSessions:a,availableWorktreesByProject:i,isVSCode:o}),g=new Set(x.map(Q6)),w=d[v]??[],y=new Map(w.map(X6));x.forEach(C=>{const k=yy(C,h.normalizedPath),j=k.toLowerCase();let S=y.get(j);S||(S=p(v,k),y.set(j,S)),S.sessionIds.includes(C.id)||m(v,S.id,C.id)}),u(v,g)})},b=[n,r,a,i,o,c,d,p,m,u],e[0]=m,e[1]=a,e[2]=i,e[3]=u,e[4]=p,e[5]=d,e[6]=c,e[7]=o,e[8]=n,e[9]=r,e[10]=f,e[11]=b):(f=e[10],b=e[11]),l.useEffect(f,b)};function Q6(t){return t.id}function X6(t){return[t.name.toLowerCase(),t]}const Z6=t=>{const e=st.c(41),{normalizedProjects:n,getSessionsForProject:r,getArchivedSessionsForProject:a,availableWorktreesByProject:i,projectRepoStatus:o,projectRootBranches:c,lastRepoStatus:d,buildGroupedSessions:p,hasSessionSearchQuery:m,normalizedSessionSearchQuery:u,filterSessionNodesForSearch:f,buildGroupSearchText:b,foldersMap:h}=t;let v;if(e[0]!==i||e[1]!==p||e[2]!==a||e[3]!==r||e[4]!==d||e[5]!==n||e[6]!==o||e[7]!==c){let P;e[9]!==i||e[10]!==p||e[11]!==a||e[12]!==r||e[13]!==d||e[14]!==o||e[15]!==c?(P=A=>{const N=fi([...r(A),...a(A)]),E=i.get(A.normalizedPath)??[],T=o.has(A.id)?!!o.get(A.id):d,R=p(N,A.normalizedPath,E,c.get(A.id)??null,T);return{project:A,groups:R}},e[9]=i,e[10]=p,e[11]=a,e[12]=r,e[13]=d,e[14]=o,e[15]=c,e[16]=P):P=e[16],v=n.map(P),e[0]=i,e[1]=p,e[2]=a,e[3]=r,e[4]=d,e[5]=n,e[6]=o,e[7]=c,e[8]=v}else v=e[8];const x=v,g=x;let w;if(e[17]!==b||e[18]!==f||e[19]!==h||e[20]!==m||e[21]!==u||e[22]!==g){e:{const P=new WeakMap;if(!m){w=P;break e}const A=N=>N.reduce((E,T)=>E+1+A(T.children),0);g.forEach(N=>{N.groups.forEach(E=>{const T=f(E.sessions,u),R=A(T),V=b(E).includes(u),_=ws(E.directory??null),B=(_?h[_]??[]:[]).filter(z=>z.name.toLowerCase().includes(u)).length;P.set(E,{filteredNodes:T,matchedSessionCount:R,folderNameMatchCount:B,groupMatches:V,hasMatch:V||R>0||B>0})})}),w=P}e[17]=b,e[18]=f,e[19]=h,e[20]=m,e[21]=u,e[22]=g,e[23]=w}else w=e[23];const y=w;let C;e:{if(!m){C=g;break e}let P;if(e[24]!==y||e[25]!==g){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=g.map(A).filter(eI),e[24]=y,e[25]=g,e[26]=P}else P=e[26];C=P}const k=C,j=m?k:g;let S;e:{if(!m){S=0;break e}let P;if(e[29]!==y||e[30]!==j){let A;e[32]!==y?(A=(N,E)=>N+E.groups.reduce((T,R)=>{const V=y.get(R);if(!V)return T;const _=V.folderNameMatchCount+(V.groupMatches?1:0);return T+V.matchedSessionCount+_},0),e[32]=y,e[33]=A):A=e[33],P=j.reduce(A,0),e[29]=y,e[30]=j,e[31]=P}else P=e[31];S=P}const I=S;let M;return e[34]!==y||e[35]!==x||e[36]!==I||e[37]!==k||e[38]!==j||e[39]!==g?(M={projectSections:x,visibleProjectSections:g,groupSearchDataByGroup:y,searchableProjectSections:k,sectionsForRender:j,searchMatchCount:I},e[34]=y,e[35]=x,e[36]=I,e[37]=k,e[38]=j,e[39]=g,e[40]=M):M=e[40],M};function eI(t){return t.groups.length>0}const tI=t=>{const e=st.c(34),{projectSections:n,activeProjectId:r,activeSessionByProject:a,setActiveSessionByProject:i,currentSessionId:o,handleSessionSelect:c,newSessionDraftOpen:d,mobileVariant:p,openNewSessionDraft:m,setActiveMainTab:u,setSessionSwitcherOpen:f,sessions:b,worktreeMetadata:h}=t;let v,x;if(e[0]!==n){x=new Map,v=new Map;const A=(N,E,T,R)=>{x.has(N)||x.set(N,new Map);const V=x.get(N);R.forEach(_=>{const U=ws(_.worktree?.path??_.session.directory??T??E);V.set(_.session.id,{directory:U}),v.has(N)||v.set(N,{id:_.session.id,directory:U}),_.children.length>0&&A(N,E,U,_.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 g;e[3]!==v||e[4]!==x?(g={metaByProject:x,firstSessionByProject:v},e[3]=v,e[4]=x,e[5]=g):g=e[5];const w=g,y=l.useRef(null);let C,k;e[6]!==r||e[7]!==a||e[8]!==o||e[9]!==c||e[10]!==p||e[11]!==d||e[12]!==m||e[13]!==n||e[14]!==w||e[15]!==u||e[16]!==i||e[17]!==f?(C=()=>{if(!r||d||y.current===r)return;const A=n.find(U=>U.project.id===r);if(!A)return;y.current=r;const N=w.metaByProject.get(r);if(o&&N&&N.has(o)){i(U=>{if(U.get(r)===o)return U;const B=new Map(U);return B.set(r,o),B});return}if(!N||N.size===0){u("chat"),p&&f(!1),m({directoryOverride:A.project.normalizedPath});return}const E=a.get(r),T=E&&N.has(E)?E:null,R=w.firstSessionByProject.get(r)?.id??null,V=T??R;if(!V||V===o)return;const _=N.get(V)?.directory??null;c(V,_,!1,r)},k=[r,a,o,c,d,p,m,n,w,u,f,i],e[6]=r,e[7]=a,e[8]=o,e[9]=c,e[10]=p,e[11]=d,e[12]=m,e[13]=n,e[14]=w,e[15]=u,e[16]=i,e[17]=f,e[18]=C,e[19]=k):(C=e[18],k=e[19]),l.useLayoutEffect(C,k);let j,S;e[20]!==r||e[21]!==o||e[22]!==w||e[23]!==i?(j=()=>{if(!r||!o)return;const A=w.metaByProject.get(r);!A||!A.has(o)||i(N=>{if(N.get(r)===o)return N;const E=new Map(N);return E.set(r,o),E})},S=[r,o,w,i],e[20]=r,e[21]=o,e[22]=w,e[23]=i,e[24]=j,e[25]=S):(j=e[24],S=e[25]),l.useEffect(j,S);let I;if(e[26]!==o||e[27]!==b||e[28]!==h){e:{if(!o){I=null;break e}const A=h.get(o)?.path;if(A){I=ws(A)??A;break e}let N;e[30]!==o?(N=T=>T.id===o,e[30]=o,e[31]=N):N=e[31];const E=b.find(N);if(!E){I=null;break e}I=ws(E.directory??null)}e[26]=o,e[27]=b,e[28]=h,e[29]=I}else I=e[29];const M=I;let P;return e[32]!==M?(P={currentSessionDirectory:M},e[32]=M,e[33]=P):P=e[33],P},sI=t=>{const e=st.c(4);let n;e[0]!==t?(n=(i,o)=>{const c=t.get(i);if(!c||c.length===0)return o;const d=new Map(o.map(nI)),p=[];return c.forEach(m=>{const u=d.get(m);u&&(p.push(u),d.delete(m))}),o.forEach(m=>{d.has(m.id)&&p.push(m)}),p},e[0]=t,e[1]=n):n=e[1];const r=n;let a;return e[2]!==r?(a={getOrderedGroups:r},e[2]=r,e[3]=a):a=e[3],a};function nI(t){return[t.id,t]}const Lo=t=>!!t.time?.archived,rI=t=>{const{t:e}=dt(),n=l.useCallback(o=>[o.label,o.branch??"",o.description??"",o.directory??""].join(" ").toLowerCase(),[]),r=l.useCallback(o=>{const c=ws(o.directory??null)??"";return`${(o.title||e("sessions.sidebar.session.untitled")).trim()} ${c}`.toLowerCase()},[e]),a=l.useCallback((o,c)=>c?o.flatMap(d=>{if(r(d.session).includes(c))return[d];const m=a(d.children,c);return m.length===0?[]:[{...d,children:m}]}):o,[r]),i=l.useCallback((o,c,d,p,m)=>{const u=ws(c??null),f=fi(o).sort((A,N)=>ri(A,N,t.pinnedSessionIds)),b=new Map(f.map(A=>[A.id,A])),h=new Map;f.forEach(A=>{const N=A.parentID;if(!N)return;const E=b.get(N);if(!E||Lo(E)!==Lo(A))return;const T=h.get(N)??[];T.push(A),h.set(N,T)}),h.forEach(A=>A.sort((N,E)=>ri(N,E,t.pinnedSessionIds)));const v=new Map;d.forEach(A=>{if(A.path){const N=ws(A.path)??A.path;v.set(N,A)}});const x=A=>{const N=ws(A.directory??null),E=t.worktreeMetadata.get(A.id)??null;if(E)return E;if(N){const T=v.get(N)??null;if(T&&N!==u)return T}return null},g=A=>{const N=h.get(A.id)??[];return{session:A,children:N.map(E=>g(E)),worktree:x(A)}},w=f.filter(A=>{const N=A.parentID;if(!N)return!0;const E=b.get(N);return E?Lo(E)!==Lo(A):!0}),y=new Map,C="__archived__",k=A=>{if(A.time?.archived)return C;const N=ws(t.worktreeMetadata.get(A.id)?.path??null),E=ws(A.directory??null);if(!N&&!E)return C;const T=ws(A.project?.worktree??null),R=N??E??T;return R?R!==u&&v.has(R)?R:R===u?u??"__project_root__":C:C};w.forEach(A=>{const N=g(A),E=k(A);y.has(E)||y.set(E,[]),y.get(E)?.push(N)});const j=u??"__project_root__",S=[{id:"root",label:m&&p&&p!=="HEAD"?e("sessions.sidebar.grouping.projectRootWithBranch",{branch:p}):e("sessions.sidebar.grouping.projectRoot"),branch:p??null,description:u?eo(u,t.homeDirectory):null,isMain:!0,isArchivedBucket:!1,worktree:null,directory:u,folderScopeKey:u,sessions:y.get(j)??[]}],I=new Map;d.forEach(A=>{const N=ws(A.path)??A.path,E=y.get(N)??[],T=E.length>0,R=E.reduce((V,_)=>{const U=Number(_.session.time?.updated??_.session.time?.created??0);return Number.isFinite(U)?Math.max(V,U):V},0);I.set(N,{hasActiveSession:T,lastUpdatedAt:R})}),[...d].sort((A,N)=>{const E=ws(A.path)??A.path,T=ws(N.path)??N.path,R=I.get(E)??{hasActiveSession:!1,lastUpdatedAt:0},V=I.get(T)??{hasActiveSession:!1,lastUpdatedAt:0};if(R.hasActiveSession!==V.hasActiveSession)return R.hasActiveSession?-1:1;if(R.hasActiveSession&&V.hasActiveSession)return V.lastUpdatedAt-R.lastUpdatedAt;const _=(A.label||A.branch||A.name||A.path||"").toLowerCase(),U=(N.label||N.branch||N.name||N.path||"").toLowerCase();return _.localeCompare(U)}).forEach(A=>{const N=ws(A.path)??A.path,E=t.gitBranches.get(N)?.trim()||null,T=A.branch?.trim()||null,V=!!(E&&T&&A.label&&Fu(A.label)===Fu(T))?E:A.label||A.name||Oa(N,t.homeDirectory)||N;S.push({id:`worktree:${N}`,label:V,branch:E||T,description:eo(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?Bd(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}},aI=t=>{const e=st.c(9),{isSessionSearchOpen:n,setIsSessionSearchOpen:r,sessionSearchInputRef:a,sessionSearchContainerRef:i}=t;let o,c;e[0]!==n||e[1]!==a?(o=()=>{if(!n||typeof window>"u")return;const m=window.requestAnimationFrame(()=>{a.current?.focus(),a.current?.select()});return()=>window.cancelAnimationFrame(m)},c=[n,a],e[0]=n,e[1]=a,e[2]=o,e[3]=c):(o=e[2],c=e[3]),l.useEffect(o,c);let d,p;e[4]!==n||e[5]!==i||e[6]!==r?(d=()=>{if(!n||typeof document>"u")return;const m=u=>{i.current&&(i.current.contains(u.target)||r(!1))};return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},p=[n,r,i],e[4]=n,e[5]=i,e[6]=r,e[7]=d,e[8]=p):(d=e[7],p=e[8]),l.useEffect(d,p)},iI=t=>{const e=st.c(42),{t:n}=dt(),[r,a]=l.useState(null),i=l.useRef(null);let o,c;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=()=>()=>{i.current&&clearTimeout(i.current)},c=[],e[0]=o,e[1]=c):(o=e[0],c=e[1]),l.useEffect(o,c);let d;e[2]!==t?(d=(V,_,U,B)=>{if(U)return;const z=()=>{!t.isSessionSearchOpen&&t.sessionSearchQuery.length===0||(t.setSessionSearchQuery(""),t.setIsSessionSearchOpen(!1))};if(B&&B!==t.activeProjectId&&t.setActiveProjectIdOnly(B),_&&_!==t.currentDirectory&&t.setDirectory(_,{showOverlay:!1}),t.mobileVariant&&(t.setActiveMainTab("chat"),t.setSessionSwitcherOpen(!1)),V===t.currentSessionId){t.allowReselect&&t.onSessionSelected?.(V),z();return}t.setCurrentSession(V,_??null),t.onSessionSelected?.(V),z()},e[2]=t,e[3]=d):d=e[3];const p=d;let m;e[4]!==t?(m=()=>{t.setActiveMainTab("chat")},e[4]=t,e[5]=m):m=e[5];const u=m;let f;e[6]!==t?(f=async()=>{t.editingId&&t.editTitle.trim()&&(await t.updateSessionTitle(t.editingId,t.editTitle.trim()),t.setEditingId(null),t.setEditTitle(""))},e[6]=t,e[7]=f):f=e[7];const b=f;let h;e[8]!==t?(h=()=>{t.setEditingId(null),t.setEditTitle("")},e[8]=t,e[9]=h):h=e[9];const v=h;let x;e[10]!==t||e[11]!==n?(x=async V=>{const _=await t.shareSession(V.id);_&&_.share?.url?H.success(n("sessions.sidebar.session.share.successTitle"),{description:n("sessions.sidebar.session.share.successDescription")}):H.error(n("sessions.sidebar.session.share.error"))},e[10]=t,e[11]=n,e[12]=x):x=e[12];const g=x;let w;e[13]!==n?(w=(V,_)=>{In(V).then(U=>{if(!U.ok){H.error(n("sessions.sidebar.session.share.copyUrlError"));return}a(_),i.current&&clearTimeout(i.current),i.current=window.setTimeout(()=>{a(null),i.current=null},2e3)}).catch(()=>{H.error(n("sessions.sidebar.session.share.copyUrlError"))})},e[13]=n,e[14]=w):w=e[14];const y=w;let C;e[15]!==t||e[16]!==n?(C=async V=>{await t.unshareSession(V)?H.success(n("sessions.sidebar.session.unshare.success")):H.error(n("sessions.sidebar.session.unshare.error"))},e[15]=t,e[16]=n,e[17]=C):C=e[17];const k=C;let j;e[18]!==t.childrenMap?(j=V=>{const _=[],U=B=>{(t.childrenMap.get(B)??[]).forEach(K=>{_.push(K),U(K.id)})};return U(V),_},e[18]=t.childrenMap,e[19]=j):j=e[19];const S=j,I=lI;let M;e[20]!==t||e[21]!==S||e[22]!==n?(M=async(V,_,U)=>{const B=_?.archivedBucket===!0,z=U?.descendantIds??I(S(V.id),B).map(cI);if(z.length===0){(B?await t.deleteSession(V.id):await t.archiveSession(V.id))?H.success(n(B?"sessions.sidebar.session.delete.success":"sessions.sidebar.session.archive.success")):H.error(n(B?"sessions.sidebar.session.delete.error":"sessions.sidebar.session.archive.error"));return}const K=[V.id,...z];if(B){const{deletedIds:Q,failedIds:te}=await t.deleteSessions(K);Q.length>0&&H.success(Q.length===1?n("sessions.sidebar.bulkActions.deletedSingle",{count:Q.length}):n("sessions.sidebar.bulkActions.deletedPlural",{count:Q.length})),te.length>0&&H.error(te.length===1?n("sessions.sidebar.bulkActions.failedDeleteSingle",{count:te.length}):n("sessions.sidebar.bulkActions.failedDeletePlural",{count:te.length}));return}const{archivedIds:F,failedIds:G}=await t.archiveSessions(K);F.length>0&&H.success(F.length===1?n("sessions.sidebar.bulkActions.archivedSingle",{count:F.length}):n("sessions.sidebar.bulkActions.archivedPlural",{count:F.length})),G.length>0&&H.error(G.length===1?n("sessions.sidebar.bulkActions.failedArchiveSingle",{count:G.length}):n("sessions.sidebar.bulkActions.failedArchivePlural",{count:G.length}))},e[20]=t,e[21]=S,e[22]=n,e[23]=M):M=e[23];const P=M;let A;e[24]!==t||e[25]!==S||e[26]!==P?(A=(V,_)=>{const U=_?.archivedBucket===!0,B=I(S(V.id),U).map(dI);if(!t.showDeletionDialog){P(V,_,{descendantIds:B});return}t.setDeleteSessionConfirm({session:V,descendantCount:B.length,descendantIds:B,archivedBucket:U})},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:_,descendantIds:U}=t.deleteSessionConfirm;t.setDeleteSessionConfirm(null),await P(V,{archivedBucket:_},{descendantIds:U})},e[28]=t,e[29]=P,e[30]=E):E=e[30];const T=E;let R;return e[31]!==T||e[32]!==r||e[33]!==v||e[34]!==y||e[35]!==N||e[36]!==b||e[37]!==u||e[38]!==p||e[39]!==g||e[40]!==k?(R={copiedSessionId:r,handleSessionSelect:p,handleSessionDoubleClick:u,handleSaveEdit:b,handleCancelEdit:v,handleShareSession:g,handleCopyShareUrl:y,handleUnshareSession:k,handleDeleteSession:N,confirmDeleteSession:T},e[31]=T,e[32]=r,e[33]=v,e[34]=y,e[35]=N,e[36]=b,e[37]=u,e[38]=p,e[39]=g,e[40]=k,e[41]=R):R=e[41],R};function oI(t){return!t.time?.archived}function lI(t,e){return e?t:t.filter(oI)}function cI(t){return t.id}function dI(t){return t.id}const uI=["project:active:","project:archived:","recent:active:","recent:archived:"],mI=t=>{const{isVSCode:e,hasLoadedGlobalSessions:n,safeStorage:r,keys:a,sessions:i,setPinnedSessionIds:o,groupOrderByProject:c,activeSessionByProject:d,collapsedGroups:p,setExpandedParents:m,setCollapsedProjects:u}=t,f=l.useRef(null),b=l.useRef(null),h=l.useCallback(()=>{if(e)return;const x=b.current;if(b.current=null,f.current=null,!x)return;const{projects:g}=Ps.getState(),w=g.map(y=>({...y,sidebarCollapsed:x.has(y.id)}));Is({projects:w}).catch(()=>{})},[e]),v=l.useCallback(x=>{typeof window>"u"||e||(b.current=x,f.current!==null&&window.clearTimeout(f.current),f.current=window.setTimeout(()=>{h()},700))},[e,h]);return l.useEffect(()=>()=>{typeof window<"u"&&f.current!==null&&window.clearTimeout(f.current),f.current=null,b.current=null},[]),l.useEffect(()=>{try{const x=r.getItem(a.sessionExpanded);if(x){const w=JSON.parse(x);Array.isArray(w)&&m(new Set(w.filter(y=>typeof y=="string")))}else{const w=r.getItem(a.sessionExpandedLegacy);if(w){try{const y=JSON.parse(w);if(Array.isArray(y)){const C=new Set;if(y.forEach(k=>{typeof k!="string"||k.length===0||uI.forEach(j=>C.add(`${j}${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 g=r.getItem(a.projectCollapse);if(g){const w=JSON.parse(g);Array.isArray(w)&&u(new Set(w.filter(y=>typeof y=="string")))}}catch{}},[a.projectCollapse,a.sessionExpanded,a.sessionExpandedLegacy,r,u,m]),l.useEffect(()=>{if(!n)return;const x=new Set(i.map(g=>g.id));o(g=>{let w=!1;const y=new Set;return g.forEach(C=>{x.has(C)?y.add(C):w=!0}),w?y:g})},[n,i,o]),l.useEffect(()=>{try{const x=Object.fromEntries(c.entries());r.setItem(a.groupOrder,JSON.stringify(x))}catch{}},[c,a.groupOrder,r]),l.useEffect(()=>{try{const x=Object.fromEntries(d.entries());r.setItem(a.projectActiveSession,JSON.stringify(x))}catch{}},[d,a.projectActiveSession,r]),l.useEffect(()=>{try{r.setItem(a.groupCollapse,JSON.stringify(Array.from(p)))}catch{}},[p,a.groupCollapse,r]),{scheduleCollapsedProjectsPersist:v}},pI=async(t,e,n)=>{if(t.length===0)return[];const r=Math.max(1,Math.min(e,t.length)),a=new Array(t.length);let i=0;const o=async()=>{for(;;){const c=i;if(i+=1,c>=t.length)return;a[c]=await n(t[c])}};return await Promise.all(Array.from({length:r},()=>o())),a},fI=t=>{const e=st.c(23),{normalizedProjects:n,gitRepoStatus:r,setProjectRepoStatus:a,setProjectRootBranches:i}=t,{git:o}=Rn(),c=tn(hI);let d,p;e[0]!==c||e[1]!==o||e[2]!==n||e[3]!==a?(d=()=>{if(!o||n.length===0){a(new Map);return}n.forEach(x=>{c(x.normalizedPath,o)})},p=[n,o,c,a],e[0]=c,e[1]=o,e[2]=n,e[3]=a,e[4]=d,e[5]=p):(d=e[4],p=e[5]),l.useEffect(d,p);let m,u;e[6]!==r||e[7]!==n||e[8]!==a?(m=()=>{const x=new Map;n.forEach(g=>{x.set(g.id,r.get(g.normalizedPath)?.isGitRepo??null)}),a(x)},u=[n,r,a],e[6]=r,e[7]=n,e[8]=a,e[9]=m,e[10]=u):(m=e[9],u=e[10]),l.useEffect(m,u);let f;if(e[11]!==r||e[12]!==n){let x;e[14]!==r?(x=g=>{const w=r.get(g.normalizedPath)?.branch??"";return`${g.id}:${w}`},e[14]=r,e[15]=x):x=e[15],f=n.map(x).join("|"),e[11]=r,e[12]=n,e[13]=f}else f=e[13];const b=f;let h;e[16]!==n||e[17]!==i?(h=()=>{let x=!1;return(async()=>{const w=await pI(n,2,xI);x||i(y=>{const C=new Map(y);return w.forEach(k=>{const{id:j,branch:S}=k;S&&C.set(j,S)}),C})})(),()=>{x=!0}},e[16]=n,e[17]=i,e[18]=h):h=e[18];let v;e[19]!==n||e[20]!==b||e[21]!==i?(v=[n,b,i],e[19]=n,e[20]=b,e[21]=i,e[22]=v):v=e[22],l.useEffect(h,v)};function hI(t){return t.ensureStatus}function gI(){return null}async function xI(t){const e=await co(t.normalizedPath).catch(gI);return{id:t.id,branch:e}}const bI=t=>{const e=st.c(14),{isVSCode:n,sessions:r,archivedSessions:a,availableWorktreesByProject:i}=t;let o;e[0]!==r?(o=new Map,r.forEach(b=>{const h=ws(b.directory??null)??ws(b.project?.worktree??null);if(!h)return;const v=o.get(h)??[];v.push(b),o.set(h,v)}),e[0]=r,e[1]=o):o=e[1];const c=o;let d;e[2]!==i||e[3]!==n||e[4]!==c?(d=b=>{const h=n?[]:i.get(b.normalizedPath)??[],v=[b.normalizedPath,...h.map(yI).filter(vI)],x=new Set,g=[];return v.forEach(w=>{(c.get(w)??[]).forEach(C=>{x.has(C.id)||(x.add(C.id),g.push(C))})}),g},e[2]=i,e[3]=n,e[4]=c,e[5]=d):d=e[5];const p=d;let m;e[6]!==a||e[7]!==i||e[8]!==n||e[9]!==r?(m=b=>{if(n){const y=a.filter(k=>{const j=ws(k.directory??null),S=ws(k.project?.worktree??null);return j?j===b.normalizedPath:S===b.normalizedPath}),C=r.filter(k=>k.time?.archived||ws(k.directory??null)?!1:ws(k.project?.worktree??null)===b.normalizedPath);return fi([...y,...C])}const h=n?[]:i.get(b.normalizedPath)??[],v=new Set([b.normalizedPath,...h.map(wI).filter(jI)]),g=(y=>y.filter(C=>to(C,b.normalizedPath,v)))(a),w=r.filter(y=>{if(y.time?.archived||ws(y.directory??null))return!1;const k=ws(y.project?.worktree??null);return k?k===b.normalizedPath||k.startsWith(`${b.normalizedPath}/`):!1});return fi([...g,...w])},e[6]=a,e[7]=i,e[8]=n,e[9]=r,e[10]=m):m=e[10];const u=m;let f;return e[11]!==u||e[12]!==p?(f={getSessionsForProject:p,getArchivedSessionsForProject:u},e[11]=u,e[12]=p,e[13]=f):f=e[13],f};function yI(t){return ws(t.path)??t.path}function vI(t){return!!t}function wI(t){return ws(t.path)??t.path}function jI(t){return!!t}const NI=t=>{const e=st.c(9),{isSessionsLoading:n,sessions:r,archivedSessions:a,normalizedProjects:i,isVSCode:o,availableWorktreesByProject:c,cleanupSessions:d}=t;let p,m;e[0]!==a||e[1]!==c||e[2]!==d||e[3]!==n||e[4]!==o||e[5]!==i||e[6]!==r?(p=()=>{if(n)return;const u=new Map;r.forEach(h=>{const v=ws(h.directory??null);if(!v)return;const x=u.get(v);if(x){x.add(h.id);return}u.set(v,new Set([h.id]))}),i.forEach(h=>{const v=Bd(h.normalizedPath),x=o?[]:c.get(h.normalizedPath)??[],g=new Set([h.normalizedPath,...x.map(SI).filter(kI)]),w=fi([...a,...r.filter(y=>y.time?.archived||ws(y.directory??null)?!1:to(y,h.normalizedPath,g))]).filter(y=>to(y,h.normalizedPath,g));u.set(v,new Set(w.map(CI)))});const f=Un.getState().foldersMap;new Set([...Object.keys(f),...u.keys()]).forEach(h=>{d(h,u.get(h)??new Set)})},m=[a,c,d,n,o,i,r],e[0]=a,e[1]=c,e[2]=d,e[3]=n,e[4]=o,e[5]=i,e[6]=r,e[7]=p,e[8]=m):(p=e[7],m=e[8]),l.useEffect(p,m)};function SI(t){return ws(t.path)??t.path}function kI(t){return!!t}function CI(t){return t.id}const II=t=>{const e=st.c(8),{isDesktopShellRuntime:n,projectSections:r,projectHeaderSentinelRefs:a}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=new Set,e[0]=i):i=e[0];const[o,c]=l.useState(i);let d;e[1]!==n||e[2]!==a?(d=()=>{if(!n)return;const m=new IntersectionObserver(u=>{u.forEach(f=>{const b=f.target.dataset.projectId;b&&c(h=>{const v=new Set(h);return f.isIntersecting?v.delete(b):v.add(b),v})})},{threshold:0});return a.current.forEach(u=>{u&&m.observe(u)}),()=>m.disconnect()},e[1]=n,e[2]=a,e[3]=d):d=e[3];let p;return e[4]!==n||e[5]!==a||e[6]!==r?(p=[n,a,r],e[4]=n,e[5]=a,e[6]=r,e[7]=p):p=e[7],l.useEffect(d,p),o},PI=t=>{const e=st.c(85),{folder:n,sessions:r,subFolderItems:a,isCollapsed:i,onToggle:o,onRename:c,onDelete:d,renderSessionNode:p,groupDirectory:m,projectId:u,mobileVariant:f,alwaysShowActions:b,isRenaming:h,renameDraft:v,onRenameDraftChange:x,onRenameSave:g,onRenameCancel:w,droppableRef:y,isDropTarget:C,onNewSession:k,onNewSubFolder:j,depth:S,hideActions:I,archivedBucket:M}=t,A=b===void 0?f===void 0?!1:f:b,N=h===void 0?!1:h,E=v===void 0?"":v,T=C===void 0?!1:C,R=S===void 0?0:S,V=I===void 0?!1:I,_=M===void 0?!1:M,{t:U}=dt(),[B,z]=l.useState(!1),[K,F]=l.useState(""),G=l.useRef(null),Q=N||B,te=N?E:K;let Z;e[0]!==n.name?(Z=()=>{F(n.name),z(!0)},e[0]=n.name,e[1]=Z):Z=e[1];const fe=Z;let ue;e[2]!==te||e[3]!==n.name||e[4]!==N||e[5]!==c||e[6]!==g?(ue=()=>{const L=te.trim();L&&L!==n.name&&c(L),N&&g&&g(),z(!1),F("")},e[2]=te,e[3]=n.name,e[4]=N,e[5]=c,e[6]=g,e[7]=ue):ue=e[7];const W=ue;let q;e[8]!==N||e[9]!==w?(q=()=>{N&&w&&w(),z(!1),F("")},e[8]=N,e[9]=w,e[10]=q):q=e[10];const J=q;let ne;e[11]!==N||e[12]!==x?(ne=L=>{N&&x?x(L):F(L)},e[11]=N,e[12]=x,e[13]=ne):ne=e[13];const ee=ne;let he,ke;e[14]!==N?(he=()=>{if(!N)return;const L=()=>{const ae=G.current;ae&&(ae.focus(),ae.select())},$=requestAnimationFrame(L),je=window.setTimeout(L,0);return()=>{cancelAnimationFrame($),window.clearTimeout(je)}},ke=[N],e[14]=N,e[15]=he,e[16]=ke):(he=e[15],ke=e[16]),l.useEffect(he,ke);const oe=i?"folder":"folder-open",me=R>0&&"ml-3";let ye;e[17]!==me?(ye=xe("oc-folder",me),e[17]=me,e[18]=ye):ye=e[18];const ie=T&&"bg-primary/10 ring-1 ring-inset ring-primary/30";let ve;e[19]!==ie?(ve=xe("group/folder relative flex items-center justify-between gap-1.5 py-1 min-w-0 rounded-md","cursor-pointer",ie),e[19]=ie,e[20]=ve):ve=e[20];const X=Q?void 0:o,Se=Q?void 0:"button",Ae=Q?void 0:0;let pe;e[21]!==o||e[22]!==Q?(pe=Q?void 0:L=>{(L.key==="Enter"||L.key===" ")&&(L.preventDefault(),o())},e[21]=o,e[22]=Q,e[23]=pe):pe=e[23];let we;e[24]!==n.name||e[25]!==i||e[26]!==U?(we=i?U("sessions.sidebar.folderItem.expandAria",{folderName:n.name}):U("sessions.sidebar.folderItem.collapseAria",{folderName:n.name}),e[24]=n.name,e[25]=i,e[26]=U,e[27]=we):we=e[27];const Ie=_?A?"pr-7":"group-hover/folder:pr-7 group-focus-within/folder:pr-7":"";let Y;e[28]!==Ie?(Y=xe("min-w-0 flex items-center gap-1.5 pl-1.5 flex-1 transition-[padding]",Ie),e[28]=Ie,e[29]=Y):Y=e[29];const re=T?"text-primary":"text-muted-foreground";let Pe;e[30]!==re?(Pe=xe("h-3.5 w-3.5 flex-shrink-0",re),e[30]=re,e[31]=Pe):Pe=e[31];let ce;e[32]!==oe||e[33]!==Pe?(ce=s.jsx(D,{name:oe,className:Pe}),e[32]=oe,e[33]=Pe,e[34]=ce):ce=e[34];let Ce;e[35]!==te||e[36]!==n.name||e[37]!==J||e[38]!==ee||e[39]!==W||e[40]!==i||e[41]!==T||e[42]!==Q||e[43]!==r||e[44]!==U?(Ce=Q?s.jsxs("form",{className:"flex min-w-0 flex-1 items-center gap-1",onPointerDown:DI,onMouseDown:TI,onSubmit:L=>{L.preventDefault(),W()},children:[s.jsx("input",{ref:G,value:te,onChange:L=>ee(L.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",autoFocus:!0,placeholder:U("sessions.sidebar.folderItem.namePlaceholder"),onClick:MI,onPointerDown:EI,onMouseDown:RI,onKeyDown:L=>{if(L.key==="Escape"){L.stopPropagation(),J();return}(L.key===" "||L.key==="Enter")&&L.stopPropagation()}}),s.jsx("button",{type:"submit",className:"shrink-0 text-muted-foreground hover:text-foreground",onClick:FI,onPointerDown:OI,onMouseDown:LI,children:s.jsx(D,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:L=>{L.stopPropagation(),J()},onPointerDown:$I,onMouseDown:_I,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:xe("typography-ui-label font-semibold truncate",T?"text-primary":"text-muted-foreground"),children:n.name}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70 flex-shrink-0",children:["• ",r.length]}),i?s.jsx(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]=te,e[36]=n.name,e[37]=J,e[38]=ee,e[39]=W,e[40]=i,e[41]=T,e[42]=Q,e[43]=r,e[44]=U,e[45]=Ce):Ce=e[45];let Te;e[46]!==Y||e[47]!==ce||e[48]!==Ce?(Te=s.jsxs("div",{className:Y,children:[ce,Ce]}),e[46]=Y,e[47]=ce,e[48]=Ce,e[49]=Te):Te=e[49];let $e;e[50]!==A||e[51]!==_||e[52]!==R||e[53]!==n.name||e[54]!==fe||e[55]!==V||e[56]!==d||e[57]!==k||e[58]!==j||e[59]!==Q||e[60]!==U?($e=!Q&&(!V||_)?s.jsx("div",{className:"flex items-center gap-0.5 px-0.5",children:s.jsxs("div",{className:xe("flex items-center gap-0.5 transition-opacity",A?"opacity-100":"opacity-0 group-hover/folder:opacity-100 group-focus-within/folder:opacity-100",_&&"absolute right-0.5 top-1/2 z-10 -translate-y-1/2 px-0"),children:[!_&&k?s.jsx("button",{type:"button",onClick:L=>{L.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":U("sessions.sidebar.folderItem.newSessionAria",{folderName:n.name}),title:U("sessions.sidebar.project.actions.newSession"),children:s.jsx(D,{name:"add",className:"h-3.5 w-3.5"})}):null,!_&&j&&R===0?s.jsx("button",{type:"button",onClick:L=>{L.stopPropagation(),j()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":U("sessions.sidebar.folderItem.newSubfolderAria",{folderName:n.name}),title:U("sessions.sidebar.folderItem.newSubfolder"),children:s.jsx(D,{name:"folder-add",className:"h-3.5 w-3.5"})}):null,_?null:s.jsx("button",{type:"button",onClick:L=>{L.stopPropagation(),fe()},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":U("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:L=>{L.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":_?U("sessions.sidebar.folderItem.deleteArchivedInFolderAria",{folderName:n.name}):U("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]=_,e[52]=R,e[53]=n.name,e[54]=fe,e[55]=V,e[56]=d,e[57]=k,e[58]=j,e[59]=Q,e[60]=U,e[61]=$e):$e=e[61];let De;e[62]!==y||e[63]!==ve||e[64]!==X||e[65]!==Se||e[66]!==Ae||e[67]!==pe||e[68]!==we||e[69]!==Te||e[70]!==$e?(De=s.jsxs("div",{ref:y,className:ve,onClick:X,role:Se,tabIndex:Ae,onKeyDown:pe,"aria-label":we,children:[Te,$e]}),e[62]=y,e[63]=ve,e[64]=X,e[65]=Se,e[66]=Ae,e[67]=pe,e[68]=we,e[69]=Te,e[70]=$e,e[71]=De):De=e[71];let de;e[72]!==_||e[73]!==m||e[74]!==i||e[75]!==u||e[76]!==p||e[77]!==r||e[78]!==a||e[79]!==U?(de=i?null:s.jsxs("div",{className:"pb-1 pl-2",children:[a,r.length>0?r.map(L=>p(L,0,m??null,u??null,_)):a?null:s.jsx("div",{className:"py-1 pl-1.5 text-left typography-micro text-muted-foreground/70",children:U("sessions.sidebar.folderItem.emptyFolder")})]}),e[72]=_,e[73]=m,e[74]=i,e[75]=u,e[76]=p,e[77]=r,e[78]=a,e[79]=U,e[80]=de):de=e[80];let O;return e[81]!==ye||e[82]!==De||e[83]!==de?(O=s.jsxs("div",{className:ye,children:[De,de]}),e[81]=ye,e[82]=De,e[83]=de,e[84]=O):O=e[84],O},AI=l.memo(PI);function DI(t){return t.stopPropagation()}function TI(t){return t.stopPropagation()}function MI(t){return t.stopPropagation()}function EI(t){return t.stopPropagation()}function RI(t){return t.stopPropagation()}function FI(t){return t.stopPropagation()}function OI(t){return t.stopPropagation()}function LI(t){return t.stopPropagation()}function $I(t){return t.stopPropagation()}function _I(t){return t.stopPropagation()}const BI=t=>{const e=st.c(15),{sessionId:n,sessionDirectory:r,sessionTitle:a,children:i}=t,o=`session-drag:${n}`;let c;e[0]!==r||e[1]!==n||e[2]!==a?(c={type:"session",sessionId:n,sessionDirectory:r,sessionTitle:a},e[0]=r,e[1]=n,e[2]=a,e[3]=c):c=e[3];let d;e[4]!==o||e[5]!==c?(d={id:o,data:c},e[4]=o,e[5]=c,e[6]=d):d=e[6];const{attributes:p,listeners:m,setNodeRef:u,isDragging:f}=Tx(d);let b;e[7]!==m?(b=g=>{g.stopPropagation(),m?.onPointerDown&&m.onPointerDown(g)},e[7]=m,e[8]=b):b=e[8];const h=b,v=f?"opacity-30":void 0;let x;return e[9]!==p||e[10]!==i||e[11]!==h||e[12]!==u||e[13]!==v?(x=s.jsx("div",{ref:u,...p,onPointerDown:h,className:v,children:i}),e[9]=p,e[10]=i,e[11]=h,e[12]=u,e[13]=v,e[14]=x):x=e[14],x},zI=t=>{const e=st.c(11),{folderId:n,children:r}=t,a=`folder-drop:${n}`;let i;e[0]!==n?(i={type:"folder",folderId:n},e[0]=n,e[1]=i):i=e[1];let o;e[2]!==a||e[3]!==i?(o={id:a,data:i},e[2]=a,e[3]=i,e[4]=o):o=e[4];const{setNodeRef:c,isOver:d}=Mx(o);let p;e[5]!==r||e[6]!==d||e[7]!==c?(p=r(c,d),e[5]=r,e[6]=d,e[7]=c,e[8]=p):p=e[8];let m;return e[9]!==p?(m=s.jsx(s.Fragment,{children:p}),e[9]=p,e[10]=m):m=e[10],m},VI=t=>{const e=st.c(20),{scopeKey:n,hasFolders:r,onSessionDroppedOnFolder:a,children:i}=t;let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o={activationConstraint:{distance:8}},e[0]=o):o=e[0];const c=Ji(ti(Yi,o)),[d,p]=l.useState(null),[m,u]=l.useState("Session"),[f,b]=l.useState(null),[h,v]=l.useState(null);if(!n){let S;return e[1]!==i?(S=s.jsx(s.Fragment,{children:i}),e[1]=i,e[2]=S):S=e[2],S}let x;e[3]!==a?(x=S=>{p(null),b(null),v(null);const{active:I,over:M}=S;if(!M)return;const P=I.data.current,A=M.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 g=x;let w,y;e[5]===Symbol.for("react.memo_cache_sentinel")?(w=S=>{const I=S.active.data.current;if(I?.type==="session"&&I.sessionId){p(I.sessionId),u(I.sessionTitle??"Session");const M=S.active.rect.current.initial?.width,P=S.active.rect.current.initial?.height;b(typeof M=="number"?M:null),v(typeof P=="number"?P:null)}},y=()=>{p(null),b(null),v(null)},e[5]=w,e[6]=y):(w=e[5],y=e[6]);let C;e[7]!==h||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:h?`${h}px`:"auto"},className:"flex items-center rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-2.5 py-1 shadow-none pointer-events-none",children:[s.jsx(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]=h,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(al,{children:C}),e[13]=C,e[14]=k):k=e[14];let j;return e[15]!==i||e[16]!==g||e[17]!==c||e[18]!==k?(j=s.jsxs(Qi,{sensors:c,collisionDetection:Xi,onDragStart:w,onDragCancel:y,onDragEnd:g,children:[i,k]}),e[15]=i,e[16]=g,e[17]=c,e[18]=k,e[19]=j):j=e[19],j},Ia=Zn()(oo(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"})),UI=50,WI=28;function KI(t){const{t:e}=dt(),{group:n,groupKey:r,projectId:a,hideGroupLabel:i,hasSessionSearchQuery:o,normalizedSessionSearchQuery:c,groupSearchDataByGroup:d,expandedSessionGroups:p,collapsedGroups:m,hideDirectoryControls:u,collapsedFolderIds:f,toggleFolderCollapse:b,renameFolder:h,deleteFolder:v,showDeletionDialog:x,setDeleteFolderConfirm:g,renderSessionNode:w,projectRepoStatus:y,lastRepoStatus:C,toggleGroupSessionLimit:k,mobileVariant:j,alwaysShowActions:S,activeProjectId:I,setActiveProjectIdOnly:M,setActiveMainTab:P,setSessionSwitcherOpen:A,openNewSessionDraft:N,addSessionToFolder:E,createFolderAndStartRename:T,renamingFolderId:R,renameFolderDraft:V,setRenameFolderDraft:_,setRenamingFolderId:U,pinnedSessionIds:B,sessionOrderIndex:z,prVisualStateByDirectoryBranch:K,onToggleCollapsedGroup:F,dragHandleProps:G,compactBodyPadding:Q=!1}=t,te=l.useCallback((et,yt)=>{const Rt=z.get(et.session.id),kt=z.get(yt.session.id);if(Rt!==void 0||kt!==void 0){if(Rt===void 0)return 1;if(kt===void 0)return-1;if(Rt!==kt)return Rt-kt}return ri(et.session,yt.session,B)},[B,z]),Z=o?d.get(n):null,fe=Ia(et=>et.displayMode),ue=Un(et=>et.foldersMap),W=fe==="minimal",q=p.has(r),J=o?!1:m.has(r),ne=u?10:5,ee=o?Z?.groupMatches===!0:!1,he=o,ke=l.useMemo(()=>[...he?Z?.filteredNodes??[]:n.sessions].sort(te),[te,n.sessions,Z?.filteredNodes,he]),oe=n.folderScopeKey??ws(n.directory??null),ge=l.useMemo(()=>oe?ue[oe]??[]:[],[oe,ue]),me=l.useMemo(()=>{const et=new Map,yt=Rt=>{Rt.forEach(kt=>{et.set(kt.session.id,kt),kt.children.length>0&&yt(kt.children)})};return yt(ke),et},[ke]),ye=l.useMemo(()=>ge.map(et=>{const yt=et.sessionIds.map(Rt=>me.get(Rt)).filter(Rt=>!!Rt).sort(te);return{folder:et,nodes:yt}}),[ge,me,te]),ie=l.useMemo(()=>{const et=new Map(ye.map(ht=>[ht.folder.id,ht])),yt=new Map;for(const{folder:ht}of ye){if(!ht.parentId)continue;const vt=yt.get(ht.parentId);vt?vt.push(ht.id):yt.set(ht.parentId,[ht.id])}const Rt=new Map,kt=ht=>{const vt=Rt.get(ht);if(vt!==void 0)return vt;const ns=et.get(ht);if(!ns)return Rt.set(ht,!1),!1;const zt=yt.get(ht)??[];if(n.isArchivedBucket&&ns.nodes.length===0){const Et=zt.some(rs=>kt(rs));return Rt.set(ht,Et),Et}if(!o||ns.folder.name.toLowerCase().includes(c)||ns.nodes.length>0)return Rt.set(ht,!0),!0;const mt=zt.some(Et=>kt(Et));return Rt.set(ht,mt),mt};return ye.filter(({folder:ht})=>kt(ht.id))},[ye,n.isArchivedBucket,o,c]),ve=l.useMemo(()=>new Set(ie.flatMap(et=>et.folder.sessionIds)),[ie]),X=l.useMemo(()=>ke.filter(et=>!ve.has(et.session.id)),[ke,ve]),Se=l.useMemo(()=>ie.filter(({folder:et})=>!et.parentId),[ie]),Ae=X.length,pe=n.isArchivedBucket||o||q?X:X.slice(0,ne),we=Ae-pe.length,Ie=n.isArchivedBucket===!0&&!o&&pe.length>=UI,Y=l.useRef(null),[re,Pe]=l.useState(null),[ce,Ce]=l.useState(0),Te=Ef({count:pe.length,getScrollElement:()=>re,estimateSize:()=>WI,overscan:8,enabled:Ie&&re!==null,scrollMargin:ce});l.useLayoutEffect(()=>{if(!Ie){re!==null&&Pe(null),ce!==0&&Ce(0);return}const et=Y.current;if(!et)return;let yt=re;if(!yt||!yt.contains(et)){let kt=et.parentElement;for(;kt;){const ht=window.getComputedStyle(kt);if(ht.overflowY==="auto"||ht.overflowY==="scroll"){yt=kt;break}kt=kt.parentElement}if(yt!==re){Pe(yt);return}}if(!yt)return;const Rt=et.getBoundingClientRect().top-yt.getBoundingClientRect().top+yt.scrollTop;Ce(kt=>Math.abs(kt-Rt)<1?kt:Rt)}),l.useEffect(()=>{if(!Ie||!re)return;const et=new ResizeObserver(()=>{Te.measure()});return et.observe(re),()=>et.disconnect()},[Ie,re,Te]);const $e=Te.getTotalSize(),De=Ie&&re!==null?Te.getVirtualItems():[];if(o&&!ee&&Se.length===0&&X.length===0)return null;const de=et=>{const yt=[],Rt=kt=>{kt.forEach(ht=>{yt.push(ht.session),ht.children.length>0&&Rt(ht.children)})};return Rt(et),yt},O=de(ke),L=a&&y.has(a)?!!y.get(a):C,$=ws(n.directory??null),je=n.branch?.trim()??null,ae=$&&je?K.get(`${$}::${je}`)??null:null,_e=!!(ae&&n.branch),le=!ae&&!n.isMain&&!!n.branch,Me=ae?.visualState??null,Ge=ae&&ae.state==="open"&&ae.checks?e("sessions.sidebar.group.pr.checksPassed",{success:ae.checks.success,total:ae.checks.total}):null,at=ae&&ae.state==="open"&&ae.checks?[ae.checks.failure>0?e("sessions.sidebar.group.pr.failingCount",{count:ae.checks.failure}):null,ae.checks.pending>0?e("sessions.sidebar.group.pr.pendingCount",{count:ae.checks.pending}):null].filter(et=>!!et).join(", "):null,Ye=ae&&ae.state==="open"?ae.mergeableState==="blocked"||ae.mergeableState==="dirty"?e("sessions.sidebar.group.pr.conflictsOrBlocked"):ae.mergeableState==="clean"||ae.canMerge===!0?e("sessions.sidebar.group.pr.mergeable"):null:null,Xe=ae&&ae.state==="open"&&ae.mergeableState?e("sessions.sidebar.group.pr.mergeState",{state:ae.mergeableState}):null,ut=ae?.base??null,rt=ae?.head??null,it=(()=>{if(!ae)return n.branch&&vy(n.branch,n.label)?{label:n.branch,color:null}:null;switch(ae.visualState){case"merged":return{label:e("sessions.sidebar.group.pr.status.merged"),color:"var(--pr-merged)"};case"open":return ae.canMerge===!0||ae.mergeableState==="clean"||ae.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:ae.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}})(),nt=it?.color??(Me?`var(--pr-${Me})`:void 0),Ne=et=>{et.preventDefault(),et.stopPropagation();const yt=ae?.url;yt&&qn(yt)},Ke=(et,yt,Rt)=>{const kt=ie.filter(({folder:zt})=>zt.parentId===et.id),ht=kt.length>0?s.jsx(s.Fragment,{children:kt.map(({folder:zt,nodes:Kt})=>Ke(zt,Kt,Rt+1))}):void 0,vt=zt=>{const Kt=ie.find(({folder:Et})=>Et.id===zt)?.nodes??[],mt=ie.filter(({folder:Et})=>Et.parentId===zt);return[...de(Kt),...mt.flatMap(({folder:Et})=>vt(Et.id))]},ns=n.isArchivedBucket?vt(et.id):[];return s.jsx(zI,{folderId:et.id,children:(zt,Kt)=>s.jsx(AI,{folder:et,sessions:yt,subFolderItems:ht,isCollapsed:o?!1:f.has(et.id),onToggle:()=>b(et.id),onRename:mt=>{oe&&h(oe,et.id,mt)},onDelete:()=>{if(n.isArchivedBucket){Nr.requestDelete({sessions:ns,mode:"session"});return}if(!oe)return;if(!x){v(oe,et.id);return}const mt=ie.filter(({folder:rs})=>rs.parentId===et.id).length,Et=yt.length;g({scopeKey:oe,folderId:et.id,folderName:et.name,subFolderCount:mt,sessionCount:Et})},renderSessionNode:w,groupDirectory:n.directory,projectId:a,mobileVariant:j,alwaysShowActions:S,isRenaming:R===et.id,renameDraft:R===et.id?V:void 0,onRenameDraftChange:mt=>_(mt),onRenameSave:()=>{const mt=V.trim();mt&&oe&&h(oe,et.id,mt),U(null),_("")},onRenameCancel:()=>{U(null),_("")},droppableRef:zt,isDropTarget:Kt,depth:Rt,onNewSession:()=>{a&&a!==I&&M(a),P("chat"),j&&A(!1),N({directoryOverride:n.directory,targetFolderId:et.id})},onNewSubFolder:Rt===0?()=>{oe&&T(oe,et.id)}:void 0,hideActions:!1,archivedBucket:n.isArchivedBucket===!0})},et.id)},Ve=()=>Se.map(({folder:et,nodes:yt})=>Ke(et,yt,0)),qe=!!(!n.isMain&&n.worktree),lt=S?qe?"pr-14":"pr-7":W?qe?"pr-2 group-hover/gh:pr-14 group-focus-within/gh:pr-14":"pr-2":qe?"pr-5 group-hover/gh:pr-14 group-focus-within/gh:pr-14":"pr-5",He=s.jsxs(VI,{scopeKey:oe,hasFolders:ie.length>0,onSessionDroppedOnFolder:(et,yt)=>{oe&&E(oe,yt,et)},children:[Ve(),Ie?s.jsx("div",{ref:Y,style:{position:"relative",height:$e>0?$e:void 0,width:"100%"},children:De.map(et=>{const yt=pe[et.index];return yt?s.jsx("div",{"data-index":et.index,ref:Te.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${et.start-ce}px)`},children:w(yt,0,n.directory,a,!0)},et.key):null})}):pe.map(et=>w(et,0,n.directory,a,n.isArchivedBucket===!0)),Ae===0&&ie.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,we>0&&!q?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:we===1?e("sessions.sidebar.group.showMoreSingle",{count:we}):e("sessions.sidebar.group.showMorePlural",{count:we})}):null,q&&Ae>ne?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=Q?"pb-2 pl-1":"pb-3 pl-4";return i?s.jsx("div",{className:"oc-group",children:s.jsx("div",{className:xe("oc-group-body",ze),children:He})}):s.jsxs("div",{className:"oc-group",children:[s.jsxs("div",{className:xe("group/gh relative flex items-start justify-between gap-1 py-1 min-w-0 rounded-md","cursor-pointer"),onClick:()=>F(r),role:"button",tabIndex:0,onKeyDown:et=>{(et.key==="Enter"||et.key===" ")&&(et.preventDefault(),F(r))},"aria-label":J?e("sessions.sidebar.group.expandAria",{label:n.label}):e("sessions.sidebar.group.collapseAria",{label:n.label}),"aria-expanded":!J,children:[s.jsx("div",{ref:G?.setActivatorNodeRef,className:xe("min-w-0 flex flex-1 items-start gap-1 overflow-hidden pl-0.5 transition-[padding] cursor-grab active:cursor-grabbing",lt),...G?.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:_e&&ae?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center",children:[s.jsxs(Ct,{children:[s.jsx(It,{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:xe("h-3.5 w-3.5 shrink-0",S?"hidden":"group-hover/gh:hidden"),style:nt?{color:nt}:void 0}),s.jsx("span",{className:xe("text-muted-foreground h-3.5 w-3.5 items-center justify-center",S?"inline-flex":"hidden group-hover/gh:inline-flex"),children:J?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"})})]}),ae.url?s.jsxs("button",{type:"button",className:"inline-flex shrink-0 items-center leading-none",onMouseDown:et=>et.stopPropagation(),onClick:Ne,children:["#",ae.number]}):s.jsxs("span",{className:"inline-flex shrink-0 items-center leading-none",children:["#",ae.number]})]})}),s.jsx(At,{side:"top",sideOffset:6,align:"start",className:"max-w-sm",children:s.jsxs("div",{className:"space-y-1 text-xs",children:[ut||rt?s.jsx("div",{className:"text-muted-foreground truncate",children:ut&&rt?s.jsxs(s.Fragment,{children:[s.jsx("span",{children:ut}),s.jsx(D,{name:"arrow-left-long",className:"mx-0.5 inline h-3 w-3 align-[-2px]"}),s.jsx("span",{children:rt})]}):s.jsx("span",{children:ut??rt??""})}):null,Xe?s.jsx("div",{className:"text-muted-foreground truncate",children:Xe}):null,Ye||Ge?s.jsxs("div",{className:"text-muted-foreground truncate",children:[Ye??"",Ye&&Ge?" • ":"",Ge??"",at?` (${at})`:""]}):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:xe("h-3.5 w-3.5 shrink-0 text-muted-foreground",S?"hidden":"group-hover/gh:hidden")}),s.jsx("span",{className:xe("text-muted-foreground h-3.5 w-3.5 items-center justify-center",S?"inline-flex":"hidden group-hover/gh:inline-flex"),children:J?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:Wi(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:xe("h-3.5 w-3.5 shrink-0 text-muted-foreground",S?"hidden":"group-hover/gh:hidden"),style:nt?{color:nt}:void 0}),s.jsx("span",{className:xe("text-muted-foreground h-3.5 w-3.5 items-center justify-center",S?"inline-flex":"hidden group-hover/gh:inline-flex"),children:J?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:Wi(n.label,c)})]}):Wi(n.label,c)}),le&&it?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||L?_e&&ae?s.jsxs(Ct,{children:[s.jsx(It,{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:nt?{color:nt}:void 0})})}),s.jsx(At,{side:"top",sideOffset:6,align:"start",className:"max-w-sm",children:s.jsxs("div",{className:"space-y-1 text-xs",children:[ut||rt?s.jsx("div",{className:"text-muted-foreground truncate",children:ut&&rt?s.jsxs(s.Fragment,{children:[s.jsx("span",{children:ut}),s.jsx(D,{name:"arrow-left-long",className:"mx-0.5 inline h-3 w-3 align-[-2px]"}),s.jsx("span",{children:rt})]}):s.jsx("span",{children:ut??rt??""})}):null,Xe?s.jsx("div",{className:"text-muted-foreground truncate",children:Xe}):null,Ye||Ge?s.jsxs("div",{className:"text-muted-foreground truncate",children:[Ye??"",Ye&&Ge?" • ":"",Ge??"",at?` (${at})`:""]}):null]})})]}):s.jsx(D,{name:"git-branch",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground",style:nt?{color:nt}:void 0}):null,s.jsx("span",{className:xe("min-w-0 truncate text-[11px] font-medium",!it.color&&"text-muted-foreground/80"),style:it.color?{color:it.color}:void 0,children:it.label})]}):null]})}),n.isArchivedBucket&&O.length>0?s.jsx("div",{className:xe("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(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:et=>{et.stopPropagation(),Nr.requestDelete({sessions:O,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(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.group.actions.deleteArchivedSessions")})})]})}):null,n.directory&&!n.isMain&&n.worktree?s.jsx("div",{className:xe("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(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:et=>{et.stopPropagation(),Nr.requestDelete({sessions:O,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(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.group.actions.deleteWorktree")})})]})}):null,n.directory?s.jsx("div",{className:xe("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(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:et=>{et.stopPropagation(),a&&a!==I&&M(a),P("chat"),j&&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(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.project.actions.newDraftSession")})})]})}):null]}),J?null:s.jsx("div",{className:xe("oc-group-body",ze),children:He})]})}function HI(t){const e=st.c(189),{t:n}=dt(),{hideDirectoryControls:r,handleOpenDirectoryDialog:a,canOpenMultiRun:i,openMultiRunLauncher:o,headerActionIconClass:c,headerActionButtonClass:d,isSessionSearchOpen:p,setIsSessionSearchOpen:m,sessionSearchInputRef:u,sessionSearchQuery:f,setSessionSearchQuery:b,hasSessionSearchQuery:h,searchMatchCount:v,collapseAllProjects:x,expandAllProjects:g,openScheduledTasksDialog:w,selectionModeEnabled:y,onToggleSelectionMode:C}=t,k=Ia(QI),j=Ia(YI),S=Ia(JI),I=Ia(qI);if(r)return null;let M;e[0]!==n?(M=n("sessions.sidebar.header.actions.addProject"),e[0]=n,e[1]=M):M=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]!==M||e[7]!==P?(A=s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:a,className:d,"aria-label":M,children:P})}),e[4]=a,e[5]=d,e[6]=M,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(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:N})}),e[11]=N,e[12]=E):E=e[12];let T;e[13]!==A||e[14]!==E?(T=s.jsxs(Ct,{children:[A,E]}),e[13]=A,e[14]=E,e[15]=T):T=e[15];let R;e[16]!==n?(R=n("sessions.sidebar.header.actions.newMultiRun"),e[16]=n,e[17]=R):R=e[17];const V=!i;let _;e[18]!==c?(_=s.jsx(wy,{className:c}),e[18]=c,e[19]=_):_=e[19];let U;e[20]!==d||e[21]!==o||e[22]!==R||e[23]!==V||e[24]!==_?(U=s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:o,className:d,"aria-label":R,disabled:V,children:_})}),e[20]=d,e[21]=o,e[22]=R,e[23]=V,e[24]=_,e[25]=U):U=e[25];let B;e[26]!==n?(B=n("sessions.sidebar.header.actions.newMultiRun"),e[26]=n,e[27]=B):B=e[27];let z;e[28]!==B?(z=s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:B})}),e[28]=B,e[29]=z):z=e[29];let K;e[30]!==z||e[31]!==U?(K=s.jsxs(Ct,{children:[U,z]}),e[30]=z,e[31]=U,e[32]=K):K=e[32];let F;e[33]!==n?(F=n("sessions.sidebar.header.actions.scheduledTasks"),e[33]=n,e[34]=F):F=e[34];let G;e[35]!==c?(G=s.jsx(D,{name:"calendar-schedule",className:c}),e[35]=c,e[36]=G):G=e[36];let Q;e[37]!==d||e[38]!==w||e[39]!==F||e[40]!==G?(Q=s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:w,className:d,"aria-label":F,children:G})}),e[37]=d,e[38]=w,e[39]=F,e[40]=G,e[41]=Q):Q=e[41];let te;e[42]!==n?(te=n("sessions.sidebar.header.actions.scheduledTasks"),e[42]=n,e[43]=te):te=e[43];let Z;e[44]!==te?(Z=s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:te})}),e[44]=te,e[45]=Z):Z=e[45];let fe;e[46]!==Q||e[47]!==Z?(fe=s.jsxs(Ct,{children:[Q,Z]}),e[46]=Q,e[47]=Z,e[48]=fe):fe=e[48];let ue;e[49]!==K||e[50]!==fe||e[51]!==T?(ue=s.jsxs("div",{className:"flex items-center gap-1.5",children:[T,K,fe]}),e[49]=K,e[50]=fe,e[51]=T,e[52]=ue):ue=e[52];let W;e[53]!==m?(W=()=>m(GI),e[53]=m,e[54]=W):W=e[54];let q;e[55]!==n?(q=n("sessions.sidebar.header.actions.searchSessions"),e[55]=n,e[56]=q):q=e[56];let J;e[57]!==c?(J=s.jsx(D,{name:"search",className:c}),e[57]=c,e[58]=J):J=e[58];let ne;e[59]!==d||e[60]!==p||e[61]!==W||e[62]!==q||e[63]!==J?(ne=s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:W,className:d,"aria-label":q,"aria-expanded":p,children:J})}),e[59]=d,e[60]=p,e[61]=W,e[62]=q,e[63]=J,e[64]=ne):ne=e[64];let ee;e[65]!==n?(ee=n("sessions.sidebar.header.actions.searchSessions"),e[65]=n,e[66]=ee):ee=e[66];let he;e[67]!==ee?(he=s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:ee})}),e[67]=ee,e[68]=he):he=e[68];let ke;e[69]!==ne||e[70]!==he?(ke=s.jsxs(Ct,{children:[ne,he]}),e[69]=ne,e[70]=he,e[71]=ke):ke=e[71];const oe=y&&"bg-interactive-hover text-primary";let ge;e[72]!==d||e[73]!==oe?(ge=xe(d,oe),e[72]=d,e[73]=oe,e[74]=ge):ge=e[74];let me;e[75]!==y||e[76]!==n?(me=n(y?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions"),e[75]=y,e[76]=n,e[77]=me):me=e[77];let ye;e[78]!==c?(ye=s.jsx(D,{name:"checkbox-multiple",className:c}),e[78]=c,e[79]=ye):ye=e[79];let ie;e[80]!==C||e[81]!==y||e[82]!==ge||e[83]!==me||e[84]!==ye?(ie=s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:C,className:ge,"aria-label":me,"aria-pressed":y,children:ye})}),e[80]=C,e[81]=y,e[82]=ge,e[83]=me,e[84]=ye,e[85]=ie):ie=e[85];let ve;e[86]!==y||e[87]!==n?(ve=n(y?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions"),e[86]=y,e[87]=n,e[88]=ve):ve=e[88];let X;e[89]!==ve?(X=s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:ve})}),e[89]=ve,e[90]=X):X=e[90];let Se;e[91]!==ie||e[92]!==X?(Se=s.jsxs(Ct,{children:[ie,X]}),e[91]=ie,e[92]=X,e[93]=Se):Se=e[93];let Ae;e[94]!==n?(Ae=n("sessions.sidebar.header.actions.sessionDisplayMode"),e[94]=n,e[95]=Ae):Ae=e[95];let pe;e[96]!==c?(pe=s.jsx(D,{name:"equalizer-2",className:c}),e[96]=c,e[97]=pe):pe=e[97];let we;e[98]!==d||e[99]!==Ae||e[100]!==pe?(we=s.jsx(It,{asChild:!0,children:s.jsx(As,{asChild:!0,children:s.jsx("button",{type:"button",className:d,"aria-label":Ae,children:pe})})}),e[98]=d,e[99]=Ae,e[100]=pe,e[101]=we):we=e[101];let Ie;e[102]!==n?(Ie=n("sessions.sidebar.header.displayMode.label"),e[102]=n,e[103]=Ie):Ie=e[103];let Y;e[104]!==Ie?(Y=s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:Ie})}),e[104]=Ie,e[105]=Y):Y=e[105];let re;e[106]!==we||e[107]!==Y?(re=s.jsxs(Ct,{children:[we,Y]}),e[106]=we,e[107]=Y,e[108]=re):re=e[108];let Pe;e[109]!==S?(Pe=()=>S("default"),e[109]=S,e[110]=Pe):Pe=e[110];let ce;e[111]!==n?(ce=n("sessions.sidebar.header.displayMode.default"),e[111]=n,e[112]=ce):ce=e[112];let Ce;e[113]!==ce?(Ce=s.jsx("span",{children:ce}),e[113]=ce,e[114]=Ce):Ce=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 $e;e[117]!==Pe||e[118]!==Ce||e[119]!==Te?($e=s.jsxs($t,{onClick:Pe,className:"flex items-center justify-between",children:[Ce,Te]}),e[117]=Pe,e[118]=Ce,e[119]=Te,e[120]=$e):$e=e[120];let De;e[121]!==S?(De=()=>S("minimal"),e[121]=S,e[122]=De):De=e[122];let de;e[123]!==n?(de=n("sessions.sidebar.header.displayMode.minimal"),e[123]=n,e[124]=de):de=e[124];let O;e[125]!==de?(O=s.jsx("span",{children:de}),e[125]=de,e[126]=O):O=e[126];let L;e[127]!==k?(L=k==="minimal"?s.jsx(D,{name:"check",className:"h-4 w-4 text-primary"}):null,e[127]=k,e[128]=L):L=e[128];let $;e[129]!==De||e[130]!==O||e[131]!==L?($=s.jsxs($t,{onClick:De,className:"flex items-center justify-between",children:[O,L]}),e[129]=De,e[130]=O,e[131]=L,e[132]=$):$=e[132];let je;e[133]===Symbol.for("react.memo_cache_sentinel")?(je=s.jsx(Gn,{}),e[133]=je):je=e[133];let ae;e[134]!==n?(ae=n("sessions.sidebar.header.displayMode.showRecent"),e[134]=n,e[135]=ae):ae=e[135];let _e;e[136]!==ae?(_e=s.jsx("span",{children:ae}),e[136]=ae,e[137]=_e):_e=e[137];let le;e[138]!==j?(le=j?s.jsx(D,{name:"check",className:"h-4 w-4 text-primary"}):null,e[138]=j,e[139]=le):le=e[139];let Me;e[140]!==_e||e[141]!==le||e[142]!==I?(Me=s.jsxs($t,{onClick:I,className:"flex items-center justify-between",children:[_e,le]}),e[140]=_e,e[141]=le,e[142]=I,e[143]=Me):Me=e[143];let Ge;e[144]===Symbol.for("react.memo_cache_sentinel")?(Ge=s.jsx(Gn,{}),e[144]=Ge):Ge=e[144];let at;e[145]===Symbol.for("react.memo_cache_sentinel")?(at=s.jsx(D,{name:"contract-up-down",className:"h-4 w-4"}),e[145]=at):at=e[145];let Ye;e[146]!==n?(Ye=n("sessions.sidebar.header.displayMode.collapseAll"),e[146]=n,e[147]=Ye):Ye=e[147];let Xe;e[148]!==Ye?(Xe=s.jsx("span",{children:Ye}),e[148]=Ye,e[149]=Xe):Xe=e[149];let ut;e[150]!==x||e[151]!==Xe?(ut=s.jsxs($t,{onClick:x,className:"flex items-center gap-2",children:[at,Xe]}),e[150]=x,e[151]=Xe,e[152]=ut):ut=e[152];let rt;e[153]===Symbol.for("react.memo_cache_sentinel")?(rt=s.jsx(D,{name:"expand-up-down",className:"h-4 w-4"}),e[153]=rt):rt=e[153];let it;e[154]!==n?(it=n("sessions.sidebar.header.displayMode.expandAll"),e[154]=n,e[155]=it):it=e[155];let nt;e[156]!==it?(nt=s.jsx("span",{children:it}),e[156]=it,e[157]=nt):nt=e[157];let Ne;e[158]!==g||e[159]!==nt?(Ne=s.jsxs($t,{onClick:g,className:"flex items-center gap-2",children:[rt,nt]}),e[158]=g,e[159]=nt,e[160]=Ne):Ne=e[160];let Ke;e[161]!==$e||e[162]!==$||e[163]!==Me||e[164]!==ut||e[165]!==Ne?(Ke=s.jsxs(Ds,{align:"end",className:"min-w-[160px]",children:[$e,$,je,Me,Ge,ut,Ne]}),e[161]=$e,e[162]=$,e[163]=Me,e[164]=ut,e[165]=Ne,e[166]=Ke):Ke=e[166];let Ve;e[167]!==re||e[168]!==Ke?(Ve=s.jsxs(Ts,{children:[re,Ke]}),e[167]=re,e[168]=Ke,e[169]=Ve):Ve=e[169];let qe;e[170]!==ke||e[171]!==Se||e[172]!==Ve?(qe=s.jsxs("div",{className:"flex items-center gap-1.5",children:[ke,Se,Ve]}),e[170]=ke,e[171]=Se,e[172]=Ve,e[173]=qe):qe=e[173];let lt;e[174]!==ue||e[175]!==qe?(lt=s.jsxs("div",{className:"flex h-8 items-center justify-between gap-2",children:[ue,qe]}),e[174]=ue,e[175]=qe,e[176]=lt):lt=e[176];let He;e[177]!==h||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:[h?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(),h?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]=h,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]!==lt||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:[lt,He]})}),e[186]=lt,e[187]=He,e[188]=ze):ze=e[188],ze}function GI(t){return!t}function qI(t){return t.toggleRecentSection}function JI(t){return t.setDisplayMode}function YI(t){return t.showRecentSection}function QI(t){return t.displayMode}const cf=7;function XI(t){const e=st.c(20),{sections:n,renderSessionNode:r}=t,{t:a}=dt();let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=new Set,e[0]=i):i=e[0];const[o,c]=l.useState(i);let d;e[1]===Symbol.for("react.memo_cache_sentinel")?(d=new Set,e[1]=d):d=e[1];const[p,m]=l.useState(d);let u;e[2]===Symbol.for("react.memo_cache_sentinel")?(u=y=>{c(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 h=b;let v,x,g;if(e[4]!==o||e[5]!==p||e[6]!==r||e[7]!==n||e[8]!==a){g=Symbol.for("react.early_return_sentinel");e:{const y=n.filter(ZI);if(y.length===0){g=null;break e}v="space-y-2 pb-2 pt-1";let C;e[12]!==o||e[13]!==p||e[14]!==r||e[15]!==a?(C=k=>{const j=o.has(k.key),S=p.has(k.key),I=S?k.items:k.items.slice(0,cf),M=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":!j,children:[s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center text-muted-foreground",children:j?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})]}),j?null:s.jsxs("div",{className:xe("space-y-0.5 pl-7"),children:[I.map(P=>r(P.node,0,P.groupDirectory,P.projectId,!1,P.secondaryMeta,"recent")),M>0&&!S?s.jsx("button",{type:"button",onClick:()=>h(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:M===1?a("sessions.sidebar.group.showMoreSingle",{count:M}):a("sessions.sidebar.group.showMorePlural",{count:M})}):null,S&&k.items.length>cf?s.jsx("button",{type:"button",onClick:()=>h(k.key),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:a("sessions.sidebar.group.showFewer")}):null]})]},k.key)},e[12]=o,e[13]=p,e[14]=r,e[15]=a,e[16]=C):C=e[16],x=y.map(C)}e[4]=o,e[5]=p,e[6]=r,e[7]=n,e[8]=a,e[9]=v,e[10]=x,e[11]=g}else v=e[9],x=e[10],g=e[11];if(g!==Symbol.for("react.early_return_sentinel"))return g;let w;return e[17]!==v||e[18]!==x?(w=s.jsx("div",{className:v,children:x}),e[17]=v,e[18]=x,e[19]=w):w=e[19],w}function ZI(t){return t.items.length>0}const Ec="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 eP(t){const e=st.c(13),{onOpenSettings:n,onOpenShortcuts:r,onOpenAbout:a,onOpenUpdate:i,showRuntimeButtons:o,showUpdateButton:c}=t,d=o===void 0?!0:o,p=c===void 0?!0:c,{t:m}=dt();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(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,className:Ec,"aria-label":m("sessions.sidebar.footer.actions.settings"),children:s.jsx(D,{name:"settings-3",className:"h-4.5 w-4.5"})})}),s.jsx(At,{side:"top",sideOffset:4,children:s.jsx("p",{children:m("sessions.sidebar.footer.actions.settings")})})]}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:r,className:Ec,"aria-label":m("sessions.sidebar.footer.actions.shortcuts"),children:s.jsx(D,{name:"question",className:"h-4.5 w-4.5"})})}),s.jsx(At,{side:"top",sideOffset:4,children:s.jsx("p",{children:m("sessions.sidebar.footer.actions.shortcuts")})})]}),s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:a,className:Ec,"aria-label":m("sessions.sidebar.footer.actions.aboutOpenChamber"),children:s.jsx(D,{name:"information",className:"h-4.5 w-4.5"})})}),s.jsx(At,{side:"top",sideOffset:4,children:s.jsx("p",{children:m("sessions.sidebar.footer.actions.aboutOpenChamber")})})]})]}):null,e[0]=a,e[1]=n,e[2]=r,e[3]=d,e[4]=m,e[5]=u):u=e[5];let f;e[6]!==i||e[7]!==p||e[8]!==m?(f=p?s.jsx(be,{type:"button",variant:"default",size:"xs",className:"ml-auto border-[var(--status-info-border)] bg-[var(--status-info-background)] text-[var(--status-info)] hover:bg-[var(--status-info-background)]/80 hover:text-[var(--status-info)] dark:border-[var(--status-info-border)] dark:bg-[var(--status-info-background)] dark:hover:bg-[var(--status-info-background)]/80",onClick:i,children:m("sessions.sidebar.footer.actions.update")}):null,e[6]=i,e[7]=p,e[8]=m,e[9]=f):f=e[9];let b;return e[10]!==u||e[11]!==f?(b=s.jsxs("div",{className:"flex shrink-0 items-center justify-start gap-1 px-2.5 py-2",children:[u,f]}),e[10]=u,e[11]=f,e[12]=b):b=e[12],b}const tP=t=>{const e=st.c(58),{id:n,projectLabel:r,projectDescription:a,projectIcon:i,projectColor:o,projectIconImage:c,projectIconBackground:d,isCollapsed:p,isActiveProject:m,isRepo:u,isDesktopShell:f,isStuck:b,hideDirectoryControls:h,alwaysShowActions:v,onToggle:x,onNewSession:g,onNewWorktreeSession:w,onRenameStart:y,onClose:C,sentinelRef:k,children:j,showCreateButtons:S,hideHeader:I,openSidebarMenuKey:M,setOpenSidebarMenuKey:P}=t,A=S===void 0?!0:S,N=I===void 0?!1:I,{t:E}=dt(),{currentTheme:T}=Cr();let R;e[0]!==n?(R={id:n},e[0]=n,e[1]=R):R=e[1];const{attributes:V,listeners:_,setNodeRef:U,transform:B,transition:z,isDragging:K}=Sl(R),[F,G]=l.useState(!1),Q=l.useRef(!1),te=`project:${n}`,Z=M===te;let fe;e[2]===Symbol.for("react.memo_cache_sentinel")?(fe=()=>{G(!1)},e[2]=fe):fe=e[2];const ue=c?.updatedAt;let W;e[3]!==n||e[4]!==ue?(W=[n,ue],e[3]=n,e[4]=ue,e[5]=W):W=e[5],l.useEffect(fe,W);const q=i?Rl[i]:null,J=o?po[o]??null:null;let ne;e[6]!==T||e[7]!==n||e[8]!==F||e[9]!==c?(ne=F?null:mo({id:n,iconImage:c},{themeVariant:T.metadata.variant,iconColor:T.colors.surface.foreground}),e[6]=T,e[7]=n,e[8]=F,e[9]=c,e[10]=ne):ne=e[10];const ee=ne;let he;e[11]!==te||e[12]!==P?(he=re=>{P(re?te:null)},e[11]=te,e[12]=P,e[13]=he):he=e[13];const ke=he,oe=rP,ge=aP,me=iP;let ye;e[14]===Symbol.for("react.memo_cache_sentinel")?(ye=re=>{(re.button===2||re.button===0&&re.ctrlKey)&&(Q.current=!0)},e[14]=ye):ye=e[14];const ie=ye;let ve;e[15]!==x?(ve=()=>{if(Q.current){Q.current=!1;return}x()},e[15]=x,e[16]=ve):ve=e[16];const X=ve;let Se;e[17]!==B?(Se=kl.Transform.toString(B),e[17]=B,e[18]=Se):Se=e[18];let Ae;e[19]!==Se||e[20]!==z?(Ae={transform:Se,transition:z},e[19]=Se,e[20]=z,e[21]=Ae):Ae=e[21];const pe=K&&"opacity-30";let we;e[22]!==pe?(we=xe("relative",pe),e[22]=pe,e[23]=we):we=e[23];let Ie;e[24]!==v||e[25]!==V||e[26]!==ke||e[27]!==X||e[28]!==h||e[29]!==N||e[30]!==J||e[31]!==n||e[32]!==ee||e[33]!==m||e[34]!==p||e[35]!==f||e[36]!==Z||e[37]!==u||e[38]!==b||e[39]!==_||e[40]!==C||e[41]!==g||e[42]!==w||e[43]!==y||e[44]!==a||e[45]!==d||e[46]!==q||e[47]!==r||e[48]!==k||e[49]!==A||e[50]!==E?(Ie=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:xe("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(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsxs("button",{type:"button",onMouseDown:ie,onClick:X,..._,className:xe("flex-1 min-w-0 flex items-center gap-1.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 rounded-md cursor-grab active:cursor-grabbing transition-[padding]",u&&!h?v?"pr-20":"pr-7 group-hover/project:pr-20 group-focus-within/project:pr-20":v?"pr-14":"pr-7 group-hover/project:pr-14 group-focus-within/project:pr-14"),children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 flex-shrink-0 items-center justify-center",children:[s.jsx("span",{className:xe("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"})}),ee?s.jsx("span",{className:xe("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:ee,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>G(!0)})}):q?s.jsx(D,{name:q,className:xe("h-3.5 w-3.5",v?"hidden":"group-hover/project:hidden group-focus-within/project:hidden"),style:J?{color:J}:void 0}):s.jsx(D,{name:"folder",className:xe("h-3.5 w-3.5 text-muted-foreground/80",v?"hidden":"group-hover/project:hidden group-focus-within/project:hidden"),style:J?{color:J}:void 0})]}),s.jsx("span",{className:xe("text-[14px] font-normal truncate lowercase",m?"text-foreground":"text-foreground group-hover/project:text-foreground"),children:r})]})}),s.jsx(At,{side:"right",sideOffset:8,children:a})]}),s.jsxs("div",{className:xe("absolute top-1/2 z-10 flex -translate-y-1/2 items-center gap-1",A?"right-7":"right-0.5"),children:[A&&u&&!h&&w?s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:re=>{re.stopPropagation(),w()},className:xe("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(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:E("sessions.sidebar.project.actions.newWorktreeEllipsis")})})]}):null,s.jsxs(Ts,{open:Z,onOpenChange:ke,children:[s.jsx(As,{asChild:!0,children:s.jsx("button",{type:"button",className:xe("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",Z?"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:me,onClick:oe,children:s.jsx(D,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsxs(Ds,{align:"end",className:"min-w-[180px]",children:[A&&!u&&!h&&g&&s.jsxs($t,{onClick:g,children:[s.jsx(D,{name:"add",className:"mr-1.5 h-4 w-4"}),E("sessions.sidebar.project.actions.newSession")]}),s.jsxs($t,{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($t,{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&&g?s.jsx("div",{className:"absolute right-0.5 top-1/2 z-10 -translate-y-1/2",children:s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",onClick:re=>{re.stopPropagation(),g()},className:xe("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(At,{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]=ke,e[27]=X,e[28]=h,e[29]=N,e[30]=J,e[31]=n,e[32]=ee,e[33]=m,e[34]=p,e[35]=f,e[36]=Z,e[37]=u,e[38]=b,e[39]=_,e[40]=C,e[41]=g,e[42]=w,e[43]=y,e[44]=a,e[45]=d,e[46]=q,e[47]=r,e[48]=k,e[49]=A,e[50]=E,e[51]=Ie):Ie=e[51];let Y;return e[52]!==j||e[53]!==U||e[54]!==Ae||e[55]!==we||e[56]!==Ie?(Y=s.jsxs("div",{ref:U,style:Ae,className:we,children:[Ie,j]}),e[52]=j,e[53]=U,e[54]=Ae,e[55]=we,e[56]=Ie,e[57]=Y):Y=e[57],Y},sP=t=>{const e=st.c(21),{id:n,disabled:r,children:a}=t,i=r===void 0?!1:r;let o;e[0]!==i||e[1]!==n?(o={id:n,disabled:i},e[0]=i,e[1]=n,e[2]=o):o=e[2];const{listeners:c,setNodeRef:d,setActivatorNodeRef:p,transform:m,transition:u,isDragging:f}=Sl(o);let b;e[3]!==c||e[4]!==p?(b={listeners:c,setActivatorNodeRef:p},e[3]=c,e[4]=p,e[5]=b):b=e[5];const h=b;let v;e[6]!==m?(v=kl.Transform.toString(m),e[6]=m,e[7]=v):v=e[7];let x;e[8]!==v||e[9]!==u?(x={transform:v,transition:u},e[8]=v,e[9]=u,e[10]=x):x=e[10];const g=f&&"opacity-50";let w;e[11]!==g?(w=xe("space-y-0.5 rounded-md",g),e[11]=g,e[12]=w):w=e[12];let y;e[13]!==a||e[14]!==h?(y=typeof a=="function"?a(h):a,e[13]=a,e[14]=h,e[15]=y):y=e[15];let C;return e[16]!==d||e[17]!==x||e[18]!==w||e[19]!==y?(C=s.jsx("div",{ref:d,style:x,className:w,children:y}),e[16]=d,e[17]=x,e[18]=w,e[19]=y,e[20]=C):C=e[20],C},nP=l.memo(sP);function rP(t){t.stopPropagation()}function aP(t){t.stopPropagation()}function iP(t){t.stopPropagation()}function oP(t){const e=st.c(25),{t:n}=dt();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:Rx},e[1]=a):a=e[1];const i=Ji(ti(Yi,r),ti(Ex,a));let o;e[2]===Symbol.for("react.memo_cache_sentinel")?(o={activationConstraint:{distance:8}},e[2]=o):o=e[2];const c=Ji(ti(Yi,o));if(t.projectSections.length===0){const f=(t.mobileVariant,"");let b;e[3]!==f?(b=xe("space-y-1 pb-1 pl-2.5 pr-2",f),e[3]=f,e[4]=b):b=e[4];let h;return e[5]!==t.emptyState||e[6]!==t.topContent||e[7]!==b?(h=s.jsxs(Ns,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:b,children:[t.topContent,t.emptyState]}),e[5]=t.emptyState,e[6]=t.topContent,e[7]=b,e[8]=h):h=e[8],h}if(t.sectionsForRender.length===0){const f=(t.mobileVariant,"");let b;e[9]!==f?(b=xe("space-y-1 pb-1 pl-2.5 pr-2",f),e[9]=f,e[10]=b):b=e[10];let h;return e[11]!==t.searchEmptyState||e[12]!==b?(h=s.jsx(Ns,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:b,children:t.searchEmptyState}),e[11]=t.searchEmptyState,e[12]=b,e[13]=h):h=e[13],h}const d=(t.mobileVariant,"");let p;e[14]!==d?(p=xe("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(hP)??f.groups.find(fP)??f.groups.find(pP)??f.groups[0];if(!b)return s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:n("sessions.sidebar.empty.noSessions.title")});const h=f.groups.find(mP);return[b,...h&&h.id!==b.id?[h]:[]].map(x=>{const g=`${f.project.id}:${x.id}`,w=x.id===b.id;return s.jsx(l.Fragment,{children:t.renderGroupSessions(x,g,f.project.id,w,null,!0)},g)})})()}):s.jsx(s.Fragment,{children:s.jsxs(Qi,{sensors:i,collisionDetection:Xi,onDragEnd:f=>{if(t.isInlineEditing)return;const{active:b,over:h}=f;if(!h||b.id===h.id)return;const v=t.sectionsForRender.findIndex(g=>g.project.id===b.id),x=t.sectionsForRender.findIndex(g=>g.project.id===h.id);v===-1||x===-1||v===x||t.reorderProjects(v,x)},children:[s.jsx(rl,{items:t.sectionsForRender.map(uP),strategy:Vc,children:t.sectionsForRender.map(f=>{const b=f.project,h=b.id,v=fh(b.label?.trim()||Oa(b.normalizedPath,t.homeDirectory)||b.normalizedPath),x=eo(b.normalizedPath,t.homeDirectory),g=t.collapsedProjects.has(h),w=h===t.activeProjectId,y=t.projectRepoStatus.get(h),C=t.getOrderedGroups(h,f.groups),k=C.find(dP)??null,j=k?C.filter(S=>S.id!==k.id):C;return s.jsx(tP,{id:h,projectLabel:v,projectDescription:x,projectIcon:b.icon,projectColor:b.color,projectIconImage:b.iconImage,projectIconBackground:b.iconBackground,isCollapsed:g,isActiveProject:w,isRepo:!!y,isDesktopShell:t.isDesktopShellRuntime,isStuck:t.stuckProjectHeaders.has(h),hideDirectoryControls:t.hideDirectoryControls,mobileVariant:t.mobileVariant,alwaysShowActions:t.alwaysShowActions,onToggle:()=>t.toggleProject(h),onNewSession:()=>{h!==t.activeProjectId&&t.setActiveProjectIdOnly(h),t.setActiveMainTab("chat"),t.mobileVariant&&t.setSessionSwitcherOpen(!1),t.openNewSessionDraft({directoryOverride:b.normalizedPath})},onNewWorktreeSession:()=>{h!==t.activeProjectId&&t.setActiveProjectIdOnly(h),t.setActiveMainTab("chat"),t.mobileVariant&&t.setSessionSwitcherOpen(!1),t.openNewWorktreeDialog()},onRenameStart:()=>t.openProjectEditDialog(h),onClose:()=>t.removeProject(h),sentinelRef:S=>{t.projectHeaderSentinelRefs.current.set(h,S)},showCreateButtons:!0,openSidebarMenuKey:t.openSidebarMenuKey,setOpenSidebarMenuKey:t.setOpenSidebarMenuKey,children:g?null:s.jsx("div",{className:"space-y-0 pt-0 pb-0.5 pl-3",children:f.groups.length>0?s.jsxs(Qi,{sensors:c,collisionDetection:Xi,onDragEnd:S=>{if(t.isInlineEditing)return;const{active:I,over:M}=S;if(!M||I.id===M.id)return;const P=j.findIndex(T=>T.id===I.id),A=j.findIndex(T=>T.id===M.id);if(P===-1||A===-1||P===A)return;const N=Mf(j,P,A).map(cP),E=k?[k.id,...N]:N;t.setGroupOrderByProject(T=>{const R=new Map(T);return R.set(h,E),R})},children:[k?t.renderGroupSessions(k,`${h}:${k.id}`,h,!0):null,s.jsx(rl,{items:j.map(lP),strategy:Vc,children:j.map(S=>{const I=`${h}:${S.id}`;return s.jsx(nP,{id:S.id,disabled:t.isInlineEditing,children:M=>t.renderGroupSessions(S,I,h,!1,M)},S.id)})}),s.jsx(al,{dropAnimation:null})]}):s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:n("sessions.sidebar.empty.noSessions.title")})})},h)})}),s.jsx(al,{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(Ns,{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 lP(t){return t.id}function cP(t){return t.id}function dP(t){return t.isMain}function uP(t){return t.project.id}function mP(t){return t.isArchivedBucket}function pP(t){return t.isMain}function fP(t){return t.sessions.length>0}function hP(t){return t.isMain&&t.sessions.length>0}function gP(t){if(typeof t!="number"||!Number.isFinite(t))return"";const e=new Date(t);if(Number.isNaN(e.getTime()))return"";const n=e.toLocaleString(void 0,{month:"short"}),r=e.getDate(),a=e.getFullYear(),i=String(e.getHours()).padStart(2,"0"),o=String(e.getMinutes()).padStart(2,"0");return`${n} ${r}, ${a}, ${i}:${o}`}function xP(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 bP(t){const e=t.info.role==="user"?"User":"Assistant",n=gP(t.info.time?.created),r=xP(t),a=n&&r?`${n} (${r})`:n||r;return a?`**${e}**
183
+
184
+ *${a}*`:`**${e}**`}function yP(t){return t.filter(e=>e.type==="text"&&typeof e.text=="string").map(e=>e.text).join("")}function Eg(t){const e=bP(t),n=yP(t.parts).trim();return n?`${e}
185
+
186
+ ${n}`:""}function Rg(t,e){const n="#".repeat(Math.min(e+1,6)),r=t.agent?` — ${t.agent}`:"",a=`${n} Sub-agent: ${t.title}${r}
187
+
188
+ ---
189
+
190
+ `,i=t.records.map(Eg).filter(Boolean).join(`
191
+
192
+ ---
193
+
194
+ `),o=[a+i];for(const c of t.children)o.push(Rg(c,e+1));return o.join(`
195
+
196
+ ---
197
+
198
+ `)}function vP(t,e,n){const r=e?.trim()||"Session",a=new Date().toISOString().split("T")[0],i=`# ${r}
199
+
200
+ *Exported on ${a}*
201
+
202
+ ---
203
+
204
+ `,o=t.map(Eg).filter(Boolean).join(`
205
+
206
+ ---
207
+
208
+ `);let c=i+o;if(n&&n.length>0){const d=n.map(p=>Rg(p,1)).join(`
209
+
210
+ ---
211
+
212
+ `);c+=`
213
+
214
+ ---
215
+
216
+ `+d}return c}function wP(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 jP(t,e){const n=await jy(e,t);if(n)return n;if(!on())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 NP(t){const e=Xn()?.files;if(e?.revealPath)try{return!!(await e.revealPath(t))?.success}catch{return!1}return await Ny(t)?!0:il(t)}function SP(){return Od()}function kP(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 CP=(t,e)=>{if(!e)return Array.from(t);const n=[],r=new Set;for(const a of t){r.has(a)||(r.add(a),n.push(a));const i=e.get(a);if(i)for(const o of i)r.has(o)||(r.add(o),n.push(o))}return n},ur=Zn()((t,e)=>({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null,enable:()=>{e().enabled||t({enabled:!0})},disable:()=>{t({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null})},toggleMode:()=>{e().enabled?t({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null}):t({enabled:!0})},toggleSelected:(n,r,a)=>{const i=e(),o=new Set(i.selectedIds);let c=i.scopeKey,d=i.anchorId;r!==null&&i.scopeKey!==null&&r!==i.scopeKey?(o.clear(),c=r,d=null):c===null&&r!==null&&(c=r);const m=a&&a.length>0?[n,...a]:[n];if(o.has(n)){for(const f of m)o.delete(f);d===n&&(d=null)}else{for(const f of m)o.add(f);d=n}o.size===0?t({selectedIds:o,scopeKey:null,anchorId:null}):t({selectedIds:o,scopeKey:c,anchorId:d})},setRange:(n,r,a,i,o)=>{const c=e();if(a.length===0)return;const d=n&&a.includes(n)?n:a[0],p=a.indexOf(d),m=a.indexOf(r);if(p<0||m<0)return;const[u,f]=p<=m?[p,m]:[m,p],b=a.slice(u,f+1),h=CP(b,o),x=i!==null&&c.scopeKey!==null&&i!==c.scopeKey?new Set:new Set(c.selectedIds);for(const g of h)x.add(g);t({selectedIds:x,scopeKey:i??c.scopeKey,anchorId:d})},replaceAll:(n,r)=>{if(n.length===0){t({selectedIds:new Set,scopeKey:null,anchorId:null});return}t({selectedIds:new Set(n),scopeKey:r,anchorId:n[0]??null})},clear:()=>{t({selectedIds:new Set,scopeKey:null,anchorId:null})},removeMany:n=>{const r=e();if(r.selectedIds.size===0||n.length===0)return;const a=new Set(r.selectedIds);for(const i of n)a.delete(i);a.size!==r.selectedIds.size&&(a.size===0?t({selectedIds:a,scopeKey:null,anchorId:null}):t({selectedIds:a}))}})),IP=/^[a-z0-9](?:[a-z0-9-]{0,48}[a-z0-9])?$/,Fg=/^g[1-9]\d*$/,Oi=(t,e,n,r,a)=>{if(!IP.test(t)||e!==void 0&&!Fg.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}},sl=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 Oi(n,void 0,e[1],e[2],void 0);if(e.length===4){const[,c,d,p]=e;return Fg.test(c)?Oi(n,c,d,p,void 0):Oi(n,void 0,c,d,p)}const[,r,a,i,o]=e;return r===""?Oi(n,void 0,a,i,o):Oi(n,r,a,i,o)},PP=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("/")},AP=(t,e,n,r)=>{const a=[t];return r&&a.push(r),a.push(e,n,"fusion"),a.join("/")},Og=t=>{const e=st.c(35),{value:n,onChange:r,className:a,disabled:i,id:o,portalToBody:c}=t,{t:d}=dt(),p=bt(DP),m=bt(TP),u=bt(MP);let f;e[0]!==p?(f=p(),e[0]=p,e[1]=f):f=e[1];const b=f;let h;e[2]!==b?(h=b.filter(EP),e[2]=b,e[3]=h):h=e[3];const v=h;let x,g;e[4]!==m?(x=()=>{m()},g=[m],e[4]=m,e[5]=x,e[6]=g):(x=e[5],g=e[6]),l.useEffect(x,g);let w,y;e[7]!==u||e[8]!==i||e[9]!==r||e[10]!==v||e[11]!==n?(w=()=>{if(i)return;const N=n.trim();if(N.length>0&&v.some(R=>R.name===N))return;const E=typeof u=="string"&&u.trim().length>0?u.trim():null;if(E&&v.some(R=>R.name===E)){r(E);return}const T=v[0]?.name;T&&r(T)},y=[u,i,r,v,n],e[7]=u,e[8]=i,e[9]=r,e[10]=v,e[11]=n,e[12]=w,e[13]=y):(w=e[12],y=e[13]),l.useEffect(w,y);const C=n.trim().length>0?n:void 0;let k;e[14]!==a?(k=xe("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 j;e[16]!==d?(j=d("multirun.agentSelector.placeholder"),e[16]=d,e[17]=j):j=e[17];let S;e[18]!==j?(S=s.jsx(us,{placeholder:j}),e[18]=j,e[19]=S):S=e[19];let I;e[20]!==o||e[21]!==k||e[22]!==S?(I=s.jsx(ls,{id:o,size:"lg",className:k,children:S}),e[20]=o,e[21]=k,e[22]=S,e[23]=I):I=e[23];let M;e[24]!==v?(M=v.length>0&&s.jsx(qc,{children:v.map(RP)}),e[24]=v,e[25]=M):M=e[25];let P;e[26]!==c||e[27]!==M?(P=s.jsx(cs,{fitContent:!0,portalToBody:c,children:M}),e[26]=c,e[27]=M,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(os,{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 DP(t){return t.getVisibleAgents}function TP(t){return t.loadAgents}function MP(t){return t.currentAgentName}function EP(t){return t.mode!=="subagent"}function RP(t){return s.jsx(Tt,{value:t.name,className:"w-auto whitespace-nowrap",children:t.name},t.name)}const Lg="h-7",qi=()=>`${Date.now()}-${Math.random().toString(36).substring(2,9)}`,FP=t=>{const e=st.c(12),{model:n,instanceIndex:r,totalSameModel:a,onRemove:i}=t,o=n.displayName||`${n.providerID}/${n.modelID}`,c=a>1?`${o} (${r})`:o;let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=xe("flex items-center gap-1.5 px-2 rounded-md bg-interactive-selection/20 border border-border/30",Lg),e[0]=d):d=e[0];let p;e[1]!==n.providerID?(p=s.jsx(pr,{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},$g=t=>{const e=st.c(117),{selectedModels:n,onAdd:r,onRemove:a,onUpdate:i,minModels:o,addButtonLabel:c,showChips:d,maxModels:p,addButtonClassName:m,dropdownSide:u,dropdownClassName:f,containerClassName:b,triggerIcon:h}=t,v=d===void 0?!0:d,x=u===void 0?"top":u,{t:g}=dt(),w=bt(OP),y=bt(LP),C=Re($P),k=Re(_P),{favoriteModelsList:j,recentModelsList:S}=qf(),[I,M]=l.useState(!1),[P,A]=l.useState(""),[N,E]=l.useState(null),T=l.useRef(null),R=l.useRef(null),V=p===1,_=p===void 0||n.length<p||V;let U;if(e[0]!==n){U=new Map;for(const L of n){const $=`${L.providerID}:${L.modelID}`;U.set($,(U.get($)||0)+1)}e[0]=n,e[1]=U}else U=e[1];const B=U;let z;e[2]!==n?(z=L=>n.filter(je=>je.providerID===L.providerID&&je.modelID===L.modelID).findIndex(je=>je.instanceId===L.instanceId)+1,e[2]=n,e[3]=z):z=e[3];const K=z;let F,G;e[4]!==x||e[5]!==I?(F=()=>{if(!I||!R.current)return;const L=R.current.getBoundingClientRect();if(x==="bottom"){const Me=(window.visualViewport?.height??document.documentElement.clientHeight??window.innerHeight)-L.bottom-16-112;E(Math.max(160,Math.min(320,Me)));return}let $=R.current.parentElement;for(;$&&!($.getAttribute("role")==="dialog"||$.hasAttribute("data-scroll-shadow"));){const _e=getComputedStyle($);if(_e.overflow==="auto"||_e.overflow==="hidden"||_e.overflowY==="auto"||_e.overflowY==="hidden")break;$=$.parentElement}const je=$?$.getBoundingClientRect().top:0,ae=L.top-je-16;E(Math.max(150,Math.min(300,ae)))},G=[x,I],e[4]=x,e[5]=I,e[6]=F,e[7]=G):(F=e[6],G=e[7]),l.useEffect(F,G);let Q,te;e[8]!==_||e[9]!==I?(Q=()=>{!_&&I&&(M(!1),A(""))},te=[_,I],e[8]=_,e[9]=I,e[10]=Q,e[11]=te):(Q=e[10],te=e[11]),l.useEffect(Q,te);let Z,fe;e[12]!==I?(Z=()=>{if(!I)return;const L=$=>{T.current&&!T.current.contains($.target)&&(M(!1),A(""))};return document.addEventListener("mousedown",L),()=>document.removeEventListener("mousedown",L)},fe=[I],e[12]=I,e[13]=Z,e[14]=fe):(Z=e[13],fe=e[14]),l.useEffect(Z,fe);let ue;e[15]!==V||e[16]!==r||e[17]!==i||e[18]!==n.length?(ue=L=>{const $={providerID:L.providerID,modelID:L.modelID,displayName:L.model.name||L.modelID,instanceId:qi()};V&&n.length>0&&i?i(0,$):r($),V&&(M(!1),A(""))},e[15]=V,e[16]=r,e[17]=i,e[18]=n.length,e[19]=ue):ue=e[19];const W=ue;let q;e[20]!==g?(q=g("multirun.modelMultiSelect.search.placeholder"),e[20]=g,e[21]=q):q=e[21];let J;e[22]!==g?(J=g("multirun.modelMultiSelect.search.noResults"),e[22]=g,e[23]=J):J=e[23];let ne;e[24]!==g?(ne=g("multirun.modelMultiSelect.sections.favorites"),e[24]=g,e[25]=ne):ne=e[25];let ee;e[26]!==g?(ee=g("multirun.modelMultiSelect.sections.recent"),e[26]=g,e[27]=ee):ee=e[27];let he;e[28]!==g?(he=g("multirun.modelMultiSelect.keyboard.hint"),e[28]=g,e[29]=he):he=e[29];let ke;e[30]!==g?(ke=g("settings.agents.modelSelector.actions.favorite"),e[30]=g,e[31]=ke):ke=e[31];let oe;e[32]!==g?(oe=g("settings.agents.modelSelector.actions.unfavorite"),e[32]=g,e[33]=oe):oe=e[33];let ge;e[34]!==g?(ge=g("chat.modelControls.capabilities"),e[34]=g,e[35]=ge):ge=e[35];let me;e[36]!==g?(me=g("chat.modelControls.capability.toolCalling"),e[36]=g,e[37]=me):me=e[37];let ye;e[38]!==g?(ye=g("chat.modelControls.capability.reasoning"),e[38]=g,e[39]=ye):ye=e[39];let ie;e[40]!==g?(ie=g("chat.modelControls.input"),e[40]=g,e[41]=ie):ie=e[41];let ve;e[42]!==g?(ve=g("chat.modelControls.output"),e[42]=g,e[43]=ve):ve=e[43];let X;e[44]!==g?(X=g("chat.modelControls.costPerMillion"),e[44]=g,e[45]=X):X=e[45];let Se;e[46]!==q||e[47]!==J||e[48]!==ne||e[49]!==ee||e[50]!==he||e[51]!==ke||e[52]!==oe||e[53]!==ge||e[54]!==me||e[55]!==ye||e[56]!==ie||e[57]!==ve||e[58]!==X?(Se={searchPlaceholder:q,noResults:J,favorites:ne,recent:ee,keyboardHint:he,favorite:ke,unfavorite:oe,capabilities:ge,capabilityToolCalling:me,capabilityReasoning:ye,input:ie,output:ve,costPerMillion:X},e[46]=q,e[47]=J,e[48]=ne,e[49]=ee,e[50]=he,e[51]=ke,e[52]=oe,e[53]=ge,e[54]=me,e[55]=ye,e[56]=ie,e[57]=ve,e[58]=X,e[59]=Se):Se=e[59];const Ae=Se;let pe;e[60]!==b?(pe=xe("relative",b),e[60]=b,e[61]=pe):pe=e[61];let we;e[62]!==m?(we=xe(Lg,"!border-border/80 !bg-[var(--surface-subtle)] hover:!bg-[var(--interactive-hover)]/70",m),e[62]=m,e[63]=we):we=e[63];const Ie=!_;let Y;e[64]!==I?(Y=()=>{M(!I)},e[64]=I,e[65]=Y):Y=e[65];let re;e[66]!==h?(re=h??s.jsx(D,{name:"add",className:"h-3.5 w-3.5 mr-1"}),e[66]=h,e[67]=re):re=e[67];let Pe;e[68]!==c||e[69]!==g?(Pe=c??g("multirun.modelMultiSelect.actions.addModel"),e[68]=c,e[69]=g,e[70]=Pe):Pe=e[70];let ce;e[71]!==we||e[72]!==Ie||e[73]!==Y||e[74]!==re||e[75]!==Pe?(ce=s.jsxs(be,{ref:R,type:"button",variant:"outline",size:"sm",className:we,disabled:Ie,onClick:Y,children:[re,Pe]}),e[71]=we,e[72]=Ie,e[73]=Y,e[74]=re,e[75]=Pe,e[76]=ce):ce=e[76];let Ce;e[77]!==N||e[78]!==_||e[79]!==f||e[80]!==x||e[81]!==j||e[82]!==W||e[83]!==k||e[84]!==I||e[85]!==Ae||e[86]!==B||e[87]!==y||e[88]!==w||e[89]!==S||e[90]!==P||e[91]!==C?(Ce=I?s.jsx("div",{className:xe("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(Jf,{providers:w,favoriteModels:j,recentModels:S,modelsMetadata:y,searchQuery:P,onSearchQueryChange:A,onSelect:W,labels:Ae,selectionCount:L=>B.get(`${L.providerID}:${L.modelID}`)||0,disabled:!_,maxHeightClassName:"flex-1",maxHeightStyle:{maxHeight:N?`${N}px`:"300px"},stickyHeaders:!0,tooltipsEnabled:I,isFavorite:L=>k(L.providerID,L.modelID),onToggleFavorite:L=>C(L.providerID,L.modelID),onEscape:()=>{M(!1),A("")}})}):null,e[77]=N,e[78]=_,e[79]=f,e[80]=x,e[81]=j,e[82]=W,e[83]=k,e[84]=I,e[85]=Ae,e[86]=B,e[87]=y,e[88]=w,e[89]=S,e[90]=P,e[91]=C,e[92]=Ce):Ce=e[92];let Te;e[93]!==pe||e[94]!==ce||e[95]!==Ce?(Te=s.jsxs("div",{className:pe,ref:T,children:[ce,Ce]}),e[93]=pe,e[94]=ce,e[95]=Ce,e[96]=Te):Te=e[96];let $e;e[97]!==K||e[98]!==B||e[99]!==a||e[100]!==i||e[101]!==w||e[102]!==n||e[103]!==v||e[104]!==g?($e=v&&n.length>0&&s.jsx("div",{className:"flex flex-col gap-2 w-full",children:n.map((L,$)=>{const je=`${L.providerID}:${L.modelID}`,ae=B.get(je)||1,_e=K(L),Me=w.find(Xe=>Xe.id===L.providerID)?.models?.find(Xe=>Xe.id===L.modelID),Ge=Me?.variants?Object.keys(Me.variants):[],at=Ge.length>0,Ye=L.variant??"__default__";return s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(FP,{model:L,instanceIndex:_e,totalSameModel:ae,onRemove:()=>a($)}),at&&s.jsxs(os,{value:Ye,onValueChange:Xe=>{if(!i)return;i($,{...L,variant:Xe==="__default__"?void 0:Xe})},children:[s.jsxs(ls,{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:xe("h-3.5 w-3.5 flex-shrink-0",Ye==="__default__"?"text-muted-foreground":"text-[color:var(--status-info)]")}),s.jsx(us,{placeholder:g("multirun.modelMultiSelect.variant.placeholder"),children:Xe=>Xe==="__default__"?g("multirun.modelMultiSelect.variant.default"):Xe})]}),s.jsxs(cs,{fitContent:!0,children:[s.jsx(Tt,{value:"__default__",className:"pr-2 [&>span:first-child]:hidden",children:g("multirun.modelMultiSelect.variant.default")}),Ge.map(BP)]})]})]},L.instanceId)})}),e[97]=K,e[98]=B,e[99]=a,e[100]=i,e[101]=w,e[102]=n,e[103]=v,e[104]=g,e[105]=$e):$e=e[105];let De;e[106]!==Te||e[107]!==$e?(De=s.jsxs("div",{className:"flex flex-wrap gap-1.5 items-center",children:[Te,$e]}),e[106]=Te,e[107]=$e,e[108]=De):De=e[108];let de;e[109]!==p||e[110]!==o||e[111]!==n.length||e[112]!==g?(de=o!==void 0&&n.length<o&&s.jsx("p",{className:"typography-micro text-muted-foreground",children:p!==void 0?g("multirun.modelMultiSelect.validation.minToMax",{min:o,max:p}):g("multirun.modelMultiSelect.validation.minOnly",{min:o})}),e[109]=p,e[110]=o,e[111]=n.length,e[112]=g,e[113]=de):de=e[113];let O;return e[114]!==De||e[115]!==de?(O=s.jsxs("div",{className:"space-y-2",children:[De,de]}),e[114]=De,e[115]=de,e[116]=O):O=e[116],O};function OP(t){return t.providers}function LP(t){return t.modelsMetadata}function $P(t){return t.toggleFavoriteModel}function _P(t){return t.isFavoriteModel}function BP(t){return s.jsx(Tt,{value:t,className:"pr-2 [&>span:first-child]:hidden",children:t},t)}const zP=(t,e,n)=>{const r=t.session.title?.trim()||t.session.id;return`
217
+
218
+ --- RESULT ${n+1}: ${r} ---
219
+ ${e.trim()}
220
+ --- END RESULT ${n+1} ---`},df=(t,e)=>Lt.getState().getWorktreeMetadata(t)?.projectDirectory??e,VP=async t=>{const e=t.directory??void 0,n=Sy(t.session.id,e);if(n.length===0&&t.directory){const a=(await sn.withDirectory(t.directory,()=>sn.getSdkClient().session.messages({sessionID:t.session.id,directory:t.directory??void 0,limit:50}))).data??[];for(let i=a.length-1;i>=0;i-=1){const o=a[i];if(o.info?.role==="assistant")return Ou(o.parts??[]).trim()}return""}for(let r=n.length-1;r>=0;r-=1){const a=n[r];if(a.role==="assistant")return Ou(ky(a.id,e)).trim()}return""};function UP({session:t,open:e,onOpenChange:n}){const{t:r}=dt(),a=Id(),i=Pa(U=>U.activeSessions),o=Pa(U=>U.archivedSessions),c=bt(U=>U.providers),d=bt(U=>U.currentProviderId),p=bt(U=>U.currentModelId),m=bt(U=>U.currentAgentName),[u,f]=l.useState(d??""),[b,h]=l.useState(p??""),[v,x]=l.useState(()=>d&&p?[{providerID:d,modelID:p,instanceId:qi()}]:[]),[g,w]=l.useState(""),[y,C]=l.useState(m??""),[k,j]=l.useState([]),[S,I]=l.useState(!1),M=l.useMemo(()=>sl(t.title),[t.title]),P=l.useMemo(()=>{const U=new Map;for(const B of a)U.set(B.id,B);for(const B of i)U.set(B.id,B);for(const B of o)U.set(B.id,B);return t.id&&U.set(t.id,t),Array.from(U.values())},[i,o,a,t]);l.useEffect(()=>{if(!e||!M)return;const U=Lt.getState().getDirectoryForSession(t.id),B=df(t.id,U),z=P.map(K=>{const F=sl(K.title);if(!F||F.groupSlug!==M.groupSlug||F.fusion||(F.runGroup??null)!==(M.runGroup??null))return null;const G=Lt.getState().getDirectoryForSession(K.id)??Ui(K),Q=df(K.id,G);return B&&Q&&B!==Q?null:{session:K,directory:G,projectDirectory:Q}}).filter(K=>K!==null).sort((K,F)=>(K.session.time?.created??0)-(F.session.time?.created??0));j(z)},[P,e,M,t.id]);const N=c.find(U=>U.id===u)?.models.find(U=>U.id===b),E=N?.variants?Object.keys(N.variants):[],T=!!(M&&u&&b&&k.length>0&&!S),R=l.useCallback(U=>{x([U]),f(U.providerID),h(U.modelID),w("")},[]),V=v[0]?.displayName||v[0]?.modelID||r("multirun.fusion.model.placeholder"),_=async()=>{if(!(!M||!u||!b)){I(!0);try{const U=await Promise.all(k.map(te=>VP(te))),B=k.map((te,Z)=>({source:te,text:U[Z]??""})).filter(te=>te.text.trim().length>0);if(B.length===0){H.error(r("multirun.fusion.toast.noOutputs"));return}const z=k[0]?.projectDirectory??k[0]?.directory??null,K=AP(M.groupSlug,u,b,M.runGroup),[F,G]=await Promise.all([yn("session.fusion.visible"),yn("session.fusion.instructions")]),Q=await Lt.getState().createSession(K,z,null);if(!Q)throw new Error("Failed to create fusion session");Lt.getState().setCurrentSession(Q.id,z),n(!1),await sn.withDirectory(z??sn.getDirectory(),()=>sn.sendMessage({id:Q.id,providerID:u,modelID:b,variant:g||void 0,agent:y||void 0,text:F,additionalParts:[{text:G,synthetic:!0},...B.map((te,Z)=>({text:zP(te.source,te.text,Z),synthetic:!0})),{text:`
221
+
222
+ --- FUSION INPUTS END ---
223
+ Now write the final fused answer.`,synthetic:!0}]}))}catch(U){console.error("[MultiRunFusion] Failed to start fusion",U),H.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(ys,{children:[s.jsx(hs,{children:r("multirun.fusion.title")}),s.jsx(Ss,{children:r("multirun.fusion.description")})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("div",{className:"max-w-full",children:s.jsx($g,{selectedModels:v,onAdd:R,onUpdate:(U,B)=>R(B),onRemove:()=>{x([]),f(""),h(""),w("")},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(pr,{providerId:u,className:"h-3.5 w-3.5 mr-1"}):void 0})}),E.length>0?s.jsxs(os,{value:g||"__default__",onValueChange:U=>w(U==="__default__"?"":U),children:[s.jsxs(ls,{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:U=>U==="__default__"?r("multirun.modelMultiSelect.variant.default"):U})]}),s.jsxs(cs,{fitContent:!0,portalToBody:!0,children:[s.jsx(Tt,{value:"__default__",children:r("multirun.modelMultiSelect.variant.default")}),E.map(U=>s.jsx(Tt,{value:U,children:U},U))]})]}):null,s.jsx(Og,{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(U=>s.jsxs("div",{className:"flex items-center gap-2 rounded-md px-2 py-1.5 typography-meta",children:[s.jsx(pr,{providerId:sl(U.session.title)?.providerID??"",className:"h-4 w-4"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:U.session.title||U.session.id}),s.jsx("button",{type:"button",onClick:()=>j(B=>B.filter(z=>z.session.id!==U.session.id)),className:"text-muted-foreground hover:text-foreground",children:s.jsx(D,{name:"close",className:"h-4 w-4"})})]},U.session.id))})]}),s.jsxs(Vs,{children:[s.jsx(be,{variant:"ghost",onClick:()=>n(!1),children:r("multirun.fusion.actions.cancel")}),s.jsx(be,{onClick:_,disabled:!T,children:r(S?"multirun.fusion.actions.starting":"multirun.fusion.actions.start")})]})]})})}function WP(t){const e=st.c(7);let n,r,a,i,o;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx("path",{d:"M12 4.5v6.25M12 10.75v3.5M12 10.75H7.25A3.25 3.25 0 0 0 4 14v1.25M12 10.75h4.75A3.25 3.25 0 0 1 20 14v1.25",stroke:"currentColor",strokeWidth:"1.65",strokeLinecap:"round",strokeLinejoin:"round"}),r=s.jsx("path",{d:"M9.25 7.25 12 4.5l2.75 2.75",stroke:"currentColor",strokeWidth:"1.65",strokeLinecap:"round",strokeLinejoin:"round"}),a=s.jsx("circle",{cx:"4",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),i=s.jsx("circle",{cx:"12",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),o=s.jsx("circle",{cx:"20",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),e[0]=n,e[1]=r,e[2]=a,e[3]=i,e[4]=o):(n=e[0],r=e[1],a=e[2],i=e[3],o=e[4]);let c;return e[5]!==t?(c=s.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",...t,children:[n,r,a,i,o]}),e[5]=t,e[6]=c):c=e[6],c}const uf=t=>t.children.length===0?"":t.children.map(e=>`${e.session.id}:${e.children.length}`).join("|"),ja=(t,e)=>{if(!e)return!1;if(t.session.id===e)return!0;for(const n of t.children)if(ja(n,e))return!0;return!1},jd=(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(jd(i,e,n,r))return!0;return!1},KP=(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||uf(t.node)!==uf(e.node)||t.depth!==e.depth||t.groupDirectory!==e.groupDirectory||t.projectId!==e.projectId||t.archivedBucket!==e.archivedBucket)return!1;if(t.currentSessionId!==e.currentSessionId){const m=ja(t.node,t.currentSessionId),u=ja(e.node,e.currentSessionId);if(m||u)return!1}if(t.pinnedSessionIds.has(a)!==e.pinnedSessionIds.has(i))return!1;{const m=t.renderContext??"project",u=e.renderContext??"project",f=t.archivedBucket??!1,b=e.archivedBucket??!1,h=`${m}:${f?"archived":"active"}:${a}`,v=`${u}:${b?"archived":"active"}:${i}`;if(t.expandedParents.has(h)!==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=ja(t.node,t.editingId),u=ja(e.node,e.editingId);if(m||u)return!1}if(t.editTitle!==e.editTitle){const m=ja(t.node,t.editingId),u=ja(e.node,e.editingId);if(m||u)return!1}if(t.copiedSessionId===a!=(e.copiedSessionId===i))return!1;const o=jd(t.node,t.openSidebarMenuKey,t.renderContext??"project",t.archivedBucket??!1),c=jd(e.node,e.openSidebarMenuKey,e.renderContext??"project",e.archivedBucket??!1);if(o!==c)return!1;const d=ws(n.directory??null)??ws(t.groupDirectory??null),p=ws(r.directory??null)??ws(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 HP(t){const{t:e}=dt(),{node:n,depth:r=0,groupDirectory:a,projectId:i,archivedBucket:o=!1,directoryStatus:c,currentSessionId:d,pinnedSessionIds:p,expandedParents:m,hasSessionSearchQuery:u,normalizedSessionSearchQuery:f,notifyOnSubtasks:b,editingId:h,setEditingId:v,editTitle:x,setEditTitle:g,handleSaveEdit:w,handleCancelEdit:y,toggleParent:C,handleSessionSelect:k,handleSessionDoubleClick:j,togglePinnedSession:S,handleShareSession:I,copiedSessionId:M,handleCopyShareUrl:P,handleUnshareSession:A,openSidebarMenuKey:N,setOpenSidebarMenuKey:E,renamingFolderId:T,getFoldersForScope:R,getSessionFolderId:V,removeSessionFromFolder:_,addSessionToFolder:U,createFolderAndStartRename:B,openContextPanelTab:z,handleDeleteSession:K,mobileVariant:F,alwaysShowActions:G,renderSessionNode:Q,secondaryMeta:te,renderContext:Z="project"}=t,fe=!!te?.projectLabel,ue=!!te?.branchLabel,q=Ia(Je=>Je.displayMode)==="minimal",J=l.useMemo(()=>on(),[]),ne=l.useMemo(()=>Pd(),[]),ee=l.useContext(Cy),he=J?"group-hover:opacity-100 group-hover:pointer-events-auto":"group-hover:opacity-100 group-hover:pointer-events-auto group-focus-within:opacity-100 group-focus-within:pointer-events-auto",ke=J?"group-hover:opacity-0":"group-hover:opacity-0 group-focus-within:opacity-0",oe=J,ge=!o&&!F,me=q?J?"group-hover:pr-2":"group-hover:pr-2 group-focus-within:pr-2":J?ge&&oe?"group-hover:pr-18":ge||oe?"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",ye=ge?"pr-13":"pr-7",ie=l.useRef(!1),[ve,X]=l.useState(!1),Se=n.session,pe=Uf(Se.id)??Se,we=ws(Se.directory??null)??ws(a??null),Ie=Iy(we??void 0),Y=zd(),re=ur(Je=>Je.enabled),Pe=ur(l.useCallback(Je=>Je.selectedIds.has(Se.id),[Se.id])),ce=ur(Je=>Je.toggleSelected),Ce=ur(Je=>Je.setRange),Te=l.useCallback(Je=>{const _t=[],Gt=is=>{is.children.forEach(Ue=>{_t.push(Ue.session.id),Gt(Ue)})};return Gt(Je),_t},[]),[$e,De]=l.useState(!1),[de,O]=l.useState(!0),L=`${Z}:${o?"archived":"active"}:${Se.id}`,$=hh(l.useCallback(Je=>!!Je.sessionMemoryState.get(Se.id)?.isZombie,[Se.id])),je=Py(Se.id),ae=Ay(Se.id,we??void 0),le=(we?c.get(we):null)==="missing",Me=d===Se.id,Ge=pe.title||e("sessions.sidebar.session.untitled"),at=n.children.length>0,Ye=p.has(Se.id),Xe=L,ut=u?!0:m.has(Xe),rt=!!pe.parentID,nt=Dy(Se.id)>0&&(!rt||b),Ne=pe.summary,Ke=Hf(Ne),Ve=pe.time?.updated||pe.time?.created||Date.now(),qe=Ty(Ve),lt=Fy(Ve),He=N===L,ze=l.useMemo(()=>sl(pe.title)!==null,[pe.title]),[et,yt]=l.useState(!1),Rt=l.useMemo(()=>Te(n).length,[Te,n]),kt=l.useCallback(async Je=>{const _t=[];let Gt=0;for(const is of Je)try{await Y.ensureSessionRenderable(is.session.id);const Ue=Lu(Ie.getState(),is.session.id).list,gt=is.session.title||e("sessions.sidebar.session.export.untitledSubagent"),Pt=is.session.agent,Mt=await kt(is.children);Gt+=Mt.skipped,_t.push({title:gt,agent:Pt,records:Ue,children:Mt.children})}catch{Gt+=Te(is).length+1}return{children:_t,skipped:Gt}},[Te,Ie,Y,e]),ht=l.useCallback(Je=>{Je<=0||H.warning(Je===1?e("sessions.sidebar.session.export.skippedSubtaskSingle",{count:Je}):e("sessions.sidebar.session.export.skippedSubtaskMany",{count:Je}))},[e]),vt=l.useCallback(async Je=>{if(!we){H.error(e("sessions.sidebar.session.export.nothingToExport"));return}await Y.ensureSessionRenderable(Se.id);const _t=Lu(Ie.getState(),Se.id).list;if(_t.length===0){H.error(e("sessions.sidebar.session.export.nothingToExport"));return}let Gt,is=0;if(Je&&n.children.length>0){const Mt=await kt(n.children);Gt=Mt.children,is=Mt.skipped}const Ue=vP(_t,pe.title??null,Gt),gt=kP(pe.title??null),Pt=await jP(Ue,gt);if(Pt){H.success(e("sessions.sidebar.session.export.success"),{action:{label:e(SP()),onClick:()=>{NP(Pt).then(Mt=>{Mt||H.error(e("sessions.sidebar.session.export.failedRevealPath"))})}}}),ht(is);return}wP(Ue,gt),H.success(e("sessions.sidebar.session.export.success")),ht(is)},[kt,Ie,n.children,pe.title,Se.id,we,ht,Y,e]),ns=l.useCallback(async()=>{if(n.children.length>0){O(!0),De(!0);return}await vt(!1)},[vt,n.children.length]),zt=l.useCallback(()=>{we&&ol("desktop_open_session_mini_chat_window",{sessionId:Se.id,directory:we}).catch(Je=>{console.warn("[session-sidebar] failed to open mini chat window",Je)})},[Se.id,we]);if(h===Se.id)return s.jsx("div",{className:xe("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:Je=>{Je.preventDefault(),w()},children:[s.jsx("input",{value:x,onChange:Je=>g(Je.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",autoFocus:!0,placeholder:e("sessions.sidebar.session.menu.rename"),onKeyDown:Je=>{if(Je.key==="Escape"){Je.stopPropagation(),y();return}(Je.key===" "||Je.key==="Enter")&&Je.stopPropagation()}}),s.jsx("button",{type:"submit","aria-label":e("sessions.sidebar.session.rename.save"),title:e("sessions.sidebar.session.rename.save"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(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"})})]}),q?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:[at?s.jsx("span",{className:"inline-flex items-center justify-center flex-shrink-0",children:ut?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:qe}),Ke?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:["+",Ke.additions]}),s.jsxs("span",{className:"text-status-error/65",children:["/-",Ke.deletions]})]}):null,fe?s.jsx("span",{className:"truncate",children:te?.projectLabel}):null,ue?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:te?.branchLabel})]}):null]})})]})},Se.id);const Kt=je?.type??"idle",mt=Kt==="busy"||Kt==="retry",Et=ae.length,gs=mt||!mt&&nt&&!Me,xs=mt?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")}),bs=gs||Ye?s.jsxs("span",{className:xe("pointer-events-none absolute inline-flex h-3.5 items-center justify-center gap-0.5 transition-opacity",q?"top-1/2 -translate-y-1/2":"top-[14.5px] -translate-y-1/2",gs&&Ye?"left-[-18px] w-6":"left-[-10px] w-3.5",at&&!G?"opacity-100 group-hover:opacity-0 group-focus-within:opacity-0":""),children:[gs?xs:null,Ye?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,Wt=at?s.jsx("span",{role:"button",tabIndex:0,onClick:Je=>{Je.stopPropagation(),C(Xe)},onKeyDown:Je=>{(Je.key==="Enter"||Je.key===" ")&&(Je.preventDefault(),Je.stopPropagation(),C(Xe))},className:xe("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",q?"top-1/2 -translate-y-1/2":"top-[14.5px] -translate-y-1/2",q&&gs&&!G?"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(ut?"sessions.sidebar.session.subsessions.collapse":"sessions.sidebar.session.subsessions.expand"),children:ut?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,We=$?s.jsx(D,{name:"error-warning",className:"h-4 w-4 text-status-warning"}):null,St=Je=>{E(Je?L:null)},qt=Je=>{Je.preventDefault(),Je.stopPropagation(),E(He?null:L)},wt=Je=>{Je.preventDefault(),Je.stopPropagation()},es=Je=>{Je.preventDefault(),Je.stopPropagation()},ds=Je=>{Je.preventDefault(),Je.stopPropagation()},Ms=Je=>{Je.preventDefault(),Je.stopPropagation()},as=Je=>{Je.preventDefault(),Je.stopPropagation(),E(null),K(Se,{archivedBucket:o})},$s=Je=>{Je.preventDefault(),Je.stopPropagation()},Ls=Je=>{Je.preventDefault(),Je.stopPropagation()},ln=Je=>{Je.preventDefault(),Je.stopPropagation(),ee?.vscode?.executeCommand("openchamber.openSessionInEditor",Se.id,Ge)},Xs=Je=>{if(ie.current){ie.current=!1;return}if(re){if(Je?.preventDefault(),Je?.stopPropagation(),Je?.shiftKey){const Gt=(typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[]).map(gt=>gt.getAttribute("data-session-row")).filter(gt=>typeof gt=="string"&&gt.length>0),is=ur.getState().anchorId,Ue=new Map;Ue.set(Se.id,Te(n)),Ce(is,Se.id,Gt,we??null,Ue);return}ce(Se.id,we??null,Te(n));return}k(Se.id,we,le,i)},Vt=Je=>{(Je.button===2||Je.button===0&&Je.ctrlKey&&!re)&&(ie.current=!0)},Ut=Je=>{F&&Je.pointerType==="touch"&&X(!0)},se=Je=>{F&&Je.pointerType==="touch"&&X(!1)},xt=s.jsxs(Ds,{align:"end",className:"min-w-[180px]",onCloseAutoFocus:Je=>{T&&Je.preventDefault()},children:[s.jsxs($t,{onClick:()=>{v(Se.id),g(Ge)},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($t,{onClick:()=>S(Se.id),className:"[&>svg]:mr-1",children:[Ye?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(Ye?"sessions.sidebar.session.menu.unpin":"sessions.sidebar.session.menu.pin")]}),pe.share?s.jsxs(s.Fragment,{children:[s.jsx($t,{onClick:()=>{pe.share?.url&&P(pe.share.url,Se.id)},className:"[&>svg]:mr-1",children:M===Se.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($t,{onClick:()=>A(Se.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($t,{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($t,{onClick:()=>{ns()},className:"[&>svg]:mr-1",children:[s.jsx(D,{name:"download",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.exportMarkdown")]}),ze?s.jsxs($t,{onClick:()=>yt(!0),className:"[&>svg]:mr-1",children:[s.jsx(WP,{className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.runFusion")]}):null,we&&!o?(()=>{const Je=R(we),_t=V(we,Se.id);return s.jsxs(s.Fragment,{children:[s.jsx(Gn,{}),s.jsxs(My,{children:[s.jsxs(Ey,{className:"[&>svg]:mr-1",children:[s.jsx(D,{name:"folder",className:"h-4 w-4"}),e("sessions.sidebar.folders.moveToFolder")]}),s.jsxs(Ry,{className:"min-w-[180px]",children:[Je.length===0?s.jsx($t,{disabled:!0,className:"text-muted-foreground",children:e("sessions.sidebar.folders.none")}):Je.map(Gt=>s.jsxs($t,{onClick:()=>{_t===Gt.id?_(we,Se.id):U(we,Gt.id,Se.id)},children:[s.jsx("span",{className:"flex-1 truncate",children:Gt.name}),_t===Gt.id?s.jsx(D,{name:"check",className:"ml-2 h-3.5 w-3.5 text-primary flex-shrink-0"}):null]},Gt.id)),s.jsx(Gn,{}),s.jsxs($t,{onClick:()=>{const Gt=B(we);Gt&&U(we,Gt.id,Se.id)},children:[s.jsx(D,{name:"add",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.newFolderEllipsis")]}),_t?s.jsxs($t,{onClick:()=>{_(we,Se.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,J?null:s.jsxs($t,{disabled:!we,onClick:()=>{we&&z(we,{mode:"chat",dedupeKey:`session:${Se.id}`,label:Ge})},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")})]}),ne?s.jsxs($t,{disabled:!we,onClick:zt,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(Gn,{}),s.jsxs($t,{className:"text-destructive focus:text-destructive [&>svg]:mr-1",onClick:()=>K(Se,{archivedBucket:o}),children:[s.jsx(D,{name:"delete-bin",className:"mr-1 h-4 w-4"}),e(o?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive")]})]});return s.jsxs(l.Fragment,{children:[s.jsx(BI,{sessionId:Se.id,sessionDirectory:we??null,sessionTitle:Ge,children:s.jsxs("div",{"data-session-row":Se.id,"data-session-scope":we??"","data-session-archived":o?"1":"0",className:xe("group relative my-0.5 flex items-center rounded-sm px-1.5 py-1",le?"opacity-75":"",r>0&&"pl-[20px]",Pe&&"bg-primary/15"),children:[bs,Wt,s.jsx("div",{className:"flex min-w-0 flex-1 items-center",children:q?s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",disabled:le,onPointerDown:Ut,onPointerUp:se,onPointerCancel:se,onMouseDown:Vt,onClick:Je=>Xs(Je),onDoubleClick:Je=>{Je.stopPropagation(),j()},className:xe("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]",ve&&"bg-interactive-hover/70",G?J?me:ye:me),children:s.jsxs("div",{className:xe("flex w-full items-center min-w-0 flex-1 overflow-hidden","gap-1"),children:[s.jsx("div",{className:xe("block min-w-0 flex-1 truncate typography-ui-label font-normal",Me?"text-primary":"text-foreground"),children:Wi(Ge,f)}),G?s.jsx("span",{className:"ml-2 flex-shrink-0 text-[0.72rem] text-muted-foreground/75",children:lt}):null,G?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:xe("whitespace-nowrap text-right text-[0.72rem] text-muted-foreground/75 transition-opacity duration-150",He?"opacity-0":ke),children:lt})}),Et>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:Et})]}):null]})})}),s.jsx(At,{side:"right",sideOffset:8,className:"max-w-xs text-left",children:s.jsxs("div",{className:"flex flex-col gap-1 text-left text-xs",children:[s.jsxs("div",{className:xe("flex items-center gap-3 text-left text-muted-foreground",te?.projectLabel?"justify-between":"justify-start"),children:[te?.projectLabel?s.jsx("div",{className:"min-w-0 truncate",children:te.projectLabel}):null,s.jsx("div",{className:"flex-shrink-0",children:qe})]}),te?.branchLabel||Ke?s.jsxs("div",{className:xe("flex items-center gap-3 text-left text-muted-foreground",te?.branchLabel?"justify-between":"justify-start"),children:[te?.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:te.branchLabel})]})}):null,Ke?s.jsxs("span",{className:"flex flex-shrink-0 items-center gap-0.5",children:[s.jsxs("span",{className:"text-status-success",children:["+",Ke.additions]}),s.jsxs("span",{className:"text-status-error",children:["-",Ke.deletions]})]}):null]}):null]})})]}):s.jsxs("button",{type:"button",disabled:le,onPointerDown:Ut,onPointerUp:se,onPointerCancel:se,onMouseDown:Vt,onClick:Je=>Xs(Je),onDoubleClick:Je=>{Je.stopPropagation(),j()},className:xe("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]",ve&&"bg-interactive-hover/70",G?J?me:ye:me),children:[s.jsxs("div",{className:xe("flex w-full items-center min-w-0 flex-1 overflow-hidden","gap-1"),children:[s.jsx("div",{className:xe("block min-w-0 flex-1 truncate typography-ui-label font-normal",Me?"text-primary":"text-foreground"),children:Wi(Ge,f)}),Et>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:Et})]}):null]}),q?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:qe}),Ke?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:["+",Ke.additions]}),s.jsx("span",{className:"text-muted-foreground/60",children:"/"}),s.jsxs("span",{className:"text-status-error/65",children:["-",Ke.deletions]})]}):null,fe?s.jsx("span",{className:"truncate",children:te?.projectLabel}):null,ue?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:te?.branchLabel})]}):null]})})]})}),We&&!F?s.jsx("div",{className:xe("absolute top-1/2 -translate-y-1/2 z-10",q?"right-0":"right-[30px]"),children:We}):null,s.jsxs("div",{className:xe("absolute right-0 top-1/2 z-10 flex -translate-y-1/2 items-center gap-0.5 transition-opacity",He||G&&!J?"opacity-100":xe("opacity-0",he)),children:[ge?s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",className:xe("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",q&&!G?"h-4 w-4":"h-6 w-6"),"aria-label":e("sessions.sidebar.bulkActions.archive"),onPointerDown:ds,onMouseDown:Ms,onClick:as,onKeyDown:Je=>Je.stopPropagation(),children:s.jsx(D,{name:"archive",className:xe(q&&!G?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),s.jsx(At,{side:"left",sideOffset:8,children:e("sessions.sidebar.bulkActions.archive")})]}):null,oe?s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx("button",{type:"button",className:xe("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",q&&!G?"h-4 w-4":"h-6 w-6"),"aria-label":e("sessions.sidebar.session.actions.openInEditor"),onPointerDown:$s,onMouseDown:Ls,onClick:ln,onKeyDown:Je=>Je.stopPropagation(),children:s.jsx(D,{name:"external-link",className:xe(q&&!G?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),s.jsx(At,{side:"left",sideOffset:8,children:e("sessions.sidebar.session.actions.openInEditor")})]}):null,s.jsxs(Ts,{open:He,onOpenChange:St,children:[s.jsx(As,{asChild:!0,children:s.jsx("button",{type:"button",className:xe("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",q&&!G?He?"h-4 w-4 opacity-100":xe("h-4 w-4 opacity-0",he):"h-6 w-6 opacity-100"),"aria-label":e("sessions.sidebar.session.menu.label"),onPointerDown:wt,onMouseDown:es,onClick:qt,onKeyDown:Je=>Je.stopPropagation(),children:s.jsx(D,{name:"more-2",className:xe(q&&!G?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),xt]})]})]})}),at&&ut?n.children.map(Je=>Q(Je,r+1,we??a,i,o,void 0,Z)):null,s.jsx(ps,{open:$e,onOpenChange:De,children:s.jsxs(ms,{showCloseButton:!1,className:"max-w-sm gap-5",children:[s.jsxs(ys,{children:[s.jsx(hs,{children:e("sessions.sidebar.session.export.dialog.title")}),s.jsx(Ss,{children:Rt===1?e("sessions.sidebar.session.export.dialog.descriptionSingle",{count:Rt}):e("sessions.sidebar.session.export.dialog.descriptionMany",{count:Rt})})]}),s.jsxs("label",{className:"flex items-center gap-2 typography-ui-label cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:de,onChange:Je=>O(Je.target.checked),className:"h-4 w-4 rounded border-border accent-primary"}),e("sessions.sidebar.session.export.dialog.includeSubtasks")]}),s.jsxs(Vs,{children:[s.jsx(be,{type:"button",onClick:()=>De(!1),variant:"outline",size:"sm",children:e("sessions.sidebar.dialogs.cancel")}),s.jsx(be,{type:"button",onClick:()=>{De(!1),vt(de)},size:"sm",children:e("sessions.sidebar.session.export.dialog.confirm")})]})]})}),ze?s.jsx(UP,{session:pe,open:et,onOpenChange:yt}):null]},Se.id)}const GP=l.memo(HP,KP);function qP(t){const e=st.c(71),{t:n}=dt(),{value:r,setValue:a,showDeletionDialog:i,setShowDeletionDialog:o,onConfirm:c}=t;let d,p,m,u,f,b,h,v,x,g;if(e[0]!==a||e[1]!==n||e[2]!==r){const B=n("sessions.sidebar.session.untitled");u=ps,x=!!r,e[13]!==a?(g=K=>{K||a(null)},e[13]=a,e[14]=g):g=e[14],m=ms,h=!1,v="max-w-sm gap-5",p=ys;let z;e[15]!==n||e[16]!==r?.archivedBucket?(z=r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.title"):n("sessions.sidebar.dialogs.archiveSession.title"),e[15]=n,e[16]=r?.archivedBucket,e[17]=z):z=e[17],e[18]!==z?(b=s.jsx(hs,{children:z}),e[18]=z,e[19]=b):b=e[19],d=Ss,f=r&&r.descendantCount>0?r.archivedBucket?r.descendantCount===1?n("sessions.sidebar.dialogs.deleteSession.withOneSubtask",{sessionTitle:r.session.title||B,count:r.descendantCount}):n("sessions.sidebar.dialogs.deleteSession.withManySubtasks",{sessionTitle:r.session.title||B,count:r.descendantCount}):r.descendantCount===1?n("sessions.sidebar.dialogs.archiveSession.withOneSubtask",{sessionTitle:r.session.title||B,count:r.descendantCount}):n("sessions.sidebar.dialogs.archiveSession.withManySubtasks",{sessionTitle:r.session.title||B,count:r.descendantCount}):r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.single",{sessionTitle:r?.session.title||B}):n("sessions.sidebar.dialogs.archiveSession.single",{sessionTitle:r?.session.title||B}),e[0]=a,e[1]=n,e[2]=r,e[3]=d,e[4]=p,e[5]=m,e[6]=u,e[7]=f,e[8]=b,e[9]=h,e[10]=v,e[11]=x,e[12]=g}else d=e[3],p=e[4],m=e[5],u=e[6],f=e[7],b=e[8],h=e[9],v=e[10],x=e[11],g=e[12];let w;e[20]!==d||e[21]!==f?(w=s.jsx(d,{children:f}),e[20]=d,e[21]=f,e[22]=w):w=e[22];let y;e[23]!==p||e[24]!==b||e[25]!==w?(y=s.jsxs(p,{children:[b,w]}),e[23]=p,e[24]=b,e[25]=w,e[26]=y):y=e[26];let C;e[27]!==o||e[28]!==i?(C=()=>o(!i),e[27]=o,e[28]=i,e[29]=C):C=e[29];const k=!i;let j;e[30]!==i?(j=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]=j):j=e[31];let S;e[32]!==n?(S=n("sessions.sidebar.dialogs.neverAsk"),e[32]=n,e[33]=S):S=e[33];let I;e[34]!==j||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:[j,S]}),e[34]=j,e[35]=S,e[36]=C,e[37]=k,e[38]=I):I=e[38];let M;e[39]!==a?(M=()=>a(null),e[39]=a,e[40]=M):M=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]!==M||e[44]!==P?(A=s.jsx("button",{type:"button",onClick:M,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]=M,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 T;e[51]!==N||e[52]!==E?(T=s.jsx("button",{type:"button",onClick:N,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:E}),e[51]=N,e[52]=E,e[53]=T):T=e[53];let R;e[54]!==A||e[55]!==T?(R=s.jsxs("div",{className:"flex items-center gap-2",children:[A,T]}),e[54]=A,e[55]=T,e[56]=R):R=e[56];let V;e[57]!==I||e[58]!==R?(V=s.jsxs(Vs,{className:"w-full sm:items-center sm:justify-between",children:[I,R]}),e[57]=I,e[58]=R,e[59]=V):V=e[59];let _;e[60]!==m||e[61]!==h||e[62]!==V||e[63]!==v||e[64]!==y?(_=s.jsxs(m,{showCloseButton:h,className:v,children:[y,V]}),e[60]=m,e[61]=h,e[62]=V,e[63]=v,e[64]=y,e[65]=_):_=e[65];let U;return e[66]!==u||e[67]!==_||e[68]!==x||e[69]!==g?(U=s.jsx(u,{open:x,onOpenChange:g,children:_}),e[66]=u,e[67]=_,e[68]=x,e[69]=g,e[70]=U):U=e[70],U}function JP(t){const e=st.c(57),{t:n}=dt(),{value:r,setValue:a,showDeletionDialog:i,setShowDeletionDialog:o,onConfirm:c}=t,d=r?.archivedBucket===!0,p=r?.sessionCount??0;let m;e[0]!==d||e[1]!==p||e[2]!==n?(m=n(d?p===1?"sessions.sidebar.dialogs.deleteSession.title":"sessions.sidebar.dialogs.deleteSessions.title":p===1?"sessions.sidebar.dialogs.archiveSession.title":"sessions.sidebar.dialogs.archiveSessions.title"),e[0]=d,e[1]=p,e[2]=n,e[3]=m):m=e[3];const u=m;let f;e[4]!==d||e[5]!==p||e[6]!==n?(f=d?p===1?n("sessions.sidebar.dialogs.deleteSessions.singleDescription",{count:p}):n("sessions.sidebar.dialogs.deleteSessions.pluralDescription",{count:p}):p===1?n("sessions.sidebar.dialogs.archiveSessions.singleDescription",{count:p}):n("sessions.sidebar.dialogs.archiveSessions.pluralDescription",{count:p}),e[4]=d,e[5]=p,e[6]=n,e[7]=f):f=e[7];const b=f,h=!!r;let v;e[8]!==a?(v=U=>{U||a(null)},e[8]=a,e[9]=v):v=e[9];let x;e[10]!==u?(x=s.jsx(hs,{children:u}),e[10]=u,e[11]=x):x=e[11];let g;e[12]!==b?(g=s.jsx(Ss,{children:b}),e[12]=b,e[13]=g):g=e[13];let w;e[14]!==x||e[15]!==g?(w=s.jsxs(ys,{children:[x,g]}),e[14]=x,e[15]=g,e[16]=w):w=e[16];let y;e[17]!==o||e[18]!==i?(y=()=>o(!i),e[17]=o,e[18]=i,e[19]=y):y=e[19];const 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 j;e[22]!==n?(j=n("sessions.sidebar.dialogs.neverAsk"),e[22]=n,e[23]=j):j=e[23];let S;e[24]!==j||e[25]!==y||e[26]!==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,j]}),e[24]=j,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 M;e[31]!==n?(M=n("sessions.sidebar.dialogs.cancel"),e[31]=n,e[32]=M):M=e[32];let P;e[33]!==I||e[34]!==M?(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:M}),e[33]=I,e[34]=M,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 T;e[44]!==P||e[45]!==E?(T=s.jsxs("div",{className:"flex items-center gap-2",children:[P,E]}),e[44]=P,e[45]=E,e[46]=T):T=e[46];let R;e[47]!==S||e[48]!==T?(R=s.jsxs(Vs,{className:"w-full sm:items-center sm:justify-between",children:[S,T]}),e[47]=S,e[48]=T,e[49]=R):R=e[49];let V;e[50]!==R||e[51]!==w?(V=s.jsxs(ms,{showCloseButton:!1,className:"max-w-sm gap-5",children:[w,R]}),e[50]=R,e[51]=w,e[52]=V):V=e[52];let _;return e[53]!==h||e[54]!==V||e[55]!==v?(_=s.jsx(ps,{open:h,onOpenChange:v,children:V}),e[53]=h,e[54]=V,e[55]=v,e[56]=_):_=e[56],_}function YP(t){const e=st.c(36),{t:n}=dt(),{value:r,setValue:a,onConfirm:i}=t,o=!!r;let c;e[0]!==a?(c=k=>{k||a(null)},e[0]=a,e[1]=c):c=e[1];let d;e[2]!==n?(d=n("sessions.sidebar.dialogs.deleteFolder.title"),e[2]=n,e[3]=d):d=e[3];let p;e[4]!==d?(p=s.jsx(hs,{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(Ss,{children:m}),e[9]=m,e[10]=u):u=e[10];let f;e[11]!==p||e[12]!==u?(f=s.jsxs(ys,{children:[p,u]}),e[11]=p,e[12]=u,e[13]=f):f=e[13];let b;e[14]!==a?(b=()=>a(null),e[14]=a,e[15]=b):b=e[15];let h;e[16]!==n?(h=n("sessions.sidebar.dialogs.cancel"),e[16]=n,e[17]=h):h=e[17];let v;e[18]!==b||e[19]!==h?(v=s.jsx("button",{type:"button",onClick:b,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:h}),e[18]=b,e[19]=h,e[20]=v):v=e[20];let x;e[21]!==n?(x=n("sessions.sidebar.bulkActions.delete"),e[21]=n,e[22]=x):x=e[22];let g;e[23]!==i||e[24]!==x?(g=s.jsx("button",{type:"button",onClick:i,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:x}),e[23]=i,e[24]=x,e[25]=g):g=e[25];let w;e[26]!==g||e[27]!==v?(w=s.jsxs(Vs,{children:[v,g]}),e[26]=g,e[27]=v,e[28]=w):w=e[28];let y;e[29]!==w||e[30]!==f?(y=s.jsxs(ms,{showCloseButton:!1,className:"max-w-sm gap-5",children:[f,w]}),e[29]=w,e[30]=f,e[31]=y):y=e[31];let C;return e[32]!==o||e[33]!==c||e[34]!==y?(C=s.jsx(ps,{open:o,onOpenChange:c,children:y}),e[32]=o,e[33]=c,e[34]=y,e[35]=C):C=e[35],C}const QP=t=>{const e=st.c(46),{selectedCount:n,scopeKey:r,scopeFolders:a,archivedBucket:i,onMoveToFolder:o,onCreateFolderAndMove:c,onRemoveFromFolder:d,canRemoveFromFolder:p,onDelete:m,onDone:u}=t,{t:f}=dt(),b=!!r&&!i;let h;e[0]!==i||e[1]!==f?(h=f(i?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[0]=i,e[1]=f,e[2]=h):h=e[2];const v=h;let x;e[3]!==n||e[4]!==f?(x=f("sessions.sidebar.bulkActions.selectedCount",{count:n}),e[3]=n,e[4]=f,e[5]=x):x=e[5];let g;e[6]!==x?(g=s.jsx("span",{className:"typography-ui-label text-muted-foreground whitespace-nowrap",children:x}),e[6]=x,e[7]=g):g=e[7];let w;e[8]!==b||e[9]!==p||e[10]!==c||e[11]!==o||e[12]!==d||e[13]!==a||e[14]!==f?(w=b?s.jsxs(Ts,{children:[s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(As,{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(At,{side:"top",sideOffset:4,children:s.jsx("p",{children:f("sessions.sidebar.bulkActions.moveToFolder")})})]}),s.jsxs(Ds,{align:"end",className:"min-w-[180px]",children:[a.length===0?s.jsx($t,{disabled:!0,className:"text-muted-foreground",children:f("sessions.sidebar.folders.none")}):a.map(V=>s.jsx($t,{onClick:()=>o(V.id),children:s.jsx("span",{className:"flex-1 truncate",children:V.name})},V.id)),s.jsx(Gn,{}),s.jsxs($t,{onClick:c,children:[s.jsx(D,{name:"add",className:"mr-1 h-4 w-4"}),f("sessions.sidebar.folders.newFolderEllipsis")]}),p?s.jsxs($t,{onClick:d,className:"text-destructive focus:text-destructive",children:[s.jsx(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]=o,e[12]=d,e[13]=a,e[14]=f,e[15]=w):w=e[15];let y;e[16]===Symbol.for("react.memo_cache_sentinel")?(y=xe("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(It,{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 j;e[21]!==v?(j=s.jsx(At,{side:"top",sideOffset:4,children:s.jsx("p",{children:v})}),e[21]=v,e[22]=j):j=e[22];let S;e[23]!==k||e[24]!==j?(S=s.jsxs(Ct,{children:[k,j]}),e[23]=k,e[24]=j,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 M;e[28]===Symbol.for("react.memo_cache_sentinel")?(M=s.jsx(D,{name:"close",className:"h-4 w-4"}),e[28]=M):M=e[28];let P;e[29]!==u||e[30]!==I?(P=s.jsx(It,{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:M})}),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(At,{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(Ct,{children:[P,N]}),e[36]=P,e[37]=N,e[38]=E):E=e[38];let T;e[39]!==E||e[40]!==w||e[41]!==S?(T=s.jsxs("div",{className:"ml-auto flex items-center gap-0.5",children:[w,S,E]}),e[39]=E,e[40]=w,e[41]=S,e[42]=T):T=e[42];let R;return e[43]!==T||e[44]!==g?(R=s.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-t border-border px-2.5 py-1.5",children:[g,T]}),e[43]=T,e[44]=g,e[45]=R):R=e[45],R},_g="oc.sessions.activeNow",XP=2160*60*1e3,Bg=t=>!!t.parentID,su=t=>!!t.time?.archived,Nd=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},ZP=t=>{try{const e=t.getItem(_g);if(!e)return[];const n=JSON.parse(e);if(!Array.isArray(n))return[];const r=new Set,a=[];return n.forEach(i=>{const o=typeof i=="string"?i:i&&typeof i=="object"&&"sessionId"in i&&typeof i.sessionId=="string"?i.sessionId:null;!o||r.has(o)||(r.add(o),a.push({sessionId:o}))}),a}catch{return[]}},Rc=(t,e)=>{try{t.setItem(_g,JSON.stringify(e))}catch{}},eA=(t,e,n=Date.now())=>{const r=n-XP;return t.filter(a=>{const i=e.get(a.sessionId);return i?su(i)?!1:Nd(i)>=r:!0})},tA=(t,e)=>!e||t.some(n=>n.sessionId===e)?t:[{sessionId:e},...t],zg=t=>[...t].sort((e,n)=>Nd(n)-Nd(e)),sA=(t,e)=>{const n=t.map(r=>e.get(r.sessionId)??null).filter(r=>!!r).filter(r=>!su(r)).filter(r=>!Bg(r));return zg(n)},nA=(t,e)=>{const n=t.filter(r=>{if(su(r)||Bg(r))return!1;const a=e[r.id];return a?.type==="busy"||a?.type==="retry"});return zg(n)},$o=vr(),Fc=Zn((t,e)=>({entries:ZP($o),setEntries:n=>{n!==e().entries&&(t({entries:n}),Rc($o,n))},addSession:n=>{const r=tA(e().entries,n);r!==e().entries&&(t({entries:r}),Rc($o,r))},prune:n=>{const r=e().entries,a=eA(r,n);a.length===r.length&&a.every((i,o)=>i.sessionId===r[o]?.sessionId)||(t({entries:a}),Rc($o,a))}})),_o="oc.sessions.projectCollapse",mf="oc.sessions.groupOrder",pf="oc.sessions.groupCollapse",ff="oc.sessions.activeSessionByProject",Oc="oc.sessions.expandedParents.v2",rA="oc.sessions.expandedParents",aA="oc.sessions.pinned",iA=(t,e)=>{const n=new Set;for(const r of t){const a=ws(r.path)?.toLowerCase();a&&n.add(a)}for(const r of e.values())for(const a of r){const i=ws(a.path)?.toLowerCase();i&&n.add(i)}return n},oA=(t,e)=>{if(t.time?.archived)return!0;const n=ws(Ui(t))?.toLowerCase();return!n||e.size===0?!0:e.has(n)},lA=5*6e4,hf=({mobileVariant:t=!1,onSessionSelected:e,allowReselect:n=!1,hideDirectoryControls:r=!1,showOnlyMainWorkspace:a=!1})=>{const{t:i}=dt(),[o,c]=l.useState(!1),[d,p]=l.useState(""),m=l.useRef(null),u=l.useRef(null),f=l.useRef(new Set),[b,h]=l.useState(null),[v,x]=l.useState(""),[g,w]=l.useState(null),[y,C]=l.useState(new Set),[k]=l.useState(()=>new Map),j=l.useMemo(()=>vr(),[]),S=Fc(Fe=>Fe.entries),I=Fc(Fe=>Fe.addSession),M=Fc(Fe=>Fe.prune),[P,A]=l.useState(new Set),[N,E]=l.useState(new Map),[T,R]=l.useState(new Set),[V,_]=l.useState(!1),[U,B]=l.useState(!1),[z,K]=l.useState(null),[F,G]=l.useState(null),[Q,te]=l.useState(""),[Z,fe]=l.useState(null),[ue,W]=l.useState(null),[q,J]=l.useState(null),ne=tc(Fe=>Fe.ids),ee=tc(Fe=>Fe.setIds),he=tc(Fe=>Fe.toggle),[ke,oe]=l.useState(()=>{try{const Fe=vr().getItem(pf);if(!Fe)return new Set;const Nt=JSON.parse(Fe);return new Set(Array.isArray(Nt)?Nt.filter(pt=>typeof pt=="string"):[])}catch{return new Set}}),[ge,me]=l.useState(()=>{try{const Fe=vr().getItem(mf);if(!Fe)return new Map;const Nt=JSON.parse(Fe),pt=new Map;return Object.entries(Nt).forEach(([Jt,js])=>{Array.isArray(js)&&pt.set(Jt,js.filter(en=>typeof en=="string"))}),pt}catch{return new Map}}),[ye,ie]=l.useState(()=>{try{const Fe=vr().getItem(ff);if(!Fe)return new Map;const Nt=JSON.parse(Fe),pt=new Map;return Object.entries(Nt).forEach(([Jt,js])=>{typeof js=="string"&&js.length>0&&pt.set(Jt,js)}),pt}catch{return new Map}}),[ve,X]=l.useState(new Map),Se=l.useRef(new Map),Ae=l.useRef(0),pe=zs(Fe=>Fe.homeDirectory),we=zs(Fe=>Fe.currentDirectory),Ie=zs(Fe=>Fe.setDirectory),Y=Ps(Fe=>Fe.projects),re=Ps(Fe=>Fe.activeProjectId),Pe=Ps(Fe=>Fe.removeProject),ce=Ps(Fe=>Fe.setActiveProjectIdOnly),Ce=Ps(Fe=>Fe.updateProjectMeta),Te=Ps(Fe=>Fe.reorderProjects),$e=Re(Fe=>Fe.setActiveMainTab),De=Re(Fe=>Fe.openContextPanelTab),de=Re(Fe=>Fe.setSettingsDialogOpen),O=Re(Fe=>Fe.toggleHelpDialog),L=Re(Fe=>Fe.setAboutDialogOpen),$=Re(Fe=>Fe.setSessionSwitcherOpen),je=Re(Fe=>Fe.setScheduledTasksDialogOpen),ae=Re(Fe=>Fe.openMultiRunLauncher),_e=Re(Fe=>Fe.notifyOnSubtasks),le=Re(Fe=>Fe.showDeletionDialog),Me=Re(Fe=>Fe.setShowDeletionDialog),Ge=Ml(d,120),at=l.useMemo(()=>Ge.trim().toLowerCase(),[Ge]),Ye=at.length>0,Xe=Un(Fe=>Fe.collapsedFolderIds),ut=Un(Fe=>Fe.foldersMap),rt=Un(Fe=>Fe.getFoldersForScope),it=Un(Fe=>Fe.createFolder),nt=Un(Fe=>Fe.renameFolder),Ne=Un(Fe=>Fe.deleteFolder),Ke=Un(Fe=>Fe.addSessionToFolder),Ve=Un(Fe=>Fe.addSessionsToFolder),qe=Un(Fe=>Fe.removeSessionFromFolder),lt=Un(Fe=>Fe.removeSessionsFromFolders),He=Un(Fe=>Fe.toggleFolderCollapse),ze=Un(Fe=>Fe.cleanupSessions),et=Un(Fe=>Fe.getSessionFolderId);aI({isSessionSearchOpen:o,setIsSessionSearchOpen:c,sessionSearchInputRef:u,sessionSearchContainerRef:m});const yt=oh(),Rt=zd(),kt=Id(),ht=Oy(),vt=Pa(Fe=>Fe.hasLoaded),ns=Pa(Fe=>Fe.activeSessions),zt=Pa(Fe=>Fe.archivedSessions),Kt=Lt(Fe=>Fe.currentSessionId),mt=Lt(Fe=>!!Fe.newSessionDraft?.open),Et=Lt(Fe=>Fe.setCurrentSession),rs=Lt(Fe=>Fe.updateSessionTitle),gs=Lt(Fe=>Fe.shareSession),xs=Lt(Fe=>Fe.unshareSession),bs=Lt(Fe=>Fe.worktreeMetadata),Wt=Lt(Fe=>Fe.availableWorktreesByProject),We=Lt(Fe=>Fe.openNewSessionDraft),St=Ta(Jn(Fe=>({checkForUpdates:Fe.checkForUpdates,available:Fe.available,runtimeType:Fe.runtimeType,info:Fe.info,downloading:Fe.downloading,downloaded:Fe.downloaded,progress:Fe.progress,error:Fe.error,downloadUpdate:Fe.downloadUpdate,restartToUpdate:Fe.restartToUpdate}))),qt=l.useMemo(()=>iA(Y,Wt),[Wt,Y]),wt=l.useMemo(()=>{const Fe=new Map(kt.map(Jt=>[Jt.id,Jt])),Nt=ns.map(Jt=>Fe.get(Jt.id)??Jt),pt=new Set(Nt.map(Jt=>Jt.id));return kt.forEach(Jt=>{pt.has(Jt.id)||Nt.push(Jt)}),Nt.filter(Jt=>oA(Jt,qt))},[ns,qt,kt]),es=l.useMemo(()=>kt.map(Fe=>{const Nt=ws(Fe.directory??null)??"";return`${Fe.id}:${Fe.title??""}:${Fe.time?.archived?1:0}:${Nt}`}).join("|"),[kt]),ds=l.useRef(kt);l.useEffect(()=>{ds.current=kt},[es,kt]),l.useEffect(()=>{let Fe=!1;const Nt=async()=>{const pt=Ps.getState().projects;if(pt.length===0)return;const Jt=new Map,js=[];await Promise.all(pt.map(async en=>{const mn=ws(en.path);if(mn)try{if(!(tn.getState().directories.get(mn)?.isGitRepo??await Sr(()=>import("./modelPrefsAutoSave-D4IOtl1d.js").then(Cn=>Cn.f1),__vite__mapDeps([2,0,1,3,4])).then(Cn=>Cn.checkIsGitRepository(mn))))return;const kn=await Hc({id:en.id,path:mn});if(Fe||kn.length===0)return;Jt.set(mn,kn),js.push(...kn)}catch{}})),!Fe&&Lt.setState({availableWorktrees:js,availableWorktreesByProject:Jt})};return Gc(ds.current),Nt(),()=>{Fe=!0}},[we,es,Y]),l.useEffect(()=>{let Fe=null;const Nt=Tg(pt=>{pt.type==="scheduled-task-ran"&&(Fe&&clearTimeout(Fe),Fe=setTimeout(()=>{Gc(ds.current)},500))});return()=>{Fe&&clearTimeout(Fe),Nt()}},[]);const Ms=l.useMemo(()=>vn(),[]),as=l.useMemo(()=>on(),[]),{isTablet:$s}=nn(),Ls=t||$s,{buildGroupSearchText:ln,filterSessionNodesForSearch:Xs,buildGroupedSessions:Vt}=rI({homeDirectory:pe,worktreeMetadata:bs,pinnedSessionIds:ne,gitBranches:yt,isVSCode:as}),{scheduleCollapsedProjectsPersist:Ut}=mI({isVSCode:as,hasLoadedGlobalSessions:vt,safeStorage:j,keys:{sessionExpanded:Oc,sessionExpandedLegacy:rA,projectCollapse:_o,sessionPinned:aA,groupOrder:mf,projectActiveSession:ff,groupCollapse:pf},sessions:wt,setPinnedSessionIds:ee,groupOrderByProject:ge,activeSessionByProject:ye,collapsedGroups:ke,setExpandedParents:C,setCollapsedProjects:A}),se=l.useMemo(()=>[...wt].sort((Fe,Nt)=>ri(Fe,Nt,ne)),[wt,ne]),xt=l.useMemo(()=>new Map(se.map((Fe,Nt)=>[Fe.id,Nt])),[se]),Je=l.useMemo(()=>{const Fe=new Map;return se.forEach(Nt=>{const pt=Nt.parentID;if(!pt)return;const Jt=Fe.get(pt)??[];Jt.push(Nt),Fe.set(pt,Jt)}),Fe.forEach(Nt=>Nt.sort((pt,Jt)=>ri(pt,Jt,ne))),Fe},[se,ne]),_t=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")})]}),Gt=l.useMemo(()=>Y.find(Fe=>Fe.id===g)??null,[Y,g]),is=l.useCallback(Fe=>{g&&(Ce(g,Fe),w(null))},[g,Ce]),Ue=l.useCallback(()=>{_(!0)},[]),gt=l.useCallback(()=>{const Fe=Ta.getState();if(Fe.available&&Fe.info){B(!0);return}St.checkForUpdates().then(()=>{const{available:Nt,error:pt}=Ta.getState();if(pt){H.error(i("sessions.sidebar.updateCheck.errorTitle"),{description:pt});return}if(!Nt){H.success(i("sessions.sidebar.updateCheck.latestVersion"));return}B(!0)})},[i,St]),Pt=l.useCallback(()=>{t&&$(!1),de(!0)},[t,$,de]),Mt=St.available&&(St.runtimeType==="desktop"||St.runtimeType==="web"),ts=Lt(Fe=>Fe.deleteSession),Ot=Lt(Fe=>Fe.deleteSessions),ks=Lt(Fe=>Fe.archiveSession),Zs=Lt(Fe=>Fe.archiveSessions),{copiedSessionId:Hs,handleSessionSelect:ss,handleSessionDoubleClick:Es,handleSaveEdit:Pn,handleCancelEdit:an,handleShareSession:Ir,handleCopyShareUrl:er,handleUnshareSession:Js,handleDeleteSession:An,confirmDeleteSession:tr}=iI({activeProjectId:re,currentDirectory:we,currentSessionId:Kt,mobileVariant:t,allowReselect:n,onSessionSelected:e,isSessionSearchOpen:o,sessionSearchQuery:d,setSessionSearchQuery:p,setIsSessionSearchOpen:c,setActiveProjectIdOnly:ce,setDirectory:Ie,setActiveMainTab:$e,setSessionSwitcherOpen:$,setCurrentSession:Et,updateSessionTitle:rs,shareSession:gs,unshareSession:xs,deleteSession:ts,deleteSessions:Ot,archiveSession:ks,archiveSessions:Zs,childrenMap:Je,showDeletionDialog:le,setDeleteSessionConfirm:fe,deleteSessionConfirm:Z,setEditingId:h,setEditTitle:x,editingId:b,editTitle:v}),Be=l.useCallback(()=>{if(!ue)return;const{scopeKey:Fe,folderId:Nt}=ue;W(null),Ne(Fe,Nt)},[ue,Ne]),Dt=l.useCallback(()=>{Nr.requestDirectoryDialog()},[]);l.useEffect(()=>{if(!Kt)return;const Nt=wt.find(Jt=>Jt.id===Kt)?.parentID;if(!Nt)return;const pt=[`project:active:${Nt}`,`project:archived:${Nt}`,`recent:active:${Nt}`,`recent:archived:${Nt}`];C(Jt=>{if(pt.every(en=>Jt.has(en)))return Jt;const js=new Set(Jt);pt.forEach(en=>js.add(en));try{j.setItem(Oc,JSON.stringify(Array.from(js)))}catch{}return js})},[Kt,wt,j]);const Yt=l.useCallback(Fe=>{C(Nt=>{const pt=new Set(Nt);pt.has(Fe)?pt.delete(Fe):pt.add(Fe);try{j.setItem(Oc,JSON.stringify(Array.from(pt)))}catch{}return pt})},[j]),Qt=l.useCallback((Fe,Nt)=>{if(!Fe)return null;Nt&&Xe.has(Nt)&&He(Nt);const pt=it(Fe,i("sessions.sidebar.folder.newFolderName"),Nt);return G(pt.id),te(pt.name),pt},[Xe,He,it,i]),vs=l.useCallback(Fe=>{R(Nt=>{const pt=new Set(Nt);return pt.has(Fe)?pt.delete(Fe):pt.add(Fe),pt})},[]),Rs=l.useCallback(()=>{Ae.current=Date.now()+150,A(()=>{const Fe=new Set(Y.map(Nt=>Nt.id));try{j.setItem(_o,JSON.stringify(Array.from(Fe)))}catch{}return as||Ut(Fe),Fe})},[Y,as,j,Ut]),Cs=l.useCallback(()=>{Ae.current=Date.now()+150,A(()=>{const Fe=new Set;try{j.setItem(_o,JSON.stringify([]))}catch{}return as||Ut(Fe),Fe})},[as,j,Ut]),_s=l.useCallback(Fe=>{Ae.current=Date.now()+150,A(Nt=>{const pt=new Set(Nt);pt.has(Fe)?pt.delete(Fe):pt.add(Fe);try{j.setItem(_o,JSON.stringify(Array.from(pt)))}catch{}return as||Ut(pt),pt})},[as,j,Ut]),Qs=l.useMemo(()=>Y.map(Fe=>({...Fe,normalizedPath:ws(Fe.path)})).filter(Fe=>!!Fe.normalizedPath),[Y]),Fn=l.useMemo(()=>Qs.map(Fe=>Fe.normalizedPath),[Qs]),{github:gr}=Rn(),zr=Bn(Fe=>Fe.status),Pr=Bn(Fe=>Fe.hasChecked),Nn=Ly(Fn),wn=mr(Fe=>Fe.ensureEntry),zn=mr(Fe=>Fe.setParams),sr=mr(Fe=>Fe.refreshTargets);fI({normalizedProjects:Qs,gitRepoStatus:Nn,setProjectRepoStatus:E,setProjectRootBranches:X});const gn=Lt(Fe=>Fe.isLoading);NI({isSessionsLoading:gn,sessions:wt,archivedSessions:zt,normalizedProjects:Qs,isVSCode:as,availableWorktreesByProject:Wt,cleanupSessions:ze});const{getSessionsForProject:nr,getArchivedSessionsForProject:Vr}=bI({isVSCode:as,sessions:wt,archivedSessions:zt,availableWorktreesByProject:Wt});Y6({normalizedProjects:Qs,sessions:wt,archivedSessions:zt,availableWorktreesByProject:Wt,isVSCode:as,isSessionsLoading:gn,foldersMap:ut,createFolder:it,addSessionToFolder:Ke,cleanupSessions:ze});const Ar=l.useRef(!1);re&&N.has(re)&&(Ar.current=!!N.get(re));const{projectSections:rr,groupSearchDataByGroup:ua,sectionsForRender:Sn,searchMatchCount:ma}=Z6({normalizedProjects:Qs,getSessionsForProject:nr,getArchivedSessionsForProject:Vr,availableWorktreesByProject:Wt,projectRepoStatus:N,projectRootBranches:ve,lastRepoStatus:Ar.current,buildGroupedSessions:Vt,hasSessionSearchQuery:Ye,normalizedSessionSearchQuery:at,filterSessionNodesForSearch:Xs,buildGroupSearchText:ln,foldersMap:ut}),ar=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:pa}=tI({projectSections:rr,activeProjectId:re,activeSessionByProject:ye,setActiveSessionByProject:ie,currentSessionId:Kt,handleSessionSelect:ss,newSessionDraftOpen:mt,mobileVariant:t,openNewSessionDraft:We,setActiveMainTab:$e,setSessionSwitcherOpen:$,sessions:wt,worktreeMetadata:bs}),{getOrderedGroups:Ur}=sI(ge),ir=l.useRef(!1);l.useEffect(()=>{if(ir.current||rr.length===0)return;const Fe=rr.flatMap(Nt=>Nt.groups.filter(pt=>pt.isArchivedBucket).map(pt=>`${Nt.project.id}:${pt.id}`));Fe.length>0&&oe(Nt=>new Set([...Nt,...Fe])),ir.current=!0},[rr]);const xn=l.useMemo(()=>{const Fe=new Map,Nt=new Map;return rr.forEach(pt=>{const Jt=fh(pt.project.label?.trim()||Oa(pt.project.normalizedPath,pe)||pt.project.normalizedPath);pt.groups.forEach(js=>{const en=js.branch&&js.branch!=="HEAD"&&js.branch!==Jt?js.branch:null,mn={projectLabel:Jt,branchLabel:en},br=Qn=>{Qn.forEach(kn=>{const Cn=pt.project.normalizedPath.length,ki=Nt.get(kn.session.id)??-1;Cn<ki||(Fe.set(kn.session.id,{node:kn,projectId:pt.project.id,groupDirectory:js.directory,secondaryMeta:mn}),Nt.set(kn.session.id,Cn),kn.children.length>0&&br(kn.children))})};br(js.sessions)})}),Fe},[rr,pe]),cn=Ia(Fe=>Fe.showRecentSection),_r=l.useMemo(()=>cn?sA(S,new Map(wt.map(Fe=>[Fe.id,Fe]))).sort((Fe,Nt)=>ri(Fe,Nt,ne)):[],[S,ne,wt,cn]),dn=l.useMemo(()=>cn?nA(wt,ht):[],[ht,wt,cn]);l.useEffect(()=>{!cn||dn.length===0||dn.forEach(Fe=>I(Fe.id))},[I,dn,cn]),l.useEffect(()=>{if(!cn)return;const Fe=new Map;[...wt,...zt].forEach(Nt=>{Fe.set(Nt.id,Nt)}),M(Fe)},[zt,M,wt,cn]);const Dr=l.useMemo(()=>{if(!cn)return[];const Fe=Nt=>{const pt=xn.get(Nt.id),Jt=ws(Nt.directory??null);return{node:pt?.node??{session:Nt,children:[],worktree:null},projectId:pt?.projectId??null,groupDirectory:pt?.groupDirectory??Jt,secondaryMeta:pt?.secondaryMeta??null}};return[{key:"active-now",title:i("sessions.sidebar.activity.recentTitle"),items:_r.map(Fe)}]},[_r,xn,cn,i]),Wr=l.useMemo(()=>new Set(_r.map(Fe=>Fe.id)),[_r]),Va=l.useMemo(()=>[...Wr],[Wr]);f6({currentSessionId:Kt,sortedSessions:se,recentSessionIds:Va,ensureSessionRenderable:Rt.ensureSessionRenderable});const xr=l.useMemo(()=>{if(!as||Ye||Wr.size===0)return Sn;const Fe=Nt=>Nt.reduce((pt,Jt)=>{if(Wr.has(Jt.session.id))return pt;const js=Fe(Jt.children);return js.length===Jt.children.length?(pt.push(Jt),pt):(pt.push({...Jt,children:js}),pt)},[]);return Sn.map(Nt=>({...Nt,groups:Nt.groups.map(pt=>({...pt,sessions:Fe(pt.sessions)}))}))},[as,Ye,Wr,Sn]),Ua=l.useMemo(()=>{const Fe=new Set;return xr.forEach(Nt=>{Nt.groups.forEach(pt=>{const Jt=ws(pt.directory??null),js=pt.branch?.trim()||yt.get(Jt||"")?.trim();!Jt||!js||Fe.add(Hi(Jt,js))})}),[...Fe]},[yt,xr]),fn=S0(Ua);l.useEffect(()=>{if(!Pr||!zr?.connected||!gr)return;const Fe=[],Nt=Date.now();if(xr.forEach(Jt=>{P.has(Jt.project.id)||Jt.groups.forEach(js=>{const en=ws(js.directory??null),mn=js.branch?.trim()||yt.get(en||"")?.trim();if(!en||!mn)return;const br=Hi(en,mn),Qn=mr.getState().entries[br],kn=!!Qn?.status?.pr,Cn=`${en}::${mn}`,ki=Math.max(Qn?.lastRefreshAt??0,Qn?.lastDiscoveryPollAt??0),Ci=!!(Qn?.isInitialStatusResolved&&!kn&&(!f.current.has(Cn)||Nt-ki>=lA));(!Qn||!Qn.isInitialStatusResolved||Ci)&&(Ci&&f.current.add(Cn),Fe.push({directory:en,branch:mn}))})}),Fe.length===0)return;const pt=new Map;Fe.forEach(Jt=>{const js=Hi(Jt.directory,Jt.branch,Jt.remoteName??null);pt.has(js)||pt.set(js,Jt)}),pt.forEach((Jt,js)=>{wn(js),zn(js,{directory:Jt.directory,branch:Jt.branch,remoteName:Jt.remoteName??null,canShow:!0,github:gr,githubAuthChecked:Pr,githubConnected:zr.connected})}),sr([...pt.values()],{force:!0,silent:!0,markInitialResolved:!0})},[P,wn,gr,Pr,zr?.connected,yt,sr,xr,zn]);const Le=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",Qe="h-4.5 w-4.5",tt=II({isDesktopShellRuntime:Ms,projectSections:rr,projectHeaderSentinelRefs:Se}),ct=l.useCallback((Fe,Nt=0,pt,Jt,js=!1,en,mn="project")=>s.jsx(GP,{node:Fe,depth:Nt,groupDirectory:pt,projectId:Jt,archivedBucket:js,directoryStatus:k,currentSessionId:Kt,pinnedSessionIds:ne,expandedParents:y,hasSessionSearchQuery:Ye,normalizedSessionSearchQuery:at,notifyOnSubtasks:_e,editingId:b,setEditingId:h,editTitle:v,setEditTitle:x,handleSaveEdit:Pn,handleCancelEdit:an,toggleParent:Yt,handleSessionSelect:ss,handleSessionDoubleClick:Es,togglePinnedSession:he,handleShareSession:Ir,copiedSessionId:Hs,handleCopyShareUrl:er,handleUnshareSession:Js,openSidebarMenuKey:z,setOpenSidebarMenuKey:K,renamingFolderId:F,getFoldersForScope:rt,getSessionFolderId:et,removeSessionFromFolder:qe,addSessionToFolder:Ke,createFolderAndStartRename:Qt,openContextPanelTab:De,handleDeleteSession:An,mobileVariant:t,alwaysShowActions:Ls,renderSessionNode:ct,secondaryMeta:en,renderContext:mn}),[k,Kt,ne,y,Ye,at,_e,b,h,v,x,Pn,an,Yt,ss,Es,he,Ir,Hs,er,Js,z,K,F,rt,et,qe,Ke,Qt,De,An,t,Ls]),Ft=l.useCallback(Fe=>{oe(Nt=>{const pt=new Set(Nt);return pt.has(Fe)?pt.delete(Fe):pt.add(Fe),pt})},[]),Xt=l.useMemo(()=>{const Fe=new Map;for(const[Nt,pt]of fn)Fe.set(Nt,{visualState:pt.visualState,number:pt.number,url:pt.url,state:pt.prState,draft:pt.draft,title:pt.title,base:pt.base,head:pt.head,checks:pt.checks,canMerge:pt.canMerge,mergeableState:pt.mergeableState,repo:pt.repo});return Fe},[fn]),Ws=l.useCallback((Fe,Nt,pt,Jt,js,en)=>s.jsx(KI,{group:Fe,groupKey:Nt,projectId:pt,hideGroupLabel:Jt,compactBodyPadding:en,hasSessionSearchQuery:Ye,normalizedSessionSearchQuery:at,groupSearchDataByGroup:ua,expandedSessionGroups:T,collapsedGroups:ke,hideDirectoryControls:r,collapsedFolderIds:Xe,toggleFolderCollapse:He,renameFolder:nt,deleteFolder:Ne,showDeletionDialog:le,setDeleteFolderConfirm:W,renderSessionNode:ct,currentSessionDirectory:pa,projectRepoStatus:N,lastRepoStatus:Ar.current,toggleGroupSessionLimit:vs,mobileVariant:t,alwaysShowActions:Ls,activeProjectId:re,setActiveProjectIdOnly:ce,setActiveMainTab:$e,setSessionSwitcherOpen:$,openNewSessionDraft:We,addSessionToFolder:Ke,createFolderAndStartRename:Qt,renamingFolderId:F,renameFolderDraft:Q,setRenameFolderDraft:te,setRenamingFolderId:G,pinnedSessionIds:ne,sessionOrderIndex:xt,prVisualStateByDirectoryBranch:Xt,onToggleCollapsedGroup:Ft,dragHandleProps:js}),[Ye,at,ua,T,ke,r,Xe,He,nt,Ne,le,ct,pa,N,vs,t,Ls,re,ce,$e,$,We,Ke,Qt,F,Q,ne,xt,Xt,Ft]),Bs=cn&&!Ye?s.jsx(XI,{sections:Dr,renderSessionNode:ct}):null,On=!!(F||b||g),ta=ur(Fe=>Fe.enabled),Ks=ur(Fe=>Fe.selectedIds),Tr=ur(Fe=>Fe.scopeKey),ji=ur,Bl=l.useCallback(()=>{ur.getState().toggleMode()},[]),Yn=l.useCallback(()=>{ur.getState().disable()},[]),Mr=l.useMemo(()=>{if(Ks.size===0||typeof document>"u")return!1;let Fe=!1,Nt=!1;for(const pt of Ks){const Jt=document.querySelectorAll(`[data-session-row="${CSS.escape(pt)}"]`);for(const js of Jt)js.getAttribute("data-session-archived")==="1"?Nt=!0:Fe=!0}return Nt&&!Fe},[Ks]),hn=l.useMemo(()=>{if(Tr)return Tr;if(Ks.size===0||typeof document>"u")return null;for(const Fe of Ks){const pt=document.querySelector(`[data-session-row="${CSS.escape(Fe)}"]`)?.getAttribute("data-session-scope");if(pt&&pt.length>0)return pt}return null},[Ks,Tr]),Ni=l.useMemo(()=>hn?ut[hn]??[]:[],[ut,hn]),au=l.useMemo(()=>{if(!hn||Ks.size===0)return!1;const Fe=ut[hn]??[];for(const Nt of Fe)for(const pt of Nt.sessionIds)if(Ks.has(pt))return!0;return!1},[ut,hn,Ks]),Si=l.useCallback(Fe=>{!hn||Ks.size===0||Ve(hn,Fe,Array.from(Ks))},[Ve,Ks,hn]),Wa=l.useCallback(()=>{if(!hn||Ks.size===0)return;const Fe=Qt(hn);Fe&&Ve(hn,Fe.id,Array.from(Ks))},[Ve,Qt,Ks,hn]),xo=l.useCallback(()=>{!hn||Ks.size===0||lt(hn,Array.from(Ks))},[lt,Ks,hn]),sa=l.useCallback(async()=>{const Fe=Array.from(Ks);if(Fe.length!==0){if(Mr){const{deletedIds:Nt,failedIds:pt}=await Ot(Fe);Nt.length>0&&H.success(Nt.length===1?i("sessions.sidebar.bulkActions.deletedSingle",{count:Nt.length}):i("sessions.sidebar.bulkActions.deletedPlural",{count:Nt.length})),pt.length>0&&H.error(pt.length===1?i("sessions.sidebar.bulkActions.failedDeleteSingle",{count:pt.length}):i("sessions.sidebar.bulkActions.failedDeletePlural",{count:pt.length}))}else{const{archivedIds:Nt,failedIds:pt}=await Zs(Fe);Nt.length>0&&H.success(Nt.length===1?i("sessions.sidebar.bulkActions.archivedSingle",{count:Nt.length}):i("sessions.sidebar.bulkActions.archivedPlural",{count:Nt.length})),pt.length>0&&H.error(pt.length===1?i("sessions.sidebar.bulkActions.failedArchiveSingle",{count:pt.length}):i("sessions.sidebar.bulkActions.failedArchivePlural",{count:pt.length}))}ur.getState().clear()}},[Zs,Mr,Ot,Ks,i]),Ka=l.useCallback(()=>{const Fe=Ks.size;if(Fe!==0){if(!le){sa();return}J({sessionCount:Fe,archivedBucket:Mr})}},[Mr,sa,Ks,le]),bo=l.useCallback(async()=>{J(null),await sa()},[sa]);l.useEffect(()=>{if(!ta)return;const Fe=typeof navigator<"u"&&/Macintosh|Mac OS X/.test(navigator.userAgent||""),Nt=pt=>{if(On)return;const Jt=pt.target;if(Jt&&(Jt.tagName==="INPUT"||Jt.tagName==="TEXTAREA"||Jt.isContentEditable))return;const js=Fe?pt.metaKey:pt.ctrlKey;if(pt.key==="Escape"){pt.preventDefault(),ur.getState().disable();return}if(js&&pt.key==="Backspace"){pt.preventDefault(),Ka();return}if(js&&(pt.key==="a"||pt.key==="A")){const en=typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[];if(en.length===0)return;pt.preventDefault();const br=ji.getState().scopeKey??en[0]?.getAttribute("data-session-scope")??null,Qn=Cn=>br?Cn.getAttribute("data-session-scope")===br:!0,kn=en.filter(Qn).map(Cn=>Cn.getAttribute("data-session-row")).filter(Cn=>typeof Cn=="string"&&Cn.length>0);if(kn.length===0)return;ji.getState().replaceAll(kn,br||null)}};return window.addEventListener("keydown",Nt),()=>window.removeEventListener("keydown",Nt)},[Ka,On,ji,ta]);const yo=l.useCallback(()=>{$e("chat"),t&&$(!1),ae()},[t,ae,$e,$]);return s.jsxs("div",{ref:m,className:xe("relative flex h-full flex-col text-foreground overflow-x-hidden",t?"":"bg-transparent"),children:[s.jsx(HI,{hideDirectoryControls:r,handleOpenDirectoryDialog:Dt,canOpenMultiRun:Y.length>0,openMultiRunLauncher:yo,headerActionIconClass:Qe,headerActionButtonClass:Le,isSessionSearchOpen:o,setIsSessionSearchOpen:c,sessionSearchInputRef:u,sessionSearchQuery:d,setSessionSearchQuery:p,hasSessionSearchQuery:Ye,searchMatchCount:ma,collapseAllProjects:Rs,expandAllProjects:Cs,openScheduledTasksDialog:()=>je(!0),selectionModeEnabled:ta,onToggleSelectionMode:Bl}),s.jsx(oP,{topContent:Bs,sectionsForRender:xr,projectSections:rr,activeProjectId:re,showOnlyMainWorkspace:a,hasSessionSearchQuery:Ye,emptyState:_t,searchEmptyState:ar,renderGroupSessions:Ws,homeDirectory:pe,collapsedProjects:P,hideDirectoryControls:r,projectRepoStatus:N,isDesktopShellRuntime:Ms,stuckProjectHeaders:tt,mobileVariant:t,alwaysShowActions:Ls,toggleProject:_s,setActiveProjectIdOnly:ce,setActiveMainTab:$e,setSessionSwitcherOpen:$,openNewSessionDraft:We,openNewWorktreeDialog:Ue,openProjectEditDialog:w,removeProject:Pe,projectHeaderSentinelRefs:Se,reorderProjects:Te,getOrderedGroups:Ur,setGroupOrderByProject:me,openSidebarMenuKey:z,setOpenSidebarMenuKey:K,isInlineEditing:On}),ta&&Ks.size>0?s.jsx(QP,{selectedCount:Ks.size,scopeKey:hn,scopeFolders:Ni,archivedBucket:Mr,onMoveToFolder:Si,onCreateFolderAndMove:Wa,onRemoveFromFolder:xo,canRemoveFromFolder:au,onDelete:Ka,onDone:Yn}):null,s.jsx(eP,{onOpenSettings:Pt,onOpenShortcuts:O,onOpenAbout:()=>L(!0),onOpenUpdate:gt,showRuntimeButtons:!as,showUpdateButton:Mt}),s.jsx(bd,{open:U,onOpenChange:B,info:St.info,downloading:St.downloading,downloaded:St.downloaded,progress:St.progress,error:St.error,onDownload:St.downloadUpdate,onRestart:St.restartToUpdate,runtimeType:St.runtimeType}),Gt?s.jsx($y,{open:!!Gt,onOpenChange:Fe=>{Fe||w(null)},projectId:Gt.id,projectName:Gt.label||Oa(Gt.path,pe),projectPath:Gt.path,initialIcon:Gt.icon,initialColor:Gt.color,initialIconBackground:Gt.iconBackground,onSave:is}):null,s.jsx(y6,{open:V,onOpenChange:_,onWorktreeCreated:(Fe,Nt)=>{if($e("chat"),t&&$(!1),Nt?.sessionId){Et(Nt.sessionId);return}We({directoryOverride:Fe})}}),s.jsx(q6,{}),s.jsx(qP,{value:Z,setValue:fe,showDeletionDialog:le,setShowDeletionDialog:Me,onConfirm:tr}),s.jsx(YP,{value:ue,setValue:W,onConfirm:Be}),s.jsx(JP,{value:q,setValue:J,showDeletionDialog:le,setShowDeletionDialog:Me,onConfirm:bo})]})},cA=()=>{const t=st.c(13),[e,n]=Oe.useState(!1);let r,a;t[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>{n(vn())},a=[],t[0]=r,t[1]=a):(r=t[0],a=t[1]),Oe.useEffect(r,a);let i;t[2]!==e?(i=async f=>e?await _y(f):{success:!0,path:f},t[2]=e,t[3]=i):i=t[3];const o=i;let c;t[4]!==e?(c=async f=>e?await By():{success:!0},t[4]=e,t[5]=c):c=t[5];const d=c;let p;t[6]!==e?(p=async f=>e?await zy():{success:!0},t[6]=e,t[7]=p):p=t[7];const m=p;let u;return t[8]!==e||t[9]!==o||t[10]!==d||t[11]!==m?(u={isDesktop:e,requestAccess:o,startAccessing:d,stopAccessing:m},t[8]=e,t[9]=o,t[10]=d,t[11]=m,t[12]=u):u=t[12],u},dA=t=>t==="/",Nl=t=>t.replace(/\\/g,"/"),nu=t=>{if(!t||dA(t))return t;let e=t;for(;e.length>1&&e.endsWith("/");)e=e.slice(0,-1);return e},oi=t=>t.endsWith("/"),uA=t=>{const e=t.trim();return!e||oi(e)?e:`${e}/`},ru=t=>t.lastIndexOf("/"),Vg=t=>{if(oi(t))return t;const e=ru(t);return e<0?t:t.slice(0,e+1)},mA=t=>{const e=ru(t);return t.slice(e+1)},Ug=t=>{const e=nu(t.trim());if(!e||e==="~"||e==="~/"||e==="/")return null;const n=ru(e);return n<0?null:e.startsWith("~/")&&n<=1?"~/":n===0?"/":`${e.slice(0,n)}/`},pA=t=>oi(t)&&Ug(t)!==null,fA=(t,e)=>`${Vg(t)}${e}/`,qa=t=>{if(!t)return null;const e=nu(Nl(t.trim()));return e?e.toLowerCase():null},gf=(t,e)=>{const n=t.trim();return n==="~"?e:n.startsWith("~/")?`${e}${n.slice(1)}`:n},hA=t=>typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?t.metaKey&&!t.ctrlKey:t.ctrlKey&&!t.metaKey,Lc=t=>{if(!t)return;t.focus({preventScroll:!0});const e=t.value.length;t.setSelectionRange(e,e),t.scrollLeft=t.scrollWidth},gA=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 Nl(e.home.trim())}}catch{}return sn.getFilesystemHome().catch(()=>null)},xA=({open:t,onOpenChange:e})=>{const{t:n}=dt(),r=zs(ae=>ae.homeDirectory),a=Ps(ae=>ae.projects),i=Ps(ae=>ae.addProject),o=Wn(ae=>ae.profiles),c=Wn(ae=>ae.globalIdentity),d=Wn(ae=>ae.defaultGitIdentityId),p=Wn(ae=>ae.loadProfiles),m=Wn(ae=>ae.loadGlobalIdentity),u=Wn(ae=>ae.loadDefaultGitIdentityId),f=Tl(),{isDesktop:b,requestAccess:h,startAccessing:v}=cA(),{isMobile:x}=nn(),g=l.useRef(null),w=l.useRef(null),y=l.useRef(new Map),[C,k]=l.useState(""),[j,S]=l.useState("~/"),[I,M]=l.useState([]),[P,A]=l.useState(!1),[N,E]=l.useState(!1),[T,R]=l.useState(0),[V,_]=l.useState(!1),[U,B]=l.useState(!1),[z,K]=l.useState(0),[F,G]=l.useState(!1),[Q,te]=l.useState(""),[Z,fe]=l.useState(null),ue=C||r,W=l.useMemo(()=>new Set(a.map(ae=>qa(ae.path)).filter(ae=>!!ae)),[a]);l.useEffect(()=>{if(!t)return;S("~/"),M([]),R(0),_(!1),B(!1),G(!1),te(""),fe(null),requestAnimationFrame(()=>Lc(g.current));let ae=!1;return(async()=>{const le=await gA();ae||(k(le||r||""),requestAnimationFrame(()=>Lc(g.current)))})(),()=>{ae=!0}},[r,t]),l.useEffect(()=>{t&&(p(),m(),u())},[u,p,m,t]);const q=l.useMemo(()=>{const ae=new Map;c&&ae.set(c.id,c);for(const _e of o)ae.set(_e.id,_e);return Array.from(ae.values())},[o,c]);l.useEffect(()=>{if(!t||!F||Z!==null)return;const ae=typeof d=="string"?d.trim():"";if(ae&&q.some(le=>le.id===ae)){fe(ae);return}const _e=q.find(le=>le.authType==="ssh"||le.sshKey);_e&&fe(_e.id)},[q,d,F,t,Z]);const J=l.useMemo(()=>q.find(ae=>ae.id===Z)??null,[q,Z]),ne=l.useMemo(()=>Vg(j),[j]),ee=l.useMemo(()=>oi(j)?"":mA(j),[j]),he=l.useMemo(()=>ue?gf(ne,ue):"",[ne,ue]);l.useEffect(()=>{if(!t||!he){M([]);return}let ae=!1;return A(!0),E(!1),sn.listLocalDirectory(he).then(_e=>{if(ae)return;E(!1);const le=_e.filter(Me=>Me.isDirectory).map(Me=>({name:Me.name,path:Nl(Me.path)})).sort((Me,Ge)=>Me.name.localeCompare(Ge.name));M(le)}).catch(()=>{ae||(M([]),E(!0))}).finally(()=>{ae||A(!1)}),()=>{ae=!0}},[he,t]);const ke=l.useMemo(()=>{const ae=ee.toLowerCase(),_e=f||ee.startsWith(".");return I.filter(le=>le.name.toLowerCase().startsWith(ae)&&(_e||!le.name.startsWith(".")))},[ee,I,f]),oe=l.useMemo(()=>{const ae=[];pA(j)&&ae.push({type:"up",value:"browse:up",name:"..",path:Ug(j)});for(const _e of ke){const le=qa(_e.path);ae.push({type:"directory",value:`browse:${_e.path}`,name:_e.name,path:_e.path,disabled:!!(le&&W.has(le))})}return ae},[W,ke,j]);l.useEffect(()=>{R(0)},[j,oe.length]);const ge=l.useMemo(()=>ue?nu(gf(j,ue)):"",[ue,j]),me=qa(ge),ye=!!(me&&W.has(me)),ie=l.useMemo(()=>ee?ke.find(ae=>ae.name===ee)??null:null,[ee,ke]),ve=!!(ge&&!ye&&(oi(j)&&N||!oi(j)&&ee.trim().length>0&&ie===null)),X=!V&&!U&&!ye&&!!ge,Se=X&&Q.trim().length>0,Ae=oe[T]??null,pe=!!(Ae&&(Ae.type==="up"||Ae.type==="directory"&&!Ae.disabled)),we=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?"⌘":"Ctrl",Ie=n(ye?"directoryExplorerDialog.actions.alreadyAdded":F?V?"directoryExplorerDialog.actions.cloning":"directoryExplorerDialog.actions.cloneAndAdd":V?"directoryExplorerDialog.actions.adding":ve?"directoryExplorerDialog.actions.createAndAdd":"directoryExplorerDialog.actions.addProject");l.useLayoutEffect(()=>{const ae=w.current;if(!ae)return;const _e=()=>K(Math.ceil(ae.getBoundingClientRect().width));if(_e(),typeof ResizeObserver>"u")return;const le=new ResizeObserver(_e);return le.observe(ae),()=>le.disconnect()},[Ie]),l.useLayoutEffect(()=>{const ae=g.current;ae&&(ae.scrollLeft=ae.scrollWidth)},[z,j]),l.useLayoutEffect(()=>{t&&Lc(g.current)},[t]),l.useLayoutEffect(()=>{const ae=oe[T];ae&&y.current.get(ae.value)?.scrollIntoView({block:"nearest"})},[T,oe]);const Y=l.useCallback(()=>{e(!1)},[e]),re=l.useCallback(async ae=>{if(!ae||V)return;const _e=qa(ae);if(_e&&W.has(_e))return;let le=ae;_(!0);try{const Me=!F&&ve&&qa(ae)===qa(ge);if(F){const at=Q.trim();if(!at){H.error(n("directoryExplorerDialog.toast.cloneUrlRequired"));return}le=(await sn.cloneRepository({remoteUrl:at,destinationPath:ae,gitIdentityId:J?.id??null})).path}else Me&&await sn.createDirectory(ae,{allowOutsideWorkspace:!0});if(!i(le)){H.error(n("directoryExplorerDialog.toast.failedToAddProject"),{description:n("directoryExplorerDialog.toast.selectValidDirectoryPath")});return}Y()}catch(Me){H.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:Me instanceof Error?Me.message:n("directoryExplorerDialog.toast.unknownError")})}finally{_(!1)}},[i,W,Q,Y,F,V,J?.id,ve,ge,n]),Pe=l.useCallback(ae=>{S(uA(ae))},[]),ce=l.useCallback(ae=>{S(fA(j,ae.name))},[j]),Ce=l.useCallback(ae=>{if(ae){if(ae.type==="up"){ae.path&&Pe(ae.path);return}ae.disabled||ce(ae)}},[Pe,ce]),Te=l.useCallback(async()=>{if(!(!b||U)){B(!0);try{const ae=await h(ge);if(!ae.success||!ae.path){ae.error&&ae.error!=="Directory selection cancelled"&&H.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:ae.error});return}const _e=await v(ae.path);if(!_e.success){H.error(n("directoryExplorerDialog.toast.failedToOpenDirectory"),{description:_e.error||n("directoryExplorerDialog.toast.desktopCouldNotGrantAccess")});return}await re(ae.path)}catch(ae){H.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:ae instanceof Error?ae.message:n("directoryExplorerDialog.toast.unknownError")})}finally{B(!1)}}},[re,b,U,h,v,n,ge]),$e=l.useCallback(ae=>{if(ae.key==="ArrowDown"){ae.preventDefault(),R(_e=>Math.min(oe.length-1,_e+1));return}if(ae.key==="ArrowUp"){ae.preventDefault(),R(_e=>Math.max(0,_e-1));return}if(ae.key==="Enter"){if(ae.preventDefault(),hA(ae)){re(ge);return}pe&&Ce(Ae);return}ae.key==="Backspace"&&j===""&&(ae.preventDefault(),Y())},[Ce,re,Y,pe,Ae,j,oe.length,ge]),De=s.jsxs("button",{type:"button",onClick:()=>Wo(!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")]}),de=s.jsxs("div",{className:"px-2.5 py-1.5",children:[F?s.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5",children:[s.jsx(Bt,{value:Q,onChange:ae=>te(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($h,{activeProfile:J,identities:q,onSelect:ae=>fe(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:g,value:j,onChange:ae=>S(Nl(ae.target.value)),onKeyDown:$e,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&&z>0?{paddingRight:`${z+24}px`}:void 0,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off"}),x?null:s.jsx(be,{ref:w,variant:"outline",size:"xs",tabIndex:-1,className:"absolute right-1.5 top-1/2 h-7 -translate-y-1/2 gap-1 px-2 typography-meta",disabled:F?!Se:!X,onMouseDown:ae=>ae.preventDefault(),onClick:()=>{re(ge)},title:Ie,children:Ie})]})]}),O=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")}):oe.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:oe.map((ae,_e)=>{const le=_e===T;return s.jsxs("button",{ref:Me=>{Me?y.current.set(ae.value,Me):y.current.delete(ae.value)},type:"button",disabled:ae.type==="directory"&&ae.disabled,onMouseEnter:()=>R(_e),onMouseDown:Me=>Me.preventDefault(),onClick:()=>Ce(ae),className:xe("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",le&&"bg-interactive-selection text-interactive-selection-foreground",!le&&"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")}):null]},ae.value)})})]})}),L=s.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3",children:[de,O]}),$=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:we}),s.jsx(D,{name:"corner-down-left",className:"h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.add")]})]}),je=()=>s.jsxs(s.Fragment,{children:[x?null:$,s.jsxs("div",{className:xe("flex w-full flex-row justify-end gap-2 sm:w-auto",x&&"justify-stretch"),children:[b?s.jsx(be,{variant:"ghost",size:"xs",onClick:Te,disabled:V||U||F,children:n(U?"directoryExplorerDialog.actions.openingFinder":"directoryExplorerDialog.actions.openInFinder")}):null,s.jsx(be,{variant:"ghost",size:"xs",onClick:()=>G(ae=>!ae),disabled:V||U,className:xe(x&&"flex-1"),children:n(F?"directoryExplorerDialog.actions.addLocalProject":"directoryExplorerDialog.actions.cloneRepository")}),x?s.jsx(be,{size:"xs",onClick:()=>{re(ge)},disabled:F?!Se:!X,className:"flex-1",children:Ie}):null]})]});return x?s.jsx(Lr,{open:t,onClose:Y,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:je()}),children:s.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-3",children:[s.jsx("div",{className:"flex justify-end",children:De}),L]})}):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(ys,{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(hs,{children:n("directoryExplorerDialog.title")}),s.jsx(Ss,{className:"mt-2",children:n("directoryExplorerDialog.description")})]}),De]})}),s.jsx("div",{className:"min-h-0 flex-1 px-2 pb-0",children:L}),s.jsx(Vs,{className:"flex w-full flex-col gap-3 px-5 py-3 sm:flex-row sm:items-center sm:justify-between",children:je()})]})})},va=t=>t?s.jsx("span",{className:"text-foreground/80 dark:text-foreground/70",children:t}):void 0,Rr=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},bA=()=>{const{t}=dt(),[e,n]=l.useState(!1),[r,a]=l.useState(!1),[i,o]=l.useState(null),[c,d]=l.useState([]),[p,m]=l.useState(!1),[u,f]=l.useState(!1),[b,h]=l.useState(!1),[v,x]=l.useState(!1),[g,w]=l.useState(new Set),y=Lt(X=>X.getWorktreeMetadata),C=Lt(X=>X.newSessionDraft),k=Lt(X=>X.setNewSessionDraftTarget),j=Lt(X=>X.setDraftBootstrapPendingDirectory),S=Vy,I=Ky,M=Lt(X=>X.deleteSessions),P=Lt(X=>X.archiveSessions),A=Re(X=>X.showDeletionDialog),N=Re(X=>X.setShowDeletionDialog),E=zs(X=>X.currentDirectory),T=zs(X=>X.homeDirectory),R=zs(X=>X.isHomeReady),V=Ps(X=>X.projects),_=Ps(X=>X.activeProjectId),{isMobile:U,isTablet:B,hasTouchInput:z}=nn(),K=U||B||z,F=l.useMemo(()=>{const Se=(_?V.find(Ae=>Ae.id===_)??null:null)?.path??E;return Rr(Se)},[_,E,V]),G=l.useCallback(X=>{const Ae=Rr(X.projectDirectory)||F;return{id:(V.find(we=>Rr(we.path)===Ae)??null)?.id??`path:${Ae}`,path:Ae}},[F,V]),Q=v&&g.size>0,te=l.useMemo(()=>{const X=i?.worktree;return X&&typeof X.branch=="string"&&X.branch.trim().length>0?!0:c.length>0&&c.every(({metadata:Se})=>typeof Se.branch=="string"&&Se.branch.trim().length>0)},[i?.worktree,c]),Z=i?.mode==="worktree",fe=Z,ue=b||!Z||!te,W=b||!Z;l.useEffect(()=>{r||!R||V.length>0||(a(!0),n(!0))},[r,R,V.length]);const q=l.useCallback(X=>{o({sessions:X.sessions,dateLabel:X.dateLabel,mode:X.mode??"session",worktree:X.worktree??null})},[]),J=l.useCallback(()=>{o(null),d([]),m(!1),f(!1),h(!1),x(!1),w(new Set)},[]),ne=l.useCallback(async X=>{if(X.sessions.length===0)return;if(X.sessions.length===1){const we=X.sessions[0];await S(we.id)?H.success(t("sessions.sidebar.session.delete.success")):H.error(t("sessions.sidebar.session.delete.error"));return}const Se=X.sessions.map(we=>we.id),{deletedIds:Ae,failedIds:pe}=await M(Se);if(Ae.length>0){const we=pe.length>0?pe.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:pe.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:pe.length}):X.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:X.dateLabel}):void 0;H.success(Ae.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:Ae.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:Ae.length}),{description:va(we)})}pe.length>0&&H.error(pe.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:pe.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:pe.length}),{description:va(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))})},[S,M,t]);l.useEffect(()=>Nr.onDeleteRequest(X=>{if(!A&&(X.mode??"session")==="session"){ne(X);return}q(X)}),[q,A,ne]),l.useEffect(()=>Nr.onDirectoryRequest(()=>{n(!0)}),[]),l.useEffect(()=>{if(!i){d([]),m(!1),f(!1),x(!1),w(new Set);return}const X=i.sessions.map(pe=>{const we=y(pe.id);return we?{session:pe,metadata:we}:null}).filter(pe=>!!pe);d(X),m(!1),x(!1),w(new Set);const Se=new Map;if(i.worktree?.path&&Se.set(Rr(i.worktree.path),i.worktree),X.forEach(({metadata:pe})=>{pe.path&&Se.set(Rr(pe.path),pe)}),Se.size===0){x(!0);return}let Ae=!1;return(async()=>{const pe=new Map,we=new Set;await Promise.all(Array.from(Se.entries()).map(async([Ie,Y])=>{try{const re=await Uy(Y.path);pe.set(Ie,re),re?.isDirty&&we.add(Ie)}catch{Y.status&&(pe.set(Ie,Y.status),Y.status.isDirty&&we.add(Ie))}})).catch(Ie=>{console.warn("Failed to inspect worktree status before deletion:",Ie)}),!Ae&&(w(we),x(!0),o(Ie=>{if(!Ie?.worktree?.path)return Ie;const Y=Rr(Ie.worktree.path),re=pe.get(Y);if(!re)return Ie;const Pe=Ie.worktree.status;return Pe?.isDirty===re.isDirty&&Pe?.ahead===re.ahead&&Pe?.behind===re.behind&&Pe?.upstream===re.upstream?Ie:{...Ie,worktree:{...Ie.worktree,status:re}}}),d(Ie=>Ie.map(Y=>{const re=Rr(Y.metadata.path),Pe=pe.get(re);return Pe?{session:Y.session,metadata:{...Y.metadata,status:Pe}}:Y})))})(),()=>{Ae=!0}},[i,y]),l.useEffect(()=>{te||m(!1)},[te]);const ee=l.useCallback(async(X,Se)=>{const Ae=p&&te,pe=G(X),we=Rr(X.path),Ie=Rr(pe.path);try{await Wy(pe,X,{deleteRemoteBranch:Ae,deleteLocalBranch:Se});const Y=Rr(C?.directoryOverride);return C?.open&&we&&Y===we&&Ie&&(j(null),k({projectId:pe.id,directoryOverride:Ie},{force:!0})),Rr(E)===we&&Ie&&zs.getState().setDirectory(Ie,{showOverlay:!1}),!0}catch(Y){return H.error(t("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle"),{description:va(Y instanceof Error?Y.message:t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),!1}},[te,E,p,G,C?.directoryOverride,C?.open,j,k,t]),he=l.useCallback(async()=>{if(i){h(!0);try{const X=fe,Se=X&&p,Ae=X&&u;if(i.sessions.length===0&&Z&&i.worktree){if(!await ee(i.worktree,Ae)){J();return}const Ie=t(p&&te?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.removed");H.success(t("sessions.sidebar.sessionDialogs.worktree.removedTitle"),{description:va(Ie)}),J();return}if(i.sessions.length===1){const pe=i.sessions[0];if(!(Z?await I(pe.id):await S(pe.id,{archiveWorktree:!1,deleteRemoteBranch:Se,deleteLocalBranch:Ae}))){H.error(t(Z?"sessions.sidebar.session.archive.error":"sessions.sidebar.session.delete.error")),h(!1);return}const Ie=!Z&&X?t(Se?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.attachedArchived"):void 0;H.success(t(Z?"sessions.sidebar.session.archive.success":"sessions.sidebar.session.delete.success"),{description:va(Ie),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}else{const pe=i.sessions.map(Y=>Y.id);let we=[],Ie=[];if(Z){const Y=await P(pe);we=Y.archivedIds,Ie=Y.failedIds}else{const Y=await M(pe);we=Y.deletedIds,Ie=Y.failedIds}if(Z&&i.worktree&&Ie.length===0&&await ee(i.worktree,Ae),we.length>0){const Y=!Z&&X?t(Se?"sessions.sidebar.sessionDialogs.worktree.archivedAndRemoteRemoved":"sessions.sidebar.sessionDialogs.worktree.attachedArchivedPlural"):void 0,Pe=[Ie.length>0?Z?Ie.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToArchive",{count:Ie.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToArchive",{count:Ie.length}):Ie.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:Ie.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:Ie.length}):i.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:i.dateLabel}):void 0,Y].filter(Boolean).join(" ");H.success(Z?we.length===1?t("sessions.sidebar.bulkActions.archivedSingle",{count:we.length}):t("sessions.sidebar.bulkActions.archivedPlural",{count:we.length}):we.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:we.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:we.length}),{description:va(Pe||void 0),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}if(Ie.length>0&&(H.error(Z?Ie.length===1?t("sessions.sidebar.bulkActions.failedArchiveSingle",{count:Ie.length}):t("sessions.sidebar.bulkActions.failedArchivePlural",{count:Ie.length}):Ie.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:Ie.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:Ie.length}),{description:va(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),we.length===0)){h(!1);return}}Z&&i.sessions.length===1&&i.worktree&&await ee(i.worktree,Ae),J()}finally{h(!1)}}},[i,p,u,S,M,I,P,J,fe,Z,te,ee,t]),ke=i?.worktree??c[0]?.metadata??null,oe=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:xe(Z?"space-y-3":"space-y-2"),children:[i.sessions.length>0&&s.jsxs("div",{className:xe(Z?"rounded-lg bg-muted/30 p-3":"space-y-1.5 rounded-xl border border-border/40 bg-sidebar/60 p-3"),children:[Z&&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:xe(Z?"mt-2 space-y-1":"space-y-0.5"),children:[i.sessions.slice(0,5).map(X=>s.jsxs("li",{className:xe(Z?"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:xe(!Z&&"hidden"),children:"•"}),s.jsx("span",{className:"truncate",children:X.title||t("sessions.sidebar.session.untitled")})]},X.id)),i.sessions.length>5&&s.jsx("li",{className:xe(Z?"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})})]})]}),Z?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")}),ke?.label?s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:ke.label}):null]}),s.jsx("p",{className:"typography-micro text-muted-foreground/80 break-all",children:ke?eo(ke.path,T):t("sessions.sidebar.sessionDialogs.worktree.pathUnavailable")}),Q&&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,me=Z?te?s.jsxs("button",{type:"button",onClick:()=>{ue||m(X=>!X)},disabled:ue,className:xe("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",ue?"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,ye=Z?s.jsxs("button",{type:"button",onClick:()=>{W||f(X=>!X)},disabled:W,className:xe("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",W?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[u?s.jsx(D,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(D,{name:"checkbox-blank",className:"size-4"}),t("sessions.sidebar.sessionDialogs.actions.deleteLocalBranch")]}):null,ie=Z?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:[ye,me]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(be,{variant:"ghost",onClick:J,disabled:b,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(be,{variant:"destructive",onClick:he,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(be,{variant:"ghost",onClick:J,disabled:b,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(be,{variant:"destructive",onClick:he,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")})]})]}),ve=Z?t("sessions.sidebar.sessionDialogs.actions.deleteWorktree"):i?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction");return s.jsxs(s.Fragment,{children:[K?s.jsx(Lr,{open:!!i,onClose:()=>{b||J()},title:ve,footer:s.jsx("div",{className:"flex justify-end gap-2",children:ie}),children:s.jsxs("div",{className:"space-y-2 pb-2",children:[oe&&s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:oe}),ge]})}):s.jsx(ps,{open:!!i,onOpenChange:X=>{if(!X){if(b)return;J()}},children:s.jsxs(ms,{className:xe(Z?"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(ys,{children:[s.jsxs(hs,{className:xe(Z&&"flex items-center gap-2"),children:[Z&&s.jsx(D,{name:"delete-bin",className:"h-5 w-5"}),ve]}),oe&&s.jsx(Ss,{children:oe})]}),s.jsx("div",{className:xe(Z&&"flex-1 min-h-0 overflow-y-auto space-y-2"),children:ge}),s.jsx(Vs,{className:"mt-2 gap-2 pt-1 pb-1",children:ie})]})}),s.jsx(xA,{open:e,onOpenChange:n})]})},Sd=t=>t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").substring(0,50),yA=(t,e)=>{const n=Sd(t),r=Sd(e);return`${n}-${r}`.substring(0,60)},xf=(t,e)=>`${t}/${e}`,vA=()=>{const t=Ps.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=zs.getState().currentDirectory??null;if(r&&r.trim().length>0){const a=r.replace(/\\/g,"/").replace(/\/+$/,"")||r;return{id:`path:${a}`,path:a}}return null},$c=Zn()(bi(t=>({isLoading:!1,error:null,createMultiRun:async e=>{const n=e.name.trim(),{groups:r,agent:a,files:i,setupCommands:o}=e;if(!n)return t({error:"Group name is required"}),null;if(!r||r.length===0)return t({error:"At least one run group is required"}),null;for(let c=0;c<r.length;c++){if(!r[c].prompt.trim())return t({error:`Group ${c+1}: prompt is required`}),null;if(r[c].models.length<1)return t({error:`Group ${c+1}: select at least 1 model`}),null;if(r[c].models.length>5)return t({error:`Group ${c+1}: maximum 5 models allowed`}),null}t({isLoading:!0,error:null});try{const c=vA();if(!c)return t({error:"Select a project",isLoading:!1}),null;const d=c.path,m=await rh(d)&&e.isolateRuns!==!1,u=Sd(n),f=m?await co(d):void 0,b=m?await Hy(d):null,h=[],v=o?.filter(C=>C.trim().length>0)??[];for(let C=0;C<r.length;C++){const k=r[C],j=k.prompt,S=new Map;for(const M of k.models){const P=`${M.providerID}:${M.modelID}`;S.set(P,(S.get(P)||0)+1)}const I=new Map;for(const M of k.models){const P=`${M.providerID}:${M.modelID}`,A=S.get(P)||1,N=(I.get(P)||0)+1;I.set(P,N);const E=yA(M.providerID,M.modelID),T=r.length>1?`g${C+1}`:void 0,R=A>1?xf(u,`${E}/${N}`):xf(u,E),V=T?`${T}/${R}`:R,_=PP({groupSlug:u,runGroup:T,providerID:M.providerID,modelID:M.modelID,index:A>1?N:void 0});try{if(!m){const K=await sn.withDirectory(d,()=>sn.createSession({title:_}));h.push({sessionId:K.id,worktreePath:d,providerID:M.providerID,modelID:M.modelID,variant:M.variant,prompt:j});continue}const U=await Gy(c,{preferredName:V,mode:"new",branchName:V,worktreeName:V,startRef:e.worktreeBaseBranch||"HEAD",setupCommands:v},{resolvedRootTrackingRemote:b}),B={...U,createdFromBranch:f,kind:"standard"},z=await sn.withDirectory(U.path,()=>sn.createSession({title:_}));Lt.getState().setWorktreeMetadata(z.id,B),h.push({sessionId:z.id,worktreePath:U.path,providerID:M.providerID,modelID:M.modelID,variant:M.variant,prompt:j})}catch(U){console.warn("[MultiRun] Failed to create session:",U)}}}const x=o?.filter(C=>C.trim().length>0)??[];x.length>0&&ah(c,x).catch(()=>{console.warn("[MultiRun] Failed to save worktree setup commands")});const g=h.map(C=>C.sessionId),w=h[0]?.sessionId??null;if(g.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=Fl.getState().expandText;await Promise.allSettled(h.map(async k=>{try{const j=await C(k.prompt).catch(()=>k.prompt);await sn.withDirectory(k.worktreePath,()=>sn.sendMessage({id:k.sessionId,providerID:k.providerID,modelID:k.modelID,variant:k.variant,text:j,agent:a,files:y}))}catch(j){console.warn("[MultiRun] Failed to start run:",j)}}))}catch(C){console.warn("[MultiRun] Failed to start runs:",C)}})(),t({isLoading:!1}),{groupSlug:u,sessionIds:g,firstSessionId:w}}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"})),wA="oc:lastWorktreeSourceBranch";function Wg(t){const e=st.c(30),{git:n}=Rn(),r=Md(t),a=Td(t),i=Ed(t),o=dh(t),c=tn(CA),d=tn(kA);let p,m;e[0]!==t||e[1]!==d||e[2]!==n||e[3]!==a||e[4]!==i?(p=()=>{!t||!n||a!==null||i||d(t,n,{silent:!0})},m=[t,n,d,a,i],e[0]=t,e[1]=d,e[2]=n,e[3]=a,e[4]=i,e[5]=p,e[6]=m):(p=e[5],m=e[6]),l.useEffect(p,m);let u;e[7]!==r?.all||e[8]!==t||e[9]!==c||e[10]!==n||e[11]!==a?(u=()=>{!t||!n||a===!0&&(r?.all||c(t,n))},e[7]=r?.all,e[8]=t,e[9]=c,e[10]=n,e[11]=a,e[12]=u):u=e[12];const f=r?.all;let b;e[13]!==t||e[14]!==c||e[15]!==n||e[16]!==a||e[17]!==f?(b=[t,n,a,f,c],e[13]=t,e[14]=c,e[15]=n,e[16]=a,e[17]=f,e[18]=b):b=e[18],l.useEffect(u,b);const h=i||a===!0&&o;let v;e:{if(!r?.all){let S;e[19]===Symbol.for("react.memo_cache_sentinel")?(S=[],e[19]=S):S=e[19],v=S;break e}let j;e[20]!==r.all?(j=r.all.filter(SA).sort(),e[20]=r.all,e[21]=j):j=e[21],v=j}const x=v;let g;e:{if(!r?.all){let S;e[22]===Symbol.for("react.memo_cache_sentinel")?(S=[],e[22]=S):S=e[22],g=S;break e}let j;e[23]!==r.all?(j=r.all.filter(NA).map(jA).sort(),e[23]=r.all,e[24]=j):j=e[24],g=j}const w=g;let y;e:{if(!t){y=null;break e}if(a!==null){y=a;break e}if(h){y=null;break e}y=r?.all?!0:null}const C=y;let k;return e[25]!==C||e[26]!==h||e[27]!==x||e[28]!==w?(k={localBranches:x,remoteBranches:w,isLoading:h,isGitRepository:C},e[25]=C,e[26]=h,e[27]=x,e[28]=w,e[29]=k):k=e[29],k}function jA(t){return t.replace(/^remotes\//,"")}function NA(t){return t.startsWith("remotes/")}function SA(t){return!t.startsWith("remotes/")}function kA(t){return t.fetchStatus}function CA(t){return t.fetchBranches}const IA=({directory:t,value:e,onChange:n,className:r,disabled:a,id:i})=>{const{t:o}=dt(),{localBranches:c,remoteBranches:d,isLoading:p,isGitRepository:m}=Wg(t),u=l.useMemo(()=>[...c,...d.map(b=>`remotes/${b}`)],[c,d]);l.useEffect(()=>{if(a||p||u.length===0||e&&u.includes(e))return;(async()=>{try{const h=t?await co(t).catch(()=>null):null,v=localStorage.getItem(wA);v&&u.includes(v)?n(v):h&&u.includes(h)?n(h):u.includes("main")?n("main"):u.includes("master")?n("master"):u[0]&&n(u[0])}catch{}})()},[u,t,a,p,n,e]);const f=a||!m||p;return s.jsxs("div",{children:[s.jsxs(os,{value:e,onValueChange:n,disabled:f,children:[s.jsx(ls,{id:i,size:"lg",className:r??"w-fit typography-meta text-foreground",children:s.jsx(us,{placeholder:o(p?"multiRun.branchSelector.status.loadingBranches":"multiRun.branchSelector.placeholder.selectSourceBranch")})}),s.jsx(cs,{className:"max-h-[280px] max-w-[320px]",children:p?s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:o("multiRun.branchSelector.status.loadingBranches")}):c.length===0&&d.length===0?s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:o("multiRun.branchSelector.status.noBranchesFound")}):s.jsxs(s.Fragment,{children:[c.length>0&&s.jsxs(qc,{children:[s.jsx($u,{className:"font-semibold text-foreground",children:o("multiRun.branchSelector.groups.localBranches")}),c.map(b=>s.jsx(Tt,{value:b,className:"whitespace-normal break-all",children:b},b))]}),c.length>0&&d.length>0&&s.jsx(qy,{}),d.length>0&&s.jsxs(qc,{children:[s.jsx($u,{className:"font-semibold text-foreground",children:o("multiRun.branchSelector.groups.remoteBranches")}),d.map(b=>s.jsx(Tt,{value:`remotes/${b}`,className:"whitespace-normal break-all",children:b},`remotes/${b}`))]})]})})]}),m===!1&&s.jsx("p",{className:"typography-micro text-muted-foreground/70 mt-2",children:o("multiRun.branchSelector.status.notInGitRepository")})]})},PA=10*1024*1024,_c=5,nl=t=>{const e=st.c(3),{children:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(It,{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(Ct,{children:[r,s.jsx(At,{side:"top",className:"max-w-[240px]",children:n})]}),e[1]=n,e[2]=a):a=e[2],a},ka=t=>{const e=st.c(9),{htmlFor:n,required:r,children:a,info:i}=t;let o;e[0]!==r?(o=r&&s.jsx("span",{className:"text-destructive ml-0.5",children:"*"}),e[0]=r,e[1]=o):o=e[1];let c;e[2]!==a||e[3]!==n||e[4]!==o?(c=s.jsxs("label",{htmlFor:n,className:"typography-meta font-medium text-foreground",children:[a,o]}),e[2]=a,e[3]=n,e[4]=o,e[5]=c):c=e[5];const d=i&&i;let p;return e[6]!==c||e[7]!==d?(p=s.jsxs("div",{className:"flex items-center gap-1.5",children:[c,d]}),e[6]=c,e[7]=d,e[8]=p):p=e[8],p},AA=({initialPrompt:t,onCreated:e,onCancel:n,isWindowed:r=!1})=>{const{t:a}=dt(),[i,o]=l.useState(""),[c,d]=l.useState(()=>[{id:qi(),prompt:"",models:[]}]),[p,m]=l.useState(""),[u,f]=l.useState([]),[b,h]=l.useState(!1),[v,x]=l.useState([]),[g,w]=l.useState(!1),[y,C]=l.useState(!1),[k,j]=l.useState(!0),S=l.useRef(null),I=zs(Y=>Y.currentDirectory??null),M=zs(Y=>Y.homeDirectory??null),P=l.useMemo(()=>{if(typeof window>"u")return null;const Y=window.__VSCODE_CONFIG__?.workspaceFolder;return typeof Y=="string"&&Y.trim().length>0?Y.trim():null},[]),A=Ps(Y=>Y.activeProjectId),N=Ps(Y=>Y.setActiveProjectIdOnly),E=Ps(Y=>Y.projects),[T,R]=l.useState(()=>A??null);l.useEffect(()=>{if(A){R(A);return}!T&&E.length>0&&R(E[0].id)},[A,E,T]);const V=l.useMemo(()=>T?E.find(Y=>Y.id===T)??null:null,[E,T]),_=V?.path??I,U=l.useCallback(Y=>{R(Y),Y!==A&&N(Y)},[A,N]),{currentTheme:B}=Cr(),z=l.useCallback(Y=>{const re=Y.label?.trim()||Oa(Y.path,M),Pe=mo({id:Y.id,iconImage:Y.iconImage??null},{themeVariant:B.metadata.variant,iconColor:B.colors.surface.foreground}),ce=Y.icon?Rl[Y.icon]:null,Ce=Y.color?po[Y.color]:void 0;return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[Pe?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:Y.iconBackground?{backgroundColor:Y.iconBackground}:void 0,children:s.jsx("img",{src:Pe,alt:"",className:"h-full w-full object-contain",draggable:!1})}):ce?s.jsx(D,{name:ce,className:"h-3.5 w-3.5 shrink-0",style:Ce?{color:Ce}:void 0}):s.jsx(D,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:Ce?{color:Ce}:void 0}),s.jsx("span",{className:"truncate",children:re})]})},[M,B.metadata.variant,B.colors.surface.foreground]),K=l.useMemo(()=>{if(V?.path)return{id:V.id,path:V.path};const Y=I??P;return Y?{id:`path:${Y}`,path:Y}:null},[V,I,P]),[F]=l.useState(()=>typeof window<"u"?vn():!1),G=l.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),Q=Wf(),te=l.useMemo(()=>{if(typeof window>"u")return null;const Y=window.__OPENCHAMBER_MACOS_MAJOR__;if(typeof Y=="number"&&Number.isFinite(Y)&&Y>0)return Y;if(typeof navigator>"u")return null;const re=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!re)return null;const Pe=Number.parseInt(re[1],10),ce=Number.parseInt(re[2],10);return Number.isNaN(Pe)?null:Pe===10?ce:Pe},[]),Z=l.useMemo(()=>F&&G||Q?"pl-[5.5rem]":"pl-3",[F,G,Q]),fe=l.useMemo(()=>!F||!G||te===null?"":te>=26?"h-12":te<=15?"h-14":"",[F,G,te]),ue=l.useCallback(async Y=>{Y.target.closest("button, a, input, select, textarea")||Y.button===0&&F&&await Jy()},[F]);l.useEffect(()=>{if(!n)return;const Y=re=>{re.key==="Escape"&&(re.preventDefault(),re.stopPropagation(),n())};return window.addEventListener("keydown",Y,!0),()=>window.removeEventListener("keydown",Y,!0)},[n]);const[W,q]=l.useState(""),{isLoading:J,isGitRepository:ne}=Wg(_),ee=l.useRef(!1),he=ne===!0,ke=he&&k;l.useEffect(()=>{if(ne===!1){ee.current=!0,j(!1);return}ne===!0&&ee.current&&(ee.current=!1,j(!0))},[ne]);const oe=$c(Y=>Y.createMultiRun),ge=$c(Y=>Y.error),me=$c(Y=>Y.clearError);l.useEffect(()=>{typeof t=="string"&&t.trim().length>0&&d(Y=>{const re=[...Y];return re.length>0&&!re[0].prompt.trim()&&(re[0]={...re[0],prompt:t}),re})},[t]),l.useEffect(()=>{if(!K)return;let Y=!1;return C(!0),(async()=>{try{const re=await _d(K);Y||x(re)}catch{}finally{Y||C(!1)}})(),()=>{Y=!0}},[K]);const ye=l.useCallback((Y,re)=>{d(Pe=>Pe.map(ce=>ce.id===Y?{...ce,...re}:ce))},[]),ie=l.useCallback(Y=>{d(re=>re.filter(Pe=>Pe.id!==Y))},[]),ve=l.useCallback(()=>{d(Y=>[...Y,{id:qi(),prompt:"",models:[]}])},[]),X=async Y=>{const re=Y.target.files;if(!re)return;let Pe=0;for(let ce=0;ce<re.length;ce++){const Ce=re[ce];if(Ce.size>PA){H.error(a("multirun.launcher.toast.fileTooLarge",{fileName:Ce.name}));continue}try{const Te=await new Promise(($e,De)=>{const de=new FileReader;de.onload=()=>$e(de.result),de.onerror=De,de.readAsDataURL(Ce)});f($e=>[...$e,{id:qi(),filename:Ce.name,mimeType:Ce.type||"application/octet-stream",size:Ce.size,dataUrl:Te}]),Pe++}catch(Te){console.error("File attach failed",Te),H.error(a("multirun.launcher.toast.attachFailed",{fileName:Ce.name}))}}Pe>0&&H.success(Pe===1?a("multirun.launcher.toast.attachedSingle",{count:Pe}):a("multirun.launcher.toast.attachedPlural",{count:Pe})),S.current&&(S.current.value="")},Se=Y=>{f(re=>re.filter(Pe=>Pe.id!==Y))},Ae=l.useMemo(()=>c.reduce((Y,re)=>Y+re.models.length,0),[c]),pe=async Y=>{Y.preventDefault();const re=c.filter(Pe=>Pe.prompt.trim()&&Pe.models.length>=1);if(re.length!==0&&!(Ae<1)){h(!0),me();try{T&&T!==A&&N(T);const Pe=u.map(De=>({mime:De.mimeType,filename:De.filename,url:De.dataUrl})),ce=v.filter(De=>De.trim().length>0),Ce=re.map(De=>({prompt:De.prompt.trim(),models:De.models.map(de=>({providerID:de.providerID,modelID:de.modelID,displayName:de.displayName,variant:de.variant}))})),Te={name:i.trim(),groups:Ce,agent:p||void 0,worktreeBaseBranch:ke?W:void 0,isolateRuns:ke,files:Pe.length>0?Pe:void 0,setupCommands:ce.length>0?ce:void 0},$e=await oe(Te);$e&&($e.firstSessionId&&Lt.getState().setCurrentSession($e.firstSessionId),e?.())}finally{h(!1)}}},we=!!(i.trim()&&c.some(Y=>Y.prompt.trim()&&Y.models.length>=1)&&Ae>=1&&_&&!J&&(ne===!1||!ke||W)),Ie=v.filter(Y=>Y.trim()).length;return s.jsxs("form",{onSubmit:pe,className:"flex flex-col h-full bg-background",children:[r?null:s.jsxs("header",{onMouseDown:ue,className:xe("relative flex h-12 shrink-0 items-center justify-center border-b app-region-drag select-none",Z,fe),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(Ct,{children:[s.jsx(It,{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(At,{children:s.jsx("p",{children:a("multirun.launcher.actions.closeEsc")})})]})})]}),s.jsx(lo,{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(ka,{htmlFor:"multirun-project",required:!0,children:a("multirun.launcher.project.label")}),E.length>0?s.jsxs(os,{value:T??void 0,onValueChange:U,children:[s.jsx(ls,{id:"multirun-project",size:"lg",className:"w-fit max-w-full",children:V?s.jsx(us,{children:z(V)}):s.jsx(us,{placeholder:a("multirun.launcher.project.placeholder")})}),s.jsx(cs,{fitContent:!0,children:E.map(Y=>s.jsx(Tt,{value:Y.id,className:"max-w-[24rem]",children:z(Y)},Y.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(ka,{htmlFor:"group-name",required:!0,info:s.jsx(nl,{children:a("multirun.launcher.groupName.info")}),children:a("multirun.launcher.groupName.label")}),s.jsx(Bt,{id:"group-name",value:i,onChange:Y=>o(Y.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(ka,{htmlFor:"multirun-worktree-base-branch",info:s.jsx(nl,{children:a("multirun.launcher.baseBranch.info")}),children:a("multirun.launcher.baseBranch.label")}),s.jsx(IA,{directory:_,value:W,onChange:q,disabled:!ke,id:"multirun-worktree-base-branch"}),s.jsxs("label",{className:"mt-1.5 flex w-fit items-center gap-1.5 typography-micro text-muted-foreground",children:[s.jsx(fs,{checked:k,onChange:j,disabled:!he,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(ka,{htmlFor:"multirun-agent",info:s.jsx(nl,{children:a("multirun.launcher.agent.info")}),children:a("multirun.launcher.agent.label")}),s.jsx(Og,{value:p,onChange:m,id:"multirun-agent"})]})]}),s.jsxs(fr,{open:g,onOpenChange:w,children:[s.jsxs(kr,{className:"w-full flex items-center gap-2 py-1.5 px-2 -mx-2 rounded-lg hover:bg-[var(--interactive-hover)]/50 transition-colors group",children:[s.jsx(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")}),Ie>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:Ie}),s.jsx(D,{name:"arrow-down-s",className:xe("h-3.5 w-3.5 text-muted-foreground/50 transition-transform duration-200 ml-auto",g&&"rotate-180")})]}),s.jsx(hr,{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((Y,re)=>s.jsxs("div",{className:"flex gap-1.5",children:[s.jsx(Bt,{value:Y,onChange:Pe=>{const ce=[...v];ce[re]=Pe.target.value,x(ce)},placeholder:a("multirun.launcher.setupCommands.commandPlaceholder"),className:"h-8 flex-1 font-mono text-xs"}),s.jsx("button",{type:"button",onClick:()=>x(v.filter((Pe,ce)=>ce!==re)),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"})})]},`${Y}-${re}`)),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(ka,{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:X,accept:"*/*"}),s.jsxs(Ct,{children:[s.jsx(It,{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(At,{children:a("multirun.launcher.attachments.tooltip")})]}),u.map(Y=>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:[Y.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:Y.filename,children:Y.filename}),s.jsx("button",{type:"button",onClick:()=>Se(Y.id),className:"text-muted-foreground hover:text-destructive",children:s.jsx(D,{name:"close",className:"h-3 w-3"})})]},Y.id))]})]}),c.map((Y,re)=>s.jsx(DA,{group:Y,groupIndex:re,canRemove:c.length>1,onUpdate:ye,onRemove:ie},Y.id)),s.jsxs("button",{type:"button",onClick:ve,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:[!ke&&ne!==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(be,{type:"button",variant:"ghost",size:"sm",onClick:n,children:a("multirun.launcher.actions.cancel")}),s.jsx(be,{type:"submit",size:"sm",disabled:!we||b,children:b?a("multirun.launcher.actions.creating"):s.jsx(s.Fragment,{children:a("multirun.launcher.actions.startWithRunCount",{count:Ae})})})]})})]})},DA=t=>{const e=st.c(99),{group:n,groupIndex:r,canRemove:a,onUpdate:i,onRemove:o}=t,{t:c}=dt(),[d,p]=l.useState(!1),[m,u]=l.useState(""),[f,b]=l.useState(!1),[h,v]=l.useState(""),[x,g]=l.useState(!1),[w,y]=l.useState(""),C=l.useRef(null),k=l.useRef(null),j=l.useRef(null),S=l.useRef(null);let I;e[0]!==n.id||e[1]!==n.models||e[2]!==i?(I=ce=>{n.models.length>=_c||i(n.id,{models:[...n.models,ce]})},e[0]=n.id,e[1]=n.models,e[2]=i,e[3]=I):I=e[3];const M=I;let P;e[4]!==n.id||e[5]!==n.models||e[6]!==i?(P=ce=>{i(n.id,{models:n.models.filter((Ce,Te)=>Te!==ce)})},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=(ce,Ce)=>{i(n.id,{models:n.models.map((Te,$e)=>$e===ce?Ce:Te)})},e[8]=n.id,e[9]=n.models,e[10]=i,e[11]=N):N=e[11];const E=N;let T;e[12]===Symbol.for("react.memo_cache_sentinel")?(T=(ce,Ce)=>{if(ce.startsWith("/")){const de=ce.indexOf(" "),O=ce.indexOf(`
224
+ `),L=Math.min(de===-1?ce.length:de,O===-1?ce.length:O);if(Ce<=L&&de===-1){v(ce.substring(1,L)),b(!0),p(!1),g(!1);return}}b(!1);const Te=ce.substring(0,Ce),$e=Te.lastIndexOf("#");if($e!==-1){const de=$e>0?Te[$e-1]:null,O=Te.substring($e+1);if((!de||/\s/.test(de))&&!O.includes(" ")&&!O.includes(`
225
+ `)){y(O),g(!0),p(!1);return}}g(!1);const De=Te.lastIndexOf("@");if(De!==-1){const de=De>0?Te[De-1]:null,O=Te.substring(De+1);(!de||/\s/.test(de))&&!O.includes(" ")&&!O.includes(`
226
+ `)?(u(O),p(!0)):p(!1);return}p(!1)},e[12]=T):T=e[12];const R=T;let V;e[13]!==n.id||e[14]!==i?(V=ce=>{i(n.id,{prompt:ce})},e[13]=n.id,e[14]=i,e[15]=V):V=e[15];const _=V;let U;e[16]!==n.prompt||e[17]!==_?(U=ce=>{const Ce=n.prompt,$e=C.current?.selectionStart??Ce.length,de=Ce.substring(0,$e).lastIndexOf("@"),O=ce.relativePath&&ce.relativePath.trim().length>0?ce.relativePath.trim():ce.path||ce.name,L=de!==-1?de:$e,$=`${Ce.substring(0,L)}@${O} ${Ce.substring($e)}`,je=L+O.length+2;_($),p(!1),u(""),requestAnimationFrame(()=>{const ae=C.current;ae&&(ae.selectionStart=je,ae.selectionEnd=je,ae.focus()),R($,je)})},e[16]=n.prompt,e[17]=_,e[18]=U):U=e[18];const B=U;let z;e[19]!==n.prompt||e[20]!==_?(z=ce=>{const Ce=n.prompt,$e=C.current?.selectionStart??Ce.length,de=Ce.substring(0,$e).lastIndexOf("@"),O=de!==-1?de:$e,L=`${Ce.substring(0,O)}@${ce} ${Ce.substring($e)}`,$=O+ce.length+2;_(L),p(!1),u(""),requestAnimationFrame(()=>{const je=C.current;je&&(je.selectionStart=$,je.selectionEnd=$,je.focus()),R(L,$)})},e[19]=n.prompt,e[20]=_,e[21]=z):z=e[21];const K=z;let F;e[22]!==_?(F=ce=>{const Ce=`/${ce.name} `;_(Ce),b(!1),v(""),g(!1),requestAnimationFrame(()=>{const Te=C.current;Te&&(Te.focus(),Te.selectionStart=Te.value.length,Te.selectionEnd=Te.value.length),R(Ce,Ce.length)})},e[22]=_,e[23]=F):F=e[23];const G=F;let Q;e[24]!==n.prompt||e[25]!==_?(Q=(ce,Ce)=>{const Te=n.prompt,De=C.current?.selectionStart??Te.length,O=Te.substring(0,De).lastIndexOf("#"),L=O!==-1?O:De,$=`${Te.substring(0,L)}#${Ce} ${Te.substring(De)}`,je=L+Ce.length+2;_($),g(!1),y(""),requestAnimationFrame(()=>{const ae=C.current;ae&&(ae.selectionStart=je,ae.selectionEnd=je,ae.focus()),R($,je)})},e[24]=n.prompt,e[25]=_,e[26]=Q):Q=e[26];const te=Q;let Z;e[27]!==f||e[28]!==d||e[29]!==x?(Z=ce=>{if(f&&j.current&&(ce.key==="Enter"||ce.key==="ArrowUp"||ce.key==="ArrowDown"||ce.key==="Escape"||ce.key==="Tab")){ce.preventDefault(),j.current.handleKeyDown(ce.key);return}d&&k.current&&(ce.key==="Enter"||ce.key==="ArrowUp"||ce.key==="ArrowDown"||ce.key==="Escape"||ce.key==="Tab")&&(ce.preventDefault(),k.current.handleKeyDown(ce.key)),x&&S.current&&(ce.key==="Enter"||ce.key==="ArrowUp"||ce.key==="ArrowDown"||ce.key==="Escape"||ce.key==="Tab")&&(ce.preventDefault(),S.current.handleKeyDown(ce.key))},e[27]=f,e[28]=d,e[29]=x,e[30]=Z):Z=e[30];const fe=Z,ue=r+1;let W;e[31]!==c||e[32]!==ue?(W=c("multirun.launcher.groups.groupLabel",{index:ue}),e[31]=c,e[32]=ue,e[33]=W):W=e[33];let q;e[34]!==W?(q=s.jsx("span",{className:"typography-meta font-medium text-foreground",children:W}),e[34]=W,e[35]=q):q=e[35];let J;e[36]!==a||e[37]!==n.id||e[38]!==o||e[39]!==c?(J=a&&s.jsx("button",{type:"button",onClick:()=>o(n.id),className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10","aria-label":c("multirun.launcher.groups.removeGroup"),children:s.jsx(D,{name:"close",className:"h-3.5 w-3.5"})}),e[36]=a,e[37]=n.id,e[38]=o,e[39]=c,e[40]=J):J=e[40];let ne;e[41]!==q||e[42]!==J?(ne=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[q,J]}),e[41]=q,e[42]=J,e[43]=ne):ne=e[43];let ee;e[44]!==c?(ee=c("multirun.launcher.groups.prompt.label"),e[44]=c,e[45]=ee):ee=e[45];let he;e[46]!==ee?(he=s.jsx(ka,{required:!0,children:ee}),e[46]=ee,e[47]=he):he=e[47];const ke=n.prompt;let oe;e[48]!==_?(oe=ce=>{const Ce=ce.target.value;_(Ce);const Te=ce.target.selectionStart??Ce.length;R(Ce,Te)},e[48]=_,e[49]=oe):oe=e[49];let ge;e[50]!==c?(ge=c("multirun.launcher.groups.prompt.placeholder"),e[50]=c,e[51]=ge):ge=e[51];let me;e[52]!==n.prompt||e[53]!==fe||e[54]!==oe||e[55]!==ge?(me=s.jsx(un,{ref:C,value:ke,onChange:oe,onKeyDown:fe,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]=fe,e[54]=oe,e[55]=ge,e[56]=me):me=e[56];let ye;e[57]!==h||e[58]!==G||e[59]!==f?(ye=f?s.jsx(uh,{ref:j,searchQuery:h,onCommandSelect:G,onClose:()=>b(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[57]=h,e[58]=G,e[59]=f,e[60]=ye):ye=e[60];let ie;e[61]!==K||e[62]!==B||e[63]!==m||e[64]!==d?(ie=d?s.jsx(mh,{ref:k,searchQuery:m,onFileSelect:B,onAgentSelect:K,onClose:()=>p(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[61]=K,e[62]=B,e[63]=m,e[64]=d,e[65]=ie):ie=e[65];let ve;e[66]!==te||e[67]!==x||e[68]!==w?(ve=x?s.jsx(ph,{ref:S,searchQuery:w,onSnippetSelect:te,onClose:()=>g(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[66]=te,e[67]=x,e[68]=w,e[69]=ve):ve=e[69];let X;e[70]!==me||e[71]!==ye||e[72]!==ie||e[73]!==ve?(X=s.jsxs("div",{className:"relative",children:[me,ye,ie,ve]}),e[70]=me,e[71]=ye,e[72]=ie,e[73]=ve,e[74]=X):X=e[74];let Se;e[75]!==he||e[76]!==X?(Se=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[he,X]}),e[75]=he,e[76]=X,e[77]=Se):Se=e[77];let Ae;e[78]!==c?(Ae=c("multirun.launcher.models.info",{max:_c}),e[78]=c,e[79]=Ae):Ae=e[79];let pe;e[80]!==Ae?(pe=s.jsx(nl,{children:Ae}),e[80]=Ae,e[81]=pe):pe=e[81];let we;e[82]!==c?(we=c("multirun.launcher.models.label"),e[82]=c,e[83]=we):we=e[83];let Ie;e[84]!==pe||e[85]!==we?(Ie=s.jsx(ka,{required:!0,info:pe,children:we}),e[84]=pe,e[85]=we,e[86]=Ie):Ie=e[86];let Y;e[87]!==n.models||e[88]!==M||e[89]!==A||e[90]!==E?(Y=s.jsx($g,{selectedModels:n.models,onAdd:M,onRemove:A,onUpdate:E,minModels:1,maxModels:_c}),e[87]=n.models,e[88]=M,e[89]=A,e[90]=E,e[91]=Y):Y=e[91];let re;e[92]!==Ie||e[93]!==Y?(re=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[Ie,Y]}),e[92]=Ie,e[93]=Y,e[94]=re):re=e[94];let Pe;return e[95]!==ne||e[96]!==Se||e[97]!==re?(Pe=s.jsxs("div",{className:"rounded-lg border border-border p-3 space-y-3",children:[ne,Se,re]}),e[95]=ne,e[96]=Se,e[97]=re,e[98]=Pe):Pe=e[98],Pe},bf=()=>{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}},TA=()=>{const t=st.c(2),[e,n]=l.useState(bf),r=l.useRef(null);let a,i;return t[0]===Symbol.for("react.memo_cache_sentinel")?(a=()=>{if(typeof window>"u")return;const o=window.visualViewport,c=()=>{r.current===null&&(r.current=requestAnimationFrame(()=>{r.current=null;const d=bf();n(p=>p.height===d.height&&p.keyboardHeight===d.keyboardHeight?p:d)}))};return o?(o.addEventListener("resize",c),o.addEventListener("scroll",c,{passive:!0})):window.addEventListener("resize",c),c(),()=>{r.current!==null&&cancelAnimationFrame(r.current),o?(o.removeEventListener("resize",c),o.removeEventListener("scroll",c)):window.removeEventListener("resize",c)}},i=[],t[0]=a,t[1]=i):(a=t[0],i=t[1]),l.useEffect(a,i),e};class MA extends l.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,n){this.setState({error:e,errorInfo:n})}handleReset=()=>{this.setState({hasError:!1,error:void 0,errorInfo:void 0})};render(){return this.state.hasError?s.jsx("div",{className:"flex items-center justify-center min-h-screen p-4",children:s.jsxs(gh,{className:"w-full max-w-md",children:[s.jsx(Yy,{className:"text-center",children:s.jsxs(Qy,{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(Xy,{className:"space-y-4",children:[s.jsx("p",{className:"text-sm text-muted-foreground text-center",children:this.props.texts.description}),this.props.sessionId&&s.jsxs("div",{className:"text-xs text-muted-foreground text-center",children:[this.props.texts.sessionLabel,": ",this.props.sessionId]}),this.state.error&&s.jsxs("details",{className:"text-xs font-mono bg-muted p-3 rounded",children:[s.jsx("summary",{className:"cursor-pointer hover:bg-interactive-hover/80",children:this.props.texts.detailsSummary}),s.jsx("pre",{className:"mt-2 max-h-48 overflow-auto",children:this.state.error.toString()})]}),s.jsx("div",{className:"flex gap-2",children:s.jsxs(be,{onClick:this.handleReset,variant:"outline",className:"flex-1",children:[s.jsx(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 EA(t){const e=st.c(22),{t:n}=dt();let r;e[0]!==n?(r=n("chat.errorBoundary.title"),e[0]=n,e[1]=r):r=e[1];let a;e[2]!==n?(a=n("chat.errorBoundary.description"),e[2]=n,e[3]=a):a=e[3];let i;e[4]!==n?(i=n("chat.errorBoundary.sessionLabel"),e[4]=n,e[5]=i):i=e[5];let o;e[6]!==n?(o=n("chat.errorBoundary.detailsSummary"),e[6]=n,e[7]=o):o=e[7];let c;e[8]!==n?(c=n("chat.errorBoundary.resetAction"),e[8]=n,e[9]=c):c=e[9];let d;e[10]!==n?(d=n("chat.errorBoundary.persistentHint"),e[10]=n,e[11]=d):d=e[11];let p;e[12]!==r||e[13]!==a||e[14]!==i||e[15]!==o||e[16]!==c||e[17]!==d?(p={title:r,description:a,sessionLabel:i,detailsSummary:o,resetAction:c,persistentHint:d},e[12]=r,e[13]=a,e[14]=i,e[15]=o,e[16]=c,e[17]=d,e[18]=p):p=e[18];let m;return e[19]!==t||e[20]!==p?(m=s.jsx(MA,{...t,texts:p}),e[19]=t,e[20]=p,e[21]=m):m=e[21],m}const kd=t=>{const e=st.c(5),{readOnly:n}=t,r=n===void 0?!1:n,i=Lt(RA)||void 0;let o;e[0]!==r?(o=s.jsx(Zy,{readOnly:r}),e[0]=r,e[1]=o):o=e[1];let c;return e[2]!==i||e[3]!==o?(c=s.jsx(EA,{sessionId:i,children:o}),e[2]=i,e[3]=o,e[4]=c):c=e[4],c};function RA(t){return t.currentSessionId}const FA=ea(()=>Sr(()=>Promise.resolve().then(()=>J2),void 0).then(t=>({default:t.PlanView}))),yf=ea(()=>Sr(()=>Promise.resolve().then(()=>rN),void 0).then(t=>({default:t.GitView}))),OA=ea(()=>Sr(()=>Promise.resolve().then(()=>g2),void 0).then(t=>({default:t.DiffView}))),vf=ea(()=>Sr(()=>import("./TerminalView-ClACTVsY.js"),__vite__mapDeps([5,0,1,2,3,4,6])).then(t=>({default:t.TerminalView}))),LA=ea(()=>Sr(()=>Promise.resolve().then(()=>U2),void 0).then(t=>({default:t.FilesView}))),$A=ea(()=>Sr(()=>Promise.resolve().then(()=>h4),void 0).then(t=>({default:t.SettingsView}))),_A=ea(()=>Sr(()=>import("./SettingsWindow-DbIrbkwH.js"),__vite__mapDeps([7,0,1,2,3,4,6])).then(t=>({default:t.SettingsWindow}))),BA=ea(()=>Sr(()=>import("./MultiRunWindow-BXZBRXf8.js"),__vite__mapDeps([8,0,1,2,3,4,6])).then(t=>({default:t.MultiRunWindow}))),Bo=85,zA=280,VA=500,UA=360,WA=860,KA=()=>{const{t}=dt(),e=1140,n=1220,r=640,a=700,i=Re(K=>K.isSidebarOpen),o=Re(K=>K.isRightSidebarOpen),c=Re(K=>K.isBottomTerminalOpen),d=Re(K=>K.setRightSidebarOpen),p=Re(K=>K.setBottomTerminalOpen),m=Re(K=>K.activeMainTab),u=Re(K=>K.setIsMobile),f=Re(K=>K.isSessionSwitcherOpen),b=Re(K=>K.isSettingsDialogOpen),h=Re(K=>K.setSettingsDialogOpen),v=Re(K=>K.isMultiRunLauncherOpen),x=Re(K=>K.setMultiRunLauncherOpen),g=Re(K=>K.multiRunLauncherPrefillPrompt),{isMobile:w,isTablet:y}=nn(),C=TA(),k=Re(K=>K.sidebarWidth),j=Re(K=>K.rightSidebarWidth),S=l.useRef(!1),I=l.useRef(!1),[M,P]=l.useState(!1),A=l.useRef(!1),N=pu(0),E=Oe.useRef(0),T=pu(0),R=Oe.useRef(0);Oe.useEffect(()=>{w&&(E.current=window.innerWidth*(Bo/100),R.current=window.innerWidth*(Bo/100))},[w]),Oe.useEffect(()=>{if(!w)return;const K=M?0:-E.current;fu(N,K,{type:"spring",stiffness:400,damping:35,mass:.8})},[M,w,N]),Oe.useEffect(()=>{if(!w)return;A.current=o;const K=o?0:R.current;fu(T,K,{type:"spring",stiffness:400,damping:35,mass:.8})},[w,o,T]),Oe.useEffect(()=>{w&&P(f)},[f,w]),Oe.useEffect(()=>{!w||!b||(P(!1),f&&Re.getState().setSessionSwitcherOpen(!1),o&&d(!1))},[w,b,f,o,d]),Oe.useEffect(()=>{w&&(A.current=o)},[o,w]);const V=Ta(K=>K.checkForUpdates);l.useEffect(()=>{let te=!1,Z=null;const fe=W=>{const q=Math.round(W*1e3);return Math.max(3e5,Math.min(864e5,q))},ue=W=>{te||(Z=window.setTimeout(async()=>{const q=await V(),J=typeof q=="number"&&Number.isFinite(q)?fe(q):36e5;ue(J)},W))};return ue(3e3),()=>{te=!0,Z!==null&&window.clearTimeout(Z)}},[V]),l.useEffect(()=>{Re.getState().isMobile!==w&&u(w)},[w,u]),l.useEffect(()=>{if(typeof window>"u")return;let K;const F=()=>{K!==void 0&&window.clearTimeout(K),K=window.setTimeout(()=>{Re.getState().updateProportionalSidebarWidths()},150)};return window.addEventListener("resize",F),()=>{window.removeEventListener("resize",F),K!==void 0&&window.clearTimeout(K)}},[]),l.useEffect(()=>{if(typeof window>"u")return;let K;const F=()=>{const Q=Re.getState(),te=window.innerWidth,Z=window.innerHeight;if(!w&&!y){const fe=te<e,ue=te>=n;fe?Q.isRightSidebarOpen&&(d(!1),S.current=!0):ue&&S.current&&(d(!0),S.current=!1);const W=Z<r,q=Z>=a;W?Q.isBottomTerminalOpen&&(p(!1),I.current=!0):q&&I.current&&(p(!0),I.current=!1)}},G=()=>{K!==void 0&&window.clearTimeout(K),K=window.setTimeout(()=>{F()},100)};return F(),window.addEventListener("resize",G),()=>{window.removeEventListener("resize",G),K!==void 0&&window.clearTimeout(K)}},[w,y,p,d]),l.useEffect(()=>{if(typeof window>"u")return;const K=Re.subscribe((F,G)=>{const Q=window.innerWidth,te=window.innerHeight,Z=Q>=n,fe=te>=a;F.isRightSidebarOpen!==G.isRightSidebarOpen&&Z&&(S.current=!1),F.isBottomTerminalOpen!==G.isBottomTerminalOpen&&fe&&(I.current=!1)});return()=>{K()}},[w,y,p,d]);const _=l.useMemo(()=>{switch(m){case"plan":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(FA,{})});case"git":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(yf,{})});case"diff":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(OA,{})});case"terminal":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(vf,{})});case"files":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(LA,{})});default:return null}},[m]),U=m==="chat",B=l.useMemo(()=>Math.min(VA,Math.max(zA,k||ed)),[k]),z=l.useMemo(()=>Math.min(WA,Math.max(UA,j||td)),[j]);return s.jsx(Wj,{children:s.jsxs("div",{"data-page-scroll-lock":"true",className:xe("main-content-safe-area",w?"flex flex-col":"flex h-[100dvh]","bg-background"),style:w&&C.height>0?{height:C.height}:void 0,children:[s.jsx(g4,{}),s.jsx(n6,{}),s.jsx(o6,{}),s.jsx(bA,{}),w?s.jsxs(ev,{value:{leftDrawerOpen:M,rightDrawerOpen:o,toggleLeftDrawer:()=>{o&&d(!1),P(!M)},toggleRightDrawer:()=>{M&&P(!1),d(!o)},leftDrawerX:N,rightDrawerX:T,leftDrawerWidth:E,rightDrawerWidth:R,setMobileLeftDrawerOpen:P,setRightSidebarOpen:d},children:[!b&&s.jsx(nm,{onToggleLeftDrawer:()=>{o&&d(!1),P(!M)},onToggleRightDrawer:()=>{M&&P(!1),d(!o)},leftDrawerOpen:M,rightDrawerOpen:o}),s.jsx(Wl.button,{type:"button",initial:!1,animate:{opacity:M||o?1:0,pointerEvents:M||o?"auto":"none"},className:"fixed left-0 right-0 bottom-0 top-[var(--oc-header-height,56px)] z-40 bg-black/50 cursor-default",onClick:()=>{P(!1),d(!1)},"aria-label":t("mainLayout.mobile.closeDrawerAria")}),s.jsx(Wl.aside,{drag:"x",dragElastic:.08,dragMomentum:!1,dragConstraints:{left:-(E.current||window.innerWidth*.85),right:0},style:{width:`${Bo}%`,x:N},onDragEnd:(K,F)=>{const G=E.current||window.innerWidth*.85,Q=G*.3,te=500,Z=N.get(),fe=F.offset.x<-Q||F.velocity.x<-te,ue=F.offset.x>Q||F.velocity.x>te;fe?(N.set(-G),P(!1)):ue?(N.set(0),P(!0)):Z>-G/2?N.set(0):N.set(-G)},className:xe("fixed left-0 top-[var(--oc-header-height,56px)] z-50 h-[calc(100%-var(--oc-header-height,56px))] bg-background","cursor-grab active:cursor-grabbing"),"aria-hidden":!M,children:s.jsx("div",{"data-page-scroll-lock":"true",className:"h-full overflow-hidden flex bg-[var(--surface-background)] shadow-none drawer-safe-area",style:{backgroundImage:"linear-gradient(var(--surface-muted), var(--surface-muted))"},children:s.jsx("div",{className:"flex-1 min-w-0 overflow-hidden flex flex-col","data-page-scroll-lock":"true",children:s.jsx(Ys,{children:s.jsx(hf,{mobileVariant:!0})})})})}),s.jsx(Wl.aside,{drag:"x",dragElastic:.08,dragMomentum:!1,dragConstraints:{left:0,right:R.current||window.innerWidth*.85},style:{width:`${Bo}%`,x:T},onDragEnd:(K,F)=>{const G=R.current||window.innerWidth*.85,Q=G*.3,te=500,Z=T.get(),fe=F.offset.x>Q||F.velocity.x>te,ue=F.offset.x<-Q||F.velocity.x<-te;fe?(T.set(G),d(!1)):ue?(T.set(0),d(!0)):Z<G/2?T.set(0):T.set(G)},className:xe("fixed right-0 top-[var(--oc-header-height,56px)] z-50 h-[calc(100%-var(--oc-header-height,56px))] bg-background","cursor-grab active:cursor-grabbing"),"aria-hidden":!o,children:s.jsx("div",{className:"h-full overflow-hidden flex flex-col bg-background shadow-none drawer-safe-area","data-page-scroll-lock":"true",children:s.jsx(Ys,{children:s.jsx(l.Suspense,{fallback:null,children:s.jsx(yf,{})})})})}),s.jsx("div",{"data-page-scroll-lock":"true",className:xe("flex flex-1 overflow-hidden relative",b&&"hidden"),children:s.jsxs("main",{className:"w-full h-full overflow-hidden bg-background relative","data-page-scroll-lock":"true",children:[s.jsx("div",{className:xe("absolute inset-0",!U&&"invisible"),children:s.jsx(Ys,{children:s.jsx(kd,{})})}),_&&s.jsx("div",{className:"absolute inset-0",children:s.jsx(Ys,{children:_})}),v&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",children:s.jsx(Ys,{children:s.jsx(AA,{initialPrompt:g,onCreated:()=>x(!1),onCancel:()=>x(!1)})})})]})}),b&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",style:{paddingTop:"var(--oc-safe-area-top, 0px)"},children:s.jsx(Ys,{children:s.jsx(l.Suspense,{fallback:null,children:s.jsx($A,{onClose:()=>h(!1)})})})})]}):s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[s.jsx(nm,{}),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:`${i?B:0}px`,opacity:i?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:`${i?B:0}px`,opacity:i?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:`${o?z:0}px`,opacity:o?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:`${o?z:0}px`,opacity:o?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(X1,{isOpen:i,isMobile:w,className:"border-0",children:s.jsx(hf,{})}),s.jsxs("div",{className:xe("relative flex flex-1 min-w-0 flex-col overflow-hidden","bg-background","border border-border/50 rounded-[10px]",!i&&"border-l-transparent",!o&&"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:xe("absolute inset-0",!U&&"invisible"),children:s.jsx(Ys,{children:s.jsx(kd,{})})}),_&&s.jsx("div",{className:"absolute inset-0",children:s.jsx(Ys,{children:_})})]}),s.jsx(FS,{})]})}),s.jsx(G1,{isOpen:c,isMobile:w,children:c?s.jsx(Ys,{children:s.jsx(l.Suspense,{fallback:null,children:s.jsx(vf,{})})}):null})]}),s.jsx(Z1,{isOpen:o,className:"border-0",children:s.jsx(Ys,{children:s.jsx($N,{})})})]})]}),s.jsx(l.Suspense,{fallback:null,children:s.jsx(_A,{open:b,onOpenChange:h})}),s.jsx(l.Suspense,{fallback:null,children:s.jsx(BA,{open:v,onOpenChange:x,initialPrompt:g})})]})]})})},HA=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`},dr=t=>{const e=st.c(8),{label:n,value:r}=t;let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[0]=a):a=e[0];let i;e[1]!==n?(i=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:n}),e[1]=n,e[2]=i):i=e[2];let o;e[3]!==r?(o=s.jsx("div",{className:"typography-markdown font-semibold text-[var(--surface-foreground)]",children:r}),e[3]=r,e[4]=o):o=e[4];let c;return e[5]!==i||e[6]!==o?(c=s.jsxs("div",{className:"rounded-md p-2",style:a,children:[i,o]}),e[5]=i,e[6]=o,e[7]=c):c=e[7],c},wf=t=>{const e=st.c(43),{title:n,snapshot:r,emptyLabel:a}=t,{t:i}=dt();let o;if(e[0]!==a||e[1]!==r.durationMs||e[2]!==r.entries||e[3]!==r.lastUpdatedAt||e[4]!==r.startedAt||e[5]!==i||e[6]!==n){const c=r.entries.slice(0,12);let d;e[8]!==r.entries?(d=r.entries.reduce(JA,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?HA(r.durationMs):i("memoryDebugPanel.common.idle"),e[12]=r.durationMs,e[13]=r.startedAt,e[14]=i,e[15]=u):u=e[15];let f;e[16]!==u?(f=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:u}),e[16]=u,e[17]=f):f=e[17];let b;e[18]!==m||e[19]!==f?(b=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[m,f]}),e[18]=m,e[19]=f,e[20]=b):b=e[20];let h;e[21]!==i?(h=i("memoryDebugPanel.metric.metrics"),e[21]=i,e[22]=h):h=e[22];let v;e[23]!==r.entries.length||e[24]!==h?(v=s.jsx(dr,{label:h,value:r.entries.length}),e[23]=r.entries.length,e[24]=h,e[25]=v):v=e[25];let x;e[26]!==i?(x=i("memoryDebugPanel.metric.samples"),e[26]=i,e[27]=x):x=e[27];let g;e[28]!==x||e[29]!==p?(g=s.jsx(dr,{label:x,value:p}),e[28]=x,e[29]=p,e[30]=g):g=e[30];let w;e[31]!==i?(w=i("memoryDebugPanel.metric.lastUpdate"),e[31]=i,e[32]=w):w=e[32];let y;e[33]!==r.lastUpdatedAt||e[34]!==i?(y=r.lastUpdatedAt?i("memoryDebugPanel.common.live"):i("memoryDebugPanel.common.notAvailable"),e[33]=r.lastUpdatedAt,e[34]=i,e[35]=y):y=e[35];let C;e[36]!==w||e[37]!==y?(C=s.jsx(dr,{label:w,value:y}),e[36]=w,e[37]=y,e[38]=C):C=e[38];let k;e[39]!==g||e[40]!==C||e[41]!==v?(k=s.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[v,g,C]}),e[39]=g,e[40]=C,e[41]=v,e[42]=k):k=e[42],o=s.jsxs("div",{className:"space-y-2 border-t border-[var(--interactive-border)] pt-2 first:border-t-0 first:pt-0",children:[b,k,c.length===0?s.jsx("div",{className:"rounded-md p-3 typography-meta text-[var(--surface-muted-foreground)]",style:{backgroundColor:"color-mix(in srgb, var(--surface-muted) 45%, transparent)"},children:a}):s.jsx(Ns,{outerClassName:"max-h-64",className:"pr-1",children:s.jsx("div",{className:"space-y-1",children:c.map(j=>s.jsxs("div",{className:"rounded-md border border-[var(--interactive-border)] p-2",style:{backgroundColor:"color-mix(in srgb, var(--surface-elevated) 88%, transparent)"},children:[s.jsx("div",{className:"typography-meta font-medium text-[var(--surface-foreground)] break-all",children:j.metric}),s.jsxs("div",{className:"mt-1 grid grid-cols-4 gap-2 typography-meta text-[var(--surface-muted-foreground)]",children:[s.jsx("span",{children:i("memoryDebugPanel.metric.countValue",{value:j.count})}),s.jsx("span",{children:i("memoryDebugPanel.metric.avgValue",{value:j.avg})}),s.jsx("span",{children:i("memoryDebugPanel.metric.maxValue",{value:j.max})}),s.jsx("span",{children:i("memoryDebugPanel.metric.totalValue",{value:j.total})})]})]},j.metric))})})]}),e[0]=a,e[1]=r.durationMs,e[2]=r.entries,e[3]=r.lastUpdatedAt,e[4]=r.startedAt,e[5]=i,e[6]=n,e[7]=o}else o=e[7];return o},GA=t=>{const e=st.c(101),{onClose:n}=t,{t:r}=dt(),[a,i]=l.useState("memory"),[o,c]=l.useState("idle"),d=Lt(YA),p=hh(QA),m=El(),u=sh(XA),f=mr(ZA),[b,h]=l.useState(eD),[v,x]=l.useState(tD);let g;e[0]!==b.entries?(g=new Map,b.entries.forEach(Ae=>{g.set(Ae.metric,Ae.count)}),e[0]=b.entries,e[1]=g):g=e[1];let w;e[2]!==g?(w=g.get("ui.message_list.render")??0,e[2]=g,e[3]=w):w=e[3];let y;e[4]!==g?(y=g.get("ui.message_list.render.streaming")??0,e[4]=g,e[5]=y):y=e[5];let C;e[6]!==g?(C=g.get("ui.chat_message.render")??0,e[6]=g,e[7]=C):C=e[7];let k;e[8]!==g?(k=g.get("ui.chat_message.render.streaming")??0,e[8]=g,e[9]=k):k=e[9];let j;e[10]!==g?(j=g.get("ui.chat_message.render.static_during_stream")??0,e[10]=g,e[11]=j):j=e[11];let S;e[12]!==g?(S=g.get("ui.chat_message.render.static_outside_active_turn_during_stream")??0,e[12]=g,e[13]=S):S=e[13];let I;e[14]!==w||e[15]!==y||e[16]!==C||e[17]!==k||e[18]!==j||e[19]!==S?(I={messageListRender:w,messageListRenderStreaming:y,chatMessageRender:C,chatMessageRenderStreaming:k,chatMessageRenderStaticDuringStream:j,chatMessageRenderStaticOutsideActiveTurnDuringStream:S},e[14]=w,e[15]=y,e[16]=C,e[17]=k,e[18]=j,e[19]=S,e[20]=I):I=e[20];const M=I;let P,A;e[21]===Symbol.for("react.memo_cache_sentinel")?(P=()=>{const Ae=()=>{h(Ko()),x(Ho())};Ae();const pe=window.setInterval(Ae,500);return()=>window.clearInterval(pe)},A=[],e[21]=P,e[22]=A):(P=e[21],A=e[22]),l.useEffect(P,A);let N,E;e[23]!==o?(N=()=>{if(o==="idle")return;const Ae=window.setTimeout(()=>{c("idle")},1500);return()=>window.clearTimeout(Ae)},E=[o],e[23]=o,e[24]=N,e[25]=E):(N=e[24],E=e[25]),l.useEffect(N,E);let T=0,R;if(e[26]!==u?(R=Object.keys(u),e[26]=u,e[27]=R):R=e[27],e[28]!==u||e[29]!==R||e[30]!==T){for(const Ae of R)T=T+(u[Ae]?.length??0);e[28]=u,e[29]=R,e[30]=T,e[31]=T}else T=e[31];const V=T;let _;if(e[32]!==d||e[33]!==u||e[34]!==p||e[35]!==m||e[36]!==r){let Ae;e[38]!==d||e[39]!==u||e[40]!==p||e[41]!==r?(Ae=pe=>{const we=u[pe.id]?.length||0,Ie=p.get(pe.id);return{id:pe.id,title:pe.title||r("memoryDebugPanel.common.untitled"),messageCount:we,isStreaming:Ie?.isStreaming||!1,isZombie:Ie?.isZombie||!1,backgroundCount:Ie?.backgroundMessageCount||0,lastAccessed:Ie?.lastAccessedAt||0,isCurrent:pe.id===d}},e[38]=d,e[39]=u,e[40]=p,e[41]=r,e[42]=Ae):Ae=e[42],_=m.map(Ae).sort(sD),e[32]=d,e[33]=u,e[34]=p,e[35]=m,e[36]=r,e[37]=_}else _=e[37];const U=_;let B;e[43]!==u?(B=Object.keys(u),e[43]=u,e[44]=B):B=e[44];const z=B.length;let K;e[45]===Symbol.for("react.memo_cache_sentinel")?(K=async()=>{try{const Ae={generatedAt:new Date().toISOString(),ui:Ko(),vscode:Ho()};await navigator.clipboard.writeText(JSON.stringify(Ae,null,2)),c("copied")}catch{c("error")}},e[45]=K):K=e[45];const F=K;let G;e[46]===Symbol.for("react.memo_cache_sentinel")?(G={backgroundColor:"color-mix(in srgb, var(--surface-background) 94%, transparent)"},e[46]=G):G=e[46];let Q;e[47]!==a?(Q=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]=Q):Q=e[48];let te;e[49]!==r?(te=r("memoryDebugPanel.title"),e[49]=r,e[50]=te):te=e[50];let Z;e[51]!==te?(Z=s.jsx("h3",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:te}),e[51]=te,e[52]=Z):Z=e[52];let fe;e[53]!==Q||e[54]!==Z?(fe=s.jsxs("div",{className:"flex items-center gap-2",children:[Q,Z]}),e[53]=Q,e[54]=Z,e[55]=fe):fe=e[55];let ue;e[56]!==a?(ue=a==="streaming"?s.jsxs(s.Fragment,{children:[s.jsx(be,{size:"xs",variant:"ghost",onClick:F,children:s.jsx(D,{name:"file-copy",className:"h-3.5 w-3.5"})}),s.jsx(be,{size:"xs",variant:"ghost",onClick:()=>{sv(),h(Ko()),x(Ho())},children:s.jsx(D,{name:"refresh",className:"h-3.5 w-3.5"})})]}):null,e[56]=a,e[57]=ue):ue=e[57];let W;e[58]!==n?(W=n?s.jsx(be,{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]=W):W=e[59];let q;e[60]!==ue||e[61]!==W?(q=s.jsxs("div",{className:"flex items-center gap-1",children:[ue,W]}),e[60]=ue,e[61]=W,e[62]=q):q=e[62];let J;e[63]!==fe||e[64]!==q?(J=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-2",children:[fe,q]}),e[63]=fe,e[64]=q,e[65]=J):J=e[65];let ne;e[66]===Symbol.for("react.memo_cache_sentinel")?(ne={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[66]=ne):ne=e[66];const ee=a==="memory"?"secondary":"ghost";let he;e[67]===Symbol.for("react.memo_cache_sentinel")?(he=()=>i("memory"),e[67]=he):he=e[67];let ke;e[68]!==r?(ke=r("memoryDebugPanel.tabs.memory"),e[68]=r,e[69]=ke):ke=e[69];let oe;e[70]!==ee||e[71]!==ke?(oe=s.jsx(be,{size:"sm",variant:ee,className:"flex-1",onClick:he,children:ke}),e[70]=ee,e[71]=ke,e[72]=oe):oe=e[72];const ge=a==="streaming"?"secondary":"ghost";let me;e[73]===Symbol.for("react.memo_cache_sentinel")?(me=()=>i("streaming"),e[73]=me):me=e[73];let ye;e[74]!==r?(ye=r("memoryDebugPanel.tabs.streaming"),e[74]=r,e[75]=ye):ye=e[75];let ie;e[76]!==ge||e[77]!==ye?(ie=s.jsx(be,{size:"sm",variant:ge,className:"flex-1",onClick:me,children:ye}),e[76]=ge,e[77]=ye,e[78]=ie):ie=e[78];let ve;e[79]!==oe||e[80]!==ie?(ve=s.jsxs("div",{className:"mb-3 flex gap-1 rounded-md p-1",style:ne,children:[oe,ie]}),e[79]=oe,e[80]=ie,e[81]=ve):ve=e[81];let X;e[82]!==a||e[83]!==z||e[84]!==o||e[85]!==d||e[86]!==u||e[87]!==p||e[88]!==U||e[89]!==m||e[90]!==M||e[91]!==b||e[92]!==r||e[93]!==f||e[94]!==V||e[95]!==v?(X=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(dr,{label:r("memoryDebugPanel.metric.totalMessages"),value:V}),s.jsx(dr,{label:r("memoryDebugPanel.metric.cachedSessions"),value:`${z} / ${_u.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:tv()})})]}),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:_u.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(Ns,{outerClassName:"max-h-48",className:"space-y-1 pr-1",children:U.map(Ae=>s.jsxs("div",{className:"typography-meta flex items-center justify-between rounded p-1.5",style:{backgroundColor:Ae.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:Ae.title}),Ae.isStreaming?s.jsx(D,{name:"pulse",className:"h-3 w-3 animate-pulse text-[var(--status-info)]"}):null,Ae.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:Ae.messageCount})}),Ae.backgroundCount>0?s.jsxs("span",{className:"text-[var(--status-info)]",children:["+",Ae.backgroundCount]}):null]})]},Ae.id))})]}),s.jsx("div",{className:"flex gap-2 border-t border-[var(--interactive-border)] pt-2",children:s.jsxs(Ct,{children:[s.jsx(It,{asChild:!0,children:s.jsx(be,{size:"sm",variant:"outline",className:"typography-meta",onClick:()=>{console.log("[DebugPanel] Session store state:",{sessions:m.map(nD),currentSessionId:d,cachedSessions:Object.keys(u),memoryStates:Object.fromEntries(p)})},children:r("memoryDebugPanel.actions.logState")})}),s.jsx(At,{side:"top",children:r("memoryDebugPanel.tooltip.logCurrentState")})]})})]}):s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md border border-[var(--interactive-border)] px-3 py-2 typography-meta text-[var(--surface-muted-foreground)]",children:[s.jsx("span",{children:r(o==="copied"?"memoryDebugPanel.streaming.copy.copied":o==="error"?"memoryDebugPanel.streaming.copy.failed":"memoryDebugPanel.streaming.copy.hint")}),s.jsx(be,{size:"xs",variant:"outline",onClick:F,children:r("memoryDebugPanel.actions.copyJson")})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[s.jsx(dr,{label:r("memoryDebugPanel.metric.uiMetrics"),value:b.entries.length}),s.jsx(dr,{label:r("memoryDebugPanel.metric.vscodeMetrics"),value:v.entries.length}),s.jsx(dr,{label:r("memoryDebugPanel.metric.messageListRenders"),value:M.messageListRender}),s.jsx(dr,{label:r("memoryDebugPanel.metric.messageListStreamRenders"),value:M.messageListRenderStreaming}),s.jsx(dr,{label:r("memoryDebugPanel.metric.chatMessageRenders"),value:M.chatMessageRender}),s.jsx(dr,{label:r("memoryDebugPanel.metric.chatMessageStreamRenders"),value:M.chatMessageRenderStreaming}),s.jsx(dr,{label:r("memoryDebugPanel.metric.chatMessageStaticDuringStream"),value:M.chatMessageRenderStaticDuringStream}),s.jsx(dr,{label:r("memoryDebugPanel.metric.chatMessageStaticOutsideActiveTurn"),value:M.chatMessageRenderStaticOutsideActiveTurnDuringStream})]}),s.jsx(wf,{title:r("memoryDebugPanel.section.uiStreamingMetrics"),snapshot:b,emptyLabel:r("memoryDebugPanel.section.noUiSamples")}),v.entries.length>0?s.jsx(wf,{title:r("memoryDebugPanel.section.vscodeBridgeMetrics"),snapshot:v,emptyLabel:r("memoryDebugPanel.section.noVscodeSamples")}):null]}),e[82]=a,e[83]=z,e[84]=o,e[85]=d,e[86]=u,e[87]=p,e[88]=U,e[89]=m,e[90]=M,e[91]=b,e[92]=r,e[93]=f,e[94]=V,e[95]=v,e[96]=X):X=e[96];let Se;return e[97]!==J||e[98]!==ve||e[99]!==X?(Se=s.jsxs(gh,{className:"fixed bottom-4 right-4 z-50 w-[28rem] p-4 shadow-none bottom-safe-area",style:G,children:[J,ve,X]}),e[97]=J,e[98]=ve,e[99]=X,e[100]=Se):Se=e[100],Se},qA=GA;function JA(t,e){return t+e.count}function YA(t){return t.currentSessionId}function QA(t){return t.sessionMemoryState}function XA(t){return t.message}function ZA(t){return t.totalRequestCount}function eD(){return Ko()}function tD(){return Ho()}function sD(t,e){return e.lastAccessed-t.lastAccessed}function nD(t){return{id:t.id,title:t.title}}const rD=()=>{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()??"":""},aD=async()=>{const t=rD()||window.getSelection()?.toString()||"";if(!t.trim())return!1;try{if(typeof navigator<"u"&&navigator.clipboard?.writeText)return await navigator.clipboard.writeText(t),!0}catch{}return document.execCommand("copy")},jf="openchamber:menu-action",Bc="openchamber:check-for-updates",iD=t=>{const e=Lt(k=>k.openNewSessionDraft),n=Re(k=>k.toggleCommandPalette),r=Re(k=>k.setCommandPaletteOpen),a=Re(k=>k.toggleHelpDialog),i=Re(k=>k.toggleSidebar),o=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),h=Re(k=>k.setBottomTerminalExpanded),v=Ta(k=>k.checkForUpdates),{setThemeMode:x}=Cr(),g=l.useRef(!1),w=l.useCallback(()=>{g.current||(g.current=!0,v().then(()=>{const{available:k,error:j}=Ta.getState();if(j){H.error("Failed to check for updates",{description:j});return}k||H.success("You are on the latest version")}).finally(()=>{g.current=!1}))},[v]),y=l.useCallback(()=>{Nr.requestDirectoryDialog()},[]),C=l.useCallback(k=>{switch(k){case"about":p(!0);break;case"settings":d(!0);break;case"command-palette":n();break;case"quick-open":r(!0);break;case"new-session":c("chat"),o(!1),e();break;case"new-worktree-session":c("chat"),o(!1),lh();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":h(!Re.getState().isBottomTerminalExpanded);break;case"copy":{const j=new Event("openchamber:copy",{cancelable:!0});!window.dispatchEvent(j)||aD();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":{nv().catch(()=>{H.error("Failed to collect OpenCode status")});break}}},[y,t,e,p,c,o,r,d,h,u,f,x,b,n,a,m,i]);l.useEffect(()=>{const k=S=>{const I=S.detail;I&&C(I)},j=()=>{w()};return window.addEventListener(jf,k),window.addEventListener(Bc,j),()=>{window.removeEventListener(jf,k),window.removeEventListener(Bc,j)}},[C,w]),l.useEffect(()=>{if(typeof window>"u")return;const j=window.__TAURI__?.event?.listen;if(typeof j!="function")return;let S=null,I=null;return j("openchamber:menu-action",M=>{const P=M?.payload;typeof P=="string"&&C(P)}).then(M=>{S=M}).catch(()=>{}),j("openchamber:check-for-updates",()=>{window.dispatchEvent(new Event(Bc))}).then(M=>{I=M}).catch(()=>{}),()=>{(async()=>{try{const P=S?.();P instanceof Promise&&await P}catch{}try{const P=I?.();P instanceof Promise&&await P}catch{}})()}},[C])},oD=["chat","git","diff","terminal","files"],lD=["settings","agents","commands","skills","providers","usage","git-identities"],wr={SESSION:"session",TAB:"tab",SETTINGS:"settings",FILE:"file"};function Nf(t){const e=cD();return{sessionId:dD(e),tab:uD(e),settingsPath:mD(e),diffFile:pD(e)}}function cD(){if(typeof window>"u")return new URLSearchParams;try{return new URLSearchParams(window.location.search)}catch{return new URLSearchParams}}function dD(t){const e=t.get(wr.SESSION);return!e||e.trim().length===0?null:e.trim()}function uD(t){const e=t.get(wr.TAB);if(!e)return null;const n=e.toLowerCase().trim();return oD.includes(n)?n:null}function mD(t){const e=t.get(wr.SETTINGS);if(!e)return null;const n=e.toLowerCase().trim();return n.length===0?null:n==="openchamber"||n==="general"||n==="preferences"?"home":(lD.includes(n),n)}function pD(t){const e=t.get(wr.FILE);if(!e||e.trim().length===0)return null;try{return decodeURIComponent(e.trim())}catch{return e.trim()}}function Sf(){if(typeof window>"u")return!1;try{const t=new URLSearchParams(window.location.search);return t.has(wr.SESSION)||t.has(wr.TAB)||t.has(wr.SETTINGS)||t.has(wr.FILE)}catch{return!1}}const fD="chat";function Kg(t){const e=new URLSearchParams;if(t.sessionId&&t.sessionId.trim().length>0&&e.set(wr.SESSION,t.sessionId),t.isSettingsOpen){const n=t.settingsPath.trim().length>0?t.settingsPath:"home";return e.set(wr.SETTINGS,n),e}return t.tab!==fD&&e.set(wr.TAB,t.tab),t.tab==="diff"&&t.diffFile&&t.diffFile.trim().length>0&&e.set(wr.FILE,t.diffFile),e}function hD(t,e){const n=typeof window<"u"?window.location.pathname:"/",r=t.toString();return r?`${n}?${r}`:n}function gD(t){if(typeof window>"u")return!0;try{const e=new URLSearchParams(window.location.search),n=Kg(t),r=[...e.entries()].sort((i,o)=>i[0].localeCompare(o[0])),a=[...n.entries()].sort((i,o)=>i[0].localeCompare(o[0]));if(r.length!==a.length)return!1;for(let i=0;i<r.length;i++)if(r[i][0]!==a[i][0]||r[i][1]!==a[i][1])return!1;return!0}catch{return!0}}function xD(t,e={}){if(!(typeof window>"u")&&!bD()&&!(!e.force&&gD(t)))try{const n=Kg(t),r=hD(n);e.replace?window.history.replaceState({...window.history.state,route:t},"",r):window.history.pushState({route:t},"",r)}catch{}}function bD(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function yD(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function vD(){const t=l.useMemo(()=>yD(),[]),e=l.useRef(!1),n=l.useRef(!1),r=Lt(u=>u.setCurrentSession),a=Re(u=>u.setActiveMainTab),i=Re(u=>u.setSettingsDialogOpen),o=Re(u=>u.setSettingsPage),c=Re(u=>u.navigateToDiff),d=l.useCallback(async u=>{if(!n.current){n.current=!0;try{if(u.sessionId){const f=Lt.getState().currentSessionId;u.sessionId!==f&&await r(u.sessionId)}if(u.settingsPath){o(lg(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,o,c]),p=l.useCallback(()=>{const u=Lt.getState(),f=Re.getState();return{sessionId:u.currentSessionId,tab:f.activeMainTab,isSettingsOpen:f.isSettingsDialogOpen,settingsPath:f.settingsPage,diffFile:f.pendingDiffFile}},[]),m=l.useCallback((u={})=>{if(t||n.current)return;const f=p();xD(f,u)},[t,p]);l.useEffect(()=>{if(e.current||(e.current=!0,!Sf()))return;const u=Nf();(async()=>(await d(u),t||m({replace:!0})))()},[d,t,m]),l.useEffect(()=>{if(t)return;let u=Lt.getState().currentSessionId;return Lt.subscribe(b=>{const h=b.currentSessionId;h===u||n.current||(u=h,m())})},[t,m]),l.useEffect(()=>{if(t)return;let u=Re.getState().activeMainTab,f=Re.getState().isSettingsDialogOpen,b=Re.getState().settingsPage,h=Re.getState().pendingDiffFile;return Re.subscribe(x=>{if(n.current)return;const g=x.activeMainTab!==u,w=x.isSettingsDialogOpen!==f,y=x.settingsPage!==b,C=x.pendingDiffFile!==h&&x.activeMainTab==="diff";u=x.activeMainTab,f=x.isSettingsDialogOpen,b=x.settingsPage,h=x.pendingDiffFile,(g||w||y||C)&&m()})},[t,m]),l.useEffect(()=>{if(typeof window>"u"||t)return;const u=()=>{const f=Nf();if(Sf())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 wD="/api/notifications/stream",jD=()=>typeof document>"u"?!0:document.visibilityState==="visible"&&document.hasFocus(),ND=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}},SD=t=>{const e=st.c(3),n=t?.enabled??!0;let r,a;e[0]!==n?(r=()=>{if(!n||vn()||!Yr()||typeof window>"u"||typeof EventSource>"u")return;const i=new EventSource(wD);return i.onmessage=kD,()=>{i.close()}},a=[n],e[0]=n,e[1]=r,e[2]=a):(r=e[1],a=e[2]),l.useEffect(r,a)};function kD(t){let e;try{e=JSON.parse(t.data)}catch{return}const n=Re.getState();if(!n.nativeNotificationsEnabled||n.notificationMode!=="always"&&jD())return;const r=ND(e);if(!r)return;Xn()?.notifications?.notifyAgentCompletion(r)}const CD=t=>!(t.dismissed==="true"||t.sessionShown==="true"||t.hasActiveToast),ID=t=>!(!t.version||t.seenVersions.has(t.version)||t.dismissedVersion!==null&&t.dismissedVersion===t.version),PD=t=>{if(t===null||typeof t!="object")return"";const e=t.version;return typeof e!="string"?"":e.trim()},AD=t=>!t||t.available!==!0||typeof t.latestVersion!="string"?"":t.latestVersion.trim(),kf="pwa-install-toast-shown",Cf="pwa-install-toast-dismissed",DD=()=>{const t=st.c(6),{browserTab:e}=wg(),{t:n}=dt(),r=l.useRef(n);let a,i;t[0]!==n?(a=()=>{r.current=n},i=[n],t[0]=n,t[1]=a,t[2]=i):(a=t[1],i=t[2]),l.useEffect(a,i);let o,c;t[3]!==e?(o=()=>{if(typeof window>"u"||!Yr()||!e)return;let d=null,p=null;const m=()=>{p!==null&&(H.dismiss(p),p=null)},u=async()=>{if(!d)return;const h=d;d=null,m(),await h.prompt();const{outcome:v}=await h.userChoice;v==="accepted"&&H.success(r.current("pwa.installPrompt.started"))},f=h=>{const v=h;if(typeof v.prompt!="function")return;v.preventDefault(),d=v;const x=vr(),g=zf();CD({dismissed:x.getItem(Cf),sessionShown:g.getItem(kf),hasActiveToast:p!==null})&&(g.setItem(kf,"true"),p=H.info(r.current("pwa.installPrompt.description"),{duration:1/0,action:{label:r.current("pwa.installPrompt.action"),onClick:()=>{u()}},cancel:{label:r.current("pwa.installPrompt.dismiss"),onClick:()=>{vr().setItem(Cf,"true"),m()}}}))},b=()=>{d=null,m(),H.success(r.current("pwa.installPrompt.installed"))};return window.addEventListener("beforeinstallprompt",f),window.addEventListener("appinstalled",b),()=>{m(),window.removeEventListener("beforeinstallprompt",f),window.removeEventListener("appinstalled",b)}},c=[e],t[3]=e,t[4]=o,t[5]=c):(o=t[4],c=t[5]),l.useEffect(o,c)},TD=["local","remote",null],MD=["ok","not-configured","unreachable","wrong-service","missing"];function Hg(t){if(!t||typeof t!="object")return{valid:!1};const e=t,n=e.target,r=e.status;if(n!==null&&(typeof n!="string"||!TD.includes(n)))return{valid:!1};if(typeof r!="string"||!MD.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 If(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 ED(t){return t.isDesktopShell?t.bootOutcomeKnown?t.bootViewIsMain===!1?!0:t.isInitialized:!1:t.isInitialized}function RD(t){return t.isTauriShell&&!t.isDesktopLocalOriginActive}function Pf(){if(Cd()!=="valid")return null;const e=window.__OPENCHAMBER_DESKTOP_BOOT_OUTCOME__,n=Hg(e);return n.valid?n.outcome:null}function Cd(){if(typeof window>"u")return"not-injected";const t=window.__OPENCHAMBER_DESKTOP_BOOT_OUTCOME__;return t==null?"not-injected":Hg(t).valid?"valid":"malformed"}const FD=()=>{const t=st.c(5),[e,n]=l.useState(OD),{isUpdating:r,message:a}=e;let i,o;if(t[0]===Symbol.for("react.memo_cache_sentinel")?(i=()=>av(n),o=[],t[0]=i,t[1]=o):(i=t[0],o=t[1]),l.useEffect(i,o),!r)return null;let c;t[2]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(Ld,{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 OD(){return rv()}const LD=({open:t,onOpenChange:e})=>{const{t:n}=dt(),r=!1,[a,i]=l.useState(null),[o,c]=l.useState(null),[d,p]=l.useState(!1),[m,u]=l.useState(!1),[f,b]=l.useState(null),[h,v]=l.useState(!1);l.useCallback(async()=>{},[f,d,r,n]),l.useEffect(()=>{if(!t)return;(async()=>{try{const w=await fetch("/api/system/info");if(w.ok){const y=await w.json();if(typeof y.openchamberVersion=="string"&&y.openchamberVersion.trim()){i(y.openchamberVersion);return}}}catch{}i(await iv())})()},[t]),l.useEffect(()=>{if(!t)return;let g=!1;return(async()=>{try{const y=await fetch("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!y.ok)return;const C=await y.json().catch(()=>null),k=typeof C?.currentVersion=="string"?C.currentVersion.trim():"";!g&&k&&c(k)}catch{}})(),()=>{g=!0}},[t]),l.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(Ld,{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})}),o&&s.jsx("p",{children:n("aboutDialog.openCodeVersionLabel",{version:o})})]})]}),r,s.jsxs("div",{className:"flex flex-col items-center gap-2 pt-2",children:[s.jsxs("div",{className:"flex items-center justify-center gap-4",children:[s.jsxs("a",{href:"https://github.com/btriapitsyn/openchamber",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(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")})]})})})},zc=(t,e)=>{const n=t.get(e);return typeof n!="string"?null:n.trim()||null},$D=(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},_D=()=>{const t=bn(i=>i.completeAuth),[e,n]=l.useState("working"),[r,a]=l.useState("Completing MCP authorization...");return l.useEffect(()=>{if(typeof window>"u"){n("error"),a("Browser context unavailable.");return}const i=new URLSearchParams(window.location.search),o=zc(i,"code"),c=pg(i),d=Xd(i),p=zc(i,"error"),m=zc(i,"error_description");if(p){d&&fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("error"),a(m??p);return}(async()=>{try{if(!o)throw new Error("Missing OAuth authorization code. Start authorization again from MCP Settings or paste the returned code into OpenChamber manually.");let u=c;if(!u&&d){const f=await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`);if(f.ok){const b=await f.json().catch(()=>null);b?.name?.trim()&&(u={name:b.name.trim(),directory:typeof b.directory=="string"&&b.directory.trim()?b.directory.trim():null})}}if(!u?.name)throw new Error("Authorization session details were not available. Start authorization again from MCP Settings or paste the returned code into OpenChamber manually.");await t(u.name,o,u.directory),d&&await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("success"),a("Authorization completed. You can close this tab and return to OpenChamber.")}catch(u){d&&await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("error"),a($D(u,"Failed to complete MCP authorization."))}})()},[t]),s.jsx("div",{className:"flex min-h-screen items-center justify-center bg-background px-6 py-12 text-foreground",children:s.jsxs("div",{className:"w-full max-w-xl rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-8 shadow-sm",children:[s.jsxs("div",{className:"space-y-3 text-center",children:[s.jsx("div",{className:e==="error"?"text-[var(--status-error)]":e==="success"?"text-[var(--status-success)]":"text-[var(--status-info)]",children:s.jsx("h1",{className:"typography-hero font-semibold",children:e==="working"?"Completing Authorization":e==="success"?"Authorization Complete":"Authorization Failed"})}),s.jsx("p",{className:"typography-body text-muted-foreground",children:r})]}),e!=="working"&&s.jsx("div",{className:"mt-8 flex justify-center",children:s.jsx(be,{type:"button",onClick:()=>{typeof window>"u"||window.location.replace("/")},children:"Return to OpenChamber"})})]})})},Li="opencode-update-available",zo="opencode-upgrade-progress",BD=5e3,zD=[1e4,6e4],Af="opencode-update-toast-dismissed-version",Gg=()=>{const{t}=dt(),e=Re(o=>o.showOpenCodeUpdateNotifications),n=Oe.useRef(new Set),r=Oe.useRef(!1);Oe.useEffect(()=>{e||H.dismiss(Li)},[e]);const a=Oe.useCallback(()=>{H.dismiss(zo),ni({message:t("opencodeUpdate.toast.reload.message"),mode:"projects",scopes:["all"]})},[t]),i=Oe.useCallback(async()=>{if(!r.current){r.current=!0,H.dismiss(Li),H.message(t("opencodeUpdate.toast.upgrading.title"),{id:zo,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 o=await fetch("/api/opencode/upgrade",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),c=await o.json().catch(()=>null);if(!o.ok||c?.success===!1)throw new Error(c?.error||o.statusText||t("opencodeUpdate.toast.failed.description"));H.success(t("opencodeUpdate.toast.updated.title"),{id:zo,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(o){H.error(t("opencodeUpdate.toast.failed.title"),{id:zo,description:o instanceof Error?o.message:t("opencodeUpdate.toast.failed.description"),duration:1/0})}finally{r.current=!1}}},[a,t]);return Oe.useEffect(()=>{const o=u=>{if(!Re.getState().showOpenCodeUpdateNotifications){H.dismiss(Li);return}ID({version:u,dismissedVersion:vr().getItem(Af),seenVersions:n.current})&&(n.current.add(u),H.info(t("opencodeUpdate.toast.available.title"),{id:Li,description:t("opencodeUpdate.toast.available.description",{version:u}),duration:1/0,action:{label:t("opencodeUpdate.toast.actions.update"),onClick:i},cancel:{label:t("opencodeUpdate.toast.actions.dismiss"),onClick:()=>{vr().setItem(Af,u),H.dismiss(Li)}}}))},c=u=>{const f=PD(u.detail);o(f)};let d=!1;const p=[],m=async u=>{try{const f=await fetch("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!f.ok)throw new Error(f.statusText||"OpenCode upgrade status check failed");const b=await f.json().catch(()=>null),h=AD(b);!d&&h&&o(h)}catch{const f=zD[u];!d&&f!==void 0&&p.push(setTimeout(()=>{m(u+1)},f))}};return e&&p.push(setTimeout(()=>{m(0)},BD)),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},Df=ea(()=>Sr(()=>import("./OnboardingScreen-AGACaSpL.js"),__vite__mapDeps([9,0,1,2,3,4])).then(t=>({default:t.OnboardingScreen}))),VD=()=>{const t=st.c(3),e=Re(qD),n=Re(JD);let r;return t[0]!==e||t[1]!==n?(r=s.jsx(LD,{open:e,onOpenChange:n}),t[0]=e,t[1]=n,t[2]=r):r=t[2],r},UD=t=>{const e=st.c(21),{onRetry:n,isRetrying:r}=t,{t:a}=dt();let i;e[0]!==a?(i=a("startup.initRecovery.title"),e[0]=a,e[1]=i):i=e[1];let o;e[2]!==i?(o=s.jsx("h1",{className:"typography-title text-foreground",children:i}),e[2]=i,e[3]=o):o=e[3];let c;e[4]!==a?(c=a("startup.initRecovery.description"),e[4]=a,e[5]=c):c=e[5];let d;e[6]!==c?(d=s.jsx("p",{className:"typography-body text-muted-foreground",children:c}),e[6]=c,e[7]=d):d=e[7];let p;e[8]!==o||e[9]!==d?(p=s.jsxs("div",{className:"flex flex-col gap-2",children:[o,d]}),e[8]=o,e[9]=d,e[10]=p):p=e[10];let m;e[11]!==r||e[12]!==a?(m=a(r?"startup.initRecovery.retrying":"startup.initRecovery.retry"),e[11]=r,e[12]=a,e[13]=m):m=e[13];let u;e[14]!==r||e[15]!==n||e[16]!==m?(u=s.jsx(be,{type:"button",onClick:n,disabled:r,children:m}),e[14]=r,e[15]=n,e[16]=m,e[17]=u):u=e[17];let f;return e[18]!==p||e[19]!==u?(f=s.jsx("div",{className:"flex h-full items-center justify-center bg-background px-6 text-foreground",children:s.jsxs("div",{className:"flex max-w-md flex-col items-center gap-4 text-center",children:[p,u]})}),e[18]=p,e[19]=u,e[20]=f):f=e[20],f},Tf=t=>t?t.replace(/\\/g,"/").replace(/\/+$/g,""):"",WD=()=>{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"}},KD=()=>typeof window>"u"?!1:window.location.pathname===mg,HD=t=>{const e=st.c(23),{embeddedSessionChat:n,isVSCodeRuntime:r,embeddedBackgroundWorkEnabled:a}=t,i=zs(YD),o=Lt(QD),c=Lt(XD),d=zd(),p=l.useRef(null);let m;e[0]!==n.directory?(m=Tf(n.directory),e[0]=n.directory,e[1]=m):m=e[1];const u=m;let f;e[2]!==i?(f=Tf(i),e[2]=i,e[3]=f):f=e[3];const b=f;let h,v;if(e[4]!==b||e[5]!==o||e[6]!==n.directory||e[7]!==n.sessionId||e[8]!==u||e[9]!==r||e[10]!==c||e[11]!==d?(h=()=>{if(r||u&&b!==u)return;const k=`${u}
227
+ ${n.sessionId}`;p.current===k&&o===n.sessionId||(p.current=k,c(n.sessionId,n.directory),d.ensureSessionRenderable(n.sessionId,!0))},v=[b,o,n.directory,n.sessionId,u,r,c,d],e[4]=b,e[5]=o,e[6]=n.directory,e[7]=n.sessionId,e[8]=u,e[9]=r,e[10]=c,e[11]=d,e[12]=h,e[13]=v):(h=e[12],v=e[13]),l.useEffect(h,v),u&&b!==u)return null;let x;e[14]!==a?(x=s.jsx(xh,{embeddedBackgroundWorkEnabled:a}),e[14]=a,e[15]=x):x=e[15];let g;e[16]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(Gg,{}),e[16]=g):g=e[16];let w;e[17]!==n.readOnly?(w=s.jsx(kd,{readOnly:n.readOnly}),e[17]=n.readOnly,e[18]=w):w=e[18];let y;e[19]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx(bh,{}),e[19]=y):y=e[19];let C;return e[20]!==x||e[21]!==w?(C=s.jsxs(s.Fragment,{children:[x,g,w,y]}),e[20]=x,e[21]=w,e[22]=C):C=e[22],C};function GD({apis:t}){const e=bt(W=>W.initializeApp),n=bt(W=>W.isInitialized),r=bt(W=>W.isConnected),a=bt(W=>W.providers.length),i=bt(W=>W.agents.length),o=bt(W=>W.loadProviders),c=bt(W=>W.loadAgents),d=Lt(W=>W.error),p=Lt(W=>W.clearError),m=zs(W=>W.currentDirectory),u=zs(W=>W.setDirectory),f=zs(W=>W.isSwitchingDirectory),[b,h]=l.useState(!1),v=Bn(W=>W.refreshStatus),[x,g]=l.useState(()=>t.runtime.isVSCode),[w,y]=l.useState(!0),[C,k]=l.useState(!1),[j,S]=l.useState(0),[I,M]=l.useState(!1),P=Re(W=>W.wideChatLayoutEnabled),A=Re(W=>W.mobileKeyboardMode),N=l.useMemo(()=>vn(),[]),E=Ad(W=>W.setPlanModeEnabled),[T,R]=l.useState(()=>Cd()),[V,_]=l.useState(()=>{const W=Pf();return W!==null?If({isDesktopShell:!0,bootOutcome:W}):null}),U=l.useRef(!1),B=l.useMemo(()=>WD(),[]),z=!B||w,K=l.useMemo(()=>KD(),[]);l.useEffect(()=>(Bu(b),()=>{Bu(!1)}),[b]),l.useEffect(()=>{ov(A)},[A]),l.useEffect(()=>{g(t.runtime.isVSCode)},[t.runtime.isVSCode]),l.useEffect(()=>(document.documentElement.classList.toggle("wide-chat-layout",P),()=>{document.documentElement.classList.remove("wide-chat-layout")}),[P]),l.useEffect(()=>(zu(t),()=>zu(null)),[t]),l.useEffect(()=>{B||v(t.github,{force:!0})},[t.github,B,v]),lv();const F=T==="valid",G=V?.screen==="main";l.useEffect(()=>{if(!ED({isDesktopShell:N,isInitialized:n,bootOutcomeKnown:F,bootViewIsMain:G}))return;const W=setTimeout(()=>{const q=document.getElementById("initial-loading");q&&(q.classList.add("fade-out"),setTimeout(()=>{q.remove()},300))},150);return()=>clearTimeout(W)},[N,n,F,G]),l.useEffect(()=>{if(!N||T!=="malformed")return;const W=document.getElementById("initial-loading");W&&(W.textContent="Desktop startup failed — please restart the app.")},[N,T]),l.useEffect(()=>{if(N)return;const W=setTimeout(()=>{const q=document.getElementById("initial-loading");q&&!n&&(q.classList.add("fade-out"),setTimeout(()=>{q.remove()},300))},5e3);return()=>clearTimeout(W)},[N,n]),l.useEffect(()=>{let W=!1;return(async()=>{const J=await fetch("/health",{method:"GET"}).catch(()=>null);if(!J||!J.ok||W)return;const ne=await J.json().catch(()=>null);if(!ne||W)return;const ee=ne.planModeExperimentalEnabled;E(ee===!0||ee===1||ee==="1"||ee==="true")})(),()=>{W=!0}},[E]),l.useEffect(()=>{x||e()},[e,x]),l.useEffect(()=>{if(x||n)return;let W=!0,q,J=0;const ne=10,ee=1e3,he=async()=>{if(!W)return;if(J>=ne){k(!0);return}const ke=bt.getState();if(ke.isInitialized){k(!1);return}J+=1,await ke.initializeApp();const oe=bt.getState();if(!W)return;if(oe.isInitialized){k(!1);return}if(J>=ne){k(!0);return}const ge=Math.min(ee*Math.pow(2,J-1),16e3);q=setTimeout(he,ge)};return q=setTimeout(he,ee),()=>{W=!1,q&&clearTimeout(q)}},[j,n,x]),l.useEffect(()=>{n&&k(!1)},[n]),l.useEffect(()=>{if(!C)return;const W=document.getElementById("initial-loading");W&&(W.classList.add("fade-out"),setTimeout(()=>{W.remove()},300))},[C]),l.useEffect(()=>{if(x||!r||a>0&&i>0)return;let W=!0,q=0;const J=15,ne=async()=>{const he=bt.getState();if(!(he.providers.length>0&&he.agents.length>0))try{he.providers.length===0&&await o(),bt.getState().agents.length===0&&await c()}catch{}};ne();const ee=setInterval(()=>{if(W){if(++q>=J){clearInterval(ee);return}ne()}},2e3);return()=>{W=!1,clearInterval(ee)}},[r,x,c,o,a,i]),l.useEffect(()=>{f||x||r&&sn.setDirectory(m)},[m,f,r,x]),l.useEffect(()=>{if(!B||typeof window>"u")return;const W=ne=>{const ee=ne?.visible===!0;y(ee)},q=ne=>{if(ne.origin!==window.location.origin)return;const ee=ne.data;ee?.type==="openchamber:embedded-visibility"&&W(ee.payload)},J=window;return J.__openchamberSetEmbeddedVisibility=W,window.addEventListener("message",q),()=>{window.removeEventListener("message",q),J.__openchamberSetEmbeddedVisibility===W&&delete J.__openchamberSetEmbeddedVisibility}},[B]),l.useEffect(()=>{!B?.directory||x||m!==B.directory&&u(B.directory,{showOverlay:!1})},[m,B,x,u]),l.useEffect(()=>{if(!B||typeof window>"u")return;const W=q=>{q.storageArea===window.localStorage&&q.key==="ui-store"&&Re.persist.rehydrate()};return window.addEventListener("storage",W),()=>{window.removeEventListener("storage",W)}},[B]),l.useEffect(()=>{if(typeof window>"u")return;const W=q=>{const J=q.detail,ne=typeof J?.sessionId=="string"?J.sessionId.trim():"";if(!ne)return;const ee=typeof J?.directory=="string"&&J.directory.trim().length>0?J.directory.trim():null;Re.getState().setActiveMainTab("chat"),Lt.getState().setCurrentSession(ne,ee)};return window.addEventListener("openchamber:open-session",W),()=>window.removeEventListener("openchamber:open-session",W)},[]),l.useEffect(()=>{if(typeof window>"u")return;const W=q=>{const J=q.detail,ne=typeof J?.directory=="string"&&J.directory.trim().length>0?J.directory.trim():null,ee=typeof J?.projectId=="string"&&J.projectId.trim().length>0?J.projectId.trim():null;Re.getState().setActiveMainTab("chat"),Re.getState().setSessionSwitcherOpen(!1),Lt.getState().openNewSessionDraft({selectedProjectId:ee,directoryOverride:ne,preserveDirectoryOverride:!!ne})};return window.addEventListener("openchamber:open-draft-session",W),()=>window.removeEventListener("openchamber:open-draft-session",W)},[]),l.useEffect(()=>{if(typeof window>"u")return;const W=q=>{const J=q.detail,ne=typeof J?.projectPath=="string"?J.projectPath.trim():"";if(!ne)return;const ee=Ps.getState(),he=ee.projects.find(ke=>ke.path===ne);he?ee.setActiveProject(he.id):ee.addProject(ne)};return window.addEventListener("openchamber:open-project",W),()=>window.removeEventListener("openchamber:open-project",W)},[]),l.useEffect(()=>{typeof window>"u"||!n||f||U.current||(U.current=!0,window.__openchamberAppReady=!0,window.dispatchEvent(new Event("openchamber:app-ready")))},[n,f]),cv({enabled:z}),SD({enabled:z}),DD(),dv(),vD();const Q=l.useCallback(()=>{h(W=>!W)},[]);iD(Q),l.useEffect(()=>{if(B)return;const W=q=>{Dd(q)&&q.shiftKey&&!q.altKey&&(q.code==="KeyD"||q.key.toLowerCase()==="d")&&(q.preventDefault(),h(ne=>!ne))};return window.addEventListener("keydown",W,!0),()=>window.removeEventListener("keydown",W,!0)},[B]),l.useEffect(()=>{B||d&&setTimeout(()=>p(),5e3)},[p,B,d]),l.useEffect(()=>{if(!N||T!=="not-injected")return;let W=!1,q=0;const J=200,ne=2e3,ee=50,he=()=>{if(W)return;q++;const ke=Cd();if(ke!=="not-injected"){if(W=!0,R(ke),ke==="valid"){const ge=Pf();ge&&_(If({isDesktopShell:!0,bootOutcome:ge}))}return}const oe=Math.min(J*Math.pow(1.1,q),ne);if(q>=ee){const ge=document.getElementById("initial-loading");ge&&!ge.textContent?.includes("taking longer")&&(ge.textContent="Desktop startup is taking longer than expected...")}window.setTimeout(he,oe)};return window.setTimeout(he,J),()=>{W=!0}},[N,T]);const te=l.useCallback(async()=>{if(RD({isTauriShell:Ea(),isDesktopLocalOriginActive:Qr()})){await ih();return}window.location.reload()},[]),Z=l.useCallback(async()=>{if(!I){k(!1),M(!0);try{await bt.getState().initializeApp()}finally{M(!1)}bt.getState().isInitialized||S(W=>W+1)}},[I]),fe=W=>{if(W.screen==="recovery")return W.variant};if(N&&V&&V.screen!=="main"){if(V.screen==="chooser")return s.jsx(Ys,{children:s.jsx("div",{className:"h-full text-foreground bg-transparent",children:s.jsx(l.Suspense,{fallback:s.jsx("div",{className:"h-full"}),children:s.jsx(Df,{mode:"first-launch",onCliAvailable:te,onChooseRemote:()=>{}})})})});const W=fe(V),q=V.screen==="recovery"&&"url"in V?V.url:void 0;return s.jsx(Ys,{children:s.jsx("div",{className:"h-full text-foreground bg-transparent",children:s.jsx(l.Suspense,{fallback:s.jsx("div",{className:"h-full"}),children:s.jsx(Df,{mode:"recovery",recoveryVariant:W,recoveryHostUrl:q,recoveryHostLabel:void 0,onCliAvailable:te})})})})}if(B)return s.jsx(Ys,{children:s.jsx(Vu,{sdk:sn.getSdkClient(),directory:m||"",children:s.jsx(Uu,{apis:t,children:s.jsx(Wu,{delayDuration:300,skipDelayDuration:150,children:s.jsx("div",{className:"h-full text-foreground bg-background",children:s.jsx(HD,{embeddedSessionChat:B,isVSCodeRuntime:x,embeddedBackgroundWorkEnabled:z})})})})})});if(K)return s.jsx(Ys,{children:s.jsx(_D,{})});if(C&&!n&&!x&&!B)return s.jsx(Ys,{children:s.jsx(UD,{onRetry:()=>{Z()},isRetrying:I})});const ue=!n&&!N;return s.jsx(Ys,{children:s.jsx(Vu,{sdk:sn.getSdkClient(),directory:m||"",children:s.jsx(Uu,{apis:t,children:s.jsx(Fw,{children:s.jsx(uv,{children:s.jsx(Wu,{delayDuration:300,skipDelayDuration:150,children:s.jsxs("div",{className:N?"h-full text-foreground bg-transparent":"h-full text-foreground bg-background",children:[s.jsx(xh,{embeddedBackgroundWorkEnabled:z}),s.jsx(Gg,{}),s.jsx(KA,{}),s.jsx(bh,{}),!ue&&s.jsxs(s.Fragment,{children:[s.jsx(FD,{}),s.jsx(VD,{}),b&&s.jsx(qA,{onClose:()=>h(!1)})]})]})})})})})})})}function qD(t){return t.isAboutDialogOpen}function JD(t){return t.setAboutDialogOpen}function YD(t){return t.currentDirectory}function QD(t){return t.currentSessionId}function XD(t){return t.setCurrentSession}const ZD=typeof window<"u"&&window.__OPENCHAMBER_RUNTIME_APIS__||(()=>{throw new Error("Runtime APIs not provided for legacy UI entrypoint.")})();mv();pv().then(()=>{Promise.all([fv(),hv()]).catch(t=>{console.error("[main] settings init failed:",t)}),gv(),xv(),bv()}).catch(t=>{console.error("[main] appearance init failed:",t)});const qg=document.getElementById("root");if(!qg)throw new Error("Root element not found");Fx.createRoot(qg).render(s.jsx(Oe.StrictMode,{children:s.jsx(yv,{children:s.jsx(vv,{children:s.jsx(wv,{children:s.jsx(jv,{children:s.jsx(GD,{apis:ZD})})})})})}));const lT=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"}));export{AA as M,Go as P,$r as S,i4 as a,lT as m,rn as u};