@openchamber/web 1.11.1 → 1.11.2

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 (42) hide show
  1. package/dist/assets/{JsonTreeView-bLRkNPS9.js → JsonTreeView-9F0tH9yA.js} +1 -1
  2. package/dist/assets/{MarkdownRendererImpl-FSTq-eVA.js → MarkdownRendererImpl-C3QofAGm.js} +1 -1
  3. package/dist/assets/{MultiRunWindow-DezP_Pyy.js → MultiRunWindow-wnUGv0Dl.js} +1 -1
  4. package/dist/assets/{OnboardingScreen-CeZMVgH8.js → OnboardingScreen-17dAs0NH.js} +2 -2
  5. package/dist/assets/{SettingsWindow-Dlfk0yzA.js → SettingsWindow-BgyVY5gz.js} +1 -1
  6. package/dist/assets/TerminalView-D11XIZuz.js +1 -0
  7. package/dist/assets/{ToolOutputDialog-CePopKV7.js → ToolOutputDialog-DFG7ANVw.js} +6 -6
  8. package/dist/assets/es-Chl2Hu6K.js +15 -0
  9. package/dist/assets/index-0bVkxg-Z.css +1 -0
  10. package/dist/assets/{index-CKlDk4Io.js → index-BV2XTsJJ.js} +1 -1
  11. package/dist/assets/ko-BSrH3F9n.js +15 -0
  12. package/dist/assets/{main-BvaFBcXN.js → main-BHkNwOz1.js} +2 -2
  13. package/dist/assets/main-Bqf4fXgq.js +225 -0
  14. package/dist/assets/miniChat-BmB-E5xo.js +2 -0
  15. package/dist/assets/{modelPrefsAutoSave-HUPrH1r2.js → modelPrefsAutoSave-2uwW8uD9.js} +98 -96
  16. package/dist/assets/pl-YlGvPmFg.js +15 -0
  17. package/dist/assets/pt-BR-BonIMDN_.js +15 -0
  18. package/dist/assets/{renderElectronMiniChatApp-EXGwfTjq.js → renderElectronMiniChatApp-B_qrXCU2.js} +2 -2
  19. package/dist/assets/uk-lPqA3MHn.js +15 -0
  20. package/dist/assets/{vendor-.bun-BFTPeDgG.js → vendor-.bun-Boz6Tqcq.js} +20 -20
  21. package/dist/assets/zh-CN-C5nQQsUL.js +15 -0
  22. package/dist/index.html +4 -4
  23. package/dist/mini-chat.html +4 -4
  24. package/package.json +1 -1
  25. package/server/lib/git/DOCUMENTATION.md +1 -0
  26. package/server/lib/git/routes.js +26 -0
  27. package/server/lib/git/service.js +96 -10
  28. package/server/lib/git/service.test.js +39 -0
  29. package/server/lib/opencode/settings-helpers.js +10 -1
  30. package/server/lib/opencode/settings-helpers.test.js +35 -0
  31. package/server/lib/opencode/skill-routes.js +43 -49
  32. package/server/lib/opencode/skills.js +78 -10
  33. package/dist/assets/TerminalView-CdCfCaFq.js +0 -1
  34. package/dist/assets/es-CyjenLd8.js +0 -15
  35. package/dist/assets/index-NnYXwoao.css +0 -1
  36. package/dist/assets/ko-Cs7yF9Jn.js +0 -15
  37. package/dist/assets/main-DcpUnRRo.js +0 -225
  38. package/dist/assets/miniChat-Dmzb8Mwv.js +0 -2
  39. package/dist/assets/pl-XjTt7Hsk.js +0 -15
  40. package/dist/assets/pt-BR-knvpJ94d.js +0 -15
  41. package/dist/assets/uk-DUPvcQAj.js +0 -15
  42. package/dist/assets/zh-CN-DWiTG93s.js +0 -15
@@ -1,225 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-.bun-BFTPeDgG.js","assets/vendor--V65Sl9C2.css","assets/modelPrefsAutoSave-HUPrH1r2.js","assets/index-CKlDk4Io.js","assets/index-NnYXwoao.css","assets/TerminalView-CdCfCaFq.js","assets/JsonTreeView-bLRkNPS9.js","assets/SettingsWindow-Dlfk0yzA.js","assets/MultiRunWindow-DezP_Pyy.js","assets/OnboardingScreen-CeZMVgH8.js"])))=>i.map(i=>d[i]);
2
- import{c as at,R as l,u as Qo,a as Li,j as s,b as Sd,C as kd,P as Yo,S as Vc,d as Fg,D as Xo,e as Zo,f as el,g as tr,i as gi,r as Be,k as Lg,l as Og,p as Zi,m as vl,n as $g,o as Bg,q as _g,_ as vr,s as Oi,t as Fa,v as Vg,w as pr,W as zg,x as Ug,V as Wg,F as Kg,y as Hg,E as Gg,z as Yn,A as qg,B as xi,G as ru,H as Jg,I as Qg,J as Vl,K as Yg,L as Xg,M as Zg,N as au,O as iu,Q as ex,T as jh,U as Nh,X as tx,Y as ou,Z as sx,$ as nx,a0 as rx,a1 as ax,a2 as ix,a3 as ox,a4 as lx,a5 as Sh,a6 as cx,a7 as zc,a8 as kh,a9 as Ch,aa as Xa,ab as Ti,ac as Uc,ad as lt,ae as Ih,af as Ph,ag as dx,ah as ux,ai as mx,aj as px,ak as hx,al as fx,am as gx,an as xx,ao as bx,ap as lu,aq as yx,ar as vx,as as cu,at as du,au as zl,av as wx}from"./vendor-.bun-BFTPeDgG.js";import{a as jx,b as Nx,f as Sx}from"./index-CKlDk4Io.js";import{u as pt,a as Te,b as an,c as me,I,d as Ds,i as dn,g as dr,e as Zr,s as Ul,r as Wl,f as Kl,h as Fs,o as rn,j as Vs,T as kt,k as Ct,l as Pt,m as Ia,n as Vr,p as uu,D as zt,q as kx,t as tl,v as Rn,w as H,x as Os,y as Dn,z as $s,A as Bs,B as Ah,C as mu,E as Cx,F as Ix,G as pu,H as Px,J as Ax,K as Dx,L as Tx,M as _n,N as yn,O as Xn,P as Wc,Q as Sn,R as $i,S as Mx,U as gt,V as Vt,W as Ex,X as Dh,Y as ja,Z as Cd,_ as Kn,$ as Id,a0 as wl,a1 as Rx,a2 as hu,a3 as Fx,a4 as Lx,a5 as Th,a6 as Ox,a7 as $x,a8 as Mh,a9 as Pd,aa as sl,ab as Eh,ac as jl,ad as Br,ae as Ad,af as Oo,ag as Bx,ah as _x,ai as Xs,aj as Rh,ak as Fh,al as Kt,am as Ts,an as Pr,ao as oi,ap as Vx,aq as Lh,ar as Cs,as as js,at as we,au as vs,av as ws,aw as Pa,ax as zx,ay as Ux,az as ho,aA as kn,aB as Oh,aC as $h,aD as Nl,aE as Wx,aF as Kx,aG as fu,aH as bn,aI as xs,aJ as Hx,aK as Gx,aL as qx,aM as Jx,aN as Qx,aO as Yx,aP as Xx,aQ as Ws,aR as Zx,aS as eb,aT as Rs,aU as tb,aV as sb,aW as nb,aX as rb,aY as br,aZ as eo,a_ as ab,a$ as Ks,b0 as ds,b1 as us,b2 as ys,b3 as ms,b4 as Lt,b5 as ib,b6 as Aa,b7 as ob,b8 as Er,b9 as Dd,ba as Sl,bb as lb,bc as Td,bd as cb,be as db,bf as Md,bg as ub,bh as nn,bi as to,bj as yr,bk as mb,bl as pb,bm as Hl,bn as kl,bo as Ed,bp as Rd,bq as Cl,br as $n,bs as Fd,bt as Da,bu as Il,bv as Za,bw as li,bx as ci,by as gu,bz as nl,bA as rl,bB as Wi,bC as di,bD as Bh,bE as hb,bF as jr,bG as fb,bH as xu,bI as al,bJ as Pl,bK as _h,bL as gb,bM as xb,bN as so,bO as bb,bP as Ld,bQ as yb,bR as ei,bS as Ki,bT as Vh,bU as ui,bV as zh,bW as vb,bX as wb,bY as Od,bZ as ea,b_ as ti,b$ as Na,c0 as Al,c1 as no,c2 as ro,c3 as Kc,c4 as Uh,c5 as $d,c6 as Wh,c7 as Hi,c8 as jb,c9 as Nb,ca as Sb,cb as kb,cc as Cb,cd as si,ce as Gl,cf as bu,cg as Ib,ch as Pb,ci as Ab,cj as Db,ck as Ja,cl as ql,cm as Tb,cn as yu,co as sa,cp as Mb,cq as vu,cr as wu,cs as ju,ct as Nu,cu as $o,cv as Su,cw as Eb,cx as Jl,cy as Rb,cz as Fb,cA as Lb,cB as Ob,cC as $b,cD as Bb,cE as _b,cF as Ql,cG as ku,cH as Vb,cI as zb,cJ as Ub,cK as Wb,cL as Kb,cM as Yl,cN as Hb,cO as Cu,cP as Mi,cQ as Gb,cR as qb,cS as Kh,cT as Jb,cU as Qa,cV as Qb,cW as Iu,cX as Yb,cY as Hh,cZ as fo,c_ as Bi,c$ as Xb,d0 as Gh,d1 as Zb,d2 as ey,d3 as Pu,d4 as Au,d5 as qh,d6 as Jh,d7 as Xl,d8 as go,d9 as ty,da as sy,db as ny,dc as ry,dd as Qh,de as Yh,df as Hc,dg as Bd,dh as ay,di as ks,dj as Gi,dk as mi,dl as ni,dm as Du,dn as qn,dp as iy,dq as _i,dr as oy,ds as Xh,dt as ly,du as cy,dv as Gc,dw as dy,dx as uy,dy as Tu,dz as my,dA as py,dB as _d,dC as Zh,dD as hy,dE as fy,dF as gy,dG as xy,dH as Mu,dI as by,dJ as yy,dK as vy,dL as wy,dM as Zl,dN as jy,dO as ef,dP as Ny,dQ as Sy,dR as ky,dS as Cy,dT as Iy,dU as Py,dV as Ay,dW as Dy,dX as Ty,dY as My,dZ as Ey,d_ as Ry,d$ as Fy,e0 as Eu,e1 as Ly,e2 as tf,e3 as Oy,e4 as $y,e5 as By,e6 as _y,e7 as Ur,e8 as Vy,e9 as Ru,ea as zy,eb as Bo,ec as _o,ed as Uy,ee as Wy,ef as Ky,eg as Hy,eh as Fu,ei as Gy,ej as Lu,ek as qy,el as Ou,em as Jy,en as Qy,eo as Yy,ep as $u,eq as Bu,er as _u,es as Xy,et as sf,eu as nf,ev as Zy,ew as ev,ex as tv,ey as sv,ez as nv,eA as rv,eB as av,eC as iv,eD as ov,eE as lv,eF as cv}from"./modelPrefsAutoSave-HUPrH1r2.js";import{J as dv}from"./JsonTreeView-bLRkNPS9.js";const uv=({transform:t})=>({...t,y:0}),mv=t=>{const e=at.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}=Sd(i);let h;e[2]!==p?(h=kd.Transform.toString(p),e[2]=p,e[3]=h):h=e[3];let b;e[4]!==h||e[5]!==m?(b={transform:h,transition:m},e[4]=h,e[5]=m,e[6]=b):b=e[6];const f=u&&"opacity-50";let v;e[7]!==a||e[8]!==f?(v=me("h-full rounded-md",a,f),e[7]=a,e[8]=f,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},pv=t=>{const e=at.c(6),{id:n,children:r,className:a}=t;let i;e[0]!==a?(i=me("h-full",a),e[0]=a,e[1]=i):i=e[1];let o;return e[2]!==r||e[3]!==n||e[4]!==i?(o=s.jsx("div",{className:i,"data-sortable-tab-id":n,children:r}),e[2]=r,e[3]=n,e[4]=i,e[5]=o):o=e[5],o},Ar=t=>{const e=at.c(121),{items:n,activeId:r,onSelect:a,onClose:i,onReorder:o,layoutMode:c,variant:d,activePillInsetClassName:p,activePillButtonClassName:m,inactiveTabsIconOnly:u,iconOnlyActiveTab:h,animateActivePill:b,activePillLowercase:f,className:v}=t,x=c===void 0?"scrollable":c,g=d===void 0?"default":d,w=u===void 0?!1:u,y=h===void 0?!1:h,k=f===void 0?!0:f,{t:D}=pt(),j=Te(hv),{isTablet:S}=an(),A=j||S,E=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[C,N]=l.useState(P);let T;e[1]!==n?(T=n.map(fv),e[1]=n,e[2]=T):T=e[2];const M=T,R=x==="scrollable",L=g==="default",$=g==="active-pill",B=g==="animated",O=$||B,_=L,ee=O||_,z=$&&R,ne=O,re=b??B,ue=typeof o=="function",Q=ue?mv:pv;let de;e[3]===Symbol.for("react.memo_cache_sentinel")?(de=new Map,e[3]=de):de=e[3];const X=l.useRef(de),[F,V]=l.useState(null);let q;e[4]===Symbol.for("react.memo_cache_sentinel")?(q={activationConstraint:{distance:8}},e[4]=q):q=e[4];const te=Qo(Li(Yo,q)),U=gv;let ae;e[5]===Symbol.for("react.memo_cache_sentinel")?(ae=(nt,ye)=>{if(ye){X.current.set(nt,ye);return}X.current.delete(nt)},e[5]=ae):ae=e[5];const je=ae;let oe;e[6]!==r||e[7]!==ee?(oe=()=>{if(!ee||!r){V(xv);return}const nt=E.current,ye=X.current.get(r);if(!nt||!ye){V(bv);return}let Je=0,_e=0,Ue=ye;for(;Ue&&Ue!==nt;)Je=Je+Ue.offsetLeft,_e=_e+Ue.offsetTop,Ue=Ue.offsetParent;const ot={left:Je,top:_e,width:ye.offsetWidth,height:ye.offsetHeight};V(Xe=>U(Xe,ot)?Xe:ot)},e[6]=r,e[7]=ee,e[8]=oe):oe=e[8];const ve=oe;let K;e[9]!==R?(K=()=>{if(!R){N({left:!1,right:!1});return}const nt=E.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]=K):K=e[10];const ce=K;let Z;e[11]!==R||e[12]!==ce?(Z=()=>{if(!R){N({left:!1,right:!1});return}const nt=E.current;if(!nt)return;ce(),nt.addEventListener("scroll",ce,{passive:!0});const ye=new ResizeObserver(ce);return ye.observe(nt),()=>{nt.removeEventListener("scroll",ce),ye.disconnect()}},e[11]=R,e[12]=ce,e[13]=Z):Z=e[13];let le;e[14]!==R||e[15]!==n.length||e[16]!==ce?(le=[R,n.length,ce],e[14]=R,e[15]=n.length,e[16]=ce,e[17]=le):le=e[17],l.useEffect(Z,le);let se;e[18]!==r||e[19]!==ve||e[20]!==ee?(se=()=>{if(!ee){V(null);return}ve();const nt=E.current;if(!nt)return;const ye=new ResizeObserver(ve);if(ye.observe(nt),r){const Je=X.current.get(r);Je&&ye.observe(Je)}return()=>{ye.disconnect()}},e[18]=r,e[19]=ve,e[20]=ee,e[21]=se):se=e[21];let Ie;e[22]!==r||e[23]!==n.length||e[24]!==ve||e[25]!==ee?(Ie=[r,n.length,ve,ee],e[22]=r,e[23]=n.length,e[24]=ve,e[25]=ee,e[26]=Ie):Ie=e[26],l.useEffect(se,Ie);let Ne;e[27]!==ve?(Ne=()=>{ve()},e[27]=ve,e[28]=Ne):Ne=e[28],l.useLayoutEffect(Ne);let Y;e[29]!==r||e[30]!==R||e[31]!==ce?(Y=()=>{if(!R||!r)return;const nt=E.current;if(!nt)return;const ye=window.requestAnimationFrame(()=>{const Je=typeof window.CSS?.escape=="function"?window.CSS.escape(r):r.replace(/"/g,'\\"'),_e=nt.querySelector(`[data-sortable-tab-id="${Je}"]`);_e&&(_e.scrollIntoView({block:"nearest",inline:"nearest"}),ce())});return()=>{window.cancelAnimationFrame(ye)}},e[29]=r,e[30]=R,e[31]=ce,e[32]=Y):Y=e[32];let fe;e[33]!==r||e[34]!==R||e[35]!==n.length||e[36]!==ce?(fe=[r,R,n.length,ce],e[33]=r,e[34]=R,e[35]=n.length,e[36]=ce,e[37]=fe):fe=e[37],l.useEffect(Y,fe);let ke;e[38]!==o?(ke=nt=>{if(!o)return;const{active:ye,over:Je}=nt;!Je||ye.id===Je.id||o(String(ye.id),String(Je.id))},e[38]=o,e[39]=ke):ke=e[39];const be=ke;let pe;e[40]!==v?(pe=me("relative flex h-full min-w-0 flex-1",v),e[40]=v,e[41]=pe):pe=e[41];let Ee;e[42]!==R||e[43]!==C||e[44]!==O?(Ee=R&&C.left?s.jsx("div",{className:me("pointer-events-none absolute inset-y-0 left-0 z-20 bg-gradient-to-r to-transparent",O?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,e[42]=R,e[43]=C,e[44]=O,e[45]=Ee):Ee=e[45];let ze;e[46]!==R||e[47]!==C||e[48]!==O?(ze=R&&C.right?s.jsx("div",{className:me("pointer-events-none absolute inset-y-0 right-0 z-20 bg-gradient-to-l to-transparent",O?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,e[46]=R,e[47]=C,e[48]=O,e[49]=ze):ze=e[49];const G=O?"items-center overflow-x-hidden overflow-y-hidden":"items-stretch",Pe=O&&"@container/pill-tabs",Le=O&&"pill-tabs__track",Ae=O&&(p??"gap-0.5 py-0.5"),ge=_&&"items-center overflow-y-hidden",W=ne&&"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",ie=R?"overflow-x-auto scrollbar-none":"overflow-x-hidden";let Me;e[50]!==G||e[51]!==Pe||e[52]!==Le||e[53]!==Ae||e[54]!==ge||e[55]!==W||e[56]!==ie?(Me=me("relative flex h-full min-w-0 flex-1",G,Pe,Le,Ae,ge,W,ie),e[50]=G,e[51]=Pe,e[52]=Le,e[53]=Ae,e[54]=ge,e[55]=W,e[56]=ie,e[57]=Me):Me=e[57];let Ve;e[58]!==R?(Ve=R?{scrollbarWidth:"none",msOverflowStyle:"none"}:void 0,e[58]=R,e[59]=Ve):Ve=e[59];let Ce;e[60]!==D?(Ce=D("sortableTabsStrip.aria.tabs"),e[60]=D,e[61]=Ce):Ce=e[61];let xe;e[62]!==F||e[63]!==re||e[64]!==O?(xe=O&&F?s.jsx("div",{className:me("pointer-events-none absolute left-0 top-0 z-0 rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] bg-[var(--surface-elevated)]","border border-border/60"),style:{transform:`translate3d(${F.left}px, ${F.top}px, 0)`,width:`${F.width}px`,height:`${F.height}px`,transition:re?"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]=F,e[63]=re,e[64]=O,e[65]=xe):xe=e[65];let De;e[66]!==F||e[67]!==_?(De=_&&F?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(${F.left}px, 0, 0)`,width:`${F.width}px`},"aria-hidden":!0}):null,e[66]=F,e[67]=_,e[68]=De):De=e[68];let Ye;if(e[69]!==Q||e[70]!==r||e[71]!==m||e[72]!==k||e[73]!==A||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]!==z||e[83]!==O){let nt;e[85]!==Q||e[86]!==r||e[87]!==m||e[88]!==k||e[89]!==A||e[90]!==y||e[91]!==w||e[92]!==$||e[93]!==j||e[94]!==R||e[95]!==i||e[96]!==a||e[97]!==z||e[98]!==O?(nt=ye=>{const Je=ye.id===r,_e=w&&O&&!Je&&!!ye.icon,Ue=!_e,ot=!!ye.icon&&(!y||Je),Xe=w&&O&&Je&&!R&&!z,We=ye.closable!==!1&&!!i,bt=We&&!!ye.icon,Dt=R||z?void 0:O?Xe?"flex-none basis-auto":j?"flex-1 basis-0 min-w-0":"flex-1 basis-0 min-w-fit":"min-w-0 flex-1 basis-0";return s.jsx(Q,{id:ye.id,className:Dt,children:s.jsxs("div",{ref:Ht=>je(ye.id,Ht),className:me("group flex h-full min-w-0 flex-nowrap items-center",R||z?"shrink-0":O?"w-full":"w-full min-w-0",O?"relative z-10 bg-transparent":Je?"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":Je,"aria-label":_e?ye.title??ye.label:void 0,onClick:()=>a(ye.id),className:me(O?"animated-tabs__button pill-tabs__button relative z-10 flex flex-1 min-w-0 flex-nowrap items-center justify-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] text-sm font-medium transition-colors duration-150 !min-h-0":"flex h-full min-w-0 flex-nowrap items-center typography-micro",O&&k?"lowercase":null,O&&(_e?"gap-0":"gap-1.5"),O?z?"shrink-0 whitespace-nowrap px-3 text-center":R?"max-w-56 shrink-0 px-3 text-center":_e?"px-2 !min-w-0 text-center":Xe?"shrink-0 whitespace-nowrap px-3 text-center":"px-3 text-center":R?"max-w-56 justify-start truncate px-3 text-left":"w-full justify-center truncate px-3 text-center",O?m??($?j?"h-[38px]":"h-[31px]":"h-7"):null,O?Je?"text-foreground":"text-muted-foreground hover:text-foreground":null,O?"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] focus-visible:ring-offset-1 focus-visible:ring-offset-background":null),title:ye.title??ye.label,children:O?s.jsxs(s.Fragment,{children:[ot?s.jsxs("span",{className:"relative flex h-4 w-4 shrink-0 items-center justify-center",children:[s.jsx("span",{className:me("flex items-center justify-center transition-opacity",bt&&(A?"opacity-0":"group-hover:opacity-0")),children:ye.icon}),bt?s.jsx("span",{role:"button",tabIndex:-1,className:me("absolute inset-0 z-20 flex !min-h-0 !min-w-0 items-center justify-center rounded-sm text-muted-foreground transition-opacity hover:text-foreground",A?"opacity-100":"opacity-0 group-hover:opacity-100"),onPointerDown:yv,onClick:Ht=>{Ht.stopPropagation(),i?.(ye.id)},"aria-label":ye.closeLabel??`Close ${ye.label} tab`,title:ye.closeLabel??`Close ${ye.label} tab`,children:s.jsx(I,{name:"close",className:"h-3.5 w-3.5"})}):null]}):null,Ue?s.jsx("span",{className:"animated-tabs__label truncate",children:ye.label}):null]}):s.jsxs("span",{className:me("flex min-w-0 flex-nowrap items-center gap-1.5",!R&&"justify-center"),children:[ot?s.jsxs("span",{className:me("relative flex h-4 w-4 shrink-0 items-center justify-center transition-colors duration-200 ease-out",Je?"text-[var(--primary-base)]":"text-muted-foreground"),children:[s.jsx("span",{className:me("flex items-center justify-center transition-opacity",bt&&(A?"opacity-0":"group-hover:opacity-0")),children:ye.icon}),bt?s.jsx("span",{role:"button",tabIndex:-1,className:me("absolute inset-0 z-20 flex !min-h-0 !min-w-0 items-center justify-center rounded-sm text-muted-foreground transition-opacity hover:text-foreground",A?"opacity-100":"opacity-0 group-hover:opacity-100"),onPointerDown:vv,onClick:Ht=>{Ht.stopPropagation(),i?.(ye.id)},"aria-label":ye.closeLabel??`Close ${ye.label} tab`,title:ye.closeLabel??`Close ${ye.label} tab`,children:s.jsx(I,{name:"close",className:"h-3.5 w-3.5"})}):null]}):null,s.jsx("span",{className:"truncate leading-[1.2]",children:ye.label})]})}),We&&!bt?s.jsx("button",{type:"button",onPointerDown:wv,onClick:Ht=>{Ht.stopPropagation(),i?.(ye.id)},className:me("relative z-20 inline-flex !min-h-0 !min-w-0 items-center justify-center transition-opacity",O?"-ml-2.5 mr-1 h-[88%] w-5 self-center !aspect-auto rounded-md":"aspect-square h-[65%] min-h-4 max-h-5 rounded-sm mr-1",O?Je?"text-muted-foreground hover:bg-transparent hover:text-foreground":"text-muted-foreground opacity-0 hover:bg-transparent hover:text-foreground group-hover:opacity-100":Je?"text-muted-foreground hover:bg-interactive-hover/60 hover:text-foreground":"text-muted-foreground opacity-0 hover:bg-interactive-hover/80 hover:text-foreground group-hover:opacity-100"),"aria-label":ye.closeLabel??`Close ${ye.label} tab`,title:ye.closeLabel??`Close ${ye.label} tab`,children:s.jsx(I,{name:"close",className:"h-3 w-3"})}):null]})},ye.id)},e[85]=Q,e[86]=r,e[87]=m,e[88]=k,e[89]=A,e[90]=y,e[91]=w,e[92]=$,e[93]=j,e[94]=R,e[95]=i,e[96]=a,e[97]=z,e[98]=O,e[99]=nt):nt=e[99],Ye=n.map(nt),e[69]=Q,e[70]=r,e[71]=m,e[72]=k,e[73]=A,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]=z,e[83]=O,e[84]=Ye}else Ye=e[84];let rt;e[100]!==Me||e[101]!==Ve||e[102]!==Ce||e[103]!==xe||e[104]!==De||e[105]!==Ye?(rt=s.jsxs("div",{ref:E,className:Me,style:Ve,role:"tablist","aria-label":Ce,children:[xe,De,Ye]}),e[100]=Me,e[101]=Ve,e[102]=Ce,e[103]=xe,e[104]=De,e[105]=Ye,e[106]=rt):rt=e[106];let Re;e[107]!==pe||e[108]!==Ee||e[109]!==ze||e[110]!==rt?(Re=s.jsxs("div",{className:pe,children:[Ee,ze,rt]}),e[107]=pe,e[108]=Ee,e[109]=ze,e[110]=rt,e[111]=Re):Re=e[111];const he=Re;if(!ue)return he;let qe;e[112]===Symbol.for("react.memo_cache_sentinel")?(qe=[uv],e[112]=qe):qe=e[112];let et;e[113]!==M||e[114]!==he?(et=s.jsx(Vc,{items:M,strategy:Fg,children:he}),e[113]=M,e[114]=he,e[115]=et):et=e[115];let Ke;e[116]===Symbol.for("react.memo_cache_sentinel")?(Ke=s.jsx(Xo,{dropAnimation:null}),e[116]=Ke):Ke=e[116];let st;return e[117]!==be||e[118]!==te||e[119]!==et?(st=s.jsxs(Zo,{sensors:te,collisionDetection:el,onDragEnd:be,modifiers:qe,children:[et,Ke]}),e[117]=be,e[118]=te,e[119]=et,e[120]=st):st=e[120],st};function hv(t){return t.isMobile}function fv(t){return t.id}function gv(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 xv(t){return t===null?t:null}function bv(t){return t===null?t:null}function yv(t){t.stopPropagation()}function vv(t){t.stopPropagation()}function wv(t){t.stopPropagation()}function Vu(t){const e=at.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 Mr=[{id:"claude",name:"Claude"},{id:"codex",name:"Codex"},{id:"github-copilot",name:"GitHub Copilot"},{id:"google",name:"Google"},{id:"kimi-for-coding",name:"Kimi for Coding"},{id:"nano-gpt",name:"NanoGPT"},{id:"openrouter",name:"OpenRouter"},{id:"zai-coding-plan",name:"z.ai"},{id:"zhipuai-coding-plan",name:"Zhipu AI Coding Plan"},{id:"minimax-cn-coding-plan",name:"MiniMax Coding Plan (minimaxi.com)"},{id:"minimax-coding-plan",name:"MiniMax Coding Plan (minimax.io)"},{id:"ollama-cloud",name:"Ollama Cloud"},{id:"zhipuai-coding-plan",name:"ZhipuAI"}];Mr.reduce((t,e)=>(t[e.id]=e,t),{});const jv=t=>typeof t!="number"||Number.isNaN(t)?null:Math.max(0,Math.min(100,Math.round(t))),Nv=t=>typeof t!="number"||Number.isNaN(t)?"-":`${Math.round(t)}%`,qi=(t,e)=>t??Nv(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??""}},rf=t=>t===null?"safe":t>=80?"critical":t>=50?"warn":"safe",zd=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,Sv=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},Ji=(t,e,n,r)=>{let a=n;if(a===null&&r&&(a=Sv(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 h;m?h="exhausted":p<=d?h="on-track":u<=130?h="slightly-fast":h="too-fast";const b=a>=120*3600,f=b?86400:3600,v=b?"d":"h",x=a/f,g=Math.max(c/f,x*.01),w=t/g,y=Number.isFinite(w)?`${Math.min(999.9,Math.max(0,w)).toFixed(1)}%/${v}`:"-",k=u>100?`+${Math.round(u)}%`:`${Math.round(u)}%`;let D=null;const j=a/86400;return j>=7&&(D=100/j),{elapsedRatio:d,usageRatio:p,predictedFinalPercent:u,remainingSeconds:o,isExhausted:m,elapsedSeconds:c,totalSeconds:a,status:h,paceRateText:y,predictText:k,dailyAllocationPercent:D}},kv=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)"}},zu=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`},_r=t=>Math.min(100,Math.max(0,t*100));function il(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 Cv=[{id:"gemini-auth",label:"Gemini",matcher:t=>t.startsWith("gemini/"),order:1},{id:"antigravity-auth",label:"Antigravity",matcher:t=>t.startsWith("antigravity/"),order:2}],af={google:Cv};function of(t,e){const n=af[e]??[];for(const r of n)if(r.matcher(t))return r;return null}function lf(t){return af[t]??[]}function cf(t){return[...t].sort((e,n)=>e.order-n.order)}function Iv(t,e){const n=new Map;for(const r of Object.keys(t)){const i=of(r,e)?.id??null;n.has(i)||n.set(i,[]),n.get(i).push(r)}return n}function Pv(t,e,n){const r=new Map;for(const a of t){const i=e(a),c=of(i,n)?.id??null;r.has(c)||r.set(c,[]),r.get(c).push(a)}return r}function Av(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 Ud=6e4,Uu=t=>{const e=Mr.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))):Ud,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,h]of Object.entries(d))Array.isArray(h)&&(c[u]=h.filter(b=>typeof b=="string"));const p={},m=t?.usageExpandedFamilies;if(m&&typeof m=="object")for(const[u,h]of Object.entries(m))Array.isArray(h)&&(p[u]=h.filter(b=>typeof b=="string"));return{autoRefresh:n,refreshIntervalMs:r,displayMode:a,dropdownProviderIds:o,selectedModels:c,expandedFamilies:p}},Dv=async()=>{const t=dr()?.settings;if(t)try{const n=(await t.load())?.settings;return Uu(n??null)}catch{}if(!dn()){const e=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(e.ok){const n=await e.json().catch(()=>null);return Uu(n)}}return{autoRefresh:!1,refreshIntervalMs:Ud,displayMode:"usage",dropdownProviderIds:Mr.map(e=>e.id),selectedModels:{},expandedFamilies:{}}},Ls=tr()(gi((t,e)=>({results:[],selectedProviderId:null,isLoading:!1,isFetchingProvider:{},lastUpdated:null,error:null,autoRefresh:!1,refreshIntervalMs:Ud,displayMode:"usage",dropdownProviderIds:Mr.map(n=>n.id),selectedModels:{},expandedFamilies:{},loadSettings:async()=>{try{const n=await Dv();t(n)}catch(n){console.warn("Failed to load usage settings:",n)}},fetchAllQuotas:async()=>{t({isLoading:!0,error:null});const n=Mr.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}})),Ds({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}}}),Ds({usageExpandedFamilies:e().expandedFamilies})},applyDefaultSelections:(n,r)=>{if((e().selectedModels[n]?.length??0)>0)return;const i=Av(n,r);i.length!==0&&(t(o=>({selectedModels:{...o.selectedModels,[n]:i}})),Ds({usageSelectedModels:e().selectedModels}))}}),{name:"quota-store"})),df=()=>{const t=at.c(5),e=Ls(Tv),n=Ls(Mv),r=Ls(Ev);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 Tv(t){return t.autoRefresh}function Mv(t){return t.refreshIntervalMs}function Ev(t){return t.fetchAllQuotas}const ol=Be.forwardRef((t,e)=>{const n=at.c(11);let r,a;n[0]!==t?({className:r,...a}=t,n[0]=t,n[1]=r,n[2]=a):(r=n[1],a=n[2]);let i;n[3]!==r?(i=me("peer inline-flex shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-none transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[checked]:bg-primary data-[unchecked]:bg-[var(--interactive-border)]",r),n[3]=r,n[4]=i):i=n[4];let o;n[5]===Symbol.for("react.memo_cache_sentinel")?(o={width:"36px",height:"20px",minWidth:"36px",minHeight:"20px"},n[5]=o):o=n[5];let c;n[6]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(Lg,{className:me("pointer-events-none block rounded-full bg-background shadow-none ring-0 transition-transform data-[checked]:translate-x-4 data-[unchecked]:translate-x-0"),style:{width:"16px",height:"16px",minWidth:"16px",minHeight:"16px"}}),n[6]=c):c=n[6];let d;return n[7]!==a||n[8]!==e||n[9]!==i?(d=s.jsx(Og,{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});ol.displayName="Switch";const xo=()=>{try{const e=Fs.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const n=rn.getDirectory();if(n?.trim())return n.trim()}catch(t){console.warn("[McpConfigStore] Error resolving config directory:",t)}return null},Wu=t=>t?Object.entries(t).map(([e,n])=>({key:e,value:n})):[],Ku=t=>{const e=t.filter(n=>n.key.trim());if(e.length!==0)return Object.fromEntries(e.map(n=>[n.key.trim(),n.value]))},bo=t=>typeof t!="string"?void 0:t.trim()||void 0,ec=800,Rv=5e3,Fv="__default__",qc=new Map,tc=new Map,uf=t=>t?.trim()||Fv,sc=t=>{qc.delete(uf(t))},Qi=tr()(gi(Zi((t,e)=>({mcpServers:[],selectedMcpName:null,isLoading:!1,mcpDraft:null,setSelectedMcp:n=>t({selectedMcpName:n}),setMcpDraft:n=>t({mcpDraft:n}),loadMcpConfigs:async n=>{const r=xo(),a=uf(r),i=Date.now(),o=qc.get(a)??0,c=e().mcpServers.length>0;if(!n?.force&&c&&i-o<Rv)return!0;const d=tc.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 h=await u.json();return t({mcpServers:h,isLoading:!1}),qc.set(a,Date.now()),!0}catch(m){return console.error("[McpConfigStore] Failed to load MCP configs:",m),t({isLoading:!1}),!1}})();tc.set(a,p);try{return await p}finally{tc.delete(a)}},createMcp:async n=>{Ul("Creating MCP server configuration…");let r=!1;try{const a=Hu(n),i=xo(),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 sc(i),d?.requiresReload?(r=!0,await Wl({message:d.message,delayMs:d.reloadDelayMs??ec,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||Kl()}},updateMcp:async(n,r)=>{Ul("Updating MCP server configuration…");let a=!1;try{const i=Hu(r),o=xo(),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 sc(o),p?.requiresReload?(a=!0,await Wl({message:p.message,delayMs:p.reloadDelayMs??ec,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||Kl()}},deleteMcp:async n=>{Ul("Deleting MCP server configuration…");let r=!1;try{const a=xo(),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 sc(a),c?.requiresReload&&(r=!0,await Wl({message:c.message,delayMs:c.reloadDelayMs??ec,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||Kl()}},getMcpByName:n=>e().mcpServers.find(r=>r.name===n)}),{name:"mcp-config-store",storage:vl(()=>Zr()),partialize:t=>({selectedMcpName:t.selectedMcpName})}),{name:"mcp-config-store"}));function Hu(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=Ku(t.environment)??{}),t.headers!==void 0&&(e.headers=Ku(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:bo(t.oauthClientId),clientSecret:bo(t.oauthClientSecret),scope:bo(t.oauthScope),redirectUri:bo(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 Lv={},Ov={},$r=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},Ka=t=>$r(t)??"__global__",da=t=>{const e=$r(t);return e?rn.getScopedApiClient(e):rn.getApiClient()},Nn=tr()(gi((t,e)=>({byDirectory:{},diagnosticsByDirectory:{},loadingKeys:{},lastErrorKeys:{},getStatusForDirectory:n=>{const r=Ka(n??Vs.getState().currentDirectory);return e().byDirectory[r]??Lv},getDiagnosticForDirectory:n=>{const r=Ka(n??Vs.getState().currentDirectory);return e().diagnosticsByDirectory[r]??Ov},getErrorForDirectory:n=>{const r=Ka(n??Vs.getState().currentDirectory);return e().lastErrorKeys[r]??null},refresh:async n=>{const r=$r(n?.directory??Vs.getState().currentDirectory),a=Ka(r);n?.silent||t(i=>({loadingKeys:{...i.loadingKeys,[a]:!0},lastErrorKeys:{...i.lastErrorKeys,[a]:null}}));try{const c=(await da(r).mcp.status()).data??{};t(d=>({byDirectory:{...d.byDirectory,[a]:c},diagnosticsByDirectory:{...d.diagnosticsByDirectory,[a]:Object.fromEntries(Object.entries(d.diagnosticsByDirectory[a]??{}).filter(([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=$r(r??Vs.getState().currentDirectory),i=Ka(a),o=da(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=$r(r??Vs.getState().currentDirectory);await da(a).mcp.disconnect({name:n},{throwOnError:!0}),await e().refresh({directory:a,silent:!0})},startAuth:async(n,r)=>{const a=$r(r??Vs.getState().currentDirectory),c=(await da(a).mcp.auth.start({name:n},{throwOnError:!0})).data?.authorizationUrl;if(!c)throw new Error("Authorization URL was not returned");return c},completeAuth:async(n,r,a)=>{const i=$r(a??Vs.getState().currentDirectory);await da(i).mcp.auth.callback({name:n,code:r},{throwOnError:!0}),await e().refresh({directory:i,silent:!0})},clearAuth:async(n,r)=>{const a=$r(r??Vs.getState().currentDirectory);await da(a).mcp.auth.remove({name:n},{throwOnError:!0}),await e().refresh({directory:a,silent:!0})},testConnection:async(n,r)=>{const a=$r(r??Vs.getState().currentDirectory),i=Ka(a),o=da(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(f=>({diagnosticsByDirectory:{...f.diagnosticsByDirectory,[i]:{...f.diagnosticsByDirectory[i]??{},[n]:{status:"failed",error:p??"Connection failed"}}}}))}await e().refresh({directory:a,silent:!0});const u=e().getStatusForDirectory(a)[n],h=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:h??e().getStatusForDirectory(a)[n],error:p,warning:m}}})));function $v(t){const e=at.c(4);let n,r;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx("path",{d:"M15.688 2.343a2.588 2.588 0 00-3.61 0l-9.626 9.44a.863.863 0 01-1.203 0 .823.823 0 010-1.18l9.626-9.44a4.313 4.313 0 016.016 0 4.116 4.116 0 011.204 3.54 4.3 4.3 0 013.609 1.18l.05.05a4.115 4.115 0 010 5.9l-8.706 8.537a.274.274 0 000 .393l1.788 1.754a.823.823 0 010 1.18.863.863 0 01-1.203 0l-1.788-1.753a1.92 1.92 0 010-2.754l8.706-8.538a2.47 2.47 0 000-3.54l-.05-.049a2.588 2.588 0 00-3.607-.003l-7.172 7.034-.002.002-.098.097a.863.863 0 01-1.204 0 .823.823 0 010-1.18l7.273-7.133a2.47 2.47 0 00-.003-3.537z"}),r=s.jsx("path",{d:"M14.485 4.703a.823.823 0 000-1.18.863.863 0 00-1.204 0l-7.119 6.982a4.115 4.115 0 000 5.9 4.314 4.314 0 006.016 0l7.12-6.982a.823.823 0 000-1.18.863.863 0 00-1.204 0l-7.119 6.982a2.588 2.588 0 01-3.61 0 2.47 2.47 0 010-3.54l7.12-6.982z"}),e[0]=n,e[1]=r):(n=e[0],r=e[1]);let a;return e[2]!==t?(a=s.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",fill:"currentColor",stroke:"currentColor",strokeWidth:"0.5",fillRule:"evenodd",viewBox:"-0.5 -0.5 25 25",...t,children:[n,r]}),e[2]=t,e[3]=a):a=e[3],a}const Bv=(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}},_v=t=>{switch(t?.status){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"default"}},mf=({active:t,className:e})=>{const{t:n}=pt(),a=Vs(g=>g.currentDirectory)??null,i=Nn(g=>g.getStatusForDirectory(a)),o=Nn(g=>g.refresh),c=Nn(g=>g.connect),d=Nn(g=>g.disconnect),p=Qi(g=>g.mcpServers),m=Qi(g=>g.loadMcpConfigs),[u,h]=l.useState(!1),[b,f]=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;h(!0);const w=new Promise(y=>setTimeout(y,500));Promise.all([o({directory:a}),w]).finally(()=>{h(!1)})},[u,o,a]);return s.jsxs("div",{className:me("w-full",e),children:[s.jsx("div",{className:"border-b border-[var(--interactive-border)]",children:s.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-2.5",children:[s.jsxs("div",{className:"min-w-0 flex items-baseline gap-2",children:[s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:n("mcpDropdown.title")}),a&&s.jsx("div",{className:"truncate typography-micro text-muted-foreground",children:a.split("/").pop()||a})]}),s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",disabled:u,onClick:x,"aria-label":n("mcpDropdown.actions.refreshAria"),children:s.jsx(I,{name:"refresh",className:me("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=_v(w),k=w?.status==="connected",D=b===g,j=Bv(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(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("span",{className:me("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(Pt,{side:"left",children:s.jsx("p",{children:j})})]}),s.jsx("span",{className:"typography-ui-label truncate",children:g})]})}),s.jsx(ol,{checked:k,disabled:D,className:"data-[checked]:bg-status-info",onCheckedChange:async S=>{f(g);try{S?await c(g,a):await d(g,a)}finally{f(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")})]})]})},Yi=t=>{const e=at.c(20),{percent:n,tonePercent:r,className:a,expectedMarkerPercent:i}=t;let o;e[0]!==n?(o=jv(n)??0,e[0]=n,e[1]=o):o=e[1];const c=o,d=r??n;let p;e[2]!==d?(p=rf(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 h;e[4]!==m?(h=m==="critical"?{backgroundColor:"var(--status-error)"}:m==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"},e[4]=m,e[5]=h):h=e[5];const b=h;let f;e[6]!==a?(f=me("relative h-2.5 rounded-full bg-[var(--interactive-border)] overflow-hidden",a),e[6]=a,e[7]=f):f=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]!==f||e[17]!==g||e[18]!==w?(y=s.jsxs("div",{className:f,children:[g,w]}),e[16]=f,e[17]=g,e[18]=w,e[19]=y):y=e[19],y},Xi=t=>{const e=at.c(67),{paceInfo:n,className:r,compact:a}=t,i=a===void 0?!1:a,{t:o}=pt();let c;e[0]!==n.status?(c=kv(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 h=u;if(i){let S;e[13]!==r?(S=me("flex items-center gap-1.5",r),e[13]=r,e[14]=S):S=e[14];let A;e[15]!==d?(A={backgroundColor:d},e[15]=d,e[16]=A):A=e[16];let E;e[17]!==m||e[18]!==A?(E=s.jsx("div",{className:"h-2 w-2 rounded-full flex-shrink-0",style:A,title:m}),e[17]=m,e[18]=A,e[19]=E):E=e[19];let P;e[20]!==d?(P={color:d},e[20]=d,e[21]=P):P=e[21];const C=n.isExhausted?void 0:h;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:zu(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 T;e[27]!==N||e[28]!==P||e[29]!==C?(T=s.jsx("span",{className:"typography-micro tabular-nums",style:P,title:C,children:N}),e[27]=N,e[28]=P,e[29]=C,e[30]=T):T=e[30];let M;return e[31]!==T||e[32]!==S||e[33]!==E?(M=s.jsxs("div",{className:S,children:[E,T]}),e[31]=T,e[32]=S,e[33]=E,e[34]=M):M=e[34],M}let b;e[35]!==r?(b=me("flex items-center justify-between gap-2",r),e[35]=r,e[36]=b):b=e[36];let f;e[37]!==n.isExhausted||e[38]!==n.paceRateText||e[39]!==o?(f=!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]=f):f=e[40];let v;e[41]!==f?(v=s.jsx("div",{className:"flex items-center gap-1.5",children:f}),e[41]=f,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]!==h||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:zu(n.remainingSeconds)})]}):s.jsxs("span",{title:h,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]=h,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 k;e[57]!==m||e[58]!==y?(k=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]=k):k=e[59];let D;e[60]!==w||e[61]!==k?(D=s.jsxs("div",{className:"flex items-center gap-1.5",children:[w,k]}),e[60]=w,e[61]=k,e[62]=D):D=e[62];let j;return e[63]!==D||e[64]!==b||e[65]!==v?(j=s.jsxs("div",{className:b,children:[v,D]}),e[63]=D,e[64]=b,e[65]=v,e[66]=j):j=e[66],j},ur=$g,wr=t=>{const e=at.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&&Be.isValidElement(r)?{render:r}:{children:r},e[5]=n,e[6]=r,e[7]=o):o=e[7];const c=o;let d;e[8]!==a?(d=me("flex w-full items-center justify-between rounded-lg px-2 py-1.5 text-left text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",a),e[8]=a,e[9]=d):d=e[9];let p;return e[10]!==i||e[11]!==c||e[12]!==d?(p=s.jsx(Bg,{className:d,...i,...c}),e[10]=i,e[11]=c,e[12]=d,e[13]=p):p=e[13],p},mr=t=>{const e=at.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let a;e[3]!==n?(a=me("overflow-hidden data-[closed]:animate-collapsible-up data-[open]:animate-collapsible-down",n),e[3]=n,e[4]=a):a=e[4];let i;return e[5]!==r||e[6]!==a?(i=s.jsx(_g,{className:a,...r}),e[5]=r,e[6]=a,e[7]=i):i=e[7],i},ta=[{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"}],Jc="finder",Qc=new Set(["finder","terminal"]),Yc=t=>t?ta.find(e=>e.id===t)??null:null,nc=()=>ta.filter(t=>Qc.has(t.id)).map(t=>({...t})),Vv=()=>{if(typeof window>"u")return Jc;const t=window.localStorage.getItem("openInAppId");return t&&Yc(t)?t:Jc};let rc=!1,Ha=!1,Jr=!1,Qr=0,Vi=null;const Gu=()=>{Vi&&(clearTimeout(Vi),Vi=null)},Cr=tr()((t,e)=>({selectedAppId:Vv(),availableApps:nc(),hasLoadedApps:!1,isCacheStale:!1,isScanning:!1,initialize:()=>{if(rc||typeof window>"u")return;rc=!0;const n=(d,p=!0)=>{if(!Array.isArray(d)||d.length===0){t({availableApps:nc(),hasLoadedApps:p});return}const m=new Set(d.map(f=>f.name)),u=new Map(d.map(f=>[f.name,f.iconDataUrl??void 0])),b=ta.filter(f=>m.has(f.appName)||Qc.has(f.id)).map(f=>({...f,iconDataUrl:u.get(f.appName)}));t({availableApps:b,hasLoadedApps:!0})},r=async d=>{if(!Ia()||!Vr()||Ha||e().hasLoadedApps&&!d)return;const m=ta.map(u=>u.appName);Gu(),Ha=!0,Jr=!1,t({isScanning:!0});try{const{apps:u,success:h,hasCache:b,isCacheStale:f}=await uu(m,d),v=h&&!b&&u.length===0&&Qr<3;if(t({isCacheStale:b?f:!1}),n(u,h?!v:!1),h){if(v){const g=[800,1600,3200][Qr]??3200;Qr+=1,Jr=!0,Vi=setTimeout(()=>{r()},g);return}Qr=0,Jr=!1;return}if(Qr<3){const g=[1e3,3e3,7e3][Qr]??7e3;Qr+=1,Jr=!0,Vi=setTimeout(()=>{r()},g)}}finally{Ha=!1,Jr||t({isScanning:!1})}};r();const a=d=>{const p=d.detail,m=p&&typeof p.openInAppId=="string"&&p.openInAppId.length>0&&Yc(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)&&(Qr=3,Jr=!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(rc||e().initialize(),!Ia()||!Vr()||Ha||e().hasLoadedApps&&!n)return;const a=ta.map(i=>i.appName);Gu(),n&&t({hasLoadedApps:!1}),Ha=!0,Jr=!1,t({isScanning:!0});try{const{apps:i,hasCache:o,isCacheStale:c}=await uu(a,n),d=new Set(i.map(h=>h.name)),p=new Map(i.map(h=>[h.name,h.iconDataUrl??void 0])),u=ta.filter(h=>d.has(h.appName)||Qc.has(h.id)).map(h=>({...h,iconDataUrl:p.get(h.appName)}));t({availableApps:u.length>0?u:nc(),hasLoadedApps:u.length>0,isCacheStale:o?c:!1})}finally{Ha=!1,Jr||t({isScanning:!1})}},selectApp:async n=>{Yc(n)&&(t({selectedAppId:n}),typeof window<"u"&&window.localStorage.setItem("openInAppId",n),await Ds({openInAppId:n}))}})),zv="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",Uv="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAeGVYSWZNTQAqAAAACAAEARoABQAAAAEAAAA+ARsABQAAAAEAAABGASgAAwAAAAEAAgAAh2kABAAAAAEAAABOAAAAAAAAAJAAAAABAAAAkAAAAAEAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAIKADAAQAAAABAAAAIAAAAAB+C9pSAAAACXBIWXMAABYlAAAWJQFJUiTwAAABnWlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNi4wLjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczpleGlmPSJodHRwOi8vbnMuYWRvYmUuY29tL2V4aWYvMS4wLyI+CiAgICAgICAgIDxleGlmOlBpeGVsWERpbWVuc2lvbj4yNTY8L2V4aWY6UGl4ZWxYRGltZW5zaW9uPgogICAgICAgICA8ZXhpZjpQaXhlbFlEaW1lbnNpb24+MjU2PC9leGlmOlBpeGVsWURpbWVuc2lvbj4KICAgICAgPC9yZGY6RGVzY3JpcHRpb24+CiAgIDwvcmRmOlJERj4KPC94OnhtcG1ldGE+Cl6wHhsAAAQzSURBVFgJ7VZNbBNHFH67Xv9RxwnBDqlUoQglcZK6qSIEJIQWAYJQoVY9IE5RTzn20FMvqdpDesq9B24+NdwthAJCkZChJg1JSOXYQIwQKQIaBdtENbs73t2+N8miGWOcpFHUHniyd97OvJ9v3nv7ZgDe038cAeVd/jOZjC94sKdfU+Bj24G9igpexwYPyiu2bauKqqqirkOTqmrjnIOyFsoyUKDocSCj/7mU7ujoMER5l68JYOFZ4YSiwPjd9O0jjx7ch1KhAJZVAcdx0LxDv3XetYKjggr4I4bzHo8G4aYmONjZBYf6+2dUzfd9PNowJajUZmef/PX5zcWl0rmvvnbQHrra+f/M+S+dqYXs2t3Hz09Ve5UicCmZ3NPb1Zv66btv+65dSULA64WGxkbw+Xx8V9XK9d4pWowxeFUqgW6acHroC/j5l0sLD/PZY98MDf3t6mouQ+On3X1H7/2e7rtOztHpgbY2+CAUgperq+D3+7cNgtLSEA7D0+VluDF5FS7cSff2HT56DF1dd/3KhQTWJ/lclsc8jIrk9IfRURgZGQEvRqNSWa8D2t1W/liXXK8Ro0i0lF0ExaPEXec0SgAqhrm3VCzwdS9GQNd1GBsbg0AgAIlEAlpbW7EYLVF/U56AagieiGwbuhERlSQApmEE8c/XKXxU0fF4HNowFfPz81Aul7edBjLGbeHITANsZga4g42HVAM2Y74KM/kSIQ/izgcHB2FiYgJmZmZ4MZpYULRG5PF4+Bx/2cLDxuhhYUqFLwGoWCaQEBGhNjAa4+Pj/J3SQA6pHpqbm/kcNitIJpOgaZIZvlbrQbZNJvcjSZOZDKhwRKLic4l2Pjc3B8FgkE+trKxAVUN0RWuOZNtCHyJJACj/bgREIZcnA9PT029SQM63unuywSOwUWOuTQmAhfmnlluPxIjUk6u1RrbJh0jyV0Ap2OZnJhrbjOcRqEqBBMDCAtltAORDJAkAVj2mWS5CUXinPDUx+oxFkgBYjO0qANu2wKoqQgkAfgW7C4AiYMmfoQSgwpjj7GYRUh/Q66SAmdisNxql227FfP1bXrRlVExdtCNHwDRLdPkgwmi8OUREhe3y1NLJFpEfbWMNvBRtSI2o+KqYi+zbx4NQwptMCO8E1HjEHYjKm/HknG5FZIsCG4lEoLS2lhP1JAB3bt1KH//s+GJPd3dPJpvlN5kwXiYIhHukisr1eAItXsm6YzGItrTcn5+dvS3qSQBSqVQhFouNnj039CsaCC7mcqDjgbNT6op1AtrU8Wo3Ojk5KaVAOptdR8PDwxf3t7SMvXjxvJNOPP31a35Krt8CXKl3j2SUDip/IAjRaBRaP9z/cHW18GMikbhcrVUTAAm1t7d/NDAwcDIUCvVqmtqkyLe3ajtvvTtg4x3SLpbLa3+kUr9N5fP55beE3k/8HyLwDx2/HIx7q3WfAAAAAElFTkSuQmCC",ac=t=>({...t,fallbackIconDataUrl:t.id==="finder"?zv:t.id==="terminal"?Uv:void 0}),qu=t=>{const e=at.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 h;e[2]===Symbol.for("react.memo_cache_sentinel")?(h=()=>o(!0),e[2]=h):h=e[2];let b;return e[3]!==p?(b=s.jsx("img",{src:p,alt:"",className:"h-4 w-4 rounded-sm",onError:h}),e[3]=p,e[4]=b):b=e[4],b}let m;e[5]===Symbol.for("react.memo_cache_sentinel")?(m=me("h-4 w-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=m):m=e[5];let u;return e[6]!==d?(u=s.jsx("span",{className:m,children:d}),e[6]=d,e[7]=u):u=e[7],u},Wv=t=>{const e=at.c(82),{directory:n,className:r}=t,{t:a}=pt(),i=Cr(Kv),o=Cr(Hv),c=Cr(Gv),d=Cr(qv),p=Cr(Jv),m=Cr(Qv),u=Cr(Yv);let h,b;e[0]!==p?(h=()=>{p()},b=[p],e[0]=p,e[1]=h,e[2]=b):(h=e[1],b=e[2]),l.useEffect(h,b);const f=Ia()&&Vr();let v;e:{let U;e[3]!==o||e[4]!==i?(U=o.find(oe=>oe.id===i)??o.find(Xv)??o[0]??ta[0],e[3]=o,e[4]=i,e[5]=U):U=e[5];const ae=U;if(ae){let oe;e[6]!==ae?(oe=ac(ae),e[6]=ae,e[7]=oe):oe=e[7],v=oe;break e}let je;e[8]===Symbol.for("react.memo_cache_sentinel")?(je=ac(ta[0]),e[8]=je):je=e[8],v=je}const x=v;if(!f||!n||o.length===0)return null;let g;e[9]!==n?(g=async U=>{await kx(n,U.id,U.appName)||await tl(n,U.appName)},e[9]=n,e[10]=g):g=e[10];const w=g;let y;e[11]!==w||e[12]!==u?(y=async U=>{await u(U.id),await w(U)},e[11]=w,e[12]=u,e[13]=y):y=e[13];const k=y;let D;e[14]!==n||e[15]!==a?(D=async()=>{(await Rn(n)).ok&&H.success(a("openInApp.toast.pathCopied"))},e[14]=n,e[15]=a,e[16]=D):D=e[16];const j=D;let S;e[17]!==r?(S=me("app-region-no-drag inline-flex h-7 items-center self-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px]","bg-[var(--surface-elevated)] overflow-hidden","border border-border/60",r),e[17]=r,e[18]=S):S=e[18];let A;e[19]!==w||e[20]!==x?(A=()=>{w(x)},e[19]=w,e[20]=x,e[21]=A):A=e[21];let E;e[22]===Symbol.for("react.memo_cache_sentinel")?(E=me("inline-flex h-full items-center gap-2 px-3 typography-ui-label font-medium","text-foreground hover:bg-interactive-hover transition-colors"),e[22]=E):E=e[22];let P;e[23]!==x.label||e[24]!==a?(P=a("openInApp.actions.openInAria",{app:x.label}),e[23]=x.label,e[24]=a,e[25]=P):P=e[25];let C;e[26]!==x.fallbackIconDataUrl||e[27]!==x.iconDataUrl||e[28]!==x.label?(C=s.jsx(qu,{label:x.label,iconDataUrl:x.iconDataUrl,fallbackIconDataUrl:x.fallbackIconDataUrl}),e[26]=x.fallbackIconDataUrl,e[27]=x.iconDataUrl,e[28]=x.label,e[29]=C):C=e[29];const N=d?"animate-pulse text-muted-foreground":void 0;let T;e[30]!==N?(T=me("header-open-label",N),e[30]=N,e[31]=T):T=e[31];let M;e[32]!==a?(M=a("openInApp.actions.open"),e[32]=a,e[33]=M):M=e[33];let R;e[34]!==T||e[35]!==M?(R=s.jsx("span",{className:T,children:M}),e[34]=T,e[35]=M,e[36]=R):R=e[36];let L;e[37]!==P||e[38]!==C||e[39]!==R||e[40]!==A?(L=s.jsxs("button",{type:"button",onClick:A,className:E,"aria-label":P,children:[C,R]}),e[37]=P,e[38]=C,e[39]=R,e[40]=A,e[41]=L):L=e[41];let $;e[42]===Symbol.for("react.memo_cache_sentinel")?($=me("inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-muted-foreground","hover:bg-interactive-hover hover:text-foreground transition-colors"),e[42]=$):$=e[42];let B;e[43]!==a?(B=a("openInApp.actions.chooseAppAria"),e[43]=a,e[44]=B):B=e[44];let O;e[45]===Symbol.for("react.memo_cache_sentinel")?(O=s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4"}),e[45]=O):O=e[45];let _;e[46]!==B?(_=s.jsx(Os,{asChild:!0,children:s.jsx("button",{type:"button",className:$,"aria-label":B,children:O})}),e[46]=B,e[47]=_):_=e[47];let ee;e[48]===Symbol.for("react.memo_cache_sentinel")?(ee={translate:"-30px 0"},e[48]=ee):ee=e[48];let z;e[49]!==j?(z=()=>{j()},e[49]=j,e[50]=z):z=e[50];let ne;e[51]===Symbol.for("react.memo_cache_sentinel")?(ne=s.jsx(I,{name:"file-copy",className:"h-4 w-4"}),e[51]=ne):ne=e[51];let re;e[52]!==a?(re=a("openInApp.actions.copyPath"),e[52]=a,e[53]=re):re=e[53];let ue;e[54]!==re?(ue=s.jsx("span",{className:"typography-ui-label text-foreground",children:re}),e[54]=re,e[55]=ue):ue=e[55];let Q;e[56]!==z||e[57]!==ue?(Q=s.jsxs(zt,{className:"flex items-center gap-2",onClick:z,children:[ne,ue]}),e[56]=z,e[57]=ue,e[58]=Q):Q=e[58];let de;e[59]===Symbol.for("react.memo_cache_sentinel")?(de=s.jsx(Dn,{}),e[59]=de):de=e[59];let X;if(e[60]!==o||e[61]!==k||e[62]!==x.id){let U;e[64]!==k||e[65]!==x.id?(U=ae=>{const je=ac(ae);return s.jsxs(zt,{className:"flex items-center gap-2",onClick:()=>{k(ae)},children:[s.jsx(qu,{label:ae.label,iconDataUrl:ae.iconDataUrl,fallbackIconDataUrl:je.fallbackIconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:ae.label}),x.id===ae.id?s.jsx(I,{name:"check",className:"ml-auto h-4 w-4 text-primary"}):null]},ae.id)},e[64]=k,e[65]=x.id,e[66]=U):U=e[66],X=o.map(U),e[60]=o,e[61]=k,e[62]=x.id,e[63]=X}else X=e[63];let F;e[67]!==c||e[68]!==m||e[69]!==a?(F=c?s.jsxs(zt,{className:"flex items-center gap-2",onClick:()=>{m(!0)},children:[s.jsx(I,{name:"refresh",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:a("openInApp.actions.refreshApps")})]}):null,e[67]=c,e[68]=m,e[69]=a,e[70]=F):F=e[70];let V;e[71]!==Q||e[72]!==X||e[73]!==F?(V=s.jsxs($s,{align:"center",className:"w-56 max-h-[70vh] overflow-y-auto",style:ee,children:[Q,de,X,F]}),e[71]=Q,e[72]=X,e[73]=F,e[74]=V):V=e[74];let q;e[75]!==_||e[76]!==V?(q=s.jsxs(Bs,{children:[_,V]}),e[75]=_,e[76]=V,e[77]=q):q=e[77];let te;return e[78]!==L||e[79]!==q||e[80]!==S?(te=s.jsxs("div",{className:S,children:[L,q]}),e[78]=L,e[79]=q,e[80]=S,e[81]=te):te=e[81],te};function Kv(t){return t.selectedAppId}function Hv(t){return t.availableApps}function Gv(t){return t.isCacheStale}function qv(t){return t.isScanning}function Jv(t){return t.initialize}function Qv(t){return t.loadInstalledApps}function Yv(t){return t.selectApp}function Xv(t){return t.id===Jc}const Zv=1e6,e1="terminal-store";let Ju=!1;const ic=t=>typeof t=="object"&&t!==null,t1=t=>{const e=/^tab-(\d+)$/.exec(t);if(!e)return null;const n=Number(e[1]);return Number.isFinite(n)?n:null};function Un(t){let e=t.trim();for(;e.length>1&&e.endsWith("/");)e=e.slice(0,-1);return e}const oc=(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}),pf=/\x1b\[[0-9;]*m/g,s1=/(https?:\/\/(?:localhost|127\.0\.0\.1|0\.0\.0\.0|\[(?:::1|::)\])(?::\d{2,5})?(?:\/[\w\-./~%!$&'()*+,;=:@?#[\]]*)?)/i,n1=new Set([".",",",";",":","!","?"]),r1=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(n1.has(n)){e=e.slice(0,-1);continue}break}return e},a1=t=>{if(!t)return null;const n=t.replace(pf,"").match(s1);if(!n?.[1])return null;let r=r1(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},i1=t=>{if(!t)return null;const n=t.replace(pf,"").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}/`},lc=t=>({tabs:[t],activeTabId:t.id}),Sr=(t,e)=>t.tabs.findIndex(n=>n.id===e),cn=tr()(gi(Zi((t,e)=>({sessions:new Map,projectActionRuns:{},nextChunkId:1,nextTabId:1,hasHydrated:typeof window>"u",ensureDirectory:n=>{const r=Un(n);r&&t(a=>{if(a.sessions.has(r))return a;const i=new Map(a.sessions),o=`tab-${a.nextTabId}`,c=oc(o,"Terminal");return i.set(r,lc(c)),{sessions:i,nextTabId:a.nextTabId+1}})},getDirectoryState:n=>{const r=Un(n);return e().sessions.get(r)},getActiveTab:n=>{const r=Un(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=Un(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=oc(a,m);return c?o.set(r,{...c,tabs:[...c.tabs,u]}):o.set(r,lc(u)),{sessions:o,nextTabId:d}}),a},setActiveTab:(n,r)=>{const a=Un(n);t(i=>{const o=new Map(i.sessions),c=o.get(a);return!c||c.activeTabId===r||Sr(c,r)<0?i:(o.set(a,{...c,activeTabId:r}),{sessions:o})})},setTabLabel:(n,r,a)=>{const i=Un(n),o=a.trim();o&&t(c=>{const d=new Map(c.sessions),p=d.get(i);if(!p)return c;const m=Sr(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=Un(n);t(o=>{const c=new Map(o.sessions),d=c.get(i);if(!d)return o;const p=Sr(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=Un(n),c=e().sessions.get(a)?.tabs.find(d=>d.id===r)?.terminalSessionId??null;if(c)try{await jx(c)}catch{}t(d=>{const p=new Map(d.sessions),m=p.get(a);if(!m)return d;const u=Sr(m,r);if(u<0)return d;const h=m.tabs.filter(x=>x.id!==r),b=Object.fromEntries(Object.entries(d.projectActionRuns).filter(([,x])=>!(x.directory===a&&x.tabId===r))),f=Object.keys(b).length!==Object.keys(d.projectActionRuns).length;if(h.length===0){const x=`tab-${d.nextTabId}`,g=oc(x,"Terminal");return p.set(a,lc(g)),{sessions:p,nextTabId:d.nextTabId+1,...f?{projectActionRuns:b}:{}}}let v=m.activeTabId;return m.activeTabId===r&&(v=h[Math.min(u,h.length-1)]?.id??h[0]?.id??null),p.set(a,{...m,tabs:h,activeTabId:v}),{sessions:p,...f?{projectActionRuns:b}:{}}})},setTabSessionId:(n,r,a)=>{const i=Un(n);t(o=>{const c=new Map(o.sessions),d=c.get(i);if(!d)return o;const p=Sr(d,r);if(p<0)return o;const m=d.tabs[p],u=a!==null&&m.terminalSessionId!==a,h=a?"running":m.terminalSessionId?"exited":m.lifecycle,b={...m,terminalSessionId:a,lifecycle:h,isConnecting:!1,...u?{bufferChunks:[],bufferLength:0}:{}},f=[...d.tabs];return f[p]=b,c.set(i,{...d,tabs:f}),{sessions:c}})},setTabLifecycle:(n,r,a)=>{const i=Un(n);t(o=>{const c=new Map(o.sessions),d=c.get(i);if(!d)return o;const p=Sr(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=Un(n);t(o=>{const c=new Map(o.sessions),d=c.get(i);if(!d)return o;const p=Sr(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=Un(n);t(o=>{const c=new Map(o.sessions),d=c.get(i);if(!d)return o;const p=Sr(d,r);if(p<0)return o;const m=d.tabs[p],u=o.nextChunkId,h={id:u,data:a},b=[...m.bufferChunks,h];let f=m.bufferLength+a.length;for(;f>Zv&&b.length>1;){const w=b.shift();if(!w)break;f-=w.data.length}const v=m.previewUrlLocked?null:a1(a)??i1(a),x=!!(v&&v!==m.previewUrl),g=[...d.tabs];return g[p]={...m,bufferChunks:b,bufferLength:f,...x?{previewUrl:v,previewAutoOpened:!1}:null},c.set(i,{...d,tabs:g}),{sessions:c,nextChunkId:u+1}})},setTabPreviewUrl:(n,r,a,i={})=>{const o=Un(n);t(c=>{const d=new Map(c.sessions),p=d.get(o);if(!p)return c;const m=Sr(p,r);if(m<0)return c;const u=p.tabs[m],h=i.autoOpened??u.previewAutoOpened,b=i.locked??u.previewUrlLocked;if(u.previewUrl===a&&u.previewAutoOpened===h&&u.previewUrlLocked===b)return c;const f=[...p.tabs];return f[m]={...u,previewUrl:a,previewAutoOpened:h,previewUrlLocked:b},d.set(o,{...p,tabs:f}),{sessions:d}})},markPreviewAutoOpened:(n,r)=>{const a=Un(n);t(i=>{const o=new Map(i.sessions),c=o.get(a);if(!c)return i;const d=Sr(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=Un(n);t(i=>{const o=new Map(i.sessions),c=o.get(a);if(!c)return i;const d=Sr(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=Un(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:e1,storage:vl(()=>Ah()),partialize:t=>({sessions:Array.from(t.sessions.entries()).map(([e,n])=>[e,{activeTabId:n.activeTabId,tabs:n.tabs.map(r=>({id:r.id,label:r.label,iconKey:r.iconKey,terminalSessionId:r.terminalSessionId,lifecycle:r.lifecycle,createdAt:r.createdAt}))}]),nextTabId:t.nextTabId}),merge:(t,e)=>{if(!ic(t))return e;const n=Array.isArray(t.sessions)?t.sessions:[],r=new Map;let a=0;for(const c of n){if(!Array.isArray(c)||c.length!==2)continue;const[d,p]=c;if(typeof d!="string"||!ic(p))continue;const m=Array.isArray(p.tabs)?p.tabs:[],u=[];for(const f of m){if(!ic(f))continue;const v=typeof f.id=="string"?f.id:null;if(!v)continue;const x=t1(v);x!==null&&(a=Math.max(a,x));const g=typeof f.terminalSessionId=="string"||f.terminalSessionId===null?f.terminalSessionId:null,w=f.lifecycle,y=w==="idle"||w==="running"||w==="exited"?w:g?"running":"idle";u.push({id:v,label:typeof f.label=="string"?f.label:"Terminal",iconKey:typeof f.iconKey=="string"?f.iconKey:null,terminalSessionId:g,lifecycle:y,createdAt:typeof f.createdAt=="number"?f.createdAt:Date.now(),bufferChunks:[],bufferLength:0,isConnecting:!1,previewUrl:null,previewAutoOpened:!1,previewUrlLocked:!1})}if(u.length===0)continue;const h=typeof p.activeTabId=="string"?p.activeTabId:null,b=h?u.some(f=>f.id===h):!1;r.set(d,{tabs:u,activeTabId:b?h: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"&&!Ju){Ju=!0;const t=cn.persist,e=()=>{cn.getState().hasHydrated||cn.setState({hasHydrated:!0})};t?.hasHydrated?.()?e():t?.onFinishHydration?t.onFinishHydration(e):e()}const Qu=(t,e)=>e.updatedAtMs-t.updatedAtMs,Js=tr((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([Ax(),pu()]),a={};for(const i of r.sort(Qu))a[i.id]=i;e().listenerReady||await Dx(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 Px();t({importCandidates:n,isImportsLoading:!1})}catch(n){t({isImportsLoading:!1,error:n instanceof Error?n.message:String(n)})}}},refreshStatuses:async()=>{try{const n=await pu(),r={};for(const a of n.sort(Qu))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 Ix({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=Tx(n,r);a&&a.trim()&&(i.nickname=a.trim()),await e().upsertInstance(i)},removeInstance:async n=>{await mu(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 Cx(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 mu(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})})),hf=[{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"}],Vo=Object.fromEntries(hf.map(t=>[t.key,t.Icon])),Xc="openchamber:project-actions-updated",ff=t=>{const e=(t||"").trim().replace(/\\/g,"/");return e?e==="/"?"/":e.length>1?e.replace(/\/+$/,""):e:""},Yr=(t,e)=>`${ff(t)}::${e}`,o1=t=>{const e=t.trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},Yu=t=>{if(typeof t!="number"||!Number.isFinite(t))return null;const e=Math.round(t);return e<1||e>65535?null:e},l1=(t,e)=>{if(!e.enabled||e.type!=="local")return null;const n=Yu(e.localPort),r=Yu(e.remotePort);if(!n||!r)return null;const a=o1(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}`}},gf=t=>{const e=[];for(const n of t)if(!(!n?.id||!Array.isArray(n.portForwards)))for(const r of n.portForwards){const a=l1(n,r);a&&e.push(a)}return e},c1=(t,e)=>{const n=(t||"").trim();return n&&gf(e).find(i=>i.id===n)?.url||null},d1=[{pattern:/^dev(:.*)?$/i},{pattern:/^start(:.*)?$/i},{pattern:/^preview(:.*)?$/i},{pattern:/^serve(:.*)?$/i},{pattern:/^develop(:.*)?$/i}],u1=["dev","start","preview","serve"];async function m1(t,e,n){if(!t)return null;const r=f1(e);if(r)return{command:r.command,label:r.name||"Start Preview",actionId:r.id};if(n){const a=g1(n);if(a){const i=await x1(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 p1(t)){const a=await h1(),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 p1(t){const e=`${t}/index.html`,n=await ll(e);return typeof n=="string"&&n.trim().length>0}async function h1(){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 f1(t){for(const e of t){const n=`${e.name} ${e.command}`.toLowerCase();if(u1.some(a=>n.includes(a)))return e}return null}function g1(t){for(const{pattern:e}of d1)for(const n of Object.keys(t))if(e.test(n))return n;return null}async function x1(t){const e=await ll(`${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 ll(`${t}/${r}`);if(typeof i=="string"&&i.trim().length>0)return a}return"npm"}async function ll(t){const e=dr()?.files;if(e?.readFile)try{const n=await e.readFile(t,{optional:!0});return typeof n?.content=="string"?n.content:null}catch{return null}try{const n=await fetch(`/api/fs/read?path=${encodeURIComponent(t)}&optional=true`,{cache:"no-store"});return n.ok?n.text():null}catch{return null}}async function b1(t){try{const e=await ll(`${t}/package.json`);return e==null?null:JSON.parse(e).scripts||null}catch{return null}}const y1=t=>new Promise(e=>{window.setTimeout(e,t)}),v1="\x1B",w1=new RegExp(`${v1}\\[[0-9;?]*[ -/]*[@-~]`,"g"),j1=/https?:\/\/[^\s<>'"`]+/gi,rr="__openchamber_auto_discover_preview__",N1=15e3,S1=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},k1=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}},C1=t=>{const n=t.replace(w1,"").match(j1);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,h=m==="/"||m==="",b=!!(c.search||c.hash);let f=0;return p&&(f+=50),h&&(f+=30),f-=Math.min(u*5,20),b&&(f-=10),f};return a.sort((o,c)=>i(c)-i(o)),a[0]?.parsed.origin??a[0]?.raw??null}return r[0]??null},I1=(t,e)=>{const n=t.trim();if(!n)return e;const r=n.split(/\s+/).filter(Boolean);if(r.length>=2){const a=r[0],i=r[1].slice(0,3),o=`${a} ${i}`.trim();return r.length>2||o.length<n.length?`${o}...`:o}return n.length>12?`${n.slice(0,9).trimEnd()}...`:n},Xu=({projectRef:t,directory:e,className:n,compact:r=!1,allowMobile:a=!1})=>{const{t:i}=pt(),{terminal:o,runtime:c}=_n(),{isMobile:d}=an(),p=l.useMemo(()=>yn(),[]),m=Js(G=>G.instances),u=Js(G=>G.load),h=Te(G=>G.setBottomTerminalOpen),b=Te(G=>G.setActiveMainTab),f=Te(G=>G.setSettingsPage),v=Te(G=>G.setSettingsDialogOpen),x=Te(G=>G.setSettingsProjectsSelectedId),g=Te(G=>G.openContextPreview),w=cn(G=>G.sessions),y=cn(G=>G.ensureDirectory),k=cn(G=>G.setTabLabel),D=cn(G=>G.setTabIconKey),j=cn(G=>G.setActiveTab),S=cn(G=>G.setConnecting),A=cn(G=>G.setTabSessionId),E=cn(G=>G.setTabPreviewUrl),P=cn(G=>G.projectActionRuns),C=cn(G=>G.setProjectActionRun),N=cn(G=>G.updateProjectActionRunStatus),T=cn(G=>G.removeProjectActionRun),[M,R]=l.useState([]),[L,$]=l.useState(null),[B,O]=l.useState(!1),_=l.useRef({}),ee=l.useRef({}),z=l.useRef({}),ne=l.useRef({}),re=l.useRef(0),ue=t?.id??null,Q=t?.path??"",de=l.useMemo(()=>ue?{id:ue,path:Q}:null,[ue,Q]);l.useEffect(()=>{p&&u().catch(()=>{})},[p,u]);const X=l.useCallback(async G=>{await Xn(G)},[]),F=l.useCallback(async()=>{if(!de)return;const G=re.current+1;re.current=G,O(!0);try{const Pe=await Wc(de);if(re.current!==G)return;const Le=Pe.actions;R(Le),$(Ae=>Ae===rr||Ae&&Le.some(ge=>ge.id===Ae)?Ae:null)}catch{if(re.current!==G)return}finally{re.current===G&&O(!1)}},[de]),V=l.useMemo(()=>ff(e||de?.path||""),[e,de?.path]),q=l.useMemo(()=>L?M.find(G=>G.id===L)??null:null,[M,L]),te=l.useMemo(()=>({id:rr,name:i("projectActions.actions.autoDiscover"),command:"",icon:"search",autoOpenUrl:!0}),[i]),U=!d,ae=l.useMemo(()=>U?[te,...M]:M,[M,te,U]);l.useEffect(()=>{F()},[F]),l.useEffect(()=>{if(typeof window>"u")return;const G=Pe=>{const Le=Pe.detail;ue&&(Le?.projectId&&Le.projectId!==ue||F())};return window.addEventListener(Xc,G),()=>{window.removeEventListener(Xc,G)}},[F,ue]),l.useEffect(()=>{L&&(L===rr&&U||M.some(G=>G.id===L)||$(null))},[M,U,L]),l.useEffect(()=>{for(const[G,Pe]of Object.entries(P)){const Ae=w.get(Pe.directory)?.tabs.find(ge=>ge.id===Pe.tabId);(!Ae||Ae.terminalSessionId!==Pe.sessionId)&&T(G)}},[P,T,w]),l.useEffect(()=>{for(const[G,Pe]of Object.entries(P)){const Le=ee.current[G]??{lastSeenChunkId:null,openedUrl:!1,tail:"",openInPreview:!1};ee.current[G]=Le;const Ae=ae.find(De=>De.id===Pe.actionId);if(!Ae)continue;const W=w.get(Pe.directory)?.tabs.find(De=>De.id===Pe.tabId);if(!W||!Array.isArray(W.bufferChunks)||W.bufferChunks.length===0)continue;const ie=W.bufferChunks.filter(De=>Le.lastSeenChunkId===null?!0:De.id>Le.lastSeenChunkId);if(ie.length===0)continue;const Me=ie.map(De=>De.data).join(""),Ve=`${Le.tail}${Me}`,Ce=!Le.openedUrl&&Ae.autoOpenUrl===!0?C1(Ve):null,xe=ie[ie.length-1]?.id??Le.lastSeenChunkId;if(Le.lastSeenChunkId=xe,Le.tail=Ve.slice(-512),Ce)if(Le.openedUrl=!0,Le.openInPreview){const De=P[G];De&&(E(De.directory,De.tabId,Ce,{locked:!1,autoOpened:!1}),De.status==="waiting-for-preview"&&N(G,"running"),window.clearTimeout(ne.current[G]),delete ne.current[G],g(De.directory,Ce))}else X(Ce),H.success(i("projectActions.toast.openedUrlFromOutput"));ee.current[G]=Le}for(const G of Object.keys(ee.current))P[G]||(delete ee.current[G],window.clearTimeout(ne.current[G]),delete ne.current[G])},[ae,g,X,P,E,i,w,N]);const je=l.useCallback(async(G,Pe={})=>{if(!V)throw new Error(i("projectActions.error.noActiveDirectory"));const Le=Yr(V,G.id);y(V);const Ae=cn.getState(),ge=Ae.getDirectoryState(V);let W=_.current[Le]||null;const ie=W?!!ge?.tabs.some(Ce=>Ce.id===W):!1;(!W||!ie)&&(W=Ae.createTab(V),_.current[Le]=W),k(V,W,`Action: ${G.name}`),D(V,W,G.icon||"play"),Pe.revealTerminal!==!1&&(j(V,W),h(!0),b("terminal"));const Ve=cn.getState().getDirectoryState(V)?.tabs.find(Ce=>Ce.id===W);return{key:Le,tabId:W,sessionId:Ve?.terminalSessionId??null}},[y,V,b,j,h,D,k,i]),oe=l.useCallback(async G=>{if(c.isVSCode||!a&&d)return;if(!V){H.error(i("projectActions.error.noActiveDirectoryForAction"));return}const Pe=Yr(V,G.id),Le=P[Pe];if(!(Le&&Le.status==="running"))try{const Ae=G.id===rr?await(async()=>{const[Re,he]=await Promise.all([Wc({id:de?.id??"",path:V}),b1(V)]),qe=await m1(V,Re.actions,he);if(!qe)throw new Error(i("contextPanel.preview.noDevServer"));return{id:rr,name:i("projectActions.actions.autoDiscover"),command:qe.command,icon:"search",autoOpenUrl:!0,openUrl:qe.previewUrlHint||""}})():G,ge=Ae.autoOpenUrl===!0&&(Ae.openUrl||"").trim().length>0,{key:W,tabId:ie,sessionId:Me}=await je(Ae,{revealTerminal:!ge&&G.id!==rr});let Ve=Me,Ce=!1;if(!Ve){S(V,ie,!0);try{Ve=(await o.createSession({cwd:V})).sessionId,Ce=!0,A(V,ie,Ve)}finally{S(V,ie,!1)}}if(!Ve)throw new Error(i("projectActions.error.failedToCreateTerminalSession"));Ce&&await y1(350),Ae.id===rr&&(z.current[W]?.(),S(V,ie,!0),z.current[W]=Nx(Ve,Re=>{Re.type==="data"&&typeof Re.data=="string"&&Re.data.length>0&&cn.getState().appendToBuffer(V,ie,Re.data),Re.type==="exit"&&(cn.getState().setTabLifecycle(V,ie,"exited"),cn.getState().setConnecting(V,ie,!1),cn.getState().removeProjectActionRun(W),delete ee.current[W],z.current[W]?.(),delete z.current[W],window.clearTimeout(ne.current[W]),delete ne.current[W])},()=>{cn.getState().setConnecting(V,ie,!1)},{maxRetries:60,initialRetryDelay:250,maxRetryDelay:2e3,connectionTimeout:5e3}));const xe=Ae.autoOpenUrl===!0&&p&&(Ae.desktopOpenSshForward||"").trim().length>0,De=Ae.autoOpenUrl?k1(Ae.openUrl):null,Ye=Ae.autoOpenUrl&&p?c1(Ae.desktopOpenSshForward,m):null;C({key:W,directory:V,actionId:Ae.id,tabId:ie,sessionId:Ve,status:Ae.id===rr&&!De?"waiting-for-preview":"running"}),window.clearTimeout(ne.current[W]),delete ne.current[W],Ae.id===rr&&!De&&(ne.current[W]=window.setTimeout(()=>{cn.getState().updateProjectActionRunStatus(W,"running"),delete ne.current[W]},N1)),Ye?(E(V,ie,null,{locked:!0}),X(Ye),H.success(i("projectActions.toast.openedForwardedUrl"))):De?(E(V,ie,De,{locked:!0,autoOpened:!0}),g(V,De),H.success(i("projectActions.toast.openedActionUrl"))):ge?(E(V,ie,null,{locked:!0}),H.error(i("projectActions.error.invalidCustomUrlFormat"))):xe?(E(V,ie,null,{locked:!0}),H.error(i("projectActions.error.selectedDesktopSshForwardUnavailable"))):E(V,ie,null,{locked:!1,autoOpened:!1}),ee.current[W]={lastSeenChunkId:null,openedUrl:!!Ye||!!De||ge,tail:"",openInPreview:Ae.id===rr};const rt=S1(Ae.command.trim().replace(/\r\n|\r/g,`
3
- `));await o.sendInput(Ve,`${rt}\r`)}catch(Ae){T(Pe),delete ee.current[Pe],z.current[Pe]?.(),delete z.current[Pe],window.clearTimeout(ne.current[Pe]),delete ne.current[Pe],H.error(Ae instanceof Error?Ae.message:i("projectActions.error.failedToRunAction"))}},[m,je,a,d,p,V,X,g,P,c.isVSCode,T,S,C,E,A,de?.id,i,o]),ve=l.useCallback(async G=>{const Pe=Yr(V,G.id),Le=P[Pe];if(!Le)return;N(Pe,"stopping");try{await o.sendInput(Le.sessionId,"")}catch{}if(await new Promise(W=>{window.setTimeout(W,1e3)}),cn.getState().getDirectoryState(Le.directory)?.tabs.find(W=>W.id===Le.tabId)?.terminalSessionId===Le.sessionId){if(typeof o.forceKill=="function")try{await o.forceKill({sessionId:Le.sessionId})}catch{}else try{await o.close(Le.sessionId)}catch{}A(Le.directory,Le.tabId,null)}T(Pe),delete ee.current[Pe],z.current[Pe]?.(),delete z.current[Pe],window.clearTimeout(ne.current[Pe]),delete ne.current[Pe]},[V,P,T,A,o,N]),K=l.useCallback(()=>{const G=q??ae[0];if(!G)return;const Pe=Yr(V,G.id),Le=P[Pe];if(Le?.status!=="stopping"){if(Le){ve(G);return}oe(G)}},[ae,V,oe,P,q,ve]),ce=l.useCallback((G,Pe=!1)=>{if($(G.id),!Pe){oe(G);return}const Le=Yr(V,G.id),Ae=P[Le];if(Ae?.status!=="stopping"){if(Ae){ve(G);return}oe(G)}},[V,oe,P,ve]),Z=l.useCallback(()=>{de?.id&&(x(de.id),f("projects"),v(!0))},[v,f,x,de?.id]);if(c.isVSCode||!a&&d||!de||!V)return null;const le=q??ae[0]??null;if(!le)return null;const se=le.icon||"play",Ie=le.id===rr?"search":Vo[se]||"play",Ne=I1(le.name,i("projectActions.label.fallbackAction")),Y=Yr(V,le.id),fe=P[Y],ke=fe?.status==="stopping",be=fe?.status==="waiting-for-preview",pe=fe?w.get(fe.directory)?.tabs.find(G=>G.id===fe.tabId)?.previewUrl??null:null,Ee=!!(fe&&pe),ze=()=>{!fe||!pe||g(fe.directory,pe)};return r?s.jsxs("div",{className:"inline-flex items-center",children:[s.jsx("button",{type:"button",disabled:B||ke,className:me("app-region-no-drag inline-flex h-9 w-9 items-center justify-center rounded-[10px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] p-2","typography-ui-label font-medium text-muted-foreground hover:bg-interactive-hover hover:text-foreground transition-colors","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","disabled:cursor-not-allowed",n),onClick:K,"aria-label":fe?i("projectActions.actions.stopNamedAria",{name:le.name}):i("projectActions.actions.runNamedAria",{name:le.name}),children:ke||be?s.jsx(I,{name:"loader-4",className:"h-5 w-5 animate-spin text-[var(--status-warning)]"}):fe?s.jsx(I,{name:"stop",className:"h-5 w-5 text-[var(--status-warning)]"}):s.jsx(I,{name:Ie,className:"h-5 w-5"})}),Ee?s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",className:"app-region-no-drag -ml-1 inline-flex h-9 w-7 items-center justify-center rounded-[10px] text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":i("projectActions.actions.openPreview"),onClick:ze,children:s.jsx(I,{name:"global",className:"h-4 w-4"})})}),s.jsx(Pt,{sideOffset:6,children:i("projectActions.actions.openPreview")})]}):null,s.jsxs(Bs,{children:[s.jsx(Os,{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(I,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})}),s.jsxs($s,{align:"end",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs(zt,{className:"flex items-center gap-2",onClick:Z,children:[s.jsx(I,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("projectActions.actions.addNewAction")})]}),s.jsx(Dn,{}),ae.map(G=>{const Pe=G.icon||"play",Le=G.id===rr?"search":Vo[Pe]||"play",Ae=Yr(V,G.id),ge=P[Ae],W=!!ge,ie=ge?.status==="stopping";return s.jsxs(zt,{className:"flex items-center gap-2",onClick:()=>{ce(G,!0)},children:[s.jsx(I,{name:Le,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:G.name}),ie||ge?.status==="waiting-for-preview"?s.jsx(I,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):W?s.jsx(I,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},G.id)})]})]})]}):s.jsxs("div",{className:me("app-region-no-drag inline-flex shrink-0 items-center self-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px]","bg-[var(--surface-elevated)] overflow-hidden","border border-border/60",r?"h-9":"h-7",n),children:[s.jsxs("button",{type:"button",onClick:K,disabled:B||ke,className:me("inline-flex h-full items-center typography-ui-label font-medium text-foreground hover:bg-interactive-hover",r?"w-9 justify-center px-0":"gap-2 px-3","transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed"),"aria-label":fe?i("projectActions.actions.stopNamedAria",{name:le.name}):i("projectActions.actions.runNamedAria",{name:le.name}),children:[s.jsx("span",{className:"inline-flex h-4 w-4 shrink-0 items-center justify-center",children:ke||be?s.jsx(I,{name:"loader-4",className:"h-4 w-4 animate-spin text-[var(--status-warning)]"}):fe?s.jsx(I,{name:"stop",className:"h-4 w-4 text-[var(--status-warning)]"}):s.jsx(I,{name:Ie,className:"h-4 w-4"})}),r?null:s.jsx("span",{className:"header-open-label whitespace-nowrap",children:Ne})]}),Ee?s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:ze,className:me(r?"inline-flex h-full w-8 items-center justify-center":"inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-foreground","hover:bg-interactive-hover transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),"aria-label":i("projectActions.actions.openPreview"),children:s.jsx(I,{name:"global",className:"h-4 w-4"})})}),s.jsx(Pt,{sideOffset:6,children:i("projectActions.actions.openPreview")})]}):null,s.jsxs(Bs,{children:[s.jsx(Os,{asChild:!0,children:s.jsx("button",{type:"button",className:me(r?"inline-flex h-full w-8 items-center justify-center":"inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-muted-foreground","hover:bg-interactive-hover hover:text-foreground transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),"aria-label":i("projectActions.actions.chooseActionAria"),children:s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4"})})}),s.jsxs($s,{align:"center",className:"w-52 max-h-[70vh] overflow-y-auto",style:{translate:"-30px 0"},children:[s.jsxs(zt,{className:"flex items-center gap-2",onClick:Z,children:[s.jsx(I,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("projectActions.actions.addNewAction")})]}),s.jsx(Dn,{}),ae.map(G=>{const Pe=G.icon||"play",Le=G.id===rr?"search":Vo[Pe]||"play",Ae=Yr(V,G.id),ge=P[Ae],W=!!ge,ie=ge?.status==="stopping";return s.jsxs(zt,{className:"flex items-center gap-2",onClick:()=>{ce(G)},children:[s.jsx(I,{name:Le,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:G.name}),ie||ge?.status==="waiting-for-preview"?s.jsx(I,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):W?s.jsx(I,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},G.id)})]})]})]})},Dl="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",P1="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",Ni=l.memo(function(e){const n=at.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??Dl,h=p??"h-[18px] w-[18px]";let b;n[0]!==d||n[1]!==h?(b=s.jsx(I,{name:d,className:h}),n[0]=d,n[1]=h,n[2]=b):b=n[2];let f;n[3]!==i||n[4]!==o||n[5]!==u||n[6]!==b?(f=s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:o,"aria-label":i,className:u,children:b})}),n[3]=i,n[4]=o,n[5]=u,n[6]=b,n[7]=f):f=n[7];let v;n[8]!==a?(v=s.jsx(Pt,{children:s.jsx("p",{children:a})}),n[8]=a,n[9]=v):v=n[9];let x;return n[10]!==f||n[11]!==v?(x=s.jsxs(kt,{children:[f,v]}),n[10]=f,n[11]=v,n[12]=x):x=n[12],x}),A1=l.memo(function(e){const n=at.c(42),{isMobile:r,githubAuthStatus:a,githubAccounts:i,githubAvatarUrl:o,githubLogin:c,isSwitchingGitHubAccount:d,handleGitHubAccountSwitch:p}=e,{t:m}=pt();if(!a?.connected||r)return null;if(i.length>1){let f;n[0]===Symbol.for("react.memo_cache_sentinel")?(f=me(Dl,"h-7 w-7 overflow-hidden rounded-full border border-border/60 bg-muted/80 p-0"),n[0]=f):f=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(I,{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(Os,{asChild:!0,children:s.jsx("button",{type:"button",className:f,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($i,{className:"typography-ui-header font-semibold text-foreground",children:w}),n[14]=w,n[15]=y):y=n[15];let k;n[16]===Symbol.for("react.memo_cache_sentinel")?(k=s.jsx(Dn,{}),n[16]=k):k=n[16];let D;if(n[17]!==i||n[18]!==p||n[19]!==d||n[20]!==m){let A;n[22]!==p||n[23]!==d||n[24]!==m?(A=E=>{const P=E.user,C=!!E.current;return s.jsxs(zt,{className:"gap-2",disabled:C||d,onSelect:()=>{C||p(E.id)},children:[P?.avatarUrl?s.jsx("img",{src:P.avatarUrl,alt:P.login?m("header.github.avatarWithLogin",{login:P.login}):m("header.github.avatar"),className:"h-6 w-6 rounded-full border border-border/60 bg-muted object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-6 w-6 items-center justify-center rounded-full border border-border/60 bg-muted",children:s.jsx(I,{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]}),C?s.jsx(I,{name:"check",className:"h-4 w-4 text-primary"}):null]},E.id)},n[22]=p,n[23]=d,n[24]=m,n[25]=A):A=n[25],D=i.map(A),n[17]=i,n[18]=p,n[19]=d,n[20]=m,n[21]=D}else D=n[21];let j;n[26]!==y||n[27]!==D?(j=s.jsxs($s,{align:"end",className:"w-64",children:[y,k,D]}),n[26]=y,n[27]=D,n[28]=j):j=n[28];let S;return n[29]!==g||n[30]!==j?(S=s.jsxs(Bs,{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 h;n[35]!==o||n[36]!==c||n[37]!==m?(h=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(I,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"}),n[35]=o,n[36]=c,n[37]=m,n[38]=h):h=n[38];let b;return n[39]!==u||n[40]!==h?(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:h}),n[39]=u,n[40]=h,n[41]=b):b=n[41],b}),D1=l.memo(function(e){const n=at.c(76),{isDesktopApp:r,currentInstanceLabel:a,compactCurrentInstanceLabel:i,isDesktopServicesOpen:o,setIsDesktopServicesOpen:c,refreshCurrentInstanceLabel:d,desktopServicesTab:p,setDesktopServicesTab:m,quotaResultsLength:u,fetchAllQuotas:h,servicesTabItems:b,quotaLastUpdated:f,quotaDisplayMode:v,quotaDisplayTabItems:x,handleDisplayModeChange:g,handleUsageRefresh:w,isQuotaLoading:y,isUsageRefreshSpinning:k,hasRateLimits:D,rateLimitGroups:j,expandedFamilies:S,toggleFamilyExpanded:A,shortcutLabel:E,showDevShutdown:P,isDevShutdownInFlight:C,onDevShutdown:N}=e,{t:T}=pt();let M;n[0]!==p||n[1]!==h||n[2]!==u||n[3]!==d||n[4]!==c?(M=te=>{c(te),te&&(d(),p==="usage"&&u===0&&h())},n[0]=p,n[1]=h,n[2]=u,n[3]=d,n[4]=c,n[5]=M):M=n[5];let R;n[6]!==a||n[7]!==r||n[8]!==T?(R=r?T("header.services.openWithCurrent",{current:a}):T("header.services.open"),n[6]=a,n[7]=r,n[8]=T,n[9]=R):R=n[9];const L=r?"w-auto max-w-[14rem] justify-start gap-1.5 px-2.5":"h-8 w-8";let $;n[10]!==L?($=me(Dl,L),n[10]=L,n[11]=$):$=n[11];let B;n[12]===Symbol.for("react.memo_cache_sentinel")?(B=s.jsx(I,{name:"stack",className:"h-[18px] w-[18px]"}),n[12]=B):B=n[12];let O;n[13]!==i||n[14]!==r?(O=r?s.jsx("span",{className:"truncate typography-ui-label font-medium text-foreground",children:i}):null,n[13]=i,n[14]=r,n[15]=O):O=n[15];let _;n[16]!==R||n[17]!==$||n[18]!==O?(_=s.jsx(Ct,{asChild:!0,children:s.jsx(Os,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":R,className:$,children:[B,O]})})}),n[16]=R,n[17]=$,n[18]=O,n[19]=_):_=n[19];let ee;n[20]!==a||n[21]!==r||n[22]!==E||n[23]!==T?(ee=r?T("header.services.tooltip.currentInstanceWithShortcuts",{current:a,toggle:E("toggle_services_menu"),nextTab:E("cycle_services_tab")}):T("header.services.tooltip.servicesWithShortcuts",{toggle:E("toggle_services_menu"),nextTab:E("cycle_services_tab")}),n[20]=a,n[21]=r,n[22]=E,n[23]=T,n[24]=ee):ee=n[24];let z;n[25]!==ee?(z=s.jsx(Pt,{children:s.jsx("p",{children:ee})}),n[25]=ee,n[26]=z):z=n[26];let ne;n[27]!==_||n[28]!==z?(ne=s.jsxs(kt,{children:[_,z]}),n[27]=_,n[28]=z,n[29]=ne):ne=n[29];let re;n[30]!==h||n[31]!==u||n[32]!==m?(re=te=>{const U=te;m(U),U==="usage"&&u===0&&h()},n[30]=h,n[31]=u,n[32]=m,n[33]=re):re=n[33];let ue;n[34]!==p||n[35]!==b||n[36]!==re?(ue=s.jsx("div",{className:"sticky top-0 z-20 px-2 pt-1.5 pb-px",children:s.jsx("div",{className:"h-9",children:s.jsx(Ar,{items:b,activeId:p,onSelect:re,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]=re,n[37]=ue):ue=n[37];let Q;n[38]!==p||n[39]!==r||n[40]!==o||n[41]!==c?(Q=r&&p==="instance"?s.jsx(Mx,{embedded:!0,open:o&&p==="instance",onOpenChange:E1,onHostSwitched:()=>c(!1)}):null,n[38]=p,n[39]=r,n[40]=o,n[41]=c,n[42]=Q):Q=n[42];let de;n[43]!==p||n[44]!==o?(de=p==="mcp"?s.jsx(mf,{active:o&&p==="mcp"}):null,n[43]=p,n[44]=o,n[45]=de):de=n[45];let X;n[46]!==p||n[47]!==S||n[48]!==g||n[49]!==w||n[50]!==D||n[51]!==y||n[52]!==k||n[53]!==v||n[54]!==x||n[55]!==f||n[56]!==j||n[57]!==T||n[58]!==A?(X=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:T("header.services.rateLimits")}),s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:xf(f)})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("div",{className:"h-7 w-[10.5rem]",children:s.jsx(Ar,{items:x,activeId:v,onSelect:te=>{g(te)},layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",className:"h-full"})}),s.jsx("button",{type:"button",className:me("inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors","hover:text-foreground hover:bg-interactive-hover","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),onClick:w,disabled:y||k,"aria-label":T("header.services.refreshRateLimitsAria"),children:s.jsx(I,{name:"refresh",className:me("h-4 w-4",k&&"animate-spin")})})]})]}),D?null:s.jsx("div",{className:"px-4 py-5 text-center",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:T("header.services.noRateLimits")})}),s.jsx("div",{className:"py-2",children:j.map((te,U)=>{const ae=S[te.providerId]??[];return s.jsxs(l.Fragment,{children:[U>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(Sn,{providerId:te.providerId,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:te.providerName})]}),te.entries.length===0&&(!te.modelFamilies||te.modelFamilies.length===0)?s.jsx("div",{className:"px-4 pb-2",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:te.error??T("header.services.noRateLimitsReported")})}):s.jsxs("div",{className:"space-y-3 px-4 pb-2",children:[te.entries.map(je=>{const[oe,ve]=je,K=v==="remaining"?ve.remainingPercent:ve.usedPercent,ce=Ji(ve.usedPercent,ve.resetAt,ve.windowSeconds,oe),Z=ce?.dailyAllocationPercent!=null?v==="remaining"?100-_r(ce.elapsedRatio):_r(ce.elapsedRatio):null,le=qi(ve.valueLabel,K),se=Vd(ve.resetAt,ve.resetAfterFormatted??ve.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:zd(oe)}),se?s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:se}):null]}),s.jsx("span",{className:"typography-ui-label tabular-nums text-foreground",children:le==="-"?"":le})]}),s.jsx(Yi,{percent:K,tonePercent:ve.usedPercent,className:"h-1.5",expectedMarkerPercent:Z}),ce?s.jsx(Xi,{paceInfo:ce,compact:!0}):null]},`${te.providerId}-${oe}`)}),te.modelFamilies&&te.modelFamilies.length>0?s.jsx("div",{className:"space-y-0.5",children:te.modelFamilies.map(je=>{const oe=je.familyId??"other",ve=ae.includes(oe);return s.jsxs(ur,{open:ve,onOpenChange:()=>A(te.providerId,oe),children:[s.jsxs(wr,{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:je.familyLabel}),ve?s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(I,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsx(mr,{children:s.jsx("div",{className:"space-y-2.5 pb-1 pl-1 pt-1",children:je.models.map(K=>{const[ce,Z]=K,le=v==="remaining"?Z.remainingPercent:Z.usedPercent,se=Ji(Z.usedPercent,Z.resetAt,Z.windowSeconds),Ie=se?.dailyAllocationPercent!=null?v==="remaining"?100-_r(se.elapsedRatio):_r(se.elapsedRatio):null,Ne=qi(Z.valueLabel,le);return s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3",children:[s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:il(ce)}),s.jsx("span",{className:"typography-ui-label tabular-nums text-foreground",children:Ne==="-"?"":Ne})]}),s.jsx(Yi,{percent:le,tonePercent:Z.usedPercent,className:"h-1.5",expectedMarkerPercent:Ie}),se?s.jsx(Xi,{paceInfo:se,compact:!0}):null]},`${te.providerId}-${ce}`)})})})]},oe)})}):null]})]},te.providerId)})})]}):null,n[46]=p,n[47]=S,n[48]=g,n[49]=w,n[50]=D,n[51]=y,n[52]=k,n[53]=v,n[54]=x,n[55]=f,n[56]=j,n[57]=T,n[58]=A,n[59]=X):X=n[59];let F;n[60]!==C||n[61]!==N||n[62]!==P||n[63]!==T?(F=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(zt,{disabled:C,onSelect:()=>{N()},children:T("header.services.shutdownDev")})})]}):null,n[60]=C,n[61]=N,n[62]=P,n[63]=T,n[64]=F):F=n[64];let V;n[65]!==ue||n[66]!==Q||n[67]!==de||n[68]!==X||n[69]!==F?(V=s.jsxs($s,{align:"end",className:"w-[min(27rem,calc(100vw-2rem))] max-h-[75vh] overflow-y-auto bg-[var(--surface-elevated)] p-0",children:[ue,Q,de,X,F]}),n[65]=ue,n[66]=Q,n[67]=de,n[68]=X,n[69]=F,n[70]=V):V=n[70];let q;return n[71]!==o||n[72]!==M||n[73]!==ne||n[74]!==V?(q=s.jsxs(Bs,{open:o,onOpenChange:M,children:[ne,V]}),n[71]=o,n[72]=M,n[73]=ne,n[74]=V,n[75]=q):q=n[75],q}),T1=(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??""),M1=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},xf=t=>{if(!t)return"-";try{return new Date(t).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"})}catch{return"-"}},ar=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},yo=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,Zu=({onToggleLeftDrawer:t,onToggleRightDrawer:e,leftDrawerOpen:n,rightDrawerOpen:r,desktopRightSidebarActionsHost:a=null})=>{const{t:i}=pt(),o=Te($e=>$e.setSessionSwitcherOpen),c=Te($e=>$e.toggleSidebar),d=Te($e=>$e.isSidebarOpen),p=Te($e=>$e.isRightSidebarOpen),m=Te($e=>$e.toggleBottomTerminal),u=Te($e=>$e.toggleRightSidebar),h=Te($e=>$e.openContextOverview),b=Te($e=>$e.openContextPlan),f=Te($e=>$e.openContextBrowser),v=Te($e=>$e.closeContextPanel),x=Te($e=>$e.contextPanelByDirectory),g=Te($e=>$e.activeMainTab),w=Te($e=>$e.setActiveMainTab),y=Te($e=>$e.shortcutOverrides),k=gt($e=>$e.getCurrentModel),D=_n(),[j,S]=l.useState(!1),A=Vt($e=>$e.getContextUsage),E=Vt($e=>$e.openNewSessionDraft),P=Vt($e=>!!$e.newSessionDraft?.open),C=Vt($e=>$e.currentSessionId),N=Ex(C??""),T=Dh(C??null),M=ja($e=>$e.activeSessions),R=Cd(),L=Fs($e=>$e.activeProjectId?$e.projects.find(Ft=>Ft.id===$e.activeProjectId)??null:null),$=l.useMemo(()=>{if(!L)return null;const $e=L.label?.trim();if($e)return $e;const Ft=L.path.split(/[\\/]/).filter(Boolean);return Ft[Ft.length-1]??null},[L]),B=Ls($e=>$e.results),O=Ls($e=>$e.fetchAllQuotas),_=Ls($e=>$e.isLoading),ee=Ls($e=>$e.lastUpdated),z=Ls($e=>$e.displayMode),ne=Ls($e=>$e.dropdownProviderIds),re=Ls($e=>$e.loadSettings),ue=Ls($e=>$e.setDisplayMode),{isMobile:Q}=an(),de=Kn($e=>$e.status),X=Kn($e=>$e.setStatus),F=l.useRef(null),[V,q]=l.useState(()=>typeof window>"u"?!1:yn()),te=l.useMemo(()=>Id(),[]),U=wl(),[ae,je]=l.useState(!1),oe=l.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),ve=l.useMemo(()=>{if(typeof window>"u")return null;const $e=window.__OPENCHAMBER_MACOS_MAJOR__;if(typeof $e=="number"&&Number.isFinite($e)&&$e>0)return $e;if(typeof navigator>"u")return null;const Ft=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!Ft)return null;const as=Number.parseInt(Ft[1],10),fs=Number.parseInt(Ft[2],10);return Number.isNaN(as)?null:as===10?fs:as},[]);Be.useEffect(()=>{typeof window>"u"||q(yn())},[]);const K=k(),ce=K&&typeof K.limit=="object"&&K.limit!==null?K.limit:null,Z=ce&&typeof ce.context=="number"?ce.context:0,le=ce&&typeof ce.output=="number"?ce.output:0,se=A(Z,le),[Ie,Ne]=l.useState(null),Y=!C||N;Be.useEffect(()=>{if(!C){Ne($e=>$e===null?$e:null);return}if(se&&se.totalTokens>0){Ne($e=>T1($e,se)?$e:se);return}Y&&Ne($e=>$e===null?$e:null)},[se,C,Y]);const fe=Te($e=>$e.isSessionSwitcherOpen),ke=de?.connected?de.user?.avatarUrl??null:null,be=de?.connected?de.user?.login??null:null,pe=de?.accounts??[],[Ee,ze]=l.useState(!1),[G,Pe]=l.useState(!1),[Le,Ae]=l.useState(!1),[ge,W]=l.useState(!1),[ie,Me]=l.useState("Local"),Ve=l.useMemo(()=>M1(ie),[ie]),[Ce,xe]=l.useState(V?"instance":"usage"),[De,Ye]=l.useState("usage");Be.useEffect(()=>{!V&&Ce==="instance"&&xe("usage")},[Ce,V]);const rt=l.useMemo(()=>dn(),[]),Re=l.useMemo(()=>Q?typeof t=="function"?!!n:fe:d,[Q,fe,d,n,t]),he=!rt&&g==="chat"&&!!Ie&&Ie.totalTokens>0,qe=Ie&&Ie.contextLimit>0?Math.min(999,Ie.totalTokens/Ie.contextLimit*100):0,et=l.useCallback(async()=>{if(!(typeof window>"u"||!V))try{const $e=await Rx(),Ft=window.location.href,as=window.__OPENCHAMBER_LOCAL_ORIGIN__||window.location.origin;if(hu(Ft,as)){Me("Local");return}const fs=$e.hosts.find(Gs=>hu(Ft,Gs.url));if(fs?.label?.trim()){Me(Fx(fs.label.trim()));return}Me("Instance")}catch{Me("Local")}},[V]);Be.useEffect(()=>{et()},[et]),df();const Ke=Ls($e=>$e.selectedModels),st=Ls($e=>$e.expandedFamilies),nt=Ls($e=>$e.toggleFamilyExpanded),ye=l.useMemo(()=>{const $e=[];for(const Ft of Mr){if(!ne.includes(Ft.id))continue;const as=B.find(Ys=>Ys.providerId===Ft.id),fs=as?.usage?.windows??{},Gs=as?.usage?.models,Hs=Object.entries(fs),Ss={providerId:Ft.id,providerName:Ft.name,entries:Hs,error:as&&!as.ok&&as.configured?as.error:void 0};if(Gs&&Object.keys(Gs).length>0){const Ys=Ke[Ft.id]??[],on=Ys.length>0,sr=Iv(Gs,Ft.id),Hn=lf(Ft.id),Gn=cf(Hn);Ss.modelFamilies=[];for(const Zs of Gn){const Vn=sr.get(Zs.id)??[];if(Vn.length===0)continue;const Cn=on?Vn.filter(fr=>Ys.includes(fr)):Vn;if(Cn.length===0)continue;const Zn=[];for(const fr of Cn){const Dr=Gs[fr];if(Dr?.windows){const nr=Object.entries(Dr.windows);nr.length>0&&Zn.push([fr,nr[0][1]])}}Zn.length>0&&Ss.modelFamilies.push({familyId:Zs.id,familyLabel:Zs.label,models:Zn})}const Rr=sr.get(null)??[],Nr=on?Rr.filter(Zs=>Ys.includes(Zs)):Rr;if(Nr.length>0){const Zs=[];for(const Vn of Nr){const Cn=Gs[Vn];if(Cn?.windows){const Zn=Object.entries(Cn.windows);Zn.length>0&&Zs.push([Vn,Zn[0][1]])}}Zs.length>0&&Ss.modelFamilies.push({familyId:null,familyLabel:i("header.services.modelFamily.other"),models:Zs})}}(Hs.length>0||Ss.modelFamilies&&Ss.modelFamilies.length>0||Ss.error)&&$e.push(Ss)}return $e},[ne,B,Ke,i]),Je=ye.length>0;l.useEffect(()=>{re()},[re]);const _e=l.useCallback(async $e=>{ue($e);try{await Ds({usageDisplayMode:$e})}catch(Ft){console.warn("Failed to update usage display mode:",Ft)}},[ue]),Ue=l.useCallback(()=>{if(ge)return;W(!0);const $e=new Promise(Ft=>setTimeout(Ft,500));Promise.all([O(),$e]).finally(()=>{W(!1)})},[O,ge]),ot=l.useMemo(()=>C?R.find($e=>$e.id===C)??M.find($e=>$e.id===C)??T??Lx().find($e=>$e.id===C)??null:null,[C,T,M,R]),Xe=l.useRef(null),[We,bt]=l.useState(0);l.useEffect(()=>{if(!C){Xe.current&&(Xe.current=null,bt(fs=>fs+1));return}if(ot){Xe.current={sessionId:C,session:ot,expiresAt:Date.now()+2e3};return}const $e=Xe.current;if(!$e||$e.sessionId!==C)return;const Ft=$e.expiresAt-Date.now();if(Ft<=0){Xe.current=null,bt(fs=>fs+1);return}const as=window.setTimeout(()=>{Xe.current?.sessionId===C&&(Xe.current=null),bt(fs=>fs+1)},Ft);return()=>{window.clearTimeout(as)}},[C,ot]);const Dt=(()=>{if(ot)return ot;if(!C)return null;const $e=Xe.current;return $e&&$e.sessionId===C&&$e.expiresAt>Date.now()?$e.session:null})(),Ht=Vt($e=>C?$e.worktreeMetadata.get(C)?.path??"":""),rs=Vt($e=>C?$e.worktreeMetadata.get(C)?.branch?.trim()??null:null),jt=Th($e=>C?$e.getAttachment(C):void 0),St=l.useMemo(()=>jt?Ox(jt):null,[jt]),ns=l.useMemo(()=>jt?jt.legacy?"legacy":jt.degraded?"degraded":jt.worktreeStatus==="missing"?"missing":jt.worktreeStatus==="invalid"?"invalid":jt.attentionReason?"attention":null:null,[jt]),ut=l.useMemo(()=>ar(Ht||""),[Ht]),Gt=l.useMemo(()=>{const $e=typeof Dt?.directory=="string"?Dt.directory:"";return ar($e||"")},[Dt?.directory]),Xt=Vt($e=>$e.newSessionDraft?.open?ar($e.newSessionDraft.bootstrapPendingDirectory??$e.newSessionDraft.directoryOverride??""):""),Wt=l.useMemo(()=>ut||Gt||Xt,[Xt,Gt,ut]),is=Vt($e=>{const Ft=ar(ut||Gt||"");if(!Ft)return null;for(const as of $e.availableWorktreesByProject.values()){const Gs=as.find(Hs=>ar(Hs.path)===Ft)?.branch?.trim();if(Gs)return Gs}return null}),ps=$x(Wt||null)||rs||is,Ns=l.useMemo(()=>{if(!C)return $??"OpenChamber";const $e=Dt?.title?.trim();return $e&&$e.length>0?$e:"Untitled Session"},[$,Dt?.title,C]),Mt=l.useMemo(()=>Mh(Dt?.summary),[Dt?.summary]),He=l.useMemo(()=>Mt||{additions:0,deletions:0},[Mt]),At=He.additions>0||He.deletions>0,Et=l.useMemo(()=>ar(Wt||L?.path||""),[L?.path,Wt]),wt=l.useMemo(()=>L?{id:L.id,path:L.path}:null,[L]),$t=l.useRef(null);l.useEffect(()=>{!wt||!Et||($t.current={projectRef:wt,directory:Et})},[Et,wt]);const qt=l.useMemo(()=>wt&&Et?{projectRef:wt,directory:Et}:$t.current,[Et,wt]),Ms=Pd($e=>$e.planModeEnabled),cs=Vt($e=>$e.isSessionPlanAvailable),Is=Ms&&C?cs(C):!1,Es=Is,ft=l.useRef("");l.useEffect(()=>{if(!Ms){Te.getState().activeMainTab==="plan"&&Te.getState().setActiveMainTab("chat");return}if(!C)return;const $e=`${C||"none"}:${Gt||"none"}:${Dt?.time?.created||0}:${Dt?.slug||"none"}`;ft.current!==$e&&(ft.current=$e),!Is&&Te.getState().activeMainTab==="plan"&&Te.getState().setActiveMainTab("chat")},[Ms,Is,Dt?.slug,Dt?.time?.created,C,Gt]);const hs=l.useCallback(async $e=>{if(!(!$e||Ee)){ze(!0);try{const Ft=D.github?await D.github.authActivate($e):await(async()=>{const as=await fetch("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:$e})}),fs=await as.json().catch(()=>null);if(!as.ok||!fs)throw new Error(fs?.error||as.statusText);return fs})();X(Ft)}catch(Ft){console.error("Failed to switch GitHub account:",Ft)}finally{ze(!1)}}},[Ee,D.github,X]),J=l.useCallback(()=>{if(typeof document>"u")return;const $e=document.activeElement;if(!$e)return;const Ft=$e.tagName;(Ft==="INPUT"||Ft==="TEXTAREA"||Ft==="SELECT"||$e.isContentEditable)&&$e.blur()},[]),ct=l.useCallback(()=>{if(Q){J(),o(!fe);return}c()},[J,Q,fe,o,c]),vt=l.useCallback(()=>{w("chat"),o(!1),E()},[E,w,o]),Tt=l.useCallback(()=>{sl("desktop_open_draft_mini_chat_window",{directory:ar(Wt||L?.path||""),projectId:L?.id??null}).catch($e=>{console.warn("[header] failed to open draft mini chat window",$e)})},[L?.id,L?.path,Wt]),Yt=l.useCallback(()=>{if(P){Tt();return}C&&sl("desktop_open_session_mini_chat_window",{sessionId:C,directory:ar(Wt||L?.path||"")}).catch($e=>{console.warn("[header] failed to open session mini chat window",$e)})},[L?.path,C,Tt,P,Wt]),Zt=l.useCallback(()=>{const $e=ar(Wt||"");if(!$e)return;const Ft=x[$e];if(yo(Ft)==="context"){v($e);return}h($e)},[v,x,h,Wt]),Ps=l.useMemo(()=>{const $e=ar(Wt||"");if(!$e)return!1;const Ft=x[$e];return yo(Ft)==="context"},[x,Wt]),As=l.useCallback(()=>{const $e=ar(Wt||"");if(!$e)return;const Ft=x[$e];if(yo(Ft)==="plan"){v($e);return}b($e)},[v,x,b,Wt]),Ge=l.useCallback(()=>{const $e=ar(Wt||"");$e&&f($e)},[f,Wt]),yt=l.useMemo(()=>{const $e=ar(Wt||"");if(!$e)return!1;const Ft=x[$e];return yo(Ft)==="plan"},[x,Wt]),It=Dl,Rt=P1,ss=l.useMemo(()=>!d&&(V&&oe&&!ae||U)?"pl-[5.5rem]":"pl-3",[V,ae,oe,d,U]);Be.useEffect(()=>{if(!V||!oe){je(!1);return}let $e=!1,Ft=null;const as=async()=>{try{const{getCurrentWindow:Gs}=await vr(async()=>{const{getCurrentWindow:Ys}=await import("./vendor-.bun-BFTPeDgG.js").then(on=>on.bK);return{getCurrentWindow:Ys}},__vite__mapDeps([0,1])),Ss=await Gs().isFullscreen();$e||je(Ss)}catch{$e||je(!1)}},fs=async()=>{try{const{getCurrentWindow:Gs}=await vr(async()=>{const{getCurrentWindow:Ss}=await import("./vendor-.bun-BFTPeDgG.js").then(Ys=>Ys.bK);return{getCurrentWindow:Ss}},__vite__mapDeps([0,1]));Ft=await Gs().onResized(()=>{as()})}catch{}};return as(),fs(),()=>{$e=!0,Ft&&Ft()}},[V,oe]);const it=l.useMemo(()=>!V||!oe||ve===null?"":ve>=26?"h-12":ve<=15?"h-14":"",[V,oe,ve]),Bt=l.useMemo(()=>{if(!(V||rt))return{paddingLeft:U&&!d?"max(calc(0.75rem + var(--oc-wco-left-inset, 0px)), 5.5rem)":"calc(0.75rem + var(--oc-wco-left-inset, 0px))",paddingRight:"calc(0.75rem + var(--oc-wco-right-inset, 0px))",minHeight:"max(3rem, var(--oc-wco-titlebar-height, 0px))",height:"max(3rem, var(--oc-wco-titlebar-height, 0px))"}},[V,d,U,rt]),bs=l.useCallback(()=>{if(typeof document>"u")return;const $e=F.current?.getBoundingClientRect().height;$e&&document.documentElement.style.setProperty("--oc-header-height",`${$e}px`)},[]);Be.useEffect(()=>{if(typeof window>"u")return;bs();const $e=F.current;if(!$e||typeof ResizeObserver>"u")return()=>{};let Ft=0;const as=()=>{Ft||(Ft=requestAnimationFrame(()=>{Ft=0,bs()}))},fs=new ResizeObserver(as);return fs.observe($e),window.addEventListener("resize",as),window.addEventListener("orientationchange",as),()=>{Ft&&cancelAnimationFrame(Ft),fs.disconnect(),window.removeEventListener("resize",as),window.removeEventListener("orientationchange",as)}},[bs]),Be.useEffect(()=>{bs()},[bs,Q,it]);const es=l.useCallback(async $e=>{const Ft=$e.target;Ft.closest(".app-region-no-drag")||Ft.closest("button, a, input, select, textarea")||$e.button===0&&V&&await Eh()},[V]),Ut=l.useMemo(()=>{if(Q){const $e=[{id:"chat",label:i("layout.mainTab.chat"),icon:"chat-4"}];return Es&&$e.push({id:"plan",label:i("layout.mainTab.plan"),icon:"file-text"}),$e.push({id:"diff",label:i("layout.mainTab.diff"),icon:"diff"},{id:"files",label:i("layout.mainTab.files"),icon:"folder-6"},{id:"terminal",label:i("layout.mainTab.terminal"),icon:"terminal-box"}),$e}return[]},[Q,Es,i]),os=l.useCallback($e=>jl(Br($e,y)),[y]);Be.useEffect(()=>{!Q&&(g==="git"||g==="terminal"||g==="diff"||g==="files")&&w("chat")},[g,Q,w]);const en=l.useMemo(()=>{const $e=[];return V&&$e.push({value:"instance",label:i("layout.services.instance"),icon:"server"}),$e.push({value:"usage",label:i("layout.services.usage"),icon:"timer"},{value:"mcp",label:"MCP",icon:$v}),$e},[V,i]),qs=l.useMemo(()=>en.map($e=>({id:$e.value,label:$e.label,icon:s.jsx(I,{name:$e.icon,className:"h-3.5 w-3.5"})})),[en]),zs=l.useMemo(()=>{if(typeof window>"u"||V||rt)return!1;const $e=window.location.hostname;return $e==="localhost"||$e==="127.0.0.1"||$e==="::1"},[V,rt]),un=l.useCallback(async()=>{if(j)return;S(!0),Ae(!1);const $e=[];let Ft=!1;try{try{for(const[,as]of cn.getState().sessions.entries())for(const fs of as.tabs)fs.previewUrl&&$e.push(fs.previewUrl)}catch{}try{await Sx({})}catch{}try{(await fetch("/api/system/dev-shutdown",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({previewUrls:$e})})).ok?Ft=!0:Ft=(await fetch("/api/system/shutdown",{method:"POST"})).ok}catch{}}finally{Ft||S(!1)}},[j,Ae]),Qs=l.useMemo(()=>[{value:"usage",label:i("header.services.used")},{value:"remaining",label:i("header.services.remaining")}],[i]),mn=l.useMemo(()=>Qs.map($e=>({id:$e.value,label:$e.label})),[Qs]),ln=l.useMemo(()=>[{id:"usage",label:i("layout.services.usage"),icon:s.jsx(I,{name:"timer",className:"h-3.5 w-3.5"})},{id:"mcp",label:"MCP",icon:s.jsx(I,{name:"command",className:"h-3.5 w-3.5"})}],[i]);Be.useEffect(()=>{const $e=Ft=>{if(Ad(Ft)&&!Ft.shiftKey&&!Ft.altKey){const as=parseInt(Ft.key,10);as>=1&&as<=Ut.length&&(Ft.preventDefault(),w(Ut[as-1].id))}};return window.addEventListener("keydown",$e),()=>window.removeEventListener("keydown",$e)},[Ut,w]),Be.useEffect(()=>{const $e=Ft=>{const as=Br("toggle_services_menu",y);if(Oo(Ft,as)){Ft.preventDefault(),Le?Ae(!1):(Ae(!0),et(),Ce==="usage"&&B.length===0&&O());return}const fs=Br("cycle_services_tab",y);if(Oo(Ft,fs)){Ft.preventDefault();const Hs=en.map(sr=>sr.value);if(Hs.length===0)return;const Ss=Hs.indexOf(Ce),Ys=Ss===-1?0:(Ss+1)%Hs.length,on=Hs[Ys];xe(on),Ae(!0),et(),on==="usage"&&B.length===0&&O();return}const Gs=Br("toggle_context_plan",y);Oo(Ft,Gs)&&(Ft.preventDefault(),As())};return window.addEventListener("keydown",$e),()=>window.removeEventListener("keydown",$e)},[y,Le,Ce,en,B.length,O,et,As]);const wn=$e=>{const Ft=g===$e.id,as=$e.icon==="diff",fs=as?null:$e.icon,Gs=$e.id==="chat",Hs=Ys=>as?s.jsx(Vu,{size:Ys}):fs?s.jsx(I,{name:fs,className:`h-${Ys/4} w-${Ys/4}`}):null,Ss=s.jsxs("button",{type:"button",onClick:()=>w($e.id),className:me("relative flex h-8 items-center gap-2 px-3 rounded-lg typography-ui-label font-medium transition-colors",Ft?"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",Gs&&!Q&&"min-w-[100px] justify-center"),"aria-label":$e.label,"aria-selected":Ft,role:"tab",children:[Q?Hs(20):s.jsxs(s.Fragment,{children:[Hs(16),s.jsx("span",{className:"header-tab-label",children:$e.label})]}),$e.badge!==void 0&&$e.badge>0&&s.jsx("span",{className:"header-tab-badge typography-micro text-status-info font-medium",children:$e.badge})]});return s.jsx(l.Fragment,{children:Ss},$e.id)},tn=s.jsxs(s.Fragment,{children:[Es&&s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":i("header.actions.openPlanAria"),onClick:As,className:me(It,yt&&"bg-[var(--interactive-hover)]"),children:s.jsx(I,{name:"file-text",className:"h-[18px] w-[18px]"})})}),s.jsx(Pt,{children:s.jsx("p",{children:i("header.actions.planWithShortcut",{shortcut:os("toggle_context_plan")})})})]}),s.jsx(Wv,{directory:Et,className:"mr-1"}),s.jsx(D1,{isDesktopApp:V,currentInstanceLabel:ie,compactCurrentInstanceLabel:Ve,isDesktopServicesOpen:Le,setIsDesktopServicesOpen:Ae,refreshCurrentInstanceLabel:et,desktopServicesTab:Ce,setDesktopServicesTab:xe,quotaResultsLength:B.length,fetchAllQuotas:O,servicesTabItems:qs,quotaLastUpdated:ee,quotaDisplayMode:z,quotaDisplayTabItems:mn,handleDisplayModeChange:_e,handleUsageRefresh:Ue,isQuotaLoading:_,isUsageRefreshSpinning:ge,hasRateLimits:Je,rateLimitGroups:ye,expandedFamilies:st,toggleFamilyExpanded:nt,shortcutLabel:os,showDevShutdown:zs,isDevShutdownInFlight:j,onDevShutdown:un}),s.jsx(Ni,{title:i("header.actions.terminalPanelWithShortcut",{shortcut:os("toggle_terminal")}),ariaLabel:i("header.actions.toggleTerminalPanelAria"),onClick:m,Icon:"terminal-box"}),te?s.jsx(Ni,{title:i("contextPanel.browser.open"),ariaLabel:i("contextPanel.browser.open"),onClick:Ge,Icon:"global"}):null,s.jsx(Ni,{title:i("header.actions.rightSidebarWithShortcut",{shortcut:os("toggle_right_sidebar")}),ariaLabel:i("header.actions.toggleRightSidebarAria"),onClick:u,Icon:"layout-right"}),s.jsx(A1,{isMobile:Q,githubAuthStatus:de,githubAccounts:pe,githubAvatarUrl:ke,githubLogin:be,isSwitchingGitHubAccount:Ee,handleGitHubAccountSwitch:hs})]}),fn=!p||!a,hr=te&&(P||!!C),Fn=()=>s.jsxs("div",{onMouseDown:es,className:me("app-region-drag relative flex h-12 select-none items-center pr-3",ss,it),style:Bt,role:"tablist","aria-label":i("header.navigation.mainAria"),children:[s.jsx(Ni,{visible:!d,title:i("header.actions.openSessionsWithShortcut",{shortcut:os("toggle_sidebar")}),ariaLabel:i("header.actions.openSessionsAria"),onClick:ct,className:`${It} shrink-0`,Icon:"layout-left"}),s.jsxs("div",{className:me("flex min-w-0 flex-1 items-center",!d&&"pl-3"),children:[Re?null:s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":i("header.actions.newSessionAria"),onClick:vt,className:me(It,"mr-6 shrink-0"),children:s.jsx(I,{name:"chat-new",className:"h-[18px] w-[18px]"})})}),s.jsx(Pt,{children:s.jsx("p",{children:i("header.actions.newSessionWithShortcut",{shortcut:os("new_chat")})})})]}),qt&&s.jsx(Xu,{projectRef:qt.projectRef,directory:qt.directory,className:"mr-2"}),s.jsx(Bx,{children:s.jsxs("button",{type:"button","aria-label":i("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:P?i("sessions.switcher.draftTitle"):Ns}),$||ps||!P&&(At||ns)?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:[$?s.jsx("span",{className:"truncate",children:$}):null,ps?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(I,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:ps})]}):null,!P&&At?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:["+",He.additions]}),s.jsx("span",{className:"text-muted-foreground/60",children:"/"}),s.jsxs("span",{className:"text-status-error/65",children:["-",He.deletions]})]}):null,!P&&ns?s.jsxs("span",{className:me("inline-flex min-w-0 items-center gap-0.5",ns==="attention"||ns==="invalid"||ns==="missing"?"text-status-warning":"text-muted-foreground/60"),children:[s.jsx(I,{name:"alert",className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:St})]}):null]}):null]})}),Ut.length>0&&s.jsx("div",{className:"flex items-center gap-1 rounded-lg bg-[var(--surface-muted)]/50 p-1",children:Ut.map($e=>wn($e))}),s.jsx("div",{className:"flex-1"}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[he&&Ie?s.jsx(_x,{totalTokens:Ie.totalTokens,percentage:qe,colorPercentage:Ie.percentage,contextLimit:Ie.contextLimit,outputLimit:Ie.outputLimit??0,size:"compact",hideIcon:!0,showPercentIcon:!0,onClick:Zt,pressed:Ps,className:fn&&!hr?"mr-3.5":"",valueClassName:"typography-ui-label font-medium leading-none text-foreground",percentIconClassName:"h-5 w-5"}):null,s.jsx(Ni,{visible:hr,title:i(P?"header.actions.newMiniChat":"header.actions.openSessionMiniChat"),ariaLabel:i(P?"header.actions.newMiniChatAria":"header.actions.openSessionMiniChatAria"),onClick:Yt,className:me(It,fn&&he?"mr-3.5":"mr-1"),Icon:"picture-in-picture-2"}),fn?tn:null,!fn&&a?Oi.createPortal(tn,a):null]})]})]}),Tn=()=>s.jsxs("div",{className:"app-region-drag relative flex items-center gap-2 px-3 py-2 select-none",children:[s.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[t?s.jsx("button",{type:"button",onClick:t,className:me(Rt,n&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":i(n?"header.actions.closeSessionsAria":"header.actions.openSessionsAria"),children:s.jsx(I,{name:"layout-left",className:"h-5 w-5"})}):fe?s.jsx("button",{type:"button",onClick:()=>o(!1),className:"app-region-no-drag h-9 w-9 p-2 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary rounded-md active:bg-interactive-active","aria-label":i("header.actions.backAria"),children:s.jsx(I,{name:"arrow-left-s",className:"h-5 w-5"})}):s.jsx("button",{type:"button",onClick:ct,className:"app-region-no-drag h-9 w-9 p-2 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary rounded-md active:bg-interactive-active","aria-label":i("header.actions.openSessionsAria"),children:s.jsx(I,{name:"play-list-add",className:"h-5 w-5"})}),fe&&s.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:i("header.sessions.title")})]}),!fe&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"app-region-no-drag flex min-w-0 flex-1 items-center",children:s.jsx("div",{className:"flex min-w-0 flex-1 overflow-x-auto overflow-y-hidden scrollbar-hidden touch-pan-x overscroll-x-contain",children:s.jsx("div",{className:"flex w-max items-center gap-1 pr-1",children:s.jsx("div",{className:"flex items-center gap-0.5 rounded-lg bg-[var(--surface-muted)]/50 p-0.5",role:"tablist","aria-label":i("header.navigation.mainAria"),children:Ut.map($e=>{const Ft=g===$e.id,as=$e.icon==="diff",fs=as?null:$e.icon;return s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>{Q&&J(),w($e.id)},"aria-label":$e.label,"aria-selected":Ft,role:"tab",className:me(Rt,"relative rounded-lg",Ft&&"bg-interactive-selection text-interactive-selection-foreground"),children:[as?s.jsx(Vu,{className:"h-5 w-5"}):fs?s.jsx(I,{name:fs,className:"h-5 w-5"}):null,$e.badge!==void 0&&$e.badge>0&&s.jsx("span",{className:"absolute -top-1 -right-1 text-[10px] font-semibold text-primary",children:$e.badge}),$e.showDot&&s.jsx("span",{className:"absolute top-1.5 right-1.5 h-2 w-2 rounded-full bg-primary","aria-label":i("header.changes.availableAria")})]})}),s.jsx(Pt,{children:s.jsx("p",{children:$e.label})})]},$e.id)})})})})}),s.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[qt&&s.jsx(Xu,{projectRef:qt.projectRef,directory:qt.directory,compact:!0,allowMobile:!0,className:"h-9"}),s.jsxs(Bs,{open:G,onOpenChange:$e=>{Pe($e),$e&&B.length===0&&O()},children:[s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(Os,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":i("header.services.viewAria"),className:Rt,children:s.jsx(I,{name:"stack",className:"h-5 w-5"})})})}),s.jsx(Pt,{children:s.jsx("p",{children:i("header.services.title")})})]}),s.jsx($s,{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(Ar,{items:ln,activeId:De,onSelect:$e=>{const Ft=$e;Ye(Ft),Ft==="usage"&&B.length===0&&O()},layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",activePillButtonClassName:"h-8",className:"h-full"})}),s.jsx("button",{type:"button",onClick:()=>Pe(!1),className:"inline-flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover","aria-label":i("header.services.closeAria"),children:s.jsx(I,{name:"close",className:"h-5 w-5"})})]})}),De==="mcp"&&s.jsx(mf,{active:G&&De==="mcp"}),De==="usage"&&s.jsxs("div",{className:"flex-1 overflow-y-auto overflow-x-hidden pb-[calc(4rem+env(safe-area-inset-bottom))]",children:[s.jsx("div",{className:"border-b border-[var(--interactive-border)]",children:s.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-3",children:[s.jsxs("div",{className:"flex flex-col min-w-0 gap-0.5",children:[s.jsx("span",{className:"typography-ui-header font-semibold text-foreground",children:i("header.services.rateLimits")}),s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:xf(ee)})]}),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:()=>_e("usage"),className:me("typography-ui-label px-1 pb-0.5 transition-colors",z==="usage"?"text-foreground border-b-2 border-[var(--primary-base)]":"text-muted-foreground hover:text-foreground"),children:i("header.services.used")}),s.jsx("span",{className:"text-muted-foreground typography-ui-label px-0.5",children:"·"}),s.jsx("button",{type:"button",onClick:()=>_e("remaining"),className:me("typography-ui-label px-1 pb-0.5 transition-colors",z==="remaining"?"text-foreground border-b-2 border-[var(--primary-base)]":"text-muted-foreground hover:text-foreground"),children:i("header.services.remaining")})]}),s.jsx("button",{type:"button",className:me("inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors","hover:text-foreground hover:bg-interactive-hover","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),onClick:Ue,disabled:_||ge,"aria-label":i("header.services.refreshRateLimitsAria"),children:s.jsx(I,{name:"refresh",className:me("h-4 w-4",ge&&"animate-spin")})})]})]})}),!Je&&s.jsx("div",{className:"px-4 py-6 text-center",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:i("header.services.noRateLimits")})}),s.jsx("div",{className:"py-1",children:ye.map(($e,Ft)=>s.jsxs(l.Fragment,{children:[Ft>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(Sn,{providerId:$e.providerId,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:$e.providerName})]}),$e.entries.length===0&&(!$e.modelFamilies||$e.modelFamilies.length===0)?s.jsx("div",{className:"px-4 pb-2",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:$e.error??i("header.services.noRateLimitsReported")})}):s.jsxs("div",{className:"space-y-3 px-4 pb-2",children:[$e.entries.map(([as,fs])=>{const Gs=z==="remaining"?fs.remainingPercent:fs.usedPercent,Hs=Ji(fs.usedPercent,fs.resetAt,fs.windowSeconds,as),Ss=Hs?.dailyAllocationPercent!=null?z==="remaining"?100-_r(Hs.elapsedRatio):_r(Hs.elapsedRatio):null,Ys=qi(fs.valueLabel,Gs),on=Vd(fs.resetAt,fs.resetAfterFormatted??fs.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:zd(as)}),on?s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:on}):null]}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:Ys==="-"?"":Ys})]}),s.jsx(Yi,{percent:Gs,tonePercent:fs.usedPercent,className:"h-1.5",expectedMarkerPercent:Ss}),Hs?s.jsx(Xi,{paceInfo:Hs,compact:!0}):null]},`${$e.providerId}-${as}`)}),$e.modelFamilies&&$e.modelFamilies.length>0&&s.jsx("div",{className:"space-y-0.5",children:$e.modelFamilies.map(as=>{const Gs=(st[$e.providerId]??[]).includes(as.familyId??"other");return s.jsxs(ur,{open:Gs,onOpenChange:()=>nt($e.providerId,as.familyId??"other"),children:[s.jsxs(wr,{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:as.familyLabel}),Gs?s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(I,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsx(mr,{children:s.jsx("div",{className:"space-y-2.5 pb-1 pl-1 pt-1",children:as.models.map(([Hs,Ss])=>{const Ys=z==="remaining"?Ss.remainingPercent:Ss.usedPercent,on=Ji(Ss.usedPercent,Ss.resetAt,Ss.windowSeconds),sr=on?.dailyAllocationPercent!=null?z==="remaining"?100-_r(on.elapsedRatio):_r(on.elapsedRatio):null,Hn=qi(Ss.valueLabel,Ys);return s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3",children:[s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:il(Hs)}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:Hn==="-"?"":Hn})]}),s.jsx(Yi,{percent:Ys,tonePercent:Ss.usedPercent,className:"h-1.5",expectedMarkerPercent:sr}),on?s.jsx(Xi,{paceInfo:on,compact:!0}):null]},`${$e.providerId}-${Hs}`)})})})]},as.familyId??"other")})})]})]},$e.providerId))})]})]})})]}),e?s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:e,className:me(Rt,"relative",r&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":r?"Close git sidebar":"Open git sidebar",children:s.jsx(I,{name:"layout-right",className:"h-5 w-5"})})}),s.jsx(Pt,{children:s.jsx("p",{children:r?"Close git sidebar":"Open git sidebar"})})]}):null]})]})]}),Mn=me("header-safe-area relative z-10",Q&&"border-b border-border/50","bg-background");return s.jsx("header",{ref:F,className:Mn,style:{"--padding-scale":"1"},children:Q?Tn():Fn()})};function E1(){}const em=180,tm=640,R1=110,F1=t=>{const e=at.c(44),{isOpen:n,isMobile:r,children:a}=t,{t:i}=pt(),o=Te(L1),c=Te(O1),d=Te($1),p=Te(B1),[m,u]=l.useState(null),[h,b]=l.useState(!1),f=l.useRef(null),v=l.useRef(0),x=l.useRef(o||300),g=Math.min(tm,Math.max(em,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 k,D;e[3]!==c||e[4]!==r||e[5]!==n?(k=()=>{if(r||!n||!c)return;const re=()=>{const de=f.current?.parentElement?.getBoundingClientRect().height;if(!de||de<=0)return;const X=Math.max(0,Math.round(de));u(F=>F===X?F:X)};re();const ue=f.current?.parentElement;if(!ue)return;const Q=new ResizeObserver(re);return Q.observe(ue),()=>{Q.disconnect()}},D=[c,r,n],e[3]=c,e[4]=r,e[5]=n,e[6]=k,e[7]=D):(k=e[6],D=e[7]),l.useEffect(k,D);let j,S;if(e[8]!==c||e[9]!==r||e[10]!==h||e[11]!==d||e[12]!==p?(j=()=>{if(r||!h||c)return;const re=Q=>{const de=v.current-Q.clientY,X=Math.min(tm,Math.max(em,x.current+de));d(X)},ue=()=>{b(!1),Te.getState().bottomTerminalHeight<=R1&&p(!1)};return window.addEventListener("pointermove",re),window.addEventListener("pointerup",ue,{once:!0}),()=>{window.removeEventListener("pointermove",re),window.removeEventListener("pointerup",ue)}},S=[c,r,h,d,p],e[8]=c,e[9]=r,e[10]=h,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 A=n?c?Math.max(0,m??g):g:0,E=n&&c;let P;e[15]!==A||e[16]!==c||e[17]!==n?(P=re=>{!n||c||(b(!0),v.current=re.clientY,x.current=A,re.preventDefault())},e[15]=A,e[16]=c,e[17]=n,e[18]=P):P=e[18];const C=P,N=E?"absolute inset-x-0 bottom-0 z-40":"relative",T=h?"transition-none":"transition-[height] duration-300 ease-in-out",M=!n&&"border-t-0";let R;e[19]!==M||e[20]!==N||e[21]!==T?(R=me("flex overflow-hidden border-t border-border bg-sidebar",N,T,M),e[19]=M,e[20]=N,e[21]=T,e[22]=R):R=e[22];let L;e[23]!==A||e[24]!==E?(L=E?{top:"var(--oc-header-height, 48px)"}:{height:`${A}px`,minHeight:`${A}px`,maxHeight:`${A}px`},e[23]=A,e[24]=E,e[25]=L):L=e[25];const $=!n||!c&&A===0;let B;e[26]!==C||e[27]!==c||e[28]!==n||e[29]!==h||e[30]!==i?(B=n&&!c&&s.jsx("div",{className:me("absolute left-0 top-0 z-20 h-[3px] w-full cursor-row-resize hover:bg-[var(--interactive-border)]/80 transition-colors",h&&"bg-[var(--interactive-border)]"),onPointerDown:C,role:"separator","aria-orientation":"horizontal","aria-label":i("terminalView.bottomDock.resizeAria")}),e[26]=C,e[27]=c,e[28]=n,e[29]=h,e[30]=i,e[31]=B):B=e[31];const O=!n&&"pointer-events-none select-none opacity-0";let _;e[32]!==O?(_=me("relative z-10 flex h-full min-h-0 w-full flex-col transition-opacity duration-300 ease-in-out",O),e[32]=O,e[33]=_):_=e[33];const ee=!n;let z;e[34]!==a||e[35]!==_||e[36]!==ee?(z=s.jsx("div",{className:_,"aria-hidden":ee,children:a}),e[34]=a,e[35]=_,e[36]=ee,e[37]=z):z=e[37];let ne;return e[38]!==R||e[39]!==L||e[40]!==$||e[41]!==B||e[42]!==z?(ne=s.jsxs("section",{ref:f,className:R,style:L,"aria-hidden":$,children:[B,z]}),e[38]=R,e[39]=L,e[40]=$,e[41]=B,e[42]=z,e[43]=ne):ne=e[43],ne};function L1(t){return t.bottomTerminalHeight}function O1(t){return t.isBottomTerminalExpanded}function $1(t){return t.setBottomTerminalHeight}function B1(t){return t.setBottomTerminalOpen}const Zc=280,sm=280,nm=500,_1=({isOpen:t,isMobile:e,children:n,className:r})=>{const{t:a}=pt(),i=Te(k=>k.sidebarWidth),o=Te(k=>k.setSidebarWidth),[c,d]=l.useState(!1),p=l.useRef(0),m=l.useRef(i||Zc),u=l.useRef(null),h=l.useRef(null),b=l.useRef(null),f=l.useCallback(k=>Math.min(nm,Math.max(sm,k)),[]),v=l.useCallback(k=>{const D=b.current;D&&D.style.setProperty("--oc-left-sidebar-width",`${k}px`)},[]);if(l.useEffect(()=>{e&&c&&d(!1)},[e,c]),l.useEffect(()=>{c||(u.current=null,h.current=null)},[c]),e)return null;const x=t?Math.min(nm,Math.max(sm,i||Zc)):0,g=k=>{if(t){try{k.currentTarget.setPointerCapture(k.pointerId)}catch{}h.current=k.pointerId,d(!0),p.current=k.clientX,m.current=x,u.current=x,v(x),k.preventDefault()}},w=k=>{if(e||!c||h.current!==k.pointerId)return;const D=k.clientX-p.current,j=f(m.current+D);u.current!==j&&(u.current=j,v(j))},y=k=>{if(h.current!==k.pointerId||e)return;try{k.currentTarget.releasePointerCapture(k.pointerId)}catch{}const D=f(u.current??x);h.current=null,u.current=null,d(!1),o(D)};return s.jsxs("aside",{ref:b,className:me("relative flex h-full overflow-hidden border-r border-border/40","bg-sidebar",c?"transition-none":"transition-[width] duration-300 ease-in-out",!t&&"border-r-0",r),style:{width:"var(--oc-left-sidebar-width)",minWidth:"var(--oc-left-sidebar-width)",maxWidth:"var(--oc-left-sidebar-width)","--oc-left-sidebar-width":`${c?u.current??x:x}px`,overflowX:"clip"},"aria-hidden":!t||x===0,children:[t&&s.jsx("div",{className:me("absolute right-0 top-0 z-20 h-full w-[3px] cursor-col-resize hover:bg-[var(--interactive-border)]/80 transition-colors",c&&"bg-[var(--interactive-border)]"),onPointerDown:g,onPointerMove:w,onPointerUp:y,onPointerCancel:y,role:"separator","aria-orientation":"vertical","aria-label":a("sidebar.resize.leftPanelAria")}),s.jsx("div",{className:me("relative z-10 flex h-full flex-col transition-opacity duration-300 ease-in-out",c&&"pointer-events-none",!t&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-left-sidebar-width)",overflowX:"hidden"},"aria-hidden":!t,children:s.jsx("div",{className:"flex-1 overflow-y-auto",children:s.jsx(Xs,{children:n})})})]})},bf=420,rm=400,am=860,V1=({isOpen:t,children:e,className:n,onTopActionsHostChange:r})=>{const{t:a}=pt(),i=Te(E=>E.rightSidebarWidth),o=Te(E=>E.setRightSidebarWidth),c=l.useMemo(()=>yn(),[]),d=l.useMemo(()=>dn(),[]),p=wl(),[m,u]=l.useState(!1),h=l.useRef(0),b=l.useRef(i||420),f=l.useRef(null),v=l.useRef(null),x=l.useRef(null),g=l.useCallback(E=>Math.min(am,Math.max(rm,E)),[]),w=l.useCallback(E=>{const P=x.current;P&&P.style.setProperty("--oc-right-sidebar-width",`${E}px`)},[]),y=t?Math.min(am,Math.max(rm,i||bf)):0,k=E=>{if(t){try{E.currentTarget.setPointerCapture(E.pointerId)}catch{}v.current=E.pointerId,u(!0),h.current=E.clientX,b.current=y,f.current=y,w(y),E.preventDefault()}},D=E=>{if(!m||v.current!==E.pointerId)return;const P=h.current-E.clientX,C=g(b.current+P);f.current!==C&&(f.current=C,w(C))},j=E=>{if(v.current!==E.pointerId)return;try{E.currentTarget.releasePointerCapture(E.pointerId)}catch{}const P=g(f.current??y);v.current=null,f.current=null,u(!1),o(P)};l.useEffect(()=>{m||(f.current=null,v.current=null)},[m]),l.useEffect(()=>{t||r?.(null)},[t,r]);const S=l.useCallback(async E=>{const P=E.target;P.closest(".app-region-no-drag")||P.closest("button, a, input, select, textarea")||E.button===0&&c&&await Eh()},[c]),A=l.useMemo(()=>{if(!(c||d))return{paddingLeft:"calc(0.75rem + var(--oc-wco-left-inset, 0px))",paddingRight:"calc(0.75rem + var(--oc-wco-right-inset, 0px))",...p?{paddingTop:"var(--oc-safe-area-top, 0px)"}:null}},[c,p,d]);return s.jsxs("aside",{ref:x,className:me("relative flex h-full overflow-hidden border-l border-border/40","bg-sidebar",m?"transition-none":"transition-[width] duration-300 ease-in-out",!t&&"border-l-0",n),style:{width:"var(--oc-right-sidebar-width)",minWidth:"var(--oc-right-sidebar-width)",maxWidth:"var(--oc-right-sidebar-width)","--oc-right-sidebar-width":`${m?f.current??y:y}px`,overflowX:"clip"},"aria-hidden":!t||y===0,children:[t?s.jsx("div",{onMouseDown:S,className:me("app-region-drag absolute inset-x-0 top-0 z-20 flex items-center justify-end px-3","h-[var(--oc-header-height,56px)]"),style:A,"aria-hidden":!0,children:s.jsx("div",{ref:r,className:"app-region-no-drag flex items-center gap-1"})}):null,t&&s.jsx("div",{className:me("absolute left-0 top-0 z-20 h-full w-[3px] cursor-col-resize hover:bg-[var(--interactive-border)]/80 transition-colors",m&&"bg-[var(--interactive-border)]"),onPointerDown:k,onPointerMove:D,onPointerUp:j,onPointerCancel:j,role:"separator","aria-orientation":"vertical","aria-label":a("sidebar.resize.rightPanelAria")}),s.jsx("div",{className:me("relative z-10 flex h-full min-h-0 w-full flex-col transition-opacity duration-300 ease-in-out",m&&"pointer-events-none",!t&&"pointer-events-none select-none opacity-0"),style:t?{paddingTop:"var(--oc-header-height, 56px)"}:void 0,"aria-hidden":!t,children:t?e:null})]})},z1=new Intl.NumberFormat("en-US",{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}),U1=t=>{if(typeof t!="number"||Number.isNaN(t))return"";if(t===0)return"0";const e=z1.format(t);return e.endsWith(".0")?e.slice(0,-2):e},ao=({providerId:t,modelId:e,onChange:n,className:r,allowedProviderIds:a,placeholder:i})=>{const{t:o}=pt(),{isReady:c,isUnavailable:d}=Rh(),p=gt(F=>F.providers),m=gt(F=>F.modelsMetadata),u=Te(F=>F.isMobile),h=Te(F=>F.hiddenModels),b=Te(F=>F.toggleFavoriteModel),f=Te(F=>F.isFavoriteModel),v=Te(F=>F.addRecentModel),{favoriteModelsList:x,recentModelsList:g}=Fh(),{isMobile:w}=an(),y=u||w,[k,D]=l.useState(!1),[j,S]=l.useState(new Set),[A,E]=l.useState(!1),[P,C]=l.useState(""),[N,T]=l.useState(0),M=l.useRef([]),R=l.useMemo(()=>!Array.isArray(a)||a.length===0?null:new Set(a),[a]),L=l.useMemo(()=>(R?p.filter(V=>R.has(String(V.id))):p).map(V=>{const te=(Array.isArray(V.models)?V.models:[]).filter(U=>{const ae=typeof U?.id=="string"?U.id:"";return!h.some(je=>je.providerID===String(V.id)&&je.modelID===ae)});return{...V,models:te}}).filter(V=>V.models.length>0),[p,R,h]),$=()=>D(!1),B=F=>{S(V=>{const q=new Set(V);return q.has(F)?q.delete(F):q.add(F),q})};l.useEffect(()=>{A||(C(""),T(0))},[A]),l.useEffect(()=>{T(0)},[P]);const O=F=>{const V=F?.name||F?.id||"",q=String(V);return q.length>40?q.substring(0,37)+"...":q},_=(F,V)=>{const q=`${F}/${V}`;return m.get(q)},ee=(F,V)=>{n(F,V),F&&V&&v(F,V),E(!1)},z=(F,V)=>{if(!P.trim())return!0;const q=P.toLowerCase();return F.toLowerCase().includes(q)||V.toLowerCase().includes(q)},ne=(F,V,q,te,U,ae)=>{const je=_(V,q),oe=U1(je?.limit?.context),ve=t===V&&e===q,K=f(V,q),ce=te==="fav"||te==="recent";return s.jsxs(zt,{ref:Z=>{M.current[U]=Z},className:me("group flex items-center gap-2",ae&&"bg-interactive-selection"),onSelect:()=>ee(V,q),onMouseEnter:()=>T(U),children:[s.jsxs("div",{className:"flex items-center gap-1.5 flex-1 min-w-0",children:[ce&&s.jsx(Sn,{providerId:V,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"font-medium truncate",children:O(F)}),oe?s.jsx("span",{className:"typography-micro text-muted-foreground flex-shrink-0",children:oe}):null]}),s.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[ve&&s.jsx(I,{name:"check",className:"h-4 w-4 text-primary"}),s.jsx("button",{onClick:Z=>{Z.preventDefault(),Z.stopPropagation(),b(V,q)},className:me("model-favorite-button flex h-4 w-4 items-center justify-center hover:text-primary/80",K?"text-primary":"text-muted-foreground"),"aria-label":o(K?"settings.agents.modelSelector.actions.unfavorite":"settings.agents.modelSelector.actions.favorite"),title:o(K?"settings.agents.modelSelector.actions.removeFromFavorites":"settings.agents.modelSelector.actions.addToFavorites"),children:K?s.jsx(I,{name:"star-fill",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"star",className:"h-3.5 w-3.5"})})]})]},`${te}-${V}-${q}`)},re=x.filter(({model:F,providerID:V})=>{if(R&&!R.has(V))return!1;const te=p.find(ae=>ae.id===V)?.name||V,U=O(F);return z(U,te)}),ue=g.filter(({model:F,providerID:V})=>{if(R&&!R.has(V))return!1;const te=p.find(ae=>ae.id===V)?.name||V,U=O(F);return z(U,te)}),Q=L.map(F=>{const q=(Array.isArray(F.models)?F.models:[]).filter(te=>{const U=O(te);return z(U,F.name||F.id||"")});return{...F,models:q}}).filter(F=>F.models.length>0),de=re.length>0||ue.length>0||Q.length>0,X=()=>y?s.jsx(Pr,{open:k,onClose:$,title:o("settings.agents.modelSelector.title"),children:s.jsxs("div",{className:"space-y-1",children:[x.length>0&&s.jsxs("div",{className:"rounded-xl border border-border/40 bg-[var(--surface-elevated)] mb-2",children:[s.jsx("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground uppercase tracking-wider",children:o("settings.agents.modelSelector.section.favorites")}),s.jsx("div",{className:"border-t border-border/20",children:x.map(({model:F,providerID:V,modelID:q})=>{const te=V===t&&q===e;return s.jsxs("div",{className:me("flex w-full items-center justify-between px-2 py-1.5 text-left","typography-meta",te?"bg-primary/10 text-primary":"text-foreground"),children:[s.jsx("button",{type:"button",className:"flex-1 flex flex-col min-w-0 mr-2",onClick:()=>{ee(V,q),$()},children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Sn,{providerId:V,className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"font-medium truncate",children:O(F)})]})}),s.jsx("button",{onClick:U=>{U.preventDefault(),U.stopPropagation(),b(V,q)},className:"model-favorite-button flex h-8 w-8 items-center justify-center text-primary hover:text-primary/80 active:scale-95 touch-manipulation","aria-label":o("settings.agents.modelSelector.actions.unfavorite"),children:s.jsx(I,{name:"star-fill",className:"h-4 w-4"})})]},`fav-mobile-${V}-${q}`)})})]}),g.length>0&&s.jsxs("div",{className:"rounded-xl border border-border/40 bg-[var(--surface-elevated)] mb-2",children:[s.jsx("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground uppercase tracking-wider",children:o("settings.agents.modelSelector.section.recents")}),s.jsx("div",{className:"border-t border-border/20",children:g.map(({model:F,providerID:V,modelID:q})=>{const te=V===t&&q===e;return s.jsxs("div",{className:me("flex w-full items-center justify-between px-2 py-1.5 text-left","typography-meta",te?"bg-primary/10 text-primary":"text-foreground"),children:[s.jsx("button",{type:"button",className:"flex-1 flex flex-col min-w-0 mr-2",onClick:()=>{ee(V,q),$()},children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Sn,{providerId:V,className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"font-medium truncate",children:O(F)})]})}),s.jsx("button",{onClick:U=>{U.preventDefault(),U.stopPropagation(),b(V,q)},className:"model-favorite-button flex h-8 w-8 items-center justify-center text-muted-foreground/50 hover:text-primary/80 active:scale-95 touch-manipulation","aria-label":o("settings.agents.modelSelector.actions.favorite"),children:s.jsx(I,{name:"star",className:"h-4 w-4"})})]},`recent-mobile-${V}-${q}`)})})]}),L.map(F=>{const V=Array.isArray(F.models)?F.models:[];if(V.length===0)return null;const q=F.id===t,te=j.has(F.id);return s.jsxs("div",{className:"rounded-xl border border-border/40 bg-[var(--surface-elevated)]",children:[s.jsxs("button",{type:"button",className:"flex w-full items-center justify-between gap-1.5 px-2 py-1.5 text-left",onClick:()=>B(F.id),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Sn,{providerId:F.id,className:"h-3.5 w-3.5"}),s.jsx("span",{className:"typography-meta font-medium text-foreground",children:F.name}),q&&s.jsx("span",{className:"typography-micro text-primary/80",children:o("settings.agents.modelSelector.badge.current")})]}),te?s.jsx(I,{name:"arrow-down-s",className:"h-3 w-3 text-muted-foreground"}):s.jsx(I,{name:"arrow-right-s",className:"h-3 w-3 text-muted-foreground"})]}),te&&s.jsx("div",{className:"border-t border-border/20",children:V.map(U=>{const ae=F.id===t&&U.id===e;return s.jsxs("div",{className:me("flex w-full items-center justify-between px-2 py-1.5 text-left","typography-meta",ae?"bg-primary/10 text-primary":"text-foreground"),children:[s.jsx("button",{type:"button",className:"flex-1 flex flex-col min-w-0 mr-2",onClick:()=>{ee(F.id,U.id),$()},children:s.jsx("span",{className:"font-medium truncate",children:O(U)})}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[s.jsx("button",{onClick:je=>{je.preventDefault(),je.stopPropagation(),b(F.id,U.id)},className:me("flex h-8 w-8 items-center justify-center active:scale-95 touch-manipulation hover:text-primary/80",f(F.id,U.id)?"text-primary":"text-muted-foreground/50"),"aria-label":f(F.id,U.id)?o("settings.agents.modelSelector.actions.unfavorite"):o("settings.agents.modelSelector.actions.favorite"),children:f(F.id,U.id)?s.jsx(I,{name:"star-fill",className:"h-4 w-4"}):s.jsx(I,{name:"star",className:"h-4 w-4"})}),ae&&s.jsx("div",{className:"h-2 w-2 rounded-full bg-primary"})]})]},U.id)})})]},F.id)}),s.jsx("button",{type:"button",className:"flex w-full items-center justify-between rounded-lg border border-border/40 bg-[var(--surface-elevated)] px-2 py-1.5 text-left",onClick:()=>{ee("",""),$()},children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:i||o("settings.agents.modelSelector.noModelOptional")})})]})}):null;return s.jsxs(s.Fragment,{children:[y?s.jsxs("button",{type:"button",onClick:c?()=>D(!0):void 0,disabled:!c,className:me("flex w-full items-center justify-between gap-2 rounded-lg border border-border/40 bg-[var(--surface-elevated)] px-2 py-1.5 text-left",!c&&"opacity-60 cursor-not-allowed",r),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[c?t?s.jsx(Sn,{providerId:t,className:"h-3.5 w-3.5"}):s.jsx(I,{name:"pencil-ai",className:"h-3 w-3 text-muted-foreground"}):s.jsxs(s.Fragment,{children:[s.jsx(I,{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")})]}),c&&s.jsx("span",{className:"typography-meta font-medium text-foreground",children:t&&e?`${t}/${e}`:i||o("settings.agents.modelSelector.selectPlaceholder")})]}),s.jsx(I,{name:"arrow-down-s",className:"h-3 w-3 text-muted-foreground"})]}):s.jsxs(Bs,{open:c&&A,onOpenChange:c?E:void 0,children:[s.jsx(Os,{asChild:!0,children:s.jsxs("div",{className:me("border-input data-[placeholder]:text-muted-foreground flex items-center justify-between gap-2 rounded-lg border bg-transparent px-2 py-2 typography-ui-label whitespace-nowrap shadow-none outline-none hover:bg-interactive-hover data-[popup-open]:bg-interactive-active h-6 w-fit",r),children:[c?s.jsxs(s.Fragment,{children:[t?s.jsxs(s.Fragment,{children:[s.jsx(Sn,{providerId:t,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx(I,{name:"pencil-ai",className:"h-3 w-3 text-primary/60 hidden"})]}):s.jsx(I,{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:t&&e?`${t}/${e}`:i||o("settings.agents.modelSelector.notSelected")})]}):s.jsxs(s.Fragment,{children:[s.jsx(I,{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:o(d?"common.unavailable":"common.loading")})]}),s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/50"})]})}),s.jsx($s,{className:"w-[min(380px,calc(100vw-2rem))] p-0 flex flex-col",align:"start",children:(()=>{const F=[];re.forEach(({model:U,providerID:ae,modelID:je})=>{F.push({model:U,providerID:ae,modelID:je,section:"fav"})}),ue.forEach(({model:U,providerID:ae,modelID:je})=>{F.push({model:U,providerID:ae,modelID:je,section:"recent"})}),Q.forEach(U=>{U.models.forEach(ae=>{F.push({model:ae,providerID:U.id,modelID:ae.id,section:"provider"})})});const V=F.length,q=U=>{if(U.stopPropagation(),U.key==="ArrowDown"){U.preventDefault();const ae=(N+1)%Math.max(1,V);T(ae),setTimeout(()=>{M.current[ae]?.scrollIntoView({behavior:"smooth",block:"nearest"})},0)}else if(U.key==="ArrowUp"){U.preventDefault();const ae=(N-1+Math.max(1,V))%Math.max(1,V);T(ae),setTimeout(()=>{M.current[ae]?.scrollIntoView({behavior:"smooth",block:"nearest"})},0)}else if(U.key==="Enter"){U.preventDefault();const ae=F[N];ae&&ee(ae.providerID,ae.modelID)}else U.key==="Escape"&&(U.preventDefault(),E(!1))};let te=0;return s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"p-2 border-b border-border/40",children:s.jsxs("div",{className:"relative",children:[s.jsx(I,{name:"search",className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Kt,{type:"text",placeholder:o("settings.agents.modelSelector.searchPlaceholder"),value:P,onChange:U=>C(U.target.value),onKeyDown:q,className:"pl-8 h-8 typography-meta",autoFocus:!0})]})}),s.jsx(Ts,{outerClassName:"max-h-[min(400px,calc(100dvh-12rem))] flex-1",children:s.jsxs("div",{className:"p-1",children:[s.jsxs(zt,{className:me("flex items-center gap-2"),onSelect:()=>ee("",""),children:[s.jsx(I,{name:"close",className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"text-muted-foreground",children:i||o("settings.agents.modelSelector.notSelected")}),!t&&!e&&s.jsx(I,{name:"check",className:"h-4 w-4 text-primary ml-auto"})]}),s.jsx(Dn,{}),!de&&P&&s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:o("settings.agents.modelSelector.state.noModelsFound")}),re.length>0&&s.jsxs("div",{children:[s.jsxs($i,{className:"typography-micro font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2 -mx-1 px-3 py-1.5 border-b border-border/30",children:[s.jsx(I,{name:"star-fill",className:"h-4 w-4 text-primary"}),o("settings.agents.modelSelector.section.favorites")]}),re.map(({model:U,providerID:ae,modelID:je})=>{const oe=te++;return ne(U,ae,je,"fav",oe,N===oe)})]}),ue.length>0&&s.jsxs("div",{children:[re.length>0&&s.jsx(Dn,{}),s.jsxs($i,{className:"typography-micro font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2 -mx-1 px-3 py-1.5 border-b border-border/30",children:[s.jsx(I,{name:"time",className:"h-4 w-4"}),o("settings.agents.modelSelector.section.recent")]}),ue.map(({model:U,providerID:ae,modelID:je})=>{const oe=te++;return ne(U,ae,je,"recent",oe,N===oe)})]}),(re.length>0||ue.length>0)&&Q.length>0&&s.jsx(Dn,{}),Q.map((U,ae)=>s.jsxs("div",{children:[ae>0&&s.jsx(Dn,{}),s.jsxs($i,{className:"typography-micro font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2 -mx-1 px-3 py-1.5 border-b border-border/30",children:[s.jsx(Sn,{providerId:U.id,className:"h-4 w-4 flex-shrink-0"}),U.name]}),U.models.map(je=>{const oe=te++;return ne(je,U.id,je.id,"provider",oe,N===oe)})]},U.id))]})}),s.jsx("div",{className:"px-3 pt-1 pb-1.5 border-t border-border/40 typography-micro text-muted-foreground",children:o("settings.agents.modelSelector.keyboardHints")})]})})()})]}),X()]})},Tl=t=>{const e=at.c(34),{agentName:n,onChange:r,className:a,filter:i}=t,{t:o}=pt(),{isReady:c,isUnavailable:d}=Rh(),p=gt(W1),m=oi(K1),u=oi(H1),h=gt(G1);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 f=b;let v;if(e[2]!==i||e[3]!==f){const $=Vx(f);v=i?$.filter(i):$,e[2]=i,e[3]=f,e[4]=v}else v=e[4];const x=v,g=Te(q1),{isMobile:w}=an(),y=g||w,[k,D]=l.useState(!1);let j,S;e[5]!==u||e[6]!==h||e[7]!==f.length?(j=()=>{f.length>0||(h(),u())},S=[f.length,h,u],e[5]=u,e[6]=h,e[7]=f.length,e[8]=j,e[9]=S):(j=e[8],S=e[9]),l.useEffect(j,S);let A;e[10]===Symbol.for("react.memo_cache_sentinel")?(A=()=>D(!1),e[10]=A):A=e[10];const E=A;let P;e[11]!==r?(P=$=>{r($)},e[11]=r,e[12]=P):P=e[12];const C=P;let N;e[13]!==n||e[14]!==x||e[15]!==C||e[16]!==y||e[17]!==k||e[18]!==o?(N=()=>y?s.jsx(Pr,{open:k,onClose:E,title:o("settings.commands.agentSelector.title"),children:s.jsxs("div",{className:"space-y-1",children:[s.jsxs("button",{type:"button",className:me("flex w-full items-center justify-between rounded-lg border border-border/40 bg-background/95 px-2 py-1.5 text-left",n?"text-foreground":"bg-primary/10 text-primary"),onClick:()=>{C(""),E()},children:[s.jsx("span",{className:me("typography-meta",n?"text-muted-foreground":"font-medium"),children:o("settings.commands.agentSelector.notSelected")}),!n&&s.jsx("div",{className:"h-2 w-2 rounded-full bg-primary"})]}),x.map($=>{const B=$.name===n;return s.jsxs("button",{type:"button",className:me("flex w-full items-center justify-between rounded-lg border border-border/40 bg-background/95 px-2 py-1.5 text-left",B?"bg-primary/10 text-primary":"text-foreground"),onClick:()=>{C($.name),E()},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})]}),B&&s.jsx("div",{className:"h-2 w-2 rounded-full bg-primary"})]},$.name)})]})}):null,e[13]=n,e[14]=x,e[15]=C,e[16]=y,e[17]=k,e[18]=o,e[19]=N):N=e[19];const T=N;let M;e[20]!==n||e[21]!==x||e[22]!==a||e[23]!==C||e[24]!==y||e[25]!==c||e[26]!==d||e[27]!==o?(M=y?s.jsxs("button",{type:"button",onClick:c?()=>D(!0):void 0,disabled:!c,className:me("flex w-full items-center justify-between gap-2 rounded-lg border border-border/40 bg-background/95 px-2 py-1.5 text-left",!c&&"opacity-60 cursor-not-allowed",a),children:[s.jsx("div",{className:"flex items-center gap-2",children:c?s.jsxs(s.Fragment,{children:[s.jsx(I,{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(I,{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(I,{name:"arrow-down-s",className:"h-3 w-3 text-muted-foreground"})]}):c?s.jsxs(Bs,{children:[s.jsx(Os,{asChild:!0,children:s.jsxs("div",{className:me("flex items-center gap-2 px-2 rounded-lg bg-interactive-selection/20 border border-border/20 cursor-pointer hover:bg-interactive-hover/30 h-6 w-fit",a),children:[s.jsx(I,{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(I,{name:"arrow-down-s",className:"h-3 w-3 flex-shrink-0 text-muted-foreground"})]})}),s.jsxs($s,{className:"max-w-[300px]",children:[s.jsx(zt,{className:"typography-meta",onSelect:()=>C(""),children:s.jsx("span",{className:"text-muted-foreground",children:o("settings.commands.agentSelector.notSelected")})}),x.map($=>s.jsx(zt,{className:"typography-meta",onSelect:()=>C($.name),children:s.jsx("span",{className:"font-medium",children:$.name})},$.name))]})]}):s.jsxs("div",{className:me("flex items-center gap-2 px-2 rounded-lg bg-interactive-selection/20 border border-border/20 h-6 w-fit opacity-60",a),children:[s.jsx(I,{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]=C,e[24]=y,e[25]=c,e[26]=d,e[27]=o,e[28]=M):M=e[28];let R;e[29]!==T?(R=T(),e[29]=T,e[30]=R):R=e[30];let L;return e[31]!==M||e[32]!==R?(L=s.jsxs(s.Fragment,{children:[M,R]}),e[31]=M,e[32]=R,e[33]=L):L=e[33],L};function W1(t){return t.agents}function K1(t){return t.agents}function H1(t){return t.loadAgents}function G1(t){return t.loadAgents}function q1(t){return t.isMobile}const im=t=>({providerID:t.providerID,modelID:t.modelID,variant:t.variant,agent:t.agent}),J1=t=>{const e=at.c(38),{value:n,options:r,disabled:a,onChange:i}=t,{t:o}=pt();let c;e[0]!==o||e[1]!==n?(c=n||o("rightSidebar.contextNotesTodo.sendDialog.variant.default"),e[0]=o,e[1]=n,e[2]=c):c=e[2];const d=c,p=a?"cursor-not-allowed opacity-60":"cursor-pointer hover:bg-interactive-hover/30";let m;e[3]!==p?(m=me("flex h-6 w-fit items-center gap-1.5 rounded-lg border border-border/20 bg-interactive-selection/20 px-2",p),e[3]=p,e[4]=m):m=e[4];let u;e[5]!==d?(u=s.jsx("span",{className:"typography-micro whitespace-nowrap font-medium capitalize",children:d}),e[5]=d,e[6]=u):u=e[6];let h;e[7]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(I,{name:"arrow-down-s",className:"h-3 w-3 flex-shrink-0 text-muted-foreground"}),e[7]=h):h=e[7];let b;e[8]!==m||e[9]!==u?(b=s.jsxs("div",{className:m,children:[u,h]}),e[8]=m,e[9]=u,e[10]=b):b=e[10];const f=b;if(a)return f;let v;e[11]!==f?(v=s.jsx(Os,{asChild:!0,children:f}),e[11]=f,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=me("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 k;e[19]!==w||e[20]!==y?(k=s.jsx("span",{className:w,children:y}),e[19]=w,e[20]=y,e[21]=k):k=e[21];let D;e[22]!==k||e[23]!==x?(D=s.jsx(zt,{className:"typography-meta",onSelect:x,children:k}),e[22]=k,e[23]=x,e[24]=D):D=e[24];let j;if(e[25]!==i||e[26]!==r||e[27]!==n){let E;e[29]!==i||e[30]!==n?(E=P=>s.jsx(zt,{className:"typography-meta",onSelect:()=>i(P),children:s.jsx("span",{className:me("font-medium capitalize",n===P&&"text-primary"),children:P})},P),e[29]=i,e[30]=n,e[31]=E):E=e[31],j=r.map(E),e[25]=i,e[26]=r,e[27]=n,e[28]=j}else j=e[28];let S;e[32]!==D||e[33]!==j?(S=s.jsxs($s,{align:"start",className:"max-w-[220px]",children:[D,j]}),e[32]=D,e[33]=j,e[34]=S):S=e[34];let A;return e[35]!==S||e[36]!==v?(A=s.jsxs(Bs,{children:[v,S]}),e[35]=S,e[36]=v,e[37]=A):A=e[37],A};function yf(t){const e=at.c(99),{t:n}=pt(),{open:r,onOpenChange:a,target:i,projectDirectory:o,submitting:c,onConfirm:d}=t,p=c===void 0?!1:c,m=gt(aw),u=gt(rw),h=oi(nw),b=gt(sw),f=gt(tw),v=gt(ew),x=gt(Z1),g=gt(X1);let w;e[0]!==g||e[1]!==v||e[2]!==f||e[3]!==x?(w=()=>im({providerID:f,modelID:v,variant:x,agent:g}),e[0]=g,e[1]=v,e[2]=f,e[3]=x,e[4]=w):w=e[4];const[y,k]=l.useState(w);let D,j;e[5]!==h||e[6]!==u||e[7]!==m||e[8]!==r||e[9]!==o?(D=()=>{r&&(m({directory:o}),u({directory:o}),h())},j=[r,m,u,h,o],e[5]=h,e[6]=u,e[7]=m,e[8]=r,e[9]=o,e[10]=D,e[11]=j):(D=e[10],j=e[11]),l.useEffect(D,j);let S,A;e[12]!==g||e[13]!==v||e[14]!==f||e[15]!==x||e[16]!==r?(S=()=>{r&&k(im({providerID:f,modelID:v,variant:x,agent:g}))},A=[r,f,v,x,g],e[12]=g,e[13]=v,e[14]=f,e[15]=x,e[16]=r,e[17]=S,e[18]=A):(S=e[17],A=e[18]),l.useEffect(S,A);let E,P;e[19]!==y.modelID||e[20]!==y.providerID||e[21]!==r||e[22]!==b?(E=()=>{if(!r||b.length===0)return;const fe=b.find(Ee=>Ee.id===y.providerID)??b[0],ke=Array.isArray(fe?.models)?fe.models:[],be=ke.some(Ee=>Ee.id===y.modelID),pe=ke[0]?.id??"";fe?.id===y.providerID&&be||k(Ee=>({...Ee,providerID:fe?.id??"",modelID:be?Ee.modelID:pe,variant:""}))},P=[r,b,y.providerID,y.modelID],e[19]=y.modelID,e[20]=y.providerID,e[21]=r,e[22]=b,e[23]=E,e[24]=P):(E=e[23],P=e[24]),l.useEffect(E,P);const C=Y1;let N;if(e[25]!==y.modelID||e[26]!==y.providerID||e[27]!==b){let fe;e[29]!==y.providerID?(fe=be=>be.id===y.providerID,e[29]=y.providerID,e[30]=fe):fe=e[30],N=b.find(fe)?.models?.find(be=>be.id===y.modelID),e[25]=y.modelID,e[26]=y.providerID,e[27]=b,e[28]=N}else N=e[28];const T=N;let M;e[31]!==T?(M=T?.variants?Object.keys(T.variants):[],e[31]=T,e[32]=M):M=e[32];const R=M,L=R.length>0;let $,B;e[33]!==y.variant||e[34]!==L?($=()=>{L||!y.variant||k(Q1)},B=[L,y.variant],e[33]=y.variant,e[34]=L,e[35]=$,e[36]=B):($=e[35],B=e[36]),l.useEffect($,B);let O;e[37]!==y.modelID||e[38]!==y.providerID?(O=y.providerID.trim().length>0&&y.modelID.trim().length>0,e[37]=y.modelID,e[38]=y.providerID,e[39]=O):O=e[39];const _=O;let ee;e[40]!==_||e[41]!==y||e[42]!==d||e[43]!==p?(ee=()=>{!_||p||d(y)},e[40]=_,e[41]=y,e[42]=d,e[43]=p,e[44]=ee):ee=e[44];const z=ee;let ne,re;e[45]!==z||e[46]!==r?(ne=()=>{if(!r)return;const fe=ke=>{(ke.metaKey||ke.ctrlKey)&&ke.key==="Enter"&&(ke.preventDefault(),z())};return window.addEventListener("keydown",fe),()=>window.removeEventListener("keydown",fe)},re=[r,z],e[45]=z,e[46]=r,e[47]=ne,e[48]=re):(ne=e[47],re=e[48]),l.useEffect(ne,re);let ue;e[49]!==n||e[50]!==i?(ue=n(i==="worktree"?"rightSidebar.contextNotesTodo.sendDialog.title.newWorktree":"rightSidebar.contextNotesTodo.sendDialog.title.newSession"),e[49]=n,e[50]=i,e[51]=ue):ue=e[51];const Q=ue;let de;e[52]!==a||e[53]!==p?(de=fe=>{p||a(fe)},e[52]=a,e[53]=p,e[54]=de):de=e[54];let X;e[55]!==Q?(X=s.jsx(Cs,{children:s.jsx(js,{children:Q})}),e[55]=Q,e[56]=X):X=e[56];let F;e[57]===Symbol.for("react.memo_cache_sentinel")?(F=(fe,ke)=>{k(be=>({...be,providerID:fe,modelID:ke,variant:""}))},e[57]=F):F=e[57];let V;e[58]!==y.modelID||e[59]!==y.providerID?(V=s.jsx(ao,{providerId:y.providerID,modelId:y.modelID,onChange:F}),e[58]=y.modelID,e[59]=y.providerID,e[60]=V):V=e[60];const q=!L;let te;e[61]===Symbol.for("react.memo_cache_sentinel")?(te=fe=>k(ke=>({...ke,variant:fe})),e[61]=te):te=e[61];let U;e[62]!==y.variant||e[63]!==q||e[64]!==R?(U=s.jsx(J1,{value:y.variant,options:R,disabled:q,onChange:te}),e[62]=y.variant,e[63]=q,e[64]=R,e[65]=U):U=e[65];let ae;e[66]===Symbol.for("react.memo_cache_sentinel")?(ae=fe=>k(ke=>({...ke,agent:fe})),e[66]=ae):ae=e[66];let je;e[67]!==y.agent?(je=s.jsx(Tl,{agentName:y.agent,filter:C,onChange:ae}),e[67]=y.agent,e[68]=je):je=e[68];let oe;e[69]!==V||e[70]!==U||e[71]!==je?(oe=s.jsxs("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-2",children:[V,U,je]}),e[69]=V,e[70]=U,e[71]=je,e[72]=oe):oe=e[72];let ve;e[73]!==a?(ve=()=>a(!1),e[73]=a,e[74]=ve):ve=e[74];let K;e[75]!==n?(K=n("rightSidebar.contextNotesTodo.sendDialog.actions.cancel"),e[75]=n,e[76]=K):K=e[76];let ce;e[77]!==p||e[78]!==ve||e[79]!==K?(ce=s.jsx(we,{variant:"ghost",size:"sm",onClick:ve,disabled:p,children:K}),e[77]=p,e[78]=ve,e[79]=K,e[80]=ce):ce=e[80];const Z=!_||p;let le;e[81]!==p||e[82]!==n?(le=n(p?"rightSidebar.contextNotesTodo.sendDialog.actions.sending":"rightSidebar.contextNotesTodo.sendDialog.actions.send"),e[81]=p,e[82]=n,e[83]=le):le=e[83];let se;e[84]!==z||e[85]!==Z||e[86]!==le?(se=s.jsx(we,{size:"sm",onClick:z,disabled:Z,children:le}),e[84]=z,e[85]=Z,e[86]=le,e[87]=se):se=e[87];let Ie;e[88]!==ce||e[89]!==se?(Ie=s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[ce,se]}),e[88]=ce,e[89]=se,e[90]=Ie):Ie=e[90];let Ne;e[91]!==X||e[92]!==oe||e[93]!==Ie?(Ne=s.jsxs(vs,{className:"max-w-lg",children:[X,oe,Ie]}),e[91]=X,e[92]=oe,e[93]=Ie,e[94]=Ne):Ne=e[94];let Y;return e[95]!==r||e[96]!==de||e[97]!==Ne?(Y=s.jsx(ws,{open:r,onOpenChange:de,children:Ne}),e[95]=r,e[96]=de,e[97]=Ne,e[98]=Y):Y=e[98],Y}function Q1(t){return{...t,variant:""}}function Y1(t){return Lh(t.mode)}function X1(t){return t.currentAgentName||""}function Z1(t){return t.currentVariant||""}function ew(t){return t.currentModelId}function tw(t){return t.currentProviderId}function sw(t){return t.providers}function nw(t){return t.loadAgents}function rw(t){return t.loadAgents}function aw(t){return t.loadProviders}const iw=async(t,e)=>{const n=await Hx(t.path);return{...t,title:n?.title||t.path.split("/").pop()||e}},ow=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`todo_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,lw=({projectRef:t,projectLabel:e,canCreateWorktree:n=!1,onActionComplete:r,className:a})=>{const{t:i}=pt(),[o,c]=l.useState(!1),[d,p]=l.useState(""),[m,u]=l.useState([]),[h,b]=l.useState(""),[f,v]=l.useState(null),[x,g]=l.useState(()=>new Set),[w,y]=l.useState([]),[k,D]=l.useState(null),[j,S]=l.useState(!1),[A,E]=l.useState(0),P=l.useRef(!1),C=l.useRef(""),N=Vt(Y=>Y.currentSessionId),T=Vt(Y=>Y.createSession),M=Vt(Y=>Y.initializeNewOpenChamberSession),R=Vt(Y=>Y.sendMessage),L=Vt(Y=>Y.setCurrentSession),$=Pa(Y=>Y.setPendingInputText),B=Vs(Y=>Y.currentDirectory),O=Te(Y=>Y.openContextPanelTab),_=Te(Y=>Y.setActiveMainTab),ee=Te(Y=>Y.setSessionSwitcherOpen),z=l.useCallback(async(Y,fe)=>{if(!t)return!1;const ke=await zx(t,{notes:Y,todos:fe});return ke||H.error(i("rightSidebar.contextNotesTodo.toast.saveNotesFailed")),ke},[t,i]);l.useEffect(()=>{if(!t){p(""),u([]),y([]),b(""),g(new Set);return}let Y=!1;return c(!0),(async()=>{try{const fe=await Ux(t),ke=await Promise.all(fe.plans.map(be=>iw(be,i("rightSidebar.contextNotesTodo.plan.defaultTitle"))));if(Y)return;p(fe.notes),u(fe.todos),y(ke),C.current=fe.notes,P.current=!0,b(""),g(new Set)}catch{Y||(H.error(i("rightSidebar.contextNotesTodo.toast.loadNotesFailed")),p(""),u([]),y([]),C.current="",P.current=!0)}finally{Y||c(!1)}})(),()=>{Y=!0}},[A,t,i]),l.useEffect(()=>{if(!t)return;const Y=fe=>{const ke=fe.detail;ke?.projectId&&ke.projectId!==t.id||E(be=>be+1)};return window.addEventListener("openchamber:project-plan-saved",Y),window.addEventListener("openchamber:project-notes-updated",Y),()=>{window.removeEventListener("openchamber:project-plan-saved",Y),window.removeEventListener("openchamber:project-notes-updated",Y)}},[t]);const ne=l.useCallback(()=>{C.current=d,z(d,m)},[d,z,m]);l.useEffect(()=>{if(!t||!P.current||d===C.current)return;const Y=window.setTimeout(()=>{C.current=d,z(d,m)},400);return()=>{window.clearTimeout(Y)}},[d,z,t,m]);const re=l.useCallback(()=>{const Y=h.trim();if(!Y)return;const fe=[...m,{id:ow(),text:Y.slice(0,ho),completed:!1,createdAt:Date.now()}];u(fe),b(""),z(d,fe)},[h,d,z,m]),ue=l.useCallback(Y=>{g(fe=>{const ke=new Set(fe);return ke.has(Y)?ke.delete(Y):ke.add(Y),ke})},[]),Q=l.useCallback((Y,fe)=>{const ke=m.map(be=>be.id===Y?{...be,completed:fe}:be);u(ke),z(d,ke)},[d,z,m]),de=l.useCallback(Y=>{const fe=m.filter(ke=>ke.id!==Y);u(fe),z(d,fe)},[d,z,m]),X=l.useCallback(()=>{const Y=m.filter(fe=>!fe.completed);Y.length!==m.length&&(u(Y),z(d,Y))},[d,z,m]),F=h.slice(0,ho),V=m.reduce((Y,fe)=>Y+(fe.completed?1:0),0),q=l.useCallback(()=>{_("chat"),ee(!1)},[_,ee]),te=l.useCallback((Y,fe)=>{!t||f||D({kind:"session",todoId:Y,todoText:fe})},[t,f]),U=l.useCallback(Y=>{if(!N){H.error(i("rightSidebar.contextNotesTodo.toast.noActiveSession"));return}q();const fe=`\`\`\`md
4
- ${Y}
5
- \`\`\``;$(fe,"append"),H.success(i("rightSidebar.contextNotesTodo.toast.sentToCurrentSession")),r?.()},[N,r,q,$,i]),ae=l.useCallback((Y,fe)=>{if(!(!t||f)){if(!n){H.error(i("rightSidebar.contextNotesTodo.toast.worktreeRequiresGitRepo"));return}D({kind:"worktree",todoId:Y,todoText:fe})}},[n,t,f,i]),je=l.useCallback(async Y=>{if(!t||!k)return;const fe=await kn("plan.todo.visible",{todo_text:k.todoText}),be=[{synthetic:!0,text:await kn("plan.todo.instructions",{todo_text:k.todoText})}];S(!0),v(k.todoId);try{q();let pe=null,Ee=t.path;if(k.kind==="worktree"){if(!n){H.error(i("rightSidebar.contextNotesTodo.toast.worktreeRequiresGitRepo"));return}const G=await Oh(t.path,$h());if(!G?.id)return;pe=G.id,Ee=null}else{const G=await T(void 0,t.path,null);if(!G?.id){H.error(i("rightSidebar.contextNotesTodo.toast.createSessionFailed"));return}pe=G.id,Ee=G.directory??t.path,M(G.id,gt.getState().agents??[])}if(!pe)return;const ze=Nl.getState();ze.saveSessionModelSelection(pe,Y.providerID,Y.modelID),Y.agent.trim()&&(ze.saveSessionAgentSelection(pe,Y.agent),ze.saveAgentModelForSession(pe,Y.agent,Y.providerID,Y.modelID),ze.saveAgentModelVariantForSession(pe,Y.agent,Y.providerID,Y.modelID,Y.variant||void 0)),L(pe,Ee),await R(fe,Y.providerID,Y.modelID,Y.agent.trim()||void 0,void 0,void 0,be,Y.variant||void 0),H.success(k.kind==="worktree"?i("rightSidebar.contextNotesTodo.toast.sentToNewWorktreeSession"):i("rightSidebar.contextNotesTodo.toast.sentToNewSession")),D(null),r?.()}catch(pe){const Ee=pe instanceof Error?pe.message:void 0;H.error(i("rightSidebar.contextNotesTodo.toast.sendTodoFailed"),Ee?{description:Ee}:void 0)}finally{S(!1),v(null)}},[n,T,M,r,k,t,q,R,L,i]),oe=l.useRef(null),[ve,K]=l.useState(!1),[ce,Z]=l.useState(null),le=l.useCallback(async Y=>{if(!(!t||ce)){Z(Y);try{if(!await Wx(t,Y)){H.error(i("rightSidebar.contextNotesTodo.toast.deletePlanFailed"));return}y(ke=>ke.filter(be=>be.id!==Y)),window.dispatchEvent(new CustomEvent("openchamber:project-plan-saved",{detail:{projectId:t.id}}))}finally{Z(null)}}},[ce,t,i]),se=l.useCallback(()=>{!t||ve||oe.current?.click()},[ve,t]),Ie=l.useCallback(async Y=>{if(!(!t||!Y)){K(!0);try{const fe=await Y.text();if(!fe.trim()){H.error(i("rightSidebar.contextNotesTodo.toast.planFileEmpty"));return}const ke=Y.name.replace(/\.(md|markdown|txt)$/i,"").trim();if(!await Kx(t,fe,ke)){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(fe){const ke=fe instanceof Error?fe.message:void 0;H.error(i("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"),ke?{description:ke}:void 0)}finally{K(!1)}}},[t,i]),Ne=l.useCallback(Y=>{const fe=t?.path?.trim(),ke=B?.trim()||fe;ke&&O(ke,{mode:"plan",targetPath:Y.path,dedupeKey:Y.path,label:Y.title})},[B,O,t]);return t?s.jsxs("div",{className:me("w-full min-w-0 space-y-3 p-3",a),children:[s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("h3",{className:"min-w-0 truncate typography-ui-label font-semibold text-foreground",title:t.path,children:i("rightSidebar.contextNotesTodo.notes.title",{project:e?.trim()||t.path.split("/").filter(Boolean).pop()||t.path})}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[d.length,"/",fu]})]}),s.jsx(bn,{value:d,onChange:Y=>p(Y.target.value.slice(0,fu)),onBlur:ne,placeholder:i("rightSidebar.contextNotesTodo.notes.placeholder"),className:"min-h-28 max-h-80 resize-none",useScrollShadow:!0,scrollShadowSize:56,disabled:o})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-label font-semibold text-foreground",children:i("rightSidebar.contextNotesTodo.todo.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:m.length===1?i("rightSidebar.contextNotesTodo.todo.itemsSingle",{count:m.length}):i("rightSidebar.contextNotesTodo.todo.itemsPlural",{count:m.length})}),s.jsx("button",{type:"button",onClick:X,disabled:o||V===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:[F.length,"/",ho]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Kt,{value:F,onChange:Y=>b(Y.target.value.slice(0,ho)),onKeyDown:Y=>{Y.key==="Enter"&&(Y.preventDefault(),re())},placeholder:i("rightSidebar.contextNotesTodo.todo.inputPlaceholder"),disabled:o,className:"h-8"}),s.jsx("button",{type:"button",onClick:re,disabled:o||F.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(I,{name:"add",className:"h-4 w-4"})})]}),s.jsx("div",{className:"max-h-56 overflow-y-auto rounded-lg border border-border/60 bg-background/40",children:m.length===0?s.jsx("p",{className:"px-3 py-3 typography-meta text-muted-foreground",children:i("rightSidebar.contextNotesTodo.todo.empty")}):s.jsx("ul",{className:"divide-y divide-border/50",children:m.map(Y=>{const fe=x.has(Y.id);return s.jsxs("li",{className:"flex items-start gap-1.5 px-2.5 py-1.5",children:[s.jsx("div",{className:"flex h-6 items-center",children:s.jsx(xs,{checked:Y.completed,onChange:ke=>Q(Y.id,ke),ariaLabel:i("rightSidebar.contextNotesTodo.todo.actions.markComplete",{text:Y.text})})}),s.jsx("button",{type:"button",onClick:()=>ue(Y.id),className:me("block min-h-6 min-w-0 flex-1 bg-transparent p-0 text-left typography-ui-label leading-6 text-foreground",fe?"whitespace-normal break-words":"overflow-hidden text-ellipsis whitespace-nowrap","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",Y.completed&&"text-muted-foreground line-through"),title:fe?void 0:Y.text,"aria-label":fe?i("rightSidebar.contextNotesTodo.todo.actions.collapse",{text:Y.text}):i("rightSidebar.contextNotesTodo.todo.actions.expand",{text:Y.text}),children:Y.text}),s.jsxs("div",{className:"flex h-6 items-center gap-0.5",children:[s.jsx("button",{type:"button",onClick:()=>de(Y.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:Y.text}),title:i("rightSidebar.contextNotesTodo.todo.actions.delete",{text:Y.text}),children:s.jsx(I,{name:"delete-bin",className:"h-3.5 w-3.5"})}),s.jsxs(Bs,{children:[s.jsx(Os,{asChild:!0,children:s.jsx("button",{type:"button",disabled:f===Y.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:Y.text}),title:i("rightSidebar.contextNotesTodo.todo.actions.send",{text:Y.text}),children:s.jsx(I,{name:"send-plane",className:"h-3.5 w-3.5"})})}),s.jsxs($s,{align:"end",className:"w-56",children:[s.jsx(zt,{onClick:()=>U(Y.text),children:i("rightSidebar.contextNotesTodo.todo.sendMenu.currentSession")}),s.jsx(zt,{onClick:()=>te(Y.id,Y.text),children:i("rightSidebar.contextNotesTodo.todo.sendMenu.newSession")}),s.jsx(zt,{onClick:()=>{ae(Y.id,Y.text)},disabled:!n,children:i("rightSidebar.contextNotesTodo.todo.sendMenu.newWorktreeSession")})]})]})]})]},Y.id)})})})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-label font-semibold text-foreground",children:i("rightSidebar.contextNotesTodo.plans.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:w.length===1?i("rightSidebar.contextNotesTodo.plans.filesSingle",{count:w.length}):i("rightSidebar.contextNotesTodo.plans.filesPlural",{count:w.length})})]}),s.jsx("input",{ref:oe,type:"file",accept:".md,.markdown,.txt,text/markdown,text/plain",className:"hidden",onChange:Y=>{const fe=Y.target.files?.[0]??null;Ie(fe),Y.currentTarget.value=""}}),s.jsx("button",{type:"button",onClick:se,disabled:!t||ve,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(I,{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(Y=>s.jsxs("li",{className:"flex items-center gap-1.5 px-2.5 py-1.5",children:[s.jsxs("button",{type:"button",onClick:()=>Ne(Y),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:Y.title}),s.jsx("span",{className:"flex-shrink-0 typography-micro text-muted-foreground",children:new Date(Y.createdAt).toLocaleDateString()})]}),s.jsx("button",{type:"button",onClick:()=>{le(Y.id)},disabled:ce===Y.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:Y.title}),children:s.jsx(I,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},Y.id))})})]}),s.jsx(yf,{open:k!==null,onOpenChange:Y=>{!Y&&!j&&D(null)},target:k?.kind??"session",projectDirectory:t?.path??null,submitting:j,onConfirm:je})]}):s.jsx("div",{className:me("w-full min-w-0 p-3",a),children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:i("rightSidebar.contextNotesTodo.empty.selectProject")})})},vf=12,cw=[{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"}],dw=t=>{const e=at.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?cw:o,u=Be.useRef(!1);let h,b;e[0]!==n||e[1]!==c?(h=()=>{!n&&u.current&&c?.(),n&&(u.current=!0)},b=[n,c],e[0]=n,e[1]=c,e[2]=h,e[3]=b):(h=e[2],b=e[3]),Be.useEffect(h,b);let f;e[4]===Symbol.for("react.memo_cache_sentinel")?(f=Array.from({length:vf},uw),e[4]=f):f=e[4];const v=f;if(!n)return null;let x;e[5]!==a?(x=me("fireworks-overlay pointer-events-none",a),e[5]=a,e[6]=x):x=e[6];let g;if(e[7]!==d||e[8]!==m||e[9]!==p){let y;e[11]!==d||e[12]!==p?(y=k=>{const D={"--burst-delay":`${k.delay}ms`,"--burst-x":`${k.x}%`,"--burst-y":`${k.y}%`,"--firework-color":`var(${k.colorVar})`,"--firework-duration":`${p}ms`};return s.jsx("div",{className:"firework-burst",style:D,children:v.map((j,S)=>{const A=j.x*k.radius,E=j.y*k.radius,P={"--translate-x":`${A}px`,"--translate-y":`${E}px`,"--particle-delay":`${j.delay}ms`,color:`var(${k.colorVar})`};return s.jsx("span",{className:"firework-particle",style:P},`${k.id}-${S}-${d}`)})},`${k.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 uw(t,e){const n=Math.PI*2*e/vf;return{x:Math.cos(n),y:Math.sin(n),delay:e*18}}const mw=t=>{const e=at.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]=Be.useState(i),d=Be.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(pw)},e[4]=u):u=e[4];const h=u;let b;e[5]!==a?(b=()=>{m(),c(hw),d.current=window.setTimeout(()=>{c(fw),d.current=null},a)},e[5]=a,e[6]=b):b=e[6];const f=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]),Be.useEffect(v,x);let g;return e[9]!==o.cycle||e[10]!==o.isActive||e[11]!==f?(g={isActive:o.isActive,burstKey:o.cycle,triggerFireworks:f,dismissFireworks:h},e[9]=o.cycle,e[10]=o.isActive,e[11]=f,e[12]=g):g=e[12],g};function pw(t){return t.isActive?{...t,isActive:!1}:t}function hw(t){return{isActive:!0,cycle:t.cycle+1}}function fw(t){return t.isActive?{...t,isActive:!1}:t}const wf=l.createContext(void 0),gw=t=>{const e=at.c(10),{children:n}=t,{isActive:r,burstKey:a,triggerFireworks:i,dismissFireworks:o}=mw();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(dw,{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(wf.Provider,{value:d,children:[n,p]}),e[6]=n,e[7]=p,e[8]=d,e[9]=m):m=e[9],m},xw=()=>{const t=l.useContext(wf);if(!t)throw new Error("useFireworksCelebration must be used within FireworksProvider");return t},Jn=tr()(gi(Zi((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 Xx();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 Yx();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 Qx();return t({discoveredCredentials:n}),!0}catch(n){return console.error("Failed to discover git credentials:",n),t({discoveredCredentials:[]}),!1}},loadDefaultGitIdentityId:async()=>{const n=r=>{if(typeof r!="string")return null;const a=r.trim();return a.length>0?a:null};try{let r=null;if(r===null){const a=dr()?.settings;if(a)try{const 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 Ds({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 Jx(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 qx(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 Gx(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:vl(()=>Zr()),partialize:t=>({selectedProfileId:t.selectedProfileId})}),{name:"git-identities-store"}));typeof window<"u"&&(window.__zustand_git_identities_store__=Jn);function Ta(t){const e=at.c(12);let n,r,a;e[0]!==t?({className:n,style:a,...r}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=a):(n=e[1],r=e[2],a=e[3]);let i;e[4]!==a?(i={color:"var(--surface-elevated-foreground)",...a},e[4]=a,e[5]=i):i=e[5];let o;e[6]!==n?(o=me("flex h-full w-full flex-col overflow-hidden rounded-xl",n),e[6]=n,e[7]=o):o=e[7];let c;return e[8]!==r||e[9]!==i||e[10]!==o?(c=s.jsx(Fa,{"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 ra=Be.forwardRef((t,e)=>{const n=at.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(I,{name:"search",className:"size-4 shrink-0 opacity-50"}),n[3]=i):i=n[3];let o;n[4]!==r?(o=me("placeholder:text-muted-foreground flex h-8 w-full rounded-lg bg-transparent py-2 typography-meta outline-none focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50",r),n[4]=r,n[5]=o):o=n[5];let c;return n[6]!==a||n[7]!==e||n[8]!==o?(c=s.jsxs("div",{"data-slot":"command-input-wrapper",className:"flex h-8 items-center gap-2 border-b px-3",children:[i,s.jsx(Fa.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});ra.displayName="CommandInput";function Ma(t){const e=at.c(14);let n,r,a,i,o;e[0]!==t?({className:r,children:n,scrollbarClassName:o,disableHorizontal:a,...i}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=a,e[4]=i,e[5]=o):(n=e[1],r=e[2],a=e[3],i=e[4],o=e[5]);let c;e[6]!==r?(c=me("scroll-py-1 overflow-x-hidden h-full min-h-0",r),e[6]=r,e[7]=c):c=e[7];const d=o??"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",p=a??!0;let m;return e[8]!==n||e[9]!==i||e[10]!==c||e[11]!==d||e[12]!==p?(m=s.jsx(Ts,{as:Fa.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 Ea(t){const e=at.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(Fa.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 Bn(t){const e=at.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let a;e[3]!==n?(a=me("text-foreground [&_[cmdk-group-heading]]:text-muted-foreground overflow-hidden p-1 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:typography-meta [&_[cmdk-group-heading]]:font-medium",n),e[3]=n,e[4]=a):a=e[4];let i;return e[5]!==r||e[6]!==a?(i=s.jsx(Fa.Group,{"data-slot":"command-group",className:a,...r}),e[5]=r,e[6]=a,e[7]=i):i=e[7],i}function va(t){const e=at.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let a;e[3]!==n?(a=me("bg-border -mx-1 h-px",n),e[3]=n,e[4]=a):a=e[4];let i;return e[5]!==r||e[6]!==a?(i=s.jsx(Fa.Separator,{"data-slot":"command-separator",className:a,...r}),e[5]=r,e[6]=a,e[7]=i):i=e[7],i}function An(t){const e=at.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let a;e[3]!==n?(a=me("data-[selected=true]:bg-interactive-selection data-[selected=true]:text-interactive-selection-foreground data-[highlighted]:bg-interactive-hover hover:bg-interactive-hover [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 typography-meta outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",n),e[3]=n,e[4]=a):a=e[4];let i;return e[5]!==r||e[6]!==a?(i=s.jsx(Fa.Item,{"data-slot":"command-item",className:a,...r}),e[5]=r,e[6]=a,e[7]=i):i=e[7],i}function bw(t){const e=at.c(12);let n,r,a,i;if(e[0]!==t){const{className:c,...d}=t,p=vw,m=typeof d.children=="string"?d.children:"",u=m?m.split("+").map(yw).filter(Boolean):[];n="command-shortcut",e[5]!==c?(r=me("text-muted-foreground ml-auto flex items-center gap-1 typography-meta",c),e[5]=c,e[6]=r):r=e[6],a=d,i=u.length>0?u.map((h,b)=>s.jsxs(Be.Fragment,{children:[b>0&&s.jsx("span",{className:"opacity-60 text-xs",children:"+"}),p(h)]},`${h}-${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 yw(t){return t.trim()}function vw(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(I,{name:"command",className:"size-3.5"}):e==="shift"||e==="⇧"?s.jsx(I,{name:"arrow-up",className:"size-3.5"}):s.jsx("span",{className:"text-xs font-medium",children:t})}const ed=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},ww=t=>{const e=ed(t);if(!e)return null;const r=e.indexOf("/.git/worktrees/");return r>0&&e.slice(0,r)||null};function jw(t,e,n){const r=at.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([Ws("git rev-parse --absolute-git-dir",t),Ws("git rev-parse --show-toplevel",t)]);if(d||!p.success||!m.success)return;const u=ed((p.stdout||"").trim()),h=ww(u);if(!h)return;const b=ed((m.stdout||"").trim());if(!b||b===h)return;const f=n||"",v=b.split("/").filter(Boolean).pop()||b;i({source:"sdk",path:b,projectDirectory:h,branch:f,label:f||v,name:v,worktreeRoot:b,worktreeStatus:"ready",headState:f?"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 Qn=t=>{const e=t.trim();return e?`'${e.replace(/'/g,"'\\''")}'`:"''"},pi=t=>(t||"").split(/\r?\n/).map(e=>e.trim()).filter(Boolean),zr=t=>!!t.success,Ml=t=>(t.stdout||"").trim(),Sa=t=>(t.stderr||"").trim();async function Nw(t){const n=((await Ws("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 Sw(t){const e=`refs/heads/${t.targetBranch}`,n=new Set(t.excludePaths),a=(await Nw(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 Ws("git status --porcelain",o);Ml(c)||i.push(o)}return i}async function jf(t,e){for(const n of e)await Ws("git reset --hard",n).catch(()=>{})}async function kw(t,e){const n=e.trim();if(!n||n==="HEAD")return"HEAD";const r=await Ws(`git show-ref --verify --quiet ${Qn(`refs/heads/${n}`)}`,t);if(zr(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 Ws(`git branch --track ${Qn(d)} ${Qn(`${c}/${d}`)}`,t),d}const a=await Ws(`git show-ref --verify --quiet ${Qn(`refs/remotes/origin/${n}`)}`,t);return zr(a)&&await Ws(`git branch --track ${Qn(n)} ${Qn(`origin/${n}`)}`,t),n}async function Si(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 kw(e,r),i=await Ws(`git cherry ${Qn(a)} ${Qn(n)}`,e),o=pi(i.stdout),c=new Set;for(const u of o){const h=u.match(/^\+\s+([0-9a-f]{7,40})\b/i);h&&c.add(h[1])}const d=await Ws(`git rev-list --reverse ${Qn(`${a}..${n}`)}`,e),m=pi(d.stdout).filter(u=>c.has(u));return{repoRoot:e,sourceBranch:n,targetBranch:a,commits:m}}async function Cw(t,e){const n=await Ws('mkdir -p "$HOME/.config/openchamber/tmp"',t);if(!zr(n))throw new Error(Sa(n)||"Failed to create temp directory parent");const r=await Ws('mktemp -d "$HOME/.config/openchamber/tmp/oc-integrate-XXXXXX"',t),a=Ml(r);if(!a)throw new Error(Sa(r)||"Failed to create temp directory");const i=await Ws(`git worktree add --force ${Qn(a)} ${Qn(e)}`,t);if(!zr(i))throw new Error(Sa(i)||"Failed to create temp worktree");return a}async function cl(t,e){await Ws(`git worktree remove --force ${Qn(e)}`,t).catch(()=>{}),await Ws("git worktree prune",t).catch(()=>{})}async function Iw(t){const e=await Ws("git rev-parse --abbrev-ref --symbolic-full-name @{u}",t),n=Ml(e);if(!n)return;await Ws("git fetch",t);const r=await Ws(`git merge --ff-only ${Qn(n)}`,t);if(!zr(r))throw new Error(Sa(r)||"Fast-forward failed")}async function dl(t){const e=await Ws("git status --porcelain",t),n=await Ws("git diff --name-only --diff-filter=U",t),r=await Ws("git diff",t),a=await Ws("git show --no-patch --pretty=fuller CHERRY_PICK_HEAD",t),i=await Ws("git show CHERRY_PICK_HEAD",t);return{statusPorcelain:e.stdout||"",unmergedFiles:pi(n.stdout),diff:r.stdout||r.stderr||"",currentPatchMeta:a.stdout||a.stderr||"",currentPatch:i.stdout||i.stderr||""}}async function Pw(t){return dl(t)}async function Aw(t){const e=await Ws("git rev-parse --verify --quiet CHERRY_PICK_HEAD",t);return zr(e)}async function Dw(t){if(t.commits.length===0)return{kind:"noop",reason:"No commits to move"};const e=await Cw(t.repoRoot,t.targetBranch);let n=[];try{await Iw(e);const r=await Ws("git status --porcelain",e);if(Ml(r))throw new Error("Target branch has local changes; abort integration and retry");const a=await Sw({repoRoot:t.repoRoot,targetBranch:t.targetBranch,excludePaths:[e]}).catch(()=>[]);for(n=[...t.commits];n.length>0;){const i=n[0],o=await Ws(`git cherry-pick ${Qn(i)}`,e);if(zr(o)){n.shift();continue}const c=await Ws("git diff --name-only --diff-filter=U",e);if(pi(c.stdout).length>0){const p=await dl(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(Sa(o)||"Cherry-pick failed")}return await cl(t.repoRoot,e),await jf(t.repoRoot,a).catch(()=>{}),{kind:"success",moved:t.commits.length}}catch(r){throw await cl(t.repoRoot,e).catch(()=>{}),r}}async function Tw(t){await Ws("git cherry-pick --abort",t.tempWorktreePath).catch(()=>{}),await cl(t.repoRoot,t.tempWorktreePath)}async function Mw(t){const e=await Ws("git cherry-pick --continue",t.tempWorktreePath);if(!zr(e)){const i=await Ws("git diff --name-only --diff-filter=U",t.tempWorktreePath);if(pi(i.stdout).length>0){const c=await dl(t.tempWorktreePath);return{kind:"conflict",state:t,details:c}}throw new Error(Sa(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 Ws(`git cherry-pick ${Qn(i)}`,n);if(zr(o)){a.shift();continue}const c=await Ws("git diff --name-only --diff-filter=U",n);if(pi(c.stdout).length>0){const p=await dl(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(Sa(o)||"Cherry-pick failed")}return await cl(t.repoRoot,t.tempWorktreePath),await jf(t.repoRoot,t.cleanTargetWorktrees).catch(()=>{}),{kind:"success",moved:t.remainingCommits.length}}const Ew=({repoRoot:t,sourceBranch:e,worktreeMetadata:n,localBranches:r,defaultTargetBranch:a,refreshKey:i,onRefresh:o})=>{const{t:c}=pt(),d=Vt(O=>O.currentSessionId),p=Te(O=>O.setActiveMainTab),[m,u]=Be.useState(!1),h=Be.useRef(null),[b,f]=Be.useState(a);Be.useEffect(()=>{f(a)},[a]),Be.useEffect(()=>{if(m){const O=setTimeout(()=>{h.current?.focus()},0);return()=>clearTimeout(O)}},[m]);const v=!!(t&&e&&b&&b!=="HEAD"&&e!==b),[x,g]=Be.useState({kind:"idle"}),[w,y]=Be.useState(!1),[k,D]=Be.useState([]),j=Be.useMemo(()=>d?`openchamber.integrate.conflict:${d}`:null,[d]);Be.useEffect(()=>{if(!j||typeof window>"u")return;const O=window.localStorage.getItem(j);if(!O)return;let _=!1;try{const ee=JSON.parse(O);if(!ee?.tempWorktreePath||ee.repoRoot!==t){window.localStorage.removeItem(j);return}(async()=>{const z=await Aw(ee.tempWorktreePath).catch(()=>!1);if(_)return;if(!z){window.localStorage.removeItem(j);return}const ne=await Pw(ee.tempWorktreePath).catch(()=>null);_||ne&&g({kind:"conflict",state:ee,details:ne})})()}catch{window.localStorage.removeItem(j)}return()=>{_=!0}},[j,t]),Be.useEffect(()=>{if(!v){g({kind:"idle"});return}let O=!1;return g({kind:"loading"}),(async()=>{try{const _=await Si({repoRoot:t,sourceBranch:e,targetBranch:b});if(O)return;if(g({kind:"ready",plan:_}),_.commits.length>0){const ne=_.commits.slice(-50).reverse().map(de=>JSON.stringify(de)).join(" "),ue=((await Ws(`git show -s --format=%H%x09%h%x09%s ${ne}`,t)).stdout||"").split(/\r?\n/).filter(Boolean),Q=[];for(const de of ue){const[X,F,V]=de.split(" ");!X||!F||Q.push({sha:X,short:F,subject:V||""})}O||(D(Q),y(!1))}else O||(D([]),y(!1))}catch{O||g({kind:"idle"})}})(),()=>{O=!0}},[v,t,e,b,i]);const S=Be.useCallback(O=>{d&&Vt.getState().setWorktreeMetadata(d,{...n,createdFromBranch:O})},[d,n]),A=Vt(O=>O.openNewSessionDraft),E=Be.useCallback(async O=>{const _=await kn("git.integrate.cherrypick.resolve.visible",{current_commit:O.state.currentCommit,target_branch:O.state.targetBranch}),ee=await kn("git.integrate.cherrypick.resolve.instructions",{repo_root:O.state.repoRoot,temp_worktree_path:O.state.tempWorktreePath,source_branch:O.state.sourceBranch,target_branch:O.state.targetBranch,current_commit:O.state.currentCommit}),z=`Cherry-pick conflict context (JSON)
6
- ${JSON.stringify({repoRoot:O.state.repoRoot,tempWorktreePath:O.state.tempWorktreePath,sourceBranch:O.state.sourceBranch,targetBranch:O.state.targetBranch,currentCommit:O.state.currentCommit,remainingCommits:O.state.remainingCommits,statusPorcelain:O.details.statusPorcelain,unmergedFiles:O.details.unmergedFiles,currentPatchMeta:O.details.currentPatchMeta,currentPatch:O.details.currentPatch,diff:O.details.diff},null,2)}`;return{visibleText:_,instructionsText:ee,payloadText:z}},[]),P=Pa(O=>O.setPendingInputText),C=Pa(O=>O.setPendingSyntheticParts),N=Be.useCallback(async(O,_)=>{const ee=await E(O);if(_){A({directoryOverride:O.state.tempWorktreePath,initialPrompt:ee.visibleText,syntheticParts:[{text:ee.instructionsText,synthetic:!0},{text:ee.payloadText,synthetic:!0}]}),p("chat");return}if(!d){H.error(c("gitView.integrate.noActiveSession"),{description:c("gitView.integrate.noActiveSessionDescription")});return}P(ee.visibleText,"replace"),C([{text:ee.instructionsText,synthetic:!0},{text:ee.payloadText,synthetic:!0}]),p("chat")},[d,p,E,A,P,C,c]),T=Be.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 O=await Dw(x.plan);if(O.kind==="success"){H.success(c("gitView.integrate.commitsMovedToast"),{description:O.moved===1?c("gitView.integrate.commitsMovedDescriptionSingle",{count:O.moved,branch:x.plan.targetBranch}):c("gitView.integrate.commitsMovedDescriptionPlural",{count:O.moved,branch:x.plan.targetBranch})});const _=await Si(x.plan);g({kind:"ready",plan:_}),o?.();return}O.kind==="conflict"&&(H.error(c("gitView.integrate.cherryPickConflictToast"),{description:c("gitView.integrate.cherryPickConflictDescription")}),g({kind:"conflict",state:O.state,details:O.details}),j&&typeof window<"u"&&window.localStorage.setItem(j,JSON.stringify(O.state)))}catch(O){const _=O instanceof Error?O.message:String(O);H.error(c("gitView.integrate.failedToMoveToast"),{description:_});const ee=await Si({repoRoot:t,sourceBranch:e,targetBranch:b}).catch(()=>null);g(ee?{kind:"ready",plan:ee}:{kind:"idle"})}}},[x,o,t,e,b,j,c]),M=Be.useCallback(async()=>{if(x.kind==="conflict")try{await Tw(x.state),H.message(c("gitView.integrate.cherryPickAbortedToast")),j&&typeof window<"u"&&window.localStorage.removeItem(j)}finally{const O=await Si({repoRoot:t,sourceBranch:e,targetBranch:b}).catch(()=>null);g(O?{kind:"ready",plan:O}:{kind:"idle"})}},[x,t,e,b,j,c]),R=Be.useCallback(async()=>{if(x.kind==="conflict")try{const O=await Mw(x.state);if(O.kind==="success"){H.success(c("gitView.integrate.cherryPickFinishedToast"));const _=await Si({repoRoot:t,sourceBranch:e,targetBranch:b}).catch(()=>null);g(_?{kind:"ready",plan:_}:{kind:"idle"}),j&&typeof window<"u"&&window.localStorage.removeItem(j),o?.();return}O.kind==="conflict"&&(g({kind:"conflict",state:O.state,details:O.details}),j&&typeof window<"u"&&window.localStorage.setItem(j,JSON.stringify(O.state)))}catch(O){const _=O instanceof Error?O.message:String(O);H.error(c("gitView.integrate.cherryPickContinueFailedToast"),{description:_})}},[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(I,{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(I,{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(Bs,{open:m,onOpenChange:u,children:[s.jsx(Os,{asChild:!0,children:s.jsxs(we,{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(I,{name:"arrow-down-s",className:"size-4 opacity-60"})]})}),s.jsx($s,{align:"end",className:"w-72 p-0 max-h-[var(--available-height)] flex flex-col overflow-hidden",children:s.jsxs(Ta,{className:"h-full min-h-0",children:[s.jsx(ra,{ref:h,placeholder:c("gitView.branch.searchPlaceholder")}),s.jsxs(Ma,{className:"h-full min-h-0",scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[s.jsx(Ea,{children:c("gitView.branch.empty")}),s.jsx(Bn,{heading:c("gitView.branch.localBranches"),children:r.map(O=>s.jsx(An,{value:O,onSelect:()=>{f(O),S(O),u(!1)},children:O},O))})]})]})})]}),x.kind==="ready"?s.jsx(we,{size:"sm",onClick:()=>{T()},disabled:!v||x.plan.commits.length===0,children:c("gitView.integrate.move")}):x.kind==="loading"?s.jsx(we,{size:"sm",variant:"outline",disabled:!0,children:c("gitView.integrate.checking")}):x.kind==="running"?s.jsx(we,{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,")"]})]}),k.length>0&&x.plan.commits.length>5&&s.jsx("button",{type:"button",onClick:()=>y(O=>!O),className:"typography-micro text-muted-foreground hover:text-foreground",children:c(w?"gitView.integrate.showLess":"gitView.integrate.showAll")})]}),s.jsxs("div",{className:"space-y-1",children:[(w?k:k.slice(0,5)).map(O=>s.jsxs("div",{className:"flex items-baseline gap-2 min-w-0",children:[s.jsx("span",{className:"font-mono text-xs text-muted-foreground flex-shrink-0",children:O.short}),s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:O.subject||O.sha})]},O.sha)),k.length===0&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:c("gitView.integrate.previewUnavailable")}),x.plan.commits.length>k.length&&s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:c("gitView.integrate.showingFirstCommits",{count:k.length})})]})]}),x.kind==="conflict"&&s.jsxs("div",{className:"rounded-md border border-border/60 bg-background/60 p-3 space-y-2",children:[s.jsx("div",{className:"typography-meta text-foreground",children:c("gitView.integrate.conflictsInFiles",{count:x.details.unmergedFiles.length})}),s.jsxs("div",{className:"typography-micro text-muted-foreground/80",children:[c("gitView.integrate.currentCommit"),": ",s.jsx("span",{className:"font-mono",children:x.state.currentCommit.slice(0,7)})]}),s.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[x.details.unmergedFiles.slice(0,6).map(O=>s.jsx("span",{className:"font-mono text-xs px-2 py-0.5 rounded bg-muted/40 text-muted-foreground",children:O},O)),x.details.unmergedFiles.length>6&&s.jsx("span",{className:"text-xs text-muted-foreground",children:c("gitView.integrate.moreFiles",{count:x.details.unmergedFiles.length-6})})]}),s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsx(we,{size:"sm",variant:"ghost",className:"typography-meta",onClick:()=>{M()},children:c("gitView.operation.abort")}),s.jsxs(we,{size:"sm",variant:"secondary",className:"typography-meta gap-1",disabled:!d,onClick:()=>{N({state:x.state,details:x.details},!1)},children:[s.jsx(I,{name:"sparkling",className:"size-3.5"}),c("gitView.integrate.currentSession")]}),s.jsxs(we,{size:"sm",variant:"secondary",className:"typography-meta gap-1",onClick:()=>{N({state:x.state,details:x.details},!0)},children:[s.jsx(I,{name:"sparkling",className:"size-3.5"}),c("gitView.integrate.newSession")]}),s.jsx(we,{size:"sm",className:"typography-meta",onClick:()=>{R()},children:c("gitView.operation.continue")})]})]})]})]})},Rw=t=>t.trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._/-]/g,"-").replace(/-+/g,"-").replace(/\/{2,}/g,"/").replace(/\/-+/g,"/").replace(/-+\//g,"/").replace(/^[-/]+/,"").replace(/[-/]+$/,""),Fw=({currentBranch:t,localBranches:e,remoteBranches:n,branchInfo:r,onCheckout:a,onCreate:i,remotes:o=[],disabled:c=!1})=>{const{t:d}=pt(),[p,m]=l.useState(!1),[u,h]=l.useState(""),[b,f]=l.useState(!1),[v,x]=l.useState(!1),[g,w]=l.useState(""),[y,k]=l.useState(!1),D=l.useRef(null),j=l.useCallback($=>{$.stopPropagation()},[]),S=o.length>1,A=l.useMemo(()=>Rw(g),[g]),E=l.useMemo(()=>{const $=u.toLowerCase();return $?e.filter(B=>B.toLowerCase().includes($)):e},[u,e]),P=l.useMemo(()=>{const $=u.toLowerCase();return $?n.filter(B=>B.toLowerCase().includes($)):n},[u,n]),C=$=>{if($===t){m(!1);return}a($),m(!1),h("")},N=()=>{f(!0),setTimeout(()=>D.current?.focus(),50)},T=async()=>{if(!(!A||y)){if(S){x(!0);return}k(!0);try{await i(A,o[0]),w(""),f(!1),m(!1)}finally{k(!1)}}},M=async $=>{if(!(!A||y)){k(!0);try{await i(A,$),w(""),f(!1),x(!1),m(!1)}finally{k(!1)}}},R=()=>{x(!1)},L=()=>{w(""),f(!1),x(!1)};return l.useEffect(()=>{p||(h(""),f(!1),x(!1),w(""))},[p]),s.jsxs(Bs,{open:p,onOpenChange:m,children:[s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(Os,{asChild:!0,children:s.jsxs(we,{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(I,{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(I,{name:"arrow-down-s",className:"size-4 opacity-60"})]})})}),s.jsx(Pt,{sideOffset:8,children:d("gitView.branch.currentBranchTooltip")})]}),s.jsx($s,{align:"start",className:"w-72 p-0 max-h-[60vh] flex flex-col",children:s.jsxs(Ta,{className:"h-full min-h-0",children:[s.jsx(ra,{placeholder:d("gitView.branch.searchPlaceholder"),value:u,onValueChange:h}),s.jsxs(Ma,{scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[s.jsx(Ea,{children:d("gitView.branch.empty")}),s.jsx(Bn,{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(I,{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:A})," ",d("gitView.branch.pushToSuffix")]})]}),s.jsx("div",{className:"flex flex-col gap-1",children:o.map($=>s.jsxs("button",{type:"button",onClick:()=>M($),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(I,{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:D,placeholder:d("gitView.branch.newBranchPlaceholder"),value:g,onChange:$=>w($.target.value),onClick:$=>$.stopPropagation(),onKeyDown:$=>{j($),$.key==="Enter"?($.preventDefault(),T()):$.key==="Escape"&&($.preventDefault(),L())},className:"flex-1 min-w-0 bg-transparent typography-meta outline-none placeholder:text-muted-foreground"}),s.jsx("button",{type:"button",onClick:T,disabled:!A||y,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:y?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"add",className:"size-4"})}),s.jsx("button",{type:"button",onClick:L,disabled:y,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:s.jsx(I,{name:"close",className:"size-4"})})]}):s.jsxs(An,{onSelect:N,children:[s.jsx(I,{name:"add",className:"size-4"}),s.jsx("span",{children:d("gitView.branch.create")})]})}),s.jsx(va,{}),s.jsxs(Bn,{heading:d("gitView.branch.localBranches"),children:[E.map($=>s.jsxs(An,{onSelect:()=>C($),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-${$}`)),E.length===0&&s.jsx(An,{disabled:!0,className:"justify-center",children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:d("gitView.branch.noLocalBranches")})})]}),s.jsx(va,{}),s.jsxs(Bn,{heading:d("gitView.branch.remoteBranches"),children:[P.map($=>s.jsx(An,{onSelect:()=>C($),children:s.jsx("span",{className:"typography-ui-label text-foreground",children:$})},`remote-${$}`)),P.length===0&&s.jsx(An,{disabled:!0,className:"justify-center",children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:d("gitView.branch.noRemoteBranches")})})]})]})]})})]})},Lw=t=>t.trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._/-]/g,"-").replace(/-+/g,"-").replace(/\/{2,}/g,"/").replace(/\/-+/g,"/").replace(/-+\//g,"/").replace(/^[-/]+/,"").replace(/[-/]+$/,""),Ow=({currentBranch:t,onRename:e,showEditButton:n=!0})=>{const{t:r}=pt(),[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))},h=async()=>{if(!t||!e||!o.trim())return;const v=Lw(o);if(v===t){i(!1);return}p(!0);try{await e(t,v),i(!1),c("")}finally{p(!1)}},b=()=>{i(!1),c("")},f=v=>{v.key==="Enter"?(v.preventDefault(),h()):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(),h()},children:[s.jsx(I,{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:f,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(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{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(I,{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(I,{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(we,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 shrink-0",onClick:u,title:r("gitView.branch.renameTitle"),children:s.jsx(I,{name:"edit",className:"size-4"})})]})]})},$w=t=>{const e=at.c(41),{syncAction:n,remotes:r,onFetch:a,onSync:i,onRemoveRemote:o,disabled:c,removingRemoteName:d,aheadCount:p,behindCount:m,trackingRemoteName:u,hasUncommittedChanges:h}=t,b=r===void 0?[]:r,f=d===void 0?null:d,v=p===void 0?0:p,x=m===void 0?0:m,g=h===void 0?!1:h,{t:w}=pt(),y=l.useRef(!1),k=!!f,D=b.find(K=>K.name===u)??b[0],j=x>0&&g,S=c||n!==null||k||!D||j,A=c||n!==null||k||b.length===0,E=v>0||x>0;let P;e[0]!==w?(P=w("gitView.sync.sync"),e[0]=w,e[1]=P):P=e[1];const C=x>0?`↓${x}`:null,N=v>0?`↑${v}`:null;let T;e[2]!==P||e[3]!==C||e[4]!==N?(T=[P,C,N].filter(Boolean),e[2]=P,e[3]=C,e[4]=N,e[5]=T):T=e[5];const M=T.join(" "),R=j?w("gitView.sync.commitOrStashTooltip"):D?E?w("gitView.sync.syncChangesTooltip",{ahead:v,behind:x}):w("gitView.sync.syncChanges"):w("gitView.sync.noRemoteTooltip"),L=()=>{D&&i(D)},$="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 B;e[6]===Symbol.for("react.memo_cache_sentinel")?(B=me("inline-flex h-7 items-center gap-1.5 px-2 typography-ui-label font-medium text-foreground","transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50"),e[6]=B):B=e[6];let O;e[7]!==w?(O=w("gitView.sync.syncChanges"),e[7]=w,e[8]=O):O=e[8];let _;e[9]!==n?(_=n==="sync"?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"refresh",className:"size-4"}),e[9]=n,e[10]=_):_=e[10];let ee;e[11]!==M?(ee=s.jsx("span",{className:"whitespace-nowrap tabular-nums",children:M}),e[11]=M,e[12]=ee):ee=e[12];let z;e[13]!==L||e[14]!==S||e[15]!==O||e[16]!==_||e[17]!==ee?(z=s.jsx(Ct,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:L,disabled:S,className:B,"aria-label":O,children:[_,ee]})}),e[13]=L,e[14]=S,e[15]=O,e[16]=_,e[17]=ee,e[18]=z):z=e[18];let ne;e[19]!==R?(ne=s.jsx(Pt,{sideOffset:8,children:R}),e[19]=R,e[20]=ne):ne=e[20];let re;e[21]!==z||e[22]!==ne?(re=s.jsxs(kt,{children:[z,ne]}),e[21]=z,e[22]=ne,e[23]=re):re=e[23];const ue=Bs;let Q;e[24]===Symbol.for("react.memo_cache_sentinel")?(Q=me("inline-flex h-7 w-6 items-center justify-center border-l border-[var(--interactive-border)] text-muted-foreground","transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50"),e[24]=Q):Q=e[24];let de;e[25]!==w?(de=w("gitView.sync.moreActionsAria"),e[25]=w,e[26]=de):de=e[26];let X;e[27]===Symbol.for("react.memo_cache_sentinel")?(X=s.jsx(I,{name:"arrow-down-s",className:"size-4"}),e[27]=X):X=e[27];let F;e[28]!==A||e[29]!==de?(F=s.jsx(Os,{asChild:!0,children:s.jsx("button",{type:"button",className:Q,disabled:A,"aria-label":de,children:X})}),e[28]=A,e[29]=de,e[30]=F):F=e[30];const V=$s,q="start",te=-40,U="w-[min(360px,calc(100vw-2rem))] max-h-[320px] overflow-y-auto",ae=b.map(K=>s.jsx(zt,{onSelect:ce=>{if(y.current){ce.preventDefault(),y.current=!1;return}a(K)},children:s.jsxs("div",{className:"flex w-full items-center gap-2",children:[s.jsx(I,{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:K.name})}),s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:K.fetchUrl})]})}),o&&K.name!==u?s.jsx(we,{type:"button",variant:"destructive",size:"xs",className:"h-6 w-6 px-0",disabled:n!==null||k,onPointerDown:ce=>{y.current=!0,ce.preventDefault(),ce.stopPropagation()},onClick:ce=>{y.current=!0,ce.preventDefault(),ce.stopPropagation(),o(K)},"aria-label":w("gitView.header.removeRemoteAria",{name:K.name}),title:w("gitView.header.removeRemoteTitle",{name:K.name}),children:f===K.name?s.jsx(I,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(I,{name:"close",className:"size-3.5"})}):null]})},K.name));let je;e[31]!==V||e[32]!==ae?(je=s.jsx(V,{align:q,alignOffset:te,className:U,children:ae}),e[31]=V,e[32]=ae,e[33]=je):je=e[33];let oe;e[34]!==ue||e[35]!==F||e[36]!==je?(oe=s.jsxs(ue,{children:[F,je]}),e[34]=ue,e[35]=F,e[36]=je,e[37]=oe):oe=e[37];let ve;return e[38]!==re||e[39]!==oe?(ve=s.jsxs("div",{className:$,children:[re,oe]}),e[38]=re,e[39]=oe,e[40]=ve):ve=e[40],ve},Bw={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart",user:"user-3"},_w={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 Nf(t){return t&&_w[t]||"var(--primary)"}const om=t=>{const e=at.c(8),{icon:n,className:r,colorToken:a}=t,i=Bw[n??"branch"]??"user-3";let o;e[0]!==a?(o=Nf(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(I,{name:i,className:r,style:c}),e[4]=r,e[5]=i,e[6]=c,e[7]=d):d=e[7],d},Sf=t=>{const e=at.c(35),{activeProfile:n,identities:r,onSelect:a,isApplying:i,iconOnly:o}=t,c=o===void 0?!1:o,{t:d}=pt(),p=i||r.length===0,m=n?.color;let u;e[0]!==m?(u=Nf(m),e[0]=m,e[1]=u):u=e[1];let h;e[2]!==u?(h={color:u},e[2]=u,e[3]=h):h=e[3];let b;e[4]!==n?.color||e[5]!==n?.icon||e[6]!==i?(b=i?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(om,{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 f;e[8]!==n?.name||e[9]!==c||e[10]!==d?(f=!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]=f):f=e[11];let v;e[12]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx(I,{name:"arrow-down-s",className:"size-4 opacity-60"}),e[12]=v):v=e[12];let x;e[13]!==p||e[14]!==h||e[15]!==b||e[16]!==f?(x=s.jsx(Ct,{asChild:!0,children:s.jsx(Os,{asChild:!0,children:s.jsxs(we,{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:h,disabled:p,children:[b,f,v]})})}),e[13]=p,e[14]=h,e[15]=b,e[16]=f,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(Pt,{sideOffset:8,children:g}),e[20]=g,e[21]=w):w=e[21];let y;e[22]!==w||e[23]!==x?(y=s.jsxs(kt,{children:[x,w]}),e[22]=w,e[23]=x,e[24]=y):y=e[24];let k;e[25]!==n?.id||e[26]!==r||e[27]!==a||e[28]!==d?(k=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 A=n?.id===S.id;return s.jsx(zt,{onSelect:()=>a(S),children:s.jsxs("span",{className:"flex items-center gap-2",children:[s.jsx(om,{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})]}),A?s.jsx(I,{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]=k):k=e[29];let D;e[30]!==k?(D=s.jsx($s,{align:"end",className:"w-64",children:k}),e[30]=k,e[31]=D):D=e[31];let j;return e[32]!==y||e[33]!==D?(j=s.jsxs(Bs,{children:[y,D]}),e[32]=y,e[33]=D,e[34]=j):j=e[34],j},Vw=t=>{const e=at.c(48),{status:n,localBranches:r,remoteBranches:a,branchInfo:i,syncAction:o,remotes:c,onFetch:d,onSync:p,onRemoveRemote:m,removingRemoteName:u,onCheckoutBranch:h,onCreateBranch:b,onRenameBranch:f,activeIdentityProfile:v,availableIdentities:x,onSelectIdentity:g,isApplyingIdentity:w,isWorktreeMode:y,onOpenHistory:k,actionTabItems:D,activeActionTab:j,onSelectActionTab:S}=t,{t:A}=pt();if(!n)return null;let E;e[0]!==k||e[1]!==A?(E=k?s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(we,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0",onClick:k,children:s.jsx(I,{name:"history",className:"size-4"})})}),s.jsx(Pt,{sideOffset:8,children:A("gitView.history.title")})]}):null,e[0]=k,e[1]=A,e[2]=E):E=e[2];let P;e[3]!==E?(P=s.jsx("div",{className:"flex items-center gap-1 shrink-0",children:E}),e[3]=E,e[4]=P):P=e[4];const C=P,N=!n;let T;e[5]!==n.tracking?(T=n.tracking?.split("/")[0],e[5]=n.tracking,e[6]=T):T=e[6];const M=(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]!==T||e[17]!==M?(R=s.jsx($w,{syncAction:o,remotes:c,onFetch:d,onSync:p,onRemoveRemote:m,removingRemoteName:u,disabled:N,iconOnly:!0,aheadCount:n.ahead,behindCount:n.behind,trackingRemoteName:T,hasUncommittedChanges:M}),e[7]=d,e[8]=m,e[9]=p,e[10]=c,e[11]=u,e[12]=n.ahead,e[13]=n.behind,e[14]=o,e[15]=N,e[16]=T,e[17]=M,e[18]=R):R=e[18];const L=R;let $;e[19]!==v||e[20]!==x||e[21]!==w||e[22]!==g?($=s.jsx(Sf,{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 B=$;let O;e[24]!==i||e[25]!==y||e[26]!==r||e[27]!==h||e[28]!==b||e[29]!==f||e[30]!==a||e[31]!==c||e[32]!==n.current?(O=s.jsx("div",{className:"min-w-0 flex-1",children:y?s.jsx(Ow,{currentBranch:n.current,onRename:f}):s.jsx(Fw,{currentBranch:n.current,localBranches:r,remoteBranches:a,branchInfo:i,onCheckout:h,onCreate:b,remotes:c})}),e[24]=i,e[25]=y,e[26]=r,e[27]=h,e[28]=b,e[29]=f,e[30]=a,e[31]=c,e[32]=n.current,e[33]=O):O=e[33];let _;e[34]!==B||e[35]!==C?(_=s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[C,B]}),e[34]=B,e[35]=C,e[36]=_):_=e[36];let ee;e[37]!==O||e[38]!==_?(ee=s.jsxs("div",{className:"flex items-center justify-between gap-2 min-w-0",children:[O,_]}),e[37]=O,e[38]=_,e[39]=ee):ee=e[39];let z;e[40]!==D||e[41]!==j||e[42]!==S||e[43]!==L?(z=D&&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(Ar,{items:D,activeId:j,onSelect:S,layoutMode:"fit",variant:"active-pill",iconOnlyActiveTab:!0,activePillButtonClassName:"h-7",className:"h-full"})}),s.jsx("div",{className:"shrink-0",children:L})]}):null,e[40]=D,e[41]=j,e[42]=S,e[43]=L,e[44]=z):z=e[44];let ne;return e[45]!==ee||e[46]!==z?(ne=s.jsxs("header",{className:"@container/git-header px-3 py-2 bg-transparent",children:[ee,z]}),e[45]=ee,e[46]=z,e[47]=ne):ne=e[47],ne},zw=({open:t,onOpenChange:e,directory:n,hasUncommittedChanges:r,uncommittedFileCount:a,onChanged:i})=>{const{t:o}=pt(),[c,d]=l.useState([]),[p,m]=l.useState(!1),[u,h]=l.useState(""),[b,f]=l.useState(""),[v,x]=l.useState(null),[g,w]=l.useState({}),y=l.useCallback(async()=>{if(n){m(!0);try{const E=await Zx(n);d(E.stashes),w({})}catch(E){H.error(E instanceof Error?E.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 E=!1;const P=c.map(C=>C.ref);return eb(n,P).then(C=>{E||w(C.counts)}).catch(()=>{}),()=>{E=!0}},[n,t,c]);const k=l.useMemo(()=>{const E=u.trim().toLowerCase();return E?c.filter(P=>`${P.ref} ${P.message} ${P.relativeTime}`.toLowerCase().includes(E)):c},[u,c]),D=l.useCallback(async()=>{await y(),await i?.()},[y,i]),j=async()=>{if(!(!n||v)){x("create");try{(await tb(n,{message:b.trim()||void 0})).created?(H.success(o("gitView.stashes.toast.created")),f("")):H.info(o("gitView.stashes.toast.noChanges")),await D()}catch(E){H.error(E instanceof Error?E.message:o("gitView.stashes.toast.createFailed"))}finally{x(null)}}},S=async(E,P)=>{if(!(!n||v)&&!(P==="drop"&&!window.confirm(o("gitView.stashes.confirm.drop",{ref:E.ref})))){x(`${P}:${E.ref}`);try{P==="apply"&&await sb(n,{ref:E.ref}),P==="pop"&&await nb(n,{ref:E.ref}),P==="drop"&&await rb(n,{ref:E.ref});const C=P==="apply"?"gitView.stashes.toast.applySuccess":P==="pop"?"gitView.stashes.toast.popSuccess":"gitView.stashes.toast.dropSuccess";H.success(o(C)),await D()}catch(C){const N=P==="apply"?"gitView.stashes.toast.applyFailed":P==="pop"?"gitView.stashes.toast.popFailed":"gitView.stashes.toast.dropFailed";H.error(C instanceof Error?C.message:o(N)),await D()}finally{x(null)}}},A=v!==null;return s.jsx(ws,{open:t,onOpenChange:e,children:s.jsxs(vs,{className:"max-w-2xl max-h-[70vh] flex flex-col",children:[s.jsxs(Cs,{children:[s.jsxs(js,{className:"flex items-center gap-2",children:[s.jsx(I,{name:"archive-stack",className:"h-5 w-5"}),o("gitView.stashes.title")]}),s.jsx(Rs,{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(Kt,{value:b,onChange:E=>f(E.target.value),placeholder:o("gitView.stashes.messagePlaceholder"),disabled:A||!r,className:"flex-1"}),s.jsxs(we,{onClick:j,disabled:!r||A||!n,children:[v==="create"?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{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(I,{name:"search",className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),s.jsx(Kt,{value:u,onChange:E=>h(E.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(I,{name:"loader-4",className:"size-5 animate-spin"})}):k.length===0?s.jsx("div",{className:"py-8 text-center text-muted-foreground",children:o(u?"gitView.stashes.empty.search":"gitView.stashes.empty.list")}):k.map((E,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:E.message||o("gitView.stashes.untitled")}),s.jsxs("p",{className:"typography-meta truncate text-muted-foreground",children:[s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("span",{children:P===0&&!u.trim()?o("gitView.stashes.latestLabel"):o("gitView.stashes.itemNumber",{number:P+1})})}),s.jsx(Pt,{sideOffset:6,children:E.ref})]})," · ",E.relativeTime," · ",typeof g[E.ref]=="number"?o("gitView.stashes.fileCount",{count:g[E.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(cc,{label:o("gitView.stashes.actions.apply"),loading:v===`apply:${E.ref}`,onClick:()=>S(E,"apply"),disabled:A,children:s.jsx(I,{name:"inbox-unarchive",className:"size-4"})}),s.jsx(cc,{label:o("gitView.stashes.actions.pop"),loading:v===`pop:${E.ref}`,onClick:()=>S(E,"pop"),disabled:A,children:s.jsx(I,{name:"inbox-unarchive-fill",className:"size-4"})}),s.jsx(cc,{label:o("gitView.stashes.actions.drop"),loading:v===`drop:${E.ref}`,onClick:()=>S(E,"drop"),disabled:A,destructive:!0,children:s.jsx(I,{name:"delete-bin",className:"size-4"})})]})]},E.ref))})]})})},cc=t=>{const e=at.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=me("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(I,{name:"loader-4",className:"size-4 animate-spin"}):c,e[2]=c,e[3]=r,e[4]=u):u=e[4];let h;e[5]!==a||e[6]!==n||e[7]!==o||e[8]!==d||e[9]!==m||e[10]!==u?(h=s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":n,"aria-busy":d,className:m,onClick:o,disabled:a,children:u})}),e[5]=a,e[6]=n,e[7]=o,e[8]=d,e[9]=m,e[10]=u,e[11]=h):h=e[11];let b;e[12]!==n?(b=s.jsx(Pt,{sideOffset:6,children:n}),e[12]=n,e[13]=b):b=e[13];let f;return e[14]!==h||e[15]!==b?(f=s.jsxs(kt,{children:[h,b]}),e[14]=h,e[15]=b,e[16]=f):f=e[16],f},kf={"?":{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"}},Uw=kf.M;function Ww(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 Kw(t){const e=Ww(t);return kf[e]??Uw}const lm=l.memo(function(e){const n=at.c(71),{file:r,checked:a,onToggle:i,onViewDiff:o,onRevert:c,isReverting:d,stats:p,rowPaddingClassName:m,indentPx:u}=e,h=u===void 0?0:u;let b;n[0]!==r?(b=Kw(r),n[0]=r,n[1]=b):b=n[1];const f=b,{t:v}=pt(),x=f.description,g=p?.insertions??0,w=p?.deletions??0;let y;n[2]!==i||n[3]!==o?(y=F=>{F.key===" "?(F.preventDefault(),i()):F.key==="Enter"&&(F.preventDefault(),o())},n[2]=i,n[3]=o,n[4]=y):y=n[4];const k=y;let D;n[5]!==c?(D=F=>{F.preventDefault(),F.stopPropagation(),c()},n[5]=c,n[6]=D):D=n[6];const j=D,S=`group flex items-center gap-2 py-1.5 hover:bg-sidebar/40 cursor-pointer ${m??"px-3"}`;let A;n[7]!==h?(A=h>0?{paddingLeft:`${h}px`}:void 0,n[7]=h,n[8]=A):A=n[8];let E;n[9]!==i?(E=()=>i(),n[9]=i,n[10]=E):E=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 C;n[14]!==a||n[15]!==E||n[16]!==P?(C=s.jsx("div",{className:"flex size-5 shrink-0 items-center justify-center",onClick:Hw,children:s.jsx(xs,{size:"sm",checked:a,onChange:E,ariaLabel:P})}),n[14]=a,n[15]=E,n[16]=P,n[17]=C):C=n[17];let N;n[18]!==f.color?(N={color:f.color},n[18]=f.color,n[19]=N):N=n[19];let T;n[20]!==f.code||n[21]!==x||n[22]!==N?(T=s.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:N,title:x,"aria-label":x,children:f.code}),n[20]=f.code,n[21]=x,n[22]=N,n[23]=T):T=n[23];let M;n[24]!==r.path?(M=s.jsx(br,{filePath:r.path,className:"h-3.5 w-3.5 shrink-0"}),n[24]=r.path,n[25]=M):M=n[25];let R;if(n[26]!==r.path){e:{const F=r.path.lastIndexOf("/");if(F===-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 V=r.path.slice(0,F),q=r.path.slice(F);let te;n[29]===Symbol.for("react.memo_cache_sentinel")?(te={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},n[29]=te):te=n[29];let U;n[30]===Symbol.for("react.memo_cache_sentinel")?(U=s.jsx("span",{className:"text-muted-foreground",children:"/"}),n[30]=U):U=n[30];const ae=s.jsx("span",{className:"text-foreground",children:q.slice(1)});let je;n[31]!==ae?(je=s.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[U,ae]}),n[31]=ae,n[32]=je):je=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:te,children:V}),je]})}n[26]=r.path,n[27]=R}else R=n[27];let L;n[33]===Symbol.for("react.memo_cache_sentinel")?(L={color:"var(--status-success)"},n[33]=L):L=n[33];let $;n[34]!==g?($=s.jsxs("span",{style:L,children:["+",g]}),n[34]=g,n[35]=$):$=n[35];let B,O;n[36]===Symbol.for("react.memo_cache_sentinel")?(B=s.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),O={color:"var(--status-error)"},n[36]=B,n[37]=O):(B=n[36],O=n[37]);let _;n[38]!==w?(_=s.jsxs("span",{style:O,children:["-",w]}),n[38]=w,n[39]=_):_=n[39];let ee;n[40]!==$||n[41]!==_?(ee=s.jsxs("span",{className:"shrink-0 typography-micro",children:[$,B,_]}),n[40]=$,n[41]=_,n[42]=ee):ee=n[42];let z;n[43]!==r.path||n[44]!==v?(z=v("gitView.changes.revertFileAria",{path:r.path}),n[43]=r.path,n[44]=v,n[45]=z):z=n[45];let ne;n[46]!==d?(ne=d?s.jsx(I,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(I,{name:"arrow-go-back",className:"size-3.5"}),n[46]=d,n[47]=ne):ne=n[47];let re;n[48]!==j||n[49]!==d||n[50]!==z||n[51]!==ne?(re=s.jsx(Ct,{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":z,children:ne})}),n[48]=j,n[49]=d,n[50]=z,n[51]=ne,n[52]=re):re=n[52];let ue;n[53]!==v?(ue=v("gitView.changes.revertFileTooltip"),n[53]=v,n[54]=ue):ue=n[54];let Q;n[55]!==ue?(Q=s.jsx(Pt,{sideOffset:8,children:ue}),n[55]=ue,n[56]=Q):Q=n[56];let de;n[57]!==re||n[58]!==Q?(de=s.jsxs(kt,{children:[re,Q]}),n[57]=re,n[58]=Q,n[59]=de):de=n[59];let X;return n[60]!==k||n[61]!==o||n[62]!==T||n[63]!==M||n[64]!==R||n[65]!==ee||n[66]!==de||n[67]!==S||n[68]!==A||n[69]!==C?(X=s.jsxs("div",{className:S,role:"button",tabIndex:0,onClick:o,onKeyDown:k,style:A,children:[C,T,M,R,ee,de]}),n[60]=k,n[61]=o,n[62]=T,n[63]=M,n[64]=R,n[65]=ee,n[66]=de,n[67]=S,n[68]=A,n[69]=C,n[70]=X):X=n[70],X});function Hw(t){t.stopPropagation()}const Gw=1e3,qw=34,cm=14,Cf=t=>t.replace(/\\/g,"/").replace(/^\/+/,"").trim(),dm=(t,e)=>({id:`dir:${t}`,path:t,name:e,children:new Map,directFiles:[],files:[]}),Jw=t=>{const e=dm("","");for(const n of t){const r=Cf(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=dm(c,d);m.files.push(n),o.children.set(d,m),o=m}}o.directFiles.push(n)}return e},Qw=(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:${Cf(d.path)}`,kind:"file",depth:i,file:d})};return r(t,0),n},um=(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"},Yw=({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:h,onOpenStashes:b})=>{const{t:f}=pt(),v=l.useRef(null),g=Te(X=>X.gitChangesViewMode)==="tree",w=e.size,y=t.length,[k,D]=l.useState(!1),j=l.useMemo(()=>Jw(t),[t]),[S,A]=l.useState(new Set),E=l.useMemo(()=>Array.from(j.children.values()).map(X=>X.path),[j]);l.useEffect(()=>{g&&A(X=>{const F=new Set,V=new Set(E);return X.forEach(q=>{if(q.includes("/")){F.add(q);return}V.has(q)&&F.add(q)}),E.forEach(q=>F.add(q)),F})},[g,E]);const P=l.useMemo(()=>Qw(j,S),[S,j]),C=l.useMemo(()=>g?P:t,[t,g,P]),N=C.length,T=N>=Gw,M=w>0,R=y>0&&w===y,L=M&&!R,$=Vg({count:N,getScrollElement:()=>v.current,estimateSize:()=>qw,overscan:10,enabled:T});l.useEffect(()=>{if(!T)return;const X=v.current;if(!X)return;const F=new ResizeObserver(()=>{$.measure()});return F.observe(X),()=>F.disconnect()},[T,$]);const B=$.getTotalSize(),O=l.useMemo(()=>T&&B>=0?$.getVirtualItems():[],[T,$,B]);l.useEffect(()=>{if(!h)return;if(N===0){h([]);return}const X=F=>{if(!g)return F.path;const V=F;return V.kind==="file"?V.file.path:null};if(!T){h(C.slice(0,Math.min(30,N)).map(F=>X(F)).filter(F=>!!F));return}h(O.map(F=>C[F.index]).map(F=>F?X(F):null).filter(F=>!!F))},[g,h,N,C,T,O]);const _="flex flex-col flex-1 min-h-0",ee="flex items-center justify-between gap-2 px-0 py-3 border-b border-border/40",z=`flex-1 min-h-0 pr-0 ${u??""}`.trim(),ne="pl-0 pr-2",re=l.useCallback(X=>{A(F=>{const V=new Set(F);return V.has(X)?V.delete(X):V.add(X),V})},[]),ue=l.useCallback(X=>{const V=um(X,e)!=="all";for(const q of X.files){const te=e.has(q.path);(V&&!te||!V&&te)&&a(q.path)}},[a,e]),Q=l.useCallback(X=>{if(!g){const U=X;return s.jsx(lm,{file:U,checked:e.has(U.path),stats:n?.[U.path],onToggle:()=>a(U.path),onViewDiff:()=>d(U.path),onRevert:()=>p(U.path),isReverting:r.has(U.path)||m,rowPaddingClassName:ne})}const F=X;if(F.kind==="file"){const U=F.file;return s.jsx(lm,{file:U,checked:e.has(U.path),stats:n?.[U.path],onToggle:()=>a(U.path),onViewDiff:()=>d(U.path),onRevert:()=>p(U.path),isReverting:r.has(U.path)||m,rowPaddingClassName:ne,indentPx:F.depth*cm})}const V=F.directory,q=S.has(V.path),te=um(V,e);return s.jsxs("div",{className:me("group flex items-center gap-2 py-1.5 hover:bg-sidebar/40",ne),style:{paddingLeft:`${F.depth*cm}px`},children:[s.jsx("div",{className:"flex size-5 shrink-0 items-center justify-center",children:s.jsx(xs,{size:"sm",checked:te==="all",indeterminate:te==="partial",onChange:()=>ue(V),ariaLabel:f("gitView.changes.toggleDirectorySelectionAria",{path:V.path})})}),s.jsxs("button",{type:"button",onClick:()=>re(V.path),className:"flex min-w-0 flex-1 items-center gap-2 rounded text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":q?f("gitView.changes.collapseDirectoryAria",{path:V.path}):f("gitView.changes.expandDirectoryAria",{path:V.path}),children:[q?s.jsx(I,{name:"folder-open-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):s.jsx(I,{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:V.path,children:V.name}),s.jsx("span",{className:"ml-auto shrink-0 typography-micro text-muted-foreground",children:V.files.length})]})]})},[n,S,m,g,p,a,d,r,ne,e,f,re,ue]),de=l.useCallback(async()=>{!c||m||t.length===0||(await c(t.map(X=>X.path)),D(!1))},[t,m,c]);return s.jsxs(s.Fragment,{children:[s.jsxs("section",{className:_,children:[s.jsxs("header",{className:ee,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:f("gitView.changes.title")}),y>0?s.jsxs("div",{className:me("inline-flex h-6 items-center gap-1 rounded px-1.5",m&&"cursor-not-allowed opacity-50"),children:[s.jsx(xs,{size:"sm",checked:M,indeterminate:L,disabled:m,onChange:()=>R?o():i(),ariaLabel:f(R?"gitView.changes.clearSelectionAria":"gitView.changes.selectAllAria")}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[w,"/",y]})]}):null,b?s.jsx(we,{type:"button",variant:"ghost",size:"xs",className:"h-6 px-1.5",onClick:b,"aria-label":f("gitView.stashes.title"),title:f("gitView.stashes.title"),children:s.jsx(I,{name:"archive-stack",className:"size-4"})}):null]}),s.jsx("div",{className:"flex items-center gap-2 pr-1",children:y>0&&c?s.jsx(we,{variant:"destructive",size:"xs",onClick:()=>D(!0),disabled:m,children:f("gitView.changes.revertAll")}):null})]}),s.jsxs("div",{className:me("relative flex flex-col min-h-0 w-full overflow-hidden",z),children:[s.jsx(eo,{ref:v,className:"overlay-scrollbar-target overlay-scrollbar-container flex-1 min-h-0 w-full overflow-y-auto overflow-x-hidden",children:T?s.jsx("div",{className:"relative w-full",style:{height:`${$.getTotalSize()}px`},children:O.map(X=>{const F=C[X.index];if(!F)return null;const V=g?F.key:`file:${F.path}`;return s.jsx("div",{ref:$.measureElement,"data-index":X.index,className:me("absolute left-0 top-0 w-full",X.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(${X.start}px)`},children:Q(F)},V)})}):s.jsx("div",{role:"list","aria-label":f("gitView.changes.changedFilesAria"),children:C.map((X,F)=>s.jsx("div",{className:me("relative",F>0&&"before:pointer-events-none before:absolute before:left-0 before:right-2 before:top-0 before:border-t before:border-border/60"),children:Q(X)},g?X.key:`file:${X.path}`))})}),s.jsx(ab,{containerRef:v,disableHorizontal:!0})]})]}),s.jsx(ws,{open:k,onOpenChange:X=>{m||D(X)},children:s.jsxs(vs,{className:"max-w-md",children:[s.jsxs(Cs,{children:[s.jsx(js,{children:f("gitView.changes.revertAllDialogTitle")}),s.jsx(Rs,{children:y===1?f("gitView.changes.revertAllDescriptionSingle",{count:y}):f("gitView.changes.revertAllDescriptionPlural",{count:y})})]}),s.jsxs(Ks,{children:[s.jsx(we,{variant:"outline",size:"sm",onClick:()=>D(!1),disabled:m,children:f("gitView.common.cancel")}),s.jsx(we,{variant:"destructive",size:"sm",onClick:()=>{de()},disabled:m,children:f(m?"gitView.changes.reverting":"gitView.changes.revertAll")})]})]})})]})},dc=38,vo=200,Xw=t=>{const e=at.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}=pt(),h=l.useRef(null),b=Te(Zw);let f;e[0]===Symbol.for("react.memo_cache_sentinel")?(f=()=>{const E=h.current;if(!E)return;const P=document.activeElement===E,C=()=>{E.style.height=`${dc}px`;const T=E.scrollHeight,M=Math.min(Math.max(T,dc),vo);E.style.height=`${M}px`,E.style.overflowY=T>vo?"auto":"hidden",T>vo&&!P&&(E.scrollTop=E.scrollHeight)};C();const N=window.requestAnimationFrame(C);return()=>{window.cancelAnimationFrame(N)}},e[0]=f):f=e[0];let v;e[1]!==n?(v=[n],e[1]=n,e[2]=v):v=e[2],l.useLayoutEffect(f,v);let x;e[3]!==r?(x=E=>r(E.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",k=m||b,D=d&&"opacity-50";let j;e[8]!==D?(j=me("w-full rounded-lg border border-border/60 bg-surface-elevated px-3 py-2 typography-ui-label text-foreground placeholder:text-muted-foreground","resize-none outline-none transition-[border-color,box-shadow] duration-150","focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",D),e[8]=D,e[9]=j):j=e[9];let S;e[10]===Symbol.for("react.memo_cache_sentinel")?(S={minHeight:dc,maxHeight:vo},e[10]=S):S=e[10];let A;return e[11]!==d||e[12]!==k||e[13]!==j||e[14]!==x||e[15]!==g||e[16]!==w||e[17]!==y||e[18]!==n?(A=s.jsx("textarea",{ref:h,value:n,onChange:x,placeholder:g,rows:1,disabled:d,autoCorrect:w,autoCapitalize:y,spellCheck:k,className:j,style:S}),e[11]=d,e[12]=k,e[13]=j,e[14]=x,e[15]=g,e[16]=w,e[17]=y,e[18]=n,e[19]=A):A=e[19],A};function Zw(t){return t.inputSpellcheckEnabled}const ej=t=>{const e=at.c(30),{highlights:n,onInsert:r}=t,{t:a}=pt();if(n.length===0)return null;let i;e[0]!==n||e[1]!==r?(i=()=>{r(n)},e[0]=n,e[1]=r,e[2]=i):i=e[2];const 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(I,{name:"arrow-down",className:"size-4"}),e[9]=m):m=e[9];let u;e[10]!==o||e[11]!==p?(u=s.jsx(Ct,{asChild:!0,children:s.jsx(we,{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 h;e[13]!==a?(h=a("gitView.commit.aiHighlights.insertTooltip"),e[13]=a,e[14]=h):h=e[14];let b;e[15]!==h?(b=s.jsx(Pt,{sideOffset:8,children:h}),e[15]=h,e[16]=b):b=e[16];let f;e[17]!==u||e[18]!==b?(f=s.jsxs(kt,{children:[u,b]}),e[17]=u,e[18]=b,e[19]=f):f=e[19];let v;e[20]!==d||e[21]!==f?(v=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[d,f]}),e[20]=d,e[21]=f,e[22]=v):v=e[22];let x;e[23]!==n?(x=n.map(tj),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 tj(t,e){return s.jsx("li",{className:"typography-meta text-foreground",children:t},`${t}-${e}`)}const sj=t=>{const e=at.c(72),{selectedCount:n,commitMessage:r,onCommitMessageChange:a,generatedHighlights:i,onInsertHighlights:o,onGenerateMessage:c,isGeneratingMessage:d,onCommit:p,onCommitAndPush:m,commitAction:u,gitmojiEnabled:h,onOpenGitmojiPicker:b}=t,{t:f}=pt(),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}=an();let k;e[4]!==f?(k=f("gitView.commit.title"),e[4]=f,e[5]=k):k=e[5];let D;e[6]!==k?(D=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:k})}),e[6]=k,e[7]=D):D=e[7];let j;e[8]!==v||e[9]!==f?(j=v?null:s.jsx("p",{className:"typography-meta text-muted-foreground",children:f("gitView.commit.selectFilesHint")}),e[8]=v,e[9]=f,e[10]=j):j=e[10];let S;e[11]!==i||e[12]!==o?(S=s.jsx(ej,{highlights:i,onInsert:o}),e[11]=i,e[12]=o,e[13]=S):S=e[13];let A;e[14]!==f?(A=f("gitView.commit.messagePlaceholder"),e[14]=f,e[15]=A):A=e[15];const E=u!==null;let P;e[16]!==r||e[17]!==y||e[18]!==w||e[19]!==a||e[20]!==A||e[21]!==E?(P=s.jsx(Xw,{value:r,onChange:a,placeholder:A,disabled:E,hasTouchInput:y,isMobile:w}),e[16]=r,e[17]=y,e[18]=w,e[19]=a,e[20]=A,e[21]=E,e[22]=P):P=e[22];let C;e[23]!==h||e[24]!==b||e[25]!==f?(C=h&&s.jsxs(we,{variant:"outline",size:"sm",onClick:b,className:"w-fit",type:"button",children:[s.jsx(I,{name:"emotion-happy",className:"size-4"}),f("gitView.commit.addGitmoji")]}),e[23]=h,e[24]=b,e[25]=f,e[26]=C):C=e[26];const N=d||u!==null||n===0;let T;e[27]!==f?(T=f("gitView.commit.generateAria"),e[27]=f,e[28]=T):T=e[28];let M;e[29]!==d?(M=d?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"ai-generate-2",className:"size-4 text-primary"}),e[29]=d,e[30]=M):M=e[30];let R;e[31]!==f?(R=f("gitView.commit.generate"),e[31]=f,e[32]=R):R=e[32];let L;e[33]!==R?(L=s.jsx("span",{className:"commit-actions__label",children:R}),e[33]=R,e[34]=L):L=e[34];let $;e[35]!==c||e[36]!==N||e[37]!==T||e[38]!==M||e[39]!==L?($=s.jsxs(we,{variant:"outline",size:"sm",onClick:c,disabled:N,type:"button","aria-label":T,className:"commit-actions__btn",children:[M,L]}),e[35]=c,e[36]=N,e[37]=T,e[38]=M,e[39]=L,e[40]=$):$=e[40];let B;e[41]===Symbol.for("react.memo_cache_sentinel")?(B=s.jsx("div",{className:"flex-1"}),e[41]=B):B=e[41];const O=!g||d;let _;e[42]!==f?(_=f("gitView.commit.commitAria"),e[42]=f,e[43]=_):_=e[43];let ee;e[44]!==u||e[45]!==f?(ee=u==="commit"?s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"commit-actions__label",children:f("gitView.commit.committing")})]}):s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"git-commit",className:"size-4"}),s.jsx("span",{className:"commit-actions__label",children:f("gitView.commit.commit")})]}),e[44]=u,e[45]=f,e[46]=ee):ee=e[46];let z;e[47]!==p||e[48]!==O||e[49]!==_||e[50]!==ee?(z=s.jsx(we,{size:"sm",variant:"outline",onClick:p,disabled:O,className:"commit-actions__btn whitespace-nowrap","aria-label":_,children:ee}),e[47]=p,e[48]=O,e[49]=_,e[50]=ee,e[51]=z):z=e[51];let ne;e[52]!==g||e[53]!==u||e[54]!==d||e[55]!==w||e[56]!==m||e[57]!==f?(ne=w?s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(we,{variant:"default",size:"sm",onClick:()=>m(),disabled:!g||d,className:"h-7 w-7 p-0","aria-label":f("gitView.commit.pushAria"),children:u==="commitAndPush"?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"arrow-up",className:"size-3.5"})})}),s.jsx(Pt,{side:"top",children:s.jsx("p",{children:f("gitView.commit.push")})})]}):s.jsx(we,{size:"sm",variant:"default",onClick:()=>m(),disabled:!g||d,className:"commit-actions__btn","aria-label":f("gitView.commit.pushAria"),children:u==="commitAndPush"?s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"commit-actions__label",children:f("gitView.commit.pushing")})]}):s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"arrow-up",className:"size-3.5"}),s.jsx("span",{className:"commit-actions__label",children:f("gitView.commit.push")})]})}),e[52]=g,e[53]=u,e[54]=d,e[55]=w,e[56]=m,e[57]=f,e[58]=ne):ne=e[58];let re;e[59]!==$||e[60]!==z||e[61]!==ne?(re=s.jsxs("div",{className:"@container/commit-actions flex items-center gap-2 min-w-0",children:[$,B,z,ne]}),e[59]=$,e[60]=z,e[61]=ne,e[62]=re):re=e[62];let ue;e[63]!==re||e[64]!==j||e[65]!==S||e[66]!==P||e[67]!==C?(ue=s.jsxs("div",{className:"flex flex-col gap-3 px-0 pt-1 pb-3",children:[j,S,P,C,re]}),e[63]=re,e[64]=j,e[65]=S,e[66]=P,e[67]=C,e[68]=ue):ue=e[68];let Q;return e[69]!==ue||e[70]!==D?(Q=s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[D,ue]}),e[69]=ue,e[70]=D,e[71]=Q):Q=e[71],Q},nj=t=>{const e=at.c(16),{onOpenStashes:n}=t,{t:r}=pt();let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=s.jsx(I,{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(we,{type:"button",variant:"outline",size:"sm",onClick:n,className:"gap-1.5",children:[s.jsx(I,{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 mm(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 rj(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 aj=l.memo(t=>{const e=at.c(55),{entry:n,isExpanded:r,onToggle:a,files:i,isLoadingFiles:o,onCopyHash:c}=t,{t:d}=pt(),p=r?"bg-sidebar/90":"hover:bg-sidebar/40";let m;e[0]!==p?(m=me("w-full flex items-start gap-3 px-3 py-2 text-left transition-colors",p),e[0]=p,e[1]=m):m=e[1];let u;e[2]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx("div",{className:"h-2 w-2 translate-y-2 rounded-full shrink-0",style:{backgroundColor:"var(--status-success)"},"aria-hidden":!0}),e[2]=u):u=e[2];let h;e[3]!==n.message?(h=s.jsx("p",{className:"typography-ui-label font-medium text-foreground line-clamp-1",children:n.message}),e[3]=n.message,e[4]=h):h=e[4];let b;e[5]!==n.author_name?(b=s.jsx("span",{className:"truncate min-w-[3ch]",title:n.author_name,children:n.author_name}),e[5]=n.author_name,e[6]=b):b=e[6];let f;e[7]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx("span",{className:"shrink-0",children:"·"}),e[7]=f):f=e[7];let v;e[8]!==n.date?(v=mm(n.date),e[8]=n.date,e[9]=v):v=e[9];let x;e[10]!==n.date?(x=mm(n.date),e[10]=n.date,e[11]=x):x=e[11];let g;e[12]!==v||e[13]!==x?(g=s.jsx("span",{className:"truncate min-w-0",title:v,children:x}),e[12]=v,e[13]=x,e[14]=g):g=e[14];let w;e[15]!==b||e[16]!==g?(w=s.jsxs("div",{className:"flex items-center gap-1 min-w-0 truncate",children:[b,f,g]}),e[15]=b,e[16]=g,e[17]=w):w=e[17];let y;e[18]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx("span",{className:"shrink-0",children:"·"}),e[18]=y):y=e[18];let k;e[19]!==n.hash?(k=n.hash.slice(0,8),e[19]=n.hash,e[20]=k):k=e[20];let D;e[21]!==k?(D=s.jsx("code",{className:"shrink-0 font-mono",children:k}),e[21]=k,e[22]=D):D=e[22];let j;e[23]!==n.hash||e[24]!==c?(j=$=>{$.stopPropagation(),c(n.hash)},e[23]=n.hash,e[24]=c,e[25]=j):j=e[25];let S;e[26]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsx(I,{name:"file-copy",className:"size-3"}),e[26]=S):S=e[26];let A;e[27]!==j?(A=s.jsx(Ct,{asChild:!0,children:s.jsx(we,{variant:"ghost",size:"sm",className:"h-5 px-1 shrink-0",onClick:j,children:S})}),e[27]=j,e[28]=A):A=e[28];let E;e[29]!==d?(E=d("gitView.history.copySha"),e[29]=d,e[30]=E):E=e[30];let P;e[31]!==E?(P=s.jsx(Pt,{sideOffset:8,children:E}),e[31]=E,e[32]=P):P=e[32];let C;e[33]!==A||e[34]!==P?(C=s.jsxs(kt,{children:[A,P]}),e[33]=A,e[34]=P,e[35]=C):C=e[35];let N;e[36]!==w||e[37]!==D||e[38]!==C?(N=s.jsxs("div",{className:"flex items-center gap-1 typography-meta text-muted-foreground",children:[w,y,D,C]}),e[36]=w,e[37]=D,e[38]=C,e[39]=N):N=e[39];let T;e[40]!==N||e[41]!==h?(T=s.jsxs("div",{className:"min-w-0 flex-1",children:[h,N]}),e[40]=N,e[41]=h,e[42]=T):T=e[42];let M;e[43]!==a||e[44]!==m||e[45]!==T?(M=s.jsxs("button",{type:"button",onClick:a,className:m,children:[u,T]}),e[43]=a,e[44]=m,e[45]=T,e[46]=M):M=e[46];let R;e[47]!==i||e[48]!==r||e[49]!==o||e[50]!==d?(R=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(I,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:d("gitView.history.loadingFiles")})]}):i.length===0?s.jsx("p",{className:"typography-micro text-muted-foreground py-2",children:d("gitView.history.noFiles")}):s.jsx("ul",{className:"space-y-0.5 py-2",children:i.map($=>s.jsxs("li",{className:"flex items-center gap-2 typography-micro",children:[s.jsx("span",{className:me("font-semibold w-3 text-center",rj($.changeType)),children:$.changeType}),s.jsx("span",{className:"truncate text-foreground min-w-0",title:$.path,children:$.path}),!$.isBinary&&s.jsxs("span",{className:"shrink-0",children:[s.jsxs("span",{style:{color:"var(--status-success)"},children:["+",$.insertions]}),s.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),s.jsxs("span",{style:{color:"var(--status-error)"},children:["-",$.deletions]})]}),$.isBinary&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:d("gitView.history.binary")})]},$.path))})}),e[47]=i,e[48]=r,e[49]=o,e[50]=d,e[51]=R):R=e[51];let L;return e[52]!==M||e[53]!==R?(L=s.jsxs("li",{children:[M,R]}),e[52]=M,e[53]=R,e[54]=L):L=e[54],L}),ij=[{labelKey:"gitView.history.logSize25",value:25},{labelKey:"gitView.history.logSize50",value:50},{labelKey:"gitView.history.logSize100",value:100}],oj=t=>{const e=at.c(54),{log:n,isLogLoading:r,logMaxCount:a,onLogMaxCountChange:i,expandedCommitHashes:o,onToggleCommit:c,commitFilesMap:d,loadingCommitHashes:p,onCopyHash:m,showHeader:u,contentMaxHeightClassName:h,branchDivider:b}=t,f=u===void 0?!0:u,v=h===void 0?"max-h-[50vh]":h,x=b===void 0?null:b,{t:g}=pt(),[w,y]=l.useState(!0);if(!n)return null;const k=x!==null&&x.insertBeforeIndex>0&&x.insertBeforeIndex<n.all.length,D=x!==null&&x.insertBeforeIndex===n.all.length,j=k||D;let S;e[0]!==x||e[1]!==k||e[2]!==D||e[3]!==n.all?(S=k?n.all.slice(0,x.insertBeforeIndex):D?n.all:[],e[0]=x,e[1]=k,e[2]=D,e[3]=n.all,e[4]=S):S=e[4];const A=S;let E;if(e[5]!==x||e[6]!==d||e[7]!==v||e[8]!==o||e[9]!==k||e[10]!==j||e[11]!==p||e[12]!==n.all||e[13]!==m||e[14]!==c||e[15]!==g||e[16]!==A){const O=k?n.all.slice(x.insertBeforeIndex):[];let _;e[18]!==x?.direction?(_=x?.direction==="down"?s.jsx(I,{name:"arrow-down-s",className:"size-3.5"}):s.jsx(I,{name:"arrow-up",className:"size-3.5"}),e[18]=x?.direction,e[19]=_):_=e[19];const ee=_;let z;e[20]!==d||e[21]!==o||e[22]!==p||e[23]!==m||e[24]!==c?(z=re=>s.jsx("ul",{className:"divide-y divide-border/60",children:re.map(ue=>s.jsx(aj,{entry:ue,isExpanded:o.has(ue.hash),onToggle:()=>c(ue.hash),files:d.get(ue.hash)??[],isLoadingFiles:p.has(ue.hash),onCopyHash:m},ue.hash))}),e[20]=d,e[21]=o,e[22]=p,e[23]=m,e[24]=c,e[25]=z):z=e[25];const ne=z;E=s.jsx(Ts,{outerClassName:`min-h-0 ${v}`,className:"h-full w-full",children:n.all.length===0?s.jsx("div",{className:"flex h-full items-center justify-center p-4",children:s.jsx("p",{className:"typography-ui-label text-muted-foreground",children:g("gitView.history.noCommits")})}):j&&x?s.jsxs("div",{className:"flex flex-col gap-0",children:[A.length>0?s.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:ne(A)}):null,s.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5","aria-hidden":!0,children:[s.jsx("span",{className:"h-px flex-1 bg-border/60"}),s.jsxs("span",{className:"inline-flex max-w-[80%] items-center gap-1 typography-micro text-muted-foreground",children:[s.jsx("span",{className:"truncate",title:x.branchName,children:x.branchName}),ee]}),s.jsx("span",{className:"h-px flex-1 bg-border/60"})]}),O.length>0?s.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:ne(O)}):null]}):ne(n.all)}),e[5]=x,e[6]=d,e[7]=v,e[8]=o,e[9]=k,e[10]=j,e[11]=p,e[12]=n.all,e[13]=m,e[14]=c,e[15]=g,e[16]=A,e[17]=E}else E=e[17];const P=E;if(!f){if(j){let _;return e[26]!==P?(_=s.jsx("section",{className:"h-full min-h-0",children:P}),e[26]=P,e[27]=_):_=e[27],_}let O;return e[28]!==P?(O=s.jsx("section",{className:"h-full min-h-0 rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:P}),e[28]=P,e[29]=O):O=e[29],O}let C;e[30]!==g?(C=g("gitView.history.title"),e[30]=g,e[31]=C):C=e[31];let N;e[32]!==C?(N=s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:C}),e[32]=C,e[33]=N):N=e[33];let T;e[34]!==r||e[35]!==w||e[36]!==a||e[37]!==i||e[38]!==g?(T=w&&s.jsx("div",{onClick:lj,onPointerDown:cj,children:s.jsxs(ds,{value:String(a),onValueChange:O=>i(Number(O)),disabled:r,children:[s.jsx(us,{size:"sm",className:"data-[size=sm]:h-auto h-7 min-h-7 w-auto justify-between px-2 py-0",disabled:r,children:s.jsx(ys,{placeholder:g("gitView.history.commitsPlaceholder")})}),s.jsx(ms,{children:ij.map(O=>s.jsx(Lt,{value:String(O.value),children:g(O.labelKey)},O.value))})]})}),e[34]=r,e[35]=w,e[36]=a,e[37]=i,e[38]=g,e[39]=T):T=e[39];let M;e[40]!==w?(M=w?s.jsx(I,{name:"arrow-up-s",className:"size-4 text-muted-foreground"}):s.jsx(I,{name:"arrow-down-s",className:"size-4 text-muted-foreground"}),e[40]=w,e[41]=M):M=e[41];let R;e[42]!==T||e[43]!==M?(R=s.jsxs("div",{className:"flex items-center gap-2",children:[T,M]}),e[42]=T,e[43]=M,e[44]=R):R=e[44];let L;e[45]!==R||e[46]!==N?(L=s.jsxs(wr,{className:"flex w-full items-center justify-between px-3 h-10 hover:bg-transparent",children:[N,R]}),e[45]=R,e[46]=N,e[47]=L):L=e[47];let $;e[48]!==P?($=s.jsx(mr,{children:P}),e[48]=P,e[49]=$):$=e[49];let B;return e[50]!==w||e[51]!==L||e[52]!==$?(B=s.jsxs(ur,{open:w,onOpenChange:y,className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[L,$]}),e[50]=w,e[51]=L,e[52]=$,e[53]=B):B=e[53],B};function lj(t){return t.stopPropagation()}function cj(t){return t.stopPropagation()}const dj=9e4,uj=15e3,mj=5*6e4,pj=[2e3,5e3],hj=6e4,fj=2*6e4,gj=5*6e4,xj=720*6e4,bj="openchamber.github-pr-status",yj=t=>t==="closed"||t==="merged",vj=t=>{const e=t?.checks;return e?e.state==="pending"||e.pending>0:!1},zi=(t,e,n)=>`${t}::${e}`,wo=new Map,jo=new Map,ki=new Set,pm=new Map,Ei=()=>({status:null,isLoading:!1,error:null,isInitialStatusResolved:!1,lastRefreshAt:0,lastDiscoveryPollAt:0,watchers:0,params:null,identity:null,resolvedRemoteName:null}),ul=t=>t?.params?.directory&&t.params.branch?{directory:t.params.directory,branch:t.params.branch,remoteName:t.params.remoteName??t.resolvedRemoteName??t.identity?.remoteName??null}:!t?.identity?.directory||!t.identity.branch?null:t.identity,Wd=t=>{const e=ul(t);return!e?.directory||!e.branch?null:`${e.directory}::${e.branch}`},If=(t,e)=>Object.entries(t).filter(([,n])=>Wd(n)===e).map(([n])=>n),wj=(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}}},No=t=>!t?.params?.canShow||!t.params.github?.prStatus?null:{...t.params,remoteName:t.params.remoteName??t.resolvedRemoteName??t.identity?.remoteName??null},jj=(t,e,n)=>{const r=If(t,e),a=r.map(d=>No(t[d])).filter(d=>!!d);if(a.length===0)return null;const i=No(t[n]);if(i&&Wd(t[n])===e)return i;const o=r.map(d=>t[d]).find(d=>!!(d?.resolvedRemoteName&&No(d)));if(o)return No(o);const c=a.find(d=>!!d.remoteName);return c||(a[0]??null)},Nj=t=>({status:t.status,isInitialStatusResolved:t.isInitialStatusResolved,lastRefreshAt:t.lastRefreshAt,lastDiscoveryPollAt:t.lastDiscoveryPollAt,identity:ul(t),resolvedRemoteName:t.resolvedRemoteName??t.status?.resolvedRemoteName??null}),Sj=t=>({...Ei(),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}),cr=tr()(Zi((t,e)=>({entries:{},activeRequestCount:0,totalRequestCount:0,ensureEntry:n=>{t(r=>r.entries[n]?r:{entries:{...r.entries,[n]:Ei()}})},setParams:(n,r)=>{t(a=>{const i=a.entries[n]??Ei();return{entries:{...a.entries,[n]:wj(i,r)}}})},startWatching:n=>{if(t(i=>{const o=i.entries[n]??Ei();return{entries:{...i.entries,[n]:{...o,watchers:o.watchers+1}}}}),wo.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=jo.get(n)??[];c.push(o),jo.set(n,c)};e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0}),pj.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<mj)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(yj(i.status?.pr?.state))return;const c=Date.now()-i.lastRefreshAt,d=vj(i.status)?hj:i.status?.checks&&i.status.checks.state!=="pending"?gj:fj;c<d||e().refresh(n,{force:!0,onlyExistingPr:!0,silent:!0,markInitialResolved:!0})},uj);wo.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=wo.get(n);typeof a=="number"&&window.clearInterval(a),wo.delete(n);const i=jo.get(n);i&&i.length>0&&i.forEach(o=>{window.clearTimeout(o)}),jo.delete(n)},refresh:async(n,r)=>{const a=e(),i=a.entries[n],o=Wd(i);if(!i||!o)return;const c=If(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<dj||ki.has(o))return;const m=jj(a.entries,o,n);if(m){if(ki.add(o),pm.set(o,Date.now()),t(u=>{const h={...u.entries};return c.forEach(b=>{const f=h[b];f&&(h[b]={...f,lastRefreshAt:Date.now(),isLoading:r?.silent?f.isLoading:!0,error:null})}),{entries:h}}),m.githubAuthChecked&&m.githubConnected===!1){t(u=>{const h={...u.entries};return c.forEach(b=>{const f=h[b];f&&(h[b]={...f,status:{connected:!1},error:null,isLoading:r?.silent?f.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?f.isInitialStatusResolved:!0})}),{entries:h}}),ki.delete(o);return}if(!m.github?.prStatus){t(u=>{const h={...u.entries};return c.forEach(b=>{const f=h[b];f&&(h[b]={...f,status:null,error:"GitHub runtime API unavailable",isLoading:r?.silent?f.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?f.isInitialStatusResolved:!0})}),{entries:h}}),ki.delete(o);return}try{t(h=>({...h,activeRequestCount:h.activeRequestCount+1,totalRequestCount:h.totalRequestCount+1}));const u=await m.github.prStatus(m.directory,m.branch,m.remoteName??void 0,{force:r?.force});t(h=>{const b={...h.entries};return c.forEach(f=>{const v=b[f];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,k=y.resolvedRemoteName??v.resolvedRemoteName??m.remoteName??null,D=ul(v)??{directory:m.directory,branch:m.branch,remoteName:m.remoteName??null};b[f]={...v,status:y,error:null,isLoading:r?.silent?v.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?v.isInitialStatusResolved:!0,resolvedRemoteName:k,identity:{...D,remoteName:k??D.remoteName??null}}}),{entries:b}})}catch(u){const h=u instanceof Error?u.message:String(u);t(b=>{const f={...b.entries};return c.forEach(v=>{const x=f[v];x&&(f[v]={...x,error:h||"Failed to load PR status",isLoading:r?.silent?x.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?x.isInitialStatusResolved:!0})}),{entries:f}})}finally{ki.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:zi(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]??Ei();return{entries:{...a.entries,[n]:{...i,status:r(i.status)}}}})}}),{name:bj,storage:vl(()=>Zr()),partialize:t=>({entries:Object.fromEntries(Object.entries(t.entries).filter(([,e])=>{const n=ul(e);if(!n?.directory||!n.branch)return!1;const r=Math.max(e.lastRefreshAt,e.lastDiscoveryPollAt);return r===0||Date.now()-r<xj}).map(([e,n])=>[e,Nj(n)]))}),merge:(t,e)=>{const n=t?.entries??{};return{...e,entries:Object.fromEntries(Object.entries(n).map(([a,i])=>[a,Sj(i)]))}}})),kj=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"},Cj=t=>{const e=kj(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}},Ij=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 uc=new Map,hm=new Map;const Pj=t=>{const e=at.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=Cj(c);if(!d)continue;const p=Ij(d);a.set(o,p),i.set(o,d)}if(a.size===uc.size){let o=!0;for(const[c,d]of a)if(uc.get(c)!==d){o=!1;break}if(o)return hm}return uc=a,hm=i,i},e[0]=t,e[1]=n):n=e[1],cr(n)},Aj=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"}},Dj=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"},Tj=[2e3,5e3],fm=t=>t.replace(/^refs\/heads\//,"").replace(/[-_]+/g," ").replace(/\s+/g," ").trim().replace(/\b\w/g,e=>e.toUpperCase()),Xr=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):""},Mj=(t,e)=>{const n=Xr(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},Ej=(t,e)=>`${t}::${e}`,Kd=t=>{const e=String(t||"").trim();if(!e)return"";const n=e.indexOf("/");return n<=0?"":e.slice(0,n).trim()},mc=(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=Kd(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)},Rj=t=>t.startsWith("pr-"),Fj=(t,e)=>{const n=Kd(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=>!Rj(o.name)).forEach(o=>i(o)),t.forEach(o=>i(o)),a},pc=new Map,hc=Xn;function Lj(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 Oj=({directory:t,branch:e,baseBranch:n,trackingBranch:r,remotes:a=[],remoteBranches:i=[],onGeneratedDescription:o})=>{const{t:c}=pt(),{github:d}=_n(),p=Kn(Ge=>Ge.status),m=Kn(Ge=>Ge.hasChecked),u=Te(Ge=>Ge.setSettingsDialogOpen),h=Te(Ge=>Ge.setSettingsPage),b=Te(Ge=>Ge.setActiveMainTab),f=Vt(Ge=>Ge.currentSessionId),{isMobile:v,hasTouchInput:x}=an(),g=l.useCallback(()=>{h("github"),u(!0)},[u,h]),w=l.useMemo(()=>Ej(t,e),[t,e]),y=l.useMemo(()=>pc.get(w)??null,[w]),k=cr(Ge=>Ge.ensureEntry),D=cr(Ge=>Ge.setParams),j=cr(Ge=>Ge.startWatching),S=cr(Ge=>Ge.stopWatching),A=cr(Ge=>Ge.refresh),E=cr(Ge=>Ge.updateStatus),[P,C]=l.useState(()=>y?.title??fm(e)),[N,T]=l.useState(()=>y?.body??""),[M,R]=l.useState(()=>y?.draft??!1),[L,$]=l.useState(()=>y?.additionalContext??""),[B,O]=l.useState(()=>{const Ge=typeof y?.targetBaseBranch=="string"?Xr(y.targetBaseBranch):"";return Ge||Xr(n)}),[_,ee]=l.useState("squash"),[z,ne]=l.useState(!1),[re,ue]=l.useState(!1),[Q,de]=l.useState(!1),[X,F]=l.useState(!1),[V,q]=l.useState(!1),[te,U]=l.useState(!1),[ae,je]=l.useState(null),[oe,ve]=l.useState(""),[K,ce]=l.useState(""),[Z,le]=l.useState(!1),[se,Ie]=l.useState(!1),[Ne,Y]=l.useState(()=>mc(a,{selectedRemoteName:y?.selectedRemoteName,trackingBranch:r})),[fe,ke]=l.useState(!1),{detectedUpstream:be,upstreamBranches:pe}=Lj(t,d);l.useEffect(()=>{ke(!1)},[t]);const Ee=a.some(Ge=>Ge.name==="upstream"),G=!!(t&&e&&n&&(e!==n||(Ee||be!==null))),Pe=l.useMemo(()=>zi(t,e),[t,e]),Le=cr(Ge=>Ge.entries[Pe]),Ae=Le?.isLoading??!1,ge=Le?.status??null,W=Le?.error??null,ie=Le?.isInitialStatusResolved??!1,Me=l.useMemo(()=>{const Ge=fe?null:Ne?.name?.trim()||null,yt=new Set;for(const ss of i){const it=Mj(ss,Ge);!it||it==="HEAD"||yt.add(it)}if(fe)for(const ss of pe)ss&&ss!=="HEAD"&&yt.add(ss);const It=Xr(n);It&&It!=="HEAD"&&yt.add(It);const Rt=Xr(B);return Rt&&Rt!=="HEAD"&&yt.add(Rt),Array.from(yt).sort((ss,it)=>ss.localeCompare(it))},[n,i,Ne?.name,B,pe,fe]);l.useEffect(()=>{if(a.length===0){Ne&&Y(null);return}(!Ne||!a.some(Ge=>Ge.name===Ne.name))&&Y(mc(a,{selectedRemoteName:y?.selectedRemoteName,trackingBranch:r}))},[y?.selectedRemoteName,a,Ne,r]),l.useEffect(()=>{const Ge=Xr(n);if(!B&&Ge){O(Ge);return}if(Me.length!==0&&!Me.includes(B)){const yt=Me.includes(Ge)?Ge:Me[0];yt&&O(yt)}},[Me,n,B]);const[Ve,Ce]=l.useState(!1),[xe,De]=l.useState(null),[Ye,rt]=l.useState(!1),[Re,he]=l.useState(new Set),[qe,et]=l.useState(!1),[Ke,st]=l.useState(null),[nt,ye]=l.useState(!1),Je=l.useRef(new Set),_e=l.useRef(null),Ue=l.useRef(!1),ot=l.useRef(new Set),Xe=l.useRef([]);l.useEffect(()=>{be&&!Ee&&ke(!0)},[be,Ee]),l.useEffect(()=>{fe&&be?.defaultBranch&&O(be.defaultBranch)},[fe,be?.defaultBranch]);const We=ge?.pr??null,bt=We?`${t}#${We.number}`:null,Dt=!!(bt&&ae===bt);l.useEffect(()=>{if(!d?.prContext||!We||typeof We.body=="string"&&We.body.length>0)return;const Ge=`${t}#${We.number}`;if(Je.current.has(Ge))return;Je.current.add(Ge),je(Ge);let yt=!1;return d.prContext(t,We.number,{includeDiff:!1,includeCheckDetails:!1}).then(It=>{if(yt)return;const Rt=It?.pr;Rt&&E(Pe,ss=>!ss?.pr||ss.pr.number!==We.number?ss:{...ss,pr:{...ss.pr,body:Rt.body||""}})}).catch(()=>{}).finally(()=>{yt||je(It=>It===Ge?null:It)}),()=>{yt=!0}},[t,d,We,Pe,E]),l.useEffect(()=>{if(!We){U(!1),ve(""),ce(""),_e.current=null;return}const Ge=_e.current!==null&&_e.current!==We.number;Ge&&U(!1),(!te||Ge)&&(ve(We.title||""),ce(We.body||"")),_e.current=We.number},[te,We]);const Ht=l.useCallback(async()=>{if(!d?.prContext){H.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(We){Ce(!0),he(new Set),rt(!0);try{const Ge=await d.prContext(t,We.number,{includeDiff:!1,includeCheckDetails:!0});De(Ge)}catch(Ge){const yt=Ge instanceof Error?Ge.message:String(Ge);H.error(c("gitView.pr.toast.loadCheckDetailsFailed"),{description:yt})}finally{rt(!1)}}},[t,d,We,c]),rs=l.useCallback(async()=>{if(!d?.prContext){H.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(We){et(!0),ye(!0);try{const Ge=await d.prContext(t,We.number,{includeDiff:!1,includeCheckDetails:!1});st(Ge)}catch(Ge){const yt=Ge instanceof Error?Ge.message:String(Ge);H.error(c("gitView.pr.toast.loadCommentsFailed"),{description:yt})}finally{ye(!1)}}},[t,d,We,c]),jt=l.useCallback(Ge=>{if(!Ge)return"";const yt=Date.parse(Ge);return Number.isFinite(yt)?new Date(yt).toLocaleString():Ge},[]),St=l.useMemo(()=>{const Ge=p?.user?.login;return typeof Ge=="string"?Ge.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)]",[]),ut=l.useCallback(Ge=>{const yt=St.toLowerCase(),It=/(^|[^\w`])@([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,38}))/g;return Ge.replace(It,(Rt,ss,it)=>{const Bt=`@${it}`,bs=it.toLowerCase();return`${ss}[${Bt}](https://github.com/${bs}${yt&&bs===yt?"?oc-self-mention=1":""})`})},[St]),Gt=l.useMemo(()=>{const Ge=(Ke?.issueComments??[]).map(Rt=>({id:`issue-${Rt.id}`,body:Rt.body||"",authorName:Rt.author?.name||Rt.author?.login||c("gitView.pr.comments.unknownAuthor"),authorLogin:Rt.author?.login||null,avatarUrl:Rt.author?.avatarUrl||null,createdAt:Rt.createdAt,context:c("gitView.pr.comments.generalContext"),path:null,line:null})),yt=(Ke?.reviewComments??[]).map(Rt=>({id:`review-${Rt.id}`,body:Rt.body||"",authorName:Rt.author?.name||Rt.author?.login||c("gitView.pr.comments.unknownAuthor"),authorLogin:Rt.author?.login||null,avatarUrl:Rt.author?.avatarUrl||null,createdAt:Rt.createdAt,context:c("gitView.pr.comments.reviewContext"),path:Rt.path||null,line:Rt.line??null})),It=[...Ge,...yt];return It.sort((Rt,ss)=>{const it=Rt.createdAt?Date.parse(Rt.createdAt):0,Bt=ss.createdAt?Date.parse(ss.createdAt):0,bs=Number.isFinite(it)?it:0,es=Number.isFinite(Bt)?Bt:0;return bs-es}),It},[Ke,c]),Xt=l.useCallback(()=>{if(!f)return H.error(c("gitView.pr.toast.noActiveSession"),{description:c("gitView.pr.toast.noActiveSessionDescription")}),null;const{currentProviderId:Ge,currentModelId:yt,currentAgentName:It,currentVariant:Rt}=gt.getState(),ss=Nl.getState().lastUsedProvider,it=Ge||ss?.providerID,Bt=yt||ss?.modelID;return!it||!Bt?(H.error(c("gitView.pr.toast.noModelSelected")),null):{sessionId:f,providerID:it,modelID:Bt,currentAgentName:It??null,currentVariant:Rt??null}},[f,c]),Wt=l.useCallback((Ge,yt,It,Rt)=>{Vt.getState().sendMessage(yt,Ge.providerID,Ge.modelID,Ge.currentAgentName??void 0,void 0,void 0,[{text:It,synthetic:!0},{text:Rt,synthetic:!0}],Ge.currentVariant??void 0).catch(ss=>{const it=ss instanceof Error?ss.message:String(ss);H.error(c("gitView.pr.toast.sendMessageFailed"),{description:it})})},[c]),is=l.useCallback(Ge=>{const yt=Ge.status||"unknown",It=Ge.conclusion??void 0,Rt=It?`${yt} / ${It}`:yt,ss=Ge.app?.name||Ge.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:Ge.name}),s.jsx("div",{className:"typography-micro text-muted-foreground truncate",children:ss?`${ss} · ${Rt}`:Rt})]}),Ge.detailsUrl?s.jsx(we,{variant:"outline",size:"sm",asChild:!0,className:"flex-shrink-0",children:s.jsxs("a",{href:Ge.detailsUrl,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(I,{name:"external-link",className:"size-4"}),"Open"]})}):null]}),Ge.output?.title?s.jsx("div",{className:"typography-micro text-foreground",children:Ge.output.title}):null,Ge.output?.summary?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap",children:Ge.output.summary}):null,Ge.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:Ge.output.text}):null,Array.isArray(Ge.annotations)&&Ge.annotations.length>0?s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"typography-micro text-muted-foreground",children:["Failed annotations",Ge.annotations.length>20?` (showing 20/${Ge.annotations.length})`:""]}),s.jsx("div",{className:"space-y-1",children:Ge.annotations.slice(0,20).map((it,Bt)=>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:[it.title||it.level||"Issue",it.path?` · ${it.path}`:"",typeof it.startLine=="number"?`:${it.startLine}`:"",typeof it.endLine=="number"&&it.endLine!==it.startLine?`-${it.endLine}`:""]}),s.jsx("div",{className:"typography-micro text-foreground whitespace-pre-wrap mt-1",children:it.message}),it.rawDetails?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap mt-1",children:it.rawDetails}):null]},`${it.path||"file"}:${it.startLine||Bt}:${Bt}`))})]}):null,Ge.job?.steps&&Ge.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:Ge.job.steps.map((it,Bt)=>{const bs=(it.conclusion||"").toLowerCase(),es=bs&&!["success","neutral","skipped"].includes(bs),Ut=`${Ge.id??"run"}:${Ge.job?.jobId??"job"}:${it.number??Bt}:${it.name}`,os=Re.has(Ut);return es?s.jsxs(ur,{open:os,children:[s.jsxs("button",{type:"button",onClick:()=>{he(en=>{const qs=new Set(en);return qs.has(Ut)?qs.delete(Ut):qs.add(Ut),qs})},className:"typography-micro flex w-full items-center gap-2 rounded px-2 py-1 text-left "+(es?"bg-destructive/10 text-destructive":"text-muted-foreground"),children:[os?s.jsx(I,{name:"arrow-down-s",className:"size-4"}):s.jsx(I,{name:"arrow-right-s",className:"size-4"}),s.jsx("span",{className:"truncate",children:it.name}),it.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:it.conclusion}):null]}),s.jsx(mr,{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 it.number=="number"?s.jsxs("div",{children:[c("gitView.pr.checks.stepLabel"),": ",it.number]}):null,it.status?s.jsxs("div",{children:[c("gitView.pr.checks.statusLabel"),": ",it.status]}):null,it.conclusion?s.jsxs("div",{children:[c("gitView.pr.checks.conclusionLabel"),": ",it.conclusion]}):null,it.startedAt?s.jsxs("div",{children:[c("gitView.pr.checks.startedLabel"),": ",jt(it.startedAt)]}):null,it.completedAt?s.jsxs("div",{children:[c("gitView.pr.checks.completedLabel"),": ",jt(it.completedAt)]}):null]})})]},Ut):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:it.name}),it.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:it.conclusion}):null]},Ut)})})]}):null]})},[Re,jt,c]),gs=l.useCallback(async()=>{if(b("chat"),!d?.prContext){H.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!We)return;const Ge=Xt();if(Ge)try{const yt=await d.prContext(t,We.number,{includeDiff:!1,includeCheckDetails:!0}),Rt=(yt.checkRuns??[]).filter(es=>{const Ut=typeof es.conclusion=="string"?es.conclusion.toLowerCase():"";return Ut?!["success","neutral","skipped"].includes(Ut):!1});if(Rt.length===0){H.message(c("gitView.pr.toast.noFailedChecks"));return}const ss=await kn("github.pr.checks.review.visible"),it=await kn("github.pr.checks.review.instructions"),Bt=Rt.flatMap(es=>(Array.isArray(es.annotations)?es.annotations:[]).map(os=>({run:es.name,level:os.level,title:os.title,path:os.path,startLine:os.startLine,endLine:os.endLine,message:os.message,rawDetails:os.rawDetails}))),bs=`GitHub PR failed checks (JSON)
7
- ${JSON.stringify({repo:yt.repo??null,pr:yt.pr??null,failedChecks:Rt,failedAnnotations:Bt},null,2)}`;Wt(Ge,ss,it,bs)}catch(yt){const It=yt instanceof Error?yt.message:String(yt);H.error(c("gitView.pr.toast.loadChecksFailed"),{description:It})}},[t,Wt,d,We,Xt,b,c]),ps=l.useCallback(async()=>{if(b("chat"),!d?.prContext){H.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!We)return;const Ge=Xt();if(Ge)try{const yt=await d.prContext(t,We.number,{includeDiff:!1,includeCheckDetails:!1}),It=yt.issueComments??[],Rt=yt.reviewComments??[];if(It.length+Rt.length===0){H.message(c("gitView.pr.toast.noPrComments"));return}const it=await kn("github.pr.comments.review.visible"),Bt=await kn("github.pr.comments.review.instructions"),bs=`GitHub PR comments (JSON)
8
- ${JSON.stringify({repo:yt.repo??null,pr:yt.pr??null,issueComments:It,reviewComments:Rt},null,2)}`;Wt(Ge,it,Bt,bs)}catch(yt){const It=yt instanceof Error?yt.message:String(yt);H.error(c("gitView.pr.toast.loadPrCommentsFailed"),{description:It})}},[t,Wt,d,We,Xt,b,c]),Ns=l.useCallback(async Ge=>{et(!1),b("chat");const yt=Xt();if(!yt)return;const It=await kn("github.pr.comment.single.visible"),Rt=await kn("github.pr.comment.single.instructions"),ss=`GitHub PR comment (JSON)
9
- ${JSON.stringify({repo:Ke?.repo??null,pr:Ke?.pr??We??null,comment:Ge},null,2)}`;Wt(yt,It,Rt,ss)},[Ke,Wt,We,Xt,b]),Mt=l.useCallback(async Ge=>{await A(Pe,Ge)},[Pe,A]),He=l.useCallback(()=>{Xe.current.forEach(Ge=>{window.clearTimeout(Ge)}),Xe.current=Tj.map(Ge=>window.setTimeout(()=>{Mt({force:!0,silent:!0,markInitialResolved:!0})},Ge))},[Mt]);l.useEffect(()=>{if(!d?.prStatus||!G||a.length<=1||Ue.current||ge?.pr)return;const Ge=`${w}::${Ne?.name??""}`;if(ot.current.has(Ge))return;ot.current.add(Ge);const yt=Fj(a,r).filter(ss=>ss.name!==Ne?.name);if(yt.length===0)return;let It=!1;return(async()=>{for(const ss of yt){if(It)return;try{if(!(await d.prStatus(t,e,ss.name))?.pr)continue;if(It)return;Y(Bt=>Bt?.name===ss.name?Bt:ss);return}catch{}}})(),()=>{It=!0}},[e,G,t,d,a,Ne?.name,w,ge?.pr,r]),l.useEffect(()=>{k(Pe),D(Pe,{directory:t,branch:e,remoteName:Ne?.name??null,canShow:G,github:d,githubAuthChecked:m,githubConnected:p?.connected??null})},[e,G,t,k,d,m,p?.connected,Pe,Ne?.name,D]),l.useEffect(()=>(j(Pe),()=>{S(Pe)}),[Pe,j,S]),l.useEffect(()=>{const Ge=pc.get(w)??null;C(Ge?.title??fm(e)),T(Ge?.body??""),R(Ge?.draft??!1),O(Ge?.targetBaseBranch?Xr(Ge.targetBaseBranch):Xr(n));const yt=mc(a,{selectedRemoteName:Ge?.selectedRemoteName,trackingBranch:r});Y(It=>It?.name===yt?.name?It:yt)},[n,e,a,w,r]),l.useEffect(()=>{Mt({markInitialResolved:!0})},[Pe,Mt]),l.useEffect(()=>{!G||!Ne?.name||Mt({force:!0,silent:!0,markInitialResolved:!0})},[G,Mt,Ne?.name]),l.useEffect(()=>{const Ge=ge?.resolvedRemoteName?.trim();if(!Ge||Ue.current)return;const yt=a.find(It=>It.name===Ge);yt&&Y(It=>It?.name===yt.name?It:yt)},[a,ge?.resolvedRemoteName]),l.useEffect(()=>{const Ge=ge?.pr?.state==="closed"||ge?.pr?.state==="merged",yt=Le?.lastRefreshAt??0,It=Date.now()-yt>6e4,Rt=!Ge&&It,ss=()=>{Rt&&Mt({force:!0,silent:!0})},it=()=>{document.visibilityState==="visible"&&Rt&&Mt({force:!0,silent:!0})};return window.addEventListener("focus",ss),document.addEventListener("visibilitychange",it),()=>{window.removeEventListener("focus",ss),document.removeEventListener("visibilitychange",it)}},[Mt,ge?.pr?.state,Le?.lastRefreshAt]),l.useEffect(()=>{m&&p?.connected===!1&&Mt({force:!0,silent:!0,markInitialResolved:!0})},[m,p,Mt]),l.useEffect(()=>{!t||!e||pc.set(w,{title:P,body:N,draft:M,additionalContext:L,targetBaseBranch:B,selectedRemoteName:Ne?.name})},[w,P,N,M,L,B,Ne?.name,t,e]),l.useEffect(()=>{const Ge=Xe.current;return()=>{Ge.forEach(yt=>{window.clearTimeout(yt)}),Xe.current=[]}},[]);const At=l.useCallback(async()=>{if(!z&&t){ne(!0);try{const yt={base:fe&&be?.defaultBranchSha?be.defaultBranchSha:B,head:e};L&&(yt.context=L);const It=await ib(t,yt);It.title?.trim()&&C(It.title.trim()),It.body?.trim()&&T(It.body.trim()),o?.()}catch(Ge){const yt=Ge instanceof Error?Ge.message:String(Ge);H.error(c("gitView.pr.toast.generateDescriptionFailed"),{description:yt})}finally{ne(!1)}}},[L,e,be?.defaultBranchSha,t,z,o,B,c,fe]),Et=l.useCallback(async()=>{if(!d?.prCreate){H.error(c("gitView.pr.toast.githubApiUnavailable"));return}const Ge=P.trim();if(!Ge){H.error(c("gitView.pr.toast.titleRequired"));return}const yt=B.trim();if(!yt){H.error(c("gitView.pr.toast.baseBranchRequired"));return}if(!fe&&yt===e){H.error(c("gitView.pr.toast.baseMustDifferFromHead"));return}ue(!0);try{const It=Kd(r),Rt=fe&&be,ss=await d.prCreate({directory:t,title:Ge,head:e,base:yt,...N.trim()?{body:N}:{},draft:M,...Rt?{targetRepo:{owner:be.owner,repo:be.repo},headRemote:"origin"}:{...Ne?{remote:Ne.name}:{},...It&&It!==Ne?.name?{headRemote:It}:{}}});H.success(c("gitView.pr.toast.prCreated")),E(Pe,it=>it&&{...it,pr:ss}),await Mt({force:!0}),He()}catch(It){const Rt=It instanceof Error?It.message:String(It);H.error(c("gitView.pr.toast.createPrFailed"),{description:Rt})}finally{ue(!1)}},[N,e,be,t,M,d,Pe,Mt,He,Ne,B,P,r,E,fe,c]),wt=l.useCallback(async Ge=>{if(!d?.prMerge){H.error(c("gitView.pr.toast.githubApiUnavailable"));return}F(!0);try{const yt=await d.prMerge({directory:t,number:Ge.number,method:_});yt.merged?H.success(c("gitView.pr.toast.prMerged")):H.message(c("gitView.pr.toast.prNotMerged"),{description:yt.message||c("gitView.pr.notMergeable")}),await Mt({force:!0}),He()}catch(yt){const It=yt instanceof Error?yt.message:String(yt);H.error(c("gitView.pr.toast.mergeFailed"),{description:It}),Ge.url&&hc(Ge.url)}finally{F(!1)}},[t,d,_,Mt,He,c]),$t=l.useCallback(async Ge=>{if(!d?.prReady){H.error(c("gitView.pr.toast.githubApiUnavailable"));return}q(!0);try{await d.prReady({directory:t,number:Ge.number}),H.success(c("gitView.pr.toast.markedReady")),await Mt({force:!0}),He()}catch(yt){const It=yt instanceof Error?yt.message:String(yt);H.error(c("gitView.pr.toast.markReadyFailed"),{description:It}),Ge.url&&hc(Ge.url)}finally{q(!1)}},[t,d,Mt,He,c]),qt=l.useCallback(async Ge=>{if(!d?.prUpdate){H.error(c("gitView.pr.toast.githubApiUnavailable"));return}const yt=oe.trim();if(!yt){H.error(c("gitView.pr.toast.titleRequired"));return}de(!0);try{const It=await d.prUpdate({directory:t,number:Ge.number,title:yt,body:K});E(Pe,Rt=>Rt&&{...Rt,pr:{...Rt.pr??Ge,...It}}),U(!1),H.success(c("gitView.pr.toast.prUpdated")),await Mt({force:!0}),He()}catch(It){const Rt=It instanceof Error?It.message:String(It);H.error(c("gitView.pr.toast.updatePrFailed"),{description:Rt})}finally{de(!1)}},[t,K,oe,d,Pe,Mt,He,E,c]);if(!G)return s.jsx("section",{className:"border-0 bg-transparent rounded-none",children:s.jsxs("div",{className:"space-y-1 pt-3",children:[s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:c("gitView.pullRequest.title")}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pullRequest.availableOnFeatureBranches")})]})});const Ms=ge?.repo?.url||null,cs=fe&&be?.url?be.url:Ms,Is=ge?.checks??null,Es=!!ge?.canMerge,ft=!!ge?.connected,hs=m&&ge?.connected===!1,J=Dj(ge),ct=J?`var(--pr-${J})`:"var(--status-info)",vt=J==="draft"?"git-pr-draft":J==="merged"?"git-merge":J==="closed"?"git-close-pull-request":"git-pull-request",Tt=We?[`${We.state}${We.draft?" (draft)":""}`,We.mergeable===!1?c("gitView.pr.notMergeable"):null,We.state==="open"&&typeof We.mergeableState=="string"&&We.mergeableState&&We.mergeableState!=="unknown"?We.mergeableState:null].filter(Boolean).join(" · "):"",Yt=Is?Is.total>0?`${Is.success}/${Is.total} ${c("gitView.pr.checks.label")}`:`${Is.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:[We?s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",className:"inline-flex size-6 shrink-0 items-center justify-center rounded-md border border-border/60 bg-background/70 hover:bg-interactive-hover/60",onClick:()=>{hc(We.url)},"aria-label":c("gitView.pr.actions.openOnGitHubAria"),children:s.jsx(I,{name:vt,className:"size-4 shrink-0",style:{color:ct}})})}),s.jsx(Pt,{children:s.jsx("p",{children:c("gitView.pr.actions.openOnGitHub")})})]}):s.jsx(I,{name:vt,className:"size-4 shrink-0",style:{color:"var(--surface-muted-foreground)"}}),s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground truncate",children:c("gitView.pullRequest.title")}),We?s.jsxs("span",{className:"typography-meta text-muted-foreground truncate",children:["#",We.number]}):null]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Ae?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}):null,s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",className:"inline-flex size-5 items-center justify-center rounded hover:bg-interactive-hover/60 disabled:opacity-40",disabled:Ae,onClick:()=>{Mt({force:!0})},"aria-label":c("gitView.pr.actions.refreshAria"),children:s.jsx(I,{name:"refresh",className:"size-3.5 text-muted-foreground"})})}),s.jsx(Pt,{children:s.jsx("p",{children:c("gitView.pr.actions.refresh")})})]})]})]}),We?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:ct},children:Tt}),Is?s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx("span",{className:`h-2 w-2 rounded-full ${Aj(Is.state)}`}),Yt]}):null,r&&Ne&&r.split("/")[0]!==Ne.name?s.jsxs("span",{className:"min-w-0 truncate",children:[r.split("/")[0]," → ",Ne.name]}):null]}):null]}),s.jsxs("div",{className:"flex flex-col gap-3 py-3",children:[hs?s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-meta text-muted-foreground",children:c("gitView.pr.githubNotConnected")}),s.jsx(we,{variant:"outline",size:"sm",onClick:g,className:"w-fit",children:c("gitView.pr.actions.openSettings")})]}):null,W?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:W}),cs?s.jsx(we,{variant:"outline",size:"sm",asChild:!0,className:"w-fit",children:s.jsxs("a",{href:cs,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(I,{name:"external-link",className:"size-4"}),"Open Repo"]})}):null]}):null,!We&&!ie&&!W&&!hs?s.jsxs("div",{className:"flex items-center gap-2 typography-micro text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),c("gitView.pr.checkingStatus")]}):We?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:[te?s.jsxs("div",{className:"space-y-2",children:[s.jsx(Kt,{value:oe,onChange:Ge=>ve(Ge.target.value),placeholder:c("gitView.pr.placeholder.title"),autoCorrect:x?"on":"off",autoCapitalize:x?"sentences":"off",spellCheck:x}),s.jsx(bn,{value:K,onChange:Ge=>ce(Ge.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:We.title}),We.body?.trim()?s.jsx(Aa,{content:We.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(Dt?"gitView.pr.loadingDescription":"gitView.pr.noDescription")})]}),Es&&We.draft?s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.draftMustBeReady")}):null,Es?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:[We.state==="open"?te?s.jsxs(s.Fragment,{children:[s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(we,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>{U(!1),ve(We.title||""),ce(We.body||"")},disabled:Q,"aria-label":c("gitView.pr.actions.cancelEditingAria"),children:s.jsx(I,{name:"close",className:"size-4"})})}),s.jsx(Pt,{children:s.jsx("p",{children:c("gitView.pr.actions.cancelEditing")})})]}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(we,{size:"sm",className:"h-7 w-7 px-0",onClick:()=>qt(We),disabled:Q||!oe.trim(),"aria-label":c("gitView.pr.actions.savePrAria"),children:Q?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"check",className:"size-4"})})}),s.jsx(Pt,{children:s.jsx("p",{children:c("gitView.pr.actions.savePr")})})]})]}):s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(we,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>U(!0),"aria-label":c("gitView.pr.actions.editPrAria"),children:s.jsx(I,{name:"edit",className:"size-4"})})}),s.jsx(Pt,{children:s.jsx("p",{children:c("gitView.pr.actions.editPr")})})]}):null,Is?s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(we,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:Ht,disabled:Ye,"aria-label":c("gitView.pr.actions.openChecksAria"),children:Ye?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"information",className:"size-4"})})}),s.jsx(Pt,{children:s.jsx("p",{children:c("gitView.pr.actions.openChecks")})})]}):null,Is?.failure?s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(we,{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(I,{name:"error-warning",className:"size-4"})})}),s.jsx(Pt,{children:s.jsx("p",{children:c("gitView.pr.actions.resolveFailedChecks")})})]}):null,s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(we,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:rs,"aria-label":c("gitView.pr.actions.openCommentsAria"),children:s.jsx(I,{name:"chat-4",className:"size-4"})})}),s.jsx(Pt,{children:s.jsx("p",{children:c("gitView.pr.actions.openComments")})})]}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(we,{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:ps,"aria-label":c("gitView.pr.actions.shareCommentsAria"),children:s.jsx(I,{name:"ai-generate-2",className:"size-4"})})}),s.jsx(Pt,{children:s.jsx("p",{children:c("gitView.pr.actions.shareComments")})})]}),Es&&We.draft&&We.state==="open"?s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(we,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>$t(We),disabled:V||X||Q||te,"aria-label":c("gitView.pr.actions.markReadyAria"),children:V?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"checkbox-circle",className:"size-4"})})}),s.jsx(Pt,{children:s.jsx("p",{children:c("gitView.pr.actions.markReady")})})]}):null]}),s.jsx("div",{className:"ml-auto flex items-center gap-2",children:Es?s.jsxs(s.Fragment,{children:[s.jsxs(ds,{value:_,onValueChange:Ge=>ee(Ge),disabled:X||We.state!=="open",children:[s.jsx(us,{size:"lg",className:"h-7 w-auto min-w-0",children:s.jsx(ys,{})}),s.jsxs(ms,{children:[s.jsx(Lt,{value:"squash",children:c("gitView.pr.mergeMethod.squash")}),s.jsx(Lt,{value:"merge",children:c("gitView.pr.mergeMethod.merge")}),s.jsx(Lt,{value:"rebase",children:c("gitView.pr.mergeMethod.rebase")})]})]}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(we,{size:"sm",className:"h-7 w-7 px-0",onClick:()=>wt(We),disabled:X||V||We.state!=="open"||We.draft||Q||te,"aria-label":c("gitView.pr.actions.mergePrAria"),children:X?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"git-merge",className:"size-4"})})}),s.jsx(Pt,{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)"})," → ",B," ",s.jsxs("span",{className:"opacity-60",children:["(",fe&&be?"upstream":"remote",")"]})]})]}),cs?s.jsx(we,{variant:"outline",size:"sm",asChild:!0,children:s.jsxs("a",{href:cs,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(I,{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(Kt,{value:P,onChange:Ge=>C(Ge.target.value),placeholder:c("gitView.pr.placeholder.title"),autoCorrect:x?"on":"off",autoCapitalize:x?"sentences":"off",spellCheck:x})]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.field.baseBranch")}),Me.length>0?s.jsxs(ds,{value:B,onValueChange:O,children:[s.jsx(us,{className:"h-9",children:s.jsx(ys,{placeholder:c("gitView.pr.placeholder.selectBaseBranch")})}),s.jsx(ms,{children:Me.map(Ge=>s.jsx(Lt,{value:Ge,children:Ge},Ge))})]}):s.jsx(Kt,{value:B,onChange:Ge=>O(Ge.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(bn,{value:N,onChange:Ge=>T(Ge.target.value),className:"min-h-[110px]",placeholder:c("gitView.pr.placeholder.whatChanged"),autoCorrect:x?"on":"off",autoCapitalize:x?"sentences":"off",spellCheck:x})]}),s.jsxs("div",{className:"flex items-center gap-2 cursor-pointer",role:"button",tabIndex:0,"aria-pressed":M,onClick:()=>R(Ge=>!Ge),onKeyDown:Ge=>{(Ge.key===" "||Ge.key==="Enter")&&(Ge.preventDefault(),R(yt=>!yt))},children:[s.jsx(xs,{size:"sm",checked:M,onChange:Ge=>R(Ge),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(we,{variant:"outline",size:"sm",onClick:()=>Ie(!0),children:L.trim()?c("gitView.pr.actions.edit"):c("gitView.pr.actions.add")})]}),L.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(ur,{open:Z,onOpenChange:le,children:[s.jsxs(wr,{className:"flex w-full items-center justify-between rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-3 py-2 hover:bg-[var(--interactive-hover)]",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.additionalContext.optional")}),s.jsx("span",{className:"typography-micro text-[var(--primary-base)]",children:Z?c("gitView.pr.actions.hide"):L.trim()?c("gitView.pr.actions.edit"):c("gitView.pr.actions.add")})]}),s.jsx(mr,{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(bn,{value:L,onChange:Ge=>$(Ge.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(Pr,{open:se,onClose:()=>Ie(!1),title:c("gitView.pr.additionalContext.title"),footer:s.jsx(we,{size:"sm",onClick:()=>Ie(!1),className:"w-full",children:c("gitView.common.done")}),children:s.jsxs("div",{className:"space-y-3",children:[s.jsx(bn,{value:L,onChange:Ge=>$(Ge.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(we,{variant:"outline",size:"sm",onClick:At,disabled:z||re,children:[z?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"ai-generate-2",className:"size-4 text-primary"}),c("gitView.commit.generate")]}),s.jsx("div",{className:"flex-1"}),s.jsxs(we,{size:"sm",className:"min-w-[7.5rem] justify-center gap-2",onClick:Et,disabled:re||!ft||!B.trim()||!fe&&B.trim()===e,children:[s.jsx("span",{className:"inline-flex size-4 items-center justify-center",children:re?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"git-pull-request",className:"size-4"})}),s.jsx("span",{children:c("gitView.pr.actions.createPr")})]})]})]})]}),s.jsx(ws,{open:Ve,onOpenChange:Ce,children:s.jsxs(vs,{className:"max-w-2xl max-h-[70vh] flex flex-col min-h-0",children:[s.jsxs(Cs,{children:[s.jsxs(js,{className:"flex items-center gap-2",children:[s.jsx(I,{name:"git-pull-request",className:"h-5 w-5"}),c("gitView.pr.checkDetails.title")]}),s.jsx(Rs,{children:We?c("gitView.pr.numberLabel",{number:We.number}):c("gitView.pullRequest.title")})]}),s.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto mt-2",children:[Ye?s.jsxs("div",{className:"text-center text-muted-foreground py-8 flex items-center justify-center gap-2",children:[s.jsx(I,{name:"loader-4",className:"h-4 w-4 animate-spin"}),c("gitView.loading.loading")]}):null,Ye?null:s.jsx("div",{className:"space-y-3",children:Array.isArray(xe?.checkRuns)&&xe?.checkRuns.length>0?xe.checkRuns.map((Ge,yt)=>{const It=`${Ge.id??"run"}:${Ge.job?.jobId??"job"}:${Ge.name}:${yt}`;return s.jsx("div",{className:"p-1",children:is(Ge)},It)}):s.jsx("div",{className:"text-center text-muted-foreground py-8",children:c("gitView.pr.checkDetails.empty")})})]})]})}),s.jsx(ws,{open:qe,onOpenChange:et,children:s.jsxs(vs,{className:"max-w-2xl max-h-[82vh] min-h-[38rem] flex flex-col gap-2",children:[s.jsx(Cs,{children:s.jsxs(js,{className:"flex items-center gap-2",children:[s.jsx(I,{name:"git-pull-request",className:"h-5 w-5"}),c("gitView.pr.comments.title"),We?s.jsx("span",{className:"typography-meta text-muted-foreground",children:c("gitView.pr.numberLabel",{number:We.number})}):null]})}),s.jsxs(eo,{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(I,{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:Gt.length>0?s.jsx("div",{className:"relative pl-3",children:s.jsx("div",{children:Gt.map((Ge,yt)=>{const It=(Ge.authorName||"?").charAt(0).toUpperCase(),Rt=yt===Gt.length-1;return s.jsxs("div",{className:"relative pl-10 pb-5 last:pb-0",children:[Rt?null:s.jsx("div",{className:"absolute left-4 top-[2.375rem] bottom-[0.375rem] w-px bg-border/60"}),s.jsx("div",{className:"absolute left-0 top-0 z-10 flex size-8 items-center justify-center overflow-hidden rounded-full border border-border/60 bg-surface-elevated text-xs text-muted-foreground",children:Ge.avatarUrl?s.jsx("img",{src:Ge.avatarUrl,alt:Ge.authorName,className:"h-full w-full object-cover"}):s.jsx("span",{children:It})}),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:[Ge.authorName,Ge.authorLogin&&Ge.authorLogin!==Ge.authorName?` · @${Ge.authorLogin}`:""]}),Ge.createdAt?s.jsx("span",{className:"whitespace-nowrap",children:jt(Ge.createdAt)}):null,s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsxs(we,{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:()=>{Ns(Ge)},"aria-label":c("gitView.pr.actions.sendCommentToAgentAria"),children:[s.jsx(I,{name:"ai-generate-2",className:"size-3.5"}),c("gitView.pr.actions.sendToAgent")]})}),s.jsx(Pt,{children:s.jsx("p",{children:c("gitView.pr.actions.sendCommentToAgent")})})]})]}),s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[Ge.context,Ge.path?` · ${Ge.path}`:"",Ge.line?`:${Ge.line}`:""]}),s.jsx(Aa,{content:ut(Ge.body),className:["typography-markdown-body text-foreground break-words [&_a]:no-underline [&_a:hover]:no-underline",ns].filter(Boolean).join(" ")})]})]},Ge.id)})})}):s.jsx("div",{className:"text-center text-muted-foreground py-8",children:c("gitView.pr.comments.empty")})})]})]})})]})},$j=t=>{const e=at.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}=pt(),h=Vt(Bj),b=Vt(_j),f=Pa(Vj),v=Pa(zj),x=Te(Uj),[g,w]=l.useState(!1),[y,k]=l.useState(null),[D,j]=l.useState(null);let S,A;e[2]!==i||e[3]!==n||e[4]!==u?(S=()=>{!n||!i||(w(!0),j(null),k(null),ob(i).then(ke=>{k(ke)}).catch(ke=>{const be=ke instanceof Error?ke.message:u("gitView.conflict.loadFailed");j(be)}).finally(()=>{w(!1)}))},A=[n,i,u],e[2]=i,e[3]=n,e[4]=u,e[5]=S,e[6]=A):(S=e[5],A=e[6]),l.useEffect(S,A);let E;e[7]!==y||e[8]!==i||e[9]!==o?(E=async()=>{if(!y)return null;const ke=o==="merge"?"merge":"rebase",be=y.headInfo||(o==="merge"?"MERGE_HEAD":"REBASE_HEAD"),pe=o==="merge"?"git commit --no-edit":"git rebase --continue",Ee=await kn("git.conflict.resolve.visible",{operation_label:ke,head_ref:be}),ze=await kn("git.conflict.resolve.instructions",{operation_label:ke,directory:i,operation:o,head_info:y.headInfo||"N/A",continue_cmd:pe}),G=`${ke} conflict context (JSON)
10
- ${JSON.stringify({directory:i,operation:y.operation,headInfo:y.headInfo,statusPorcelain:y.statusPorcelain,unmergedFiles:y.unmergedFiles,diff:y.diff},null,2)}`;return{visibleText:Ee,instructionsText:ze,payloadText:G}},e[7]=y,e[8]=i,e[9]=o,e[10]=E):E=e[10];const P=E;let C;e[11]!==c||e[12]!==r?(C=()=>{c(),r(!1)},e[11]=c,e[12]=r,e[13]=C):C=e[13];const N=C;let T;e[14]!==d||e[15]!==r?(T=()=>{d?.(),r(!1)},e[14]=d,e[15]=r,e[16]=T):T=e[16];const M=T;let R;e[17]!==P||e[18]!==b||e[19]!==d||e[20]!==r||e[21]!==x||e[22]!==f||e[23]!==v||e[24]!==u?(R=async()=>{const ke=await P();if(!ke){H.error(u("gitView.conflict.noDetailsAvailable"));return}if(!b){H.error(u("gitView.conflict.noActiveSession"),{description:u("gitView.conflict.noActiveSessionDescription")});return}f(ke.visibleText,"replace"),v([{text:ke.instructionsText,synthetic:!0},{text:ke.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]=f,e[23]=v,e[24]=u,e[25]=R):R=e[25];const L=R;let $;e[26]!==P||e[27]!==i||e[28]!==d||e[29]!==r||e[30]!==h||e[31]!==x||e[32]!==u?($=async()=>{const ke=await P();if(!ke){H.error(u("gitView.conflict.noDetailsAvailable"));return}h({directoryOverride:i,initialPrompt:ke.visibleText,syntheticParts:[{text:ke.instructionsText,synthetic:!0},{text:ke.payloadText,synthetic:!0}]}),x("chat"),d?.(),r(!1)},e[26]=P,e[27]=i,e[28]=d,e[29]=r,e[30]=h,e[31]=x,e[32]=u,e[33]=$):$=e[33];const B=$;let O,_,ee,z,ne,re,ue,Q,de,X,F,V,q,te,U,ae,je,oe,ve,K,ce,Z;if(e[34]!==y||e[35]!==m||e[36]!==b||e[37]!==N||e[38]!==M||e[39]!==L||e[40]!==B||e[41]!==g||e[42]!==D||e[43]!==r||e[44]!==n||e[45]!==o||e[46]!==u){const ke=u(o==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),be=y?.unmergedFiles||m;ee=ws,ce=n,Z=r,_=vs,K="max-w-md w-[calc(100vw-2rem)]",te="flex flex-col gap-4 overflow-hidden";let pe;e[69]===Symbol.for("react.memo_cache_sentinel")?(pe=s.jsx(I,{name:"alert",className:"size-5 shrink-0 text-[var(--status-warning)]"}),e[69]=pe):pe=e[69];const Ee=s.jsxs("div",{className:"flex items-center gap-2",children:[pe,s.jsx(js,{children:u("gitView.conflict.detectedTitle",{operation:ke})})]});let ze;e[70]!==o||e[71]!==u?(ze=u("gitView.conflict.detectedDescription",{operation:o}),e[70]=o,e[71]=u,e[72]=ze):ze=e[72];let G;e[73]!==ze?(G=s.jsx(Rs,{children:ze}),e[73]=ze,e[74]=G):G=e[74],e[75]!==Ee||e[76]!==G?(U=s.jsxs(Cs,{children:[Ee,G]}),e[75]=Ee,e[76]=G,e[77]=U):U=e[77],e[78]!==g||e[79]!==u?(ae=g&&s.jsxs("div",{className:"flex items-center justify-center gap-2 py-4 text-muted-foreground",children:[s.jsx(I,{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]=ae):ae=e[80],e[81]!==D||e[82]!==u?(je=D&&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:D})}),e[81]=D,e[82]=u,e[83]=je):je=e[83],e[84]!==be||e[85]!==u?(oe=be.length>0&&s.jsxs("div",{className:"space-y-2 overflow-hidden",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:u("gitView.conflict.conflictedFiles")}),s.jsx("span",{className:"typography-micro px-1.5 py-0.5 rounded bg-[var(--surface-elevated)] text-muted-foreground",children:be.length})]}),s.jsx("div",{className:"bg-[var(--surface-elevated)] rounded-lg p-3 max-h-40 overflow-y-auto overflow-x-hidden",children:s.jsx("ul",{className:"space-y-1",children:be.map(Wj)})})]}),e[84]=be,e[85]=u,e[86]=oe):oe=e[86],e[87]!==y||e[88]!==u?(ve=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]=ve):ve=e[89],F="flex flex-col gap-2 pt-2";let Pe;e[90]!==B?(Pe=()=>{B()},e[90]=B,e[91]=Pe):Pe=e[91];const Le=g||!y;let Ae;e[92]!==g?(Ae=g?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"add",className:"size-4"}),e[92]=g,e[93]=Ae):Ae=e[93];let ge;e[94]!==u?(ge=u("gitView.conflict.resolveNewSession"),e[94]=u,e[95]=ge):ge=e[95],e[96]!==Pe||e[97]!==Le||e[98]!==Ae||e[99]!==ge?(V=s.jsxs(we,{variant:"default",onClick:Pe,disabled:Le,className:"w-full gap-2",children:[Ae,ge]}),e[96]=Pe,e[97]=Le,e[98]=Ae,e[99]=ge,e[100]=V):V=e[100];let W;e[101]!==L?(W=()=>{L()},e[101]=L,e[102]=W):W=e[102];const ie=g||!y||!b;let Me;e[103]!==g?(Me=g?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"chat-1",className:"size-4"}),e[103]=g,e[104]=Me):Me=e[104];let Ve;e[105]!==u?(Ve=u("gitView.conflict.resolveCurrentSession"),e[105]=u,e[106]=Ve):Ve=e[106],e[107]!==W||e[108]!==ie||e[109]!==Me||e[110]!==Ve?(q=s.jsxs(we,{variant:"outline",onClick:W,disabled:ie,className:"w-full gap-2",children:[Me,Ve]}),e[107]=W,e[108]=ie,e[109]=Me,e[110]=Ve,e[111]=q):q=e[111],de="flex gap-2 pt-1";let Ce;e[112]!==u?(Ce=u("gitView.conflict.continueLater"),e[112]=u,e[113]=Ce):Ce=e[113],e[114]!==M||e[115]!==Ce?(X=s.jsx(we,{variant:"ghost",size:"sm",onClick:M,className:"flex-1",children:Ce}),e[114]=M,e[115]=Ce,e[116]=X):X=e[116],O=we,z="destructive",ne="sm",re=N,ue="flex-1",Q=u("gitView.conflict.abortOperation",{operation:ke}),e[34]=y,e[35]=m,e[36]=b,e[37]=N,e[38]=M,e[39]=L,e[40]=B,e[41]=g,e[42]=D,e[43]=r,e[44]=n,e[45]=o,e[46]=u,e[47]=O,e[48]=_,e[49]=ee,e[50]=z,e[51]=ne,e[52]=re,e[53]=ue,e[54]=Q,e[55]=de,e[56]=X,e[57]=F,e[58]=V,e[59]=q,e[60]=te,e[61]=U,e[62]=ae,e[63]=je,e[64]=oe,e[65]=ve,e[66]=K,e[67]=ce,e[68]=Z}else O=e[47],_=e[48],ee=e[49],z=e[50],ne=e[51],re=e[52],ue=e[53],Q=e[54],de=e[55],X=e[56],F=e[57],V=e[58],q=e[59],te=e[60],U=e[61],ae=e[62],je=e[63],oe=e[64],ve=e[65],K=e[66],ce=e[67],Z=e[68];let le;e[117]!==O||e[118]!==z||e[119]!==ne||e[120]!==re||e[121]!==ue||e[122]!==Q?(le=s.jsx(O,{variant:z,size:ne,onClick:re,className:ue,children:Q}),e[117]=O,e[118]=z,e[119]=ne,e[120]=re,e[121]=ue,e[122]=Q,e[123]=le):le=e[123];let se;e[124]!==de||e[125]!==X||e[126]!==le?(se=s.jsxs("div",{className:de,children:[X,le]}),e[124]=de,e[125]=X,e[126]=le,e[127]=se):se=e[127];let Ie;e[128]!==F||e[129]!==V||e[130]!==q||e[131]!==se?(Ie=s.jsxs("div",{className:F,children:[V,q,se]}),e[128]=F,e[129]=V,e[130]=q,e[131]=se,e[132]=Ie):Ie=e[132];let Ne;e[133]!==te||e[134]!==U||e[135]!==ae||e[136]!==je||e[137]!==oe||e[138]!==ve||e[139]!==Ie?(Ne=s.jsxs("div",{className:te,children:[U,ae,je,oe,ve,Ie]}),e[133]=te,e[134]=U,e[135]=ae,e[136]=je,e[137]=oe,e[138]=ve,e[139]=Ie,e[140]=Ne):Ne=e[140];let Y;e[141]!==_||e[142]!==K||e[143]!==Ne?(Y=s.jsx(_,{className:K,children:Ne}),e[141]=_,e[142]=K,e[143]=Ne,e[144]=Y):Y=e[144];let fe;return e[145]!==ee||e[146]!==ce||e[147]!==Z||e[148]!==Y?(fe=s.jsx(ee,{open:ce,onOpenChange:Z,children:Y}),e[145]=ee,e[146]=ce,e[147]=Z,e[148]=Y,e[149]=fe):fe=e[149],fe};function Bj(t){return t.openNewSessionDraft}function _j(t){return t.currentSessionId}function Vj(t){return t.setPendingInputText}function zj(t){return t.setPendingSyntheticParts}function Uj(t){return t.setActiveMainTab}function Wj(t){return s.jsx("li",{className:"typography-micro text-foreground font-mono truncate block",title:t,children:t},t)}const Kj=({open:t,onOpenChange:e,operation:n,targetBranch:r,onConfirm:a})=>{const{t:i}=pt(),[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 f=b instanceof Error?b.message:`Failed to ${n}`;H.error(f)}finally{p(!1)}},h=()=>{d||e(!1)};return s.jsx(ws,{open:t,onOpenChange:d?void 0:e,children:s.jsxs(vs,{className:"max-w-md",children:[s.jsxs(Cs,{children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(I,{name:"alert",className:"size-5 text-[var(--status-warning)]"}),s.jsx(js,{children:i("gitView.stash.title")})]}),s.jsx(Rs,{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(xs,{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(Ks,{className:"gap-2",children:[s.jsx(we,{variant:"ghost",size:"sm",onClick:h,disabled:d,children:i("gitView.common.cancel")}),s.jsx(we,{variant:"default",size:"sm",onClick:u,disabled:d,className:"gap-1.5",children:d?s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),i("gitView.common.processing")]}):i("gitView.stash.confirmButton",{operation:m})})]})]})})},Hj=({mergeInProgress:t,rebaseInProgress:e,onContinue:n,onAbort:r,onResolveWithAI:a,hasUnresolvedConflicts:i=!1,isLoading:o=!1})=>{const{t:c}=pt(),[d,p]=l.useState(null),m=t&&t.head,u=e&&(e.headName||e.onto),h=m?"merge":u?"rebase":null;if(!h)return null;const b=async()=>{p("continue");try{await n()}finally{p(null)}},f=async()=>{p("abort");try{await r()}finally{p(null)}},v=d!==null,x=c(h==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),g=h==="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(I,{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(we,{variant:"outline",size:"sm",onClick:a,disabled:v||o,className:"gap-1.5",children:[s.jsx(I,{name:"sparkling",className:"size-4"}),c("gitView.operation.resolveWithAi")]}),d!=="continue"&&s.jsxs(we,{variant:"ghost",size:"sm",onClick:f,disabled:v||o,className:"gap-1.5",children:[d==="abort"?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"close",className:"size-4"}),c("gitView.operation.abort")]}),!i&&s.jsxs(we,{variant:"default",size:"sm",onClick:b,disabled:v||o,className:"gap-1.5",children:[d==="continue"?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{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")})]})})},Gj=t=>{const e=at.c(104),{currentBranch:n,localBranches:r,remoteBranches:a,onMerge:i,onRebase:o,disabled:c,isOperating:d,operationLogs:p,onOperationComplete:m,mode:u,defaultTargetBranch:h}=t,b=c===void 0?!1:c,f=d===void 0?!1:d,v=p===void 0?[]:p,x=u===void 0?"dialog":u,{t:g}=pt(),[w,y]=l.useState(!1),[k,D]=l.useState("merge"),[j,S]=l.useState(null),[A,E]=l.useState(!1),[P,C]=l.useState(""),N=l.useRef(null),T=l.useRef(null),M=b||f,R=n||g("gitView.branch.currentBranchFallback"),L=v.length>0&&v.every(qj),$=v.some(Jj);let B;e[0]===Symbol.for("react.memo_cache_sentinel")?(B=()=>{T.current&&(T.current.scrollTop=T.current.scrollHeight)},e[0]=B):B=e[0],l.useEffect(B,[v]);let O;if(e[1]!==P||e[2]!==n||e[3]!==r||e[4]!==a){e:{const W=P.toLowerCase();let ie;e[6]!==a?(ie=new Set(a.map(Qj).filter(Boolean)),e[6]=a,e[7]=ie):ie=e[7];const Me=ie;let Ve;e[8]!==n||e[9]!==Me?(Ve=xe=>xe!==n&&!Me.has(xe),e[8]=n,e[9]=Me,e[10]=Ve):Ve=e[10];const Ce=r.filter(Ve);if(!W){O=Ce;break e}O=Ce.filter(xe=>xe.toLowerCase().includes(W))}e[1]=P,e[2]=n,e[3]=r,e[4]=a,e[5]=O}else O=e[5];const _=O;let ee;if(e[11]!==P||e[12]!==a){e:{const W=P.toLowerCase();if(!W){ee=a;break e}ee=a.filter(ie=>ie.toLowerCase().includes(W))}e[11]=P,e[12]=a,e[13]=ee}else ee=e[13];const z=ee;let ne;e[14]!==h||e[15]!==r||e[16]!==a?(ne=()=>h&&(a.includes(h)||r.includes(h))?h:null,e[14]=h,e[15]=r,e[16]=a,e[17]=ne):ne=e[17];const re=ne;let ue;e[18]!==re||e[19]!==y?(ue=()=>{y(!0),S(re()),D("merge"),C("")},e[18]=re,e[19]=y,e[20]=ue):ue=e[20];const Q=ue;let de;e[21]===Symbol.for("react.memo_cache_sentinel")?(de=W=>{S(W),E(!1),C("")},e[21]=de):de=e[21];const X=de;let F;e[22]!==i||e[23]!==o||e[24]!==k||e[25]!==j?(F=()=>{j&&(k==="merge"?i(j):o(j))},e[22]=i,e[23]=o,e[24]=k,e[25]=j,e[26]=F):F=e[26];const V=F;let q;e[27]!==f||e[28]!==y?(q=()=>{f||(S(null),D("merge"),C(""),y(!1))},e[27]=f,e[28]=y,e[29]=q):q=e[29];const te=q,U=()=>{f&&!L||(L&&m?.(),S(null),D("merge"),C(""),y(!1))};let ae,je;e[30]!==A?(ae=()=>{A||C("")},je=[A],e[30]=A,e[31]=ae,e[32]=je):(ae=e[31],je=e[32]),l.useEffect(ae,je);let oe,ve;e[33]!==x||e[34]!==re||e[35]!==j?(oe=()=>{x!=="inline"||j||S(re())},ve=[x,re,j],e[33]=x,e[34]=re,e[35]=j,e[36]=oe,e[37]=ve):(oe=e[36],ve=e[37]),l.useEffect(oe,ve);const Z=f?s.jsxs("div",{className:"space-y-3",children:[s.jsx("div",{ref:T,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(Yj)})}),L?x==="dialog"?s.jsx(Ks,{children:s.jsx(we,{variant:"default",size:"sm",onClick:U,children:g($?"gitView.common.close":"gitView.common.done")})}):s.jsx("div",{className:"flex justify-end",children:s.jsx(we,{variant:"default",size:"sm",onClick:U,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:()=>D("merge"),className:me("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",k==="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(I,{name:"git-merge",className:me("size-4",k==="merge"?"text-primary":"text-muted-foreground")}),s.jsx("span",{className:me("typography-ui-label",k==="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:()=>D("rebase"),className:me("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",k==="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(I,{name:"git-branch",className:me("size-4",k==="rebase"?"text-primary":"text-muted-foreground")}),s.jsx("span",{className:me("typography-ui-label",k==="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:k==="merge"?g("gitView.branch.branchToMergeInto",{branch:R}):g("gitView.branch.branchToRebaseOnto")}),s.jsxs(Bs,{open:A,onOpenChange:E,modal:!1,children:[s.jsx(Os,{asChild:!0,children:s.jsxs(we,{variant:"outline",size:"lg",className:"w-full justify-between",children:[s.jsx("span",{className:me("truncate",!j&&"text-muted-foreground"),children:j||g("gitView.branch.selectBranch")}),s.jsx(I,{name:"arrow-down-s",className:"size-4 opacity-60 shrink-0"})]})}),s.jsx($s,{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(Ta,{className:"h-full min-h-0",children:[s.jsx(ra,{ref:N,placeholder:g("gitView.branch.searchPlaceholder"),value:P,onValueChange:C,onKeyDown:Xj}),s.jsxs(Ma,{className:"h-full min-h-0",disableHorizontal:!0,children:[s.jsx(Ea,{children:g("gitView.branch.empty")}),_.length>0&&s.jsx(Bn,{heading:g("gitView.branch.localBranches"),children:_.map(W=>s.jsx(An,{onSelect:()=>X(W),children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:W})},`local-${W}`))}),_.length>0&&z.length>0?s.jsx(va,{}):null,z.length>0&&s.jsx(Bn,{heading:g("gitView.branch.remoteBranches"),children:z.map(W=>s.jsx(An,{onSelect:()=>X(W),children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:W})},`remote-${W}`))})]})]})})]})]}),j?s.jsx("div",{className:"rounded-lg bg-muted/50 p-3",children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:k==="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(Ks,{className:"gap-2 pt-1",children:[s.jsx(we,{variant:"ghost",size:"sm",onClick:te,children:g("gitView.common.cancel")}),s.jsx(we,{variant:"default",size:"sm",onClick:V,disabled:!j,className:"gap-1.5",children:k==="merge"?s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"git-merge",className:"size-4"}),g("gitView.operation.merge")]}):s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"git-branch",className:"size-4"}),g("gitView.operation.rebase")]})})]}):s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsx(we,{variant:"destructive",size:"sm",onClick:te,disabled:M,children:g("gitView.common.reset")}),s.jsx("div",{className:"flex-1"}),s.jsx(we,{variant:"default",size:"sm",onClick:V,disabled:M||!j,children:g(k==="merge"?"gitView.operation.merge":"gitView.operation.rebase")})]})]});if(x==="inline"){let W;e[38]!==g?(W=g("gitView.branch.updateTitle"),e[38]=g,e[39]=W):W=e[39];let ie;e[40]!==W?(ie=s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:W}),e[40]=W,e[41]=ie):ie=e[41];let Me;e[42]!==g?(Me=g("gitView.branch.updateDescriptionPrefix"),e[42]=g,e[43]=Me):Me=e[43];let Ve;e[44]!==R?(Ve=s.jsx("span",{className:"font-mono text-foreground",children:R}),e[44]=R,e[45]=Ve):Ve=e[45];let Ce;e[46]!==Me||e[47]!==Ve?(Ce=s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[Me," ",Ve,"."]}),e[46]=Me,e[47]=Ve,e[48]=Ce):Ce=e[48];let xe;e[49]!==ie||e[50]!==Ce?(xe=s.jsx("header",{className:"border-b border-border/40 px-0 py-3",children:s.jsxs("div",{className:"space-y-1",children:[ie,Ce]})}),e[49]=ie,e[50]=Ce,e[51]=xe):xe=e[51];let De;e[52]!==Z?(De=s.jsx("div",{className:"pt-3",children:Z}),e[52]=Z,e[53]=De):De=e[53];let Ye;return e[54]!==xe||e[55]!==De?(Ye=s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[xe,De]}),e[54]=xe,e[55]=De,e[56]=Ye):Ye=e[56],Ye}let le;e[57]!==f?(le=f?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"git-merge",className:"size-4"}),e[57]=f,e[58]=le):le=e[58];let se;e[59]!==g?(se=g("gitView.branch.mergeRebase"),e[59]=g,e[60]=se):se=e[60];let Ie;e[61]!==se?(Ie=s.jsx("span",{children:se}),e[61]=se,e[62]=Ie):Ie=e[62];let Ne;e[63]!==Q||e[64]!==M||e[65]!==le||e[66]!==Ie?(Ne=s.jsx(Ct,{asChild:!0,children:s.jsxs(we,{variant:"outline",size:"sm",className:"gap-1.5",onClick:Q,disabled:M,children:[le,Ie]})}),e[63]=Q,e[64]=M,e[65]=le,e[66]=Ie,e[67]=Ne):Ne=e[67];let Y;e[68]!==g?(Y=g("gitView.branch.mergeRebaseTooltip"),e[68]=g,e[69]=Y):Y=e[69];let fe;e[70]!==Y?(fe=s.jsx(Pt,{sideOffset:8,children:Y}),e[70]=Y,e[71]=fe):fe=e[71];let ke;e[72]!==Ne||e[73]!==fe?(ke=s.jsxs(kt,{children:[Ne,fe]}),e[72]=Ne,e[73]=fe,e[74]=ke):ke=e[74];let be;e[75]!==U||e[76]!==y?(be=W=>{W?y(!0):U()},e[75]=U,e[76]=y,e[77]=be):be=e[77];let pe;e[78]!==g?(pe=g("gitView.branch.updateTitle"),e[78]=g,e[79]=pe):pe=e[79];let Ee;e[80]!==pe?(Ee=s.jsx(js,{children:pe}),e[80]=pe,e[81]=Ee):Ee=e[81];let ze;e[82]!==$||e[83]!==f||e[84]!==k||e[85]!==L||e[86]!==g||e[87]!==R?(ze=f?g(L?$?"gitView.branch.operationFailed":"gitView.branch.operationCompleted":k==="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]=f,e[84]=k,e[85]=L,e[86]=g,e[87]=R,e[88]=ze):ze=e[88];let G;e[89]!==ze?(G=s.jsx(Rs,{children:ze}),e[89]=ze,e[90]=G):G=e[90];let Pe;e[91]!==Ee||e[92]!==G?(Pe=s.jsxs(Cs,{children:[Ee,G]}),e[91]=Ee,e[92]=G,e[93]=Pe):Pe=e[93];let Le;e[94]!==Z||e[95]!==Pe?(Le=s.jsxs(vs,{className:"max-w-md",children:[Pe,Z]}),e[94]=Z,e[95]=Pe,e[96]=Le):Le=e[96];let Ae;e[97]!==w||e[98]!==be||e[99]!==Le?(Ae=s.jsx(ws,{open:w,onOpenChange:be,children:Le}),e[97]=w,e[98]=be,e[99]=Le,e[100]=Ae):Ae=e[100];let ge;return e[101]!==ke||e[102]!==Ae?(ge=s.jsxs(s.Fragment,{children:[ke,Ae]}),e[101]=ke,e[102]=Ae,e[103]=ge):ge=e[103],ge};function qj(t){return t.status==="done"||t.status==="error"}function Jj(t){return t.status==="error"}function Qj(t){return t.slice(t.indexOf("/")+1)}function Yj(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(I,{name:"loader-4",className:"size-3.5 animate-spin text-primary"}),t.status==="done"&&s.jsx(I,{name:"check",className:"size-3.5 text-success"}),t.status==="error"&&s.jsx(I,{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:me("typography-micro",t.status==="error"&&"text-destructive",t.status==="done"&&"text-muted-foreground",t.status==="running"&&"text-foreground",t.status==="pending"&&"text-muted-foreground/60"),children:t.message})]},e)}function Xj(t){return t.stopPropagation()}const gm="oc.git.actionTab",Zj=t=>t==="commit"||t==="branch"||t==="pr",Pf="gitmojiCache",e0=1e3*60*60*24*7,Af="1",t0=40,s0=20,n0="https://raw.githubusercontent.com/carloscuesta/gitmoji/master/packages/gitmojis/src/gitmojis.json",xm={feat:":sparkles:",feature:":sparkles:",fix:":bug:",bug:":bug:",hotfix:":ambulance:",docs:":memo:",documentation:":memo:",style:":lipstick:",refactor:":recycle:",perf:":zap:",performance:":zap:",test:":white_check_mark:",tests:":white_check_mark:",build:":construction_worker:",ci:":green_heart:",chore:":wrench:",revert:":rewind:",wip:":construction:",security:":lock:",release:":bookmark:",merge:":twisted_rightwards_arrows:",mv:":truck:",move:":truck:",rename:":truck:",remove:":fire:",delete:":fire:",add:":sparkles:",create:":sparkles:",implement:":sparkles:",update:":recycle:",improve:":zap:",optimize:":zap:",upgrade:":arrow_up:",downgrade:":arrow_down:",deploy:":rocket:",init:":tada:",initial:":tada:"},Df=t=>{if(!t||typeof t!="object")return!1;const e=t;return typeof e.emoji=="string"&&typeof e.code=="string"&&typeof e.description=="string"},r0=()=>{if(typeof window>"u")return null;try{const t=localStorage.getItem(Pf);if(!t)return null;const e=JSON.parse(t);return!e||e.version!==Af||typeof e.fetchedAt!="number"||!Array.isArray(e.gitmojis)?null:{gitmojis:e.gitmojis.filter(Df),fetchedAt:e.fetchedAt,version:e.version}}catch{return null}},a0=t=>{if(!(typeof window>"u"))try{const e={gitmojis:t,fetchedAt:Date.now(),version:Af};localStorage.setItem(Pf,JSON.stringify(e))}catch{return}},i0=t=>Date.now()-t.fetchedAt<e0,o0=(t,e)=>{const n=t.toLowerCase(),r=/^([a-z]+)(?:\(.*\))?!?:/,a=n.match(r);if(a){const c=a[1],d=xm[c];if(d)return e.find(p=>p.code===d)||null}const i=n.split(" ")[0],o=xm[i];return o&&e.find(c=>c.code===o)||null},bm=new Map,ua=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),Tf=()=>{const{t}=pt(),{git:e}=_n(),n=Er(),[r,a]=l.useState(null),[i,o]=l.useState(!1),c=Vt(Oe=>Oe.currentSessionId),d=Vt(Oe=>Oe.newSessionDraft),p=Vt(Oe=>Oe.setDraftBootstrapPendingDirectory),m=Vt(Oe=>Oe.worktreeMetadata),u=Vt(Oe=>Oe.availableWorktrees),h=ua(n),b=l.useMemo(()=>{if(!h)return;const Oe=u.find(Ze=>ua(Ze.path)===h);if(Oe)return Oe;for(const Ze of m.values())if(ua(Ze.path)===h)return Ze},[u,h,m]),f=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:k}=Jn(pr(Oe=>({profiles:Oe.profiles,globalIdentity:Oe.globalIdentity,defaultGitIdentityId:Oe.defaultGitIdentityId,loadProfiles:Oe.loadProfiles,loadGlobalIdentity:Oe.loadGlobalIdentity,loadDefaultGitIdentityId:Oe.loadDefaultGitIdentityId}))),D=Dd(n??null),j=Sl(n??null),S=Th(Oe=>c?Oe.getAttachment(c):void 0),A=S?lb(S):[],E=S&&!S.degraded&&!S.legacy?S.worktreeRoot??void 0:void 0,P=jw(n,f,j?.current??void 0),C=Td(n??null),N=cb(n??null),T=db(n??null),M=Md(n??null),R=ub(n??null),L=nn(Oe=>Oe.setActiveDirectory),$=nn(Oe=>Oe.fetchAll),B=nn(Oe=>Oe.ensureAll),O=nn(Oe=>Oe.fetchStatus),_=nn(Oe=>Oe.fetchBranches),ee=nn(Oe=>Oe.fetchLog),z=nn(Oe=>Oe.fetchIdentity),ne=nn(Oe=>Oe.prefetchDiffs),re=nn(Oe=>Oe.setLogMaxCount),ue=Te(Oe=>Oe.isMobile),Q=Te(Oe=>Oe.openContextDiff),de=Te(Oe=>Oe.navigateToDiff),X=Te(Oe=>Oe.setRightSidebarOpen),F=l.useRef(null);l.useEffect(()=>{if(!n){a(null),o(!1);return}let Oe=!1,Ze=null;const tt=async()=>{try{const dt=await pb(n);if(Oe)return;a(dt.status),dt.status==="pending"&&(Ze=window.setTimeout(()=>{tt()},500))}catch{Oe||a(null)}};return tt(),()=>{Oe=!0,Ze!==null&&window.clearTimeout(Ze)}},[n]),l.useEffect(()=>{const Oe=F.current;F.current=r,!(!n||!e)&&(Oe==="pending"&&r==="ready"&&(o(!0),$(n,e).finally(()=>{window.setTimeout(()=>{o(!1)},1200)})),r==="failed"&&(p(null),o(!1)))},[n,$,e,p,r]);const V=ua(d?.bootstrapPendingDirectory??null),q=!!(n&&V&&V===ua(n)),U=!!(n&&(r==="pending"||q))||i,ae=l.useMemo(()=>n?bm.get(n)??null:null,[n]),je=gt(Oe=>Oe.settingsGitmojiEnabled),[oe,ve]=l.useState(null);l.useEffect(()=>{const Oe=E||P?.projectDirectory;if(!Oe){ve(null);return}let Ze=!1;return to(Oe).then(tt=>{if(Ze)return;const dt=tt.trim();ve(dt&&dt!=="HEAD"?dt:null)}).catch(()=>{Ze||ve(null)}),()=>{Ze=!0}},[E,P?.projectDirectory]);const[K,ce]=l.useState(ae?.commitMessage??""),[Z,le]=l.useState([]),[se,Ie]=l.useState(!1),Ne=l.useRef(null),[Y,fe]=l.useState(null),[ke,be]=l.useState(!1),[pe,Ee]=l.useState(null),[ze,G]=l.useState(25),[Pe,Le]=l.useState(!1),{triggerFireworks:Ae}=xw(),ge=l.useRef(new Map),W=l.useRef(0),ie=l.useCallback(()=>{W.current+=1,Le(!0)},[]),Me=l.useCallback(()=>{W.current=Math.max(0,W.current-1),W.current===0&&Le(!1)},[]),[Ve,Ce]=l.useState(()=>new Set(ae?.selectedPaths??[])),[xe,De]=l.useState(!1),[Ye,rt]=l.useState(new Set),[Re,he]=l.useState(!1),[qe,et]=l.useState(0),[Ke,st]=l.useState(!1),[nt,ye]=l.useState(ae?.generatedHighlights??[]),Je=l.useCallback(()=>{const Oe=Ne.current;Oe&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{Oe.scrollTo({top:Oe.scrollHeight,behavior:"smooth"})})})},[]),_e=E||P?.projectDirectory||null,Ue=j?.current||null,ot=l.useMemo(()=>{const Oe=j?.tracking;return Oe?Oe.startsWith("origin/"):!0},[j?.tracking]),Xe=l.useMemo(()=>{const Oe=P?.createdFromBranch,Ze=typeof Oe=="string"?Oe.trim():"",tt=typeof j?.current=="string"?j.current.trim():"",dt=typeof oe=="string"?oe.trim():"";return Ze?Ze===tt&&Ze.startsWith("opencode/")&&dt.length>0&&dt!==Ze?dt:Ze:dt||tt||"HEAD"},[P?.createdFromBranch,j,oe]),We=l.useCallback(()=>{ye([])},[]),[bt,Dt]=l.useState(new Set),[Ht,rs]=l.useState(new Map),[jt,St]=l.useState(new Set),[ns,ut]=l.useState(null),[Gt,Xt]=l.useState(null),[Wt,is]=l.useState([]),[gs,ps]=l.useState(""),[Ns,Mt]=l.useState(!1),He=l.useMemo(()=>[{id:"commit",label:t("gitView.tabs.commit"),icon:s.jsx(I,{name:"git-commit",className:"h-3.5 w-3.5"})},{id:"branch",label:t("gitView.tabs.update"),icon:s.jsx(I,{name:"git-merge",className:"h-3.5 w-3.5"})},{id:"pr",label:t("gitView.tabs.pr"),icon:s.jsx(I,{name:"git-pull-request",className:"h-3.5 w-3.5"})}],[t]),[At,Et]=l.useState(()=>{if(typeof window>"u")return"commit";const Oe=window.localStorage.getItem(gm);return Oe==="worktree"?"branch":Zj(Oe)?Oe:"commit"}),[wt,$t]=l.useState([]),[qt,Ms]=l.useState(null),[cs,Is]=l.useState(null),[Es,ft]=l.useState([]),[hs,J]=l.useState(!1),[ct,vt]=l.useState([]),[Tt,Yt]=l.useState("merge"),Zt=l.useMemo(()=>c?`openchamber.conflict:${c}`:null,[c]),Ps=l.useCallback((Oe,Ze,tt)=>{if(!Zt||typeof window>"u")return;const dt={directory:Oe,conflictFiles:Ze,operation:tt};window.localStorage.setItem(Zt,JSON.stringify(dt))},[Zt]),As=l.useCallback(()=>{!Zt||typeof window>"u"||window.localStorage.removeItem(Zt)},[Zt]);l.useEffect(()=>{typeof window>"u"||window.localStorage.setItem(gm,At)},[At]),l.useEffect(()=>{if(!Zt||typeof window>"u"||!n)return;const Oe=window.localStorage.getItem(Zt);if(Oe)try{const Ze=JSON.parse(Oe);if(Ze.directory!==n){window.localStorage.removeItem(Zt);return}vt(Ze.conflictFiles??[]),Yt(Ze.operation??"merge"),J(!0)}catch{window.localStorage.removeItem(Zt)}},[Zt,n]);const[Ge,yt]=l.useState(!1),[It,Rt]=l.useState("merge"),[ss,it]=l.useState(""),Bt=l.useCallback(Oe=>{Rn(Oe).then(Ze=>{if(Ze.ok){H.success(t("gitView.toast.commitHashCopied"));return}H.error(t("gitView.toast.copyFailed"))})},[t]),bs=l.useCallback(Oe=>{Dt(Ze=>{const tt=new Set(Ze);return tt.has(Oe)?tt.delete(Oe):tt.add(Oe),tt})},[]);l.useEffect(()=>{if(!n||!e)return;const Oe=Array.from(bt).filter(Ze=>!Ht.has(Ze)&&!jt.has(Ze));if(Oe.length!==0){St(Ze=>{const tt=new Set(Ze);for(const dt of Oe)tt.add(dt);return tt});for(const Ze of Oe)e.getCommitFiles(n,Ze).then(tt=>{rs(dt=>new Map(dt).set(Ze,tt.files))}).catch(tt=>{console.error("Failed to fetch commit files:",tt),rs(dt=>new Map(dt).set(Ze,[]))}).finally(()=>{St(tt=>{const dt=new Set(tt);return dt.delete(Ze),dt})})}},[bt,n,e,Ht,jt]),l.useEffect(()=>{n&&bm.set(n,{directory:n,selectedPaths:Array.from(Ve),commitMessage:K,generatedHighlights:nt})},[K,n,Ve,nt]),l.useEffect(()=>{w(),y(),k()},[w,y,k]),l.useEffect(()=>{if(!n||!e?.getRemoteUrl){Xt(null);return}e.getRemoteUrl(n).then(Xt).catch(()=>Xt(null))},[n,e]);const es=l.useCallback(async()=>{if(!n||!e?.getRemotes){$t([]);return}try{const Oe=await e.getRemotes(n);$t(Oe)}catch{$t([])}},[n,e]);l.useEffect(()=>{es()},[es]),l.useEffect(()=>{if(!je){is([]);return}let Oe=!1;const Ze=r0();return Ze&&(is(Ze.gitmojis),i0(Ze))?()=>{Oe=!0}:((async()=>{try{const dt=await fetch(n0);if(!dt.ok)throw new Error(`Failed to load gitmojis: ${dt.statusText}`);const Ot=await dt.json(),Jt=Array.isArray(Ot.gitmojis)?Ot.gitmojis.filter(Df):[];Oe||(is(Jt),a0(Jt))}catch(dt){Oe||console.warn("Failed to load gitmoji list:",dt)}})(),()=>{Oe=!0})},[je]),l.useEffect(()=>{n&&(L(n),B(n,e))},[n,L,B,e]),l.useEffect(()=>{if(n)return yr.onGitRefreshHint(Oe=>{ua(Oe.directory)===ua(n)&&O(n,e)})},[n,O,e]);const Ut=l.useCallback(async(Oe=!0)=>{if(n)try{await Promise.all([O(n,e),_(n,e)])}catch(Ze){if(Oe){const tt=Ze instanceof Error?Ze.message:t("gitView.toast.refreshRepositoryFailed");H.error(tt)}}},[n,e,O,_,t]),os=l.useCallback(async()=>{n&&await ee(n,e,ze)},[n,e,ee,ze]),en=l.useCallback(async()=>{n&&await z(n,e)},[n,e,z]);l.useEffect(()=>{if(!n||!e?.hasLocalIdentity||D!==!0)return;const Oe=typeof g=="string"?g.trim():"";if(!Oe||Oe==="global"||ge.current.get(n)===Oe)return;let tt=!1;return(async()=>{try{const Ot=await e.hasLocalIdentity?.(n);if(tt||Ot===!0)return;ie(),await e.setGitIdentity(n,Oe),ge.current.set(n,Oe),await en()}catch(Ot){console.warn("Failed to auto-apply default git identity:",Ot)}finally{tt||Me()}})(),()=>{tt=!0}},[ie,n,g,Me,e,D,en]);const qs=l.useMemo(()=>{if(!j)return[];const Oe=j.files??[],Ze=new Map;for(const tt of Oe)Ze.set(tt.path,tt);return Array.from(Ze.values()).sort((tt,dt)=>tt.path.localeCompare(dt.path))},[j]);l.useEffect(()=>{if(!n||qs.length===0)return;const Oe=[],Ze=new Set,tt=Ot=>{!Ot||Ze.has(Ot)||(Ze.add(Ot),Oe.push(Ot))};if(Array.from(Ve).forEach(tt),Z.forEach(tt),qs.slice(0,s0).forEach(Ot=>tt(Ot.path)),Oe.length===0)return;const dt=window.setTimeout(()=>{ne(n,e,Oe,{maxFiles:t0})},120);return()=>{window.clearTimeout(dt)}},[qs,n,e,ne,Ve,Z]),l.useEffect(()=>{if(!j||qs.length===0){Ce(new Set),De(!1);return}Ce(Oe=>{const Ze=new Set,tt=Oe??new Set;for(const dt of qs)tt.has(dt.path)?Ze.add(dt.path):xe||Ze.add(dt.path);return Ze})},[j,qs,xe]);const zs=async(Oe,Ze)=>{if(n){fe(Oe);try{const tt=dt=>{const Ot=`${dt.name}/`,Jt=j?.tracking?.startsWith(Ot)?j.tracking.slice(Ot.length):void 0;return{remote:dt.name,branch:Jt,rebase:!0}};if(Oe==="fetch"){if(!Ze)throw new Error("No remote available for fetch");await e.gitFetch(n,{remote:Ze.name}),H.success(t("gitView.toast.fetchedFromRemote",{name:Ze.name}))}else if(Oe==="pull"){if(!Ze)throw new Error("No remote available for pull");const dt=await e.gitPull(n,tt(Ze));H.success(dt.files.length===1?t("gitView.toast.pulledFilesSingle",{count:dt.files.length,name:Ze.name}):t("gitView.toast.pulledFilesPlural",{count:dt.files.length,name:Ze.name}))}else if(Oe==="push")await e.gitPush(n),H.success(t("gitView.toast.pushedToUpstream"));else if(Oe==="sync"){if(!Ze)throw new Error("No remote available for sync");let dt=0,Ot=!1;await e.gitFetch(n,{remote:Ze.name});const Jt=await e.getGitStatus(n);if((Jt.behind??0)>0){if((Jt.files?.length??0)>0){H.error(t("gitView.toast.commitOrStashBeforeSync"));return}dt=(await e.gitPull(n,tt(Ze))).files.length}((await e.getGitStatus(n)).ahead??0)>0&&(await e.gitPush(n),Ot=!0),dt>0&&Ot?H.success(dt===1?t("gitView.toast.syncedPulledSingleAndPushed",{count:dt,name:Ze.name}):t("gitView.toast.syncedPulledPluralAndPushed",{count:dt,name:Ze.name})):dt>0?H.success(dt===1?t("gitView.toast.pulledFilesSingle",{count:dt,name:Ze.name}):t("gitView.toast.pulledFilesPlural",{count:dt,name:Ze.name})):Ot?H.success(t("gitView.toast.pushedToUpstream")):H.success(t("gitView.toast.alreadyUpToDate"))}await Ut(!1),await os()}catch(tt){const dt=tt instanceof Error?tt.message:t("gitView.toast.syncActionFailed",{action:Oe==="sync"?t("gitView.sync.syncChanges"):Oe==="pull"?t("gitView.sync.pull"):Oe});H.error(dt)}finally{fe(null)}}},un=l.useCallback(async Oe=>{if(!n)return;const Ze=Oe.name.trim();if(!Ze){H.error(t("gitView.toast.remoteNameRequired"));return}if(Ze==="origin"){H.error(t("gitView.toast.cannotRemoveOriginRemote"));return}Ms(Ze);try{await e.removeRemote(n,{remote:Ze}),H.success(t("gitView.toast.removedRemote",{name:Ze})),await Promise.all([Ut(!1),es()])}catch(tt){const dt=tt instanceof Error?tt.message:`Failed to remove ${Ze}`;H.error(dt)}finally{Ms(null)}},[n,e,es,Ut,t]),Qs=async(Oe={})=>{if(!n)return;if(!K.trim()){H.error(t("gitView.toast.enterCommitMessage"));return}const Ze=Array.from(Ve).sort();if(Ze.length===0){H.error(t("gitView.toast.selectFileToCommit"));return}const tt=Oe.pushAfter?"commitAndPush":"commit";Ee(tt);try{if(await e.createGitCommit(n,K.trim(),{files:Ze}),H.success(t("gitView.toast.commitCreated")),ce(""),Ce(new Set),De(!1),We(),await Ut(),Oe.pushAfter){fe("sync");const dt=j?.tracking?.split("/")[0],Ot=Mn.find(Ba=>Ba.name===dt)??Mn[0];if(!Ot)throw new Error("No remote available for sync");const Jt=`${Ot.name}/`,_s=j?.tracking?.startsWith(Jt)?j.tracking.slice(Jt.length):void 0;let hn=0,zn=!1;await e.gitFetch(n,{remote:Ot.name}),((await e.getGitStatus(n)).behind??0)>0&&(hn=(await e.gitPull(n,{remote:Ot.name,branch:_s,rebase:!0})).files.length),((await e.getGitStatus(n)).ahead??0)>0&&(await e.gitPush(n),zn=!0),hn>0&&zn?H.success(hn===1?t("gitView.toast.syncedPulledSingleAndPushed",{count:hn,name:Ot.name}):t("gitView.toast.syncedPulledPluralAndPushed",{count:hn,name:Ot.name})):hn>0?H.success(hn===1?t("gitView.toast.pulledFilesSingle",{count:hn,name:Ot.name}):t("gitView.toast.pulledFilesPlural",{count:hn,name:Ot.name})):zn?H.success(t("gitView.toast.pushedToUpstream")):H.success(t("gitView.toast.alreadyUpToDate")),Ae(),await Ut(!1)}else await Ut(!1);await os(),et(dt=>dt+1)}catch(dt){const Ot=dt instanceof Error?dt.message:t("gitView.toast.createCommitFailed");H.error(Ot)}finally{Ee(null),Oe.pushAfter&&fe(null)}},mn=l.useCallback(async()=>{if(n){if(Ve.size===0){H.error(t("gitView.toast.selectFileToDescribe"));return}console.error("[git-generation][browser] generate button clicked",{directory:n,selectedFiles:Ve.size}),st(!0);try{const{message:Oe}=await mb(n,Array.from(Ve)),Ze=Oe.subject?.trim()??"",tt=Array.isArray(Oe.highlights)?Oe.highlights:[];if(Ze){let dt=Ze;if(je&&Wt.length>0){const Ot=o0(Ze,Wt);if(Ot){const{code:Jt,emoji:_s}=Ot;!Ze.startsWith(Jt)&&!Ze.startsWith(_s)&&(dt=`${Jt} ${Ze}`)}}ce(dt)}ye(tt),Je()}catch(Oe){console.error("[git-generation][browser] GitView generate handler failed",{message:Oe instanceof Error?Oe.message:String(Oe),error:Oe});const Ze=Oe instanceof Error?Oe.message:t("gitView.toast.generateCommitMessageFailed");H.error(Ze)}finally{st(!1)}}},[n,Ve,je,Wt,Je,t]),ln=Oe=>Oe.reason==="attention"?`${Oe.attentionReason} in progress`:Oe.reason==="missing"?"worktree is missing":"worktree is invalid",wn=async(Oe,Ze)=>{if(!n||!j)return;const tt=Hl(S);if(tt.length>0){H.error(t("gitView.toast.cannotCreateBranch",{reason:ln(tt[0])}));return}const dt=j.current??null,Ot=Ze?.name??"origin";try{await e.createBranch(n,Oe,dt??"HEAD"),H.success(t("gitView.toast.createdBranch",{name:Oe})),await e.checkoutBranch(n,Oe);let Jt=!1;try{await e.gitPush(n,{remote:Ot,branch:Oe,options:["--set-upstream"]}),Jt=!0}catch(_s){const hn=_s instanceof Error?_s.message:`Unable to push new branch to ${Ot}.`;H.warning(t("gitView.toast.branchCreatedLocally"),{description:s.jsxs("span",{className:"text-foreground/80 dark:text-foreground/70",children:["Upstream setup failed: ",hn]})})}await Ut(),await os(),Jt&&H.success(t("gitView.toast.upstreamSet",{branch:Oe,remote:Ot}))}catch(Jt){const _s=Jt instanceof Error?Jt.message:t("gitView.toast.createBranchFailed");throw H.error(_s),Jt}},tn=async(Oe,Ze)=>{if(!n)return;const tt=Hl(S);if(tt.length>0){H.error(t("gitView.toast.cannotRenameBranch",{reason:ln(tt[0])}));return}try{await e.renameBranch(n,Oe,Ze),H.success(t("gitView.toast.renamedBranch",{oldName:Oe,newName:Ze})),await Ut(),await os()}catch(dt){const Ot=dt instanceof Error?dt.message:t("gitView.toast.renameBranchFailed",{oldName:Oe,newName:Ze});H.error(Ot)}},fn=async Oe=>{if(!n)return;const Ze=Hl(S);if(Ze.length>0){H.error(t("gitView.toast.cannotCheckout",{reason:ln(Ze[0])}));return}const tt=Oe.replace(/^remotes\//,"");if(j?.current!==tt)try{await e.checkoutBranch(n,tt),H.success(t("gitView.toast.checkedOut",{name:tt})),await Ut(),await os()}catch(dt){const Ot=dt instanceof Error?dt.message:t("gitView.toast.checkoutFailed",{name:tt});H.error(Ot)}},hr=async Oe=>{if(n){ie();try{await e.setGitIdentity(n,Oe.id),H.success(t("gitView.toast.appliedIdentity",{name:Oe.name})),await en()}catch(Ze){const tt=Ze instanceof Error?Ze.message:t("gitView.toast.applyIdentityFailed");H.error(tt)}finally{Me()}}},Fn=l.useMemo(()=>C?.all?C.all.filter(Oe=>!Oe.startsWith("remotes/")).sort():[],[C]),Tn=l.useMemo(()=>C?.all?C.all.filter(Oe=>Oe.startsWith("remotes/")).map(Oe=>Oe.replace(/^remotes\//,"")).sort():[],[C]),Mn=l.useMemo(()=>{if(wt.length>0)return wt;const Oe=new Set,Ze=j?.tracking?.trim();Ze&&Ze.includes("/")&&Oe.add(Ze.split("/")[0]);for(const tt of Tn){const dt=tt.indexOf("/");dt>0&&Oe.add(tt.slice(0,dt))}return Oe.size===0&&Gt&&Oe.add("origin"),Array.from(Oe).map(tt=>({name:tt,fetchUrl:Gt??"",pushUrl:Gt??""}))},[wt,Tn,Gt,j?.tracking]),$e=l.useMemo(()=>{const Oe=new Set(Mn.map(Ot=>Ot.name)),Ze=Ot=>{if(!Ot)return"";let Jt=Ot.trim();if(!Jt||Jt==="HEAD")return"";if(Fn.includes(Jt))return Jt;Jt.startsWith("refs/heads/")&&(Jt=Jt.slice(11)),Jt.startsWith("heads/")&&(Jt=Jt.slice(6)),Jt.startsWith("remotes/")&&(Jt=Jt.slice(8));const _s=Jt.indexOf("/");if(_s>0){const hn=Jt.slice(0,_s);if(Oe.has(hn)){const zn=Jt.slice(_s+1).trim();zn&&(Jt=zn)}}return Jt},tt=Ze(typeof P?.createdFromBranch=="string"?P.createdFromBranch:"");if(tt)return tt;const dt=Ze(typeof oe=="string"?oe:"");return dt||(Fn.includes("main")?"main":Fn.includes("master")?"master":Fn.includes("develop")?"develop":"main")},[Mn,Fn,oe,P?.createdFromBranch]),Ft=l.useMemo(()=>Mn.map(tt=>tt.name).map(tt=>`${tt}/${$e}`).find(tt=>Tn.includes(tt))??$e,[$e,Mn,Tn]),as=l.useMemo(()=>{const Oe=new Map;x&&Oe.set(x.id,x);let Ze=null;if(Gt)try{let tt=Gt.trim();tt.startsWith("git@")&&(tt=`https://${tt.slice(4).replace(":","/")}`),tt.endsWith(".git")&&(tt=tt.slice(0,-4));const dt=new URL(tt);Ze=dt.hostname+dt.pathname}catch{}for(const tt of v){if(tt.authType!=="token"){Oe.set(tt.id,tt);continue}const dt=tt.host;if(!dt){Oe.set(tt.id,tt);continue}if(!dt.includes("/")){Oe.set(tt.id,tt);continue}Ze&&Ze===dt&&Oe.set(tt.id,tt)}return Array.from(Oe.values())},[v,x,Gt]),fs=l.useMemo(()=>{if(T?.userName&&T?.userEmail){const Oe=v.find(Ze=>Ze.userName===T.userName&&Ze.userEmail===T.userEmail);return Oe||(x&&x.userName===T.userName&&x.userEmail===T.userEmail?x:{id:"local-config",name:T.userName,userName:T.userName,userEmail:T.userEmail,sshKey:T.sshCommand?.replace("ssh -i ","")??null,color:"info",icon:"user"})}return x??null},[T,v,x]),Gs=Ve.size,Hs=M||Y!==null||pe!==null,Ss=j?.current??null,Ys=!!(P&&_e&&Ue&&ot),on=!!(n&&Ss),sr=!!Ss,Hn=Ys&&_e&&Ue&&P?{repoRoot:_e,sourceBranch:Ue,worktreeMetadata:P}:null,Gn=l.useMemo(()=>!on||!n||!Ss?null:{directory:n,branch:Ss},[on,Ss,n]);l.useEffect(()=>{if(!n||!e||!N?.all?.length||!Ss||!$e||Ss===$e){ut(null);return}let Oe=!1;return(async()=>{try{const tt=await e.getGitLog(n,{from:$e,to:"HEAD",maxCount:ze});if(Oe)return;const dt=new Set((tt?.all??[]).map(Jt=>Jt.hash).filter(Jt=>typeof Jt=="string"&&Jt.length>0));if(dt.size===0){ut(null);return}const Ot=N.all.findIndex(Jt=>!dt.has(Jt.hash));if(Ot===0){ut(null);return}if(Ot===-1){ut({insertBeforeIndex:N.all.length,branchName:Ss,direction:"up"});return}ut({insertBeforeIndex:Ot,branchName:Ss,direction:"up"})}catch{Oe||ut(null)}})(),()=>{Oe=!0}},[$e,Ss,n,e,N,ze]);const Rr=Oe=>{Ce(Ze=>{const tt=new Set(Ze);return tt.has(Oe)?tt.delete(Oe):tt.add(Oe),tt}),De(!0)},Nr=()=>{const Oe=new Set(qs.map(Ze=>Ze.path));Ce(Oe),De(!0)},Zs=()=>{Ce(new Set),De(!0)},Vn=l.useCallback(async Oe=>{if(n){rt(Ze=>{const tt=new Set(Ze);return tt.add(Oe),tt});try{await e.revertGitFile(n,Oe),H.success(t("gitView.toast.revertedFile",{path:Oe})),await Ut(!1)}catch(Ze){const tt=Ze instanceof Error?Ze.message:t("gitView.toast.revertFailed");H.error(tt)}finally{rt(Ze=>{const tt=new Set(Ze);return tt.delete(Oe),tt})}}},[n,Ut,e,t]),Cn=l.useCallback(async Oe=>{if(!n||Oe.length===0||Re)return;const Ze=Array.from(new Set(Oe));he(!0),rt(dt=>{const Ot=new Set(dt);return Ze.forEach(Jt=>Ot.add(Jt)),Ot});const tt=[];try{if(await Promise.all(Ze.map(async dt=>{try{await e.revertGitFile(n,dt)}catch(Ot){tt.push({path:dt,message:Ot instanceof Error?Ot.message:t("gitView.toast.revertFailed")})}})),await Ut(!1),tt.length===0)H.success(Ze.length===1?t("gitView.toast.revertedFilesSingle",{count:Ze.length}):t("gitView.toast.revertedFilesPlural",{count:Ze.length}));else if(tt.length===Ze.length)H.error(tt[0]?.message||t("gitView.toast.revertFailed"));else{const dt=Ze.length-tt.length;H.warning(dt===1?t("gitView.toast.revertedSomeSingle",{success:dt,failed:tt.length}):t("gitView.toast.revertedSomePlural",{success:dt,failed:tt.length}))}}finally{rt(dt=>{const Ot=new Set(dt);return Ze.forEach(Jt=>Ot.delete(Jt)),Ot}),he(!1)}},[n,e,Re,Ut,t]),Zn=l.useCallback(Oe=>{if(Oe.length===0)return;const Ze=Oe.map(tt=>tt.trim()).filter(Boolean);if(Ze.length===0){We();return}ce(tt=>{const dt=tt.trim(),Ot=dt.length>0?`
11
-
12
- `:"";return`${dt}${Ot}${Ze.join(`
13
- `)}`.trim()}),We()},[We]),fr=l.useCallback((Oe,Ze)=>{const tt=Ze||Oe;ce(dt=>{const Ot=dt.trimStart();return Ot.startsWith(Oe)||Ze&&Ot.startsWith(Ze)?dt:`${tt.endsWith(" ")?tt:`${tt} `}${dt}`.trimStart()}),ps(""),Ie(!1)},[]),Dr=l.useCallback(Oe=>{G(Oe),n&&(re(n,Oe),ee(n,e,Oe))},[n,re,ee,e]),nr=l.useCallback(Oe=>{const Ze=Oe instanceof Error?Oe.message.toLowerCase():"";return Ze.includes("uncommitted changes")||Ze.includes("local changes")||Ze.includes("your local changes would be overwritten")||Ze.includes("please commit your changes or stash them")||Ze.includes("cannot rebase: you have unstaged changes")||Ze.includes("error: cannot pull with rebase")},[]),Ln=l.useCallback((Oe,Ze)=>{ft(tt=>[...tt,{message:Oe,status:Ze,timestamp:Date.now()}])},[]),vn=l.useCallback((Oe,Ze)=>{ft(tt=>{if(tt.length===0)return tt;const dt=[...tt];return dt[dt.length-1]={...dt[dt.length-1],status:Oe,...Ze?{message:Ze}:{}},dt})},[]),pn=l.useCallback(()=>{ft([])},[]),En=l.useCallback(()=>{ft([]),Is(null)},[]),Fr=l.useCallback(Oe=>{const Ze=Oe.trim(),tt=new Set(Mn.map(Ot=>Ot.name)),dt=Ze.indexOf("/");if(dt>0){const Ot=Ze.slice(0,dt),Jt=Ze.slice(dt+1);if(tt.has(Ot)&&Jt)return{branch:Ze,remote:Ot,remoteBranch:Jt}}for(const Ot of Mn){const Jt=`${Ot.name}/${Ze}`;if(Tn.includes(Jt))return{branch:Jt,remote:Ot.name,remoteBranch:Ze}}return{branch:Ze,remote:null,remoteBranch:null}},[Mn,Tn]),Wr=l.useCallback(async Oe=>{if(!n)return;Is("merge"),pn();const Ze=j?.current,tt=Fr(Oe);try{tt.remote&&tt.remoteBranch&&(Ln(`Fetching ${tt.remote}/${tt.remoteBranch}...`,"running"),await e.gitFetch(n,{remote:tt.remote,branch:tt.remoteBranch}),vn("done",`Fetched ${tt.remote}/${tt.remoteBranch}`)),Ln(`Merging ${tt.branch} into ${Ze}...`,"running");const dt=await e.merge(n,{branch:tt.branch});dt.conflict?(vn("error","Merge conflicts detected"),vt(dt.conflictFiles??[]),Yt("merge"),J(!0),Ps(n,dt.conflictFiles??[],"merge")):(vn("done",`Merged ${tt.branch} into ${Ze}`),As(),Ln("Refreshing repository status...","running"),await Ut(),await os(),vn("done","Repository status updated"))}catch(dt){if(nr(dt))vn("error","Uncommitted changes detected"),Rt("merge"),it(tt.branch),yt(!0);else{const Ot=dt instanceof Error?dt.message:`Failed to merge ${tt.branch}`;vn("error",Ot)}}},[n,e,j,Fr,Ut,os,nr,Ps,As,Ln,vn,pn]),Kr=l.useCallback(async Oe=>{if(!n)return;Is("rebase"),pn();const Ze=j?.current,tt=Fr(Oe);try{tt.remote&&tt.remoteBranch&&(Ln(`Fetching ${tt.remote}/${tt.remoteBranch}...`,"running"),await e.gitFetch(n,{remote:tt.remote,branch:tt.remoteBranch}),vn("done",`Fetched ${tt.remote}/${tt.remoteBranch}`)),Ln(`Rebasing ${Ze} onto ${tt.branch}...`,"running");const dt=await e.rebase(n,{onto:tt.branch});dt.conflict?(vn("error","Rebase conflicts detected"),vt(dt.conflictFiles??[]),Yt("rebase"),J(!0),Ps(n,dt.conflictFiles??[],"rebase")):(vn("done",`Rebased ${Ze} onto ${tt.branch}`),As(),Ln("Refreshing repository status...","running"),await Ut(),await os(),vn("done","Repository status updated"))}catch(dt){if(nr(dt))vn("error","Uncommitted changes detected"),Rt("rebase"),it(tt.branch),yt(!0);else{const Ot=dt instanceof Error?dt.message:`Failed to rebase onto ${tt.branch}`;vn("error",Ot)}}},[n,e,j,Fr,Ut,os,nr,Ps,As,Ln,vn,pn]),La=l.useCallback(async()=>{if(n)try{Tt==="merge"?(await e.abortMerge(n),H.success(t("gitView.toast.mergeAborted"))):(await e.abortRebase(n),H.success(t("gitView.toast.rebaseAborted"))),As(),await Ut(),await os()}catch(Oe){const Ze=Oe instanceof Error?Oe.message:`Failed to abort ${Tt}`;H.error(Ze)}},[n,e,Tt,Ut,os,As,t]),jn=l.useMemo(()=>j?.files?j.files.some(Oe=>Oe.index==="U"||Oe.working_dir==="U"||Oe.index==="A"&&Oe.working_dir==="A"||Oe.index==="D"&&Oe.working_dir==="D"):!1,[j?.files]),aa=l.useCallback(async()=>{if(n)try{const Oe=!!j?.mergeInProgress?.head,Ze=!!(j?.rebaseInProgress?.headName||j?.rebaseInProgress?.onto);if(Oe){const tt=await e.continueMerge(n);tt.conflict?(vt(tt.conflictFiles??[]),Yt("merge"),J(!0),Ps(n,tt.conflictFiles??[],"merge"),H.error(t("gitView.toast.mergeConflictsDetected"))):(As(),H.success(t("gitView.toast.mergeCompleted")),await Ut(),await os())}else if(Ze){const tt=await e.continueRebase(n);tt.conflict?(vt(tt.conflictFiles??[]),Yt("rebase"),J(!0),Ps(n,tt.conflictFiles??[],"rebase"),H.error(t("gitView.toast.rebaseConflictsDetected"))):(As(),H.success(t("gitView.toast.rebaseStepCompleted")),await Ut(),await os())}}catch(Oe){const Ze=Oe instanceof Error?Oe.message:t("gitView.toast.continueOperationFailed");H.error(Ze)}},[n,e,j,Ut,os,Ps,As,t]),yi=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"))),As(),await Ut(),await os()}catch(Oe){const Ze=Oe instanceof Error?Oe.message:t("gitView.toast.abortOperationFailed");H.error(Ze)}},[n,e,j,Ut,os,As,t]),Oa=l.useCallback(()=>{if(!n)return;const Ze=!!j?.mergeInProgress?.head?"merge":"rebase",tt=j?.files?.filter(dt=>dt.index==="U"||dt.working_dir==="U").map(dt=>dt.path)??[];tt.length>0&&vt(tt),Yt(Ze),J(!0)},[n,j]),ia=l.useCallback(async Oe=>{if(!n)return;const Ze=j?.current,tt=It,dt=ss;try{await e.stash(n,{message:`Auto-stash before ${tt} with ${dt}`,includeUntracked:!0})}catch(_s){const hn=_s instanceof Error?_s.message:"Failed to stash changes";H.error(hn);return}let Ot=!1,Jt=!1;try{if(tt==="merge"){const _s=await e.merge(n,{branch:dt});_s.conflict?(Jt=!0,vt(_s.conflictFiles??[]),Yt("merge"),J(!0)):(Ot=!0,H.success(t("gitView.toast.mergedIntoBranch",{branch:dt,currentBranch:Ze||""})))}else{const _s=await e.rebase(n,{onto:dt});_s.conflict?(Jt=!0,vt(_s.conflictFiles??[]),Yt("rebase"),J(!0)):(Ot=!0,H.success(t("gitView.toast.rebasedOntoBranch",{currentBranch:Ze||"",branch:dt})))}if(Oe&&Ot)try{await e.stashPop(n),H.success(t("gitView.toast.stashedRestored"))}catch(_s){const hn=_s instanceof Error?_s.message:t("gitView.toast.restoreStashFailed");H.error(hn)}else Oe&&Jt&&H.info(t("gitView.toast.restoreStashManually"));await Ut(),await os()}catch(_s){if(Oe)try{await e.stashPop(n)}catch{}throw _s}},[n,e,j,It,ss,Ut,os,t]);return n?M&&D===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(I,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"typography-ui-label",children:t("gitView.loading.checkingRepository")})]})}):D===!1?U?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-4 text-center",children:[s.jsx(I,{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(I,{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")}),A.includes("open-without-worktree-features")?s.jsx("p",{className:"typography-meta mt-2 text-muted-foreground",children:t("gitView.empty.worktreeFeaturesUnavailable")}):null]}):s.jsxs("div",{className:me("flex h-full flex-col overflow-hidden","bg-sidebar"),children:[s.jsx(Vw,{status:j,localBranches:Fn,remoteBranches:Tn,branchInfo:C?.branches,syncAction:Y,remotes:Mn,onFetch:Oe=>zs("fetch",Oe),onSync:Oe=>zs("sync",Oe),onRemoveRemote:un,removingRemoteName:qt,onCheckoutBranch:fn,onCreateBranch:wn,onRenameBranch:tn,activeIdentityProfile:fs,availableIdentities:as,onSelectIdentity:hr,isApplyingIdentity:Pe,isWorktreeMode:!!P,onOpenHistory:()=>Mt(!0),actionTabItems:He,activeActionTab:At,onSelectActionTab:Oe=>Et(Oe)}),n&&(j?.mergeInProgress?.head||j?.rebaseInProgress?.headName||j?.rebaseInProgress?.onto)&&s.jsx(Hj,{mergeInProgress:j?.mergeInProgress,rebaseInProgress:j?.rebaseInProgress,onContinue:aa,onAbort:yi,onResolveWithAI:Oa,hasUnresolvedConflicts:jn,isLoading:M}),s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:s.jsx("div",{className:"h-full min-h-0 flex flex-col",children:s.jsx("div",{className:me("min-w-0 min-h-0 h-full flex flex-col","bg-sidebar"),children:s.jsxs(Ts,{as:eo,ref:Ne,outerClassName:"flex-1 min-h-0",className:me("px-4","pt-1 pb-4"),disableHorizontal:!0,preventOverscroll:!0,children:[At==="commit"?s.jsx("div",{className:"space-y-4",children:(qs?.length??0)>0?s.jsxs(s.Fragment,{children:[s.jsx(Yw,{maxListHeightClassName:"max-h-[40vh]",changeEntries:qs,onVisiblePathsChange:le,selectedPaths:Ve,diffStats:j?.diffStats,revertingPaths:Ye,onToggleFile:Rr,onSelectAll:Nr,onClearSelection:Zs,onRevertAll:Cn,onViewDiff:Oe=>{if(n&&!ue){Q(n,Oe);return}de(Oe),ue&&X(!1)},onRevertFile:Vn,isRevertingAll:Re,onOpenStashes:()=>be(!0)}),s.jsx(sj,{selectedCount:Gs,commitMessage:K,onCommitMessageChange:ce,generatedHighlights:nt,onInsertHighlights:Zn,onGenerateMessage:mn,isGeneratingMessage:Ke,onCommit:()=>Qs({pushAfter:!1}),onCommitAndPush:()=>Qs({pushAfter:!0}),commitAction:pe,gitmojiEnabled:je,onOpenGitmojiPicker:()=>Ie(!0)})]}):s.jsx(nj,{onOpenStashes:()=>be(!0)})}):null,At==="branch"?s.jsx("div",{className:"space-y-4",children:sr?s.jsxs(s.Fragment,{children:[s.jsx(Gj,{mode:"inline",currentBranch:j?.current,localBranches:Fn,remoteBranches:Tn,defaultTargetBranch:Ft,onMerge:Wr,onRebase:Kr,disabled:Hs,isOperating:cs!==null,operationLogs:Es,onOperationComplete:En}),Hn?s.jsx(Ew,{repoRoot:Hn.repoRoot,sourceBranch:Hn.sourceBranch,worktreeMetadata:Hn.worktreeMetadata,localBranches:Fn,defaultTargetBranch:Xe,refreshKey:qe,onRefresh:()=>{n&&(O(n,e),_(n,e),ee(n,e,ze))}},Hn.worktreeMetadata.path):null]}):s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("gitView.branch.actionsUnavailable")})}):null,At==="pr"?s.jsx("div",{className:"space-y-4",children:Gn?s.jsx(Oj,{directory:Gn.directory,branch:Gn.branch,baseBranch:$e,trackingBranch:j?.tracking??void 0,remotes:wt,remoteBranches:Tn,onGeneratedDescription:Je}):s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:t("gitView.pullRequest.title")}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:t("gitView.pullRequest.createHint")})]})}):null]})})})}),s.jsx(ws,{open:Ns,onOpenChange:Mt,children:s.jsxs(vs,{className:"max-w-5xl h-[90vh] max-h-[90vh] flex flex-col overflow-hidden",children:[s.jsxs(Cs,{children:[s.jsx(js,{children:t("gitView.history.title")}),s.jsx(Rs,{children:t("gitView.history.dialogDescription")})]}),s.jsx("div",{className:"flex-1 min-h-0",children:s.jsx(oj,{log:N,isLogLoading:R,logMaxCount:ze,onLogMaxCountChange:Dr,expandedCommitHashes:bt,onToggleCommit:bs,commitFilesMap:Ht,loadingCommitHashes:jt,onCopyHash:Bt,showHeader:!1,contentMaxHeightClassName:"h-full max-h-none",branchDivider:ns})})]})}),s.jsx(zw,{open:ke,onOpenChange:be,directory:n,hasUncommittedChanges:(j?.files?.length??0)>0,uncommittedFileCount:j?.files?.length??0,onChanged:async()=>{await Ut(!1),await os()}}),s.jsx(ws,{open:se,onOpenChange:Ie,children:s.jsxs(vs,{className:"max-w-md p-0 overflow-hidden",children:[s.jsx(Cs,{className:"px-4 pt-4",children:s.jsx(js,{children:t("gitView.gitmoji.title")})}),s.jsxs(Ta,{className:"h-[420px]",children:[s.jsx(ra,{placeholder:t("gitView.gitmoji.searchPlaceholder"),value:gs,onValueChange:ps}),s.jsxs(Ma,{children:[s.jsx(Ea,{children:t("gitView.gitmoji.empty")}),s.jsx(Bn,{children:(Wt.length===0?[]:Wt.filter(Oe=>{const Ze=gs.trim().toLowerCase();return Ze?Oe.emoji.includes(Ze)||Oe.code.toLowerCase().includes(Ze)||Oe.description.toLowerCase().includes(Ze):!0})).map(Oe=>s.jsxs(An,{onSelect:()=>fr(Oe.emoji,Oe.code),children:[s.jsx("span",{className:"text-lg",children:Oe.emoji}),s.jsx("span",{className:"typography-ui-label text-foreground",children:Oe.code}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:Oe.description})]},Oe.code))})]})]})]})}),n&&s.jsx($j,{open:hs,onOpenChange:J,conflictFiles:ct,directory:n,operation:Tt,onAbort:La,onClearState:As}),s.jsx(Kj,{open:Ge,onOpenChange:yt,operation:It,targetBranch:ss,onConfirm:ia})]}):s.jsx("div",{className:"flex h-full items-center justify-center px-4 text-center",children:s.jsx("p",{className:"typography-ui-label text-muted-foreground",children:t("gitView.empty.selectSessionOrDirectory")})})},l0=Object.freeze(Object.defineProperty({__proto__:null,GitView:Tf},Symbol.toStringTag,{value:"Module"})),td=5e3,c0=(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},d0=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"},u0=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()},Hd=async(t,e)=>{try{const n=await u0(t,e);return c0(n,td)>td?{ok:!1,reason:"too-large"}:{ok:!0}}catch(n){return{ok:!1,reason:d0(n)}}},Gd=t=>t==="too-large"?`File is too large to open (>${td.toLocaleString()} lines)`:t==="missing"?"File not found":"Failed to open file",m0=t=>t.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),Wn=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},Mf=(t,e)=>{const n=Wn(e),r=Wn(t).replace(/\/+$/,"");return n===r?".":!r||!n.startsWith(`${r}/`)?n:n.slice(r.length+1)},p0=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),h0=new Set(["node_modules"]),f0=t=>h0.has(t),g0=t=>{const e=Wn(t);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},Ef=(t,e)=>s.jsx(br,{filePath:t,extension:e}),x0=t=>{const e=at.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},b0=t=>{const e=at.c(63),{node:n,root:r,isExpanded:a,isActive:i,status:o,badge:c,permissions:d,downloadFile:p,contextMenuPath:m,setContextMenuPath:u,onSelect:h,onToggle:b,onRevealPath:f,onOpenDialog:v}=t,{t:x}=pt(),g=n.type==="directory",{canRename:w,canCreateFile:y,canCreateFolder:k,canDelete:D,canReveal:j}=d;let S;e[0]!==y||e[1]!==k||e[2]!==D||e[3]!==w||e[4]!==j||e[5]!==n.path||e[6]!==u?(S=re=>{!w&&!y&&!k&&!D&&!j||(re?.preventDefault(),u(n.path))},e[0]=y,e[1]=k,e[2]=D,e[3]=w,e[4]=j,e[5]=n.path,e[6]=u,e[7]=S):S=e[7];const A=S;let E;e[8]!==g||e[9]!==n||e[10]!==h||e[11]!==b?(E=()=>{g?b(n.path):h(n)},e[8]=g,e[9]=n,e[10]=h,e[11]=b,e[12]=E):E=e[12];const P=E;let C;e[13]!==n.path||e[14]!==u?(C=re=>{re.stopPropagation(),u(n.path)},e[13]=n.path,e[14]=u,e[15]=C):C=e[15];const N=C;let T;e[16]!==n.path||e[17]!==r?(T=re=>{const ue=Mf(r,n.path);!ue||ue==="."||(re.dataTransfer.setData("application/x-openchamber-file-path",ue),re.dataTransfer.effectAllowed="copy")},e[16]=n.path,e[17]=r,e[18]=T):T=e[18];const M=T,R=i?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let L;e[19]!==R?(L=me("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",R,"cursor-grab active:cursor-grabbing"),e[19]=R,e[20]=L):L=e[20];let $;e[21]!==g||e[22]!==a||e[23]!==n.extension||e[24]!==n.path?($=g?a?s.jsx(I,{name:"folder-open-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):s.jsx(I,{name:"folder-3-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):Ef(n.path,n.extension),e[21]=g,e[22]=a,e[23]=n.extension,e[24]=n.path,e[25]=$):$=e[25];let B;e[26]!==n.name||e[27]!==n.path?(B=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]=B):B=e[28];let O;e[29]!==g||e[30]!==o?(O=!g&&o&&s.jsx(x0,{status:o}),e[29]=g,e[30]=o,e[31]=O):O=e[31];let _;e[32]!==c||e[33]!==g?(_=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]=_):_=e[34];let ee;e[35]!==A||e[36]!==M||e[37]!==P||e[38]!==_||e[39]!==L||e[40]!==$||e[41]!==B||e[42]!==O?(ee=s.jsxs("button",{type:"button",onClick:P,onContextMenu:A,draggable:!0,onDragStart:M,className:L,children:[$,B,O,_]}),e[35]=A,e[36]=M,e[37]=P,e[38]=_,e[39]=L,e[40]=$,e[41]=B,e[42]=O,e[43]=ee):ee=e[43];let z;e[44]!==y||e[45]!==k||e[46]!==D||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]!==f||e[56]!==u||e[57]!==x?(z=(w||y||k||D||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(Bs,{open:m===n.path,onOpenChange:re=>u(re?n.path:null),children:[s.jsx(Os,{asChild:!0,children:s.jsx(we,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:N,children:s.jsx(I,{name:"more-2-fill",className:"h-4 w-4"})})}),s.jsxs($s,{align:"end",side:"bottom",onCloseAutoFocus:()=>u(null),children:[w&&s.jsxs(zt,{onClick:re=>{re.stopPropagation(),v("rename",n)},children:[s.jsx(I,{name:"edit",className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.rename")]}),s.jsxs(zt,{onClick:re=>{re.stopPropagation(),Rn(n.path).then(ue=>{if(ue.ok){H.success(x("sidebarFilesTree.toast.pathCopied"));return}H.error(x("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(I,{name:"file-copy",className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.copyPath")]}),!g&&p&&s.jsxs(zt,{onClick:re=>{re.stopPropagation(),p(n.path)},children:[s.jsx(I,{name:"download",className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.save")]}),j&&s.jsxs(zt,{onClick:re=>{re.stopPropagation(),f(n.path)},children:[s.jsx(I,{name:"folder-received",className:"mr-2 h-4 w-4"})," ",x(Fd())]}),g&&(y||k)&&s.jsxs(s.Fragment,{children:[s.jsx(Dn,{}),y&&s.jsxs(zt,{onClick:re=>{re.stopPropagation(),v("createFile",n)},children:[s.jsx(I,{name:"file-add",className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.newFile")]}),k&&s.jsxs(zt,{onClick:re=>{re.stopPropagation(),v("createFolder",n)},children:[s.jsx(I,{name:"folder-add",className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.newFolder")]})]}),D&&s.jsxs(s.Fragment,{children:[s.jsx(Dn,{}),s.jsxs(zt,{onClick:re=>{re.stopPropagation(),v("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"delete-bin",className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.delete")]})]})]})]})}),e[44]=y,e[45]=k,e[46]=D,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]=f,e[56]=u,e[57]=x,e[58]=z):z=e[58];let ne;return e[59]!==A||e[60]!==ee||e[61]!==z?(ne=s.jsxs("div",{className:"group relative flex items-center",onContextMenu:A,children:[ee,z]}),e[59]=A,e[60]=ee,e[61]=z,e[62]=ne):ne=e[62],ne},y0=()=>{const t=at.c(240),{t:e}=pt(),{files:n,runtime:r}=_n(),a=Er()??"";let i;t[0]!==a?(i=Wn(a.trim()),t[0]=a,t[1]=i):i=t[1];const o=i,c=kl(),d=Ed(),p=Rd(v0),m=Te(w0),u=Sl(a),[h,b]=l.useState(""),f=Cl(h,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,k]=l.useState(!1);let D;t[3]===Symbol.for("react.memo_cache_sentinel")?(D={},t[3]=D):D=t[3];const[j,S]=l.useState(D);let A;t[4]===Symbol.for("react.memo_cache_sentinel")?(A=new Set,t[4]=A):A=t[4];const E=l.useRef(A);let P;t[5]===Symbol.for("react.memo_cache_sentinel")?(P=new Set,t[5]=P):P=t[5];const C=l.useRef(P);let N;t[6]===Symbol.for("react.memo_cache_sentinel")?(N=[],t[6]=N):N=t[6];const T=N;let M;t[7]===Symbol.for("react.memo_cache_sentinel")?(M=[],t[7]=M):M=t[7];const R=M;let L;t[8]!==o?(L=J=>o?J.byRoot[o]?.expandedPaths??T:T,t[8]=o,t[9]=L):L=t[9];const $=$n(L);let B;t[10]!==o?(B=J=>o?J.byRoot[o]?.selectedPath??null:null,t[10]=o,t[11]=B):B=t[11];const O=$n(B),_=$n(j0),ee=$n(N0),z=$n(S0),ne=$n(k0);let re;t[12]!==o?(re=J=>o?J.contextPanelByDirectory[o]?.tabs??R:R,t[12]=o,t[13]=re):re=t[13];const ue=Te(re);let Q;t[14]!==ue?(Q=new Set(ue.map(C0).filter(I0).map(P0)),t[14]=ue,t[15]=Q):Q=t[15];const de=Q,[X,F]=l.useState(null),[V,q]=l.useState(null),[te,U]=l.useState(null),[ae,je]=l.useState(""),[oe,ve]=l.useState(!1),K=!!n.writeFile,ce=!!n.createDirectory,Z=!!n.rename,le=!!n.delete,se=!!n.revealPath;let Ie;t[16]!==K||t[17]!==ce||t[18]!==le||t[19]!==Z||t[20]!==se?(Ie={canRename:Z,canCreateFile:K,canCreateFolder:ce,canDelete:le,canReveal:se},t[16]=K,t[17]=ce,t[18]=le,t[19]=Z,t[20]=se,t[21]=Ie):Ie=t[21];const Ne=Ie;let Y;t[22]!==n||t[23]!==e?(Y=J=>{n.revealPath&&n.revealPath(J).catch(()=>{H.error(e("sidebarFilesTree.toast.revealFailed"))})},t[22]=n,t[23]=e,t[24]=Y):Y=t[24];const fe=Y;let ke;t[25]===Symbol.for("react.memo_cache_sentinel")?(ke=(J,ct)=>{q(J),U(ct),je(J==="rename"&&ct.name||""),ve(!1)},t[25]=ke):ke=t[25];const be=ke;let pe;t[26]!==d||t[27]!==c?(pe=(J,ct)=>{const vt=ct.filter(A0).filter(Tt=>c||!Tt.name.startsWith(".")).filter(Tt=>d||!f0(Tt.name)).map(Tt=>{const Yt=Tt.name,Zt=Wn(Tt.path||""),Ps=Zt?p0(Zt)?Zt:Wn(`${J}/${Zt}`):Wn(`${J}/${Yt}`),As=Tt.isDirectory?"directory":"file",Ge=As==="file"&&Yt.includes(".")?Yt.split(".").pop()?.toLowerCase():void 0;return{name:Yt,path:Ps,type:As,extension:Ge}});return m0(vt)},t[26]=d,t[27]=c,t[28]=pe):pe=t[28];const Ee=pe;let ze;t[29]!==n||t[30]!==Ee||t[31]!==r.isDesktop||t[32]!==d?(ze=async J=>{const ct=Wn(J.trim());if(!ct||E.current.has(ct)||C.current.has(ct))return;C.current=new Set(C.current),C.current.add(ct);const vt=!d;await(r.isDesktop?n.listDirectory(ct,{respectGitignore:vt}).then(T0):rn.listLocalDirectory(ct,{respectGitignore:vt}).then(E0)).then(Yt=>{const Zt=Ee(ct,Yt);E.current=new Set(E.current),E.current.add(ct),S(Ps=>({...Ps,[ct]:Zt}))}).catch(()=>{S(Yt=>({...Yt,[ct]:Yt[ct]??[]}))}).finally(()=>{C.current=new Set(C.current),C.current.delete(ct)})},t[29]=n,t[30]=Ee,t[31]=r.isDesktop,t[32]=d,t[33]=ze):ze=t[33];const G=ze;let Pe;t[34]!==G||t[35]!==o?(Pe=async()=>{o&&(E.current=new Set,C.current=new Set,S(R0),await G(o))},t[34]=G,t[35]=o,t[36]=Pe):Pe=t[36];const Le=Pe;let Ae;t[37]!==G||t[38]!==Le?(Ae=async J=>{if(!J){await Le();return}const ct=Wn(J);E.current=new Set(E.current),E.current.delete(ct),C.current=new Set(C.current),C.current.delete(ct),await G(ct)},t[37]=G,t[38]=Le,t[39]=Ae):Ae=t[39];const ge=Ae;let W;t[40]!==G||t[41]!==o?(W=()=>{o&&(E.current=new Set,C.current=new Set,S(F0),G(o))},t[40]=G,t[41]=o,t[42]=W):W=t[42];let ie;t[43]!==G||t[44]!==o||t[45]!==d||t[46]!==c?(ie=[G,o,c,d],t[43]=G,t[44]=o,t[45]=d,t[46]=c,t[47]=ie):ie=t[47],l.useEffect(W,ie);let Me,Ve;t[48]!==$||t[49]!==G||t[50]!==o?(Me=()=>{if(!o||$.length===0)return;const J=$.map(L0).filter(vt=>!!vt&&vt!==o&&vt.startsWith(`${o}/`)&&!E.current.has(vt)&&!C.current.has(vt)).sort(O0);if(J.length===0)return;let ct=!1;return(async()=>{for(let vt=0;vt<J.length&&!ct;vt=vt+3,vt){const Tt=J.slice(vt,vt+3);await Promise.all(Tt.map(Yt=>G(Yt)))}})(),()=>{ct=!0}},Ve=[$,G,o],t[48]=$,t[49]=G,t[50]=o,t[51]=Me,t[52]=Ve):(Me=t[51],Ve=t[52]),l.useEffect(Me,Ve);let Ce,xe;t[53]!==a||t[54]!==f||t[55]!==p||t[56]!==d||t[57]!==c?(Ce=()=>{if(!a){w([]),k(!1);return}const J=f.trim();if(!J){w([]),k(!1);return}let ct=!1;return k(!0),p(a,J,150,{includeHidden:c,respectGitignore:!d,type:"file"}).then(vt=>{if(ct)return;const Yt=vt.filter(Zt=>d||!g0(Zt.path)).map($0);w(Yt)}).catch(()=>{ct||w([])}).finally(()=>{ct||k(!1)}),()=>{ct=!0}},xe=[a,f,p,c,d],t[53]=a,t[54]=f,t[55]=p,t[56]=d,t[57]=c,t[58]=Ce,t[59]=xe):(Ce=t[58],xe=t[59]),l.useEffect(Ce,xe);let De;t[60]!==u||t[61]!==de||t[62]!==o?(De=J=>{if(de.has(J))return"open";if(u?.files){const ct=J.startsWith(o+"/")?J.slice(o.length+1):J,vt=u.files.find(Tt=>Tt.path===ct);if(vt){if(vt.index==="A"||vt.working_dir==="?")return"git-added";if(vt.index==="D")return"git-deleted";if(vt.index==="M"||vt.working_dir==="M")return"git-modified"}}return null},t[60]=u,t[61]=de,t[62]=o,t[63]=De):De=t[63];const Ye=De;let rt;t[64]!==u||t[65]!==o?(rt=J=>{if(!u?.files)return null;const ct=J.startsWith(o+"/")?J.slice(o.length+1):J,vt=ct?`${ct}/`:"";let Tt=0,Yt=0;for(const Zt of u.files)Zt.path.startsWith(vt)&&((Zt.index==="M"||Zt.working_dir==="M")&&Tt++,(Zt.index==="A"||Zt.working_dir==="?")&&Yt++);return Tt+Yt>0?{modified:Tt,added:Yt}:null},t[64]=u,t[65]=o,t[66]=rt):rt=t[66];const Re=rt;let he;t[67]!==ee||t[68]!==n||t[69]!==m||t[70]!==o||t[71]!==_?(he=async J=>{if(!o)return;const ct=await Hd(n,J.path);if(!ct.ok){H.error(Gd(ct.reason));return}_(o,J.path),ee(o,J.path),m(o,J.path)},t[67]=ee,t[68]=n,t[69]=m,t[70]=o,t[71]=_,t[72]=he):he=t[72];const qe=he;let et;t[73]!==G||t[74]!==o||t[75]!==ne?(et=async J=>{const ct=Wn(J);o&&(ne(o,ct),E.current.has(ct)||await G(ct))},t[73]=G,t[74]=o,t[75]=ne,t[76]=et):et=t[76];const Ke=et;let st;t[77]!==V||t[78]!==te||t[79]!==ae||t[80]!==n||t[81]!==ge||t[82]!==z||t[83]!==o||t[84]!==O||t[85]!==_||t[86]!==e?(st=async J=>{if(J?.preventDefault(),!te||!V)return;ve(!0);const ct=()=>ve(!1),vt=()=>q(null);if(V==="createFile"){if(!ae.trim()){H.error(e("sidebarFilesTree.toast.filenameRequired")),ct();return}if(!n.writeFile){H.error(e("sidebarFilesTree.toast.writeNotSupported")),ct();return}const Tt=te.path,Yt=Tt?`${Tt}/`:"",Zt=Wn(`${Yt}${ae.trim()}`);await n.writeFile(Zt,"").then(async Ps=>{Ps.success&&(H.success(e("sidebarFilesTree.toast.fileCreated")),await ge(Tt)),vt()}).catch(()=>H.error(e("sidebarFilesTree.toast.operationFailed"))).finally(ct);return}if(V==="createFolder"){if(!ae.trim()){H.error(e("sidebarFilesTree.toast.folderNameRequired")),ct();return}const Tt=te.path,Yt=Tt?`${Tt}/`:"",Zt=Wn(`${Yt}${ae.trim()}`);await n.createDirectory(Zt).then(async Ps=>{Ps.success&&(H.success(e("sidebarFilesTree.toast.folderCreated")),await ge(Tt)),vt()}).catch(()=>H.error(e("sidebarFilesTree.toast.operationFailed"))).finally(ct);return}if(V==="rename"){if(!ae.trim()){H.error(e("sidebarFilesTree.toast.nameRequired")),ct();return}if(!n.rename){H.error(e("sidebarFilesTree.toast.renameNotSupported")),ct();return}const Tt=te.path,Yt=Tt.split("/").slice(0,-1).join("/"),Zt=Yt?`${Yt}/`:"",Ps=Wn(`${Zt}${ae.trim()}`);await n.rename(Tt,Ps).then(async As=>{As.success&&(H.success(e("sidebarFilesTree.toast.renamedSuccessfully")),await ge(Yt),o&&z(o,Tt),(O===Tt||O&&O.startsWith(`${Tt}/`))&&_(o,null)),vt()}).catch(()=>H.error(e("sidebarFilesTree.toast.operationFailed"))).finally(ct);return}if(V==="delete"){if(!n.delete){H.error(e("sidebarFilesTree.toast.deleteNotSupported")),ct();return}const Tt=te.path,Yt=Tt.split("/").slice(0,-1).join("/");await n.delete(Tt).then(async Zt=>{Zt.success&&(H.success(e("sidebarFilesTree.toast.deletedSuccessfully")),await ge(Yt),o&&z(o,Tt),(O===Tt||O&&O.startsWith(Tt+"/"))&&_(o,null)),vt()}).catch(()=>H.error(e("sidebarFilesTree.toast.operationFailed"))).finally(ct);return}ct()},t[77]=V,t[78]=te,t[79]=ae,t[80]=n,t[81]=ge,t[82]=z,t[83]=o,t[84]=O,t[85]=_,t[86]=e,t[87]=st):st=t[87];const nt=st;let ye,Je,_e,Ue,ot,Xe,We;if(t[88]!==K||t[89]!==ce||t[90]!==j||t[91]!==X||t[92]!==a||t[93]!==$||t[94]!==Ne||t[95]!==n.downloadFile||t[96]!==Ye||t[97]!==Re||t[98]!==qe||t[99]!==fe||t[100]!==Le||t[101]!==o||t[102]!==h||t[103]!==g||t[104]!==y||t[105]!==O||t[106]!==e||t[107]!==Ke){let J=function(Bt,bs){const es=j[Bt]??[];return es.map((Ut,os)=>{const en=Ut.type==="directory",qs=en&&$.includes(Ut.path),zs=O===Ut.path,un=os===es.length-1;return s.jsxs("li",{className:"relative",children:[bs>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),un&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-sidebar/50"})]}),s.jsx(b0,{node:Ut,root:o,isExpanded:qs,isActive:zs,status:en?void 0:Ye(Ut.path),badge:en?Re(Ut.path):void 0,permissions:Ne,downloadFile:n.downloadFile,contextMenuPath:X,setContextMenuPath:F,onSelect:qe,onToggle:Ke,onRevealPath:fe,onOpenDialog:be}),en&&qs&&s.jsx("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:J(Ut.path,bs+1)})]},Ut.path)})};const ct=!!(o&&j[o]);Xe="flex h-full min-h-0 flex-col overflow-hidden bg-sidebar";let vt;t[115]===Symbol.for("react.memo_cache_sentinel")?(vt=s.jsx(I,{name:"search",className:"pointer-events-none absolute left-2 top-2 h-4 w-4 text-muted-foreground"}),t[115]=vt):vt=t[115];let Tt;t[116]===Symbol.for("react.memo_cache_sentinel")?(Tt=Bt=>b(Bt.target.value),t[116]=Tt):Tt=t[116];let Yt;t[117]!==e?(Yt=e("sidebarFilesTree.search.placeholder"),t[117]=e,t[118]=Yt):Yt=t[118];let Zt;t[119]!==h||t[120]!==Yt?(Zt=s.jsx(Kt,{ref:v,value:h,onChange:Tt,placeholder:Yt,className:"h-8 pl-8 pr-8 typography-meta"}),t[119]=h,t[120]=Yt,t[121]=Zt):Zt=t[121];let Ps;t[122]!==h||t[123]!==e?(Ps=h.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(I,{name:"close",className:"h-4 w-4"})}):null,t[122]=h,t[123]=e,t[124]=Ps):Ps=t[124];let As;t[125]!==Zt||t[126]!==Ps?(As=s.jsxs("div",{className:"relative min-w-0 flex-1",children:[vt,Zt,Ps]}),t[125]=Zt,t[126]=Ps,t[127]=As):As=t[127];let Ge;t[128]!==K||t[129]!==a||t[130]!==e?(Ge=K&&s.jsx(we,{variant:"ghost",size:"sm",onClick:()=>be("createFile",{path:a,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:e("sidebarFilesTree.actions.newFileTitle"),children:s.jsx(I,{name:"file-add",className:"h-4 w-4"})}),t[128]=K,t[129]=a,t[130]=e,t[131]=Ge):Ge=t[131];let yt;t[132]!==ce||t[133]!==a||t[134]!==e?(yt=ce&&s.jsx(we,{variant:"ghost",size:"sm",onClick:()=>be("createFolder",{path:a,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:e("sidebarFilesTree.actions.newFolderTitle"),children:s.jsx(I,{name:"folder-add",className:"h-4 w-4"})}),t[132]=ce,t[133]=a,t[134]=e,t[135]=yt):yt=t[135];let It;t[136]!==Le?(It=()=>{Le()},t[136]=Le,t[137]=It):It=t[137];let Rt;t[138]!==e?(Rt=e("sidebarFilesTree.actions.refreshTitle"),t[138]=e,t[139]=Rt):Rt=t[139];let ss;t[140]===Symbol.for("react.memo_cache_sentinel")?(ss=s.jsx(I,{name:"refresh",className:"h-4 w-4"}),t[140]=ss):ss=t[140];let it;t[141]!==It||t[142]!==Rt?(it=s.jsx(we,{variant:"ghost",size:"sm",onClick:It,className:"h-8 w-8 p-0 flex-shrink-0",title:Rt,children:ss}),t[141]=It,t[142]=Rt,t[143]=it):it=t[143],t[144]!==As||t[145]!==Ge||t[146]!==yt||t[147]!==it?(We=s.jsxs("div",{className:"flex items-center gap-2 border-b border-border/40 px-3 py-2",children:[As,Ge,yt,it]}),t[144]=As,t[145]=Ge,t[146]=yt,t[147]=it,t[148]=We):We=t[148],ye=Ts,Ue="flex-1 min-h-0",ot="p-2",Je="flex flex-col",_e=y?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"h-4 w-4 animate-spin"}),e("sidebarFilesTree.state.searching")]}):g.length>0?g.map(Bt=>{const bs=O===Bt.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>qe(Bt),draggable:!0,onDragStart:es=>{const Ut=Bt.relativePath||Mf(o??"",Bt.path);!Ut||Ut==="."||(es.dataTransfer.setData("application/x-openchamber-file-path",Ut),es.dataTransfer.effectAllowed="copy")},className:me("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors cursor-grab active:cursor-grabbing",bs?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),title:Bt.path,children:[Ef(Bt.path,Bt.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},children:Bt.relativePath??Bt.path})]})},Bt.path)}):ct&&o?J(o,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:e("sidebarFilesTree.state.loading")}),t[88]=K,t[89]=ce,t[90]=j,t[91]=X,t[92]=a,t[93]=$,t[94]=Ne,t[95]=n.downloadFile,t[96]=Ye,t[97]=Re,t[98]=qe,t[99]=fe,t[100]=Le,t[101]=o,t[102]=h,t[103]=g,t[104]=y,t[105]=O,t[106]=e,t[107]=Ke,t[108]=ye,t[109]=Je,t[110]=_e,t[111]=Ue,t[112]=ot,t[113]=Xe,t[114]=We}else ye=t[108],Je=t[109],_e=t[110],Ue=t[111],ot=t[112],Xe=t[113],We=t[114];let bt;t[149]!==Je||t[150]!==_e?(bt=s.jsx("ul",{className:Je,children:_e}),t[149]=Je,t[150]=_e,t[151]=bt):bt=t[151];let Dt;t[152]!==ye||t[153]!==Ue||t[154]!==ot||t[155]!==bt?(Dt=s.jsx(ye,{outerClassName:Ue,className:ot,children:bt}),t[152]=ye,t[153]=Ue,t[154]=ot,t[155]=bt,t[156]=Dt):Dt=t[156];const Ht=!!V;let rs;t[157]===Symbol.for("react.memo_cache_sentinel")?(rs=J=>!J&&q(null),t[157]=rs):rs=t[157];let jt;t[158]!==V||t[159]!==e?(jt=V==="createFile"&&e("sidebarFilesTree.dialog.createFile.title"),t[158]=V,t[159]=e,t[160]=jt):jt=t[160];let St;t[161]!==V||t[162]!==e?(St=V==="createFolder"&&e("sidebarFilesTree.dialog.createFolder.title"),t[161]=V,t[162]=e,t[163]=St):St=t[163];let ns;t[164]!==V||t[165]!==e?(ns=V==="rename"&&e("sidebarFilesTree.dialog.rename.title"),t[164]=V,t[165]=e,t[166]=ns):ns=t[166];let ut;t[167]!==V||t[168]!==e?(ut=V==="delete"&&e("sidebarFilesTree.dialog.delete.title"),t[167]=V,t[168]=e,t[169]=ut):ut=t[169];let Gt;t[170]!==jt||t[171]!==St||t[172]!==ns||t[173]!==ut?(Gt=s.jsxs(js,{children:[jt,St,ns,ut]}),t[170]=jt,t[171]=St,t[172]=ns,t[173]=ut,t[174]=Gt):Gt=t[174];let Xt;t[175]!==V||t[176]!==te?.path||t[177]!==e?(Xt=V==="createFile"&&e("sidebarFilesTree.dialog.createFile.description",{path:te?.path??e("sidebarFilesTree.dialog.rootFallback")}),t[175]=V,t[176]=te?.path,t[177]=e,t[178]=Xt):Xt=t[178];let Wt;t[179]!==V||t[180]!==te?.path||t[181]!==e?(Wt=V==="createFolder"&&e("sidebarFilesTree.dialog.createFolder.description",{path:te?.path??e("sidebarFilesTree.dialog.rootFallback")}),t[179]=V,t[180]=te?.path,t[181]=e,t[182]=Wt):Wt=t[182];let is;t[183]!==V||t[184]!==te?.name||t[185]!==e?(is=V==="rename"&&e("sidebarFilesTree.dialog.rename.description",{name:te?.name??""}),t[183]=V,t[184]=te?.name,t[185]=e,t[186]=is):is=t[186];let gs;t[187]!==V||t[188]!==te?.name||t[189]!==e?(gs=V==="delete"&&e("sidebarFilesTree.dialog.delete.description",{name:te?.name??""}),t[187]=V,t[188]=te?.name,t[189]=e,t[190]=gs):gs=t[190];let ps;t[191]!==Xt||t[192]!==Wt||t[193]!==is||t[194]!==gs?(ps=s.jsxs(Rs,{children:[Xt,Wt,is,gs]}),t[191]=Xt,t[192]=Wt,t[193]=is,t[194]=gs,t[195]=ps):ps=t[195];let Ns;t[196]!==Gt||t[197]!==ps?(Ns=s.jsxs(Cs,{children:[Gt,ps]}),t[196]=Gt,t[197]=ps,t[198]=Ns):Ns=t[198];let Mt;t[199]!==V||t[200]!==ae||t[201]!==nt||t[202]!==e?(Mt=V!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(Kt,{value:ae,onChange:J=>je(J.target.value),placeholder:e(V==="rename"?"sidebarFilesTree.dialog.rename.placeholder":"sidebarFilesTree.dialog.namePlaceholder"),onKeyDown:J=>{J.key==="Enter"&&nt()},autoFocus:!0})}),t[199]=V,t[200]=ae,t[201]=nt,t[202]=e,t[203]=Mt):Mt=t[203];let He;t[204]===Symbol.for("react.memo_cache_sentinel")?(He=()=>q(null),t[204]=He):He=t[204];let At;t[205]!==e?(At=e("sidebarFilesTree.dialog.cancel"),t[205]=e,t[206]=At):At=t[206];let Et;t[207]!==oe||t[208]!==At?(Et=s.jsx(we,{variant:"outline",onClick:He,disabled:oe,children:At}),t[207]=oe,t[208]=At,t[209]=Et):Et=t[209];const wt=V==="delete"?"destructive":"default";let $t;t[210]!==nt?($t=()=>{nt()},t[210]=nt,t[211]=$t):$t=t[211];let qt;t[212]!==V||t[213]!==ae||t[214]!==oe?(qt=oe||V!=="delete"&&!ae.trim(),t[212]=V,t[213]=ae,t[214]=oe,t[215]=qt):qt=t[215];let Ms;t[216]!==V||t[217]!==oe||t[218]!==e?(Ms=oe?s.jsx(I,{name:"loader-4",className:"animate-spin"}):e(V==="delete"?"sidebarFilesTree.dialog.delete.confirm":"sidebarFilesTree.dialog.confirm"),t[216]=V,t[217]=oe,t[218]=e,t[219]=Ms):Ms=t[219];let cs;t[220]!==wt||t[221]!==$t||t[222]!==qt||t[223]!==Ms?(cs=s.jsx(we,{variant:wt,onClick:$t,disabled:qt,children:Ms}),t[220]=wt,t[221]=$t,t[222]=qt,t[223]=Ms,t[224]=cs):cs=t[224];let Is;t[225]!==Et||t[226]!==cs?(Is=s.jsxs(Ks,{children:[Et,cs]}),t[225]=Et,t[226]=cs,t[227]=Is):Is=t[227];let Es;t[228]!==Ns||t[229]!==Mt||t[230]!==Is?(Es=s.jsxs(vs,{children:[Ns,Mt,Is]}),t[228]=Ns,t[229]=Mt,t[230]=Is,t[231]=Es):Es=t[231];let ft;t[232]!==Ht||t[233]!==Es?(ft=s.jsx(ws,{open:Ht,onOpenChange:rs,children:Es}),t[232]=Ht,t[233]=Es,t[234]=ft):ft=t[234];let hs;return t[235]!==Xe||t[236]!==We||t[237]!==Dt||t[238]!==ft?(hs=s.jsxs("section",{className:Xe,children:[We,Dt,ft]}),t[235]=Xe,t[236]=We,t[237]=Dt,t[238]=ft,t[239]=hs):hs=t[239],hs};function v0(t){return t.searchFiles}function w0(t){return t.openContextFile}function j0(t){return t.setSelectedPath}function N0(t){return t.addOpenPath}function S0(t){return t.removeOpenPathsByPrefix}function k0(t){return t.toggleExpandedPath}function C0(t){return t.mode==="file"?t.targetPath:null}function I0(t){return typeof t=="string"&&t.length>0}function P0(t){return Wn(t)}function A0(t){return t&&typeof t.name=="string"&&t.name.length>0}function D0(t){return{name:t.name,path:t.path,isDirectory:t.isDirectory}}function T0(t){return t.entries.map(D0)}function M0(t){return{name:t.name,path:t.path,isDirectory:t.isDirectory}}function E0(t){return t.map(M0)}function R0(t){return Object.keys(t).length===0?t:{}}function F0(t){return Object.keys(t).length===0?t:{}}function L0(t){return Wn(t)}function O0(t,e){return t.split("/").length-e.split("/").length}function $0(t){return{name:t.name,path:Wn(t.path),type:"file",extension:t.extension,relativePath:t.relativePath}}function B0(t,e){const n=at.c(6),{git:r}=_n(),a=nn(_0);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 _0(t){return t.ensureStatus}const V0=()=>{const t=at.c(17),e=Fs(U0),n=Fs(W0),r=Vs(K0),a=nn(H0);let i;e:{if(e){let f;t[0]!==e||t[1]!==n?(f=n.find(v=>v.id===e)??n[0]??null,t[0]=e,t[1]=n,t[2]=f):f=t[2],i=f;break e}i=n[0]??null}const o=i;let c;e:{if(!o){c=null;break e}let f;t[3]!==o.id||t[4]!==o.path?(f={id:o.id,path:o.path},t[3]=o.id,t[4]=o.path,t[5]=f):f=t[5],c=f}const d=c;let p;e:{if(!o){p=null;break e}let f;t[6]!==o.label||t[7]!==o.path||t[8]!==r?(f=o.label?.trim()||Da(o.path,r)||o.path,t[6]=o.label,t[7]=o.path,t[8]=r,t[9]=f):f=t[9],p=f}const m=p;let u;e:{if(!o){u=!1;break e}let f;t[10]!==o.path||t[11]!==a?(f=a.get(o.path)?.isGitRepo,t[10]=o.path,t[11]=a,t[12]=f):f=t[12],u=f===!0}const h=u;let b;return t[13]!==h||t[14]!==m||t[15]!==d?(b=s.jsx("div",{className:"h-full min-h-0 overflow-auto bg-sidebar",children:s.jsx(lw,{projectRef:d,projectLabel:m,canCreateWorktree:h})}),t[13]=h,t[14]=m,t[15]=d,t[16]=b):b=t[16],b},z0=()=>{const t=at.c(38),{t:e}=pt(),n=Te(G0),r=Te(q0),a=Te(J0),i=Er();B0(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(I,{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(I,{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 h;t[10]!==e?(h=e("layout.rightSidebar.context"),t[10]=e,t[11]=h):h=t[11];let b;t[12]===Symbol.for("react.memo_cache_sentinel")?(b=s.jsx(I,{name:"booklet",className:"h-3.5 w-3.5"}),t[12]=b):b=t[12];let f;t[13]!==h?(f={id:"context",label:h,icon:b},t[13]=h,t[14]=f):f=t[14];let v;t[15]!==d||t[16]!==u||t[17]!==f?(v=[d,u,f],t[15]=d,t[16]=u,t[17]=f,t[18]=v):v=t[18];const x=v;let g;t[19]!==r?(g=A=>r(A),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(Ar,{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(Tf,{}),t[25]=n,t[26]=y):y=t[26];let k;t[27]!==n?(k=n==="files"&&s.jsx(y0,{}),t[27]=n,t[28]=k):k=t[28];let D;t[29]!==n?(D=n==="context"&&s.jsx(V0,{}),t[29]=n,t[30]=D):D=t[30];let j;t[31]!==y||t[32]!==k||t[33]!==D?(j=s.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden",children:[y,k,D]}),t[31]=y,t[32]=k,t[33]=D,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 U0(t){return t.activeProjectId}function W0(t){return t.projects}function K0(t){return t.homeDirectory}function H0(t){return t.directories}function G0(t){return t.rightSidebarTab}function q0(t){return t.setRightSidebarTab}function J0(t){return t.isRightSidebarOpen}function Rf(t){const e=at.c(63),{draft:n,onEdit:r,onDelete:a,className:i,maxWidth:o}=t,{t:c}=pt(),p=Il()?.currentTheme,[m,u]=Be.useState(!1),h=typeof n.text=="string"?n.text:"";let b;e[0]!==h?(b=h.length>150||h.split(`
14
- `).length>3,e[0]=h,e[1]=b):b=e[1];const f=b;let v;e[2]!==i?(v=me("rounded-lg border shadow-none w-full max-w-[min(100%,calc(var(--oc-context-panel-width,100vw)-var(--oc-editor-gutter-width,0px)))] overflow-hidden transition-all duration-200",i),e[2]=i,e[3]=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 k;e[8]!==n.fileLabel?(k=s.jsx("span",{className:"truncate max-w-[200px]",title:n.fileLabel,children:n.fileLabel}),e[8]=n.fileLabel,e[9]=k):k=e[9];let D;e[10]===Symbol.for("react.memo_cache_sentinel")?(D=s.jsx("span",{children:"•"}),e[10]=D):D=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 A;e[17]!==n.side?(A=n.side&&s.jsxs("span",{children:["(",n.side,")"]}),e[17]=n.side,e[18]=A):A=e[18];let E;e[19]!==S||e[20]!==A||e[21]!==k?(E=s.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground mb-1.5",children:[k,D,S,A]}),e[19]=S,e[20]=A,e[21]=k,e[22]=E):E=e[22];const P=m||!f,C=!m&&f&&"line-clamp-3";let N;e[23]!==C?(N=me("text-sm whitespace-pre-wrap break-words leading-relaxed",C),e[23]=C,e[24]=N):N=e[24];let T;e[25]!==h||e[26]!==N?(T=s.jsx("div",{className:N,children:h}),e[25]=h,e[26]=N,e[27]=T):T=e[27];let M;e[28]!==f||e[29]!==m||e[30]!==c?(M=f&&s.jsx(wr,{asChild:!0,children:s.jsx(we,{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(I,{name:"arrow-up-s",className:"size-3 mr-1"}),c("inlineComment.actions.showLess")]}):s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"arrow-down-s",className:"size-3 mr-1"}),c("inlineComment.actions.showMore")]})})}),e[28]=f,e[29]=m,e[30]=c,e[31]=M):M=e[31];let R;e[32]===Symbol.for("react.memo_cache_sentinel")?(R=s.jsx(mr,{}),e[32]=R):R=e[32];let L;e[33]!==P||e[34]!==T||e[35]!==M?(L=s.jsxs(ur,{open:P,onOpenChange:u,children:[T,M,R]}),e[33]=P,e[34]=T,e[35]=M,e[36]=L):L=e[36];let $;e[37]!==E||e[38]!==L?($=s.jsxs("div",{className:"flex-1 min-w-0",children:[E,L]}),e[37]=E,e[38]=L,e[39]=$):$=e[39];let B;e[40]===Symbol.for("react.memo_cache_sentinel")?(B=s.jsx(Os,{asChild:!0,children:s.jsx(we,{variant:"ghost",size:"icon",className:"h-6 w-6 -mr-1 text-muted-foreground hover:text-foreground",children:s.jsx(I,{name:"more",className:"size-4"})})}),e[40]=B):B=e[40];let O;e[41]===Symbol.for("react.memo_cache_sentinel")?(O=s.jsx(I,{name:"edit",className:"size-4 mr-2"}),e[41]=O):O=e[41];let _;e[42]!==c?(_=c("inlineComment.actions.editComment"),e[42]=c,e[43]=_):_=e[43];let ee;e[44]!==r||e[45]!==_?(ee=s.jsxs(zt,{onClick:r,children:[O,_]}),e[44]=r,e[45]=_,e[46]=ee):ee=e[46];let z;e[47]===Symbol.for("react.memo_cache_sentinel")?(z=s.jsx(I,{name:"delete-bin",className:"size-4 mr-2"}),e[47]=z):z=e[47];let ne;e[48]!==c?(ne=c("inlineComment.actions.deleteComment"),e[48]=c,e[49]=ne):ne=e[49];let re;e[50]!==a||e[51]!==ne?(re=s.jsxs(zt,{onClick:a,className:"text-destructive",children:[z,ne]}),e[50]=a,e[51]=ne,e[52]=re):re=e[52];let ue;e[53]!==ee||e[54]!==re?(ue=s.jsxs(Bs,{children:[B,s.jsxs($s,{align:"end",children:[ee,re]})]}),e[53]=ee,e[54]=re,e[55]=ue):ue=e[55];let Q;e[56]!==$||e[57]!==ue?(Q=s.jsxs("div",{className:"flex items-start justify-between gap-2 p-3",children:[$,ue]}),e[56]=$,e[57]=ue,e[58]=Q):Q=e[58];let de;return e[59]!==v||e[60]!==Q||e[61]!==y?(de=s.jsx("div",{className:v,style:y,"data-comment-card":"true",children:Q}),e[59]=v,e[60]=Q,e[61]=y,e[62]=de):de=e[62],de}function ml(t){const e=at.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:h}=pt(),f=Il()?.currentTheme,{isMobile:v}=an(),[x,g]=l.useState(m),w=Be.useRef(null),y=Be.useRef(o);let k,D;e[0]!==o?(k=()=>{o&&(y.current=o)},D=[o],e[0]=o,e[1]=k,e[2]=D):(k=e[1],D=e[2]),Be.useEffect(k,D);const j=sN,S=j(o);let A,E;e[3]!==v?(A=()=>{const ce=w.current;if(!ce)return;const Z=ce.closest(".overlay-scrollbar-container"),le=Z?.scrollTop??window.scrollY,se=Z?.scrollLeft??window.scrollX;if(v){ce.scrollIntoView({behavior:"auto",block:"nearest"});try{ce.focus({preventScroll:!0})}catch{ce.focus()}return}try{ce.focus({preventScroll:!0})}catch{ce.focus()}const Ie=ce.value.length;try{ce.setSelectionRange(Ie,Ie)}catch{}requestAnimationFrame(()=>{Z?(Z.scrollTop=le,Z.scrollLeft=se):window.scrollTo({top:le,left:se})})},E=[v],e[3]=v,e[4]=A,e[5]=E):(A=e[4],E=e[5]),Be.useEffect(A,E);let P;e[6]!==a||e[7]!==r||e[8]!==x?(P=ce=>{(ce.metaKey||ce.ctrlKey)&&ce.key==="Enter"?(ce.preventDefault(),x.trim()&&r(x,j(y.current))):ce.key==="Escape"&&(ce.preventDefault(),a())},e[6]=a,e[7]=r,e[8]=x,e[9]=P):P=e[9];const C=P;let N;e[10]!==r||e[11]!==x?(N=ce=>{ce.stopPropagation(),x.trim()&&r(x,j(y.current))},e[10]=r,e[11]=x,e[12]=N):N=e[12];const T=N;let M;e[13]!==d?(M=me("rounded-lg border shadow-none w-full max-w-[min(100%,calc(var(--oc-context-panel-width,100vw)-var(--oc-editor-gutter-width,0px)))] overflow-hidden animate-in fade-in zoom-in-95 duration-200",d),e[13]=d,e[14]=M):M=e[14];const R=f?.colors?.surface?.elevated,L=f?.colors?.interactive?.border,$=p?`${Math.max(200,Math.floor(p))}px`:void 0;let B;e[15]!==R||e[16]!==L||e[17]!==$?(B={backgroundColor:R,borderColor:L,maxWidth:$},e[15]=R,e[16]=L,e[17]=$,e[18]=B):B=e[18];const O="true",_=tN,ee=eN,z="p-3",ne=(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:h("inlineComment.range.lines",{start:S.start,end:S.end})})]});let re;e[19]===Symbol.for("react.memo_cache_sentinel")?(re=ce=>g(ce.target.value),e[19]=re):re=e[19];let ue;e[20]!==h?(ue=h("inlineComment.input.placeholder"),e[20]=h,e[21]=ue):ue=e[21];let Q;e[22]!==C||e[23]!==ue||e[24]!==x?(Q=s.jsx(bn,{simple:!0,ref:w,value:x,onChange:re,onKeyDown:C,placeholder:ue,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]=C,e[23]=ue,e[24]=x,e[25]=Q):Q=e[25];let de;e[26]!==h?(de=h("inlineComment.actions.cancel"),e[26]=h,e[27]=de):de=e[27];let X;e[28]!==a||e[29]!==de?(X=s.jsx(we,{variant:"ghost",size:"sm",onClick:a,onPointerDown:Z0,onTouchStart:X0,className:"h-8 text-muted-foreground hover:text-foreground",children:de}),e[28]=a,e[29]=de,e[30]=X):X=e[30];let F;e[31]!==x?(F=x.trim(),e[31]=x,e[32]=F):F=e[32];const V=!F,q=f?.colors?.status?.success,te=f?.colors?.status?.successForeground;let U;e[33]!==q||e[34]!==te?(U={backgroundColor:q,color:te},e[33]=q,e[34]=te,e[35]=U):U=e[35];let ae;e[36]!==u||e[37]!==h?(ae=h(u?"inlineComment.actions.save":"inlineComment.actions.comment"),e[36]=u,e[37]=h,e[38]=ae):ae=e[38];let je;e[39]!==T||e[40]!==V||e[41]!==U||e[42]!==ae?(je=s.jsx(we,{size:"sm",onClick:T,onPointerDown:Y0,onTouchStart:Q0,disabled:V,className:"h-8 min-w-[80px]",style:U,children:ae}),e[39]=T,e[40]=V,e[41]=U,e[42]=ae,e[43]=je):je=e[43];let oe;e[44]!==X||e[45]!==je?(oe=s.jsxs("div",{className:"flex items-center justify-end gap-2 mt-3",children:[X,je]}),e[44]=X,e[45]=je,e[46]=oe):oe=e[46];let ve;e[47]!==ne||e[48]!==Q||e[49]!==oe?(ve=s.jsxs("div",{className:z,children:[ne,Q,oe]}),e[47]=ne,e[48]=Q,e[49]=oe,e[50]=ve):ve=e[50];let K;return e[51]!==B||e[52]!==_||e[53]!==ee||e[54]!==ve||e[55]!==M?(K=s.jsx("div",{className:M,style:B,"data-comment-input":O,onPointerDown:_,onTouchStart:ee,children:ve}),e[51]=B,e[52]=_,e[53]=ee,e[54]=ve,e[55]=M,e[56]=K):K=e[56],K}function Q0(t){return t.stopPropagation()}function Y0(t){return t.stopPropagation()}function X0(t){return t.stopPropagation()}function Z0(t){return t.stopPropagation()}function eN(t){return t.stopPropagation()}function tN(t){return t.stopPropagation()}function sN(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 nN=t=>{const e=Math.min(t.startLine,t.endLine),n=Math.max(t.startLine,t.endLine);return{...t,startLine:e,endLine:n}},pl=t=>{const e=Math.min(t.start,t.end),n=Math.max(t.start,t.end);return{...t,start:e,end:n}};function qd(t){const e=at.c(40),{t:n}=pt(),{source:r,fileLabel:a,language:i,getCodeForRange:o,toStoreRange:c,fromDraftRange:d}=t,p=Vt(cN),m=Vt(lN),u=Za(oN),h=Za(iN),b=Za(aN),f=Za(rN),[v,x]=l.useState(null),[g,w]=l.useState(""),[y,k]=l.useState(null),D=p??(m?"draft":null);let j;e:{if(!D||!a){let z;e[0]===Symbol.for("react.memo_cache_sentinel")?(z=[],e[0]=z):z=e[0],j=z;break e}let O;e[1]!==f||e[2]!==D?(O=f[D]??[],e[1]=f,e[2]=D,e[3]=O):O=e[3];const _=O;let ee;if(e[4]!==a||e[5]!==_||e[6]!==r){let z;e[8]!==a||e[9]!==r?(z=ne=>ne.source===r&&ne.fileLabel===a,e[8]=a,e[9]=r,e[10]=z):z=e[10],ee=_.filter(z),e[4]=a,e[5]=_,e[6]=r,e[7]=ee}else ee=e[7];j=ee}const S=j;let A;e[11]===Symbol.for("react.memo_cache_sentinel")?(A=()=>{x(null),w(""),k(null)},e[11]=A):A=e[11];const E=A;let P;e[12]===Symbol.for("react.memo_cache_sentinel")?(P=()=>{E()},e[12]=P):P=e[12];const C=P;let N;e[13]!==d?(N=O=>{const _=pl(d(O));x(_),w(O.text),k(O.id)},e[13]=d,e[14]=N):N=e[14];const T=N;let M;e[15]!==y||e[16]!==b?(M=O=>{b(O.sessionKey,O.id),y===O.id&&E()},e[15]=y,e[16]=b,e[17]=M):M=e[17];const R=M;let L;e[18]!==u||e[19]!==y||e[20]!==a||e[21]!==o||e[22]!==i||e[23]!==v||e[24]!==D||e[25]!==r||e[26]!==n||e[27]!==c||e[28]!==h?(L=(O,_)=>{const ee=_??v,z=O.trim();if(!ee||!z||!a)return;if(!D){H.error(n("inlineComment.toast.selectSessionToSave"));return}const ne=pl(ee),re=nN(c(ne)),ue=o(ne);y?h(D,y,{fileLabel:a,startLine:re.startLine,endLine:re.endLine,side:re.side,code:ue,language:i,text:z}):u({sessionKey:D,source:r,fileLabel:a,startLine:re.startLine,endLine:re.endLine,side:re.side,code:ue,language:i,text:z}),E()},e[18]=u,e[19]=y,e[20]=a,e[21]=o,e[22]=i,e[23]=v,e[24]=D,e[25]=r,e[26]=n,e[27]=c,e[28]=h,e[29]=L):L=e[29];const $=L;let B;return e[30]!==g||e[31]!==R||e[32]!==S||e[33]!==y||e[34]!==d||e[35]!==$||e[36]!==v||e[37]!==D||e[38]!==T?(B={sessionKey:D,drafts:S,selection:v,setSelection:x,commentText:g,setCommentText:w,editingDraftId:y,setEditingDraftId:k,reset:E,cancel:C,startEdit:T,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]=D,e[38]=T,e[39]=B):B=e[39],B}function rN(t){return t.drafts}function aN(t){return t.removeDraft}function iN(t){return t.updateDraft}function oN(t){return t.addDraft}function lN(t){return t.newSessionDraft?.open}function cN(t){return t.currentSessionId}function Ff(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:h}=t,b=[];for(const f of e){const v=d(f);if(f.id===n){b.push({afterLine:v.end,id:`edit-${f.id}`,content:s.jsx(ml,{initialText:r,fileLabel:o,lineRange:v,isEditing:!0,onSave:p,onCancel:m},`edit-${f.id}`)});continue}b.push({afterLine:v.end,id:`card-${f.id}`,content:s.jsx(Rf,{draft:f,onEdit:()=>u(f),onDelete:()=>h(f)},`card-${f.id}`)})}if(a&&!n&&!i){const f={...a,start:Math.min(a.start,a.end),end:Math.max(a.start,a.end)};b.push({afterLine:f.end,id:c,content:s.jsx(ml,{initialText:r,fileLabel:o,lineRange:f,isEditing:!1,onSave:p,onCancel:m},c)})}return b}const zo=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}`},dN=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 uN(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 ym(t){if(!(!t||t<=0))return Math.max(200,Math.floor(t))}function mN(t){const{diffRootRef:e,drafts:n,selection:r,editingDraftId:a,commentText:i,fileLabel:o,onSave:c,onCancel:d,onEdit:p,onDelete:m}=t,[u,h]=l.useState(0),[b,f]=l.useState(null),v=l.useMemo(()=>!r||a?null:zo({type:"new",selection:r}),[a,r]),x=l.useMemo(()=>{const y=n.map(k=>zo({type:k.id===a?"edit":"saved",draft:k}));return v&&y.push(v),y},[n,a,v]),g=l.useCallback(y=>{const k=e.current;if(!k)return null;const D=k.querySelector("diffs-container");if(!(D instanceof HTMLElement))return null;const j=D.querySelector(`[data-annotation-id="${y}"]`);if(j instanceof HTMLElement)return j;const S=D.shadowRoot;return S?S.querySelector(`[data-annotation-id="${y}"]`):null},[e]);l.useEffect(()=>{if(x.length===0)return;let y=!1,k=0;const D=12,j=()=>{y||x.every(A=>!!g(A))||k>=D||(k+=1,requestAnimationFrame(()=>{y||(h(A=>A+1),j())}))};return j(),()=>{y=!0}},[x,g]),l.useEffect(()=>{const y=e.current;if(!y)return;const k=()=>{const j=getComputedStyle(y),S=uN(j.getPropertyValue("--oc-context-panel-width")),A=y.getBoundingClientRect(),E=S??A.width;f(E>0?E:null)};k();const D=new ResizeObserver(()=>{k()});return D.observe(y),window.addEventListener("resize",k),()=>{D.disconnect(),window.removeEventListener("resize",k)}},[e]);const w=l.useCallback(y=>{const D=e.current?.getBoundingClientRect(),j=y.closest("[data-annotation-content]"),S=j instanceof HTMLElement?j.getBoundingClientRect():y.getBoundingClientRect(),A=[S.width];D&&A.push(D.right-S.left);const E=A.filter(P=>Number.isFinite(P)&&P>0);return E.length>0?ym(Math.min(...E)):ym(b)},[e,b]);return s.jsxs(s.Fragment,{children:[n.map(y=>{const k=zo({type:y.id===a?"edit":"saved",draft:y}),D=g(k);if(!D)return null;const j=w(D);return y.id===a?Oi.createPortal(s.jsx(ml,{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}),D,`draft-edit-${y.id}`):Oi.createPortal(s.jsx(Rf,{draft:y,onEdit:()=>p(y),onDelete:()=>m(y),maxWidth:j}),D,`draft-card-${y.id}`)}),r&&!a&&v&&(()=>{const y=g(v);if(!y)return null;const k=w(y);return Oi.createPortal(s.jsx(ml,{initialText:i,fileLabel:o,lineRange:r,isEditing:!1,onSave:c,onCancel:d,maxWidth:k}),y,v)})()]})}function pN(){return new Worker(zg,{type:"module"})}const hN=["typescript","javascript","tsx","jsx","json","markdown"],sd={unified:{poolSize:1,totalASTLRUCacheSize:24,lineDiffType:"none"},split:{poolSize:2,totalASTLRUCacheSize:56,lineDiffType:"word-alt"}};let vm,wm;const jm=t=>{const e=sd[t],n=new Ug({workerFactory:pN,poolSize:e.poolSize,totalASTLRUCacheSize:e.totalASTLRUCacheSize},{theme:{light:"pierre-light",dark:"pierre-dark"},langs:hN,lineDiffType:e.lineDiffType,preferredHighlighter:"shiki-wasm"});return n.initialize(),n},fN=t=>{if(!(typeof window>"u"))return t==="split"?(wm??=jm("split"),wm):(vm??=jm("unified"),vm)},gN=t=>{const e=at.c(7),{children:n,renderTheme:r}=t,a=nd("unified"),i=nd("split");let o,c;e[0]!==r||e[1]!==i||e[2]!==a?(o=()=>{a&&a.setRenderOptions({theme:r,lineDiffType:sd.unified.lineDiffType}),i&&i.setRenderOptions({theme:r,lineDiffType:sd.split.lineDiffType})},c=[r,i,a],e[0]=r,e[1]=i,e[2]=a,e[3]=o,e[4]=c):(o=e[3],c=e[4]),Be.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},xN=t=>{const e=at.c(11),{children:n}=t,r=Il();let a,i;if(e[0]!==r?.availableThemes||e[1]!==r?.darkThemeId||e[2]!==r?.lightThemeId){const p=li(!1),m=li(!0),u=r?.lightThemeId??p.metadata.id,h=r?.darkThemeId??m.metadata.id;i=r?.availableThemes.find(b=>b.metadata.id===u)??p,a=r?.availableThemes.find(b=>b.metadata.id===h)??m,ci(i),ci(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(gN,{renderTheme:c,children:n}),e[8]=n,e[9]=c,e[10]=d):d=e[10],d},nd=t=>{const e=at.c(2),n=t===void 0?"unified":t;let r;return e[0]!==n?(r=fN(n),e[0]=n,e[1]=r):r=e[1],r},bN=5e5,yN=`
15
- :host {
16
- font-family: var(--font-mono);
17
- font-size: var(--text-code);
18
- }
19
-
20
- pre, [data-code] {
21
- font-family: var(--font-mono);
22
- font-size: var(--text-code);
23
- }
24
-
25
- /* Mobile touch selection support */
26
- [data-line-number] {
27
- touch-action: manipulation;
28
- -webkit-tap-highlight-color: transparent;
29
- cursor: pointer;
30
- }
31
-
32
- /* Ensure interactive line numbers work on touch */
33
- pre[data-interactive-line-numbers] [data-line-number] {
34
- touch-action: manipulation;
35
- }
36
-
37
- [data-diff-header],
38
- [data-diff] {
39
- [data-separator] {
40
- height: 24px !important;
41
- }
42
- }
43
- `;function vN(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 Nm(t){const e=t.length>400?`${t.slice(0,200)}${t.slice(-200)}`:t;return`${t.length}:${vN(e)}`}const wN=(t,e,n)=>{const i=(n.side==="deletions"?t:e).split(`
44
- `),o=Math.min(n.start,n.end),c=Math.max(n.start,n.end),d=Math.max(1,o),p=Math.min(i.length,c);return d>p?"":i.slice(d-1,p).join(`
45
- `)},jN=(t,e)=>t===e?!0:!t||!e?!1:t.start===e.start&&t.end===e.end&&t.side===e.side,So=new WeakMap,NN={lineHeight:24,hunkSeparatorHeight:24,fileGap:0};function SN(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 kN(t){if(typeof document>"u")return null;const e=SN(t);let n=So.get(e.key);if(!n){const a=new Hg;a.setup(e.root,e.content),n={virtualizer:a,refs:0},So.set(e.key,n)}n.refs+=1;let r=!1;return{virtualizer:n.virtualizer,release:()=>{if(r)return;r=!0;const a=So.get(e.key);a&&(a.refs-=1,!(a.refs>0)&&(a.virtualizer.cleanUp(),So.delete(e.key)))}}}const Lf=({original:t,modified:e,language:n,fileName:r,renderSideBySide:a,wrapLines:i,layout:o="fill"})=>{const c=Il(),d=c?.currentTheme.metadata.variant==="dark",p=c?.availableThemes.find(q=>q.metadata.id===c.lightThemeId)??li(!1),m=c?.availableThemes.find(q=>q.metadata.id===c.darkThemeId)??li(!0),{isMobile:u}=an(),h=qd({source:"diff",fileLabel:r||"unknown",language:n,getCodeForRange:q=>wN(t,e,q),toStoreRange:q=>({startLine:q.start,endLine:q.end,side:q.side==="deletions"?"original":"modified"}),fromDraftRange:q=>({start:q.startLine,end:q.endLine,side:q.side==="original"?"deletions":"additions"})}),{drafts:b,selection:f,setSelection:v,commentText:x,setCommentText:g,editingDraftId:w,saveComment:y,cancel:k,startEdit:D,deleteDraft:j}=h,S=Be.useRef(null),A=Be.useRef(null),E=Be.useRef(!1),P=Be.useRef(null);Be.useEffect(()=>{S.current=f},[f]),Be.useEffect(()=>{A.current=w},[w]);const C=Be.useCallback(q=>{if(E.current)return;const te=S.current;if(u&&te&&q&&q.side===te.side){const U=Math.min(te.start,q.start),ae=Math.max(te.end,q.end);v({...q,start:U,end:ae})}else v(q);q&&(A.current||g(""))},[u,g,v]),N=Be.useCallback(()=>{k()},[k]),T=Be.useCallback(q=>{const te=document.createElement("div");te.style.position="relative";const U=zo(q.metadata);return te.dataset.annotationId=U,te.dataset.annotationSide=q.side,te.dataset.annotationLine=String(q.lineNumber),te},[]),M=Be.useCallback((q,te)=>{y(q,te??f??void 0)},[y,f]),R=Be.useCallback(q=>{v(q);const te=_.current;if(te)try{E.current=!0,te.setSelectedLines(q),P.current=q}catch{}finally{E.current=!1}},[v]),L=Be.useCallback(q=>{const te=q.closest("[data-line-type]")?.getAttribute("data-line-type")??q.getAttribute("data-line-type");if(te==="change-deletion")return"deletions";if(te==="change-addition")return"additions";const U=q.getAttribute("data-column-side")??q.getAttribute("data-side")??q.closest("[data-column-side]")?.getAttribute("data-column-side");if(U==="deletions"||U==="left"||U==="original")return"deletions";if(U==="additions"||U==="right"||U==="modified")return"additions";const ae=q.closest("[data-line-type]");if(ae instanceof HTMLElement){const je=ae.getBoundingClientRect(),oe=q.getBoundingClientRect(),ve=je.left+je.width/2;return oe.left+oe.width/2<ve?"deletions":"additions"}return"additions"},[]);ci(p),ci(m);const $=`${p.metadata.id}:${m.metadata.id}:${d?"dark":"light"}`,B=Be.useRef(null),O=Be.useRef(null),_=Be.useRef(null),ee=Be.useRef(null),[,z]=l.useReducer(q=>q+1,0),ne=nd(a?"split":"unified"),re=Be.useMemo(()=>gu(p),[p]),ue=Be.useMemo(()=>gu(m),[m]);l.useLayoutEffect(()=>{const q=B.current;if(!q)return;const te=q.querySelector("diffs-container");if(!te)return;const U=d?ue:re,ae=(Y,fe)=>Y.colors?.[fe],je=ae(re,"terminal.ansiGreen"),oe=ae(re,"terminal.ansiRed"),ve=ae(re,"terminal.ansiBlue"),K=ae(ue,"terminal.ansiGreen"),ce=ae(ue,"terminal.ansiRed"),Z=ae(ue,"terminal.ansiBlue");te.style.setProperty("--shiki-light",re.fg),te.style.setProperty("--shiki-light-bg",re.bg),je&&te.style.setProperty("--shiki-light-addition-color",je),oe&&te.style.setProperty("--shiki-light-deletion-color",oe),ve&&te.style.setProperty("--shiki-light-modified-color",ve),te.style.setProperty("--shiki-dark",ue.fg),te.style.setProperty("--shiki-dark-bg",ue.bg),K&&te.style.setProperty("--shiki-dark-addition-color",K),ce&&te.style.setProperty("--shiki-dark-deletion-color",ce),Z&&te.style.setProperty("--shiki-dark-modified-color",Z),te.style.setProperty("--diffs-bg",U.bg),te.style.setProperty("--diffs-fg",U.fg);const le=d?K:je,se=d?ce:oe,Ie=d?Z:ve;le&&te.style.setProperty("--diffs-addition-color-override",le),se&&te.style.setProperty("--diffs-deletion-color-override",se),Ie&&te.style.setProperty("--diffs-modified-color-override",Ie);const Ne=te.shadowRoot?.querySelector("pre");Ne&&(Ne.style.setProperty("--shiki-light",re.fg),Ne.style.setProperty("--shiki-light-bg",re.bg),je&&Ne.style.setProperty("--shiki-light-addition-color",je),oe&&Ne.style.setProperty("--shiki-light-deletion-color",oe),ve&&Ne.style.setProperty("--shiki-light-modified-color",ve),Ne.style.setProperty("--shiki-dark",ue.fg),Ne.style.setProperty("--shiki-dark-bg",ue.bg),K&&Ne.style.setProperty("--shiki-dark-addition-color",K),ce&&Ne.style.setProperty("--shiki-dark-deletion-color",ce),Z&&Ne.style.setProperty("--shiki-dark-modified-color",Z),Ne.style.setProperty("--diffs-bg",U.bg),Ne.style.setProperty("--diffs-fg",U.fg),le&&Ne.style.setProperty("--diffs-addition-color-override",le),se&&Ne.style.setProperty("--diffs-deletion-color-override",se),Ie&&Ne.style.setProperty("--diffs-modified-color-override",Ie))},[ue,$,d,re]);const Q=Be.useMemo(()=>Math.max(t.length,e.length)>bN,[t.length,e.length]),de=Be.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:Q?0:1e3,maxLineLengthForHighlighting:Q?1:1e3,expansionLineCount:20,overflow:i?"wrap":"scroll",disableFileHeader:!0,enableLineSelection:!0,enableHoverUtility:!1,onLineSelected:C,unsafeCSS:yN,renderAnnotation:T}),[m.metadata.id,d,Q,p.metadata.id,a,i,C,T]),X=Be.useMemo(()=>dN({drafts:b,editingDraftId:w,selection:f}),[w,b,f]),F=Be.useRef(X);if(Be.useEffect(()=>{F.current=X},[X]),Be.useEffect(()=>{if(typeof window>"u")return;const q=O.current;if(!q||!ne)return;_.current?.cleanUp(),_.current=null,ee.current?.release(),ee.current=null,q.innerHTML="";const te=kN(q);ee.current=te;const U=te?new Wg(de,te.virtualizer,NN,ne):new Kg(de,ne);_.current=U,P.current=null;const ae={name:r||"",contents:t,lang:n,cacheKey:`old:${$}:${r}:${Nm(t)}`},je={name:r||"",contents:e,lang:n,cacheKey:`new:${$}:${r}:${Nm(e)}`};return U.render({oldFile:ae,newFile:je,lineAnnotations:F.current,containerWrapper:q}),requestAnimationFrame(()=>{z()}),()=>{U.cleanUp(),_.current===U&&(_.current=null),te?.release(),te&&ee.current===te&&(ee.current=null),q.innerHTML=""}},[$,r,n,e,de,t,ne]),Be.useEffect(()=>{const q=_.current;if(q){try{q.setLineAnnotations(X)}catch(te){console.error("Failed to apply diff line annotations",te);try{q.setLineAnnotations([])}catch{}}requestAnimationFrame(()=>{if(_.current===q){try{q.rerender()}catch{}z()}})}},[X]),Be.useEffect(()=>{const q=_.current;if(!q||f!==null)return;const te=P.current;if(!jN(f,te))try{E.current=!0,q.setSelectedLines(f),P.current=f}catch{}finally{E.current=!1}},[f]),Be.useEffect(()=>{const q=O.current;if(!q)return;let te=null,U=()=>{};const ae=()=>{const oe=q.querySelector("diffs-container")?.shadowRoot;if(!oe){te=requestAnimationFrame(ae);return}const ve=K=>{if(!(K instanceof MouseEvent)||K.button!==0||!(K.target instanceof Element))return;const ce=K.target.closest("[data-column-number]");if(!(ce instanceof HTMLElement))return;const Z=ce.getAttribute("data-column-number"),le=Z?parseInt(Z,10):NaN;if(Number.isNaN(le))return;const se=L(ce);C({start:le,end:le,side:se}),K.preventDefault(),K.stopPropagation()};oe.addEventListener("click",ve,!0),U=()=>{oe.removeEventListener("click",ve,!0)}};return ae(),()=>{te!==null&&cancelAnimationFrame(te),U()}},[$,r,C,L]),Be.useEffect(()=>{const q=O.current;if(!q)return;let te=null,U=null;const je=setTimeout(()=>{const oe=q.querySelector("diffs-container");if(!(oe instanceof HTMLElement))return;const ve=oe.shadowRoot;te=new MutationObserver(()=>{U&&cancelAnimationFrame(U),U=requestAnimationFrame(()=>{z(),U=null})}),te.observe(oe,{childList:!0,subtree:!0}),ve&&te.observe(ve,{childList:!0,subtree:!0})},100);return()=>{clearTimeout(je),U&&cancelAnimationFrame(U),te?.disconnect()}},[$,r]),typeof window>"u")return null;const V=s.jsx(mN,{diffRootRef:B,drafts:b,selection:f,editingDraftId:w,commentText:x,fileLabel:r?.split("/").pop()??"",onSave:M,onCancel:N,onEdit:q=>{R({start:q.startLine,end:q.endLine,side:q.side==="original"?"deletions":"additions"}),D(q)},onDelete:j});return o==="fill"?s.jsx("div",{className:me("flex flex-col relative","size-full"),"data-diff-virtual-root":!0,children:s.jsxs("div",{className:"flex-1 relative min-h-0",children:[s.jsx(Ts,{outerClassName:"pierre-diff-wrapper size-full",disableHorizontal:!1,fillContainer:!0,"data-diff-virtual-content":!0,children:s.jsx("div",{ref:B,className:"size-full relative",children:s.jsx("div",{ref:O,className:"size-full"})})}),V]})}):s.jsxs("div",{className:me("relative","w-full"),children:[s.jsx("div",{ref:B,className:"pierre-diff-wrapper w-full overflow-x-auto overflow-y-visible relative",children:s.jsx("div",{ref:O,className:"w-full"})}),V]})},CN=1100,rd=15e3,Sm=500,IN=t=>t<=6?t:t<=12?6:t<=25?4:2,Of=l.memo(()=>{const t=at.c(4),{t:e}=pt();let n;t[0]!==e?(n=e("diffView.binary.unavailable"),t[0]=e,t[1]=n):n=t[1];let r;return t[2]!==n?(r=s.jsx("div",{className:"rounded-lg border border-border/60 bg-background px-3 py-2",children:s.jsx("div",{className:"typography-meta text-muted-foreground",children:n})}),t[2]=n,t[3]=r):r=t[3],r}),$f={"?":{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"}},PN=$f.M,Uo=[{value:"single",labelKey:"diffView.mode.single.label",descriptionKey:"diffView.mode.single.description"},{value:"stacked",labelKey:"diffView.mode.stacked.label",descriptionKey:"diffView.mode.stacked.description"}],AN=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"},Bf=t=>{const e=AN(t);return $f[e]??PN},DN=t=>{const{index:e,working_dir:n}=t;return e==="A"||n==="A"||e==="?"||n==="?"},TN=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),MN=(t,e)=>{const n=t.replace(/\\/g,"/").replace(/\/+$/g,""),r=e.replace(/\\/g,"/");if(TN(r))return r;const a=r.replace(/^\/+/,"");return n?`${n}/${a}`:a},km=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),Cm=(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},EN=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},hl=(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]})},RN=l.memo(t=>{const e=at.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}=pt();let h;e[0]!==o?(h=S=>{if(!o)return S;const A=S.lastIndexOf("/");return A>=0?S.slice(A+1):S},e[0]=o,e[1]=h):h=e[1];const b=h;if(n.length===0)return null;let f;e[2]!==b||e[3]!==a||e[4]!==u?(f=a?s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[s.jsx(br,{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)}),hl(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]=f):f=e[5];let v;e[6]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx(I,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[6]=v):v=e[6];let x;e[7]!==f?(x=s.jsx(Os,{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:[f,v]})}),e[7]=f,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($i,{className:"typography-meta text-muted-foreground",children:u("diffView.selector.viewMode")}),s.jsx(nl,{value:d,onValueChange:S=>p(S),children:Uo.map(S=>s.jsx(rl,{value:S.value,className:"items-center",children:s.jsx("span",{className:"typography-meta text-foreground",children:u(S.labelKey)})},S.value))}),s.jsx(Dn,{})]}):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=A=>s.jsx(rl,{value:A.path,children:s.jsxs("div",{className:"flex w-full min-w-0 items-center gap-3",children:[s.jsx(br,{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)}),s.jsx("span",{className:"ml-auto",children:hl(A.insertions,A.deletions)})]})},A.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 k;e[19]!==i||e[20]!==w||e[21]!==y?(k=s.jsx(nl,{value:w,onValueChange:i,children:y}),e[19]=i,e[20]=w,e[21]=y,e[22]=k):k=e[22];let D;e[23]!==g||e[24]!==k?(D=s.jsxs($s,{className:"max-h-[70vh] min-w-[320px] overflow-y-auto",children:[g,k]}),e[23]=g,e[24]=k,e[25]=D):D=e[25];let j;return e[26]!==D||e[27]!==x?(j=s.jsxs(Bs,{children:[x,D]}),e[26]=D,e[27]=x,e[28]=j):j=e[28],j}),FN=l.memo(t=>{const e=at.c(31),{mode:n,onModeChange:r}=t,{t:a}=pt();let i,o,c,d,p,m;if(e[0]!==n||e[1]!==a){const y=Uo.find(k=>k.value===n)??Uo[0];o=Bs,i=Os,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 h;e[11]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(I,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[11]=h):h=e[11];let b;e[12]!==p||e[13]!==u?(b=s.jsxs("button",{className:p,children:[u,h]}),e[12]=p,e[13]=u,e[14]=b):b=e[14];let f;e[15]!==i||e[16]!==m||e[17]!==b?(f=s.jsx(i,{asChild:m,children:b}),e[15]=i,e[16]=m,e[17]=b,e[18]=f):f=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=Uo.map(y=>s.jsx(rl,{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($s,{className:"min-w-[140px]",children:s.jsx(nl,{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]!==f?(w=s.jsxs(o,{children:[f,g]}),e[27]=o,e[28]=g,e[29]=f,e[30]=w):w=e[30],w}),LN=l.memo(t=>{const e=at.c(11),{changedFiles:n,selectedFile:r,onSelectFile:a}=t,{t:i}=pt();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=Bf(p),u=r===p.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>a(p.path),className:me("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left transition-colors",u?"bg-interactive-selection text-interactive-selection-foreground":"text-muted-foreground hover:bg-interactive-hover hover:text-foreground"),children:[s.jsx(br,{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}),hl(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(Ts,{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}),ON=l.memo(t=>{const e=at.c(21),{filePath:n,diff:r,isVisible:a,renderSideBySide:i}=t,{t:o}=pt(),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 h;e[2]!==r.original||e[3]!==n||e[4]!==c||e[5]!==m||e[6]!==i||e[7]!==o?(h=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]=h):h=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 f;return e[17]!==p||e[18]!==h||e[19]!==b?(f=s.jsx("div",{className:"absolute inset-0 overflow-auto p-4",style:u,children:s.jsxs("div",{className:p,children:[h,b]})}),e[17]=p,e[18]=h,e[19]=b,e[20]=f):f=e[20],f}),$N=l.memo(t=>{const e=at.c(20),{filePath:n,diff:r,renderSideBySide:a}=t,{t:i}=pt(),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 h;e[8]!==r.modified||e[9]!==n||e[10]!==c||e[11]!==o||e[12]!==p||e[13]!==a||e[14]!==i?(h=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]=h):h=e[15];let b;return e[16]!==d||e[17]!==u||e[18]!==h?(b=s.jsx("div",{className:"w-full overflow-auto p-4",style:m,children:s.jsxs("div",{className:d,children:[u,h]})}),e[16]=d,e[17]=u,e[18]=h,e[19]=b):b=e[19],b}),BN=l.memo(t=>{const e=at.c(15),{filePath:n,diff:r,renderSideBySide:a,wrapLines:i}=t;let o;e[0]!==n?(o=Wi(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(Of,{}),e[2]=m):m=e[2],m}if(di(n)){let m;return e[3]!==r||e[4]!==n||e[5]!==a?(m=s.jsx($N,{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(Lf,{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}),_N=l.memo(t=>{const e=at.c(15),{filePath:n,diff:r,isVisible:a,renderSideBySide:i,wrapLines:o}=t;let c;e[0]!==n?(c=Wi(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(Of,{}),e[2]=m):m=e[2],m}if(!a)return null;if(di(n)){let m;return e[3]!==r||e[4]!==n||e[5]!==a||e[6]!==i?(m=s.jsx(ON,{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(Ts,{outerClassName:"absolute inset-0",disableHorizontal:!1,observeMutations:!1,preventOverscroll:!0,"data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:s.jsx(Lf,{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}),VN=l.memo(t=>{const e=at.c(122),{directory:n,file:r,layout:a,wrapLines:i,scrollRootRef:o,isSelected:c,onSelect:d,registerSectionRef:p,defaultCollapsed:m,expandRequestPath:u,expandRequestNonce:h,showOpenInEditorAction:b,isOpeningInEditor:f,onOpenInEditor:v}=t,x=m===void 0?!1:m,g=u===void 0?null:u,w=h===void 0?0:h,y=b===void 0?!1:b,k=f===void 0?!1:f,{t:D}=pt(),{git:j}=_n();let S;e[0]!==n||e[1]!==r.path?(S=qe=>qe.directories.get(n)?.diffCache.get(r.path)??null,e[0]=n,e[1]=r.path,e[2]=S):S=e[2];const A=nn(S),E=nn(UN),P=Te(WN),[C,N]=l.useState(!x),[T,M]=l.useState(!1),[R,L]=l.useState(0),[$,B]=l.useState(null),[O,_]=l.useState(!1),[ee,z]=l.useState(!1),ne=l.useRef(null),re=l.useRef(null);let ue;e[3]!==r?(ue=Bf(r),e[3]=r,e[4]=ue):ue=e[4];const Q=ue,de=a==="side-by-side";let X;e:{if(!A){X=null;break e}let qe;e[5]!==A.isBinary||e[6]!==A.modified||e[7]!==A.original?(qe={original:A.original,modified:A.modified,isBinary:A.isBinary},e[5]=A.isBinary,e[6]=A.modified,e[7]=A.original,e[8]=qe):qe=e[8],X=qe}const F=X;let V;e[9]!==r.path||e[10]!==p?(V=qe=>{re.current=qe,p(r.path,qe)},e[9]=r.path,e[10]=p,e[11]=V):V=e[11];const q=V;let te;e[12]===Symbol.for("react.memo_cache_sentinel")?(te=qe=>{N(qe),qe&&M(!0)},e[12]=te):te=e[12];const U=te;let ae;e[13]!==r.path||e[14]!==d?(ae=()=>{d(r.path)},e[13]=r.path,e[14]=d,e[15]=ae):ae=e[15];const je=ae;let oe,ve;e[16]!==T||e[17]!==C||e[18]!==o?(oe=()=>{if(!C||T)return;const qe=re.current;if(!qe)return;if(!o.current||typeof IntersectionObserver>"u"){M(!0);return}const et=new IntersectionObserver(Ke=>{Ke.some(KN)&&(M(!0),et.disconnect())},{root:o.current,rootMargin:"200px 0px",threshold:.1});return et.observe(qe),()=>et.disconnect()},ve=[T,C,o],e[16]=T,e[17]=C,e[18]=o,e[19]=oe,e[20]=ve):(oe=e[19],ve=e[20]),l.useEffect(oe,ve);let K,ce;e[21]!==w||e[22]!==g||e[23]!==r.path?(K=()=>{w<=0||g!==r.path||(N(!0),M(!0))},ce=[w,g,r.path],e[21]=w,e[22]=g,e[23]=r.path,e[24]=K,e[25]=ce):(K=e[24],ce=e[25]),l.useEffect(K,ce);let Z,le;e[26]!==F||e[27]!==R||e[28]!==n||e[29]!==r.path||e[30]!==j||e[31]!==T||e[32]!==C||e[33]!==E?(Z=()=>{if(!C||!T)return;if(!n||F){ne.current=null,_(!1);return}const qe=`${n}::${r.path}::${R}`;if(ne.current===qe)return;ne.current=qe,B(null),_(!0);let et=!1;const Ke=j.getGitFileDiff(n,{path:r.path}),st=new Promise(HN);return Promise.race([Ke,st]).then(nt=>{et||(E(n,r.path,{original:nt.original??"",modified:nt.modified??"",isBinary:nt.isBinary}),_(!1))}).catch(nt=>{if(et)return;const ye=nt instanceof Error?nt.message:String(nt);B(ye),_(!1)}),()=>{et=!0,ne.current===qe&&(ne.current=null)}},le=[n,F,R,r.path,j,T,C,E],e[26]=F,e[27]=R,e[28]=n,e[29]=r.path,e[30]=j,e[31]=T,e[32]=C,e[33]=E,e[34]=Z,e[35]=le):(Z=e[34],le=e[35]),l.useEffect(Z,le);let se;e[36]!==je||e[37]!==C?(se=()=>{U(!C),je()},e[36]=je,e[37]=C,e[38]=se):se=e[38];const Ie=se,Ne=C?"rounded-b-none":"rounded-b-xl",Y=c?"ring-1 ring-inset ring-[var(--interactive-selection)]":null;let fe;e[39]!==Ne||e[40]!==Y?(fe=me("group/header relative flex w-full items-center gap-2 px-3 py-1.5 rounded-t-xl border border-border/60 overflow-hidden","bg-background",Ne,"text-muted-foreground hover:text-foreground",Y),e[39]=Ne,e[40]=Y,e[41]=fe):fe=e[41];let ke;e[42]===Symbol.for("react.memo_cache_sentinel")?(ke=s.jsx("div",{className:"absolute inset-0 pointer-events-none group-hover/header:bg-interactive-hover"}),e[42]=ke):ke=e[42];let be;e[43]!==C?(be=s.jsx("span",{className:"flex size-5 items-center justify-center opacity-70 group-hover/header:opacity-100",children:C?s.jsx(I,{name:"arrow-down-s",className:"size-4"}):s.jsx(I,{name:"arrow-right-s",className:"size-4"})}),e[43]=C,e[44]=be):be=e[44];let pe;e[45]!==Q.color?(pe={color:Q.color},e[45]=Q.color,e[46]=pe):pe=e[46];let Ee;e[47]!==Q.descriptionKey||e[48]!==D?(Ee=D(Q.descriptionKey),e[47]=Q.descriptionKey,e[48]=D,e[49]=Ee):Ee=e[49];let ze;e[50]!==Q.descriptionKey||e[51]!==D?(ze=D(Q.descriptionKey),e[50]=Q.descriptionKey,e[51]=D,e[52]=ze):ze=e[52];let G;e[53]!==Q.code||e[54]!==pe||e[55]!==Ee||e[56]!==ze?(G=s.jsx("span",{className:"typography-micro font-semibold leading-none w-4 text-center uppercase",style:pe,title:Ee,"aria-label":ze,children:Q.code}),e[53]=Q.code,e[54]=pe,e[55]=Ee,e[56]=ze,e[57]=G):G=e[57];const Pe=r.path;let Le;e[58]!==r.path?(Le=s.jsx(br,{filePath:r.path,className:"h-3.5 w-3.5 flex-shrink-0 align-middle"}),e[58]=r.path,e[59]=Le):Le=e[59];let Ae;if(e[60]!==r.path){e:{const qe=r.path.lastIndexOf("/");if(qe===-1){let Ue;e[62]===Symbol.for("react.memo_cache_sentinel")?(Ue={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},e[62]=Ue):Ue=e[62],Ae=s.jsx("span",{className:"block min-w-0 truncate typography-ui-label text-foreground",style:Ue,children:r.path});break e}const et=r.path.slice(0,qe),Ke=r.path.slice(qe+1);let st;e[63]===Symbol.for("react.memo_cache_sentinel")?(st={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},e[63]=st):st=e[63];let nt;e[64]!==et?(nt=s.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:st,children:et}),e[64]=et,e[65]=nt):nt=e[65];let ye;e[66]===Symbol.for("react.memo_cache_sentinel")?(ye=s.jsx("span",{className:"text-muted-foreground",children:"/"}),e[66]=ye):ye=e[66];let Je;e[67]!==Ke?(Je=s.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[ye,s.jsx("span",{className:"text-foreground",children:Ke})]}),e[67]=Ke,e[68]=Je):Je=e[68];let _e;e[69]!==nt||e[70]!==Je?(_e=s.jsxs("span",{className:"flex min-w-0 items-baseline overflow-hidden",children:[nt,Je]}),e[69]=nt,e[70]=Je,e[71]=_e):_e=e[71],Ae=_e}e[60]=r.path,e[61]=Ae}else Ae=e[61];let ge;e[72]!==Le||e[73]!==Ae?(ge=s.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[Le,Ae]}),e[72]=Le,e[73]=Ae,e[74]=ge):ge=e[74];let W;e[75]!==r.path||e[76]!==ge?(W=s.jsx("span",{className:"min-w-0 flex-1 overflow-hidden typography-ui-label",title:Pe,children:ge}),e[75]=r.path,e[76]=ge,e[77]=W):W=e[77];let ie;e[78]!==be||e[79]!==G||e[80]!==W?(ie=s.jsxs("div",{className:"relative flex min-w-0 flex-1 items-center gap-2",children:[be,G,W]}),e[78]=be,e[79]=G,e[80]=W,e[81]=ie):ie=e[81];let Me;e[82]!==r.deletions||e[83]!==r.insertions?(Me=hl(r.insertions,r.deletions),e[82]=r.deletions,e[83]=r.insertions,e[84]=Me):Me=e[84];let Ve;e[85]!==F||e[86]!==r.path||e[87]!==k||e[88]!==v||e[89]!==y||e[90]!==D?(Ve=y&&v?s.jsx(we,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",title:D("diffView.actions.openFileInEditorAtChange"),onClick:qe=>{qe.stopPropagation(),v(r.path,F)},disabled:k,children:k?s.jsx(I,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(I,{name:"edit",className:"size-3.5"})}):null,e[85]=F,e[86]=r.path,e[87]=k,e[88]=v,e[89]=y,e[90]=D,e[91]=Ve):Ve=e[91];const Ce=de?"side-by-side":"unified";let xe;e[92]!==r.path||e[93]!==P?(xe=qe=>{const et=qe==="side-by-side"?"side-by-side":"inline";P(r.path,et)},e[92]=r.path,e[93]=P,e[94]=xe):xe=e[94];let De;e[95]!==Ce||e[96]!==xe?(De=s.jsx(Bh,{mode:Ce,onModeChange:xe,className:"opacity-70"}),e[95]=Ce,e[96]=xe,e[97]=De):De=e[97];let Ye;e[98]!==Me||e[99]!==Ve||e[100]!==De?(Ye=s.jsxs("div",{className:"relative flex items-center gap-2",children:[Me,Ve,De]}),e[98]=Me,e[99]=Ve,e[100]=De,e[101]=Ye):Ye=e[101];let rt;e[102]!==Ie||e[103]!==fe||e[104]!==ie||e[105]!==Ye?(rt=s.jsx("div",{className:"sticky top-0 z-10 bg-background",children:s.jsxs("button",{type:"button",onClick:Ie,className:fe,children:[ke,ie,Ye]})}),e[102]=Ie,e[103]=fe,e[104]=ie,e[105]=Ye,e[106]=rt):rt=e[106];let Re;e[107]!==F||e[108]!==$||e[109]!==r.deletions||e[110]!==r.insertions||e[111]!==r.path||e[112]!==ee||e[113]!==C||e[114]!==O||e[115]!==de||e[116]!==i?(Re=C&&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:()=>L(GN),children:"Retry"})]}):null,O&&!F&&!$?s.jsxs("div",{className:"flex items-center justify-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"animate-spin"}),"Loading diff…"]}):null,F&&!ee&&r.insertions+r.deletions>Sm?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:()=>z(!0),children:"Render anyway"})]}):null,F&&(ee||r.insertions+r.deletions<=Sm)?s.jsx(BN,{filePath:r.path,diff:F,renderSideBySide:de,wrapLines:i}):null]}),e[107]=F,e[108]=$,e[109]=r.deletions,e[110]=r.insertions,e[111]=r.path,e[112]=ee,e[113]=C,e[114]=O,e[115]=de,e[116]=i,e[117]=Re):Re=e[117];let he;return e[118]!==q||e[119]!==rt||e[120]!==Re?(he=s.jsxs("div",{ref:q,className:"scroll-mt-4",children:[rt,Re]}),e[118]=q,e[119]=rt,e[120]=Re,e[121]=he):he=e[121],he}),_f=({hideStackedFileSidebar:t=!1,stackedDefaultCollapsedAll:e=!1,hideFileSelector:n=!1,pinSelectedFileHeaderToTopOnNavigate:r=!1,showOpenInEditorAction:a=!1})=>{const{t:i}=pt(),{git:o,files:c}=_n(),d=Er(),{screenWidth:p,isMobile:m}=an(),u=Dd(d??null),h=Sl(d??null),b=Md(d??null),f=nn(ie=>ie.setActiveDirectory),v=nn(ie=>ie.ensureStatus),x=nn(ie=>ie.fetchStatus),g=nn(ie=>ie.setDiff),[w,y]=l.useState(null),[k,D]=l.useState(null),[j,S]=l.useState(0),[A,E]=l.useState(null),[P,C]=l.useState(0),[N,T]=l.useState(null),M=l.useRef(null),R=Te(ie=>ie.pendingDiffFile),L=Te(ie=>ie.setPendingDiffFile),$=Te(ie=>ie.diffLayoutPreference),B=Te(ie=>ie.diffFileLayout),O=Te(ie=>ie.setDiffFileLayout),_=Te(ie=>ie.diffWrapLines),ee=Te(ie=>ie.setDiffWrapLines),z=Te(ie=>ie.diffViewMode),ne=Te(ie=>ie.setDiffViewMode),re=Te(ie=>ie.openContextFileAtLine),ue=_,Q=z==="stacked",de=m||p<=768,X=!t&&!de&&p>=1024,F=l.useRef(null),V=l.useRef(new Map),q=l.useRef(null),te=l.useRef(null),U=l.useRef(!1);l.useEffect(()=>{if(!r||!Q||!A)return;const ie=F.current;if(!ie)return;let Me=null,Ve=!1,Ce=0;const xe=Date.now()+1200;let De=0;const Ye=()=>{Ve||(Ve=!0,E(null))},rt=()=>{Ye()},Re=()=>{if(De>0){De-=1;return}Ye()};window.addEventListener("wheel",rt,{passive:!0,capture:!0}),window.addEventListener("touchstart",rt,{passive:!0,capture:!0}),window.addEventListener("pointerdown",rt,{capture:!0}),window.addEventListener("keydown",rt,{capture:!0}),ie.addEventListener("scroll",Re,{passive:!0});const he=()=>{if(Ve||Date.now()>xe){Ye();return}const qe=F.current,et=V.current.get(A);if(!qe||!et){Ye();return}const Ke=qe.getBoundingClientRect(),nt=et.getBoundingClientRect().top-Ke.top;if(Math.abs(nt)<=1){if(Ce+=1,Ce>=2){Ye();return}}else{Ce=0;const ye=Math.max(0,qe.scrollHeight-qe.clientHeight),Je=Math.min(ye,Math.max(0,qe.scrollTop+nt));if(Math.abs(Je-qe.scrollTop)<=.5){Ye();return}De+=1,qe.scrollTop=Je}Me=window.requestAnimationFrame(he)};return Me=window.requestAnimationFrame(he),()=>{Ve=!0,Me!==null&&window.cancelAnimationFrame(Me),window.removeEventListener("wheel",rt,!0),window.removeEventListener("touchstart",rt,!0),window.removeEventListener("pointerdown",rt,!0),window.removeEventListener("keydown",rt,!0),ie.removeEventListener("scroll",Re)}},[Q,r,A]);const ae=l.useMemo(()=>{if(!h?.files)return[];const ie=h.diffStats??{};return h.files.map(Me=>({...Me,insertions:ie[Me.path]?.insertions??0,deletions:ie[Me.path]?.deletions??0,isNew:DN(Me)})).sort((Me,Ve)=>Me.path.localeCompare(Ve.path))},[h]),je=l.useMemo(()=>w?ae.find(ie=>ie.path===w)??null:null,[ae,w]),oe=l.useCallback(ie=>{const Me=B[ie.path];if(Me)return Me;if($==="inline")return"inline";if($==="side-by-side")return"side-by-side";const Ve=p<CN;return ie.isNew||Ve?"inline":"side-by-side"},[B,$,p]),ve=l.useMemo(()=>je?oe(je):null,[oe,je]);l.useEffect(()=>{d&&(f(d),v(d,o))},[d,f,v,o]),l.useEffect(()=>{if(d)return yr.onGitRefreshHint(ie=>{km(ie.directory)===km(d)&&x(d,o)})},[d,x,o]),l.useEffect(()=>{R&&(y(R),L(null),Q&&(U.current=!0,q.current=R,D(R),S(ie=>ie+1)))},[Q,R,L]),l.useEffect(()=>{!w&&!R&&ae.length>0&&y(ae[0].path)},[ae,w,R]),l.useEffect(()=>{w&&ae.length>0&&(ae.some(Me=>Me.path===w)||y(ae[0]?.path??null))},[ae,w]);const K=l.useCallback((ie,Me)=>{const Ve=V.current;Me?Ve.set(ie,Me):Ve.delete(ie)},[]),ce=l.useCallback(ie=>{const Me=V.current.get(ie),Ve=F.current;if(!Me||!Ve)return{ok:!1,aligned:!1,didMove:!1,atScrollLimit:!1,delta:0};const Ce=Ve.getBoundingClientRect(),De=Me.getBoundingClientRect().top-Ce.top,Ye=Math.max(0,Ve.scrollHeight-Ve.clientHeight),rt=Ve.scrollTop+De,Re=Math.min(Ye,Math.max(0,rt)),he=Math.abs(Re-Ve.scrollTop)>.5;Ve.scrollTop=Re;const qe=Math.abs(De)<=1,et=Re<=.5||Re>=Ye-.5;return{ok:!0,aligned:qe,didMove:he,atScrollLimit:et,delta:De}},[]);l.useEffect(()=>{if(!Q){q.current=null,U.current=!1,te.current!==null&&(window.cancelAnimationFrame(te.current),te.current=null);return}if(!q.current)return;let Me=0;const Ve=120;let Ce=!1,xe=0,De=!1,Ye=0;const rt=Date.now()+2e3,Re=()=>{De||(De=!0,window.removeEventListener("wheel",qe,!0),window.removeEventListener("touchstart",qe,!0),window.removeEventListener("pointerdown",qe,!0),window.removeEventListener("keydown",qe,!0),Ke?.removeEventListener("scroll",et))},he=()=>{Ce||(Ce=!0,Re(),q.current=null,U.current=!1,te.current!==null&&(window.cancelAnimationFrame(te.current),te.current=null))},qe=()=>{he()},et=()=>{if(xe>0){xe-=1;return}he()},Ke=F.current;window.addEventListener("wheel",qe,{passive:!0,capture:!0}),window.addEventListener("touchstart",qe,{passive:!0,capture:!0}),window.addEventListener("pointerdown",qe,{capture:!0}),window.addEventListener("keydown",qe,{capture:!0}),Ke?.addEventListener("scroll",et,{passive:!0});const st=()=>{if(Date.now()>rt){he(),te.current=null;return}if(Ce){te.current=null;return}const nt=q.current;if(!nt){he(),te.current=null;return}xe+=1;const ye=ce(nt);if(!ye.ok){xe=Math.max(0,xe-1),Me+=1,Me<Ve?te.current=window.requestAnimationFrame(st):(he(),te.current=null);return}if(!ye.aligned){if(Me+=1,ye.didMove){if(Ye=0,Me<Ve){te.current=window.requestAnimationFrame(st);return}}else if(Ye+=1,Ye<6&&(ye.atScrollLimit||Math.abs(ye.delta)>1)){te.current=window.requestAnimationFrame(st);return}}r&&U.current&&E(nt),he()};return te.current=window.requestAnimationFrame(st),()=>{Ce=!0,Re(),te.current!==null&&(window.cancelAnimationFrame(te.current),te.current=null)}},[Q,r,ce,w,j]);const Z=l.useCallback(ie=>{y(ie)},[]),le=l.useCallback(ie=>{if(te.current!==null&&(window.cancelAnimationFrame(te.current),te.current=null),q.current=null,y(ie),!Q){U.current=!1;return}U.current=!0,q.current=ie,ce(ie)},[Q,ce]),se=l.useCallback(ie=>{ne(ie),ie==="stacked"&&w&&(ce(w).aligned||(q.current=w))},[ce,w,ne]),Ie=l.useCallback(ie=>{const Me=ie==="side-by-side"?"side-by-side":"inline";if(Q){ae.forEach(Ve=>{O(Ve.path,Me)});return}je&&O(je.path,Me)},[ae,Q,je,O]),Ne=(ve??"side-by-side")==="side-by-side",Y=!n&&(!Q||!X),fe=nn(l.useCallback(ie=>!d||!w?null:ie.directories.get(d)?.diffCache.get(w)??null,[d,w])),ke=l.useMemo(()=>fe?{original:fe.original,modified:fe.modified,isBinary:fe.isBinary}:null,[fe]),[be,pe]=l.useState(null),Ee=l.useCallback(async(ie,Me)=>{if(!(!d||!ie)){pe(ie);try{let Ve=null;if(Me&&!Me.isBinary&&!di(ie)&&(Ve=Cm(Me.original,Me.modified)),Ve===null)try{const rt=await o.getGitDiff(d,{path:ie,contextLines:3});Ve=EN(rt.diff)}catch{Ve=null}let Ce=Me;if(Ve===null||!Ce){const rt=await o.getGitFileDiff(d,{path:ie});Ce={original:rt.original??"",modified:rt.modified??"",isBinary:rt.isBinary},g(d,ie,Ce)}const xe=Ve??(Ce.isBinary||di(ie)?1:Cm(Ce.original,Ce.modified)),De=MN(d,ie),Ye=await Hd(c,De);if(!Ye.ok){H.error(Gd(Ye.reason));return}re(d,De,xe,1)}finally{pe(Ve=>Ve===ie?null:Ve)}}},[d,c,o,re,g]),ze=l.useCallback(async()=>{w&&await Ee(w,ke)},[Ee,ke,w]),G=!!(w&&be===w),Pe=!!fe,Le=!Q&&!!w&&!Pe;l.useEffect(()=>{if(Q)return;if(T(null),!d||!w){M.current=null;return}if(fe){M.current=null;return}const ie=`${d}::${w}::${P}`;if(M.current===ie)return;M.current=ie;let Me=!1;const Ve=o.getGitFileDiff(d,{path:w}),Ce=rd,xe=new Promise((De,Ye)=>{setTimeout(()=>Ye(new Error(`Timed out after ${Ce}ms`)),Ce)});return Promise.race([Ve,xe]).then(De=>{Me||g(d,w,{original:De.original??"",modified:De.modified??"",isBinary:De.isBinary})}).catch(De=>{if(Me)return;const Ye=De instanceof Error?De.message:String(De);T(Ye)}),()=>{Me=!0,M.current===ie&&(M.current=null)}},[d,Q,w,fe,o,g,P]);const Ae=()=>!d||!w||!ke?null:s.jsx(_N,{filePath:w,diff:ke,isVisible:!0,renderSideBySide:Ne,wrapLines:ue},w),ge=()=>{if(!d)return null;const ie=IN(ae.length);return s.jsxs("div",{className:"flex flex-1 min-h-0 h-full gap-3 px-3 pb-3 pt-2",children:[X&&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:ae.length})]}),s.jsx(LN,{changedFiles:ae,selectedFile:w,onSelectFile:le})]}),s.jsx(Ts,{ref:F,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:ae.map((Me,Ve)=>s.jsx(VN,{directory:d,file:Me,layout:oe(Me),wrapLines:ue,scrollRootRef:F,isSelected:Me.path===w,onSelect:Z,registerSectionRef:K,defaultCollapsed:e?!0:Ve>=ie,expandRequestPath:k,expandRequestNonce:j,showOpenInEditorAction:a,isOpeningInEditor:be===Me.path,onOpenInEditor:(Ce,xe)=>{Ee(Ce,xe)}},Me.path))})})]})},W=()=>d?b&&!h?s.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"animate-spin"}),i("diffView.state.loadingRepositoryStatus")]}):u===!1?s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:i("diffView.state.notGitRepository")}):ae.length===0?s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:i("diffView.state.cleanWorkingTree")}):Q?ge():s.jsxs("div",{className:"flex flex-1 min-h-0 overflow-hidden px-3 py-3 relative","data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:[Ae(),Le&&!Pe&&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:()=>{T(null),C(ie=>ie+1)},children:i("diffView.actions.retry")})]}):s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"loader-4",className:"animate-spin"}),i("diffView.state.loadingDiff")]})})]}):s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:i("diffView.state.selectSessionDirectory")});return s.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background",children:[s.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 bg-background",children:[!m&&s.jsxs("div",{className:"flex items-center gap-1 rounded-md px-2 py-1 text-muted-foreground shrink-0",children:[s.jsx(I,{name:"git-commit",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:b&&!h?i("diffView.state.loadingChanges"):ae.length===1?i("diffView.summary.changedFilesSingle",{count:ae.length}):i("diffView.summary.changedFilesPlural",{count:ae.length})})]}),!de&&s.jsx(FN,{mode:z,onModeChange:se}),Y&&s.jsx(RN,{changedFiles:ae,selectedFile:w,selectedFileEntry:je,onSelectFile:le,isMobile:de,showModeSelector:de,mode:z,onModeChange:se}),s.jsx("div",{className:"flex-1"}),je&&s.jsx(we,{variant:"ghost",size:"sm",onClick:()=>ee(!_),className:me("h-5 w-5 p-0 transition-opacity",ue?"text-foreground opacity-100":"text-muted-foreground opacity-60 hover:opacity-100"),title:i(ue?"diffView.actions.disableLineWrap":"diffView.actions.enableLineWrap"),children:s.jsx(I,{name:"text-wrap",className:"size-4"})}),a&&je&&!Q&&s.jsx(we,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",onClick:()=>{ze()},disabled:G,title:i("diffView.actions.openFileAtFirstChangedLine"),children:G?s.jsx(I,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(I,{name:"edit",className:"size-3.5"})}),je&&ve&&s.jsx(Bh,{mode:ve==="side-by-side"?"side-by-side":"unified",onModeChange:Ie})]}),W()]})},zN=()=>{const t=at.c(6),{git:e}=_n(),n=Er(),r=nn(qN),a=nn(JN),i=hb(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 UN(t){return t.setDiff}function WN(t){return t.setDiffFileLayout}function KN(t){return t.isIntersecting}function HN(t,e){setTimeout(()=>e(new Error(`Timed out after ${rd}ms`)),rd)}function GN(t){return t+1}function qN(t){return t.setActiveDirectory}function JN(t){return t.ensureStatus}const QN=Object.freeze(Object.defineProperty({__proto__:null,DiffView:_f,useDiffFileCount:zN},Symbol.toStringTag,{value:"Module"})),YN={next:"Next match",prev:"Previous match",select:"Select all matches",replace:"Replace",replaceAll:"Replace all",close:"Close"},XN={case:"Match case",re:"Regular expression",word:"Match whole word"};function ZN(t){const e=t.querySelector(".cm-search");if(e){for(const[n,r]of Object.entries(YN)){const a=e.querySelector(`button[name="${n}"]`);a&&!a.title&&(a.title=r)}for(const[n,r]of Object.entries(XN)){const i=e.querySelector(`input[name="${n}"]`)?.parentElement;i&&!i.title&&(i.title=r)}}}const Im=new xi,Pm=new xi,Am=new xi,Dm=new xi,Tm=new xi,Mm=new xi,Em=t=>t,fc=sx,e2=nx,t2=rx;class s2 extends ax{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 Rm=(t,e)=>!t||t.length===0?[]:tx.define({create(n){const r=new jh,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,Nh.widget({widget:new s2(i.id,e),block:!0,side:1}))}return r.finish()},update(n,r){return n.map(r.changes)},provide:n=>Yn.decorations.from(n)}),Fm=t=>{if(!t)return[];const e=Math.max(1,t.start),n=Math.max(e,t.end);return ex.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 jh;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,Nh.line({class:"oc-cm-selected-line"}))}return a.finish()}},{decorations:r=>r.decorations})};function ad({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:h}){const b=l.useRef(null),f=l.useRef(null),v=l.useRef(t),x=l.useRef(e),g=l.useRef(c),w=l.useRef(d),y=l.useRef(h),k=l.useRef(p),D=l.useRef(new Map),[j,S]=l.useState([]),A=l.useCallback(P=>{const C=(P??[]).map(N=>{const T=D.current.get(N.id);return T?{id:N.id,content:N.content,container:T}:null}).filter(N=>N!==null);S(N=>N.length===C.length&&N.every((T,M)=>{const R=C[M];return T.id===R.id&&T.content===R.content&&T.container===R.container})?N:C)},[]),E=l.useCallback(P=>{const C=b.current,N=P??f.current;if(!C||!N)return;const T=N.dom.querySelector(".cm-gutters"),M=T instanceof HTMLElement?T.getBoundingClientRect().width:0;C.style.setProperty("--oc-editor-gutter-width",`${M}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=h},[h]),l.useEffect(()=>{k.current=p,A(p)},[p,A]),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 T=window.__OPENCHAMBER_CSP_NONCE__;return typeof T=="string"&&T.length>0?T:null})(),C=Gg.create({doc:v.current,extensions:[...P?[Yn.cspNonce.of(P)]:[],qg({fixed:!0}),Im.of(ru(i)),Jg(),Qg.of(" "),Vl.of([Yg,...Xg,...Zg]),Yn.updateListener.of(N=>{E(N.view),(N.viewportChanged||N.geometryChanged)&&A(k.current);const T=au(N.startState),M=au(N.state);if(T!==M&&y.current?.(M),!N.docChanged)return;const R=N.state.doc.toString();v.current=R,x.current(R),A(k.current)}),Pm.of(Yn.editable.of(!a)),Am.of(n??[]),Dm.of(Fm(o)),Tm.of(Rm(p,D.current)),Mm.of(m?[iu({top:!0}),Vl.of(Em(ou))]:[])]});return f.current=new Yn({state:C,parent:b.current}),fc(f.current,f.current.state.doc.length,200),f.current.requestMeasure(),requestAnimationFrame(()=>{E(f.current),A(k.current)}),f.current&&g.current?.(f.current),()=>{w.current?.(),f.current?.destroy(),f.current=null,S([])}},[k,E,A]),l.useEffect(()=>{const P=f.current;P&&(P.dispatch({effects:[Im.reconfigure(ru(i)),Pm.reconfigure(Yn.editable.of(!a)),Am.reconfigure(n??[]),Dm.reconfigure(Fm(o)),Tm.reconfigure(Rm(p,D.current)),Mm.reconfigure(m?[iu({top:!0}),Vl.of(Em(ou))]:[])]}),fc(P,P.state.doc.length,200),P.requestMeasure(),requestAnimationFrame(()=>{E(P),A(k.current)}))},[n,o,i,a,p,m,E,A]),l.useEffect(()=>{const P=f.current;!P||m===!1||(u?(e2(P),requestAnimationFrame(()=>{ZN(P.dom)})):t2(P))},[u,m]),l.useEffect(()=>{const P=f.current;if(!P)return;const C=P.state.doc.toString();C!==t&&(P.dispatch({changes:{from:0,to:C.length,insert:t}}),fc(P,P.state.doc.length,300),P.requestMeasure(),requestAnimationFrame(()=>E(P)))},[t,E]),s.jsxs(s.Fragment,{children:[s.jsx("div",{ref:b,className:me("h-full w-full","[&_.cm-editor]:h-full [&_.cm-editor]:w-full","[&_.cm-scroller]:font-mono [&_.cm-scroller]:text-[var(--text-code)] [&_.cm-scroller]:leading-6","[&_.cm-lineNumbers]:text-[var(--tools-edit-line-number)]",r)}),j.map(P=>Oi.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)},Lm=(t,e)=>{const n=t.state.doc.lineAt(e.main.head);return{lineNumber:n.number,character:e.main.head-n.from+1,selection:e}},Om=(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:ix.cursor(i),effects:Yn.scrollIntoView(i,{y:"center"})})};function r2({open:t,onOpenChange:e,view:n,variant:r="overlay"}){const{t:a}=pt(),[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=Lm(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:Yn.scrollIntoView(x.main.from,{y:"center"})});return}Om(n,u,c.current.character)}},[u,t,n]);const h=l.useCallback(()=>{if(!n||d.current||!c.current)return;const{selection:x}=c.current;n.dispatch({selection:x,effects:Yn.scrollIntoView(x.main.from,{y:"center"})})},[n]),b=l.useCallback(x=>{x||h(),e(x)},[e,h]),f=l.useCallback(()=>{!n||u===null||!c.current||(d.current=!0,Om(n,u,c.current.character),e(!1),n.focus())},[u,e,n]);l.useEffect(()=>{if(!t)return;const x=w=>{const y=p.current,k=w.target;!y||!(k instanceof Node)||y.contains(k)||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??Lm(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(Kt,{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(),f())},placeholder:a("goToLineDialog.field.linePlaceholderShort"),className:"h-6 w-20 rounded-md border-border/70 bg-transparent px-2 typography-meta"}),s.jsx(we,{variant:"outline",size:"xs",onClick:f,disabled:!n||u===null,className:"h-6 px-2",children:a("goToLineDialog.actions.go")})]}):null:s.jsx("div",{ref:p,className:me("absolute left-3 top-3 z-40 w-[min(32rem,calc(100%-1.5rem))] rounded-xl border border-[var(--interactive-border)] bg-[color:color-mix(in_srgb,var(--surface-elevated)_94%,transparent)] p-2.5 shadow-lg backdrop-blur-sm transition-all",t?"pointer-events-auto translate-y-0 opacity-100":"pointer-events-none -translate-y-1 opacity-0"),children:s.jsxs("div",{className:"min-w-0",children:[s.jsx(Kt,{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(),f())},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 id=t=>{const e=at.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(I,{name:"eye",className:"size-4","aria-hidden":"true"}):s.jsx(I,{name:"eye-off",className:"size-4","aria-hidden":"true"}),e[0]=a,e[1]=c):c=e[1];let d;e[2]!==i||e[3]!==r||e[4]!==c?(d=s.jsx(Ct,{asChild:!0,children:s.jsx(we,{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(Pt,{sideOffset:8,children:o}),e[6]=o,e[7]=p):p=e[7];let m;return e[8]!==d||e[9]!==p?(m=s.jsxs(kt,{children:[d,p]}),e[8]=d,e[9]=p,e[10]=m):m=e[10],m},od=ox.define(lx);function a2(t){const e=t.trim().toLowerCase();switch(e){case"bash":case"sh":case"zsh":case"shell":case"shellsession":case"console":return od;case"json":case"jsonc":case"json5":return Ch().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 zc().language;case"css":return kh().language;case"py":case"python":return Sh().language;case"heex":case"eex":case"leex":return zc().language;default:return Ih.matchLanguageName(Ph,e,!0)}}const Vf=t=>t.split("/").pop()?.toLowerCase()??"",i2=t=>{const e=Vf(t);return e?Ih.matchFilename(Ph,e):null},o2=()=>Ti(Uc.define([{tag:[lt.heading1,lt.heading2,lt.heading3,lt.heading4,lt.heading5,lt.heading6],fontWeight:"600"},{tag:lt.strong,fontWeight:"600"},{tag:lt.emphasis,fontStyle:"italic"},{tag:lt.strikethrough,textDecoration:"line-through"},{tag:[lt.link,lt.url],color:"var(--markdown-link, currentColor)",textDecoration:"underline"},{tag:lt.monospace,color:"var(--markdown-inline-code, currentColor)",backgroundColor:"var(--markdown-inline-code-bg, transparent)"},{tag:lt.quote,color:"var(--markdown-blockquote, currentColor)",fontStyle:"italic"},{tag:lt.list,color:"color-mix(in srgb, var(--muted-foreground) 40%, var(--foreground) 60%)"},{tag:lt.heading,color:"var(--markdown-heading1, currentColor)"}]));function zf(t){const e=t.toLowerCase();switch(Vf(e)){case"makefile":case"gnumakefile":return od}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 Ch();case"css":case"scss":case"sass":case"less":return kh();case"html":case"htm":return zc();case"md":case"mdx":case"markdown":case"mdown":case"mkd":return[cx({codeLanguages:a2}),o2()];case"sh":case"bash":case"zsh":case"fish":case"env":return od;case"py":case"pyw":case"pyi":return Sh();default:return null}}async function l2(t){const e=i2(t);if(!e)return null;if(e.support)return e.support;try{return await e.load()}catch{return null}}function ld(t){const e=t.metadata.variant==="dark",n=t.config?.fonts?.mono||"monospace",r=t.colors.syntax.highlights||{},a=t.colors.syntax.tokens||{},i=Yn.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=Uc.define([{tag:[lt.comment,lt.docComment,lt.meta,lt.documentMeta],class:"cm-comment"},{tag:[lt.keyword,lt.controlKeyword,lt.moduleKeyword,lt.definitionKeyword,lt.modifier],class:"cm-keyword"},{tag:[lt.operatorKeyword,lt.operator,lt.derefOperator,lt.updateOperator,lt.definitionOperator,lt.typeOperator,lt.controlOperator,lt.logicOperator,lt.bitwiseOperator,lt.arithmeticOperator,lt.compareOperator],class:"cm-operator"},{tag:[lt.punctuation,lt.separator,lt.bracket,lt.paren,lt.brace,lt.squareBracket,lt.angleBracket],class:"cm-punctuation"},{tag:[lt.string,lt.regexp,lt.attributeValue,lt.special(lt.string),lt.monospace],class:"cm-string"},{tag:lt.escape,class:"cm-string-2"},{tag:[lt.number,lt.bool,lt.atom,lt.null,lt.self],class:"cm-number"},{tag:[lt.function(lt.variableName),lt.function(lt.definition(lt.variableName)),lt.function(lt.propertyName),lt.standard(lt.variableName),lt.special(lt.variableName)],class:"cm-builtin"},{tag:lt.definition(lt.variableName),class:"cm-def"},{tag:[lt.variableName,lt.local(lt.variableName),lt.constant(lt.variableName),lt.literal],class:"cm-variable"},{tag:lt.propertyName,class:"cm-property"},{tag:lt.attributeName,class:"cm-attribute"},{tag:[lt.className,lt.typeName,lt.namespace],class:"cm-variable-3"},{tag:[lt.tagName,lt.labelName,lt.annotation,lt.macroName],class:"cm-tag"},{tag:lt.link,class:"cm-link"},{tag:[lt.heading,lt.heading1,lt.heading2,lt.heading3,lt.heading4,lt.heading5,lt.heading6],class:"cm-keyword"}]),c=Uc.define([{tag:[lt.comment,lt.docComment,lt.meta,lt.documentMeta],color:t.colors.syntax.base.comment},{tag:[lt.keyword,lt.controlKeyword,lt.moduleKeyword,lt.definitionKeyword,lt.modifier],color:t.colors.syntax.base.keyword},{tag:[lt.operatorKeyword,lt.operator,lt.derefOperator,lt.updateOperator,lt.definitionOperator,lt.typeOperator,lt.controlOperator,lt.logicOperator,lt.bitwiseOperator,lt.arithmeticOperator,lt.compareOperator],color:t.colors.syntax.base.operator},{tag:[lt.string,lt.regexp,lt.attributeValue,lt.special(lt.string),lt.monospace],color:t.colors.syntax.base.string},{tag:lt.escape,color:a.stringEscape||t.colors.syntax.base.string},{tag:[lt.number,lt.bool,lt.atom,lt.null,lt.self],color:t.colors.syntax.base.number},{tag:[lt.function(lt.variableName),lt.function(lt.definition(lt.variableName)),lt.function(lt.propertyName),lt.standard(lt.variableName),lt.special(lt.variableName)],color:t.colors.syntax.base.function},{tag:lt.definition(lt.variableName),color:a.variableGlobal||t.colors.syntax.base.variable},{tag:[lt.variableName,lt.local(lt.variableName),lt.constant(lt.variableName),lt.literal],color:t.colors.syntax.base.variable},{tag:lt.propertyName,color:a.variableProperty||t.colors.syntax.base.variable},{tag:lt.attributeName,color:a.variableOther||t.colors.syntax.base.variable},{tag:[lt.className,lt.typeName,lt.namespace],color:t.colors.syntax.base.type},{tag:[lt.tagName,lt.labelName,lt.annotation,lt.macroName],color:a.tag||t.colors.syntax.base.keyword},{tag:lt.link,color:a.url||t.colors.syntax.base.function,textDecoration:"underline"},{tag:[lt.punctuation,lt.separator,lt.bracket,lt.paren,lt.brace,lt.squareBracket,lt.angleBracket],color:a.punctuation||t.colors.syntax.base.comment}]);return[i,Ti(dx,{fallback:!0}),Ti(ux),Ti(o),Ti(c)]}const c2=t=>{const e=gn(t);if(!e)return"";if(e==="/"||/^[A-Za-z]:\/$/.test(e))return e;const n=e.lastIndexOf("/");if(n<0)return e;if(n===0)return"/";const r=e.slice(0,n);return/^[A-Za-z]:$/.test(r)?`${r}/`:r},d2=t=>{const e=at.c(8),{label:n,iconDataUrl:r}=t,[a,i]=l.useState(!1);let o;e[0]!==n?(o=n.trim().slice(0,1).toUpperCase()||"?",e[0]=n,e[1]=o):o=e[1];const c=o;if(r&&!a){let m;e[2]===Symbol.for("react.memo_cache_sentinel")?(m=()=>i(!0),e[2]=m):m=e[2];let u;return e[3]!==r?(u=s.jsx("img",{src:r,alt:"",className:"h-4 w-4 rounded-sm",onError:m}),e[3]=r,e[4]=u):u=e[4],u}let d;e[5]===Symbol.for("react.memo_cache_sentinel")?(d=me("h-4 w-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=d):d=e[5];let p;return e[6]!==c?(p=s.jsx("span",{className:d,children:c}),e[6]=c,e[7]=p):p=e[7],p},u2=t=>t.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),gn=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+/g,"/");n&&!r.startsWith("//")&&(r=`/${r}`);const a=r==="/",i=/^[A-Za-z]:\/$/.test(r);return!a&&!i&&(r=r.replace(/\/+$/,"")),r},m2=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),$m=t=>/^[A-Za-z]:\//.test(t)?t.toLowerCase():t,fl=(t,e)=>{const n=gn(e),r=gn(t);if(!n||!r)return!1;const a=$m(n),i=$m(r);return i===a||i.startsWith(`${a}/`)},Bm=(t,e)=>{const n=gn(e),r=gn(t);if(!fl(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},cd=(t,e)=>{if(!e)return"";const n=gn(e);if(!t||!fl(n,t))return n;const r=n.slice(t.length);return r.startsWith("/")?r.slice(1):r},p2=new Set(["node_modules"]),h2=t=>{const e=at.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},f2=t=>p2.has(t),g2=t=>{const e=gn(t);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},x2=t=>{const n=(t instanceof Error?t.message:String(t??"")).toLowerCase();return n.includes("is a directory")||n.includes("eisdir")},Ci=2e5,Uf="openchamber:files:auto-save-enabled",b2=()=>{if(typeof window>"u")return!0;try{return window.localStorage.getItem(Uf)!=="false"}catch{return!0}},Wf=(t,e)=>s.jsx(br,{filePath:t,extension:e}),y2=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="md"||e==="markdown"},v2=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="json"||e==="jsonc"||e==="json5"||e==="geojson"},gc=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="html"||e==="htm"},w2=t=>{const e=at.c(62),{node:n,root:r,isExpanded:a,isActive:i,isMobile:o,alwaysShowActions:c,status:d,badge:p,permissions:m,downloadFile:u,contextMenuPath:h,setContextMenuPath:b,onSelect:f,onToggle:v,onRevealPath:x,onOpenDialog:g}=t,{t:w}=pt(),y=n.type==="directory",{canRename:k,canCreateFile:D,canCreateFolder:j,canDelete:S,canReveal:A}=m;let E;e[0]!==D||e[1]!==j||e[2]!==S||e[3]!==k||e[4]!==A||e[5]!==n.path||e[6]!==b?(E=Q=>{!k&&!D&&!j&&!S&&!A||(Q?.preventDefault(),b(n.path))},e[0]=D,e[1]=j,e[2]=S,e[3]=k,e[4]=A,e[5]=n.path,e[6]=b,e[7]=E):E=e[7];const P=E;let C;e[8]!==y||e[9]!==n||e[10]!==f||e[11]!==v?(C=()=>{y?v(n.path):f(n)},e[8]=y,e[9]=n,e[10]=f,e[11]=v,e[12]=C):C=e[12];const N=C;let T;e[13]!==n.path||e[14]!==b?(T=Q=>{Q.stopPropagation(),b(n.path)},e[13]=n.path,e[14]=b,e[15]=T):T=e[15];const M=T,R=o?void 0:P,L=o?void 0:P,$=i?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let B;e[16]!==$?(B=me("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",$),e[16]=$,e[17]=B):B=e[17];let O;e[18]!==y||e[19]!==a||e[20]!==n.extension||e[21]!==n.path?(O=y?a?s.jsx(I,{name:"folder-open-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):s.jsx(I,{name:"folder-3-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):Wf(n.path,n.extension),e[18]=y,e[19]=a,e[20]=n.extension,e[21]=n.path,e[22]=O):O=e[22];let _;e[23]!==n.name||e[24]!==n.path?(_=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:n.path,children:n.name}),e[23]=n.name,e[24]=n.path,e[25]=_):_=e[25];let ee;e[26]!==y||e[27]!==d?(ee=!y&&d&&s.jsx(h2,{status:d}),e[26]=y,e[27]=d,e[28]=ee):ee=e[28];let z;e[29]!==p||e[30]!==y?(z=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]=z):z=e[31];let ne;e[32]!==N||e[33]!==ee||e[34]!==z||e[35]!==L||e[36]!==B||e[37]!==O||e[38]!==_?(ne=s.jsxs("button",{type:"button",onClick:N,onContextMenu:L,className:B,children:[O,_,ee,z]}),e[32]=N,e[33]=ee,e[34]=z,e[35]=L,e[36]=B,e[37]=O,e[38]=_,e[39]=ne):ne=e[39];let re;e[40]!==c||e[41]!==D||e[42]!==j||e[43]!==S||e[44]!==k||e[45]!==A||e[46]!==h||e[47]!==u||e[48]!==M||e[49]!==y||e[50]!==o||e[51]!==n||e[52]!==g||e[53]!==x||e[54]!==r||e[55]!==b||e[56]!==w?(re=(k||D||j||S||A)&&s.jsx("div",{className:me("absolute right-1 top-1/2 -translate-y-1/2",c?"opacity-100":"opacity-0 focus-within:opacity-100 group-hover:opacity-100"),children:s.jsxs(Bs,{open:h===n.path,onOpenChange:Q=>b(Q?n.path:null),children:[s.jsx(Os,{asChild:!0,children:s.jsx(we,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:M,children:s.jsx(I,{name:"more-2-fill",className:"h-4 w-4"})})}),s.jsxs($s,{align:"end",side:"bottom",onCloseAutoFocus:()=>b(null),children:[k&&s.jsxs(zt,{onClick:Q=>{Q.stopPropagation(),g("rename",n)},children:[s.jsx(I,{name:"edit",className:"mr-2 h-4 w-4"})," ",w("sidebarFilesTree.menu.rename")]}),s.jsxs(zt,{onClick:Q=>{Q.stopPropagation(),Rn(n.path).then(de=>{if(de.ok){H.success(w("sidebarFilesTree.toast.pathCopied"));return}H.error(w("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(I,{name:"file-copy",className:"mr-2 h-4 w-4"})," ",w("sidebarFilesTree.menu.copyPath")]}),s.jsxs(zt,{onClick:Q=>{Q.stopPropagation();const de=cd(r,n.path)||n.path;Rn(de).then(X=>{if(X.ok){H.success(w("filesView.toast.relativePathCopied"));return}H.error(w("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(I,{name:"file-copy-2",className:"mr-2 h-4 w-4"})," ",w("filesView.tree.menu.copyRelativePath")]}),!y&&u&&s.jsxs(zt,{onClick:Q=>{Q.stopPropagation(),u(n.path)},children:[s.jsx(I,{name:"download",className:"mr-2 h-4 w-4"})," ",w("sidebarFilesTree.menu.save")]}),A&&s.jsxs(zt,{onClick:Q=>{Q.stopPropagation(),x(n.path)},children:[s.jsx(I,{name:"folder-received",className:"mr-2 h-4 w-4"})," ",w(Fd())]}),y&&(D||j)&&s.jsxs(s.Fragment,{children:[s.jsx(Dn,{}),D&&s.jsxs(zt,{onClick:Q=>{Q.stopPropagation(),g("createFile",n)},children:[s.jsx(I,{name:"file-add",className:"mr-2 h-4 w-4"})," ",w("sidebarFilesTree.menu.newFile")]}),j&&s.jsxs(zt,{onClick:Q=>{Q.stopPropagation(),g("createFolder",n)},children:[s.jsx(I,{name:"folder-add",className:"mr-2 h-4 w-4"})," ",w("sidebarFilesTree.menu.newFolder")]})]}),S&&s.jsxs(s.Fragment,{children:[s.jsx(Dn,{}),s.jsxs(zt,{onClick:Q=>{Q.stopPropagation(),g("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"delete-bin",className:"mr-2 h-4 w-4"})," ",w("sidebarFilesTree.menu.delete")]})]})]})]})}),e[40]=c,e[41]=D,e[42]=j,e[43]=S,e[44]=k,e[45]=A,e[46]=h,e[47]=u,e[48]=M,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]=re):re=e[57];let ue;return e[58]!==ne||e[59]!==re||e[60]!==R?(ue=s.jsxs("div",{className:"group relative flex items-center",onContextMenu:R,children:[ne,re]}),e[58]=ne,e[59]=re,e[60]=R,e[61]=ue):ue=e[61],ue},Kf=({mode:t="full"})=>{const{t:e}=pt(),{files:n,runtime:r}=_n(),{currentTheme:a,availableThemes:i,lightThemeId:o,darkThemeId:c}=jr(),{isMobile:d,isTablet:p,screenWidth:m}=an(),u=d||p,h=kl(),b=Ed(),f=Er()??"",v=gn(f.trim()),x=d||t!=="editor-only",g=t==="editor-only"&&!d,w=Rd(Se=>Se.searchFiles),y=Sl(f),[k,D]=l.useState(""),j=Cl(k,200),S=l.useRef(null),[A,E]=l.useState(!1),[P,C]=l.useState(!0),[N,T]=l.useState(!1),[M,R]=l.useState(!1),[L,$]=l.useState(!1),B=l.useRef(null),O=l.useRef(0),_=l.useCallback(Se=>{O.current=Math.max(0,O.current+(Se?1:-1))},[]),ee=l.useCallback(Se=>Se instanceof Element?Se.closest('[data-slot="dropdown-menu-content"], [data-slot="dropdown-menu-item"]')!==null:!1,[]);l.useEffect(()=>{if(!L)return;const Se=Qe=>{O.current>0||ee(Qe.target)||B.current&&!B.current.contains(Qe.target)&&$(!1)};return document.addEventListener("mousedown",Se),()=>document.removeEventListener("mousedown",Se)},[ee,L]);const[z,ne]=l.useState("edit"),[re,ue]=l.useState("edit"),[Q,de]=l.useState("tree"),[X,F]=l.useState("edit"),V=l.useRef({}),q=l.useRef({}),te=l.useRef({}),U=l.useMemo(()=>i.find(Se=>Se.metadata.id===o)??li(!1),[i,o]),ae=l.useMemo(()=>i.find(Se=>Se.metadata.id===c)??li(!0),[i,c]);l.useEffect(()=>{ci(U),ci(ae)},[U,ae]);const je=l.useMemo(()=>[],[]),oe=$n(Se=>v?Se.byRoot[v]?.openPaths??je:je),ve=$n(Se=>v?Se.byRoot[v]?.selectedPath??null:null),K=$n(Se=>v?Se.byRoot[v]?.expandedPaths??je:je),ce=$n(Se=>Se.addOpenPath),Z=$n(Se=>Se.removeOpenPath),le=$n(Se=>Se.removeOpenPathsByPrefix),se=$n(Se=>Se.setSelectedPath),Ie=$n(Se=>Se.toggleExpandedPath),Ne=$n(Se=>Se.expandPaths),Y=l.useCallback(Se=>{const Qe=gn(Se),mt=Qe.split("/"),xt=mt[mt.length-1]||Qe,_t=xt.includes(".")?xt.split(".").pop()?.toLowerCase():void 0;return{name:xt,path:Qe,type:"file",extension:_t}},[]),fe=l.useMemo(()=>oe.map(Y),[oe,Y]),ke=l.useMemo(()=>ve??oe[0]??null,[oe,ve]),be=l.useMemo(()=>ke?Y(ke):null,[ke,Y]),pe=be?.path??"",Ee=!!(v&&pe&&!fl(pe,v)),ze=l.useMemo(()=>({allowOutsideWorkspace:t==="editor-only"&&Ee}),[t,Ee]),G=l.useRef(null),[Pe,Le]=l.useState({left:!1,right:!1}),Ae=l.useCallback(()=>{const Se=G.current;Se&&Le({left:Se.scrollLeft>2,right:Se.scrollLeft+Se.clientWidth<Se.scrollWidth-2})},[]);l.useEffect(()=>{const Se=G.current;if(!Se)return;Ae(),Se.addEventListener("scroll",Ae,{passive:!0});const Qe=new ResizeObserver(Ae);return Qe.observe(Se),()=>{Se.removeEventListener("scroll",Ae),Qe.disconnect()}},[Ae,fe.length]);const[ge,W]=l.useState({}),ie=l.useRef(new Set),Me=l.useRef(new Set),Ve=l.useRef(new Map),Ce=l.useRef(0),[xe,De]=l.useState([]),[Ye,rt]=l.useState(!1),[Re,he]=l.useState(""),[qe,et]=l.useState(!1),[Ke,st]=l.useState(null),[nt,ye]=l.useState(""),[Je,_e]=l.useState(null),[Ue,ot]=l.useState(""),[Xe,We]=l.useState(!1),bt=l.useRef(null),Dt=l.useRef(null),Ht=l.useRef(0),[rs,jt]=l.useState("idle"),[St,ns]=l.useState(b2),[ut,Gt]=l.useState(!1),Xt=l.useRef(null),Wt=l.useRef(null),is=l.useRef(null),gs=l.useRef(!1),ps=l.useRef(null),Ns=l.useRef(null),Mt=l.useRef(null),He=l.useRef(null),[At,Et]=l.useState(0),wt=l.useRef(null),$t=l.useRef({key:"",attempts:0});l.useEffect(()=>()=>{wt.current!==null&&typeof window<"u"&&(window.cancelAnimationFrame(wt.current),wt.current=null)},[]);const[qt,Ms]=l.useState(null),[cs,Is]=l.useState(null),[Es,ft]=l.useState(""),[hs,J]=l.useState(!1),[ct,vt]=l.useState(null),[Tt,Yt]=l.useState(!1),[Zt,Ps]=l.useState(!1),[As,Ge]=l.useState(!1),yt=!!n.writeFile,It=!!n.createDirectory,Rt=!!n.rename,ss=!!n.delete,it=!!n.revealPath,Bt=Cr(Se=>Se.availableApps),bs=Cr(Se=>Se.isCacheStale),es=Cr(Se=>Se.initialize),Ut=Cr(Se=>Se.loadInstalledApps);l.useEffect(()=>{es()},[es]);const os=l.useCallback(Se=>{n.revealPath&&n.revealPath(Se).catch(()=>{H.error(e("sidebarFilesTree.toast.revealFailed"))})},[n,e]),en=l.useCallback(async Se=>{if(!be?.path||await fb(be.path,Se.id,Se.appName)||await tl(be.path,Se.appName))return;const xt=c2(be.path)||v;xt&&await tl(xt,Se.appName)||H.error(e("filesView.toast.openInAppFailed",{app:Se.appName}))},[v,be?.path,e]),qs=l.useCallback((Se,Qe)=>{Ms(Se),Is(Qe),ft(Se==="rename"&&Qe.name||""),J(!1)},[]),[zs,un]=l.useState(null),Qs=l.useRef(!1),mn=l.useRef(null),[ln,wn]=l.useState(!1),tn=Te(Se=>Se.setMainTabGuard),fn=Te(Se=>Se.pendingFileNavigation),hr=Te(Se=>Se.setPendingFileNavigation),Fn=Te(Se=>Se.pendingFileFocusPath),Tn=Te(Se=>Se.setPendingFileFocusPath),Mn=Te(Se=>Se.shortcutOverrides),$e=gt(Se=>Se.settingsDefaultFileViewerPreview);l.useEffect(()=>{const Se=()=>{Qs.current=!1,mn.current=null,wn(!1)};return document.addEventListener("mouseup",Se),()=>document.removeEventListener("mouseup",Se)},[]),l.useEffect(()=>()=>{ps.current!==null&&window.clearTimeout(ps.current),Ns.current!==null&&window.clearTimeout(Ns.current)},[]);const Ft=l.useCallback((Se,Qe)=>{const mt=Se.split(`
48
- `),xt=Math.max(1,Qe.start),_t=Math.min(mt.length,Qe.end);return xt>_t?"":mt.slice(xt-1,_t).join(`
49
- `)},[]),as=qd({source:"file",fileLabel:be?.path??null,language:be?.path&&Wi(be.path)||"text",getCodeForRange:Se=>Ft(Re,pl(Se)),toStoreRange:Se=>({startLine:Se.start,endLine:Se.end}),fromDraftRange:Se=>({start:Se.startLine,end:Se.endLine})}),{drafts:fs,commentText:Gs,editingDraftId:Hs,setSelection:Ss,saveComment:Ys,cancel:on,reset:sr,startEdit:Hn,deleteDraft:Gn}=as;l.useEffect(()=>{un(null),sr(),tn(null),ot(""),We(!1)},[be?.path,sr,tn]),l.useEffect(()=>{Ss(zs)},[zs,Ss]),l.useEffect(()=>{if(!zs&&!Hs)return;const Se=mt=>{const xt=mt.target;xt.closest('[data-comment-input="true"]')||xt.closest('[data-comment-card="true"]')||xt.closest(".cm-gutterElement")||xt.closest("[data-sonner-toast]")||xt.closest("[data-sonner-toaster]")||(un(null),on())},Qe=setTimeout(()=>{document.addEventListener("click",Se)},100);return()=>{clearTimeout(Qe),document.removeEventListener("click",Se)}},[on,Hs,zs]);const Rr=l.useCallback((Se,Qe)=>{const mt=Qe??zs??void 0;Qe&&un(Qe),Ys(Se,mt),un(null)},[zs,Ys]),Nr=l.useCallback((Se,Qe)=>{const mt=Qe.filter(xt=>xt&&typeof xt.name=="string"&&xt.name.length>0).filter(xt=>h||!xt.name.startsWith(".")).filter(xt=>b||!f2(xt.name)).map(xt=>{const _t=xt.name,Qt=gn(xt.path||""),ls=Qt?m2(Qt)?Qt:gn(`${Se}/${Qt}`):gn(`${Se}/${_t}`),Us=xt.isDirectory?"directory":"file",Pn=Us==="file"&&_t.includes(".")?_t.split(".").pop()?.toLowerCase():void 0;return{name:_t,path:ls,type:Us,extension:Pn}});return u2(mt)},[b,h]),Zs=l.useCallback(async Se=>{const Qe=gn(Se.trim());if(!Qe||ie.current.has(Qe)||Me.current.has(Qe))return;Me.current=new Set(Me.current),Me.current.add(Qe);const mt=Ce.current+1;Ce.current=mt,Ve.current=new Map(Ve.current),Ve.current.set(Qe,mt);const xt=()=>Ve.current.get(Qe)===mt,_t=!b;await(r.isDesktop?n.listDirectory(Qe,{respectGitignore:_t}).then(ls=>ls.entries.map(Us=>({name:Us.name,path:Us.path,isDirectory:Us.isDirectory}))):rn.listLocalDirectory(Qe,{respectGitignore:_t}).then(ls=>ls.map(Us=>({name:Us.name,path:Us.path,isDirectory:Us.isDirectory})))).then(ls=>{if(!xt())return;const Us=Nr(Qe,ls);ie.current=new Set(ie.current),ie.current.add(Qe),W(Pn=>({...Pn,[Qe]:Us}))}).catch(()=>{xt()&&W(ls=>({...ls,[Qe]:ls[Qe]??[]}))}).finally(()=>{xt()&&(Ve.current=new Map(Ve.current),Ve.current.delete(Qe),Me.current=new Set(Me.current),Me.current.delete(Qe))})},[n,Nr,r.isDesktop,b]),Vn=l.useCallback(async()=>{v&&(ie.current=new Set,Me.current=new Set,Ve.current=new Map,W(Se=>Object.keys(Se).length===0?Se:{}),await Zs(v))},[Zs,v]),Cn=l.useCallback(async Se=>{if(!Se){await Vn();return}const Qe=gn(Se);ie.current=new Set(ie.current),ie.current.delete(Qe),Me.current=new Set(Me.current),Me.current.delete(Qe),await Zs(Qe)},[Zs,Vn]),Zn=l.useRef(""),fr=l.useRef("");l.useEffect(()=>{if(!v)return;const Se=`${v}|h${h?"1":"0"}|g${b?"1":"0"}`,Qe=Zn.current!==v,mt=fr.current!==Se;!Qe&&!mt||(Qe&&(Zn.current=v,he(""),st(null),ye(""),_e(null),E(!1)),mt&&(fr.current=Se,ie.current=new Set,Me.current=new Set,Ve.current=new Map,W(xt=>Object.keys(xt).length===0?xt:{}),Zs(v)))},[Zs,v,b,h]),l.useEffect(()=>{if(!n.listDirectory)return;const Se=()=>{if(!document.hidden&&K.length>0)for(const Qe of K)Cn(Qe)};return document.addEventListener("visibilitychange",Se),()=>document.removeEventListener("visibilitychange",Se)},[K,n.listDirectory,Cn]),l.useEffect(()=>{if(!n.listDirectory||K.length===0)return;const Se=setInterval(()=>{if(!document.hidden)for(const Qe of K)Cn(Qe)},8e3);return()=>clearInterval(Se)},[K,n.listDirectory,Cn]);const Dr=l.useCallback(async Se=>{if(Se?.preventDefault(),!cs||!qt)return;J(!0);const Qe=()=>{Ms(null)},mt=_t=>{H.error(_t)},xt=()=>{J(!1)};if(qt==="createFile"){if(!Es.trim()){mt(e("sidebarFilesTree.toast.filenameRequired")),xt();return}if(!n.writeFile){mt(e("sidebarFilesTree.toast.writeNotSupported")),xt();return}const _t=cs.path,Qt=_t?`${_t}/`:"",ls=gn(`${Qt}${Es.trim()}`);await n.writeFile(ls,"").then(async Us=>{Us.success&&(H.success(e("sidebarFilesTree.toast.fileCreated")),await Cn(_t)),Qe()}).catch(()=>mt(e("sidebarFilesTree.toast.operationFailed"))).finally(xt);return}if(qt==="createFolder"){if(!Es.trim()){mt(e("sidebarFilesTree.toast.folderNameRequired")),xt();return}const _t=cs.path,Qt=_t?`${_t}/`:"",ls=gn(`${Qt}${Es.trim()}`);await n.createDirectory(ls).then(async Us=>{Us.success&&(H.success(e("sidebarFilesTree.toast.folderCreated")),await Cn(_t)),Qe()}).catch(()=>mt(e("sidebarFilesTree.toast.operationFailed"))).finally(xt);return}if(qt==="rename"){if(!Es.trim()){mt(e("sidebarFilesTree.toast.nameRequired")),xt();return}if(!n.rename){mt(e("sidebarFilesTree.toast.renameNotSupported")),xt();return}const _t=cs.path,Qt=_t.split("/").slice(0,-1).join("/"),ls=Qt?`${Qt}/`:"",Us=gn(`${ls}${Es.trim()}`);await n.rename(_t,Us).then(async Pn=>{Pn.success&&(H.success(e("sidebarFilesTree.toast.renamedSuccessfully")),await Cn(Qt),v&&le(v,_t),(be?.path===_t||be?.path.startsWith(`${_t}/`))&&(v&&se(v,null),he(""),st(null),ye(""),_e(null),d&&E(!1))),Qe()}).catch(()=>mt(e("sidebarFilesTree.toast.operationFailed"))).finally(xt);return}if(qt==="delete"){if(!n.delete){mt(e("sidebarFilesTree.toast.deleteNotSupported")),xt();return}const _t=cs.path,Qt=_t.split("/").slice(0,-1).join("/");await n.delete(_t).then(async ls=>{ls.success&&(H.success(e("sidebarFilesTree.toast.deletedSuccessfully")),await Cn(Qt),v&&le(v,_t),(be?.path===_t||be?.path.startsWith(`${_t}/`))&&(v&&se(v,null),he(""),st(null),ye(""),_e(null),d&&E(!1))),Qe()}).catch(()=>mt(e("sidebarFilesTree.toast.operationFailed"))).finally(xt);return}xt()},[qt,cs,Es,n,Cn,d,le,v,be?.path,se,e]);l.useEffect(()=>{if(!f){De([]),rt(!1);return}const Se=j.trim();if(!Se){De([]),rt(!1);return}let Qe=!1;return rt(!0),w(f,Se,150,{includeHidden:h,respectGitignore:!b,type:"file"}).then(mt=>{if(Qe)return;const _t=mt.filter(Qt=>b||!g2(Qt.path)).map(Qt=>({name:Qt.name,path:gn(Qt.path),type:"file",extension:Qt.extension,relativePath:Qt.relativePath}));De(_t)}).catch(()=>{Qe||De([])}).finally(()=>{Qe||rt(!1)}),()=>{Qe=!0}},[f,j,w,h,b]);const nr=l.useCallback(async(Se,Qe)=>{if(n.readFile)return(await n.readFile(Se,Qe)).content??"";const mt=new URLSearchParams({path:Se});Qe?.allowOutsideWorkspace&&mt.set("allowOutsideWorkspace","true"),Qe?.optional&&mt.set("optional","true");const xt=await fetch(`/api/fs/read?${mt.toString()}`,{cache:Qe?.optional?"no-store":"default"});if(!xt.ok){const _t=await xt.json().catch(()=>({error:xt.statusText}));throw new Error(_t.error||e("filesView.error.readFileFailed"))}return xt.text()},[n,e]),Ln=l.useCallback(async(Se,Qe)=>{if(n.statFile){const mt=await n.statFile(Se,Qe);return{path:mt.path,size:mt.size,mtimeMs:mt.mtimeMs}}return null},[n]),vn=l.useMemo(()=>Re.length>Ci?`${Re.slice(0,Ci)}
50
-
51
- … truncated …`:Re,[Re]),pn=l.useMemo(()=>Ue!==vn,[Ue,vn]),En=l.useCallback(async()=>{if(!be||!n.writeFile)return H.error(e("filesView.toast.savingNotSupported")),!1;if(!pn)return!0;We(!0);try{return(await n.writeFile(be.path,Ue))?.success?(he(Ue),Ln(be.path).then(Qe=>{Qe&&(Dt.current=Qe)}).catch(()=>{}),!0):(H.error(e("filesView.toast.writeFileFailed")),!1)}catch(Se){return H.error(Se instanceof Error?Se.message:e("filesView.toast.saveFailed")),!1}finally{We(!1)}},[Ue,n,pn,Ln,be,e]);l.useEffect(()=>{if(!pn){tn(null);return}const Se=Qe=>gs.current?(gs.current=!1,!0):(Gt(!0),Wt.current=Qe,!1);return tn(Se),()=>{Te.getState().mainTabGuard===Se&&tn(null)}},[pn,tn]),l.useEffect(()=>{try{window.localStorage.setItem(Uf,St?"true":"false")}catch{}},[St]),l.useEffect(()=>{St||(jt("idle"),bt.current&&(clearTimeout(bt.current),bt.current=null))},[St]);const Fr=1500;l.useEffect(()=>{const Se=!!(be&&n.writeFile);if(!(!St||!pn||!Se||Xe))return bt.current=setTimeout(()=>{En().then(Qe=>{Qe&&(jt("saved"),setTimeout(()=>jt("idle"),2e3))})},Fr),()=>{bt.current&&(clearTimeout(bt.current),bt.current=null)}},[St,Ue,pn,be,n.writeFile,Xe,En]),l.useEffect(()=>{jt("idle")},[be?.path]),l.useEffect(()=>{const Se=Qe=>{Ad(Qe)&&(Qe.key.toLowerCase()==="s"?(Qe.preventDefault(),bt.current&&(clearTimeout(bt.current),bt.current=null),Xe||En().then(mt=>{mt&&(jt("saved"),setTimeout(()=>jt("idle"),2e3))})):Qe.key.toLowerCase()==="f"&&(Qe.preventDefault(),R(!0)))};return window.addEventListener("keydown",Se),()=>window.removeEventListener("keydown",Se)},[Xe,En]);const Wr=l.useCallback(async Se=>{const Qe=Ht.current+1;Ht.current=Qe;const mt=()=>{if(!v)return!1;const ls=$n.getState().byRoot[v],Us=ls?.selectedPath??ls?.openPaths[0]??null;return Ht.current===Qe&&Us===Se.path};st(null),ye(""),_e(null);const xt=di(Se.path),_t=Se.path.toLowerCase().endsWith(".svg");if(d&&E(!0),r.isDesktop&&xt&&!_t){he(""),ot(""),et(!0);return}if(!r.isDesktop&&xt&&!_t){he(""),ot(""),_e(Se.path),et(!1);return}et(!0);const Qt={allowOutsideWorkspace:t==="editor-only"&&!!v&&!fl(Se.path,v)};await nr(Se.path,Qt).then(ls=>{mt()&&(he(ls),ot(ls.length>Ci?`${ls.slice(0,Ci)}
52
-
53
- … truncated …`:ls),_e(Se.path),Ln(Se.path,Qt).then(Us=>{Us&&mt()&&(Dt.current=Us)}).catch(()=>{}))}).catch(ls=>{if(mt()){if(x2(ls)){if(et(!1),v&&se(v,null),st(null),he(""),ot(""),_e(null),Dt.current=null,k.trim().length>0&&D(""),d&&E(!1),v){const Pn=[...Bm(Se.path,v),Se.path];Pn.length>0&&Ne(v,Pn);for(const po of Pn)ie.current.has(po)||Zs(po)}return}he(""),ot(""),st(ls instanceof Error?ls.message:e("filesView.error.readFileFailed")),Dt.current=null}}).finally(()=>{mt()&&et(!1)})},[Ne,d,Zs,t,nr,Ln,v,r.isDesktop,k,se,e]),Kr=l.useCallback(async(Se,Qe)=>{if(!v)return;const mt=Bm(Se,v),xt=Qe?[...mt,Se]:mt;xt.length>0&&Ne(v,xt);for(const _t of xt)ie.current.has(_t)||await Zs(_t)},[Ne,Zs,v]),La=l.useCallback((Se,Qe)=>{const mt=Qe.findIndex(xt=>xt.path===Se);return mt===-1||Qe.length<=1?null:Qe[mt+1]??Qe[mt-1]??null},[]),jn=l.useCallback(async Se=>{if(gs.current)gs.current=!1;else if(pn){Gt(!0),Xt.current=Se;return}v&&(se(v,Se.path),ce(v,Se.path),Kr(Se.path,!1)),st(null),ye(""),he(""),ot(""),_e(null),d&&E(!0)},[ce,Kr,pn,d,v,se]);l.useEffect(()=>{be?.path&&Kr(be.path,!1)},[Kr,be?.path]),l.useEffect(()=>{if(!be){Ht.current+=1,et(!1);return}Je!==be.path&&Wr(be)},[Wr,Je,be]);const aa=l.useRef(pn);aa.current=pn,l.useEffect(()=>{if(!be?.path||Je!==be.path)return;let Se=!1;const Qe=window.setInterval(()=>{document.hidden||Ln(be.path,ze).then(mt=>{if(Se||!mt)return;const xt=Dt.current;if(!xt||xt.path!==be.path){Dt.current=mt;return}const _t=mt.mtimeMs!==void 0&&xt.mtimeMs!==void 0&&mt.mtimeMs!==xt.mtimeMs,Qt=mt.size!==xt.size;!_t&&!Qt||aa.current||(Dt.current=mt,_e(null))}).catch(()=>{})},2e3);return()=>{Se=!0,window.clearInterval(Qe)}},[Je,Ln,be?.path,ze]);const yi=l.useCallback(()=>{const Se=Xt.current,Qe=Wt.current,mt=is.current;if(Xt.current=null,Wt.current=null,is.current=null,gs.current=!0,Gt(!1),ot(vn),mt){v&&Z(v,mt),be?.path===mt&&(Se?jn(Se):(v&&se(v,null),he(""),st(null),ye(""),_e(null),d&&E(!1)));return}if(Se){jn(Se);return}Qe&&(tn(null),Te.getState().setActiveMainTab(Qe))},[vn,jn,d,Z,v,be?.path,tn,se]),Oa=l.useCallback(async()=>{const Se=Xt.current,Qe=Wt.current,mt=is.current;if(!await En()){gs.current=!1;return}if(Xt.current=null,Wt.current=null,is.current=null,gs.current=!0,Gt(!1),mt){v&&Z(v,mt),be?.path===mt&&(Se?await jn(Se):(v&&se(v,null),he(""),st(null),ye(""),_e(null),d&&E(!1)));return}if(Se){await jn(Se);return}Qe&&(tn(null),Te.getState().setActiveMainTab(Qe))},[jn,d,Z,v,En,be?.path,tn,se]),ia=l.useCallback(Se=>{const Qe=be?.path===Se,mt=La(Se,fe);if(Qe&&pn){Gt(!0),Xt.current=mt,is.current=Se;return}if(v&&Z(v,Se),!!Qe){if(mt){jn(mt);return}v&&se(v,null),he(""),st(null),ye(""),_e(null),d&&E(!1)}},[La,jn,pn,d,fe,Z,v,be?.path,se]),Oe=l.useCallback(Se=>{if(oe.includes(Se))return"open";if(y?.files){const Qe=Se.startsWith(v+"/")?Se.slice(v.length+1):Se,mt=y.files.find(xt=>xt.path===Qe);if(mt){if(mt.index==="A"||mt.working_dir==="?")return"git-added";if(mt.index==="D")return"git-deleted";if(mt.index==="M"||mt.working_dir==="M")return"git-modified"}}return null},[oe,y,v]),Ze=l.useCallback(Se=>{if(!y?.files)return null;const Qe=Se.startsWith(v+"/")?Se.slice(v.length+1):Se,mt=Qe?`${Qe}/`:"";let xt=0,_t=0;for(const Qt of y.files)Qt.path.startsWith(mt)&&((Qt.index==="M"||Qt.working_dir==="M")&&xt++,(Qt.index==="A"||Qt.working_dir==="?")&&_t++);return xt+_t>0?{modified:xt,added:_t}:null},[y,v]),tt=l.useCallback(async Se=>{const Qe=gn(Se);v&&(Ie(v,Qe),ie.current.has(Qe)||await Zs(Qe))},[Zs,v,Ie]),dt=l.useMemo(()=>({canRename:Rt,canCreateFile:yt,canCreateFolder:It,canDelete:ss,canReveal:it}),[Rt,yt,It,ss,it]);function Ot(Se,Qe){const mt=ge[Se]??[];return mt.map((xt,_t)=>{const Qt=xt.type==="directory",ls=Qt&&K.includes(xt.path),Us=be?.path===xt.path,Pn=_t===mt.length-1;return s.jsxs("li",{className:"relative",children:[Qe>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),Pn&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-background"})]}),s.jsx(w2,{node:xt,root:v,isExpanded:ls,isActive:Us,isMobile:d,alwaysShowActions:u,status:Qt?void 0:Oe(xt.path),badge:Qt?Ze(xt.path):void 0,permissions:dt,downloadFile:n.downloadFile,contextMenuPath:ct,setContextMenuPath:vt,onSelect:jn,onToggle:tt,onRevealPath:os,onOpenDialog:qs}),Qt&&ls&&s.jsx("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:Ot(xt.path,Qe+1)})]},xt.path)})}const Jt=!!(be?.path&&di(be.path)),_s=!!(be?.path&&be.path.toLowerCase().endsWith(".svg")),hn=l.useMemo(()=>gn(fn?.path??""),[fn?.path]),zn=!!(fn&&hn&&pe&&pe===hn&&!qe&&!Ke&&!Jt),$a=l.useMemo(()=>cd(v,pe),[pe,v]),Rl=!!(be&&(!Jt||_s)&&Re.length>0),Ba=!!(be&&$a.length>0),er=!!(be&&!Ee&&!Jt&&n.writeFile&&Re.length<=Ci),oa=!!(be?.path&&y2(be.path)),Hr=!!(be?.path&&v2(be.path)),_a=!!(be?.path&&gc(be.path)),vi=!!(be&&!Jt)&&!oa&&!(_a&&X==="preview"),Va=l.useMemo(()=>pe?zf(pe):null,[pe]),[za,Gr]=l.useState(null);l.useEffect(()=>{let Se=!1;const Qe=be?.path;if(!Qe||Va){Gr(null);return}return Gr(null),l2(Qe).then(mt=>{Se||Gr(mt)}),()=>{Se=!0}},[be?.path,Va]),l.useEffect(()=>{!er&&z==="edit"&&ne("view")},[er,z]);const sn="openchamber:files:md-viewer-mode",Ua="openchamber:files:html-viewer-mode",Wa="openchamber:files:json-viewer-mode";l.useEffect(()=>{const Se=be?.path;if(!Se)return;const Qe=$e?"view":"edit";ne(V.current[Se]??Qe);let mt=$e?"preview":"edit";try{const Qt=localStorage.getItem(sn);(Qt==="preview"||Qt==="edit")&&(mt=Qt)}catch{}ue(q.current[Se]??mt);let xt=$e?"preview":"edit";try{const Qt=localStorage.getItem(Ua);(Qt==="preview"||Qt==="edit")&&(xt=Qt)}catch{}F(te.current[Se]??xt);let _t=$e?"tree":"text";try{const Qt=localStorage.getItem(Wa);(Qt==="tree"||Qt==="text")&&(_t=Qt)}catch{}de(_t)},[be?.path,$e]);const Ll=l.useCallback(Se=>{const Qe=be?.path;Qe&&(V.current[Qe]=Se),ne(Se)},[be?.path]),Ol=l.useCallback(Se=>{const Qe=be?.path;Qe&&(q.current[Qe]=Se),ue(Se);try{localStorage.setItem(sn,Se)}catch{}},[be?.path]),Tr=l.useCallback(()=>re,[re]),In=l.useCallback(Se=>{de(Se);try{localStorage.setItem(Wa,Se)}catch{}},[]),$l=l.useCallback(Se=>{const Qe=be?.path;Qe&&(te.current[Qe]=Se),F(Se);try{localStorage.setItem(Ua,Se)}catch{}},[be?.path]),oo=l.useCallback(()=>X,[X]);l.useEffect(()=>{if(!fn||!v)return;const Se=()=>{typeof window>"u"||wt.current===null&&(wt.current=window.requestAnimationFrame(()=>{wt.current=null,Et(Lr=>Lr+1)}))},Qe=(Lr,ca)=>{if(Lr.state.doc.length!==ca.length)return!1;if(ca.length===0)return!0;const _l=Math.min(128,ca.length);if(Lr.state.sliceDoc(0,_l)!==ca.slice(0,_l))return!1;const nu=Math.max(0,ca.length-_l);return Lr.state.sliceDoc(nu,ca.length)===ca.slice(nu)},mt=gn(fn.path);if(!mt){hr(null),$t.current={key:"",attempts:0};return}const xt=`${mt}:${fn.line}:${fn.column??1}`;if($t.current.key!==xt&&($t.current={key:xt,attempts:0}),be?.path!==mt){if(ut)return;jn(Y(mt));return}if(qe||Je!==mt)return;if(Ke||Jt){hr(null),$t.current={key:"",attempts:0};return}if(!er)return;if(z!=="edit"){ne("edit");return}const _t=Mt.current;if(!_t){Se();return}if(!Qe(_t,Ue)){Se();return}const Qt=Math.max(1,Math.min(fn.line,_t.state.doc.lines)),ls=_t.state.doc.line(Qt),Us=Math.max(1,fn.column||1),Pn=Math.max(0,ls.to-ls.from),po=Math.min(Pn,Us-1),ji=ls.from+po;if(!(_t.state.selection.main.head===ji)||$t.current.attempts===0){$t.current.attempts+=1,_t.dispatch({selection:{anchor:ji},effects:Yn.scrollIntoView(ji,{y:"center"})}),_t.focus(),Se();return}typeof window<"u"&&window.requestAnimationFrame(()=>{const Lr=Mt.current;Lr&&(Lr.dispatch({selection:{anchor:ji},effects:Yn.scrollIntoView(ji,{y:"center"})}),Lr.focus())}),hr(null),$t.current={key:"",attempts:0}},[er,ut,Ue,At,Ke,qe,Jt,Je,jn,fn,v,be?.path,hr,z,Y]),l.useEffect(()=>{if(!Fn||!v)return;const Se=gn(Fn);if(!Se){Tn(null);return}if(be?.path!==Se){if(ut)return;jn(Y(Se));return}if(!(qe||Je!==Se||Ke||Jt)){if(er&&z==="edit"){const Qe=Mt.current;if(!Qe)return;Qe.focus()}Tn(null)}},[er,ut,Ke,qe,jn,Jt,Je,Fn,v,be?.path,Tn,z,Y]);const qr=l.useCallback(Se=>{if(!d||!Se||!Se.hasFocus||typeof window>"u")return;const Qe=window.visualViewport;if(!Qe)return;const mt=document.documentElement.clientHeight||window.innerHeight;if(Math.max(0,mt-(Qe.offsetTop+Qe.height))<=0)return;const _t=Se.state.selection.main.head,Qt=Se.coordsAtPos(_t);if(!Qt)return;const ls=Math.round(Qe.offsetTop+Qe.height),Pn=Qt.bottom+20-ls;Pn<=0||(Se.scrollDOM.scrollTop+=Pn)},[d]);l.useEffect(()=>{if(!d||typeof window>"u")return;const Se=()=>{window.requestAnimationFrame(()=>{qr(Mt.current)})},Qe=window.visualViewport;return Qe?.addEventListener("resize",Se),Qe?.addEventListener("scroll",Se),document.addEventListener("selectionchange",Se),()=>{Qe?.removeEventListener("resize",Se),Qe?.removeEventListener("scroll",Se),document.removeEventListener("selectionchange",Se)}},[d,qr]),l.useEffect(()=>{if(!er||z!=="edit"||d)return;const Se=Br("open_go_to_line",Mn),Qe=mt=>{const xt=mt.target;if(xt?.closest('[role="dialog"]'))return;const _t=!!xt?.closest(".cm-editor");xt?.closest('input, textarea, [contenteditable="true"], [role="textbox"]')&&!_t||!document.activeElement?.closest(".cm-editor")||Oo(mt,Se)&&(mt.preventDefault(),Ge(!0))};return window.addEventListener("keydown",Qe),()=>window.removeEventListener("keydown",Qe)},[er,d,Mn,z]);const lo=l.useMemo(()=>{if(!be?.path)return[ld(a)];const Se=[ld(a)],Qe=Va??za;return Qe&&Se.push(Qe),P&&Se.push(Yn.lineWrapping),d&&Se.push(Yn.updateListener.of(mt=>{mt.view.hasFocus&&(mt.selectionSet||mt.focusChanged||mt.viewportChanged||mt.geometryChanged)&&window.requestAnimationFrame(()=>{qr(mt.view)})})),Se},[a,be?.path,Va,za,P,d,qr]),co=l.useMemo(()=>({light:U.metadata.id,dark:ae.metadata.id}),[U.metadata.id,ae.metadata.id]),la=be?.path&&Jt?r.isDesktop?_s?`data:${xu(be.path)};utf8,${encodeURIComponent(Re)}`:nt:_s?`data:${xu(be.path)};utf8,${encodeURIComponent(Re)}`:`/api/fs/raw?${new URLSearchParams({path:be.path,...ze.allowOutsideWorkspace?{allowOutsideWorkspace:"true"}:{}}).toString()}`:"";l.useEffect(()=>{let Se=!1;return(async()=>{if(!r.isDesktop||!be?.path||!Jt||_s){ye("");return}st(null),await(n.readFileBinary?n.readFileBinary(be.path,ze).then(xt=>xt.dataUrl):Promise.resolve(px(be.path,"asset"))).then(xt=>{Se||(ye(xt),_e(be.path))}).catch(xt=>{Se||(ye(""),st(xt instanceof Error?xt.message:e("filesView.error.readFileFailed")),_e(null))}).finally(()=>{Se||et(!1)})})(),()=>{Se=!0}},[n,Jt,_s,r.isDesktop,be?.path,ze,e]);const wi=()=>s.jsx(ws,{open:!!qt,onOpenChange:Se=>!Se&&Ms(null),children:s.jsxs(vs,{children:[s.jsxs(Cs,{children:[s.jsxs(js,{children:[qt==="createFile"&&e("filesView.dialog.createFile.title"),qt==="createFolder"&&e("filesView.dialog.createFolder.title"),qt==="rename"&&e("filesView.dialog.rename.title"),qt==="delete"&&e("filesView.dialog.delete.title")]}),s.jsxs(Rs,{children:[qt==="createFile"&&e("filesView.dialog.createFile.description",{path:cs?.path??e("filesView.dialog.rootFallback")}),qt==="createFolder"&&e("filesView.dialog.createFolder.description",{path:cs?.path??e("filesView.dialog.rootFallback")}),qt==="rename"&&e("filesView.dialog.rename.description",{name:cs?.name??""}),qt==="delete"&&e("filesView.dialog.delete.description",{name:cs?.name??""})]})]}),qt!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(Kt,{value:Es,onChange:Se=>ft(Se.target.value),placeholder:e(qt==="rename"?"filesView.dialog.rename.placeholder":"filesView.dialog.namePlaceholder"),onKeyDown:Se=>{Se.key==="Enter"&&Dr()},autoFocus:!0})}),s.jsxs(Ks,{children:[s.jsx(we,{variant:"outline",onClick:()=>Ms(null),disabled:hs,children:e("filesView.dialog.cancel")}),s.jsx(we,{variant:qt==="delete"?"destructive":"default",onClick:()=>{Dr()},disabled:hs||qt!=="delete"&&!Es.trim(),children:hs?s.jsx(I,{name:"loader-4",className:"animate-spin"}):e(qt==="delete"?"filesView.dialog.delete.confirm":"filesView.dialog.confirm")})]})]})}),Bl=l.useMemo(()=>Ff({drafts:fs,editingDraftId:Hs,commentText:Gs,selection:zs,isDragging:ln,fileLabel:be?.path??"",newWidgetId:"files-new-comment-input",mapDraftToRange:Se=>({start:Se.startLine,end:Se.endLine}),onSave:Rr,onCancel:()=>{un(null),on()},onEdit:Se=>{Hn(Se),un({start:Se.startLine,end:Se.endLine})},onDelete:Gn}),[on,Gs,Gn,Hs,fs,Rr,ln,zs,be?.path,Hn]),uo=l.useCallback((Se,Qe)=>s.jsx("div",{className:"h-full",children:s.jsx(mx,{file:{name:Se.name,contents:Qe,lang:Wi(Se.path)||void 0},options:{disableFileHeader:!0,overflow:P?"wrap":"scroll",theme:co,themeType:a.metadata.variant==="dark"?"dark":"light"},className:"block h-full w-full",style:{height:"100%"}})}),[a.metadata.variant,co,P]),mo=({exitFullscreenOnly:Se=!1}={})=>be?s.jsxs("div",{className:"pointer-events-auto flex items-center gap-1 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-1 shadow-sm",children:[er&&z==="edit"&&s.jsxs(s.Fragment,{children:[Xe?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-muted-foreground typography-meta",children:[s.jsx(I,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),e("filesView.editor.saving")]}):St&&rs==="saved"&&!pn?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-[color:var(--status-success)] typography-meta",children:[s.jsx(I,{name:"check",className:"h-3.5 w-3.5"}),e("filesView.editor.saved")]}):pn?s.jsx(we,{variant:"ghost",size:"sm",onClick:()=>{En()},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(St?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:`${al()}+S`}),"aria-label":e("filesView.editor.saveAria",{shortcut:`${al()}+S`}),children:s.jsx(I,{name:"save-3",className:"h-4 w-4"})}):null,s.jsx(we,{variant:"ghost",size:"sm",onClick:()=>ns(Qe=>!Qe),className:me("h-6 w-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",St?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(St?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),"aria-label":e(St?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),children:St?s.jsx(I,{name:"file-check-fill",className:"size-4"}):s.jsx(I,{name:"file-check",className:"size-4"})})]}),s.jsxs(Bs,{onOpenChange:_,children:[s.jsx(Os,{asChild:!0,children:s.jsx(we,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 text-foreground opacity-100 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.openInDesktopApp"),"aria-label":e("filesView.editor.openInDesktopApp"),children:s.jsx(I,{name:"file-transfer",className:"h-4 w-4"})})}),s.jsxs($s,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[Bt.map(Qe=>s.jsxs(zt,{className:"flex items-center gap-2",onClick:()=>{en(Qe)},children:[s.jsx(d2,{label:Qe.label,iconDataUrl:Qe.iconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:Qe.label})]},Qe.id)),bs?s.jsxs(zt,{className:"flex items-center gap-2",onClick:()=>{Ut(!0)},children:[s.jsx(I,{name:"refresh",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:e("filesView.editor.refreshApps")})]}):null]})]}),!Jt&&s.jsxs(s.Fragment,{children:[s.jsx(we,{variant:"ghost",size:"sm",onClick:()=>C(!P),className:me("h-6 w-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(I,{name:"text-wrap",className:"size-4"})}),z==="edit"&&s.jsxs(s.Fragment,{children:[s.jsx(we,{variant:"ghost",size:"sm",onClick:Qe=>{R(!M),Qe.currentTarget.blur()},className:"h-6 w-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.findInFile"),children:s.jsx(I,{name:"search",className:"size-4"})}),s.jsx(we,{variant:"ghost",size:"sm",onClick:Qe=>{Ge(mt=>!mt),Qe.currentTarget.blur()},className:"h-6 w-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.goToLine"),children:s.jsx(I,{name:"menu-fold-2",className:"size-4"})}),s.jsx(r2,{open:As,onOpenChange:Ge,view:Mt.current,variant:"inline"})]})]}),vi&&er&&!Hr&&!_a&&s.jsx(id,{currentMode:z==="view"?"preview":"edit",onToggle:()=>{Ll(z==="view"?"edit":"view")}}),(oa||gc(be?.path??""))&&s.jsx(id,{currentMode:oa?Tr():oo(),onToggle:()=>{gc(be?.path??"")?$l(oo()==="preview"?"edit":"preview"):Ol(Tr()==="preview"?"edit":"preview")}}),Hr&&s.jsx(we,{variant:"ghost",size:"sm",onClick:()=>In(Q==="tree"?"text":"tree"),className:"h-6 w-6 p-0 text-muted-foreground opacity-65 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:e(Q==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),children:Q==="tree"?s.jsx(I,{name:"code-sslash",className:"size-4"}):s.jsx(I,{name:"node-tree",className:"size-4"})}),Rl&&s.jsx(we,{variant:"ghost",size:"sm",onClick:async()=>{(await Rn(Re)).ok?(Yt(!0),ps.current!==null&&window.clearTimeout(ps.current),ps.current=window.setTimeout(()=>{Yt(!1)},1200)):H.error(e("filesView.toast.copyFailed"))},className:"h-6 w-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.copyFileContents"),"aria-label":e("filesView.editor.copyFileContents"),children:Tt?s.jsx(I,{name:"check",className:"h-4 w-4 text-[color:var(--status-success)]"}):s.jsx(I,{name:"clipboard",className:"h-4 w-4"})}),Ba&&s.jsx(we,{variant:"ghost",size:"sm",onClick:async()=>{(await Rn($a)).ok?(Ps(!0),Ns.current!==null&&window.clearTimeout(Ns.current),Ns.current=window.setTimeout(()=>{Ps(!1)},1200)):H.error(e("filesView.toast.copyFailed"))},className:"h-6 w-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.copyFilePathTitle",{path:$a}),"aria-label":e("filesView.editor.copyFilePathTitle",{path:$a}),children:Zt?s.jsx(I,{name:"check",className:"h-4 w-4 text-[color:var(--status-success)]"}):s.jsx(I,{name:"file-copy-2",className:"h-4 w-4"})}),n.downloadFile&&s.jsx(we,{variant:"ghost",size:"sm",onClick:()=>{const Qe=n.downloadFile;Qe&&Qe(be.path)},className:"h-6 w-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.saveFile"),"aria-label":e("filesView.editor.saveFile"),children:s.jsx(I,{name:"download",className:"h-4 w-4"})}),Se?s.jsx(we,{variant:"ghost",size:"sm",onClick:()=>T(!1),className:"h-6 w-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.exitFullscreen"),"aria-label":e("filesView.editor.exitFullscreen"),children:s.jsx(I,{name:"fullscreen-exit",className:"h-4 w-4"})}):!d&&t==="full"&&s.jsx(we,{variant:"ghost",size:"sm",onClick:()=>T(!N),className:"h-6 w-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e(N?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),"aria-label":e(N?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),children:N?s.jsx(I,{name:"fullscreen-exit",className:"h-4 w-4"}):s.jsx(I,{name:"fullscreen",className:"h-4 w-4"})})]}):null,Fe=s.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden",children:[s.jsx(ws,{open:ut,onOpenChange:Se=>{Se||Gt(!0)},children:s.jsxs(vs,{showCloseButton:!1,className:"max-w-md",children:[s.jsxs(Cs,{children:[s.jsx(js,{children:e("filesView.unsaved.title")}),s.jsx(Rs,{children:e("filesView.unsaved.description")})]}),s.jsxs(Ks,{children:[s.jsx(we,{variant:"outline",onClick:()=>{Oa()},disabled:Xe,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(we,{variant:"destructive",onClick:yi,children:e("filesView.unsaved.discard")})]})]})}),s.jsx("div",{className:me("flex flex-col flex-shrink-0",x&&"border-b border-border/40"),children:x?s.jsxs("div",{className:"flex min-w-0 items-center px-3 py-1.5",children:[d&&A&&s.jsx("button",{type:"button",onClick:()=>E(!1),"aria-label":e("filesView.editor.back"),className:"inline-flex h-7 w-7 flex-shrink-0 items-center justify-center mr-1 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(I,{name:"arrow-left-s",className:"h-5 w-5"})}),d?be?s.jsxs(Bs,{children:[s.jsx(Os,{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(br,{filePath:be.path,extension:be.extension,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:be.name}),s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground"})]})}),s.jsx($s,{align:"start",className:"min-w-[16rem]",children:fe.map(Se=>{const Qe=be?.path===Se.path;return s.jsxs(zt,{onSelect:mt=>{if(mt.target.closest("[data-close-open-file]")){mt.preventDefault();return}Qe||jn(Se)},className:me("flex items-center justify-between gap-2",Qe&&"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]"),children:[s.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2 truncate",children:[s.jsx(br,{filePath:Se.path,extension:Se.extension,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:Se.name})]}),s.jsx("button",{type:"button","data-close-open-file":!0,onPointerDown:mt=>{mt.preventDefault(),mt.stopPropagation()},onClick:mt=>{mt.preventDefault(),mt.stopPropagation(),ia(Se.path)},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]","aria-label":e("filesView.editor.closeFileAria",{name:Se.name}),children:s.jsx(I,{name:"close",className:"h-3.5 w-3.5"})})]},Se.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")}):fe.length>0?s.jsxs("div",{className:"relative min-w-0 flex-1",children:[Pe.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"}),Pe.right&&s.jsx("div",{className:"pointer-events-none absolute right-0 top-0 bottom-0 w-6 z-10 bg-gradient-to-l from-background to-transparent"}),s.jsx("div",{ref:G,className:"flex min-w-0 items-center gap-1 overflow-x-auto scrollbar-none",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:fe.map(Se=>{const Qe=be?.path===Se.path;return s.jsxs("div",{title:cd(v,Se.path),className:me("group inline-flex items-center gap-1 rounded-md border px-2 py-1 typography-ui-label transition-colors whitespace-nowrap",Qe?"bg-[var(--interactive-selection)] border-[var(--primary-muted)] text-[var(--interactive-selection-foreground)]":"bg-transparent border-[var(--interactive-border)] text-[var(--surface-muted-foreground)] hover:bg-[var(--interactive-hover)] hover:text-[var(--surface-foreground)]"),children:[s.jsx(br,{filePath:Se.path,extension:Se.extension,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("button",{type:"button",onClick:()=>{Qe||jn(Se)},className:"max-w-[12rem] truncate text-left",children:Se.name}),s.jsx("button",{type:"button",onClick:mt=>{mt.stopPropagation(),ia(Se.path)},className:me("rounded-sm p-0.5 text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]",!Qe&&!u&&"opacity-0 group-hover:opacity-100"),"aria-label":e("filesView.editor.closeFileAria",{name:Se.name}),children:s.jsx(I,{name:"close",className:"h-3.5 w-3.5"})})]},Se.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")})]}):null}),s.jsxs("div",{className:"flex-1 min-h-0 min-w-0 relative",children:[be&&!M&&s.jsx("div",{ref:B,className:"absolute right-3 top-3 z-30",onMouseEnter:()=>$(!0),onMouseLeave:()=>{O.current>0||$(!1)},children:L?mo():s.jsx(we,{variant:"ghost",size:"sm",onClick:()=>$(!0),className:"h-8 w-8 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-0 text-muted-foreground shadow-sm hover:text-foreground","aria-label":e("filesView.editor.showControlsAria"),title:e("filesView.editor.controlsTitle"),children:s.jsx(I,{name:"more-2-fill",className:"h-4 w-4"})})}),s.jsx(Ts,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:be?qe?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(I,{name:"loader-4",className:"h-4 w-4 animate-spin"}),e("filesView.state.loading")]}):Ke?s.jsx("div",{className:"p-3 typography-ui text-[color:var(--status-error)]",children:Ke}):Jt?s.jsx("div",{className:"flex h-full items-center justify-center p-3",children:s.jsx("img",{src:la,alt:be?.name??e("filesView.editor.imageAltFallback"),className:"max-w-full max-h-[70vh] object-contain rounded-md border border-border/30 bg-primary/10"})}):be&&Hr&&Q==="tree"?s.jsx(Xs,{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(dv,{jsonString:Re,maxHeight:"100%",initiallyExpandedDepth:2})})}):be&&oa&&Tr()==="preview"?s.jsxs("div",{className:"h-full overflow-auto p-3",children:[Re.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(Re.length/1024)})}),s.jsx(Xs,{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(Aa,{content:Re,className:"typography-markdown-body",stripFrontmatter:!0})})]}):be&&_a&&X==="preview"?s.jsx("div",{className:"h-full overflow-hidden",children:s.jsx("iframe",{srcDoc:(()=>{const Se=be.path.substring(0,be.path.lastIndexOf("/")+1);if(!Se)return Re;const Qe=`<base href="${r.isDesktop,Se}">`;return Re.replace(/<head([^>]*)>/i,`<head$1>${Qe}`)})(),className:"w-full h-full border-none",sandbox:"allow-scripts allow-same-origin allow-forms",title:e("filesView.editor.htmlPreviewTitle")})}):be&&vi&&z==="view"?uo(be,Ue):s.jsxs("div",{className:me("relative h-full",zn&&"overflow-hidden"),ref:He,children:[s.jsx("div",{className:me("h-full",zn&&"invisible"),children:s.jsx(ad,{value:Ue,onChange:ot,readOnly:!er,extensions:lo,className:"h-full",blockWidgets:Bl,onViewReady:Se=>{Mt.current=Se,Et(Qe=>Qe+1),window.requestAnimationFrame(()=>{qr(Se)})},onViewDestroy:()=>{Mt.current&&(Mt.current=null),Et(Se=>Se+1)},enableSearch:!0,searchOpen:M,onSearchOpenChange:R,highlightLines:zs?{start:Math.min(zs.start,zs.end),end:Math.max(zs.start,zs.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(Se,Qe,mt)=>{if(!(mt instanceof MouseEvent)||mt.button!==0)return!1;mt.preventDefault();const xt=Se.state.doc.lineAt(Qe.from).number;if(d&&zs&&!mt.shiftKey){const _t=Math.min(zs.start,zs.end,xt),Qt=Math.max(zs.start,zs.end,xt);return un({start:_t,end:Qt}),Qs.current=!1,mn.current=null,wn(!1),!0}if(Qs.current=!0,mn.current=xt,wn(!0),zs&&mt.shiftKey){const _t=Math.min(zs.start,xt),Qt=Math.max(zs.end,xt);un({start:_t,end:Qt})}else un({start:xt,end:xt});return!0},mouseover:(Se,Qe,mt)=>{if(!(mt instanceof MouseEvent)||mt.buttons!==1||!Qs.current||mn.current===null)return!1;const xt=Se.state.doc.lineAt(Qe.from).number,_t=Math.min(mn.current,xt),Qt=Math.max(mn.current,xt);return un({start:_t,end:Qt}),wn(!0),!1},mouseup:()=>(Qs.current=!1,mn.current=null,wn(!1),!1)}}})}),zn&&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(I,{name:"loader-4",className:"h-4 w-4 animate-spin"}),e("filesView.state.openingFileAtChange")]})})]}):s.jsx("div",{className:"p-3 typography-ui text-muted-foreground",children:e("filesView.editor.pickFileFromTree")})})]})]}),Nt=!!(v&&ge[v]),ht=s.jsxs("section",{className:me("flex min-h-0 flex-col overflow-hidden",d?"h-full w-full bg-background":"h-full rounded-xl border border-border/60 bg-background/70"),children:[s.jsx("div",{className:me("flex flex-col gap-2 py-2",d?"px-3":"px-2"),children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("div",{className:"relative flex-1 min-w-0",children:[s.jsx(I,{name:"search",className:"pointer-events-none absolute left-2 top-2 h-4 w-4 text-muted-foreground"}),s.jsx(Kt,{ref:S,value:k,onChange:Se=>D(Se.target.value),placeholder:e("filesView.tree.search.placeholder"),className:"h-8 pl-8 pr-8 typography-meta"}),k.trim().length>0&&s.jsx("button",{type:"button","aria-label":e("filesView.tree.search.clearAria"),className:"absolute right-2 top-2 inline-flex h-4 w-4 items-center justify-center text-muted-foreground hover:text-foreground",onClick:()=>{D(""),S.current?.focus()},children:s.jsx(I,{name:"close",className:"h-4 w-4"})})]}),s.jsx(we,{variant:"ghost",size:"sm",onClick:()=>qs("createFile",{path:f,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFileTitle"),children:s.jsx(I,{name:"file-add",className:"h-4 w-4"})}),s.jsx(we,{variant:"ghost",size:"sm",onClick:()=>qs("createFolder",{path:f,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFolderTitle"),children:s.jsx(I,{name:"folder-add",className:"h-4 w-4"})}),s.jsx(we,{variant:"ghost",size:"sm",onClick:()=>{Vn()},className:"h-8 w-8 p-0 flex-shrink-0",children:s.jsx(I,{name:"refresh",className:"h-4 w-4"})})]})}),s.jsx(Ts,{outerClassName:"flex-1 min-h-0",className:me("py-2",d?"px-3":"px-2"),children:s.jsx("ul",{className:"flex flex-col",children:Ye?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"h-4 w-4 animate-spin"}),e("filesView.tree.search.searching")]}):xe.length>0?xe.map(Se=>{const Qe=be?.path===Se.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>{jn(Se)},className:me("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors",Qe?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),children:[Wf(Se.path,Se.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},title:Se.path,children:Se.relativePath??Se.path})]})},Se.path)}):Nt?Ot(v,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:e("filesView.state.loading")})})})]}),ts=t==="full"&&N&&be&&s.jsx("div",{className:"absolute inset-0 z-50 flex flex-col bg-background",children:s.jsxs("div",{className:"flex-1 min-h-0 min-w-0 relative",children:[s.jsx("div",{className:"absolute right-4 top-4 z-30",children:mo({exitFullscreenOnly:!0})}),s.jsx(Ts,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:qe?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(I,{name:"loader-4",className:"h-4 w-4 animate-spin"}),"Loading…"]}):Ke?s.jsx("div",{className:"p-4 typography-ui text-[color:var(--status-error)]",children:Ke}):Jt?s.jsx("div",{className:"flex h-full items-center justify-center p-4",children:s.jsx("img",{src:la,alt:be.name,className:"max-w-full max-h-full object-contain rounded-md border border-border/30 bg-primary/10"})}):oa&&Tr()==="preview"?s.jsxs("div",{className:"h-full overflow-auto p-4",children:[Re.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(Re.length/1024)})}),s.jsx(Xs,{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(Aa,{content:Re,className:"typography-markdown-body",stripFrontmatter:!0})})]}):vi&&z==="view"?uo(be,Ue):s.jsxs("div",{className:me("relative h-full",zn&&"overflow-hidden"),children:[s.jsx("div",{className:me("h-full",zn&&"invisible"),children:s.jsx(ad,{value:Ue,onChange:ot,readOnly:!er,extensions:lo,className:"h-full",onViewReady:Se=>{Mt.current=Se,window.requestAnimationFrame(()=>{qr(Se)})},onViewDestroy:()=>{Mt.current&&(Mt.current=null)}})}),zn&&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(I,{name:"loader-4",className:"h-4 w-4 animate-spin"}),e("filesView.state.openingFileAtChange")]})})]})})]})});return s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden bg-background relative",children:[wi(),ts,d?A?Fe:ht: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:Fe})}):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:ht}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden rounded-xl border border-border/60 bg-background",children:Fe})]})]})},j2=Object.freeze(Object.defineProperty({__proto__:null,FilesView:Kf},Symbol.toStringTag,{value:"Module"})),Ir=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},xc=(t,e)=>{const n=Ir(t),r=e.replace(/\\/g,"/").replace(/^\/+/,"").replace(/\/+$/,"");return!n||n==="/"?`/${r}`:`${n}/${r}`},N2=(t,e,n)=>xc(xc(xc(t,".opencode"),"plans"),`${e}-${n}.md`),S2=(t,e)=>`~/.opencode/plans/${t}-${e}.md`,k2=(t,e)=>{const n=t.trim();return n.startsWith("~")?n==="~"?e||n:(n.startsWith("~/")||n.startsWith("~\\"))&&e?`${e}${n.slice(1)}`:n:n},C2=(t,e)=>{const n=Ir(e.currentDirectory),r=Ir(e.homeDirectory),a=Ir(t);return n&&a.startsWith(n+"/")?a.slice(n.length+1):r&&a===r?"~":r&&a.startsWith(r+"/")?`~${a.slice(r.length)}`:a},I2=(t,e,n)=>{const r=Ir(t.trim());if(!r)return null;const a=n?e.find(o=>o.id===n)??null:null;if(a?.path){const o=Ir(a.path);if(r===o||r.startsWith(`${o}/`))return{id:a.id,path:a.path}}const i=e.filter(o=>{const c=Ir(o.path);return r===c||r.startsWith(`${c}/`)}).sort((o,c)=>Ir(c.path).length-Ir(o.path).length)[0];return i?{id:i.id,path:i.path}:null},Hf=({targetPath:t=null})=>{const{t:e}=pt(),n=Vt(ge=>ge.currentSessionId),r=Vt(ge=>ge.createSession),a=Vt(ge=>ge.initializeNewOpenChamberSession),i=Vt(ge=>ge.sendMessage),o=Vt(ge=>ge.setCurrentSession),c=Pl(),d=Vs(ge=>ge.homeDirectory),p=Pd(ge=>ge.planModeEnabled),m=Fs(ge=>ge.projects),u=Fs(ge=>ge.activeProjectId),h=nn(ge=>ge.directories),b=Er()??"",f=Te(ge=>ge.setActiveMainTab),v=Te(ge=>ge.setSessionSwitcherOpen),x=_n(),{isMobile:g}=an(),{currentTheme:w}=jr();l.useMemo(()=>_h(w),[w]);const y=l.useMemo(()=>n?c.find(ge=>ge.id===n)??null:null,[n,c]),k=l.useMemo(()=>{const ge=typeof y?.directory=="string"?y.directory:"";return Ir(ge||"")},[y?.directory]),D=l.useMemo(()=>Ir(b||k),[b,k]),j=l.useMemo(()=>I2(D,m,u),[u,D,m]),S=l.useMemo(()=>j?h.get(j.path)?.isGitRepo===!0:!1,[j,h]),[A,E]=l.useState(null),[P,C]=l.useState(!1),[N,T]=l.useState(null),M=l.useMemo(()=>!N||!k||!d?N:C2(N,{currentDirectory:k,homeDirectory:d}),[N,k,d]),[R,L]=l.useState(""),[$,B]=l.useState(null),O=l.useMemo(()=>M&&M.split("/").pop()||e("planView.file.defaultName"),[M,e]),_=l.useMemo(()=>R.trim()&&gb(R).title||e("planView.title.default"),[R,e]),ee=l.useMemo(()=>_.trim()||e("planView.title.default"),[_,e]),[z,ne]=l.useState(!1),[re,ue]=l.useState(!1),[Q,de]=l.useState("edit"),X=l.useRef(null),[F,V]=l.useState(null),q=l.useRef(null),te=l.useRef(null),U="openchamber:plan:md-viewer-mode";l.useEffect(()=>{try{const ge=localStorage.getItem(U);if(!ge)return;const W=JSON.parse(ge);(W==="preview"||W==="edit")&&de(W)}catch{}},[]);const ae=l.useCallback(ge=>{de(ge);try{localStorage.setItem(U,JSON.stringify(ge))}catch{}},[]),je=l.useRef(!1),oe=l.useRef(null),[ve,K]=l.useState(!1);l.useEffect(()=>{const ge=()=>{je.current=!1,oe.current=null,K(!1)};return document.addEventListener("mouseup",ge),()=>document.removeEventListener("mouseup",ge)},[]);const ce=l.useCallback((ge,W)=>{const ie=ge.split(`
54
- `),Me=Math.max(1,W.start),Ve=Math.min(ie.length,W.end);return Me>Ve?"":ie.slice(Me-1,Ve).join(`
55
- `)},[]),Z=qd({source:"plan",fileLabel:O,language:N&&Wi(N)||"markdown",getCodeForRange:ge=>ce(R,pl(ge)),toStoreRange:ge=>({startLine:ge.start,endLine:ge.end}),fromDraftRange:ge=>({start:ge.startLine,end:ge.endLine})}),{drafts:le,commentText:se,editingDraftId:Ie,setSelection:Ne,saveComment:Y,cancel:fe,reset:ke,startEdit:be,deleteDraft:pe}=Z;l.useEffect(()=>{V(null),ke()},[R,ke]),l.useEffect(()=>{Ne(F)},[F,Ne]);const Ee=l.useCallback(()=>{V(null),fe()},[fe]),ze=l.useCallback((ge,W)=>{W&&V(W),Y(ge,W??F??void 0),V(null)},[F,Y]);l.useEffect(()=>{if(!F)return;const ge=ie=>{const Me=ie.target;Me.closest('[data-comment-card="true"]')||Me.closest('[data-comment-input="true"]')||Me.closest(".oc-block-widget")||Me.closest(".cm-gutterElement")||Me.closest("[data-sonner-toast]")||Me.closest("[data-sonner-toaster]")||(V(null),fe())},W=window.setTimeout(()=>{document.addEventListener("click",ge)},100);return()=>{window.clearTimeout(W),document.removeEventListener("click",ge)}},[fe,Ie,g,F]);const G=l.useMemo(()=>{const ge=[ld(w)],W=zf(N||"plan.md");return W&&ge.push(W),ge.push(Yn.lineWrapping),ge},[w,N]);l.useEffect(()=>{if(!p&&!t){T(null),L(""),ne(!1);return}let ge=!1;const W=async Me=>{if(x.files?.readFile)return(await x.files.readFile(Me))?.content??"";const Ve=dr()?.files;if(Ve?.readFile)return(await Ve.readFile(Me,{optional:!0}))?.content??"";const Ce=await fetch(`/api/fs/read?path=${encodeURIComponent(Me)}&optional=true`,{cache:"no-store"});if(!Ce.ok)throw new Error(`Failed to read plan file (${Ce.status})`);return Ce.text()};return(async()=>{if(T(null),L(""),B(null),t){ne(!0);try{const Me=await W(t);if(ge)return;T(t),L(Me)}catch{if(ge)return;T(null),L("")}finally{ge||ne(!1)}return}if(!y?.slug||!y?.time?.created||!k){T(null),L("");return}ne(!0);try{const Me=N2(k,y.time.created,y.slug),Ve=k2(S2(y.time.created,y.slug),d||null);let Ce=null,xe=null;try{xe=await W(Me),Ce=Me}catch{}if(!Ce)try{xe=await W(Ve),Ce=Ve}catch{}if(ge)return;if(!Ce||xe===null){T(null),L("");return}T(Ce),L(xe)}catch{if(ge)return;T(null),L("")}finally{ge||ne(!1)}})(),()=>{ge=!0}},[d,p,x.files,k,y?.slug,y?.time?.created,t]),l.useEffect(()=>{if(!N){B(null);return}const ge=window.setTimeout(async()=>{B(null);try{if(x.files?.writeFile){if(!(await x.files.writeFile(N,R))?.success)throw new Error(e("planView.error.writeFailed"))}else{const W=await fetch("/api/fs/write",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:N,content:R})});if(!W.ok)throw new Error(e("planView.error.writePlanFileFailed",{status:W.status}))}}catch(W){B(W instanceof Error?W.message:e("planView.error.saveFailed"))}},350);return()=>{window.clearTimeout(ge)}},[R,N,x.files,e]),l.useEffect(()=>()=>{X.current!==null&&window.clearTimeout(X.current)},[]);const Pe=l.useCallback(()=>{f("chat"),v(!1)},[f,v]),Le=l.useCallback(async ge=>{if(!j||!A)return;const W=await kn(A.action==="improve"?"plan.improve.visible":"plan.implement.visible",{plan_title:ee}),Me=[{synthetic:!0,text:await kn(A.action==="improve"?"plan.improve.instructions":"plan.implement.instructions",{plan_title:ee,plan_path:N??""})}];C(!0);try{Pe();let Ve=null,Ce=j.path;if(A.target==="worktree"){if(!S)return;const De=await Oh(j.path,$h());if(!De?.id)return;Ve=De.id,Ce=null}else{const De=await r(void 0,j.path,null);if(!De?.id)return;Ve=De.id,Ce=De.directory??j.path,a(De.id,gt.getState().agents??[])}if(!Ve)return;const xe=Nl.getState();xe.saveSessionModelSelection(Ve,ge.providerID,ge.modelID),ge.agent.trim()&&(xe.saveSessionAgentSelection(Ve,ge.agent),xe.saveAgentModelForSession(Ve,ge.agent,ge.providerID,ge.modelID),xe.saveAgentModelVariantForSession(Ve,ge.agent,ge.providerID,ge.modelID,ge.variant||void 0)),o(Ve,Ce),await i(W,ge.providerID,ge.modelID,ge.agent.trim()||void 0,void 0,void 0,Me,ge.variant||void 0),E(null)}finally{C(!1)}},[S,r,j,a,A,N,Pe,i,ee,o]),Ae=l.useMemo(()=>Ff({drafts:le,editingDraftId:Ie,commentText:se,selection:F,isDragging:ve,fileLabel:O,newWidgetId:"plan-new-comment-input",mapDraftToRange:ge=>({start:ge.startLine,end:ge.endLine}),onSave:ze,onCancel:Ee,onEdit:ge=>{be(ge),V({start:ge.startLine,end:ge.endLine})},onDelete:pe}),[se,pe,Ie,Ee,ze,ve,F,le,O,be]);return s.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden bg-background",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2 border-b border-border/40 px-3 py-1.5 flex-shrink-0",children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"typography-ui-label font-medium truncate",children:_}),$?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(Bs,{children:[s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(Os,{asChild:!0,children:s.jsx(we,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0","aria-label":e("planView.actions.improvePlanAria"),disabled:!R.trim(),children:s.jsx(I,{name:"loop-right-ai",className:"size-4"})})})}),s.jsx(Pt,{sideOffset:8,children:e("planView.actions.improve")})]}),s.jsxs($s,{align:"end",children:[s.jsx(zt,{onClick:()=>E({action:"improve",target:"session"}),children:e("planView.actions.sendToNewSession")}),s.jsx(zt,{onClick:()=>E({action:"improve",target:"worktree"}),disabled:!S,children:e("planView.actions.sendToNewWorktreeSession")})]})]}),s.jsxs(Bs,{children:[s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(Os,{asChild:!0,children:s.jsx(we,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0","aria-label":e("planView.actions.implementPlanAria"),disabled:!R.trim(),children:s.jsx(I,{name:"code-ai",className:"size-4"})})})}),s.jsx(Pt,{sideOffset:8,children:e("planView.actions.implement")})]}),s.jsxs($s,{align:"end",children:[s.jsx(zt,{onClick:()=>E({action:"implement",target:"session"}),children:e("planView.actions.sendToNewSession")}),s.jsx(zt,{onClick:()=>E({action:"implement",target:"worktree"}),disabled:!S,children:e("planView.actions.sendToNewWorktreeSession")})]})]}),s.jsx(id,{currentMode:Q,onToggle:()=>ae(Q==="preview"?"edit":"preview")}),s.jsx(we,{variant:"ghost",size:"sm",onClick:async()=>{(await Rn(R)).ok&&(ue(!0),X.current!==null&&window.clearTimeout(X.current),X.current=window.setTimeout(()=>{ue(!1)},1200))},className:"h-5 w-5 p-0",title:e("planView.actions.copyPlanContents"),"aria-label":e("planView.actions.copyPlanContents"),children:re?s.jsx(I,{name:"check",className:"h-4 w-4 text-[color:var(--status-success)]"}):s.jsx(I,{name:"clipboard",className:"h-4 w-4"})})]}):null]}),s.jsx(yf,{open:A!==null,onOpenChange:ge=>{!ge&&!P&&E(null)},target:A?.target??"session",projectDirectory:j?.path??null,submitting:P,onConfirm:Le}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 relative",children:s.jsx(Ts,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:z?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:Q==="preview"?s.jsx("div",{className:"h-full overflow-auto p-3",children:s.jsx(Xs,{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(Aa,{content:R,className:"typography-markdown-body"})})}):s.jsx("div",{className:"relative h-full",ref:te,children:s.jsx(ad,{value:R,onChange:L,readOnly:!1,className:"h-full",extensions:G,onViewReady:ge=>{q.current=ge},onViewDestroy:()=>{q.current=null},blockWidgets:Ae,highlightLines:F?{start:Math.min(F.start,F.end),end:Math.max(F.start,F.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(ge,W,ie)=>{if(!(ie instanceof MouseEvent)||ie.button!==0)return!1;ie.preventDefault();const Me=ge.state.doc.lineAt(W.from).number;if(g&&F&&!ie.shiftKey){const Ve=Math.min(F.start,F.end,Me),Ce=Math.max(F.start,F.end,Me);return V({start:Ve,end:Ce}),je.current=!1,oe.current=null,K(!1),!0}if(je.current=!0,oe.current=Me,K(!0),F&&ie.shiftKey){const Ve=Math.min(F.start,Me),Ce=Math.max(F.end,Me);V({start:Ve,end:Ce})}else V({start:Me,end:Me});return!0},mouseover:(ge,W,ie)=>{if(!(ie instanceof MouseEvent)||ie.buttons!==1||!je.current||oe.current===null)return!1;const Me=ge.state.doc.lineAt(W.from).number,Ve=Math.min(oe.current,Me),Ce=Math.max(oe.current,Me);return V({start:Ve,end:Ce}),K(!0),!1},mouseup:()=>(je.current=!1,oe.current=null,K(!1),!1)}}})})})})})})]})},P2=Object.freeze(Object.defineProperty({__proto__:null,PlanView:Hf},Symbol.toStringTag,{value:"Module"})),dd={input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:0},Wo={user:0,assistant:0,tool:0,other:0},ga=t=>typeof t!="number"||!Number.isFinite(t)||t<0?0:t,_m=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{...dd,total:ga(n)};if(!n||typeof n!="object")return dd;const r=n,a=ga(r.input),i=ga(r.output),o=ga(r.reasoning),c=ga(r.cache?.read),d=ga(r.cache?.write);return{input:a,output:i,reasoning:o,cacheRead:c,cacheWrite:d,total:a+i+o+c+d}},A2=(...t)=>{for(const e of t)if(typeof e=="string"&&e.trim().length>0)return e;return""},ir=t=>typeof t=="string"?t.length:typeof t=="number"||typeof t=="boolean"?String(t).length:Array.isArray(t)?t.reduce((e,n)=>e+ir(n),0):t&&typeof t=="object"?Object.values(t).reduce((e,n)=>e+ir(n),0):0,D2=(t,e)=>{const n=t,r=typeof n.type=="string"?n.type:"";if(r==="reasoning")return{...Wo,assistant:ir(n.text)+ir(n.content)};const a=A2(n.text,n.content,n.value,n.source?.value,n.source?.text?.value);return r==="tool"||e==="tool"?{user:0,assistant:0,tool:ir(n.input)+ir(n.output)+ir(n.error)+ir(n.call?.input)+ir(n.call?.output)+ir(n.call?.error)+ir(n.raw)+Math.round(ir(n.metadata)*.25)+Math.round(ir(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}},Vm=(t,e)=>({user:t.user+e.user,assistant:t.assistant+e.assistant,tool:t.tool+e.tool,other:t.other+e.other}),T2=t=>{const e=so(t.info);return e.isUser?"user":e.role==="assistant"?"assistant":e.role==="tool"?"tool":"other"},M2=(t,e)=>{if(t.length===0)return{...Wo};const n=t.reduce((r,a)=>{const i=T2(a);let o={...Wo};for(const c of a.parts)o=Vm(o,D2(c,i));return Vm(r,o)},{...Wo});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)}},Ya=t=>t.toLocaleString(),E2=t=>!Number.isFinite(t)||t<=0?"$0.00":t<.01?`$${t.toFixed(4)}`:`$${t.toFixed(2)}`,R2=t=>!t||!Number.isFinite(t)?"-":new Date(t).toLocaleString(void 0,{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"}),F2=t=>!t||!Number.isFinite(t)?"-":new Date(t).toLocaleString(void 0,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}),L2=t=>t&&`${t[0].toUpperCase()}${t.slice(1)}`,O2=(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}},$2=()=>{const t=at.c(199),{t:e}=pt(),{currentTheme:n}=jr();let r;t[0]!==n?(r=_h(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=Vt(B2),h=Pl(),b=xb(u??""),f=gt(_2);let v;t[3]===Symbol.for("react.memo_cache_sentinel")?(v=()=>{m.current!==null&&(window.clearTimeout(m.current),m.current=null),c(V2),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(jt,St)=>{(await Rn(St)).ok?(p(jt),m.current!==null&&window.clearTimeout(m.current),m.current=window.setTimeout(()=>{p(ut=>ut===jt?null:ut),m.current=null},2e3)):p(null)},t[8]=y):y=t[8];const k=y;let D;t[9]!==u||t[10]!==h?(D=u?h.find(jt=>jt.id===u)??null:null,t[9]=u,t[10]=h,t[11]=D):D=t[11];const j=D;let S,A,E,P,C;if(t[12]!==f||t[13]!==b){S=b.filter(z2);let jt;t[19]!==b?(jt=b.filter(U2),t[19]=b,t[20]=jt):jt=t[20],C=jt;let St=null;for(let ut=S.length-1;ut>=0;ut=ut-1,ut){const Gt=S[ut];if(_m(Gt).total>0){St=Gt;break}}E=St?_m(St):dd,P=S.reduce(W2,0);const ns=St?.info??null;A=O2(f,ns?.providerID||"",ns?.modelID||""),t[12]=f,t[13]=b,t[14]=S,t[15]=A,t[16]=E,t[17]=P,t[18]=C}else S=t[14],A=t[15],E=t[16],P=t[17],C=t[18];const N=A,T=N.contextLimit,M=T&&T>0?Math.min(999,E.total/T*100):0;let R;if(t[21]!==b){const jt=[...b].reverse().find(K2)?.info?.system||"";R=M2(b,jt),t[21]=b,t[22]=R}else R=t[22];const L=R,$=L.user,B=L.assistant,O=L.tool,_=Math.max(0,E.input-$-B-O),ee=$+B+O+_,z=b[0]?.info?.time?.created,ne=b.length>0?b[b.length-1]?.info?.time?.created:null;let re;t[23]!==j?.title||t[24]!==e?(re=j?.title||e("contextSidebar.session.untitled"),t[23]=j?.title,t[24]=e,t[25]=re):re=t[25];const ue=j?.time?.created??z??null,Q=ne??j?.time?.created??null;let de;t[26]!==B||t[27]!==_||t[28]!==O||t[29]!==$?(de={user:$,assistant:B,tool:O,other:_},t[26]=B,t[27]=_,t[28]=O,t[29]=$,t[30]=de):de=t[30];let X;t[31]!==S.length||t[32]!==ee||t[33]!==T||t[34]!==N||t[35]!==b.length||t[36]!==re||t[37]!==ue||t[38]!==Q||t[39]!==de||t[40]!==E||t[41]!==P||t[42]!==M||t[43]!==C.length?(X={sessionTitle:re,messagesCount:b.length,userMessagesCount:C.length,assistantMessagesCount:S.length,createdAt:ue,lastActivityAt:Q,providerModel:N,tokenBreakdown:E,usagePercent:M,totalAssistantCost:P,contextLimit:T,breakdown:de,breakdownTotal:ee},t[31]=S.length,t[32]=ee,t[33]=T,t[34]=N,t[35]=b.length,t[36]=re,t[37]=ue,t[38]=Q,t[39]=de,t[40]=E,t[41]=P,t[42]=M,t[43]=C.length,t[44]=X):X=t[44];const F=X;if(!u){let jt;t[45]!==e?(jt=e("contextSidebar.empty.openSession"),t[45]=e,t[46]=jt):jt=t[46];let St;return t[47]!==jt?(St=s.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center typography-ui-label text-muted-foreground",children:jt}),t[47]=jt,t[48]=St):St=t[48],St}let V;t[49]!==e?(V=e("contextSidebar.breakdown.user"),t[49]=e,t[50]=V):V=t[50];let q;t[51]!==V||t[52]!==F.breakdown.user?(q={key:"user",label:V,value:F.breakdown.user,color:"var(--status-success)"},t[51]=V,t[52]=F.breakdown.user,t[53]=q):q=t[53];let te;t[54]!==e?(te=e("contextSidebar.breakdown.assistant"),t[54]=e,t[55]=te):te=t[55];let U;t[56]!==te||t[57]!==F.breakdown.assistant?(U={key:"assistant",label:te,value:F.breakdown.assistant,color:"var(--primary-base)"},t[56]=te,t[57]=F.breakdown.assistant,t[58]=U):U=t[58];let ae;t[59]!==e?(ae=e("contextSidebar.breakdown.toolCalls"),t[59]=e,t[60]=ae):ae=t[60];let je;t[61]!==ae||t[62]!==F.breakdown.tool?(je={key:"tool",label:ae,value:F.breakdown.tool,color:"var(--status-warning)"},t[61]=ae,t[62]=F.breakdown.tool,t[63]=je):je=t[63];let oe;t[64]!==e?(oe=e("contextSidebar.breakdown.other"),t[64]=e,t[65]=oe):oe=t[65];let ve;t[66]!==oe||t[67]!==F.breakdown.other?(ve={key:"other",label:oe,value:F.breakdown.other,color:"var(--surface-muted-foreground)"},t[66]=oe,t[67]=F.breakdown.other,t[68]=ve):ve=t[68];let K;t[69]!==q||t[70]!==U||t[71]!==je||t[72]!==ve?(K=[q,U,je,ve],t[69]=q,t[70]=U,t[71]=je,t[72]=ve,t[73]=K):K=t[73];const ce=K;let Z;t[74]!==F.sessionTitle?(Z=s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:F.sessionTitle}),t[74]=F.sessionTitle,t[75]=Z):Z=t[75];let le;t[76]!==F.providerModel.modelName||t[77]!==F.providerModel.providerName?(le=s.jsxs("span",{children:[F.providerModel.providerName," / ",F.providerModel.modelName]}),t[76]=F.providerModel.modelName,t[77]=F.providerModel.providerName,t[78]=le):le=t[78];let se;t[79]!==F.createdAt?(se=F.createdAt&&s.jsxs(s.Fragment,{children:[s.jsx("span",{children:"·"}),s.jsx("span",{children:R2(F.createdAt)})]}),t[79]=F.createdAt,t[80]=se):se=t[80];let Ie;t[81]!==le||t[82]!==se?(Ie=s.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-2 gap-y-0.5 typography-micro text-muted-foreground/70",children:[le,se]}),t[81]=le,t[82]=se,t[83]=Ie):Ie=t[83];let Ne;t[84]!==Z||t[85]!==Ie?(Ne=s.jsxs("div",{className:"mb-6",children:[Z,Ie]}),t[84]=Z,t[85]=Ie,t[86]=Ne):Ne=t[86];let Y;t[87]!==e?(Y=e("contextSidebar.section.context"),t[87]=e,t[88]=Y):Y=t[88];let fe;t[89]!==Y?(fe=s.jsx("span",{className:"typography-micro text-muted-foreground",children:Y}),t[89]=Y,t[90]=fe):fe=t[90];let ke;t[91]!==F.tokenBreakdown.total?(ke=Ya(F.tokenBreakdown.total),t[91]=F.tokenBreakdown.total,t[92]=ke):ke=t[92];let be;t[93]!==F.contextLimit?(be=F.contextLimit?` / ${Ya(F.contextLimit)}`:"",t[93]=F.contextLimit,t[94]=be):be=t[94];let pe;t[95]!==ke||t[96]!==be?(pe=s.jsxs("span",{className:"typography-micro tabular-nums text-muted-foreground/70",children:[ke,be]}),t[95]=ke,t[96]=be,t[97]=pe):pe=t[97];let Ee;t[98]!==fe||t[99]!==pe?(Ee=s.jsxs("div",{className:"flex items-baseline justify-between",children:[fe,pe]}),t[98]=fe,t[99]=pe,t[100]=Ee):Ee=t[100];let ze;t[101]!==F.usagePercent?(ze=F.usagePercent>0&&s.jsx("div",{className:"rounded-full transition-all duration-300",style:{width:`${Math.max(.5,F.usagePercent)}%`,backgroundColor:F.usagePercent>80?"var(--status-warning)":"var(--primary-base)"}}),t[101]=F.usagePercent,t[102]=ze):ze=t[102];let G;t[103]!==ze?(G=s.jsx("div",{className:"mt-2.5 flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:ze}),t[103]=ze,t[104]=G):G=t[104];let Pe;t[105]!==e||t[106]!==F.usagePercent?(Pe=e("contextSidebar.context.percentUsed",{percent:F.usagePercent.toFixed(1)}),t[105]=e,t[106]=F.usagePercent,t[107]=Pe):Pe=t[107];let Le;t[108]!==Pe?(Le=s.jsx("div",{className:"mt-1.5 typography-micro font-medium tabular-nums text-foreground/80",children:Pe}),t[108]=Pe,t[109]=Le):Le=t[109];let Ae;t[110]!==Ee||t[111]!==G||t[112]!==Le?(Ae=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[Ee,G,Le]}),t[110]=Ee,t[111]=G,t[112]=Le,t[113]=Ae):Ae=t[113];let ge;t[114]!==e?(ge=e("contextSidebar.stats.messages"),t[114]=e,t[115]=ge):ge=t[115];let W;t[116]!==F.messagesCount?(W=Ya(F.messagesCount),t[116]=F.messagesCount,t[117]=W):W=t[117];let ie;t[118]!==ge||t[119]!==W?(ie={label:ge,value:W},t[118]=ge,t[119]=W,t[120]=ie):ie=t[120];let Me;t[121]!==e?(Me=e("contextSidebar.stats.user"),t[121]=e,t[122]=Me):Me=t[122];let Ve;t[123]!==F.userMessagesCount?(Ve=Ya(F.userMessagesCount),t[123]=F.userMessagesCount,t[124]=Ve):Ve=t[124];let Ce;t[125]!==Me||t[126]!==Ve?(Ce={label:Me,value:Ve},t[125]=Me,t[126]=Ve,t[127]=Ce):Ce=t[127];let xe;t[128]!==e?(xe=e("contextSidebar.stats.assistant"),t[128]=e,t[129]=xe):xe=t[129];let De;t[130]!==F.assistantMessagesCount?(De=Ya(F.assistantMessagesCount),t[130]=F.assistantMessagesCount,t[131]=De):De=t[131];let Ye;t[132]!==xe||t[133]!==De?(Ye={label:xe,value:De},t[132]=xe,t[133]=De,t[134]=Ye):Ye=t[134];let rt;t[135]!==e?(rt=e("contextSidebar.stats.cost"),t[135]=e,t[136]=rt):rt=t[136];let Re;t[137]!==F.totalAssistantCost?(Re=E2(F.totalAssistantCost),t[137]=F.totalAssistantCost,t[138]=Re):Re=t[138];let he;t[139]!==rt||t[140]!==Re?(he={label:rt,value:Re},t[139]=rt,t[140]=Re,t[141]=he):he=t[141];let qe;t[142]!==ie||t[143]!==Ce||t[144]!==Ye||t[145]!==he?(qe=[ie,Ce,Ye,he],t[142]=ie,t[143]=Ce,t[144]=Ye,t[145]=he,t[146]=qe):qe=t[146];const et=qe;let Ke;t[147]!==et?(Ke=s.jsx("div",{className:"mb-5 grid grid-cols-2 gap-2",children:et.map(H2)}),t[147]=et,t[148]=Ke):Ke=t[148];let st;t[149]!==e?(st=e("contextSidebar.section.lastAssistantMessage"),t[149]=e,t[150]=st):st=t[150];let nt;t[151]!==st?(nt=s.jsx("div",{className:"typography-micro text-muted-foreground",children:st}),t[151]=st,t[152]=nt):nt=t[152];let ye;t[153]!==e||t[154]!==F.tokenBreakdown.cacheRead||t[155]!==F.tokenBreakdown.cacheWrite||t[156]!==F.tokenBreakdown.input||t[157]!==F.tokenBreakdown.output||t[158]!==F.tokenBreakdown.reasoning?(ye=s.jsx("div",{className:"mt-2.5 grid grid-cols-3 gap-x-4 gap-y-2.5",children:[{label:e("contextSidebar.tokens.input"),value:F.tokenBreakdown.input},{label:e("contextSidebar.tokens.output"),value:F.tokenBreakdown.output},{label:e("contextSidebar.tokens.reasoning"),value:F.tokenBreakdown.reasoning},{label:e("contextSidebar.tokens.cacheRead"),value:F.tokenBreakdown.cacheRead},{label:e("contextSidebar.tokens.cacheWrite"),value:F.tokenBreakdown.cacheWrite}].map(G2)}),t[153]=e,t[154]=F.tokenBreakdown.cacheRead,t[155]=F.tokenBreakdown.cacheWrite,t[156]=F.tokenBreakdown.input,t[157]=F.tokenBreakdown.output,t[158]=F.tokenBreakdown.reasoning,t[159]=ye):ye=t[159];let Je;t[160]!==nt||t[161]!==ye?(Je=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[nt,ye]}),t[160]=nt,t[161]=ye,t[162]=Je):Je=t[162];let _e;t[163]!==ce||t[164]!==F.breakdownTotal?(_e=s.jsx("div",{className:"flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:ce.map(jt=>jt.value<=0||F.breakdownTotal<=0?null:s.jsx("div",{style:{width:`${jt.value/F.breakdownTotal*100}%`,backgroundColor:jt.color}},jt.key))}),t[163]=ce,t[164]=F.breakdownTotal,t[165]=_e):_e=t[165];let Ue;t[166]!==ce||t[167]!==F.breakdownTotal?(Ue=s.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-x-4 gap-y-1",children:ce.map(jt=>{const St=F.breakdownTotal>0?jt.value/F.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:jt.color}}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70",children:[jt.label," ",s.jsxs("span",{className:"tabular-nums",children:[St.toFixed(0),"%"]})]})]},jt.key)})}),t[166]=ce,t[167]=F.breakdownTotal,t[168]=Ue):Ue=t[168];let ot;t[169]!==_e||t[170]!==Ue?(ot=s.jsxs("div",{className:"mb-6",children:[_e,Ue]}),t[169]=_e,t[170]=Ue,t[171]=ot):ot=t[171];let Xe;t[172]!==e?(Xe=e("contextSidebar.section.rawMessages"),t[172]=e,t[173]=Xe):Xe=t[173];let We;t[174]!==Xe?(We=s.jsx("div",{className:"typography-micro text-muted-foreground",children:Xe}),t[174]=Xe,t[175]=We):We=t[175];let bt;if(t[176]!==d||t[177]!==o||t[178]!==b||t[179]!==a||t[180]!==e){let jt;t[182]!==d||t[183]!==o||t[184]!==a||t[185]!==e?(jt=St=>{const ns=so(St.info).role,ut=o[St.info.id]===!0,Gt=d===St.info.id,Xt=St.info.time?.created??null,Wt=ut?JSON.stringify({info:St.info,parts:St.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":ut,onClick:()=>{c(is=>({...is,[St.info.id]:is[St.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:L2(ns)}),s.jsx("span",{className:"min-w-0 truncate typography-micro text-muted-foreground",children:St.info.id})]}),s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:F2(Xt)})]})}),ut&&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:is=>{is.stopPropagation(),k(St.info.id,Wt)},"aria-label":e(Gt?"contextSidebar.actions.copied":"contextSidebar.actions.copyJson"),title:e(Gt?"contextSidebar.actions.copied":"contextSidebar.actions.copy"),children:Gt?s.jsx(I,{name:"check",className:"size-3.5"}):s.jsx(I,{name:"file-copy",className:"size-3.5"})})}),s.jsx(hx,{language:"json",style:a,PreTag:"div",customStyle:{margin:0,padding:"0.75rem",background:"transparent",fontSize:"var(--text-micro)",lineHeight:"1.35"},codeTagProps:{style:{whiteSpace:"pre-wrap",wordBreak:"break-word",overflowWrap:"break-word"}},wrapLongLines:!0,children:Wt})]})})]},St.info.id)},t[182]=d,t[183]=o,t[184]=a,t[185]=e,t[186]=jt):jt=t[186],bt=[...b].reverse().map(jt),t[176]=d,t[177]=o,t[178]=b,t[179]=a,t[180]=e,t[181]=bt}else bt=t[181];let Dt;t[187]!==bt?(Dt=s.jsx("div",{className:"mt-2.5 space-y-1",children:bt}),t[187]=bt,t[188]=Dt):Dt=t[188];let Ht;t[189]!==We||t[190]!==Dt?(Ht=s.jsxs("div",{children:[We,Dt]}),t[189]=We,t[190]=Dt,t[191]=Ht):Ht=t[191];let rs;return t[192]!==Ne||t[193]!==Ae||t[194]!==Ke||t[195]!==Je||t[196]!==ot||t[197]!==Ht?(rs=s.jsx("div",{className:"h-full overflow-y-auto bg-background",children:s.jsxs("div",{className:"mx-auto w-full max-w-[52rem] px-5 py-6",children:[Ne,Ae,Ke,Je,ot,Ht]})}),t[192]=Ne,t[193]=Ae,t[194]=Ke,t[195]=Je,t[196]=ot,t[197]=Ht,t[198]=rs):rs=t[198],rs};function B2(t){return t.currentSessionId}function _2(t){return t.providers}function V2(t){return Object.keys(t).length>0?{}:t}function z2(t){return so(t.info).role==="assistant"}function U2(t){return so(t.info).isUser}function W2(t,e){const n=ga(e.info.cost);return t+n}function K2(t){return so(t.info).isUser&&typeof t.info.system=="string"}function H2(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 G2(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:Ya(t.value)})]},t.label)}const q2=360,J2=1400,Gf=600,Q2=24,zm=200,Y2=(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",ud=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"},qf=({pageUrl:t,viewport:e,devicePixelRatio:n,target:r,screenshotAttached:a,intro:i})=>{const o=r.text.trim(),c=Object.entries(r.attributes).map(([b,f])=>`${b}="${f}"`).join(" "),d=r.computedStyle,p=r.bounds,m=r.center,u=i.replace(/[.:]+$/g,""),h=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}`,h?`- Ancestry: ${h}`: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
- `)},X2=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 h=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*h),u.fillRect(e.bounds.x*h,e.bounds.y*b,e.bounds.width*h,e.bounds.height*b),u.strokeRect(e.bounds.x*h,e.bounds.y*b,e.bounds.width*h,e.bounds.height*b);const f=await new Promise(v=>m.toBlob(v,"image/jpeg",.82));return f?new File([f],`preview-annotation-${Date.now()}.jpg`,{type:"image/jpeg"}):null}catch(r){return console.warn("[preview] failed to capture annotation screenshot:",r),null}return null},Z2=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},Um=t=>Number.isFinite(t)?Math.min(J2,Math.max(q2,Math.round(t))):Gf,eS=(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},tS=(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"),sS=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},nS=(t,e)=>{if(t.label)return t.label;if(t.mode==="file")return sS(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 tS(t.mode,e)},rS=t=>{if(t.mode==="file")return t.targetPath?s.jsx(br,{filePath:t.targetPath,className:"h-3.5 w-3.5"}):void 0;if(t.mode==="diff")return s.jsx(I,{name:"arrow-left-right",className:"h-3.5 w-3.5"});if(t.mode==="plan")return s.jsx(I,{name:"file-text",className:"h-3.5 w-3.5"});if(t.mode==="context")return s.jsx(I,{name:"donut-chart-fill",className:"h-3.5 w-3.5"});if(t.mode==="chat")return s.jsx(I,{name:"chat-4",className:"h-3.5 w-3.5"});if(t.mode==="preview")return s.jsx(I,{name:"global",className:"h-3.5 w-3.5 text-[var(--status-info)]"});if(t.mode==="browser")return s.jsx(I,{name:"global",className:"h-3.5 w-3.5"})},aS=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
- });`,bc=`(() => {
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
- })()`,yc=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"}},oS=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 h=u.getContext("2d");if(!h)return null;h.scale(m,m),h.drawImage(o,0,0,c,d);const b=c/Math.max(1,r||c),f=d/Math.max(1,a||d);h.fillStyle="rgba(37, 99, 235, 0.14)",h.strokeStyle="rgb(37, 99, 235)",h.lineWidth=Math.max(2,2*b),h.fillRect(i.bounds.x*b,i.bounds.y*f,i.bounds.width*b,i.bounds.height*f),h.strokeRect(i.bounds.x*b,i.bounds.y*f,i.bounds.width*b,i.bounds.height*f);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}},lS=(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()},cS=(t,e)=>t.length<=e?t:`${t.slice(0,e-3)}...`,ba=new Map,dS=3e4,uS=t=>{const e=ba.get(t);return e?e.expiresAt-Date.now()<=dS?(ba.delete(t),null):e:null},mS=({rawUrl:t,onNavigate:e})=>{const{t:n}=pt(),{currentTheme:r}=jr(),[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),[h,b]=l.useState(!1),[f,v]=l.useState(!1),[x,g]=l.useState("all"),[w,y]=l.useState([]),[k,D]=l.useState(!1),[j,S]=l.useState(null),A=Vt(oe=>oe.currentSessionId),E=Vt(oe=>oe.newSessionDraft?.open),P=Za(oe=>oe.addDraft),C=Pa(oe=>oe.addAttachedFile);let N=null;try{N=t?new URL(t):null}catch{N=null}const T=N?N.hostname==="localhost"||N.hostname==="127.0.0.1"||N.hostname==="::1"||N.hostname==="[::1]"||N.hostname==="0.0.0.0":!1,M=N?N.hostname==="0.0.0.0"?new URL(N.toString().replace("0.0.0.0","127.0.0.1")):N:null,R=M?M.toString():"",L=r.metadata.variant;l.useEffect(()=>{if(!R||!T){p({status:"idle"});return}const oe=uS(R);if(oe){p({status:"ready",proxyBasePath:oe.proxyBasePath,expiresAt:oe.expiresAt});return}let ve=!1;return p({status:"loading"}),(async()=>{try{const K=await fetch("/api/preview/targets",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({url:R})});if(!K.ok){ba.delete(R);const se=await K.json().catch(()=>({})),Ie=typeof se?.error=="string"?se.error:`HTTP ${K.status}`;ve||p({status:"error",message:Ie});return}const ce=await K.json(),Z=typeof ce.proxyBasePath=="string"?ce.proxyBasePath:"",le=typeof ce.expiresAt=="number"?ce.expiresAt:0;if(!Z){ba.delete(R),ve||p({status:"error",message:n("contextPanel.preview.proxyError")});return}ba.set(R,{proxyBasePath:Z,expiresAt:le}),ve||p({status:"ready",proxyBasePath:Z,expiresAt:le})}catch(K){if(ba.delete(R),!ve){const ce=K instanceof Error?K.message:String(K);p({status:"error",message:ce})}}})(),()=>{ve=!0}},[T,o,n,R]);const $=M&&(M.protocol==="http:"||M.protocol==="https:")?M.toString():"",B=T&&d.status==="ready"&&M?(()=>{const oe=M.pathname||"/",ve=new URLSearchParams(M.search);ve.set("ocPreview",String(a));const K=ve.toString(),ce=M.hash||"";return`${d.proxyBasePath}${oe}${K?`?${K}`:""}${ce}`})():"",O=T?B:$,_=O||$,ee=T&&(d.status==="loading"||d.status==="idle"),z=T&&d.status==="error",ne=l.useCallback(oe=>{const ve=A??(E?"draft":null);if(!ve){H.error(n("contextPanel.preview.inspect.attachNoSession"));return}const K=t||O||"",ce=typeof window<"u"?{width:window.innerWidth,height:window.innerHeight}:{width:0,height:0},Z=typeof window<"u"?window.devicePixelRatio:1;(async()=>{let le=!1;try{const se=m.current,Ie=se?await X2(se,oe):null;Ie&&(await C(Ie),le=!0)}catch{le=!1}P({sessionKey:ve,source:"preview-annotation",fileLabel:K||"preview",startLine:1,endLine:1,code:qf({pageUrl:K,viewport:ce,devicePixelRatio:Z,target:oe,screenshotAttached:le,intro:n("contextPanel.preview.inspect.attachAnnotation")}),language:"markdown",text:""}),H.success(n("contextPanel.preview.inspect.attached"))})()},[C,P,A,O,E,t,n]);l.useEffect(()=>{b(!1),y([]),v(!1),g("all"),D(!1),S(null),u.current=1},[O]),l.useEffect(()=>{const oe=m.current?.contentWindow;!h||!oe||oe.postMessage({source:"openchamber-preview-parent",version:1,type:"set-inspect-mode",enabled:k},window.location.origin)},[h,k]),l.useEffect(()=>{const oe=m.current?.contentWindow;!h||!oe||oe.postMessage({source:"openchamber-preview-parent",version:1,type:"set-color-scheme",scheme:L},window.location.origin)},[h,L]),l.useEffect(()=>{if(!k||typeof window>"u")return;const oe=ve=>{ve.key==="Escape"&&(ve.preventDefault(),ve.stopImmediatePropagation(),D(!1))};return window.addEventListener("keydown",oe,!0),()=>window.removeEventListener("keydown",oe,!0)},[k]),l.useEffect(()=>{if(!T||typeof window>"u")return;const oe=ce=>{if(typeof ce=="string")return ce;if(ce==null)return"";try{return JSON.stringify(ce)}catch{return String(ce)}},ve=ce=>{const Z=u.current;u.current+=1,y(le=>{const se=[...le,{...ce,id:Z}];return se.length>zm?se.slice(se.length-zm):se})},K=ce=>{if(ce.source!==m.current?.contentWindow)return;const Z=ce.data;if(!(!Z||Z.source!=="openchamber-preview-bridge"||Z.version!==1)){if(Z.type==="ready"){b(!0);return}if(Z.type==="console"){const le=Z.level==="error"||Z.level==="warn"||Z.level==="info"||Z.level==="debug"?Z.level:"log",se=Array.isArray(Z.args)?Z.args.map(oe).filter(Boolean):[];ve({level:le,message:se.join(" "),ts:typeof Z.ts=="number"?Z.ts:Date.now()});return}if(Z.type==="runtime-error"){const le=oe(Z.filename),se=typeof Z.line=="number"?Z.line:null,Ie=typeof Z.column=="number"?Z.column:null,Ne=le?`${le}${se!==null?`:${se}${Ie!==null?`:${Ie}`:""}`:""}`:"",Y=oe(Z.stack);ve({level:"runtime",message:oe(Z.message)||n("contextPanel.preview.console.runtimeError"),details:[Ne,Y].filter(Boolean).join(`
148
- `),ts:typeof Z.ts=="number"?Z.ts:Date.now()});return}if(Z.type==="resource-error"){const le=oe(Z.tag)||"resource",se=oe(Z.url);ve({level:"resource",message:se?`${le}: ${se}`:le,details:oe(Z.outerHTML),ts:typeof Z.ts=="number"?Z.ts:Date.now()});return}if(Z.type==="hover"){S(ud(Z.target)?Z.target:null);return}if(Z.type==="select"&&ud(Z.target)){S(Z.target),D(!1),ne(Z.target);return}if(Z.type==="navigate-preview"){const le=typeof Z.url=="string"?Z.url:"",se=Z.navigation==="external"?"external":"proxy";if(le&&se==="external"){Xn(le);return}le&&e(le)}}};return window.addEventListener("message",K),()=>{window.removeEventListener("message",K)}},[ne,T,e,n]);const re=w.filter(oe=>oe.level==="error"||oe.level==="runtime"||oe.level==="resource").length,ue=w.filter(oe=>Y2(oe,x)),Q=l.useCallback(()=>{const oe=[`Preview URL: ${t||O||""}`,`Events: ${w.length}`,""].join(`
149
- `),ve=w.map(K=>{const ce=new Date(K.ts).toISOString(),Z=K.details?`
150
- ${K.details}`:"";return`[${ce}] [${K.level}] ${K.message}${Z}`}).join(`
151
- `);Rn(`${oe}${ve}`).then(K=>{K.ok?H.success(n("contextPanel.preview.console.copied")):H.error(n("contextPanel.preview.console.copyFailed"))})},[w,O,t,n]),de=l.useCallback(()=>{const oe=A??(E?"draft":null);if(!oe){H.error(n("contextPanel.preview.console.attachNoSession"));return}const ve=[`Preview URL: ${t||O||""}`,`Events: ${w.length}`,""].join(`
152
- `),K=w.map(ce=>{const Z=new Date(ce.ts).toISOString(),le=ce.details?`
153
- ${ce.details}`:"";return`[${Z}] [${ce.level}] ${ce.message}${le}`}).join(`
154
- `);P({sessionKey:oe,source:"preview-console",fileLabel:t||O||"preview",startLine:1,endLine:Math.max(1,w.length),code:`${ve}${K}`,language:"text",text:n("contextPanel.preview.console.attachAnnotation")}),H.success(n("contextPanel.preview.console.attached"))},[P,w,A,O,E,t,n]),[X,F]=l.useState("unknown"),V=l.useRef(0),q=l.useRef(0),te=15e3;l.useEffect(()=>{if(!B){F("unknown"),V.current=0,q.current=0;return}let oe=!1;return V.current||(V.current=Date.now(),q.current=0),F("unknown"),(async()=>{const K=await(async()=>{try{return await fetch(B,{method:"GET",credentials:"include",cache:"no-store",redirect:"manual"})}catch{return null}})();if(oe)return;if(!K){F("unreachable");return}if(K.status===403||K.status===404){ba.delete(R),p({status:"loading"}),c();return}if(K.status!==502){F("reachable");return}const ce=V.current||Date.now();if(Date.now()-ce<te){F("starting"),q.current+=1;const le=q.current,se=Math.min(2e3,250*Math.pow(2,Math.min(4,le)));setTimeout(()=>{oe||i()},se).unref?.();return}F("unreachable")})(),()=>{oe=!0}},[B,a,R]);const U=T&&d.status==="ready"&&(X==="unknown"||X==="starting"),ae=T&&d.status==="ready"&&X==="unreachable",je=l.useCallback(oe=>{if(!T||d.status!=="ready"||typeof window>"u")return;const ve=oe.currentTarget.contentWindow;if(ve)try{const K=ve.location;if(K.origin!==window.location.origin||K.pathname.startsWith(d.proxyBasePath))return;const ce=`${d.proxyBasePath}${K.pathname}${K.search}${K.hash}`;ve.location.replace(ce)}catch{}},[T,d]);return s.jsxs("div",{className:"absolute inset-0 flex flex-col",children:[s.jsxs("div",{className:"flex items-center gap-1 border-b border-border/40 bg-[var(--surface-background)] px-2 py-1",children:[s.jsx("div",{className:"min-w-0 flex-1 truncate typography-micro text-muted-foreground",title:_||t,children:_||t||n("contextPanel.preview.empty")}),s.jsx(we,{type:"button",size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>i(),title:n("contextPanel.preview.actions.reload"),"aria-label":n("contextPanel.preview.actions.reload"),disabled:!O,children:s.jsx(I,{name:"refresh",className:"h-3.5 w-3.5"})}),s.jsx(we,{type:"button",size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{$&&Xn($)},title:n("contextPanel.preview.actions.openExternal"),"aria-label":n("contextPanel.preview.actions.openExternal"),disabled:!$,children:s.jsx(I,{name:"external-link",className:"h-3.5 w-3.5"})}),T?s.jsx(we,{type:"button",size:"sm",variant:k?"secondary":"ghost",className:"h-7 gap-1 px-2",onClick:()=>D(oe=>!oe),title:n("contextPanel.preview.inspect.toggle"),"aria-label":n("contextPanel.preview.inspect.toggle"),disabled:!h,children:s.jsx(I,{name:"cursor",className:"h-3.5 w-3.5"})}):null,T?s.jsxs(we,{type:"button",size:"sm",variant:f?"secondary":"ghost",className:"h-7 gap-1 px-2",onClick:()=>v(oe=>!oe),title:n(h?"contextPanel.preview.console.open":"contextPanel.preview.console.waiting"),"aria-label":n(h?"contextPanel.preview.console.open":"contextPanel.preview.console.waiting"),disabled:!h&&w.length===0,children:[s.jsx(I,{name:"terminal-box",className:"h-3.5 w-3.5"}),re>0?s.jsx("span",{className:"typography-micro text-status-error",children:re}):null]}):null]}),s.jsxs("div",{className:"relative min-h-0 flex-1 bg-background",children:[U?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")})]}):ae?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(we,{type:"button",size:"sm",variant:"outline",onClick:()=>i(),children:n("contextPanel.preview.actions.retry")})]}):O&&(!T||X==="reachable")?s.jsxs("div",{className:"relative h-full w-full",children:[s.jsx("iframe",{ref:m,src:O,title:n("contextPanel.preview.iframeTitle"),className:"h-full w-full border-0",style:{colorScheme:L},onLoad:je,sandbox:T?"allow-scripts allow-same-origin allow-forms allow-popups allow-downloads":"allow-scripts allow-forms"},`${O}:${a}`),k&&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]}):ee?s.jsx("div",{className:"flex h-full items-center justify-center px-6 text-sm text-muted-foreground",children:n("contextPanel.preview.loading")}):z?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")}),f?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(we,{type:"button",size:"xs",variant:"ghost",onClick:de,disabled:w.length===0,children:n("contextPanel.preview.console.attach")}),s.jsx(we,{type:"button",size:"xs",variant:"ghost",onClick:Q,disabled:w.length===0,children:n("contextPanel.preview.console.copy")}),s.jsx(we,{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(we,{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")}):ue.length===0?s.jsx("div",{className:"px-2 py-3 text-muted-foreground",children:n("contextPanel.preview.console.noFilteredEvents")}):ue.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:me("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]})]})},pS=({initialUrl:t,directory:e,tabID:n})=>{const{t:r}=pt(),a=l.useRef(null),i=Te(E=>E.setContextPanelTabTargetPath),o=yc(t),c=o!=="about:blank"?o:"",[d,p]=l.useState(c),[m,u]=l.useState(c),[h,b]=l.useState(!1),[f,v]=l.useState(!0),x=l.useRef(null),g=f,w=l.useCallback(E=>{!E||E==="about:blank"||!e||!n||i(e,n,E)},[e,n,i]),y=Vt(E=>E.currentSessionId),k=Vt(E=>E.newSessionDraft?.open),D=Za(E=>E.addDraft),j=Pa(E=>E.addAttachedFile);l.useEffect(()=>{const E=a.current;if(!E)return;const P=()=>{try{const R=E.getURL();R&&R!=="about:blank"&&(u(R),p(R),w(R))}catch{}},C=R=>{const L=R.detail;typeof L?.url=="string"&&L.url&&(u(L.url),p(L.url),w(L.url))},N=()=>{x.current&&clearTimeout(x.current),x.current=setTimeout(()=>v(!0),200)},T=()=>{x.current&&clearTimeout(x.current),v(!1),P()},M=R=>{const L=R.detail;if(L?.disposition==="new-window"||L?.disposition==="foreground-tab"||L?.disposition==="background-tab"){R.preventDefault();const $=a.current;typeof $?.loadURL=="function"&&L.url&&$.loadURL(L.url)}};E.addEventListener("did-navigate",C),E.addEventListener("did-navigate-in-page",C),E.addEventListener("did-start-loading",N),E.addEventListener("did-stop-loading",T),E.addEventListener("new-window",M);try{E.isLoading()||(v(!1),P())}catch{}return()=>{x.current&&clearTimeout(x.current),E.removeEventListener("did-navigate",C),E.removeEventListener("did-navigate-in-page",C),E.removeEventListener("did-start-loading",N),E.removeEventListener("did-stop-loading",T),E.removeEventListener("new-window",M)}},[w]),l.useEffect(()=>{const E=setTimeout(()=>v(!1),3e4);return()=>clearTimeout(E)},[]),l.useEffect(()=>{if(!h)return;const E=P=>{if(P.key!=="Escape")return;P.preventDefault(),P.stopImmediatePropagation(),b(!1);const C=a.current;try{C?.executeJavaScript?.(bc).catch(()=>{})}catch{}};return window.addEventListener("keydown",E,!0),()=>window.removeEventListener("keydown",E,!0)},[h]),l.useEffect(()=>{const E=a.current;return()=>{try{const P=E?.getURL?.();P&&P!=="about:blank"&&i(e,n,P)}catch{}try{E?.executeJavaScript?.(bc).catch(()=>{})}catch{}}},[e,n,i]);const S=l.useCallback(E=>{const P=a.current;if(typeof P?.loadURL!="function")return;const C=yc(E);try{P.loadURL(C)}catch{}},[]),A=l.useCallback(()=>{const E=a.current;if(E){if(h){b(!1);try{E.executeJavaScript?.(bc).catch(()=>{})}catch{}return}b(!0),E.executeJavaScript?.(iS,!0).then(async P=>{if(b(!1),!P||!ud(P))return;const C=y??(k?"draft":null);if(!C){H.error(r("contextPanel.preview.inspect.attachNoSession"));return}const N=typeof E.getWebContentsId=="function"?E.getWebContentsId():null;if(N==null)return;const T=await bb("desktop_browser_capture_page",{webContentsId:N}),M=await E.executeJavaScript?.("({ width: window.innerWidth, height: window.innerHeight })",!0).catch(()=>null),R=Number.isFinite(M?.width)?M.width:T.width,L=Number.isFinite(M?.height)?M.height:T.height,$=await oS(T.base64,T.width,T.height,R,L,P),B=!!$;$&&await j($),D({sessionKey:C,source:"preview-annotation",fileLabel:m||"browser",startLine:1,endLine:1,code:qf({pageUrl:m,viewport:{width:R,height:L},devicePixelRatio:window.devicePixelRatio||1,target:P,screenshotAttached:B,intro:r("contextPanel.preview.inspect.attachAnnotationWithScreenshot")}),language:"markdown",text:""}),H.success(r("contextPanel.preview.inspect.attached"))}).catch(()=>b(!1))}},[j,D,y,m,h,k,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(we,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{a.current?.goBack?.()}catch{}},children:s.jsx(I,{name:"arrow-left",className:"h-3.5 w-3.5"})}),s.jsx(we,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{a.current?.goForward?.()}catch{}},children:s.jsx(I,{name:"arrow-right",className:"h-3.5 w-3.5"})}),s.jsx(we,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{a.current?.reload?.()}catch{}},children:s.jsx(I,{name:"refresh",className:"h-3.5 w-3.5"})}),s.jsx("form",{className:"min-w-0 flex-1",onSubmit:E=>{E.preventDefault(),S(d)},children:s.jsx("input",{value:d,onChange:E=>p(E.target.value),className:"h-7 w-full rounded-md border border-border/50 bg-[var(--surface-elevated)] px-2 typography-micro text-foreground outline-none focus:border-[var(--interactive-focus-ring)]","aria-label":r("contextPanel.browser.addressAria")})}),s.jsx(we,{type:"button",variant:h?"secondary":"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:A,title:r("contextPanel.preview.inspect.toggle"),"aria-label":r("contextPanel.preview.inspect.toggle"),children:s.jsx(I,{name:"cursor",className:"h-3.5 w-3.5"})}),s.jsx(we,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{Xn(m)},children:s.jsx(I,{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:yc(t),partition:"persist:openchamber-browser",style:{width:"100%",height:"100%",border:"none"}}),(!m||m==="about:blank")&&!f?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]})]})},hS=()=>{const{t}=pt(),e=Er()??"",n=l.useMemo(()=>Z2(e),[e]),r=Te(U=>n?U.contextPanelByDirectory[n]:void 0),a=Te(U=>U.closeContextPanel),i=Te(U=>U.closeContextPanelTab),o=Te(U=>U.toggleContextPanelExpanded),c=Te(U=>U.setContextPanelWidth),d=Te(U=>U.setActiveContextPanelTab),p=Te(U=>U.reorderContextPanelTabs),m=Te(U=>U.setPendingDiffFile),u=$n(U=>U.setSelectedPath),h=Te(U=>U.openContextPreview),{themeMode:b,lightThemeId:f,darkThemeId:v,currentTheme:x}=jr(),g=l.useMemo(()=>r?.tabs??[],[r?.tabs]),w=g.find(U=>U.id===r?.activeTabId)??g[g.length-1]??null,y=!!(r?.isOpen&&w),k=!!(y&&r?.expanded),D=Um(r?.width??Gf),[j,S]=l.useState(!1),A=l.useRef(0),E=l.useRef(D),P=l.useRef(null),C=l.useRef(null),N=l.useRef(null),T=l.useRef(new Map),M=l.useRef(!1);l.useEffect(()=>{if(!y||M.current){M.current=y;return}const U=window.requestAnimationFrame(()=>{N.current?.focus({preventScroll:!0})});return M.current=!0,()=>window.cancelAnimationFrame(U)},[y]);const R=l.useCallback(U=>{const ae=N.current;ae&&ae.style.setProperty("--oc-context-panel-width",`${U}px`)},[]),L=l.useCallback(U=>{if(!(!y||k||!n)){try{U.currentTarget.setPointerCapture(U.pointerId)}catch{}C.current=U.pointerId,S(!0),A.current=U.clientX,E.current=D,P.current=D,R(D),U.preventDefault()}},[R,n,k,y,D]),$=l.useCallback(U=>{if(!j||C.current!==U.pointerId)return;const ae=A.current-U.clientX,je=Um(E.current+ae);P.current!==je&&(P.current=je,R(je))},[R,j]),B=l.useCallback(U=>{if(C.current!==U.pointerId||!n)return;try{U.currentTarget.releasePointerCapture(U.pointerId)}catch{}const ae=P.current??D;S(!1),C.current=null,P.current=null,c(n,ae)},[n,c,D]);l.useEffect(()=>{j||(P.current=null)},[j]);const O=l.useCallback(()=>{n&&a(n)},[a,n]),_=l.useCallback(()=>{n&&o(n)},[n,o]),ee=l.useCallback(U=>{U.key==="Escape"&&(U.preventDefault(),U.stopPropagation(),O())},[O]);l.useEffect(()=>{if(!(!n||!w)){if(w.mode==="file"&&w.targetPath){u(n,w.targetPath);return}w.mode==="diff"&&w.targetPath&&m(w.targetPath)}},[w,n,m,u]);const z=w?.mode==="chat"?w.id:null,ne=l.useCallback(()=>{if(typeof window>"u")return;const U={themeMode:b,lightThemeId:f,darkThemeId:v,currentTheme:x};for(const ae of T.current.values()){const je=ae.contentWindow;if(!je)continue;const oe=je.__openchamberApplyThemeSync;if(typeof oe=="function")try{oe(U);continue}catch{}je.postMessage({type:"openchamber:theme-sync",payload:U},window.location.origin)}},[x,v,f,b]),re=l.useCallback(()=>{if(!(typeof window>"u"))for(const[U,ae]of T.current.entries()){const je=ae.contentWindow;if(!je)continue;const oe={visible:z===U},ve=je.__openchamberSetEmbeddedVisibility;if(typeof ve=="function")try{ve(oe);continue}catch{}je.postMessage({type:"openchamber:embedded-visibility",payload:oe},window.location.origin)}},[z]);l.useLayoutEffect(()=>{g.some(ae=>ae.mode==="chat")&&(ne(),re())},[v,f,re,ne,g,b]);const ue=l.useMemo(()=>g.map(U=>{const ae=nS(U,t),je=cS(ae,Q2),oe=eS(U.targetPath,e);return{id:U.id,label:je,icon:rS(U),title:oe?`${ae}: ${oe}`:ae,closeLabel:t("contextPanel.tab.closeTabAria",{label:je})}}),[e,t,g]),Q=w?.mode==="diff"?s.jsx(_f,{hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!0,hideFileSelector:!0,pinSelectedFileHeaderToTopOnNavigate:!0,showOpenInEditorAction:!0}):w?.mode==="context"?s.jsx($2,{}):w?.mode==="plan"?s.jsx(Hf,{targetPath:w.targetPath}):w?.mode==="preview"?s.jsx(mS,{rawUrl:w.targetPath??"",onNavigate:U=>h(e,U)}):s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[s.jsx(I,{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")})]}),de=l.useMemo(()=>g.filter(U=>U.mode==="chat"),[g]),X=l.useMemo(()=>g.filter(U=>U.mode==="browser"),[g]),F=l.useMemo(()=>g.some(U=>U.mode==="file"),[g]),V=w?.mode==="file",q=s.jsxs("header",{className:"flex h-8 items-stretch border-b border-transparent",children:[s.jsx(Ar,{items:ue,activeId:w?.id??null,onSelect:U=>{n&&d(n,U)},onClose:U=>{n&&i(n,U)},onReorder:(U,ae)=>{n&&p(n,U,ae)},layoutMode:"scrollable",variant:"default"}),s.jsxs("div",{className:"flex items-center gap-1 px-1.5",children:[s.jsx(we,{type:"button",variant:"ghost",size:"sm",onClick:_,className:"h-7 w-7 p-0",title:t(k?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),"aria-label":t(k?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),children:k?s.jsx(I,{name:"fullscreen-exit",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"fullscreen",className:"h-3.5 w-3.5"})}),s.jsx(we,{type:"button",variant:"ghost",size:"sm",onClick:O,className:"h-7 w-7 p-0",title:t("contextPanel.actions.closePanel"),"aria-label":t("contextPanel.actions.closePanel"),children:s.jsx(I,{name:"close",className:"h-3.5 w-3.5"})})]})]});if(!y)return null;const te=k?{"--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??D:D}px`};return s.jsxs("aside",{ref:N,"data-context-panel":"true",tabIndex:-1,className:me("flex min-h-0 flex-col overflow-hidden bg-background",!k&&"border-l border-border/40",k?"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:ee,style:te,children:[!k&&s.jsx("div",{className:me("absolute left-0 top-0 z-20 h-full w-[3px] cursor-col-resize transition-colors hover:bg-[var(--interactive-border)]/80",j&&"bg-[var(--interactive-border)]"),onPointerDown:L,onPointerMove:$,onPointerUp:B,onPointerCancel:B,role:"separator","aria-orientation":"vertical","aria-label":t("contextPanel.actions.resizePanelAria")}),q,s.jsxs("div",{className:me("relative min-h-0 flex-1 overflow-hidden",j&&"pointer-events-none"),children:[F?s.jsx("div",{className:me("absolute inset-0",V?"block":"hidden"),children:s.jsx(Kf,{mode:"editor-only"})}):null,de.map(U=>{const ae=aS(U.dedupeKey);if(!ae)return null;const je=lS(ae,n||null,U.readOnly);return je?s.jsx("iframe",{ref:oe=>{if(!oe){T.current.delete(U.id);return}T.current.set(U.id,oe)},src:je,title:t("contextPanel.iframe.sessionChatTitle",{sessionID:ae}),className:me("absolute inset-0 h-full w-full border-0 bg-background",z===U.id?"block":"hidden"),onLoad:()=>{ne(),re()}},U.id):null}),X.map(U=>s.jsx("div",{className:me("absolute inset-0",w?.mode!=="browser"&&"hidden"),children:s.jsx(pS,{initialUrl:U.targetPath??"",directory:n,tabID:U.id})},U.id)),w?.mode!=="chat"&&!V&&w?.mode!=="browser"?Q:null]})]})},Jd=[{slug:"home",title:"Settings",group:"general",kind:"single",description:"Search and jump to common pages.",keywords:["search","settings"]},{slug:"projects",title:"Projects",group:"projects",kind:"split",keywords:["project","projects","worktree","worktrees","repo","repository","directory"]},{slug:"remote-instances",title:"Remote Instances",group:"projects",kind:"split",keywords:["ssh","remote","instances","tunnels","forwarding","connection"],isAvailable:t=>t.isDesktop&&!t.isWeb&&!t.isVSCode},{slug:"providers",title:"Providers",group:"opencode",kind:"split",keywords:["provider","providers","models","model","api key","api keys","openai","anthropic","ollama","credentials"]},{slug:"usage",title:"Usage",group:"usage",kind:"split",keywords:["quota","billing","tokens","usage","limits"]},{slug:"agents",title:"Agents",group:"opencode",kind:"split",keywords:["agent","agents","prompts","tools","permissions"]},{slug:"behavior",title:"Behavior",group:"opencode",kind:"single",keywords:["behavior","agents.md","system prompt","global rules","instructions","override"]},{slug:"commands",title:"Commands",group:"opencode",kind:"split",keywords:["command","commands","slash","macros","automation"]},{slug:"mcp",title:"MCP",group:"opencode",kind:"split",keywords:["mcp","model context protocol","servers","tools","remote","stdio"]},{slug:"skills.installed",title:"Skills",group:"skills",kind:"split",keywords:["skill","skills","instructions","install","catalog"]},{slug:"skills.catalog",title:"Skills Catalog",group:"skills",kind:"single",keywords:["install","catalog","external","repository","skills catalog"]},{slug:"git",title:"Git",group:"git",kind:"single",keywords:["git","github","identity","identities","ssh","profiles","credentials","keys","commit","gitmoji","oauth","prs","issues"],isAvailable:t=>!t.isVSCode},{slug:"appearance",title:"Appearance",group:"appearance",kind:"single",keywords:["theme","font","spacing","padding","corner radius","radius","input bar","keyboard","viewport","mobile","terminal","pwa","install name","app shortcuts"]},{slug:"chat",title:"Chat",group:"general",kind:"single",keywords:["tools","diff","reasoning","dotfiles","draft","queue","output","copy","image","split messages","message actions"]},{slug:"shortcuts",title:"Shortcuts",group:"general",kind:"single",keywords:["keyboard","hotkeys","shortcuts","bindings"],isAvailable:t=>!t.isVSCode},{slug:"sessions",title:"Sessions",group:"general",kind:"single",keywords:["defaults","default agent","default model","retention","memory","limits","zen"]},{slug:"magic-prompts",title:"Magic Prompts",group:"general",kind:"split",keywords:["prompts","templates","git","github","review","commit","pull request"],isAvailable:t=>!t.isVSCode},{slug:"notifications",title:"Notifications",group:"general",kind:"single",keywords:["alerts","native","summary","summarization"]},{slug:"voice",title:"Voice",group:"advanced",kind:"single",keywords:["tts","speech","voice"],isAvailable:t=>!t.isVSCode},{slug:"tunnel",title:"Remote Tunnel",group:"advanced",kind:"single",keywords:["tunnel","cloudflare","qr","remote","mobile","share"],isAvailable:t=>!t.isVSCode}],fS={sessions:"sessions",agents:"agents",commands:"commands",mcp:"mcp",skills:"skills.installed",providers:"providers",usage:"usage","git-identities":"git",settings:"home"};function Ri(t){const e=t.trim().toLowerCase();return Jd.find(n=>n.slug===e)??null}function Jf(t){const e=(t??"").trim().toLowerCase();if(!e)return"home";const n=fS[e];if(n)return n;const r=Ri(e);return r?r.slug:"home"}const Qf=t=>t.replace(/[-_]/g," ").replace(/\b\w/g,e=>e.toUpperCase()),io=t=>{const e=at.c(39),{className:n}=t,{t:r}=pt(),a=Fs(gS),i=Fs(xS),o=Fs(bS),c=dn();let d;e[0]!==a?(d=[...a].sort(yS),e[0]=a,e[1]=d):d=e[1];const p=d;let m;e:{if(p.length===0){m=null;break e}let M;e[2]!==i||e[3]!==p?(M=p.find(R=>R.id===i)??p[0],e[2]=i,e[3]=p,e[4]=M):M=e[4],m=M}const u=m;if(c||p.length===0)return null;let h;e[5]!==u||e[6]!==r?(h=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]=h):h=e[7];const b=h;let f;e[8]!==b?(f=Qf(b),e[8]=b,e[9]=f):f=e[9];const v=f;let x;e[10]!==n?(x=me(n),e[10]=n,e[11]=x):x=e[11];let g;e[12]!==r?(g=r("settings.shared.projectSelector.switchProjectAria"),e[12]=r,e[13]=g):g=e[13];let w;e[14]!==r?(w=r("settings.shared.projectSelector.switchProjectTitle"),e[14]=r,e[15]=w):w=e[15];let y,k;e[16]===Symbol.for("react.memo_cache_sentinel")?(y=me("text-foreground border border-border/80 appearance-none flex h-8 w-full min-w-0 rounded-lg bg-transparent px-3 py-1 outline-none","hover:border-input focus-visible:ring-1 focus-visible:ring-primary/50 focus-visible:border-primary/70","flex items-center gap-1.5 text-left"),k=s.jsx(I,{name:"folder",className:"h-4 w-4 opacity-70"}),e[16]=y,e[17]=k):(y=e[16],k=e[17]);let D;e[18]!==v?(D=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium",children:v}),e[18]=v,e[19]=D):D=e[19];let j;e[20]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(I,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[20]=j):j=e[20];let S;e[21]!==D||e[22]!==g||e[23]!==w?(S=s.jsx(Os,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":g,title:w,className:y,children:[k,D,j]})}),e[21]=D,e[22]=g,e[23]=w,e[24]=S):S=e[24];const A=u?.id??"";let E;e[25]!==o?(E=M=>{M&&o(M)},e[25]=o,e[26]=E):E=e[26];let P;e[27]!==p?(P=p.map(vS),e[27]=p,e[28]=P):P=e[28];let C;e[29]!==A||e[30]!==E||e[31]!==P?(C=s.jsx($s,{align:"start",className:"w-auto",children:s.jsx(nl,{value:A,onValueChange:E,children:P})}),e[29]=A,e[30]=E,e[31]=P,e[32]=C):C=e[32];let N;e[33]!==S||e[34]!==C?(N=s.jsxs(Bs,{children:[S,C]}),e[33]=S,e[34]=C,e[35]=N):N=e[35];let T;return e[36]!==N||e[37]!==x?(T=s.jsx("div",{className:x,children:N}),e[36]=N,e[37]=x,e[38]=T):T=e[38],T};function gS(t){return t.projects}function xS(t){return t.activeProjectId}function bS(t){return t.setActiveProject}function yS(t,e){return(t.label||t.path).localeCompare(e.label||e.path)}function vS(t){const e=t.label?.trim()?t.label.trim():t.path.split("/").filter(Boolean).pop()||t.path,n=Qf(e);return s.jsx(rl,{value:t.id,children:s.jsx("span",{className:"min-w-0 truncate typography-ui",children:n})},t.id)}function wS(t,e){return`opencode:sidebar-group:${t}:${e}`}const md=t=>{const e=at.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=wS(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 C=localStorage.getItem(p);if(C!==null)return C==="true"}catch{}return c},e[3]=c,e[4]=p,e[5]=u):u=e[5];const[h,b]=Be.useState(u);let f,v;e[6]!==h||e[7]!==p?(f=()=>{try{localStorage.setItem(p,String(h))}catch{}},v=[p,h],e[6]=h,e[7]=p,e[8]=f,e[9]=v):(f=e[8],v=e[9]),Be.useEffect(f,v);let x;e[10]===Symbol.for("react.memo_cache_sentinel")?(x=()=>b(jS),e[10]=x):x=e[10];let g;e[11]===Symbol.for("react.memo_cache_sentinel")?(g=me("flex w-full items-center gap-1 rounded-md px-2 py-1 text-left","text-xs font-semibold uppercase tracking-wide text-muted-foreground","hover:bg-[var(--interactive-hover)] transition-colors duration-150","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50"),e[11]=g):g=e[11];const w=!h&&"-rotate-90";let y;e[12]!==w?(y=me("h-3.5 w-3.5 flex-shrink-0 transition-transform duration-200",w),e[12]=w,e[13]=y):y=e[13];let k;e[14]!==y?(k=s.jsx(I,{name:"arrow-down-s",className:y}),e[14]=y,e[15]=k):k=e[15];let D;e[16]!==n?(D=s.jsx("span",{className:"flex-1 truncate",children:n}),e[16]=n,e[17]=D):D=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]!==h||e[22]!==k||e[23]!==D||e[24]!==j?(S=s.jsxs("button",{type:"button",onClick:x,"aria-expanded":h,"aria-controls":m,className:g,children:[k,D,j]}),e[20]=m,e[21]=h,e[22]=k,e[23]=D,e[24]=j,e[25]=S):S=e[25];const A=!h;let E;e[26]!==o||e[27]!==m||e[28]!==A?(E=s.jsx("div",{id:m,hidden:A,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]=A,e[29]=E):E=e[29];let P;return e[30]!==S||e[31]!==E?(P=s.jsxs("div",{children:[S,E]}),e[30]=S,e[31]=E,e[32]=P):P=e[32],P};function jS(t){return!t}const NS=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},SS=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())},Wm=t=>{const e=SS(NS(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},kS=({onItemSelect:t})=>{const{t:e}=pt(),[n,r]=l.useState(null),[a,i]=l.useState(""),[o,c]=l.useState(null),[d,p]=l.useState(null),[m,u]=l.useState(!1),[h,b]=l.useState(null),{selectedAgentName:f,agents:v,setSelectedAgent:x,setAgentDraft:g,createAgent:w,deleteAgent:y,loadAgents:k}=oi(pr(_=>({selectedAgentName:_.selectedAgentName,agents:_.agents,setSelectedAgent:_.setSelectedAgent,setAgentDraft:_.setAgentDraft,createAgent:_.createAgent,deleteAgent:_.deleteAgent,loadAgents:_.loadAgents})));l.useEffect(()=>{k()},[k]);const D="bg-background",j=()=>{const _="new-agent";let ee=_,z=1;for(;v.some(ne=>ne.name===ee);)ee=`${_}-${z}`,z++;g({name:ee,scope:"user"}),x(ee),t?.()},S=async _=>{if(ei(_)){H.error(e("settings.agents.sidebar.toast.builtInCannotDelete"));return}c(_),p("delete")},A=async _=>{ei(_)&&(c(_),p("reset"))},E=()=>{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})),E()):d==="delete"?H.error(e("settings.agents.sidebar.toast.deleteFailed")):H.error(e("settings.agents.sidebar.toast.resetFailed")),u(!1)},C=_=>{const ee=_.name;let z=1,ne=`${ee}-copy`;for(;v.some(de=>de.name===ne);)z++,ne=`${ee}-copy-${z}`;const re=_,ue=_.model?.providerID&&_.model?.modelID?`${_.model.providerID}/${_.model.modelID}`:null,Q=_;g({name:ne,scope:re.scope||"user",description:_.description,model:ue,temperature:_.temperature,top_p:_.topP,prompt:_.prompt,mode:_.mode,permission:Wm(_.permission),disable:Q.disable}),x(ne)},N=_=>{i(_.name),r(_)},T=async()=>{if(!n)return;const _=a.trim().replace(/\s+/g,"-");if(!_){H.error(e("settings.agents.sidebar.toast.agentNameRequired"));return}if(_===n.name){r(null);return}if(v.some(re=>re.name===_)){H.error(e("settings.agents.sidebar.toast.agentExists"));return}const ee=n.model?.providerID&&n.model?.modelID?`${n.model.providerID}/${n.model.modelID}`:null,z=n;await w({name:_,description:n.description,model:ee,temperature:n.temperature,top_p:n.topP,prompt:n.prompt,mode:n.mode,permission:Wm(n.permission),disable:z.disable,scope:z.scope})?await y(n.name)?(H.success(`Agent renamed to "${_}"`),x(_)):H.error(e("settings.agents.sidebar.toast.removeOldAfterRenameFailed")):H.error(e("settings.agents.sidebar.toast.renameFailed")),r(null)},M=_=>{switch(_){case"primary":return s.jsx(I,{name:"ai-agent",className:"h-3 w-3 text-primary"});case"all":return s.jsx(I,{name:"ai-agent-fill",className:"h-3 w-3 text-primary"});case"subagent":return s.jsx(I,{name:"robot",className:"h-3 w-3 text-primary"});default:return null}},R=v.filter(_=>!yb(_)),L=R.filter(ei),$=R.filter(_=>!ei(_)),{groupedCustomAgents:B,ungroupedCustomAgents:O}=Be.useMemo(()=>{const _={},ee=[];for(const ne of $){const re=ne;re.group?(_[re.group]||(_[re.group]=[]),_[re.group].push(ne)):ee.push(ne)}return{groupedCustomAgents:Object.keys(_).sort((ne,re)=>ne.localeCompare(re)).map(ne=>({name:ne,agents:_[ne]})),ungroupedCustomAgents:ee}},[$]);return s.jsxs("div",{className:me("flex h-full flex-col",D),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(io,{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(we,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:j,children:s.jsx(I,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(Ts,{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(I,{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:[L.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")}),L.map(_=>s.jsx(vc,{agent:_,isSelected:f===_.name,onSelect:()=>{x(_.name),t?.()},onReset:()=>A(_),onDuplicate:()=>C(_),getAgentModeIcon:M,isMenuOpen:h===_.name,onMenuOpenChange:ee=>b(ee?_.name:null)},_.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")}),B.map(({name:_,agents:ee})=>s.jsx(md,{label:_,count:ee.length,storageKey:"agents",children:ee.map(z=>s.jsx(vc,{agent:z,isSelected:f===z.name,onSelect:()=>{x(z.name),t?.()},onRename:()=>N(z),onDelete:()=>S(z),onDuplicate:()=>C(z),getAgentModeIcon:M,isMenuOpen:h===z.name,onMenuOpenChange:ne=>b(ne?z.name:null)},z.name))},_)),O.map(_=>s.jsx(vc,{agent:_,isSelected:f===_.name,onSelect:()=>{x(_.name),t?.()},onRename:()=>N(_),onDelete:()=>S(_),onDuplicate:()=>C(_),getAgentModeIcon:M,isMenuOpen:h===_.name,onMenuOpenChange:ee=>b(ee?_.name:null)},_.name))]})]})}),s.jsx(ws,{open:o!==null&&d!==null,onOpenChange:_=>{!_&&!m&&E()},children:s.jsxs(vs,{className:"max-w-md",children:[s.jsxs(Cs,{children:[s.jsx(js,{children:e(d==="delete"?"settings.agents.sidebar.dialog.deleteTitle":"settings.agents.sidebar.dialog.resetTitle")}),s.jsx(Rs,{children:d==="delete"?e("settings.agents.sidebar.dialog.deleteDescription",{name:o?.name??""}):e("settings.agents.sidebar.dialog.resetDescription",{name:o?.name??""})})]}),s.jsxs(Ks,{children:[s.jsx(we,{size:"sm",variant:"ghost",onClick:E,disabled:m,children:e("settings.common.actions.cancel")}),s.jsx(we,{size:"sm",onClick:P,disabled:m,children:e(d==="delete"?"settings.common.actions.delete":"settings.common.actions.reset")})]})]})}),s.jsx(ws,{open:n!==null,onOpenChange:_=>!_&&r(null),children:s.jsxs(vs,{children:[s.jsxs(Cs,{children:[s.jsx(js,{children:e("settings.agents.sidebar.renameDialog.title")}),s.jsx(Rs,{children:e("settings.agents.sidebar.renameDialog.description",{name:n?.name??""})})]}),s.jsx(Kt,{value:a,onChange:_=>i(_.target.value),placeholder:e("settings.agents.sidebar.renameDialog.placeholder"),className:"text-foreground placeholder:text-muted-foreground",onKeyDown:_=>{_.key==="Enter"&&T()}}),s.jsxs(Ks,{children:[s.jsx(we,{size:"sm",variant:"ghost",onClick:()=>r(null),children:e("settings.common.actions.cancel")}),s.jsx(we,{size:"sm",onClick:T,children:e("settings.common.actions.rename")})]})]})})]})},vc=t=>{const e=at.c(58),{agent:n,isSelected:r,onSelect:a,onDelete:i,onReset:o,onRename:c,onDuplicate:d,getAgentModeIcon:p,isMenuOpen:m,onMenuOpenChange:u}=t,{t:h}=pt(),b=n;let f;e[0]===Symbol.for("react.memo_cache_sentinel")?(f=Ki(),e[0]=f):f=e[0];const v=f,x=r?"bg-interactive-selection":"hover:bg-interactive-hover";let g;e[1]!==x?(g=me("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",x),e[1]=x,e[2]=g):g=e[2];let w;e[3]!==u?(w=v?void 0:ee=>{ee.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 k;e[7]!==n.mode||e[8]!==p?(k=p(n.mode),e[7]=n.mode,e[8]=p,e[9]=k):k=e[9];let D;e[10]!==n||e[11]!==b.scope||e[12]!==h?(D=(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)?h("settings.agents.sidebar.badge.system"):b.scope}),e[10]=n,e[11]=b.scope,e[12]=h,e[13]=D):D=e[13];let j;e[14]!==y||e[15]!==k||e[16]!==D?(j=s.jsxs("div",{className:"flex items-center gap-1.5",children:[y,k,D]}),e[14]=y,e[15]=k,e[16]=D,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 A;e[20]!==a||e[21]!==j||e[22]!==S?(A=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]=A):A=e[23];let E;e[24]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx(Os,{asChild:!0,children:s.jsx(we,{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(I,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[24]=E):E=e[24];let P;e[25]!==c||e[26]!==h?(P=c&&s.jsxs(zt,{onClick:ee=>{ee.stopPropagation(),c()},children:[s.jsx(I,{name:"edit",className:"h-4 w-4 mr-px"}),h("settings.common.actions.rename")]}),e[25]=c,e[26]=h,e[27]=P):P=e[27];let C;e[28]!==d?(C=ee=>{ee.stopPropagation(),d()},e[28]=d,e[29]=C):C=e[29];let N;e[30]===Symbol.for("react.memo_cache_sentinel")?(N=s.jsx(I,{name:"file-copy",className:"h-4 w-4 mr-px"}),e[30]=N):N=e[30];let T;e[31]!==h?(T=h("settings.common.actions.duplicate"),e[31]=h,e[32]=T):T=e[32];let M;e[33]!==C||e[34]!==T?(M=s.jsxs(zt,{onClick:C,children:[N,T]}),e[33]=C,e[34]=T,e[35]=M):M=e[35];let R;e[36]!==o||e[37]!==h?(R=o&&s.jsxs(zt,{onClick:ee=>{ee.stopPropagation(),o()},children:[s.jsx(I,{name:"restart",className:"h-4 w-4 mr-px"}),h("settings.common.actions.reset")]}),e[36]=o,e[37]=h,e[38]=R):R=e[38];let L;e[39]!==i||e[40]!==h?(L=i&&s.jsxs(zt,{onClick:ee=>{ee.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"delete-bin",className:"h-4 w-4 mr-px"}),h("settings.common.actions.delete")]}),e[39]=i,e[40]=h,e[41]=L):L=e[41];let $;e[42]!==P||e[43]!==M||e[44]!==R||e[45]!==L?($=s.jsxs($s,{align:"end",className:"w-fit min-w-20",children:[P,M,R,L]}),e[42]=P,e[43]=M,e[44]=R,e[45]=L,e[46]=$):$=e[46];let B;e[47]!==m||e[48]!==u||e[49]!==$?(B=s.jsxs(Bs,{open:m,onOpenChange:u,children:[E,$]}),e[47]=m,e[48]=u,e[49]=$,e[50]=B):B=e[50];let O;e[51]!==A||e[52]!==B?(O=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[A,B]}),e[51]=A,e[52]=B,e[53]=O):O=e[53];let _;return e[54]!==O||e[55]!==g||e[56]!==w?(_=s.jsx("div",{className:g,onContextMenu:w,children:O}),e[54]=O,e[55]=g,e[56]=w,e[57]=_):_=e[57],_};function Km(t,e,n){return Math.min(n,Math.max(e,t))}function CS(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 Hm(t,e){const n=CS(e);return n<=0?t:Number(t.toFixed(n))}const xn=Be.forwardRef((t,e)=>{const n=at.c(125);let r,a,i,o,c,d,p,m,u,h,b,f,v;n[0]!==t?({value:v,onValueChange:p,min:u,max:h,step:b,className:r,containerClassName:a,onBlur:c,disabled:i,fallbackValue:o,onClear:d,emptyLabel:f,...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]=h,n[11]=b,n[12]=f,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],h=n[10],b=n[11],f=n[12],v=n[13]);const x=u===void 0?-1/0:u,g=h===void 0?1/0:h,w=b===void 0?1:b,y=f===void 0?"—":f,{t:k}=pt();let D;n[14]!==v?(D=()=>v===void 0?"":String(v),n[14]=v,n[15]=D):D=n[15];const[j,S]=Be.useState(D),{isMobile:A}=an(),E=Be.useRef(!1),P=Be.useRef(null);let C;n[16]===Symbol.for("react.memo_cache_sentinel")?(C=()=>{if(typeof document>"u"||typeof window>"u")return;P.current?.();const ke=Ee=>{Ee.preventDefault(),Ee.stopPropagation(),Ee.stopImmediatePropagation?.(),P.current?.()},be=window.setTimeout(()=>{P.current?.()},700),pe=()=>{window.clearTimeout(be),document.removeEventListener("click",ke,!0),P.current=null};P.current=pe,document.addEventListener("click",ke,!0)},n[16]=C):C=n[16];const N=C;let T,M;n[17]===Symbol.for("react.memo_cache_sentinel")?(T=()=>()=>{P.current?.()},M=[],n[17]=T,n[18]=M):(T=n[17],M=n[18]),Be.useEffect(T,M);let R,L;n[19]!==v?(L=()=>{S(v===void 0?"":String(v))},R=[v],n[19]=v,n[20]=R,n[21]=L):(R=n[20],L=n[21]),Be.useEffect(L,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 B=$;let O;n[22]!==g||n[23]!==x||n[24]!==p||n[25]!==w?(O=ke=>{const be=Km(ke,x,g);p(Hm(be,w))},n[22]=g,n[23]=x,n[24]=p,n[25]=w,n[26]=O):O=n[26];const _=O;let ee;n[27]!==_||n[28]!==d?(ee=ke=>{const be=ke.target.value;if(S(be),be.trim()===""){d?.();return}const pe=Number(be);Number.isFinite(pe)&&_(pe)},n[27]=_,n[28]=d,n[29]=ee):ee=n[29];const z=ee;let ne;n[30]!==j||n[31]!==g||n[32]!==x||n[33]!==c||n[34]!==d||n[35]!==p||n[36]!==w||n[37]!==v?(ne=ke=>{if(j.trim()===""){d||S(v===void 0?"":String(v)),c?.(ke);return}const be=Number(j);if(!Number.isFinite(be))S(v===void 0?"":String(v));else{const pe=Km(be,x,g),Ee=Hm(pe,w);Ee!==v&&p(Ee),S(String(Ee))}c?.(ke)},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]=ne):ne=n[38];const re=ne,ue=!!(i||B>=g),Q=!!(i||B<=x);let de;n[39]!==B||n[40]!==_||n[41]!==Q||n[42]!==w?(de=()=>{Q||_(B-w)},n[39]=B,n[40]=_,n[41]=Q,n[42]=w,n[43]=de):de=n[43];const X=de;let F;n[44]!==B||n[45]!==_||n[46]!==ue||n[47]!==w?(F=()=>{ue||_(B+w)},n[44]=B,n[45]=_,n[46]=ue,n[47]=w,n[48]=F):F=n[48];const V=F;let q;if(n[49]!==r||n[50]!==a||n[51]!==Q||n[52]!==j||n[53]!==y||n[54]!==X||n[55]!==V||n[56]!==ue||n[57]!==A||n[58]!==k||n[59]!==v){q=Symbol.for("react.early_return_sentinel");e:{const ke=pe=>Ee=>{Ee.preventDefault(),Ee.stopPropagation(),E.current=!0,N(),pe()},be=pe=>Ee=>{if(E.current){E.current=!1,Ee.preventDefault(),Ee.stopPropagation();return}pe()};if(A){let pe;n[61]!==a?(pe=me("flex h-9 shrink-0 items-stretch overflow-x-hidden overflow-y-hidden rounded-lg border border-border bg-transparent select-none overscroll-contain","[-webkit-user-select:none] [-webkit-touch-callout:none]","disabled:pointer-events-none disabled:opacity-50",a),n[61]=a,n[62]=pe):pe=n[62];let Ee;n[63]!==k?(Ee=k("numberInput.actions.decreaseAria"),n[63]=k,n[64]=Ee):Ee=n[64];const ze=ke(X),G=be(X),Pe=!Q&&"active:bg-interactive-hover";let Le;n[65]!==Pe?(Le=me("grid h-full min-h-0 w-9 place-items-center overflow-x-hidden overflow-y-hidden border-r border-border p-0 leading-none touch-none","text-muted-foreground","disabled:pointer-events-none disabled:opacity-50",Pe),n[65]=Pe,n[66]=Le):Le=n[66];let Ae;n[67]===Symbol.for("react.memo_cache_sentinel")?(Ae=s.jsx(I,{name:"subtract",className:"block h-4 w-4"}),n[67]=Ae):Ae=n[67];const ge=s.jsx("button",{type:"button","aria-label":Ee,disabled:Q,onTouchStart:ze,onClick:G,className:Le,children:Ae});let W;n[68]!==r?(W=me("flex h-full min-w-0 w-14 items-center justify-center bg-transparent px-1.5","text-center text-[16px] leading-none text-foreground [font-variant-numeric:tabular-nums]",r),n[68]=r,n[69]=W):W=n[69];const ie=v===void 0?y:j;let Me;n[70]!==W||n[71]!==ie?(Me=s.jsx("div",{className:W,"aria-live":"polite",children:ie}),n[70]=W,n[71]=ie,n[72]=Me):Me=n[72];let Ve;n[73]!==k?(Ve=k("numberInput.actions.increaseAria"),n[73]=k,n[74]=Ve):Ve=n[74];const Ce=ke(V),xe=be(V),De=!ue&&"active:bg-interactive-hover";let Ye;n[75]!==De?(Ye=me("grid h-full min-h-0 w-9 place-items-center overflow-x-hidden overflow-y-hidden border-l border-border p-0 leading-none touch-none","text-muted-foreground","disabled:pointer-events-none disabled:opacity-50",De),n[75]=De,n[76]=Ye):Ye=n[76];let rt;n[77]===Symbol.for("react.memo_cache_sentinel")?(rt=s.jsx(I,{name:"add",className:"block h-4 w-4"}),n[77]=rt):rt=n[77];const Re=s.jsx("button",{type:"button","aria-label":Ve,disabled:ue,onTouchStart:Ce,onClick:xe,className:Ye,children:rt});let he;n[78]!==pe||n[79]!==ge||n[80]!==Me||n[81]!==Re?(he=s.jsxs("div",{className:pe,children:[ge,Me,Re]}),n[78]=pe,n[79]=ge,n[80]=Me,n[81]=Re,n[82]=he):he=n[82],q=he;break e}}n[49]=r,n[50]=a,n[51]=Q,n[52]=j,n[53]=y,n[54]=X,n[55]=V,n[56]=ue,n[57]=A,n[58]=k,n[59]=v,n[60]=q}else q=n[60];if(q!==Symbol.for("react.early_return_sentinel"))return q;let te;n[83]!==a?(te=me("flex h-7 shrink-0 items-stretch overflow-x-hidden overflow-y-hidden rounded-lg border border-border bg-transparent","disabled:pointer-events-none disabled:opacity-50",a),n[83]=a,n[84]=te):te=n[84];let U;n[85]!==k?(U=k("numberInput.actions.decreaseAria"),n[85]=k,n[86]=U):U=n[86];let ae;n[87]!==B||n[88]!==_||n[89]!==w?(ae=()=>_(B-w),n[87]=B,n[88]=_,n[89]=w,n[90]=ae):ae=n[90];let je,oe;n[91]===Symbol.for("react.memo_cache_sentinel")?(je=me("flex h-full w-7 items-center justify-center overflow-x-hidden overflow-y-hidden border-r border-border p-0 leading-none touch-manipulation","text-muted-foreground hover:bg-interactive-hover hover:text-foreground","disabled:pointer-events-none disabled:opacity-50"),oe=s.jsx(I,{name:"subtract",className:"block h-3.5 w-3.5"}),n[91]=je,n[92]=oe):(je=n[91],oe=n[92]);let ve;n[93]!==Q||n[94]!==U||n[95]!==ae?(ve=s.jsx("button",{type:"button","aria-label":U,disabled:Q,onClick:ae,className:je,children:oe}),n[93]=Q,n[94]=U,n[95]=ae,n[96]=ve):ve=n[96];const K=m.inputMode??"numeric";let ce;n[97]!==r?(ce=me("h-full min-w-0 w-14 bg-transparent px-1.5 text-center typography-ui-label leading-none text-foreground [font-variant-numeric:tabular-nums]","placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground","appearance-none outline-none [appearance:textfield] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden","disabled:pointer-events-none disabled:cursor-not-allowed",r),n[97]=r,n[98]=ce):ce=n[98];let Z;n[99]!==i||n[100]!==j||n[101]!==re||n[102]!==z||n[103]!==m||n[104]!==e||n[105]!==K||n[106]!==ce?(Z=s.jsx("input",{...m,ref:e,type:"text",inputMode:K,value:j,onChange:z,onBlur:re,disabled:i,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",className:ce}),n[99]=i,n[100]=j,n[101]=re,n[102]=z,n[103]=m,n[104]=e,n[105]=K,n[106]=ce,n[107]=Z):Z=n[107];let le;n[108]!==k?(le=k("numberInput.actions.increaseAria"),n[108]=k,n[109]=le):le=n[109];let se;n[110]!==B||n[111]!==_||n[112]!==w?(se=()=>_(B+w),n[110]=B,n[111]=_,n[112]=w,n[113]=se):se=n[113];let Ie,Ne;n[114]===Symbol.for("react.memo_cache_sentinel")?(Ie=me("flex h-full w-7 items-center justify-center overflow-x-hidden overflow-y-hidden border-l border-border p-0 leading-none touch-manipulation","text-muted-foreground hover:bg-interactive-hover hover:text-foreground","disabled:pointer-events-none disabled:opacity-50"),Ne=s.jsx(I,{name:"add",className:"block h-3.5 w-3.5"}),n[114]=Ie,n[115]=Ne):(Ie=n[114],Ne=n[115]);let Y;n[116]!==ue||n[117]!==le||n[118]!==se?(Y=s.jsx("button",{type:"button","aria-label":le,disabled:ue,onClick:se,className:Ie,children:Ne}),n[116]=ue,n[117]=le,n[118]=se,n[119]=Y):Y=n[119];let fe;return n[120]!==te||n[121]!==ve||n[122]!==Z||n[123]!==Y?(fe=s.jsxs("div",{className:te,children:[ve,Z,Y]}),n[120]=te,n[121]=ve,n[122]=Z,n[123]=Y,n[124]=fe):fe=n[124],fe});xn.displayName="NumberInput";const Gm=["*","read","edit","glob","grep","list","bash","task","skill","lsp","todoread","todowrite","webfetch","websearch","codesearch","external_directory","doom_loop","question","plan_enter","plan_exit"],Ko=t=>t==="allow"||t==="ask"||t==="deny",ya=(t,e)=>`${t}::${e}`,Ra=t=>{const e=new Map;for(const n of t)!n.permission||n.permission==="invalid"||n.pattern&&Ko(n.action)&&e.set(ya(n.permission,n.pattern),{permission:n.permission,pattern:n.pattern,action:n.action});return Array.from(e.values())},ko=t=>{const e=new Map;for(const n of Ra(t))e.set(ya(n.permission,n.pattern),n);return e},qm=t=>[...t].sort((e,n)=>{const r=e.permission.localeCompare(n.permission);return r!==0?r:e.pattern.localeCompare(n.pattern)}),IS=(t,e)=>{const n=qm(Ra(t)),r=qm(Ra(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})},PS=t=>t.find(n=>n.permission==="*"&&n.pattern==="*")?.action??"allow",AS=(t,e)=>Ra(t).filter(n=>!(n.permission==="*"&&n.pattern==="*")).filter(n=>n.pattern!=="*"||n.action!==e),DS=t=>{if(Ko(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(Ko(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))Ko(i)&&e.push({permission:n,pattern:a,action:i})}return e},TS=(t,e)=>{const n=Ra(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},MS=()=>{const{t}=pt(),{isMobile:e}=an(),{selectedAgentName:n,getAgentByName:r,createAgent:a,updateAgent:i,agents:o,agentDraft:c,setAgentDraft:d}=oi(pr(pe=>({selectedAgentName:pe.selectedAgentName,getAgentByName:pe.getAgentByName,createAgent:pe.createAgent,updateAgent:pe.updateAgent,agents:pe.agents,agentDraft:pe.agentDraft,setAgentDraft:pe.setAgentDraft}))),p=n?r(n):null,m=!!(c&&c.name===n&&!p),[u,h]=l.useState(""),[b,f]=l.useState("user"),[v,x]=l.useState(""),[g,w]=l.useState("subagent"),[y,k]=l.useState(""),[D,j]=l.useState(void 0),[S,A]=l.useState(void 0),[E,P]=l.useState(""),[C,N]=l.useState("allow"),[T,M]=l.useState([]),[R,L]=l.useState([]),[$,B]=l.useState(""),[O,_]=l.useState("*"),[ee,z]=l.useState(!1),[ne,re]=l.useState(!1),ue=l.useRef(null),Q=Vs(pe=>pe.currentDirectory??null),[de,X]=l.useState([]),F=Vh(pe=>pe.permission);l.useEffect(()=>{let pe=!1;return(async()=>{const ze=await rn.listToolIds({directory:Q});if(pe)return;const G=new Set(["write","patch","multiedit"]),Pe=ze.map(Le=>typeof Le=="string"?Le.trim():"").filter(Boolean).filter(Le=>Le!=="*").filter(Le=>Le!=="invalid").filter(Le=>!G.has(Le));X(Array.from(new Set(Pe)).sort((Le,Ae)=>Le.localeCompare(Ae)))})(),()=>{pe=!0}},[Q]);const V=l.useMemo(()=>{const pe=new Set;for(const Ee of o){const ze=Ra(Array.isArray(Ee.permission)?Ee.permission:[]);for(const G of ze)G.permission&&G.permission!=="*"&&G.permission!=="invalid"&&pe.add(G.permission)}for(const Ee of Object.values(F))for(const ze of Ee){const G=ze.permission?.trim();G&&G!=="invalid"&&pe.add(G)}for(const Ee of de)pe.add(Ee);return Array.from(pe).sort((Ee,ze)=>Ee.localeCompare(ze))},[o,F,de]),q=l.useMemo(()=>ko(T),[T]),te=l.useMemo(()=>ko(R),[R]),U=l.useCallback(pe=>te.get(ya(pe,"*"))?.action,[te]),ae=l.useCallback(pe=>R.filter(Ee=>Ee.permission===pe&&Ee.pattern!=="*").sort((Ee,ze)=>Ee.pattern.localeCompare(ze.pattern)),[R]),je=l.useMemo(()=>{const pe=new Set;for(const Ee of Gm)pe.add(Ee);for(const Ee of V)pe.add(Ee);return Array.from(pe).sort((Ee,ze)=>Ee.localeCompare(ze))},[V]),oe=l.useCallback(pe=>{const Ee=pe==="*"?C:U(pe)??C,ze=ae(pe),G=!1,Pe=ze.reduce((Ae,ge)=>(Ae[ge.action]=(Ae[ge.action]??0)+1,Ae),{allow:0,ask:0,deny:0}),Le=["allow","ask","deny"].filter(Ae=>Pe[Ae]>0).map(Ae=>`${Pe[Ae]} ${Ae}`).join(", ");return{defaultAction:Ee,patternRulesCount:ze.length,patternSummary:Le,hasDefaultHint:G}},[ae,U,C]),ve=l.useCallback(pe=>t(pe==="allow"?"settings.common.permission.allow":pe==="deny"?"settings.common.permission.deny":"settings.common.permission.ask"),[t]),K=l.useCallback(pe=>pe==="global"?t("settings.common.scope.global"):ve(pe),[ve,t]),ce=l.useMemo(()=>{const pe=new Set;for(const Ee of Gm)pe.add(Ee);for(const Ee of V)pe.add(Ee);return Array.from(pe).sort((Ee,ze)=>Ee.localeCompare(ze))},[V]),Z=l.useCallback((pe,Ee,ze)=>{L(G=>{const Pe=ko(G);return Pe.set(ya(pe,Ee),{permission:pe,pattern:Ee,action:ze}),Array.from(Pe.values())})},[]),le=l.useCallback((pe,Ee)=>{L(ze=>{const G=ko(ze);return G.delete(ya(pe,Ee)),Array.from(G.values())})},[]),se=l.useCallback((pe,Ee)=>{const ze=q.get(ya(pe,Ee));if(ze){Z(pe,Ee,ze.action);return}le(pe,Ee)},[q,le,Z]),Ie=l.useCallback((pe,Ee,ze)=>{Z(pe,Ee,ze)},[Z]),Ne=l.useCallback(pe=>{N(pe),L(Ee=>Ee.filter(ze=>!(ze.pattern==="*"&&ze.action===pe)))},[]),Y=l.useCallback(pe=>{const Ee=$.trim();if(!Ee){H.error(t("settings.agents.page.toast.permissionNameRequired"));return}const ze=O.trim()||"*";if(Ee==="*"&&ze==="*"){Ne(pe),B(""),_("*");return}ze==="*"&&Ee!=="*"&&pe===C?le(Ee,"*"):Z(Ee,ze,pe),B(""),_("*")},[C,$,O,le,Ne,t,Z]),fe=l.useCallback(pe=>pe==="*"?t("settings.agents.page.permissions.defaultLabel"):pe==="webfetch"?"WebFetch":pe==="websearch"?"WebSearch":pe==="codesearch"?"CodeSearch":pe==="doom_loop"?"Doom Loop":pe==="external_directory"?"External Directory":pe==="todowrite"?"TodoWrite":pe==="todoread"?"TodoRead":pe.split(/[_-]+/g).filter(Boolean).map(Ee=>Ee.charAt(0).toUpperCase()+Ee.slice(1)).join(" "),[t]);l.useEffect(()=>{B(""),_("*");const pe=Ee=>{const ze=Ra(Ee),G=PS(ze),Pe=AS(ze,G);return N(G),M(Pe),L(Pe),{global:G,rules:Pe}};if(m&&c){const Ee=c.name||"",ze=c.scope||"user",G=c.description||"",Pe=c.mode||"subagent",Le=c.model||"",Ae=c.temperature,ge=c.top_p,W=c.prompt||"";h(Ee),f(ze),x(G),w(Pe),k(Le),j(Ae),A(ge),P(W);const ie=DS(c.permission),Me=pe(ie);ue.current={draftName:Ee,draftScope:ze,description:G,mode:Pe,model:Le,temperature:Ae,topP:ge,prompt:W,globalPermission:Me.global,permissionRules:Me.rules};return}if(p&&n===p.name){const Ee=p.description||"",ze=p.mode||"subagent",G=p.model?.providerID&&p.model?.modelID?`${p.model.providerID}/${p.model.modelID}`:"",Pe=p.temperature,Le=p.topP,Ae=p.prompt||"";x(Ee),w(ze),k(G),j(Pe),A(Le),P(Ae);const ge=pe(Array.isArray(p.permission)?p.permission:[]);ue.current={draftName:"",draftScope:"user",description:Ee,mode:ze,model:G,temperature:Pe,topP:Le,prompt:Ae,globalPermission:ge.global,permissionRules:ge.rules}}},[c,m,p,n]);const ke=l.useMemo(()=>{const pe=ue.current;return pe?!!(m&&(u!==pe.draftName||b!==pe.draftScope)||v!==pe.description||g!==pe.mode||y!==pe.model||D!==pe.temperature||S!==pe.topP||E!==pe.prompt||C!==pe.globalPermission||!IS(R,pe.permissionRules)):!1},[v,u,b,C,m,g,y,R,E,D,S]),be=async()=>{const pe=m?u.trim().replace(/\s+/g,"-"):n?.trim();if(!pe){H.error(t("settings.agents.sidebar.toast.agentNameRequired"));return}if(m&&o.some(Ee=>Ee.name===pe)){H.error(t("settings.agents.sidebar.toast.agentExists"));return}re(!0);try{const Ee=y.trim(),ze=TS(C,R),G={name:pe,description:v.trim()||void 0,mode:g,model:Ee===""?null:Ee,temperature:D,top_p:S,prompt:E.trim()||void 0,permission:ze,scope:m?b:void 0};let Pe;m?(Pe=await a(G),Pe&&d(null)):Pe=await i(pe,G),Pe?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(Ee){console.error("Error saving agent:",Ee);const ze=Ee instanceof Error&&Ee.message?Ee.message:t("settings.agents.page.toast.saveUnexpectedError");H.error(ze)}finally{re(!1)}};return n?s.jsx(Ts,{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(Kt,{value:u,onChange:pe=>h(pe.target.value),placeholder:t("settings.agents.page.field.agentNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(ds,{value:b,onValueChange:pe=>f(pe),children:[s.jsx(us,{className:"w-fit min-w-[100px]",children:s.jsx(ys,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(ms,{align:"end",children:[s.jsx(Lt,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(I,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(Lt,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(I,{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(bn,{value:v,onChange:pe=>x(pe.target.value),placeholder:t("settings.agents.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})})]}),s.jsx("div",{className:"pb-1.5 pt-0.5",children:s.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.agents.page.field.mode")}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{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(we,{variant:"chip",size:"xs","aria-pressed":g==="primary",onClick:()=>w("primary"),className:"!font-normal",children:t("settings.agents.page.mode.primary")}),s.jsx(we,{variant:"chip",size:"xs","aria-pressed":g==="subagent",onClick:()=>w("subagent"),className:"!font-normal",children:t("settings.agents.page.mode.subagent")}),s.jsx(we,{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(ao,{providerId:ui(y)?.providerId??"",modelId:ui(y)?.modelId??"",onChange:(pe,Ee)=>{k(pe&&Ee?`${pe}/${Ee}`:"")}})})]}),s.jsxs("div",{className:me("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsxs("div",{className:me("flex min-w-0 flex-col",e?"w-full":"sm:w-56 shrink-0"),children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.agents.page.field.temperature")}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:t("settings.agents.page.field.temperatureTooltip")})]})]}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.agents.page.field.temperatureRange")})]}),s.jsxs("div",{className:me("flex items-center gap-2",e?"w-full":"w-fit"),children:[s.jsx(xn,{value:D,fallbackValue:.7,onValueChange:j,onClear:()=>j(void 0),min:0,max:2,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),D!==void 0&&s.jsx(we,{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(I,{name:"close",className:"h-3.5 w-3.5"})})]})]}),s.jsxs("div",{className:me("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsxs("div",{className:me("flex min-w-0 flex-col",e?"w-full":"sm:w-56 shrink-0"),children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.agents.page.field.topP")}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:t("settings.agents.page.field.topPTooltip")})]})]}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.agents.page.field.topPRange")})]}),s.jsxs("div",{className:me("flex items-center gap-2",e?"w-full":"w-fit"),children:[s.jsx(xn,{value:S,fallbackValue:.9,onValueChange:A,onClear:()=>A(void 0),min:0,max:1,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),S!==void 0&&s.jsx(we,{size:"sm",type:"button",variant:"ghost",onClick:()=>A(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(I,{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(bn,{value:E,onChange:pe=>P(pe.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(we,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>z(pe=>!pe),children:t(ee?"settings.agents.page.permissions.hideEditor":"settings.agents.page.permissions.advancedEditor")})]}),ee?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(ds,{value:C,onValueChange:pe=>Ne(pe),children:[s.jsx(us,{className:"w-[100px]",children:s.jsx(ys,{children:ve(C)})}),s.jsxs(ms,{children:[s.jsx(Lt,{value:"allow",children:t("settings.common.permission.allow")}),s.jsx(Lt,{value:"ask",children:t("settings.common.permission.ask")}),s.jsx(Lt,{value:"deny",children:t("settings.common.permission.deny")})]})]})]}),s.jsx("div",{className:"space-y-4",children:je.filter(pe=>pe!=="*").map(pe=>{const Ee=fe(pe),{defaultAction:ze,patternRulesCount:G}=oe(pe),Pe=U(pe),Le=Pe??"global",Ae=ae(pe),ge=["allow","ask","deny"].filter(W=>W!==C);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:Ee}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono",children:pe})]}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:G>0?t("settings.agents.page.permissions.globalSummary",{summary:ze}):ze})]}),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:"*"}),Pe&&s.jsx(we,{size:"sm",variant:"ghost",onClick:()=>se(pe,"*"),className:"px-1.5 py-0 h-5",children:s.jsx(I,{name:"subtract",className:"h-3.5 w-3.5 text-muted-foreground hover:text-foreground"})})]}),s.jsxs(ds,{value:Le,onValueChange:W=>{if(W==="global"){le(pe,"*");return}Z(pe,"*",W)},children:[s.jsx(us,{className:"w-[90px]",children:s.jsx(ys,{children:K(Le)})}),s.jsxs(ms,{children:[s.jsx(Lt,{value:"global",children:t("settings.common.scope.global")}),ge.map(W=>s.jsx(Lt,{value:W,className:"capitalize",children:ve(W)},W))]})]})]}),Ae.map(W=>{const ie=ya(W.permission,W.pattern),Me=q.get(ie),Ve=!Me,Ce=!!(Me&&Me.action!==W.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:W.pattern}),Ve&&s.jsx("span",{className:"typography-micro text-[var(--status-success)]",children:t("settings.common.badge.new")}),Ce&&s.jsx("span",{className:"typography-micro text-[var(--status-warning)]",children:t("settings.common.badge.modified")}),(Ve||Ce)&&s.jsx(we,{size:"sm",variant:"ghost",onClick:()=>Ve?le(W.permission,W.pattern):se(W.permission,W.pattern),className:"px-1.5 py-0 h-5",children:s.jsx(I,{name:"subtract",className:"h-3.5 w-3.5 text-muted-foreground hover:text-foreground"})})]}),s.jsxs(ds,{value:W.action,onValueChange:xe=>Ie(W.permission,W.pattern,xe),children:[s.jsx(us,{className:"w-[90px]",children:s.jsx(ys,{children:ve(W.action)})}),s.jsxs(ms,{children:[s.jsx(Lt,{value:"allow",children:t("settings.common.permission.allow")}),s.jsx(Lt,{value:"ask",children:t("settings.common.permission.ask")}),s.jsx(Lt,{value:"deny",children:t("settings.common.permission.deny")})]})]})]},ie)})]})]},pe)})}),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(ds,{value:$,onValueChange:B,children:[s.jsx(us,{className:"w-full sm:w-[160px]",children:$?s.jsx("span",{className:"truncate",children:fe($)}):s.jsx("span",{className:"text-muted-foreground",children:t("settings.agents.page.permissions.permissionPlaceholder")})}),s.jsx(ms,{children:ce.map(pe=>s.jsx(Lt,{value:pe,children:s.jsx("div",{className:"flex items-center justify-between gap-2 w-full",children:s.jsx("span",{children:fe(pe)})})},pe))})]}),s.jsx(Kt,{value:O,onChange:pe=>_(pe.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(we,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Y("allow"),children:t("settings.common.permission.allow")}),s.jsx(we,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Y("ask"),children:t("settings.common.permission.ask")}),s.jsx(we,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Y("deny"),children:t("settings.common.permission.deny")})]})]})]})]}):s.jsx("section",{className:"px-2 pb-2 pt-0 space-y-0",children:je.map((pe,Ee)=>{const{defaultAction:ze,patternRulesCount:G,patternSummary:Pe,hasDefaultHint:Le}=oe(pe),Ae=fe(pe),ge=Le?`${ze} (env blocked)`:ze;return s.jsxs("div",{className:me("flex flex-col gap-1 py-1.5 sm:flex-row sm:items-center sm:justify-between sm:gap-8",Ee>0&&"border-t border-[var(--surface-subtle)]"),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:Ae}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono hidden sm:inline-block",children:pe})]}),s.jsxs("div",{className:"flex items-center gap-3",children:[G>0?s.jsx("span",{className:"typography-micro text-muted-foreground bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:t("settings.agents.page.permissions.globalSummary",{summary:ge})}):s.jsx("span",{className:me("typography-micro capitalize px-1.5 py-0.5 rounded",ge==="allow"?"text-[var(--status-success)] bg-[var(--status-success)]/10":ge==="deny"?"text-[var(--status-error)] bg-[var(--status-error)]/10":"text-[var(--status-warning)] bg-[var(--status-warning)]/10"),children:ge}),G>0&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:t("settings.agents.page.permissions.rulesSummary",{summary:Pe})})]})]},pe)})})]}),s.jsx("div",{className:"px-2 py-1",children:s.jsx(we,{onClick:be,disabled:ne||!ke,size:"xs",className:"!font-normal",children:t(ne?"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(I,{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")})]})})},ES="~/.config/opencode/AGENTS.md",Yf=async(t,e)=>{const n=await t.json().catch(()=>null);return typeof n?.error=="string"&&n.error.trim()?n.error:e},RS=t=>t.length>0&&!t.endsWith(`
155
- `)?`${t}
156
- `:t,Co={prompt:"",responseStyleEnabled:!1,responseStylePreset:"concise",responseStyleCustomInstructions:""},FS=(t,e)=>t==="custom"?e:wb(t),LS=t=>t==="custom"?"custom":zh(t)?t:"concise",Jm={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"},Qm=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 Yf(n,e))},OS=()=>{const{t}=pt(),[e,n]=l.useState(""),[r,a]=l.useState(Co.responseStyleEnabled),[i,o]=l.useState(Co.responseStylePreset),[c,d]=l.useState(Co.responseStyleCustomInstructions),[p,m]=l.useState(!0),[u,h]=l.useState(!1),[b,f]=l.useState(""),v=l.useRef(null);l.useEffect(()=>{const y=new AbortController;return(async()=>{try{const[D,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=Co;if(D.ok){const A=await D.json();S={...S,responseStyleEnabled:A.responseStyleEnabled===!0,responseStylePreset:LS(A.responseStylePreset),responseStyleCustomInstructions:typeof A.responseStyleCustomInstructions=="string"?A.responseStyleCustomInstructions:""},typeof A.globalBehaviorPrompt=="string"&&(S={...S,prompt:A.globalBehaviorPrompt})}if(!S.prompt.trim()&&j.ok){const A=await j.json();typeof A.content=="string"&&(S={...S,prompt:A.content})}n(S.prompt),a(S.responseStyleEnabled),o(S.responseStylePreset),d(S.responseStyleCustomInstructions),f(S.prompt),v.current={enabled:S.responseStyleEnabled,preset:S.responseStylePreset,custom:S.responseStyleCustomInstructions}}catch(D){D.name!=="AbortError"&&console.warn("Failed to load behavior settings:",D)}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 k={enabled:r,preset:i,custom:c},D=setTimeout(async()=>{try{await Qm({responseStyleEnabled:k.enabled,responseStylePreset:k.preset,responseStyleCustomInstructions:k.custom},t("settings.behavior.page.toast.saveFailed")),v.current=k}catch(j){const S=j instanceof Error?j.message:t("settings.behavior.page.toast.saveFailed");H.error(S)}},400);return()=>clearTimeout(D)},[r,i,c,p,t]);const x=FS(i,c),g=e!==b,w=async()=>{h(!0);try{const y=RS(e),k=await fetch("/api/behavior/agents-md",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({content:y})});if(!k.ok)throw new Error(await Yf(k,t("settings.behavior.page.toast.saveFailed")));await Qm({globalBehaviorPrompt:y},t("settings.behavior.page.toast.saveFailed")),n(y),f(y),H.success(t("settings.behavior.page.toast.saved"))}catch(y){console.error("Failed to save behavior:",y);const k=y instanceof Error?y.message:t("settings.behavior.page.toast.saveFailed");H.error(k)}finally{h(!1)}};return s.jsx(Ts,{outerClassName:"h-full",className:"w-full",children:s.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8 space-y-6",children:[s.jsx("div",{className:"space-y-1",children:s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground",children:t("settings.behavior.page.title")})}),s.jsxs("div",{children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.behavior.page.section.systemPrompt")}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{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:ES})})]})})]})]})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsx(bn,{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(we,{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(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:t("settings.behavior.page.responseStyle.tooltip")})]})]})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsxs("label",{className:"flex items-center gap-2 typography-ui-label text-foreground",children:[s.jsx(xs,{checked:r,onChange:a,disabled:p,ariaLabel:t("settings.behavior.page.responseStyle.enableAria")}),t("settings.behavior.page.responseStyle.enable")]}),s.jsxs(ds,{value:i,onValueChange:y=>o(y),disabled:p||!r,children:[s.jsx(us,{className:"w-full sm:w-56",size:"lg",children:s.jsx(ys,{children:y=>y==="custom"?t("settings.behavior.page.responseStyle.option.custom"):zh(y)?t(Jm[y]):null})}),s.jsxs(ms,{children:[vb.map(y=>s.jsx(Lt,{value:y,children:t(Jm[y])},y)),s.jsx(Lt,{value:"custom",children:t("settings.behavior.page.responseStyle.option.custom")})]})]}),s.jsx(bn,{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"})]})]})]})})},$S=t=>{const e=at.c(169),{onItemSelect:n}=t,{t:r}=pt(),[a,i]=l.useState(null),[o,c]=l.useState(""),[d,p]=l.useState(null),[m,u]=l.useState(null),[h,b]=l.useState(!1),[f,v]=l.useState(null),{selectedCommandName:x,commands:g,setSelectedCommand:w,setCommandDraft:y,createCommand:k,deleteCommand:D,loadCommands:j}=Od(pr(BS)),S=ea(_S),A=ea(VS);let E,P;e[0]!==j||e[1]!==A?(E=()=>{j(),A()},P=[j,A],e[0]=j,e[1]=A,e[2]=E,e[3]=P):(E=e[2],P=e[3]),l.useEffect(E,P);let C;e[4]!==S?(C=new Set(S.map(zS)),e[4]=S,e[5]=C):C=e[5];const N=C;let T;if(e[6]!==g||e[7]!==N){let _e;e[9]!==N?(_e=Ue=>!N.has(Ue.name),e[9]=N,e[10]=_e):_e=e[10],T=g.filter(_e),e[6]=g,e[7]=N,e[8]=T}else T=e[8];const M=T;let R,L;e[11]!==x||e[12]!==w||e[13]!==N?(R=()=>{x&&N.has(x)&&w(null)},L=[x,w,N],e[11]=x,e[12]=w,e[13]=N,e[14]=R,e[15]=L):(R=e[14],L=e[15]),l.useEffect(R,L);let $;e[16]!==g||e[17]!==n||e[18]!==y||e[19]!==w?($=()=>{let _e="new-command",Ue=1;for(;g.some(ot=>ot.name===_e);)_e=`new-command-${Ue}`,Ue++;y({name:_e,scope:"user"}),w(_e),n?.()},e[16]=g,e[17]=n,e[18]=y,e[19]=w,e[20]=$):$=e[20];const B=$;let O;e[21]!==r?(O=async _e=>{if(ti(_e)){H.error(r("settings.commands.sidebar.toast.builtInCannotDelete"));return}p(_e),u("delete")},e[21]=r,e[22]=O):O=e[22];const _=O;let ee;e[23]===Symbol.for("react.memo_cache_sentinel")?(ee=async _e=>{ti(_e)&&(p(_e),u("reset"))},e[23]=ee):ee=e[23];const z=ee;let ne;e[24]===Symbol.for("react.memo_cache_sentinel")?(ne=()=>{p(null),u(null)},e[24]=ne):ne=e[24];const re=ne;let ue;e[25]!==d||e[26]!==m||e[27]!==D||e[28]!==r?(ue=async()=>{if(!d||!m)return;b(!0),await D(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})),re()):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]=D,e[28]=r,e[29]=ue):ue=e[29];const Q=ue;let de;e[30]!==g||e[31]!==y||e[32]!==w?(de=_e=>{const Ue=_e.name;let ot=1,Xe=`${Ue}-copy`;for(;g.some(We=>We.name===Xe);)ot++,Xe=`${Ue}-copy-${ot}`;y({name:Xe,scope:_e.scope||"user",description:_e.description,template:_e.template,agent:_e.agent,model:_e.model}),w(Xe)},e[30]=g,e[31]=y,e[32]=w,e[33]=de):de=e[33];const X=de;let F;e[34]===Symbol.for("react.memo_cache_sentinel")?(F=_e=>{c(_e.name),i(_e)},e[34]=F):F=e[34];const V=F;let q;e[35]!==g||e[36]!==k||e[37]!==D||e[38]!==a||e[39]!==o||e[40]!==w||e[41]!==r?(q=async()=>{if(!a)return;const _e=o.trim().replace(/\s+/g,"-");if(!_e){H.error(r("settings.commands.sidebar.toast.commandNameRequired"));return}if(_e===a.name){i(null);return}if(g.some(ot=>ot.name===_e)){H.error(r("settings.commands.sidebar.toast.commandExists"));return}await k({name:_e,description:a.description,template:a.template,agent:a.agent,model:a.model})?await D(a.name)?(H.success(`Command renamed to "${_e}"`),w(_e)):H.error(r("settings.commands.sidebar.toast.removeOldAfterRenameFailed")):H.error(r("settings.commands.sidebar.toast.renameFailed")),i(null)},e[35]=g,e[36]=k,e[37]=D,e[38]=a,e[39]=o,e[40]=w,e[41]=r,e[42]=q):q=e[42];const te=q;let U,ae,je,oe,ve,K;if(e[43]!==M||e[44]!==B||e[45]!==_||e[46]!==X||e[47]!==n||e[48]!==f||e[49]!==x||e[50]!==w||e[51]!==r){const _e=M.filter(ti),Ue=M.filter(US);e[58]===Symbol.for("react.memo_cache_sentinel")?(ve=me("flex h-full flex-col","bg-background"),e[58]=ve):ve=e[58];let ot;e[59]!==r?(ot=r("settings.commands.sidebar.title"),e[59]=r,e[60]=ot):ot=e[60];let Xe;e[61]!==ot?(Xe=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:ot}),e[61]=ot,e[62]=Xe):Xe=e[62];let We;e[63]===Symbol.for("react.memo_cache_sentinel")?(We=s.jsx(io,{className:"mb-3"}),e[63]=We):We=e[63];let bt;e[64]!==M.length||e[65]!==r?(bt=r("settings.commands.sidebar.total",{count:M.length}),e[64]=M.length,e[65]=r,e[66]=bt):bt=e[66];let Dt;e[67]!==bt?(Dt=s.jsx("span",{className:"typography-meta text-muted-foreground",children:bt}),e[67]=bt,e[68]=Dt):Dt=e[68];let Ht;e[69]===Symbol.for("react.memo_cache_sentinel")?(Ht=s.jsx(I,{name:"add",className:"h-3.5 w-3.5"}),e[69]=Ht):Ht=e[69];let rs;e[70]!==B?(rs=s.jsx(we,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:B,children:Ht}),e[70]=B,e[71]=rs):rs=e[71];let jt;e[72]!==Dt||e[73]!==rs?(jt=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Dt,rs]}),e[72]=Dt,e[73]=rs,e[74]=jt):jt=e[74],e[75]!==Xe||e[76]!==jt?(K=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[Xe,We,jt]}),e[75]=Xe,e[76]=jt,e[77]=K):K=e[77],U=Ts,ae="flex-1 min-h-0",je="space-y-1 px-3 py-2",oe=M.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(I,{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:[_e.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:r("settings.commands.sidebar.section.builtIn")}),[..._e].sort(WS).map(St=>s.jsx(Ym,{command:St,isSelected:x===St.name,onSelect:()=>{w(St.name),n?.()},onReset:()=>z(St),onDuplicate:()=>X(St),isMenuOpen:f===St.name,onMenuOpenChange:ns=>v(ns?St.name:null)},St.name))]}),Ue.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")}),[...Ue].sort(KS).map(St=>s.jsx(Ym,{command:St,isSelected:x===St.name,onSelect:()=>{w(St.name),n?.()},onRename:()=>V(St),onDelete:()=>_(St),onDuplicate:()=>X(St),isMenuOpen:f===St.name,onMenuOpenChange:ns=>v(ns?St.name:null)},St.name))]})]}),e[43]=M,e[44]=B,e[45]=_,e[46]=X,e[47]=n,e[48]=f,e[49]=x,e[50]=w,e[51]=r,e[52]=U,e[53]=ae,e[54]=je,e[55]=oe,e[56]=ve,e[57]=K}else U=e[52],ae=e[53],je=e[54],oe=e[55],ve=e[56],K=e[57];let ce;e[78]!==U||e[79]!==ae||e[80]!==je||e[81]!==oe?(ce=s.jsx(U,{outerClassName:ae,className:je,children:oe}),e[78]=U,e[79]=ae,e[80]=je,e[81]=oe,e[82]=ce):ce=e[82];const Z=d!==null&&m!==null;let le;e[83]!==h?(le=_e=>{!_e&&!h&&re()},e[83]=h,e[84]=le):le=e[84];let se;e[85]!==m||e[86]!==r?(se=r(m==="delete"?"settings.commands.sidebar.dialog.deleteTitle":"settings.commands.sidebar.dialog.resetTitle"),e[85]=m,e[86]=r,e[87]=se):se=e[87];let Ie;e[88]!==se?(Ie=s.jsx(js,{children:se}),e[88]=se,e[89]=Ie):Ie=e[89];let Ne;e[90]!==d?.name||e[91]!==m||e[92]!==r?(Ne=m==="delete"?r("settings.commands.sidebar.dialog.deleteDescription",{name:d?.name??""}):r("settings.commands.sidebar.dialog.resetDescription",{name:d?.name??""}),e[90]=d?.name,e[91]=m,e[92]=r,e[93]=Ne):Ne=e[93];let Y;e[94]!==Ne?(Y=s.jsx(Rs,{children:Ne}),e[94]=Ne,e[95]=Y):Y=e[95];let fe;e[96]!==Ie||e[97]!==Y?(fe=s.jsxs(Cs,{children:[Ie,Y]}),e[96]=Ie,e[97]=Y,e[98]=fe):fe=e[98];let ke;e[99]!==r?(ke=r("settings.common.actions.cancel"),e[99]=r,e[100]=ke):ke=e[100];let be;e[101]!==h||e[102]!==ke?(be=s.jsx(we,{size:"sm",variant:"ghost",onClick:re,disabled:h,children:ke}),e[101]=h,e[102]=ke,e[103]=be):be=e[103];let pe;e[104]!==m||e[105]!==r?(pe=r(m==="delete"?"settings.common.actions.delete":"settings.common.actions.reset"),e[104]=m,e[105]=r,e[106]=pe):pe=e[106];let Ee;e[107]!==Q||e[108]!==h||e[109]!==pe?(Ee=s.jsx(we,{size:"sm",onClick:Q,disabled:h,children:pe}),e[107]=Q,e[108]=h,e[109]=pe,e[110]=Ee):Ee=e[110];let ze;e[111]!==be||e[112]!==Ee?(ze=s.jsxs(Ks,{children:[be,Ee]}),e[111]=be,e[112]=Ee,e[113]=ze):ze=e[113];let G;e[114]!==fe||e[115]!==ze?(G=s.jsxs(vs,{className:"max-w-md",children:[fe,ze]}),e[114]=fe,e[115]=ze,e[116]=G):G=e[116];let Pe;e[117]!==Z||e[118]!==le||e[119]!==G?(Pe=s.jsx(ws,{open:Z,onOpenChange:le,children:G}),e[117]=Z,e[118]=le,e[119]=G,e[120]=Pe):Pe=e[120];const Le=a!==null;let Ae;e[121]===Symbol.for("react.memo_cache_sentinel")?(Ae=_e=>!_e&&i(null),e[121]=Ae):Ae=e[121];let ge;e[122]!==r?(ge=r("settings.commands.sidebar.renameDialog.title"),e[122]=r,e[123]=ge):ge=e[123];let W;e[124]!==ge?(W=s.jsx(js,{children:ge}),e[124]=ge,e[125]=W):W=e[125];const ie=a?.name??"";let Me;e[126]!==r||e[127]!==ie?(Me=r("settings.commands.sidebar.renameDialog.description",{name:ie}),e[126]=r,e[127]=ie,e[128]=Me):Me=e[128];let Ve;e[129]!==Me?(Ve=s.jsx(Rs,{children:Me}),e[129]=Me,e[130]=Ve):Ve=e[130];let Ce;e[131]!==W||e[132]!==Ve?(Ce=s.jsxs(Cs,{children:[W,Ve]}),e[131]=W,e[132]=Ve,e[133]=Ce):Ce=e[133];let xe;e[134]===Symbol.for("react.memo_cache_sentinel")?(xe=_e=>c(_e.target.value),e[134]=xe):xe=e[134];let De;e[135]!==r?(De=r("settings.commands.sidebar.renameDialog.placeholder"),e[135]=r,e[136]=De):De=e[136];let Ye;e[137]!==te?(Ye=_e=>{_e.key==="Enter"&&te()},e[137]=te,e[138]=Ye):Ye=e[138];let rt;e[139]!==o||e[140]!==De||e[141]!==Ye?(rt=s.jsx(Kt,{value:o,onChange:xe,placeholder:De,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:Ye}),e[139]=o,e[140]=De,e[141]=Ye,e[142]=rt):rt=e[142];let Re;e[143]===Symbol.for("react.memo_cache_sentinel")?(Re=()=>i(null),e[143]=Re):Re=e[143];let he;e[144]!==r?(he=r("settings.common.actions.cancel"),e[144]=r,e[145]=he):he=e[145];let qe;e[146]!==he?(qe=s.jsx(we,{size:"sm",variant:"ghost",onClick:Re,children:he}),e[146]=he,e[147]=qe):qe=e[147];let et;e[148]!==r?(et=r("settings.common.actions.rename"),e[148]=r,e[149]=et):et=e[149];let Ke;e[150]!==te||e[151]!==et?(Ke=s.jsx(we,{size:"sm",onClick:te,children:et}),e[150]=te,e[151]=et,e[152]=Ke):Ke=e[152];let st;e[153]!==qe||e[154]!==Ke?(st=s.jsxs(Ks,{children:[qe,Ke]}),e[153]=qe,e[154]=Ke,e[155]=st):st=e[155];let nt;e[156]!==Ce||e[157]!==rt||e[158]!==st?(nt=s.jsxs(vs,{children:[Ce,rt,st]}),e[156]=Ce,e[157]=rt,e[158]=st,e[159]=nt):nt=e[159];let ye;e[160]!==Le||e[161]!==nt?(ye=s.jsx(ws,{open:Le,onOpenChange:Ae,children:nt}),e[160]=Le,e[161]=nt,e[162]=ye):ye=e[162];let Je;return e[163]!==ve||e[164]!==K||e[165]!==ce||e[166]!==Pe||e[167]!==ye?(Je=s.jsxs("div",{className:ve,children:[K,ce,Pe,ye]}),e[163]=ve,e[164]=K,e[165]=ce,e[166]=Pe,e[167]=ye,e[168]=Je):Je=e[168],Je},Ym=t=>{const e=at.c(53),{command:n,isSelected:r,onSelect:a,onDelete:i,onReset:o,onRename:c,onDuplicate:d,isMenuOpen:p,onMenuOpenChange:m}=t,{t:u}=pt();let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=Ki(),e[0]=h):h=e[0];const b=h,f=r?"bg-interactive-selection":"hover:bg-interactive-hover";let v;e[1]!==f?(v=me("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",f),e[1]=f,e[2]=v):v=e[2];let x;e[3]!==m?(x=b?void 0:B=>{B.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||ti(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:ti(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 k;e[13]!==n.description?(k=n.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n.description}),e[13]=n.description,e[14]=k):k=e[14];let D;e[15]!==a||e[16]!==y||e[17]!==k?(D=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,k]}),e[15]=a,e[16]=y,e[17]=k,e[18]=D):D=e[18];let j;e[19]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(Os,{asChild:!0,children:s.jsx(we,{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(I,{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(zt,{onClick:B=>{B.stopPropagation(),c()},children:[s.jsx(I,{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 A;e[23]!==d?(A=B=>{B.stopPropagation(),d()},e[23]=d,e[24]=A):A=e[24];let E;e[25]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx(I,{name:"file-copy",className:"h-4 w-4 mr-px"}),e[25]=E):E=e[25];let P;e[26]!==u?(P=u("settings.common.actions.duplicate"),e[26]=u,e[27]=P):P=e[27];let C;e[28]!==A||e[29]!==P?(C=s.jsxs(zt,{onClick:A,children:[E,P]}),e[28]=A,e[29]=P,e[30]=C):C=e[30];let N;e[31]!==o||e[32]!==u?(N=o&&s.jsxs(zt,{onClick:B=>{B.stopPropagation(),o()},children:[s.jsx(I,{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 T;e[34]!==i||e[35]!==u?(T=i&&s.jsxs(zt,{onClick:B=>{B.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"delete-bin",className:"h-4 w-4 mr-px"}),u("settings.common.actions.delete")]}),e[34]=i,e[35]=u,e[36]=T):T=e[36];let M;e[37]!==S||e[38]!==C||e[39]!==N||e[40]!==T?(M=s.jsxs($s,{align:"end",className:"w-fit min-w-20",children:[S,C,N,T]}),e[37]=S,e[38]=C,e[39]=N,e[40]=T,e[41]=M):M=e[41];let R;e[42]!==p||e[43]!==m||e[44]!==M?(R=s.jsxs(Bs,{open:p,onOpenChange:m,children:[j,M]}),e[42]=p,e[43]=m,e[44]=M,e[45]=R):R=e[45];let L;e[46]!==R||e[47]!==D?(L=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[D,R]}),e[46]=R,e[47]=D,e[48]=L):L=e[48];let $;return e[49]!==L||e[50]!==v||e[51]!==x?($=s.jsx("div",{className:v,onContextMenu:x,children:L}),e[49]=L,e[50]=v,e[51]=x,e[52]=$):$=e[52],$};function BS(t){return{selectedCommandName:t.selectedCommandName,commands:t.commands,setSelectedCommand:t.setSelectedCommand,setCommandDraft:t.setCommandDraft,createCommand:t.createCommand,deleteCommand:t.deleteCommand,loadCommands:t.loadCommands}}function _S(t){return t.skills}function VS(t){return t.loadSkills}function zS(t){return t.name}function US(t){return!ti(t)}function WS(t,e){return t.name.localeCompare(e.name)}function KS(t,e){return t.name.localeCompare(e.name)}const HS=()=>{const{t}=pt(),{selectedCommandName:e,getCommandByName:n,createCommand:r,updateCommand:a,commands:i,commandDraft:o,setCommandDraft:c}=Od(pr(C=>({selectedCommandName:C.selectedCommandName,getCommandByName:C.getCommandByName,createCommand:C.createCommand,updateCommand:C.updateCommand,commands:C.commands,commandDraft:C.commandDraft,setCommandDraft:C.setCommandDraft}))),d=e?n(e):null,p=!!(o&&o.name===e&&!d),[m,u]=l.useState(""),[h,b]=l.useState("user"),[f,v]=l.useState(""),[x,g]=l.useState(""),[w,y]=l.useState(""),[k,D]=l.useState(""),[j,S]=l.useState(!1),A=l.useRef(null);l.useEffect(()=>{if(p&&o){const C=o.name||"",N=o.scope||"user",T=o.description||"",M=o.agent||"",R=o.model||"",L=o.template||"";u(C),b(N),v(T),g(M),y(R),D(L),A.current={draftName:C,draftScope:N,description:T,agent:M,model:R,template:L}}else if(d){const C=d.description||"",N=d.agent||"",T=d.model||"",M=d.template||"";v(C),g(N),y(T),D(M),A.current={draftName:"",draftScope:"user",description:C,agent:N,model:T,template:M}}},[d,p,e,i,o]);const E=l.useMemo(()=>{const C=A.current;return C?!!(p&&(m!==C.draftName||h!==C.draftScope)||f!==C.description||x!==C.agent||w!==C.model||k!==C.template):!1},[x,f,m,h,p,w,k]),P=async()=>{const C=p?m.trim().replace(/\s+/g,"-"):e?.trim();if(!C){H.error(t("settings.commands.sidebar.toast.commandNameRequired"));return}if(!k.trim()){H.error(t("settings.commands.page.toast.templateRequired"));return}if(p&&i.some(N=>N.name===C)){H.error(t("settings.commands.sidebar.toast.commandExists"));return}S(!0);try{const N=x.trim(),T=w.trim(),M=k.trim(),R={name:C,description:f.trim()||void 0,agent:N===""?null:N,model:T===""?null:T,template:M,scope:p?h:void 0};let L;p?(L=await r(R),L&&c(null)):L=await a(C,R),L?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(Ts,{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(Kt,{value:m,onChange:C=>u(C.target.value),placeholder:t("settings.commands.page.field.commandNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(ds,{value:h,onValueChange:C=>b(C),children:[s.jsx(us,{className:"w-fit min-w-[100px]",children:s.jsx(ys,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(ms,{align:"end",children:[s.jsx(Lt,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(I,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(Lt,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(I,{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(bn,{value:f,onChange:C=>v(C.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(Tl,{agentName:x,onChange:C=>g(C)})})]}),s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.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(ao,{providerId:ui(w)?.providerId??"",modelId:ui(w)?.modelId??"",onChange:(C,N)=>{y(C&&N?`${C}/${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(bn,{value:k,onChange:C=>D(C.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(we,{onClick:P,disabled:j||!E,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(I,{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")})]})})},Xm=t=>{switch(t){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"idle"}},Zm=t=>{const e=at.c(5),{tone:n,enabled:r}=t;if(!r){let o;return e[0]===Symbol.for("react.memo_cache_sentinel")?(o=s.jsx("span",{className:"inline-block h-2 w-2 rounded-full bg-muted-foreground/30 flex-shrink-0"}),e[0]=o):o=e[0],o}let a;e[1]!==n?(a=me("inline-block h-2 w-2 rounded-full flex-shrink-0",{success:"bg-[var(--status-success)]",error:"bg-[var(--status-error)]",warning:"bg-[var(--status-warning)]",idle:"bg-muted-foreground/40"}[n]),e[1]=n,e[2]=a):a=e[2];let i;return e[3]!==a?(i=s.jsx("span",{className:a}),e[3]=a,e[4]=i):i=e[4],i},GS=t=>{const e=at.c(116),{onItemSelect:n}=t,{t:r}=pt(),{mcpServers:a,selectedMcpName:i,setSelectedMcp:o,setMcpDraft:c,loadMcpConfigs:d,deleteMcp:p}=Qi(pr(qS)),m=Vs(JS);let u;e[0]!==m?(u=ge=>ge.getStatusForDirectory(m??null),e[0]=m,e[1]=u):u=e[1];const h=Nn(u),b=Nn(QS),f=Nn(YS),[v,x]=l.useState(null),[g,w]=l.useState(!1),[y,k]=l.useState(null),[D,j]=l.useState(!1);let S;e[2]!==a?(S=a.filter(XS),e[2]=a,e[3]=S):S=e[3];const A=S;let E;e[4]!==a?(E=a.filter(ZS),e[4]=a,e[5]=E):E=e[5];const P=E;let C,N;e[6]!==d?(C=()=>{d()},N=[d],e[6]=d,e[7]=C,e[8]=N):(C=e[7],N=e[8]),l.useEffect(C,N);let T;e[9]!==m||e[10]!==f||e[11]!==D||e[12]!==b?(T=()=>{if(D)return;j(!0);const ge=new Promise(ek);Promise.all([b({directory:m,silent:!0}),ge]).then(()=>{const W=f(m);W&&H.error(W)}).finally(()=>{j(!1)})},e[9]=m,e[10]=f,e[11]=D,e[12]=b,e[13]=T):T=e[13];const M=T;let R;e[14]!==a||e[15]!==n||e[16]!==c||e[17]!==o?(R=()=>{let ge="new-mcp-server",W=1;for(;a.some(Me=>Me.name===ge);)ge=`new-mcp-server-${W}`,W++;c({name:ge,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),o(ge),n?.()},e[14]=a,e[15]=n,e[16]=c,e[17]=o,e[18]=R):R=e[18];const L=R;let $;e[19]!==p||e[20]!==v||e[21]!==r?($=async()=>{if(!v)return;w(!0);const ge=await p(v.name);ge.ok?ge.reloadFailed?H.warning(ge.message||`MCP server "${v.name}" deleted, but OpenCode reload failed`,{description:ge.warning||r("settings.mcp.sidebar.toast.refreshListIfStale")}):H.success(ge.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 B=$;let O;e[23]===Symbol.for("react.memo_cache_sentinel")?(O=me("flex h-full flex-col","bg-background"),e[23]=O):O=e[23];let _;e[24]!==r?(_=r("settings.mcp.sidebar.title"),e[24]=r,e[25]=_):_=e[25];let ee;e[26]!==_?(ee=s.jsx("h2",{className:"text-base font-semibold text-foreground",children:_}),e[26]=_,e[27]=ee):ee=e[27];let z;e[28]!==r?(z=r("settings.mcp.sidebar.actions.refreshStatusAria"),e[28]=r,e[29]=z):z=e[29];let ne;e[30]!==r?(ne=r("settings.mcp.sidebar.actions.refreshStatusTitle"),e[30]=r,e[31]=ne):ne=e[31];const re=D&&"animate-spin";let ue;e[32]!==re?(ue=me("h-4 w-4",re),e[32]=re,e[33]=ue):ue=e[33];let Q;e[34]!==ue?(Q=s.jsx(I,{name:"refresh",className:ue}),e[34]=ue,e[35]=Q):Q=e[35];let de;e[36]!==M||e[37]!==D||e[38]!==z||e[39]!==ne||e[40]!==Q?(de=s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",disabled:D,onClick:M,"aria-label":z,title:ne,children:Q}),e[36]=M,e[37]=D,e[38]=z,e[39]=ne,e[40]=Q,e[41]=de):de=e[41];let X;e[42]!==ee||e[43]!==de?(X=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[ee,de]}),e[42]=ee,e[43]=de,e[44]=X):X=e[44];let F;e[45]===Symbol.for("react.memo_cache_sentinel")?(F=s.jsx(io,{className:"mb-3"}),e[45]=F):F=e[45];let V;e[46]!==a.length||e[47]!==r?(V=r("settings.mcp.sidebar.total",{count:a.length}),e[46]=a.length,e[47]=r,e[48]=V):V=e[48];let q;e[49]!==V?(q=s.jsx("span",{className:"typography-meta text-muted-foreground",children:V}),e[49]=V,e[50]=q):q=e[50];let te;e[51]!==r?(te=r("settings.mcp.sidebar.actions.addServerTitle"),e[51]=r,e[52]=te):te=e[52];let U;e[53]===Symbol.for("react.memo_cache_sentinel")?(U=s.jsx(I,{name:"add",className:"h-3.5 w-3.5"}),e[53]=U):U=e[53];let ae;e[54]!==L||e[55]!==te?(ae=s.jsx(we,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:L,title:te,children:U}),e[54]=L,e[55]=te,e[56]=ae):ae=e[56];let je;e[57]!==q||e[58]!==ae?(je=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[q,ae]}),e[57]=q,e[58]=ae,e[59]=je):je=e[59];let oe;e[60]!==X||e[61]!==je?(oe=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[X,F,je]}),e[60]=X,e[61]=je,e[62]=oe):oe=e[62];let ve;e[63]!==a.length||e[64]!==h||e[65]!==n||e[66]!==y||e[67]!==A||e[68]!==i||e[69]!==c||e[70]!==o||e[71]!==r||e[72]!==P?(ve=s.jsx(Ts,{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(I,{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:[A.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")}),A.map(ge=>{const W=h[ge.name],ie=Xm(W?.status),Me=i===ge.name,Ve=Ki();return s.jsxs("div",{className:me("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",Me?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:Ve?void 0:Ce=>{Ce.preventDefault(),k(ge.name)},children:[s.jsxs("button",{onClick:()=>{o(ge.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(Zm,{tone:ie,enabled:ge.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:ge.name}),s.jsx("span",{title:ge.type==="local"?r("settings.mcp.sidebar.serverType.localTitle"):r("settings.mcp.sidebar.serverType.remoteTitle"),children:ge.type==="local"?s.jsx(I,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(I,{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:ge.type==="local"?ge.command?.join(" ")??"":ge.url??""})]}),s.jsxs(Bs,{open:y===ge.name,onOpenChange:Ce=>k(Ce?ge.name:null),children:[s.jsx(Os,{asChild:!0,children:s.jsx(we,{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(I,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx($s,{align:"end",className:"w-fit min-w-20",children:s.jsxs(zt,{onClick:Ce=>{Ce.stopPropagation(),x(ge)},className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"delete-bin",className:"h-4 w-4 mr-px"}),r("settings.common.actions.delete")]})})]})]},ge.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(ge=>{const W=h[ge.name],ie=Xm(W?.status),Me=i===ge.name,Ve=Ki();return s.jsxs("div",{className:me("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",Me?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:Ve?void 0:Ce=>{Ce.preventDefault(),k(ge.name)},children:[s.jsxs("button",{onClick:()=>{o(ge.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(Zm,{tone:ie,enabled:ge.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:ge.name}),s.jsx("span",{title:ge.type==="local"?r("settings.mcp.sidebar.serverType.localTitle"):r("settings.mcp.sidebar.serverType.remoteTitle"),children:ge.type==="local"?s.jsx(I,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(I,{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:ge.type==="local"?ge.command?.join(" ")??"":ge.url??""})]}),s.jsxs(Bs,{open:y===ge.name,onOpenChange:Ce=>k(Ce?ge.name:null),children:[s.jsx(Os,{asChild:!0,children:s.jsx(we,{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(I,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx($s,{align:"end",className:"w-fit min-w-20",children:s.jsxs(zt,{onClick:Ce=>{Ce.stopPropagation(),x(ge)},className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"delete-bin",className:"h-4 w-4 mr-px"}),r("settings.common.actions.delete")]})})]})]},ge.name)})]})]})}),e[63]=a.length,e[64]=h,e[65]=n,e[66]=y,e[67]=A,e[68]=i,e[69]=c,e[70]=o,e[71]=r,e[72]=P,e[73]=ve):ve=e[73];const K=v!==null;let ce;e[74]!==g?(ce=ge=>{!ge&&!g&&x(null)},e[74]=g,e[75]=ce):ce=e[75];let Z;e[76]!==r?(Z=r("settings.mcp.sidebar.deleteDialog.title"),e[76]=r,e[77]=Z):Z=e[77];let le;e[78]!==Z?(le=s.jsx(js,{children:Z}),e[78]=Z,e[79]=le):le=e[79];const se=v?.name||"";let Ie;e[80]!==r||e[81]!==se?(Ie=r("settings.mcp.sidebar.deleteDialog.descriptionPrefix",{name:se}),e[80]=r,e[81]=se,e[82]=Ie):Ie=e[82];let Ne;e[83]===Symbol.for("react.memo_cache_sentinel")?(Ne=s.jsx("code",{className:"text-foreground",children:"opencode.json"}),e[83]=Ne):Ne=e[83];let Y;e[84]!==Ie?(Y=s.jsxs(Rs,{children:[Ie," ",Ne,"."]}),e[84]=Ie,e[85]=Y):Y=e[85];let fe;e[86]!==le||e[87]!==Y?(fe=s.jsxs(Cs,{children:[le,Y]}),e[86]=le,e[87]=Y,e[88]=fe):fe=e[88];let ke;e[89]===Symbol.for("react.memo_cache_sentinel")?(ke=()=>x(null),e[89]=ke):ke=e[89];let be;e[90]!==r?(be=r("settings.common.actions.cancel"),e[90]=r,e[91]=be):be=e[91];let pe;e[92]!==g||e[93]!==be?(pe=s.jsx(we,{size:"sm",variant:"ghost",onClick:ke,disabled:g,children:be}),e[92]=g,e[93]=be,e[94]=pe):pe=e[94];let Ee;e[95]!==g||e[96]!==r?(Ee=r(g?"settings.mcp.sidebar.actions.deleting":"settings.common.actions.delete"),e[95]=g,e[96]=r,e[97]=Ee):Ee=e[97];let ze;e[98]!==B||e[99]!==g||e[100]!==Ee?(ze=s.jsx(we,{size:"sm",onClick:B,disabled:g,children:Ee}),e[98]=B,e[99]=g,e[100]=Ee,e[101]=ze):ze=e[101];let G;e[102]!==pe||e[103]!==ze?(G=s.jsxs(Ks,{children:[pe,ze]}),e[102]=pe,e[103]=ze,e[104]=G):G=e[104];let Pe;e[105]!==fe||e[106]!==G?(Pe=s.jsxs(vs,{className:"max-w-md",children:[fe,G]}),e[105]=fe,e[106]=G,e[107]=Pe):Pe=e[107];let Le;e[108]!==K||e[109]!==ce||e[110]!==Pe?(Le=s.jsx(ws,{open:K,onOpenChange:ce,children:Pe}),e[108]=K,e[109]=ce,e[110]=Pe,e[111]=Le):Le=e[111];let Ae;return e[112]!==oe||e[113]!==ve||e[114]!==Le?(Ae=s.jsxs("div",{className:O,children:[oe,ve,Le]}),e[112]=oe,e[113]=ve,e[114]=Le,e[115]=Ae):Ae=e[115],Ae};function qS(t){return{mcpServers:t.mcpServers,selectedMcpName:t.selectedMcpName,setSelectedMcp:t.setSelectedMcp,setMcpDraft:t.setMcpDraft,loadMcpConfigs:t.loadMcpConfigs,deleteMcp:t.deleteMcp}}function JS(t){return t.currentDirectory}function QS(t){return t.refresh}function YS(t){return t.getErrorForDirectory}function XS(t){return t.scope==="project"}function ZS(t){return t.scope!=="project"}function ek(t){return setTimeout(t,500)}function na(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Ii(t){return Array.isArray(t)&&t.every(e=>typeof e=="string")}function ma(t,e){return e!==void 0?{ok:!1,error:t,parsed:e}:{ok:!1,error:t}}function wc(t,e,n){const r=tk(n),a=typeof n.url=="string"?n.url.trim():"",i=ep(n,"env","environment"),o=ep(n,"headers"),c=sk(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():"",h=nk(n),b=rk(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:h,enabled:b}}function tk(t){const e=t.command,n=t.args;if(Ii(e)&&Ii(n))return[...e,...n];if(Ii(e))return e;if(typeof e=="string"&&e.trim()){const r=e.trim().split(/\s+/);return Ii(n)?[...r,...n]:r}return Ii(n)?n:[]}function ep(t,...e){for(const n of e){const r=t[n];if(!na(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 sk(t){if(t.oauth===!1||t.oauth===null||t.oauth===void 0||!na(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 nk(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 rk(t){return"disabled"in t&&t.disabled===!0?!1:"enabled"in t?!!t.enabled:!0}function ak(t){const e=t.mcpServers;if(na(e)){const r=Object.keys(e);if(r.length===1){const a=r[0],i=e[a];if(na(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"&&na(a)});if(n.length===1){const r=n[0],a=t[r];if(Xf(a))return{name:r,entry:a}}return null}function Xf(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 ma("No JSON content provided");n=JSON.parse(o)}catch(o){return ma(o instanceof Error?`Invalid JSON: ${o.message}`:"Invalid JSON")}if(!na(n))return ma("Expected a JSON object, not an array or primitive");const r=n,a=r.mcpServers;if(na(a)){const o=Object.keys(a);if(o.length===0)return ma("mcpServers object is empty",n);if(o.length>1)return ma("Paste one server at a time. Found "+o.length+" servers in mcpServers",n);const c=o[0],d=a[c];return na(d)?wc(c,jc(d),d):ma("Server entry is not a valid object",n)}const i=ak(r);if(i)return wc(i.name,jc(i.entry),i.entry);if(Xf(r)){const o=jc(r),c=typeof r.name=="string"&&r.name.trim()?r.name.trim():e?.fallbackName;return wc(c,o,r)}return ma("No recognizable MCP server configuration found in JSON",n)}function jc(t){return t.type==="remote"?"remote":t.type==="local"?"local":typeof t.url=="string"&&t.url.trim()?"remote":(Array.isArray(t.command)||typeof t.command=="string"||Array.isArray(t.args),"local")}function ok(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 Zf="/mcp/oauth/callback",lk=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}},eg=t=>{const e=ck(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}},Qd=t=>{const e=t.get("state");return typeof e!="string"?null:e.trim()||null},ck=t=>{if(typeof t!="string"||!t.trim())return null;const e=lk(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 dk(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 uk(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:eg(n.searchParams),stateKey:Qd(n.searchParams)}}catch{}return{code:e,context:null,stateKey:null}}const mk=({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=h=>{const b=h.split(`
159
- `).filter(f=>f.trim().length>0);e(b)},u=async()=>{try{const b=(await navigator.clipboard.readText()).trim(),f=b.includes(`
160
- `)?b.split(`
161
- `).filter(v=>v.trim()):dk(b);d(f.join(`
162
- `)),e(f),H.success(a(f.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(we,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:u,type:"button",title:n,children:[s.jsx(I,{name:"clipboard",className:"h-3 w-3"}),r]})}),s.jsx(bn,{value:c,onChange:h=>{d(h.target.value),m(h.target.value)},onBlur:()=>{const h=c.split(`
163
- `).map(b=>b.trimEnd()).join(`
164
- `);d(h),m(h)},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((h,b)=>s.jsxs("span",{className:"block",children:[s.jsxs("span",{className:"text-muted-foreground select-none mr-2",children:["[",b,"]"]}),h]},b))})})]})]})},pk=t=>t.toUpperCase().replace(/[^A-Z0-9_]/g,"_"),tp=({value:t,onChange:e,keyTransform:n=pk,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:h,hideValueTitle:b,showValueTitle:f,addVariable:v,plainTextWarning:x,removeVariableAria:g})=>{const[w,y]=l.useState(new Set),k=()=>e([...t,{key:"",value:""}]),D=P=>{e(t.filter((C,N)=>N!==P)),y(C=>{const N=new Set(C);return N.delete(P),N})},j=(P,C,N)=>{const T=[...t];T[P]={...T[P],[C]:N},e(T)},S=P=>{y(C=>{const N=new Set(C);return N.has(P)?N.delete(P):N.add(P),N})},A=async()=>{try{const P=await navigator.clipboard.readText(),C=[];for(const T of P.split(`
168
- `)){const M=T.trim();if(!M||M.startsWith("#"))continue;const R=M.indexOf("=");if(R===-1)continue;const L=M.slice(0,R).trim();let $=M.slice(R+1).trim();($.startsWith('"')&&$.endsWith('"')||$.startsWith("'")&&$.endsWith("'"))&&($=$.slice(1,-1)),L&&C.push({key:L,value:$})}if(C.length===0){H.error(c);return}const N=[...t];for(const T of C){const M=N.findIndex(R=>R.key===T.key);M!==-1?N[M]=T:N.push(T)}e(N),H.success(d(C.length))}catch{H.error(p)}},E=t.some(P=>P.value.length>0);return s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("span",{className:"typography-micro text-muted-foreground w-32 shrink-0",children:m}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:u})]}),s.jsxs(we,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:A,type:"button",title:o,children:[s.jsx(I,{name:"clipboard",className:"h-3 w-3"}),i]})]}),s.jsx("div",{className:"space-y-1.5",children:t.map((P,C)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Kt,{value:P.key,onChange:N=>j(C,"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(Kt,{type:w.has(C)?"text":"password",value:P.value,onChange:N=>j(C,"value",N.target.value),placeholder:h,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(C),className:"absolute right-2 text-muted-foreground/60 hover:text-muted-foreground",title:w.has(C)?b:f,children:w.has(C)?s.jsx(I,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"eye",className:"h-3.5 w-3.5"})})]}),s.jsx(we,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 shrink-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>D(C),"aria-label":g,children:s.jsx(I,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},C))}),s.jsxs(we,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:k,type:"button",children:[s.jsx(I,{name:"add",className:"h-3.5 w-3.5"}),v]}),E&&s.jsx("p",{className:"typography-micro text-muted-foreground/60",children:x})]})},sp=t=>{const e=at.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 h={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=me("typography-micro font-medium rounded-full px-2 py-0.5",h.text,h.bg);let f;e[5]!==a||e[6]!==n?(f=a(n),e[5]=a,e[6]=n,e[7]=f):f=e[7],d=s.jsxs("span",{className:b,children:["● ",f]});break e}c=me("typography-micro font-medium",h.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},hk=(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")}},fk=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)]"}},gk=(t,e,n,r)=>!!(t==="failed"||t==="needs_auth"||t==="needs_client_registration"||e||n||r),np=(t,e)=>{if(typeof window>"u")return null;const n=new URL(Zf,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()},xk=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")}},bk=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},Pi=async t=>{typeof t!="string"||!t.trim()||await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(t.trim())}`,{method:"DELETE"}).catch(()=>{})},Nc=(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},yk=(t,e)=>{const n=typeof e=="string"&&e.trim()?e.trim():"__global__";return`${t??"__none__"}::${n}`},vk=()=>{const{t}=pt(),e=l.useCallback((He,At)=>t(He,At),[t]),{selectedMcpName:n,mcpServers:r,mcpDraft:a,setMcpDraft:i,setSelectedMcp:o,getMcpByName:c,createMcp:d,updateMcp:p,deleteMcp:m}=Qi(pr(He=>({selectedMcpName:He.selectedMcpName,mcpServers:He.mcpServers,mcpDraft:He.mcpDraft,setMcpDraft:He.setMcpDraft,setSelectedMcp:He.setSelectedMcp,getMcpByName:He.getMcpByName,createMcp:He.createMcp,updateMcp:He.updateMcp,deleteMcp:He.deleteMcp}))),u=Vs(He=>He.currentDirectory),h=l.useMemo(()=>dn(),[]),b=Nn(He=>He.getStatusForDirectory(u??null)),f=Nn(He=>He.getDiagnosticForDirectory(u??null)),v=Nn(He=>He.refresh),x=Nn(He=>He.connect),g=Nn(He=>He.disconnect),w=Nn(He=>He.startAuth),y=Nn(He=>He.completeAuth),k=Nn(He=>He.clearAuth),D=Nn(He=>He.testConnection),j=n?c(n):null,S=!!(a&&a.name===n&&!j),[A,E]=l.useState(""),[P,C]=l.useState("user"),[N,T]=l.useState("local"),[M,R]=l.useState([]),[L,$]=l.useState(""),[B,O]=l.useState([]),[_,ee]=l.useState([]),[z,ne]=l.useState(!0),[re,ue]=l.useState(""),[Q,de]=l.useState(""),[X,F]=l.useState(""),[V,q]=l.useState(""),[te,U]=l.useState(""),[ae,je]=l.useState(!0),[oe,ve]=l.useState(!1),[K,ce]=l.useState(!1),[Z,le]=l.useState(!1),[se,Ie]=l.useState(!1),[Ne,Y]=l.useState(!1),[fe,ke]=l.useState(!1),[be,pe]=l.useState(!1),[Ee,ze]=l.useState(!1),[G,Pe]=l.useState(null),[Le,Ae]=l.useState(null),[ge,W]=l.useState(""),[ie,Me]=l.useState(!1),Ve=l.useRef(0),Ce=l.useRef(!1),[xe,De]=l.useState(!1),[Ye,rt]=l.useState(!1),[Re,he]=l.useState(""),[qe,et]=l.useState(null),Ke=l.useMemo(()=>yk(n,u),[u,n]),st=l.useRef(Ke),nt=l.useRef(null),ye=l.useCallback(()=>{Pe(null),Ae(null),W(""),Me(!1),Ve.current=0,ze(!1),Y(!1),ke(!1),Ce.current=!1},[]),Je=l.useCallback(()=>{he(""),et(null),rt(!0)},[]),_e=l.useCallback(async()=>{try{const He=await navigator.clipboard.readText();he(He),et(null)}catch{H.error(t("settings.mcp.page.toast.clipboardReadFailed"))}},[t]),Ue=l.useCallback(()=>{const He=ik(Re,{fallbackName:A});if(!He.ok){et(He.error);return}const Et=ok(He,{name:A,scope:P,type:N,command:M,url:L,environment:B,headers:_,oauthEnabled:z,oauthClientId:re,oauthClientSecret:Q,oauthScope:X,oauthRedirectUri:V,timeout:te,enabled:ae},{isNewServer:S});E(Et.name),T(Et.type),R(Et.command??[]),$(Et.url??""),O(Et.environment??[]),ee(Et.headers??[]),ne(Et.oauthEnabled??!1),ue(Et.oauthClientId??""),de(Et.oauthClientSecret??""),F(Et.oauthScope??""),q(Et.oauthRedirectUri??""),U(Et.timeout??""),je(Et.enabled??!0),rt(!1),he(""),et(null),H.success(t("settings.mcp.page.toast.configImported"))},[Re,A,P,N,M,L,B,_,z,re,Q,X,V,te,ae,S,t]);l.useEffect(()=>{if(S&&a){E(a.name),C(a.scope||"user"),T(a.type),R(a.command),$(a.url),O(a.environment),ee(a.headers),ne(a.oauthEnabled),ue(a.oauthClientId),de(a.oauthClientSecret),F(a.oauthScope),q(a.oauthRedirectUri),U(a.timeout),je(a.enabled),De(!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){C(j.scope==="project"?"project":"user");const He=Wu(j.environment),At=j.type==="remote"?j:null,Et=Wu(At?.headers),wt=At?.oauth,$t=wt&&typeof wt=="object"?wt:null,qt=wt!==!1,Ms=j.type,cs=Ms==="local"?j.command??[]:[],Is=Ms==="remote"?j.url??"":"",Es=typeof At?.timeout=="number"&&Number.isFinite(At.timeout)?String(At.timeout):"";T(Ms),R(cs),$(Is),O(He),ee(Et),ne(qt),ue(qt?$t?.clientId??"":""),de(qt?$t?.clientSecret??"":""),F(qt?$t?.scope??"":""),q(qt?$t?.redirectUri??"":""),U(Es),je(j.enabled),De(!1),nt.current={mcpType:Ms,command:cs,url:Is,envEntries:He,headerEntries:Et,oauthEnabled:qt,oauthClientId:qt?$t?.clientId??"":"",oauthClientSecret:qt?$t?.clientSecret??"":"",oauthScope:qt?$t?.scope??"":"",oauthRedirectUri:qt?$t?.redirectUri??"":"",timeout:Es,enabled:j.enabled}}},[j,S,a]);const ot=l.useMemo(()=>{const He=nt.current;return He?N!==He.mcpType||ae!==He.enabled||JSON.stringify(M)!==JSON.stringify(He.command)||L!==He.url||JSON.stringify(B)!==JSON.stringify(He.envEntries)||JSON.stringify(_)!==JSON.stringify(He.headerEntries)||z!==He.oauthEnabled||re!==He.oauthClientId||Q!==He.oauthClientSecret||X!==He.oauthScope||V!==He.oauthRedirectUri||te!==He.timeout:!1},[N,M,L,B,_,z,re,Q,X,V,te,ae]),Xe=async()=>{const He=S?A.trim():n??"";if(!He){H.error(t("settings.mcp.page.toast.nameRequired"));return}if(S&&r.some(Et=>Et.name===He)){H.error(t("settings.mcp.page.toast.serverNameExists"));return}if(N==="local"&&M.filter(Boolean).length===0){H.error(t("settings.mcp.page.toast.localCommandRequired"));return}if(N==="remote"&&!L.trim()){H.error(t("settings.mcp.page.toast.remoteUrlRequired"));return}const At={name:He,scope:P,type:N,command:M,url:L,environment:B,headers:_,oauthEnabled:z,oauthClientId:re,oauthClientSecret:Q,oauthScope:X,oauthRedirectUri:V,timeout:te,enabled:ae};ve(!0);try{const Et=S?await d(At):await p(He,At);Et.ok?(await Pi(Le),ye(),S&&(i(null),o(He)),await v({directory:u,silent:!0}),Et.reloadFailed?H.warning(Et.message||t(S?"settings.mcp.page.toast.serverCreatedReloadFailed":"settings.mcp.page.toast.savedReloadFailed"),{description:Et.warning||t("settings.mcp.page.toast.retryRefreshHint")}):H.success(Et.message||t(S?"settings.mcp.page.toast.serverCreatedReloading":"settings.mcp.page.toast.savedReloading"))):H.error(t("settings.mcp.page.toast.saveFailed"))}catch(Et){H.error(Et instanceof Error?Et.message:t("settings.mcp.page.toast.unexpectedError"))}finally{ve(!1)}},We=async()=>{if(!n)return;le(!0);const He=await m(n);He.ok?(await Pi(Le),ye(),He.reloadFailed?H.warning(He.message||t("settings.mcp.page.toast.serverDeletedReloadFailed",{name:n}),{description:He.warning||t("settings.mcp.page.toast.refreshListIfStale")}):H.success(He.message||t("settings.mcp.page.toast.serverDeleted",{name:n})),ce(!1)):H.error(t("settings.mcp.page.toast.deleteFailed")),le(!1)},bt=async()=>{if(n){Ie(!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 At=Nn.getState().getStatusForDirectory(u??null)[n];At?.status==="connected"?H.success(t("settings.mcp.page.toast.connected")):At?.status==="needs_auth"?H.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):At?.status==="needs_client_registration"?H.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):At?.status==="failed"?H.error(At.error||t("settings.mcp.page.toast.connectionFailed")):H.message(t("settings.mcp.page.toast.connectionAttemptFinished"));return}await v({directory:u,silent:!0})}catch(He){H.error(He instanceof Error?He.message:t("settings.mcp.page.toast.connectionFailed"))}finally{Ie(!1)}}},Dt=l.useCallback(()=>S?(H.error(t("settings.mcp.page.toast.createServerBeforeLiveActions")),!1):ot?(H.error(t("settings.mcp.page.toast.saveBeforeLiveActions")),!1):!0,[ot,S,t]),Ht=l.useCallback(async(He=!1)=>{try{await v({directory:u,silent:He})}catch(At){He||H.error(At instanceof Error?At.message:t("settings.mcp.page.toast.refreshStatusFailed"))}},[u,v,t]);l.useEffect(()=>{Ht(!0)},[Ht]),l.useEffect(()=>{st.current=Ke,Ie(!1),pe(!1),ye()},[ye,Ke]);const rs=l.useCallback(async()=>{if(!n||N!=="remote"||!Dt())return;Y(!0);const He=Ke;let At=null;try{const Et=Nn.getState().getStatusForDirectory(u??null)[n]?.status;Ce.current=Et==="needs_auth"||Et==="needs_client_registration";const wt=np(n,u);if(!wt)throw new Error(t("settings.mcp.page.toast.oauthRedirectUrlBuildFailed"));if(!V.trim()&&!h){const cs=await p(n,{oauthEnabled:z,oauthClientId:re,oauthClientSecret:Q,oauthScope:X,oauthRedirectUri:wt});if(!cs.ok)throw new Error(t("settings.mcp.page.toast.oauthBrowserCallbackSaveFailed"));if(cs.reloadFailed)throw new Error(cs.warning||cs.message||t("settings.mcp.page.toast.openCodeReloadFailedAfterCallbackSave"));if(st.current!==He)return;q(wt),nt.current=nt.current?{...nt.current,oauthRedirectUri:wt}:nt.current}const $t=await w(n,u),qt=Qd(new URL($t).searchParams);if(qt&&(At=qt,await xk({state:qt,name:n,directory:u})),st.current!==He)return;Pe($t),Ae(qt??null),Me(!0),Ve.current=0;const Ms=await Xn($t);if(st.current!==He)return;Ms?H.message(t(h?"settings.mcp.page.toast.completeAuthorizationInBrowserWithPaste":"settings.mcp.page.toast.completeAuthorizationInBrowser")):H.error(t("settings.mcp.page.toast.openAuthorizationUrlFailed"))}catch(Et){await Pi(At),st.current===He&&H.error(Nc(Et,t("settings.mcp.page.toast.authorizationStartFailed"),e))}finally{st.current===He&&Y(!1)}},[u,h,N,re,Q,z,V,X,Dt,Ke,n,w,t,e,p]),jt=l.useCallback(async()=>{if(!n||!Dt())return;ke(!0);const He=Ke;try{if(await k(n,u),st.current!==He)return;Pe(null),Ae(null),W(""),Me(!1),Ve.current=0,await Pi(Le),H.success(t("settings.mcp.page.toast.savedAuthorizationRemoved"))}catch(At){st.current===He&&H.error(Nc(At,t("settings.mcp.page.toast.clearAuthorizationFailed"),e))}finally{st.current===He&&ke(!1)}},[Le,k,u,Dt,Ke,n,t,e]),St=l.useCallback(async()=>{if(!G)return;if((await Rn(G)).ok){H.success(t("settings.mcp.page.toast.authorizationUrlCopied"));return}H.error(t("settings.mcp.page.toast.authorizationUrlCopyFailed"))},[G,t]),ns=l.useCallback(async()=>{const He=uk(ge);if(!He.code){H.error(t("settings.mcp.page.toast.pasteCallbackOrCodeFirst"));return}const At=He.stateKey?await bk(He.stateKey):null,Et=He.context??At,wt=Et?.name??n,$t=Et?.directory??u;if(!wt){H.error(t("settings.mcp.page.toast.missingServerDetails"));return}if(!Et&&!Dt())return;ze(!0);const qt=Ke;try{if(await y(wt,He.code,$t),await Pi(He.stateKey??Le),st.current!==qt)return;W(""),Pe(null),Ae(null),Me(!1),Ve.current=0,H.success(wt===n?t("settings.mcp.page.toast.authorizationCompleted"):t("settings.mcp.page.toast.authorizationCompletedFor",{name:wt}))}catch(Ms){st.current===qt&&H.error(Nc(Ms,t("settings.mcp.page.toast.authorizationCompleteFailed"),e))}finally{st.current===qt&&ze(!1)}},[ge,Le,y,u,Dt,Ke,n,t,e]),ut=l.useCallback(async()=>{if(!(!n||!Dt())){if(!ae){H.error(t("settings.mcp.page.toast.enableServerBeforeTest"));return}pe(!0);try{const He=await D(n,u),At=He.status?.status;He.warning?H.warning(He.warning):At==="connected"?H.success(t("settings.mcp.page.toast.connectionTestSucceeded")):At==="needs_auth"?H.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):At==="needs_client_registration"?H.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):At==="failed"?H.error(He.status?.error||He.error||t("settings.mcp.page.toast.connectionTestFailed")):He.error?H.error(He.error):H.message(t("settings.mcp.page.toast.connectionTestFinished"))}catch(He){H.error(He instanceof Error?He.message:t("settings.mcp.page.toast.connectionTestFailed"))}finally{pe(!1)}}},[u,ae,Dt,n,t,D]);if(l.useEffect(()=>{if(!ie||!n)return;const He=window.setInterval(()=>{(async()=>{Ve.current+=1,await v({directory:u,silent:!0});const At=Nn.getState().getStatusForDirectory(u??null)[n];if(At){if(Ce.current&&At.status!=="needs_auth"&&At.status!=="needs_client_registration"){Me(!1),Ve.current=0,Ce.current=!1,Pe(null),W(""),At.status==="connected"&&H.success(t("settings.mcp.page.toast.authorizationCompleted"));return}if(!Ce.current&&At.status==="failed"){Me(!1),Ve.current=0,Ce.current=!1,H.error(At.error||t("settings.mcp.page.toast.authorizationFailed"));return}Ve.current>=30&&(Me(!1),Ve.current=0,Ce.current=!1,H.message(t("settings.mcp.page.toast.authorizationStillInProgress")))}})()},2e3);return()=>{window.clearInterval(He)}},[u,ie,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(I,{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 Gt=b[n],Xt=n?f[n]:void 0,Wt=Gt??Xt,is=Gt?.status==="connected",gs=Gt?.status==="needs_auth"||Gt?.status==="needs_client_registration",ps=h?null:np(n,u),Ns=hk(Wt?.status,e,Wt&&"error"in Wt?Wt.error:void 0),Mt=He=>{switch(He){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 He}};return s.jsxs(Ts,{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(sp,{status:Wt?.status,enabled:ae,getStatusLabel:Mt,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(we,{variant:is?"outline":"default",size:"xs",className:"!font-normal",onClick:bt,disabled:se||!ae,children:t(se?"settings.mcp.page.actions.working":is?"settings.mcp.page.actions.disconnect":"settings.mcp.page.actions.connect")}),N==="remote"&&s.jsxs(s.Fragment,{children:[s.jsx(we,{variant:gs?"default":"outline",size:"xs",className:"!font-normal",onClick:()=>{rs()},disabled:Ne||!ae,children:t(Ne?"settings.mcp.page.actions.starting":gs?"settings.mcp.page.actions.authorize":"settings.mcp.page.actions.reauthorize")}),s.jsx(we,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{jt()},disabled:fe||!ae,children:t(fe?"settings.mcp.page.actions.clearing":"settings.mcp.page.actions.clearAuth")})]}),is&&s.jsx(we,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{ut()},disabled:be||!ae,children:t(be?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.test")})]})]})]})}),!S&&gk(Wt?.status,G,gs,ie)&&s.jsx("div",{className:"mb-6 px-2",children:s.jsxs("div",{className:me("rounded-lg border p-3",fk(Wt?.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(sp,{status:Wt?.status,enabled:ae,getStatusLabel:Mt})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:Ns}),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:!is&&s.jsx(we,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ut()},disabled:be||!ae,children:t(be?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.testConnection")})}),G&&s.jsx("div",{className:"rounded-md border border-[var(--interactive-border)] bg-[var(--surface-background)] px-3 py-2",children:s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:t("settings.mcp.page.auth.authorizationUrl")}),s.jsx("div",{className:"break-all typography-micro text-foreground font-mono",children:G}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(we,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Xn(G)},children:[s.jsx(I,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.openInBrowser")]}),s.jsxs(we,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{St()},children:[s.jsx(I,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.copyLink")]})]})]})}),N==="remote"&&(gs||ie||G)&&s.jsx("div",{className:"rounded-md border border-[var(--interactive-border)] bg-[var(--surface-background)] px-3 py-3",children:s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:t("settings.mcp.page.auth.manualFallbackTitle")}),s.jsx("p",{className:"mt-1 typography-micro text-muted-foreground",children:t("settings.mcp.page.auth.manualFallbackDescription")})]}),s.jsx(bn,{value:ge,onChange:He=>W(He.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(we,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ns()},disabled:Ee,children:t(Ee?"settings.mcp.page.actions.completing":"settings.mcp.page.actions.completeAuthorization")})})]})})]}),ie&&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(Kt,{value:A,onChange:He=>E(He.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(ds,{value:P,onValueChange:He=>C(He),children:[s.jsx(us,{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(I,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"folder",className:"h-3.5 w-3.5"})}),s.jsxs(ms,{align:"end",children:[s.jsx(Lt,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(I,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(Lt,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(I,{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(we,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:Je,type:"button",title:t("settings.mcp.page.server.importJsonTitle"),children:[s.jsx(I,{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":ae,onClick:()=>je(!ae),onKeyDown:He=>{(He.key===" "||He.key==="Enter")&&(He.preventDefault(),je(!ae))},children:[s.jsx(xs,{checked:ae,onChange:je,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(we,{variant:"chip",size:"xs","aria-pressed":N==="local",onClick:()=>T("local"),className:"!font-normal",children:t("settings.mcp.page.transport.local")}),s.jsx(we,{variant:"chip",size:"xs","aria-pressed":N==="remote",onClick:()=>T("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(mk,{value:M,onChange:R,pasteCommandTitle:t("settings.mcp.page.connection.pasteCommandTitle"),pasteCommandLabel:t("settings.mcp.page.connection.pasteCommand"),pasteSuccess:He=>t("settings.mcp.page.toast.pastedArgumentsCount",{count:He}),clipboardReadFailed:t("settings.mcp.page.toast.clipboardReadFailed"),preview:He=>t("settings.mcp.page.connection.previewArgs",{count:He})}):s.jsx(Kt,{value:L,onChange:He=>$(He.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(ur,{open:xe,onOpenChange:De,children:[s.jsxs(wr,{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(z?"settings.mcp.page.advanced.autoDetect":"settings.mcp.page.advanced.custom")," · ",_.length," ",t("settings.mcp.page.advanced.headers"),te?` · ${te}ms`:"",")"]})]}),xe?s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(I,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(mr,{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(Kt,{type:"number",min:"1",step:"1",value:te,onChange:He=>U(He.target.value),placeholder:"5000",className:"h-7 w-32 font-mono px-2","data-bwignore":"true","data-1p-ignore":"true"})})]}),s.jsx("p",{className:"typography-micro text-muted-foreground sm:pl-64",children:t("settings.mcp.page.advanced.timeoutHint")})]}),s.jsxs("div",{children:[s.jsxs("div",{className:"mb-2 typography-ui-label text-foreground",children:[t("settings.mcp.page.advanced.requestHeaders"),_.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",_.length,")"]})]}),s.jsx(tp,{value:_,onChange:ee,keyTransform:He=>He.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:He=>t("settings.mcp.page.toast.importedVariablesCount",{count:He}),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":z,onClick:()=>ne(!z),onKeyDown:He=>{(He.key===" "||He.key==="Enter")&&(He.preventDefault(),ne(!z))},children:[s.jsx(xs,{checked:z,onChange:ne,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(Kt,{value:re,onChange:He=>ue(He.target.value),placeholder:t("settings.mcp.page.advanced.oauthClientIdPlaceholder"),className:"font-mono typography-meta",disabled:!z,"data-bwignore":"true","data-1p-ignore":"true"}),s.jsx(Kt,{value:Q,onChange:He=>de(He.target.value),placeholder:t("settings.mcp.page.advanced.oauthClientSecretPlaceholder"),className:"font-mono typography-meta",disabled:!z,"data-bwignore":"true","data-1p-ignore":"true"}),s.jsx(Kt,{value:X,onChange:He=>F(He.target.value),placeholder:t("settings.mcp.page.advanced.oauthScopesPlaceholder"),className:"font-mono typography-meta",disabled:!z,"data-bwignore":"true","data-1p-ignore":"true"}),s.jsx(Kt,{value:V,onChange:He=>q(He.target.value),placeholder:t("settings.mcp.page.advanced.oauthRedirectUriPlaceholder"),className:"font-mono typography-meta",disabled:!z,"data-bwignore":"true","data-1p-ignore":"true"})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("settings.mcp.page.advanced.oauthHint")}),ps&&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:ps})]})]})]})})]})})]}),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"),B.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",B.length,")"]})]})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:B.length===0?s.jsxs(we,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:()=>O([{key:"",value:""}]),children:[s.jsx(I,{name:"add",className:"h-3.5 w-3.5"}),t("settings.mcp.page.env.addEnvironmentVariable")]}):s.jsx(tp,{value:B,onChange:O,keyPlaceholder:t("settings.mcp.page.env.keyPlaceholder"),pasteLabel:t("settings.mcp.page.env.pasteEnv"),pasteTitle:t("settings.mcp.page.env.pasteEnvTitle"),noPairsFoundError:t("settings.mcp.page.toast.noKeyValuePairsFound"),importSuccess:He=>t("settings.mcp.page.toast.importedVariablesCount",{count:He}),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(we,{onClick:Xe,disabled:oe||!ot&&!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(we,{variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>ce(!0),children:t("settings.common.actions.delete")})]})]}),s.jsx(ws,{open:Ye,onOpenChange:He=>{He||(rt(!1),he(""),et(null))},children:s.jsxs(vs,{className:"max-w-md",children:[s.jsxs(Cs,{children:[s.jsx(js,{children:t("settings.mcp.page.importDialog.title")}),s.jsx(Rs,{children:t("settings.mcp.page.importDialog.description")})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsx(bn,{value:Re,onChange:He=>{he(He.target.value),et(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"}),qe&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:qe}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:s.jsxs(we,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:_e,type:"button",children:[s.jsx(I,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.importDialog.pasteFromClipboard")]})})]}),s.jsxs(Ks,{children:[s.jsx(we,{variant:"outline",onClick:()=>{rt(!1),he(""),et(null)},className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(we,{onClick:Ue,disabled:!Re.trim(),size:"sm",children:t("settings.common.actions.import")})]})]})}),s.jsx(ws,{open:K,onOpenChange:He=>{!He&&!Z&&ce(!1)},children:s.jsxs(vs,{className:"max-w-md",children:[s.jsxs(Cs,{children:[s.jsx(js,{children:t("settings.mcp.page.deleteDialog.title",{name:n??""})}),s.jsxs(Rs,{children:[t("settings.mcp.page.deleteDialog.descriptionPrefix")," ",s.jsx("code",{className:"text-foreground",children:"opencode.json"}),"."," ",t("settings.mcp.page.deleteDialog.descriptionSuffix")]})]}),s.jsxs(Ks,{children:[s.jsx(we,{variant:"outline",onClick:()=>ce(!1),disabled:Z,className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(we,{variant:"destructive",size:"sm",onClick:We,disabled:Z,children:t(Z?"settings.mcp.page.actions.deleting":"settings.common.actions.delete")})]})]})})]})},wk=t=>{const e=at.c(150),{onItemSelect:n}=t,{t:r}=pt(),[a,i]=l.useState(null),[o,c]=l.useState(""),[d,p]=l.useState(null),[m,u]=l.useState(!1),[h,b]=l.useState(null),{selectedSkillName:f,skills:v,setSelectedSkill:x,setSkillDraft:g,createSkill:w,deleteSkill:y,getSkillDetail:k}=ea(pr(jk));let D;e[0]!==n||e[1]!==x||e[2]!==g||e[3]!==v?(D=()=>{let _e="new-skill",Ue=1;for(;v.some(ot=>ot.name===_e);)_e=`new-skill-${Ue}`,Ue++;g({name:_e,scope:"user",source:"opencode",description:""}),x(_e),n?.()},e[0]=n,e[1]=x,e[2]=g,e[3]=v,e[4]=D):D=e[4];const j=D;let S;e[5]===Symbol.for("react.memo_cache_sentinel")?(S=async _e=>{p(_e)},e[5]=S):S=e[5];const A=S;let E;e[6]!==d||e[7]!==y||e[8]!==r?(E=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]=E):E=e[9];const P=E;let C;e[10]!==k||e[11]!==x||e[12]!==g||e[13]!==v||e[14]!==r?(C=async _e=>{const Ue=_e.name;let ot=1,Xe=`${Ue}-copy`;for(;v.some(bt=>bt.name===Xe);)ot++,Xe=`${Ue}-copy-${ot}`;const We=await k(_e.name);if(!We){H.error(r("settings.skills.sidebar.toast.duplicateLoadFailed"));return}g({name:Xe,scope:_e.scope||"user",source:_e.source||"opencode",description:(We.sources.md.fields.includes("description"),""),instructions:""}),x(Xe)},e[10]=k,e[11]=x,e[12]=g,e[13]=v,e[14]=r,e[15]=C):C=e[15];const N=C;let T;e[16]===Symbol.for("react.memo_cache_sentinel")?(T=_e=>{c(_e.name),i(_e)},e[16]=T):T=e[16];const M=T;let R;e[17]!==w||e[18]!==y||e[19]!==k||e[20]!==a||e[21]!==o||e[22]!==x||e[23]!==v||e[24]!==r?(R=async()=>{if(!a)return;const _e=o.trim().replace(/\s+/g,"-").toLowerCase();if(!_e){H.error(r("settings.skills.page.toast.skillNameRequired"));return}if(_e===a.name){i(null);return}if(v.some(Xe=>Xe.name===_e)){H.error(r("settings.skills.page.toast.skillExists"));return}if(!await k(a.name)){H.error(r("settings.skills.sidebar.toast.renameLoadFailed")),i(null);return}await w({name:_e,description:"Renamed skill",scope:a.scope,source:a.source})?await y(a.name)?(H.success(`Skill renamed to "${_e}"`),x(_e)):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]=k,e[20]=a,e[21]=o,e[22]=x,e[23]=v,e[24]=r,e[25]=R):R=e[25];const L=R;let $;e[26]!==v?($=v.filter(Nk),e[26]=v,e[27]=$):$=e[27];const B=$;let O;e[28]!==v?(O=v.filter(Sk),e[28]=v,e[29]=O):O=e[29];const _=O;let ee;e[30]===Symbol.for("react.memo_cache_sentinel")?(ee=function(Ue){const ot={},Xe=[];for(const bt of Ue)bt.group?(ot[bt.group]||(ot[bt.group]=[]),ot[bt.group].push(bt)):Xe.push(bt);const We=Object.keys(ot).sort(kk).map(bt=>({name:bt,skills:[...ot[bt]].sort(Ck)}));return Xe.sort(Ik),{sortedGroups:We,ungrouped:Xe}},e[30]=ee):ee=e[30];const z=ee;let ne;e[31]!==B?(ne=z(B),e[31]=B,e[32]=ne):ne=e[32];const re=ne;let ue;e[33]!==_?(ue=z(_),e[33]=_,e[34]=ue):ue=e[34];const Q=ue;let de;e[35]===Symbol.for("react.memo_cache_sentinel")?(de=me("flex h-full flex-col","bg-background"),e[35]=de):de=e[35];let X;e[36]!==r?(X=r("settings.skills.sidebar.title"),e[36]=r,e[37]=X):X=e[37];let F;e[38]!==X?(F=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:X}),e[38]=X,e[39]=F):F=e[39];let V;e[40]===Symbol.for("react.memo_cache_sentinel")?(V=s.jsx(io,{className:"mb-3"}),e[40]=V):V=e[40];let q;e[41]!==v.length||e[42]!==r?(q=r("settings.skills.sidebar.total",{count:v.length}),e[41]=v.length,e[42]=r,e[43]=q):q=e[43];let te;e[44]!==q?(te=s.jsx("span",{className:"typography-meta text-muted-foreground",children:q}),e[44]=q,e[45]=te):te=e[45];let U;e[46]===Symbol.for("react.memo_cache_sentinel")?(U=s.jsx(I,{name:"add",className:"h-3.5 w-3.5"}),e[46]=U):U=e[46];let ae;e[47]!==j?(ae=s.jsx(we,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:j,children:U}),e[47]=j,e[48]=ae):ae=e[48];let je;e[49]!==te||e[50]!==ae?(je=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[te,ae]}),e[49]=te,e[50]=ae,e[51]=je):je=e[51];let oe;e[52]!==F||e[53]!==je?(oe=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[F,V,je]}),e[52]=F,e[53]=je,e[54]=oe):oe=e[54];let ve;e[55]!==re||e[56]!==Q||e[57]!==N||e[58]!==n||e[59]!==h||e[60]!==B||e[61]!==f||e[62]!==x||e[63]!==v.length||e[64]!==r||e[65]!==_?(ve=s.jsx(Ts,{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(I,{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:[B.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")}),re.sortedGroups.map(_e=>{const{name:Ue,skills:ot}=_e;return s.jsx(md,{label:Ue,count:ot.length,storageKey:"project-skills",children:ot.map(Xe=>s.jsx(Io,{skill:Xe,isSelected:f===Xe.name,onSelect:()=>{x(Xe.name),n?.()},onRename:()=>M(Xe),onDelete:()=>A(Xe),onDuplicate:()=>N(Xe),isMenuOpen:h===Xe.name,onMenuOpenChange:We=>b(We?Xe.name:null)},Xe.name))},Ue)}),re.ungrouped.map(_e=>s.jsx(Io,{skill:_e,isSelected:f===_e.name,onSelect:()=>{x(_e.name),n?.()},onRename:()=>M(_e),onDelete:()=>A(_e),onDuplicate:()=>N(_e),isMenuOpen:h===_e.name,onMenuOpenChange:Ue=>b(Ue?_e.name:null)},_e.name))]}),_.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:r("settings.skills.sidebar.section.user")}),Q.sortedGroups.map(_e=>{const{name:Ue,skills:ot}=_e;return s.jsx(md,{label:Ue,count:ot.length,storageKey:"user-skills",children:ot.map(Xe=>s.jsx(Io,{skill:Xe,isSelected:f===Xe.name,onSelect:()=>{x(Xe.name),n?.()},onRename:()=>M(Xe),onDelete:()=>A(Xe),onDuplicate:()=>N(Xe),isMenuOpen:h===Xe.name,onMenuOpenChange:We=>b(We?Xe.name:null)},Xe.name))},Ue)}),Q.ungrouped.map(_e=>s.jsx(Io,{skill:_e,isSelected:f===_e.name,onSelect:()=>{x(_e.name),n?.()},onRename:()=>M(_e),onDelete:()=>A(_e),onDuplicate:()=>N(_e),isMenuOpen:h===_e.name,onMenuOpenChange:Ue=>b(Ue?_e.name:null)},_e.name))]})]})}),e[55]=re,e[56]=Q,e[57]=N,e[58]=n,e[59]=h,e[60]=B,e[61]=f,e[62]=x,e[63]=v.length,e[64]=r,e[65]=_,e[66]=ve):ve=e[66];const K=d!==null;let ce;e[67]!==m?(ce=_e=>{!_e&&!m&&p(null)},e[67]=m,e[68]=ce):ce=e[68];let Z;e[69]!==r?(Z=r("settings.skills.sidebar.deleteDialog.title"),e[69]=r,e[70]=Z):Z=e[70];let le;e[71]!==Z?(le=s.jsx(js,{children:Z}),e[71]=Z,e[72]=le):le=e[72];const se=d?.name??"";let Ie;e[73]!==r||e[74]!==se?(Ie=r("settings.skills.sidebar.deleteDialog.description",{name:se}),e[73]=r,e[74]=se,e[75]=Ie):Ie=e[75];let Ne;e[76]!==Ie?(Ne=s.jsx(Rs,{children:Ie}),e[76]=Ie,e[77]=Ne):Ne=e[77];let Y;e[78]!==le||e[79]!==Ne?(Y=s.jsxs(Cs,{children:[le,Ne]}),e[78]=le,e[79]=Ne,e[80]=Y):Y=e[80];let fe;e[81]===Symbol.for("react.memo_cache_sentinel")?(fe=()=>p(null),e[81]=fe):fe=e[81];let ke;e[82]!==r?(ke=r("settings.common.actions.cancel"),e[82]=r,e[83]=ke):ke=e[83];let be;e[84]!==m||e[85]!==ke?(be=s.jsx(we,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:fe,disabled:m,children:ke}),e[84]=m,e[85]=ke,e[86]=be):be=e[86];let pe;e[87]!==r?(pe=r("settings.common.actions.delete"),e[87]=r,e[88]=pe):pe=e[88];let Ee;e[89]!==P||e[90]!==m||e[91]!==pe?(Ee=s.jsx(we,{size:"sm",onClick:P,disabled:m,children:pe}),e[89]=P,e[90]=m,e[91]=pe,e[92]=Ee):Ee=e[92];let ze;e[93]!==be||e[94]!==Ee?(ze=s.jsxs(Ks,{children:[be,Ee]}),e[93]=be,e[94]=Ee,e[95]=ze):ze=e[95];let G;e[96]!==Y||e[97]!==ze?(G=s.jsxs(vs,{className:"max-w-md",children:[Y,ze]}),e[96]=Y,e[97]=ze,e[98]=G):G=e[98];let Pe;e[99]!==K||e[100]!==ce||e[101]!==G?(Pe=s.jsx(ws,{open:K,onOpenChange:ce,children:G}),e[99]=K,e[100]=ce,e[101]=G,e[102]=Pe):Pe=e[102];const Le=a!==null;let Ae;e[103]===Symbol.for("react.memo_cache_sentinel")?(Ae=_e=>!_e&&i(null),e[103]=Ae):Ae=e[103];let ge;e[104]!==r?(ge=r("settings.skills.sidebar.renameDialog.title"),e[104]=r,e[105]=ge):ge=e[105];let W;e[106]!==ge?(W=s.jsx(js,{children:ge}),e[106]=ge,e[107]=W):W=e[107];const ie=a?.name??"";let Me;e[108]!==r||e[109]!==ie?(Me=r("settings.skills.sidebar.renameDialog.description",{name:ie}),e[108]=r,e[109]=ie,e[110]=Me):Me=e[110];let Ve;e[111]!==Me?(Ve=s.jsx(Rs,{children:Me}),e[111]=Me,e[112]=Ve):Ve=e[112];let Ce;e[113]!==W||e[114]!==Ve?(Ce=s.jsxs(Cs,{children:[W,Ve]}),e[113]=W,e[114]=Ve,e[115]=Ce):Ce=e[115];let xe;e[116]===Symbol.for("react.memo_cache_sentinel")?(xe=_e=>c(_e.target.value),e[116]=xe):xe=e[116];let De;e[117]!==r?(De=r("settings.skills.sidebar.renameDialog.placeholder"),e[117]=r,e[118]=De):De=e[118];let Ye;e[119]!==L?(Ye=_e=>{_e.key==="Enter"&&L()},e[119]=L,e[120]=Ye):Ye=e[120];let rt;e[121]!==o||e[122]!==De||e[123]!==Ye?(rt=s.jsx(Kt,{value:o,onChange:xe,placeholder:De,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:Ye}),e[121]=o,e[122]=De,e[123]=Ye,e[124]=rt):rt=e[124];let Re;e[125]===Symbol.for("react.memo_cache_sentinel")?(Re=()=>i(null),e[125]=Re):Re=e[125];let he;e[126]!==r?(he=r("settings.common.actions.cancel"),e[126]=r,e[127]=he):he=e[127];let qe;e[128]!==he?(qe=s.jsx(we,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:Re,children:he}),e[128]=he,e[129]=qe):qe=e[129];let et;e[130]!==r?(et=r("settings.common.actions.rename"),e[130]=r,e[131]=et):et=e[131];let Ke;e[132]!==L||e[133]!==et?(Ke=s.jsx(we,{size:"sm",onClick:L,children:et}),e[132]=L,e[133]=et,e[134]=Ke):Ke=e[134];let st;e[135]!==qe||e[136]!==Ke?(st=s.jsxs(Ks,{children:[qe,Ke]}),e[135]=qe,e[136]=Ke,e[137]=st):st=e[137];let nt;e[138]!==Ce||e[139]!==rt||e[140]!==st?(nt=s.jsxs(vs,{children:[Ce,rt,st]}),e[138]=Ce,e[139]=rt,e[140]=st,e[141]=nt):nt=e[141];let ye;e[142]!==Le||e[143]!==nt?(ye=s.jsx(ws,{open:Le,onOpenChange:Ae,children:nt}),e[142]=Le,e[143]=nt,e[144]=ye):ye=e[144];let Je;return e[145]!==oe||e[146]!==ve||e[147]!==Pe||e[148]!==ye?(Je=s.jsxs("div",{className:de,children:[oe,ve,Pe,ye]}),e[145]=oe,e[146]=ve,e[147]=Pe,e[148]=ye,e[149]=Je):Je=e[149],Je},Io=t=>{const e=at.c(63),{skill:n,isSelected:r,onSelect:a,onDelete:i,onRename:o,onDuplicate:c,isMenuOpen:d,onMenuOpenChange:p}=t,{t:m}=pt();let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u=Ki(),e[0]=u):u=e[0];const h=u,b=r?"bg-interactive-selection":"hover:bg-interactive-hover";let f;e[1]!==b?(f=me("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",b),e[1]=b,e[2]=f):f=e[2];let v;e[3]!==p?(v=h?void 0:ne=>{ne.preventDefault(),p(!0)},e[3]=p,e[4]=v):v=e[4];let x;e[5]!==n.name?(x=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n.name}),e[5]=n.name,e[6]=x):x=e[6];let g;e[7]!==n.scope?(g=s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:n.scope}),e[7]=n.scope,e[8]=g):g=e[8];let w;e[9]!==n.source||e[10]!==m?(w=n.source==="claude"&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:m("settings.skills.sidebar.badge.claude")}),e[9]=n.source,e[10]=m,e[11]=w):w=e[11];let y;e[12]!==n.source||e[13]!==m?(y=n.source==="agents"&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:m("settings.skills.sidebar.badge.agents")}),e[12]=n.source,e[13]=m,e[14]=y):y=e[14];let k;e[15]!==x||e[16]!==g||e[17]!==w||e[18]!==y?(k=s.jsxs("div",{className:"flex items-center gap-1.5",children:[x,g,w,y]}),e[15]=x,e[16]=g,e[17]=w,e[18]=y,e[19]=k):k=e[19];let D;e[20]!==a||e[21]!==k?(D=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[20]=a,e[21]=k,e[22]=D):D=e[22];let j;e[23]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(Os,{asChild:!0,children:s.jsx(we,{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(I,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[23]=j):j=e[23];let S;e[24]!==o?(S=ne=>{ne.stopPropagation(),o()},e[24]=o,e[25]=S):S=e[25];let A;e[26]===Symbol.for("react.memo_cache_sentinel")?(A=s.jsx(I,{name:"edit",className:"h-4 w-4 mr-px"}),e[26]=A):A=e[26];let E;e[27]!==m?(E=m("settings.common.actions.rename"),e[27]=m,e[28]=E):E=e[28];let P;e[29]!==S||e[30]!==E?(P=s.jsxs(zt,{onClick:S,children:[A,E]}),e[29]=S,e[30]=E,e[31]=P):P=e[31];let C;e[32]!==c?(C=ne=>{ne.stopPropagation(),c()},e[32]=c,e[33]=C):C=e[33];let N;e[34]===Symbol.for("react.memo_cache_sentinel")?(N=s.jsx(I,{name:"file-copy",className:"h-4 w-4 mr-px"}),e[34]=N):N=e[34];let T;e[35]!==m?(T=m("settings.common.actions.duplicate"),e[35]=m,e[36]=T):T=e[36];let M;e[37]!==C||e[38]!==T?(M=s.jsxs(zt,{onClick:C,children:[N,T]}),e[37]=C,e[38]=T,e[39]=M):M=e[39];let R;e[40]!==i?(R=ne=>{ne.stopPropagation(),i()},e[40]=i,e[41]=R):R=e[41];let L;e[42]===Symbol.for("react.memo_cache_sentinel")?(L=s.jsx(I,{name:"delete-bin",className:"h-4 w-4 mr-px"}),e[42]=L):L=e[42];let $;e[43]!==m?($=m("settings.common.actions.delete"),e[43]=m,e[44]=$):$=e[44];let B;e[45]!==R||e[46]!==$?(B=s.jsxs(zt,{onClick:R,className:"text-destructive focus:text-destructive",children:[L,$]}),e[45]=R,e[46]=$,e[47]=B):B=e[47];let O;e[48]!==P||e[49]!==M||e[50]!==B?(O=s.jsxs($s,{align:"end",className:"w-fit min-w-20",children:[P,M,B]}),e[48]=P,e[49]=M,e[50]=B,e[51]=O):O=e[51];let _;e[52]!==d||e[53]!==p||e[54]!==O?(_=s.jsxs(Bs,{open:d,onOpenChange:p,children:[j,O]}),e[52]=d,e[53]=p,e[54]=O,e[55]=_):_=e[55];let ee;e[56]!==D||e[57]!==_?(ee=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[D,_]}),e[56]=D,e[57]=_,e[58]=ee):ee=e[58];let z;return e[59]!==ee||e[60]!==f||e[61]!==v?(z=s.jsx("div",{className:f,onContextMenu:v,children:ee}),e[59]=ee,e[60]=f,e[61]=v,e[62]=z):z=e[62],z};function jk(t){return{selectedSkillName:t.selectedSkillName,skills:t.skills,setSelectedSkill:t.setSelectedSkill,setSkillDraft:t.setSkillDraft,createSkill:t.createSkill,deleteSkill:t.deleteSkill,getSkillDetail:t.getSkillDetail}}function Nk(t){return t.scope==="project"}function Sk(t){return t.scope==="user"}function kk(t,e){return t.localeCompare(e)}function Ck(t,e){return t.name.localeCompare(e.name)}function Ik(t,e){return t.name.localeCompare(e.name)}const Pk=()=>`custom:${Date.now()}-${Math.random().toString(16).slice(2)}`,Ak=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},Dk=async()=>{try{const t=dr()?.settings;if(t)return(await t.load())?.settings||{};const e=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});return e.ok?await e.json().catch(()=>null):null}catch{return null}},Tk=t=>{const e=at.c(158),{open:n,onOpenChange:r}=t,{t:a}=pt(),i=Na(Mk),o=Na(Ek),c=Na(Rk),d=Jn(Fk),p=Jn(Lk),[m,u]=l.useState(""),[h,b]=l.useState(""),[f,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,k]=l.useState(null),[D,j]=l.useState(!1);let S;e[1]===Symbol.for("react.memo_cache_sentinel")?(S=[],e[1]=S):S=e[1];const[A,E]=l.useState(S),[P,C]=l.useState(null),N=l.useRef(0);let T;e[2]===Symbol.for("react.memo_cache_sentinel")?(T=ye=>{N.current=N.current+1,j(!1),k(null),ye?.clearIdentity&&(E([]),C(null))},e[2]=T):T=e[2];const M=T;let R,L;e[3]!==p||e[4]!==n?(R=()=>{n&&(N.current=N.current+1,u(""),b(""),v(""),k(null),j(!1),E([]),C(null),p(),(async()=>{const ye=await Dk(),Je=Array.isArray(ye?.skillCatalogs)?ye?.skillCatalogs:[];w(Je||[])})())},L=[n,p],e[3]=p,e[4]=n,e[5]=R,e[6]=L):(R=e[5],L=e[6]),l.useEffect(R,L);let $;e[7]!==h?($=h.trim(),e[7]=h,e[8]=$):$=e[8];const B=$;let O;e[9]!==f?(O=f.trim(),e[9]=f,e[10]=O):O=e[10];const _=O;let ee;if(e[11]!==g||e[12]!==B||e[13]!==_){let ye;e[15]!==B||e[16]!==_?(ye=Je=>{const _e=(Je.source||"").trim(),Ue=(Je.subpath||"").trim();return _e===B&&Ue===_},e[15]=B,e[16]=_,e[17]=ye):ye=e[17],ee=g.some(ye),e[11]=g,e[12]=B,e[13]=_,e[14]=ee}else ee=e[14];const z=ee;let ne;e[18]!==d||e[19]!==P||e[20]!==m||e[21]!==i||e[22]!==h||e[23]!==f||e[24]!==a?(ne=async()=>{const ye=h.trim();if(!ye){H.error(a("settings.skills.catalog.add.toast.repositoryRequired"));return}m.trim()||u(Ak(ye)),j(!1),k(null);const Je=N.current+1;N.current=Je;const _e=await i({source:ye,subpath:f.trim()||void 0,gitIdentityId:P||void 0});if(N.current!==Je)return;if(!_e.ok){if(_e.error?.kind==="authRequired"){if(dn()){H.error(a("settings.skills.catalog.shared.toast.privateRepoNotSupportedVsCode"));return}const ot=_e.error.identities||[];if(E(ot),!P&&ot.length>0){const Xe=d&&d!=="global"&&ot.some(We=>We.id===d)?d:ot[0].id;C(Xe)}H.error(a("settings.skills.catalog.add.toast.authenticationRequiredScan"));return}H.error(_e.error?.message||a("settings.skills.catalog.add.toast.scanFailed"));return}const Ue=_e.items?.length||0;if(k(Ue),Ue===0){H.error(a("settings.skills.catalog.add.toast.noSkillsFound")),j(!1);return}E([]),j(!0),H.success(a("settings.skills.catalog.shared.toast.foundSkills",{count:Ue}))},e[18]=d,e[19]=P,e[20]=m,e[21]=i,e[22]=h,e[23]=f,e[24]=a,e[25]=ne):ne=e[25];const re=ne;let ue;e[26]!==g||e[27]!==P||e[28]!==z||e[29]!==m||e[30]!==o||e[31]!==r||e[32]!==D||e[33]!==h||e[34]!==f||e[35]!==a?(ue=async()=>{const ye=m.trim(),Je=h.trim(),_e=f.trim();if(!ye){H.error(a("settings.skills.catalog.add.toast.catalogNameRequired"));return}if(!Je){H.error(a("settings.skills.catalog.add.toast.repositoryRequired"));return}if(!D){H.error(a("settings.skills.catalog.add.toast.scanBeforeAdd"));return}if(z){H.error(a("settings.skills.catalog.add.toast.catalogAlreadyExists"));return}const Ue={id:Pk(),label:ye,source:Je,..._e?{subpath:_e}:{},...P?{gitIdentityId:P}:{}},ot=[...g,Ue];try{await Ds({skillCatalogs:ot}),w(ot),H.success(a("settings.skills.catalog.add.toast.catalogAdded")),await o({refresh:!0}),r(!1)}catch(Xe){const We=Xe;H.error(We instanceof Error?We.message:a("settings.skills.catalog.add.toast.saveFailed"))}},e[26]=g,e[27]=P,e[28]=z,e[29]=m,e[30]=o,e[31]=r,e[32]=D,e[33]=h,e[34]=f,e[35]=a,e[36]=ue):ue=e[36];const Q=ue;let de;e[37]!==a?(de=a("settings.skills.catalog.add.title"),e[37]=a,e[38]=de):de=e[38];let X;e[39]!==de?(X=s.jsx(js,{children:de}),e[39]=de,e[40]=X):X=e[40];let F;e[41]!==a?(F=a("settings.skills.catalog.add.descriptionPrefix"),e[41]=a,e[42]=F):F=e[42];let V;e[43]===Symbol.for("react.memo_cache_sentinel")?(V=s.jsx("code",{className:"font-mono",children:"SKILL.md"}),e[43]=V):V=e[43];let q;e[44]!==a?(q=a("settings.skills.catalog.add.descriptionSuffix"),e[44]=a,e[45]=q):q=e[45];let te;e[46]!==F||e[47]!==q?(te=s.jsxs(Rs,{children:[F," ",V,q]}),e[46]=F,e[47]=q,e[48]=te):te=e[48];let U;e[49]!==X||e[50]!==te?(U=s.jsxs(Cs,{children:[X,te]}),e[49]=X,e[50]=te,e[51]=U):U=e[51];let ae;e[52]!==a?(ae=a("settings.skills.catalog.add.field.catalogName"),e[52]=a,e[53]=ae):ae=e[53];let je;e[54]!==ae?(je=s.jsx("label",{className:"typography-ui-label text-foreground",children:ae}),e[54]=ae,e[55]=je):je=e[55];let oe;e[56]===Symbol.for("react.memo_cache_sentinel")?(oe=ye=>u(ye.target.value),e[56]=oe):oe=e[56];let ve;e[57]!==a?(ve=a("settings.skills.catalog.add.field.catalogNamePlaceholder"),e[57]=a,e[58]=ve):ve=e[58];let K;e[59]!==m||e[60]!==ve?(K=s.jsx(Kt,{value:m,onChange:oe,placeholder:ve}),e[59]=m,e[60]=ve,e[61]=K):K=e[61];let ce;e[62]!==je||e[63]!==K?(ce=s.jsxs("div",{className:"space-y-2",children:[je,K]}),e[62]=je,e[63]=K,e[64]=ce):ce=e[64];let Z;e[65]!==a?(Z=a("settings.skills.catalog.add.field.repository"),e[65]=a,e[66]=Z):Z=e[66];let le;e[67]!==Z?(le=s.jsx("label",{className:"typography-ui-label text-foreground",children:Z}),e[67]=Z,e[68]=le):le=e[68];let se;e[69]===Symbol.for("react.memo_cache_sentinel")?(se=ye=>{b(ye.target.value),M({clearIdentity:!0})},e[69]=se):se=e[69];let Ie;e[70]!==a?(Ie=a("settings.skills.catalog.shared.field.repositoryPlaceholder"),e[70]=a,e[71]=Ie):Ie=e[71];let Ne;e[72]!==h||e[73]!==Ie?(Ne=s.jsx(Kt,{value:h,onChange:se,placeholder:Ie}),e[72]=h,e[73]=Ie,e[74]=Ne):Ne=e[74];let Y;e[75]!==a?(Y=a("settings.skills.catalog.add.field.repositoryHint"),e[75]=a,e[76]=Y):Y=e[76];let fe;e[77]!==Y?(fe=s.jsx("p",{className:"typography-micro text-muted-foreground",children:Y}),e[77]=Y,e[78]=fe):fe=e[78];let ke;e[79]!==le||e[80]!==Ne||e[81]!==fe?(ke=s.jsxs("div",{className:"space-y-2",children:[le,Ne,fe]}),e[79]=le,e[80]=Ne,e[81]=fe,e[82]=ke):ke=e[82];let be;e[83]!==a?(be=a("settings.skills.catalog.add.field.optionalSubpath"),e[83]=a,e[84]=be):be=e[84];let pe;e[85]!==be?(pe=s.jsx("label",{className:"typography-ui-label text-foreground",children:be}),e[85]=be,e[86]=pe):pe=e[86];let Ee;e[87]===Symbol.for("react.memo_cache_sentinel")?(Ee=ye=>{v(ye.target.value),M({clearIdentity:!0})},e[87]=Ee):Ee=e[87];let ze;e[88]!==a?(ze=a("settings.skills.catalog.shared.field.subpathPlaceholder"),e[88]=a,e[89]=ze):ze=e[89];let G;e[90]!==f||e[91]!==ze?(G=s.jsx(Kt,{value:f,onChange:Ee,placeholder:ze}),e[90]=f,e[91]=ze,e[92]=G):G=e[92];let Pe;e[93]!==pe||e[94]!==G?(Pe=s.jsxs("div",{className:"space-y-2",children:[pe,G]}),e[93]=pe,e[94]=G,e[95]=Pe):Pe=e[95];let Le;e[96]!==P||e[97]!==A||e[98]!==a?(Le=A.length>0&&!dn()?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(ds,{value:P||"",onValueChange:ye=>{C(ye),M()},children:[s.jsx(us,{className:"w-fit",children:s.jsx("span",{children:A.find(ye=>ye.id===P)?.name||a("settings.skills.catalog.shared.auth.chooseIdentity")})}),s.jsx(ms,{align:"start",children:A.map(Ok)})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:a("settings.skills.catalog.shared.auth.footerHint")})]}):null,e[96]=P,e[97]=A,e[98]=a,e[99]=Le):Le=e[99];let Ae;e[100]!==y||e[101]!==a?(Ae=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]=Ae):Ae=e[102];let ge;e[103]!==z||e[104]!==a?(ge=z?s.jsx("div",{className:"typography-meta text-muted-foreground",children:a("settings.skills.catalog.add.duplicateMessage")}):null,e[103]=z,e[104]=a,e[105]=ge):ge=e[105];let W;e[106]!==ce||e[107]!==ke||e[108]!==Pe||e[109]!==Le||e[110]!==Ae||e[111]!==ge?(W=s.jsxs("div",{className:"space-y-4",children:[ce,ke,Pe,Le,Ae,ge]}),e[106]=ce,e[107]=ke,e[108]=Pe,e[109]=Le,e[110]=Ae,e[111]=ge,e[112]=W):W=e[112];let ie;e[113]!==r?(ie=()=>r(!1),e[113]=r,e[114]=ie):ie=e[114];let Me;e[115]!==a?(Me=a("settings.common.actions.cancel"),e[115]=a,e[116]=Me):Me=e[116];let Ve;e[117]!==ie||e[118]!==Me?(Ve=s.jsx(we,{size:"sm",variant:"ghost",onClick:ie,children:Me}),e[117]=ie,e[118]=Me,e[119]=Ve):Ve=e[119];let Ce;e[120]!==re?(Ce=()=>{re()},e[120]=re,e[121]=Ce):Ce=e[121];let xe;e[122]!==c||e[123]!==h?(xe=c||!h.trim(),e[122]=c,e[123]=h,e[124]=xe):xe=e[124];let De;e[125]===Symbol.for("react.memo_cache_sentinel")?(De=s.jsx(I,{name:"git-repository",className:"h-4 w-4"}),e[125]=De):De=e[125];let Ye;e[126]!==c||e[127]!==a?(Ye=a(c?"settings.skills.catalog.shared.actions.scanning":"settings.skills.catalog.shared.actions.scan"),e[126]=c,e[127]=a,e[128]=Ye):Ye=e[128];let rt;e[129]!==Ce||e[130]!==xe||e[131]!==Ye?(rt=s.jsxs(we,{size:"sm",className:"gap-2",variant:"ghost",onClick:Ce,disabled:xe,children:[De,Ye]}),e[129]=Ce,e[130]=xe,e[131]=Ye,e[132]=rt):rt=e[132];let Re;e[133]!==Q?(Re=()=>{Q()},e[133]=Q,e[134]=Re):Re=e[134];let he;e[135]!==z||e[136]!==m||e[137]!==D||e[138]!==h?(he=!D||z||!m.trim()||!h.trim(),e[135]=z,e[136]=m,e[137]=D,e[138]=h,e[139]=he):he=e[139];let qe;e[140]!==a?(qe=a("settings.skills.catalog.add.actions.addCatalog"),e[140]=a,e[141]=qe):qe=e[141];let et;e[142]!==Re||e[143]!==he||e[144]!==qe?(et=s.jsx(we,{size:"sm",onClick:Re,disabled:he,children:qe}),e[142]=Re,e[143]=he,e[144]=qe,e[145]=et):et=e[145];let Ke;e[146]!==Ve||e[147]!==rt||e[148]!==et?(Ke=s.jsxs(Ks,{children:[Ve,rt,et]}),e[146]=Ve,e[147]=rt,e[148]=et,e[149]=Ke):Ke=e[149];let st;e[150]!==U||e[151]!==W||e[152]!==Ke?(st=s.jsxs(vs,{className:"max-w-xl",children:[U,W,Ke]}),e[150]=U,e[151]=W,e[152]=Ke,e[153]=st):st=e[153];let nt;return e[154]!==r||e[155]!==n||e[156]!==st?(nt=s.jsx(ws,{open:n,onOpenChange:r,children:st}),e[154]=r,e[155]=n,e[156]=st,e[157]=nt):nt=e[157],nt};function Mk(t){return t.scanRepo}function Ek(t){return t.loadCatalog}function Rk(t){return t.isScanning}function Fk(t){return t.defaultGitIdentityId}function Lk(t){return t.loadDefaultGitIdentityId}function Ok(t){return s.jsx(Lt,{value:t.id,children:t.name},t.id)}const $k=t=>{const e=at.c(85),{open:n,onOpenChange:r,conflicts:a,onConfirm:i}=t,{t:o}=pt();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 X={};for(const F of a)X[F.skillName]="skip";p(X)},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 h;e[5]!==a?(h=X=>{const F={};for(const V of a)F[V.skillName]=X;p(F)},e[5]=a,e[6]=h):h=e[6];const b=h;let f;e[7]!==a||e[8]!==d?(f=a.length>0&&a.every(X=>d[X.skillName]),e[7]=a,e[8]=d,e[9]=f):f=e[9];const v=f;let x;e[10]!==o?(x=o("settings.skills.catalog.conflicts.title"),e[10]=o,e[11]=x):x=e[11];let g;e[12]!==x?(g=s.jsx(js,{children:x}),e[12]=x,e[13]=g):g=e[13];let w;e[14]!==o?(w=o("settings.skills.catalog.conflicts.description"),e[14]=o,e[15]=w):w=e[15];let y;e[16]!==w?(y=s.jsx(Rs,{children:w}),e[16]=w,e[17]=y):y=e[17];let k;e[18]!==g||e[19]!==y?(k=s.jsxs(Cs,{children:[g,y]}),e[18]=g,e[19]=y,e[20]=k):k=e[20];let D;e[21]!==a.length||e[22]!==o?(D=o("settings.skills.catalog.conflicts.count",{count:a.length}),e[21]=a.length,e[22]=o,e[23]=D):D=e[23];let j;e[24]!==D?(j=s.jsx("span",{className:"typography-meta text-muted-foreground",children:D}),e[24]=D,e[25]=j):j=e[25];let S;e[26]!==b?(S=()=>b("skip"),e[26]=b,e[27]=S):S=e[27];let A;e[28]!==o?(A=o("settings.skills.catalog.conflicts.actions.skipAll"),e[28]=o,e[29]=A):A=e[29];let E;e[30]!==S||e[31]!==A?(E=s.jsx(we,{variant:"outline",size:"xs",className:"!font-normal",onClick:S,children:A}),e[30]=S,e[31]=A,e[32]=E):E=e[32];let P;e[33]!==b?(P=()=>b("overwrite"),e[33]=b,e[34]=P):P=e[34];let C;e[35]!==o?(C=o("settings.skills.catalog.conflicts.actions.overwriteAll"),e[35]=o,e[36]=C):C=e[36];let N;e[37]!==P||e[38]!==C?(N=s.jsx(we,{variant:"outline",size:"xs",className:"!font-normal",onClick:P,children:C}),e[37]=P,e[38]=C,e[39]=N):N=e[39];let T;e[40]!==E||e[41]!==N?(T=s.jsxs("div",{className:"flex items-center gap-2",children:[E,N]}),e[40]=E,e[41]=N,e[42]=T):T=e[42];let M;e[43]!==j||e[44]!==T?(M=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[j,T]}),e[43]=j,e[44]=T,e[45]=M):M=e[45];let R;if(e[46]!==a||e[47]!==d||e[48]!==o){let X;e[50]!==d||e[51]!==o?(X=F=>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:F.skillName}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:o("settings.skills.catalog.conflicts.installedIn",{scope:F.scope==="project"?o("settings.skills.catalog.conflicts.scope.project"):o("settings.skills.catalog.conflicts.scope.user"),source:F.source==="agents"?o("settings.skills.catalog.conflicts.source.agents"):o("settings.skills.catalog.conflicts.source.opencode")})})]}),s.jsxs(ds,{value:d[F.skillName]||"skip",onValueChange:V=>p(q=>({...q,[F.skillName]:V})),children:[s.jsx(us,{className:"w-fit",children:s.jsx("span",{className:"capitalize",children:(d[F.skillName]||"skip")==="overwrite"?o("settings.skills.catalog.conflicts.decision.overwrite"):o("settings.skills.catalog.conflicts.decision.skip")})}),s.jsxs(ms,{align:"end",children:[s.jsx(Lt,{value:"skip",className:"pr-2 [&>span:first-child]:hidden",children:o("settings.skills.catalog.conflicts.decision.skip")}),s.jsx(Lt,{value:"overwrite",className:"pr-2 [&>span:first-child]:hidden",children:o("settings.skills.catalog.conflicts.decision.overwrite")})]})]})]},F.skillName),e[50]=d,e[51]=o,e[52]=X):X=e[52],R=a.map(X),e[46]=a,e[47]=d,e[48]=o,e[49]=R}else R=e[49];let L;e[53]!==R?(L=s.jsx("div",{className:"space-y-2",children:R}),e[53]=R,e[54]=L):L=e[54];let $;e[55]!==M||e[56]!==L?($=s.jsxs("div",{className:"space-y-3",children:[M,L]}),e[55]=M,e[56]=L,e[57]=$):$=e[57];let B;e[58]!==r?(B=()=>r(!1),e[58]=r,e[59]=B):B=e[59];let O;e[60]!==o?(O=o("settings.common.actions.cancel"),e[60]=o,e[61]=O):O=e[61];let _;e[62]!==B||e[63]!==O?(_=s.jsx(we,{size:"sm",variant:"ghost",onClick:B,children:O}),e[62]=B,e[63]=O,e[64]=_):_=e[64];let ee;e[65]!==d||e[66]!==i?(ee=()=>i(d),e[65]=d,e[66]=i,e[67]=ee):ee=e[67];const z=!v;let ne;e[68]!==o?(ne=o("settings.skills.catalog.conflicts.actions.continue"),e[68]=o,e[69]=ne):ne=e[69];let re;e[70]!==ee||e[71]!==z||e[72]!==ne?(re=s.jsx(we,{size:"sm",onClick:ee,disabled:z,children:ne}),e[70]=ee,e[71]=z,e[72]=ne,e[73]=re):re=e[73];let ue;e[74]!==_||e[75]!==re?(ue=s.jsxs(Ks,{children:[_,re]}),e[74]=_,e[75]=re,e[76]=ue):ue=e[76];let Q;e[77]!==k||e[78]!==$||e[79]!==ue?(Q=s.jsxs(vs,{className:"max-w-2xl",children:[k,$,ue]}),e[77]=k,e[78]=$,e[79]=ue,e[80]=Q):Q=e[80];let de;return e[81]!==r||e[82]!==n||e[83]!==Q?(de=s.jsx(ws,{open:n,onOpenChange:r,children:Q}),e[81]=r,e[82]=n,e[83]=Q,e[84]=de):de=e[84],de},Yd=[{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 Ui(t,e){return t==="project"&&e==="agents"?"project-agents":t==="project"?"project-opencode":e==="agents"?"user-agents":"user-opencode"}function tg(t){const e=Yd.find(n=>n.value===t);return e?{scope:e.scope,source:e.source}:{scope:"user",source:"opencode"}}const Bk=t=>{const e=at.c(124),{open:n,onOpenChange:r,item:a}=t,{t:i}=pt(),o=Na(_k),c=Na(Vk),[d,p]=l.useState("user"),[m,u]=l.useState("opencode"),h=Fs(zk),b=Fs(Uk),[f,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,k]=l.useState(w),[D,j]=l.useState(null);let S,A;e[1]!==b||e[2]!==n?(S=()=>{n&&(p("user"),u("opencode"),v(b),g(!1),k([]),j(null))},A=[n,b],e[1]=b,e[2]=n,e[3]=S,e[4]=A):(S=e[3],A=e[4]),l.useEffect(S,A);let E;e[5]!==i?(E=Ae=>{switch(Ae){case"project-opencode":return i("settings.skills.location.option.projectOpencode.label");case"user-agents":return i("settings.skills.location.option.userAgents.label");case"project-agents":return i("settings.skills.location.option.projectAgents.label");default:return i("settings.skills.location.option.userOpencode.label")}},e[5]=i,e[6]=E):E=e[6];const P=E;let C;e[7]!==i?(C=Ae=>{switch(Ae){case"project-opencode":return i("settings.skills.location.option.projectOpencode.description");case"user-agents":return i("settings.skills.location.option.userAgents.description");case"project-agents":return i("settings.skills.location.option.projectAgents.description");default:return i("settings.skills.location.option.userOpencode.description")}},e[7]=i,e[8]=C):C=e[8];const N=C;let T;e:{if(h.length===0){T=null;break e}if(f&&h.some(Ae=>Ae.id===f)){T=f;break e}if(b&&h.some(Ae=>Ae.id===b)){T=b;break e}T=h[0]?.id??null}const M=T;let R;e:{if(d!=="project"){R=null;break e}const Ae=M;if(!Ae){R=null;break e}let ge;if(e[9]!==Ae||e[10]!==h){let ie;e[12]!==Ae?(ie=Me=>Me.id===Ae,e[12]=Ae,e[13]=ie):ie=e[13],ge=h.find(ie),e[9]=Ae,e[10]=h,e[11]=ge}else ge=e[11];R=ge?.path??null}const L=R;let $;e[14]!==o||e[15]!==a||e[16]!==r||e[17]!==i?($=async Ae=>{const ge={skillDir:Ae.skillDir};a?.clawdhub&&(ge.clawdhub={slug:a.clawdhub.slug,version:a.clawdhub.version});const W=await o({source:Ae.source,subpath:Ae.subpath,gitIdentityId:a?.gitIdentityId,scope:Ae.scope,targetSource:Ae.targetSource,selections:[ge],conflictPolicy:"prompt",conflictDecisions:Ae.conflictDecisions},{directory:Ae.directoryOverride??null});if(W.ok){H.success(i("settings.skills.catalog.installSkill.toast.installed")),r(!1);return}if(W.error?.kind==="conflicts"){j({source:Ae.source,subpath:Ae.subpath,scope:Ae.scope,targetSource:Ae.targetSource,skillDir:Ae.skillDir,directoryOverride:Ae.directoryOverride??null}),k(W.error.conflicts),g(!0);return}if(W.error?.kind==="authRequired"){H.error(W.error.message||i("settings.skills.catalog.installSkill.toast.authRequired"));return}H.error(W.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 B=$;if(!a)return null;let O;e[19]!==i?(O=i("settings.skills.catalog.installSkill.title"),e[19]=i,e[20]=O):O=e[20];let _;e[21]!==O?(_=s.jsx(js,{children:O}),e[21]=O,e[22]=_):_=e[22];let ee;e[23]!==i?(ee=i("settings.skills.catalog.installSkill.descriptionPrefix"),e[23]=i,e[24]=ee):ee=e[24];let z;e[25]!==a.skillName?(z=s.jsx("span",{className:"font-semibold text-foreground",children:a.skillName}),e[25]=a.skillName,e[26]=z):z=e[26];let ne;e[27]!==i?(ne=i("settings.skills.catalog.installSkill.descriptionSuffix"),e[27]=i,e[28]=ne):ne=e[28];let re;e[29]!==ee||e[30]!==z||e[31]!==ne?(re=s.jsxs(Rs,{children:[ee," ",z," ",ne]}),e[29]=ee,e[30]=z,e[31]=ne,e[32]=re):re=e[32];let ue;e[33]!==_||e[34]!==re?(ue=s.jsxs(Cs,{children:[_,re]}),e[33]=_,e[34]=re,e[35]=ue):ue=e[35];let Q;e[36]!==i?(Q=i("settings.skills.catalog.installSkill.field.destination"),e[36]=i,e[37]=Q):Q=e[37];let de;e[38]!==Q?(de=s.jsx("span",{className:"typography-ui-label text-foreground",children:Q}),e[38]=Q,e[39]=de):de=e[39];let X;e[40]!==d||e[41]!==m?(X=Ui(d,m),e[40]=d,e[41]=m,e[42]=X):X=e[42];let F;e[43]===Symbol.for("react.memo_cache_sentinel")?(F=Ae=>{const ge=tg(Ae);p(ge.scope),u(ge.source==="agents"?"agents":"opencode")},e[43]=F):F=e[43];let V;e[44]!==d?(V=d==="user"?s.jsx(I,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"folder",className:"h-3.5 w-3.5"}),e[44]=d,e[45]=V):V=e[45];let q;e[46]!==m?(q=m==="agents"?s.jsx(I,{name:"robot-2",className:"h-3.5 w-3.5"}):null,e[46]=m,e[47]=q):q=e[47];let te;e[48]!==P||e[49]!==d||e[50]!==m?(te=P(Ui(d,m)),e[48]=P,e[49]=d,e[50]=m,e[51]=te):te=e[51];let U;e[52]!==te?(U=s.jsx("span",{children:te}),e[52]=te,e[53]=U):U=e[53];let ae;e[54]!==V||e[55]!==q||e[56]!==U?(ae=s.jsxs(us,{className:"w-fit gap-1.5",children:[V,q,U]}),e[54]=V,e[55]=q,e[56]=U,e[57]=ae):ae=e[57];let je;e[58]!==N||e[59]!==P?(je=Yd.map(Ae=>s.jsx(Lt,{value:Ae.value,className:"pr-2 [&>span:first-child]:hidden",children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[Ae.scope==="user"?s.jsx(I,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"folder",className:"h-3.5 w-3.5"}),Ae.source==="agents"?s.jsx(I,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:P(Ae.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-5",children:N(Ae.value)})]})},Ae.value)),e[58]=N,e[59]=P,e[60]=je):je=e[60];let oe;e[61]!==je?(oe=s.jsx(ms,{align:"start",children:je}),e[61]=je,e[62]=oe):oe=e[62];let ve;e[63]!==X||e[64]!==ae||e[65]!==oe?(ve=s.jsxs(ds,{value:X,onValueChange:F,children:[ae,oe]}),e[63]=X,e[64]=ae,e[65]=oe,e[66]=ve):ve=e[66];let K;e[67]!==de||e[68]!==ve?(K=s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[de,ve]}),e[67]=de,e[68]=ve,e[69]=K):K=e[69];let ce;e[70]!==h||e[71]!==M||e[72]!==d||e[73]!==i?(ce=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")}),h.length===0?s.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.skills.catalog.installSkill.field.noProjects")}):s.jsxs(ds,{value:M??"",onValueChange:Ae=>v(Ae),disabled:h.length===1,children:[s.jsx(us,{className:"w-fit",children:s.jsx(ys,{placeholder:i("settings.skills.catalog.installSkill.field.chooseProjectPlaceholder")})}),s.jsx(ms,{align:"start",children:h.map(Wk)})]})]}),e[70]=h,e[71]=M,e[72]=d,e[73]=i,e[74]=ce):ce=e[74];let Z;e[75]!==a.warnings?(Z=a.warnings?.length?s.jsx("div",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-2 py-1.5 rounded",children:a.warnings.join(" · ")}):null,e[75]=a.warnings,e[76]=Z):Z=e[76];let le;e[77]!==K||e[78]!==ce||e[79]!==Z?(le=s.jsxs("div",{className:"mt-2 space-y-3",children:[K,ce,Z]}),e[77]=K,e[78]=ce,e[79]=Z,e[80]=le):le=e[80];let se;e[81]!==r?(se=()=>r(!1),e[81]=r,e[82]=se):se=e[82];let Ie;e[83]!==i?(Ie=i("settings.common.actions.cancel"),e[83]=i,e[84]=Ie):Ie=e[84];let Ne;e[85]!==se||e[86]!==Ie?(Ne=s.jsx(we,{size:"sm",variant:"ghost",onClick:se,children:Ie}),e[85]=se,e[86]=Ie,e[87]=Ne):Ne=e[87];const Y=c||!a.installable||d==="project"&&!L;let fe;e[88]!==L||e[89]!==B||e[90]!==a.repoSource||e[91]!==a.repoSubpath||e[92]!==a.skillDir||e[93]!==d||e[94]!==m?(fe=()=>{B({source:a.repoSource,subpath:a.repoSubpath,scope:d,targetSource:m,skillDir:a.skillDir,directoryOverride:L})},e[88]=L,e[89]=B,e[90]=a.repoSource,e[91]=a.repoSubpath,e[92]=a.skillDir,e[93]=d,e[94]=m,e[95]=fe):fe=e[95];let ke;e[96]!==c||e[97]!==i?(ke=i(c?"settings.skills.catalog.installSkill.actions.installing":"settings.skills.catalog.installSkill.actions.install"),e[96]=c,e[97]=i,e[98]=ke):ke=e[98];let be;e[99]!==Y||e[100]!==fe||e[101]!==ke?(be=s.jsx(we,{size:"sm",disabled:Y,onClick:fe,children:ke}),e[99]=Y,e[100]=fe,e[101]=ke,e[102]=be):be=e[102];let pe;e[103]!==Ne||e[104]!==be?(pe=s.jsxs(Ks,{children:[Ne,be]}),e[103]=Ne,e[104]=be,e[105]=pe):pe=e[105];let Ee;e[106]!==ue||e[107]!==le||e[108]!==pe?(Ee=s.jsxs(vs,{className:"max-w-md",children:[ue,le,pe]}),e[106]=ue,e[107]=le,e[108]=pe,e[109]=Ee):Ee=e[109];let ze;e[110]!==r||e[111]!==n||e[112]!==Ee?(ze=s.jsx(ws,{open:n,onOpenChange:r,children:Ee}),e[110]=r,e[111]=n,e[112]=Ee,e[113]=ze):ze=e[113];let G;e[114]!==D||e[115]!==B?(G=Ae=>{D&&(B({source:D.source,subpath:D.subpath,scope:D.scope,targetSource:D.targetSource,skillDir:D.skillDir,conflictDecisions:Ae,directoryOverride:D.directoryOverride??null}),g(!1))},e[114]=D,e[115]=B,e[116]=G):G=e[116];let Pe;e[117]!==y||e[118]!==x||e[119]!==G?(Pe=s.jsx($k,{open:x,onOpenChange:g,conflicts:y,onConfirm:G}),e[117]=y,e[118]=x,e[119]=G,e[120]=Pe):Pe=e[120];let Le;return e[121]!==ze||e[122]!==Pe?(Le=s.jsxs(s.Fragment,{children:[ze,Pe]}),e[121]=ze,e[122]=Pe,e[123]=Le):Le=e[123],Le};function _k(t){return t.installSkills}function Vk(t){return t.isInstalling}function zk(t){return t.projects}function Uk(t){return t.activeProjectId}function Wk(t){return s.jsx(Lt,{value:t.id,children:t.label||t.path},t.id)}const Kk=async()=>{try{const t=dr()?.settings;if(t)return(await t.load())?.settings||{};const e=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});return e.ok?await e.json().catch(()=>null):null}catch{return null}},Hk=({mode:t,onModeChange:e,showModeTabs:n=!0})=>{const{t:r}=pt(),{sources:a,itemsBySource:i,selectedSourceId:o,setSelectedSource:c,loadCatalog:d,loadSource:p,loadMoreClawdHub:m,isLoadingCatalog:u,isLoadingSource:h,isLoadingMore:b,loadedSourceIds:f,clawdhubHasMoreBySource:v,lastCatalogError:x}=Na(pr(_=>({sources:_.sources,itemsBySource:_.itemsBySource,selectedSourceId:_.selectedSourceId,setSelectedSource:_.setSelectedSource,loadCatalog:_.loadCatalog,loadSource:_.loadSource,loadMoreClawdHub:_.loadMoreClawdHub,isLoadingCatalog:_.isLoadingCatalog,isLoadingSource:_.isLoadingSource,isLoadingMore:_.isLoadingMore,loadedSourceIds:_.loadedSourceIds,clawdhubHasMoreBySource:_.clawdhubHasMoreBySource,lastCatalogError:_.lastCatalogError}))),[g,w]=l.useState(""),[y,k]=l.useState(!1),[D,j]=l.useState(!1),[S,A]=l.useState(null),[E,P]=l.useState(!1),[C,N]=l.useState(!1);l.useEffect(()=>{d()},[d]),l.useEffect(()=>{o&&(f[o]||p(o))},[o,f,p]);const T=l.useMemo(()=>o?i[o]||[]:[],[i,o]),M=l.useMemo(()=>{const _=g.trim().toLowerCase();return _?T.filter(ee=>{const z=ee.skillName.toLowerCase(),ne=(ee.description||"").toLowerCase(),re=(ee.frontmatterName||"").toLowerCase();return z.includes(_)||ne.includes(_)||re.includes(_)}):T},[T,g]),R=l.useMemo(()=>a.find(_=>_.id===o)||null,[a,o]),L=!!(o&&o.startsWith("custom:")),$=R?.source==="clawdhub:registry"||R?.sourceType==="clawdhub",B=!!(o&&(v[o]??!0)),O=async()=>{if(!(!o||!L)){P(!0);try{const _=await Kk(),z=(Array.isArray(_?.skillCatalogs)?_?.skillCatalogs:[]).filter(ne=>ne.id!==o);await Ds({skillCatalogs:z}),await d({refresh:!0}),N(!1)}finally{P(!1)}}};return s.jsx(Ts,{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(Ar,{items:[{id:"manual",label:r("settings.skills.catalog.page.mode.manual")},{id:"external",label:r("settings.skills.catalog.page.mode.external")}],activeId:t,onSelect:_=>e(_),layoutMode:"fit",variant:"animated",animateActivePill:!1,className:"h-full"})})}),s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground px-1",children:r("settings.skills.catalog.page.title")})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:r("settings.skills.catalog.page.section.sourceRepository")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2 py-1.5",children:[s.jsxs(ds,{value:o||"",onValueChange:_=>c(_),children:[s.jsx(us,{className:"w-fit",children:s.jsx(ys,{placeholder:r("settings.skills.catalog.page.field.selectSourcePlaceholder"),children:R?.label})}),s.jsx(ms,{align:"start",children:a.map(_=>s.jsx(Lt,{value:_.id,children:_.label},_.id))})]}),s.jsx(we,{variant:"outline",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>{o?p(o,{refresh:!0}):d({refresh:!0})},disabled:u||h,title:r("settings.skills.catalog.page.actions.refreshTitle"),children:s.jsx(I,{name:"refresh",className:me("h-3.5 w-3.5",(u||h)&&"animate-spin")})}),L&&s.jsx(we,{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:E,title:r("settings.skills.catalog.page.actions.removeCatalogTitle"),children:s.jsx(I,{name:"delete-bin",className:"h-3.5 w-3.5"})}),s.jsxs(we,{size:"xs",className:"!font-normal gap-1",onClick:()=>k(!0),children:[s.jsx(I,{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(I,{name:"search",className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Kt,{value:g,onChange:_=>w(_.target.value),placeholder:r("settings.skills.catalog.shared.field.searchSkillsPlaceholder"),className:"h-7 pl-8 w-full sm:w-64"})]}),s.jsx("span",{className:"typography-meta text-muted-foreground mt-1 block",children:u?r("settings.skills.catalog.page.loading.catalog"):r("settings.skills.catalog.page.foundCount",{count:M.length})})]})]})]}),x&&s.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-4 py-3",children:[s.jsx("div",{className:"typography-ui-label font-medium text-[var(--status-error)]",children:r("settings.skills.catalog.page.error.catalogTitle")}),s.jsx("div",{className:"typography-meta text-[var(--status-error)]/80 mt-1",children:x.message})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("section",{className:"px-2 pb-2 pt-0",children:M.length===0&&!h?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")})]}):h?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx(I,{name:"refresh",className:"mx-auto mb-3 h-5 w-5 animate-spin opacity-50"}),s.jsx("p",{className:"typography-meta",children:r("settings.skills.catalog.page.loading.skills")})]}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:M.map(_=>{const ee=_.installed?.isInstalled,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:_.skillName}),ee&&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:z||r("settings.skills.catalog.page.badge.unknown")})}),!_.installable&&s.jsx("span",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:r("settings.skills.catalog.page.badge.notInstallable")})]}),_.description?s.jsx("div",{className:"typography-meta text-muted-foreground mt-0.5 line-clamp-2",children:_.description}):s.jsx("div",{className:"typography-meta text-muted-foreground/50 mt-0.5 italic",children:r("settings.skills.catalog.shared.noDescription")}),_.clawdhub&&s.jsxs("div",{className:"typography-micro text-muted-foreground mt-1.5 flex items-center gap-3",children:[_.clawdhub.owner&&s.jsxs("span",{children:[r("settings.skills.catalog.page.byOwnerPrefix")," ",s.jsx("span",{className:"font-medium text-foreground/80",children:_.clawdhub.owner})]}),s.jsxs("span",{className:"flex items-center gap-1",children:[s.jsx(I,{name:"download",className:"h-3 w-3"}),_.clawdhub.downloads?.toLocaleString()??0]}),(_.clawdhub.stars??0)>0&&s.jsxs("span",{className:"flex items-center gap-1",children:[s.jsx(I,{name:"star",className:"h-3 w-3"}),_.clawdhub.stars]}),s.jsxs("span",{className:"bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:["v",_.clawdhub.version]})]}),_.warnings?.length?s.jsx("div",{className:"typography-micro text-[var(--status-warning)] mt-1.5 bg-[var(--status-warning)]/10 px-2 py-1 rounded w-fit",children:_.warnings.join(" · ")}):null]}),s.jsx(we,{variant:"outline",size:"xs",className:"!font-normal shrink-0",disabled:!_.installable,onClick:()=>{A(_),j(!0)},children:r("settings.skills.catalog.shared.actions.install")})]})},`${_.sourceId}:${_.skillDir}`)})})}),$&&B&&!h&&M.length>0&&s.jsx("div",{className:"flex justify-center mt-2 px-2",children:s.jsx(we,{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(Tk,{open:y,onOpenChange:k}),s.jsx(Bk,{open:D,onOpenChange:j,item:S}),s.jsx(ws,{open:C,onOpenChange:_=>{E||N(_)},children:s.jsxs(vs,{className:"max-w-md",children:[s.jsxs(Cs,{children:[s.jsx(js,{children:r("settings.skills.catalog.page.removeDialog.title")}),s.jsx(Rs,{children:r("settings.skills.catalog.page.removeDialog.description")})]}),s.jsxs(Ks,{children:[s.jsx(we,{size:"sm",variant:"ghost",onClick:()=>N(!1),disabled:E,children:r("settings.common.actions.cancel")}),s.jsx(we,{size:"sm",variant:"destructive",onClick:()=>{O()},disabled:E,children:r("settings.skills.catalog.page.actions.removeCatalog")})]})]})})]})})},Gk=()=>{const t=at.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Hk,{mode:"external",onModeChange:Jk,showModeTabs:!1}),t[0]=e):e=t[0],e},qk=()=>{const{t}=pt(),{selectedSkillName:e,getSkillByName:n,getSkillDetail:r,createSkill:a,updateSkill:i,skills:o,skillDraft:c,setSkillDraft:d,setSelectedSkill:p}=ea(pr(Y=>({selectedSkillName:Y.selectedSkillName,getSkillByName:Y.getSkillByName,getSkillDetail:Y.getSkillDetail,createSkill:Y.createSkill,updateSkill:Y.updateSkill,skills:Y.skills,skillDraft:Y.skillDraft,setSkillDraft:Y.setSkillDraft,setSelectedSkill:Y.setSelectedSkill}))),m=e?n(e):null,u=!!(c&&c.name===e&&!m),h=!!(e&&!m&&!c);l.useEffect(()=>{h&&p(null)},[h,p]);const[b,f]=l.useState(""),[v,x]=l.useState("user"),[g,w]=l.useState("opencode"),[y,k]=l.useState(""),[D,j]=l.useState(""),[S,A]=l.useState([]),[E,P]=l.useState([]),[C,N]=l.useState(!1),[T,M]=l.useState(!1),[R,L]=l.useState(""),[$,B]=l.useState(""),[O,_]=l.useState(!1),[ee,z]=l.useState(""),[ne,re]=l.useState(""),[ue,Q]=l.useState(null),[de,X]=l.useState(!1),[F,V]=l.useState(""),[q,te]=l.useState(null),[U,ae]=l.useState(!1),je=u?b.trim()!==""||y.trim()!==""||D.trim()!==""||E.length>0:y!==R||D!==$,oe=ue?ne!==F:ee.trim()!=="",ve=l.useCallback(Y=>{switch(Y){case"project-opencode":return t("settings.skills.location.option.projectOpencode.label");case"user-agents":return t("settings.skills.location.option.userAgents.label");case"project-agents":return t("settings.skills.location.option.projectAgents.label");default:return t("settings.skills.location.option.userOpencode.label")}},[t]),K=l.useCallback(Y=>{switch(Y){case"project-opencode":return t("settings.skills.location.option.projectOpencode.description");case"user-agents":return t("settings.skills.location.option.userAgents.description");case"project-agents":return t("settings.skills.location.option.projectAgents.description");default:return t("settings.skills.location.option.userOpencode.description")}},[t]);l.useEffect(()=>{(async()=>{if(u&&c)f(c.name||""),x(c.scope||"user"),w(c.source==="agents"?"agents":"opencode"),k(c.description||""),j(c.instructions||""),L(""),B(""),A([]),P(c.pendingFiles||[]);else if(e&&m){M(!0);try{const fe=await r(e);if(fe){const ke=fe.sources.md;k(ke.description||""),j(ke.instructions||""),L(ke.description||""),B(ke.instructions||""),A(ke.supportingFiles||[])}}catch(fe){console.error("Failed to load skill details:",fe)}finally{M(!1)}}})()},[m,u,e,o,c,r]);const ce=async()=>{const Y=u?b.trim().replace(/\s+/g,"-").toLowerCase():e?.trim();if(!Y){H.error(t("settings.skills.page.toast.skillNameRequired"));return}if(!/^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/.test(Y)||Y.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(fe=>fe.name===Y)){H.error(t("settings.skills.page.toast.skillExists"));return}N(!0);try{const fe={name:Y,description:y.trim(),instructions:D.trim()||void 0,scope:u?v:void 0,source:u?g:void 0,supportingFiles:u&&E.length>0?E:void 0};let ke;u?(ke=await a(fe),ke&&(d(null),P([]),p(Y))):(ke=await i(Y,fe),ke&&(L(y.trim()),B(D.trim()))),ke?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(fe){console.error("Error saving skill:",fe),H.error(t("settings.skills.page.toast.saveUnexpectedError"))}finally{N(!1)}},Z=()=>{Q(null),z(""),re(""),V(""),_(!0)},le=async Y=>{if(Q(Y),z(Y),u){const ke=E.find(be=>be.path===Y)?.content||"";re(ke),V(ke),_(!0);return}if(e){X(!0),_(!0);try{const{readSupportingFile:fe}=ea.getState(),ke=await fe(e,Y);re(ke||""),V(ke||"")}catch{H.error(t("settings.skills.page.toast.loadFileContentFailed")),re(""),V("")}finally{X(!1)}}},se=async()=>{if(!ee.trim()){H.error(t("settings.skills.page.toast.fileNameRequired"));return}const Y=ee.trim(),fe=ue!==null;if(u){if(fe)P(pe=>pe.map(Ee=>Ee.path===ue?{path:Y,content:ne}:Ee)),H.success(t("settings.skills.page.toast.fileUpdated",{path:Y}));else{if(E.some(pe=>pe.path===Y)){H.error(t("settings.skills.page.toast.fileExists"));return}P(pe=>[...pe,{path:Y,content:ne}]),H.success(t("settings.skills.page.toast.fileAdded",{path:Y}))}_(!1),Q(null);return}if(!e){H.error(t("settings.skills.page.toast.noSkillSelected"));return}const{writeSupportingFile:ke}=ea.getState();if(await ke(e,Y,ne)){H.success(fe?t("settings.skills.page.toast.fileUpdated",{path:Y}):t("settings.skills.page.toast.fileCreated",{path:Y})),_(!1),Q(null);const pe=await r(e);pe&&A(pe.sources.md.supportingFiles||[])}else H.error(t(fe?"settings.skills.page.toast.updateFileFailed":"settings.skills.page.toast.createFileFailed"))},Ie=Y=>{if(u){P(fe=>fe.filter(ke=>ke.path!==Y)),H.success(t("settings.skills.page.toast.fileRemoved",{path:Y}));return}e&&te(Y)},Ne=async()=>{if(!q||!e)return;ae(!0);const{deleteSupportingFile:Y}=ea.getState();if(await Y(e,q)){H.success(t("settings.skills.page.toast.fileDeleted",{path:q}));const ke=await r(e);ke&&A(ke.sources.md.supportingFiles||[]),te(null)}else H.error(t("settings.skills.page.toast.deleteFileFailed"));ae(!1)};return!e&&!c||h?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(I,{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")})]})}):T?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(Ts,{outerClassName:"h-full",className:"w-full",children:[s.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[s.jsx("div",{className:"mb-4",children:s.jsxs("div",{className:"min-w-0",children:[s.jsxs("h2",{className:"typography-ui-header font-semibold text-foreground truncate flex items-center gap-2",children:[u?t("settings.skills.page.title.newSkill"):e,m?.source==="claude"&&s.jsx("span",{className:"typography-micro font-normal bg-[var(--surface-muted)] text-muted-foreground px-1.5 py-0.5 rounded",children:t("settings.skills.page.badge.claudeCompatible")})]}),s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:m?t("settings.skills.page.subtitle.skillLocation",{location:ve(Ui(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(Kt,{value:b,onChange:Y=>f(Y.target.value.toLowerCase().replace(/\s+/g,"-")),placeholder:t("settings.skills.page.field.skillNamePlaceholder"),className:"h-7 w-40 px-2"}),s.jsxs(ds,{value:Ui(v,g),onValueChange:Y=>{const fe=tg(Y);x(fe.scope),w(fe.source==="agents"?"agents":"opencode")},children:[s.jsxs(us,{className:"w-fit gap-1.5",children:[v==="user"?s.jsx(I,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"folder",className:"h-3.5 w-3.5"}),g==="agents"?s.jsx(I,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:ve(Ui(v,g))})]}),s.jsx(ms,{align:"start",children:Yd.map(Y=>s.jsx(Lt,{value:Y.value,children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[Y.scope==="user"?s.jsx(I,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"folder",className:"h-3.5 w-3.5"}),Y.source==="agents"?s.jsx(I,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:ve(Y.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-6",children:K(Y.value)})]})},Y.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(bn,{value:y,onChange:Y=>k(Y.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(bn,{value:D,onChange:Y=>j(Y.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(we,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:Z,children:[s.jsx(I,{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 Y=u?E:S;return Y.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:Y.map(fe=>s.jsxs("div",{className:"flex items-center gap-2 py-1.5 cursor-pointer group",onClick:()=>le(fe.path),children:[s.jsx(I,{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:fe.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(we,{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:ke=>{ke.stopPropagation(),Ie(fe.path)},children:s.jsx(I,{name:"delete-bin",className:"h-3 w-3"})})]},fe.path))})})()})]}),s.jsx("div",{className:"px-2 py-1",children:s.jsx(we,{onClick:ce,disabled:C||!je,size:"xs",className:"!font-normal",children:t(C?"settings.common.actions.saving":u?"settings.skills.page.actions.createSkill":"settings.common.actions.saveChanges")})})]}),s.jsx(ws,{open:q!==null,onOpenChange:Y=>{!Y&&!U&&te(null)},children:s.jsxs(vs,{className:"max-w-md",children:[s.jsxs(Cs,{children:[s.jsx(js,{children:t("settings.skills.page.deleteFileDialog.title")}),s.jsx(Rs,{children:t("settings.skills.page.deleteFileDialog.description",{path:q??""})})]}),s.jsxs(Ks,{children:[s.jsx(we,{size:"sm",variant:"ghost",onClick:()=>te(null),disabled:U,children:t("settings.common.actions.cancel")}),s.jsx(we,{size:"sm",variant:"destructive",onClick:Ne,disabled:U,children:t("settings.common.actions.delete")})]})]})}),s.jsx(ws,{open:O,onOpenChange:Y=>{_(Y),Y||Q(null)},children:s.jsxs(vs,{className:"max-w-3xl max-h-[85vh] flex flex-col",children:[s.jsxs(Cs,{className:"flex-shrink-0",children:[s.jsx(js,{children:t(ue?"settings.skills.page.fileDialog.titleEdit":"settings.skills.page.fileDialog.titleAdd")}),s.jsx(Rs,{children:t(ue?"settings.skills.page.fileDialog.descriptionEdit":"settings.skills.page.fileDialog.descriptionAdd")})]}),de?s.jsx("div",{className:"flex-1 flex items-center justify-center py-8",children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.skills.page.loading.fileContent")})}):s.jsxs("div",{className:"space-y-4 flex-1 min-h-0 flex flex-col pt-2",children:[s.jsxs("div",{className:"space-y-2 flex-shrink-0",children:[s.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:t("settings.skills.page.fileDialog.field.filePath")}),s.jsx(Kt,{value:ee,onChange:Y=>z(Y.target.value),placeholder:t("settings.skills.page.fileDialog.field.filePathPlaceholder"),className:"text-foreground placeholder:text-muted-foreground focus-visible:ring-[var(--primary-base)]",disabled:ue!==null}),!ue&&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(bn,{value:ne,onChange:Y=>re(Y.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(Ks,{className:"mt-4",children:[s.jsx(we,{size:"sm",variant:"ghost",onClick:()=>{_(!1),Q(null)},children:t("settings.common.actions.cancel")}),s.jsx(we,{size:"sm",onClick:se,disabled:de||!oe,children:t(ue?"settings.common.actions.saveChanges":"settings.skills.page.actions.createFile")})]})]})})]})},rp=t=>{const e=at.c(2),{view:n}=t,r=n===void 0?"installed":n;let a;return e[0]!==r?(a=r==="catalog"?s.jsx(Gk,{}):s.jsx(qk,{}),e[0]=r,e[1]=a):a=e[1],a};function Jk(){}const sg=t=>{const e=at.c(26),{header:n,footer:r,children:a,className:i,variant:o}=t,c=o===void 0?"sidebar":o,d=dn(),p=l.useRef(null),[m,u]=l.useState(!1),[h,b]=l.useState(!1),f=c==="background"||d?"bg-background":"bg-sidebar",v=f==="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 k,D;e[4]===Symbol.for("react.memo_cache_sentinel")?(k=()=>{const N=p.current;if(!N)return;const T=()=>g();return N.addEventListener("scroll",T,{passive:!0}),()=>N.removeEventListener("scroll",T)},D=[g],e[4]=k,e[5]=D):(k=e[4],D=e[5]),l.useEffect(k,D);let j;e[6]!==f||e[7]!==i?(j=me("flex h-full flex-col",f,i),e[6]=f,e[7]=i,e[8]=j):j=e[8];let S;e[9]!==a?(S=s.jsx(Ts,{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 A;e[11]!==v||e[12]!==m?(A=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]=A):A=e[13];let E;e[14]!==v||e[15]!==h?(E=h&&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]=h,e[16]=E):E=e[16];let P;e[17]!==E||e[18]!==S||e[19]!==A?(P=s.jsxs("div",{className:"relative flex flex-1 min-h-0 flex-col",children:[S,A,E]}),e[17]=E,e[18]=S,e[19]=A,e[20]=P):P=e[20];let C;return e[21]!==r||e[22]!==n||e[23]!==P||e[24]!==j?(C=s.jsxs("div",{className:j,children:[n,P,r]}),e[21]=r,e[22]=n,e[23]=P,e[24]=j,e[25]=C):C=e[25],C},ng=t=>{const e=at.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 h;e[0]!==d||e[1]!==u?(h=me("group relative flex items-center rounded-md px-1.5 py-0.5 transition-all duration-200",u,d),e[0]=d,e[1]=u,e[2]=h):h=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 f;e[5]!==o||e[6]!==b?(f=s.jsxs("div",{className:"flex items-center gap-1.5",children:[o,b]}),e[5]=o,e[6]=b,e[7]=f):f=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]!==f||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:[f,v]}),e[10]=i,e[11]=f,e[12]=v,e[13]=x):x=e[13];let g;e[14]!==c||e[15]!==m?(g=m&&s.jsxs(Bs,{children:[s.jsx(Os,{asChild:!0,children:s.jsx(we,{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(I,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx($s,{align:"end",className:"w-fit min-w-20",children:c.map(Qk)})]}),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]!==h||e[21]!==w?(y=s.jsx("div",{className:h,children:w}),e[20]=h,e[21]=w,e[22]=y):y=e[22],y};function Qk(t){const e=t.icon;return s.jsxs(zt,{onClick:n=>{n.stopPropagation(),t.onClick()},className:me(t.destructive&&"text-destructive focus:text-destructive"),children:[e&&s.jsx(I,{name:e,className:"h-4 w-4 mr-px"}),t.label]},t.label)}const Yk=t=>{const e=at.c(41),{onItemSelect:n}=t,{t:r}=pt(),a=Fs(Xk),i=Te(Zk),o=Te(e3),{currentTheme:c}=jr();let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=new Set,e[0]=d):d=e[0];const[p,m]=l.useState(d);let u;e[1]===Symbol.for("react.memo_cache_sentinel")?(u=dn(),e[1]=u):u=e[1];const h=u,b=t3;let f,v;e[2]!==a||e[3]!==i||e[4]!==o?(f=()=>{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]=f,e[6]=v):(f=e[5],v=e[6]),l.useEffect(f,v);let x;e[7]===Symbol.for("react.memo_cache_sentinel")?(x=me("border-b px-3","pt-4 pb-3"),e[7]=x):x=e[7];let g;e[8]!==r?(g=r("settings.page.projects.title"),e[8]=r,e[9]=g):g=e[9];let w;e[10]!==g?(w=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:g}),e[10]=g,e[11]=w):w=e[11];let 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 k;e[15]!==y?(k=s.jsx("span",{className:"typography-meta text-muted-foreground",children:y}),e[15]=y,e[16]=k):k=e[16];let D;e[17]!==r?(D=!h&&s.jsx(we,{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(I,{name:"add",className:"size-4"})}),e[17]=r,e[18]=D):D=e[18];let j;e[19]!==D||e[20]!==k?(j=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[k,D]}),e[19]=D,e[20]=k,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 A;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=C=>{const N=C.id===i,T=C.icon?Al[C.icon]:null,M=`${C.id}:${C.iconImage?.updatedAt??0}`,R=p.has(M)?null:no(C,{themeVariant:c.metadata.variant,iconColor:c.colors.surface.foreground}),L=C.color?ro[C.color]??null:null,$=R?s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center overflow-hidden rounded-[2px]",style:C.iconBackground?{backgroundColor:C.iconBackground}:void 0,children:s.jsx("img",{src:R,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>{m(B=>{if(B.has(M))return B;const O=new Set(B);return O.add(M),O})}})}):T?s.jsx(I,{name:T,className:me("h-4 w-4",N?"text-foreground":"text-muted-foreground/70"),style:L?{color:L}:void 0}):s.jsx(I,{name:"folder",className:me("h-4 w-4",N?"text-foreground":"text-muted-foreground/70"),style:L?{color:L}:void 0});return s.jsx(ng,{title:C.label||C.path,icon:$,selected:N,onSelect:()=>{o(C.id),n?.()}},C.id)},e[32]=p,e[33]=c,e[34]=n,e[35]=i,e[36]=o,e[37]=P):P=e[37],A=a.map(P),e[25]=p,e[26]=c,e[27]=n,e[28]=a,e[29]=i,e[30]=o,e[31]=A}else A=e[31];let E;return e[38]!==S||e[39]!==A?(E=s.jsx(sg,{variant:"background",header:S,children:A}),e[38]=S,e[39]=A,e[40]=E):E=e[40],E};function Xk(t){return t.projects}function Zk(t){return t.settingsProjectsSelectedId}function e3(t){return t.setSettingsProjectsSelectedId}function t3(){yr.requestDirectoryDialog()}const s3=({projectRef:t=null})=>{const{t:e}=pt(),{isMobile:n,isTablet:r}=an(),a=n||r,i=Fs(T=>T.getActiveProject()),o=t?.path??i?.path??null,c=Vt(T=>T.getWorktreeMetadata),d=Pl(),p=Vs(T=>T.homeDirectory),[m,u]=l.useState([]),[h,b]=l.useState(!1),[f,v]=l.useState(null),[x,g]=l.useState([]),[w,y]=l.useState(!1),k=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]),D=l.useCallback(async()=>{if(!(!k||f===!1))try{const T=await Kc(k);g(T)}catch{}},[k,f]);l.useEffect(()=>{if(!o)return;let T=!1;return v(null),(async()=>{try{const M=await Uh(o);if(T)return;v(M)}catch{}})(),()=>{T=!0}},[o]),l.useEffect(()=>{if(!k){g([]),y(!1);return}if(f===!1){g([]),y(!1);return}let T=!1;return y(!0),g([]),(async()=>{try{const M=await Kc(k);if(T)return;g(M)}catch{}finally{T||y(!1)}})(),()=>{T=!0}},[k,f]),l.useEffect(()=>{if(!k)return;let T=!1;return b(!0),(async()=>{try{const M=await $d(k);T||u(M.length>0?M:[""])}catch{T||u([""])}finally{T||b(!1)}})(),()=>{T=!0}},[k]);const j=l.useCallback((T,M)=>{u(R=>{const L=[...R];return L[T]=M,L})},[]),S=l.useCallback(()=>{u(T=>[...T,""])},[]),A=l.useCallback(async T=>{if(!k)return;const M=T.filter(R=>R.trim().length>0);await Wh(k,M)},[k]),E=l.useCallback(T=>{u(M=>{const R=M.filter((L,$)=>$!==T);return A(R),R.length>0?R:[""]})},[A]),P=l.useCallback(()=>{A(m)},[A,m]),C=l.useCallback(T=>{const M=z=>z.replace(/\\/g,"/").replace(/\/+$/,""),R=M(T.path),L=d.filter(z=>{const ne=c(z.id);if(ne?.path&&M(ne.path)===R)return!0;const re=z.directory;return!!(re&&M(re)===R)}),$=new Set(L.map(z=>z.id)),B=z=>{const ne=d.filter(ue=>{const Q=ue.parentID;return Q&&z.has(Q)});if(ne.length===0)return[];const re=new Set(ne.map(ue=>ue.id));return[...ne,...B(re)]},O=B($),_=new Set,ee=[...L,...O].filter(z=>_.has(z.id)?!1:(_.add(z.id),!0));yr.requestDelete({sessions:ee,mode:"worktree",worktree:T})},[d,c]),N=l.useMemo(()=>d.map(T=>T.id).join(","),[d]);return l.useEffect(()=>{f&&o&&D()},[N,f,o,D]),o?f===!1?s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.worktrees.state.gitOnly")}):s.jsxs("div",{className:"max-w-[44rem] space-y-5",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-normal text-foreground",children:e("settings.openchamber.worktrees.setup.title")}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsxs(Pt,{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")]})]})]})}),h?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((T,M)=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(Kt,{value:T,onChange:R=>j(M,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:()=>{E(M)},className:"flex-shrink-0 flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("settings.openchamber.worktrees.setup.removeCommandAria"),children:s.jsx(I,{name:"close",className:"h-4 w-4"})})]},M)),s.jsxs(we,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:S,children:[s.jsx(I,{name:"add",className:"h-3.5 w-3.5"}),e("settings.openchamber.worktrees.setup.addCommand")]})]})]}),s.jsxs("div",{className:"space-y-2 border-t border-border/40 pt-4",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-normal text-foreground",children:e("settings.openchamber.worktrees.list.title")}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{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(T=>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:T.label||T.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:Hi(T.path,p)})]}),s.jsx("button",{type:"button",onClick:()=>C(T),className:me("flex-shrink-0 flex h-7 w-7 items-center justify-center rounded text-muted-foreground/50 hover:text-destructive hover:bg-destructive/10 transition-opacity focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",a?"opacity-100":"opacity-0 group-hover:opacity-100"),"aria-label":e("settings.openchamber.worktrees.list.deleteWorktreeAria",{name:T.branch||T.label||T.path}),children:s.jsx(I,{name:"delete-bin",className:"h-4 w-4"})})]},T.path))})]})]}):s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.worktrees.state.selectProject")})},n3=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`action_${Date.now()}_${Math.random().toString(36).slice(2,7)}`,r3=()=>({id:n3(),name:"",command:"",icon:"play"}),a3=({projectRef:t})=>{const{t:e}=pt(),n=l.useMemo(()=>yn(),[]),r=Js(S=>S.instances),a=Js(S=>S.load),[i,o]=l.useState([]),[c,d]=l.useState(!1),[p,m]=l.useState(!1),[u,h]=l.useState(null),[b,f]=l.useState({});l.useEffect(()=>{n&&a().catch(()=>{})},[n,a]),l.useEffect(()=>{let S=!1;return d(!0),(async()=>{try{const A=await Wc(t);if(S)return;o(A.actions),h(JSON.stringify({actions:A.actions}))}catch{if(S)return;o([]),h(JSON.stringify({actions:[]}))}finally{S||d(!1)}})(),()=>{S=!0}},[t]);const v=l.useMemo(()=>n?gf(r):[],[r,n]),x=l.useMemo(()=>i.some(A=>A.name.trim().length===0||A.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=r3();o(A=>[...A,S]),f(A=>({...A,[S.id]:!0}))},[]),y=l.useCallback(S=>{o(A=>A.filter(E=>E.id!==S)),f(A=>{const E={...A};return delete E[S],E})},[]),k=l.useCallback((S,A)=>{o(E=>E.map(P=>P.id===S?A(P):P))},[]),D=l.useCallback(async()=>{if(x){H.error(x);return}m(!0);try{if(!await jb(t,{actions:i,primaryActionId:null})){H.error(e("settings.projects.actions.toast.saveFailed"));return}h(JSON.stringify({actions:i})),typeof window<"u"&&window.dispatchEvent(new CustomEvent(Xc,{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(we,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:w,children:[s.jsx(I,{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 A=S.icon||"play",E=Vo[A]||"play",P=b[S.id]??!1,C=S.name.trim()||e("settings.projects.actions.state.untitled");return s.jsxs(ur,{open:P,onOpenChange:N=>{f(T=>({...T,[S.id]:N}))},className:me("py-1.5"),children:[s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs(wr,{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(I,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(I,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"}),s.jsx(I,{name:E,className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),s.jsx("div",{className:"min-w-0 flex-1",children:s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:C})})})]}),s.jsx(we,{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(I,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),s.jsx(mr,{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(Bs,{children:[s.jsx(Os,{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(I,{name:E,className:"h-4 w-4"})})}),s.jsx($s,{align:"start",className:"w-56 p-2",children:s.jsx("div",{className:"grid grid-cols-6 gap-1",children:hf.map(N=>{const T=N.Icon,M=(S.icon||"play")===N.key;return s.jsx("button",{type:"button",onClick:()=>k(S.id,R=>({...R,icon:N.key})),className:me("inline-flex h-8 w-8 items-center justify-center rounded-md border border-transparent text-foreground hover:bg-[var(--interactive-hover)]",M&&"border-[var(--primary-base)] bg-[var(--primary-base)]/10 text-[var(--primary-base)]"),"aria-label":e("settings.projects.actions.field.iconAria",{icon:N.label}),children:s.jsx(I,{name:T,className:"h-4 w-4"})},N.key)})})})]}),s.jsx(Kt,{value:S.name,onChange:N=>k(S.id,T=>({...T,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(bn,{value:S.command,onChange:N=>k(S.id,T=>({...T,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:()=>k(S.id,N=>({...N,...N.autoOpenUrl===!0?{autoOpenUrl:void 0}:{autoOpenUrl:!0}})),onKeyDown:N=>{(N.key===" "||N.key==="Enter")&&(N.preventDefault(),k(S.id,T=>({...T,...T.autoOpenUrl===!0?{autoOpenUrl:void 0}:{autoOpenUrl:!0}})))},children:[s.jsx(xs,{checked:S.autoOpenUrl===!0,onChange:N=>k(S.id,T=>({...T,...N?{autoOpenUrl:!0}:{autoOpenUrl:void 0}})),ariaLabel:e("settings.projects.actions.field.autoOpenUrlForAria",{title:C})}),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(Kt,{value:S.openUrl||"",onChange:N=>k(S.id,T=>({...T,openUrl:N.target.value})),placeholder:e("settings.projects.actions.field.overrideUrlPlaceholder"),className:"h-7 w-full max-w-[24rem]"}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{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(ds,{value:S.desktopOpenSshForward&&v.some(N=>N.id===S.desktopOpenSshForward)?S.desktopOpenSshForward:"__none__",onValueChange:N=>{k(S.id,T=>({...T,...N==="__none__"?{desktopOpenSshForward:void 0}:{desktopOpenSshForward:N}}))},children:[s.jsx(us,{className:"h-7 w-full max-w-[30rem]",children:s.jsx(ys,{placeholder:e("settings.projects.actions.field.useOutputManualUrl")})}),s.jsxs(ms,{children:[s.jsx(Lt,{value:"__none__",children:e("settings.projects.actions.field.useOutputManualUrl")}),v.map(N=>s.jsx(Lt,{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(we,{type:"button",size:"xs",className:"!font-normal",onClick:D,disabled:!j,children:e(p?"settings.common.actions.saving":"settings.projects.actions.actions.save")})]})]})]})},i3=()=>{const t=at.c(201),{t:e}=pt(),n=Fs(o3),r=Fs(l3),a=Fs(c3),i=Fs(d3),o=Fs(u3),c=Te(m3),d=Te(p3),{currentTheme:p}=jr();let m;e:{if(!c){m=null;break e}let wt;t[0]!==n||t[1]!==c?(wt=n.find($t=>$t.id===c)??null,t[0]=n,t[1]=c,t[2]=wt):wt=t[2],m=wt}const u=m;let h,b;t[3]!==n||t[4]!==c||t[5]!==d?(h=()=>{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]=h,t[7]=b):(h=t[6],b=t[7]),l.useEffect(h,b);const[f,v]=l.useState(""),[x,g]=l.useState(null),[w,y]=l.useState(null),[k,D]=l.useState(null),[j,S]=l.useState(!1),[A,E]=l.useState(!1),[P,C]=l.useState(!1),[N,T]=l.useState(!1),[M,R]=l.useState(null),[L,$]=l.useState(null),[B,O]=l.useState(!1),_=l.useRef(null);let ee;t[8]===Symbol.for("react.memo_cache_sentinel")?(ee=()=>{R(null),$(h3)},t[8]=ee):ee=t[8];const z=ee;let ne;e:{if(!u){ne=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],ne=wt}const re=ne;let ue,Q;t[12]!==u?(ue=()=>{if(!u){v(""),g(null),y(null),D(null);return}v(u.label??""),g(u.icon??null),y(u.color??null),D(u.iconBackground??null),T(!1),z(),O(!1)},Q=[u,z],t[12]=u,t[13]=ue,t[14]=Q):(ue=t[13],Q=t[14]),l.useEffect(ue,Q);let de,X;t[15]===Symbol.for("react.memo_cache_sentinel")?(de=()=>()=>{z()},X=[z],t[15]=de,t[16]=X):(de=t[15],X=t[16]),l.useEffect(de,X);let F;t[17]!==w||t[18]!==x||t[19]!==k||t[20]!==f||t[21]!==N||t[22]!==M||t[23]!==u?(F=!!u&&(f.trim()!==(u?.label??"").trim()||x!==(u?.icon??null)||w!==(u?.color??null)||k!==(u?.iconBackground??null)||N||!!M),t[17]=w,t[18]=x,t[19]=k,t[20]=f,t[21]=N,t[22]=M,t[23]=u,t[24]=F):F=t[24];const V=F;let q;t[25]!==w||t[26]!==x||t[27]!==k||t[28]!==f||t[29]!==N||t[30]!==M||t[31]!==i||t[32]!==u||t[33]!==e||t[34]!==r||t[35]!==a?(q=async()=>{if(!u)return;if(M){S(!0);const $t=await a(u.id,M);if(S(!1),!$t.ok){H.error($t.error||e("settings.projects.page.toast.uploadIconFailed"));return}H.success(e("settings.projects.page.toast.iconUpdated")),z(),T(!1)}const wt=N&&!!u.iconImage;if(wt){E(!0);const $t=await i(u.id);if(E(!1),!$t.ok){H.error($t.error||e("settings.projects.page.toast.removeIconFailed"));return}H.success(e("settings.projects.page.toast.iconRemoved")),T(!1),D(null)}r(u.id,{label:f.trim(),icon:x,color:w,iconBackground:wt?null:k})},t[25]=w,t[26]=x,t[27]=k,t[28]=f,t[29]=N,t[30]=M,t[31]=i,t[32]=u,t[33]=e,t[34]=r,t[35]=a,t[36]=q):q=t[36];const te=q,U=w?ro[w]??null:null,ae=!!u?.iconImage,je=!!(M&&L),oe=u?.iconImage?.source==="custom",ve=ae&&!N||je,K=ve;let ce;t[37]!==p||t[38]!==je||t[39]!==ae||t[40]!==N||t[41]!==L||t[42]!==B||t[43]!==u?(ce=B?null:je?L:u&&ae&&!N?no(u,{themeVariant:p.metadata.variant,iconColor:p.colors.surface.foreground}):null,t[37]=p,t[38]=je,t[39]=ae,t[40]=N,t[41]=L,t[42]=B,t[43]=u,t[44]=ce):ce=t[44];const Z=ce;let le;t[45]!==j||t[46]!==u?(le=wt=>{!u||!wt||j||(T(!1),O(!1),R(wt),$($t=>($t&&URL.revokeObjectURL($t),URL.createObjectURL(wt))))},t[45]=j,t[46]=u,t[47]=le):le=t[47];const se=le;let Ie;t[48]!==je||t[49]!==K||t[50]!==ae||t[51]!==A||t[52]!==u?(Ie=()=>{!u||!K||A||(je&&z(),T(!!ae),O(!1))},t[48]=je,t[49]=K,t[50]=ae,t[51]=A,t[52]=u,t[53]=Ie):Ie=t[53];const Ne=Ie;let Y;t[54]!==o||t[55]!==P||t[56]!==u||t[57]!==e?(Y=async()=>{!u||P||(z(),T(!1),O(!1),C(!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(()=>{C(!1)}))},t[54]=o,t[55]=P,t[56]=u,t[57]=e,t[58]=Y):Y=t[58];const fe=Y;if(!u){let wt;t[59]!==e?(wt=e("settings.projects.page.empty.noProjects"),t[59]=e,t[60]=wt):wt=t[60];let $t;return t[61]!==wt?($t=s.jsx(Ts,{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]=$t):$t=t[62],$t}let ke;t[63]!==u.label||t[64]!==e?(ke=u.label??e("settings.projects.page.title.default"),t[63]=u.label,t[64]=e,t[65]=ke):ke=t[65];let be;t[66]!==ke?(be=s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:ke}),t[66]=ke,t[67]=be):be=t[67];let pe;t[68]!==u.path?(pe=s.jsx("p",{className:"typography-meta text-muted-foreground truncate",title:u.path,children:u.path}),t[68]=u.path,t[69]=pe):pe=t[69];let Ee;t[70]!==be||t[71]!==pe?(Ee=s.jsx("div",{className:"mb-4 flex items-center justify-between gap-4",children:s.jsxs("div",{className:"min-w-0",children:[be,pe]})}),t[70]=be,t[71]=pe,t[72]=Ee):Ee=t[72];let ze;t[73]!==e?(ze=e("settings.projects.page.field.projectName"),t[73]=e,t[74]=ze):ze=t[74];let G;t[75]!==ze?(G=s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:ze})}),t[75]=ze,t[76]=G):G=t[76];let Pe;t[77]===Symbol.for("react.memo_cache_sentinel")?(Pe=wt=>v(wt.target.value),t[77]=Pe):Pe=t[77];let Le;t[78]!==e?(Le=e("settings.projects.page.field.projectNamePlaceholder"),t[78]=e,t[79]=Le):Le=t[79];let Ae;t[80]!==f||t[81]!==Le?(Ae=s.jsx("div",{className:"mt-1.5 flex min-w-0 items-center gap-2",children:s.jsx(Kt,{value:f,onChange:Pe,placeholder:Le,className:"h-7 min-w-0 w-full sm:max-w-[19rem]"})}),t[80]=f,t[81]=Le,t[82]=Ae):Ae=t[82];let ge;t[83]!==G||t[84]!==Ae?(ge=s.jsxs("div",{className:"py-1.5",children:[G,Ae]}),t[83]=G,t[84]=Ae,t[85]=ge):ge=t[85];let W;t[86]!==e?(W=e("settings.projects.page.field.accentColor"),t[86]=e,t[87]=W):W=t[87];let ie;t[88]!==W?(ie=s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:W})}),t[88]=W,t[89]=ie):ie=t[89];let Me;t[90]===Symbol.for("react.memo_cache_sentinel")?(Me=()=>y(null),t[90]=Me):Me=t[90];const Ve=w===null?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-border/40 hover:border-border hover:bg-[var(--surface-muted)]";let Ce;t[91]!==Ve?(Ce=me("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",Ve),t[91]=Ve,t[92]=Ce):Ce=t[92];let xe;t[93]!==e?(xe=e("settings.projects.page.field.none"),t[93]=e,t[94]=xe):xe=t[94];let De;t[95]===Symbol.for("react.memo_cache_sentinel")?(De=s.jsx(I,{name:"close",className:"h-4 w-4 text-muted-foreground"}),t[95]=De):De=t[95];let Ye;t[96]!==Ce||t[97]!==xe?(Ye=s.jsx("button",{type:"button",onClick:Me,className:Ce,title:xe,children:De}),t[96]=Ce,t[97]=xe,t[98]=Ye):Ye=t[98];let rt;t[99]!==w?(rt=Nb.map(wt=>s.jsx("button",{type:"button",onClick:()=>y(wt.key),className:me("h-7 w-7 rounded-md border transition-colors",w===wt.key?"border-2 border-foreground ring-1 ring-[var(--primary-base)]/40":"border-transparent hover:border-border/70"),style:{backgroundColor:wt.cssVar},title:wt.label},wt.key)),t[99]=w,t[100]=rt):rt=t[100];let Re;t[101]!==Ye||t[102]!==rt?(Re=s.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-2",children:[Ye,rt]}),t[101]=Ye,t[102]=rt,t[103]=Re):Re=t[103];let he;t[104]!==ie||t[105]!==Re?(he=s.jsxs("div",{className:"py-1.5",children:[ie,Re]}),t[104]=ie,t[105]=Re,t[106]=he):he=t[106];let qe;t[107]!==e?(qe=e("settings.projects.page.field.projectIcon"),t[107]=e,t[108]=qe):qe=t[108];let et;t[109]!==qe?(et=s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:qe})}),t[109]=qe,t[110]=et):et=t[110];let Ke;t[111]!==se?(Ke=s.jsx("input",{ref:_,type:"file",accept:"image/png,image/jpeg,image/svg+xml,.png,.jpg,.jpeg,.svg",className:"hidden",onChange:wt=>{const $t=wt.target.files?.[0]??null;se($t),wt.currentTarget.value=""}}),t[111]=se,t[112]=Ke):Ke=t[112];let st;t[113]===Symbol.for("react.memo_cache_sentinel")?(st=()=>g(null),t[113]=st):st=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 ye;t[114]!==nt?(ye=me("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",nt),t[114]=nt,t[115]=ye):ye=t[115];let Je;t[116]!==e?(Je=e("settings.projects.page.field.none"),t[116]=e,t[117]=Je):Je=t[117];let _e;t[118]===Symbol.for("react.memo_cache_sentinel")?(_e=s.jsx(I,{name:"close",className:"h-4 w-4 text-muted-foreground"}),t[118]=_e):_e=t[118];let Ue;t[119]!==ye||t[120]!==Je?(Ue=s.jsx("button",{type:"button",onClick:st,className:ye,title:Je,children:_e}),t[119]=ye,t[120]=Je,t[121]=Ue):Ue=t[121];let ot;t[122]!==U||t[123]!==x?(ot=Sb.map(wt=>{const $t=wt.Icon;return s.jsx("button",{type:"button",onClick:()=>g(wt.key),className:me("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",x===wt.key?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-transparent hover:border-border hover:bg-[var(--surface-muted)]"),title:wt.label,children:s.jsx(I,{name:$t,className:"w-4 h-4",style:U&&x===wt.key?{color:U}:void 0})},wt.key)}),t[122]=U,t[123]=x,t[124]=ot):ot=t[124];let Xe;t[125]!==Ue||t[126]!==ot?(Xe=s.jsxs("div",{className:"mt-1.5 flex max-w-[22rem] flex-wrap items-center gap-2",children:[Ue,ot]}),t[125]=Ue,t[126]=ot,t[127]=Xe):Xe=t[127];let We;t[128]!==ve||t[129]!==k||t[130]!==Z||t[131]!==e?(We=ve&&Z&&s.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.projects.page.field.preview")}),s.jsx("span",{className:"inline-flex h-7 w-7 items-center justify-center rounded-md border border-border/60 bg-[var(--surface-elevated)] p-1",children:s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center overflow-hidden rounded-[2px]",style:k?{backgroundColor:k}:void 0,children:s.jsx("img",{src:Z,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>O(!0)})})})]}),t[128]=ve,t[129]=k,t[130]=Z,t[131]=e,t[132]=We):We=t[132];let bt;t[133]!==ve||t[134]!==k||t[135]!==e?(bt=ve&&s.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[s.jsx("input",{type:"color",value:k??"#000000",onChange:wt=>D(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(Kt,{value:k??"",onChange:wt=>D(wt.target.value),placeholder:"#000000",className:"h-7 w-[8rem]"}),s.jsx(we,{type:"button",size:"xs",variant:"outline",onClick:()=>D(null),className:"h-7 w-7 p-0","aria-label":e("settings.projects.page.field.clearIconBackgroundAria"),title:e("settings.projects.page.field.clearBackground"),disabled:!k,children:s.jsx(I,{name:"close",className:"h-3.5 w-3.5"})})]}),t[133]=ve,t[134]=k,t[135]=e,t[136]=bt):bt=t[136];let Dt;t[137]!==fe||t[138]!==oe||t[139]!==P||t[140]!==j||t[141]!==e?(Dt=!oe&&s.jsxs(s.Fragment,{children:[s.jsx(we,{size:"xs",className:"h-6 !font-normal",onClick:()=>_.current?.click(),disabled:j,children:e(j?"settings.projects.page.actions.uploading":"settings.projects.page.actions.uploadIcon")}),s.jsx(we,{size:"xs",className:"h-6 !font-normal",variant:"outline",onClick:()=>{fe()},disabled:P,children:e(P?"settings.projects.page.actions.discovering":"settings.projects.page.actions.discoverFavicon")})]}),t[137]=fe,t[138]=oe,t[139]=P,t[140]=j,t[141]=e,t[142]=Dt):Dt=t[142];let Ht;t[143]!==Ne||t[144]!==K||t[145]!==A||t[146]!==e?(Ht=K&&s.jsx(we,{size:"xs",className:"!font-normal",variant:"outline",onClick:()=>{Ne()},disabled:A,children:e(A?"settings.projects.page.actions.removing":"settings.projects.page.actions.removeProjectIcon")}),t[143]=Ne,t[144]=K,t[145]=A,t[146]=e,t[147]=Ht):Ht=t[147];let rs;t[148]!==A||t[149]!==N||t[150]!==e?(rs=N&&s.jsx(we,{size:"xs",className:"!font-normal",variant:"outline",onClick:()=>T(!1),disabled:A,children:e("settings.projects.page.actions.undoRemove")}),t[148]=A,t[149]=N,t[150]=e,t[151]=rs):rs=t[151];let jt;t[152]!==Dt||t[153]!==Ht||t[154]!==rs?(jt=s.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[Dt,Ht,rs]}),t[152]=Dt,t[153]=Ht,t[154]=rs,t[155]=jt):jt=t[155];let St;t[156]!==et||t[157]!==Ke||t[158]!==Xe||t[159]!==We||t[160]!==bt||t[161]!==jt?(St=s.jsxs("div",{className:"py-1.5",children:[et,Ke,Xe,We,bt,jt]}),t[156]=et,t[157]=Ke,t[158]=Xe,t[159]=We,t[160]=bt,t[161]=jt,t[162]=St):St=t[162];let ns;t[163]!==ge||t[164]!==he||t[165]!==St?(ns=s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[ge,he,St]}),t[163]=ge,t[164]=he,t[165]=St,t[166]=ns):ns=t[166];let ut;t[167]!==V||t[168]!==A||t[169]!==j||t[170]!==f?(ut=!V||f.trim().length===0||j||A,t[167]=V,t[168]=A,t[169]=j,t[170]=f,t[171]=ut):ut=t[171];let Gt;t[172]!==e?(Gt=e("settings.common.actions.saveChanges"),t[172]=e,t[173]=Gt):Gt=t[173];let Xt;t[174]!==te||t[175]!==ut||t[176]!==Gt?(Xt=s.jsx("div",{className:"mt-0.5 px-2 py-1",children:s.jsx(we,{onClick:te,disabled:ut,size:"xs",className:"!font-normal",children:Gt})}),t[174]=te,t[175]=ut,t[176]=Gt,t[177]=Xt):Xt=t[177];let Wt;t[178]!==ns||t[179]!==Xt?(Wt=s.jsxs("div",{className:"mb-8",children:[ns,Xt]}),t[178]=ns,t[179]=Xt,t[180]=Wt):Wt=t[180];let is;t[181]!==re?(is=re&&s.jsx(a3,{projectRef:re}),t[181]=re,t[182]=is):is=t[182];let gs;t[183]!==is?(gs=s.jsx("div",{className:"mb-8",children:s.jsx("section",{className:"px-2 pb-2 pt-0",children:is})}),t[183]=is,t[184]=gs):gs=t[184];let ps;t[185]!==e?(ps=e("settings.projects.page.section.worktree"),t[185]=e,t[186]=ps):ps=t[186];let Ns;t[187]!==ps?(Ns=s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:ps})}),t[187]=ps,t[188]=Ns):Ns=t[188];let Mt;t[189]!==re?(Mt=re&&s.jsx(s3,{projectRef:re}),t[189]=re,t[190]=Mt):Mt=t[190];let He;t[191]!==Mt?(He=s.jsx("section",{className:"px-2 pb-2 pt-0",children:Mt}),t[191]=Mt,t[192]=He):He=t[192];let At;t[193]!==Ns||t[194]!==He?(At=s.jsxs("div",{className:"mb-8",children:[Ns,He]}),t[193]=Ns,t[194]=He,t[195]=At):At=t[195];let Et;return t[196]!==Ee||t[197]!==Wt||t[198]!==gs||t[199]!==At?(Et=s.jsx(Ts,{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:[Ee,Wt,gs,At]})}),t[196]=Ee,t[197]=Wt,t[198]=gs,t[199]=At,t[200]=Et):Et=t[200],Et};function o3(t){return t.projects}function l3(t){return t.updateProjectMeta}function c3(t){return t.uploadProjectIcon}function d3(t){return t.removeProjectIcon}function u3(t){return t.discoverProjectIcon}function m3(t){return t.settingsProjectsSelectedId}function p3(t){return t.setSettingsProjectsSelectedId}function h3(t){return t&&URL.revokeObjectURL(t),null}const f3=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`,g3=()=>Math.floor(2e4+Math.random()*3e4),x3=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")},b3=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"}},y3=({onItemSelect:t})=>{const{t:e}=pt(),n=Js(g=>g.instances),r=Js(g=>g.statusesById),a=Js(g=>g.isLoading),i=Js(g=>g.load),o=Js(g=>g.loadImports),c=Js(g=>g.createFromCommand),d=Js(g=>g.connect),p=Js(g=>g.disconnect),m=Js(g=>g.retry),u=Js(g=>g.removeInstance),h=Js(g=>g.upsertInstance),b=Te(g=>g.settingsRemoteInstancesSelectedId),f=Te(g=>g.setSettingsRemoteInstancesSelectedId);l.useEffect(()=>{i(),o()},[i,o]),l.useEffect(()=>{if(!a){if(n.length===0){b!==null&&f(null);return}b&&n.some(g=>g.id===b)||f(n[0].id)}},[n,a,b,f]);const v=l.useCallback(async()=>{const g=f3();try{await c(g,"ssh user@example.com",e("settings.remoteInstances.sidebar.newSshInstanceName")),f(g),t?.()}catch(w){H.error(e("settings.remoteInstances.sidebar.toast.createFailed"),{description:w instanceof Error?w.message:String(w)})}},[c,t,f,e]),x=l.useCallback(async g=>{try{await d(g.id);return}catch(w){if(!x3(w)||!window.confirm(e("settings.remoteInstances.sidebar.confirm.localPortInUseRetry")))throw w;const k={...g,localForward:{...g.localForward,preferredLocalPort:g3()}};await h(k),await d(k.id),H.success(e("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[d,e,h]);return s.jsx(sg,{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(we,{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(I,{name:"add",className:"size-4"})})]})]}),children:n.map(g=>{const w=r[g.id],y=g.id===b,k=g.nickname?.trim()||g.sshParsed?.destination||g.id,D=`${e(b3(w?.phase))}${w?.localUrl?` · ${w.localUrl}`:""}`,j=w?.phase==="ready",S=w?.phase==="error"||w?.phase==="degraded";return s.jsx(ng,{title:k,metadata:D,selected:y,onSelect:()=>{f(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(E=>{H.error(e(j?"settings.remoteInstances.sidebar.toast.disconnectFailed":"settings.remoteInstances.sidebar.toast.connectFailed"),{description:E instanceof Error?E.message:String(E)})})}},{label:e("settings.remoteInstances.sidebar.actions.retry"),icon:"refresh",onClick:()=>{S&&m(g.id).catch(A=>{H.error(e("settings.remoteInstances.sidebar.toast.retryFailed"),{description:A instanceof Error?A.message:String(A)})})}},{label:e("settings.remoteInstances.sidebar.actions.remove"),icon:"delete-bin",destructive:!0,onClick:()=>{u(g.id).then(()=>{if(b===g.id){const A=n.find(E=>E.id!==g.id);f(A?.id||null)}}).catch(A=>{H.error(e("settings.remoteInstances.sidebar.toast.removeFailed"),{description:A instanceof Error?A.message:String(A)})})}}]},g.id)})})},ap=t=>{const e=at.c(10),{children:n,className:r,outerClassName:a}=t;let i;e[0]!==a?(i=me("h-full",a),e[0]=a,e[1]=i):i=e[1];let o;e[2]!==r?(o=me("mx-auto max-w-3xl space-y-6 p-3 sm:p-6 sm:pt-8",r),e[2]=r,e[3]=o):o=e[3];let c;e[4]!==n||e[5]!==o?(c=s.jsx("div",{className:o,children:n}),e[4]=n,e[5]=o,e[6]=c):c=e[6];let d;return e[7]!==i||e[8]!==c?(d=s.jsx(Ts,{outerClassName:i,className:"w-full",children:c}),e[7]=i,e[8]=c,e[9]=d):d=e[9],d},pd=()=>Math.floor(2e4+Math.random()*3e4),v3=t=>{const e=(t instanceof Error?t.message:String(t)).toLowerCase();return e.includes("address already in use")||e.includes("eaddrinuse")||e.includes("port already in use")},w3=t=>{switch(t){case"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"}},j3=new Set(["config_resolved","auth_check","master_connecting","remote_probe","installing","updating","server_detecting","server_starting","forwarding"]),rg=t=>!!(t&&j3.has(t)),N3=t=>t==="ready"?"bg-[var(--status-success)] animate-pulse":t==="error"?"bg-[var(--status-error)] animate-pulse":t==="degraded"||rg(t)?"bg-[var(--status-warning)] animate-pulse":"bg-muted-foreground/40",S3=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}`,k3=()=>({id:`forward-${Date.now()}-${Math.random().toString(16).slice(2)}`,enabled:!0,type:"local",localHost:"127.0.0.1",localPort:pd(),remoteHost:"127.0.0.1",remotePort:80}),C3=t=>t.trim().replace(/\*/g,"host").replace(/\?/g,"x")||"user@host",Or=t=>{const e=at.c(8),{label:n,hint:r}=t;let a;e[0]!==n?(a=s.jsx("span",{children:n}),e[0]=n,e[1]=a):a=e[1];let i;e[2]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx(Ct,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),e[2]=i):i=e[2];let o;e[3]!==r?(o=s.jsxs(kt,{children:[i,s.jsx(Pt,{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},I3=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"}},ip=(t,e)=>{const n=(t||"").trim();return`${!n||n==="127.0.0.1"||n==="::1"?"localhost":n}:${e||0}`},P3=t=>{const e=(t||"").trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},A3=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}`},D3=t=>{const e=t.trim();if(e)try{window.location.assign(e)}catch{window.location.href=e}},T3=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}},M3=()=>{const{t}=pt(),e=Js(W=>W.instances),n=Js(W=>W.statusesById),r=Js(W=>W.importCandidates),a=Js(W=>W.isImportsLoading),i=Js(W=>W.isSaving),o=Js(W=>W.error),c=Js(W=>W.load),d=Js(W=>W.loadImports),p=Js(W=>W.refreshStatuses),m=Js(W=>W.upsertInstance),u=Js(W=>W.createFromCommand),h=Js(W=>W.removeInstance),b=Js(W=>W.connect),f=Js(W=>W.disconnect),v=Js(W=>W.retry),x=Te(W=>W.settingsRemoteInstancesSelectedId),g=Te(W=>W.setSettingsRemoteInstancesSelectedId),w=l.useMemo(()=>x&&e.find(W=>W.id===x)||null,[e,x]),[y,k]=l.useState(null),[D,j]=l.useState(!1),[S,A]=l.useState(!1),[E,P]=l.useState(null),[C,N]=l.useState([]),[T,M]=l.useState(null),[R,L]=l.useState(""),[$,B]=l.useState(!1),[O,_]=l.useState({}),[ee,z]=l.useState(!1),[ne,re]=l.useState(!1),[ue,Q]=l.useState(()=>Date.now());l.useEffect(()=>{c(),d()},[c,d]),l.useEffect(()=>{k(w)},[w]),l.useEffect(()=>{if(!x)return;const W=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||p()},2e3);return()=>{window.clearInterval(W)}},[p,x]),l.useEffect(()=>{let W=null,ie=Date.now();const Me=()=>{const Ce=Date.now();Ce-ie>=1e3&&(Q(Ce),ie=Ce),W=requestAnimationFrame(Me)};(typeof document>"u"||document.visibilityState==="visible")&&(W=requestAnimationFrame(Me));const Ve=()=>{document.visibilityState==="visible"&&W===null?W=requestAnimationFrame(Me):document.visibilityState!=="visible"&&W!==null&&(cancelAnimationFrame(W),W=null)};return document.addEventListener("visibilitychange",Ve),()=>{document.removeEventListener("visibilitychange",Ve),W!==null&&cancelAnimationFrame(W)}},[]);const de=x?n[x]:null,X=de?.phase,F=X==="ready",V=X==="degraded",q=rg(X),U=F||(q||V),ae=de?Math.max(0,ue-de.updatedAtMs):0,je=V&&ae>12e3,oe=l.useMemo(()=>!y||!w?!1:JSON.stringify(y)!==JSON.stringify(w),[y,w]),ve=l.useCallback(W=>{k(ie=>ie&&W(ie))},[]),K=l.useCallback(async()=>{if(!y)return;const W=T3(y);if(!W.sshCommand.trim()){H.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}if(!(W.localForward.bindHost==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces")))){if(W.auth.sshPassword?.enabled&&W.auth.sshPassword.value?.trim()&&W.auth.sshPassword.store!=="settings"){const ie=window.confirm(t("settings.remoteInstances.page.confirm.storeSshPasswordPlaintext"));W.auth.sshPassword.store=ie?"settings":"never",ie||(W.auth.sshPassword.value=void 0)}if(W.auth.openchamberPassword?.enabled&&W.auth.openchamberPassword.value?.trim()&&W.auth.openchamberPassword.store!=="settings"){const ie=window.confirm(t("settings.remoteInstances.page.confirm.storeUiPasswordPlaintext"));W.auth.openchamberPassword.store=ie?"settings":"never",ie||(W.auth.openchamberPassword.value=void 0)}try{await m(W),H.success(t("settings.remoteInstances.page.toast.instanceSaved"))}catch(ie){H.error(t("settings.remoteInstances.page.toast.saveFailed"),{description:ie instanceof Error?ie.message:String(ie)})}}},[y,t,m]),ce=l.useCallback(async(W,ie)=>{const Me=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{return await u(Me,`ssh ${ie}`,W),g(Me),H.success(t("settings.remoteInstances.page.toast.instanceCreated")),!0}catch(Ve){return H.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:Ve instanceof Error?Ve.message:String(Ve)}),!1}},[u,g,t]),Z=l.useCallback(()=>{$||(M(null),L(""))},[$]),le=l.useCallback((W,ie)=>{if(ie){M(W),L(C3(W));return}ce(W,W)},[ce]),se=l.useCallback(async()=>{const W=T,ie=R.trim();if(W){if(!ie){H.error(t("settings.remoteInstances.page.toast.destinationRequired"));return}B(!0);try{await ce(W,ie)&&(M(null),L(""))}finally{B(!1)}}},[ce,R,T,t]),Ie=l.useCallback(async()=>{if(w)try{await b(w.id);return}catch(W){if(!v3(W)||!window.confirm(t("settings.remoteInstances.sidebar.confirm.localPortInUseRetry")))throw W;const Me={...w,localForward:{...w.localForward,preferredLocalPort:pd()}};await m(Me),await b(Me.id),H.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[b,w,t,m]),Ne=l.useCallback(async W=>(await kb(W,600)).map(Me=>A3(Me)),[]),Y=l.useCallback(async()=>{if(y){j(!0),A(!0),P(null);try{const W=await Ne(y.id);N(W)}catch(W){N([]),P(W instanceof Error?W.message:String(W))}finally{A(!1)}}},[y,Ne]);l.useEffect(()=>{if(!D||!y)return;let W=!1;const ie=async()=>{try{const Ve=await Ne(y.id);W||(N(Ve),P(null))}catch(Ve){W||P(Ve instanceof Error?Ve.message:String(Ve))}};ie();const Me=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||ie()},1e3);return()=>{W=!0,window.clearInterval(Me)}},[y,D,Ne]);const fe=l.useMemo(()=>C.join(`
176
- `),[C]),ke=l.useCallback(()=>{if(!fe.trim()){H.error(t("settings.remoteInstances.page.toast.noLogsToCopy"));return}Rn(fe).then(W=>{W.ok&&H.success(t("settings.remoteInstances.page.toast.logsCopied"))})},[fe,t]),be=l.useCallback(async()=>{if(y)try{await Cb(y.id),N([]),H.success(t("settings.remoteInstances.page.toast.logsCleared"))}catch(W){H.error(t("settings.remoteInstances.page.toast.clearLogsFailed"),{description:W instanceof Error?W.message:String(W)})}},[y,t]),pe=l.useCallback(async()=>{if(!de?.localUrl){H.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}const W=de.localUrl.trim();if(!W){H.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}D3(W)},[de?.localUrl,t]),Ee=l.useCallback(()=>{if(!y)return;z(!0),(U?f(y.id):Ie()).catch(ie=>{const Me=U?F?"settings.remoteInstances.page.toast.disconnectFailed":"settings.remoteInstances.page.toast.cancelConnectionFailed":"settings.remoteInstances.page.toast.connectFailed";H.error(t(Me),{description:ie instanceof Error?ie.message:String(ie)})}).finally(()=>{z(!1)})},[U,Ie,f,y,F,t]),ze=l.useCallback(()=>{if(!y||q)return;re(!0),(V?f(y.id).then(()=>Ie()):v(y.id)).catch(ie=>{H.error(t("settings.remoteInstances.page.toast.retryFailed"),{description:ie instanceof Error?ie.message:String(ie)})}).finally(()=>{re(!1)})},[Ie,f,y,q,V,v,t]),G=t(q?"settings.remoteInstances.page.actions.connecting":V?je?"settings.remoteInstances.page.actions.reconnectNow":"settings.remoteInstances.page.actions.reconnecting":"settings.remoteInstances.sidebar.actions.retry"),Pe=!ee&&!ne&&(X==="error"||X==="idle"||!X||V&&je)&&!q,Le=t(F?"settings.remoteInstances.sidebar.actions.disconnect":U?"settings.remoteInstances.page.actions.cancel":"settings.remoteInstances.sidebar.actions.connect");if(!y)return s.jsxs(ap,{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(W=>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:[W.host,W.pattern?` ${t("settings.remoteInstances.page.import.patternSuffix")}`:""]}),s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[W.source," config"]})]}),s.jsx(we,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{le(W.host,W.pattern)},children:t("settings.remoteInstances.page.actions.create")})]},`${W.source}:${W.host}`))})})]}),s.jsx(ws,{open:!!T,onOpenChange:W=>{W||Z()},children:s.jsxs(vs,{className:"sm:max-w-md",children:[s.jsxs(Cs,{children:[s.jsx(js,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Rs,{children:T?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:T}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:W=>{W.preventDefault(),se()},children:[s.jsx(Kt,{value:R,onChange:W=>L(W.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(we,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Z,disabled:$,children:t("settings.common.actions.cancel")}),s.jsx(we,{type:"submit",size:"xs",className:"!font-normal",disabled:$,children:t("settings.remoteInstances.page.actions.create")})]})]})]})})]});const Ae=y.remoteOpenchamber.mode==="managed",ge=y.nickname?.trim()||y.sshParsed?.destination||y.id;return s.jsxs(ap,{children:[s.jsxs("div",{className:"mb-6 px-1",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:ge}),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 ${N3(X)}`}),s.jsx("span",{children:t(w3(X))}),de?.localUrl?s.jsx("span",{className:"font-mono text-foreground/80",children:de.localUrl}):null,je?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(we,{type:"button",variant:U?"outline":"default",size:"xs",className:"!font-normal",onClick:Ee,disabled:ee||ne,children:[U?s.jsx(I,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"plug-2",className:"h-3.5 w-3.5"}),Le]}),s.jsxs(we,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:ze,disabled:!Pe,children:[s.jsx(I,{name:"refresh",className:`h-3.5 w-3.5 ${q||V&&!je?"animate-spin":""}`}),G]}),s.jsxs(we,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Y()},children:[s.jsx(I,{name:"terminal-window",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.logs")]}),s.jsxs(we,{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"))&&h(y.id).then(()=>{g(null),H.success(t("settings.remoteInstances.page.toast.instanceRemoved"))}).catch(ie=>{H.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:ie instanceof Error?ie.message:String(ie)})})},children:[s.jsx(I,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.remove")]})]}),de?.localUrl?s.jsxs("div",{className:"flex flex-wrap items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx("span",{children:t("settings.remoteInstances.page.status.currentLocalUrl")}),s.jsx("span",{className:"font-mono text-foreground/90",children:de.localUrl})]}):null]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.section.instance")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.section.instanceDescription")})]}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.sshCommand")}),s.jsx(Kt,{className:"h-7 md:max-w-xl",value:y.sshCommand,onChange:W=>ve(ie=>({...ie,sshCommand:W.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(Kt,{className:"h-7 md:max-w-sm",value:y.nickname||"",onChange:W=>ve(ie=>({...ie,nickname:W.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(xn,{containerClassName:"w-fit",min:5,max:240,step:1,className:"w-16 tabular-nums",value:y.connectionTimeoutSec,onValueChange:W=>{ve(ie=>({...ie,connectionTimeoutSec:Number.isFinite(W)?W:ie.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(Or,{label:t("settings.remoteInstances.page.field.mode"),hint:t("settings.remoteInstances.page.field.modeHint")})}),s.jsxs(ds,{value:y.remoteOpenchamber.mode,onValueChange:W=>ve(ie=>({...ie,remoteOpenchamber:{...ie.remoteOpenchamber,mode:W==="external"?"external":"managed"}})),children:[s.jsx(us,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(ys,{placeholder:t("settings.remoteInstances.page.field.modePlaceholder")})}),s.jsxs(ms,{children:[s.jsx(Lt,{value:"managed",children:t("settings.remoteInstances.page.field.modeManaged")}),s.jsx(Lt,{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(Or,{label:t("settings.remoteInstances.page.field.preferredRemotePort"),hint:t("settings.remoteInstances.page.field.preferredRemotePortHint")})}),s.jsx(xn,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-20 tabular-nums",value:y.remoteOpenchamber.preferredPort,onValueChange:W=>{ve(ie=>({...ie,remoteOpenchamber:{...ie.remoteOpenchamber,preferredPort:Number.isFinite(W)&&W>0?W:void 0}}))},onClear:()=>{ve(W=>({...W,remoteOpenchamber:{...W.remoteOpenchamber,preferredPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]}),Ae?s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Or,{label:t("settings.remoteInstances.page.field.installMethod"),hint:t("settings.remoteInstances.page.field.installMethodHint")})}),s.jsxs(ds,{value:y.remoteOpenchamber.installMethod,onValueChange:W=>ve(ie=>({...ie,remoteOpenchamber:{...ie.remoteOpenchamber,installMethod:W==="npm"||W==="download_release"||W==="upload_bundle"?W:"bun"}})),children:[s.jsx(us,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(ys,{placeholder:t("settings.remoteInstances.page.field.selectInstallMethodPlaceholder")})}),s.jsxs(ms,{children:[s.jsx(Lt,{value:"bun",children:"bun"}),s.jsx(Lt,{value:"npm",children:"npm"}),s.jsx(Lt,{value:"download_release",children:t("settings.remoteInstances.page.field.installMethodDownloadRelease")}),s.jsx(Lt,{value:"upload_bundle",children:t("settings.remoteInstances.page.field.installMethodUploadBundle")})]})]})]}):null,Ae?s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(Or,{label:t("settings.remoteInstances.page.field.keepServerRunning"),hint:t("settings.remoteInstances.page.field.keepServerRunningHint")})}),s.jsx("div",{className:"flex w-full items-center gap-2 md:max-w-xs",children:s.jsx(ol,{checked:y.remoteOpenchamber.keepRunning,onCheckedChange:W=>ve(ie=>({...ie,remoteOpenchamber:{...ie.remoteOpenchamber,keepRunning:W}}))})})]}):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(Or,{label:t("settings.remoteInstances.page.field.bindHost"),hint:t("settings.remoteInstances.page.field.bindHostHint")})}),s.jsxs(ds,{value:y.localForward.bindHost,onValueChange:W=>{W==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces"))||ve(ie=>({...ie,localForward:{...ie.localForward,bindHost:W==="localhost"||W==="0.0.0.0"?W:"127.0.0.1"}}))},children:[s.jsx(us,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(ys,{placeholder:t("settings.remoteInstances.page.field.selectBindHostPlaceholder")})}),s.jsxs(ms,{children:[s.jsx(Lt,{value:"127.0.0.1",children:"127.0.0.1"}),s.jsx(Lt,{value:"localhost",children:"localhost"}),s.jsx(Lt,{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(Or,{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(xn,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-20 tabular-nums",value:y.localForward.preferredLocalPort,onValueChange:W=>{ve(ie=>({...ie,localForward:{...ie.localForward,preferredLocalPort:Number.isFinite(W)&&W>0?W:void 0}}))},onClear:()=>{ve(W=>({...W,localForward:{...W.localForward,preferredLocalPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")}),s.jsx(we,{type:"button",variant:"outline",size:"xs",className:"!font-normal h-7 w-7 px-0",title:t("settings.remoteInstances.page.actions.pickRandomPort"),onClick:()=>ve(W=>({...W,localForward:{...W.localForward,preferredLocalPort:pd()}})),children:s.jsx(I,{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(Kt,{className:"h-7 md:max-w-sm",type:"password",value:y.auth.sshPassword?.value||"",onChange:W=>ve(ie=>({...ie,auth:{...ie.auth,sshPassword:{enabled:W.target.value.trim().length>0,value:W.target.value,store:ie.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(Kt,{className:"h-7 md:max-w-sm",type:"password",value:y.auth.openchamberPassword?.value||"",onChange:W=>ve(ie=>({...ie,auth:{...ie.auth,openchamberPassword:{enabled:W.target.value.trim().length>0,value:W.target.value,store:ie.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((W,ie)=>{const Me=Ke=>{ve(st=>({...st,portForwards:st.portForwards.map((nt,ye)=>ye===ie?Ke(nt):nt)}))},Ve=W.type==="remote"?"Local target":"Local listen",Ce=W.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.",xe=W.type==="remote"?"Remote listen":"Remote target",De=W.type==="remote"?"Remote host and port where SSH creates the -R listener.":"Remote host and port that receives traffic from local -L listener.",Ye=ip(W.localHost||"localhost",W.localPort),rt=ip(W.remoteHost||"localhost",W.remotePort),Re=W.type==="local"&&typeof W.localPort=="number"&&W.localPort>0,he=Re?`http://${P3(W.localHost)}:${W.localPort}`:"",qe=!!O[W.id],et=W.type==="local"?t("settings.remoteInstances.page.forwardType.local"):W.type==="remote"?t("settings.remoteInstances.page.forwardType.remote"):t("settings.remoteInstances.page.forwardType.dynamic");return s.jsxs(ur,{open:qe,onOpenChange:Ke=>{_(st=>({...st,[W.id]:Ke}))},className:`${ie>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(wr,{className:"flex items-center gap-2 group",children:[s.jsx(I,{name:"arrow-down-s",className:`h-4 w-4 text-muted-foreground transition-transform ${qe?"rotate-180":""}`}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:S3(W)}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:et})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ol,{checked:W.enabled,onCheckedChange:Ke=>Me(st=>({...st,enabled:Ke})),"aria-label":t("settings.remoteInstances.page.actions.enableForwardAria")}),s.jsx(we,{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:()=>ve(Ke=>({...Ke,portForwards:Ke.portForwards.filter(st=>st.id!==W.id)})),children:s.jsx(I,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),s.jsx(mr,{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(I3(W.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(Or,{label:t("settings.remoteInstances.page.field.forwardType"),hint:t("settings.remoteInstances.page.field.forwardTypeHint")})}),s.jsxs(ds,{value:W.type,onValueChange:Ke=>Me(st=>({...st,type:Ke==="dynamic"||Ke==="remote"?Ke:"local"})),children:[s.jsx(us,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(ys,{placeholder:t("settings.remoteInstances.page.field.typePlaceholder")})}),s.jsxs(ms,{children:[s.jsx(Lt,{value:"local",children:t("settings.remoteInstances.page.forwardType.local")}),s.jsx(Lt,{value:"remote",children:t("settings.remoteInstances.page.forwardType.remote")}),s.jsx(Lt,{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(Or,{label:Ve,hint:Ce})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Kt,{className:"h-7 w-32",value:W.localHost||"127.0.0.1",onChange:Ke=>Me(st=>({...st,localHost:Ke.target.value})),placeholder:t("settings.remoteInstances.page.field.localHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(xn,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-16 tabular-nums",value:W.localPort,onValueChange:Ke=>{Me(st=>({...st,localPort:Number.isFinite(Ke)&&Ke>0?Ke:void 0}))},onClear:()=>{Me(Ke=>({...Ke,localPort:void 0}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]})]}),W.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(Or,{label:xe,hint:De})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Kt,{className:"h-7 w-32",value:W.remoteHost||"",onChange:Ke=>Me(st=>({...st,remoteHost:Ke.target.value})),placeholder:t("settings.remoteInstances.page.field.remoteHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(xn,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-16 tabular-nums",value:W.remotePort,onValueChange:Ke=>{Me(st=>({...st,remotePort:Number.isFinite(Ke)&&Ke>0?Ke:void 0}))},onClear:()=>{Me(Ke=>({...Ke,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:W.type==="dynamic"?s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Ye}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.localSocks5")})]}):W.type==="remote"?s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:rt}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")}),s.jsx(I,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(I,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Ye}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")})]}):s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Ye}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")}),s.jsx(I,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(I,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:rt}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")})]})}),Re?s.jsxs(we,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Xn(he).then(Ke=>{Ke||H.error(t("settings.remoteInstances.page.toast.openLocalEndpointFailed"))})},children:[s.jsx(I,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.openLocal")]}):null]})]})})]},W.id)}),s.jsxs(we,{type:"button",variant:"outline",size:"xs",className:"!font-normal mt-1",onClick:()=>{const W=k3();ve(ie=>({...ie,portForwards:[...ie.portForwards,W]})),_(ie=>({...ie,[W.id]:!0}))},children:[s.jsx(I,{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((W,ie)=>s.jsxs("div",{className:`flex items-center justify-between gap-2 px-1 py-2 ${ie>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:[W.host,W.pattern?" (pattern)":""]}),s.jsx("div",{className:"typography-micro text-muted-foreground truncate",children:W.sshCommand})]}),s.jsx(we,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{le(W.host,W.pattern)},children:t("settings.common.actions.import")})]},`${W.source}:${W.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(we,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{K()},disabled:!oe||i,children:t("settings.common.actions.saveChanges")}),de?.localUrl?s.jsxs(s.Fragment,{children:[s.jsxs(we,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Rn(de.localUrl||"").then(W=>{W.ok&&H.success(t("settings.remoteInstances.page.toast.localUrlCopied"))})},children:[s.jsx(I,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.copyLocalUrl")]}),s.jsxs(we,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{pe()},children:[s.jsx(I,{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(ws,{open:D,onOpenChange:j,children:s.jsxs(vs,{className:"sm:max-w-2xl",children:[s.jsxs(Cs,{children:[s.jsx(js,{children:t("settings.remoteInstances.page.logsDialog.title")}),s.jsx(Rs,{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(we,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:ke,disabled:S||!fe.trim(),children:[s.jsx(I,{name:"file-copy",className:"h-3.5 w-3.5"}),t("settings.common.actions.copyAll")]}),s.jsxs(we,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{be()},disabled:S,children:[s.jsx(I,{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")}):E?s.jsx("div",{className:"typography-meta text-[var(--status-error)]",children:E}):s.jsx("pre",{className:"max-h-[55vh] overflow-auto rounded-md border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3 typography-micro text-foreground whitespace-pre-wrap break-words",children:C.length>0?C.join(`
177
- `):t("settings.remoteInstances.page.logsDialog.empty")})]})}),s.jsx(ws,{open:!!T,onOpenChange:W=>{W||Z()},children:s.jsxs(vs,{className:"sm:max-w-md",children:[s.jsxs(Cs,{children:[s.jsx(js,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Rs,{children:T?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:T}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:W=>{W.preventDefault(),se()},children:[s.jsx(Kt,{value:R,onChange:W=>L(W.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(we,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Z,disabled:$,children:t("settings.common.actions.cancel")}),s.jsx(we,{type:"submit",size:"xs",className:"!font-normal",disabled:$,children:t("settings.common.actions.create")})]})]})]})})]})},E3="__add_provider__",R3=()=>{const t=rn.getDirectory();return typeof t=="string"&&t.trim().length>0?t.trim():null},F3=({onItemSelect:t})=>{const{t:e}=pt(),n=gt(h=>h.providers),r=gt(h=>h.selectedProviderId),a=gt(h=>h.setSelectedProvider),i=Fs(h=>h.activeProjectId),[o,c]=l.useState({}),d=l.useMemo(()=>R3(),[i]);l.useEffect(()=>{if(n.length===0){c({});return}let h=!1;return(async()=>{const f=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||h)return;c(k=>({...k,[v.id]:y}))}catch{}});await Promise.all(f)})(),()=>{h=!0}},[d,n]);const p="bg-background",m=l.useMemo(()=>n.filter(h=>!!o[h.id]?.project?.exists),[n,o]),u=l.useMemo(()=>n.filter(h=>!o[h.id]?.project?.exists),[n,o]);return s.jsxs("div",{className:me("flex h-full flex-col",p),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:e("settings.providers.sidebar.title")}),s.jsx(io,{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(we,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:()=>{a(E3),t?.()},"aria-label":e("settings.providers.sidebar.actions.connectProviderAria"),title:e("settings.providers.sidebar.actions.connectProviderTitle"),children:s.jsx(I,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(Ts,{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(I,{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(h=>s.jsx(op,{provider:h,selectedProviderId:r,onSelect:()=>{a(h.id),t?.()}},h.id))]}),m.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:me("px-2 pb-1.5 text-xs font-semibold uppercase tracking-wide text-muted-foreground",u.length>0?"pt-3":"pt-2"),children:e("settings.providers.sidebar.section.projectProviders")}),m.map(h=>s.jsx(op,{provider:h,selectedProviderId:r,onSelect:()=>{a(h.id),t?.()}},h.id))]})]})})]})},op=t=>{const e=at.c(17),{provider:n,selectedProviderId:r,onSelect:a}=t,i=Array.isArray(n.models)?n.models.length:0,o=n.id===r,c=n.id,d=o?"bg-interactive-selection":"hover:bg-interactive-hover";let p;e[0]!==d?(p=me("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",d),e[0]=d,e[1]=p):p=e[1];let m;e[2]!==n.id?(m=s.jsx(Sn,{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 h;e[4]!==u?(h=s.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:u}),e[4]=u,e[5]=h):h=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 f;e[8]!==a||e[9]!==m||e[10]!==h||e[11]!==b?(f=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,h,b]}),e[8]=a,e[9]=m,e[10]=h,e[11]=b,e[12]=f):f=e[12];let v;return e[13]!==n.id||e[14]!==p||e[15]!==f?(v=s.jsx("div",{className:p,children:f},c),e[13]=n.id,e[14]=p,e[15]=f,e[16]=v):v=e[16],v},L3=new Intl.NumberFormat("en-US",{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}),lp=t=>{if(typeof t!="number"||Number.isNaN(t))return null;if(t===0)return"0";const e=L3.format(t);return e.endsWith(".0")?e.slice(0,-2):e},Po="__add_provider__",hi=t=>typeof t=="object"&&t!==null,cp=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()},O3=t=>{if(!hi(t))return{};const e={};for(const[n,r]of Object.entries(t))Array.isArray(r)&&(e[n]=r.filter(a=>hi(a)));return e},$3=t=>{if(typeof t=="string")return{id:t};if(!hi(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}},B3=t=>{let e=[];Array.isArray(t)?e=t:hi(t)&&(Array.isArray(t.all)?e=t.all:Array.isArray(t.providers)&&(e=t.providers));const n=e.map(a=>$3(a)).filter(a=>!!a),r=new Set;return n.filter(a=>r.has(a.id)?!1:(r.add(a.id),!0))},_3=()=>{const{t}=pt(),e=gt(Z=>Z.providers),n=gt(Z=>Z.selectedProviderId),r=gt(Z=>Z.setSelectedProvider),a=gt(Z=>Z.getModelMetadata),i=Te(Z=>Z.hiddenModels),o=Te(Z=>Z.toggleHiddenModel),c=Te(Z=>Z.hideAllModels),d=Te(Z=>Z.showAllModels),[p,m]=l.useState({}),[u,h]=l.useState(!1),[b,f]=l.useState({}),[v,x]=l.useState(null),[g,w]=l.useState(""),[y,k]=l.useState(null),[D,j]=l.useState({}),[S,A]=l.useState({}),[E,P]=l.useState([]),[C,N]=l.useState(!1),[T,M]=l.useState(null),[R,L]=l.useState(""),[$,B]=l.useState(""),[O,_]=l.useState(!1),[ee,z]=l.useState({}),[ne,re]=l.useState(!1);l.useEffect(()=>{!n&&e.length>0&&r(e[0].id)},[e,n,r]),l.useEffect(()=>{let Z=!0;return(async()=>{h(!0);try{const se=await fetch("/api/provider/auth",{method:"GET",headers:{Accept:"application/json"}});if(!se.ok)throw new Error(`Auth methods request failed (${se.status})`);const Ie=await se.json().catch(()=>({}));if(!Z)return;m(O3(Ie))}catch(se){if(!Z)return;console.error("Failed to load provider auth methods:",se),H.error(t("settings.providers.page.toast.authMethodsLoadFailed"))}finally{Z&&h(!1)}})(),()=>{Z=!1}},[t]),l.useEffect(()=>{let Z=!0;return(async()=>{N(!0),M(null);try{const se=await fetch("/api/provider",{method:"GET",headers:{Accept:"application/json"}});if(!se.ok)throw new Error(`Provider list request failed (${se.status})`);const Ie=await se.json().catch(()=>({}));if(!Z)return;P(B3(Ie))}catch(se){if(!Z)return;console.error("Failed to load available providers:",se),M(t("settings.providers.page.state.unableToLoadProviderList"))}finally{Z&&N(!1)}})(),()=>{Z=!1}},[t]);const ue=l.useMemo(()=>new Set(e.map(Z=>Z.id)),[e]),Q=l.useMemo(()=>E.filter(Z=>!ue.has(Z.id)).sort((Z,le)=>{const se=(Z.name||Z.id).toLowerCase(),Ie=(le.name||le.id).toLowerCase();return se.localeCompare(Ie)}),[E,ue]);l.useEffect(()=>{n===Po&&R&&!Q.some(Z=>Z.id===R)&&L("")},[n,R,Q]),l.useEffect(()=>{if(n===Po){re(!0);return}re(!1)},[n,t]),l.useEffect(()=>{if(!n||n===Po)return;let Z=!1;return(async()=>{try{const se=await fetch(`/api/provider/${encodeURIComponent(n)}/source`,{method:"GET",headers:{Accept:"application/json"}}),Ie=await se.json().catch(()=>null);if(!se.ok)throw new Error(Ie?.error||t("settings.providers.page.toast.providerSourcesLoadFailed"));const Ne=Ie?.sources??Ie?.data?.sources;!Z&&Ne&&z(Y=>({...Y,[n]:Ne}))}catch(se){Z||console.error("Failed to load provider sources:",se)}})(),()=>{Z=!0}},[n,t]);const de=e.find(Z=>Z.id===n),X=n?ee[n]:void 0,F=async Z=>{const le=b[Z]?.trim()??"";if(!le){H.error(t("settings.providers.page.toast.apiKeyRequired"));return}const se=`api:${Z}`;x(se);try{const Ie=await fetch(`/api/auth/${encodeURIComponent(Z)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"api",key:le})}),Ne=await Ie.json().catch(()=>null);if(!Ie.ok){const Y=Ne?.error||t("settings.providers.page.toast.apiKeySaveFailed");throw new Error(Y)}H.success(t("settings.providers.page.toast.apiKeySaved")),f(Y=>({...Y,[Z]:""})),await si({scopes:["providers"],mode:"active"}),r(Z)}catch(Ie){console.error("Failed to save API key:",Ie),H.error(t("settings.providers.page.toast.apiKeySaveFailed"))}finally{x(null)}},V=async(Z,le)=>{const se=`oauth:${Z}:${le}`;x(se);try{const Ie=await fetch(`/api/provider/${encodeURIComponent(Z)}/oauth/authorize`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({method:le})}),Ne=await Ie.json().catch(()=>null);if(!Ie.ok){const ze=Ne?.error||t("settings.providers.page.toast.oauthStartFailed");throw new Error(ze)}const Y=hi(Ne)?Ne:{},fe=hi(Y.data)?Y.data:Y,ke=typeof fe.url=="string"&&fe.url||typeof fe.verification_uri_complete=="string"&&fe.verification_uri_complete||typeof fe.verification_uri=="string"&&fe.verification_uri||void 0,be=typeof fe.instructions=="string"&&fe.instructions||typeof fe.message=="string"&&fe.message||void 0,pe=typeof fe.user_code=="string"&&fe.user_code||typeof fe.code=="string"&&fe.code||typeof fe.userCode=="string"&&fe.userCode||void 0;if(!ke&&!be&&!pe)throw new Error(t("settings.providers.page.toast.oauthDetailsMissing"));const Ee=`${Z}:${le}`;A(ze=>({...ze,[Ee]:{url:ke,instructions:be,userCode:pe}})),ke&&Xn(ke),k({providerId:Z,methodIndex:le}),H.message(t("settings.providers.page.toast.completeOAuthInBrowser"))}catch(Ie){console.error("Failed to start OAuth flow:",Ie),H.error(t("settings.providers.page.toast.oauthStartFailed"))}finally{x(null)}},q=async(Z,le)=>{const se=`${Z}:${le}`,Ie=D[se]?.trim(),Ne=`oauth-complete:${Z}:${le}`;x(Ne);try{const Y={method:le};Ie&&(Y.code=Ie);const fe=await fetch(`/api/provider/${encodeURIComponent(Z)}/oauth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Y)}),ke=await fe.json().catch(()=>null);if(!fe.ok){const be=ke?.error||t("settings.providers.page.toast.oauthCompleteFailed");throw new Error(be)}H.success(t("settings.providers.page.toast.oauthCompleted")),j(be=>({...be,[se]:""})),k(null),await si({scopes:["providers"],mode:"active"}),r(Z)}catch(Y){console.error("Failed to complete OAuth flow:",Y),H.error(t("settings.providers.page.toast.oauthCompleteFailed"))}finally{x(null)}},te=async Z=>{const le=await Rn(Z);if(le.ok){H.success(t("settings.providers.page.toast.oauthLinkCopied"));return}console.error("Failed to copy OAuth link:",le.error),H.error(t("settings.providers.page.toast.oauthLinkCopyFailed"))},U=async Z=>{const le=await Rn(Z);if(le.ok){H.success(t("settings.providers.page.toast.deviceCodeCopied"));return}console.error("Failed to copy device code:",le.error),H.error(t("settings.providers.page.toast.deviceCodeCopyFailed"))},ae=async Z=>{const le=`disconnect:${Z}`;x(le);try{const se=await fetch(`/api/provider/${encodeURIComponent(Z)}/auth?scope=all`,{method:"DELETE",headers:{"Content-Type":"application/json"}}),Ie=await se.json().catch(()=>null);if(!se.ok){const Ne=Ie?.error||t("settings.providers.page.toast.providerDisconnectFailed");throw new Error(Ne)}H.success(t("settings.providers.page.toast.providerDisconnected")),await si({scopes:["providers"],mode:"active"})}catch(se){console.error("Failed to disconnect provider:",se),H.error(t("settings.providers.page.toast.providerDisconnectFailed"))}finally{x(null)}},je=n===Po;if(!je&&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(I,{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(je)return s.jsx(Ts,{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")}),C?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.state.loading")}):T?s.jsx("p",{className:"typography-meta text-muted-foreground",children:T}):Q.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.connect.allProvidersConnected")}):s.jsxs(Bs,{open:O,onOpenChange:Z=>{_(Z),Z||B("")},children:[s.jsx(Os,{asChild:!0,children:s.jsxs("button",{type:"button",className:me("flex items-center justify-between gap-2 rounded-lg border border-input bg-transparent px-2 py-2 typography-ui-label whitespace-nowrap shadow-none outline-none hover:bg-interactive-hover h-6 w-fit"),children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[R?s.jsx(Sn,{providerId:R,className:"h-3.5 w-3.5 flex-shrink-0"}):null,s.jsx("span",{className:me("truncate typography-ui-label font-normal",R?"text-foreground":"text-muted-foreground"),children:R?Q.find(Z=>Z.id===R)?.name||R:t("settings.providers.page.connect.selectProviderPlaceholder")})]}),s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/50"})]})}),s.jsxs($s,{align:"start",className:"w-[280px] p-0",onCloseAutoFocus:Z=>Z.preventDefault(),children:[s.jsxs("div",{className:"flex items-center gap-2 border-b border-[var(--surface-subtle)] px-3 py-2",onKeyDown:Z=>Z.stopPropagation(),children:[s.jsx(I,{name:"search",className:"h-4 w-4 text-muted-foreground"}),s.jsx("input",{type:"text",value:$,onChange:Z=>B(Z.target.value),onKeyDown:Z=>Z.stopPropagation(),placeholder:t("settings.providers.page.connect.searchProvidersPlaceholder"),className:"flex-1 bg-transparent typography-meta outline-none placeholder:text-muted-foreground",autoFocus:!0})]}),s.jsx(Ts,{outerClassName:"max-h-[240px]",className:"p-1",children:(()=>{const Z=Q.filter(le=>{const se=$.toLowerCase();return(le.name||le.id).toLowerCase().includes(se)||le.id.toLowerCase().includes(se)});return Z.length===0?s.jsx("p",{className:"py-4 text-center typography-meta text-muted-foreground",children:t("settings.providers.page.connect.noProvidersFound")}):Z.map(le=>s.jsxs(zt,{onSelect:()=>{L(le.id),_(!1),B("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(Sn,{providerId:le.id,className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:le.name||le.id})]}),R===le.id&&s.jsx(I,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},le.id))})()})]})]})]})})]}),R&&s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h2",{className:"typography-ui-header font-medium text-foreground",children:t("settings.providers.page.auth.title")})}),u?s.jsx("p",{className:"typography-meta text-muted-foreground px-2",children:t("settings.providers.page.auth.loadingMethods")}):s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-4",children:[s.jsxs("div",{className:"py-1.5",children:[s.jsxs("label",{className:"typography-ui-label text-foreground flex items-center gap-1.5",children:[t("settings.providers.page.auth.apiKeyLabel"),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{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(Kt,{type:"password",value:b[R]??"",onChange:Z=>f(le=>({...le,[R]:Z.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(we,{size:"xs",className:"!font-normal shrink-0",onClick:()=>F(R),disabled:v===`api:${R}`,children:v===`api:${R}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}),(()=>{const le=(p[R]??[]).filter(se=>cp(se)==="oauth");return le.length===0?null:s.jsx("div",{className:"space-y-4 border-t border-[var(--surface-subtle)] pt-2",children:le.map((se,Ie)=>{const Ne=se.label||se.name||t("settings.providers.page.auth.oauthMethodFallback",{index:String(Ie+1)}),Y=`${R}:${Ie}`,fe=y?.providerId===R&&y?.methodIndex===Ie;return s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:Ne}),(se.description||se.help)&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:String(se.description||se.help)})]}),s.jsx(we,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>V(R,Ie),disabled:v===`oauth:${R}:${Ie}`,children:t("settings.providers.page.actions.connect")})]}),S[Y]?.instructions&&s.jsx("p",{className:"typography-meta text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-2 py-1.5 rounded",children:S[Y]?.instructions}),S[Y]?.userCode&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Kt,{value:S[Y]?.userCode,readOnly:!0,className:"font-mono text-center tracking-widest"}),s.jsx(we,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>U(S[Y]?.userCode??""),children:t("settings.providers.page.actions.copyCode")})]}),S[Y]?.url&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Kt,{value:S[Y]?.url,readOnly:!0,className:"text-xs text-muted-foreground"}),s.jsxs("div",{className:"flex gap-1 shrink-0",children:[s.jsx(we,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Xn(S[Y]?.url??""),children:t("settings.providers.page.actions.open")}),s.jsx(we,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>te(S[Y]?.url??""),children:t("settings.providers.page.actions.copy")})]})]}),fe&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Kt,{value:D[Y]??"",onChange:ke=>j(be=>({...be,[Y]:ke.target.value})),placeholder:t("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs"}),s.jsx(we,{size:"xs",className:"!font-normal",onClick:()=>q(R,Ie),disabled:v===`oauth-complete:${R}:${Ie}`,children:v===`oauth-complete:${R}:${Ie}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.complete")})]})]},`${R}-${Ne}`)})})})()]})]})]})});if(!de)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(I,{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(de.models)?de.models:[],K=(p[de.id]??[]).filter(Z=>cp(Z)==="oauth"),ce=oe.filter(Z=>{const le=typeof Z?.name=="string"?Z.name:"",se=typeof Z?.id=="string"?Z.id:"",Ie=g.trim().toLowerCase();return Ie?le.toLowerCase().includes(Ie)||se.toLowerCase().includes(Ie):!0});return s.jsx(Ts,{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(Sn,{providerId:de.id,className:"h-5 w-5 shrink-0"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:de.name||de.id}),s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:s.jsx("span",{className:"font-mono",children:de.id})})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 px-1 flex items-center justify-between gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.providers.page.auth.title")}),s.jsx(we,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>re(Z=>!Z),children:t(ne?"settings.providers.page.actions.hide":"settings.providers.page.actions.reconnect")})]}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:ne?u?s.jsx("div",{className:"py-1.5 typography-meta text-muted-foreground",children:t("settings.providers.page.auth.loadingMethods")}):s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"py-1.5",children:[s.jsxs("label",{className:"typography-ui-label text-foreground flex items-center gap-1.5",children:[t("settings.providers.page.auth.apiKeyLabel"),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{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(Kt,{type:"password",value:b[de.id]??"",onChange:Z=>f(le=>({...le,[de.id]:Z.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(we,{size:"xs",className:"!font-normal shrink-0",onClick:()=>F(de.id),disabled:v===`api:${de.id}`,children:v===`api:${de.id}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}),K.length>0&&s.jsx("div",{className:"space-y-4 border-t border-[var(--surface-subtle)] pt-2",children:K.map((Z,le)=>{const se=Z.label||Z.name||t("settings.providers.page.auth.oauthMethodFallback",{index:String(le+1)}),Ie=`${de.id}:${le}`,Ne=y?.providerId===de.id&&y?.methodIndex===le;return s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:se}),(Z.description||Z.help)&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:String(Z.description||Z.help)})]}),s.jsx(we,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>V(de.id,le),disabled:v===`oauth:${de.id}:${le}`,children:t("settings.providers.page.actions.connect")})]}),S[Ie]?.instructions&&s.jsx("p",{className:"typography-meta text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-2 py-1.5 rounded",children:S[Ie]?.instructions}),S[Ie]?.userCode&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Kt,{value:S[Ie]?.userCode,readOnly:!0,className:"font-mono text-center tracking-widest"}),s.jsx(we,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>U(S[Ie]?.userCode??""),children:t("settings.providers.page.actions.copyCode")})]}),S[Ie]?.url&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Kt,{value:S[Ie]?.url,readOnly:!0,className:"text-xs text-muted-foreground"}),s.jsxs("div",{className:"flex gap-1 shrink-0",children:[s.jsx(we,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Xn(S[Ie]?.url??""),children:t("settings.providers.page.actions.open")}),s.jsx(we,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>te(S[Ie]?.url??""),children:t("settings.providers.page.actions.copy")})]})]}),Ne&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Kt,{value:D[Ie]??"",onChange:Y=>j(fe=>({...fe,[Ie]:Y.target.value})),placeholder:t("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs"}),s.jsx(we,{size:"xs",className:"!font-normal",onClick:()=>q(de.id,le),disabled:v===`oauth-complete:${de.id}:${le}`,children:v===`oauth-complete:${de.id}:${le}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.complete")})]})]},`${de.id}-${se}`)})})]}):s.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[s.jsx(I,{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:X&&(X.auth.exists||X.user.exists||X.project.exists||X.custom?.exists)?s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[t("settings.providers.page.connectionDetails.configuredIn")," ",[X.auth.exists?t("settings.providers.page.connectionDetails.source.authCredentials"):null,X.user.exists?t("settings.providers.page.connectionDetails.source.userConfig"):null,X.project.exists?t("settings.providers.page.connectionDetails.source.projectConfig"):null,X.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(we,{variant:"ghost",size:"xs",className:"!font-normal text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>ae(de.id),disabled:v===`disconnect:${de.id}`,children:v===`disconnect:${de.id}`?t("settings.providers.page.actions.disconnecting"):t("settings.providers.page.actions.disconnect")})]})})]}),s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 px-1 flex items-center justify-between gap-2",children:[s.jsxs("h3",{className:"typography-ui-header font-medium text-foreground",children:[t("settings.providers.page.models.title"),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(we,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const Z=oe.map(le=>typeof le?.id=="string"?le.id:"").filter(le=>le.length>0);c(de.id,Z)},children:t("settings.providers.page.actions.hideAll")}),s.jsx(we,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>d(de.id),children:t("settings.providers.page.actions.showAll")})]})]}),s.jsxs("section",{className:"px-2 pb-2 pt-0",children:[s.jsxs("div",{className:"relative mb-2",children:[s.jsx(I,{name:"search",className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Kt,{value:g,onChange:Z=>w(Z.target.value),placeholder:t("settings.providers.page.models.filterPlaceholder"),className:"h-7 pl-8 w-full"})]}),ce.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:ce.map(Z=>{const le=typeof Z?.id=="string"?Z.id:"",se=typeof Z?.name=="string"?Z.name:le,Ie=le?a(de.id,le):void 0,Ne=i.some(be=>be.providerID===de.id&&be.modelID===le),Y=lp(Ie?.limit?.context),fe=lp(Ie?.limit?.output),ke=[];return Ie?.tool_call&&ke.push({key:"tools",icon:"tools",label:t("settings.providers.page.models.capability.toolCalling")}),Ie?.reasoning&&ke.push({key:"reasoning",icon:"brain-ai-3",label:t("settings.providers.page.models.capability.reasoning")}),Ie?.attachment&&ke.push({key:"image",icon:"file-image",label:t("settings.providers.page.models.capability.imageInput")}),s.jsx("div",{className:"py-1.5",children:s.jsxs("div",{className:me("flex items-center gap-3",Ne&&"opacity-50"),children:[s.jsx("span",{className:"typography-meta font-medium text-foreground truncate flex-1 min-w-0",children:se}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[(Y||fe)&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex-shrink-0 bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:[Y?`${Y} ${t("settings.providers.page.models.tokenBadge.context")}`:"",Y&&fe?" · ":"",fe?`${fe} ${t("settings.providers.page.models.tokenBadge.output")}`:""]}),ke.length>0&&s.jsx("div",{className:"flex items-center gap-1 flex-shrink-0",children:ke.map(({key:be,icon:pe,label:Ee})=>s.jsx("span",{className:"flex h-5 w-5 rounded items-center justify-center text-muted-foreground bg-[var(--surface-muted)]",title:Ee,"aria-label":Ee,children:s.jsx(I,{name:pe,className:"h-3 w-3"})},be))}),s.jsx("button",{type:"button",onClick:()=>o(de.id,le),className:"flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]/50",title:t(Ne?"settings.providers.page.models.actions.showModelInSelectors":"settings.providers.page.models.actions.hideModelFromSelectors"),"aria-label":t(Ne?"settings.providers.page.models.actions.showModel":"settings.providers.page.models.actions.hideModel"),children:Ne?s.jsx(I,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"eye",className:"h-3.5 w-3.5"})})]})]})},le)})})]})]})]})})},V3=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)},z3=t=>{const e=at.c(106),{onItemSelect:n}=t,{t:r}=pt(),a=Ls(U3),i=Ls(W3),o=Ls(K3),c=Ls(H3),d=Ls(G3),p=Ls(q3),m=Ls(J3),u=Ls(Q3),h=Ls(Y3),b=Ls(X3),f=Ls(Z3),v=Ls(e5);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=t5;let y;e[3]!==h?(y=pe=>{h(pe),w({usageAutoRefresh:pe})},e[3]=h,e[4]=y):y=e[4];const k=y;let D;e[5]!==b?(D=pe=>{const Ee=Number(pe);Number.isFinite(Ee)&&(b(Ee),w({usageRefreshIntervalMs:Ee}))},e[5]=b,e[6]=D):D=e[6];const j=D;let S;e[7]!==f?(S=pe=>{pe!=="usage"&&pe!=="remaining"||(f(pe),w({usageDisplayMode:pe}))},e[7]=f,e[8]=S):S=e[8];const A=S;let E;e[9]===Symbol.for("react.memo_cache_sentinel")?(E=me("flex h-full flex-col","bg-background"),e[9]=E):E=e[9];let P;e[10]!==r?(P=r("settings.usage.sidebar.title"),e[10]=r,e[11]=P):P=e[11];let C;e[12]!==P?(C=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:P}),e[12]=P,e[13]=C):C=e[13];let N;e[14]!==r?(N=r("settings.usage.sidebar.total",{count:Mr.length}),e[14]=r,e[15]=N):N=e[15];let T;e[16]!==N?(T=s.jsx("span",{className:"typography-meta text-muted-foreground",children:N}),e[16]=N,e[17]=T):T=e[17];let M;e[18]!==r?(M=r("settings.usage.sidebar.actions.toggleAutoRefreshAria"),e[18]=r,e[19]=M):M=e[19];let R;e[20]!==k||e[21]!==M||e[22]!==p?(R=s.jsx(Ct,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(xs,{checked:p,onChange:k,ariaLabel:M})})}),e[20]=k,e[21]=M,e[22]=p,e[23]=R):R=e[23];let L;e[24]!==r?(L=r("settings.usage.sidebar.tooltip.autoRefresh"),e[24]=r,e[25]=L):L=e[25];let $;e[26]!==L?($=s.jsx(Pt,{side:"bottom",children:L}),e[26]=L,e[27]=$):$=e[27];let B;e[28]!==R||e[29]!==$?(B=s.jsxs(kt,{children:[R,$]}),e[28]=R,e[29]=$,e[30]=B):B=e[30];const O=String(m),_=!p;let ee;e[31]!==r?(ee=r("settings.usage.sidebar.field.intervalPlaceholder"),e[31]=r,e[32]=ee):ee=e[32];let z;e[33]!==ee?(z=s.jsx(us,{className:"w-fit",children:s.jsx(ys,{placeholder:ee})}),e[33]=ee,e[34]=z):z=e[34];let ne;e[35]===Symbol.for("react.memo_cache_sentinel")?(ne=s.jsxs(ms,{children:[s.jsx(Lt,{value:"30000",children:"30s"}),s.jsx(Lt,{value:"60000",children:"1m"}),s.jsx(Lt,{value:"300000",children:"5m"})]}),e[35]=ne):ne=e[35];let re;e[36]!==j||e[37]!==O||e[38]!==_||e[39]!==z?(re=s.jsxs(ds,{value:O,onValueChange:j,disabled:_,children:[z,ne]}),e[36]=j,e[37]=O,e[38]=_,e[39]=z,e[40]=re):re=e[40];let ue;e[41]!==c?(ue=()=>c(),e[41]=c,e[42]=ue):ue=e[42];let Q;e[43]!==r?(Q=r("settings.usage.sidebar.actions.refreshAria"),e[43]=r,e[44]=Q):Q=e[44];let de;e[45]!==r?(de=r("settings.usage.sidebar.actions.refreshTitle"),e[45]=r,e[46]=de):de=e[46];const X=d&&"animate-spin";let F;e[47]!==X?(F=me("h-3.5 w-3.5",X),e[47]=X,e[48]=F):F=e[48];let V;e[49]!==F?(V=s.jsx(I,{name:"refresh",className:F}),e[49]=F,e[50]=V):V=e[50];let q;e[51]!==d||e[52]!==ue||e[53]!==Q||e[54]!==de||e[55]!==V?(q=s.jsx(we,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 text-muted-foreground",onClick:ue,"aria-label":Q,title:de,disabled:d,children:V}),e[51]=d,e[52]=ue,e[53]=Q,e[54]=de,e[55]=V,e[56]=q):q=e[56];let te;e[57]!==B||e[58]!==re||e[59]!==q?(te=s.jsxs("div",{className:"flex items-center gap-2",children:[B,re,q]}),e[57]=B,e[58]=re,e[59]=q,e[60]=te):te=e[60];let U;e[61]!==T||e[62]!==te?(U=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[T,te]}),e[61]=T,e[62]=te,e[63]=U):U=e[63];let ae;e[64]!==r?(ae=r("settings.usage.sidebar.field.display"),e[64]=r,e[65]=ae):ae=e[65];let je;e[66]!==ae?(je=s.jsx("span",{className:"typography-micro text-muted-foreground",children:ae}),e[66]=ae,e[67]=je):je=e[67];let oe;e[68]!==r?(oe=r("settings.usage.sidebar.field.displayModePlaceholder"),e[68]=r,e[69]=oe):oe=e[69];let ve;e[70]!==oe?(ve=s.jsx(us,{className:"w-fit",children:s.jsx(ys,{placeholder:oe})}),e[70]=oe,e[71]=ve):ve=e[71];let K;e[72]!==r?(K=r("settings.usage.sidebar.field.displayModeUsage"),e[72]=r,e[73]=K):K=e[73];let ce;e[74]!==K?(ce=s.jsx(Lt,{value:"usage",children:K}),e[74]=K,e[75]=ce):ce=e[75];let Z;e[76]!==r?(Z=r("settings.usage.sidebar.field.displayModeRemaining"),e[76]=r,e[77]=Z):Z=e[77];let le;e[78]!==Z?(le=s.jsx(Lt,{value:"remaining",children:Z}),e[78]=Z,e[79]=le):le=e[79];let se;e[80]!==ce||e[81]!==le?(se=s.jsxs(ms,{children:[ce,le]}),e[80]=ce,e[81]=le,e[82]=se):se=e[82];let Ie;e[83]!==A||e[84]!==ve||e[85]!==se||e[86]!==u?(Ie=s.jsxs(ds,{value:u,onValueChange:A,children:[ve,se]}),e[83]=A,e[84]=ve,e[85]=se,e[86]=u,e[87]=Ie):Ie=e[87];let Ne;e[88]!==je||e[89]!==Ie?(Ne=s.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[je,Ie]}),e[88]=je,e[89]=Ie,e[90]=Ne):Ne=e[90];let Y;e[91]!==U||e[92]!==Ne||e[93]!==C?(Y=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[C,U,Ne]}),e[91]=U,e[92]=Ne,e[93]=C,e[94]=Y):Y=e[94];let fe;e[95]!==n||e[96]!==a||e[97]!==i||e[98]!==o||e[99]!==r?(fe=Mr.map(pe=>{const Ee=a.find(ge=>ge.providerId===pe.id),ze=V3(Ee?.usage),G=rf(ze),Pe=pe.id===i,Le=Ee?.configured??!1,Ae=Le?G==="critical"?{backgroundColor:"var(--status-error)"}:G==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"}:{backgroundColor:"var(--surface-muted-foreground)",opacity:.4};return s.jsx("div",{className:me("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",Pe?"bg-interactive-selection":"hover:bg-interactive-hover"),children:s.jsxs("button",{type:"button",onClick:()=>{o(pe.id),n?.()},className:"flex min-w-0 flex-1 items-center gap-2 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[s.jsx("span",{className:"h-2.5 w-2.5 rounded-full flex-shrink-0",style:Ae}),s.jsx(Sn,{providerId:pe.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:pe.name}),!Le&&s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:r("settings.usage.sidebar.status.notSet")})]})},pe.id)}),e[95]=n,e[96]=a,e[97]=i,e[98]=o,e[99]=r,e[100]=fe):fe=e[100];let ke;e[101]!==fe?(ke=s.jsx(Ts,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:fe}),e[101]=fe,e[102]=ke):ke=e[102];let be;return e[103]!==Y||e[104]!==ke?(be=s.jsxs("div",{className:E,children:[Y,ke]}),e[103]=Y,e[104]=ke,e[105]=be):be=e[105],be};function U3(t){return t.results}function W3(t){return t.selectedProviderId}function K3(t){return t.setSelectedProvider}function H3(t){return t.fetchAllQuotas}function G3(t){return t.isLoading}function q3(t){return t.autoRefresh}function J3(t){return t.refreshIntervalMs}function Q3(t){return t.displayMode}function Y3(t){return t.setAutoRefresh}function X3(t){return t.setRefreshInterval}function Z3(t){return t.setDisplayMode}function e5(t){return t.loadSettings}async function t5(t){try{await Ds(t)}catch(e){console.warn("Failed to save usage settings:",e)}}const Sc=t=>{const e=at.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=Ls(s5),u=m==="remaining"?r.remainingPercent:r.usedPercent,h=m==="remaining"?"remaining":"used";let b;e[0]!==u||e[1]!==r.valueLabel?(b=qi(r.valueLabel,u),e[0]=u,e[1]=r.valueLabel,e[2]=b):b=e[2];const f=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=zd(n),e[6]=n,e[7]=w):w=e[7];const y=w;let k;e[8]!==n||e[9]!==r.resetAt||e[10]!==r.usedPercent||e[11]!==r.windowSeconds?(k=Ji(r.usedPercent,r.resetAt,r.windowSeconds,n),e[8]=n,e[9]=r.resetAt,e[10]=r.usedPercent,e[11]=r.windowSeconds,e[12]=k):k=e[12];const D=k;let j;e:{if(!D||D.dailyAllocationPercent===null){j=null;break e}const re=_r(D.elapsedRatio);j=m==="remaining"?100-re:re}const S=j;let A;e[13]!==c||e[14]!==d||e[15]!==p?(A=d&&s.jsx(xs,{checked:p,onChange:re=>c?.(re),ariaLabel:"Show in dropdown"}),e[13]=c,e[14]=d,e[15]=p,e[16]=A):A=e[16];let E;e[17]!==y?(E=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:y}),e[17]=y,e[18]=E):E=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 C;e[21]!==E||e[22]!==P?(C=s.jsxs("div",{className:"min-w-0 flex flex-col",children:[E,P]}),e[21]=E,e[22]=P,e[23]=C):C=e[23];let N;e[24]!==C||e[25]!==A?(N=s.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[A,C]}),e[24]=C,e[25]=A,e[26]=N):N=e[26];const T=f==="-"?"":f;let M;e[27]!==T?(M=s.jsx("div",{className:"typography-ui-label text-foreground tabular-nums flex items-center justify-end",children:T}),e[27]=T,e[28]=M):M=e[28];let R;e[29]!==N||e[30]!==M?(R=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[N,M]}),e[29]=N,e[30]=M,e[31]=R):R=e[31];let L;e[32]!==u||e[33]!==S||e[34]!==r.usedPercent?(L=s.jsx(Yi,{percent:u,tonePercent:r.usedPercent,expectedMarkerPercent:S,className:"h-1.5"}),e[32]=u,e[33]=S,e[34]=r.usedPercent,e[35]=L):L=e[35];const $=g?`Resets ${g}`:"";let B;e[36]!==$?(B=s.jsx("span",{className:"typography-micro text-muted-foreground",children:$}),e[36]=$,e[37]=B):B=e[37];let O;e[38]!==h?(O=s.jsx("span",{className:"typography-micro text-muted-foreground",children:h}),e[38]=h,e[39]=O):O=e[39];let _;e[40]!==B||e[41]!==O?(_=s.jsxs("div",{className:"mt-1 flex items-center justify-between",children:[B,O]}),e[40]=B,e[41]=O,e[42]=_):_=e[42];let ee;e[43]!==L||e[44]!==_?(ee=s.jsxs("div",{className:"mt-2.5",children:[L,_]}),e[43]=L,e[44]=_,e[45]=ee):ee=e[45];let z;e[46]!==D?(z=D&&s.jsx("div",{className:"mt-1.5",children:s.jsx(Xi,{paceInfo:D})}),e[46]=D,e[47]=z):z=e[47];let ne;return e[48]!==R||e[49]!==ee||e[50]!==z?(ne=s.jsxs("div",{className:"py-3",children:[R,ee,z]}),e[48]=R,e[49]=ee,e[50]=z,e[51]=ne):ne=e[51],ne};function s5(t){return t.displayMode}const n5=t=>{if(!t)return"-";try{return new Date(t).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"})}catch{return"-"}},r5=()=>{const{t}=pt(),e=Ls(N=>N.results),n=Ls(N=>N.selectedProviderId),r=Ls(N=>N.setSelectedProvider),a=Ls(N=>N.loadSettings),i=Ls(N=>N.fetchAllQuotas),o=Ls(N=>N.isLoading),c=Ls(N=>N.lastUpdated),d=Ls(N=>N.error),p=Ls(N=>N.dropdownProviderIds),m=Ls(N=>N.setDropdownProviderIds),u=Ls(N=>N.selectedModels),h=Ls(N=>N.toggleModelSelected),b=Ls(N=>N.applyDefaultSelections);df(),l.useEffect(()=>{a(),i()},[a,i]),l.useEffect(()=>{if(n||e.length===0)return;const N=e.find(T=>T.configured)?.providerId;r(N??Mr[0]?.id??null)},[e,n,r]);const f=e.find(N=>N.providerId===n)??null,x=Mr.find(N=>N.id===n)?.name??n??t("settings.usage.sidebar.title"),g=f?.usage,w=n?p.includes(n):!1,y=l.useCallback(N=>{if(!n)return;const T=N?Array.from(new Set([...p,n])):p.filter(M=>M!==n);m(T),Ds({usageDropdownProviders:T})},[p,n,m]),k=l.useMemo(()=>g?.models?Object.entries(g.models).map(([N,T])=>({name:N,windows:T})).filter(N=>Object.keys(N.windows.windows).length>0):[],[g?.models]);l.useEffect(()=>{n&&k.length>0&&b(n,k.map(N=>N.name))},[n,k,b]);const D=l.useMemo(()=>!n||k.length===0?new Map:Pv(k,N=>N.name,n),[k,n]),j=l.useMemo(()=>{if(!n)return[];const N=lf(n);return cf(N)},[n]),[S,A]=l.useState(()=>({})),E=l.useCallback(N=>{A(T=>({...T,[N]:!T[N]}))},[]),P=l.useCallback(N=>{if(!n)return;h(n,N);const T=u[n]??[],R=T.includes(N)?T.filter($=>$!==N):[...T,N],L={...u,[n]:R};Ds({usageSelectedModels:L})},[n,u,h]),C=n?u[n]??[]:[];return n?s.jsx(Ts,{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(Sn,{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:n5(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(xs,{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(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:t("settings.usage.page.options.showInHeaderTooltip")})]})]})]})}),!f&&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})]}),f&&!f.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,T])=>s.jsx(Sc,{title:N,window:T},N))})})}),k.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 T=D.get(N.id)??[];if(T.length===0)return null;const M=S[N.id]??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(ur,{open:!M,onOpenChange:()=>E(N.id),children:[s.jsxs(wr,{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:["(",T.length,")"]})]}),M?s.jsx(I,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(mr,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:T.map(R=>{const L=Object.entries(R.windows.windows);if(L.length===0)return null;const[$,B]=L[0],O=C.includes(R.name);return s.jsx(Sc,{title:$,subtitle:il(R.name),window:B,showToggle:!0,toggleEnabled:O,onToggle:()=>P(R.name)},R.name)})})})]})},N.id)}),(()=>{const N=D.get(null)??[];if(N.length===0)return null;const T=S.other??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(ur,{open:!T,onOpenChange:()=>E("other"),children:[s.jsxs(wr,{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,")"]})]}),T?s.jsx(I,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(mr,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:N.map(M=>{const R=Object.entries(M.windows.windows);if(R.length===0)return null;const[L,$]=R[0],B=C.includes(M.name);return s.jsx(Sc,{title:L,subtitle:il(M.name),window:$,showToggle:!0,toggleEnabled:B,onToggle:()=>P(M.name)},M.name)})})})]})})})()]})]}),f?.configured&&g&&Object.keys(g.windows??{}).length===0&&k.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")})})},a5="git.commit.generate",hd=tr(t=>({selectedPromptId:a5,setSelectedPromptId:e=>{t(n=>n.selectedPromptId===e?n:{selectedPromptId:e})}})),i5=t=>{const e=at.c(23),{onItemSelect:n}=t,{t:r}=pt(),a=hd(o5),i=hd(l5);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 h;e[6]!==u?(h=s.jsx("h2",{className:"text-base font-semibold text-foreground",children:u}),e[6]=u,e[7]=h):h=e[7];let b;e[8]!==r?(b=r("settings.magicPrompts.sidebar.description"),e[8]=r,e[9]=b):b=e[9];let f;e[10]!==b?(f=s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:b}),e[10]=b,e[11]=f):f=e[11];let v;e[12]!==h||e[13]!==f?(v=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[h,f]}),e[12]=h,e[13]=f,e[14]=v):v=e[14];let x;e[15]!==n||e[16]!==a||e[17]!==i||e[18]!==r?(x=s.jsx(Ts,{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 k=a===y.id;return s.jsx("button",{type:"button",onClick:()=>{i(y.id),n?.()},className:me("flex w-full items-center rounded-md px-2 py-1.5 text-left transition-colors",k?"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 o5(t){return t.selectedPromptId}function l5(t){return t.setSelectedPromptId}const dp={"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"}]}},up=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),mp=t=>t.endsWith(".visible"),c5=()=>{const{t}=pt(),e=l.useCallback(j=>t(j),[t]),n=hd(j=>j.selectedPromptId),[r,a]=l.useState(!0),[i,o]=l.useState({}),[c,d]=l.useState({}),[p,m]=l.useState({}),[u,h]=l.useState({}),[b,f]=l.useState(!1);l.useEffect(()=>{let j=!0;return(async()=>{a(!0);try{const A=await Db();if(!j)return;o(A)}catch(A){console.warn("Failed to load magic prompts:",A),H.error(t("settings.magicPrompts.page.toast.loadFailed"))}finally{j&&a(!1)}})(),()=>{j=!1}},[t]);const v=dp[n]??dp["git.commit.generate"],x=l.useCallback(j=>up(i,j)?i[j]:Gl(j),[i]),g=l.useCallback(j=>c[j]??x(j),[c,x]),w=l.useCallback((j,S)=>{d(A=>A[j]===S?A:{...A,[j]:S})},[]),y=l.useCallback(async j=>{const S=g(j);if(mp(j)&&S.trim().length===0){H.error(t("settings.magicPrompts.page.toast.visiblePromptRequired"));return}m(A=>({...A,[j]:!0}));try{const A=S===Gl(j)?await bu(j):await Ib(j,S);o(A.overrides),H.success(t("settings.magicPrompts.page.toast.saved"))}catch(A){const E=A instanceof Error?A.message:String(A);H.error(t("settings.magicPrompts.page.toast.saveFailed"),{description:E})}finally{m(A=>({...A,[j]:!1}))}},[g,t]),k=l.useCallback(async j=>{h(S=>({...S,[j]:!0}));try{const S=await bu(j);o(S.overrides),d(A=>({...A,[j]:Gl(j)})),H.success(t("settings.magicPrompts.page.toast.resetSuccess"))}catch(S){const A=S instanceof Error?S.message:String(S);H.error(t("settings.magicPrompts.page.toast.resetFailed"),{description:A})}finally{h(S=>({...S,[j]:!1}))}},[t]),D=l.useCallback(async()=>{f(!0);try{const j=await Pb();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{f(!1)}},[t]);return r?s.jsxs("div",{className:"py-6 px-6 flex items-center gap-2 text-muted-foreground",children:[s.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-current animate-busy-pulse","aria-label":t("settings.magicPrompts.page.loading.aria")}),s.jsx("span",{className:"typography-ui",children:t("settings.magicPrompts.page.loading.text")})]}):s.jsx("div",{className:"h-full overflow-auto",children:s.jsxs("div",{className:"mx-auto w-full max-w-4xl px-6 py-6 space-y-4",children:[s.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[s.jsx("div",{className:"space-y-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground",children:e(v.titleKey)}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:e(v.descriptionKey)})]})]})}),s.jsx(we,{variant:"outline",size:"sm",onClick:()=>{D()},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 A=Ab(j.id),E=x(j.id),P=g(j.id),C=up(i,j.id),N=P!==E,T=mp(j.id)&&P.trim().length===0,M=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(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:A.description})]})]}),A.placeholders&&A.placeholders.length>0&&s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[t("settings.magicPrompts.page.placeholdersLabel")," ",A.placeholders.map(L=>`{{${L.key}}}`).join(", ")]})]}),s.jsx(bn,{value:P,onChange:L=>w(j.id,L.target.value),className:"min-h-[220px] font-mono text-sm"}),T&&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":C?"settings.magicPrompts.page.status.usingSavedOverride":"settings.magicPrompts.page.status.usingBuiltinDefault")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(we,{variant:"outline",size:"sm",onClick:()=>{k(j.id)},disabled:!C||M||R,children:t(R?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetToDefault")}),s.jsx(we,{size:"sm",onClick:()=>{y(j.id)},disabled:!N||M||R||T,children:t(M?"settings.common.actions.saving":"settings.magicPrompts.page.actions.save")})]})]})]},j.id)})]})})},ag=()=>{const{t}=pt(),e=gt(u=>u.settingsGitmojiEnabled),n=gt(u=>u.setSettingsGitmojiEnabled),r=Ed(),a=Te(u=>u.gitChangesViewMode),i=Te(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 h=null;if(!h){const b=dr()?.settings;if(b)try{const v=(await b.load())?.settings;v&&(h={gitmojiEnabled:typeof v.gitmojiEnabled=="boolean"?v.gitmojiEnabled:void 0,gitChangesViewMode:v.gitChangesViewMode==="flat"||v.gitChangesViewMode==="tree"?v.gitChangesViewMode:void 0})}catch{}}if(!h){const b=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});b.ok&&(h=await b.json())}h&&(typeof h.gitmojiEnabled=="boolean"&&n(h.gitmojiEnabled),(h.gitChangesViewMode==="flat"||h.gitChangesViewMode==="tree")&&i(h.gitChangesViewMode))}catch(h){console.warn("Failed to load git settings:",h)}finally{c(!1)}})()},[i,n]);const p=l.useCallback(async u=>{n(u);try{await Ds({gitmojiEnabled:u})}catch(h){console.warn("Failed to save gitmoji setting:",h)}},[n]),m=l.useCallback(u=>{u!==a&&(i(u),Ds({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 h=a===u.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":h,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:h,onChange:()=>{m(u.id)},ariaLabel:t("settings.openchamber.git.optionAria",{option:u.label})}),s.jsx("span",{className:h?"typography-ui-label font-normal text-foreground":"typography-ui-label font-normal text-foreground/50",children:u.label})]},u.id)})})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":e,onClick:()=>{p(!e)},onKeyDown:u=>{(u.key===" "||u.key==="Enter")&&(u.preventDefault(),p(!e))},children:[s.jsx(xs,{checked:e,onChange:u=>{p(u)},ariaLabel:t("settings.openchamber.git.enableGitmojiAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.git.enableGitmoji")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":r,onClick:()=>ql(!r),onKeyDown:u=>{(u.key===" "||u.key==="Enter")&&(u.preventDefault(),ql(!r))},children:[s.jsx(xs,{checked:r,onChange:ql,ariaLabel:t("settings.openchamber.git.showGitignoredAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.git.showGitignored")})]})]})]})},ig=()=>{const{t}=pt(),{isMobile:e}=an(),n=dr()?.github,r=Kn(A=>A.status),a=Kn(A=>A.isLoading),i=Kn(A=>A.hasChecked),o=Kn(A=>A.refreshStatus),c=Kn(A=>A.setStatus),d=l.useCallback(async A=>{await Xn(A)},[]),[p,m]=l.useState(!1),[u,h]=l.useState(null),[b,f]=l.useState(null),v=l.useRef(null),x=l.useCallback(()=>{v.current!=null&&(window.clearInterval(v.current),v.current=null),f(null)},[]);l.useEffect(()=>((async()=>{try{i||await o(n)}catch(A){console.warn("Failed to load GitHub auth status:",A)}})(),()=>{x()}),[i,o,n,x]);const g=l.useCallback(async()=>{m(!0);try{const A=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({})}),C=await P.json().catch(()=>null);if(!P.ok||!C||!("deviceCode"in C))throw new Error(C?.error||P.statusText);return C})();h(A),f(Math.max(1,A.interval)*1e3);const E=A.verificationUriComplete||A.verificationUri;d(E)}catch(A){console.error("Failed to start GitHub connect:",A),H.error(t("settings.github.page.toast.startConnectFailed"))}finally{m(!1)}},[d,n,t]),w=l.useCallback(async A=>{if(n)return n.authComplete(A);const E=await fetch("/api/github/auth/complete",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({deviceCode:A})}),P=await E.json().catch(()=>null);if(!E.ok||!P)throw new Error(P?.error||E.statusText);return P},[n]);l.useEffect(()=>{if(!(!u?.deviceCode||!b)&&v.current==null)return v.current=window.setInterval(()=>{(async()=>{try{const A=await w(u.deviceCode);if(A.connected){H.success(t("settings.github.page.toast.connected")),h(null),x(),await o(n,{force:!0});return}A.status==="slow_down"&&f(E=>E?E+5e3:5e3),(A.status==="expired_token"||A.status==="access_denied")&&(H.error(A.error||t("settings.github.page.toast.authorizationFailed")),h(null),x())}catch(A){console.warn("GitHub polling failed:",A)}})()},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(),h(null),n)await n.authDisconnect();else{const A=await fetch("/api/github/auth",{method:"DELETE",headers:{Accept:"application/json"}});if(!A.ok)throw new Error(A.statusText)}H.success(t("settings.github.page.toast.disconnected")),await o(n,{force:!0})}catch(A){console.error("Failed to disconnect GitHub:",A),H.error(t("settings.github.page.toast.disconnectFailed"))}finally{m(!1)}},[o,n,x,t]),k=l.useCallback(async A=>{if(A){m(!0);try{const E=n?await n.authActivate(A):await(async()=>{const P=await fetch("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:A})}),C=await P.json().catch(()=>null);if(!P.ok||!C)throw new Error(C?.error||P.statusText);return C})();c(E),H.success(t("settings.github.page.toast.accountSwitched"))}catch(E){console.error("Failed to switch GitHub account:",E),H.error(t("settings.github.page.toast.accountSwitchFailed"))}finally{m(!1)}}},[n,c,t]);if(a)return null;const D=!!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(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{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:[D?s.jsxs("div",{className:me("px-4 py-3",e?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[s.jsxs("div",{className:me("flex min-w-0 items-center gap-4",e?"w-full":void 0),children:[j?.avatarUrl?s.jsx("img",{src:j.avatarUrl,alt:j.login?t("settings.github.page.avatarAlt.withLogin",{login:j.login}):t("settings.github.page.avatarAlt.fallback"),className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:j?.name?.trim()||j?.login||"GitHub"}),s.jsxs("div",{className:me("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",e?"flex-wrap":"truncate"),children:[s.jsx(I,{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(we,{size:"sm",variant:"outline",onClick:y,disabled:p,className:me("text-[var(--status-error)] hover:text-[var(--status-error)]",e?"w-full":void 0),children:t("settings.github.page.actions.disconnect")})]}):s.jsxs("div",{className:"flex items-center justify-between gap-4 px-4 py-4",children:[s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.github.page.status.notConnected")})}),s.jsx(we,{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(A=>{const E=A.user,P=!!A.current;return s.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-[var(--surface-subtle)] bg-[var(--surface-muted)] px-3 py-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[E?.avatarUrl?s.jsx("img",{src:E.avatarUrl,alt:E.login?t("settings.github.page.avatarAlt.withLogin",{login:E.login}):t("settings.github.page.avatarAlt.fallback"),className:"h-6 w-6 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:s.jsx(I,{name:"github-fill",className:"h-3 w-3 text-muted-foreground"})}),s.jsxs("div",{className:"min-w-0 flex flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:E?.name?.trim()||E?.login||"GitHub"}),E?.login&&s.jsx("span",{className:"typography-micro text-muted-foreground truncate font-mono",children:E.login})]})]}),P?s.jsx("span",{className:"typography-micro text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-1.5 py-0.5 rounded",children:t("settings.github.page.status.active")}):s.jsx(we,{size:"sm",variant:"ghost",onClick:()=>k(A.id),disabled:p,children:t("settings.github.page.actions.switchTo")})]},A.id)})})]})]}),D&&s.jsx("div",{className:"mt-2 px-2 pb-2",children:s.jsx(we,{size:"sm",variant:"outline",onClick:g,disabled:p,className:me(e?"w-full":void 0),children:t("settings.github.page.actions.addAccount")})}),u&&s.jsxs("div",{className:"mt-4 rounded-lg bg-[var(--surface-elevated)]/70 p-4 border border-[var(--interactive-border)]",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx("h4",{className:"typography-ui-label text-foreground",children:t("settings.github.page.flow.title")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.github.page.flow.description")})]}),s.jsxs("div",{className:"flex items-center justify-between gap-3 mt-4",children:[s.jsx("div",{className:"font-mono text-xl tracking-widest text-foreground bg-[var(--surface-muted)] px-3 py-1.5 rounded-md border border-[var(--interactive-border)]",children:u.userCode}),s.jsx(we,{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(we,{size:"sm",variant:"ghost",disabled:p,onClick:()=>{x(),h(null)},children:t("settings.common.actions.cancel")})]})]})]})},pp=[{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)"}],d5=[{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"}],u5=({open:t,onOpenChange:e,profileId:n,importData:r})=>{const{t:a}=pt(),i=Jn(z=>z.getProfileById),o=Jn(z=>z.createProfile),c=Jn(z=>z.updateProfile),d=Jn(z=>z.deleteProfile),p=l.useMemo(()=>n&&n!=="new"&&!r?i(n):null,[n,i,r]),m=n==="new"||r!=null,u=n==="global",[h,b]=l.useState(""),[f,v]=l.useState(""),[x,g]=l.useState(""),[w,y]=l.useState("ssh"),[k,D]=l.useState(""),[j,S]=l.useState(""),[A,E]=l.useState("keyword"),[P,C]=l.useState("branch"),[N,T]=l.useState(!1),[M,R]=l.useState(!1),[L,$]=l.useState(!1);l.useEffect(()=>{if(t){if(r){const z=r.host.split("/"),ne=z.length>=3?z[z.length-1]:r.host;b(ne),v(r.username),g(""),y("token"),D(""),S(r.host),E("string"),C("code")}else if(m)b(""),v(""),g(""),y("ssh"),D(""),S(""),E("keyword"),C("branch");else if(p)b(p.name),v(p.userName),g(p.userEmail),y(p.authType||"ssh"),D(p.sshKey||""),S(p.host||""),E(p.color||"keyword"),C(p.icon||"branch");else if(u){const z=i("global");z&&(b(z.name),v(z.userName),g(z.userEmail),y(z.authType||"ssh"),D(z.sshKey||""),S(z.host||""),E(z.color||"keyword"),C(z.icon||"branch"))}}},[t,n,p,m,r,u,i]);const B=async()=>{if(!f.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}T(!0);try{const z={name:h.trim()||f.trim(),userName:f.trim(),userEmail:x.trim(),authType:w,sshKey:w==="ssh"&&k.trim()||null,host:w==="token"&&j.trim()||null,color:A,icon:P};let ne;if(m)ne=await o(z);else if(n)ne=await c(n,z);else return;ne?(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(z){console.error("Error saving profile:",z),H.error(a("settings.gitIdentities.editor.toast.saveUnexpectedError"))}finally{T(!1)}},O=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(z){console.error("Error deleting profile:",z),H.error(a("settings.gitIdentities.editor.toast.deleteUnexpectedError"))}finally{$(!1)}}},_=l.useMemo(()=>pp.find(ne=>ne.key===A)?.cssVar||"var(--syntax-keyword)",[A]),ee=r?a("settings.gitIdentities.editor.title.importCredential"):m?a("settings.gitIdentities.editor.title.newIdentity"):u?a("settings.gitIdentities.editor.title.globalIdentity"):p?.name||a("settings.gitIdentities.editor.title.editIdentity");return s.jsxs(s.Fragment,{children:[s.jsx(ws,{open:t,onOpenChange:e,children:s.jsxs(vs,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[s.jsxs(Cs,{children:[s.jsx(js,{children:ee}),s.jsx(Rs,{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(Kt,{value:h,onChange:z=>b(z.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:pp.map(z=>s.jsx("button",{type:"button",onClick:()=>E(z.key),className:me("w-6 h-6 rounded-md border-2 transition-all cursor-pointer",A===z.key?"border-foreground scale-110":"border-transparent hover:border-border"),style:{backgroundColor:z.cssVar},title:z.label},z.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:d5.map(z=>{const ne=z.Icon;return s.jsx("button",{type:"button",onClick:()=>C(z.key),className:me("w-7 h-7 rounded-md border-2 transition-all flex items-center justify-center cursor-pointer",P===z.key?"border-[var(--interactive-border)] bg-[var(--surface-muted)]":"border-transparent hover:border-[var(--interactive-border)] hover:bg-[var(--surface-muted)]/50"),title:z.label,children:s.jsx(I,{name:ne,className:"w-3.5 h-3.5",style:{color:P===z.key?_:"var(--surface-muted-foreground)"}})},z.key)})})]})]}),!u&&s.jsx("div",{className:"border-t border-border/40"}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:a("settings.gitIdentities.editor.field.userName")}),!u&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:a("settings.gitIdentities.editor.field.userNameTooltip")})]})]}),s.jsx(Kt,{value:f,onChange:z=>v(z.target.value),placeholder:a("settings.gitIdentities.editor.field.userNamePlaceholder"),required:!u,readOnly:u,disabled:u,className:"h-8"})]}),s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:a("settings.gitIdentities.editor.field.emailAddress")}),!u&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:a("settings.gitIdentities.editor.field.emailAddressTooltip")})]})]}),s.jsx(Kt,{type:"email",value:x,onChange:z=>g(z.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(we,{size:"sm",type:"button",variant:"chip","aria-pressed":w==="ssh",onClick:()=>y("ssh"),children:[s.jsx(I,{name:"lock-2",className:"w-3.5 h-3.5 mr-1"})," SSH"]}),s.jsxs(we,{size:"sm",type:"button",variant:"chip","aria-pressed":w==="token",onClick:()=>y("token"),children:[s.jsx(I,{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(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:a("settings.gitIdentities.editor.field.sshKeyPathTooltip")})]})]}),s.jsx(Kt,{value:k,onChange:z=>D(z.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(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:a("settings.gitIdentities.editor.field.hostTooltip")})]})]}),s.jsx(Kt,{value:j,onChange:z=>S(z.target.value),placeholder:a("settings.gitIdentities.editor.field.hostPlaceholder"),required:!0,className:"h-8 font-mono text-xs"})]})]})]})]}),s.jsxs(Ks,{className:"gap-2",children:[!u&&!m&&s.jsxs(we,{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(I,{name:"delete-bin",className:"w-3.5 h-3.5 mr-1"})," ",a("settings.common.actions.delete")]}),s.jsx(we,{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(we,{size:"sm",onClick:B,disabled:N,children:a(N?"settings.common.actions.saving":m?"settings.gitIdentities.editor.actions.create":"settings.gitIdentities.editor.actions.save")})]})]})}),s.jsx(ws,{open:M,onOpenChange:z=>{L||R(z)},children:s.jsxs(vs,{className:"max-w-md",children:[s.jsxs(Cs,{children:[s.jsx(js,{children:a("settings.gitIdentities.page.deleteDialog.title")}),s.jsx(Rs,{children:a("settings.gitIdentities.page.deleteDialog.description",{name:p?.name||h})})]}),s.jsxs(Ks,{children:[s.jsx(we,{variant:"ghost",onClick:()=>R(!1),disabled:L,children:a("settings.common.actions.cancel")}),s.jsx(we,{size:"sm",variant:"destructive",onClick:()=>{O()},disabled:L,children:a("settings.common.actions.delete")})]})]})})]})},m5={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart"},p5={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)"},h5=()=>{const t=at.c(116),{t:e}=pt(),{profiles:n,globalIdentity:r,defaultGitIdentityId:a,deleteProfile:i,loadProfiles:o,loadGlobalIdentity:c,loadDiscoveredCredentials:d,loadDefaultGitIdentityId:p,setDefaultGitIdentityId:m,getUnimportedCredentials:u}=Jn(pr(g5)),[h,b]=l.useState(!1),[f,v]=l.useState(null),[x,g]=l.useState(null),[w,y]=l.useState(null),[k,D]=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 A,E,P,C,N,T,M,R,L,$,B,O,_;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 Y=u();let fe;t[27]===Symbol.for("react.memo_cache_sentinel")?(fe=(W,ie)=>{v(W),g(ie??null),b(!0)},t[27]=fe):fe=t[27];const ke=fe;let be;t[28]!==a||t[29]!==m||t[30]!==e?(be=async W=>{const ie=a===W?null:W;if(!await m(ie)){H.error(e("settings.gitIdentities.page.toast.updateDefaultFailed"));return}H.success(e(ie?"settings.gitIdentities.page.toast.defaultUpdated":"settings.gitIdentities.page.toast.defaultUnset"))},t[28]=a,t[29]=m,t[30]=e,t[31]=be):be=t[31];const pe=be;let Ee;t[32]!==w||t[33]!==i||t[34]!==e?(Ee=async()=>{if(!w)return;D(!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")),D(!1)},t[32]=w,t[33]=i,t[34]=e,t[35]=Ee):Ee=t[35],E=Ee,A=Ts,C="h-full",N="w-full bg-background",_="mx-auto w-full max-w-3xl space-y-6 p-3 sm:p-6 sm:pt-8",t[36]===Symbol.for("react.memo_cache_sentinel")?(P=s.jsx(ig,{}),t[36]=P):P=t[36],B="border-t border-border/40 pt-6";let ze;t[37]!==e?(ze=e("settings.gitIdentities.page.section.title"),t[37]=e,t[38]=ze):ze=t[38];let G;t[39]!==ze?(G=s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:ze})}),t[39]=ze,t[40]=G):G=t[40];let Pe,Le;t[41]===Symbol.for("react.memo_cache_sentinel")?(Pe=()=>ke("new"),Le=s.jsx(I,{name:"add",className:"w-3.5 h-3.5 mr-1"}),t[41]=Pe,t[42]=Le):(Pe=t[41],Le=t[42]);let Ae;t[43]!==e?(Ae=e("settings.common.badge.new"),t[43]=e,t[44]=Ae):Ae=t[44];let ge;t[45]!==Ae?(ge=s.jsxs(we,{size:"sm",variant:"outline",onClick:Pe,children:[Le," ",Ae]}),t[45]=Ae,t[46]=ge):ge=t[46],t[47]!==G||t[48]!==ge?(O=s.jsxs("div",{className:"mb-3 px-1 flex items-start justify-between gap-4",children:[G,ge]}),t[47]=G,t[48]=ge,t[49]=O):O=t[49],T="rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",M=r&&s.jsx(hp,{profile:r,isDefault:a==="global",onEdit:()=>ke("global"),onToggleDefault:()=>pe("global"),isReadOnly:!0,hasBorder:n.length>0||Y.length>0}),R=n.map((W,ie)=>s.jsx(hp,{profile:W,isDefault:a===W.id,onEdit:()=>ke(W.id),onToggleDefault:()=>pe(W.id),onDelete:()=>y(W),hasBorder:ie<n.length-1||Y.length>0},W.id)),L=!r&&n.length===0&&Y.length===0&&s.jsxs("div",{className:"py-8 px-4 text-center text-muted-foreground",children:[s.jsx(I,{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")})]}),$=Y.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")})}),Y.map((W,ie)=>s.jsx(f5,{credential:W,onImport:()=>ke("new",{host:W.host,username:W.username}),hasBorder:ie<Y.length-1},`${W.host}-${W.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]=A,t[15]=E,t[16]=P,t[17]=C,t[18]=N,t[19]=T,t[20]=M,t[21]=R,t[22]=L,t[23]=$,t[24]=B,t[25]=O,t[26]=_}else A=t[14],E=t[15],P=t[16],C=t[17],N=t[18],T=t[19],M=t[20],R=t[21],L=t[22],$=t[23],B=t[24],O=t[25],_=t[26];let ee;t[50]!==T||t[51]!==M||t[52]!==R||t[53]!==L||t[54]!==$?(ee=s.jsxs("div",{className:T,children:[M,R,L,$]}),t[50]=T,t[51]=M,t[52]=R,t[53]=L,t[54]=$,t[55]=ee):ee=t[55];let z;t[56]!==ee||t[57]!==B||t[58]!==O?(z=s.jsxs("div",{className:B,children:[O,ee]}),t[56]=ee,t[57]=B,t[58]=O,t[59]=z):z=t[59];let ne;t[60]===Symbol.for("react.memo_cache_sentinel")?(ne=s.jsx(ag,{}),t[60]=ne):ne=t[60];let re;t[61]!==P||t[62]!==z||t[63]!==_?(re=s.jsxs("div",{className:_,children:[P,z,ne]}),t[61]=P,t[62]=z,t[63]=_,t[64]=re):re=t[64];let ue;t[65]!==A||t[66]!==C||t[67]!==N||t[68]!==re?(ue=s.jsx(A,{outerClassName:C,className:N,children:re}),t[65]=A,t[66]=C,t[67]=N,t[68]=re,t[69]=ue):ue=t[69];let Q;t[70]!==x||t[71]!==h||t[72]!==f?(Q=s.jsx(u5,{open:h,onOpenChange:b,profileId:f,importData:x}),t[70]=x,t[71]=h,t[72]=f,t[73]=Q):Q=t[73];const de=w!==null;let X;t[74]!==k?(X=Y=>{k||Y||y(null)},t[74]=k,t[75]=X):X=t[75];let F;t[76]!==e?(F=e("settings.gitIdentities.page.deleteDialog.title"),t[76]=e,t[77]=F):F=t[77];let V;t[78]!==F?(V=s.jsx(js,{children:F}),t[78]=F,t[79]=V):V=t[79];const q=w?.name??"";let te;t[80]!==e||t[81]!==q?(te=e("settings.gitIdentities.page.deleteDialog.description",{name:q}),t[80]=e,t[81]=q,t[82]=te):te=t[82];let U;t[83]!==te?(U=s.jsx(Rs,{children:te}),t[83]=te,t[84]=U):U=t[84];let ae;t[85]!==V||t[86]!==U?(ae=s.jsxs(Cs,{children:[V,U]}),t[85]=V,t[86]=U,t[87]=ae):ae=t[87];let je;t[88]===Symbol.for("react.memo_cache_sentinel")?(je=()=>y(null),t[88]=je):je=t[88];let oe;t[89]!==e?(oe=e("settings.common.actions.cancel"),t[89]=e,t[90]=oe):oe=t[90];let ve;t[91]!==k||t[92]!==oe?(ve=s.jsx(we,{variant:"ghost",onClick:je,disabled:k,children:oe}),t[91]=k,t[92]=oe,t[93]=ve):ve=t[93];let K;t[94]!==E?(K=()=>{E()},t[94]=E,t[95]=K):K=t[95];let ce;t[96]!==e?(ce=e("settings.common.actions.delete"),t[96]=e,t[97]=ce):ce=t[97];let Z;t[98]!==k||t[99]!==K||t[100]!==ce?(Z=s.jsx(we,{size:"sm",variant:"destructive",onClick:K,disabled:k,children:ce}),t[98]=k,t[99]=K,t[100]=ce,t[101]=Z):Z=t[101];let le;t[102]!==ve||t[103]!==Z?(le=s.jsxs(Ks,{children:[ve,Z]}),t[102]=ve,t[103]=Z,t[104]=le):le=t[104];let se;t[105]!==ae||t[106]!==le?(se=s.jsxs(vs,{className:"max-w-md",children:[ae,le]}),t[105]=ae,t[106]=le,t[107]=se):se=t[107];let Ie;t[108]!==de||t[109]!==X||t[110]!==se?(Ie=s.jsx(ws,{open:de,onOpenChange:X,children:se}),t[108]=de,t[109]=X,t[110]=se,t[111]=Ie):Ie=t[111];let Ne;return t[112]!==ue||t[113]!==Q||t[114]!==Ie?(Ne=s.jsxs(s.Fragment,{children:[ue,Q,Ie]}),t[112]=ue,t[113]=Q,t[114]=Ie,t[115]=Ne):Ne=t[115],Ne},hp=t=>{const e=at.c(54),{profile:n,isDefault:r,onEdit:a,onToggleDefault:i,onDelete:o,isReadOnly:c,hasBorder:d}=t,{t:p}=pt(),m=m5[n.icon||"branch"]||"git-branch",u=p5[n.color||""],h=n.authType||"ssh",b=d&&"border-b border-[var(--surface-subtle)]";let f;e[0]!==b?(f=me("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]=f):f=e[1];let v;e[2]!==a?(v=B=>{(B.key==="Enter"||B.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(I,{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]!==h?(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:h}),e[11]=h,e[12]=y):y=e[12];let k;e[13]!==r||e[14]!==p?(k=r&&s.jsx("span",{className:"typography-micro text-primary bg-primary/12 px-1 rounded flex-shrink-0 leading-none pb-px border border-primary/25",children:p("settings.gitIdentities.page.badge.default")}),e[13]=r,e[14]=p,e[15]=k):k=e[15];let D;e[16]!==c||e[17]!==p?(D=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]=D):D=e[18];let j;e[19]!==w||e[20]!==y||e[21]!==k||e[22]!==D?(j=s.jsxs("div",{className:"flex items-center gap-1.5",children:[w,y,k,D]}),e[19]=w,e[20]=y,e[21]=k,e[22]=D,e[23]=j):j=e[23];const S=h==="token"&&n.host?n.host:n.userEmail;let A;e[24]!==S?(A=s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:S}),e[24]=S,e[25]=A):A=e[25];let E;e[26]!==j||e[27]!==A?(E=s.jsxs("div",{className:"min-w-0",children:[j,A]}),e[26]=j,e[27]=A,e[28]=E):E=e[28];let P;e[29]!==E||e[30]!==g?(P=s.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[g,E]}),e[29]=E,e[30]=g,e[31]=P):P=e[31];let C;e[32]===Symbol.for("react.memo_cache_sentinel")?(C=s.jsx(Os,{asChild:!0,children:s.jsx(we,{size:"icon",variant:"ghost",className:"h-6 w-6 shrink-0 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",onClick:x5,children:s.jsx(I,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[32]=C):C=e[32];let N;e[33]!==i?(N=B=>{B.stopPropagation(),i()},e[33]=i,e[34]=N):N=e[34];let T;e[35]!==r||e[36]!==p?(T=p(r?"settings.gitIdentities.page.actions.unsetDefault":"settings.gitIdentities.page.actions.setAsDefault"),e[35]=r,e[36]=p,e[37]=T):T=e[37];let M;e[38]!==N||e[39]!==T?(M=s.jsx(zt,{onClick:N,children:T}),e[38]=N,e[39]=T,e[40]=M):M=e[40];let R;e[41]!==c||e[42]!==o||e[43]!==p?(R=!c&&o&&s.jsxs(zt,{onClick:B=>{B.stopPropagation(),o()},className:"text-destructive focus:text-destructive",children:[s.jsx(I,{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 L;e[45]!==M||e[46]!==R?(L=s.jsxs(Bs,{children:[C,s.jsxs($s,{align:"end",className:"w-fit min-w-28",children:[M,R]})]}),e[45]=M,e[46]=R,e[47]=L):L=e[47];let $;return e[48]!==a||e[49]!==P||e[50]!==f||e[51]!==L||e[52]!==v?($=s.jsxs("div",{className:f,onClick:a,role:"button",tabIndex:0,onKeyDown:v,children:[P,L]}),e[48]=a,e[49]=P,e[50]=f,e[51]=L,e[52]=v,e[53]=$):$=e[53],$},f5=t=>{const e=at.c(21),{credential:n,onImport:r,hasBorder:a}=t,{t:i}=pt();let o;e[0]!==n.host?(o=n.host.split("/"),e[0]=n.host,e[1]=o):o=e[1];const c=o,d=c.length>=3?c[c.length-1]:n.host,p=n.host.includes("/"),m=a&&"border-b border-[var(--surface-subtle)]";let u;e[2]!==m?(u=me("flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30",m),e[2]=m,e[3]=u):u=e[3];let h;e[4]!==d?(h=s.jsx("span",{className:"typography-ui-label text-foreground truncate block",children:d}),e[4]=d,e[5]=h):h=e[5];const b=p?n.host:n.username;let f;e[6]!==b?(f=s.jsx("span",{className:"typography-micro text-muted-foreground/60 truncate block leading-tight",children:b}),e[6]=b,e[7]=f):f=e[7];let v;e[8]!==h||e[9]!==f?(v=s.jsxs("div",{className:"min-w-0",children:[h,f]}),e[8]=h,e[9]=f,e[10]=v):v=e[10];let x;e[11]===Symbol.for("react.memo_cache_sentinel")?(x=s.jsx(I,{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(we,{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 g5(t){return{profiles:t.profiles,globalIdentity:t.globalIdentity,defaultGitIdentityId:t.defaultGitIdentityId,deleteProfile:t.deleteProfile,loadProfiles:t.loadProfiles,loadGlobalIdentity:t.loadGlobalIdentity,loadDiscoveredCredentials:t.loadDiscoveredCredentials,loadDefaultGitIdentityId:t.loadDefaultGitIdentityId,setDefaultGitIdentityId:t.setDefaultGitIdentityId,getUnimportedCredentials:t.getUnimportedCredentials}}function x5(t){return t.stopPropagation()}const og=()=>{const t=Tb();return{displayMode:t,installed:t!=="browser",browserTab:t==="browser"}},lg=()=>{const t=at.c(2),[e,n]=l.useState(b5);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(og())};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 b5(){return og()}const y5=[{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"}],v5=[{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"}],w5=[{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"}],j5=[{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"}],Ai="OpenChamber - AI Coding Assistant",fp=[{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"}],gp=[{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"}],kc=t=>t==="portrait"||t==="landscape"?t:"system",N5=[{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"}],S5=[{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"}],xp=[{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"}],k5=[{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"}],bp=[{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"}],yp=[{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"}],C5=t=>t==="markdown"?"markdown":"plain",Xd=({visibleSettings:t})=>{const{locale:e,locales:n,setLocale:r,label:a,t:i}=pt(),o=l.useCallback(J=>i(J),[i]),{isMobile:c}=an(),{browserTab:d}=lg(),p=kl(),m=Te(J=>J.showReasoningTraces),u=Te(J=>J.setShowReasoningTraces),h=Te(J=>J.mermaidRenderingMode),b=Te(J=>J.setMermaidRenderingMode),f=Te(J=>J.userMessageRenderingMode),v=Te(J=>J.setUserMessageRenderingMode),x=Te(J=>J.stickyUserHeader),g=Te(J=>J.setStickyUserHeader),w=Te(J=>J.wideChatLayoutEnabled),y=Te(J=>J.setWideChatLayoutEnabled),k=Te(J=>J.chatRenderMode),D=Te(J=>J.setChatRenderMode),j=Te(J=>J.activityRenderMode),S=Te(J=>J.setActivityRenderMode),A=Te(J=>J.fontSize),E=Te(J=>J.setFontSize),P=Te(J=>J.terminalFontSize),C=Te(J=>J.setTerminalFontSize),N=Te(J=>J.uiFont),T=Te(J=>J.setUiFont),M=Te(J=>J.monoFont),R=Te(J=>J.setMonoFont),L=Te(J=>J.padding),$=Te(J=>J.setPadding),B=Te(J=>J.inputBarOffset),O=Te(J=>J.setInputBarOffset),_=Te(J=>J.mobileKeyboardMode),ee=Te(J=>J.setMobileKeyboardMode),z=Te(J=>J.diffLayoutPreference),ne=Te(J=>J.setDiffLayoutPreference),re=Te(J=>J.diffViewMode),ue=Te(J=>J.setDiffViewMode),Q=Te(J=>J.showTerminalQuickKeysOnDesktop),de=Te(J=>J.setShowTerminalQuickKeysOnDesktop),X=yu(J=>J.queueModeEnabled),F=yu(J=>J.setQueueMode),V=Te(J=>J.persistChatDraft),q=Te(J=>J.setPersistChatDraft),te=Te(J=>J.inputSpellcheckEnabled),U=Te(J=>J.setInputSpellcheckEnabled),ae=Te(J=>J.showToolFileIcons),je=Te(J=>J.setShowToolFileIcons),oe=Te(J=>J.showExpandedBashTools),ve=Te(J=>J.setShowExpandedBashTools),K=Te(J=>J.showExpandedEditTools),ce=Te(J=>J.setShowExpandedEditTools),Z=Te(J=>J.timeFormatPreference),le=Te(J=>J.setTimeFormatPreference),se=Te(J=>J.weekStartPreference),Ie=Te(J=>J.setWeekStartPreference),Ne=Te(J=>J.showSplitAssistantMessageActions),Y=Te(J=>J.setShowSplitAssistantMessageActions),fe=Te(J=>J.showMobileSessionStatusBar),ke=Te(J=>J.setShowMobileSessionStatusBar),be=gt(J=>J.settingsMessageStreamTransport),pe=gt(J=>J.setSettingsMessageStreamTransport),Ee=Te(J=>J.isSettingsDialogOpen),{themeMode:ze,setThemeMode:G,availableThemes:Pe,customThemesLoading:Le,reloadCustomThemes:Ae,lightThemeId:ge,darkThemeId:W,setLightThemePreference:ie,setDarkThemePreference:Me}=jr(),[Ve,Ce]=l.useState(!1),[xe,De]=l.useState(0),Ye=Te(J=>J.reportUsage),rt=Te(J=>J.setReportUsage),Re=l.useCallback(J=>{rt(J),Ds({reportUsage:J})},[rt]),he=Ee&&(t?t.includes("chatRenderMode"):!0);l.useEffect(()=>{if(!he)return;let J=null,ct=Date.now();const vt=()=>{const Yt=Date.now();Yt-ct>=420&&(De(Zt=>(Zt+1)%24),ct=Yt),J=requestAnimationFrame(vt)};(typeof document>"u"||document.visibilityState==="visible")&&(J=requestAnimationFrame(vt));const Tt=()=>{document.visibilityState==="visible"&&J===null?J=requestAnimationFrame(vt):document.visibilityState!=="visible"&&J!==null&&(cancelAnimationFrame(J),J=null)};return document.addEventListener("visibilitychange",Tt),()=>{document.removeEventListener("visibilitychange",Tt),J!==null&&cancelAnimationFrame(J)}},[he]);const qe=l.useCallback(J=>{v(J),Ds({userMessageRenderingMode:J})},[v]),et=l.useCallback(J=>{g(J),Ds({stickyUserHeader:J})},[g]),Ke=l.useCallback(J=>{y(J),Ds({wideChatLayoutEnabled:J})},[y]),st=l.useCallback(J=>{Y(J),Ds({showSplitAssistantMessageActions:J})},[Y]),nt=l.useCallback(J=>{U(J),Ds({inputSpellcheckEnabled:J})},[U]),ye=l.useCallback(J=>{D(J),Ds({chatRenderMode:J})},[D]),Je=l.useCallback(J=>{pe(J),Ds({messageStreamTransport:J})},[pe]),_e=l.useCallback(J=>{S(J),Ds({activityRenderMode:J})},[S]),Ue=l.useCallback(J=>{b(J),Ds({mermaidRenderingMode:J})},[b]),ot=l.useCallback(J=>{je(J),Ds({showToolFileIcons:J})},[je]),Xe=l.useCallback(J=>{ve(J),Ds({showExpandedBashTools:J})},[ve]),We=l.useCallback(J=>{ce(J),Ds({showExpandedEditTools:J})},[ce]),bt=l.useCallback(J=>{le(J),Ds({timeFormatPreference:J})},[le]),Dt=l.useCallback(J=>{Ie(J),Ds({weekStartPreference:J})},[Ie]),Ht=l.useMemo(()=>Pe.filter(J=>J.metadata.variant==="light").sort((J,ct)=>J.metadata.name.localeCompare(ct.metadata.name)),[Pe]),rs=l.useMemo(()=>Pe.filter(J=>J.metadata.variant==="dark").sort((J,ct)=>J.metadata.name.localeCompare(ct.metadata.name)),[Pe]),jt=l.useMemo(()=>Ht.find(J=>J.metadata.id===ge)??Ht[0],[Ht,ge]),St=l.useMemo(()=>rs.find(J=>J.metadata.id===W)??rs[0],[rs,W]),ns=l.useCallback((J,ct)=>{const vt=ct==="dark"?" Dark":" Light";return J.endsWith(vt)?J.slice(0,-vt.length):J},[]),ut=J=>t?t.includes(J):!0,Gt=dn(),Xt=ut("theme")&&!Gt,Wt=ut("theme")||ut("timeFormat")||ut("weekStart"),is=Gt?Wt:ut("theme")||ut("pwaInstallName")||ut("pwaOrientation")||ut("timeFormat")||ut("weekStart"),gs=ut("fontSize")||ut("terminalFontSize")||ut("spacing")||ut("inputBarOffset"),ps=ut("terminalQuickKeys")&&!c,Ns=ut("mermaidRendering")||ut("userMessageRendering")||ut("chatRenderMode")||ut("messageTransport")||ut("activityRenderMode")&&k==="sorted"||ut("stickyUserHeader")||ut("wideChatLayout")||ut("splitAssistantMessageActions")||ut("diffLayout")||ut("mobileStatusBar")&&c||ut("dotfiles")||ut("reasoning")||ut("queueMode")||ut("persistDraft")||ut("showToolFileIcons")||ut("expandedTools")||!c&&ut("inputSpellcheck"),Mt=ut("pwaInstallName")&&sa()&&d&&!yn()&&!Gt,He=ut("pwaOrientation")&&sa()&&!yn()&&!Gt,At=ut("mobileKeyboardMode")&&sa()&&!yn()&&!Gt&&Mb(),[Et,wt]=l.useState(""),[$t,qt]=l.useState("system"),Ms=l.useMemo(()=>{const J=bp.find(ct=>ct.id===Z);return o(J?.labelKey??"settings.openchamber.visual.option.timeFormat.auto.label")},[Z,o]),cs=l.useMemo(()=>{const J=yp.find(ct=>ct.id===se);return o(J?.labelKey??"settings.openchamber.visual.option.weekStart.auto.label")},[se,o]),Is=l.useMemo(()=>{const J=fp.find(ct=>ct.id===$t);return J?o(J.labelKey):void 0},[$t,o]),Es=l.useMemo(()=>{const J=gp.find(ct=>ct.id===_);return J?o(J.labelKey):void 0},[_,o]),ft=l.useCallback(async J=>{if(typeof window>"u")return;const ct=window,Tt=J.trim().replace(/\s+/g," ").slice(0,64);if(await Ds({pwaAppName:Tt}),typeof ct.__OPENCHAMBER_SET_PWA_INSTALL_NAME__=="function"){const Yt=ct.__OPENCHAMBER_SET_PWA_INSTALL_NAME__(Tt);wt(Yt);return}wt(Tt||Ai),ct.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]),hs=l.useCallback(async J=>{if(typeof window>"u")return;const ct=window,vt=kc(J);if(await Ds({pwaOrientation:vt}),typeof ct.__OPENCHAMBER_SET_PWA_ORIENTATION__=="function"){const Tt=ct.__OPENCHAMBER_SET_PWA_ORIENTATION__(vt);qt(Tt);return}qt(vt),ct.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]);return l.useEffect(()=>{if(typeof window>"u"||!Mt&&!He&&!At)return;let J=!1;return(async()=>{try{const vt=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},cache:"no-store"});if(!vt.ok){J||wt(Ai);return}const Tt=await vt.json().catch(()=>({})),Zt=(typeof Tt?.pwaAppName=="string"?Tt.pwaAppName:"").trim().replace(/\s+/g," ").slice(0,64),Ps=kc(Tt?.pwaOrientation),As=Su(Tt?.mobileKeyboardMode);J||(Mt&&wt(Zt||Ai),He&&qt(Ps),At&&ee(As))}catch{J||(Mt&&wt(Ai),He&&qt("system"),At&&ee("native"))}})(),()=>{J=!0}},[ee,At,Mt,He]),s.jsxs("div",{className:"space-y-8",children:[is&&s.jsxs("div",{className:"mb-8 space-y-6",children:[Xt&&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:y5.map(J=>s.jsx(we,{variant:"chip",size:"xs","aria-pressed":ze===J.value,className:"!font-normal",onClick:()=>G(J.value),children:o(J.labelKey)},J.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(ds,{value:jt?.metadata.id??"",onValueChange:ie,children:[s.jsx(us,{"aria-label":i("settings.openchamber.visual.field.selectLightThemeAria"),className:"w-fit",children:s.jsx(ys,{placeholder:i("settings.openchamber.visual.field.selectThemePlaceholder"),children:jt?ns(jt.metadata.name,"light"):void 0})}),s.jsx(ms,{children:Ht.map(J=>s.jsx(Lt,{value:J.metadata.id,children:ns(J.metadata.name,"light")},J.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(ds,{value:St?.metadata.id??"",onValueChange:Me,children:[s.jsx(us,{"aria-label":i("settings.openchamber.visual.field.selectDarkThemeAria"),className:"w-fit",children:s.jsx(ys,{placeholder:i("settings.openchamber.visual.field.selectThemePlaceholder"),children:St?ns(St.metadata.name,"dark"):void 0})}),s.jsx(ms,{children:rs.map(J=>s.jsx(Lt,{value:J.metadata.id,children:ns(J.metadata.name,"dark")},J.metadata.id))})]})]})]}),s.jsxs("div",{className:"flex items-center gap-2 py-1.5",children:[s.jsx("button",{type:"button",disabled:Le||Ve,onClick:()=>{const J=Date.now();Ce(!0),Ae().finally(()=>{const ct=Date.now()-J;if(ct<500){window.setTimeout(()=>{Ce(!1)},500-ct);return}Ce(!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(Ve?"settings.openchamber.visual.actions.reloadingThemes":"settings.openchamber.visual.actions.reloadThemes")}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",className:"flex items-center justify-center rounded-md p-1 text-muted-foreground/70 hover:text-foreground","aria-label":i("settings.openchamber.visual.field.themeImportInfoAria"),children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5"})})}),s.jsx(Pt,{sideOffset:8,children:i("settings.openchamber.visual.field.themeImportInfoTooltip")})]})]})]}),Wt&&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(ds,{value:e,onValueChange:J=>r(J),children:[s.jsx(us,{"aria-label":i("settings.appearance.language.select"),className:"w-fit",children:s.jsx(ys,{children:a(e)})}),s.jsx(ms,{children:n.map(J=>s.jsx(Lt,{value:J,children:a(J)},J))})]})]}),!Gt&&(ut("timeFormat")||ut("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:[ut("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(ds,{value:Z,onValueChange:J=>bt(J),children:[s.jsx(us,{"aria-label":i("settings.openchamber.visual.field.selectTimeFormatAria"),className:"w-fit",children:s.jsx(ys,{children:Ms})}),s.jsx(ms,{children:bp.map(J=>s.jsx(Lt,{value:J.id,children:o(J.labelKey)},J.id))})]})]}),ut("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(ds,{value:se,onValueChange:J=>Dt(J),children:[s.jsx(us,{"aria-label":i("settings.openchamber.visual.field.selectWeekStartAria"),className:"w-fit",children:s.jsx(ys,{children:cs})}),s.jsx(ms,{children:yp.map(J=>s.jsx(Lt,{value:J.id,children:o(J.labelKey)},J.id))})]})]})]})]}),(Mt||He||At)&&s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[Mt&&s.jsxs("div",{className:"py-1.5 space-y-1.5",children:[s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.installAppName")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.openchamber.visual.field.installAppNameHint")})]}),s.jsxs("div",{className:"flex w-full max-w-[28rem] items-center gap-2",children:[s.jsx(Kt,{value:Et,onChange:J=>{wt(J.target.value)},onBlur:()=>{ft(Et)},onKeyDown:J=>{J.key==="Enter"&&(J.preventDefault(),ft(Et))},className:"h-7",maxLength:64,"aria-label":i("settings.openchamber.visual.field.pwaInstallAppNameAria")}),s.jsx(we,{size:"sm",type:"button",variant:"ghost",onClick:()=>{wt(Ai),ft("")},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(I,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),He&&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(ds,{value:$t,onValueChange:J=>{const ct=kc(J);qt(ct),hs(ct)},children:[s.jsx(us,{"aria-label":i("settings.openchamber.visual.field.pwaInstallOrientationAria"),className:"w-full",children:s.jsx(ys,{placeholder:i("settings.openchamber.visual.field.selectOrientationPlaceholder"),children:Is})}),s.jsx(ms,{children:fp.map(J=>s.jsx(Lt,{value:J.id,children:o(J.labelKey)},J.id))})]}),s.jsx(we,{size:"sm",type:"button",variant:"ghost",onClick:()=>{qt("system"),hs("system")},disabled:$t==="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(I,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),At&&s.jsxs("div",{className:"py-1.5 space-y-1.5",children:[s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.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(ds,{value:_,onValueChange:J=>{const ct=Su(J);ee(ct),Ds({mobileKeyboardMode:ct})},children:[s.jsx(us,{"aria-label":i("settings.openchamber.visual.field.mobileKeyboardModeAria"),className:"w-full",children:s.jsx(ys,{placeholder:i("settings.openchamber.visual.field.selectMobileKeyboardModePlaceholder"),children:Es})}),s.jsx(ms,{children:gp.map(J=>s.jsx(Lt,{value:J.id,children:o(J.labelKey)},J.id))})]}),s.jsx(we,{size:"sm",type:"button",variant:"ghost",onClick:()=>{ee("native"),Ds({mobileKeyboardMode:"native"})},disabled:_==="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(I,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]})]}),gs&&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:[ut("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(ds,{value:N,onValueChange:J=>T(J),children:[s.jsx(us,{"aria-label":i("settings.openchamber.visual.field.selectInterfaceFontAria"),className:"w-[13rem]",children:s.jsx(ys,{children:vu.find(J=>J.id===N)?.label})}),s.jsx(ms,{children:vu.map(J=>s.jsx(Lt,{value:J.id,children:s.jsx("span",{style:{fontFamily:J.stack},children:J.label})},J.id))})]}),s.jsx(we,{size:"sm",type:"button",variant:"ghost",onClick:()=>T(wu),disabled:N===wu,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(I,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),ut("terminalFontSize")&&s.jsxs("div",{className:me("py-1",c?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsx("div",{className:me("flex min-w-0 flex-col",c?"w-full":"w-56 shrink-0"),children:s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.codeFont")})}),s.jsxs("div",{className:me("flex items-center gap-2",c?"w-full":"w-fit"),children:[s.jsxs(ds,{value:M,onValueChange:J=>R(J),children:[s.jsx(us,{"aria-label":i("settings.openchamber.visual.field.selectCodeFontAria"),className:"w-[13rem]",children:s.jsx(ys,{children:ju.find(J=>J.id===M)?.label})}),s.jsx(ms,{children:ju.map(J=>s.jsx(Lt,{value:J.id,children:s.jsx("span",{style:{fontFamily:J.stack},children:J.label})},J.id))})]}),s.jsx(we,{size:"sm",type:"button",variant:"ghost",onClick:()=>R(Nu),disabled:M===Nu,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(I,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),ut("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(xn,{value:A,onValueChange:E,min:50,max:200,step:5,"aria-label":i("settings.openchamber.visual.field.fontSizePercentageAria"),className:"w-16"}),s.jsx(we,{size:"sm",type:"button",variant:"ghost",onClick:()=>E(100),disabled:A===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(I,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),ut("terminalFontSize")&&s.jsxs("div",{className:me("py-1",c?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsx("div",{className:me("flex min-w-0 flex-col",c?"w-full":"w-56 shrink-0"),children:s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.terminalFontSize")})}),s.jsxs("div",{className:me("flex items-center gap-2",c?"w-full":"w-fit"),children:[s.jsx(xn,{value:P,onValueChange:C,min:9,max:52,step:1,className:"w-16"}),s.jsx(we,{size:"sm",type:"button",variant:"ghost",onClick:()=>C(13),disabled:P===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(I,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),ut("spacing")&&s.jsxs("div",{className:me("py-1",c?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsx("div",{className:me("flex min-w-0 flex-col",c?"w-full":"w-56 shrink-0"),children:s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.spacingDensity")})}),s.jsxs("div",{className:me("flex items-center gap-2",c?"w-full":"w-fit"),children:[s.jsx(xn,{value:L,onValueChange:$,min:50,max:200,step:5,className:"w-16"}),s.jsx(we,{size:"sm",type:"button",variant:"ghost",onClick:()=>$(100),disabled:L===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(I,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),ut("inputBarOffset")&&s.jsxs("div",{className:me("py-1",c?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsx("div",{className:me("flex min-w-0 flex-col",c?"w-full":"w-56 shrink-0"),children:s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.inputBarOffset")}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:i("settings.openchamber.visual.field.inputBarOffsetTooltip")})]})]})}),s.jsxs("div",{className:me("flex items-center gap-2",c?"w-full":"w-fit"),children:[s.jsx(xn,{value:B,onValueChange:O,min:0,max:100,step:5,className:"w-16"}),s.jsx(we,{size:"sm",type:"button",variant:"ghost",onClick:()=>O(0),disabled:B===0,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetInputBarOffsetAria"),title:i("settings.common.actions.reset"),children:s.jsx(I,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]})]})}),ps&&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")}),ut("terminalQuickKeys")&&!c&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":Q,onClick:()=>de(!Q),onKeyDown:J=>{(J.key===" "||J.key==="Enter")&&(J.preventDefault(),de(!Q))},children:[s.jsx(xs,{checked:Q,onChange:de,ariaLabel:i("settings.openchamber.visual.field.terminalQuickKeysAria")}),s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.terminalQuickKeys")}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:i("settings.openchamber.visual.field.terminalQuickKeysTooltip")})]})]})]})]})}),Ns&&s.jsxs("div",{className:"space-y-3",children:[(ut("userMessageRendering")||ut("mermaidRendering")||ut("chatRenderMode")||ut("messageTransport")||ut("activityRenderMode")&&k==="sorted"||ut("diffLayout")&&!Gt)&&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:[ut("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:S5.map(J=>{const ct=k===J.id,vt=xe%12;return s.jsxs("button",{type:"button",onClick:()=>ye(J.id),"aria-pressed":ct,className:me("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",ct?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[s.jsx("span",{className:me("typography-ui-label",ct?"text-foreground":"text-muted-foreground"),children:o(J.labelKey)}),s.jsx("div",{className:"mt-2 w-full rounded-md border border-border/60 bg-muted/30 p-2",children:J.id==="live"?s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(Tt=>{const Yt=Tt*3+1,Zt=vt-Yt+1,Ps=Zt<=0?0:Zt===1?42:Zt===2?68:92,As=Ps>0;return s.jsxs("div",{className:me("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",As?"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:`${Ps}%`}})]},Tt)})}):s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(Tt=>{const Yt=vt>=(Tt+1)*3;return s.jsxs("div",{className:me("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",Yt?"translate-y-0 opacity-100":"translate-y-1 opacity-0"),children:[s.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full bg-muted-foreground/55"}),s.jsx("span",{className:"h-1.5 rounded bg-muted-foreground/30",style:{width:"92%"}})]},Tt)})})})]},J.id)})})]}),ut("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:xp.map(J=>s.jsx(we,{variant:"chip",size:"xs","aria-pressed":be===J.id,className:"!font-normal",onClick:()=>Je(J.id),children:o(J.labelKey)},J.id))}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:(()=>{const J=xp.find(ct=>ct.id===be);return J?.descriptionKey?o(J.descriptionKey):""})()})]})]}),ut("activityRenderMode")&&k==="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:k5.map(J=>{const ct=j===J.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":ct,onClick:()=>_e(J.id),onKeyDown:vt=>{(vt.key===" "||vt.key==="Enter")&&(vt.preventDefault(),_e(J.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Ja,{checked:ct,onChange:()=>_e(J.id),ariaLabel:i("settings.openchamber.visual.field.activityDefaultModeAria",{option:o(J.labelKey)})}),s.jsx("span",{className:me("typography-ui-label font-normal",ct?"text-foreground":"text-foreground/50"),children:o(J.labelKey)})]},J.id)})})]}),ut("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":oe,onClick:()=>Xe(!oe),onKeyDown:J=>{(J.key===" "||J.key==="Enter")&&(J.preventDefault(),Xe(!oe))},children:[s.jsx(xs,{checked:oe,onChange:Xe,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":K,onClick:()=>We(!K),onKeyDown:J=>{(J.key===" "||J.key==="Enter")&&(J.preventDefault(),We(!K))},children:[s.jsx(xs,{checked:K,onChange:We,ariaLabel:i("settings.openchamber.visual.field.showExpandedEditToolsAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.editTools")})]})]}),ut("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:N5.map(J=>{const ct=C5(f)===J.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":ct,onClick:()=>qe(J.id),onKeyDown:vt=>{(vt.key===" "||vt.key==="Enter")&&(vt.preventDefault(),qe(J.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Ja,{checked:ct,onChange:()=>qe(J.id),ariaLabel:i("settings.openchamber.visual.field.userMessageRenderingAria",{option:o(J.labelKey)})}),s.jsx("span",{className:me("typography-ui-label font-normal",ct?"text-foreground":"text-foreground/50"),children:o(J.labelKey)})]},J.id)})})]}),ut("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:j5.map(J=>{const ct=h===J.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":ct,onClick:()=>Ue(J.id),onKeyDown:vt=>{(vt.key===" "||vt.key==="Enter")&&(vt.preventDefault(),Ue(J.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Ja,{checked:ct,onChange:()=>Ue(J.id),ariaLabel:i("settings.openchamber.visual.field.mermaidRenderingAria",{option:o(J.labelKey)})}),s.jsx("span",{className:me("typography-ui-label font-normal",ct?"text-foreground":"text-foreground/50"),children:o(J.labelKey)})]},J.id)})})]}),ut("diffLayout")&&!Gt&&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:v5.map(J=>{const ct=z===J.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":ct,onClick:()=>ne(J.id),onKeyDown:vt=>{(vt.key===" "||vt.key==="Enter")&&(vt.preventDefault(),ne(J.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Ja,{checked:ct,onChange:()=>ne(J.id),ariaLabel:i("settings.openchamber.visual.field.diffLayoutAria",{option:o(J.labelKey)})}),s.jsx("span",{className:me("typography-ui-label font-normal",ct?"text-foreground":"text-foreground/50"),children:o(J.labelKey)})]},J.id)})})]}),ut("diffLayout")&&!Gt&&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:w5.map(J=>{const ct=re===J.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":ct,onClick:()=>ue(J.id),onKeyDown:vt=>{(vt.key===" "||vt.key==="Enter")&&(vt.preventDefault(),ue(J.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Ja,{checked:ct,onChange:()=>ue(J.id),ariaLabel:i("settings.openchamber.visual.field.diffViewModeAria",{option:o(J.labelKey)})}),s.jsx("span",{className:me("typography-ui-label font-normal",ct?"text-foreground":"text-foreground/50"),children:o(J.labelKey)})]},J.id)})})]})]}),(ut("stickyUserHeader")||ut("wideChatLayout")||ut("splitAssistantMessageActions")||ut("mobileStatusBar")&&c||ut("dotfiles")||ut("queueMode")||ut("persistDraft")||ut("showToolFileIcons")||!c&&ut("inputSpellcheck")||ut("reasoning"))&&s.jsxs("section",{className:"p-2 space-y-0.5",children:[ut("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:J=>{(J.key===" "||J.key==="Enter")&&(J.preventDefault(),u(!m))},children:[s.jsx(xs,{checked:m,onChange:u,ariaLabel:i("settings.openchamber.visual.field.showReasoningTracesAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showReasoningTraces")})]}),ut("stickyUserHeader")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":x,onClick:()=>et(!x),onKeyDown:J=>{(J.key===" "||J.key==="Enter")&&(J.preventDefault(),et(!x))},children:[s.jsx(xs,{checked:x,onChange:et,ariaLabel:i("settings.openchamber.visual.field.stickyUserHeaderAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.stickyUserHeader")})]}),ut("wideChatLayout")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":w,onClick:()=>Ke(!w),onKeyDown:J=>{(J.key===" "||J.key==="Enter")&&(J.preventDefault(),Ke(!w))},children:[s.jsx(xs,{checked:w,onChange:Ke,ariaLabel:i("settings.openchamber.visual.field.wideChatLayoutAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.wideChatLayout")})]}),ut("splitAssistantMessageActions")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":Ne,onClick:()=>st(!Ne),onKeyDown:J=>{(J.key===" "||J.key==="Enter")&&(J.preventDefault(),st(!Ne))},children:[s.jsx(xs,{checked:Ne,onChange:st,ariaLabel:i("settings.openchamber.visual.field.showSplitAssistantMessageActionsAria")}),s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showSplitAssistantMessageActions")}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 cursor-help text-muted-foreground/60"})}),s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:i("settings.openchamber.visual.field.showSplitAssistantMessageActionsTooltip")})]})]})]}),ut("showToolFileIcons")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":ae,onClick:()=>ot(!ae),onKeyDown:J=>{(J.key===" "||J.key==="Enter")&&(J.preventDefault(),ot(!ae))},children:[s.jsx(xs,{checked:ae,onChange:ot,ariaLabel:i("settings.openchamber.visual.field.showToolFileIconsAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showToolFileIcons")})]}),ut("mobileStatusBar")&&c&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":fe,onClick:()=>ke(!fe),onKeyDown:J=>{(J.key===" "||J.key==="Enter")&&(J.preventDefault(),ke(!fe))},children:[s.jsx(xs,{checked:fe,onChange:ke,ariaLabel:i("settings.openchamber.visual.field.showMobileStatusBarAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showMobileStatusBar")})]}),ut("dotfiles")&&!dn()&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":p,onClick:()=>$o(!p),onKeyDown:J=>{(J.key===" "||J.key==="Enter")&&(J.preventDefault(),$o(!p))},children:[s.jsx(xs,{checked:p,onChange:$o,ariaLabel:i("settings.openchamber.visual.field.showDotfilesAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showDotfiles")})]}),ut("queueMode")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":X,onClick:()=>F(!X),onKeyDown:J=>{(J.key===" "||J.key==="Enter")&&(J.preventDefault(),F(!X))},children:[s.jsx(xs,{checked:X,onChange:F,ariaLabel:i("settings.openchamber.visual.field.queueMessagesByDefaultAria")}),s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.queueMessagesByDefault")}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:i("settings.openchamber.visual.field.queueMessagesByDefaultTooltip",{modifier:al()})})]})]})]}),ut("persistDraft")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":V,onClick:()=>q(!V),onKeyDown:J=>{(J.key===" "||J.key==="Enter")&&(J.preventDefault(),q(!V))},children:[s.jsx(xs,{checked:V,onChange:q,ariaLabel:i("settings.openchamber.visual.field.persistDraftMessagesAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.persistDraftMessages")})]}),!c&&ut("inputSpellcheck")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":te,onClick:()=>nt(!te),onKeyDown:J=>{(J.key===" "||J.key==="Enter")&&(J.preventDefault(),nt(!te))},children:[s.jsx(xs,{checked:te,onChange:nt,ariaLabel:i("settings.openchamber.visual.field.enableSpellcheckInTextInputsAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.enableSpellcheckInTextInputs")})]})]})]}),ut("reportUsage")&&s.jsx("div",{className:"space-y-3",children:s.jsxs("section",{className:"px-2 pb-2 pt-0",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground mb-2",children:i("settings.openchamber.visual.section.privacy")}),s.jsxs("div",{className:"flex items-start gap-2 py-1.5",children:[s.jsx(xs,{checked:Ye,onChange:Re,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":Ye,onClick:()=>Re(!Ye),onKeyDown:J=>{(J.key===" "||J.key==="Enter")&&(J.preventDefault(),Re(!Ye))},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 I5(){if(typeof window>"u")return"unknown";try{const{deviceType:t}=Lb();return t}catch{return"unknown"}}function P5(){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 A5(){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 D5(t){const e=Te.getState().reportUsage,n=new URLSearchParams({reportUsage:e?"true":"false"});return n.set("deviceClass",I5()),n.set("arch",P5()),n.set("platform",A5()),t==="desktop"?(n.set("appType",Fb()?"desktop-electron":"desktop-tauri"),n.set("instanceMode",Vr()?"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 Cc(t,e){try{const n=D5(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 T5(){return Ia()?Vr()?"desktop":"web":dn()?"vscode":sa()?"web":null}const vp={checking:!1,available:!1,downloading:!1,downloaded:!1,info:null,progress:null,error:null,runtimeType:null,lastChecked:null,nextCheckInSec:null},ka=tr()((t,e)=>({...vp,checkForUpdates:async()=>{const n=T5();if(!n)return null;t({checking:!0,error:null,runtimeType:n});try{let r=null,a=null;if(n==="desktop"){let i=await Jl();t({checking:!1,available:i?.available??!1,info:i,lastChecked:Date.now(),nextCheckInSec:null});const o=await Cc("desktop",i?.currentVersion);if(a=o?.nextSuggestedCheckInSec??null,o?.available&&!i?.available){const c=await Jl();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 Cc("web"),a=r?.nextSuggestedCheckInSec??null):n==="vscode"&&(a=(await Cc("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 Jl();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 Rb(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 Eb())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(vp)}})),wp="https://github.com/btriapitsyn/openchamber/releases";function M5(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 E5(t){return t.replace(/^## \[[^\]]+\] - \d{4}-\d{2}-\d{2}\s*\n?/,"").trim()}function jp(t){return t.replace(/(^|[^a-zA-Z0-9])@([a-zA-Z0-9-]+)/g,"$1[@$2](https://github.com/$2)")}function R5(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 F5(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 Np=2e3,L5=600*1e3;async function O5(){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 $5(){try{return(await fetch("/health",{method:"GET",headers:{Accept:"application/json"}})).ok}catch{return!1}}async function B5(t,e=Math.ceil(L5/Np),n=Np){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 $5())return!0}catch{}await new Promise(a=>setTimeout(a,n))}return!1}const fd=({open:t,onOpenChange:e,info:n,downloading:r,downloaded:a,progress:i,error:o,onDownload:c,onRestart:d,runtimeType:p="desktop"})=>{const{t:m}=pt(),[u,h]=Be.useState(!1),[b,f]=Be.useState("idle"),[v,x]=Be.useState(null),g=n?.version?`${wp}/tag/v${n.version}`:wp,w=i?.total?Math.round(i.downloaded/i.total*100):0,y=p==="web",k=n?.updateCommand||"openchamber update";Be.useEffect(()=>{t||(f("idle"),x(null))},[t]);const D=async()=>{(await Rn(k)).ok&&(h(!0),setTimeout(()=>h(!1),2e3))},j=Be.useCallback(async P=>{await Xn(P)},[]),S=Be.useCallback(async()=>{f("updating"),x(null);const P=await O5();if(!P.success){f("error"),x(P.error||m("updateDialog.error.updateFailed"));return}P.autoRestart&&(f("restarting"),await new Promise(N=>setTimeout(N,2e3))),f("reconnecting"),await B5(n?.currentVersion)?window.location.reload():(f("error"),x(m("updateDialog.error.takingLonger")))},[n?.currentVersion,m]),A=b!=="idle"&&b!=="error",E=Be.useMemo(()=>{if(!n?.body)return null;const P=n.body.trim();if(!P)return null;const C=F5(P);if(C.length===0)return{kind:"raw",title:m("updateDialog.changelog.title"),content:jp(P)};const N=[...C].sort((T,M)=>R5(T.version,M.version));return{kind:"sections",title:m("updateDialog.changelog.title"),sections:N.map(T=>({version:T.version,dateLabel:M5(T.date),content:jp(E5(T.raw)||P)}))}},[n?.body,m]);return s.jsx(ws,{open:t,onOpenChange:A?void 0:e,children:s.jsxs(vs,{className:"max-w-4xl p-5 bg-background border-[var(--interactive-border)]",showCloseButton:!0,children:[s.jsxs("div",{className:"flex items-center mb-1",children:[s.jsxs(js,{className:"flex items-center gap-2.5",children:[s.jsx(I,{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&&A&&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(I,{name:"loader",className:"h-5 w-5 animate-spin text-[var(--primary-base)]"}),s.jsxs("div",{className:"typography-ui-label text-foreground",children:[b==="updating"&&m("updateDialog.status.installingUpdate"),b==="restarting"&&m("updateDialog.status.serverRestarting"),b==="reconnecting"&&m("updateDialog.status.waitingForServer")]})]}),s.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:m("updateDialog.status.autoReloadHint")})]}),E&&!A&&s.jsx("div",{className:"rounded-lg border border-[var(--surface-subtle)] bg-[var(--surface-elevated)]/20 overflow-hidden",children:s.jsx(Ts,{className:"max-h-[400px] p-0",fillContainer:!1,children:E.kind==="raw"?s.jsx("div",{className:"p-4 typography-markdown-body text-foreground leading-relaxed break-words [&_a]:!text-[var(--primary-base)] [&_a]:!no-underline hover:[&_a]:!underline",onClickCapture:P=>{const N=P.target.closest("a");N&&N.href&&(P.preventDefault(),P.stopPropagation(),j(N.href))},children:s.jsx(Aa,{content:E.content,disableLinkSafety:!0})}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:E.sections.map(P=>s.jsxs("div",{className:"p-4 hover:bg-background/40 transition-colors",children:[s.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[s.jsxs("span",{className:"typography-ui-label font-mono text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-1.5 py-0.5 rounded",children:["v",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 hover:[&_a]:!underline",onClickCapture:C=>{const T=C.target.closest("a");T&&T.href&&(C.preventDefault(),C.stopPropagation(),j(T.href))},children:s.jsx(Aa,{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(I,{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:k}),s.jsx("button",{onClick:D,className:me("flex items-center justify-center p-2 rounded","text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]","transition-colors",u&&"text-[var(--status-success)]"),title:m(u?"updateDialog.actions.copied":"updateDialog.actions.copyCommand"),children:u?s.jsx(I,{name:"check",className:"h-4 w-4"}):s.jsx(I,{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(I,{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(I,{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(I,{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(I,{name:"restart",className:"h-4 w-4"}),m("updateDialog.actions.restartToUpdate")]}),y&&!A&&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(I,{name:"download",className:"h-4 w-4"}),m("updateDialog.actions.updateNow")]}),y&&A&&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(I,{name:"loader",className:"h-4 w-4 animate-spin"}),m("updateDialog.status.updating")]})]})]})]})})},Sp="https://github.com/btriapitsyn/openchamber",_5=800,V5=()=>{const t=at.c(103),{t:e}=pt(),[n,r]=l.useState(!1),[a,i]=l.useState(!1),o=ka(pr(z5)),{isMobile:c}=an(),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 B=setTimeout(()=>{i(!1),p.current&&!o.available&&!o.error&&(H.success(e("settings.openchamber.about.toast.latestVersion")),p.current=!1)},_5);return()=>clearTimeout(B)}},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 h=o.checking||a;if(c){let B;t[7]!==d?(B=s.jsxs("span",{className:"typography-meta text-muted-foreground",children:["v",d]}),t[7]=d,t[8]=B):B=t[8];let O;t[9]!==h||t[10]!==e||t[11]!==o?(O=!o.available&&!o.error&&s.jsx("button",{onClick:()=>o.checkForUpdates(),disabled:h,className:me("typography-meta text-muted-foreground/60 hover:text-muted-foreground disabled:cursor-default",h&&"animate-pulse [animation-duration:1s]"),children:e("settings.openchamber.about.actions.checkUpdates")}),t[9]=h,t[10]=e,t[11]=o,t[12]=O):O=t[12];let _;t[13]!==h||t[14]!==e||t[15]!==o.available?(_=!h&&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(I,{name:"download",className:"h-3.5 w-3.5"}),e("settings.openchamber.about.actions.update")]}),t[13]=h,t[14]=e,t[15]=o.available,t[16]=_):_=t[16];let ee;t[17]!==B||t[18]!==O||t[19]!==_?(ee=s.jsxs("div",{className:"flex items-center justify-between",children:[B,O,_]}),t[17]=B,t[18]=O,t[19]=_,t[20]=ee):ee=t[20];let z;t[21]!==o.error?(z=o.error&&s.jsx("p",{className:"typography-micro text-[var(--status-error)] truncate",children:o.error}),t[21]=o.error,t[22]=z):z=t[22];let ne;t[23]===Symbol.for("react.memo_cache_sentinel")?(ne=s.jsxs("a",{href:Sp,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(I,{name:"github-fill",className:"h-3.5 w-3.5"}),s.jsx("span",{children:"GitHub"})]}),t[23]=ne):ne=t[23];let re;t[24]===Symbol.for("react.memo_cache_sentinel")?(re=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(I,{name:"discord-fill",className:"h-3.5 w-3.5"}),s.jsx("span",{children:"Discord"})]}),t[24]=re):re=t[24];let ue;t[25]===Symbol.for("react.memo_cache_sentinel")?(ue=s.jsxs("div",{className:"flex items-center gap-3",children:[ne,re,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(I,{name:"twitter-xfill",className:"h-3.5 w-3.5"}),s.jsx("span",{children:"@btriapitsyn"})]})]}),t[25]=ue):ue=t[25];let Q;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?(Q=s.jsx(fd,{open:n,onOpenChange:r,info:o.info,downloading:o.downloading,downloaded:o.downloaded,progress:o.progress,error:o.error,onDownload:o.downloadUpdate,onRestart:o.restartToUpdate,runtimeType:o.runtimeType}),t[26]=n,t[27]=o.downloadUpdate,t[28]=o.downloaded,t[29]=o.downloading,t[30]=o.error,t[31]=o.info,t[32]=o.progress,t[33]=o.restartToUpdate,t[34]=o.runtimeType,t[35]=Q):Q=t[35];let de;return t[36]!==Q||t[37]!==ee||t[38]!==z?(de=s.jsxs("div",{className:"w-full space-y-2",children:[ee,z,ue,Q]}),t[36]=Q,t[37]=ee,t[38]=z,t[39]=de):de=t[39],de}let b;t[40]!==e?(b=e("settings.openchamber.about.title"),t[40]=e,t[41]=b):b=t[41];let f;t[42]!==b?(f=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]=f):f=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(I,{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 k;t[56]!==e||t[57]!==o.available||t[58]!==o.checking||t[59]!==o.info?.version?(k=!o.checking&&o.available&&s.jsxs(we,{size:"sm",variant:"default",onClick:()=>r(!0),children:[s.jsx(I,{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]=k):k=t[60];let D;t[61]!==e||t[62]!==o.available||t[63]!==o.checking||t[64]!==o.error?(D=!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]=D):D=t[65];let j;t[66]!==o?(j=()=>o.checkForUpdates(),t[66]=o,t[67]=j):j=t[67];const S=o.checking;let A;t[68]!==e?(A=e("settings.openchamber.about.actions.checkForUpdates"),t[68]=e,t[69]=A):A=t[69];let E;t[70]!==j||t[71]!==A||t[72]!==o.checking?(E=s.jsx(we,{size:"sm",variant:"outline",onClick:j,disabled:S,children:A}),t[70]=j,t[71]=A,t[72]=o.checking,t[73]=E):E=t[73];let P;t[74]!==D||t[75]!==E||t[76]!==y||t[77]!==k?(P=s.jsxs("div",{className:"flex items-center gap-3",children:[y,k,D,E]}),t[74]=D,t[75]=E,t[76]=y,t[77]=k,t[78]=P):P=t[78];let C;t[79]!==P||t[80]!==w?(C=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]=C):C=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 T;t[84]===Symbol.for("react.memo_cache_sentinel")?(T=s.jsxs("a",{href:Sp,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(I,{name:"github-fill",className:"h-4 w-4"}),s.jsx("span",{children:"GitHub"})]}),t[84]=T):T=t[84];let M;t[85]===Symbol.for("react.memo_cache_sentinel")?(M=s.jsxs("div",{className:"flex items-center gap-4 px-4 py-4",children:[T,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(I,{name:"twitter-xfill",className:"h-4 w-4"}),s.jsx("span",{children:"@btriapitsyn"})]})]}),t[85]=M):M=t[85];let R;t[86]!==C||t[87]!==N?(R=s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[C,N,M]}),t[86]=C,t[87]=N,t[88]=R):R=t[88];let L;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?(L=s.jsx(fd,{open:n,onOpenChange:r,info:o.info,downloading:o.downloading,downloaded:o.downloaded,progress:o.progress,error:o.error,onDownload:o.downloadUpdate,onRestart:o.restartToUpdate,runtimeType:o.runtimeType}),t[89]=n,t[90]=o.downloadUpdate,t[91]=o.downloaded,t[92]=o.downloading,t[93]=o.error,t[94]=o.info,t[95]=o.progress,t[96]=o.restartToUpdate,t[97]=o.runtimeType,t[98]=L):L=t[98];let $;return t[99]!==R||t[100]!==L||t[101]!==f?($=s.jsxs("div",{className:"mb-8",children:[f,R,L]}),t[99]=R,t[100]=L,t[101]=f,t[102]=$):$=t[102],$};function z5(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 U5=1,W5=365,kp=30,K5=[{value:"archive",labelKey:"settings.openchamber.sessionRetention.action.archive"},{value:"delete",labelKey:"settings.openchamber.sessionRetention.action.delete"}],cg=()=>{const t=at.c(113),{t:e}=pt(),n=Te(H5),r=Te(G5),a=Te(q5),i=Te(J5),o=Te(Q5),c=Te(Y5);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:h}=Ob(d),b=p.length;let f;t[1]!==u||t[2]!==e?(f=async()=>{const se=await u({force:!0});if(se.completedIds.length===0&&se.failedIds.length===0){H.message(se.action==="archive"?e("settings.openchamber.sessionRetention.toast.noneEligibleArchive"):e("settings.openchamber.sessionRetention.toast.noneEligibleDelete"));return}se.completedIds.length>0&&H.success(se.action==="archive"?e("settings.openchamber.sessionRetention.toast.archivedCount",{count:se.completedIds.length}):e("settings.openchamber.sessionRetention.toast.deletedCount",{count:se.completedIds.length})),se.failedIds.length>0&&H.error(se.action==="archive"?e("settings.openchamber.sessionRetention.toast.failedArchiveCount",{count:se.failedIds.length}):e("settings.openchamber.sessionRetention.toast.failedDeleteCount",{count:se.failedIds.length}))},t[1]=u,t[2]=e,t[3]=f):f=t[3];const v=f;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(Ct,{asChild:!0,children:s.jsx(I,{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 k;t[11]!==y?(k=s.jsxs(kt,{children:[w,s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:y})]}),t[11]=y,t[12]=k):k=t[12];let D;t[13]!==g||t[14]!==k?(D=s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[g,k]})}),t[13]=g,t[14]=k,t[15]=D):D=t[15];let j,S;t[16]!==n||t[17]!==i?(j=()=>i(!n),S=se=>{(se.key===" "||se.key==="Enter")&&(se.preventDefault(),i(!n))},t[16]=n,t[17]=i,t[18]=j,t[19]=S):(j=t[18],S=t[19]);let A;t[20]!==e?(A=e("settings.openchamber.sessionRetention.field.enableAutoCleanupAria"),t[20]=e,t[21]=A):A=t[21];let E;t[22]!==n||t[23]!==i||t[24]!==A?(E=s.jsx(xs,{checked:n,onChange:i,ariaLabel:A}),t[22]=n,t[23]=i,t[24]=A,t[25]=E):E=t[25];let P;t[26]!==e?(P=e("settings.openchamber.sessionRetention.field.enableAutoCleanup"),t[26]=e,t[27]=P):P=t[27];let C;t[28]!==P?(C=s.jsx("span",{className:"typography-ui-label text-foreground",children:P}),t[28]=P,t[29]=C):C=t[29];let N;t[30]!==n||t[31]!==E||t[32]!==C||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:[E,C]}),t[30]=n,t[31]=E,t[32]=C,t[33]=j,t[34]=S,t[35]=N):N=t[35];let T;t[36]!==e?(T=e("settings.openchamber.sessionRetention.field.retentionPeriod"),t[36]=e,t[37]=T):T=t[37];let M;t[38]!==T?(M=s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:T})}),t[38]=T,t[39]=M):M=t[39];let R;t[40]!==e?(R=e("settings.openchamber.sessionRetention.field.retentionPeriodAria"),t[40]=e,t[41]=R):R=t[41];let L;t[42]!==r||t[43]!==o||t[44]!==R?(L=s.jsx(xn,{value:r,onValueChange:o,min:U5,max:W5,step:1,"aria-label":R,className:"w-20 tabular-nums"}),t[42]=r,t[43]=o,t[44]=R,t[45]=L):L=t[45];let $;t[46]!==e?($=e("settings.openchamber.sessionRetention.field.days"),t[46]=e,t[47]=$):$=t[47];let B;t[48]!==$?(B=s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:$}),t[48]=$,t[49]=B):B=t[49];let O;t[50]!==o?(O=()=>o(kp),t[50]=o,t[51]=O):O=t[51];const _=r===kp;let ee;t[52]!==e?(ee=e("settings.openchamber.sessionRetention.actions.resetRetentionAria"),t[52]=e,t[53]=ee):ee=t[53];let z;t[54]!==e?(z=e("settings.common.actions.reset"),t[54]=e,t[55]=z):z=t[55];let ne;t[56]===Symbol.for("react.memo_cache_sentinel")?(ne=s.jsx(I,{name:"restart",className:"h-3.5 w-3.5"}),t[56]=ne):ne=t[56];let re;t[57]!==O||t[58]!==_||t[59]!==ee||t[60]!==z?(re=s.jsx(we,{size:"sm",type:"button",variant:"ghost",onClick:O,disabled:_,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":ee,title:z,children:ne}),t[57]=O,t[58]=_,t[59]=ee,t[60]=z,t[61]=re):re=t[61];let ue;t[62]!==L||t[63]!==B||t[64]!==re?(ue=s.jsxs("div",{className:"flex items-center gap-2 sm:w-fit",children:[L,B,re]}),t[62]=L,t[63]=B,t[64]=re,t[65]=ue):ue=t[65];let Q;t[66]!==M||t[67]!==ue?(Q=s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[M,ue]}),t[66]=M,t[67]=ue,t[68]=Q):Q=t[68];let de;t[69]!==e?(de=e("settings.openchamber.sessionRetention.field.whenSessionsExpire"),t[69]=e,t[70]=de):de=t[70];let X;t[71]!==de?(X=s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:de})}),t[71]=de,t[72]=X):X=t[72];let F;t[73]!==a||t[74]!==c||t[75]!==e?(F=K5.map(se=>s.jsx(we,{type:"button",variant:"chip",size:"xs","aria-pressed":a===se.value,className:"!font-normal",onClick:()=>c(se.value),children:e(se.labelKey)},se.value)),t[73]=a,t[74]=c,t[75]=e,t[76]=F):F=t[76];let V;t[77]!==F?(V=s.jsx("div",{className:"flex flex-wrap items-center gap-1 sm:w-fit",children:F}),t[77]=F,t[78]=V):V=t[78];let q;t[79]!==X||t[80]!==V?(q=s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[X,V]}),t[79]=X,t[80]=V,t[81]=q):q=t[81];let te;t[82]!==N||t[83]!==Q||t[84]!==q?(te=s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[N,Q,q]}),t[82]=N,t[83]=Q,t[84]=q,t[85]=te):te=t[85];let U;t[86]!==e?(U=e("settings.openchamber.sessionRetention.manualCleanup.title"),t[86]=e,t[87]=U):U=t[87];let ae;t[88]!==U?(ae=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:U})}),t[88]=U,t[89]=ae):ae=t[89];let je;t[90]!==m||t[91]!==e?(je=e(m?"settings.openchamber.sessionRetention.actions.cleaningUp":"settings.openchamber.sessionRetention.actions.runCleanupNow"),t[90]=m,t[91]=e,t[92]=je):je=t[92];let oe;t[93]!==v||t[94]!==m||t[95]!==je?(oe=s.jsx("div",{className:"flex items-center gap-2 sm:w-fit",children:s.jsx(we,{type:"button",variant:"outline",size:"xs",onClick:v,disabled:m,className:"!font-normal",children:je})}),t[93]=v,t[94]=m,t[95]=je,t[96]=oe):oe=t[96];let ve;t[97]!==ae||t[98]!==oe?(ve=s.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-8",children:[ae,oe]}),t[97]=ae,t[98]=oe,t[99]=ve):ve=t[99];let K;t[100]!==h||t[101]!==b||t[102]!==e?(K=h==="archive"?e("settings.openchamber.sessionRetention.manualCleanup.eligibleArchiveNow",{count:b}):e("settings.openchamber.sessionRetention.manualCleanup.eligibleDeleteNow",{count:b}),t[100]=h,t[101]=b,t[102]=e,t[103]=K):K=t[103];let ce;t[104]!==K?(ce=s.jsx("p",{className:"typography-meta text-muted-foreground",children:K}),t[104]=K,t[105]=ce):ce=t[105];let Z;t[106]!==ve||t[107]!==ce?(Z=s.jsxs("div",{className:"mt-1 px-2 py-1.5 space-y-1",children:[ve,ce]}),t[106]=ve,t[107]=ce,t[108]=Z):Z=t[108];let le;return t[109]!==te||t[110]!==Z||t[111]!==D?(le=s.jsxs("div",{className:"mb-8",children:[D,te,Z]}),t[109]=te,t[110]=Z,t[111]=D,t[112]=le):le=t[112],le};function H5(t){return t.autoDeleteEnabled}function G5(t){return t.autoDeleteAfterDays}function q5(t){return t.sessionRetentionAction}function J5(t){return t.setAutoDeleteEnabled}function Q5(t){return t.setAutoDeleteAfterDays}function Y5(t){return t.setSessionRetentionAction}const Cp=(t,e)=>!t||!Number.isFinite(t)?e:new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"}).format(t),dg=()=>{const{t}=pt(),[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,h]=l.useState([]),[b,f]=l.useState($b),[v,x]=l.useState(""),g=l.useMemo(()=>Bb(),[]),w=l.useCallback(async()=>{a(!0),x("");try{const j=await _b();h(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 Ql();if(f(S),!S.enabled){h([]),a(!1);return}await w()}})(),()=>{j=!0,ku()}},[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){ku(),o(!1);return}x(""),o(!0);try{await Vb(),f(await Ql()),await w(),H.success(t("settings.openchamber.passkeys.toast.added"))}catch(j){if(zb(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]),k=l.useCallback(async j=>{d(j),x("");try{await Ub(j),f(await Ql()),await w(),H.success(t("settings.openchamber.passkeys.toast.removed"))}catch(S){const A=S instanceof Error?S.message:t("settings.openchamber.passkeys.toast.removeFailed");x(A),H.error(A)}finally{d(null)}},[w,t]),D=l.useCallback(async()=>{m(!0),x("");try{await Wb(),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(we,{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(we,{type:"button",variant:"ghost",size:"xs",onClick:()=>{D()},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:Cp(j.lastUsedAt,t("settings.openchamber.passkeys.time.neverUsed"))}):t("settings.openchamber.passkeys.item.added",{time:Cp(j.createdAt,t("settings.openchamber.passkeys.time.neverUsed"))})}),s.jsx(we,{type:"button",variant:"ghost",size:"xs",onClick:()=>{k(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})})]})},X5=t=>{const e=ui(t);return e||{providerId:"",modelId:""}},ug=()=>{const{t}=pt(),e=gt(M=>M.setProvider),n=gt(M=>M.setModel),r=gt(M=>M.setAgent),a=gt(M=>M.setCurrentVariant),i=gt(M=>M.setSettingsDefaultModel),o=gt(M=>M.setSettingsDefaultVariant),c=gt(M=>M.setSettingsDefaultAgent),d=gt(M=>M.setSettingsDefaultFileViewerPreview),p=gt(M=>M.settingsDefaultFileViewerPreview),m=Te(M=>M.showDeletionDialog),u=Te(M=>M.setShowDeletionDialog),h=gt(M=>M.providers),[b,f]=l.useState(),[v,x]=l.useState(),[g,w]=l.useState(),[y,k]=l.useState(!0),D=l.useMemo(()=>X5(b),[b]);l.useEffect(()=>{(async()=>{try{let R=null;if(!R){const L=dr()?.settings;if(L)try{const B=(await L.load())?.settings;B&&(R={defaultModel:typeof B.defaultModel=="string"?B.defaultModel:void 0,defaultVariant:typeof B.defaultVariant=="string"?B.defaultVariant:void 0,defaultAgent:typeof B.defaultAgent=="string"?B.defaultAgent:void 0})}catch{}}if(!R){const L=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});L.ok&&(R=await L.json())}if(R){const L=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,B=typeof R.defaultAgent=="string"&&R.defaultAgent.trim().length>0?R.defaultAgent.trim():void 0;L!==void 0&&f(L),$!==void 0&&x($),B!==void 0&&w(B)}}catch(R){console.warn("Failed to load defaults settings:",R)}finally{k(!1)}})()},[]);const j=l.useCallback(async(M,R)=>{const L=M&&R?`${M}/${R}`:void 0;f(L),x(void 0),o(void 0),a(void 0),i(L),M&&R&&h.find(B=>B.id===M)&&(e(M),n(R));try{await Ds({defaultModel:L??"",defaultVariant:""});const $=await fetch("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({defaultModel:L})});$.ok||console.warn("Failed to save default model to server:",$.status,$.statusText)}catch($){console.warn("Failed to save default model:",$)}},[h,a,n,e,i,o]),S="__default__",A=l.useCallback(M=>M===S?t("settings.openchamber.defaults.option.default"):M.charAt(0).toUpperCase()+M.slice(1),[t]),E=l.useCallback(async M=>{const R=M===S?void 0:M||void 0;x(R),o(R),a(R);try{await Ds({defaultVariant:R??""})}catch(L){console.warn("Failed to save default variant:",L)}},[a,o]),P=l.useCallback(async M=>{const R=M||void 0;w(R),c(R),M&&r(M);try{await Ds({defaultAgent:R??""})}catch(L){console.warn("Failed to save default agent:",L)}},[r,c]),C=l.useCallback(()=>{const M=!p;d(M),Ds({defaultFileViewerPreview:M}).catch(console.warn)},[p,d]),N=l.useMemo(()=>{if(!D.providerId||!D.modelId)return[];const L=h.find($=>$.id===D.providerId)?.models.find($=>$.id===D.modelId)?.variants;return L?Object.keys(L):[]},[D.modelId,D.providerId,h]),T=N.length>0;return l.useEffect(()=>{!T&&v&&(x(void 0),o(void 0),a(void 0),Ds({defaultVariant:""}).catch(()=>{}))},[v,a,o,T]),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")," ",D.providerId?s.jsxs("span",{className:"text-foreground",children:[D.providerId,"/",D.modelId,T?` (${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:me("flex flex-col gap-2 py-1 sm:flex-row sm:items-center sm:gap-8"),children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.defaults.field.defaultModel")})}),s.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:s.jsx(ao,{providerId:D.providerId,modelId:D.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(ds,{value:v??S,onValueChange:E,disabled:!T,children:[s.jsx(us,{className:"w-fit min-w-[120px]",children:s.jsx(ys,{placeholder:t("settings.openchamber.defaults.field.thinkingPlaceholder"),children:A(v??S)})}),s.jsxs(ms,{children:[s.jsx(Lt,{value:S,children:t("settings.openchamber.defaults.option.default")}),N.map(M=>s.jsx(Lt,{value:M,children:A(M)},M))]})]})})]}),s.jsxs("div",{className:"flex flex-col gap-2 py-1 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.defaults.field.defaultAgent")})}),s.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:s.jsx(Tl,{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:M=>{(M.key===" "||M.key==="Enter")&&(M.preventDefault(),u(!m))},children:[s.jsx(xs,{checked:m,onChange:u,ariaLabel:t("settings.openchamber.defaults.field.showDeletionDialogAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.defaults.field.showDeletionDialog")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1",role:"button",tabIndex:0,"aria-pressed":p,onClick:C,onKeyDown:M=>{(M.key===" "||M.key==="Enter")&&(M.preventDefault(),C())},children:[s.jsx(xs,{checked:p,onChange:d,ariaLabel:t("settings.openchamber.defaults.field.openFilesPreviewAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.defaults.field.openFilesPreview")})]})]})]})},Ip={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"}},Z5={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"},Pp="big-pickle",Ic="__not_selected__",Ap=200,Dp=100,Tp=250,eC=()=>{const{t}=pt(),{isMobile:e}=an(),n=l.useMemo(()=>yn(),[]),r=l.useMemo(()=>dn(),[]),a=!n&&!r,i=Te(K=>K.nativeNotificationsEnabled),o=Te(K=>K.setNativeNotificationsEnabled),c=Te(K=>K.notificationMode),d=Te(K=>K.setNotificationMode),p=Te(K=>K.notifyOnSubtasks),m=Te(K=>K.setNotifyOnSubtasks),u=Te(K=>K.notifyOnCompletion),h=Te(K=>K.setNotifyOnCompletion),b=Te(K=>K.notifyOnError),f=Te(K=>K.setNotifyOnError),v=Te(K=>K.notifyOnQuestion),x=Te(K=>K.setNotifyOnQuestion),g=Te(K=>K.notificationTemplates),w=Te(K=>K.setNotificationTemplates),y=Te(K=>K.summarizeLastMessage),k=Te(K=>K.setSummarizeLastMessage),D=Te(K=>K.summaryThreshold),j=Te(K=>K.setSummaryThreshold),S=Te(K=>K.summaryLength),A=Te(K=>K.setSummaryLength),E=Te(K=>K.maxLastMessageLength),P=Te(K=>K.setMaxLastMessageLength),C=gt(K=>K.settingsZenModel),N=gt(K=>K.setSettingsZenModel),[T,M]=l.useState("default"),[R,L]=l.useState(!1),[$,B]=l.useState(!1),[O,_]=l.useState(!1),[ee,z]=l.useState([]);l.useEffect(()=>{const K=new AbortController;return fetch("/api/zen/models",{method:"GET",headers:{Accept:"application/json"},signal:K.signal}).then(async ce=>{if(!ce.ok)return[];const Z=await ce.json().catch(()=>({}));return(Array.isArray(Z?.models)?Z.models:[]).map(se=>{const Ie=typeof se?.id=="string"?se.id.trim():"";return Ie?{id:Ie,name:Ie}:null}).filter(se=>se!==null)}).then(ce=>{z(ce)}).catch(ce=>{ce?.name!=="AbortError"&&console.warn("Failed to load zen utility models:",ce)}),()=>{K.abort()}},[]);const ne=l.useMemo(()=>ee,[ee]),re=l.useMemo(()=>C&&ne.some(K=>K.id===C)?C:ne.some(K=>K.id===Pp)?Pp:ne[0]?.id??"",[C,ne]),ue=l.useCallback(async K=>{const ce=K===Ic?void 0:K;N(ce);try{await Ds({zenModel:ce??"",gitProviderId:"",gitModelId:""})}catch(Z){console.warn("Failed to save utility model setting:",Z)}},[N]);l.useEffect(()=>{if(!a){L(!1),B(!1);return}typeof Notification<"u"&&M(Notification.permission);const K=typeof window<"u"&&"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window;L(K),(async()=>{if(!K){B(!1);return}try{const Z=await navigator.serviceWorker.getRegistration();if(!Z){B(!1);return}const le=await Z.pushManager.getSubscription();B(!!le)}catch{B(!1)}})()},[a]);const Q=async K=>{if(n){o(K);return}if(!a){o(K);return}if(K&&typeof Notification<"u"&&Notification.permission==="default")try{const ce=await Notification.requestPermission();M(ce),ce==="granted"?o(!0):H.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.description")})}catch(ce){console.error("Failed to request notification permission:",ce),H.error(t("settings.notifications.page.toast.requestPermissionFailed"))}else o(!!(K&&T==="granted"))},de=n||r||a&&typeof Notification<"u"&&Notification.permission==="granted",X=(K,ce,Z)=>{w({...g,[K]:{...g[K],[ce]:Z}})},F=K=>{const ce="=".repeat((4-K.length%4)%4),Z=(K+ce).replace(/-/g,"+").replace(/_/g,"/"),le=atob(Z),se=new Uint8Array(le.length);for(let Ie=0;Ie<le.length;Ie+=1)se[Ie]=le.charCodeAt(Ie);return se},V=async(K,ce,Z)=>{let le=null;const se=new Promise((Ie,Ne)=>{le=setTimeout(()=>{Ne(new Error(Z))},ce)});try{return await Promise.race([K,se])}finally{le&&clearTimeout(le)}},q=async K=>{if(K.active)return;const ce=K.installing||K.waiting;ce&&ce.state!=="activated"&&await V(new Promise(Z=>{const le=()=>{ce.state==="activated"&&(ce.removeEventListener("statechange",le),Z())};ce.addEventListener("statechange",le),le()}),15e3,"Service worker activation timed out")},te=async()=>{if(typeof navigator.serviceWorker.register!="function")throw new Error("navigator.serviceWorker.register unavailable");const K=[{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 ce=null;for(const Z of K)try{const le=Z.opts?navigator.serviceWorker.register("/sw.js",Z.opts):navigator.serviceWorker.register("/sw.js");return await V(le,1e4,`Service worker registration timed out (${Z.label})`)}catch(le){ce=le}throw ce instanceof Error?ce:new Error("Service worker registration failed")},U=async()=>{if(!("serviceWorker"in navigator))throw new Error("Service worker not supported");const K=await navigator.serviceWorker.getRegistration();if(K)return K;const ce=await te();try{await ce.update()}catch{}return await q(ce),ce},ae=K=>{const ce=K,Z=[`type=${typeof K}`,`toString=${String(K)}`,`name=${String(ce?.name??"")}`,`message=${String(ce?.message??"")}`];let le="";try{le=JSON.stringify(K)}catch{}return{summary:Z.filter(Boolean).join(" | "),json:le,stack:typeof ce?.stack=="string"?ce.stack:""}},je=async()=>{const K=dr();if(!K?.notifications){H.error(t("settings.notifications.page.toast.notificationsApiUnavailable"));return}try{await K.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(ce){console.error("Test notification failed:",ce),H.error(t("settings.notifications.page.toast.testNotificationFailed"))}},oe=async()=>{if(!R){H.error(t("settings.notifications.page.toast.pushUnsupported"));return}const K=dr();if(!K?.push){H.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}_(!0);try{if(typeof Notification<"u"&&Notification.permission==="default"){const fe=await Notification.requestPermission();if(M(fe),fe!=="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 ce=await K.push.getVapidPublicKey();if(!ce?.publicKey){H.error(t("settings.notifications.page.toast.pushKeyLoadFailed"));return}const Z=await U();await q(Z);const le=await Z.pushManager.getSubscription();if(!("pushManager"in Z)||!Z.pushManager)throw new Error("PushManager unavailable (requires installed PWA + iOS 16.4+)");const Ie=(le??await V(Z.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:F(ce.publicKey)}),15e3,"Push subscription timed out")).toJSON(),Ne=Ie.keys;if(!Ie.endpoint||!Ne?.p256dh||!Ne.auth)throw new Error("Push subscription missing keys");if(!(await V(K.push.subscribe({endpoint:Ie.endpoint,keys:{p256dh:Ne.p256dh,auth:Ne.auth},origin:typeof window<"u"?window.location.origin:void 0}),15e3,"Push subscribe request timed out"))?.ok){H.error(t("settings.notifications.page.toast.enableBackgroundFailed"));return}B(!0),H.success(t("settings.notifications.page.toast.backgroundEnabled"))}catch(ce){console.error("[Push] Enable failed:",ce);const Z=ae(ce);H.error(t("settings.notifications.page.toast.enableBackgroundFailed"),{description:Z.summary})}finally{_(!1)}},ve=async()=>{if(!R){B(!1);return}const K=dr();if(!K?.push){H.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}_(!0);try{const Z=await(await U()).pushManager.getSubscription();if(!Z){B(!1);return}const le=Z.endpoint;await Z.unsubscribe(),await K.push.unsubscribe({endpoint:le}),B(!1),H.success(t("settings.notifications.page.toast.backgroundDisabled"))}finally{_(!1)}};return s.jsxs("div",{className:"space-y-8",children:[s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.notifications.page.delivery.title")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":i&&de,onClick:()=>{Q(!(i&&de))},onKeyDown:K=>{(K.key===" "||K.key==="Enter")&&(K.preventDefault(),Q(!(i&&de)))},children:[s.jsx(xs,{checked:i&&de,onChange:K=>{Q(K)},ariaLabel:t("settings.notifications.page.delivery.enableAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.delivery.enableLabel")})]}),i&&de&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":c==="always",onClick:()=>d(c==="always"?"hidden-only":"always"),onKeyDown:K=>{(K.key===" "||K.key==="Enter")&&(K.preventDefault(),d(c==="always"?"hidden-only":"always"))},children:[s.jsx(xs,{checked:c==="always",onChange:K=>d(K?"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(we,{type:"button",variant:"outline",size:"sm",onClick:()=>{je()},children:t("settings.notifications.page.delivery.testAction")})})]})]}),a&&s.jsxs("div",{className:"mt-1 px-2",children:[s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.notifications.page.delivery.browserPermissionHint")}),T==="denied"&&s.jsx("p",{className:"typography-meta text-[var(--status-error)] mt-1",children:t("settings.notifications.page.delivery.permissionDenied")}),T==="granted"&&!i&&s.jsx("p",{className:"typography-meta text-muted-foreground/70 mt-1",children:t("settings.notifications.page.delivery.permissionGrantedButDisabled")})]}),r&&s.jsx("div",{className:"mt-1 px-2",children:s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.notifications.page.delivery.vscodeHint")})})]}),i&&de&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.notifications.page.events.title")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":u,onClick:()=>h(!u),onKeyDown:K=>{(K.key===" "||K.key==="Enter")&&(K.preventDefault(),h(!u))},children:[s.jsx(xs,{checked:u,onChange:h,ariaLabel:t("settings.notifications.page.events.completionAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.events.completionLabel")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":p,onClick:()=>m(!p),onKeyDown:K=>{(K.key===" "||K.key==="Enter")&&(K.preventDefault(),m(!p))},children:[s.jsx(xs,{checked:p,onChange:m,ariaLabel:t("settings.notifications.page.events.subtaskAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.events.subtaskLabel")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":b,onClick:()=>f(!b),onKeyDown:K=>{(K.key===" "||K.key==="Enter")&&(K.preventDefault(),f(!b))},children:[s.jsx(xs,{checked:b,onChange:f,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":v,onClick:()=>x(!v),onKeyDown:K=>{(K.key===" "||K.key==="Enter")&&(K.preventDefault(),x(!v))},children:[s.jsx(xs,{checked:v,onChange:x,ariaLabel:t("settings.notifications.page.events.questionAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.events.questionLabel")})]})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 px-1",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.notifications.page.template.title")}),s.jsxs("p",{className:"typography-meta text-muted-foreground mt-0.5",children:[t("settings.notifications.page.template.variablesLabel")," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{project_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{worktree}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{branch}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{session_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{agent_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{model_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{last_message}"})]})]}),s.jsx("div",{className:"grid grid-cols-1 gap-2 md:grid-cols-2 md:gap-3",children:["completion","subtask","error","question"].map(K=>s.jsxs("section",{className:"p-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground font-normal capitalize block",children:t(Z5[K])}),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(Kt,{value:g[K].title,onChange:ce=>X(K,"title",ce.target.value),className:"h-7",placeholder:t(Ip[K].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(Kt,{value:g[K].message,onChange:ce=>X(K,"message",ce.target.value),className:"h-7",placeholder:t(Ip[K].messageKey)})]})]})]},K))})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.notifications.page.summary.title")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":y,onClick:()=>k(!y),onKeyDown:K=>{(K.key===" "||K.key==="Enter")&&(K.preventDefault(),k(!y))},children:[s.jsx(xs,{checked:y,onChange:k,ariaLabel:t("settings.notifications.page.summary.toggleAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.summary.toggleLabel")})]}),s.jsx("div",{className:"pl-6 pb-1",children:s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[t("settings.notifications.page.summary.requiresTemplateVariable")," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{last_message}"}),"."]})}),s.jsxs("div",{className:me("flex flex-col gap-2 py-1 sm:flex-row sm:items-center sm:gap-8"),children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.summary.modelLabel")}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:t("settings.notifications.page.summary.modelTooltip")})]})]})}),s.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:s.jsxs(ds,{value:re||Ic,onValueChange:ue,children:[s.jsx(us,{className:"w-fit min-w-[220px]",children:s.jsx(ys,{placeholder:t("settings.notifications.page.summary.notSelected")})}),s.jsxs(ms,{children:[s.jsx(Lt,{value:Ic,children:t("settings.notifications.page.summary.notSelected")}),ne.map(K=>s.jsx(Lt,{value:K.id,children:K.name},K.id))]})]})})]}),y?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex items-center gap-8 py-1.5 mt-1 border-t border-[var(--surface-subtle)]",children:[s.jsxs("div",{className:"flex min-w-0 flex-col w-56 shrink-0",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.summary.thresholdLabel")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.notifications.page.summary.thresholdHint")})]}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[s.jsx(xn,{value:D,onValueChange:j,min:50,max:2e3,step:50,className:"w-20 tabular-nums"}),s.jsx(we,{size:"sm",type:"button",variant:"ghost",onClick:()=>j(Ap),disabled:D===Ap,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":t("settings.notifications.page.summary.resetThresholdAria"),title:t("settings.common.actions.reset"),children:s.jsx(I,{name:"restart",className:"h-3.5 w-3.5"})})]})]}),s.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[s.jsxs("div",{className:"flex min-w-0 flex-col w-56 shrink-0",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.summary.lengthLabel")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.notifications.page.summary.lengthHint")})]}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[s.jsx(xn,{value:S,onValueChange:A,min:20,max:500,step:10,className:"w-20 tabular-nums"}),s.jsx(we,{size:"sm",type:"button",variant:"ghost",onClick:()=>A(Dp),disabled:S===Dp,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":t("settings.notifications.page.summary.resetLengthAria"),title:t("settings.common.actions.reset"),children:s.jsx(I,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]}):s.jsxs("div",{className:me("py-1.5 mt-1 border-t border-[var(--surface-subtle)]",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsxs("div",{className:me("flex min-w-0 flex-col",e?"w-full":"w-56 shrink-0"),children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.summary.maxLengthLabel")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.notifications.page.summary.maxLengthHint")})]}),s.jsxs("div",{className:me("flex items-center gap-2",e?"w-full":"w-fit"),children:[s.jsx(xn,{value:E,onValueChange:P,min:50,max:1e3,step:10,className:"w-20 tabular-nums"}),s.jsx(we,{size:"sm",type:"button",variant:"ghost",onClick:()=>P(Tp),disabled:E===Tp,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":t("settings.notifications.page.summary.resetMaxLengthAria"),title:t("settings.common.actions.reset"),children:s.jsx(I,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]})]})]}),a&&s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.notifications.page.push.title")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsxs("div",{className:"flex items-start gap-2 py-1.5",children:[s.jsx(xs,{checked:R?$:!1,disabled:!R||O,onChange:K=>{K?oe():ve()},ariaLabel:t("settings.notifications.page.push.enableAria")}),s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:me("typography-ui-label",R?"text-foreground":"text-muted-foreground"),children:t("settings.notifications.page.push.enableLabel")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t(R?"settings.notifications.page.push.supportedHint":"settings.notifications.page.push.unsupportedHint")})]}),O&&s.jsx("div",{className:"pt-0.5 text-muted-foreground",children:s.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-current animate-busy-pulse","aria-label":t("settings.notifications.page.push.loadingAria")})})]})})]})]})},tC=[{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:"Українська"}],sC=t=>{const e=at.c(45),{modelId:n}=t,{t:r}=pt();let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=Mi.getModelStatus(),e[0]=a):a=e[0];const[i,o]=Be.useState(a),[c,d]=Be.useState(!1);let p,m;e[1]===Symbol.for("react.memo_cache_sentinel")?(p=()=>{const j=S=>o(S);return Mi.onModelStatusChange=j,aC},m=[],e[1]=p,e[2]=m):(p=e[1],m=e[2]),Be.useEffect(p,m);const u=Mi.getCurrentModelId(),h=i.state==="downloading"||i.state==="loading";let b,f;e[3]!==i.state?(b=()=>{i.state!=="downloading"&&i.state!=="loading"&&d(!1)},f=[i.state],e[3]=i.state,e[4]=b,e[5]=f):(b=e[4],f=e[5]),Be.useEffect(b,f);let v;e[6]!==n?(v=async()=>{d(!0);try{await Mi.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(h){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 A;e[15]!==i.state||e[16]!==r?(A=i.state==="downloading"?r("settings.voice.page.stt.wasmDownloading"):r("settings.voice.page.stt.wasmLoading"),e[15]=i.state,e[16]=r,e[17]=A):A=e[17];const E=S!==void 0?` (${S}%)`:"";let P;return e[18]!==A||e[19]!==E?(P=s.jsx("div",{className:"flex items-center gap-2",children:s.jsxs("span",{className:"typography-ui-compact text-muted-foreground",children:[A,E]})}),e[18]=A,e[19]=E,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 A;e[25]!==x||e[26]!==c||e[27]!==S?(A=s.jsx(we,{variant:"chip",size:"xs",disabled:c,onClick:x,children:S}),e[25]=x,e[26]=c,e[27]=S,e[28]=A):A=e[28];let E;return e[29]!==j||e[30]!==A?(E=s.jsxs("div",{className:"flex items-center gap-2",children:[j,A]}),e[29]=j,e[30]=A,e[31]=E):E=e[31],E}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 k;e[38]!==x||e[39]!==c||e[40]!==y?(k=s.jsx(we,{variant:"chip",size:"xs",disabled:c,onClick:x,children:y}),e[38]=x,e[39]=c,e[40]=y,e[41]=k):k=e[41];let D;return e[42]!==k||e[43]!==w?(D=s.jsxs("div",{className:"flex items-center gap-2",children:[w,k]}),e[42]=k,e[43]=w,e[44]=D):D=e[44],D},nC=[{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"}],rC=()=>{const{t}=pt(),{isMobile:e}=an(),{isSupported:n,language:r,setLanguage:a}=Kb(),i=gt(he=>he.voiceProvider),o=gt(he=>he.setVoiceProvider),c=gt(he=>he.speechRate),d=gt(he=>he.setSpeechRate),p=gt(he=>he.speechPitch),m=gt(he=>he.setSpeechPitch),u=gt(he=>he.speechVolume),h=gt(he=>he.setSpeechVolume),b=gt(he=>he.sayVoice),f=gt(he=>he.setSayVoice),v=gt(he=>he.browserVoice),x=gt(he=>he.setBrowserVoice),g=gt(he=>he.openaiVoice),w=gt(he=>he.setOpenaiVoice),y=gt(he=>he.openaiApiKey),k=gt(he=>he.setOpenaiApiKey),D=gt(he=>he.openaiCompatibleUrl),j=gt(he=>he.setOpenaiCompatibleUrl),S=gt(he=>he.openaiCompatibleVoice),A=gt(he=>he.setOpenaiCompatibleVoice),E=gt(he=>he.openaiCompatibleTtsModel),P=gt(he=>he.setOpenaiCompatibleTtsModel),C=gt(he=>he.showMessageTTSButtons),N=gt(he=>he.sttProvider),T=gt(he=>he.setSttProvider),M=gt(he=>he.sttServerUrl),R=gt(he=>he.setSttServerUrl),L=gt(he=>he.sttModel),$=gt(he=>he.setSttModel),B=gt(he=>he.wasmSttModel),O=gt(he=>he.setWasmSttModel),_=gt(he=>he.sttLanguage),ee=gt(he=>he.setSttLanguage),z=gt(he=>he.sttSilenceThresholdDb),ne=gt(he=>he.setSttSilenceThresholdDb),re=gt(he=>he.sttSilenceHoldMs),ue=gt(he=>he.setSttSilenceHoldMs),Q=gt(he=>he.sttTranscribeOnStop),de=gt(he=>he.setSttTranscribeOnStop),X=gt(he=>he.setShowMessageTTSButtons),F=gt(he=>he.voiceModeEnabled),V=gt(he=>he.setVoiceModeEnabled),q=gt(he=>he.summarizeMessageTTS),te=gt(he=>he.setSummarizeMessageTTS),U=gt(he=>he.summarizeVoiceConversation),ae=gt(he=>he.setSummarizeVoiceConversation),je=gt(he=>he.summarizeCharacterThreshold),oe=gt(he=>he.setSummarizeCharacterThreshold),ve=gt(he=>he.summarizeMaxLength),K=gt(he=>he.setSummarizeMaxLength),[ce,Z]=Be.useState(!1),[le,se]=Be.useState([]),[Ie,Ne]=Be.useState(!1),[Y,fe]=Be.useState(null),[ke,be]=Be.useState(!1),[pe,Ee]=Be.useState(!1),[ze,G]=Be.useState(null),[Pe,Le]=Be.useState(!1),[Ae,ge]=Be.useState(null),[W,ie]=Be.useState([]),[Me,Ve]=Be.useState(!1);Be.useEffect(()=>((async()=>{const qe=await Yl.waitForVoices();ie(qe)})(),"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=()=>{ie(window.speechSynthesis.getVoices())}),()=>{"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=null)}),[]);const Ce=Be.useMemo(()=>W.filter(he=>he.lang).sort((he,qe)=>{const et=he.lang.startsWith("en"),Ke=qe.lang.startsWith("en");if(et&&!Ke)return-1;if(!et&&Ke)return 1;const st=he.lang.localeCompare(qe.lang);return st!==0?st:he.name.localeCompare(qe.name)}),[W]),xe=Be.useCallback(()=>{if(Me){Yl.cancelSpeech(),Ve(!1);return}const he=W.find(st=>st.name===v),qe=he?.name??t("settings.voice.page.preview.browserVoiceFallback"),et=t("settings.voice.page.preview.voiceLine",{voiceName:qe});Ve(!0);const Ke=new SpeechSynthesisUtterance(et);Ke.rate=c,Ke.pitch=p,Ke.volume=u,he&&(Ke.voice=he,Ke.lang=he.lang),Ke.onend=()=>Ve(!1),Ke.onerror=()=>Ve(!1),window.speechSynthesis.cancel(),window.speechSynthesis.speak(Ke)},[v,W,c,p,u,Me,t]);Be.useEffect(()=>()=>{Me&&Yl.cancelSpeech()},[Me]),Be.useEffect(()=>{if(!F||i!=="openai"&&i!=="openai-compatible"){be(y.trim().length>0);return}(async()=>{try{const Ke=(await(await fetch("/api/tts/status")).json()).available,st=y.trim().length>0;be(Ke||st)}catch{be(y.trim().length>0)}})()},[y,F,i]),Be.useEffect(()=>{if(!F){Z(!1),se([]);return}fetch("/api/tts/say/status").then(he=>he.json()).then(he=>{if(Z(he.available),he.voices){const qe=he.voices.filter((et,Ke,st)=>st.findIndex(nt=>nt.name===et.name)===Ke).sort((et,Ke)=>et.name.localeCompare(Ke.name));se(qe)}}).catch(()=>{Z(!1)})},[F]);const De=Be.useCallback(async()=>{if(Y){Y.pause(),Y.currentTime=0,fe(null),Ne(!1);return}Ne(!0);try{const he=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(!he.ok)throw new Error("Preview failed");const qe=await he.blob(),et=URL.createObjectURL(qe),Ke=new Audio(et);Ke.onended=()=>{URL.revokeObjectURL(et),fe(null),Ne(!1)},Ke.onerror=()=>{URL.revokeObjectURL(et),fe(null),Ne(!1)},fe(Ke),await Ke.play()}catch{Ne(!1)}},[b,c,Y,t]);Be.useEffect(()=>()=>{Y&&Y.pause()},[Y]);const Ye=Be.useCallback(async()=>{if(ze){ze.pause(),ze.currentTime=0,G(null),Ee(!1);return}Ee(!0);try{const he=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(!he.ok){const st=await he.json().catch(()=>({error:"Unknown error"}));throw new Error(st.error||`HTTP ${he.status}`)}const qe=await he.blob(),et=URL.createObjectURL(qe),Ke=new Audio(et);Ke.onended=()=>{URL.revokeObjectURL(et),G(null),Ee(!1)},Ke.onerror=()=>{URL.revokeObjectURL(et),G(null),Ee(!1)},G(Ke),await Ke.play()}catch{Ee(!1)}},[g,c,ze,y,t]);Be.useEffect(()=>()=>{ze&&ze.pause()},[ze]);const rt=Be.useCallback(async()=>{if(Ae){Ae.pause(),Ae.currentTime=0,ge(null),Le(!1);return}if(D.trim()){Le(!0);try{const he=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:E||void 0,speed:c,baseURL:D})});if(!he.ok){const st=await he.json().catch(()=>({error:"Unknown error"}));throw new Error(st.error||`HTTP ${he.status}`)}const qe=await he.blob(),et=URL.createObjectURL(qe),Ke=new Audio(et);Ke.onended=()=>{URL.revokeObjectURL(et),ge(null),Le(!1)},Ke.onerror=()=>{URL.revokeObjectURL(et),ge(null),Le(!1)},ge(Ke),await Ke.play()}catch{Le(!1)}}},[D,S,E,c,Ae,t]);Be.useEffect(()=>()=>{Ae&&Ae.pause()},[Ae]);const Re="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":F,onClick:()=>V(!F),onKeyDown:he=>{(he.key===" "||he.key==="Enter")&&(he.preventDefault(),V(!F))},children:[s.jsx(xs,{checked:F,onChange:V,ariaLabel:t("settings.voice.page.field.enableVoiceModeAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.enableVoiceMode")})]}),F&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"pb-1.5 pt-0.5",children:s.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.provider")}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{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(we,{variant:"chip",size:"xs","aria-pressed":i==="browser",onClick:()=>o("browser"),className:"!font-normal",children:t("settings.voice.page.provider.browser")}),s.jsx(we,{variant:"chip",size:"xs","aria-pressed":i==="openai",onClick:()=>o("openai"),className:"!font-normal",children:"OpenAI"}),s.jsx(we,{variant:"chip",size:"xs","aria-pressed":i==="openai-compatible",onClick:()=>o("openai-compatible"),className:"!font-normal",children:t("settings.voice.page.provider.custom")}),ce&&s.jsxs(we,{variant:"chip",size:"xs","aria-pressed":i==="say",onClick:()=>o("say"),className:"!font-normal",children:[s.jsx(I,{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:me("typography-ui-label text-foreground",!ke&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.apiKey")}),s.jsx("span",{className:me("typography-meta ml-2",ke?"text-muted-foreground":"text-[var(--status-error)]/80"),children:t(ke&&!y?"settings.voice.page.field.apiKeyHintUsingConfig":ke?"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:he=>k(he.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:()=>k(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(I,{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:me("typography-ui-label text-foreground",!D.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:D,onChange:he=>j(he.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"}),D&&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(I,{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:E,onChange:he=>P(he.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:he=>A(he.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(we,{size:"xs",variant:"ghost",onClick:rt,title:t("settings.voice.page.actions.preview"),disabled:!D.trim(),children:Pe?s.jsx(I,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(I,{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"&&ke&&s.jsxs(s.Fragment,{children:[s.jsxs(ds,{value:g,onValueChange:w,children:[s.jsx(us,{className:"w-fit",children:s.jsx(ys,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(ms,{children:nC.map(he=>s.jsx(Lt,{value:he.value,children:he.label},he.value))})]}),s.jsx(we,{size:"xs",variant:"ghost",onClick:Ye,title:t("settings.voice.page.actions.preview"),children:pe?s.jsx(I,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(I,{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"&&ce&&le.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(ds,{value:b,onValueChange:f,children:[s.jsx(us,{className:"w-fit",children:s.jsx(ys,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(ms,{children:le.map(he=>s.jsx(Lt,{value:he.name,children:he.name},he.name))})]}),s.jsx(we,{size:"xs",variant:"ghost",onClick:De,title:t("settings.voice.page.actions.preview"),children:Ie?s.jsx(I,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(I,{name:"play",className:"w-3.5 h-3.5"})})]}),i==="browser"&&Ce.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(ds,{value:v||"$auto",onValueChange:he=>x(he==="$auto"?"":he),children:[s.jsx(us,{className:"w-fit max-w-[200px]",children:s.jsx(ys,{placeholder:t("settings.voice.page.field.auto")})}),s.jsxs(ms,{children:[s.jsx(Lt,{value:"$auto",children:t("settings.voice.page.field.auto")}),Ce.map(he=>s.jsxs(Lt,{value:he.name,children:[he.name," (",he.lang,")"]},he.name))]})]}),s.jsx(we,{size:"xs",variant:"ghost",onClick:xe,title:t("settings.voice.page.actions.preview"),children:Me?s.jsx(I,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(I,{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:he=>d(Number(he.target.value)),disabled:!n,className:Re}),s.jsx(xn,{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:he=>m(Number(he.target.value)),disabled:!n,className:Re}),s.jsx(xn,{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:he=>h(Number(he.target.value)),disabled:!n,className:Re}),e?s.jsx(xn,{value:Math.round(u*100),onValueChange:he=>h(he/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(ds,{value:r,onValueChange:a,disabled:!n,children:[s.jsx(us,{className:"w-fit",children:s.jsx(ys,{placeholder:t("settings.voice.page.field.selectLanguagePlaceholder")})}),s.jsx(ms,{children:tC.map(he=>s.jsx(Lt,{value:he.value,children:he.label},he.value))})]})})]})]})]})]}),F&&s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.voice.page.section.speechRecognition")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[s.jsx("div",{className:"pb-1.5 pt-0.5",children:s.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.provider")}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Pt,{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(we,{variant:"chip",size:"xs","aria-pressed":N==="browser",onClick:()=>T("browser"),className:"!font-normal",children:t("settings.voice.page.provider.browser")}),s.jsx(we,{variant:"chip",size:"xs","aria-pressed":N==="server",onClick:()=>T("server"),className:"!font-normal",children:t("settings.voice.page.provider.server")}),s.jsx(we,{variant:"chip",size:"xs","aria-pressed":N==="wasm",onClick:()=>T("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":Q,onClick:()=>de(!Q),onKeyDown:he=>{(he.key===" "||he.key==="Enter")&&(he.preventDefault(),de(!Q))},children:[s.jsx(xs,{checked:Q,onChange:de,ariaLabel:t("settings.voice.page.field.transcribeOnStopAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.transcribeOnStop")})]}),!Hb.isSupported()&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:t("settings.voice.page.field.sttBrowserSupportError")}),s.jsxs("div",{children:[s.jsx("span",{className:me("typography-ui-label text-foreground",!M.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:M,onChange:he=>R(he.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"}),M&&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(I,{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:L,onChange:he=>$(he.target.value),placeholder:"deepdml/faster-whisper-large-v3-turbo-ct2",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})})]}),s.jsxs("div",{children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.language")}),s.jsx("span",{className:"typography-meta ml-2 text-muted-foreground",children:t("settings.voice.page.field.sttLanguageHint")}),s.jsx("div",{className:"relative mt-1.5 max-w-[8rem]",children:s.jsx("input",{type:"text",value:_,onChange:he=>ee(he.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:z,onChange:he=>ne(Number(he.target.value)),className:Re}),s.jsxs("span",{className:"typography-ui-label text-foreground tabular-nums min-w-[3.5rem] text-right",children:[z," 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:re,onChange:he=>ue(Number(he.target.value)),className:Re}),s.jsx(xn,{value:re,onValueChange:ue,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(ds,{value:B,onValueChange:O,children:[s.jsx(us,{className:"mt-0.5",children:s.jsx(ys,{placeholder:t("settings.voice.page.stt.wasmModel")})}),s.jsx(ms,{children:Cu.map(he=>s.jsx(Lt,{value:he.id,children:s.jsxs("div",{className:"flex flex-col",children:[s.jsx("span",{children:he.name}),s.jsxs("span",{className:"typography-ui-compact text-muted-foreground",children:[he.size," · ",he.languages]})]})},he.id))})]}),s.jsx("p",{className:"typography-ui-compact text-muted-foreground mt-0.5",children:Cu.find(he=>he.id===B)?.description})]}),s.jsx(sC,{modelId:B})]})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.voice.page.section.playbackAndSummary")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":C,onClick:()=>X(!C),onKeyDown:he=>{(he.key===" "||he.key==="Enter")&&(he.preventDefault(),X(!C))},children:[s.jsx(xs,{checked:C,onChange:X,ariaLabel:t("settings.voice.page.field.messageReadAloudButtonAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.messageReadAloudButton")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":q,onClick:()=>te(!q),onKeyDown:he=>{(he.key===" "||he.key==="Enter")&&(he.preventDefault(),te(!q))},children:[s.jsx(xs,{checked:q,onChange:te,ariaLabel:t("settings.voice.page.field.summarizeBeforePlaybackAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.summarizeBeforePlayback")})]}),F&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":U,onClick:()=>ae(!U),onKeyDown:he=>{(he.key===" "||he.key==="Enter")&&(he.preventDefault(),ae(!U))},children:[s.jsx(xs,{checked:U,onChange:ae,ariaLabel:t("settings.voice.page.field.summarizeVoiceModeResponsesAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.summarizeVoiceModeResponses")})]}),(q||U)&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:t("settings.voice.page.field.summarizationThreshold")}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[!e&&s.jsx("input",{type:"range",min:50,max:2e3,step:50,value:je,onChange:he=>oe(Number(he.target.value)),className:Re}),s.jsx(xn,{value:je,onValueChange:oe,min:50,max:2e3,step:50,className:"w-16 tabular-nums"})]})]}),s.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:t("settings.voice.page.field.summaryMaxLength")}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[!e&&s.jsx("input",{type:"range",min:50,max:2e3,step:50,value:ve,onChange:he=>K(Number(he.target.value)),className:Re}),s.jsx(xn,{value:ve,onValueChange:K,min:50,max:2e3,step:50,className:"w-16 tabular-nums"})]})]})]})]}),F&&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 aC(){Mi.onModelStatusChange=null}const Pc=[{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}],Ac=[{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}],iC="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/get-started/create-remote-tunnel/",oC="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/do-more-with-tunnels/local-management/configuration-file/",Mp=[{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"}],lC=[".yml",".yaml",".json"],cC="settings.openchamber.tunnel.error.invalidConfigExtension",Di=t=>{const e=t.trim().toLowerCase();return lC.some(n=>e.endsWith(n))},mg=t=>t==="cloudflare"?"Cloudflare":t,Ep=t=>{const e=at.c(11),{provider:n}=t;let r;e[0]!==n?(r=mg(n),e[0]=n,e[1]=r):r=e[1];const a=r,o=n==="cloudflare"?"text-[var(--status-warning)]":"text-muted-foreground";let c;e[2]!==o?(c=me("size-4 shrink-0",o),e[2]=o,e[3]=c):c=e[3];let d;e[4]!==c?(d=s.jsx(I,{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},pa=t=>t==="quick"?"quick":t==="managed-remote"?"managed-remote":t==="managed-local"?"managed-local":"quick",Rp=(t,e,n)=>t.find(a=>a.ms===e)?.value||n,Fp=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`},dC=t=>new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"}),Ho=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()}},uC=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=Ho(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},mC=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2,10)}`,pC=()=>{const{t}=pt(),e=l.useCallback(ye=>t(ye),[t]),[n,r]=l.useState("checking"),[a,i]=l.useState(null),[o,c]=l.useState(null),[d,p]=l.useState(null),[m,u]=l.useState(null),[h,b]=l.useState(null),[f,v]=l.useState(!1),[x,g]=l.useState(!1),[w,y]=l.useState(!1),[k,D]=l.useState("cloudflare"),[j,S]=l.useState([]),[A,E]=l.useState("quick"),[P,C]=l.useState(null),[N,T]=l.useState([]),[M,R]=l.useState({}),[L,$]=l.useState(""),[B,O]=l.useState({}),[_,ee]=l.useState(new Set),[z,ne]=l.useState(!1),[re,ue]=l.useState(""),[Q,de]=l.useState(""),[X,F]=l.useState(""),[V,q]=l.useState(1800*1e3),[te,U]=l.useState(480*60*1e3),[ae,je]=l.useState(""),[oe,ve]=l.useState([]),[K,ce]=l.useState(()=>Date.now()),[Z,le]=l.useState(null),se=t(cC),Ie=l.useRef(null),Ne=l.useMemo(()=>P?!Di(P):!1,[P]),Y=l.useMemo(()=>N.find(ye=>ye.id===L)||N[0]||null,[N,L]),fe=l.useMemo(()=>oe.map(ye=>{const Je=ye.expiresAt<=K,_e=ye.status==="active"&&!Je,Ue=_e?Fp(ye.expiresAt-K):ye.inactiveReason==="expired"||Je?"expired":"inactive",ot=Ue==="expired"?t("settings.openchamber.tunnel.state.expired"):ye.inactiveReason==="tunnel-revoked"?t("settings.openchamber.tunnel.state.revoked"):t("settings.openchamber.tunnel.state.inactive"),Xe=pa(ye.mode);return{...ye,isActive:_e,mode:Xe,remainingTextForSession:Ue,inactiveLabel:ot}}),[K,oe,t]),ke=l.useMemo(()=>a?.connectUrl?a.bootstrapExpiresAt===null?!0:a.bootstrapExpiresAt>K:!1,[K,a?.bootstrapExpiresAt,a?.connectUrl]),be=l.useMemo(()=>!a||n!=="active"&&n!=="stopping"?!1:o===A,[o,n,a,A]),pe=l.useMemo(()=>!a||n!=="active"||!o?!1:o!==A,[o,n,a,A]),Ee=l.useMemo(()=>{if(typeof Z=="number"&&Number.isFinite(Z)&&Z>0)return Z;if(typeof window>"u")return null;const ye=Number(window.location.port);return Number.isFinite(ye)&&ye>0?ye:null},[Z]),ze=l.useCallback(async ye=>{await Xn(ye)},[]),G=l.useCallback(async ye=>{try{const[Je,_e,Ue,ot]=await Promise.all([fetch("/api/openchamber/tunnel/check",{signal:ye}),fetch("/api/openchamber/tunnel/status",{signal:ye}),fetch("/api/config/settings",{signal:ye,headers:{Accept:"application/json"}}),fetch("/api/openchamber/tunnel/providers",{signal:ye})]),Xe=await Je.json(),We=await _e.json(),bt=Ue.ok?await Ue.json():{},Dt=ot.ok?await ot.json():{},Ht=We.ttlConfig?.bootstrapTtlMs??(bt?.tunnelBootstrapTtlMs===null?null:typeof bt?.tunnelBootstrapTtlMs=="number"?bt.tunnelBootstrapTtlMs:1800*1e3),rs=typeof We.ttlConfig?.sessionTtlMs=="number"?We.ttlConfig.sessionTtlMs:typeof bt?.tunnelSessionTtlMs=="number"?bt.tunnelSessionTtlMs:480*60*1e3,jt=pa(We.mode??bt?.tunnelMode),St=typeof bt?.tunnelProvider=="string"&&bt.tunnelProvider.trim().length>0?bt.tunnelProvider.trim().toLowerCase():"cloudflare",ns=typeof bt?.managedLocalTunnelConfigPath=="string"&&bt.managedLocalTunnelConfigPath.trim()||null,ut=uC(We?.managedRemoteTunnelPresets),Gt=typeof We.managedRemoteTunnelHostname=="string"?We.managedRemoteTunnelHostname:"",Xt=ut.length>0?ut:Gt?[{id:`legacy-${Ho(Gt)}`,name:Gt,hostname:Ho(Gt)}]:[],Wt=Xt[0]?.id||"";if(q(Ht),U(rs),D(St),S(Array.isArray(Dt?.providers)?Dt.providers:[]),E(jt),C(ns),T(Xt),$(Wt),ve(Array.isArray(We.activeSessions)?We.activeSessions:[]),c(We.activeTunnelMode?pa(We.activeTunnelMode):We.active&&We.mode?pa(We.mode):null),ee(new Set(Array.isArray(We.managedRemoteTunnelTokenPresetIds)?We.managedRemoteTunnelTokenPresetIds:[])),le(typeof We.localPort=="number"?We.localPort:null),We.active&&We.url){i({url:We.url,connectUrl:null,bootstrapExpiresAt:typeof We.bootstrapExpiresAt=="number"?We.bootstrapExpiresAt:null}),r("active");return}r(Xe.available?"idle":"not-available")}catch{ye.aborted||(r("error"),u(t("settings.openchamber.tunnel.toast.checkAvailabilityFailed")))}},[t]);l.useEffect(()=>{const ye=new AbortController;return G(ye.signal),()=>ye.abort()},[G]),l.useEffect(()=>{if(!a?.connectUrl){p(null);return}let ye=!1;return fx.toDataURL(a.connectUrl,{width:256,margin:2,color:{dark:"#000000",light:"#ffffff"}}).then(Je=>{ye||p(Je)}).catch(()=>{ye||p(null)}),()=>{ye=!0}},[a?.connectUrl]),l.useEffect(()=>{if(!a?.bootstrapExpiresAt){je(t("settings.openchamber.tunnel.state.noExpiry"));return}let ye=null,Je=Date.now();const _e=()=>{const Xe=a.bootstrapExpiresAt?a.bootstrapExpiresAt-Date.now():0;Xe<=0?je(t("settings.openchamber.tunnel.state.expired")):je(Fp(Xe))},Ue=()=>{const Xe=Date.now();Xe-Je>=1e3&&(_e(),Je=Xe),ye=requestAnimationFrame(Ue)};_e(),(typeof document>"u"||document.visibilityState==="visible")&&(ye=requestAnimationFrame(Ue));const ot=()=>{document.visibilityState==="visible"&&ye===null?ye=requestAnimationFrame(Ue):document.visibilityState!=="visible"&&ye!==null&&(cancelAnimationFrame(ye),ye=null)};return document.addEventListener("visibilitychange",ot),()=>{document.removeEventListener("visibilitychange",ot),ye!==null&&cancelAnimationFrame(ye)}},[t,a?.bootstrapExpiresAt]),l.useEffect(()=>{let ye=null,Je=Date.now();const _e=()=>{const ot=Date.now();ot-Je>=1e3&&(ce(ot),Je=ot),ye=requestAnimationFrame(_e)};(typeof document>"u"||document.visibilityState==="visible")&&(ye=requestAnimationFrame(_e));const Ue=()=>{document.visibilityState==="visible"&&ye===null?ye=requestAnimationFrame(_e):document.visibilityState!=="visible"&&ye!==null&&(cancelAnimationFrame(ye),ye=null)};return document.addEventListener("visibilitychange",Ue),()=>{document.removeEventListener("visibilitychange",Ue),ye!==null&&cancelAnimationFrame(ye)}},[]),l.useEffect(()=>{if(n==="starting"||n==="stopping"||n==="checking")return;let ye=!1;const Je=async()=>{try{const Ue=await fetch("/api/openchamber/tunnel/status");if(!Ue.ok||ye)return;const ot=await Ue.json();if(ye)return;ve(Array.isArray(ot.activeSessions)?ot.activeSessions:[]),ee(new Set(Array.isArray(ot.managedRemoteTunnelTokenPresetIds)?ot.managedRemoteTunnelTokenPresetIds:[])),le(typeof ot.localPort=="number"?ot.localPort:null)}catch{}},_e=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||Je()},5e3);return()=>{ye=!0,window.clearInterval(_e)}},[n]);const Pe=l.useCallback(async ye=>{y(!0);try{await Ds(ye),Object.prototype.hasOwnProperty.call(ye,"tunnelMode")&&ye.tunnelMode&&E(ye.tunnelMode),Object.prototype.hasOwnProperty.call(ye,"tunnelProvider")&&typeof ye.tunnelProvider=="string"&&D(ye.tunnelProvider),Object.prototype.hasOwnProperty.call(ye,"managedLocalTunnelConfigPath")&&C(ye.managedLocalTunnelConfigPath??null),Object.prototype.hasOwnProperty.call(ye,"managedRemoteTunnelPresets")&&ye.managedRemoteTunnelPresets&&T(ye.managedRemoteTunnelPresets)}catch{H.error(t("settings.openchamber.tunnel.toast.saveSettingsFailed"))}finally{y(!1)}},[t]),Le=l.useCallback(async(ye,Je)=>{g(!0);try{await Ds({tunnelBootstrapTtlMs:ye,tunnelSessionTtlMs:Je})}catch{H.error(t("settings.openchamber.tunnel.toast.saveTtlFailed"))}finally{g(!1)}},[t]),Ae=l.useCallback(async ye=>{const Je=ye.token.trim();if(Je)try{const _e={...B,[ye.presetId]:Je};await Ds({managedRemoteTunnelPresetTokens:_e}),ee(Ue=>{const ot=new Set(Ue);return ot.add(ye.presetId),ot})}catch{H.error(t("settings.openchamber.tunnel.toast.saveTokenFailed"))}},[B,t]),ge=l.useCallback(async ye=>{b(null),u(null),await Pe({tunnelProvider:ye})},[Pe]),W=l.useCallback(async()=>{const ye=await Gb({filters:[{name:"Config",extensions:["yml","yaml","json"]}]});if(ye.success&&typeof ye.path=="string"&&ye.path.trim().length>0){const Je=ye.path.trim();if(!Di(Je)){H.error(se);return}C(Je),await Pe({managedLocalTunnelConfigPath:Je});return}Ie.current?.click()},[se,Pe]),ie=l.useCallback(ye=>{const Je=ye.trim();C(Je.length>0?Je:null)},[]),Me=l.useCallback(async()=>{if(P&&!Di(P)){H.error(se);return}await Pe({managedLocalTunnelConfigPath:P})},[se,P,Pe]),Ve=l.useCallback(async()=>{C(null),await Pe({managedLocalTunnelConfigPath:null})},[Pe]),Ce=l.useCallback(async ye=>{const Je=ye.target.files?.[0];if(!Je)return;const _e=Je.name.trim();if(_e.length!==0){if(!Di(_e)){H.error(se);return}C(_e),await Pe({managedLocalTunnelConfigPath:_e}),ye.target.value=""}},[se,Pe]),xe=l.useCallback(async()=>{if(u(null),b(null),A==="managed-local"&&P&&!Di(P)){u(se),H.error(se);return}r("starting");try{let ye="",Je="";if(A==="managed-remote"){if(!Y){r("idle"),b(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst")),H.error(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst"));return}ye=Y.hostname,Je=(B[Y.id]||"").trim(),await Pe({tunnelMode:"managed-remote",managedRemoteTunnelPresets:N})}const _e=await fetch("/api/openchamber/tunnel/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:k,mode:A,...A==="managed-remote"&&Y?{managedRemoteTunnelPresetId:Y.id,managedRemoteTunnelPresetName:Y.name}:{},...A==="managed-remote"&&ye?{managedRemoteTunnelHostname:ye}:{},...A==="managed-remote"&&Je?{managedRemoteTunnelToken:Je}:{},...A==="managed-local"&&P?{configPath:P}:{}})}),Ue=await _e.json();if(!_e.ok||!Ue.ok){if(A==="managed-remote"&&typeof Ue.error=="string"&&Ue.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(Ue.error||t("settings.openchamber.tunnel.toast.startFailed")),H.error(Ue.error||t("settings.openchamber.tunnel.toast.startFailed"));return}const ot=typeof Ue.url=="string"?Ue.url:"";if(!ot){r("error"),u(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl")),H.error(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl"));return}if(i({url:ot,connectUrl:typeof Ue.connectUrl=="string"?Ue.connectUrl:null,bootstrapExpiresAt:typeof Ue.bootstrapExpiresAt=="number"?Ue.bootstrapExpiresAt:null}),c(Ue.activeTunnelMode?pa(Ue.activeTunnelMode):Ue.mode?pa(Ue.mode):A),ve(Array.isArray(Ue.activeSessions)?Ue.activeSessions:[]),Array.isArray(Ue.managedRemoteTunnelTokenPresetIds)&&ee(new Set(Ue.managedRemoteTunnelTokenPresetIds)),typeof Ue.localPort=="number"&&le(Ue.localPort),typeof Ue.mode=="string"&&E(pa(Ue.mode)),r("active"),Ue.replacedTunnel){const Xe=typeof Ue.revokedBootstrapCount=="number"?Ue.revokedBootstrapCount:0,We=typeof Ue.invalidatedSessionCount=="number"?Ue.invalidatedSessionCount:0;Xe===1&&We===1?H.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleSingle")):Xe===1?H.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleManySessions",{invalidatedSessionCount:We})):We===1?H.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyLinksSingleSession",{revokedBootstrapCount:Xe})):H.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyMany",{revokedBootstrapCount:Xe,invalidatedSessionCount:We}))}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"))}},[se,N,Pe,Y,B,t,k,A,P]),De=l.useCallback(async()=>{r("stopping");try{await fetch("/api/openchamber/tunnel/stop",{method:"POST"});const ye=await fetch("/api/openchamber/tunnel/status");if(ye.ok){const Je=await ye.json();ve(Array.isArray(Je.activeSessions)?Je.activeSessions:[]),ee(new Set(Array.isArray(Je.managedRemoteTunnelTokenPresetIds)?Je.managedRemoteTunnelTokenPresetIds:[])),le(typeof Je.localPort=="number"?Je.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]),Ye=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]),rt=l.useCallback(async ye=>{const Je=Pc.find(_e=>_e.value===ye);Je&&(q(Je.ms),await Le(Je.ms,te))},[Le,te]),Re=l.useCallback(async ye=>{const Je=Ac.find(_e=>_e.value===ye);!Je||Je.ms===null||(U(Je.ms),await Le(V,Je.ms))},[V,Le]),he=l.useCallback(async ye=>{b(null),u(null),n!=="active"&&n!=="stopping"&&n!=="starting"&&r("idle"),await Pe({tunnelMode:ye,managedRemoteTunnelPresets:N})},[N,Pe,n]),qe=l.useCallback(async(ye,Je)=>{try{await Ds({managedRemoteTunnelPresets:Je})}catch{H.error(t("settings.openchamber.tunnel.toast.saveSelectedManagedRemoteFailed"))}},[t]),et=l.useCallback(ye=>{const Je=N.find(_e=>_e.id===ye);Je&&($(Je.id),b(null),qe(Je,N))},[N,qe]),Ke=l.useCallback(async()=>{const ye=re.trim(),Je=Ho(Q),_e=X.trim();if(!ye){H.error(t("settings.openchamber.tunnel.toast.tunnelNameRequired"));return}if(!Je){H.error(t("settings.openchamber.tunnel.toast.managedRemoteHostnameRequired"));return}if(!_e){H.error(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequired"));return}if(N.some(Xe=>Xe.hostname===Je)){H.error(t("settings.openchamber.tunnel.toast.hostnameAlreadyExists"));return}const Ue={id:mC(),name:ye,hostname:Je},ot=[...N,Ue];T(ot),$(Ue.id),R(Xe=>({...Xe,[Ue.id]:!0})),O(Xe=>({...Xe,[Ue.id]:_e})),b(null),ne(!1),ue(""),de(""),F(""),await Pe({tunnelMode:"managed-remote",managedRemoteTunnelPresets:ot,managedRemoteTunnelPresetTokens:{...B,[Ue.id]:_e}}),await Ae({presetId:Ue.id,presetName:Ue.name,hostname:Ue.hostname,token:_e}),H.success(t("settings.openchamber.tunnel.toast.managedRemoteSaved"))},[N,Q,re,X,Ae,Pe,B,t]),st=l.useCallback(async ye=>{const Je=N.find(We=>We.id===ye);if(!Je)return;const _e=N.filter(We=>We.id!==Je.id),Ue=_e[0]?.id||"",ot=L===Je.id?Ue:L,Xe=Object.fromEntries(Object.entries(B).filter(([We,bt])=>We!==Je.id&&bt.trim().length>0));T(_e),$(ot),R(We=>{const bt={...We};return delete bt[Je.id],bt}),O(We=>{const bt={...We};return delete bt[Je.id],bt}),ee(We=>{const bt=new Set(We);return bt.delete(Je.id),bt}),b(null),await Pe({managedRemoteTunnelPresets:_e,managedRemoteTunnelPresetTokens:Xe}),H.success(t("settings.openchamber.tunnel.toast.managedRemoteRemoved"))},[N,Pe,L,B,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")})]}),fe.length>0&&s.jsx("section",{className:"space-y-2 px-2 pb-2 pt-0",children:s.jsxs("div",{className:"rounded-lg border border-[var(--status-info-border)] bg-[var(--status-info-background)]/30 p-3",children:[s.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[s.jsx(I,{name:"information",className:"size-4 text-[var(--status-info)]"}),s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.tunnel.section.redeemedAccessLinks")})]}),s.jsx("div",{className:"space-y-1",children:fe.map(ye=>{const Je=ye.mode==="quick",_e=ye.mode==="managed-remote",Ue=Je?"border-[var(--status-warning-border)] bg-[var(--status-warning-background)] text-[var(--status-warning)]":_e?"border-[var(--status-info-border)] bg-[var(--status-info-background)] text-[var(--status-info)]":"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",ot=ye.isActive?Je?"text-[var(--status-warning)]":_e?"text-[var(--status-info)]":"text-[var(--status-success)]":"text-muted-foreground/50",Xe=t(Je?"settings.openchamber.tunnel.badge.quick":_e?"settings.openchamber.tunnel.badge.remote":"settings.openchamber.tunnel.badge.local");return s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 rounded border border-[var(--surface-subtle)] bg-[var(--surface-elevated)] px-2 py-1.5",children:[s.jsx(I,{name:"checkbox-blank-circle-fill",className:me("size-2.5 shrink-0",ot)}),s.jsx("span",{className:me("typography-micro rounded border px-1.5 py-0.5 uppercase",Ue),children:Xe}),s.jsx("span",{className:"typography-meta text-muted-foreground/80",children:t("settings.openchamber.tunnel.session.redeemedAt",{time:dC(ye.createdAt)})}),s.jsx("span",{className:"typography-meta text-foreground",children:ye.isActive?t("settings.openchamber.tunnel.session.expiresIn",{remaining:ye.remainingTextForSession}):ye.inactiveLabel===t("settings.openchamber.tunnel.state.inactive")?t("settings.openchamber.tunnel.state.inactive"):t("settings.openchamber.tunnel.session.inactiveWithReason",{reason:ye.inactiveLabel})})]},ye.sessionId)})})]})}),n==="not-available"&&s.jsx("section",{className:"space-y-2 px-2 pb-2 pt-0",children:s.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-[var(--status-warning)]/30 bg-[var(--status-warning)]/5 p-3",children:[s.jsx(I,{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(ds,{value:k,onValueChange:ye=>{ge(ye)},disabled:w||n==="starting"||n==="stopping",children:[s.jsx(us,{className:"max-w-[16rem]",children:s.jsx(ys,{placeholder:t("settings.openchamber.tunnel.field.providerPlaceholder"),children:mg(k)})}),s.jsxs(ms,{children:[j.length>0?j.map(ye=>s.jsx(Lt,{value:ye.provider,children:s.jsx(Ep,{provider:ye.provider})},ye.provider)):s.jsx(Lt,{value:"cloudflare",children:s.jsx(Ep,{provider:"cloudflare"})}),s.jsx(Lt,{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:Mp.map(ye=>s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(we,{variant:"chip",size:"xs","aria-pressed":A===ye.value,className:"!font-normal",onClick:()=>{he(ye.value)},disabled:w||n==="starting"||n==="stopping",children:e(ye.labelKey)})}),s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:e(ye.tooltipKey)})]},ye.value))})]})]}),s.jsxs("div",{className:"mt-2 grid grid-cols-1 gap-2 py-1.5 md:grid-cols-[14rem_auto] md:gap-x-8 md:gap-y-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label shrink-0 text-foreground",children:t("settings.openchamber.tunnel.field.connectLinkTtl")}),s.jsxs(ds,{value:Rp(Pc,V,"1800000"),onValueChange:ye=>{rt(ye)},disabled:x||w||n==="starting"||n==="stopping",children:[s.jsx(us,{className:"max-w-[11rem] min-w-0",children:s.jsx(ys,{className:"truncate"})}),s.jsx(ms,{children:Pc.map(ye=>s.jsx(Lt,{value:ye.value,children:ye.label},ye.value))})]})]}),s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label shrink-0 text-foreground",children:t("settings.openchamber.tunnel.field.tunnelSessionTtl")}),s.jsxs(ds,{value:Rp(Ac,te,"28800000"),onValueChange:ye=>{Re(ye)},disabled:x||w||n==="starting"||n==="stopping",children:[s.jsx(us,{className:"max-w-[11rem] min-w-0",children:s.jsx(ys,{className:"truncate"})}),s.jsx(ms,{children:Ac.map(ye=>s.jsx(Lt,{value:ye.value,children:ye.label},ye.value))})]})]})]}),A==="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(I,{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")})]})]})}),A==="managed-remote"&&s.jsxs("div",{className:"space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:[typeof Ee=="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:",Ee]})]})}),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(we,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>ne(ye=>!ye),disabled:n==="starting"||n==="stopping"||w,children:[s.jsx(I,{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((ye,Je)=>{const _e=B[ye.id]||"",Ue=_.has(ye.id),ot=M[ye.id]??!1;return s.jsx("div",{className:me(Je<N.length-1&&"border-b border-[var(--surface-subtle)]"),children:s.jsxs(ur,{open:ot,onOpenChange:Xe=>{R(We=>({...We,[ye.id]:Xe})),Xe&&et(ye.id)},className:"py-1.5",children:[s.jsxs("div",{className:"flex items-start gap-2 px-3",children:[s.jsxs(wr,{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:[ot?s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(I,{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:ye.name})]}),s.jsx(we,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:text-[var(--status-error)]","aria-label":t("settings.openchamber.tunnel.actions.removePresetAria",{name:ye.name}),onClick:()=>{st(ye.id)},disabled:n==="starting"||n==="stopping"||w,children:s.jsx(I,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),s.jsx(mr,{className:"pt-1.5",children:s.jsxs("div",{className:"space-y-1 px-3 pb-2",children:[s.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[t("settings.openchamber.tunnel.field.hostnameLabel")," ",s.jsx("code",{children:ye.hostname})]}),s.jsx(Kt,{type:"password",value:_e,onChange:Xe=>{const We=Xe.target.value;b(null),O(bt=>({...bt,[ye.id]:We}))},onBlur:Xe=>{const We=Xe.currentTarget.value.trim();We&&Ae({presetId:ye.id,presetName:ye.name,hostname:ye.hostname,token:We})},placeholder:t(Ue?"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(we,{variant:"ghost",size:"xs",className:"!font-normal",disabled:n==="starting"||n==="stopping"||_e.trim().length===0,onClick:()=>{Ae({presetId:ye.id,presetName:ye.name,hostname:ye.hostname,token:_e})},children:t("settings.openchamber.tunnel.actions.saveToken")})})]})})]})},ye.id)})}):s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.openchamber.tunnel.empty.noManagedRemoteTunnels")}),z&&s.jsxs("div",{className:"space-y-2 rounded-md border border-[var(--surface-subtle)] p-2",children:[s.jsx(Kt,{value:re,onChange:ye=>ue(ye.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetNamePlaceholder"),className:"h-7",disabled:w||n==="starting"||n==="stopping"}),s.jsx(Kt,{value:Q,onChange:ye=>de(ye.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetHostnamePlaceholder"),className:"h-7",disabled:w||n==="starting"||n==="stopping"}),s.jsx(Kt,{type:"password",value:X,onChange:ye=>F(ye.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetTokenPlaceholder"),className:"h-7",disabled:w||n==="starting"||n==="stopping"}),typeof Ee=="number"&&s.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[t("settings.openchamber.tunnel.note.cloudflareConnectorTargetUse")," ",s.jsxs("code",{children:["http://localhost:",Ee]}),"."]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(we,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Ke()},disabled:w||n==="starting"||n==="stopping",children:t("settings.common.actions.saveChanges")}),s.jsx(we,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{ne(!1),ue(""),de(""),F("")},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(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",className:"rounded p-0.5 text-muted-foreground/70 hover:text-foreground","aria-label":t("settings.openchamber.tunnel.field.managedRemoteTokenInfoAria"),children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5"})})}),s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:t("settings.openchamber.tunnel.tooltip.tokensSavedPath")})]})]}),!Y&&h&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:h})]}),A==="managed-local"&&s.jsx("div",{className:"space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.tunnel.field.configurationFile")}),s.jsx("input",{ref:Ie,type:"file",accept:".yml,.yaml,.json",className:"hidden",onChange:ye=>{Ce(ye)}}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Kt,{value:P||"",onChange:ye=>{ie(ye.target.value)},onBlur:()=>{Me()},placeholder:t("settings.openchamber.tunnel.field.configurationFilePlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"||w}),s.jsx(we,{variant:"outline",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.browseConfigFileAria"),onClick:()=>{W()},disabled:n==="starting"||n==="stopping"||w,children:s.jsx(I,{name:"folder",className:"size-3.5"})}),P&&s.jsx(we,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.clearConfigFileAria"),onClick:()=>{Ve()},disabled:n==="starting"||n==="stopping"||w,children:s.jsx(I,{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")}),Ne&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:se})]})}),!be&&s.jsxs("div",{className:"space-y-6",children:[s.jsx("div",{className:"rounded-lg border border-[var(--status-info-border)] bg-[var(--status-info-background)] p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(I,{name:"information",className:"mt-0.5 size-4 shrink-0 text-[var(--status-info)]"}),s.jsxs("div",{className:"space-y-1",children:[A==="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:()=>{ze(iC)},children:[t("settings.openchamber.tunnel.actions.openManagedRemoteDocs"),s.jsx(I,{name:"external-link",className:"size-3.5"})]})]}),A==="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:()=>{ze(oC)},children:[t("settings.openchamber.tunnel.actions.openManagedLocalDocs"),s.jsx(I,{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(Mp.find(ye=>ye.value===A)?.labelKey??"settings.openchamber.tunnel.option.mode.quick.label")})})]})]})}),A==="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(ds,{value:L||(N[0]?.id??""),onValueChange:ye=>{et(ye)},disabled:w||n==="starting"||n==="stopping"||N.length<=1,children:[s.jsx(us,{children:s.jsx(ys,{placeholder:t("settings.openchamber.tunnel.field.selectSavedTunnelPlaceholder"),children:Y?.name})}),s.jsx(ms,{fitContent:!0,children:N.map(ye=>s.jsx(Lt,{value:ye.id,children:ye.name},ye.id))})]})]}),pe&&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(I,{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(we,{size:"sm",variant:"outline",onClick:xe,disabled:n==="starting"||w||A==="managed-remote"&&!Y||A==="managed-local"&&Ne,className:me(nt,n==="starting"&&"opacity-70"),children:n==="starting"?s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.openchamber.tunnel.actions.startingTunnel")]}):t("settings.openchamber.tunnel.actions.startTunnel")})]})]}),be&&a&&s.jsxs("section",{className:"space-y-4 px-2 pb-2 pt-0",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("div",{className:"size-2 shrink-0 rounded-full bg-[var(--status-success)]"}),s.jsx("p",{className:"typography-meta font-medium text-foreground",children:t("settings.openchamber.tunnel.state.tunnelReady")})]}),s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta mb-1 text-muted-foreground/70",children:t("settings.openchamber.tunnel.field.publicUrlHint")}),s.jsx("code",{className:"typography-code block truncate rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:a.url})]}),ke&&a.connectUrl&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta mb-1 text-muted-foreground/70",children:t("settings.openchamber.tunnel.field.connectLink")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("code",{className:"typography-code flex-1 truncate rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:a.connectUrl}),s.jsxs(we,{size:"sm",variant:"ghost",onClick:Ye,className:"shrink-0 gap-1.5",children:[f?s.jsx(I,{name:"check",className:"size-3.5 text-[var(--status-success)]"}):s.jsx(I,{name:"file-copy",className:"size-3.5"}),t(f?"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?ae: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(we,{size:"sm",variant:"outline",onClick:xe,disabled:n==="stopping"||w||A==="managed-local"&&Ne,className:nt,children:[s.jsx(I,{name:"restart",className:"size-3.5"}),t("settings.openchamber.tunnel.actions.newConnectLink")]}),s.jsx(we,{size:"sm",variant:"ghost",onClick:De,disabled:n==="stopping"||w,className:"gap-2 text-[var(--status-error)]",children:n==="stopping"?s.jsxs(s.Fragment,{children:[s.jsx(I,{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(we,{size:"sm",variant:"ghost",onClick:xe,children:t("settings.openchamber.tunnel.actions.retry")})]})]})},pg=()=>{const{t}=pt(),[e,n]=Be.useState(""),[r,a]=Be.useState(!0),[i,o]=Be.useState(!1),c=Te(u=>u.showOpenCodeUpdateNotifications),d=Te(u=>u.setShowOpenCodeUpdateNotifications);Be.useEffect(()=>{let u=!1;return(async()=>{try{const h=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!h.ok)return;const b=await h.json().catch(()=>null);if(u||!b)return;const f=typeof b.opencodeBinary=="string"?b.opencodeBinary.trim():"";n(f)}catch{}finally{u||a(!1)}})(),()=>{u=!0}},[]);const p=Be.useCallback(async()=>{if(typeof window>"u"||!yn()||!Ia())return;const u=window.__TAURI__;if(u?.dialog?.open)try{const h=await u.dialog.open({title:t("settings.openchamber.opencodeCli.dialog.selectBinaryTitle"),multiple:!1,directory:!1});typeof h=="string"&&h.trim().length>0&&n(h.trim())}catch{}},[t]),m=Be.useCallback(async()=>{o(!0);try{await Ds({opencodeBinary:e.trim()}),await si({message:t("settings.openchamber.opencodeCli.actions.restartingOpenCode"),mode:"projects",scopes:["all"]})}finally{o(!1)}},[t,e]);return s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.openchamber.opencodeCli.title")}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsxs(Pt,{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(Kt,{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(we,{type:"button",variant:"outline",size:"xs",onClick:p,disabled:r||i||!yn()||!Ia(),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(I,{name:"folder",className:"h-4 w-4"})})]})]}),s.jsx("div",{className:"py-1.5",children:s.jsxs("div",{className:"typography-micro text-muted-foreground/70",children:[t("settings.openchamber.opencodeCli.tipPrefix")," ",s.jsx("span",{className:"font-mono",children:"OPENCODE_BINARY"})," ",t("settings.openchamber.opencodeCli.tipMiddle")," ",s.jsx("span",{className:"font-mono",children:"~/.config/openchamber/settings.json"}),"."]})}),s.jsxs("label",{className:"flex cursor-pointer items-center gap-2 py-1.5",children:[s.jsx(xs,{checked:c,onChange:d,ariaLabel:t("settings.openchamber.opencodeCli.field.showUpdateNotificationsAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.opencodeCli.field.showUpdateNotifications")})]}),s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(we,{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")})})]})]})},hg=()=>{const{t}=pt(),e=yn()&&Vr(),[n,r]=Be.useState(!1),[a,i]=Be.useState(!1),[o,c]=Be.useState(!0),[d,p]=Be.useState(!1),[m,u]=Be.useState(null),[h,b]=Be.useState(null);Be.useEffect(()=>{if(!e){c(!1);return}let y=!1;return(async()=>{try{const k=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!k.ok)throw new Error(t("settings.openchamber.desktopNetwork.error.loadFailed"));const D=await k.json().catch(()=>null);if(y)return;const j=D?.desktopLanAccessEnabled===!0;r(j),i(j),u(null)}catch(k){y||u(k instanceof Error?k.message:t("settings.openchamber.desktopNetwork.error.loadFailed"))}finally{y||c(!1)}})(),()=>{y=!0}},[e,t]),Be.useEffect(()=>{if(!e||!a){b(null);return}let y=!1;return(async()=>{const k=await qb();y||b(k)})(),()=>{y=!0}},[a,e]);const f=a!==n,v=Be.useMemo(()=>{if(typeof window>"u")return null;const y=Number(window.location.port);return Number.isFinite(y)&&y>0?y:null},[]),x=a&&h&&v?`http://${h}:${v}`:null,g=Be.useCallback(()=>{i(y=>!y)},[]),w=Be.useCallback(async()=>{if(f){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 Kh())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,f,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(xs,{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(f&&!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(we,{type:"button",size:"xs",onClick:w,disabled:o||d||!f,className:"shrink-0 !font-normal",children:t(d?"settings.common.actions.saving":"settings.openchamber.desktopNetwork.actions.saveAndRestart")})})]})]}):null},hC=new Set(["shift","control","alt","meta"]),fC=t=>{if(hC.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=Qb(t.key);return n?(e.push(n),Qa(e.join("+"))):null},gC=()=>{const t=at.c(58),{t:e}=pt();let n;t[0]!==e?(n=X=>e(X),t[0]=e,t[1]=n):n=t[1];const r=n,a=Te(xC),i=Te(bC),o=Te(yC),c=Te(vC);let d;t[2]===Symbol.for("react.memo_cache_sentinel")?(d=Jb(),t[2]=d):d=t[2];const p=d;let m;t[3]!==r?(m=(X,F)=>{const V=`settings.openchamber.keyboardShortcuts.action.${X}.label`,q=r(V);return q===V?F:q},t[3]=r,t[4]=m):m=t[4];const u=m,[h,b]=l.useState(null);let f;t[5]===Symbol.for("react.memo_cache_sentinel")?(f={},t[5]=f):f=t[5];const[v,x]=l.useState(f),[g,w]=l.useState(""),[y,k]=l.useState(""),[D,j]=l.useState(null);let S;t[6]!==a?(S=(X,F)=>{const V=Qa(F);for(const q of p){if(q.id===X)continue;const te=Br(q.id,a);if(Qa(te)===V)return q.id}return null},t[6]=a,t[7]=S):S=t[7];const A=S;let E;t[8]!==A||t[9]!==i||t[10]!==e?(E=(X,F)=>{const V=Qa(F),q=A(X,V);if(q){j({actionId:X,combo:V,conflictActionId:q}),w("");return}i(X,V),j(null),w(""),k(Iu(V)?e("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut"):""),x(te=>{const U={...te};return delete U[X],U})},t[8]=A,t[9]=i,t[10]=e,t[11]=E):E=t[11];const P=E;let C;t[12]!==D||t[13]!==i||t[14]!==e?(C=()=>{D&&(i(D.conflictActionId,Yb),i(D.actionId,D.combo),j(null),w(""),k(Iu(D.combo)?e("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut"):""),x(X=>{const F={...X};return delete F[D.actionId],F}))},t[12]=D,t[13]=i,t[14]=e,t[15]=C):C=t[15];const N=C;let T;t[16]!==o?(T=X=>{o(X),x(F=>{const V={...F};return delete V[X],V}),j(null),w(""),k("")},t[16]=o,t[17]=T):T=t[17];const M=T;let R;t[18]!==e?(R=e("settings.openchamber.keyboardShortcuts.title"),t[18]=e,t[19]=R):R=t[19];let L;t[20]!==R?(L=s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:R}),t[20]=R,t[21]=L):L=t[21];let $;t[22]!==c?($=()=>{c(),x({}),j(null),w(""),k("")},t[22]=c,t[23]=$):$=t[23];let B;t[24]!==e?(B=e("settings.openchamber.keyboardShortcuts.actions.resetAll"),t[24]=e,t[25]=B):B=t[25];let O;t[26]!==$||t[27]!==B?(O=s.jsx(we,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:$,children:B}),t[26]=$,t[27]=B,t[28]=O):O=t[28];let _;t[29]===Symbol.for("react.memo_cache_sentinel")?(_=s.jsx(Ct,{asChild:!0,children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t[29]=_):_=t[29];let ee;t[30]!==e?(ee=e("settings.openchamber.keyboardShortcuts.tooltip"),t[30]=e,t[31]=ee):ee=t[31];let z;t[32]!==ee?(z=s.jsxs(kt,{children:[_,s.jsx(Pt,{sideOffset:8,className:"max-w-xs",children:ee})]}),t[32]=ee,t[33]=z):z=t[33];let ne;t[34]!==O||t[35]!==z||t[36]!==L?(ne=s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[L,O,z]})}),t[34]=O,t[35]=z,t[36]=L,t[37]=ne):ne=t[37];let re;t[38]!==N||t[39]!==g||t[40]!==D||t[41]!==e||t[42]!==y?(re=(g||y||D)&&s.jsxs("div",{className:"mb-2 space-y-2 px-1",children:[D&&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(we,{type:"button",size:"xs",className:"!font-normal",onClick:N,children:e("settings.openchamber.keyboardShortcuts.actions.overwrite")}),s.jsx(we,{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]=D,t[41]=e,t[42]=y,t[43]=re):re=t[43];let ue;t[44]!==u||t[45]!==h||t[46]!==v||t[47]!==M||t[48]!==P||t[49]!==a||t[50]!==e?(ue=p.map((X,F)=>{const V=Br(X.id,a),q=v[X.id],te=q??V,U=typeof q=="string"&&Qa(q)!==Qa(V);return s.jsxs("div",{className:me("flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",F>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(X.id,X.label)})}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:[s.jsx(Kt,{readOnly:!0,value:h===X.id?e("settings.openchamber.keyboardShortcuts.field.pressKeys"):jl(te),onFocus:()=>{b(X.id),w("")},onBlur:()=>{h===X.id&&b(null)},onKeyDown:ae=>{if(ae.preventDefault(),ae.stopPropagation(),ae.key==="Escape"){b(null);return}const je=fC(ae);je&&(x(oe=>({...oe,[X.id]:je})),b(null),j(null),w(""))},className:"h-7 w-40 min-w-0 typography-ui-label text-center"}),s.jsx(we,{type:"button",variant:"secondary",size:"xs",className:"!font-normal",onClick:()=>{const ae=v[X.id];if(!ae){w(e("settings.openchamber.keyboardShortcuts.error.captureFirst"));return}P(X.id,ae)},disabled:!U,children:e("settings.common.actions.saveChanges")}),s.jsx(we,{type:"button",size:"xs",className:"!font-normal",variant:"ghost",onClick:()=>M(X.id),children:e("settings.common.actions.reset")})]})]},X.id)}),t[44]=u,t[45]=h,t[46]=v,t[47]=M,t[48]=P,t[49]=a,t[50]=e,t[51]=ue):ue=t[51];let Q;t[52]!==ue?(Q=s.jsx("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:ue}),t[52]=ue,t[53]=Q):Q=t[53];let de;return t[54]!==ne||t[55]!==re||t[56]!==Q?(de=s.jsxs("div",{className:"mb-8",children:[ne,re,Q]}),t[54]=ne,t[55]=re,t[56]=Q,t[57]=de):de=t[57],de};function xC(t){return t.shortcutOverrides}function bC(t){return t.setShortcutOverride}function yC(t){return t.clearShortcutOverride}function vC(t){return t.resetAllShortcutOverrides}const wC=t=>{const e=at.c(20),{section:n}=t,{isMobile:r}=an();let a;e[0]!==r?(a=r&&sa(),e[0]=r,e[1]=a):a=e[1];const i=a;let o;e[2]===Symbol.for("react.memo_cache_sentinel")?(o=dn(),e[2]=o):o=e[2];const c=o;let d;e[3]===Symbol.for("react.memo_cache_sentinel")?(d=yn()&&Vr(),e[3]=d):d=e[3];const p=d;if(!n){let f;e[4]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx(Xd,{}),e[4]=f):f=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(ug,{})}),x=!c&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(pg,{})}),g=p&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(hg,{})}),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(cg,{})}),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(dg,{})}),e[9]=y):y=e[9];let k;e[10]!==i?(k=i&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(V5,{})}),e[10]=i,e[11]=k):k=e[11];let D;return e[12]!==k?(D=s.jsx(Ts,{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:[f,v,x,g,w,y,k]})}),e[12]=k,e[13]=D):D=e[13],D}let m;e[14]!==n?(m=()=>{switch(n){case"visual":return s.jsx(NC,{});case"chat":return s.jsx(SC,{});case"sessions":return s.jsx(kC,{});case"shortcuts":return s.jsx(jC,{});case"git":return s.jsx(CC,{});case"github":return s.jsx(IC,{});case"notifications":return s.jsx(PC,{});case"voice":return s.jsx(AC,{});case"tunnel":return s.jsx(DC,{});default:return null}},e[14]=n,e[15]=m):m=e[15];const u=m;let h;e[16]!==u?(h=u(),e[16]=u,e[17]=h):h=e[17];let b;return e[18]!==h?(b=s.jsx(Ts,{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:h})}),e[18]=h,e[19]=b):b=e[19],b},jC=()=>{const t=at.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(gC,{}),t[0]=e):e=t[0],e},NC=()=>{const t=at.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=dn(),t[0]=e):e=t[0];const n=e;let r;return t[1]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(Xd,{visibleSettings:["theme","pwaInstallName","pwaOrientation","mobileKeyboardMode","timeFormat","weekStart","fontSize","terminalFontSize","spacing","inputBarOffset",...n?[]:["terminalQuickKeys"],"reportUsage"]}),t[1]=r):r=t[1],r},SC=()=>{const t=at.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Xd,{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},kC=()=>{const t=at.c(7);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=dn(),t[0]=e):e=t[0];const n=e;let r;t[1]===Symbol.for("react.memo_cache_sentinel")?(r=yn()&&Vr(),t[1]=r):r=t[1];const a=r;let i,o,c;t[2]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx(ug,{}),o=!n&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(pg,{})}),c=a&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(hg,{})}),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(cg,{})}),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(dg,{})})]}),t[6]=p):p=t[6],p},CC=()=>{const t=at.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx("div",{className:"space-y-6",children:s.jsx(ag,{})}),t[0]=e):e=t[0],e},IC=()=>{const t=at.c(1);if(dn())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(ig,{}),t[0]=e):e=t[0],e},PC=()=>{const t=at.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(eC,{}),t[0]=e):e=t[0],e},AC=()=>{const t=at.c(1);if(dn())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(rC,{}),t[0]=e):e=t[0],e},DC=()=>{const t=at.c(1);if(dn())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(pC,{}),t[0]=e):e=t[0],e},gd=176,xd=280,Lp=8;function Dc(t){return Math.min(xd,Math.max(gd,t))}const TC=["appearance","chat","notifications","sessions","shortcuts","git","magic-prompts","projects","remote-instances","agents","behavior","commands","mcp","providers","usage","skills.installed","skills.catalog","voice","tunnel"];function MC(t){const e=dn(),n=!t&&sa();return{isVSCode:e,isWeb:n,isDesktop:t}}function Op(t,e){return t.isAvailable?t.isAvailable(e):!0}function Zd(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"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 Tc=t=>{const e=at.c(95),{onOpen:n}=t,{t:r}=pt();let a;e[0]!==r?(a=r("settings.view.home.title"),e[0]=r,e[1]=a):a=e[1];let i;e[2]!==a?(i=s.jsx("h1",{className:"typography-ui-header font-semibold text-foreground",children:a}),e[2]=a,e[3]=i):i=e[3];let o;e[4]!==r?(o=r("settings.view.home.description"),e[4]=r,e[5]=o):o=e[5];let c;e[6]!==o?(c=s.jsx("p",{className:"typography-ui text-muted-foreground",children:o}),e[6]=o,e[7]=c):c=e[7];let d;e[8]!==i||e[9]!==c?(d=s.jsxs("div",{className:"space-y-1",children:[i,c]}),e[8]=i,e[9]=c,e[10]=d):d=e[10];let p;e[11]!==n?(p=()=>n("providers"),e[11]=n,e[12]=p):p=e[12];let m;e[13]===Symbol.for("react.memo_cache_sentinel")?(m=me("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[13]=m):m=e[13];let u;e[14]!==r?(u=r("settings.view.home.cards.providers.title"),e[14]=r,e[15]=u):u=e[15];let h;e[16]!==u?(h=s.jsx("div",{className:"typography-ui-label text-foreground",children:u}),e[16]=u,e[17]=h):h=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 f;e[20]!==b?(f=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:b}),e[20]=b,e[21]=f):f=e[21];let v;e[22]!==f||e[23]!==p||e[24]!==h?(v=s.jsxs("button",{type:"button",onClick:p,className:m,children:[h,f]}),e[22]=f,e[23]=p,e[24]=h,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=me("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[28]=g):g=e[28];let w;e[29]!==r?(w=r("settings.view.home.cards.agents.title"),e[29]=r,e[30]=w):w=e[30];let 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 k;e[33]!==r?(k=r("settings.view.home.cards.agents.description"),e[33]=r,e[34]=k):k=e[34];let D;e[35]!==k?(D=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:k}),e[35]=k,e[36]=D):D=e[36];let j;e[37]!==x||e[38]!==y||e[39]!==D?(j=s.jsxs("button",{type:"button",onClick:x,className:g,children:[y,D]}),e[37]=x,e[38]=y,e[39]=D,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 A;e[43]===Symbol.for("react.memo_cache_sentinel")?(A=me("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[43]=A):A=e[43];let E;e[44]!==r?(E=r("settings.view.home.cards.skillsCatalog.title"),e[44]=r,e[45]=E):E=e[45];let P;e[46]!==E?(P=s.jsx("div",{className:"typography-ui-label text-foreground",children:E}),e[46]=E,e[47]=P):P=e[47];let C;e[48]!==r?(C=r("settings.view.home.cards.skillsCatalog.description"),e[48]=r,e[49]=C):C=e[49];let N;e[50]!==C?(N=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:C}),e[50]=C,e[51]=N):N=e[51];let T;e[52]!==S||e[53]!==P||e[54]!==N?(T=s.jsxs("button",{type:"button",onClick:S,className:A,children:[P,N]}),e[52]=S,e[53]=P,e[54]=N,e[55]=T):T=e[55];let M;e[56]!==n?(M=()=>n("mcp"),e[56]=n,e[57]=M):M=e[57];let R;e[58]===Symbol.for("react.memo_cache_sentinel")?(R=me("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 L;e[59]!==r?(L=r("settings.view.home.cards.mcp.title"),e[59]=r,e[60]=L):L=e[60];let $;e[61]!==L?($=s.jsx("div",{className:"typography-ui-label text-foreground",children:L}),e[61]=L,e[62]=$):$=e[62];let B;e[63]!==r?(B=r("settings.view.home.cards.mcp.description"),e[63]=r,e[64]=B):B=e[64];let O;e[65]!==B?(O=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:B}),e[65]=B,e[66]=O):O=e[66];let _;e[67]!==M||e[68]!==$||e[69]!==O?(_=s.jsxs("button",{type:"button",onClick:M,className:R,children:[$,O]}),e[67]=M,e[68]=$,e[69]=O,e[70]=_):_=e[70];let ee;e[71]!==n?(ee=()=>n("usage"),e[71]=n,e[72]=ee):ee=e[72];let z;e[73]===Symbol.for("react.memo_cache_sentinel")?(z=me("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[73]=z):z=e[73];let ne;e[74]!==r?(ne=r("settings.view.home.cards.usage.title"),e[74]=r,e[75]=ne):ne=e[75];let re;e[76]!==ne?(re=s.jsx("div",{className:"typography-ui-label text-foreground",children:ne}),e[76]=ne,e[77]=re):re=e[77];let ue;e[78]!==r?(ue=r("settings.view.home.cards.usage.description"),e[78]=r,e[79]=ue):ue=e[79];let Q;e[80]!==ue?(Q=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:ue}),e[80]=ue,e[81]=Q):Q=e[81];let de;e[82]!==ee||e[83]!==re||e[84]!==Q?(de=s.jsxs("button",{type:"button",onClick:ee,className:z,children:[re,Q]}),e[82]=ee,e[83]=re,e[84]=Q,e[85]=de):de=e[85];let X;e[86]!==v||e[87]!==j||e[88]!==T||e[89]!==_||e[90]!==de?(X=s.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[v,j,T,_,de]}),e[86]=v,e[87]=j,e[88]=T,e[89]=_,e[90]=de,e[91]=X):X=e[91];let F;return e[92]!==X||e[93]!==d?(F=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,X]})}),e[92]=X,e[93]=d,e[94]=F):F=e[94],F},EC=t=>{const e=at.c(102),{onClose:n,forceMobile:r,isWindowed:a}=t,{t:i}=pt(),o=an(),c=r??o.isMobile,d=Te(RC),p=Te(FC),m=Te(LC);let u;e[0]!==d?(u=Jf(d),e[0]=d,e[1]=u):u=e[1];const h=u,[b,f]=l.useState("nav"),v=l.useRef(null),[x,g]=l.useState(216),[w,y]=l.useState(!1),[k,D]=l.useState(!1),j=l.useRef(0),S=l.useRef(x),A=l.useRef(null);let E;e[2]===Symbol.for("react.memo_cache_sentinel")?(E=yn(),e[2]=E):E=e[2];const P=E;let C;e[3]===Symbol.for("react.memo_cache_sentinel")?(C=MC(P),e[3]=C):C=e[3];const N=C;let T;if(e[4]!==c){let Ae;e[6]===Symbol.for("react.memo_cache_sentinel")?(Ae=W=>Op(W,N),e[6]=Ae):Ae=e[6];let ge;e[7]===Symbol.for("react.memo_cache_sentinel")?(ge=W=>!(N.isVSCode&&W.slug==="projects"),e[7]=ge):ge=e[7],T=Jd.filter(OC).filter(Ae).filter(ge).filter(W=>!(c&&W.slug==="shortcuts")),e[4]=c,e[5]=T}else T=e[5];const M=T;let R;e[8]===Symbol.for("react.memo_cache_sentinel")?(R=new Map(TC.map($C)),e[8]=R):R=e[8];const L=R;let $;if(e[9]!==M){let Ae;e[11]===Symbol.for("react.memo_cache_sentinel")?(Ae=(ge,W)=>(L.get(ge.slug)??999)-(L.get(W.slug)??999),e[11]=Ae):Ae=e[11],$=M.slice().sort(Ae),e[9]=M,e[10]=$}else $=e[10];const B=$,O=Fs(BC);let _,ee;e[12]!==w?(_=()=>{if(typeof window>"u")return;const Ae=()=>{if(!w){const ge=Dc(Math.floor(window.innerWidth*.12));g(ge)}};return window.addEventListener("resize",Ae),()=>window.removeEventListener("resize",Ae)},ee=[w],e[12]=w,e[13]=_,e[14]=ee):(_=e[13],ee=e[14]),l.useEffect(_,ee);let z,ne;e[15]!==k?(ne=()=>{if(!k)return;const Ae=W=>{const ie=W.clientX-j.current,Me=Dc(S.current+ie);g(Me),y(!0)},ge=()=>D(!1);return window.addEventListener("pointermove",Ae),window.addEventListener("pointerup",ge,{once:!0}),()=>{window.removeEventListener("pointermove",Ae),window.removeEventListener("pointerup",ge)}},z=[k],e[15]=k,e[16]=z,e[17]=ne):(z=e[16],ne=e[17]),l.useEffect(ne,z);let re;e[18]!==x?(re=Ae=>{D(!0),j.current=Ae.clientX,S.current=x,Ae.preventDefault()},e[18]=x,e[19]=re):re=e[19];const ue=re;let Q;e[20]!==x?(Q=Ae=>{const ge=Ae.shiftKey?Lp*4:Lp;let W;e:switch(Ae.key){case"ArrowLeft":{W=x-ge;break e}case"ArrowRight":{W=x+ge;break e}case"Home":{W=gd;break e}case"End":{W=xd;break e}default:return}Ae.preventDefault(),g(Dc(W)),y(!0)},e[20]=x,e[21]=Q):Q=e[21];const de=Q;let X;e[22]!==p||e[23]!==h?(X=()=>{if(!(!p&&!N.isVSCode)){if(h==="agents"){oi.getState().loadAgents();return}if(h==="commands"){Od.getState().loadCommands();return}if(h==="mcp"){Qi.getState().loadMcpConfigs();return}(h==="skills.installed"||h==="skills.catalog")&&(ea.getState().loadSkills(),Na.getState().loadCatalog())}},e[22]=p,e[23]=h,e[24]=X):X=e[24];let F;e[25]!==O||e[26]!==p||e[27]!==h?(F=[O,p,N.isVSCode,h],e[25]=O,e[26]=p,e[27]=h,e[28]=F):F=e[28],l.useEffect(X,F);let V;e[29]!==c||e[30]!==m?(V=Ae=>{if(m(Ae),v.current=Ae,!c)return;const ge=Ri(Ae);if(!ge||ge.slug==="home"){f("nav");return}f(ge.kind==="split"?"page-sidebar":"page-content")},e[29]=c,e[30]=m,e[31]=V):V=e[31];const q=V;let te;e[32]!==h?(te=Ri(h),e[32]=h,e[33]=te):te=e[33];const U=te;let ae;e[34]===Symbol.for("react.memo_cache_sentinel")?(ae={appearance:"visual",chat:"chat",shortcuts:"shortcuts",sessions:"sessions",notifications:"notifications",voice:"voice",tunnel:"tunnel"},e[34]=ae):ae=e[34];const je=ae;let oe;e[35]!==i?(oe=Ae=>{switch(Ae){case"projects":return i("settings.page.projects.title");case"remote-instances":return i("settings.page.remoteInstances.title");case"providers":return i("settings.page.providers.title");case"usage":return i("settings.page.usage.title");case"agents":return i("settings.page.agents.title");case"behavior":return i("settings.page.behavior.title");case"commands":return i("settings.page.commands.title");case"mcp":return i("settings.page.mcp.title");case"skills.installed":return i("settings.page.skills.title");case"skills.catalog":return i("settings.page.skillsCatalog.title");case"git":return i("settings.page.git.title");case"appearance":return i("settings.page.appearance.title");case"chat":return i("settings.page.chat.title");case"shortcuts":return i("settings.page.shortcuts.title");case"sessions":return i("settings.page.sessions.title");case"magic-prompts":return i("settings.page.magicPrompts.title");case"notifications":return i("settings.page.notifications.title");case"voice":return i("settings.page.voice.title");case"tunnel":return i("settings.page.tunnel.title");default:return i("settings.view.home.title")}},e[35]=i,e[36]=oe):oe=e[36];const ve=oe;let K;e[37]!==i?(K=()=>s.jsx("div",{className:"flex h-full items-center justify-center px-6",children:s.jsxs("div",{className:"max-w-md text-center",children:[s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:i("settings.view.unavailable.title")}),s.jsx("p",{className:"typography-ui text-muted-foreground mt-1",children:i("settings.view.unavailable.description")})]})}),e[37]=i,e[38]=K):K=e[38];const ce=K,Z=_C;let le;e[39]!==q||e[40]!==ce?(le=Ae=>{const ge=Ri(Ae);if(ge&&!Op(ge,N))return ce();switch(Ae){case"home":return s.jsx(Tc,{onOpen:q});case"projects":return s.jsx(i3,{});case"remote-instances":return s.jsx(M3,{});case"agents":return s.jsx(MS,{});case"behavior":return s.jsx(OS,{});case"commands":return s.jsx(HS,{});case"mcp":return s.jsx(vk,{});case"skills.installed":return s.jsx(rp,{view:"installed"});case"skills.catalog":return s.jsx(rp,{view:"catalog"});case"providers":return s.jsx(_3,{});case"usage":return s.jsx(r5,{});case"magic-prompts":return s.jsx(c5,{});case"git":return s.jsx(h5,{});case"appearance":case"chat":case"shortcuts":case"sessions":case"notifications":case"voice":case"tunnel":{const W=je[Ae]??"visual";return s.jsx(wC,{section:W})}default:return s.jsx(Tc,{onOpen:q})}},e[39]=q,e[40]=ce,e[41]=le):le=e[41];const se=le;let Ie,Ne;e[42]!==c||e[43]!==b||e[44]!==h?(Ie=()=>{if(!c||b!=="nav"||h==="home"||v.current===h)return;const Ae=Ri(h);!Ae||Ae.slug==="home"||(v.current=h,f(Ae.kind==="split"?"page-sidebar":"page-content"))},Ne=[c,b,h],e[42]=c,e[43]=b,e[44]=h,e[45]=Ie,e[46]=Ne):(Ie=e[45],Ne=e[46]),l.useEffect(Ie,Ne);const Y=c&&b!=="nav";let fe,ke,be,pe,Ee,ze,G;if(e[47]!==U||e[48]!==ve||e[49]!==c||e[50]!==a||e[51]!==b||e[52]!==n||e[53]!==q||e[54]!==se||e[55]!==h||e[56]!==Y||e[57]!==B||e[58]!==i){const Ae=al();let ge;e[66]===Symbol.for("react.memo_cache_sentinel")?(ge=()=>{f("nav")},e[66]=ge):ge=e[66];const W=ge;let ie;e[67]===Symbol.for("react.memo_cache_sentinel")?(ie=()=>{f("page-sidebar")},e[67]=ie):ie=e[67];const Me=ie;let Ve;e[68]!==ve||e[69]!==q||e[70]!==h||e[71]!==B||e[72]!==i?(Ve=()=>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:B.map(De=>{const Ye=h===De.slug,rt=Zd(De.slug);return rt?s.jsx(kt,{children:s.jsx(Ct,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>q(De.slug),"aria-current":Ye?"page":void 0,className:me("flex h-8 items-center gap-2 rounded-md px-2 overflow-hidden",Ye?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:[s.jsx(I,{name:rt,className:"h-4 w-4 shrink-0"}),s.jsxs("span",{className:"flex items-center gap-1.5 whitespace-nowrap overflow-hidden transition-opacity duration-150 opacity-100",children:[s.jsx("span",{className:"typography-ui-label font-normal truncate",children:ve(De.slug)}),(De.slug==="voice"||De.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")})]})]})})},De.slug):null})})}),s.jsx("div",{className:"overflow-hidden transition-opacity duration-150 opacity-100",children:s.jsx("div",{className:"border-t border-border bg-sidebar px-2 py-1 space-y-0.5",children:!N.isVSCode&&s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsxs("button",{type:"button",className:me("flex h-7 w-full items-center gap-2 rounded-md px-2 overflow-hidden whitespace-nowrap","text-sm font-semibold text-sidebar-foreground/90","hover:text-sidebar-foreground hover:bg-interactive-hover"),onClick:VC,children:[s.jsx(I,{name:"restart",className:"h-4 w-4 shrink-0"}),s.jsx("span",{children:i("settings.view.actions.reloadOpenCode")})]})}),s.jsx(Pt,{children:i("settings.view.actions.reloadOpenCodeTooltip")})]})})})]}),e[68]=ve,e[69]=q,e[70]=h,e[71]=B,e[72]=i,e[73]=Ve):Ve=e[73],be=Ve;let Ce;e[74]!==U||e[75]!==b||e[76]!==se||e[77]!==be||e[78]!==h?(Ce=()=>{if(b==="nav")return s.jsx("div",{className:me("flex-1 min-h-0 overflow-hidden",N.isVSCode?"bg-background":"bg-sidebar"),children:s.jsx("div",{className:"flex h-full min-h-0 flex-col",children:s.jsx(Xs,{children:be()})})});if(!U)return s.jsx("div",{className:"flex-1 bg-background"});if(b==="page-sidebar"){if(U.kind!=="split"){const Ye=se(h);return s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:s.jsx(Xs,{children:Ye})})}return s.jsx("div",{className:me("flex-1 min-h-0 overflow-hidden",N.isVSCode?"bg-background":"bg-sidebar"),children:s.jsx(Xs,{children:Z(h,{onItemSelect:()=>f("page-content")})})})}const De=se(h);return s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:s.jsx(Xs,{children:De})})},e[74]=U,e[75]=b,e[76]=se,e[77]=be,e[78]=h,e[79]=Ce):Ce=e[79],ke=Ce;let xe;e[80]!==U||e[81]!==q||e[82]!==se||e[83]!==h?(xe=()=>!U||h==="home"?s.jsx(Tc,{onOpen:q}):U.kind==="split"?s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden",children:[s.jsx("div",{className:me("w-[264px] min-w-[264px] border-r",N.isVSCode?"bg-background":"bg-sidebar"),style:{borderColor:"var(--interactive-border)"},children:s.jsx(Xs,{children:Z(h,{})})}),s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:s.jsx(Xs,{children:se(h)})})]}):s.jsx("div",{className:"h-full min-h-0 overflow-hidden bg-background",children:s.jsx(Xs,{children:se(h)})}),e[80]=U,e[81]=q,e[82]=se,e[83]=h,e[84]=xe):xe=e[84],fe=xe,pe=A,Ee="true",e[85]===Symbol.for("react.memo_cache_sentinel")?(ze=me("relative flex h-full min-h-0 flex-col overflow-hidden bg-background"),e[85]=ze):ze=e[85],G=c?s.jsxs("div",{className:me("flex items-center gap-2 px-3 py-2 border-b","bg-background"),style:{borderColor:"var(--interactive-border)"},children:[s.jsx("button",{type:"button",onClick:Y?W:n,"aria-label":i(Y?"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(I,{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"):U?ve(U.slug):i("settings.view.home.title")}),b==="page-content"&&U?.kind==="split"&&s.jsx("button",{type:"button",onClick:Me,"aria-label":i("settings.view.actions.openSectionList"),className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(I,{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:Ae}),className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg p-2 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(I,{name:"close",className:"h-5 w-5"})})]}):s.jsxs(s.Fragment,{children:[Y&&s.jsx("div",{className:me("absolute left-3 z-50",a?"top-2":"top-3"),children:s.jsx("button",{type:"button",onClick:W,"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(I,{name:"arrow-left-s",className:"h-5 w-5"})})}),n&&s.jsx("div",{className:me("absolute right-0.5 z-50",a?"top-0.5":"top-1"),children:s.jsx("button",{type:"button",onClick:n,"aria-label":i("settings.view.actions.closeSettings"),title:i("settings.view.actions.closeSettingsWithShortcut",{shortcut:Ae}),className:"inline-flex h-7 w-7 items-center justify-center rounded-md p-0.5 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(I,{name:"close",className:"h-5 w-5"})})})]}),e[47]=U,e[48]=ve,e[49]=c,e[50]=a,e[51]=b,e[52]=n,e[53]=q,e[54]=se,e[55]=h,e[56]=Y,e[57]=B,e[58]=i,e[59]=fe,e[60]=ke,e[61]=be,e[62]=pe,e[63]=Ee,e[64]=ze,e[65]=G}else fe=e[59],ke=e[60],be=e[61],pe=e[62],Ee=e[63],ze=e[64],G=e[65];let Pe;e[86]!==ue||e[87]!==de||e[88]!==c||e[89]!==k||e[90]!==x||e[91]!==fe||e[92]!==ke||e[93]!==be||e[94]!==i?(Pe=s.jsx("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:c?ke():s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:me("relative flex h-full min-h-0 flex-col overflow-hidden border-r",P?"bg-sidebar":N.isVSCode?"bg-background":"bg-sidebar",k?"":"transition-[width,min-width] duration-200 ease-[cubic-bezier(0.25,0.1,0.25,1)]"),style:{width:`${x}px`,minWidth:`${x}px`,borderColor:"var(--interactive-border)"},children:[s.jsx("div",{className:me("absolute right-0 top-0 z-20 h-full w-[6px] -mr-[3px] cursor-col-resize","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",k?"bg-primary/30":"bg-transparent hover:bg-primary/20"),tabIndex:0,onPointerDown:ue,onKeyDown:de,role:"separator","aria-orientation":"vertical","aria-valuemin":gd,"aria-valuemax":xd,"aria-valuenow":x,"aria-label":i("settings.view.actions.resizeNavigation")}),s.jsx(Xs,{children:be()})]}),s.jsx("div",{className:"flex-1 overflow-hidden bg-background",children:fe()})]})}),e[86]=ue,e[87]=de,e[88]=c,e[89]=k,e[90]=x,e[91]=fe,e[92]=ke,e[93]=be,e[94]=i,e[95]=Pe):Pe=e[95];let Le;return e[96]!==pe||e[97]!==Ee||e[98]!==ze||e[99]!==G||e[100]!==Pe?(Le=s.jsxs("div",{ref:pe,"data-settings-view":Ee,className:ze,children:[G,Pe]}),e[96]=pe,e[97]=Ee,e[98]=ze,e[99]=G,e[100]=Pe,e[101]=Le):Le=e[101],Le};function RC(t){return t.settingsPage}function FC(t){return t.isSettingsDialogOpen}function LC(t){return t.setSettingsPage}function OC(t){return t.slug!=="home"}function $C(t,e){return[t,e]}function BC(t){return t.activeProjectId}function _C(t,e){switch(t){case"projects":return s.jsx(Yk,{onItemSelect:e.onItemSelect});case"remote-instances":return s.jsx(y3,{onItemSelect:e.onItemSelect});case"agents":return s.jsx(kS,{onItemSelect:e.onItemSelect});case"commands":return s.jsx($S,{onItemSelect:e.onItemSelect});case"mcp":return s.jsx(GS,{onItemSelect:e.onItemSelect});case"skills.installed":return s.jsx(wk,{onItemSelect:e.onItemSelect});case"providers":return s.jsx(F3,{onItemSelect:e.onItemSelect});case"usage":return s.jsx(z3,{onItemSelect:e.onItemSelect});case"magic-prompts":return s.jsx(i5,{onItemSelect:e.onItemSelect});default:return null}}function VC(){si({message:"Restarting OpenCode…",mode:"projects",scopes:["all"]})}const zC=Object.freeze(Object.defineProperty({__proto__:null,SettingsView:EC,getSettingsNavIcon:Zd},Symbol.toStringTag,{value:"Module"})),bd=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},UC=()=>{const t=at.c(162),{t:e}=pt(),n=Te(WC),r=Te(KC),a=Te(HC),i=Te(GC),o=Te(qC),c=Te(JC),d=Te(QC),p=Te(YC),m=Te(XC),u=Te(ZC),h=Te(e4),b=Te(t4),f=Vt(s4),v=Vt(n4),x=ja(r4),g=Vs(a4),w=Fs(i4),y=Er(),k=Rd(o4),{files:D,git:j}=_n(),S=nn(l4),{isMobile:A}=an();let E;t[0]!==y?(E=y?bd(y):null,t[0]=y,t[1]=E):E=t[1];const P=E,[C,N]=l.useState(""),T=Cl(C,200);let M;t[2]!==T?(M=T.trim(),t[2]=T,t[3]=M):M=t[3];const R=M;let L;t[4]!==C?(L=C.trim(),t[4]=C,t[5]=L):L=t[5];const $=L;let B,O;t[6]!==n?(B=()=>{n&&N("")},O=[n],t[6]=n,t[7]=B,t[8]=O):(B=t[7],O=t[8]),l.useEffect(B,O);let _,ee;t[9]!==x||t[10]!==S||t[11]!==j||t[12]!==n?(_=()=>{if(!n||!j)return;const Xe=setTimeout(()=>{const We=new Set;for(const bt of x){const Dt=Bi(bt);!Dt||We.has(Dt)||(We.add(Dt),S(Dt,j))}},0);return()=>clearTimeout(Xe)},ee=[n,x,j,S],t[9]=x,t[10]=S,t[11]=j,t[12]=n,t[13]=_,t[14]=ee):(_=t[13],ee=t[14]),l.useEffect(_,ee);let z;t[15]!==r?(z=()=>r(!1),t[15]=r,t[16]=z):z=t[16];const ne=z;let re;t[17]!==ne?(re=Xe=>()=>{ne(),Xe()},t[17]=ne,t[18]=re):re=t[18];const ue=re;let Q;t[19]!==w?.id||t[20]!==w?.path||t[21]!==g||t[22]!==A||t[23]!==u||t[24]!==f||t[25]!==ue||t[26]!==a||t[27]!==c||t[28]!==i||t[29]!==e||t[30]!==m||t[31]!==p||t[32]!==d?(Q=()=>{const Xe=[{id:"new-session",title:e("commandPalette.item.newSession"),icon:s.jsx(I,{name:"add",className:"mr-2 h-4 w-4"}),shortcutId:"new_chat",searchText:e("commandPalette.item.newSession"),onSelect:ue(()=>{a("chat"),c(!1),f()})},{id:"new-worktree",title:e("commandPalette.item.newWorktreeDraft"),icon:s.jsx(I,{name:"git-branch",className:"mr-2 h-4 w-4"}),shortcutId:"new_chat_worktree",searchText:e("commandPalette.item.newWorktreeDraft"),onSelect:ue(c4)},{id:"add-project",title:e("commandPalette.item.addProject"),icon:s.jsx(I,{name:"folder-add",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.addProject"),onSelect:ue(d4)},{id:"toggle-sidebar",title:e(A?"commandPalette.item.showSessionSwitcher":"commandPalette.item.toggleSidebar"),icon:s.jsx(I,{name:"layout-left",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_sidebar",searchText:e(A?"commandPalette.item.showSessionSwitcher":"commandPalette.item.toggleSidebar"),onSelect:ue(()=>{if(A){const{isSessionSwitcherOpen:We}=Te.getState();c(!We)}else d()})},{id:"toggle-right-sidebar",title:e("commandPalette.item.toggleRightSidebar"),icon:s.jsx(I,{name:"layout-right",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_right_sidebar",searchText:e("commandPalette.item.toggleRightSidebar"),onSelect:ue(()=>p())},{id:"toggle-terminal",title:e("commandPalette.item.toggleTerminal"),icon:s.jsx(I,{name:"terminal-box",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_terminal",searchText:e("commandPalette.item.toggleTerminal"),onSelect:ue(()=>m())},{id:"context-usage",title:e("commandPalette.item.showContextUsage"),icon:s.jsx(I,{name:"pie-chart",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.showContextUsage"),onSelect:ue(()=>{g&&u(g)})},{id:"open-settings",title:e("commandPalette.item.openSettings"),icon:s.jsx(I,{name:"settings-3",className:"mr-2 h-4 w-4"}),shortcutId:"open_settings",searchText:e("commandPalette.item.openSettings"),onSelect:ue(()=>i(!0))}];return Id()&&Xe.splice(1,0,{id:"new-mini-chat",title:e("commandPalette.item.newMiniChat"),icon:s.jsx(I,{name:"window",className:"mr-2 h-4 w-4"}),shortcutId:"new_mini_chat",searchText:e("commandPalette.item.newMiniChat"),onSelect:ue(()=>{sl("desktop_open_draft_mini_chat_window",{directory:bd(g||w?.path||""),projectId:w?.id??null}).catch(u4)})}),Xe},t[19]=w?.id,t[20]=w?.path,t[21]=g,t[22]=A,t[23]=u,t[24]=f,t[25]=ue,t[26]=a,t[27]=c,t[28]=i,t[29]=e,t[30]=m,t[31]=p,t[32]=d,t[33]=Q):Q=t[33],w?.id,w?.path;let de;t[34]!==Q?(de=Q(),t[34]=Q,t[35]=de):de=t[35];const X=de;let F;t[36]===Symbol.for("react.memo_cache_sentinel")?(F=yn(),t[36]=F):F=t[36];const V=F;let q;t[37]===Symbol.for("react.memo_cache_sentinel")?(q={isVSCode:dn(),isWeb:!V&&sa(),isDesktop:V},t[37]=q):q=t[37];const te=q;let U;if(t[38]!==ue||t[39]!==i||t[40]!==o){let Xe;t[42]===Symbol.for("react.memo_cache_sentinel")?(Xe=We=>We.isAvailable?We.isAvailable(te):!0,t[42]=Xe):Xe=t[42],U=Jd.filter(m4).filter(Xe).map(We=>{const bt=Zd(We.slug)??"settings-3",Dt=(We.keywords??[]).join(" ");return{id:`settings:${We.slug}`,title:We.title,icon:s.jsx(I,{name:bt,className:"mr-2 h-4 w-4"}),searchText:`${We.title} ${We.group} ${Dt}`,onSelect:ue(()=>{o(We.slug),i(!0)})}}),t[38]=ue,t[39]=i,t[40]=o,t[41]=U}else U=t[41];const ae=U,je=p4;let oe;if(t[43]!==x){let Xe;t[45]===Symbol.for("react.memo_cache_sentinel")?(Xe=(We,bt)=>je(bt)-je(We),t[45]=Xe):Xe=t[45],oe=[...x].sort(Xe),t[43]=x,t[44]=oe}else oe=t[44];const ve=oe,K=Hh(),ce=Vt(h4);let Z;t[46]!==K||t[47]!==ce?(Z=(Xe,We)=>{const bt=ce.get(Xe);return bt?.branch?bt.branch.trim()||null:We&&K.get(We)?.trim()||null},t[46]=K,t[47]=ce,t[48]=Z):Z=t[48];const le=Z;let se;t[49]===Symbol.for("react.memo_cache_sentinel")?(se=[],t[49]=se):se=t[49];const[Ie,Ne]=l.useState(se),[Y,fe]=l.useState(!1);let ke,be;t[50]!==P||t[51]!==n||t[52]!==k||t[53]!==R?(ke=()=>{if(!n){Ne([]),fe(!1);return}if(!P||R.length===0){Ne([]),fe(!1);return}let Xe=!1;return fe(!0),k(P,R,10,{type:"file"}).then(We=>{Xe||Ne(We.map(f4))}).catch(()=>{Xe||Ne([])}).finally(()=>{Xe||fe(!1)}),()=>{Xe=!0}},be=[n,P,R,k],t[50]=P,t[51]=n,t[52]=k,t[53]=R,t[54]=ke,t[55]=be):(ke=t[54],be=t[55]),l.useEffect(ke,be);const pe=$.length>0;let Ee;e:{if(!pe){let We;t[56]!==X?(We=X.map(g4),t[56]=X,t[57]=We):We=t[57],Ee=We;break e}let Xe;t[58]!==X||t[59]!==$?(Xe=fo(X,$,x4,{limit:7,noFuzzy:!0}),t[58]=X,t[59]=$,t[60]=Xe):Xe=t[60],Ee=Xe}const ze=Ee;let G;e:{if(!pe){let We;t[61]===Symbol.for("react.memo_cache_sentinel")?(We=[],t[61]=We):We=t[61],G=We;break e}let Xe;t[62]!==$||t[63]!==ae?(Xe=fo(ae,$,b4,{limit:7,noFuzzy:!0}),t[62]=$,t[63]=ae,t[64]=Xe):Xe=t[64],G=Xe}const Pe=G;let Le;e:{if(!pe){let We;t[65]!==ve?(We=ve.slice(0,5).map(y4),t[65]=ve,t[66]=We):We=t[66],Le=We;break e}let Xe;t[67]!==$||t[68]!==ve?(Xe=fo(ve,$,v4,{limit:7,threshold:.2}),t[67]=$,t[68]=ve,t[69]=Xe):Xe=t[69],Le=Xe}const Ae=Le;let ge;e:{if(!pe||Ie.length===0){let We;t[70]===Symbol.for("react.memo_cache_sentinel")?(We=[],t[70]=We):We=t[70],ge=We;break e}let Xe;t[71]!==Ie||t[72]!==$?(Xe=fo(Ie,$,w4,{limit:10,threshold:.4}),t[71]=Ie,t[72]=$,t[73]=Xe):Xe=t[73],ge=Xe}const W=ge;let ie,Me,Ve,Ce,xe,De,Ye,rt,Re,he,qe,et,Ke,st,nt;if(t[74]!==le||t[75]!==ne||t[76]!==P||t[77]!==D||t[78]!==pe||t[79]!==n||t[80]!==h||t[81]!==C||t[82]!==ze||t[83]!==W||t[84]!==Ae||t[85]!==Pe||t[86]!==r||t[87]!==v||t[88]!==b||t[89]!==e){const Xe=ze.map(j4),We=Pe.map(N4),bt=Ae.map(S4);nt=pe?W.map(k4):[];let Dt;e:{if(!pe){Dt=["commands","sessions"];break e}const Mt=C4,He=[{key:"commands",score:Mt(ze)},{key:"settings",score:Mt(Pe)},{key:"sessions",score:Mt(Ae)},{key:"files",score:Mt(W)}];He.sort(I4),Dt=He.map(P4)}const Ht=Dt;let rs;t[105]!==ne||t[106]!==v?(rs=Mt=>{ne(),v(Mt.id,Bi(Mt))},t[105]=ne,t[106]=v,t[107]=rs):rs=t[107];const jt=rs;let St;t[108]!==ne||t[109]!==P||t[110]!==D||t[111]!==h?(St=async Mt=>{if(!P)return;const He=await Hd(D,Mt);if(!He.ok){H.error(Gd(He.reason));return}h(P,Mt),ne()},t[108]=ne,t[109]=P,t[110]=D,t[111]=h,t[112]=St):St=t[112];const ns=St;let ut;t[113]!==b?(ut=Mt=>jl(Br(Mt,b)),t[113]=b,t[114]=ut):ut=t[114];const Gt=ut;Ce=ws,et=n,Ke=r;let Xt;t[115]!==e?(Xt=e("commandPalette.title"),t[115]=e,t[116]=Xt):Xt=t[116];let Wt;t[117]!==Xt?(Wt=s.jsx(js,{children:Xt}),t[117]=Xt,t[118]=Wt):Wt=t[118];let is;t[119]!==e?(is=e("commandPalette.description"),t[119]=e,t[120]=is):is=t[120];let gs;t[121]!==is?(gs=s.jsx(Rs,{children:is}),t[121]=is,t[122]=gs):gs=t[122],t[123]!==Wt||t[124]!==gs?(st=s.jsxs(Cs,{className:"sr-only",children:[Wt,gs]}),t[123]=Wt,t[124]=gs,t[125]=st):st=t[125],Ve=vs,he="overflow-hidden p-0",qe=!0,Me=Ta,Ye=!1,rt="[&_[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 ps;t[126]!==e?(ps=e("commandPalette.input.placeholder"),t[126]=e,t[127]=ps):ps=t[127],t[128]!==C||t[129]!==ps?(Re=s.jsx(ra,{value:C,onValueChange:N,placeholder:ps}),t[128]=C,t[129]=ps,t[130]=Re):Re=t[130],ie=Ma;let Ns;t[131]!==e?(Ns=e("commandPalette.empty.noResults"),t[131]=e,t[132]=Ns):Ns=t[132],t[133]!==Ns?(xe=s.jsx(Ea,{children:Ns}),t[133]=Ns,t[134]=xe):xe=t[134],De=Ht.map(Mt=>Mt==="commands"&&Xe.length>0?s.jsx(Bn,{children:Xe.map(He=>s.jsxs(An,{value:He.id,onSelect:He.onSelect,children:[He.icon,s.jsx("span",{children:He.title}),He.shortcutId?s.jsx(bw,{children:Gt(He.shortcutId)}):null]},He.id))},"commands"):Mt==="settings"&&We.length>0?s.jsx(Bn,{children:We.map(A4)},"settings"):Mt==="sessions"&&bt.length>0?s.jsx(Bn,{children:bt.map(He=>{const At=He.title||e("commandPalette.session.untitled"),Et=Bi(He),wt=le(He.id,Et);return s.jsxs(An,{value:`session:${He.id}`,onSelect:()=>jt(He),children:[s.jsx(I,{name:"chat-ai-3",className:"mr-2 h-4 w-4"}),s.jsx("span",{className:"truncate",children:At}),wt?s.jsxs("span",{className:"ml-auto inline-flex items-center gap-1 text-muted-foreground typography-meta",children:[s.jsx(I,{name:"git-branch",className:"h-3 w-3"}),s.jsx("span",{className:"truncate max-w-[160px]",children:wt})]}):null]},He.id)})},"sessions"):Mt==="files"&&nt.length>0?s.jsx(Bn,{children:nt.map(He=>{const At=Xb(He.relativePath||He.name,{maxLength:80});return s.jsxs(An,{value:`file:${He.path}`,onSelect:()=>{ns(He.path)},children:[s.jsx(br,{filePath:He.path,className:"mr-2 size-4 shrink-0"}),s.jsx("span",{className:"truncate","aria-label":He.relativePath,children:At})]},`file:${He.path}`)})},"files"):null),t[74]=le,t[75]=ne,t[76]=P,t[77]=D,t[78]=pe,t[79]=n,t[80]=h,t[81]=C,t[82]=ze,t[83]=W,t[84]=Ae,t[85]=Pe,t[86]=r,t[87]=v,t[88]=b,t[89]=e,t[90]=ie,t[91]=Me,t[92]=Ve,t[93]=Ce,t[94]=xe,t[95]=De,t[96]=Ye,t[97]=rt,t[98]=Re,t[99]=he,t[100]=qe,t[101]=et,t[102]=Ke,t[103]=st,t[104]=nt}else ie=t[90],Me=t[91],Ve=t[92],Ce=t[93],xe=t[94],De=t[95],Ye=t[96],rt=t[97],Re=t[98],he=t[99],qe=t[100],et=t[101],Ke=t[102],st=t[103],nt=t[104];let ye;t[135]!==pe||t[136]!==Y||t[137]!==e||t[138]!==nt?(ye=pe&&Y&&nt.length===0?s.jsx("div",{className:"px-3 py-2 typography-meta text-muted-foreground",children:e("commandPalette.empty.searchingFiles")}):null,t[135]=pe,t[136]=Y,t[137]=e,t[138]=nt,t[139]=ye):ye=t[139];let Je;t[140]!==ie||t[141]!==xe||t[142]!==De||t[143]!==ye?(Je=s.jsxs(ie,{children:[xe,De,ye]}),t[140]=ie,t[141]=xe,t[142]=De,t[143]=ye,t[144]=Je):Je=t[144];let _e;t[145]!==Me||t[146]!==Ye||t[147]!==rt||t[148]!==Re||t[149]!==Je?(_e=s.jsxs(Me,{shouldFilter:Ye,className:rt,children:[Re,Je]}),t[145]=Me,t[146]=Ye,t[147]=rt,t[148]=Re,t[149]=Je,t[150]=_e):_e=t[150];let Ue;t[151]!==Ve||t[152]!==he||t[153]!==qe||t[154]!==_e?(Ue=s.jsx(Ve,{className:he,showCloseButton:qe,children:_e}),t[151]=Ve,t[152]=he,t[153]=qe,t[154]=_e,t[155]=Ue):Ue=t[155];let ot;return t[156]!==Ce||t[157]!==et||t[158]!==Ke||t[159]!==st||t[160]!==Ue?(ot=s.jsxs(Ce,{open:et,onOpenChange:Ke,children:[st,Ue]}),t[156]=Ce,t[157]=et,t[158]=Ke,t[159]=st,t[160]=Ue,t[161]=ot):ot=t[161],ot};function WC(t){return t.isCommandPaletteOpen}function KC(t){return t.setCommandPaletteOpen}function HC(t){return t.setActiveMainTab}function GC(t){return t.setSettingsDialogOpen}function qC(t){return t.setSettingsPage}function JC(t){return t.setSessionSwitcherOpen}function QC(t){return t.toggleSidebar}function YC(t){return t.toggleRightSidebar}function XC(t){return t.toggleBottomTerminal}function ZC(t){return t.openContextOverview}function e4(t){return t.openContextFile}function t4(t){return t.shortcutOverrides}function s4(t){return t.openNewSessionDraft}function n4(t){return t.setCurrentSession}function r4(t){return t.activeSessions}function a4(t){return t.currentDirectory}function i4(t){return t.getActiveProject()}function o4(t){return t.searchFiles}function l4(t){return t.ensureStatus}function c4(){Gh()}function d4(){yr.requestDirectoryDialog()}function u4(t){console.warn("[command-palette] failed to open draft mini chat window",t)}function m4(t){return t.slug!=="home"}function p4(t){return(typeof t.time?.updated=="number"?t.time.updated:0)||(typeof t.time?.created=="number"?t.time.created:0)}function h4(t){return t.worktreeMetadata}function f4(t){return{path:bd(t.path),name:t.name,relativePath:t.relativePath}}function g4(t){return{item:t,score:0}}function x4(t){return t.searchText}function b4(t){return t.searchText}function y4(t){return{item:t,score:0}}function v4(t){return t.title||""}function w4(t){return t.name}function j4(t){return t.item}function N4(t){return t.item}function S4(t){return t.item}function k4(t){return t.item}function C4(t){return t.length?t[0].score:1/0}function I4(t,e){return t.score-e.score}function P4(t){return t.key}function A4(t){return s.jsxs(An,{value:t.id,onSelect:t.onSelect,children:[t.icon,s.jsx("span",{children:t.title})]},t.id)}const $p=(t,e,n)=>ey(t)?jl(Br(t,n)):e,D4=()=>{const t=at.c(68),{t:e}=pt(),n=Te(T4),r=Te(M4),a=Te(E4);let i;t[0]===Symbol.for("react.memo_cache_sentinel")?(i=Zb(),t[0]=i):i=t[0];const o=i;let c,d,p,m,u,h,b,f,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=ws,f=n,v=r,c=vs,h="max-w-2xl w-[min(42rem,calc(100vw-1.5rem))] max-h-[calc(100dvh-2rem)] flex flex-col overflow-hidden";let L;t[14]===Symbol.for("react.memo_cache_sentinel")?(L=s.jsx(I,{name:"settings-3",className:"h-5 w-5"}),t[14]=L):L=t[14];let $;t[15]!==e?($=e("helpDialog.title"),t[15]=e,t[16]=$):$=t[16];let B;t[17]!==$?(B=s.jsxs(js,{className:"flex items-center gap-2",children:[L,$]}),t[17]=$,t[18]=B):B=t[18];let O;t[19]!==e?(O=e("helpDialog.description"),t[19]=e,t[20]=O):O=t[20];let _;t[21]!==O?(_=s.jsx(Rs,{children:O}),t[21]=O,t[22]=_):_=t[22],t[23]!==B||t[24]!==_?(b=s.jsxs(Cs,{children:[B,_]}),t[23]=B,t[24]=_,t[25]=b):b=t[25],u="flex-1 overflow-y-auto mt-3 pr-1",p="space-y-4",m=R.map(ee=>s.jsxs("div",{children:[s.jsx("h3",{className:"typography-meta font-semibold text-muted-foreground uppercase tracking-wider mb-2",children:e(ee.categoryKey)}),s.jsx("div",{className:"space-y-1",children:ee.items.map(z=>{const ne=z.id?$p(z.id,Array.isArray(z.keys)?z.keys[0]:z.keys,a):Array.isArray(z.keys)?z.keys:z.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:[z.icon&&s.jsx(I,{name:z.icon,className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"typography-meta",children:e(z.descriptionKey)})]}),s.jsx("div",{className:"flex items-center gap-1",children:(Array.isArray(ne)?ne:[ne]).map((re,ue)=>s.jsxs(l.Fragment,{children:[ue>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:re})]},`${re}-${ue}`))})]},z.id||z.descriptionKey)})})]},ee.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]=h,t[11]=b,t[12]=f,t[13]=v}else c=t[5],d=t[6],p=t[7],m=t[8],u=t[9],h=t[10],b=t[11],f=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(I,{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 k;t[34]!==a||t[35]!==e?(k=e("helpDialog.proTips.commandPalette",{shortcut:$p("open_command_palette",`${o} P`,a)}),t[34]=a,t[35]=e,t[36]=k):k=t[36];let D;t[37]!==k?(D=s.jsxs("li",{children:["• ",k]}),t[37]=k,t[38]=D):D=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 A;t[43]!==e?(A=e("helpDialog.proTips.themeCycling"),t[43]=e,t[44]=A):A=t[44];let E;t[45]!==A?(E=s.jsxs("li",{children:["• ",A]}),t[45]=A,t[46]=E):E=t[46];let P;t[47]!==D||t[48]!==S||t[49]!==E?(P=s.jsxs("ul",{className:"space-y-0.5 typography-meta",children:[D,S,E]}),t[47]=D,t[48]=S,t[49]=E,t[50]=P):P=t[50];let C;t[51]!==y||t[52]!==P?(C=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]=C):C=t[53];let N;t[54]!==C||t[55]!==u||t[56]!==x?(N=s.jsxs("div",{className:u,children:[x,C]}),t[54]=C,t[55]=u,t[56]=x,t[57]=N):N=t[57];let T;t[58]!==c||t[59]!==N||t[60]!==h||t[61]!==b?(T=s.jsxs(c,{className:h,children:[b,N]}),t[58]=c,t[59]=N,t[60]=h,t[61]=b,t[62]=T):T=t[62];let M;return t[63]!==d||t[64]!==T||t[65]!==f||t[66]!==v?(M=s.jsx(d,{open:f,onOpenChange:v,children:T}),t[63]=d,t[64]=T,t[65]=f,t[66]=v,t[67]=M):M=t[67],M};function T4(t){return t.isHelpDialogOpen}function M4(t){return t.setHelpDialogOpen}function E4(t){return t.shortcutOverrides}const R4=()=>{const t=at.c(32),{t:e}=pt(),n=Te(F4),r=Te(L4),a=Te(O4);let i;t[0]!==a||t[1]!==e?(i=async()=>{if(!a)return;if((await Rn(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(js,{children:c}),t[5]=c,t[6]=d):d=t[6];let p;t[7]!==e?(p=e("openCodeStatusDialog.description"),t[7]=e,t[8]=p):p=t[8];let m;t[9]!==p?(m=s.jsx(Rs,{children:p}),t[9]=p,t[10]=m):m=t[10];let u;t[11]!==d||t[12]!==m?(u=s.jsxs(Cs,{children:[d,m]}),t[11]=d,t[12]=m,t[13]=u):u=t[13];let h;t[14]!==e?(h=e("openCodeStatusDialog.actions.copy"),t[14]=e,t[15]=h):h=t[15];let b;t[16]!==o||t[17]!==h?(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:h})}),t[16]=o,t[17]=h,t[18]=b):b=t[18];let f;t[19]!==a||t[20]!==e?(f=a||e("openCodeStatusDialog.empty.noData"),t[19]=a,t[20]=e,t[21]=f):f=t[21];let v;t[22]!==f?(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:f}),t[22]=f,t[23]=v):v=t[23];let x;t[24]!==u||t[25]!==b||t[26]!==v?(x=s.jsxs(vs,{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(ws,{open:n,onOpenChange:r,children:x}),t[28]=n,t[29]=r,t[30]=x,t[31]=g):g=t[31],g};function F4(t){return t.isOpenCodeStatusDialogOpen}function L4(t){return t.setOpenCodeStatusDialogOpen}function O4(t){return t.openCodeStatusText}const $4=180,Bp=600,B4=1,_4=6,V4=({currentSessionId:t,sortedSessions:e,recentSessionIds:n=[],ensureSessionRenderable:r})=>{const a=l.useRef(new Map),i=l.useRef([]),o=l.useRef(new Set),c=l.useCallback(()=>{if(!(typeof window>"u"))for(;o.current.size<B4&&i.current.length>0;){const p=i.current.shift();if(!p)break;Vt.getState().currentSessionId!==p&&(Pu(p).renderable||(o.current.add(p),r(p).catch(()=>{}).finally(()=>{o.current.delete(p),c()})))}},[r]),d=l.useCallback(p=>{if(!p||p===t||typeof window>"u"||Pu(p).renderable||o.current.has(p)||i.current.includes(p))return;i.current.length>=_4&&i.current.shift();const m=a.current.get(p);m!==void 0&&window.clearTimeout(m);const u=window.setTimeout(()=>{a.current.delete(p),i.current.push(p),c()},$4);a.current.set(p,u)},[t,c]);l.useEffect(()=>{if(!t||e.length===0)return;const p=window.setTimeout(()=>{const m=e.findIndex(u=>u.id===t);m<0||(d(e[m-1]?.id),d(e[m+1]?.id))},Bp);return()=>window.clearTimeout(p)},[t,d,e]),l.useEffect(()=>{if(!t||n.length===0)return;const p=window.setTimeout(()=>{const m=n.indexOf(t);m<0||(d(n[m-1]),d(n[m+1]))},Bp);return()=>window.clearTimeout(p)},[t,n,d]),l.useEffect(()=>{const p=a.current;return()=>{p.forEach(m=>{clearTimeout(m)}),p.clear(),i.current=[]}},[])};function _p(t){const{localBranches:e,remoteBranches:n,query:r}=t,a=r.trim();if(!a)return{matching:[],otherLocal:e,otherRemote:n};const i=Au(e,a,m=>m),o=Au(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 h=m.label.localeCompare(u.label,void 0,{sensitivity:"accent"});return h!==0?h:m.source!==u.source?m.source.localeCompare(u.source):m.value.localeCompare(u.value)}),{matching:c,otherLocal:d,otherRemote:p}}function z4({open:t,onOpenChange:e,onSelect:n}){const{t:r}=pt(),a=Te(K=>K.isMobile),{github:i}=_n(),o=Kn(K=>K.status),c=Kn(K=>K.hasChecked),d=Te(K=>K.setSettingsDialogOpen),p=Te(K=>K.setSettingsPage),m=Fs(K=>K.getActiveProject()),u=m?.path??null,h=Be.useMemo(()=>u&&m?{id:m.id,path:u}:null,[m,u]),[b,f]=Be.useState("issues"),[v,x]=Be.useState(""),[g,w]=Be.useState([]),[y,k]=Be.useState([]),[D,j]=Be.useState(!1),[S,A]=Be.useState(!1),[E,P]=Be.useState(null),[C,N]=Be.useState(null),[T,M]=Be.useState(null),[R,L]=Be.useState(!1),[$,B]=Be.useState(new Map),[O,_]=Be.useState(1),[ee,z]=Be.useState(!1),ne=Be.useCallback(async()=>{if(!(!u||!i)&&!(c&&o?.connected===!1)){j(!0),P(null),_(1),z(!1);try{if(b==="issues"&&i.issuesList){const K=await i.issuesList(u,{page:1});K.connected===!1?(P(r("session.githubIntegration.error.notConnected")),w([])):(w(K.issues??[]),_(K.page??1),z(!!K.hasMore))}else if(b==="prs"&&i.prsList){const K=await i.prsList(u,{page:1});K.connected===!1?(P(r("session.githubIntegration.error.notConnected")),k([])):(k(K.prs??[]),_(K.page??1),z(!!K.hasMore))}}catch(K){P(K instanceof Error?K.message:r("session.githubIntegration.error.loadDataFailed"))}finally{j(!1)}}},[u,i,c,o,b,r]),re=Be.useCallback(async()=>{if(!(!u||!i)&&!(D||S)&&ee){A(!0);try{const K=O+1;if(b==="issues"&&i.issuesList){const ce=await i.issuesList(u,{page:K});ce.connected!==!1&&(w(Z=>[...Z,...ce.issues??[]]),_(ce.page??K),z(!!ce.hasMore))}else if(b==="prs"&&i.prsList){const ce=await i.prsList(u,{page:K});ce.connected!==!1&&(k(Z=>[...Z,...ce.prs??[]]),_(ce.page??K),z(!!ce.hasMore))}}catch{}finally{A(!1)}}},[u,i,b,O,ee,D,S]);Be.useEffect(()=>{if(!t){f("issues"),x(""),w([]),k([]),N(null),M(null),L(!1),P(null),B(new Map),_(1),z(!1);return}ne()},[t,ne]);const ue=Be.useCallback(async K=>{if(!(!h||!K)&&!$.has(K))try{const Z=(await qh(h,{mode:"new",branchName:K,worktreeName:K})).errors.find(le=>le.code==="branch_in_use");B(le=>new Map(le).set(K,{isValid:!Z,error:Z?r(Z.code==="branch_exists"?"session.githubIntegration.validation.branchAlreadyExists":"session.githubIntegration.validation.branchAlreadyCheckedOut"):null}))}catch{B(ce=>new Map(ce).set(K,{isValid:!1,error:r("session.githubIntegration.validation.failed")}))}},[h,$,r]);Be.useEffect(()=>{!t||b!=="prs"||y.forEach(K=>{K.head&&ue(K.head)})},[t,b,y,ue]);const Q=Be.useMemo(()=>{const K=v.trim().toLowerCase();return K?g.filter(ce=>String(ce.number)===K.replace(/^#/,"")?!0:ce.title.toLowerCase().includes(K)):g},[g,v]),de=Be.useMemo(()=>{const K=v.trim().toLowerCase();return K?y.filter(ce=>String(ce.number)===K.replace(/^#/,"")?!0:ce.title.toLowerCase().includes(K)):y},[y,v]),X=c&&o?.connected===!0,F=()=>{p("github"),d(!0)},V=K=>{N(K),M(null)},q=K=>{M(K),N(null)},te=()=>{C?n({type:"issue",item:C}):T&&n({type:"pr",item:T,includeDiff:R}),e(!1)},U=()=>{N(null),M(null),L(!1)},ae=C||T&&$.get(T.head??"")?.isValid!==!1,je=K=>K.head?$.get(K.head)?.isValid===!1:!0,oe=s.jsx(s.Fragment,{children:X?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"relative mt-2",children:[s.jsx(I,{name:"search",className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),s.jsx(Kt,{value:v,onChange:K=>x(K.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:[D&&s.jsx("div",{className:"flex items-center justify-center h-full",children:s.jsx(I,{name:"loader-4",className:"h-5 w-5 animate-spin text-muted-foreground"})}),E&&s.jsx("div",{className:"flex items-center justify-center h-full",children:s.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-md bg-destructive/10 text-destructive",children:[s.jsx(I,{name:"error-warning",className:"h-4 w-4"}),s.jsx("span",{className:"typography-small",children:E})]})}),!D&&!E&&b==="issues"&&s.jsxs("div",{className:"space-y-0.5 min-h-full",children:[Q.length>0?Q.map(K=>s.jsx("button",{onClick:()=>V(K),className:me("w-full text-left px-2 py-1.5 rounded transition-colors",C?.number===K.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:["#",K.number]}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("span",{className:"typography-small line-clamp-2",children:K.title}),K.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:[K.sourceRepo.owner,"/",K.sourceRepo.repo]}):null]})]})},`${K.sourceRepo?.owner??""}-${K.sourceRepo?.repo??""}-${K.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")}),ee&&!S&&s.jsx("div",{className:"flex justify-center pt-2",children:s.jsx(we,{variant:"ghost",size:"sm",onClick:()=>{re()},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(I,{name:"loader-4",className:"h-4 w-4 animate-spin text-muted-foreground"})})]}),!D&&!E&&b==="prs"&&s.jsxs("div",{className:"space-y-0.5 min-h-full",children:[de.length>0?de.map(K=>{const ce=je(K),Z=K.head?$.get(K.head):void 0;return s.jsx("button",{onClick:()=>!ce&&q(K),disabled:ce,className:me("w-full text-left px-2 py-1.5 rounded transition-colors",T?.number===K.number?"bg-interactive-selection text-interactive-selection-foreground":ce?"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:["#",K.number]}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("span",{className:"typography-small line-clamp-1",children:K.title}),s.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[s.jsxs("span",{className:"typography-micro text-muted-foreground",children:[K.head," → ",K.base]}),K.sourceRepo?.source==="upstream"?s.jsxs("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info",children:[K.sourceRepo.owner,"/",K.sourceRepo.repo]}):null,ce&&Z?.error&&s.jsx("span",{className:"typography-micro text-destructive",children:Z.error})]})]})]})},`${K.sourceRepo?.owner??""}-${K.sourceRepo?.repo??""}-${K.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")}),ee&&!S&&s.jsx("div",{className:"flex justify-center pt-2",children:s.jsx(we,{variant:"ghost",size:"sm",onClick:()=>{re()},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(I,{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(I,{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(we,{onClick:F,size:"sm",children:r("session.githubIntegration.connect.action")})]})}),ve=s.jsxs("div",{className:me("w-full",a?"flex flex-col gap-2":"flex flex-row items-center"),children:[s.jsxs("div",{className:me("flex items-center gap-4",a?"w-full justify-center order-1":"flex-1"),children:[!a&&(C||T)&&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(I,{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:C?r("session.githubIntegration.selected.issueNumber",{number:C.number}):r("session.githubIntegration.selected.prNumber",{number:T?.number??""})}),s.jsx("button",{onClick:U,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:s.jsx(I,{name:"close",className:"h-3.5 w-3.5"})})]}),b==="prs"&&T&&s.jsxs("label",{className:"flex items-center gap-2 cursor-pointer h-8",children:[s.jsx(xs,{checked:R,onChange:K=>L(K),ariaLabel:r("session.githubIntegration.includeDiffAria")}),s.jsx("span",{className:"typography-small text-foreground",children:r("session.githubIntegration.includeDiff")})]})]}),s.jsxs("div",{className:me("flex gap-2",a?"w-full order-2":"justify-end"),children:[s.jsx(we,{variant:"outline",size:"sm",onClick:()=>e(!1),className:me(a&&"flex-1"),children:r("session.githubIntegration.actions.cancel")}),s.jsx(we,{size:"sm",onClick:te,disabled:!ae,className:me(a&&"flex-1"),children:r("session.githubIntegration.actions.select")})]})]});return s.jsx(s.Fragment,{children:a?s.jsx(Pr,{open:t,title:r("session.githubIntegration.title"),onClose:()=>e(!1),footer:X?ve:void 0,renderHeader:K=>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")}),K]}),s.jsx("div",{className:"w-full",children:s.jsx(Ar,{items:[{id:"issues",label:r("session.githubIntegration.tabs.issues"),icon:s.jsx(I,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"prs",label:r("session.githubIntegration.tabs.pullRequests"),icon:s.jsx(I,{name:"git-pull-request",className:"h-3.5 w-3.5"})}],activeId:b,onSelect:ce=>{f(ce),x("")},variant:"active-pill",layoutMode:"fit"})}),(C||T)&&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(I,{name:"check",className:"h-3.5 w-3.5 text-status-success shrink-0"}),s.jsx("span",{className:"typography-small truncate flex-1",children:C?r("session.githubIntegration.selected.issueNumber",{number:C.number}):r("session.githubIntegration.selected.prNumber",{number:T?.number??""})}),s.jsx("button",{onClick:U,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:s.jsx(I,{name:"close",className:"h-3.5 w-3.5"})})]})]}),children:oe}):s.jsx(ws,{open:t,onOpenChange:e,children:s.jsxs(vs,{className:"max-w-2xl max-h-[70vh] flex flex-col",children:[s.jsx(Cs,{className:"flex flex-row items-center justify-between",children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsxs(js,{className:"flex items-center gap-2 shrink-0",children:[s.jsx(I,{name:"github",className:"h-5 w-5"}),r("session.githubIntegration.title")]}),s.jsx("div",{className:"w-[220px]",children:s.jsx(Ar,{items:[{id:"issues",label:r("session.githubIntegration.tabs.issues"),icon:s.jsx(I,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"prs",label:r("session.githubIntegration.tabs.pullRequests"),icon:s.jsx(I,{name:"git-pull-request",className:"h-3.5 w-3.5"})}],activeId:b,onSelect:K=>{f(K),x("")},variant:"active-pill",layoutMode:"fit"})})]})}),oe,s.jsx(Ks,{className:"mt-1",children:ve})]})})})}const Fi=t=>t.trim().replace(/^refs\/heads\//,"").replace(/^heads\//,"").replace(/\s+/g,"-").replace(/^\/+|\/+$/g,""),On=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),Vp="oc:lastWorktreeSourceBranch",U4=t=>String(t).trim().toLowerCase().replace(/[^a-z0-9._-]+/g,"-").replace(/-+/g,"-").replace(/^-+|-+$/g,"")||"pr-head",zp=(t,e,n)=>{const r=Fi(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-${U4(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}`}},W4=t=>{const e={repo:t.repo??null,issue:t.issue,comments:t.comments};return`GitHub issue context (JSON)
178
- ${JSON.stringify(e,null,2)}`},K4=t=>`GitHub pull request context (JSON)
179
- ${JSON.stringify(t,null,2)}`;function H4({open:t,onOpenChange:e,onWorktreeCreated:n}){const{t:r}=pt(),{github:a,git:i}=_n(),o=Te(xe=>xe.isMobile),c=Kn(xe=>xe.status),d=Kn(xe=>xe.hasChecked),p=Fs(xe=>xe.getActiveProject()),m=p?.path??null,u=Be.useMemo(()=>m&&p?{id:p.id,path:m}:null,[p,m]),[h,b]=Be.useState("new-branch"),[f,v]=Be.useState({branchName:"",worktreeName:"",isSyncingWorktreeName:!0,sourceBranch:"",linkedIssue:null,linkedPr:null,includePrDiff:!1}),[x,g]=Be.useState({selectedBranch:"",worktreeName:""}),w=Td(m),y=Jh(m),k=nn(xe=>xe.fetchBranches),D=Be.useMemo(()=>w?.all?w.all.filter(xe=>!xe.startsWith("remotes/")).sort():[],[w]),j=Be.useMemo(()=>w?.all?w.all.filter(xe=>xe.startsWith("remotes/")).map(xe=>xe.replace(/^remotes\//,"")).sort():[],[w]),S=Vt(xe=>xe.availableWorktreesByProject),A=Be.useMemo(()=>{if(!m)return new Set;const xe=S.get(m)??[];return new Set(xe.map(De=>De.name))},[S,m]),E=Be.useCallback((xe=10)=>{for(let De=0;De<xe;De++){const Ye=Xl();if(!A.has(Ye))return Ye}return`${Xl()}-${Date.now().toString(36).slice(-4)}`},[A]),[P,C]=Be.useState(!1),[N,T]=Be.useState(!1),[M,R]=Be.useState(!1),[L,$]=Be.useState(!1),[B,O]=Be.useState(!1),[_,ee]=Be.useState(""),[z,ne]=Be.useState(""),re=Be.useRef(null),ue=Be.useRef(null),Q=Be.useRef(null),de=Be.useRef(null),X=Be.useCallback(xe=>{let De=xe;for(;De&&De!==document.body;){const{overflowY:Ye}=window.getComputedStyle(De);if((Ye==="auto"||Ye==="scroll")&&De.scrollHeight>De.clientHeight)return De;De=De.parentElement}return null},[]),F=Be.useCallback(xe=>{xe&&(xe.scrollTop=0)},[]),V=Be.useCallback(xe=>{const De=xe.current?.querySelector('[data-slot="command-list"]')??null;F(De)},[F]),q=Be.useCallback(xe=>{const De=X(xe.current);F(De)},[X,F]),te=Be.useMemo(()=>_p({localBranches:D,remoteBranches:j,query:_}),[D,j,_]),U=Be.useMemo(()=>_p({localBranches:D,remoteBranches:j,query:z}),[D,j,z]),ae=_.trim().length>0,je=z.trim().length>0,oe=te.matching.length>0,ve=U.matching.length>0,K=!!(m&&i),ce=Be.useCallback(()=>{!m||!i||k(m,i)},[m,i,k]);Be.useEffect(()=>{!N&&!L&&ee("")},[N,L]),Be.useEffect(()=>{!M&&!B&&ne("")},[M,B]),Be.useEffect(()=>{N&&V(re),L&&q(Q)},[N,L,_,V,q]),Be.useEffect(()=>{M&&V(ue),B&&q(de)},[M,B,z,V,q]);const[Z,le]=Be.useState({isValidating:!1,branchError:null,worktreeError:null,touched:!1}),[se,Ie]=Be.useState(!1),[Ne,Y]=Be.useState(null),fe=Be.useCallback(()=>{const xe=gt.getState(),De=xe.getVisibleAgents();if(xe.settingsDefaultAgent){const Ye=De.find(rt=>rt.name===xe.settingsDefaultAgent);if(Ye)return Ye.name}return De.find(Ye=>Ye.name==="build")?.name||De[0]?.name},[]),ke=Be.useCallback(()=>{const xe=gt.getState(),De=xe.settingsDefaultModel;if(!De)return null;const Ye=ui(De);if(!Ye)return null;const{providerId:rt,modelId:Re}=Ye;return xe.getModelMetadata(rt,Re)?{providerID:rt,modelID:Re}:null},[]),be=Be.useCallback((xe,De)=>{const Ye=gt.getState(),rt=Ye.settingsDefaultVariant;if(!rt)return;const qe=Ye.providers.find(et=>et.id===xe)?.models.find(et=>et.id===De)?.variants;if(qe&&Object.prototype.hasOwnProperty.call(qe,rt))return rt},[]),pe=Be.useCallback(xe=>{const De=gt.getState();try{go.getState().saveSessionModelSelection(xe.sessionId,xe.providerID,xe.modelID)}catch{}if(xe.agentName){try{De.setAgent(xe.agentName)}catch{}try{go.getState().saveSessionAgentSelection(xe.sessionId,xe.agentName)}catch{}try{go.getState().saveAgentModelForSession(xe.sessionId,xe.agentName,xe.providerID,xe.modelID)}catch{}if(xe.variant!==void 0){try{De.setCurrentVariant(xe.variant)}catch{}try{go.getState().saveAgentModelVariantForSession(xe.sessionId,xe.agentName,xe.providerID,xe.modelID,xe.variant)}catch{}}}},[]),Ee=Be.useCallback(async xe=>{if(!m||!a)return;const De=gt.getState(),Ye=Nl.getState().lastUsedProvider,rt=ke(),Re=rt?.providerID||De.currentProviderId||Ye?.providerID,he=rt?.modelID||De.currentModelId||Ye?.modelID,qe=fe()||De.currentAgentName||void 0;if(!Re||!he){H.error(r("session.newWorktree.error.noModelSelected"));return}const et=be(Re,he);if(pe({sessionId:xe.sessionId,providerID:Re,modelID:he,agentName:qe,variant:et}),xe.issue){if(!a.issueGet||!a.issueComments)return;const Ke=await a.issueGet(m,xe.issue.number);if(Ke.connected===!1||!Ke.repo||!Ke.issue)throw new Error("Failed to load issue context");const st=await a.issueComments(m,xe.issue.number);if(st.connected===!1)throw new Error("Failed to load issue comments");const nt=await kn("github.issue.review.visible",{issue_number:String(xe.issue.number)}),ye=await kn("github.issue.review.instructions"),Je=W4({repo:Ke.repo,issue:Ke.issue,comments:st.comments??[]});await rn.sendMessage({id:xe.sessionId,providerID:Re,modelID:he,agent:qe,variant:et,text:nt,additionalParts:[{text:ye,synthetic:!0},{text:Je,synthetic:!0}]}),H.success(r("session.newWorktree.toast.sessionFromIssue"));return}if(xe.pr){if(!a.prContext)return;const Ke=await a.prContext(m,xe.pr.number,{includeDiff:xe.includeDiff,includeCheckDetails:!1});if(Ke.connected===!1||!Ke.repo||!Ke.pr)throw new Error("Failed to load PR context");const st=await kn("github.pr.review.visible",{pr_number:String(xe.pr.number)}),nt=await kn("github.pr.review.instructions"),ye=K4(Ke);await rn.sendMessage({id:xe.sessionId,providerID:Re,modelID:he,agent:qe,variant:et,text:st,additionalParts:[{text:nt,synthetic:!0},{text:ye,synthetic:!0}]}),H.success(r("session.newWorktree.toast.sessionFromPr"))}},[pe,a,m,fe,ke,be,r]),ze=h==="new-branch"?f:x;Be.useEffect(()=>{if(!w?.all||!m||f.sourceBranch)return;(async()=>{try{const De=await to(m).catch(()=>null),Ye=localStorage.getItem(Vp),rt=Ye&&w.all?.includes(Ye)?Ye:De&&w.all?.includes(De)?De:w.all?.includes("main")?"main":w.all?.includes("master")?"master":w.all?.[0]||"";rt&&v(Re=>({...Re,sourceBranch:rt}))}catch{}})()},[w,m,f.sourceBranch]),Be.useEffect(()=>{if(!t)return;b("new-branch"),g({selectedBranch:"",worktreeName:""}),T(!1),R(!1),$(!1),O(!1),ee(""),ne(""),le({isValidating:!1,branchError:null,worktreeError:null,touched:!1});const xe=E();v({branchName:xe,worktreeName:xe,isSyncingWorktreeName:!0,sourceBranch:"",linkedIssue:null,linkedPr:null,includePrDiff:!1})},[t,E]),Be.useEffect(()=>{if(h!=="new-branch"||!f.isSyncingWorktreeName)return;const xe=Fi(f.branchName),De=On(xe);v(Ye=>({...Ye,worktreeName:De}))},[h,f.branchName,f.isSyncingWorktreeName]);const G=Be.useCallback(async()=>{if(!u||!Z.touched||se)return;Ne&&Ne.abort();const xe=new AbortController;Y(xe),le(De=>({...De,isValidating:!0}));try{const De=h==="new-branch"?f.branchName:x.selectedBranch,Ye=ze.worktreeName,rt=Fi(De),Re=On(Ye);let he=null,qe=null;if(rt||(he=r("session.newWorktree.error.branchNameRequired")),Re||(qe=r("session.newWorktree.error.worktreeDirectoryRequired")),rt&&Re){const et=h==="new-branch"?f.linkedPr:null,Ke=et?zp(et,D,j):null,st=await qh(u,{mode:h==="existing-branch"||Ke?"existing":"new",branchName:rt,worktreeName:Re,existingBranch:Ke?.existingBranch??(h==="existing-branch"?rt:void 0),...Ke?.ensureRemoteName?{ensureRemoteName:Ke.ensureRemoteName}:{},...Ke?.ensureRemoteUrl?{ensureRemoteUrl:Ke.ensureRemoteUrl}:{}});if(xe.signal.aborted)return;st.ok||st.errors.forEach(nt=>{if(nt.code==="worktree_exists"){qe=qe??nt.message;return}nt.code.startsWith("branch_")&&(he=he??nt.message)})}xe.signal.aborted||le(et=>({...et,isValidating:!1,branchError:he,worktreeError:qe}))}catch{xe.signal.aborted||le(De=>({...De,isValidating:!1}))}},[u,h,f.branchName,f.linkedPr,x.selectedBranch,ze.worktreeName,D,j,Z.touched,Ne,se,r]),Pe=h==="new-branch"?f.branchName:x.selectedBranch;Be.useEffect(()=>{if(!t||!u||!Z.touched||se)return;const xe=setTimeout(()=>{G()},300);return()=>clearTimeout(xe)},[ze.worktreeName,Pe,t,u,G,Z.touched,se]);const Le=async()=>{if(!u||!m){H.error(r("session.newWorktree.error.noActiveProject"));return}le(Re=>({...Re,touched:!0}));const xe=h==="new-branch"?f.branchName:x.selectedBranch,De=ze.worktreeName,Ye=Fi(xe),rt=On(De);if(!Ye){H.error(r("session.newWorktree.error.branchNameRequired"));return}if(!rt){H.error(r("session.newWorktree.error.worktreeDirectoryRequired"));return}Ne&&(Ne.abort(),Y(null)),le(Re=>({...Re,isValidating:!1,branchError:null,worktreeError:null})),Ie(!0);try{const Re=await $d(u),he=h==="new-branch"?f.linkedPr:null,qe=f.sourceBranch;let et="";const Ke=(()=>{if(he){const ot=zp(he,D,j);return et=ot.sourceLabel,{preferredName:Ye||rt,mode:"existing",branchName:Ye,worktreeName:rt,existingBranch:ot.existingBranch,setupCommands:Re,setUpstream:ot.setUpstream,upstreamRemote:ot.upstreamRemote,upstreamBranch:ot.upstreamBranch,...ot.ensureRemoteName?{ensureRemoteName:ot.ensureRemoteName}:{},...ot.ensureRemoteUrl?{ensureRemoteUrl:ot.ensureRemoteUrl}:{}}}return et=h==="new-branch"?qe:"",{preferredName:Ye||rt,mode:h==="existing-branch"?"existing":"new",branchName:h==="existing-branch"?void 0:Ye,worktreeName:rt,existingBranch:h==="existing-branch"?Ye:void 0,setupCommands:Re,...qe&&h==="new-branch"?{startRef:qe}:{}}})(),st=await ty(m,Ke),nt=await sy(u,st),ye=h==="new-branch"?f.linkedIssue:null,Je=h==="new-branch"?f.linkedPr:null,_e=h==="new-branch"?f.includePrDiff:!1;let Ue=null;if(ye||Je){const ot=ye?`#${ye.number} ${ye.title}`.trim():Je?`#${Je.number} ${Je.title}`.trim():r("session.newWorktree.newSessionTitle"),Xe=await ny(ot,nt.path,null);if(!Xe?.id)throw new Error("Failed to create session");Ue=Xe.id,ry(Xe.id,ot).catch(()=>{});try{Vt.getState().initializeNewOpenChamberSession(Xe.id,gt.getState().agents)}catch{}}f.sourceBranch&&h==="new-branch"&&!f.linkedPr&&localStorage.setItem(Vp,f.sourceBranch),H.success(r("session.newWorktree.toast.worktreeCreated"),{description:r("session.newWorktree.toast.worktreeCreatedDescription",{target:`${nt.branch||nt.name}${et?` ${r("session.newWorktree.fromSource",{source:et})}`:""}`})}),e(!1),Ue?(n?.(nt.path,{sessionId:Ue}),Ee({sessionId:Ue,issue:ye,pr:Je,includeDiff:_e}).catch(ot=>{const Xe=ot instanceof Error?ot.message:r("session.newWorktree.error.sendGitHubContextFailed");H.error(r("session.newWorktree.error.sendGitHubContextFailed"),{description:Xe})})):n?.(nt.path)}catch(Re){const he=Re instanceof Error?Re.message:r("session.newWorktree.error.createWorktreeFailed");H.error(r("session.newWorktree.error.createWorktreeFailed"),{description:he})}finally{Ie(!1)}},Ae=xe=>{b(xe),le(De=>({...De,touched:!1,branchError:null,worktreeError:null}))},ge=xe=>{if(!xe){v(De=>({...De,linkedIssue:null,linkedPr:null,includePrDiff:!1,branchName:""}));return}if(xe.type==="issue"){const De=xe.item,Ye=`issue-${De.number}-${Xl()}`;v(rt=>({...rt,linkedIssue:De,linkedPr:null,includePrDiff:!1,branchName:Ye,worktreeName:On(Ye),isSyncingWorktreeName:!0}))}else if(xe.type==="pr"){const De=xe.item;v(Ye=>({...Ye,linkedPr:De,linkedIssue:null,includePrDiff:xe.includeDiff??!1,branchName:De.head,worktreeName:On(De.head),isSyncingWorktreeName:!0}))}},W=d&&c?.connected===!0,Me=(h==="existing-branch"?!!x.selectedBranch&&!!x.worktreeName&&!Z.branchError&&!Z.worktreeError:!!Fi(f.branchName)&&!!f.worktreeName&&!Z.branchError&&!Z.worktreeError)&&!se,Ve=()=>{v(xe=>({...xe,linkedIssue:null,linkedPr:null,branchName:"",includePrDiff:!1,isSyncingWorktreeName:!0}))},Ce=s.jsxs("div",{className:me("flex gap-2",o?"flex-col w-full":"flex-row items-center"),children:[s.jsx("div",{className:me("flex items-center gap-1.5 text-destructive",o?"w-full justify-center order-first":"mr-auto"),children:Z.touched&&(Z.branchError||Z.worktreeError)&&s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"error-warning",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"typography-micro",children:Z.branchError||Z.worktreeError})]})}),s.jsxs("div",{className:me("flex gap-2",o&&"w-full"),children:[s.jsx(we,{variant:"outline",size:"sm",onClick:()=>e(!1),disabled:se,className:me(o&&"flex-1"),children:r("session.newWorktree.actions.cancel")}),s.jsxs(we,{size:"sm",onClick:Le,disabled:!Me||se,className:me("gap-1.5",o&&"flex-1"),children:[se&&s.jsx(I,{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(Pr,{open:t,title:r("session.newWorktree.title"),onClose:()=>e(!1),footer:Ce,children:[s.jsx("div",{className:"w-full mb-4",children:s.jsx(Ar,{items:[{id:"new-branch",label:r("session.newWorktree.mode.newBranch"),icon:s.jsx(I,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"existing-branch",label:r("session.newWorktree.mode.existingBranch"),icon:s.jsx(I,{name:"git-repository",className:"h-3.5 w-3.5"})}],activeId:h,onSelect:xe=>Ae(xe),variant:"active-pill",layoutMode:"fit",className:"w-full"})}),s.jsxs("div",{className:"space-y-6",children:[h==="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(we,{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(I,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"})]}),s.jsx(we,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0 shrink-0",onClick:ce,disabled:!K||y,title:r("session.newWorktree.fetchBranches"),children:y?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"refresh",className:"size-4"})})]}),s.jsx(Pr,{open:L,title:r("session.newWorktree.selectBranch"),onClose:()=>$(!1),children:s.jsxs("div",{className:"space-y-4",ref:Q,children:[s.jsx(Kt,{value:_,onChange:xe=>ee(xe.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")}):D.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:[ae&&oe&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:r("session.newWorktree.matchingBranches")}),s.jsx("div",{className:"space-y-1",children:te.matching.map(xe=>s.jsx("button",{onClick:()=>{g(De=>({...De,selectedBranch:xe.value,worktreeName:On(xe.label)})),le(De=>({...De,touched:!0})),$(!1)},className:me("w-full text-left px-3 py-2.5 rounded-md transition-colors",x.selectedBranch===xe.value?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:xe.label})},`${xe.source}-${xe.value}`))})]}),ae&&!oe&&s.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),te.otherLocal.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:r(ae?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches")}),s.jsx("div",{className:"space-y-1",children:te.otherLocal.map(xe=>s.jsx("button",{onClick:()=>{g(De=>({...De,selectedBranch:xe,worktreeName:On(xe)})),le(De=>({...De,touched:!0})),$(!1)},className:me("w-full text-left px-3 py-2.5 rounded-md transition-colors",x.selectedBranch===xe?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:xe})},xe))})]}),te.otherRemote.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:r(ae?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches")}),s.jsx("div",{className:"space-y-1",children:te.otherRemote.map(xe=>s.jsx("button",{onClick:()=>{g(De=>({...De,selectedBranch:`remotes/${xe}`,worktreeName:On(xe)})),le(De=>({...De,touched:!0})),$(!1)},className:me("w-full text-left px-3 py-2.5 rounded-md transition-colors",x.selectedBranch===`remotes/${xe}`?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:xe})},`remotes/${xe}`))})]})]})]})})]}):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")}),h==="new-branch"&&W&&s.jsxs(we,{variant:"outline",size:"sm",onClick:()=>C(!0),className:"gap-1.5 h-7",children:[s.jsx(I,{name:"github",className:"size-4 text-status-success"}),f.linkedIssue||f.linkedPr?r("session.newWorktree.actions.change"):r("session.newWorktree.actions.startFromGitHubIssuePr")]})]}),s.jsx(Kt,{value:f.branchName,onChange:xe=>{v(De=>({...De,branchName:xe.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>le(xe=>({...xe,touched:!0})),placeholder:r("session.newWorktree.branchNamePlaceholder"),disabled:!!f.linkedPr,className:me("h-8",Z.touched&&Z.branchError&&"border-destructive",f.linkedPr&&"bg-muted text-muted-foreground")}),f.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(I,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),s.jsx("span",{className:"typography-micro",children:r("session.newWorktree.usingPrBranch",{branch:f.linkedPr.head})})]}),f.linkedIssue&&!f.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(I,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),s.jsx("span",{className:"typography-micro",children:r("session.newWorktree.fromIssue",{number:f.linkedIssue.number,title:f.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")}),h!=="existing-branch"&&s.jsxs("button",{onClick:()=>{const xe=On(h==="new-branch"?f.branchName:"");v(De=>({...De,worktreeName:xe,isSyncingWorktreeName:!0}))},disabled:!f.branchName||f.worktreeName===On(f.branchName),className:me("flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded",f.worktreeName===On(f.branchName)||!f.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(I,{name:"refresh",className:"h-3 w-3"}),s.jsx("span",{children:r("session.newWorktree.actions.reset")})]})]}),s.jsx(Kt,{value:ze.worktreeName,onChange:xe=>{h==="new-branch"?v(De=>({...De,worktreeName:xe.target.value,isSyncingWorktreeName:!1})):g(De=>({...De,worktreeName:xe.target.value}))},onBlur:()=>le(xe=>({...xe,touched:!0})),placeholder:r("session.newWorktree.worktreeDirectoryPlaceholder"),className:me("h-8",Z.touched&&Z.worktreeError&&"border-destructive")})]}),h==="new-branch"&&!f.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(we,{variant:"outline",size:"sm",onClick:()=>O(!0),className:"w-full justify-between h-9",children:[s.jsx("span",{className:f.sourceBranch?"text-foreground":"text-muted-foreground",children:f.sourceBranch||r("session.newWorktree.selectSourceBranchPlaceholder")}),s.jsx(I,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"})]}),f.sourceBranch&&s.jsx("div",{className:"typography-micro text-muted-foreground",children:r("session.newWorktree.newBranchFromSource",{source:f.sourceBranch})}),s.jsx(Pr,{open:B,title:r("session.newWorktree.selectSourceBranch"),onClose:()=>O(!1),children:s.jsxs("div",{className:"space-y-4",ref:de,children:[s.jsx(Kt,{value:z,onChange:xe=>ne(xe.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")}):D.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:[je&&ve&&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:U.matching.map(xe=>s.jsx("button",{onClick:()=>{v(De=>({...De,sourceBranch:xe.value})),O(!1)},className:me("w-full text-left px-3 py-2.5 rounded-md transition-colors",f.sourceBranch===xe.value?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:xe.label})},`${xe.source}-${xe.value}`))})]}),je&&!ve&&s.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),U.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(je?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches")}),s.jsx("div",{className:"space-y-1",children:U.otherLocal.map(xe=>s.jsx("button",{onClick:()=>{v(De=>({...De,sourceBranch:xe})),O(!1)},className:me("w-full text-left px-3 py-2.5 rounded-md transition-colors",f.sourceBranch===xe?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:xe})},xe))})]}),U.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(je?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches")}),s.jsx("div",{className:"space-y-1",children:U.otherRemote.map(xe=>s.jsx("button",{onClick:()=>{v(De=>({...De,sourceBranch:`remotes/${xe}`})),O(!1)},className:me("w-full text-left px-3 py-2.5 rounded-md transition-colors",f.sourceBranch===`remotes/${xe}`?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:xe})},`remotes/${xe}`))})]})]})]})})]}),(f.linkedIssue||f.linkedPr)&&h==="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(I,{name:"github",className:"h-3.5 w-3.5 text-status-success shrink-0"}),f.linkedIssue&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.issueNumber",{number:f.linkedIssue.number})}),f.linkedPr&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.prNumber",{number:f.linkedPr.number})}),s.jsx("span",{className:"typography-micro text-foreground truncate flex-1",children:f.linkedIssue?.title||f.linkedPr?.title}),s.jsx("a",{href:f.linkedIssue?.url||f.linkedPr?.url,target:"_blank",rel:"noopener noreferrer",className:"text-muted-foreground hover:text-foreground shrink-0",onClick:xe=>xe.stopPropagation(),children:s.jsx(I,{name:"external-link",className:"h-3 w-3"})}),s.jsx("button",{onClick:Ve,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:s.jsx(I,{name:"close",className:"h-3.5 w-3.5"})})]}),f.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:[f.linkedPr.head," → ",f.linkedPr.base]}),f.includePrDiff&&s.jsx("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-success/10 text-status-success",children:r("session.newWorktree.includeDiffBadge")})]})]})]})]}):s.jsx(ws,{open:t,onOpenChange:e,children:s.jsxs(vs,{className:"max-w-lg max-h-[80vh] flex flex-col",children:[s.jsx(Cs,{className:"flex flex-row items-center justify-between",children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsxs(js,{className:"flex items-center gap-2 shrink-0",children:[s.jsx(I,{name:"git-branch",className:"h-5 w-5"}),r("session.newWorktree.title")]}),s.jsx("div",{className:"w-[280px] shrink-0",children:s.jsx(Ar,{items:[{id:"new-branch",label:r("session.newWorktree.mode.newBranch"),icon:s.jsx(I,{name:"git-branch",className:"h-3.5 w-3.5"})},{id:"existing-branch",label:r("session.newWorktree.mode.existingBranch"),icon:s.jsx(I,{name:"git-repository",className:"h-3.5 w-3.5"})}],activeId:h,onSelect:xe=>Ae(xe),variant:"active-pill",layoutMode:"fit",className:"w-full"})})]})}),s.jsxs("div",{className:"flex-1 overflow-y-auto mt-2 space-y-6",children:[h==="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(Bs,{open:N,onOpenChange:T,children:[s.jsx(Os,{asChild:!0,children:s.jsxs(we,{variant:"outline",size:"sm",className:"h-9 min-w-[220px] max-w-full justify-between gap-2",children:[s.jsx("span",{className:me("truncate",x.selectedBranch?"text-foreground":"text-muted-foreground"),children:x.selectedBranch||r("session.newWorktree.chooseBranch")}),s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4 shrink-0 text-muted-foreground"})]})}),s.jsx($s,{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:re,children:s.jsxs(Ta,{shouldFilter:!1,children:[s.jsx(ra,{placeholder:r("session.newWorktree.searchBranches"),value:_,onValueChange:ee}),s.jsx(Ma,{disableHorizontal:!0,children:y?s.jsx("div",{className:"px-2 py-4 text-center typography-small text-muted-foreground",children:r("session.newWorktree.loadingBranches")}):D.length===0&&j.length===0?s.jsx(Ea,{children:r("session.newWorktree.noBranchesFound")}):s.jsxs(s.Fragment,{children:[ae&&oe&&s.jsx(Bn,{heading:r("session.newWorktree.matchingBranches"),children:te.matching.map(xe=>s.jsx(An,{value:xe.value,onSelect:()=>{g(De=>({...De,selectedBranch:xe.value,worktreeName:On(xe.label)})),le(De=>({...De,touched:!0})),T(!1)},children:s.jsx("span",{className:"typography-small break-all",children:xe.label})},`${xe.source}-${xe.value}`))}),ae&&!oe&&s.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),te.otherLocal.length>0&&s.jsxs(s.Fragment,{children:[ae&&s.jsx(va,{}),s.jsx(Bn,{heading:r(ae?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches"),children:te.otherLocal.map(xe=>s.jsx(An,{value:xe,onSelect:()=>{g(De=>({...De,selectedBranch:xe,worktreeName:On(xe)})),le(De=>({...De,touched:!0})),T(!1)},children:s.jsx("span",{className:"typography-small break-all",children:xe})},`local-${xe}`))})]}),te.otherRemote.length>0&&s.jsxs(s.Fragment,{children:[(te.otherLocal.length>0||ae)&&s.jsx(va,{}),s.jsx(Bn,{heading:r(ae?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches"),children:te.otherRemote.map(xe=>s.jsx(An,{value:`remotes/${xe}`,onSelect:()=>{g(De=>({...De,selectedBranch:`remotes/${xe}`,worktreeName:On(xe)})),le(De=>({...De,touched:!0})),T(!1)},children:s.jsx("span",{className:"typography-small break-all",children:xe})},`remote-${xe}`))})]})]})})]})})]}),s.jsx(we,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0 shrink-0",onClick:ce,disabled:!K||y,title:r("session.newWorktree.fetchBranches"),children:y?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{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")}),h==="new-branch"&&W&&s.jsxs(we,{variant:"outline",size:"sm",onClick:()=>C(!0),className:"gap-1.5 h-7",children:[s.jsx(I,{name:"github",className:"size-4 text-status-success"}),f.linkedIssue||f.linkedPr?r("session.newWorktree.actions.change"):r("session.newWorktree.actions.startFromGitHubIssuePr")]})]}),s.jsx(Kt,{value:f.branchName,onChange:xe=>{v(De=>({...De,branchName:xe.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>le(xe=>({...xe,touched:!0})),placeholder:r("session.newWorktree.branchNamePlaceholder"),disabled:!!f.linkedPr,className:me("h-8",Z.touched&&Z.branchError&&"border-destructive",f.linkedPr&&"bg-muted text-muted-foreground")}),f.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(I,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),s.jsx("span",{className:"typography-micro",children:r("session.newWorktree.usingPrBranch",{branch:f.linkedPr.head})})]}),f.linkedIssue&&!f.linkedPr&&s.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[s.jsx(I,{name:"check",className:"h-3.5 w-3.5 text-status-success"}),s.jsx("span",{className:"typography-micro",children:r("session.newWorktree.fromIssue",{number:f.linkedIssue.number,title:f.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")}),h!=="existing-branch"&&s.jsxs("button",{onClick:()=>{const xe=On(h==="new-branch"?f.branchName:"");v(De=>({...De,worktreeName:xe,isSyncingWorktreeName:!0}))},disabled:!f.branchName||f.worktreeName===On(f.branchName),className:me("flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded",f.worktreeName===On(f.branchName)||!f.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(I,{name:"refresh",className:"h-3 w-3"}),s.jsx("span",{children:r("session.newWorktree.actions.reset")})]})]}),s.jsx(Kt,{value:ze.worktreeName,onChange:xe=>{h==="new-branch"?v(De=>({...De,worktreeName:xe.target.value,isSyncingWorktreeName:!1})):g(De=>({...De,worktreeName:xe.target.value}))},onBlur:()=>le(xe=>({...xe,touched:!0})),placeholder:r("session.newWorktree.worktreeDirectoryPlaceholder"),className:me("h-8",Z.touched&&Z.worktreeError&&"border-destructive")})]}),h==="new-branch"&&!f.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(Bs,{open:M,onOpenChange:R,children:[s.jsx(Os,{asChild:!0,children:s.jsxs(we,{variant:"outline",size:"sm",className:"h-9 min-w-[220px] max-w-full justify-between gap-2",children:[s.jsx("span",{className:me("truncate",f.sourceBranch?"text-foreground":"text-muted-foreground"),children:f.sourceBranch||r("session.newWorktree.selectSourceBranchPlaceholder")}),s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4 shrink-0 text-muted-foreground"})]})}),s.jsx($s,{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:ue,children:s.jsxs(Ta,{shouldFilter:!1,children:[s.jsx(ra,{placeholder:r("session.newWorktree.searchBranches"),value:z,onValueChange:ne}),s.jsx(Ma,{disableHorizontal:!0,children:y?s.jsx("div",{className:"px-2 py-4 text-center typography-small text-muted-foreground",children:r("session.newWorktree.loadingBranches")}):D.length===0&&j.length===0?s.jsx(Ea,{children:r("session.newWorktree.noBranchesFound")}):s.jsxs(s.Fragment,{children:[je&&ve&&s.jsx(Bn,{heading:r("session.newWorktree.matchingBranches"),children:U.matching.map(xe=>s.jsx(An,{value:xe.value,onSelect:()=>{v(De=>({...De,sourceBranch:xe.value})),R(!1)},children:s.jsx("span",{className:"typography-small break-all",children:xe.label})},`${xe.source}-${xe.value}`))}),je&&!ve&&s.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),U.otherLocal.length>0&&s.jsxs(s.Fragment,{children:[je&&s.jsx(va,{}),s.jsx(Bn,{heading:r(je?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches"),children:U.otherLocal.map(xe=>s.jsx(An,{value:xe,onSelect:()=>{v(De=>({...De,sourceBranch:xe})),R(!1)},children:s.jsx("span",{className:"typography-small break-all",children:xe})},`local-${xe}`))})]}),U.otherRemote.length>0&&s.jsxs(s.Fragment,{children:[(U.otherLocal.length>0||je)&&s.jsx(va,{}),s.jsx(Bn,{heading:r(je?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches"),children:U.otherRemote.map(xe=>s.jsx(An,{value:`remotes/${xe}`,onSelect:()=>{v(De=>({...De,sourceBranch:`remotes/${xe}`})),R(!1)},children:s.jsx("span",{className:"typography-small break-all",children:xe})},`remote-${xe}`))})]})]})})]})})]}),f.sourceBranch&&s.jsx("div",{className:"typography-micro text-muted-foreground",children:r("session.newWorktree.newBranchFromSource",{source:f.sourceBranch})})]}),(f.linkedIssue||f.linkedPr)&&h==="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(I,{name:"github",className:"h-3.5 w-3.5 text-status-success shrink-0"}),f.linkedIssue&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.issueNumber",{number:f.linkedIssue.number})}),f.linkedPr&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:r("session.newWorktree.prNumber",{number:f.linkedPr.number})}),s.jsx("span",{className:"typography-micro text-foreground truncate flex-1",children:f.linkedIssue?.title||f.linkedPr?.title}),s.jsx("a",{href:f.linkedIssue?.url||f.linkedPr?.url,target:"_blank",rel:"noopener noreferrer",className:"text-muted-foreground hover:text-foreground shrink-0",onClick:xe=>xe.stopPropagation(),children:s.jsx(I,{name:"external-link",className:"h-3 w-3"})}),s.jsx("button",{onClick:Ve,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:s.jsx(I,{name:"close",className:"h-3.5 w-3.5"})})]}),f.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:[f.linkedPr.head," → ",f.linkedPr.base]}),f.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(Ks,{className:"mt-1 flex items-center justify-between",children:[s.jsx("div",{className:"flex items-center gap-1.5 text-destructive",children:Z.touched&&(Z.branchError||Z.worktreeError)&&s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"error-warning",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"typography-micro",children:Z.branchError||Z.worktreeError})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(we,{variant:"outline",size:"sm",onClick:()=>e(!1),disabled:se,children:r("session.newWorktree.actions.cancel")}),s.jsxs(we,{size:"sm",onClick:Le,disabled:!Me||se,className:"gap-1.5",children:[se&&s.jsx(I,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),r(se?"session.newWorktree.actions.creating":"session.newWorktree.actions.createWorktree")]})]})]})]})}),s.jsx(z4,{open:P,onOpenChange:C,onSelect:ge})]})}let ri=null,ai=null,Go=null,gl=0;const Ca=new Set,G4=3e4,q4=45e3,fg=()=>{Go&&(clearTimeout(Go),Go=null)},gg=()=>{if(ai||Ca.size===0)return;const t=Math.min(1e3*Math.pow(2,Math.min(gl,5)),G4);ai=setTimeout(()=>{ai=null,gl+=1,xg()},t)},xl=()=>{fg(),ri&&ri.close(),ri=null},Up=()=>{fg(),Ca.size!==0&&(Go=setTimeout(()=>{xl(),gg()},q4))},J4=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}},Q4=t=>{if(t.type==="openchamber:event-stream-ready"){gl=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 Ca)d(c)},xg=()=>{if(typeof window>"u"||Ca.size===0||typeof EventSource!="function"||ri&&ri.readyState!==EventSource.CLOSED)return;xl();const t=new EventSource("/api/openchamber/events");t.onopen=()=>{Up()},t.onmessage=e=>{Up();const n=J4(e.data);n&&Q4(n)},t.onerror=()=>{xl(),gg()},ri=t},bg=t=>(Ca.add(t),xg(),()=>{Ca.delete(t),Ca.size===0&&(ai&&(clearTimeout(ai),ai=null),gl=0,xl())}),El=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},fi=t=>{const e=typeof t=="string"?t.trim():"";if(!e)throw new Error("projectId is required");return e},Y4=async t=>{const e=fi(t),n=await fetch(`/api/projects/${encodeURIComponent(e)}/scheduled-tasks`);if(!n.ok)throw new Error(await El(n,"Failed to load scheduled tasks"));const r=await n.json().catch(()=>null);return!r||!Array.isArray(r.tasks)?[]:r.tasks},Wp=async(t,e)=>{const n=fi(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 El(r,"Failed to save scheduled task"));const a=await r.json().catch(()=>null);return!a||!Array.isArray(a.tasks)?[]:a.tasks},X4=async(t,e)=>{const n=fi(t),r=fi(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 El(a,"Failed to delete scheduled task"));const i=await a.json().catch(()=>null);return!i||!Array.isArray(i.tasks)?[]:i.tasks},Z4=async(t,e)=>{const n=fi(t),r=fi(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 El(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}},yg=[0,1,2,3,4,5,6],Kp=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"],Hp=()=>{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}`},qo=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},Gp=t=>{const e=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${e}-${n}-${r}`},eI=(t,e,n)=>{const r=qo(t);return r?new Intl.DateTimeFormat(n,{month:"short",day:"numeric",year:"numeric"}).format(r):e},qp=(t,e)=>new Date(t.getFullYear(),t.getMonth()+e,1),tI=(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 h=d+u;p.push({date:new Date(n,r-1,h),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},sI=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}},ha=(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")}`},bi=(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"},Jp=t=>/^(0[1-9]|1[0-2])$/.test(t)?t:bi(t,{min:1,max:12}),Ao=t=>/^[0-5][0-9]$/.test(t)?t:bi(t,{max:59}),nI=(t,e)=>bi(String(Number.parseInt(t,10)+e),{min:1,max:12,loop:!0}),Qp=(t,e)=>bi(String(Number.parseInt(t,10)+e),{min:0,max:59,loop:!0}),rI=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}},aI=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}},iI=t=>{const e=new Intl.DateTimeFormat(t,{weekday:"short"}),n=new Date(2023,0,1);return yg.map(r=>e.format(new Date(n.getFullYear(),n.getMonth(),n.getDate()+r)))},oI=(t,e)=>[...t.slice(e),...t.slice(0,e)],gr=t=>{const e=at.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},Yp=t=>{const e=at.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=sI(n),e[0]=n,e[1]=m):m=e[1];const u=m,h=Be.useRef(null),b=Be.useRef(null),[f,v]=Be.useState(null),[x,g]=Be.useState(null),w=Be.useRef(null),y=Be.useRef(null);let k;e[2]===Symbol.for("react.memo_cache_sentinel")?(k=se=>{w.current=se,v(se)},e[2]=k):k=e[2];const D=k;let j;e[3]===Symbol.for("react.memo_cache_sentinel")?(j=se=>{y.current=se,g(se)},e[3]=j):j=e[3];const S=j,A=pI,E=hI,P=fI;let C;e[4]!==r||e[5]!==u.meridiem||e[6]!==u.minute||e[7]!==a?(C=se=>{const Ie=se.replace(/\D/g,"").slice(0,2);D(Ie),Ie.length===2&&(r(a?P(A(Ie),u.minute):ha(Jp(Ie),u.minute,u.meridiem)),D(null),b.current?.focus())},e[4]=r,e[5]=u.meridiem,e[6]=u.minute,e[7]=a,e[8]=C):C=e[8];const N=C;let T;e[9]!==r||e[10]!==u.meridiem||e[11]!==u.minute||e[12]!==a?(T=()=>{const se=w.current;if(se!==null&&(D(null),se.length!==0)){if(a){r(P(A(se.padStart(2,"0")),u.minute));return}r(ha(Jp(se.padStart(2,"0")),u.minute,u.meridiem))}},e[9]=r,e[10]=u.meridiem,e[11]=u.minute,e[12]=a,e[13]=T):T=e[13];const M=T;let R;e[14]!==r||e[15]!==u.hour12||e[16]!==u.hour24||e[17]!==u.meridiem||e[18]!==a?(R=se=>{const Ie=se.replace(/\D/g,"").slice(0,2);S(Ie),Ie.length===2&&(r(a?P(u.hour24,Ao(Ie)):ha(u.hour12,Ao(Ie),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 L=R;let $;e[20]!==r||e[21]!==u.hour12||e[22]!==u.hour24||e[23]!==u.meridiem||e[24]!==a?($=()=>{const se=y.current;se!==null&&(S(null),se.length!==0&&r(a?P(u.hour24,Ao(se.padStart(2,"0"))):ha(u.hour12,Ao(se.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 B=$;let O;e[26]!==r||e[27]!==u.hour12||e[28]!==u.hour24||e[29]!==u.meridiem||e[30]!==u.minute||e[31]!==a?(O=se=>r(a?P(E(u.hour24,se),u.minute):ha(nI(u.hour12,se),u.minute,u.meridiem)),e[26]=r,e[27]=u.hour12,e[28]=u.hour24,e[29]=u.meridiem,e[30]=u.minute,e[31]=a,e[32]=O):O=e[32];const _=O;let ee;e[33]!==r||e[34]!==u.hour12||e[35]!==u.hour24||e[36]!==u.meridiem||e[37]!==u.minute||e[38]!==a?(ee=se=>r(a?P(u.hour24,Qp(u.minute,se)):ha(u.hour12,Qp(u.minute,se),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]=ee):ee=e[39];const z=ee;let ne;e[40]!==r||e[41]!==u.hour12||e[42]!==u.meridiem||e[43]!==u.minute?(ne=se=>{se!==u.meridiem&&r(ha(u.hour12,u.minute,se))},e[40]=r,e[41]=u.hour12,e[42]=u.meridiem,e[43]=u.minute,e[44]=ne):ne=e[44];const re=ne;let ue;e[45]!==M||e[46]!==_?(ue=se=>{if(se.key==="ArrowRight"){se.preventDefault(),M(),b.current?.focus();return}(se.key==="ArrowUp"||se.key==="ArrowDown")&&(se.preventDefault(),D(null),_(se.key==="ArrowUp"?1:-1))},e[45]=M,e[46]=_,e[47]=ue):ue=e[47];const Q=ue;let de;e[48]!==B||e[49]!==z?(de=se=>{if(se.key==="ArrowLeft"&&(se.currentTarget.selectionStart??0)===0){se.preventDefault(),B(),h.current?.focus();return}(se.key==="ArrowUp"||se.key==="ArrowDown")&&(se.preventDefault(),S(null),z(se.key==="ArrowUp"?1:-1))},e[48]=B,e[49]=z,e[50]=de):de=e[50];const X=de,F=a?"px-2":"pl-2 pr-1";let V;e[51]!==F?(V=me("inline-flex h-9 w-fit items-center gap-1 rounded-md border border-border bg-background focus-within:ring-1 focus-within:ring-interactive-focusRing focus-within:border-interactive-focusRing",F),e[51]=F,e[52]=V):V=e[52];const q=f??(a?u.hour24:u.hour12);let te;e[53]!==N?(te=se=>N(se.target.value),e[53]=N,e[54]=te):te=e[54];let U;e[55]===Symbol.for("react.memo_cache_sentinel")?(U=()=>D(""),e[55]=U):U=e[55];let ae;e[56]!==M||e[57]!==i||e[58]!==Q||e[59]!==q||e[60]!==te?(ae=s.jsx("input",{ref:h,inputMode:"numeric",value:q,onChange:te,onKeyDown:Q,onFocus:U,onBlur:M,maxLength:2,"aria-label":i,className:"h-7 w-7 shrink-0 rounded-sm bg-transparent text-center font-mono text-sm tabular-nums text-foreground outline-none caret-transparent focus:bg-interactive-hover"}),e[56]=M,e[57]=i,e[58]=Q,e[59]=q,e[60]=te,e[61]=ae):ae=e[61];let je;e[62]===Symbol.for("react.memo_cache_sentinel")?(je=s.jsx("span",{className:"font-mono text-sm text-muted-foreground",children:":"}),e[62]=je):je=e[62];const oe=x??u.minute;let ve;e[63]!==L?(ve=se=>L(se.target.value),e[63]=L,e[64]=ve):ve=e[64];let K;e[65]===Symbol.for("react.memo_cache_sentinel")?(K=()=>S(""),e[65]=K):K=e[65];let ce;e[66]!==B||e[67]!==o||e[68]!==X||e[69]!==oe||e[70]!==ve?(ce=s.jsx("input",{ref:b,inputMode:"numeric",value:oe,onChange:ve,onKeyDown:X,onFocus:K,onBlur:B,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]=B,e[67]=o,e[68]=X,e[69]=oe,e[70]=ve,e[71]=ce):ce=e[71];let Z;e[72]!==d||e[73]!==u.meridiem||e[74]!==c||e[75]!==p||e[76]!==re||e[77]!==a?(Z=a?null:s.jsxs(ds,{value:u.meridiem,onValueChange:se=>re(se),children:[s.jsx(us,{"aria-label":c,className:"ml-1 h-7 w-fit border-0 bg-transparent pl-2 pr-1 shadow-none hover:bg-interactive-hover focus:ring-0",children:s.jsx(ys,{})}),s.jsxs(ms,{children:[s.jsx(Lt,{value:"AM",children:d}),s.jsx(Lt,{value:"PM",children:p})]})]}),e[72]=d,e[73]=u.meridiem,e[74]=c,e[75]=p,e[76]=re,e[77]=a,e[78]=Z):Z=e[78];let le;return e[79]!==V||e[80]!==ae||e[81]!==ce||e[82]!==Z?(le=s.jsxs("div",{className:V,children:[ae,je,ce,Z]}),e[79]=V,e[80]=ae,e[81]=ce,e[82]=Z,e[83]=le):le=e[83],le},Xp=t=>new Date(t.getFullYear(),t.getMonth(),1),lI=()=>{const t=new Date;return new Date(t.getFullYear(),t.getMonth(),t.getDate())},Zp=(t,e)=>t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth()&&t.getDate()===e.getDate(),cI=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"]},eh=(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:cI(t),onceDate:typeof t.schedule.date=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(t.schedule.date)?t.schedule.date:Hp(),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:Hp(),onceTime:"09:00",weekdays:[1],timezone:n},execution:{prompt:"",providerID:e.providerID,modelID:e.modelID,variant:e.variant,agent:e.agent}}},dI=(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")},uI=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 mI(t){const{open:e,task:n,onOpenChange:r,onSave:a}=t,{t:i,locale:o}=pt(),c=gt(G=>G.loadProviders),d=gt(G=>G.loadAgents),p=gt(G=>G.providers),m=gt(G=>G.currentProviderId),u=gt(G=>G.currentModelId),h=gt(G=>G.currentVariant||""),b=gt(G=>G.currentAgentName||""),f=Te(G=>G.timeFormatPreference),v=Te(G=>G.weekStartPreference),x=Te(G=>G.isMobile),[g,w]=Be.useState(()=>eh(n,{providerID:m,modelID:u,variant:h,agent:b})),[y,k]=Be.useState(!1),[D,j]=Be.useState(!1),[S,A]=Be.useState(!1),[E,P]=Be.useState(""),[C,N]=Be.useState(!1),[T,M]=Be.useState(""),[R,L]=Be.useState(()=>{const G=qo(n?.schedule?.date||"")||new Date;return new Date(G.getFullYear(),G.getMonth(),1)}),$=Be.useRef(null),B=Be.useRef(null),O=Be.useRef(null),_=Be.useRef(null),ee=Be.useMemo(()=>aI(o),[o]),z=Be.useMemo(()=>rI(o),[o]),ne=Be.useMemo(()=>f==="24h"?!0:f==="12h"?!1:ee,[f,ee]),re=Be.useMemo(()=>v==="sunday"?0:v==="monday"?1:z,[v,z]),ue=Be.useMemo(()=>{const G=iI(o);return oI(yg.map(Pe=>({value:Pe,label:G[Pe]||""})),re)},[o,re]);Be.useEffect(()=>{e&&(c(),d())},[e,c,d]),Be.useEffect(()=>{if(!e)return;w(eh(n,{providerID:m,modelID:u,variant:h,agent:b}));const G=qo(n?.schedule?.date||"")||new Date;L(new Date(G.getFullYear(),G.getMonth(),1)),j(!1),N(!1),A(!1),M(""),P("")},[e,n,m,u,h,b]),Be.useEffect(()=>{if(!D)return;const G=Pe=>{$.current&&!$.current.contains(Pe.target)&&j(!1)};return document.addEventListener("mousedown",G),()=>{document.removeEventListener("mousedown",G)}},[D]);const Q=Be.useMemo(()=>{const Pe=p.find(Le=>Le.id===g.execution.providerID)?.models?.find(Le=>Le.id===g.execution.modelID);return Pe?.variants?Object.keys(Pe.variants):[]},[p,g.execution.providerID,g.execution.modelID]),de=Q.length>0,X=Be.useMemo(()=>!de||!g.execution.variant?"__default":Q.includes(g.execution.variant)?g.execution.variant:"__default",[g.execution.variant,de,Q]);Be.useEffect(()=>{de||!g.execution.variant||w(G=>({...G,execution:{...G.execution,variant:""}}))},[de,g.execution.variant]);const F=Be.useCallback((G,Pe)=>{w(Le=>{const Ae=new Set(Le.schedule.weekdays);return Pe?Ae.add(G):Ae.delete(G),{...Le,schedule:{...Le.schedule,weekdays:Array.from(Ae).sort((ge,W)=>ge-W)}}})},[]),V=Be.useCallback((G,Pe)=>{w(Le=>{const Ae=Le.schedule.times.slice();return Ae[G]=Pe,{...Le,schedule:{...Le.schedule,times:Ae}}})},[]),q=Be.useCallback(G=>{w(Pe=>{const Le=Pe.schedule.times.filter((Ae,ge)=>ge!==G);return{...Pe,schedule:{...Pe.schedule,times:Le.length>0?Le:["09:00"]}}})},[]),te=Be.useCallback(()=>{w(G=>({...G,schedule:{...G.schedule,times:[...G.schedule.times,"12:00"]}}))},[]),U=Be.useMemo(()=>lI(),[]),ae=Be.useMemo(()=>Xp(U),[U]),je=Be.useMemo(()=>{const G=qo(g.schedule.onceDate);return G?Zp(G,U)?i("sessions.scheduledTasks.editor.date.today"):new Intl.DateTimeFormat(o,{weekday:"short"}).format(G):null},[g.schedule.onceDate,o,i,U]),oe=Be.useMemo(()=>Xp(R).getTime()<=ae.getTime(),[R,ae]),ve=Be.useMemo(()=>ue.map(G=>G.label),[ue]),K=Be.useCallback(G=>{w(Pe=>({...Pe,schedule:{...Pe.schedule,onceDate:G}}))},[]),ce=Be.useCallback((G,Pe)=>{if(G.startsWith("/")){const ge=G.indexOf(" "),W=G.indexOf(`
180
- `),ie=Math.min(ge===-1?G.length:ge,W===-1?G.length:W);if(Pe<=ie&&ge===-1){M(G.substring(1,ie)),N(!0),A(!1);return}}N(!1);const Le=G.substring(0,Pe),Ae=Le.lastIndexOf("@");if(Ae!==-1){const ge=Ae>0?Le[Ae-1]:null,W=Le.substring(Ae+1);(!ge||/\s/.test(ge))&&!W.includes(" ")&&!W.includes(`
181
- `)?(P(W),A(!0)):A(!1);return}A(!1)},[]),Z=Be.useCallback(G=>{w(Pe=>({...Pe,execution:{...Pe.execution,prompt:G}}))},[]),le=Be.useCallback(G=>{const Pe=g.execution.prompt,Ae=B.current?.selectionStart??Pe.length,W=Pe.substring(0,Ae).lastIndexOf("@"),ie=G.relativePath&&G.relativePath.trim().length>0?G.relativePath.trim():G.path||G.name,Me=W!==-1?W:Ae,Ve=`${Pe.substring(0,Me)}@${ie} ${Pe.substring(Ae)}`,Ce=Me+ie.length+2;Z(Ve),A(!1),P(""),requestAnimationFrame(()=>{const xe=B.current;xe&&(xe.selectionStart=Ce,xe.selectionEnd=Ce,xe.focus()),ce(Ve,Ce)})},[g.execution.prompt,Z,ce]),se=Be.useCallback(G=>{const Pe=g.execution.prompt,Ae=B.current?.selectionStart??Pe.length,W=Pe.substring(0,Ae).lastIndexOf("@"),ie=W!==-1?W:Ae,Me=`${Pe.substring(0,ie)}@${G} ${Pe.substring(Ae)}`,Ve=ie+G.length+2;Z(Me),A(!1),P(""),requestAnimationFrame(()=>{const Ce=B.current;Ce&&(Ce.selectionStart=Ve,Ce.selectionEnd=Ve,Ce.focus()),ce(Me,Ve)})},[g.execution.prompt,Z,ce]),Ie=Be.useCallback(G=>{const Pe=`/${G.name} `;Z(Pe),N(!1),M(""),requestAnimationFrame(()=>{const Le=B.current;Le&&(Le.focus(),Le.selectionStart=Le.value.length,Le.selectionEnd=Le.value.length),ce(Pe,Pe.length)})},[Z,ce]),Ne=Be.useCallback(G=>{if(C&&_.current&&(G.key==="Enter"||G.key==="ArrowUp"||G.key==="ArrowDown"||G.key==="Escape"||G.key==="Tab")){G.preventDefault(),_.current.handleKeyDown(G.key);return}S&&O.current&&(G.key==="Enter"||G.key==="ArrowUp"||G.key==="ArrowDown"||G.key==="Escape"||G.key==="Tab")&&(G.preventDefault(),O.current.handleKeyDown(G.key))},[C,S]),Y=Be.useCallback(async()=>{const G=dI(g,i);if(G){H.error(G);return}const Pe=uI(g.schedule.times),Le={...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:Pe,...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}:{}};k(!0);try{await a(Le),r(!1)}catch(Ae){H.error(Ae instanceof Error?Ae.message:i("sessions.scheduledTasks.editor.toast.saveFailed"))}finally{k(!1)}},[g,r,a,i]),fe=Be.useId(),ke=Be.useCallback(()=>typeof document>"u"?!1:!!document.querySelector('[data-slot="dropdown-menu-content"], [data-slot="select-content"]'),[]),be=i(n?"sessions.scheduledTasks.editor.title.edit":"sessions.scheduledTasks.editor.title.new"),pe=i("sessions.scheduledTasks.editor.description"),Ee=s.jsxs("div",{className:"flex flex-col gap-5",children:[s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(gr,{htmlFor:"sched-name",required:!0,children:i("sessions.scheduledTasks.editor.taskName.label")}),s.jsx(Kt,{id:"sched-name",value:g.name,onChange:G=>w(Pe=>({...Pe,name:G.target.value})),placeholder:i("sessions.scheduledTasks.editor.taskName.placeholder"),maxLength:80,className:"w-full sm:max-w-[220px]"})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(gr,{children:i("sessions.scheduledTasks.editor.scheduleType.label")}),s.jsxs(ds,{value:g.schedule.kind,onValueChange:G=>{w(Pe=>({...Pe,schedule:{...Pe.schedule,kind:G}}))},children:[s.jsx(us,{className:"w-fit max-w-full",children:s.jsx(ys,{children:G=>i(G==="daily"?"sessions.scheduledTasks.editor.scheduleType.daily":G==="weekly"?"sessions.scheduledTasks.editor.scheduleType.weekly":"sessions.scheduledTasks.editor.scheduleType.once")})}),s.jsxs(ms,{children:[s.jsx(Lt,{value:"daily",children:i("sessions.scheduledTasks.editor.scheduleType.daily")}),s.jsx(Lt,{value:"weekly",children:i("sessions.scheduledTasks.editor.scheduleType.weekly")}),s.jsx(Lt,{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:$,children:[s.jsx(gr,{children:i("sessions.scheduledTasks.editor.date.label")}),s.jsxs("div",{className:"relative",children:[s.jsxs("button",{type:"button",className:"inline-flex h-9 w-fit max-w-full items-center justify-between gap-2 rounded-md border border-border bg-background px-3 text-left hover:bg-interactive-hover",onClick:()=>j(G=>!G),children:[s.jsxs("span",{className:"inline-flex items-center gap-2",children:[s.jsx(I,{name:"calendar",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:eI(g.schedule.onceDate,i("sessions.scheduledTasks.editor.date.placeholder"),o)})]}),s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"})]}),D?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:()=>L(G=>qp(G,-1)),"aria-label":i("sessions.scheduledTasks.editor.date.previousMonth"),disabled:oe,children:s.jsx(I,{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(R)}),s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-interactive-hover",onClick:()=>L(G=>qp(G,1)),"aria-label":i("sessions.scheduledTasks.editor.date.nextMonth"),children:s.jsx(I,{name:"arrow-right-s",className:"h-4 w-4"})})]}),s.jsx("div",{className:"mb-1 grid grid-cols-7 gap-1 px-1",children:ve.map((G,Pe)=>s.jsx("div",{className:"py-1 text-center typography-micro text-muted-foreground",children:G},`${G}-${Pe}`))}),s.jsx("div",{className:"grid grid-cols-7 gap-1",children:tI(R,re).map(({date:G,inCurrentMonth:Pe})=>{const Le=Gp(G),Ae=Le===g.schedule.onceDate,ge=Zp(G,U),W=G.getTime()<U.getTime(),ie=Ae?"bg-interactive-selection text-interactive-selection-foreground":W?"text-muted-foreground/40":Pe?"text-foreground hover:bg-interactive-hover":"text-muted-foreground/60 hover:bg-interactive-hover";return s.jsx("button",{type:"button",onClick:()=>{W||(K(Le),j(!1))},disabled:W,className:["h-8 rounded-md typography-ui-label",ie,ge&&!Ae?"ring-1 ring-inset ring-interactive-focusRing bg-interactive-hover/50":"",W?"cursor-not-allowed opacity-45":""].join(" "),children:G.getDate()},Le)})}),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:je||""}),s.jsx(we,{type:"button",size:"xs",variant:"ghost",onClick:()=>{K(Gp(U)),L(new Date(U.getFullYear(),U.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(gr,{children:i("sessions.scheduledTasks.editor.time.label")}),s.jsx(Yp,{value:g.schedule.onceTime,use24Hour:ne,hourAriaLabel:i("sessions.scheduledTasks.editor.time.hourAria"),minuteAriaLabel:i("sessions.scheduledTasks.editor.time.minuteAria"),periodAriaLabel:i("sessions.scheduledTasks.editor.time.periodAria"),amLabel:i("sessions.scheduledTasks.editor.time.period.am"),pmLabel:i("sessions.scheduledTasks.editor.time.period.pm"),onChange:G=>w(Pe=>({...Pe,schedule:{...Pe.schedule,onceTime:G}}))}),s.jsxs("div",{className:"mt-2 flex flex-col gap-1",children:[s.jsx(gr,{children:i("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(ds,{value:g.schedule.timezone,onValueChange:G=>{w(Pe=>({...Pe,schedule:{...Pe.schedule,timezone:G}}))},children:[s.jsx(us,{className:"w-fit max-w-full",children:s.jsx(ys,{})}),s.jsx(ms,{children:Kp.map(G=>s.jsx(Lt,{value:G,children:G},G))})]})]})]})]}):s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[g.schedule.kind==="weekly"?s.jsxs("div",{className:"flex flex-col gap-1 sm:col-span-2",children:[s.jsx(gr,{children:i("sessions.scheduledTasks.editor.weekdays.label")}),s.jsx("div",{className:"flex flex-wrap gap-x-3 gap-y-2",children:ue.map(G=>{const Pe=g.schedule.weekdays.includes(G.value);return s.jsxs("div",{className:["group inline-flex items-center gap-1.5 px-0.5 py-0.5 typography-meta",Pe?"text-foreground":"text-muted-foreground"].join(" "),children:[s.jsx(xs,{checked:Pe,onChange:Le=>F(G.value,Le),ariaLabel:G.label}),s.jsx("button",{type:"button",onClick:()=>F(G.value,!Pe),className:"group-hover:text-foreground",children:G.label})]},G.value)})})]}):null,s.jsxs("div",{className:"flex flex-col gap-2",children:[s.jsx(gr,{children:i("sessions.scheduledTasks.editor.times.label")}),s.jsx("div",{className:"flex flex-col gap-2",children:g.schedule.times.map((G,Pe)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Yp,{value:G,use24Hour:ne,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:Le=>V(Pe,Le)}),g.schedule.times.length>1?s.jsx(we,{type:"button",size:"icon",variant:"ghost",onClick:()=>q(Pe),"aria-label":i("sessions.scheduledTasks.editor.times.removeAria"),children:s.jsx(I,{name:"close",className:"h-4 w-4"})}):null]},Pe))}),s.jsx("div",{children:s.jsxs(we,{type:"button",size:"sm",variant:"outline",onClick:te,children:[s.jsx(I,{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(gr,{children:i("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(ds,{value:g.schedule.timezone,onValueChange:G=>{w(Pe=>({...Pe,schedule:{...Pe.schedule,timezone:G}}))},children:[s.jsx(us,{className:"w-fit max-w-full",children:s.jsx(ys,{})}),s.jsx(ms,{children:Kp.map(G=>s.jsx(Lt,{value:G,children:G},G))})]})]})]}),s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(gr,{required:!0,children:i("sessions.scheduledTasks.editor.model.label")}),s.jsx(ao,{providerId:g.execution.providerID,modelId:g.execution.modelID,onChange:(G,Pe)=>{w(Le=>({...Le,execution:{...Le.execution,providerID:G,modelID:Pe,variant:""}}))}})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(gr,{children:i("sessions.scheduledTasks.editor.thinkingLevel.label")}),s.jsxs(ds,{value:X,disabled:!de,onValueChange:G=>{w(Pe=>({...Pe,execution:{...Pe.execution,variant:G==="__default"?"":G}}))},children:[s.jsx(us,{className:"w-fit max-w-full",children:s.jsx(ys,{children:G=>G==="__default"?i("sessions.scheduledTasks.editor.thinkingLevel.default"):G})}),s.jsxs(ms,{children:[s.jsx(Lt,{value:"__default",children:i("sessions.scheduledTasks.editor.thinkingLevel.default")}),Q.map(G=>s.jsx(Lt,{value:G,children:G},G))]})]})]})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(gr,{children:i("sessions.scheduledTasks.editor.agent.label")}),s.jsx(Tl,{agentName:g.execution.agent,filter:G=>Lh(G.mode),onChange:G=>w(Pe=>({...Pe,execution:{...Pe.execution,agent:G}}))})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(gr,{htmlFor:"sched-prompt",required:!0,children:i("sessions.scheduledTasks.editor.prompt.label")}),s.jsxs("div",{className:"relative",children:[s.jsx(bn,{id:"sched-prompt",ref:B,value:g.execution.prompt,onChange:G=>{const Pe=G.target.value;Z(Pe);const Le=G.target.selectionStart??Pe.length;ce(Pe,Le)},onKeyDown:Ne,rows:8,placeholder:i("sessions.scheduledTasks.editor.prompt.placeholder"),className:"typography-meta min-h-[120px] max-h-[300px] resize-none overflow-y-auto"}),C?s.jsx(Qh,{ref:_,searchQuery:T,onCommandSelect:Ie,onClose:()=>N(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,S?s.jsx(Yh,{ref:O,searchQuery:E,onFileSelect:le,onAgentSelect:se,onClose:()=>A(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null]})]})]}),ze=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("label",{className:"inline-flex items-center gap-2",children:[s.jsx(xs,{checked:g.enabled,onChange:G=>w(Pe=>({...Pe,enabled:G})),ariaLabel:i("sessions.scheduledTasks.editor.enabled.aria")}),s.jsx("span",{className:"typography-meta",children:i("sessions.scheduledTasks.editor.enabled.label")})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(we,{type:"button",variant:"ghost",size:"sm",onClick:()=>r(!1),disabled:y,children:i("sessions.scheduledTasks.editor.actions.cancel")}),s.jsx(we,{type:"button",size:"sm",onClick:Y,disabled:y,children:i(y?"sessions.scheduledTasks.editor.actions.saving":"sessions.scheduledTasks.editor.actions.save")})]})]});return x?s.jsx(Pr,{open:e,title:be,onClose:()=>r(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:G=>s.jsxs("div",{className:"flex flex-col gap-1 border-b border-border/40 px-3 py-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("h2",{className:"typography-ui-label font-semibold text-foreground",children:be}),G]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:pe})]}),footer:ze,children:Ee}):s.jsx(ws,{open:e,onOpenChange:G=>{!G&&ke()||r(G)},children:s.jsxs(vs,{"aria-describedby":fe,className:"!max-w-[720px] w-[90vw] h-[680px] max-h-[85vh] gap-0 p-0 overflow-hidden",children:[s.jsx(Rs,{id:fe,className:"sr-only",children:pe}),s.jsx("header",{className:"shrink-0 px-4 sm:px-6 pt-5 pb-3",children:s.jsxs("div",{className:"mx-auto w-full max-w-2xl",children:[s.jsx(js,{className:"typography-ui-label font-medium text-foreground",children:be}),s.jsx("p",{className:"typography-meta mt-0.5 text-muted-foreground",children:pe})]})}),s.jsx(eo,{className:"flex-1 min-h-0 overflow-auto [scrollbar-gutter:stable_both-edges]",size:64,hideTopShadow:!0,children:s.jsx("div",{className:"mx-auto w-full max-w-2xl px-4 sm:px-6 pb-5",children:Ee})}),s.jsx("div",{className:"shrink-0 px-4 sm:px-6 py-3",children:s.jsx("div",{className:"mx-auto w-full max-w-2xl",children:ze})})]})})}function pI(t){return bi(t,{min:0,max:23})}function hI(t,e){return bi(String(Number.parseInt(t,10)+e),{min:0,max:23,loop:!0})}function fI(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 gI=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))},xI=(t,e)=>{const n=gI(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||""})},bI=t=>!t||!Number.isFinite(t)?"":new Date(t).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"}),th=(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),h=Math.round(r%i/a),b=h>0?`${u}h ${h}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})},yI={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"}},vI=t=>({color:`var(--status-${t})`,backgroundColor:`var(--status-${t}-background)`,borderColor:`var(--status-${t}-border)`});function wI(){const{t}=pt(),e=Te(M=>M.isScheduledTasksDialogOpen),n=Te(M=>M.setScheduledTasksDialogOpen),r=Te(M=>M.isMobile),a=Fs(M=>M.projects),i=Fs(M=>M.getActiveProject()),o=Vs(M=>M.homeDirectory),{currentTheme:c}=jr(),[d,p]=Be.useState(""),[m,u]=Be.useState([]),[h,b]=Be.useState(!0),[f,v]=Be.useState(!1),[x,g]=Be.useState(null),[w,y]=Be.useState(null),k=Be.useMemo(()=>a.find(M=>M.id===d)||null,[a,d]),D=Be.useCallback(M=>{const R=M.label?.trim()||Da(M.path,o||void 0),L=no({id:M.id,iconImage:M.iconImage??null},{themeVariant:c.metadata.variant,iconColor:c.colors.surface.foreground}),$=M.icon?Al[M.icon]:null,B=M.color?ro[M.color]:void 0;return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[L?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:M.iconBackground?{backgroundColor:M.iconBackground}:void 0,children:s.jsx("img",{src:L,alt:"",className:"h-full w-full object-contain",draggable:!1})}):$?s.jsx(I,{name:$,className:"h-3.5 w-3.5 shrink-0",style:B?{color:B}:void 0}):s.jsx(I,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:B?{color:B}:void 0}),s.jsx("span",{className:"truncate",children:R})]})},[o,c.metadata.variant,c.colors.surface.foreground]),j=Be.useCallback(async(M,R)=>{if(!M){u([]);return}R?.silent||b(!0);try{const L=await Y4(M);L.sort(($,B)=>{if($.enabled!==B.enabled)return $.enabled?-1:1;const O=$.name.localeCompare(B.name);return O!==0?O:($.state?.nextRunAt||Number.MAX_SAFE_INTEGER)-(B.state?.nextRunAt||Number.MAX_SAFE_INTEGER)}),u(L)}catch(L){H.error(L instanceof Error?L.message:t("sessions.scheduledTasks.dialog.toast.loadFailed")),R?.silent||u([])}finally{R?.silent||b(!1)}},[t]);Be.useEffect(()=>{if(!e)return;const M=i?.id||a[0]?.id||"";p(M),M?j(M):(u([]),b(!1))},[e,i,a,j]),Be.useEffect(()=>{if(!e)return;let M=null;const R=bg(L=>{L.type==="scheduled-task-ran"&&L.projectId===d&&(M&&clearTimeout(M),M=setTimeout(()=>{j(d,{silent:!0})},400))});return()=>{M&&clearTimeout(M),R()}},[e,d,j]);const S=Be.useCallback(async M=>{if(!d)throw new Error(t("sessions.scheduledTasks.dialog.error.chooseProjectFirst"));await Wp(d,M),await j(d),H.success(t("sessions.scheduledTasks.dialog.toast.saved"))},[d,j,t]),A=Be.useCallback(async(M,R)=>{if(d){y(M.id),u(L=>L.map($=>$.id===M.id?{...$,enabled:R}:$));try{await Wp(d,{...M,enabled:R}),await j(d,{silent:!0})}catch(L){H.error(L instanceof Error?L.message:t("sessions.scheduledTasks.dialog.toast.updateFailed")),await j(d,{silent:!0})}finally{y(null)}}},[d,j,t]),E=Be.useCallback(async M=>{if(!(!d||!window.confirm(t("sessions.scheduledTasks.dialog.confirm.deleteTask",{taskName:M.name})))){y(M.id);try{await X4(d,M.id),await j(d,{silent:!0}),H.success(t("sessions.scheduledTasks.dialog.toast.deleted"))}catch(L){H.error(L instanceof Error?L.message:t("sessions.scheduledTasks.dialog.toast.deleteFailed"))}finally{y(null)}}},[d,j,t]),P=Be.useCallback(async M=>{if(d){y(M.id);try{await Z4(d,M.id),await Promise.all([j(d,{silent:!0}),Hc()]),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]),C=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(ds,{value:d||"__none",onValueChange:M=>{const R=M==="__none"?"":M;p(R),R?j(R):u([])},children:[s.jsx(us,{className:r?"w-full":void 0,children:k?s.jsx(ys,{children:D(k)}):s.jsx(ys,{placeholder:t("sessions.scheduledTasks.dialog.project.placeholder")})}),s.jsxs(ms,{children:[a.length===0?s.jsx(Lt,{value:"__none",children:t("sessions.scheduledTasks.dialog.project.empty")}):null,a.map(M=>s.jsx(Lt,{value:M.id,children:D(M)},M.id))]})]})]}),N=()=>{g(null),v(!0)},T=s.jsxs("div",{className:"space-y-4",children:[r?C:s.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[C,s.jsxs(we,{onClick:N,disabled:!d,children:[s.jsx(I,{name:"add",className:"mr-1 h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.newTask")]})]}),s.jsx("div",{className:"min-h-[280px]",children:h?s.jsxs("div",{className:"flex items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"h-4 w-4 animate-spin"})," ",t("sessions.scheduledTasks.dialog.loading")]}):m.length===0?s.jsx("div",{className:"rounded-lg border border-dashed border-border p-4 typography-meta text-muted-foreground",children:t(d?"sessions.scheduledTasks.dialog.empty.noTasks":"sessions.scheduledTasks.dialog.empty.selectProject")}):s.jsx("div",{className:"space-y-2.5",children:m.map(M=>{const R=w===M.id,L=M.state?.lastStatus||"idle",$=yI[L],B=t(L==="success"?"sessions.scheduledTasks.dialog.status.success":L==="error"?"sessions.scheduledTasks.dialog.status.error":L==="running"?"sessions.scheduledTasks.dialog.status.running":"sessions.scheduledTasks.dialog.status.idle"),O=M.state?.nextRunAt,_=M.state?.lastRunAt;return s.jsxs("div",{className:me("rounded-lg border border-border p-4 transition-opacity",!M.enabled&&"opacity-60"),children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-header truncate font-semibold text-foreground",children:M.name}),s.jsx("div",{className:"typography-micro truncate text-muted-foreground",children:xI(M,t)})]}),s.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-x-5 gap-y-1 typography-micro text-muted-foreground",children:[s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(I,{name:"timer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-medium text-foreground",children:t("sessions.scheduledTasks.dialog.nextRun.label")}),O?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"text-foreground",children:th(O,t)}),s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:bI(O)})]}):s.jsx("span",{children:"—"})]}),s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(I,{name:"history",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-medium text-foreground",children:t("sessions.scheduledTasks.dialog.lastRun.label")}),L==="running"?s.jsxs("span",{className:"inline-flex items-center gap-1",style:{color:"var(--status-warning)"},children:[s.jsx(I,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),t("sessions.scheduledTasks.dialog.lastRun.runningNow")]}):_?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(I,{name:$.Icon,className:"h-3.5 w-3.5"}),B]}):null,s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:th(_,t)})]}):s.jsx("span",{children:t("sessions.scheduledTasks.dialog.lastRun.never")})]})]}),M.state?.lastError?s.jsxs("div",{className:"mt-3 flex items-start gap-2 rounded-md border p-2 typography-micro",style:vI("error"),children:[s.jsx(I,{name:"error-warning",className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"min-w-0 break-words",children:M.state.lastError})]}):null,s.jsxs("div",{className:"mt-4 flex flex-wrap items-center justify-between gap-2",children:[s.jsxs("label",{className:me("inline-flex cursor-pointer items-center gap-2 typography-micro font-medium",M.enabled?"text-foreground":"text-muted-foreground",R&&"cursor-not-allowed opacity-50"),children:[s.jsx(xs,{checked:M.enabled,onChange:ee=>{A(M,ee)},ariaLabel:M.enabled?t("sessions.scheduledTasks.dialog.taskToggle.pauseAria",{taskName:M.name}):t("sessions.scheduledTasks.dialog.taskToggle.enableAria",{taskName:M.name}),disabled:R}),M.enabled?t("sessions.scheduledTasks.dialog.taskToggle.enabled"):t("sessions.scheduledTasks.dialog.taskToggle.paused")]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[s.jsxs(we,{variant:"outline",size:"sm",onClick:()=>{P(M)},disabled:R,children:[s.jsx(I,{name:"play",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.runNow")]}),s.jsxs(we,{variant:"outline",size:"sm",onClick:()=>{g(M),v(!0)},disabled:R,"aria-label":t("sessions.scheduledTasks.dialog.actions.editAria",{taskName:M.name}),children:[s.jsx(I,{name:"edit-2",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.edit")]}),s.jsx(we,{variant:"destructive",size:"sm",onClick:()=>{E(M)},disabled:R,"aria-label":t("sessions.scheduledTasks.dialog.actions.deleteAria",{taskName:M.name}),children:s.jsx(I,{name:"delete-bin",className:"h-4 w-4"})})]})]})]},M.id)})})})]});return s.jsxs(s.Fragment,{children:[r?s.jsx(Pr,{open:e,title:t("sessions.scheduledTasks.dialog.title"),onClose:()=>n(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:M=>s.jsxs("div",{className:"flex flex-col gap-1 border-b border-border/40 px-3 py-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("h2",{className:"typography-ui-label font-semibold text-foreground",children:t("sessions.scheduledTasks.dialog.title")}),M]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("sessions.scheduledTasks.dialog.description")})]}),footer:s.jsxs(we,{className:"w-full",onClick:N,disabled:!d,children:[s.jsx(I,{name:"add",className:"mr-1 h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.newTask")]}),children:T}):s.jsx(ws,{open:e,onOpenChange:n,children:s.jsxs(vs,{className:"max-h-[85vh] max-w-2xl overflow-y-auto",children:[s.jsxs(Cs,{children:[s.jsx(js,{children:t("sessions.scheduledTasks.dialog.title")}),s.jsx(Rs,{children:t("sessions.scheduledTasks.dialog.description")})]}),T]})}),s.jsx(mI,{open:f,task:x,onOpenChange:v,onSave:S})]})}const jI=(t,e)=>{const n=e.isVSCode?[]:e.availableWorktreesByProject.get(t.normalizedPath)??[],r=new Set([t.normalizedPath,...n.map(c=>ks(c.path)??c.path).filter(c=>!!c)]),i=(c=>c.filter(d=>Gi(d,t.normalizedPath,r)))(e.archivedSessions),o=e.sessions.filter(c=>c.time?.archived||ks(c.directory??null)?!1:Gi(c,t.normalizedPath,r));return mi([...i,...o])},NI=t=>{const e=at.c(12),{normalizedProjects:n,sessions:r,archivedSessions:a,availableWorktreesByProject:i,isVSCode:o,isSessionsLoading:c,foldersMap:d,createFolder:p,addSessionToFolder:m,cleanupSessions:u}=t;let h,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?(h=()=>{c||n.forEach(f=>{const v=Bd(f.normalizedPath),x=jI(f,{sessions:r,archivedSessions:a,availableWorktreesByProject:i,isVSCode:o}),g=new Set(x.map(SI)),w=d[v]??[],y=new Map(w.map(kI));x.forEach(k=>{const D=ay(k,f.normalizedPath),j=D.toLowerCase();let S=y.get(j);S||(S=p(v,D),y.set(j,S)),S.sessionIds.includes(k.id)||m(v,S.id,k.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]=h,e[11]=b):(h=e[10],b=e[11]),l.useEffect(h,b)};function SI(t){return t.id}function kI(t){return[t.name.toLowerCase(),t]}const CI=t=>{const e=at.c(41),{normalizedProjects:n,getSessionsForProject:r,getArchivedSessionsForProject:a,availableWorktreesByProject:i,projectRepoStatus:o,projectRootBranches:c,lastRepoStatus:d,buildGroupedSessions:p,hasSessionSearchQuery:m,normalizedSessionSearchQuery:u,filterSessionNodesForSearch:h,buildGroupSearchText:b,foldersMap:f}=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=C=>{const N=mi([...r(C),...a(C)]),T=i.get(C.normalizedPath)??[],M=o.has(C.id)?!!o.get(C.id):d,R=p(N,C.normalizedPath,T,c.get(C.id)??null,M);return{project:C,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]!==h||e[19]!==f||e[20]!==m||e[21]!==u||e[22]!==g){e:{const P=new WeakMap;if(!m){w=P;break e}const C=N=>N.reduce((T,M)=>T+1+C(M.children),0);g.forEach(N=>{N.groups.forEach(T=>{const M=h(T.sessions,u),R=C(M),L=b(T).includes(u),$=ks(T.directory??null),O=($?f[$]??[]:[]).filter(_=>_.name.toLowerCase().includes(u)).length;P.set(T,{filteredNodes:M,matchedSessionCount:R,folderNameMatchCount:O,groupMatches:L,hasMatch:L||R>0||O>0})})}),w=P}e[17]=b,e[18]=h,e[19]=f,e[20]=m,e[21]=u,e[22]=g,e[23]=w}else w=e[23];const y=w;let k;e:{if(!m){k=g;break e}let P;if(e[24]!==y||e[25]!==g){let C;e[27]!==y?(C=N=>({...N,groups:N.groups.filter(T=>y.get(T)?.hasMatch===!0)}),e[27]=y,e[28]=C):C=e[28],P=g.map(C).filter(II),e[24]=y,e[25]=g,e[26]=P}else P=e[26];k=P}const D=k,j=m?D:g;let S;e:{if(!m){S=0;break e}let P;if(e[29]!==y||e[30]!==j){let C;e[32]!==y?(C=(N,T)=>N+T.groups.reduce((M,R)=>{const L=y.get(R);if(!L)return M;const $=L.folderNameMatchCount+(L.groupMatches?1:0);return M+L.matchedSessionCount+$},0),e[32]=y,e[33]=C):C=e[33],P=j.reduce(C,0),e[29]=y,e[30]=j,e[31]=P}else P=e[31];S=P}const A=S;let E;return e[34]!==y||e[35]!==x||e[36]!==A||e[37]!==D||e[38]!==j||e[39]!==g?(E={projectSections:x,visibleProjectSections:g,groupSearchDataByGroup:y,searchableProjectSections:D,sectionsForRender:j,searchMatchCount:A},e[34]=y,e[35]=x,e[36]=A,e[37]=D,e[38]=j,e[39]=g,e[40]=E):E=e[40],E};function II(t){return t.groups.length>0}const PI=t=>{const e=at.c(34),{projectSections:n,activeProjectId:r,activeSessionByProject:a,setActiveSessionByProject:i,currentSessionId:o,handleSessionSelect:c,newSessionDraftOpen:d,mobileVariant:p,openNewSessionDraft:m,setActiveMainTab:u,setSessionSwitcherOpen:h,sessions:b,worktreeMetadata:f}=t;let v,x;if(e[0]!==n){x=new Map,v=new Map;const C=(N,T,M,R)=>{x.has(N)||x.set(N,new Map);const L=x.get(N);R.forEach($=>{const B=ks($.worktree?.path??$.session.directory??M??T);L.set($.session.id,{directory:B}),v.has(N)||v.set(N,{id:$.session.id,directory:B}),$.children.length>0&&C(N,T,B,$.children)})};n.forEach(N=>{N.groups.forEach(T=>{C(N.project.id,N.project.normalizedPath,T.directory,T.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 k,D;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]!==h?(k=()=>{if(!r||d||y.current===r)return;const C=n.find(B=>B.project.id===r);if(!C)return;y.current=r;const N=w.metaByProject.get(r);if(o&&N&&N.has(o)){i(B=>{if(B.get(r)===o)return B;const O=new Map(B);return O.set(r,o),O});return}if(!N||N.size===0){u("chat"),p&&h(!1),m({directoryOverride:C.project.normalizedPath});return}const T=a.get(r),M=T&&N.has(T)?T:null,R=w.firstSessionByProject.get(r)?.id??null,L=M??R;if(!L||L===o)return;const $=N.get(L)?.directory??null;c(L,$,!1,r)},D=[r,a,o,c,d,p,m,n,w,u,h,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]=h,e[18]=k,e[19]=D):(k=e[18],D=e[19]),l.useLayoutEffect(k,D);let j,S;e[20]!==r||e[21]!==o||e[22]!==w||e[23]!==i?(j=()=>{if(!r||!o)return;const C=w.metaByProject.get(r);!C||!C.has(o)||i(N=>{if(N.get(r)===o)return N;const T=new Map(N);return T.set(r,o),T})},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 A;if(e[26]!==o||e[27]!==b||e[28]!==f){e:{if(!o){A=null;break e}const C=f.get(o)?.path;if(C){A=ks(C)??C;break e}let N;e[30]!==o?(N=M=>M.id===o,e[30]=o,e[31]=N):N=e[31];const T=b.find(N);if(!T){A=null;break e}A=ks(T.directory??null)}e[26]=o,e[27]=b,e[28]=f,e[29]=A}else A=e[29];const E=A;let P;return e[32]!==E?(P={currentSessionDirectory:E},e[32]=E,e[33]=P):P=e[33],P},AI=t=>{const e=at.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(DI)),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 DI(t){return[t.id,t]}const Do=t=>!!t.time?.archived,TI=t=>{const{t:e}=pt(),n=l.useCallback(o=>[o.label,o.branch??"",o.description??"",o.directory??""].join(" ").toLowerCase(),[]),r=l.useCallback(o=>{const c=ks(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=ks(c??null),h=mi(o).sort((C,N)=>ni(C,N,t.pinnedSessionIds)),b=new Map(h.map(C=>[C.id,C])),f=new Map;h.forEach(C=>{const N=C.parentID;if(!N)return;const T=b.get(N);if(!T||Do(T)!==Do(C))return;const M=f.get(N)??[];M.push(C),f.set(N,M)}),f.forEach(C=>C.sort((N,T)=>ni(N,T,t.pinnedSessionIds)));const v=new Map;d.forEach(C=>{if(C.path){const N=ks(C.path)??C.path;v.set(N,C)}});const x=C=>{const N=ks(C.directory??null),T=t.worktreeMetadata.get(C.id)??null;if(T)return T;if(N){const M=v.get(N)??null;if(M&&N!==u)return M}return null},g=C=>{const N=f.get(C.id)??[];return{session:C,children:N.map(T=>g(T)),worktree:x(C)}},w=h.filter(C=>{const N=C.parentID;if(!N)return!0;const T=b.get(N);return T?Do(T)!==Do(C):!0}),y=new Map,k="__archived__",D=C=>{if(C.time?.archived)return k;const N=ks(t.worktreeMetadata.get(C.id)?.path??null),T=ks(C.directory??null);if(!N&&!T)return k;const M=ks(C.project?.worktree??null),R=N??T??M;return R?R!==u&&v.has(R)?R:R===u?u??"__project_root__":k:k};w.forEach(C=>{const N=g(C),T=D(C);y.has(T)||y.set(T,[]),y.get(T)?.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?Hi(u,t.homeDirectory):null,isMain:!0,isArchivedBucket:!1,worktree:null,directory:u,folderScopeKey:u,sessions:y.get(j)??[]}],A=new Map;d.forEach(C=>{const N=ks(C.path)??C.path,T=y.get(N)??[],M=T.length>0,R=T.reduce((L,$)=>{const B=Number($.session.time?.updated??$.session.time?.created??0);return Number.isFinite(B)?Math.max(L,B):L},0);A.set(N,{hasActiveSession:M,lastUpdatedAt:R})}),[...d].sort((C,N)=>{const T=ks(C.path)??C.path,M=ks(N.path)??N.path,R=A.get(T)??{hasActiveSession:!1,lastUpdatedAt:0},L=A.get(M)??{hasActiveSession:!1,lastUpdatedAt:0};if(R.hasActiveSession!==L.hasActiveSession)return R.hasActiveSession?-1:1;if(R.hasActiveSession&&L.hasActiveSession)return L.lastUpdatedAt-R.lastUpdatedAt;const $=(C.label||C.branch||C.name||C.path||"").toLowerCase(),B=(N.label||N.branch||N.name||N.path||"").toLowerCase();return $.localeCompare(B)}).forEach(C=>{const N=ks(C.path)??C.path,T=t.gitBranches.get(N)?.trim()||null,M=C.branch?.trim()||null,L=!!(T&&M&&C.label&&Du(C.label)===Du(M))?T:C.label||C.name||Da(N,t.homeDirectory)||N;S.push({id:`worktree:${N}`,label:L,branch:T||M,description:Hi(N,t.homeDirectory),isMain:!1,isArchivedBucket:!1,worktree:C,directory:N,folderScopeKey:N,sessions:y.get(N)??[]})});const P=y.get(k)??[];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}},MI=t=>{const e=at.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)},EI=t=>{const e=at.c(42),{t:n}=pt(),[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=(R,L,$,B)=>{if($)return;const O=()=>{!t.isSessionSearchOpen&&t.sessionSearchQuery.length===0||(t.setSessionSearchQuery(""),t.setIsSessionSearchOpen(!1))};if(B&&B!==t.activeProjectId&&t.setActiveProjectIdOnly(B),L&&L!==t.currentDirectory&&t.setDirectory(L,{showOverlay:!1}),t.mobileVariant&&(t.setActiveMainTab("chat"),t.setSessionSwitcherOpen(!1)),R===t.currentSessionId){t.allowReselect&&t.onSessionSelected?.(R),O();return}t.setCurrentSession(R,L??null),t.onSessionSelected?.(R),O()},e[2]=t,e[3]=d):d=e[3];const p=d;let m;e[4]!==t?(m=()=>{t.setActiveMainTab("chat")},e[4]=t,e[5]=m):m=e[5];const u=m;let h;e[6]!==t?(h=async()=>{t.editingId&&t.editTitle.trim()&&(await t.updateSessionTitle(t.editingId,t.editTitle.trim()),t.setEditingId(null),t.setEditTitle(""))},e[6]=t,e[7]=h):h=e[7];const b=h;let f;e[8]!==t?(f=()=>{t.setEditingId(null),t.setEditTitle("")},e[8]=t,e[9]=f):f=e[9];const v=f;let x;e[10]!==t||e[11]!==n?(x=async R=>{const L=await t.shareSession(R.id);L&&L.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=(R,L)=>{Rn(R).then($=>{if(!$.ok){H.error(n("sessions.sidebar.session.share.copyUrlError"));return}a(L),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 k;e[15]!==t||e[16]!==n?(k=async R=>{await t.unshareSession(R)?H.success(n("sessions.sidebar.session.unshare.success")):H.error(n("sessions.sidebar.session.unshare.error"))},e[15]=t,e[16]=n,e[17]=k):k=e[17];const D=k;let j;e[18]!==t.childrenMap?(j=R=>{const L=[],$=B=>{(t.childrenMap.get(B)??[]).forEach(_=>{L.push(_),$(_.id)})};return $(R),L},e[18]=t.childrenMap,e[19]=j):j=e[19];const S=j;let A;e[20]!==t||e[21]!==S||e[22]!==n?(A=async(R,L)=>{const $=S(R.id),B=L?.archivedBucket===!0;if($.length===0){(B?await t.deleteSession(R.id):await t.archiveSession(R.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 O=[R.id,...$.map(RI)];if(B){const{deletedIds:z,failedIds:ne}=await t.deleteSessions(O);z.length>0&&H.success(z.length===1?n("sessions.sidebar.bulkActions.deletedSingle",{count:z.length}):n("sessions.sidebar.bulkActions.deletedPlural",{count:z.length})),ne.length>0&&H.error(ne.length===1?n("sessions.sidebar.bulkActions.failedDeleteSingle",{count:ne.length}):n("sessions.sidebar.bulkActions.failedDeletePlural",{count:ne.length}));return}const{archivedIds:_,failedIds:ee}=await t.archiveSessions(O);_.length>0&&H.success(_.length===1?n("sessions.sidebar.bulkActions.archivedSingle",{count:_.length}):n("sessions.sidebar.bulkActions.archivedPlural",{count:_.length})),ee.length>0&&H.error(ee.length===1?n("sessions.sidebar.bulkActions.failedArchiveSingle",{count:ee.length}):n("sessions.sidebar.bulkActions.failedArchivePlural",{count:ee.length}))},e[20]=t,e[21]=S,e[22]=n,e[23]=A):A=e[23];const E=A;let P;e[24]!==t||e[25]!==S||e[26]!==E?(P=(R,L)=>{const $=S(R.id);if(!t.showDeletionDialog){E(R,L);return}t.setDeleteSessionConfirm({session:R,descendantCount:$.length,archivedBucket:L?.archivedBucket===!0})},e[24]=t,e[25]=S,e[26]=E,e[27]=P):P=e[27];const C=P;let N;e[28]!==t||e[29]!==E?(N=async()=>{if(!t.deleteSessionConfirm)return;const{session:R,archivedBucket:L}=t.deleteSessionConfirm;t.setDeleteSessionConfirm(null),await E(R,{archivedBucket:L})},e[28]=t,e[29]=E,e[30]=N):N=e[30];const T=N;let M;return e[31]!==T||e[32]!==r||e[33]!==v||e[34]!==y||e[35]!==C||e[36]!==b||e[37]!==u||e[38]!==p||e[39]!==g||e[40]!==D?(M={copiedSessionId:r,handleSessionSelect:p,handleSessionDoubleClick:u,handleSaveEdit:b,handleCancelEdit:v,handleShareSession:g,handleCopyShareUrl:y,handleUnshareSession:D,handleDeleteSession:C,confirmDeleteSession:T},e[31]=T,e[32]=r,e[33]=v,e[34]=y,e[35]=C,e[36]=b,e[37]=u,e[38]=p,e[39]=g,e[40]=D,e[41]=M):M=e[41],M};function RI(t){return t.id}const FI=t=>{const e=at.c(36),{isVSCode:n,hasLoadedGlobalSessions:r,safeStorage:a,keys:i,sessions:o,setPinnedSessionIds:c,groupOrderByProject:d,activeSessionByProject:p,collapsedGroups:m,setExpandedParents:u,setCollapsedProjects:h}=t,b=l.useRef(null),f=l.useRef(null);let v;e[0]!==n?(v=()=>{if(n)return;const L=f.current;if(f.current=null,b.current=null,!L)return;const{projects:$}=Fs.getState(),B=$.map(O=>({...O,sidebarCollapsed:L.has(O.id)}));Ds({projects:B}).catch(LI)},e[0]=n,e[1]=v):v=e[1];const x=v;let g;e[2]!==x||e[3]!==n?(g=L=>{typeof window>"u"||n||(f.current=L,b.current!==null&&window.clearTimeout(b.current),b.current=window.setTimeout(()=>{x()},700))},e[2]=x,e[3]=n,e[4]=g):g=e[4];const w=g;let y,k;e[5]===Symbol.for("react.memo_cache_sentinel")?(y=()=>()=>{typeof window<"u"&&b.current!==null&&window.clearTimeout(b.current),b.current=null,f.current=null},k=[],e[5]=y,e[6]=k):(y=e[5],k=e[6]),l.useEffect(y,k);let D,j;e[7]!==i.projectCollapse||e[8]!==i.sessionExpanded||e[9]!==a||e[10]!==h||e[11]!==u?(D=()=>{try{const L=a.getItem(i.sessionExpanded);if(L){const B=JSON.parse(L);Array.isArray(B)&&u(new Set(B.filter(OI)))}const $=a.getItem(i.projectCollapse);if($){const B=JSON.parse($);Array.isArray(B)&&h(new Set(B.filter($I)))}}catch{}},j=[i.projectCollapse,i.sessionExpanded,a,h,u],e[7]=i.projectCollapse,e[8]=i.sessionExpanded,e[9]=a,e[10]=h,e[11]=u,e[12]=D,e[13]=j):(D=e[12],j=e[13]),l.useEffect(D,j);let S,A;e[14]!==r||e[15]!==o||e[16]!==c?(S=()=>{if(!r)return;const L=new Set(o.map(BI));c($=>{let B=!1;const O=new Set;return $.forEach(_=>{L.has(_)?O.add(_):B=!0}),B?O:$})},A=[r,o,c],e[14]=r,e[15]=o,e[16]=c,e[17]=S,e[18]=A):(S=e[17],A=e[18]),l.useEffect(S,A);let E,P;e[19]!==d||e[20]!==i.groupOrder||e[21]!==a?(E=()=>{try{const L=Object.fromEntries(d.entries());a.setItem(i.groupOrder,JSON.stringify(L))}catch{}},P=[d,i.groupOrder,a],e[19]=d,e[20]=i.groupOrder,e[21]=a,e[22]=E,e[23]=P):(E=e[22],P=e[23]),l.useEffect(E,P);let C,N;e[24]!==p||e[25]!==i.projectActiveSession||e[26]!==a?(C=()=>{try{const L=Object.fromEntries(p.entries());a.setItem(i.projectActiveSession,JSON.stringify(L))}catch{}},N=[p,i.projectActiveSession,a],e[24]=p,e[25]=i.projectActiveSession,e[26]=a,e[27]=C,e[28]=N):(C=e[27],N=e[28]),l.useEffect(C,N);let T,M;e[29]!==m||e[30]!==i.groupCollapse||e[31]!==a?(T=()=>{try{a.setItem(i.groupCollapse,JSON.stringify(Array.from(m)))}catch{}},M=[m,i.groupCollapse,a],e[29]=m,e[30]=i.groupCollapse,e[31]=a,e[32]=T,e[33]=M):(T=e[32],M=e[33]),l.useEffect(T,M);let R;return e[34]!==w?(R={scheduleCollapsedProjectsPersist:w},e[34]=w,e[35]=R):R=e[35],R};function LI(){}function OI(t){return typeof t=="string"}function $I(t){return typeof t=="string"}function BI(t){return t.id}const _I=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},VI=t=>{const e=at.c(23),{normalizedProjects:n,gitRepoStatus:r,setProjectRepoStatus:a,setProjectRootBranches:i}=t,{git:o}=_n(),c=nn(zI);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 h;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],h=n.map(x).join("|"),e[11]=r,e[12]=n,e[13]=h}else h=e[13];const b=h;let f;e[16]!==n||e[17]!==i?(f=()=>{let x=!1;return(async()=>{const w=await _I(n,2,WI);x||i(y=>{const k=new Map(y);return w.forEach(D=>{const{id:j,branch:S}=D;S&&k.set(j,S)}),k})})(),()=>{x=!0}},e[16]=n,e[17]=i,e[18]=f):f=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(f,v)};function zI(t){return t.ensureStatus}function UI(){return null}async function WI(t){const e=await to(t.normalizedPath).catch(UI);return{id:t.id,branch:e}}const KI=t=>{const e=at.c(14),{isVSCode:n,sessions:r,archivedSessions:a,availableWorktreesByProject:i}=t;let o;e[0]!==r?(o=new Map,r.forEach(b=>{const f=ks(b.directory??null)??ks(b.project?.worktree??null);if(!f)return;const v=o.get(f)??[];v.push(b),o.set(f,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 f=n?[]:i.get(b.normalizedPath)??[],v=[b.normalizedPath,...f.map(HI).filter(GI)],x=new Set,g=[];return v.forEach(w=>{(c.get(w)??[]).forEach(k=>{x.has(k.id)||(x.add(k.id),g.push(k))})}),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(D=>{const j=ks(D.directory??null),S=ks(D.project?.worktree??null);return j?j===b.normalizedPath:S===b.normalizedPath}),k=r.filter(D=>D.time?.archived||ks(D.directory??null)?!1:ks(D.project?.worktree??null)===b.normalizedPath);return mi([...y,...k])}const f=n?[]:i.get(b.normalizedPath)??[],v=new Set([b.normalizedPath,...f.map(qI).filter(JI)]),g=(y=>y.filter(k=>Gi(k,b.normalizedPath,v)))(a),w=r.filter(y=>{if(y.time?.archived||ks(y.directory??null))return!1;const D=ks(y.project?.worktree??null);return D?D===b.normalizedPath||D.startsWith(`${b.normalizedPath}/`):!1});return mi([...g,...w])},e[6]=a,e[7]=i,e[8]=n,e[9]=r,e[10]=m):m=e[10];const u=m;let h;return e[11]!==u||e[12]!==p?(h={getSessionsForProject:p,getArchivedSessionsForProject:u},e[11]=u,e[12]=p,e[13]=h):h=e[13],h};function HI(t){return ks(t.path)??t.path}function GI(t){return!!t}function qI(t){return ks(t.path)??t.path}function JI(t){return!!t}const QI=t=>{const e=at.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(f=>{const v=ks(f.directory??null);if(!v)return;const x=u.get(v);if(x){x.add(f.id);return}u.set(v,new Set([f.id]))}),i.forEach(f=>{const v=Bd(f.normalizedPath),x=o?[]:c.get(f.normalizedPath)??[],g=new Set([f.normalizedPath,...x.map(YI).filter(XI)]),w=mi([...a,...r.filter(y=>y.time?.archived||ks(y.directory??null)?!1:Gi(y,f.normalizedPath,g))]).filter(y=>Gi(y,f.normalizedPath,g));u.set(v,new Set(w.map(ZI)))});const h=qn.getState().foldersMap;new Set([...Object.keys(h),...u.keys()]).forEach(f=>{d(f,u.get(f)??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 YI(t){return ks(t.path)??t.path}function XI(t){return!!t}function ZI(t){return t.id}const eP=t=>{const e=at.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(h=>{const b=h.target.dataset.projectId;b&&c(f=>{const v=new Set(f);return h.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},tP=t=>{const e=at.c(85),{folder:n,sessions:r,subFolderItems:a,isCollapsed:i,onToggle:o,onRename:c,onDelete:d,renderSessionNode:p,groupDirectory:m,projectId:u,mobileVariant:h,alwaysShowActions:b,isRenaming:f,renameDraft:v,onRenameDraftChange:x,onRenameSave:g,onRenameCancel:w,droppableRef:y,isDropTarget:k,onNewSession:D,onNewSubFolder:j,depth:S,hideActions:A,archivedBucket:E}=t,C=b===void 0?h===void 0?!1:h:b,N=f===void 0?!1:f,T=v===void 0?"":v,M=k===void 0?!1:k,R=S===void 0?0:S,L=A===void 0?!1:A,$=E===void 0?!1:E,{t:B}=pt(),[O,_]=l.useState(!1),[ee,z]=l.useState(""),ne=l.useRef(null),re=N||O,ue=N?T:ee;let Q;e[0]!==n.name?(Q=()=>{z(n.name),_(!0)},e[0]=n.name,e[1]=Q):Q=e[1];const de=Q;let X;e[2]!==ue||e[3]!==n.name||e[4]!==N||e[5]!==c||e[6]!==g?(X=()=>{const ie=ue.trim();ie&&ie!==n.name&&c(ie),N&&g&&g(),_(!1),z("")},e[2]=ue,e[3]=n.name,e[4]=N,e[5]=c,e[6]=g,e[7]=X):X=e[7];const F=X;let V;e[8]!==N||e[9]!==w?(V=()=>{N&&w&&w(),_(!1),z("")},e[8]=N,e[9]=w,e[10]=V):V=e[10];const q=V;let te;e[11]!==N||e[12]!==x?(te=ie=>{N&&x?x(ie):z(ie)},e[11]=N,e[12]=x,e[13]=te):te=e[13];const U=te;let ae,je;e[14]!==N?(ae=()=>{if(!N)return;const ie=()=>{const Ce=ne.current;Ce&&(Ce.focus(),Ce.select())},Me=requestAnimationFrame(ie),Ve=window.setTimeout(ie,0);return()=>{cancelAnimationFrame(Me),window.clearTimeout(Ve)}},je=[N],e[14]=N,e[15]=ae,e[16]=je):(ae=e[15],je=e[16]),l.useEffect(ae,je);const oe=i?"folder":"folder-open",K=R>0&&"ml-3";let ce;e[17]!==K?(ce=me("oc-folder",K),e[17]=K,e[18]=ce):ce=e[18];const Z=M&&"bg-primary/10 ring-1 ring-inset ring-primary/30";let le;e[19]!==Z?(le=me("group/folder relative flex items-center justify-between gap-1.5 py-1 min-w-0 rounded-md","cursor-pointer",Z),e[19]=Z,e[20]=le):le=e[20];const se=re?void 0:o,Ie=re?void 0:"button",Ne=re?void 0:0;let Y;e[21]!==o||e[22]!==re?(Y=re?void 0:ie=>{(ie.key==="Enter"||ie.key===" ")&&(ie.preventDefault(),o())},e[21]=o,e[22]=re,e[23]=Y):Y=e[23];let fe;e[24]!==n.name||e[25]!==i||e[26]!==B?(fe=i?B("sessions.sidebar.folderItem.expandAria",{folderName:n.name}):B("sessions.sidebar.folderItem.collapseAria",{folderName:n.name}),e[24]=n.name,e[25]=i,e[26]=B,e[27]=fe):fe=e[27];const ke=$?C?"pr-7":"group-hover/folder:pr-7 group-focus-within/folder:pr-7":"";let be;e[28]!==ke?(be=me("min-w-0 flex items-center gap-1.5 pl-1.5 flex-1 transition-[padding]",ke),e[28]=ke,e[29]=be):be=e[29];const pe=M?"text-primary":"text-muted-foreground";let Ee;e[30]!==pe?(Ee=me("h-3.5 w-3.5 flex-shrink-0",pe),e[30]=pe,e[31]=Ee):Ee=e[31];let ze;e[32]!==oe||e[33]!==Ee?(ze=s.jsx(I,{name:oe,className:Ee}),e[32]=oe,e[33]=Ee,e[34]=ze):ze=e[34];let G;e[35]!==ue||e[36]!==n.name||e[37]!==q||e[38]!==U||e[39]!==F||e[40]!==i||e[41]!==M||e[42]!==re||e[43]!==r||e[44]!==B?(G=re?s.jsxs("form",{className:"flex min-w-0 flex-1 items-center gap-1",onPointerDown:nP,onMouseDown:rP,onSubmit:ie=>{ie.preventDefault(),F()},children:[s.jsx("input",{ref:ne,value:ue,onChange:ie=>U(ie.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",autoFocus:!0,placeholder:B("sessions.sidebar.folderItem.namePlaceholder"),onClick:aP,onPointerDown:iP,onMouseDown:oP,onKeyDown:ie=>{if(ie.key==="Escape"){ie.stopPropagation(),q();return}(ie.key===" "||ie.key==="Enter")&&ie.stopPropagation()}}),s.jsx("button",{type:"submit",className:"shrink-0 text-muted-foreground hover:text-foreground",onClick:lP,onPointerDown:cP,onMouseDown:dP,children:s.jsx(I,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:ie=>{ie.stopPropagation(),q()},onPointerDown:uP,onMouseDown:mP,className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(I,{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:me("typography-ui-label font-semibold truncate",M?"text-primary":"text-muted-foreground"),children:n.name}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70 flex-shrink-0",children:["• ",r.length]}),i?s.jsx(I,{name:"arrow-right-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):s.jsx(I,{name:"arrow-down-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"})]}),e[35]=ue,e[36]=n.name,e[37]=q,e[38]=U,e[39]=F,e[40]=i,e[41]=M,e[42]=re,e[43]=r,e[44]=B,e[45]=G):G=e[45];let Pe;e[46]!==be||e[47]!==ze||e[48]!==G?(Pe=s.jsxs("div",{className:be,children:[ze,G]}),e[46]=be,e[47]=ze,e[48]=G,e[49]=Pe):Pe=e[49];let Le;e[50]!==C||e[51]!==$||e[52]!==R||e[53]!==n.name||e[54]!==de||e[55]!==L||e[56]!==d||e[57]!==D||e[58]!==j||e[59]!==re||e[60]!==B?(Le=!re&&(!L||$)?s.jsx("div",{className:"flex items-center gap-0.5 px-0.5",children:s.jsxs("div",{className:me("flex items-center gap-0.5 transition-opacity",C?"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:[!$&&D?s.jsx("button",{type:"button",onClick:ie=>{ie.stopPropagation(),D()},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":B("sessions.sidebar.folderItem.newSessionAria",{folderName:n.name}),title:B("sessions.sidebar.project.actions.newSession"),children:s.jsx(I,{name:"add",className:"h-3.5 w-3.5"})}):null,!$&&j&&R===0?s.jsx("button",{type:"button",onClick:ie=>{ie.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":B("sessions.sidebar.folderItem.newSubfolderAria",{folderName:n.name}),title:B("sessions.sidebar.folderItem.newSubfolder"),children:s.jsx(I,{name:"folder-add",className:"h-3.5 w-3.5"})}):null,$?null:s.jsx("button",{type:"button",onClick:ie=>{ie.stopPropagation(),de()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":B("sessions.sidebar.folderItem.renameAria",{folderName:n.name}),children:s.jsx(I,{name:"pencil-ai",className:"h-3.5 w-3.5"})}),s.jsx("button",{type:"button",onClick:ie=>{ie.stopPropagation(),d()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":$?B("sessions.sidebar.folderItem.deleteArchivedInFolderAria",{folderName:n.name}):B("sessions.sidebar.folderItem.deleteFolderAria",{folderName:n.name}),children:s.jsx(I,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})}):null,e[50]=C,e[51]=$,e[52]=R,e[53]=n.name,e[54]=de,e[55]=L,e[56]=d,e[57]=D,e[58]=j,e[59]=re,e[60]=B,e[61]=Le):Le=e[61];let Ae;e[62]!==y||e[63]!==le||e[64]!==se||e[65]!==Ie||e[66]!==Ne||e[67]!==Y||e[68]!==fe||e[69]!==Pe||e[70]!==Le?(Ae=s.jsxs("div",{ref:y,className:le,onClick:se,role:Ie,tabIndex:Ne,onKeyDown:Y,"aria-label":fe,children:[Pe,Le]}),e[62]=y,e[63]=le,e[64]=se,e[65]=Ie,e[66]=Ne,e[67]=Y,e[68]=fe,e[69]=Pe,e[70]=Le,e[71]=Ae):Ae=e[71];let ge;e[72]!==$||e[73]!==m||e[74]!==i||e[75]!==u||e[76]!==p||e[77]!==r||e[78]!==a||e[79]!==B?(ge=i?null:s.jsxs("div",{className:"pb-1 pl-2",children:[a,r.length>0?r.map(ie=>p(ie,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:B("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]=B,e[80]=ge):ge=e[80];let W;return e[81]!==ce||e[82]!==Ae||e[83]!==ge?(W=s.jsxs("div",{className:ce,children:[Ae,ge]}),e[81]=ce,e[82]=Ae,e[83]=ge,e[84]=W):W=e[84],W},sP=l.memo(tP);function nP(t){return t.stopPropagation()}function rP(t){return t.stopPropagation()}function aP(t){return t.stopPropagation()}function iP(t){return t.stopPropagation()}function oP(t){return t.stopPropagation()}function lP(t){return t.stopPropagation()}function cP(t){return t.stopPropagation()}function dP(t){return t.stopPropagation()}function uP(t){return t.stopPropagation()}function mP(t){return t.stopPropagation()}const pP=t=>{const e=at.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:h}=gx(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 f=b,v=h?"opacity-30":void 0;let x;return e[9]!==p||e[10]!==i||e[11]!==f||e[12]!==u||e[13]!==v?(x=s.jsx("div",{ref:u,...p,onPointerDown:f,className:v,children:i}),e[9]=p,e[10]=i,e[11]=f,e[12]=u,e[13]=v,e[14]=x):x=e[14],x},hP=t=>{const e=at.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}=xx(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},fP=t=>{const e=at.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=Qo(Li(Yo,o)),[d,p]=l.useState(null),[m,u]=l.useState("Session"),[h,b]=l.useState(null),[f,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:A,over:E}=S;if(!E)return;const P=A.data.current,C=E.data.current;P?.type==="session"&&P.sessionId&&C?.type==="folder"&&C.folderId&&a(P.sessionId,C.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 A=S.active.data.current;if(A?.type==="session"&&A.sessionId){p(A.sessionId),u(A.sessionTitle??"Session");const E=S.active.rect.current.initial?.width,P=S.active.rect.current.initial?.height;b(typeof E=="number"?E: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 k;e[7]!==f||e[8]!==d||e[9]!==m||e[10]!==h||e[11]!==r?(k=d&&r?s.jsxs("div",{style:{width:h?`${h}px`:"auto",height:f?`${f}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(I,{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]=f,e[8]=d,e[9]=m,e[10]=h,e[11]=r,e[12]=k):k=e[12];let D;e[13]!==k?(D=s.jsx(Xo,{children:k}),e[13]=k,e[14]=D):D=e[14];let j;return e[15]!==i||e[16]!==g||e[17]!==c||e[18]!==D?(j=s.jsxs(Zo,{sensors:c,collisionDetection:el,onDragStart:w,onDragCancel:y,onDragEnd:g,children:[i,D]}),e[15]=i,e[16]=g,e[17]=c,e[18]=D,e[19]=j):j=e[19],j},wa=tr()(Zi(t=>({displayMode:"default",showRecentSection:!0,setDisplayMode:e=>t({displayMode:e}),setShowRecentSection:e=>t({showRecentSection:e}),toggleRecentSection:()=>t(e=>({showRecentSection:!e.showRecentSection}))}),{name:"session-display-mode"}));function gP(t){const e=at.c(289),{t:n}=pt(),{group:r,groupKey:a,projectId:i,hideGroupLabel:o,hasSessionSearchQuery:c,normalizedSessionSearchQuery:d,groupSearchDataByGroup:p,expandedSessionGroups:m,collapsedGroups:u,hideDirectoryControls:h,collapsedFolderIds:b,toggleFolderCollapse:f,renameFolder:v,deleteFolder:x,showDeletionDialog:g,setDeleteFolderConfirm:w,renderSessionNode:y,projectRepoStatus:k,lastRepoStatus:D,toggleGroupSessionLimit:j,mobileVariant:S,alwaysShowActions:A,activeProjectId:E,setActiveProjectIdOnly:P,setActiveMainTab:C,setSessionSwitcherOpen:N,openNewSessionDraft:T,addSessionToFolder:M,createFolderAndStartRename:R,renamingFolderId:L,renameFolderDraft:$,setRenameFolderDraft:B,setRenamingFolderId:O,pinnedSessionIds:_,sessionOrderIndex:ee,prVisualStateByDirectoryBranch:z,onToggleCollapsedGroup:ne,dragHandleProps:re,compactBodyPadding:ue}=t,Q=ue===void 0?!1:ue;let de;e[0]!==_||e[1]!==ee?(de=(it,Bt)=>{const bs=ee.get(it.session.id),es=ee.get(Bt.session.id);if(bs!==void 0||es!==void 0){if(bs===void 0)return 1;if(es===void 0)return-1;if(bs!==es)return bs-es}return ni(it.session,Bt.session,_)},e[0]=_,e[1]=ee,e[2]=de):de=e[2];const X=de;let F;e[3]!==r||e[4]!==p||e[5]!==c?(F=c?p.get(r):null,e[3]=r,e[4]=p,e[5]=c,e[6]=F):F=e[6];const V=F,q=wa(kP),te=qn(SP),U=q==="minimal";let ae;e[7]!==m||e[8]!==a?(ae=m.has(a),e[7]=m,e[8]=a,e[9]=ae):ae=e[9];const je=ae;let oe;e[10]!==u||e[11]!==a||e[12]!==c?(oe=c?!1:u.has(a),e[10]=u,e[11]=a,e[12]=c,e[13]=oe):oe=e[13];const ve=oe,K=h?10:5,ce=c?V?.groupMatches===!0:!1,Z=c;V?.filteredNodes;let le;e[14]!==X||e[15]!==r.sessions||e[16]!==V?.filteredNodes||e[17]!==Z?(le=[...Z?V?.filteredNodes??[]:r.sessions].sort(X),e[14]=X,e[15]=r.sessions,e[16]=V?.filteredNodes,e[17]=Z,e[18]=le):le=e[18];const se=le;let Ie;e[19]!==r.directory||e[20]!==r.folderScopeKey?(Ie=r.folderScopeKey??ks(r.directory??null),e[19]=r.directory,e[20]=r.folderScopeKey,e[21]=Ie):Ie=e[21];const Ne=Ie;let Y;e[22]!==Ne||e[23]!==te?(Y=Ne?te[Ne]??[]:[],e[22]=Ne,e[23]=te,e[24]=Y):Y=e[24];const fe=Y;let ke;if(e[25]!==se){ke=new Map;const it=Bt=>{Bt.forEach(bs=>{ke.set(bs.session.id,bs),bs.children.length>0&&it(bs.children)})};it(se),e[25]=se,e[26]=ke}else ke=e[26];const be=ke;let pe;if(e[27]!==X||e[28]!==be||e[29]!==fe){let it;e[31]!==X||e[32]!==be?(it=Bt=>{const bs=Bt.sessionIds.map(es=>be.get(es)).filter(NP).sort(X);return{folder:Bt,nodes:bs}},e[31]=X,e[32]=be,e[33]=it):it=e[33],pe=fe.map(it),e[27]=X,e[28]=be,e[29]=fe,e[30]=pe}else pe=e[30];const Ee=pe;let ze;if(e[34]!==Ee||e[35]!==r.isArchivedBucket||e[36]!==c||e[37]!==d){const it=new Map(Ee.map(jP)),Bt=new Map;for(const{folder:Ut}of Ee){if(!Ut.parentId)continue;const os=Bt.get(Ut.parentId);os?os.push(Ut.id):Bt.set(Ut.parentId,[Ut.id])}const bs=new Map,es=Ut=>{const os=bs.get(Ut);if(os!==void 0)return os;const en=it.get(Ut);if(!en)return bs.set(Ut,!1),!1;const qs=Bt.get(Ut)??[];if(r.isArchivedBucket&&en.nodes.length===0){const Qs=qs.some(mn=>es(mn));return bs.set(Ut,Qs),Qs}if(!c||en.folder.name.toLowerCase().includes(d)||en.nodes.length>0)return bs.set(Ut,!0),!0;const un=qs.some(Qs=>es(Qs));return bs.set(Ut,un),un};ze=Ee.filter(Ut=>{const{folder:os}=Ut;return es(os.id)}),e[34]=Ee,e[35]=r.isArchivedBucket,e[36]=c,e[37]=d,e[38]=ze}else ze=e[38];const G=ze;let Pe;e[39]!==G?(Pe=new Set(G.flatMap(wP)),e[39]=G,e[40]=Pe):Pe=e[40];const Le=Pe;let Ae;if(e[41]!==Le||e[42]!==se){let it;e[44]!==Le?(it=Bt=>!Le.has(Bt.session.id),e[44]=Le,e[45]=it):it=e[45],Ae=se.filter(it),e[41]=Le,e[42]=se,e[43]=Ae}else Ae=e[43];const ge=Ae;let W;e[46]!==G?(W=G.filter(vP),e[46]=G,e[47]=W):W=e[47];const ie=W;if(c&&!ce&&ie.length===0&&ge.length===0)return null;const Me=ge.length;let Ve;e[48]!==r.isArchivedBucket||e[49]!==c||e[50]!==je||e[51]!==K||e[52]!==ge?(Ve=r.isArchivedBucket||c||je?ge:ge.slice(0,K),e[48]=r.isArchivedBucket,e[49]=c,e[50]=je,e[51]=K,e[52]=ge,e[53]=Ve):Ve=e[53];const Ce=Ve,xe=Me-Ce.length,De=yP;let Ye;e[54]!==se?(Ye=De(se),e[54]=se,e[55]=Ye):Ye=e[55];const rt=Ye;let Re;e[56]!==D||e[57]!==i||e[58]!==k?(Re=i&&k.has(i)?!!k.get(i):D,e[56]=D,e[57]=i,e[58]=k,e[59]=Re):Re=e[59];const he=Re,qe=r.directory??null;let et;e[60]!==qe?(et=ks(qe),e[60]=qe,e[61]=et):et=e[61];const Ke=et;let st;e[62]!==r.branch?(st=r.branch?.trim()??null,e[62]=r.branch,e[63]=st):st=e[63];const nt=st;let ye,Je,_e,Ue,ot,Xe,We,bt;e[64]!==r.branch||e[65]!==r.isMain||e[66]!==nt||e[67]!==Ke||e[68]!==z||e[69]!==n?(Ue=Ke&&nt?z.get(`${Ke}::${nt}`)??null:null,We=!!(Ue&&r.branch),Xe=!Ue&&!r.isMain&&!!r.branch,ot=Ue?.visualState??null,ye=Ue&&Ue.state==="open"&&Ue.checks?n("sessions.sidebar.group.pr.checksPassed",{success:Ue.checks.success,total:Ue.checks.total}):null,Je=Ue&&Ue.state==="open"&&Ue.checks?[Ue.checks.failure>0?n("sessions.sidebar.group.pr.failingCount",{count:Ue.checks.failure}):null,Ue.checks.pending>0?n("sessions.sidebar.group.pr.pendingCount",{count:Ue.checks.pending}):null].filter(bP).join(", "):null,_e=Ue&&Ue.state==="open"?Ue.mergeableState==="blocked"||Ue.mergeableState==="dirty"?n("sessions.sidebar.group.pr.conflictsOrBlocked"):Ue.mergeableState==="clean"||Ue.canMerge===!0?n("sessions.sidebar.group.pr.mergeable"):null:null,bt=Ue&&Ue.state==="open"&&Ue.mergeableState?n("sessions.sidebar.group.pr.mergeState",{state:Ue.mergeableState}):null,e[64]=r.branch,e[65]=r.isMain,e[66]=nt,e[67]=Ke,e[68]=z,e[69]=n,e[70]=ye,e[71]=Je,e[72]=_e,e[73]=Ue,e[74]=ot,e[75]=Xe,e[76]=We,e[77]=bt):(ye=e[70],Je=e[71],_e=e[72],Ue=e[73],ot=e[74],Xe=e[75],We=e[76],bt=e[77]);const Dt=bt,Ht=Ue?.base??null,rs=Ue?.head??null;let jt;e:{if(!Ue){let it;e[78]!==r.branch||e[79]!==r.label?(it=r.branch&&iy(r.branch,r.label)?{label:r.branch,color:null}:null,e[78]=r.branch,e[79]=r.label,e[80]=it):it=e[80],jt=it;break e}switch(Ue.visualState){case"merged":{let it;e[81]!==n?(it=n("sessions.sidebar.group.pr.status.merged"),e[81]=n,e[82]=it):it=e[82];let Bt;e[83]!==it?(Bt={label:it,color:"var(--pr-merged)"},e[83]=it,e[84]=Bt):Bt=e[84],jt=Bt;break e}case"open":{let it;e[85]!==Ue.canMerge||e[86]!==Ue.checks?.state||e[87]!==Ue.mergeableState||e[88]!==n?(it=Ue.canMerge===!0||Ue.mergeableState==="clean"||Ue.checks?.state==="success"?{label:n("sessions.sidebar.group.pr.status.readyToMerge"),color:"var(--pr-open)"}:{label:n("sessions.sidebar.group.pr.status.open"),color:"var(--pr-open)"},e[85]=Ue.canMerge,e[86]=Ue.checks?.state,e[87]=Ue.mergeableState,e[88]=n,e[89]=it):it=e[89],jt=it;break e}case"blocked":{let it;e[90]!==Ue.mergeableState||e[91]!==n?(it=Ue.mergeableState==="dirty"?n("sessions.sidebar.group.pr.status.mergeConflicts"):n("sessions.sidebar.group.pr.status.mergeBlocked"),e[90]=Ue.mergeableState,e[91]=n,e[92]=it):it=e[92];let Bt;e[93]!==it?(Bt={label:it,color:"var(--pr-blocked)"},e[93]=it,e[94]=Bt):Bt=e[94],jt=Bt;break e}case"draft":{let it;e[95]!==n?(it=n("sessions.sidebar.group.pr.status.draft"),e[95]=n,e[96]=it):it=e[96];let Bt;e[97]!==it?(Bt={label:it,color:"var(--pr-draft)"},e[97]=it,e[98]=Bt):Bt=e[98],jt=Bt;break e}case"closed":{let it;e[99]!==n?(it=n("sessions.sidebar.group.pr.status.closed"),e[99]=n,e[100]=it):it=e[100];let Bt;e[101]!==it?(Bt={label:it,color:"var(--pr-closed)"},e[101]=it,e[102]=Bt):Bt=e[102],jt=Bt;break e}default:jt=null}}const St=jt,ns=St?.color??(ot?`var(--pr-${ot})`:void 0);let ut;e[103]!==Ue?.url?(ut=it=>{it.preventDefault(),it.stopPropagation();const Bt=Ue?.url;Bt&&Xn(Bt)},e[103]=Ue?.url,e[104]=ut):ut=e[104];const Gt=ut;let Xt,Wt,is,gs,ps,Ns;if(e[105]!==E||e[106]!==M||e[107]!==G||e[108]!==A||e[109]!==b||e[110]!==R||e[111]!==x||e[112]!==Ne||e[113]!==r.directory||e[114]!==r.isArchivedBucket||e[115]!==r.isMain||e[116]!==r.worktree||e[117]!==c||e[118]!==U||e[119]!==S||e[120]!==T||e[121]!==i||e[122]!==v||e[123]!==$||e[124]!==L||e[125]!==y||e[126]!==ie||e[127]!==C||e[128]!==P||e[129]!==w||e[130]!==B||e[131]!==O||e[132]!==N||e[133]!==g||e[134]!==f){const it=(es,Ut,os)=>{const en=G.filter(Qs=>{const{folder:mn}=Qs;return mn.parentId===es.id}),qs=en.length>0?s.jsx(s.Fragment,{children:en.map(Qs=>{const{folder:mn,nodes:ln}=Qs;return it(mn,ln,os+1)})}):void 0,zs=Qs=>{const mn=G.find(wn=>{const{folder:tn}=wn;return tn.id===Qs})?.nodes??[],ln=G.filter(wn=>{const{folder:tn}=wn;return tn.parentId===Qs});return[...De(mn),...ln.flatMap(wn=>{const{folder:tn}=wn;return zs(tn.id)})]},un=r.isArchivedBucket?zs(es.id):[];return s.jsx(hP,{folderId:es.id,children:(Qs,mn)=>s.jsx(sP,{folder:es,sessions:Ut,subFolderItems:qs,isCollapsed:c?!1:b.has(es.id),onToggle:()=>f(es.id),onRename:ln=>{Ne&&v(Ne,es.id,ln)},onDelete:()=>{if(r.isArchivedBucket){yr.requestDelete({sessions:un,mode:"session"});return}if(!Ne)return;if(!g){x(Ne,es.id);return}const ln=G.filter(tn=>{const{folder:fn}=tn;return fn.parentId===es.id}).length,wn=Ut.length;w({scopeKey:Ne,folderId:es.id,folderName:es.name,subFolderCount:ln,sessionCount:wn})},renderSessionNode:y,groupDirectory:r.directory,projectId:i,mobileVariant:S,alwaysShowActions:A,isRenaming:L===es.id,renameDraft:L===es.id?$:void 0,onRenameDraftChange:ln=>B(ln),onRenameSave:()=>{const ln=$.trim();ln&&Ne&&v(Ne,es.id,ln),O(null),B("")},onRenameCancel:()=>{O(null),B("")},droppableRef:Qs,isDropTarget:mn,depth:os,onNewSession:()=>{i&&i!==E&&P(i),C("chat"),S&&N(!1),T({directoryOverride:r.directory,targetFolderId:es.id})},onNewSubFolder:os===0?()=>{Ne&&R(Ne,es.id)}:void 0,hideActions:!1,archivedBucket:r.isArchivedBucket===!0})},es.id)},Bt=()=>ie.map(es=>{const{folder:Ut,nodes:os}=es;return it(Ut,os,0)}),bs=!!(!r.isMain&&r.worktree);Wt=A?bs?"pr-14":"pr-7":U?bs?"pr-2 group-hover/gh:pr-14 group-focus-within/gh:pr-14":"pr-2":bs?"pr-5 group-hover/gh:pr-14 group-focus-within/gh:pr-14":"pr-5",Xt=fP,is=Ne,gs=G.length>0,e[141]!==M||e[142]!==Ne?(ps=(es,Ut)=>{Ne&&M(Ne,Ut,es)},e[141]=M,e[142]=Ne,e[143]=ps):ps=e[143],Ns=Bt(),e[105]=E,e[106]=M,e[107]=G,e[108]=A,e[109]=b,e[110]=R,e[111]=x,e[112]=Ne,e[113]=r.directory,e[114]=r.isArchivedBucket,e[115]=r.isMain,e[116]=r.worktree,e[117]=c,e[118]=U,e[119]=S,e[120]=T,e[121]=i,e[122]=v,e[123]=$,e[124]=L,e[125]=y,e[126]=ie,e[127]=C,e[128]=P,e[129]=w,e[130]=B,e[131]=O,e[132]=N,e[133]=g,e[134]=f,e[135]=Xt,e[136]=Wt,e[137]=is,e[138]=gs,e[139]=ps,e[140]=Ns}else Xt=e[135],Wt=e[136],is=e[137],gs=e[138],ps=e[139],Ns=e[140];let Mt;if(e[144]!==r.directory||e[145]!==r.isArchivedBucket||e[146]!==i||e[147]!==y||e[148]!==Ce){let it;e[150]!==r.directory||e[151]!==r.isArchivedBucket||e[152]!==i||e[153]!==y?(it=Bt=>y(Bt,0,r.directory,i,r.isArchivedBucket===!0),e[150]=r.directory,e[151]=r.isArchivedBucket,e[152]=i,e[153]=y,e[154]=it):it=e[154],Mt=Ce.map(it),e[144]=r.directory,e[145]=r.isArchivedBucket,e[146]=i,e[147]=y,e[148]=Ce,e[149]=Mt}else Mt=e[149];let He;e[155]!==G.length||e[156]!==r.isArchivedBucket||e[157]!==n||e[158]!==Me?(He=Me===0&&G.length===0?s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:r.isArchivedBucket?n("sessions.sidebar.group.empty.noArchivedSessions"):n("sessions.sidebar.group.empty.noSessionsInWorkspace")}):null,e[155]=G.length,e[156]=r.isArchivedBucket,e[157]=n,e[158]=Me,e[159]=He):He=e[159];let At;e[160]!==a||e[161]!==je||e[162]!==xe||e[163]!==n||e[164]!==j?(At=xe>0&&!je?s.jsx("button",{type:"button",onClick:()=>j(a),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:xe===1?n("sessions.sidebar.group.showMoreSingle",{count:xe}):n("sessions.sidebar.group.showMorePlural",{count:xe})}):null,e[160]=a,e[161]=je,e[162]=xe,e[163]=n,e[164]=j,e[165]=At):At=e[165];let Et;e[166]!==a||e[167]!==je||e[168]!==K||e[169]!==n||e[170]!==j||e[171]!==Me?(Et=je&&Me>K?s.jsx("button",{type:"button",onClick:()=>j(a),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:n("sessions.sidebar.group.showFewer")}):null,e[166]=a,e[167]=je,e[168]=K,e[169]=n,e[170]=j,e[171]=Me,e[172]=Et):Et=e[172];let wt;e[173]!==Xt||e[174]!==is||e[175]!==gs||e[176]!==ps||e[177]!==Ns||e[178]!==Mt||e[179]!==He||e[180]!==At||e[181]!==Et?(wt=s.jsxs(Xt,{scopeKey:is,hasFolders:gs,onSessionDroppedOnFolder:ps,children:[Ns,Mt,He,At,Et]}),e[173]=Xt,e[174]=is,e[175]=gs,e[176]=ps,e[177]=Ns,e[178]=Mt,e[179]=He,e[180]=At,e[181]=Et,e[182]=wt):wt=e[182];const $t=wt,qt=Q?"pb-2 pl-1":"pb-3 pl-4";if(o){let it;e[183]!==qt?(it=me("oc-group-body",qt),e[183]=qt,e[184]=it):it=e[184];let Bt;return e[185]!==$t||e[186]!==it?(Bt=s.jsx("div",{className:"oc-group",children:s.jsx("div",{className:it,children:$t})}),e[185]=$t,e[186]=it,e[187]=Bt):Bt=e[187],Bt}let Ms;e[188]===Symbol.for("react.memo_cache_sentinel")?(Ms=me("group/gh relative flex items-start justify-between gap-1 py-1 min-w-0 rounded-md","cursor-pointer"),e[188]=Ms):Ms=e[188];let cs;e[189]!==a||e[190]!==ne?(cs=()=>ne(a),e[189]=a,e[190]=ne,e[191]=cs):cs=e[191];let Is;e[192]!==a||e[193]!==ne?(Is=it=>{(it.key==="Enter"||it.key===" ")&&(it.preventDefault(),ne(a))},e[192]=a,e[193]=ne,e[194]=Is):Is=e[194];let Es;e[195]!==r.label||e[196]!==ve||e[197]!==n?(Es=ve?n("sessions.sidebar.group.expandAria",{label:r.label}):n("sessions.sidebar.group.collapseAria",{label:r.label}),e[195]=r.label,e[196]=ve,e[197]=n,e[198]=Es):Es=e[198];const ft=!ve,hs=re?.setActivatorNodeRef;let J;e[199]!==Wt?(J=me("min-w-0 flex flex-1 items-start gap-1 overflow-hidden pl-0.5 transition-[padding] cursor-grab active:cursor-grabbing",Wt),e[199]=Wt,e[200]=J):J=e[200];let ct;e[201]!==re?.listeners?(ct=re?.listeners??{},e[201]=re?.listeners,e[202]=ct):ct=e[202];let vt;e[203]!==A||e[204]!==Ht||e[205]!==ns||e[206]!==ye||e[207]!==Je||e[208]!==r.branch||e[209]!==r.isArchivedBucket||e[210]!==r.isMain||e[211]!==r.label||e[212]!==r.worktree||e[213]!==Gt||e[214]!==rs||e[215]!==ve||e[216]!==Dt||e[217]!==_e||e[218]!==d||e[219]!==Ue||e[220]!==We?(vt=We&&Ue?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center",children:[s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 leading-none align-middle",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx(I,{name:"git-branch",className:me("h-3.5 w-3.5 shrink-0",A?"hidden":"group-hover/gh:hidden"),style:ns?{color:ns}:void 0}),s.jsx("span",{className:me("text-muted-foreground h-3.5 w-3.5 items-center justify-center",A?"inline-flex":"hidden group-hover/gh:inline-flex"),children:ve?s.jsx(I,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),Ue.url?s.jsxs("button",{type:"button",className:"inline-flex shrink-0 items-center leading-none",onMouseDown:xP,onClick:Gt,children:["#",Ue.number]}):s.jsxs("span",{className:"inline-flex shrink-0 items-center leading-none",children:["#",Ue.number]})]})}),s.jsx(Pt,{side:"top",sideOffset:6,align:"start",className:"max-w-sm",children:s.jsxs("div",{className:"space-y-1 text-xs",children:[Ht||rs?s.jsx("div",{className:"text-muted-foreground truncate",children:Ht&&rs?s.jsxs(s.Fragment,{children:[s.jsx("span",{children:Ht}),s.jsx(I,{name:"arrow-left-long",className:"mx-0.5 inline h-3 w-3 align-[-2px]"}),s.jsx("span",{children:rs})]}):s.jsx("span",{children:Ht??rs??""})}):null,Dt?s.jsx("div",{className:"text-muted-foreground truncate",children:Dt}):null,_e||ye?s.jsxs("div",{className:"text-muted-foreground truncate",children:[_e??"",_e&&ye?" • ":"",ye??"",Je?` (${Je})`:""]}):null]})})]}),s.jsx("span",{className:"ml-1 min-w-0 flex-1 truncate leading-none align-middle",children:r.branch})]}):r.isArchivedBucket?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx(I,{name:"archive",className:me("h-3.5 w-3.5 shrink-0 text-muted-foreground",A?"hidden":"group-hover/gh:hidden")}),s.jsx("span",{className:me("text-muted-foreground h-3.5 w-3.5 items-center justify-center",A?"inline-flex":"hidden group-hover/gh:inline-flex"),children:ve?s.jsx(I,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:_i(r.label,d)})]}):!r.isMain||r.worktree?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx(I,{name:"git-branch",className:me("h-3.5 w-3.5 shrink-0 text-muted-foreground",A?"hidden":"group-hover/gh:hidden"),style:ns?{color:ns}:void 0}),s.jsx("span",{className:me("text-muted-foreground h-3.5 w-3.5 items-center justify-center",A?"inline-flex":"hidden group-hover/gh:inline-flex"),children:ve?s.jsx(I,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:_i(r.label,d)})]}):_i(r.label,d),e[203]=A,e[204]=Ht,e[205]=ns,e[206]=ye,e[207]=Je,e[208]=r.branch,e[209]=r.isArchivedBucket,e[210]=r.isMain,e[211]=r.label,e[212]=r.worktree,e[213]=Gt,e[214]=rs,e[215]=ve,e[216]=Dt,e[217]=_e,e[218]=d,e[219]=Ue,e[220]=We,e[221]=vt):vt=e[221];let Tt;e[222]!==vt?(Tt=s.jsx("p",{className:"text-[14px] font-normal truncate text-foreground/92",children:vt}),e[222]=vt,e[223]=Tt):Tt=e[223];let Yt;e[224]!==Ht||e[225]!==ns||e[226]!==ye||e[227]!==Je||e[228]!==r.isArchivedBucket||e[229]!==r.isMain||e[230]!==rs||e[231]!==he||e[232]!==Dt||e[233]!==_e||e[234]!==Ue||e[235]!==Xe||e[236]!==We||e[237]!==St?(Yt=Xe&&St?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5 leading-tight",children:[r.isArchivedBucket?s.jsx(I,{name:"archive",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):!r.isMain||he?We&&Ue?s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("span",{className:"inline-flex h-3.5 w-3.5 flex-shrink-0 items-center justify-center",children:s.jsx(I,{name:"git-branch",className:"h-3.5 w-3.5 text-muted-foreground",style:ns?{color:ns}:void 0})})}),s.jsx(Pt,{side:"top",sideOffset:6,align:"start",className:"max-w-sm",children:s.jsxs("div",{className:"space-y-1 text-xs",children:[Ht||rs?s.jsx("div",{className:"text-muted-foreground truncate",children:Ht&&rs?s.jsxs(s.Fragment,{children:[s.jsx("span",{children:Ht}),s.jsx(I,{name:"arrow-left-long",className:"mx-0.5 inline h-3 w-3 align-[-2px]"}),s.jsx("span",{children:rs})]}):s.jsx("span",{children:Ht??rs??""})}):null,Dt?s.jsx("div",{className:"text-muted-foreground truncate",children:Dt}):null,_e||ye?s.jsxs("div",{className:"text-muted-foreground truncate",children:[_e??"",_e&&ye?" • ":"",ye??"",Je?` (${Je})`:""]}):null]})})]}):s.jsx(I,{name:"git-branch",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground",style:ns?{color:ns}:void 0}):null,s.jsx("span",{className:me("min-w-0 truncate text-[11px] font-medium",!St.color&&"text-muted-foreground/80"),style:St.color?{color:St.color}:void 0,children:St.label})]}):null,e[224]=Ht,e[225]=ns,e[226]=ye,e[227]=Je,e[228]=r.isArchivedBucket,e[229]=r.isMain,e[230]=rs,e[231]=he,e[232]=Dt,e[233]=_e,e[234]=Ue,e[235]=Xe,e[236]=We,e[237]=St,e[238]=Yt):Yt=e[238];let Zt;e[239]!==Tt||e[240]!==Yt?(Zt=s.jsxs("div",{className:"min-w-0 flex flex-1 flex-col justify-center gap-0.5 overflow-hidden",children:[Tt,Yt]}),e[239]=Tt,e[240]=Yt,e[241]=Zt):Zt=e[241];let Ps;e[242]!==hs||e[243]!==J||e[244]!==ct||e[245]!==Zt?(Ps=s.jsx("div",{ref:hs,className:J,...ct,children:Zt}),e[242]=hs,e[243]=J,e[244]=ct,e[245]=Zt,e[246]=Ps):Ps=e[246];let As;e[247]!==rt||e[248]!==A||e[249]!==r.isArchivedBucket||e[250]!==r.label||e[251]!==n?(As=r.isArchivedBucket&&rt.length>0?s.jsx("div",{className:me("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",A?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:it=>{it.stopPropagation(),yr.requestDelete({sessions:rt,mode:"session"})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":n("sessions.sidebar.group.actions.deleteArchivedInGroupAria",{label:r.label}),children:s.jsx(I,{name:"delete-bin",className:"h-4 w-4"})})}),s.jsx(Pt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.group.actions.deleteArchivedSessions")})})]})}):null,e[247]=rt,e[248]=A,e[249]=r.isArchivedBucket,e[250]=r.label,e[251]=n,e[252]=As):As=e[252];let Ge;e[253]!==rt||e[254]!==A||e[255]!==r.directory||e[256]!==r.isMain||e[257]!==r.label||e[258]!==r.worktree||e[259]!==n?(Ge=r.directory&&!r.isMain&&r.worktree?s.jsx("div",{className:me("absolute right-7 top-1/2 -translate-y-1/2 z-10 transition-opacity",A?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:it=>{it.stopPropagation(),yr.requestDelete({sessions:rt,mode:"worktree",worktree:r.worktree})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":n("sessions.sidebar.group.actions.deleteGroupAria",{label:r.label}),children:s.jsx(I,{name:"delete-bin",className:"h-4 w-4"})})}),s.jsx(Pt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.group.actions.deleteWorktree")})})]})}):null,e[253]=rt,e[254]=A,e[255]=r.directory,e[256]=r.isMain,e[257]=r.label,e[258]=r.worktree,e[259]=n,e[260]=Ge):Ge=e[260];let yt;e[261]!==E||e[262]!==A||e[263]!==r.directory||e[264]!==r.label||e[265]!==S||e[266]!==T||e[267]!==i||e[268]!==C||e[269]!==P||e[270]!==N||e[271]!==n?(yt=r.directory?s.jsx("div",{className:me("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",A?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:it=>{it.stopPropagation(),i&&i!==E&&P(i),C("chat"),S&&N(!1),T({directoryOverride:r.directory})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":n("sessions.sidebar.group.actions.newDraftInGroupAria",{label:r.label}),children:s.jsx(I,{name:"add",className:"h-4 w-4"})})}),s.jsx(Pt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.project.actions.newDraftSession")})})]})}):null,e[261]=E,e[262]=A,e[263]=r.directory,e[264]=r.label,e[265]=S,e[266]=T,e[267]=i,e[268]=C,e[269]=P,e[270]=N,e[271]=n,e[272]=yt):yt=e[272];let It;e[273]!==cs||e[274]!==Is||e[275]!==Es||e[276]!==ft||e[277]!==Ps||e[278]!==As||e[279]!==Ge||e[280]!==yt?(It=s.jsxs("div",{className:Ms,onClick:cs,role:"button",tabIndex:0,onKeyDown:Is,"aria-label":Es,"aria-expanded":ft,children:[Ps,As,Ge,yt]}),e[273]=cs,e[274]=Is,e[275]=Es,e[276]=ft,e[277]=Ps,e[278]=As,e[279]=Ge,e[280]=yt,e[281]=It):It=e[281];let Rt;e[282]!==$t||e[283]!==qt||e[284]!==ve?(Rt=ve?null:s.jsx("div",{className:me("oc-group-body",qt),children:$t}),e[282]=$t,e[283]=qt,e[284]=ve,e[285]=Rt):Rt=e[285];let ss;return e[286]!==It||e[287]!==Rt?(ss=s.jsxs("div",{className:"oc-group",children:[It,Rt]}),e[286]=It,e[287]=Rt,e[288]=ss):ss=e[288],ss}function xP(t){return t.stopPropagation()}function bP(t){return!!t}function yP(t){const e=[],n=r=>{r.forEach(a=>{e.push(a.session),a.children.length>0&&n(a.children)})};return n(t),e}function vP(t){const{folder:e}=t;return!e.parentId}function wP(t){return t.folder.sessionIds}function jP(t){return[t.folder.id,t]}function NP(t){return!!t}function SP(t){return t.foldersMap}function kP(t){return t.displayMode}function CP(t){const e=at.c(37),{t:n}=pt(),{hideDirectoryControls:r,handleOpenDirectoryDialog:a,handleNewSession:i,canOpenMultiRun:o,openMultiRunLauncher:c,headerActionIconClass:d,reserveHeaderActionsSpace:p,headerActionButtonClass:m,isSessionSearchOpen:u,setIsSessionSearchOpen:h,sessionSearchInputRef:b,sessionSearchQuery:f,setSessionSearchQuery:v,hasSessionSearchQuery:x,searchMatchCount:g,collapseAllProjects:w,expandAllProjects:y,openScheduledTasksDialog:k,selectionModeEnabled:D,onToggleSelectionMode:j,showSidebarToggle:S,onToggleSidebar:A,avoidWindowControlsOverlay:E}=t,P=S===void 0?!1:S,C=E===void 0?!1:E,N=wa(TP),T=wa(DP),M=wa(AP),R=wa(PP);if(r)return null;const L=P?C?"pl-[5.5rem] pr-3":"pl-3 pr-3":"px-2.5 py-1";let $;e[0]!==L?($=me("select-none flex-shrink-0",L),e[0]=L,e[1]=$):$=e[1];let B;e[2]!==C||e[3]!==P?(B=P&&C?{paddingTop:"var(--oc-safe-area-top, 0px)"}:void 0,e[2]=C,e[3]=P,e[4]=B):B=e[4];let O;e[5]!==C||e[6]!==o||e[7]!==w||e[8]!==N||e[9]!==y||e[10]!==i||e[11]!==a||e[12]!==x||e[13]!==m||e[14]!==d||e[15]!==u||e[16]!==j||e[17]!==A||e[18]!==c||e[19]!==k||e[20]!==p||e[21]!==g||e[22]!==D||e[23]!==b||e[24]!==f||e[25]!==M||e[26]!==h||e[27]!==v||e[28]!==T||e[29]!==P||e[30]!==n||e[31]!==R?(O=p?s.jsxs("div",{className:me("flex h-auto flex-col gap-1",P?C?"min-h-[calc(var(--oc-header-height,56px)-var(--oc-safe-area-top,0px))] justify-center":"min-h-[var(--oc-header-height,56px)] justify-center":"min-h-8"),children:[s.jsxs("div",{className:"flex h-8 items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[P&&A?s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:A,className:"inline-flex h-8 w-8 items-center justify-center rounded-md typography-ui-label font-medium text-foreground transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:pointer-events-none disabled:opacity-50","aria-label":n("sessions.sidebar.header.actions.closeSessions"),children:s.jsx(I,{name:"layout-left",className:"h-[18px] w-[18px]"})})}),s.jsx(Pt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.closeSessions")})})]}):null,s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:a,className:m,"aria-label":n("sessions.sidebar.header.actions.addProject"),children:s.jsx(I,{name:"folder-add",className:d})})}),s.jsx(Pt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.addProject")})})]}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:i,className:m,"aria-label":n("sessions.sidebar.header.actions.newSession"),children:s.jsx(I,{name:"chat-new",className:d})})}),s.jsx(Pt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.newSession")})})]}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:c,className:m,"aria-label":n("sessions.sidebar.header.actions.newMultiRun"),disabled:!o,children:s.jsx(oy,{className:d})})}),s.jsx(Pt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.newMultiRun")})})]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:k,className:m,"aria-label":n("sessions.sidebar.header.actions.scheduledTasks"),children:s.jsx(I,{name:"calendar-schedule",className:d})})}),s.jsx(Pt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.scheduledTasks")})})]}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:()=>h(IP),className:m,"aria-label":n("sessions.sidebar.header.actions.searchSessions"),"aria-expanded":u,children:s.jsx(I,{name:"search",className:d})})}),s.jsx(Pt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.searchSessions")})})]}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:j,className:me(m,D&&"bg-interactive-hover text-primary"),"aria-label":n(D?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions"),"aria-pressed":D,children:s.jsx(I,{name:"checkbox-multiple",className:d})})}),s.jsx(Pt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n(D?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions")})})]}),s.jsxs(Bs,{children:[s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(Os,{asChild:!0,children:s.jsx("button",{type:"button",className:m,"aria-label":n("sessions.sidebar.header.actions.sessionDisplayMode"),children:s.jsx(I,{name:"equalizer-2",className:d})})})}),s.jsx(Pt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.displayMode.label")})})]}),s.jsxs($s,{align:"end",className:"min-w-[160px]",children:[s.jsxs(zt,{onClick:()=>M("default"),className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.default")}),N==="default"?s.jsx(I,{name:"check",className:"h-4 w-4 text-primary"}):null]}),s.jsxs(zt,{onClick:()=>M("minimal"),className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.minimal")}),N==="minimal"?s.jsx(I,{name:"check",className:"h-4 w-4 text-primary"}):null]}),s.jsx(Dn,{}),s.jsxs(zt,{onClick:R,className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.showRecent")}),T?s.jsx(I,{name:"check",className:"h-4 w-4 text-primary"}):null]}),s.jsx(Dn,{}),s.jsxs(zt,{onClick:w,className:"flex items-center gap-2",children:[s.jsx(I,{name:"contract-up-down",className:"h-4 w-4"}),s.jsx("span",{children:n("sessions.sidebar.header.displayMode.collapseAll")})]}),s.jsxs(zt,{onClick:y,className:"flex items-center gap-2",children:[s.jsx(I,{name:"expand-up-down",className:"h-4 w-4"}),s.jsx("span",{children:n("sessions.sidebar.header.displayMode.expandAll")})]})]})]})]})]}),u?s.jsxs("div",{className:"pb-1",children:[s.jsxs("div",{className:"mb-1 flex items-center justify-between px-0.5 typography-micro text-muted-foreground/80",children:[x?s.jsx("span",{children:g===1?n("sessions.sidebar.header.search.matchCountSingle",{count:g}):n("sessions.sidebar.header.search.matchCountPlural",{count:g})}):s.jsx("span",{}),s.jsx("span",{children:n("sessions.sidebar.header.search.escapeHint")})]}),s.jsxs("div",{className:"relative",children:[s.jsx(I,{name:"search",className:"pointer-events-none absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),s.jsx("input",{ref:b,value:f,onChange:ee=>v(ee.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:ee=>{ee.key==="Escape"&&(ee.stopPropagation(),x?v(""):h(!1))}}),f.length>0?s.jsx("button",{type:"button",onClick:()=>v(""),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(I,{name:"close",className:"h-3.5 w-3.5"})}):null]})]}):null]}):null,e[5]=C,e[6]=o,e[7]=w,e[8]=N,e[9]=y,e[10]=i,e[11]=a,e[12]=x,e[13]=m,e[14]=d,e[15]=u,e[16]=j,e[17]=A,e[18]=c,e[19]=k,e[20]=p,e[21]=g,e[22]=D,e[23]=b,e[24]=f,e[25]=M,e[26]=h,e[27]=v,e[28]=T,e[29]=P,e[30]=n,e[31]=R,e[32]=O):O=e[32];let _;return e[33]!==$||e[34]!==B||e[35]!==O?(_=s.jsx("div",{className:$,style:B,children:O}),e[33]=$,e[34]=B,e[35]=O,e[36]=_):_=e[36],_}function IP(t){return!t}function PP(t){return t.toggleRecentSection}function AP(t){return t.setDisplayMode}function DP(t){return t.showRecentSection}function TP(t){return t.displayMode}const sh=7;function MP(t){const e=at.c(20),{sections:n,renderSessionNode:r}=t,{t:a}=pt();let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=new Set,e[0]=i):i=e[0];const[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(k=>{const D=new Set(k);return D.has(y)?D.delete(y):D.add(y),D})},e[2]=u):u=e[2];const h=u;let b;e[3]===Symbol.for("react.memo_cache_sentinel")?(b=y=>{m(k=>{const D=new Set(k);return D.has(y)?D.delete(y):D.add(y),D})},e[3]=b):b=e[3];const f=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(EP);if(y.length===0){g=null;break e}v="space-y-2 pb-2 pt-1";let k;e[12]!==o||e[13]!==p||e[14]!==r||e[15]!==a?(k=D=>{const j=o.has(D.key),S=p.has(D.key),A=S?D.items:D.items.slice(0,sh),E=D.items.length-A.length;return s.jsxs("div",{className:"space-y-1",children:[s.jsxs("button",{type:"button",onClick:()=>h(D.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(I,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"arrow-down-s",className:"h-3.5 w-3.5"})}),s.jsx("span",{className:"text-[14px] font-normal text-foreground/95",children:D.title})]}),j?null:s.jsxs("div",{className:me("space-y-0.5 pl-7"),children:[A.map(P=>r(P.node,0,P.groupDirectory,P.projectId,!1,P.secondaryMeta,"recent")),E>0&&!S?s.jsx("button",{type:"button",onClick:()=>f(D.key),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:E===1?a("sessions.sidebar.group.showMoreSingle",{count:E}):a("sessions.sidebar.group.showMorePlural",{count:E})}):null,S&&D.items.length>sh?s.jsx("button",{type:"button",onClick:()=>f(D.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]})]},D.key)},e[12]=o,e[13]=p,e[14]=r,e[15]=a,e[16]=k):k=e[16],x=y.map(k)}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 EP(t){return t.items.length>0}const Mc="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 RP(t){const e=at.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}=pt();let u;e[0]!==a||e[1]!==n||e[2]!==r||e[3]!==d||e[4]!==m?(u=d?s.jsxs(s.Fragment,{children:[s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,className:Mc,"aria-label":m("sessions.sidebar.footer.actions.settings"),children:s.jsx(I,{name:"settings-3",className:"h-4.5 w-4.5"})})}),s.jsx(Pt,{side:"top",sideOffset:4,children:s.jsx("p",{children:m("sessions.sidebar.footer.actions.settings")})})]}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:r,className:Mc,"aria-label":m("sessions.sidebar.footer.actions.shortcuts"),children:s.jsx(I,{name:"question",className:"h-4.5 w-4.5"})})}),s.jsx(Pt,{side:"top",sideOffset:4,children:s.jsx("p",{children:m("sessions.sidebar.footer.actions.shortcuts")})})]}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:a,className:Mc,"aria-label":m("sessions.sidebar.footer.actions.aboutOpenChamber"),children:s.jsx(I,{name:"information",className:"h-4.5 w-4.5"})})}),s.jsx(Pt,{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 h;e[6]!==i||e[7]!==p||e[8]!==m?(h=p?s.jsx(we,{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]=h):h=e[9];let b;return e[10]!==u||e[11]!==h?(b=s.jsxs("div",{className:"flex shrink-0 items-center justify-start gap-1 px-2.5 py-2",children:[u,h]}),e[10]=u,e[11]=h,e[12]=b):b=e[12],b}const FP=t=>{const e=at.c(58),{id:n,projectLabel:r,projectDescription:a,projectIcon:i,projectColor:o,projectIconImage:c,projectIconBackground:d,isCollapsed:p,isActiveProject:m,isRepo:u,isDesktopShell:h,isStuck:b,hideDirectoryControls:f,alwaysShowActions:v,onToggle:x,onNewSession:g,onNewWorktreeSession:w,onRenameStart:y,onClose:k,sentinelRef:D,children:j,showCreateButtons:S,hideHeader:A,openSidebarMenuKey:E,setOpenSidebarMenuKey:P}=t,C=S===void 0?!0:S,N=A===void 0?!1:A,{t:T}=pt(),{currentTheme:M}=jr();let R;e[0]!==n?(R={id:n},e[0]=n,e[1]=R):R=e[1];const{attributes:L,listeners:$,setNodeRef:B,transform:O,transition:_,isDragging:ee}=Sd(R),[z,ne]=l.useState(!1),re=l.useRef(!1),ue=`project:${n}`,Q=E===ue;let de;e[2]===Symbol.for("react.memo_cache_sentinel")?(de=()=>{ne(!1)},e[2]=de):de=e[2];const X=c?.updatedAt;let F;e[3]!==n||e[4]!==X?(F=[n,X],e[3]=n,e[4]=X,e[5]=F):F=e[5],l.useEffect(de,F);const V=i?Al[i]:null,q=o?ro[o]??null:null;let te;e[6]!==M||e[7]!==n||e[8]!==z||e[9]!==c?(te=z?null:no({id:n,iconImage:c},{themeVariant:M.metadata.variant,iconColor:M.colors.surface.foreground}),e[6]=M,e[7]=n,e[8]=z,e[9]=c,e[10]=te):te=e[10];const U=te;let ae;e[11]!==ue||e[12]!==P?(ae=pe=>{P(pe?ue:null)},e[11]=ue,e[12]=P,e[13]=ae):ae=e[13];const je=ae,oe=$P,ve=BP,K=_P;let ce;e[14]===Symbol.for("react.memo_cache_sentinel")?(ce=pe=>{(pe.button===2||pe.button===0&&pe.ctrlKey)&&(re.current=!0)},e[14]=ce):ce=e[14];const Z=ce;let le;e[15]!==x?(le=()=>{if(re.current){re.current=!1;return}x()},e[15]=x,e[16]=le):le=e[16];const se=le;let Ie;e[17]!==O?(Ie=kd.Transform.toString(O),e[17]=O,e[18]=Ie):Ie=e[18];let Ne;e[19]!==Ie||e[20]!==_?(Ne={transform:Ie,transition:_},e[19]=Ie,e[20]=_,e[21]=Ne):Ne=e[21];const Y=ee&&"opacity-30";let fe;e[22]!==Y?(fe=me("relative",Y),e[22]=Y,e[23]=fe):fe=e[23];let ke;e[24]!==v||e[25]!==L||e[26]!==je||e[27]!==se||e[28]!==f||e[29]!==N||e[30]!==q||e[31]!==n||e[32]!==U||e[33]!==m||e[34]!==p||e[35]!==h||e[36]!==Q||e[37]!==u||e[38]!==b||e[39]!==$||e[40]!==k||e[41]!==g||e[42]!==w||e[43]!==y||e[44]!==a||e[45]!==d||e[46]!==V||e[47]!==r||e[48]!==D||e[49]!==C||e[50]!==T?(ke=N?null:s.jsxs(s.Fragment,{children:[h&&s.jsx("div",{ref:D,"data-project-id":n,className:"absolute top-0 h-px w-full pointer-events-none","aria-hidden":"true"}),s.jsx("div",{className:me("w-full text-left group/project select-none"),style:{backgroundColor:h&&b?"transparent":void 0},children:s.jsxs("div",{className:"relative flex items-center gap-1 px-0.5 py-0.5",...L,children:[s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsxs("button",{type:"button",onMouseDown:Z,onClick:se,...$,className:me("flex-1 min-w-0 flex items-center gap-1.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 rounded-md cursor-grab active:cursor-grabbing transition-[padding]",u&&!f?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:me("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(I,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"arrow-down-s",className:"h-3.5 w-3.5"})}),U?s.jsx("span",{className:me("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:U,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>ne(!0)})}):V?s.jsx(I,{name:V,className:me("h-3.5 w-3.5",v?"hidden":"group-hover/project:hidden group-focus-within/project:hidden"),style:q?{color:q}:void 0}):s.jsx(I,{name:"folder",className:me("h-3.5 w-3.5 text-muted-foreground/80",v?"hidden":"group-hover/project:hidden group-focus-within/project:hidden"),style:q?{color:q}:void 0})]}),s.jsx("span",{className:me("text-[14px] font-normal truncate lowercase",m?"text-foreground":"text-foreground group-hover/project:text-foreground"),children:r})]})}),s.jsx(Pt,{side:"right",sideOffset:8,children:a})]}),s.jsxs("div",{className:me("absolute top-1/2 z-10 flex -translate-y-1/2 items-center gap-1",C?"right-7":"right-0.5"),children:[C&&u&&!f&&w?s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:pe=>{pe.stopPropagation(),w()},className:me("inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 hover:text-foreground transition-opacity",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":T("sessions.sidebar.project.actions.newWorktree"),children:s.jsx(I,{name:"node-tree",className:"h-4 w-4"})})}),s.jsx(Pt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:T("sessions.sidebar.project.actions.newWorktreeEllipsis")})})]}):null,s.jsxs(Bs,{open:Q,onOpenChange:je,children:[s.jsx(Os,{asChild:!0,children:s.jsx("button",{type:"button",className:me("inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground transition-opacity focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 hover:text-foreground",Q?"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":T("sessions.sidebar.project.actions.projectMenu"),onPointerDown:ve,onMouseDown:K,onClick:oe,children:s.jsx(I,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsxs($s,{align:"end",className:"min-w-[180px]",children:[C&&!u&&!f&&g&&s.jsxs(zt,{onClick:g,children:[s.jsx(I,{name:"add",className:"mr-1.5 h-4 w-4"}),T("sessions.sidebar.project.actions.newSession")]}),s.jsxs(zt,{onClick:y,children:[s.jsx(I,{name:"pencil-ai",className:"mr-1.5 h-4 w-4"}),T("sessions.sidebar.session.menu.rename")]}),s.jsxs(zt,{onClick:k,className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"close",className:"mr-1.5 h-4 w-4"}),T("sessions.sidebar.project.actions.closeProject")]})]})]})]}),C&&g?s.jsx("div",{className:"absolute right-0.5 top-1/2 z-10 -translate-y-1/2",children:s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:pe=>{pe.stopPropagation(),g()},className:me("inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",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":T(u?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession"),children:s.jsx(I,{name:"add",className:"h-4 w-4"})})}),s.jsx(Pt,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:T(u?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession")})})]})}):null]})})]}),e[24]=v,e[25]=L,e[26]=je,e[27]=se,e[28]=f,e[29]=N,e[30]=q,e[31]=n,e[32]=U,e[33]=m,e[34]=p,e[35]=h,e[36]=Q,e[37]=u,e[38]=b,e[39]=$,e[40]=k,e[41]=g,e[42]=w,e[43]=y,e[44]=a,e[45]=d,e[46]=V,e[47]=r,e[48]=D,e[49]=C,e[50]=T,e[51]=ke):ke=e[51];let be;return e[52]!==j||e[53]!==B||e[54]!==Ne||e[55]!==fe||e[56]!==ke?(be=s.jsxs("div",{ref:B,style:Ne,className:fe,children:[ke,j]}),e[52]=j,e[53]=B,e[54]=Ne,e[55]=fe,e[56]=ke,e[57]=be):be=e[57],be},LP=t=>{const e=at.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:h}=Sd(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 f=b;let v;e[6]!==m?(v=kd.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=h&&"opacity-50";let w;e[11]!==g?(w=me("space-y-0.5 rounded-md",g),e[11]=g,e[12]=w):w=e[12];let y;e[13]!==a||e[14]!==f?(y=typeof a=="function"?a(f):a,e[13]=a,e[14]=f,e[15]=y):y=e[15];let k;return e[16]!==d||e[17]!==x||e[18]!==w||e[19]!==y?(k=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]=k):k=e[20],k},OP=l.memo(LP);function $P(t){t.stopPropagation()}function BP(t){t.stopPropagation()}function _P(t){t.stopPropagation()}function VP(t){const e=at.c(25),{t:n}=pt();let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={activationConstraint:{distance:8}},e[0]=r):r=e[0];let a;e[1]===Symbol.for("react.memo_cache_sentinel")?(a={coordinateGetter:vx},e[1]=a):a=e[1];const i=Qo(Li(Yo,r),Li(bx,a));let o;e[2]===Symbol.for("react.memo_cache_sentinel")?(o={activationConstraint:{distance:8}},e[2]=o):o=e[2];const c=Qo(Li(Yo,o));if(t.projectSections.length===0){const h=(t.mobileVariant,"");let b;e[3]!==h?(b=me("space-y-1 pb-1 pl-2.5 pr-2",h),e[3]=h,e[4]=b):b=e[4];let f;return e[5]!==t.emptyState||e[6]!==t.topContent||e[7]!==b?(f=s.jsxs(Ts,{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]=f):f=e[8],f}if(t.sectionsForRender.length===0){const h=(t.mobileVariant,"");let b;e[9]!==h?(b=me("space-y-1 pb-1 pl-2.5 pr-2",h),e[9]=h,e[10]=b):b=e[10];let f;return e[11]!==t.searchEmptyState||e[12]!==b?(f=s.jsx(Ts,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:b,children:t.searchEmptyState}),e[11]=t.searchEmptyState,e[12]=b,e[13]=f):f=e[13],f}const d=(t.mobileVariant,"");let p;e[14]!==d?(p=me("space-y-1 pb-1 pl-2.5 pr-2",d),e[14]=d,e[15]=p):p=e[15];let m;e[16]!==c||e[17]!==i||e[18]!==t||e[19]!==n?(m=t.showOnlyMainWorkspace?s.jsx("div",{className:"space-y-[0.6rem] py-1",children:(()=>{const h=t.sectionsForRender.find(x=>x.project.id===t.activeProjectId)??t.sectionsForRender[0];if(!h)return t.hasSessionSearchQuery?t.searchEmptyState:t.emptyState;const b=h.groups.find(JP)??h.groups.find(qP)??h.groups.find(GP)??h.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 f=h.groups.find(HP);return[b,...f&&f.id!==b.id?[f]:[]].map(x=>{const g=`${h.project.id}:${x.id}`,w=x.id===b.id;return s.jsx(l.Fragment,{children:t.renderGroupSessions(x,g,h.project.id,w,null,!0)},g)})})()}):s.jsx(s.Fragment,{children:s.jsxs(Zo,{sensors:i,collisionDetection:el,onDragEnd:h=>{if(t.isInlineEditing)return;const{active:b,over:f}=h;if(!f||b.id===f.id)return;const v=t.sectionsForRender.findIndex(g=>g.project.id===b.id),x=t.sectionsForRender.findIndex(g=>g.project.id===f.id);v===-1||x===-1||v===x||t.reorderProjects(v,x)},children:[s.jsx(Vc,{items:t.sectionsForRender.map(KP),strategy:lu,children:t.sectionsForRender.map(h=>{const b=h.project,f=b.id,v=Xh(b.label?.trim()||Da(b.normalizedPath,t.homeDirectory)||b.normalizedPath),x=Hi(b.normalizedPath,t.homeDirectory),g=t.collapsedProjects.has(f),w=f===t.activeProjectId,y=t.projectRepoStatus.get(f),k=t.getOrderedGroups(f,h.groups),D=k.find(WP)??null,j=D?k.filter(S=>S.id!==D.id):k;return s.jsx(FP,{id:f,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(f),hideDirectoryControls:t.hideDirectoryControls,mobileVariant:t.mobileVariant,alwaysShowActions:t.alwaysShowActions,onToggle:()=>t.toggleProject(f),onNewSession:()=>{f!==t.activeProjectId&&t.setActiveProjectIdOnly(f),t.setActiveMainTab("chat"),t.mobileVariant&&t.setSessionSwitcherOpen(!1),t.openNewSessionDraft({directoryOverride:b.normalizedPath})},onNewWorktreeSession:()=>{f!==t.activeProjectId&&t.setActiveProjectIdOnly(f),t.setActiveMainTab("chat"),t.mobileVariant&&t.setSessionSwitcherOpen(!1),t.openNewWorktreeDialog()},onRenameStart:()=>t.openProjectEditDialog(f),onClose:()=>t.removeProject(f),sentinelRef:S=>{t.projectHeaderSentinelRefs.current.set(f,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:h.groups.length>0?s.jsxs(Zo,{sensors:c,collisionDetection:el,onDragEnd:S=>{if(t.isInlineEditing)return;const{active:A,over:E}=S;if(!E||A.id===E.id)return;const P=j.findIndex(M=>M.id===A.id),C=j.findIndex(M=>M.id===E.id);if(P===-1||C===-1||P===C)return;const N=yx(j,P,C).map(UP),T=D?[D.id,...N]:N;t.setGroupOrderByProject(M=>{const R=new Map(M);return R.set(f,T),R})},children:[D?t.renderGroupSessions(D,`${f}:${D.id}`,f,!0):null,s.jsx(Vc,{items:j.map(zP),strategy:lu,children:j.map(S=>{const A=`${f}:${S.id}`;return s.jsx(OP,{id:S.id,disabled:t.isInlineEditing,children:E=>t.renderGroupSessions(S,A,f,!1,E)},S.id)})}),s.jsx(Xo,{dropAnimation:null})]}):s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:n("sessions.sidebar.empty.noSessions.title")})})},f)})}),s.jsx(Xo,{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(Ts,{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 zP(t){return t.id}function UP(t){return t.id}function WP(t){return t.isMain}function KP(t){return t.project.id}function HP(t){return t.isArchivedBucket}function GP(t){return t.isMain}function qP(t){return t.sessions.length>0}function JP(t){return t.isMain&&t.sessions.length>0}function QP(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 YP(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 XP(t){const e=t.info.role==="user"?"User":"Assistant",n=QP(t.info.time?.created),r=YP(t),a=n&&r?`${n} (${r})`:n||r;return a?`**${e}**
182
-
183
- *${a}*`:`**${e}**`}function ZP(t){return t.filter(e=>e.type==="text"&&typeof e.text=="string").map(e=>e.text).join("")}function vg(t){const e=XP(t),n=ZP(t.parts).trim();return n?`${e}
184
-
185
- ${n}`:""}function wg(t,e){const n="#".repeat(Math.min(e+1,6)),r=t.agent?` — ${t.agent}`:"",a=`${n} Sub-agent: ${t.title}${r}
186
-
187
- ---
188
-
189
- `,i=t.records.map(vg).filter(Boolean).join(`
190
-
191
- ---
192
-
193
- `),o=[a+i];for(const c of t.children)o.push(wg(c,e+1));return o.join(`
194
-
195
- ---
196
-
197
- `)}function e6(t,e,n){const r=e?.trim()||"Session",a=new Date().toISOString().split("T")[0],i=`# ${r}
198
-
199
- *Exported on ${a}*
200
-
201
- ---
202
-
203
- `,o=t.map(vg).filter(Boolean).join(`
204
-
205
- ---
206
-
207
- `);let c=i+o;if(n&&n.length>0){const d=n.map(p=>wg(p,1)).join(`
208
-
209
- ---
210
-
211
- `);c+=`
212
-
213
- ---
214
-
215
- `+d}return c}function t6(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 s6(t,e){const n=await ly(e,t);if(n)return n;if(!dn())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 n6(t){const e=dr()?.files;if(e?.revealPath)try{return!!(await e.revealPath(t))?.success}catch{return!1}return await cy(t)?!0:tl(t)}function r6(){return Fd()}function a6(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 i6=(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},lr=tr()((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 h of m)o.delete(h);d===n&&(d=null)}else{for(const h of m)o.add(h);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,h]=p<=m?[p,m]:[m,p],b=a.slice(u,h+1),f=i6(b,o),x=i!==null&&c.scopeKey!==null&&i!==c.scopeKey?new Set:new Set(c.selectedIds);for(const g of f)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}))}})),o6=/^[a-z0-9](?:[a-z0-9-]{0,48}[a-z0-9])?$/,Jo=t=>{if(!t)return null;const e=t.split("/");if(e.length!==3&&e.length!==4)return null;const[n,r,a,i]=e;if(!o6.test(n)||!r?.trim()||!a?.trim()||r!==r.trim()||a!==a.trim())return null;if(e.length===3)return{groupSlug:n,providerID:r,modelID:a,fusion:!1};if(i==="fusion")return{groupSlug:n,providerID:r,modelID:a,fusion:!0};if(!/^\d+$/.test(i))return null;const o=Number.parseInt(i,10);return!Number.isSafeInteger(o)||o<=0?null:{groupSlug:n,providerID:r,modelID:a,index:o,fusion:!1}},l6=(t,e,n)=>`${t}/${e}/${n}/fusion`,jg=t=>{const e=at.c(35),{value:n,onChange:r,className:a,disabled:i,id:o,portalToBody:c}=t,{t:d}=pt(),p=gt(c6),m=gt(d6),u=gt(u6);let h;e[0]!==p?(h=p(),e[0]=p,e[1]=h):h=e[1];const b=h;let f;e[2]!==b?(f=b.filter(m6),e[2]=b,e[3]=f):f=e[3];const v=f;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 T=typeof u=="string"&&u.trim().length>0?u.trim():null;if(T&&v.some(R=>R.name===T)){r(T);return}const M=v[0]?.name;M&&r(M)},y=[u,i,r,v,n],e[7]=u,e[8]=i,e[9]=r,e[10]=v,e[11]=n,e[12]=w,e[13]=y):(w=e[12],y=e[13]),l.useEffect(w,y);const k=n.trim().length>0?n:void 0;let D;e[14]!==a?(D=me("max-w-full typography-meta text-foreground !border-border/80 !bg-[var(--surface-subtle)] hover:!bg-[var(--interactive-hover)]/70 data-[popup-open]:!bg-[var(--interactive-active)]/70",a),e[14]=a,e[15]=D):D=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(ys,{placeholder:j}),e[18]=j,e[19]=S):S=e[19];let A;e[20]!==o||e[21]!==D||e[22]!==S?(A=s.jsx(us,{id:o,size:"lg",className:D,children:S}),e[20]=o,e[21]=D,e[22]=S,e[23]=A):A=e[23];let E;e[24]!==v?(E=v.length>0&&s.jsx(Gc,{children:v.map(p6)}),e[24]=v,e[25]=E):E=e[25];let P;e[26]!==c||e[27]!==E?(P=s.jsx(ms,{fitContent:!0,portalToBody:c,children:E}),e[26]=c,e[27]=E,e[28]=P):P=e[28];let C;return e[29]!==i||e[30]!==r||e[31]!==k||e[32]!==A||e[33]!==P?(C=s.jsxs(ds,{value:k,onValueChange:r,disabled:i,children:[A,P]}),e[29]=i,e[30]=r,e[31]=k,e[32]=A,e[33]=P,e[34]=C):C=e[34],C};function c6(t){return t.getVisibleAgents}function d6(t){return t.loadAgents}function u6(t){return t.currentAgentName}function m6(t){return t.mode!=="subagent"}function p6(t){return s.jsx(Lt,{value:t.name,className:"w-auto whitespace-nowrap",children:t.name},t.name)}const Ng="h-7",bl=()=>`${Date.now()}-${Math.random().toString(36).substring(2,9)}`,h6=new Intl.NumberFormat("en-US",{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}),f6=t=>{if(typeof t!="number"||Number.isNaN(t))return"";if(t===0)return"0";const e=h6.format(t);return e.endsWith(".0")?e.slice(0,-2):e},g6=t=>{const e=at.c(12),{model:n,instanceIndex:r,totalSameModel:a,onRemove:i}=t,o=n.displayName||`${n.providerID}/${n.modelID}`,c=a>1?`${o} (${r})`:o;let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=me("flex items-center gap-1.5 px-2 rounded-md bg-interactive-selection/20 border border-border/30",Ng),e[0]=d):d=e[0];let p;e[1]!==n.providerID?(p=s.jsx(Sn,{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(I,{name:"close",className:"h-3.5 w-3.5"}),e[5]=u):u=e[5];let h;e[6]!==i?(h=s.jsx("button",{type:"button",onClick:i,className:"text-muted-foreground hover:text-foreground ml-0.5",children:u}),e[6]=i,e[7]=h):h=e[7];let b;return e[8]!==p||e[9]!==m||e[10]!==h?(b=s.jsxs("div",{className:d,children:[p,m,h]}),e[8]=p,e[9]=m,e[10]=h,e[11]=b):b=e[11],b},Sg=({selectedModels:t,onAdd:e,onRemove:n,onUpdate:r,minModels:a,addButtonLabel:i,showChips:o=!0,maxModels:c,addButtonClassName:d,dropdownSide:p="top",dropdownClassName:m,containerClassName:u,triggerIcon:h})=>{const{t:b}=pt(),f=gt(Q=>Q.providers),v=gt(Q=>Q.modelsMetadata),{favoriteModelsList:x,recentModelsList:g}=Fh(),[w,y]=l.useState(!1),[k,D]=l.useState(""),[j,S]=l.useState(0),[A,E]=l.useState(null),P=l.useRef(null),C=l.useRef(null),N=l.useRef(null),T=l.useRef([]),M=c===1,R=c===void 0||t.length<c||M,L=l.useMemo(()=>{const Q=new Map;for(const de of t){const X=`${de.providerID}:${de.modelID}`;Q.set(X,(Q.get(X)||0)+1)}return Q},[t]),$=l.useCallback(Q=>t.filter(X=>X.providerID===Q.providerID&&X.modelID===Q.modelID).findIndex(X=>X.instanceId===Q.instanceId)+1,[t]),B=(Q,de)=>{const X=`${Q}/${de}`;return v.get(X)},O=Q=>{const de=Q?.name||Q?.id||"",X=String(de);return X.length>40?X.substring(0,37)+"...":X},_=l.useCallback((Q,de)=>{if(!k.trim())return!0;const X=k.toLowerCase();return Q.toLowerCase().includes(X)||de.toLowerCase().includes(X)},[k]),ee=l.useMemo(()=>x.filter(({model:Q,providerID:de})=>{const F=f.find(q=>q.id===de)?.name||de,V=O(Q);return _(V,F)}),[x,f,_]),z=l.useMemo(()=>g.filter(({model:Q,providerID:de})=>{const F=f.find(q=>q.id===de)?.name||de,V=O(Q);return _(V,F)}),[g,f,_]),ne=l.useMemo(()=>f.map(Q=>{const X=(Array.isArray(Q.models)?Q.models:[]).filter(F=>{const V=O(F);return _(V,Q.name||Q.id||"")});return{...Q,models:X}}).filter(Q=>Q.models.length>0),[f,_]),re=ee.length>0||z.length>0||ne.length>0;l.useEffect(()=>{if(!w||!N.current)return;const Q=N.current.getBoundingClientRect();if(p==="bottom"){const te=(window.visualViewport?.height??document.documentElement.clientHeight??window.innerHeight)-Q.bottom-16-112;E(Math.max(160,Math.min(320,te)));return}let de=N.current.parentElement;for(;de&&!(de.getAttribute("role")==="dialog"||de.hasAttribute("data-scroll-shadow"));){const V=getComputedStyle(de);if(V.overflow==="auto"||V.overflow==="hidden"||V.overflowY==="auto"||V.overflowY==="hidden")break;de=de.parentElement}const X=de?de.getBoundingClientRect().top:0,F=Q.top-X-16;E(Math.max(150,Math.min(300,F)))},[p,w]),l.useEffect(()=>{w&&P.current&&P.current.focus()},[w]),l.useEffect(()=>{!R&&w&&(y(!1),D(""),S(0))},[R,w]),l.useEffect(()=>{if(!w)return;const Q=de=>{C.current&&!C.current.contains(de.target)&&(y(!1),D(""),S(0))};return document.addEventListener("mousedown",Q),()=>document.removeEventListener("mousedown",Q)},[w]),l.useEffect(()=>{S(0)},[k]);const ue=(Q,de,X,F,V,q)=>{const te=`${de}:${X}`,U=L.get(te)||0,ae=B(de,X),je=f6(ae?.limit?.context),oe=F==="fav"||F==="recent";return s.jsxs("button",{ref:ve=>{T.current[V]=ve},type:"button",disabled:!R,onClick:()=>{const ve={providerID:de,modelID:X,displayName:Q.name||X,instanceId:bl()};if(M&&t.length>0&&r){r(0,ve),y(!1),D(""),S(0);return}e({...ve}),M&&(y(!1),D(""),S(0))},onMouseEnter:()=>S(V),className:me("w-full text-left px-2 py-1.5 rounded-md typography-meta transition-colors flex items-center gap-2",R&&(q?"bg-interactive-selection":"hover:bg-interactive-hover/50"),!R&&"cursor-not-allowed opacity-60"),children:[s.jsxs("div",{className:"flex items-center gap-1.5 flex-1 min-w-0",children:[oe&&s.jsx(Sn,{providerId:de,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"font-medium truncate",children:O(Q)}),je&&s.jsx("span",{className:"typography-micro text-muted-foreground flex-shrink-0",children:je})]}),U>0&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex-shrink-0",children:["×",U]})]},`${F}-${te}`)};return s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex flex-wrap gap-1.5 items-center",children:[s.jsxs("div",{className:me("relative",u),ref:C,children:[s.jsxs(we,{ref:N,type:"button",variant:"outline",size:"sm",className:me(Ng,"!border-border/80 !bg-[var(--surface-subtle)] hover:!bg-[var(--interactive-hover)]/70",d),disabled:!R,onClick:()=>{y(!w)},children:[h??s.jsx(I,{name:"add",className:"h-3.5 w-3.5 mr-1"}),i??b("multirun.modelMultiSelect.actions.addModel")]}),w&&(()=>{const Q=[];ee.forEach(({model:V,providerID:q,modelID:te})=>{Q.push({model:V,providerID:q,modelID:te,section:"fav"})}),z.forEach(({model:V,providerID:q,modelID:te})=>{Q.push({model:V,providerID:q,modelID:te,section:"recent"})}),ne.forEach(V=>{V.models.forEach(q=>{Q.push({model:q,providerID:V.id,modelID:q.id,section:"provider"})})});const de=Q.length,X=V=>{if(!dy(V))if(V.key==="ArrowDown"){V.preventDefault(),V.stopPropagation();const q=(j+1)%Math.max(1,de);S(q),setTimeout(()=>{T.current[q]?.scrollIntoView({behavior:"smooth",block:"nearest"})},0)}else if(V.key==="ArrowUp"){V.preventDefault(),V.stopPropagation();const q=(j-1+Math.max(1,de))%Math.max(1,de);S(q),setTimeout(()=>{T.current[q]?.scrollIntoView({behavior:"smooth",block:"nearest"})},0)}else if(V.key==="Enter"){V.preventDefault(),V.stopPropagation();const q=Q[j];if(q&&R){const te={providerID:q.providerID,modelID:q.modelID,displayName:q.model.name||q.modelID,instanceId:bl()};M&&t.length>0&&r?r(0,te):e(te),M&&(y(!1),D(""),S(0))}}else V.key==="Escape"&&(V.preventDefault(),V.stopPropagation(),y(!1),D(""),S(0))};let F=0;return s.jsxs("div",{className:me("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",p==="top"?"bottom-full mb-1":"top-full mt-1",m),style:{background:"linear-gradient(var(--surface-elevated),var(--surface-elevated)),linear-gradient(var(--surface-background),var(--surface-background))"},children:[s.jsx("div",{className:"p-2 border-b border-border/40",children:s.jsxs("div",{className:"relative",children:[s.jsx(I,{name:"search",className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Kt,{ref:P,type:"text",placeholder:b("multirun.modelMultiSelect.search.placeholder"),value:k,onChange:V=>D(V.target.value),onKeyDown:X,className:"h-8 pl-8 typography-meta"})]})}),s.jsx(Ts,{outerClassName:"flex-1",style:{maxHeight:A?`${A}px`:"300px"},children:s.jsxs("div",{className:"p-1",children:[!re&&s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:b("multirun.modelMultiSelect.search.noResults")}),ee.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"typography-micro font-semibold text-muted-foreground uppercase tracking-wider sticky top-0 z-10 -mx-1 flex items-center gap-2 border-b border-border/30 px-3 py-1.5 [background:linear-gradient(var(--surface-elevated),var(--surface-elevated)),linear-gradient(var(--surface-background),var(--surface-background))]",children:[s.jsx(I,{name:"star-fill",className:"h-4 w-4 text-primary"}),b("multirun.modelMultiSelect.sections.favorites")]}),ee.map(({model:V,providerID:q,modelID:te})=>{const U=F++;return ue(V,q,te,"fav",U,j===U)})]}),z.length>0&&s.jsxs(s.Fragment,{children:[ee.length>0&&s.jsx("div",{className:"h-px bg-border/40 my-1"}),s.jsxs("div",{className:"typography-micro font-semibold text-muted-foreground uppercase tracking-wider sticky top-0 z-10 -mx-1 flex items-center gap-2 border-b border-border/30 px-3 py-1.5 [background:linear-gradient(var(--surface-elevated),var(--surface-elevated)),linear-gradient(var(--surface-background),var(--surface-background))]",children:[s.jsx(I,{name:"time",className:"h-4 w-4"}),b("multirun.modelMultiSelect.sections.recent")]}),z.map(({model:V,providerID:q,modelID:te})=>{const U=F++;return ue(V,q,te,"recent",U,j===U)})]}),(ee.length>0||z.length>0)&&ne.length>0&&s.jsx("div",{className:"h-px bg-border/40 my-1"}),ne.map((V,q)=>s.jsxs(l.Fragment,{children:[q>0&&s.jsx("div",{className:"h-px bg-border/40 my-1"}),s.jsxs("div",{className:"typography-micro font-semibold text-muted-foreground uppercase tracking-wider sticky top-0 z-10 -mx-1 flex items-center gap-2 border-b border-border/30 px-3 py-1.5 [background:linear-gradient(var(--surface-elevated),var(--surface-elevated)),linear-gradient(var(--surface-background),var(--surface-background))]",children:[s.jsx(Sn,{providerId:V.id,className:"h-4 w-4 flex-shrink-0"}),V.name]}),V.models.map(te=>{const U=F++;return ue(te,V.id,te.id,"provider",U,j===U)})]},V.id))]})}),s.jsx("div",{className:"px-3 pt-1 pb-1.5 border-t border-border/40 typography-micro text-muted-foreground",children:b("multirun.modelMultiSelect.keyboard.hint")})]})})()]}),o&&t.length>0&&s.jsx("div",{className:"flex flex-col gap-2 w-full",children:t.map((Q,de)=>{const X=`${Q.providerID}:${Q.modelID}`,F=L.get(X)||1,V=$(Q),te=f.find(ve=>ve.id===Q.providerID)?.models.find(ve=>ve.id===Q.modelID),U=te?.variants?Object.keys(te.variants):[],ae=U.length>0,je="__default__",oe=Q.variant??je;return s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(g6,{model:Q,instanceIndex:V,totalSameModel:F,onRemove:()=>n(de)}),ae&&s.jsxs(ds,{value:oe,onValueChange:ve=>{if(!r)return;r(de,{...Q,variant:ve===je?void 0:ve})},children:[s.jsxs(us,{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(I,{name:"brain-ai-3",className:me("h-3.5 w-3.5 flex-shrink-0",oe===je?"text-muted-foreground":"text-[color:var(--status-info)]")}),s.jsx(ys,{placeholder:b("multirun.modelMultiSelect.variant.placeholder"),children:ve=>ve===je?b("multirun.modelMultiSelect.variant.default"):ve})]}),s.jsxs(ms,{fitContent:!0,children:[s.jsx(Lt,{value:je,className:"pr-2 [&>span:first-child]:hidden",children:b("multirun.modelMultiSelect.variant.default")}),U.map(ve=>s.jsx(Lt,{value:ve,className:"pr-2 [&>span:first-child]:hidden",children:ve},ve))]})]})]},Q.instanceId)})})]}),a!==void 0&&t.length<a&&s.jsx("p",{className:"typography-micro text-muted-foreground",children:c!==void 0?b("multirun.modelMultiSelect.validation.minToMax",{min:a,max:c}):b("multirun.modelMultiSelect.validation.minOnly",{min:a})})]})},x6=(t,e,n)=>{const r=t.session.title?.trim()||t.session.id;return`
216
-
217
- --- RESULT ${n+1}: ${r} ---
218
- ${e.trim()}
219
- --- END RESULT ${n+1} ---`},nh=(t,e)=>Vt.getState().getWorktreeMetadata(t)?.projectDirectory??e,b6=async t=>{const e=t.directory??void 0,n=uy(t.session.id,e);if(n.length===0&&t.directory){const a=(await rn.withDirectory(t.directory,()=>rn.getSdkClient().session.messages({sessionID:t.session.id,directory:t.directory??void 0,limit:50}))).data??[];for(let i=a.length-1;i>=0;i-=1){const o=a[i];if(o.info?.role==="assistant")return Tu(o.parts??[]).trim()}return""}for(let r=n.length-1;r>=0;r-=1){const a=n[r];if(a.role==="assistant")return Tu(my(a.id,e)).trim()}return""};function y6({session:t,open:e,onOpenChange:n}){const{t:r}=pt(),a=Cd(),i=ja(B=>B.activeSessions),o=ja(B=>B.archivedSessions),c=gt(B=>B.providers),d=gt(B=>B.currentProviderId),p=gt(B=>B.currentModelId),m=gt(B=>B.currentAgentName),[u,h]=l.useState(d??""),[b,f]=l.useState(p??""),[v,x]=l.useState(()=>d&&p?[{providerID:d,modelID:p,instanceId:bl()}]:[]),[g,w]=l.useState(""),[y,k]=l.useState(m??""),[D,j]=l.useState([]),[S,A]=l.useState(!1),E=l.useMemo(()=>Jo(t.title),[t.title]),P=l.useMemo(()=>{const B=new Map;for(const O of a)B.set(O.id,O);for(const O of i)B.set(O.id,O);for(const O of o)B.set(O.id,O);return t.id&&B.set(t.id,t),Array.from(B.values())},[i,o,a,t]);l.useEffect(()=>{if(!e||!E)return;const B=Vt.getState().getDirectoryForSession(t.id),O=nh(t.id,B),_=P.map(ee=>{const z=Jo(ee.title);if(!z||z.groupSlug!==E.groupSlug||z.fusion)return null;const ne=Vt.getState().getDirectoryForSession(ee.id)??Bi(ee),re=nh(ee.id,ne);return O&&re&&O!==re?null:{session:ee,directory:ne,projectDirectory:re}}).filter(ee=>ee!==null).sort((ee,z)=>(ee.session.time?.created??0)-(z.session.time?.created??0));j(_)},[P,e,E,t.id]);const N=c.find(B=>B.id===u)?.models.find(B=>B.id===b),T=N?.variants?Object.keys(N.variants):[],M=!!(E&&u&&b&&D.length>0&&!S),R=l.useCallback(B=>{x([B]),h(B.providerID),f(B.modelID),w("")},[]),L=v[0]?.displayName||v[0]?.modelID||r("multirun.fusion.model.placeholder"),$=async()=>{if(!(!E||!u||!b)){A(!0);try{const B=await Promise.all(D.map(ue=>b6(ue))),O=D.map((ue,Q)=>({source:ue,text:B[Q]??""})).filter(ue=>ue.text.trim().length>0);if(O.length===0){H.error(r("multirun.fusion.toast.noOutputs"));return}const _=D[0]?.projectDirectory??D[0]?.directory??null,ee=l6(E.groupSlug,u,b),[z,ne]=await Promise.all([kn("session.fusion.visible"),kn("session.fusion.instructions")]),re=await Vt.getState().createSession(ee,_,null);if(!re)throw new Error("Failed to create fusion session");Vt.getState().setCurrentSession(re.id,_),n(!1),await rn.withDirectory(_??rn.getDirectory(),()=>rn.sendMessage({id:re.id,providerID:u,modelID:b,variant:g||void 0,agent:y||void 0,text:z,additionalParts:[{text:ne,synthetic:!0},...O.map((ue,Q)=>({text:x6(ue.source,ue.text,Q),synthetic:!0})),{text:`
220
-
221
- --- FUSION INPUTS END ---
222
- Now write the final fused answer.`,synthetic:!0}]}))}catch(B){console.error("[MultiRunFusion] Failed to start fusion",B),H.error(r("multirun.fusion.toast.failed"))}finally{A(!1)}}};return s.jsx(ws,{open:e,onOpenChange:n,children:s.jsxs(vs,{className:"max-w-xl overflow-visible",children:[s.jsxs(Cs,{children:[s.jsx(js,{children:r("multirun.fusion.title")}),s.jsx(Rs,{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(Sg,{selectedModels:v,onAdd:R,onUpdate:(B,O)=>R(O),onRemove:()=>{x([]),h(""),f(""),w("")},maxModels:1,addButtonLabel:L,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(Sn,{providerId:u,className:"h-3.5 w-3.5 mr-1"}):void 0})}),T.length>0?s.jsxs(ds,{value:g||"__default__",onValueChange:B=>w(B==="__default__"?"":B),children:[s.jsxs(us,{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(I,{name:"brain-ai-3",className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx(ys,{children:B=>B==="__default__"?r("multirun.modelMultiSelect.variant.default"):B})]}),s.jsxs(ms,{fitContent:!0,portalToBody:!0,children:[s.jsx(Lt,{value:"__default__",children:r("multirun.modelMultiSelect.variant.default")}),T.map(B=>s.jsx(Lt,{value:B,children:B},B))]})]}):null,s.jsx(jg,{value:y,onChange:k,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:D.length})}),s.jsx("div",{className:"max-h-56 space-y-1 overflow-auto rounded-lg border border-[var(--interactive-border)] p-1",children:D.map(B=>s.jsxs("div",{className:"flex items-center gap-2 rounded-md px-2 py-1.5 typography-meta",children:[s.jsx(Sn,{providerId:Jo(B.session.title)?.providerID??"",className:"h-4 w-4"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:B.session.title||B.session.id}),s.jsx("button",{type:"button",onClick:()=>j(O=>O.filter(_=>_.session.id!==B.session.id)),className:"text-muted-foreground hover:text-foreground",children:s.jsx(I,{name:"close",className:"h-4 w-4"})})]},B.session.id))})]}),s.jsxs(Ks,{children:[s.jsx(we,{variant:"ghost",onClick:()=>n(!1),children:r("multirun.fusion.actions.cancel")}),s.jsx(we,{onClick:$,disabled:!M,children:r(S?"multirun.fusion.actions.starting":"multirun.fusion.actions.start")})]})]})})}function v6(t){const e=at.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 rh=t=>t.children.length===0?"":t.children.map(e=>`${e.session.id}:${e.children.length}`).join("|"),xa=(t,e)=>{if(!e)return!1;if(t.session.id===e)return!0;for(const n of t.children)if(xa(n,e))return!0;return!1},yd=(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(yd(i,e,n,r))return!0;return!1},w6=(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||rh(t.node)!==rh(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=xa(t.node,t.currentSessionId),u=xa(e.node,e.currentSessionId);if(m||u)return!1}if(t.pinnedSessionIds.has(a)!==e.pinnedSessionIds.has(i)||t.expandedParents.has(a)!==e.expandedParents.has(i)||t.hasSessionSearchQuery!==e.hasSessionSearchQuery||t.normalizedSessionSearchQuery!==e.normalizedSessionSearchQuery||t.notifyOnSubtasks!==e.notifyOnSubtasks)return!1;if(t.editingId!==e.editingId){const m=xa(t.node,t.editingId),u=xa(e.node,e.editingId);if(m||u)return!1}if(t.editTitle!==e.editTitle){const m=xa(t.node,t.editingId),u=xa(e.node,e.editingId);if(m||u)return!1}if(t.copiedSessionId===a!=(e.copiedSessionId===i))return!1;const o=yd(t.node,t.openSidebarMenuKey,t.renderContext??"project",t.archivedBucket??!1),c=yd(e.node,e.openSidebarMenuKey,e.renderContext??"project",e.archivedBucket??!1);if(o!==c)return!1;const d=ks(n.directory??null)??ks(t.groupDirectory??null),p=ks(r.directory??null)??ks(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 j6(t){const{t:e}=pt(),{node:n,depth:r=0,groupDirectory:a,projectId:i,archivedBucket:o=!1,directoryStatus:c,currentSessionId:d,pinnedSessionIds:p,expandedParents:m,hasSessionSearchQuery:u,normalizedSessionSearchQuery:h,notifyOnSubtasks:b,editingId:f,setEditingId:v,editTitle:x,setEditTitle:g,handleSaveEdit:w,handleCancelEdit:y,toggleParent:k,handleSessionSelect:D,handleSessionDoubleClick:j,togglePinnedSession:S,handleShareSession:A,copiedSessionId:E,handleCopyShareUrl:P,handleUnshareSession:C,openSidebarMenuKey:N,setOpenSidebarMenuKey:T,renamingFolderId:M,getFoldersForScope:R,getSessionFolderId:L,removeSessionFromFolder:$,addSessionToFolder:B,createFolderAndStartRename:O,openContextPanelTab:_,handleDeleteSession:ee,mobileVariant:z,alwaysShowActions:ne,renderSessionNode:re,secondaryMeta:ue,renderContext:Q="project"}=t,de=!!ue?.projectLabel,X=!!ue?.branchLabel,V=wa(ft=>ft.displayMode)==="minimal",q=l.useMemo(()=>dn(),[]),te=l.useMemo(()=>Id(),[]),U=q?"group-hover:opacity-100 group-hover:pointer-events-auto":"group-hover:opacity-100 group-hover:pointer-events-auto group-focus-within:opacity-100 group-focus-within:pointer-events-auto",ae=q?"group-hover:opacity-0":"group-hover:opacity-0 group-focus-within:opacity-0",je=!o&&!z,oe=V?q?"group-hover:pr-2":"group-hover:pr-2 group-focus-within:pr-2":q?je?"group-hover:pr-12":"group-hover:pr-5":je?"group-hover:pr-12 group-focus-within:pr-12":"group-hover:pr-5 group-focus-within:pr-5",ve=je?"pr-13":"pr-7",K=l.useRef(!1),[ce,Z]=l.useState(!1),le=n.session,Ie=Dh(le.id)??le,Ne=ks(le.directory??null)??ks(a??null),Y=py(Ne??void 0),fe=_d(),ke=lr(ft=>ft.enabled),be=lr(l.useCallback(ft=>ft.selectedIds.has(le.id),[le.id])),pe=lr(ft=>ft.toggleSelected),Ee=lr(ft=>ft.setRange),ze=l.useCallback(ft=>{const hs=[],J=ct=>{ct.children.forEach(vt=>{hs.push(vt.session.id),J(vt)})};return J(ft),hs},[]),[G,Pe]=l.useState(!1),[Le,Ae]=l.useState(!0),ge=`${Q}:${o?"archived":"active"}:${le.id}`,W=Zh(l.useCallback(ft=>!!ft.sessionMemoryState.get(le.id)?.isZombie,[le.id])),ie=hy(le.id),Me=fy(le.id,Ne??void 0),Ce=(Ne?c.get(Ne):null)==="missing",xe=d===le.id,De=Ie.title||e("sessions.sidebar.session.untitled"),Ye=n.children.length>0,rt=p.has(le.id),Re=u?!0:m.has(le.id),he=!!Ie.parentID,et=gy(le.id)>0&&(!he||b),Ke=Ie.summary,st=Mh(Ke),nt=Ie.time?.updated||Ie.time?.created||Date.now(),ye=xy(nt),Je=wy(nt),_e=N===ge,Ue=l.useMemo(()=>Jo(Ie.title)!==null,[Ie.title]),[ot,Xe]=l.useState(!1),We=l.useMemo(()=>ze(n).length,[ze,n]),bt=l.useCallback(async ft=>{const hs=[];let J=0;for(const ct of ft)try{await fe.ensureSessionRenderable(ct.session.id);const vt=Mu(Y.getState(),ct.session.id).list,Tt=ct.session.title||e("sessions.sidebar.session.export.untitledSubagent"),Yt=ct.session.agent,Zt=await bt(ct.children);J+=Zt.skipped,hs.push({title:Tt,agent:Yt,records:vt,children:Zt.children})}catch{J+=ze(ct).length+1}return{children:hs,skipped:J}},[ze,Y,fe,e]),Dt=l.useCallback(ft=>{ft<=0||H.warning(ft===1?e("sessions.sidebar.session.export.skippedSubtaskSingle",{count:ft}):e("sessions.sidebar.session.export.skippedSubtaskMany",{count:ft}))},[e]),Ht=l.useCallback(async ft=>{if(!Ne){H.error(e("sessions.sidebar.session.export.nothingToExport"));return}await fe.ensureSessionRenderable(le.id);const hs=Mu(Y.getState(),le.id).list;if(hs.length===0){H.error(e("sessions.sidebar.session.export.nothingToExport"));return}let J,ct=0;if(ft&&n.children.length>0){const Zt=await bt(n.children);J=Zt.children,ct=Zt.skipped}const vt=e6(hs,Ie.title??null,J),Tt=a6(Ie.title??null),Yt=await s6(vt,Tt);if(Yt){H.success(e("sessions.sidebar.session.export.success"),{action:{label:e(r6()),onClick:()=>{n6(Yt).then(Zt=>{Zt||H.error(e("sessions.sidebar.session.export.failedRevealPath"))})}}}),Dt(ct);return}t6(vt,Tt),H.success(e("sessions.sidebar.session.export.success")),Dt(ct)},[bt,Y,n.children,Ie.title,le.id,Ne,Dt,fe,e]),rs=l.useCallback(async()=>{if(n.children.length>0){Ae(!0),Pe(!0);return}await Ht(!1)},[Ht,n.children.length]),jt=l.useCallback(()=>{Ne&&sl("desktop_open_session_mini_chat_window",{sessionId:le.id,directory:Ne}).catch(ft=>{console.warn("[session-sidebar] failed to open mini chat window",ft)})},[le.id,Ne]);if(f===le.id)return s.jsx("div",{className:me("group relative flex items-center rounded-sm px-1.5 py-1",r>0&&"pl-[20px]"),children:s.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-0",children:[s.jsxs("form",{className:"flex w-full items-center gap-2",onSubmit:ft=>{ft.preventDefault(),w()},children:[s.jsx("input",{value:x,onChange:ft=>g(ft.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:ft=>{if(ft.key==="Escape"){ft.stopPropagation(),y();return}(ft.key===" "||ft.key==="Enter")&&ft.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(I,{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(I,{name:"close",className:"size-4"})})]}),V?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:[Ye?s.jsx("span",{className:"inline-flex items-center justify-center flex-shrink-0",children:Re?s.jsx(I,{name:"arrow-down-s",className:"h-3 w-3"}):s.jsx(I,{name:"arrow-right-s",className:"h-3 w-3"})}):null,s.jsx("span",{className:"flex-shrink-0",children:ye}),st?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:["+",st.additions]}),s.jsxs("span",{className:"text-status-error/65",children:["/-",st.deletions]})]}):null,de?s.jsx("span",{className:"truncate",children:ue?.projectLabel}):null,X?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(I,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:ue?.branchLabel})]}):null]})})]})},le.id);const St=ie?.type??"idle",ns=St==="busy"||St==="retry",ut=Me.length,Xt=ns||!ns&&et&&!xe,Wt=ns?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")}),is=Xt||rt?s.jsxs("span",{className:me("pointer-events-none absolute inline-flex h-3.5 items-center justify-center gap-0.5 transition-opacity",V?"top-1/2 -translate-y-1/2":"top-[14.5px] -translate-y-1/2",Xt&&rt?"left-[-18px] w-6":"left-[-10px] w-3.5",Ye&&!ne?"opacity-100 group-hover:opacity-0 group-focus-within:opacity-0":""),children:[Xt?Wt:null,rt?s.jsx(I,{name:"pushpin",className:"h-3 w-3 flex-shrink-0 text-primary","aria-label":e("sessions.sidebar.session.status.pinned")}):null]}):null,gs=Ye?s.jsx("span",{role:"button",tabIndex:0,onClick:ft=>{ft.stopPropagation(),k(le.id)},onKeyDown:ft=>{(ft.key==="Enter"||ft.key===" ")&&(ft.preventDefault(),ft.stopPropagation(),k(le.id))},className:me("absolute left-[-10px] inline-flex h-3.5 w-3.5 items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",V?"top-1/2 -translate-y-1/2":"top-[14.5px] -translate-y-1/2",V&&Xt&&!ne?"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(Re?"sessions.sidebar.session.subsessions.collapse":"sessions.sidebar.session.subsessions.expand"),children:Re?s.jsx(I,{name:"arrow-down-s",className:"h-3 w-3"}):s.jsx(I,{name:"arrow-right-s",className:"h-3 w-3"})}):null,ps=W?s.jsx(I,{name:"error-warning",className:"h-4 w-4 text-status-warning"}):null,Ns=ft=>{T(ft?ge:null)},Mt=ft=>{ft.preventDefault(),ft.stopPropagation(),T(_e?null:ge)},He=ft=>{ft.preventDefault(),ft.stopPropagation()},At=ft=>{ft.preventDefault(),ft.stopPropagation()},Et=ft=>{ft.preventDefault(),ft.stopPropagation()},wt=ft=>{ft.preventDefault(),ft.stopPropagation()},$t=ft=>{ft.preventDefault(),ft.stopPropagation(),T(null),ee(le,{archivedBucket:o})},qt=ft=>{if(K.current){K.current=!1;return}if(ke){if(ft?.preventDefault(),ft?.stopPropagation(),ft?.shiftKey){const J=(typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[]).map(Tt=>Tt.getAttribute("data-session-row")).filter(Tt=>typeof Tt=="string"&&Tt.length>0),ct=lr.getState().anchorId,vt=new Map;vt.set(le.id,ze(n)),Ee(ct,le.id,J,Ne??null,vt);return}pe(le.id,Ne??null,ze(n));return}D(le.id,Ne,Ce,i)},Ms=ft=>{(ft.button===2||ft.button===0&&ft.ctrlKey&&!ke)&&(K.current=!0)},cs=ft=>{z&&ft.pointerType==="touch"&&Z(!0)},Is=ft=>{z&&ft.pointerType==="touch"&&Z(!1)},Es=s.jsxs($s,{align:"end",className:"min-w-[180px]",onCloseAutoFocus:ft=>{M&&ft.preventDefault()},children:[s.jsxs(zt,{onClick:()=>{v(le.id),g(De)},className:"[&>svg]:mr-1",children:[s.jsx(I,{name:"pencil-ai",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.rename")]}),s.jsxs(zt,{onClick:()=>S(le.id),className:"[&>svg]:mr-1",children:[rt?s.jsx(I,{name:"unpin",className:"mr-1 h-4 w-4"}):s.jsx(I,{name:"pushpin",className:"mr-1 h-4 w-4"}),e(rt?"sessions.sidebar.session.menu.unpin":"sessions.sidebar.session.menu.pin")]}),Ie.share?s.jsxs(s.Fragment,{children:[s.jsx(zt,{onClick:()=>{Ie.share?.url&&P(Ie.share.url,le.id)},className:"[&>svg]:mr-1",children:E===le.id?s.jsxs(s.Fragment,{children:[s.jsx(I,{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(I,{name:"file-copy",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.copyLink")]})}),s.jsxs(zt,{onClick:()=>C(le.id),className:"[&>svg]:mr-1",children:[s.jsx(I,{name:"link-unlink-m",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.unshare")]})]}):s.jsxs(zt,{onClick:()=>A(Ie),className:"[&>svg]:mr-1",children:[s.jsx(I,{name:"share-2",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.share")]}),s.jsxs(zt,{onClick:()=>{rs()},className:"[&>svg]:mr-1",children:[s.jsx(I,{name:"download",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.exportMarkdown")]}),Ue?s.jsxs(zt,{onClick:()=>Xe(!0),className:"[&>svg]:mr-1",children:[s.jsx(v6,{className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.runFusion")]}):null,Ne&&!o?(()=>{const ft=R(Ne),hs=L(Ne,le.id);return s.jsxs(s.Fragment,{children:[s.jsx(Dn,{}),s.jsxs(by,{children:[s.jsxs(yy,{className:"[&>svg]:mr-1",children:[s.jsx(I,{name:"folder",className:"h-4 w-4"}),e("sessions.sidebar.folders.moveToFolder")]}),s.jsxs(vy,{className:"min-w-[180px]",children:[ft.length===0?s.jsx(zt,{disabled:!0,className:"text-muted-foreground",children:e("sessions.sidebar.folders.none")}):ft.map(J=>s.jsxs(zt,{onClick:()=>{hs===J.id?$(Ne,le.id):B(Ne,J.id,le.id)},children:[s.jsx("span",{className:"flex-1 truncate",children:J.name}),hs===J.id?s.jsx(I,{name:"check",className:"ml-2 h-3.5 w-3.5 text-primary flex-shrink-0"}):null]},J.id)),s.jsx(Dn,{}),s.jsxs(zt,{onClick:()=>{const J=O(Ne);J&&B(Ne,J.id,le.id)},children:[s.jsx(I,{name:"add",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.newFolderEllipsis")]}),hs?s.jsxs(zt,{onClick:()=>{$(Ne,le.id)},className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"close",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.removeFromFolder")]}):null]})]})]})})():null,q?null:s.jsxs(zt,{disabled:!Ne,onClick:()=>{Ne&&_(Ne,{mode:"chat",dedupeKey:`session:${le.id}`,label:De})},className:"[&>svg]:mr-1",children:[s.jsx(I,{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")})]}),te?s.jsxs(zt,{disabled:!Ne,onClick:jt,className:"[&>svg]:mr-1",children:[s.jsx(I,{name:"window",className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:e("sessions.sidebar.session.menu.openMiniChatWindow")})]}):null,s.jsx(Dn,{}),s.jsxs(zt,{className:"text-destructive focus:text-destructive [&>svg]:mr-1",onClick:()=>ee(le,{archivedBucket:o}),children:[s.jsx(I,{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(pP,{sessionId:le.id,sessionDirectory:Ne??null,sessionTitle:De,children:s.jsxs("div",{"data-session-row":le.id,"data-session-scope":Ne??"","data-session-archived":o?"1":"0",className:me("group relative my-0.5 flex items-center rounded-sm px-1.5 py-1",Ce?"opacity-75":"",r>0&&"pl-[20px]",be&&"bg-primary/15"),children:[is,gs,s.jsx("div",{className:"flex min-w-0 flex-1 items-center",children:V?s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",disabled:Ce,onPointerDown:cs,onPointerUp:Is,onPointerCancel:Is,onMouseDown:Ms,onClick:ft=>qt(ft),onDoubleClick:ft=>{ft.stopPropagation(),j()},className:me("flex min-w-0 flex-1 cursor-pointer flex-col gap-0 overflow-hidden rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 text-foreground select-none disabled:cursor-not-allowed transition-[padding]",ce&&"bg-interactive-hover/70",ne?q?oe:ve:oe),children:s.jsxs("div",{className:me("flex w-full items-center min-w-0 flex-1 overflow-hidden","gap-1"),children:[s.jsx("div",{className:me("block min-w-0 flex-1 truncate typography-ui-label font-normal",xe?"text-primary":"text-foreground"),children:_i(De,h)}),ne?s.jsx("span",{className:"ml-2 flex-shrink-0 text-[0.72rem] text-muted-foreground/75",children:Je}):null,ne?null:s.jsx("div",{className:"relative ml-1 flex h-4 min-w-4 flex-shrink-0 items-center justify-end",children:s.jsx("span",{className:me("whitespace-nowrap text-right text-[0.72rem] text-muted-foreground/75 transition-opacity duration-150",_e?"opacity-0":ae),children:Je})}),ut>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(I,{name:"shield",className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:ut})]}):null]})})}),s.jsx(Pt,{side:"right",sideOffset:8,className:"max-w-xs text-left",children:s.jsxs("div",{className:"flex flex-col gap-1 text-left text-xs",children:[s.jsxs("div",{className:me("flex items-center gap-3 text-left text-muted-foreground",ue?.projectLabel?"justify-between":"justify-start"),children:[ue?.projectLabel?s.jsx("div",{className:"min-w-0 truncate",children:ue.projectLabel}):null,s.jsx("div",{className:"flex-shrink-0",children:ye})]}),ue?.branchLabel||st?s.jsxs("div",{className:me("flex items-center gap-3 text-left text-muted-foreground",ue?.branchLabel?"justify-between":"justify-start"),children:[ue?.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(I,{name:"git-branch",className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:ue.branchLabel})]})}):null,st?s.jsxs("span",{className:"flex flex-shrink-0 items-center gap-0.5",children:[s.jsxs("span",{className:"text-status-success",children:["+",st.additions]}),s.jsxs("span",{className:"text-status-error",children:["-",st.deletions]})]}):null]}):null]})})]}):s.jsxs("button",{type:"button",disabled:Ce,onPointerDown:cs,onPointerUp:Is,onPointerCancel:Is,onMouseDown:Ms,onClick:ft=>qt(ft),onDoubleClick:ft=>{ft.stopPropagation(),j()},className:me("flex min-w-0 flex-1 cursor-pointer flex-col gap-0 overflow-hidden rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 text-foreground select-none disabled:cursor-not-allowed transition-[padding]",ce&&"bg-interactive-hover/70",ne?q?oe:ve:oe),children:[s.jsxs("div",{className:me("flex w-full items-center min-w-0 flex-1 overflow-hidden","gap-1"),children:[s.jsx("div",{className:me("block min-w-0 flex-1 truncate typography-ui-label font-normal",xe?"text-primary":"text-foreground"),children:_i(De,h)}),ut>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(I,{name:"shield",className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:ut})]}):null]}),V?null:s.jsx("div",{className:"flex items-center justify-between gap-3 text-muted-foreground/60 min-w-0 overflow-hidden leading-tight",style:{fontSize:"calc(var(--text-ui-label) * 0.85)"},children:s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 overflow-hidden",children:[s.jsx("span",{className:"flex-shrink-0",children:ye}),st?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:["+",st.additions]}),s.jsx("span",{className:"text-muted-foreground/60",children:"/"}),s.jsxs("span",{className:"text-status-error/65",children:["-",st.deletions]})]}):null,de?s.jsx("span",{className:"truncate",children:ue?.projectLabel}):null,X?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(I,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:ue?.branchLabel})]}):null]})})]})}),ps&&!z?s.jsx("div",{className:me("absolute top-1/2 -translate-y-1/2 z-10",V?"right-0":"right-[30px]"),children:ps}):null,s.jsxs("div",{className:me("absolute right-0 top-1/2 z-10 flex -translate-y-1/2 items-center gap-0.5 transition-opacity",_e||ne&&!q?"opacity-100":me("opacity-0",U)),children:[je?s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",className:me("inline-flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",V&&!ne?"h-4 w-4":"h-6 w-6"),"aria-label":e("sessions.sidebar.bulkActions.archive"),onPointerDown:Et,onMouseDown:wt,onClick:$t,onKeyDown:ft=>ft.stopPropagation(),children:s.jsx(I,{name:"archive",className:me(V&&!ne?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),s.jsx(Pt,{side:"left",sideOffset:8,children:e("sessions.sidebar.bulkActions.archive")})]}):null,s.jsxs(Bs,{open:_e,onOpenChange:Ns,children:[s.jsx(Os,{asChild:!0,children:s.jsx("button",{type:"button",className:me("inline-flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",V&&!ne?_e?"h-4 w-4 opacity-100":me("h-4 w-4 opacity-0",U):"h-6 w-6 opacity-100"),"aria-label":e("sessions.sidebar.session.menu.label"),onPointerDown:He,onMouseDown:At,onClick:Mt,onKeyDown:ft=>ft.stopPropagation(),children:s.jsx(I,{name:"more-2",className:me(V&&!ne?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),Es]})]})]})}),Ye&&Re?n.children.map(ft=>re(ft,r+1,Ne??a,i,o,void 0,Q)):null,s.jsx(ws,{open:G,onOpenChange:Pe,children:s.jsxs(vs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[s.jsxs(Cs,{children:[s.jsx(js,{children:e("sessions.sidebar.session.export.dialog.title")}),s.jsx(Rs,{children:We===1?e("sessions.sidebar.session.export.dialog.descriptionSingle",{count:We}):e("sessions.sidebar.session.export.dialog.descriptionMany",{count:We})})]}),s.jsxs("label",{className:"flex items-center gap-2 typography-ui-label cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:Le,onChange:ft=>Ae(ft.target.checked),className:"h-4 w-4 rounded border-border accent-primary"}),e("sessions.sidebar.session.export.dialog.includeSubtasks")]}),s.jsxs(Ks,{children:[s.jsx(we,{type:"button",onClick:()=>Pe(!1),variant:"outline",size:"sm",children:e("sessions.sidebar.dialogs.cancel")}),s.jsx(we,{type:"button",onClick:()=>{Pe(!1),Ht(Le)},size:"sm",children:e("sessions.sidebar.session.export.dialog.confirm")})]})]})}),Ue?s.jsx(y6,{session:Ie,open:ot,onOpenChange:Xe}):null]},le.id)}const N6=l.memo(j6,w6);function S6(t){const e=at.c(71),{t:n}=pt(),{value:r,setValue:a,showDeletionDialog:i,setShowDeletionDialog:o,onConfirm:c}=t;let d,p,m,u,h,b,f,v,x,g;if(e[0]!==a||e[1]!==n||e[2]!==r){const O=n("sessions.sidebar.session.untitled");u=ws,x=!!r,e[13]!==a?(g=ee=>{ee||a(null)},e[13]=a,e[14]=g):g=e[14],m=vs,f=!1,v="max-w-sm gap-5",p=Cs;let _;e[15]!==n||e[16]!==r?.archivedBucket?(_=r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.title"):n("sessions.sidebar.dialogs.archiveSession.title"),e[15]=n,e[16]=r?.archivedBucket,e[17]=_):_=e[17],e[18]!==_?(b=s.jsx(js,{children:_}),e[18]=_,e[19]=b):b=e[19],d=Rs,h=r&&r.descendantCount>0?r.archivedBucket?r.descendantCount===1?n("sessions.sidebar.dialogs.deleteSession.withOneSubtask",{sessionTitle:r.session.title||O,count:r.descendantCount}):n("sessions.sidebar.dialogs.deleteSession.withManySubtasks",{sessionTitle:r.session.title||O,count:r.descendantCount}):r.descendantCount===1?n("sessions.sidebar.dialogs.archiveSession.withOneSubtask",{sessionTitle:r.session.title||O,count:r.descendantCount}):n("sessions.sidebar.dialogs.archiveSession.withManySubtasks",{sessionTitle:r.session.title||O,count:r.descendantCount}):r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.single",{sessionTitle:r?.session.title||O}):n("sessions.sidebar.dialogs.archiveSession.single",{sessionTitle:r?.session.title||O}),e[0]=a,e[1]=n,e[2]=r,e[3]=d,e[4]=p,e[5]=m,e[6]=u,e[7]=h,e[8]=b,e[9]=f,e[10]=v,e[11]=x,e[12]=g}else d=e[3],p=e[4],m=e[5],u=e[6],h=e[7],b=e[8],f=e[9],v=e[10],x=e[11],g=e[12];let w;e[20]!==d||e[21]!==h?(w=s.jsx(d,{children:h}),e[20]=d,e[21]=h,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 k;e[27]!==o||e[28]!==i?(k=()=>o(!i),e[27]=o,e[28]=i,e[29]=k):k=e[29];const D=!i;let j;e[30]!==i?(j=i?s.jsx(I,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(I,{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 A;e[34]!==j||e[35]!==S||e[36]!==k||e[37]!==D?(A=s.jsxs("button",{type:"button",onClick:k,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":D,children:[j,S]}),e[34]=j,e[35]=S,e[36]=k,e[37]=D,e[38]=A):A=e[38];let E;e[39]!==a?(E=()=>a(null),e[39]=a,e[40]=E):E=e[40];let P;e[41]!==n?(P=n("sessions.sidebar.dialogs.cancel"),e[41]=n,e[42]=P):P=e[42];let C;e[43]!==E||e[44]!==P?(C=s.jsx("button",{type:"button",onClick:E,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:P}),e[43]=E,e[44]=P,e[45]=C):C=e[45];let N;e[46]!==c?(N=()=>{c()},e[46]=c,e[47]=N):N=e[47];let T;e[48]!==n||e[49]!==r?.archivedBucket?(T=r?.archivedBucket?n("sessions.sidebar.bulkActions.delete"):n("sessions.sidebar.bulkActions.archive"),e[48]=n,e[49]=r?.archivedBucket,e[50]=T):T=e[50];let M;e[51]!==N||e[52]!==T?(M=s.jsx("button",{type:"button",onClick:N,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:T}),e[51]=N,e[52]=T,e[53]=M):M=e[53];let R;e[54]!==C||e[55]!==M?(R=s.jsxs("div",{className:"flex items-center gap-2",children:[C,M]}),e[54]=C,e[55]=M,e[56]=R):R=e[56];let L;e[57]!==A||e[58]!==R?(L=s.jsxs(Ks,{className:"w-full sm:items-center sm:justify-between",children:[A,R]}),e[57]=A,e[58]=R,e[59]=L):L=e[59];let $;e[60]!==m||e[61]!==f||e[62]!==L||e[63]!==v||e[64]!==y?($=s.jsxs(m,{showCloseButton:f,className:v,children:[y,L]}),e[60]=m,e[61]=f,e[62]=L,e[63]=v,e[64]=y,e[65]=$):$=e[65];let B;return e[66]!==u||e[67]!==$||e[68]!==x||e[69]!==g?(B=s.jsx(u,{open:x,onOpenChange:g,children:$}),e[66]=u,e[67]=$,e[68]=x,e[69]=g,e[70]=B):B=e[70],B}function k6(t){const e=at.c(57),{t:n}=pt(),{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 h;e[4]!==d||e[5]!==p||e[6]!==n?(h=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]=h):h=e[7];const b=h,f=!!r;let v;e[8]!==a?(v=B=>{B||a(null)},e[8]=a,e[9]=v):v=e[9];let x;e[10]!==u?(x=s.jsx(js,{children:u}),e[10]=u,e[11]=x):x=e[11];let g;e[12]!==b?(g=s.jsx(Rs,{children:b}),e[12]=b,e[13]=g):g=e[13];let w;e[14]!==x||e[15]!==g?(w=s.jsxs(Cs,{children:[x,g]}),e[14]=x,e[15]=g,e[16]=w):w=e[16];let y;e[17]!==o||e[18]!==i?(y=()=>o(!i),e[17]=o,e[18]=i,e[19]=y):y=e[19];const k=!i;let D;e[20]!==i?(D=i?s.jsx(I,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(I,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[20]=i,e[21]=D):D=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]!==k||e[27]!==D?(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":k,children:[D,j]}),e[24]=j,e[25]=y,e[26]=k,e[27]=D,e[28]=S):S=e[28];let A;e[29]!==a?(A=()=>a(null),e[29]=a,e[30]=A):A=e[30];let E;e[31]!==n?(E=n("sessions.sidebar.dialogs.cancel"),e[31]=n,e[32]=E):E=e[32];let P;e[33]!==A||e[34]!==E?(P=s.jsx("button",{type:"button",onClick:A,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:E}),e[33]=A,e[34]=E,e[35]=P):P=e[35];let C;e[36]!==c?(C=()=>{c()},e[36]=c,e[37]=C):C=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 T;e[41]!==C||e[42]!==N?(T=s.jsx("button",{type:"button",onClick:C,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]=C,e[42]=N,e[43]=T):T=e[43];let M;e[44]!==P||e[45]!==T?(M=s.jsxs("div",{className:"flex items-center gap-2",children:[P,T]}),e[44]=P,e[45]=T,e[46]=M):M=e[46];let R;e[47]!==S||e[48]!==M?(R=s.jsxs(Ks,{className:"w-full sm:items-center sm:justify-between",children:[S,M]}),e[47]=S,e[48]=M,e[49]=R):R=e[49];let L;e[50]!==R||e[51]!==w?(L=s.jsxs(vs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[w,R]}),e[50]=R,e[51]=w,e[52]=L):L=e[52];let $;return e[53]!==f||e[54]!==L||e[55]!==v?($=s.jsx(ws,{open:f,onOpenChange:v,children:L}),e[53]=f,e[54]=L,e[55]=v,e[56]=$):$=e[56],$}function C6(t){const e=at.c(36),{t:n}=pt(),{value:r,setValue:a,onConfirm:i}=t,o=!!r;let c;e[0]!==a?(c=D=>{D||a(null)},e[0]=a,e[1]=c):c=e[1];let d;e[2]!==n?(d=n("sessions.sidebar.dialogs.deleteFolder.title"),e[2]=n,e[3]=d):d=e[3];let p;e[4]!==d?(p=s.jsx(js,{children:d}),e[4]=d,e[5]=p):p=e[5];let m;e[6]!==n||e[7]!==r?(m=r&&(r.subFolderCount>0||r.sessionCount>0)?r.subFolderCount>0?r.subFolderCount===1?n("sessions.sidebar.dialogs.deleteFolder.withOneSubfolder",{folderName:r.folderName,count:r.subFolderCount}):n("sessions.sidebar.dialogs.deleteFolder.withManySubfolders",{folderName:r.folderName,count:r.subFolderCount}):n("sessions.sidebar.dialogs.deleteFolder.withContentsNoSubfolders",{folderName:r.folderName}):n("sessions.sidebar.dialogs.deleteFolder.single",{folderName:r?.folderName??""}),e[6]=n,e[7]=r,e[8]=m):m=e[8];let u;e[9]!==m?(u=s.jsx(Rs,{children:m}),e[9]=m,e[10]=u):u=e[10];let h;e[11]!==p||e[12]!==u?(h=s.jsxs(Cs,{children:[p,u]}),e[11]=p,e[12]=u,e[13]=h):h=e[13];let b;e[14]!==a?(b=()=>a(null),e[14]=a,e[15]=b):b=e[15];let f;e[16]!==n?(f=n("sessions.sidebar.dialogs.cancel"),e[16]=n,e[17]=f):f=e[17];let v;e[18]!==b||e[19]!==f?(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:f}),e[18]=b,e[19]=f,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(Ks,{children:[v,g]}),e[26]=g,e[27]=v,e[28]=w):w=e[28];let y;e[29]!==w||e[30]!==h?(y=s.jsxs(vs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[h,w]}),e[29]=w,e[30]=h,e[31]=y):y=e[31];let k;return e[32]!==o||e[33]!==c||e[34]!==y?(k=s.jsx(ws,{open:o,onOpenChange:c,children:y}),e[32]=o,e[33]=c,e[34]=y,e[35]=k):k=e[35],k}const I6=t=>{const e=at.c(46),{selectedCount:n,scopeKey:r,scopeFolders:a,archivedBucket:i,onMoveToFolder:o,onCreateFolderAndMove:c,onRemoveFromFolder:d,canRemoveFromFolder:p,onDelete:m,onDone:u}=t,{t:h}=pt(),b=!!r&&!i;let f;e[0]!==i||e[1]!==h?(f=h(i?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[0]=i,e[1]=h,e[2]=f):f=e[2];const v=f;let x;e[3]!==n||e[4]!==h?(x=h("sessions.sidebar.bulkActions.selectedCount",{count:n}),e[3]=n,e[4]=h,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]!==h?(w=b?s.jsxs(Bs,{children:[s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(Os,{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":h("sessions.sidebar.bulkActions.moveToFolder"),children:s.jsx(I,{name:"folder",className:"h-4 w-4"})})})}),s.jsx(Pt,{side:"top",sideOffset:4,children:s.jsx("p",{children:h("sessions.sidebar.bulkActions.moveToFolder")})})]}),s.jsxs($s,{align:"end",className:"min-w-[180px]",children:[a.length===0?s.jsx(zt,{disabled:!0,className:"text-muted-foreground",children:h("sessions.sidebar.folders.none")}):a.map(L=>s.jsx(zt,{onClick:()=>o(L.id),children:s.jsx("span",{className:"flex-1 truncate",children:L.name})},L.id)),s.jsx(Dn,{}),s.jsxs(zt,{onClick:c,children:[s.jsx(I,{name:"add",className:"mr-1 h-4 w-4"}),h("sessions.sidebar.folders.newFolderEllipsis")]}),p?s.jsxs(zt,{onClick:d,className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"close",className:"mr-1 h-4 w-4"}),h("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]=h,e[15]=w):w=e[15];let y;e[16]===Symbol.for("react.memo_cache_sentinel")?(y=me("inline-flex h-7 w-7 items-center justify-center rounded-md text-destructive hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50"),e[16]=y):y=e[16];let k;e[17]===Symbol.for("react.memo_cache_sentinel")?(k=s.jsx(I,{name:"delete-bin",className:"h-4 w-4"}),e[17]=k):k=e[17];let D;e[18]!==v||e[19]!==m?(D=s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:m,className:y,"aria-label":v,children:k})}),e[18]=v,e[19]=m,e[20]=D):D=e[20];let j;e[21]!==v?(j=s.jsx(Pt,{side:"top",sideOffset:4,children:s.jsx("p",{children:v})}),e[21]=v,e[22]=j):j=e[22];let S;e[23]!==D||e[24]!==j?(S=s.jsxs(kt,{children:[D,j]}),e[23]=D,e[24]=j,e[25]=S):S=e[25];let A;e[26]!==h?(A=h("sessions.sidebar.header.actions.exitSelection"),e[26]=h,e[27]=A):A=e[27];let E;e[28]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx(I,{name:"close",className:"h-4 w-4"}),e[28]=E):E=e[28];let P;e[29]!==u||e[30]!==A?(P=s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:u,className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":A,children:E})}),e[29]=u,e[30]=A,e[31]=P):P=e[31];let C;e[32]!==h?(C=h("sessions.sidebar.header.actions.exitSelection"),e[32]=h,e[33]=C):C=e[33];let N;e[34]!==C?(N=s.jsx(Pt,{side:"top",sideOffset:4,children:s.jsx("p",{children:C})}),e[34]=C,e[35]=N):N=e[35];let T;e[36]!==P||e[37]!==N?(T=s.jsxs(kt,{children:[P,N]}),e[36]=P,e[37]=N,e[38]=T):T=e[38];let M;e[39]!==T||e[40]!==w||e[41]!==S?(M=s.jsxs("div",{className:"ml-auto flex items-center gap-0.5",children:[w,S,T]}),e[39]=T,e[40]=w,e[41]=S,e[42]=M):M=e[42];let R;return e[43]!==M||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,M]}),e[43]=M,e[44]=g,e[45]=R):R=e[45],R},kg="oc.sessions.activeNow",P6=2160*60*1e3,Cg=t=>!!t.parentID,eu=t=>!!t.time?.archived,vd=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},A6=t=>{try{const e=t.getItem(kg);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[]}},Ec=(t,e)=>{try{t.setItem(kg,JSON.stringify(e))}catch{}},D6=(t,e,n=Date.now())=>{const r=n-P6;return t.filter(a=>{const i=e.get(a.sessionId);return i?eu(i)?!1:vd(i)>=r:!0})},T6=(t,e)=>!e||t.some(n=>n.sessionId===e)?t:[{sessionId:e},...t],Ig=t=>[...t].sort((e,n)=>vd(n)-vd(e)),M6=(t,e)=>{const n=t.map(r=>e.get(r.sessionId)??null).filter(r=>!!r).filter(r=>!eu(r)).filter(r=>!Cg(r));return Ig(n)},E6=(t,e)=>{const n=t.filter(r=>{if(eu(r)||Cg(r))return!1;const a=e[r.id];return a?.type==="busy"||a?.type==="retry"});return Ig(n)},To=Zr(),Rc=tr((t,e)=>({entries:A6(To),setEntries:n=>{n!==e().entries&&(t({entries:n}),Ec(To,n))},addSession:n=>{const r=T6(e().entries,n);r!==e().entries&&(t({entries:r}),Ec(To,r))},prune:n=>{const r=e().entries,a=D6(r,n);a.length===r.length&&a.every((i,o)=>i.sessionId===r[o]?.sessionId)||(t({entries:a}),Ec(To,a))}})),Mo="oc.sessions.projectCollapse",ah="oc.sessions.groupOrder",ih="oc.sessions.groupCollapse",oh="oc.sessions.activeSessionByProject",Fc="oc.sessions.expandedParents",R6="oc.sessions.pinned",F6=(t,e)=>{const n=new Set;for(const r of t){const a=ks(r.path)?.toLowerCase();a&&n.add(a)}for(const r of e.values())for(const a of r){const i=ks(a.path)?.toLowerCase();i&&n.add(i)}return n},L6=(t,e)=>{if(t.time?.archived)return!0;const n=ks(Bi(t))?.toLowerCase();return!n||e.size===0?!0:e.has(n)},O6=5*6e4,lh=({mobileVariant:t=!1,onSessionSelected:e,allowReselect:n=!1,hideDirectoryControls:r=!1,showOnlyMainWorkspace:a=!1})=>{const{t:i}=pt(),[o,c]=l.useState(!1),[d,p]=l.useState(""),m=l.useRef(null),u=l.useRef(null),h=l.useRef(new Set),[b,f]=l.useState(null),[v,x]=l.useState(""),[g,w]=l.useState(null),[y,k]=l.useState(new Set),[D]=l.useState(()=>new Map),j=l.useMemo(()=>Zr(),[]),S=Rc(Fe=>Fe.entries),A=Rc(Fe=>Fe.addSession),E=Rc(Fe=>Fe.prune),[P,C]=l.useState(new Set),[N,T]=l.useState(new Map),[M,R]=l.useState(new Set),[L,$]=l.useState(!1),[B,O]=l.useState(!1),[_,ee]=l.useState(null),[z,ne]=l.useState(null),[re,ue]=l.useState(""),[Q,de]=l.useState(null),[X,F]=l.useState(null),[V,q]=l.useState(null),te=Zl(Fe=>Fe.ids),U=Zl(Fe=>Fe.setIds),ae=Zl(Fe=>Fe.toggle),[je,oe]=l.useState(()=>{try{const Fe=Zr().getItem(ih);if(!Fe)return new Set;const Nt=JSON.parse(Fe);return new Set(Array.isArray(Nt)?Nt.filter(ht=>typeof ht=="string"):[])}catch{return new Set}}),[ve,K]=l.useState(()=>{try{const Fe=Zr().getItem(ah);if(!Fe)return new Map;const Nt=JSON.parse(Fe),ht=new Map;return Object.entries(Nt).forEach(([ts,Se])=>{Array.isArray(Se)&&ht.set(ts,Se.filter(Qe=>typeof Qe=="string"))}),ht}catch{return new Map}}),[ce,Z]=l.useState(()=>{try{const Fe=Zr().getItem(oh);if(!Fe)return new Map;const Nt=JSON.parse(Fe),ht=new Map;return Object.entries(Nt).forEach(([ts,Se])=>{typeof Se=="string"&&Se.length>0&&ht.set(ts,Se)}),ht}catch{return new Map}}),[le,se]=l.useState(new Map),Ie=l.useRef(new Map),Ne=l.useRef(0),Y=Vs(Fe=>Fe.homeDirectory),fe=Vs(Fe=>Fe.currentDirectory),ke=Vs(Fe=>Fe.setDirectory),be=Fs(Fe=>Fe.projects),pe=Fs(Fe=>Fe.activeProjectId),Ee=Fs(Fe=>Fe.removeProject),ze=Fs(Fe=>Fe.setActiveProjectIdOnly),G=Fs(Fe=>Fe.updateProjectMeta),Pe=Fs(Fe=>Fe.reorderProjects),Le=Te(Fe=>Fe.setActiveMainTab),Ae=Te(Fe=>Fe.openContextPanelTab),ge=Te(Fe=>Fe.setSettingsDialogOpen),W=Te(Fe=>Fe.toggleHelpDialog),ie=Te(Fe=>Fe.setAboutDialogOpen),Me=Te(Fe=>Fe.setSessionSwitcherOpen),Ve=Te(Fe=>Fe.setScheduledTasksDialogOpen),Ce=Te(Fe=>Fe.toggleSidebar),xe=Te(Fe=>Fe.openMultiRunLauncher),De=Te(Fe=>Fe.notifyOnSubtasks),Ye=Te(Fe=>Fe.showDeletionDialog),rt=Te(Fe=>Fe.setShowDeletionDialog),Re=Cl(d,120),he=l.useMemo(()=>Re.trim().toLowerCase(),[Re]),qe=he.length>0,et=qn(Fe=>Fe.collapsedFolderIds),Ke=qn(Fe=>Fe.foldersMap),st=qn(Fe=>Fe.getFoldersForScope),nt=qn(Fe=>Fe.createFolder),ye=qn(Fe=>Fe.renameFolder),Je=qn(Fe=>Fe.deleteFolder),_e=qn(Fe=>Fe.addSessionToFolder),Ue=qn(Fe=>Fe.addSessionsToFolder),ot=qn(Fe=>Fe.removeSessionFromFolder),Xe=qn(Fe=>Fe.removeSessionsFromFolders),We=qn(Fe=>Fe.toggleFolderCollapse),bt=qn(Fe=>Fe.cleanupSessions),Dt=qn(Fe=>Fe.getSessionFolderId);MI({isSessionSearchOpen:o,setIsSessionSearchOpen:c,sessionSearchInputRef:u,sessionSearchContainerRef:m});const Ht=Hh(),rs=_d(),jt=Cd(),St=jy(),ns=ja(Fe=>Fe.hasLoaded),ut=ja(Fe=>Fe.activeSessions),Gt=ja(Fe=>Fe.archivedSessions),Xt=Vt(Fe=>Fe.currentSessionId),Wt=Vt(Fe=>!!Fe.newSessionDraft?.open),is=Vt(Fe=>Fe.setCurrentSession),gs=Vt(Fe=>Fe.updateSessionTitle),ps=Vt(Fe=>Fe.shareSession),Ns=Vt(Fe=>Fe.unshareSession),Mt=Vt(Fe=>Fe.worktreeMetadata),He=Vt(Fe=>Fe.availableWorktreesByProject),At=Vt(Fe=>Fe.openNewSessionDraft),Et=ka(pr(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}))),wt=l.useMemo(()=>F6(be,He),[He,be]),$t=l.useMemo(()=>{const Fe=new Map(jt.map(ts=>[ts.id,ts])),Nt=ut.map(ts=>Fe.get(ts.id)??ts),ht=new Set(Nt.map(ts=>ts.id));return jt.forEach(ts=>{ht.has(ts.id)||Nt.push(ts)}),Nt.filter(ts=>L6(ts,wt))},[ut,wt,jt]),qt=l.useMemo(()=>jt.map(Fe=>{const Nt=ks(Fe.directory??null)??"";return`${Fe.id}:${Fe.title??""}:${Fe.time?.archived?1:0}:${Nt}`}).join("|"),[jt]),Ms=l.useRef(jt);l.useEffect(()=>{Ms.current=jt},[qt,jt]),l.useEffect(()=>{let Fe=!1;const Nt=async()=>{const ht=Fs.getState().projects;if(ht.length===0)return;const ts=new Map,Se=[];await Promise.all(ht.map(async Qe=>{const mt=ks(Qe.path);if(mt)try{if(!(nn.getState().directories.get(mt)?.isGitRepo??await vr(()=>import("./modelPrefsAutoSave-HUPrH1r2.js").then(ls=>ls.e$),__vite__mapDeps([2,0,1,3,4])).then(ls=>ls.checkIsGitRepository(mt))))return;const Qt=await Kc({id:Qe.id,path:mt});if(Fe||Qt.length===0)return;ts.set(mt,Qt),Se.push(...Qt)}catch{}})),!Fe&&Vt.setState({availableWorktrees:Se,availableWorktreesByProject:ts})};return Hc(Ms.current),Nt(),()=>{Fe=!0}},[fe,qt,be]),l.useEffect(()=>{let Fe=null;const Nt=bg(ht=>{ht.type==="scheduled-task-ran"&&(Fe&&clearTimeout(Fe),Fe=setTimeout(()=>{Hc(Ms.current)},500))});return()=>{Fe&&clearTimeout(Fe),Nt()}},[]);const cs=l.useMemo(()=>yn(),[]),Is=wl(),[Es,ft]=l.useState(!1),hs=l.useMemo(()=>dn(),[]),{isTablet:J}=an(),ct=t||J,vt=l.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),Tt=!t&&!hs&&!cs,Yt=!t&&!hs&&!Tt,Zt=cs&&vt&&!Es||Is?"pl-[5.5rem]":"pl-3",Ps="app-region-no-drag inline-flex h-8 w-8 items-center justify-center rounded-md typography-ui-label font-medium text-foreground transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:pointer-events-none disabled:opacity-50";l.useEffect(()=>{if(!cs||!vt){ft(!1);return}let Fe=!1,Nt=null;const ht=async()=>{try{const Se=await ky();Fe||ft(Se)}catch{Fe||ft(!1)}},ts=async()=>{try{Nt=Cy(()=>{ht()})}catch{}};return ht(),ts(),()=>{Fe=!0,Nt&&Nt()}},[cs,vt]);const As=l.useCallback(async Fe=>{const Nt=Fe.target;Nt.closest(".app-region-no-drag")||Nt.closest("button, a, input, select, textarea")||Fe.button===0&&cs&&await ef()},[cs]),{buildGroupSearchText:Ge,filterSessionNodesForSearch:yt,buildGroupedSessions:It}=TI({homeDirectory:Y,worktreeMetadata:Mt,pinnedSessionIds:te,gitBranches:Ht,isVSCode:hs}),{scheduleCollapsedProjectsPersist:Rt}=FI({isVSCode:hs,hasLoadedGlobalSessions:ns,safeStorage:j,keys:{sessionExpanded:Fc,projectCollapse:Mo,sessionPinned:R6,groupOrder:ah,projectActiveSession:oh,groupCollapse:ih},sessions:$t,setPinnedSessionIds:U,groupOrderByProject:ve,activeSessionByProject:ce,collapsedGroups:je,setExpandedParents:k,setCollapsedProjects:C}),ss=l.useMemo(()=>[...$t].sort((Fe,Nt)=>ni(Fe,Nt,te)),[$t,te]),it=l.useMemo(()=>new Map(ss.map((Fe,Nt)=>[Fe.id,Nt])),[ss]),Bt=l.useMemo(()=>{const Fe=new Map;return ss.forEach(Nt=>{const ht=Nt.parentID;if(!ht)return;const ts=Fe.get(ht)??[];ts.push(Nt),Fe.set(ht,ts)}),Fe.forEach(Nt=>Nt.sort((ht,ts)=>ni(ht,ts,te))),Fe},[ss,te]),bs=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")})]}),es=l.useMemo(()=>be.find(Fe=>Fe.id===g)??null,[be,g]),Ut=l.useCallback(Fe=>{g&&(G(g,Fe),w(null))},[g,G]),os=l.useCallback(()=>{$(!0)},[]),en=l.useCallback(()=>{const Fe=ka.getState();if(Fe.available&&Fe.info){O(!0);return}Et.checkForUpdates().then(()=>{const{available:Nt,error:ht}=ka.getState();if(ht){H.error(i("sessions.sidebar.updateCheck.errorTitle"),{description:ht});return}if(!Nt){H.success(i("sessions.sidebar.updateCheck.latestVersion"));return}O(!0)})},[i,Et]),qs=l.useCallback(()=>{t&&Me(!1),ge(!0)},[t,Me,ge]),zs=Et.available&&(Et.runtimeType==="desktop"||Et.runtimeType==="web"),un=Vt(Fe=>Fe.deleteSession),Qs=Vt(Fe=>Fe.deleteSessions),mn=Vt(Fe=>Fe.archiveSession),ln=Vt(Fe=>Fe.archiveSessions),{copiedSessionId:wn,handleSessionSelect:tn,handleSessionDoubleClick:fn,handleSaveEdit:hr,handleCancelEdit:Fn,handleShareSession:Tn,handleCopyShareUrl:Mn,handleUnshareSession:$e,handleDeleteSession:Ft,confirmDeleteSession:as}=EI({activeProjectId:pe,currentDirectory:fe,currentSessionId:Xt,mobileVariant:t,allowReselect:n,onSessionSelected:e,isSessionSearchOpen:o,sessionSearchQuery:d,setSessionSearchQuery:p,setIsSessionSearchOpen:c,setActiveProjectIdOnly:ze,setDirectory:ke,setActiveMainTab:Le,setSessionSwitcherOpen:Me,setCurrentSession:is,updateSessionTitle:gs,shareSession:ps,unshareSession:Ns,deleteSession:un,deleteSessions:Qs,archiveSession:mn,archiveSessions:ln,childrenMap:Bt,showDeletionDialog:Ye,setDeleteSessionConfirm:de,deleteSessionConfirm:Q,setEditingId:f,setEditTitle:x,editingId:b,editTitle:v}),fs=l.useCallback(()=>{if(!X)return;const{scopeKey:Fe,folderId:Nt}=X;F(null),Je(Fe,Nt)},[X,Je]),Gs=l.useCallback(()=>{yr.requestDirectoryDialog()},[]);l.useEffect(()=>{if(!Xt)return;const Nt=$t.find(ht=>ht.id===Xt)?.parentID;Nt&&k(ht=>{if(ht.has(Nt))return ht;const ts=new Set(ht);ts.add(Nt);try{j.setItem(Fc,JSON.stringify(Array.from(ts)))}catch{}return ts})},[Xt,$t,j]);const Hs=l.useCallback(Fe=>{k(Nt=>{const ht=new Set(Nt);ht.has(Fe)?ht.delete(Fe):ht.add(Fe);try{j.setItem(Fc,JSON.stringify(Array.from(ht)))}catch{}return ht})},[j]),Ss=l.useCallback((Fe,Nt)=>{if(!Fe)return null;Nt&&et.has(Nt)&&We(Nt);const ht=nt(Fe,i("sessions.sidebar.folder.newFolderName"),Nt);return ne(ht.id),ue(ht.name),ht},[et,We,nt,i]),Ys=l.useCallback(Fe=>{R(Nt=>{const ht=new Set(Nt);return ht.has(Fe)?ht.delete(Fe):ht.add(Fe),ht})},[]),on=l.useCallback(()=>{Ne.current=Date.now()+150,C(()=>{const Fe=new Set(be.map(Nt=>Nt.id));try{j.setItem(Mo,JSON.stringify(Array.from(Fe)))}catch{}return hs||Rt(Fe),Fe})},[be,hs,j,Rt]),sr=l.useCallback(()=>{Ne.current=Date.now()+150,C(()=>{const Fe=new Set;try{j.setItem(Mo,JSON.stringify([]))}catch{}return hs||Rt(Fe),Fe})},[hs,j,Rt]),Hn=l.useCallback(Fe=>{Ne.current=Date.now()+150,C(Nt=>{const ht=new Set(Nt);ht.has(Fe)?ht.delete(Fe):ht.add(Fe);try{j.setItem(Mo,JSON.stringify(Array.from(ht)))}catch{}return hs||Rt(ht),ht})},[hs,j,Rt]),Gn=l.useMemo(()=>be.map(Fe=>({...Fe,normalizedPath:ks(Fe.path)})).filter(Fe=>!!Fe.normalizedPath),[be]),Rr=l.useMemo(()=>Gn.map(Fe=>Fe.normalizedPath),[Gn]),{github:Nr}=_n(),Zs=Kn(Fe=>Fe.status),Vn=Kn(Fe=>Fe.hasChecked),Cn=Ny(Rr),Zn=cr(Fe=>Fe.ensureEntry),fr=cr(Fe=>Fe.setParams),Dr=cr(Fe=>Fe.refreshTargets);VI({normalizedProjects:Gn,gitRepoStatus:Cn,setProjectRepoStatus:T,setProjectRootBranches:se});const nr=Vt(Fe=>Fe.isLoading);QI({isSessionsLoading:nr,sessions:$t,archivedSessions:Gt,normalizedProjects:Gn,isVSCode:hs,availableWorktreesByProject:He,cleanupSessions:bt});const{getSessionsForProject:Ln,getArchivedSessionsForProject:vn}=KI({isVSCode:hs,sessions:$t,archivedSessions:Gt,availableWorktreesByProject:He});NI({normalizedProjects:Gn,sessions:$t,archivedSessions:Gt,availableWorktreesByProject:He,isVSCode:hs,isSessionsLoading:nr,foldersMap:Ke,createFolder:nt,addSessionToFolder:_e,cleanupSessions:bt});const pn=l.useRef(!1);pe&&N.has(pe)&&(pn.current=!!N.get(pe));const{projectSections:En,groupSearchDataByGroup:Fr,sectionsForRender:Wr,searchMatchCount:Kr}=CI({normalizedProjects:Gn,getSessionsForProject:Ln,getArchivedSessionsForProject:vn,availableWorktreesByProject:He,projectRepoStatus:N,projectRootBranches:le,lastRepoStatus:pn.current,buildGroupedSessions:It,hasSessionSearchQuery:qe,normalizedSessionSearchQuery:he,filterSessionNodesForSearch:yt,buildGroupSearchText:Ge,foldersMap:Ke}),La=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")})]}),jn=!0,{currentSessionDirectory:aa}=PI({projectSections:En,activeProjectId:pe,activeSessionByProject:ce,setActiveSessionByProject:Z,currentSessionId:Xt,handleSessionSelect:tn,newSessionDraftOpen:Wt,mobileVariant:t,openNewSessionDraft:At,setActiveMainTab:Le,setSessionSwitcherOpen:Me,sessions:$t,worktreeMetadata:Mt}),{getOrderedGroups:yi}=AI(ve),Oa=l.useRef(!1);l.useEffect(()=>{if(Oa.current||En.length===0)return;const Fe=En.flatMap(Nt=>Nt.groups.filter(ht=>ht.isArchivedBucket).map(ht=>`${Nt.project.id}:${ht.id}`));Fe.length>0&&oe(Nt=>new Set([...Nt,...Fe])),Oa.current=!0},[En]);const ia=l.useMemo(()=>{const Fe=new Map,Nt=new Map;return En.forEach(ht=>{const ts=Xh(ht.project.label?.trim()||Da(ht.project.normalizedPath,Y)||ht.project.normalizedPath);ht.groups.forEach(Se=>{const Qe=Se.branch&&Se.branch!=="HEAD"&&Se.branch!==ts?Se.branch:null,mt={projectLabel:ts,branchLabel:Qe},xt=_t=>{_t.forEach(Qt=>{const ls=ht.project.normalizedPath.length,Us=Nt.get(Qt.session.id)??-1;ls<Us||(Fe.set(Qt.session.id,{node:Qt,projectId:ht.project.id,groupDirectory:Se.directory,secondaryMeta:mt}),Nt.set(Qt.session.id,ls),Qt.children.length>0&&xt(Qt.children))})};xt(Se.sessions)})}),Fe},[En,Y]),Oe=wa(Fe=>Fe.showRecentSection),Ze=l.useMemo(()=>Oe?M6(S,new Map($t.map(Fe=>[Fe.id,Fe]))).sort((Fe,Nt)=>ni(Fe,Nt,te)):[],[S,te,$t,Oe]),tt=l.useMemo(()=>Oe?E6($t,St):[],[St,$t,Oe]);l.useEffect(()=>{!Oe||tt.length===0||tt.forEach(Fe=>A(Fe.id))},[A,tt,Oe]),l.useEffect(()=>{if(!Oe)return;const Fe=new Map;[...$t,...Gt].forEach(Nt=>{Fe.set(Nt.id,Nt)}),E(Fe)},[Gt,E,$t,Oe]);const dt=l.useMemo(()=>{if(!Oe)return[];const Fe=Nt=>{const ht=ia.get(Nt.id),ts=ks(Nt.directory??null);return{node:ht?.node??{session:Nt,children:[],worktree:null},projectId:ht?.projectId??null,groupDirectory:ht?.groupDirectory??ts,secondaryMeta:ht?.secondaryMeta??null}};return[{key:"active-now",title:i("sessions.sidebar.activity.recentTitle"),items:Ze.map(Fe)}]},[Ze,ia,Oe,i]),Ot=l.useMemo(()=>new Set(Ze.map(Fe=>Fe.id)),[Ze]),Jt=l.useMemo(()=>[...Ot],[Ot]);V4({currentSessionId:Xt,sortedSessions:ss,recentSessionIds:Jt,ensureSessionRenderable:rs.ensureSessionRenderable});const _s=l.useMemo(()=>{if(!hs||qe||Ot.size===0)return Wr;const Fe=Nt=>Nt.reduce((ht,ts)=>{if(Ot.has(ts.session.id))return ht;const Se=Fe(ts.children);return Se.length===ts.children.length?(ht.push(ts),ht):(ht.push({...ts,children:Se}),ht)},[]);return Wr.map(Nt=>({...Nt,groups:Nt.groups.map(ht=>({...ht,sessions:Fe(ht.sessions)}))}))},[hs,qe,Ot,Wr]),hn=l.useMemo(()=>{const Fe=new Set;return _s.forEach(Nt=>{Nt.groups.forEach(ht=>{const ts=ks(ht.directory??null),Se=ht.branch?.trim()||Ht.get(ts||"")?.trim();!ts||!Se||Fe.add(zi(ts,Se))})}),[...Fe]},[Ht,_s]),zn=Pj(hn);l.useEffect(()=>{if(!Vn||!Zs?.connected||!Nr)return;const Fe=[],Nt=Date.now();if(_s.forEach(ts=>{P.has(ts.project.id)||ts.groups.forEach(Se=>{const Qe=ks(Se.directory??null),mt=Se.branch?.trim()||Ht.get(Qe||"")?.trim();if(!Qe||!mt)return;const xt=zi(Qe,mt),_t=cr.getState().entries[xt],Qt=!!_t?.status?.pr,ls=`${Qe}::${mt}`,Us=Math.max(_t?.lastRefreshAt??0,_t?.lastDiscoveryPollAt??0),Pn=!!(_t?.isInitialStatusResolved&&!Qt&&(!h.current.has(ls)||Nt-Us>=O6));(!_t||!_t.isInitialStatusResolved||Pn)&&(Pn&&h.current.add(ls),Fe.push({directory:Qe,branch:mt}))})}),Fe.length===0)return;const ht=new Map;Fe.forEach(ts=>{const Se=zi(ts.directory,ts.branch,ts.remoteName??null);ht.has(Se)||ht.set(Se,ts)}),ht.forEach((ts,Se)=>{Zn(Se),fr(Se,{directory:ts.directory,branch:ts.branch,remoteName:ts.remoteName??null,canShow:!0,github:Nr,githubAuthChecked:Vn,githubConnected:Zs.connected})}),Dr([...ht.values()],{force:!0,silent:!0,markInitialResolved:!0})},[P,Zn,Nr,Vn,Zs?.connected,Ht,Dr,_s,fr]);const Ba=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",er="h-4.5 w-4.5",oa=eP({isDesktopShellRuntime:cs,projectSections:En,projectHeaderSentinelRefs:Ie}),Hr=l.useCallback((Fe,Nt=0,ht,ts,Se=!1,Qe,mt="project")=>s.jsx(N6,{node:Fe,depth:Nt,groupDirectory:ht,projectId:ts,archivedBucket:Se,directoryStatus:D,currentSessionId:Xt,pinnedSessionIds:te,expandedParents:y,hasSessionSearchQuery:qe,normalizedSessionSearchQuery:he,notifyOnSubtasks:De,editingId:b,setEditingId:f,editTitle:v,setEditTitle:x,handleSaveEdit:hr,handleCancelEdit:Fn,toggleParent:Hs,handleSessionSelect:tn,handleSessionDoubleClick:fn,togglePinnedSession:ae,handleShareSession:Tn,copiedSessionId:wn,handleCopyShareUrl:Mn,handleUnshareSession:$e,openSidebarMenuKey:_,setOpenSidebarMenuKey:ee,renamingFolderId:z,getFoldersForScope:st,getSessionFolderId:Dt,removeSessionFromFolder:ot,addSessionToFolder:_e,createFolderAndStartRename:Ss,openContextPanelTab:Ae,handleDeleteSession:Ft,mobileVariant:t,alwaysShowActions:ct,renderSessionNode:Hr,secondaryMeta:Qe,renderContext:mt}),[D,Xt,te,y,qe,he,De,b,f,v,x,hr,Fn,Hs,tn,fn,ae,Tn,wn,Mn,$e,_,ee,z,st,Dt,ot,_e,Ss,Ae,Ft,t,ct]),_a=l.useCallback(Fe=>{oe(Nt=>{const ht=new Set(Nt);return ht.has(Fe)?ht.delete(Fe):ht.add(Fe),ht})},[]),Fl=l.useMemo(()=>{const Fe=new Map;for(const[Nt,ht]of zn)Fe.set(Nt,{visualState:ht.visualState,number:ht.number,url:ht.url,state:ht.prState,draft:ht.draft,title:ht.title,base:ht.base,head:ht.head,checks:ht.checks,canMerge:ht.canMerge,mergeableState:ht.mergeableState,repo:ht.repo});return Fe},[zn]),vi=l.useCallback((Fe,Nt,ht,ts,Se,Qe)=>s.jsx(gP,{group:Fe,groupKey:Nt,projectId:ht,hideGroupLabel:ts,compactBodyPadding:Qe,hasSessionSearchQuery:qe,normalizedSessionSearchQuery:he,groupSearchDataByGroup:Fr,expandedSessionGroups:M,collapsedGroups:je,hideDirectoryControls:r,collapsedFolderIds:et,toggleFolderCollapse:We,renameFolder:ye,deleteFolder:Je,showDeletionDialog:Ye,setDeleteFolderConfirm:F,renderSessionNode:Hr,currentSessionDirectory:aa,projectRepoStatus:N,lastRepoStatus:pn.current,toggleGroupSessionLimit:Ys,mobileVariant:t,alwaysShowActions:ct,activeProjectId:pe,setActiveProjectIdOnly:ze,setActiveMainTab:Le,setSessionSwitcherOpen:Me,openNewSessionDraft:At,addSessionToFolder:_e,createFolderAndStartRename:Ss,renamingFolderId:z,renameFolderDraft:re,setRenameFolderDraft:ue,setRenamingFolderId:ne,pinnedSessionIds:te,sessionOrderIndex:it,prVisualStateByDirectoryBranch:Fl,onToggleCollapsedGroup:_a,dragHandleProps:Se}),[qe,he,Fr,M,je,r,et,We,ye,Je,Ye,Hr,aa,N,Ys,t,ct,pe,ze,Le,Me,At,_e,Ss,z,re,te,it,Fl,_a]),Va=Oe&&!qe?s.jsx(MP,{sections:dt,renderSessionNode:Hr}):null,za=!!(z||b||g),Gr=lr(Fe=>Fe.enabled),sn=lr(Fe=>Fe.selectedIds),Ua=lr(Fe=>Fe.scopeKey),Wa=lr,Ll=l.useCallback(()=>{lr.getState().toggleMode()},[]),Ol=l.useCallback(()=>{lr.getState().disable()},[]),Tr=l.useMemo(()=>{if(sn.size===0||typeof document>"u")return!1;let Fe=!1,Nt=!1;for(const ht of sn){const ts=document.querySelectorAll(`[data-session-row="${CSS.escape(ht)}"]`);for(const Se of ts)Se.getAttribute("data-session-archived")==="1"?Nt=!0:Fe=!0}return Nt&&!Fe},[sn]),In=l.useMemo(()=>{if(Ua)return Ua;if(sn.size===0||typeof document>"u")return null;for(const Fe of sn){const ht=document.querySelector(`[data-session-row="${CSS.escape(Fe)}"]`)?.getAttribute("data-session-scope");if(ht&&ht.length>0)return ht}return null},[sn,Ua]),$l=l.useMemo(()=>In?Ke[In]??[]:[],[Ke,In]),oo=l.useMemo(()=>{if(!In||sn.size===0)return!1;const Fe=Ke[In]??[];for(const Nt of Fe)for(const ht of Nt.sessionIds)if(sn.has(ht))return!0;return!1},[Ke,In,sn]),qr=l.useCallback(Fe=>{!In||sn.size===0||Ue(In,Fe,Array.from(sn))},[Ue,sn,In]),lo=l.useCallback(()=>{if(!In||sn.size===0)return;const Fe=Ss(In);Fe&&Ue(In,Fe.id,Array.from(sn))},[Ue,Ss,sn,In]),co=l.useCallback(()=>{!In||sn.size===0||Xe(In,Array.from(sn))},[Xe,sn,In]),la=l.useCallback(async()=>{const Fe=Array.from(sn);if(Fe.length!==0){if(Tr){const{deletedIds:Nt,failedIds:ht}=await Qs(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})),ht.length>0&&H.error(ht.length===1?i("sessions.sidebar.bulkActions.failedDeleteSingle",{count:ht.length}):i("sessions.sidebar.bulkActions.failedDeletePlural",{count:ht.length}))}else{const{archivedIds:Nt,failedIds:ht}=await ln(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})),ht.length>0&&H.error(ht.length===1?i("sessions.sidebar.bulkActions.failedArchiveSingle",{count:ht.length}):i("sessions.sidebar.bulkActions.failedArchivePlural",{count:ht.length}))}lr.getState().clear()}},[ln,Tr,Qs,sn,i]),wi=l.useCallback(()=>{const Fe=sn.size;if(Fe!==0){if(!Ye){la();return}q({sessionCount:Fe,archivedBucket:Tr})}},[Tr,la,sn,Ye]),Bl=l.useCallback(async()=>{q(null),await la()},[la]);l.useEffect(()=>{if(!Gr)return;const Fe=typeof navigator<"u"&&/Macintosh|Mac OS X/.test(navigator.userAgent||""),Nt=ht=>{if(za)return;const ts=ht.target;if(ts&&(ts.tagName==="INPUT"||ts.tagName==="TEXTAREA"||ts.isContentEditable))return;const Se=Fe?ht.metaKey:ht.ctrlKey;if(ht.key==="Escape"){ht.preventDefault(),lr.getState().disable();return}if(Se&&ht.key==="Backspace"){ht.preventDefault(),wi();return}if(Se&&(ht.key==="a"||ht.key==="A")){const Qe=typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[];if(Qe.length===0)return;ht.preventDefault();const xt=Wa.getState().scopeKey??Qe[0]?.getAttribute("data-session-scope")??null,_t=ls=>xt?ls.getAttribute("data-session-scope")===xt:!0,Qt=Qe.filter(_t).map(ls=>ls.getAttribute("data-session-row")).filter(ls=>typeof ls=="string"&&ls.length>0);if(Qt.length===0)return;Wa.getState().replaceAll(Qt,xt||null)}};return window.addEventListener("keydown",Nt),()=>window.removeEventListener("keydown",Nt)},[wi,za,Wa,Gr]);const uo=l.useCallback(()=>{Le("chat"),t&&Me(!1),At()},[t,At,Le,Me]),mo=l.useCallback(()=>{Le("chat"),t&&Me(!1),xe()},[t,xe,Le,Me]);return s.jsxs("div",{ref:m,className:me("relative flex h-full flex-col text-foreground overflow-x-hidden",t?"":"bg-transparent"),children:[Yt?s.jsx("div",{onMouseDown:As,className:me("app-region-drag flex h-[var(--oc-header-height,56px)] flex-shrink-0 items-center pr-3",Zt),children:s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Ce,className:Ps,"aria-label":i("sessions.sidebar.header.actions.closeSessions"),children:s.jsx(I,{name:"layout-left",className:"h-[18px] w-[18px]"})})}),s.jsx(Pt,{children:s.jsx("p",{children:i("sessions.sidebar.header.actions.closeSessions")})})]})}):null,s.jsx(CP,{hideDirectoryControls:r,handleOpenDirectoryDialog:Gs,handleNewSession:uo,canOpenMultiRun:be.length>0,openMultiRunLauncher:mo,headerActionIconClass:er,reserveHeaderActionsSpace:jn,headerActionButtonClass:Ba,isSessionSearchOpen:o,setIsSessionSearchOpen:c,sessionSearchInputRef:u,sessionSearchQuery:d,setSessionSearchQuery:p,hasSessionSearchQuery:qe,searchMatchCount:Kr,collapseAllProjects:on,expandAllProjects:sr,openScheduledTasksDialog:()=>Ve(!0),selectionModeEnabled:Gr,onToggleSelectionMode:Ll,showSidebarToggle:Tt,onToggleSidebar:Ce,avoidWindowControlsOverlay:Is}),s.jsx(VP,{topContent:Va,sectionsForRender:_s,projectSections:En,activeProjectId:pe,showOnlyMainWorkspace:a,hasSessionSearchQuery:qe,emptyState:bs,searchEmptyState:La,renderGroupSessions:vi,homeDirectory:Y,collapsedProjects:P,hideDirectoryControls:r,projectRepoStatus:N,isDesktopShellRuntime:cs,stuckProjectHeaders:oa,mobileVariant:t,alwaysShowActions:ct,toggleProject:Hn,setActiveProjectIdOnly:ze,setActiveMainTab:Le,setSessionSwitcherOpen:Me,openNewSessionDraft:At,openNewWorktreeDialog:os,openProjectEditDialog:w,removeProject:Ee,projectHeaderSentinelRefs:Ie,reorderProjects:Pe,getOrderedGroups:yi,setGroupOrderByProject:K,openSidebarMenuKey:_,setOpenSidebarMenuKey:ee,isInlineEditing:za}),Gr&&sn.size>0?s.jsx(I6,{selectedCount:sn.size,scopeKey:In,scopeFolders:$l,archivedBucket:Tr,onMoveToFolder:qr,onCreateFolderAndMove:lo,onRemoveFromFolder:co,canRemoveFromFolder:oo,onDelete:wi,onDone:Ol}):null,s.jsx(RP,{onOpenSettings:qs,onOpenShortcuts:W,onOpenAbout:()=>ie(!0),onOpenUpdate:en,showRuntimeButtons:!hs,showUpdateButton:zs}),s.jsx(fd,{open:B,onOpenChange:O,info:Et.info,downloading:Et.downloading,downloaded:Et.downloaded,progress:Et.progress,error:Et.error,onDownload:Et.downloadUpdate,onRestart:Et.restartToUpdate,runtimeType:Et.runtimeType}),es?s.jsx(Sy,{open:!!es,onOpenChange:Fe=>{Fe||w(null)},projectId:es.id,projectName:es.label||Da(es.path,Y),projectPath:es.path,initialIcon:es.icon,initialColor:es.color,initialIconBackground:es.iconBackground,onSave:Ut}):null,s.jsx(H4,{open:L,onOpenChange:$,onWorktreeCreated:(Fe,Nt)=>{if(Le("chat"),t&&Me(!1),Nt?.sessionId){is(Nt.sessionId);return}At({directoryOverride:Fe})}}),s.jsx(wI,{}),s.jsx(S6,{value:Q,setValue:de,showDeletionDialog:Ye,setShowDeletionDialog:rt,onConfirm:as}),s.jsx(C6,{value:X,setValue:F,onConfirm:fs}),s.jsx(k6,{value:V,setValue:q,showDeletionDialog:Ye,setShowDeletionDialog:rt,onConfirm:Bl})]})},$6=()=>{const t=at.c(13),[e,n]=Be.useState(!1);let r,a;t[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>{n(yn())},a=[],t[0]=r,t[1]=a):(r=t[0],a=t[1]),Be.useEffect(r,a);let i;t[2]!==e?(i=async h=>e?await Iy(h):{success:!0,path:h},t[2]=e,t[3]=i):i=t[3];const o=i;let c;t[4]!==e?(c=async h=>e?await Py():{success:!0},t[4]=e,t[5]=c):c=t[5];const d=c;let p;t[6]!==e?(p=async h=>e?await Ay():{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},B6=t=>t==="/",yl=t=>t.replace(/\\/g,"/"),tu=t=>{if(!t||B6(t))return t;let e=t;for(;e.length>1&&e.endsWith("/");)e=e.slice(0,-1);return e},ii=t=>t.endsWith("/"),_6=t=>{const e=t.trim();return!e||ii(e)?e:`${e}/`},su=t=>t.lastIndexOf("/"),Pg=t=>{if(ii(t))return t;const e=su(t);return e<0?t:t.slice(0,e+1)},V6=t=>{const e=su(t);return t.slice(e+1)},Ag=t=>{const e=tu(t.trim());if(!e||e==="~"||e==="~/"||e==="/")return null;const n=su(e);return n<0?null:e.startsWith("~/")&&n<=1?"~/":n===0?"/":`${e.slice(0,n)}/`},z6=t=>ii(t)&&Ag(t)!==null,U6=(t,e)=>`${Pg(t)}${e}/`,Ga=t=>{if(!t)return null;const e=tu(yl(t.trim()));return e?e.toLowerCase():null},ch=(t,e)=>{const n=t.trim();return n==="~"?e:n.startsWith("~/")?`${e}${n.slice(1)}`:n},W6=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},K6=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 yl(e.home.trim())}}catch{}return rn.getFilesystemHome().catch(()=>null)},H6=({open:t,onOpenChange:e})=>{const{t:n}=pt(),r=Vs(Ce=>Ce.homeDirectory),a=Fs(Ce=>Ce.projects),i=Fs(Ce=>Ce.addProject),o=Jn(Ce=>Ce.profiles),c=Jn(Ce=>Ce.globalIdentity),d=Jn(Ce=>Ce.defaultGitIdentityId),p=Jn(Ce=>Ce.loadProfiles),m=Jn(Ce=>Ce.loadGlobalIdentity),u=Jn(Ce=>Ce.loadDefaultGitIdentityId),h=kl(),{isDesktop:b,requestAccess:f,startAccessing:v}=$6(),{isMobile:x}=an(),g=l.useRef(null),w=l.useRef(null),y=l.useRef(new Map),[k,D]=l.useState(""),[j,S]=l.useState("~/"),[A,E]=l.useState([]),[P,C]=l.useState(!1),[N,T]=l.useState(!1),[M,R]=l.useState(0),[L,$]=l.useState(!1),[B,O]=l.useState(!1),[_,ee]=l.useState(0),[z,ne]=l.useState(!1),[re,ue]=l.useState(""),[Q,de]=l.useState(null),X=k||r,F=l.useMemo(()=>new Set(a.map(Ce=>Ga(Ce.path)).filter(Ce=>!!Ce)),[a]);l.useEffect(()=>{if(!t)return;S("~/"),E([]),R(0),$(!1),O(!1),ne(!1),ue(""),de(null),requestAnimationFrame(()=>Lc(g.current));let Ce=!1;return(async()=>{const De=await K6();Ce||(D(De||r||""),requestAnimationFrame(()=>Lc(g.current)))})(),()=>{Ce=!0}},[r,t]),l.useEffect(()=>{t&&(p(),m(),u())},[u,p,m,t]);const V=l.useMemo(()=>{const Ce=new Map;c&&Ce.set(c.id,c);for(const xe of o)Ce.set(xe.id,xe);return Array.from(Ce.values())},[o,c]);l.useEffect(()=>{if(!t||!z||Q!==null)return;const Ce=typeof d=="string"?d.trim():"";if(Ce&&V.some(De=>De.id===Ce)){de(Ce);return}const xe=V.find(De=>De.authType==="ssh"||De.sshKey);xe&&de(xe.id)},[V,d,z,t,Q]);const q=l.useMemo(()=>V.find(Ce=>Ce.id===Q)??null,[V,Q]),te=l.useMemo(()=>Pg(j),[j]),U=l.useMemo(()=>ii(j)?"":V6(j),[j]),ae=l.useMemo(()=>X?ch(te,X):"",[te,X]);l.useEffect(()=>{if(!t||!ae){E([]);return}let Ce=!1;return C(!0),T(!1),rn.listLocalDirectory(ae).then(xe=>{if(Ce)return;T(!1);const De=xe.filter(Ye=>Ye.isDirectory).map(Ye=>({name:Ye.name,path:yl(Ye.path)})).sort((Ye,rt)=>Ye.name.localeCompare(rt.name));E(De)}).catch(()=>{Ce||(E([]),T(!0))}).finally(()=>{Ce||C(!1)}),()=>{Ce=!0}},[ae,t]);const je=l.useMemo(()=>{const Ce=U.toLowerCase(),xe=h||U.startsWith(".");return A.filter(De=>De.name.toLowerCase().startsWith(Ce)&&(xe||!De.name.startsWith(".")))},[U,A,h]),oe=l.useMemo(()=>{const Ce=[];z6(j)&&Ce.push({type:"up",value:"browse:up",name:"..",path:Ag(j)});for(const xe of je){const De=Ga(xe.path);Ce.push({type:"directory",value:`browse:${xe.path}`,name:xe.name,path:xe.path,disabled:!!(De&&F.has(De))})}return Ce},[F,je,j]);l.useEffect(()=>{R(0)},[j,oe.length]);const ve=l.useMemo(()=>X?tu(ch(j,X)):"",[X,j]),K=Ga(ve),ce=!!(K&&F.has(K)),Z=l.useMemo(()=>U?je.find(Ce=>Ce.name===U)??null:null,[U,je]),le=!!(ve&&!ce&&(ii(j)&&N||!ii(j)&&U.trim().length>0&&Z===null)),se=!L&&!B&&!ce&&!!ve,Ie=se&&re.trim().length>0,Ne=oe[M]??null,Y=!!(Ne&&(Ne.type==="up"||Ne.type==="directory"&&!Ne.disabled)),fe=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?"⌘":"Ctrl",ke=n(ce?"directoryExplorerDialog.actions.alreadyAdded":z?L?"directoryExplorerDialog.actions.cloning":"directoryExplorerDialog.actions.cloneAndAdd":L?"directoryExplorerDialog.actions.adding":le?"directoryExplorerDialog.actions.createAndAdd":"directoryExplorerDialog.actions.addProject");l.useLayoutEffect(()=>{const Ce=w.current;if(!Ce)return;const xe=()=>ee(Math.ceil(Ce.getBoundingClientRect().width));if(xe(),typeof ResizeObserver>"u")return;const De=new ResizeObserver(xe);return De.observe(Ce),()=>De.disconnect()},[ke]),l.useLayoutEffect(()=>{const Ce=g.current;Ce&&(Ce.scrollLeft=Ce.scrollWidth)},[_,j]),l.useLayoutEffect(()=>{t&&Lc(g.current)},[t]),l.useLayoutEffect(()=>{const Ce=oe[M];Ce&&y.current.get(Ce.value)?.scrollIntoView({block:"nearest"})},[M,oe]);const be=l.useCallback(()=>{e(!1)},[e]),pe=l.useCallback(async Ce=>{if(!Ce||L)return;const xe=Ga(Ce);if(xe&&F.has(xe))return;let De=Ce;$(!0);try{const Ye=!z&&le&&Ga(Ce)===Ga(ve);if(z){const Re=re.trim();if(!Re){H.error(n("directoryExplorerDialog.toast.cloneUrlRequired"));return}De=(await rn.cloneRepository({remoteUrl:Re,destinationPath:Ce,gitIdentityId:q?.id??null})).path}else Ye&&await rn.createDirectory(Ce,{allowOutsideWorkspace:!0});if(!i(De)){H.error(n("directoryExplorerDialog.toast.failedToAddProject"),{description:n("directoryExplorerDialog.toast.selectValidDirectoryPath")});return}be()}catch(Ye){H.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:Ye instanceof Error?Ye.message:n("directoryExplorerDialog.toast.unknownError")})}finally{$(!1)}},[i,F,re,be,z,L,q?.id,le,ve,n]),Ee=l.useCallback(Ce=>{S(_6(Ce))},[]),ze=l.useCallback(Ce=>{S(U6(j,Ce.name))},[j]),G=l.useCallback(Ce=>{if(Ce){if(Ce.type==="up"){Ce.path&&Ee(Ce.path);return}Ce.disabled||ze(Ce)}},[Ee,ze]),Pe=l.useCallback(async()=>{if(!(!b||B)){O(!0);try{const Ce=await f(ve);if(!Ce.success||!Ce.path){Ce.error&&Ce.error!=="Directory selection cancelled"&&H.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:Ce.error});return}const xe=await v(Ce.path);if(!xe.success){H.error(n("directoryExplorerDialog.toast.failedToOpenDirectory"),{description:xe.error||n("directoryExplorerDialog.toast.desktopCouldNotGrantAccess")});return}await pe(Ce.path)}catch(Ce){H.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:Ce instanceof Error?Ce.message:n("directoryExplorerDialog.toast.unknownError")})}finally{O(!1)}}},[pe,b,B,f,v,n,ve]),Le=l.useCallback(Ce=>{if(Ce.key==="ArrowDown"){Ce.preventDefault(),R(xe=>Math.min(oe.length-1,xe+1));return}if(Ce.key==="ArrowUp"){Ce.preventDefault(),R(xe=>Math.max(0,xe-1));return}if(Ce.key==="Enter"){if(Ce.preventDefault(),W6(Ce)){pe(ve);return}Y&&G(Ne);return}Ce.key==="Backspace"&&j===""&&(Ce.preventDefault(),be())},[G,pe,be,Y,Ne,j,oe.length,ve]),Ae=s.jsxs("button",{type:"button",onClick:()=>$o(!h),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:[h?s.jsx(I,{name:"checkbox",className:"h-4 w-4 text-primary"}):s.jsx(I,{name:"checkbox-blank",className:"h-4 w-4"}),n("directoryExplorerDialog.toggle.showHidden")]}),ge=s.jsxs("div",{className:"px-2.5 py-1.5",children:[z?s.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5",children:[s.jsx(Kt,{value:re,onChange:Ce=>ue(Ce.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(Sf,{activeProfile:q,identities:V,onSelect:Ce=>de(Ce.id),isApplying:L,iconOnly:!0})]}):null,s.jsxs("div",{className:"relative",children:[s.jsx(I,{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(Kt,{ref:g,value:j,onChange:Ce=>S(yl(Ce.target.value)),onKeyDown:Le,placeholder:n("directoryExplorerDialog.pathInput.placeholder"),className:"border-transparent bg-transparent pl-9 font-mono typography-ui-label shadow-none focus-visible:ring-0",style:!x&&_>0?{paddingRight:`${_+24}px`}:void 0,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off"}),x?null:s.jsx(we,{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:z?!Ie:!se,onMouseDown:Ce=>Ce.preventDefault(),onClick:()=>{pe(ve)},title:ke,children:ke})]})]}),W=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((Ce,xe)=>{const De=xe===M;return s.jsxs("button",{ref:Ye=>{Ye?y.current.set(Ce.value,Ye):y.current.delete(Ce.value)},type:"button",disabled:Ce.type==="directory"&&Ce.disabled,onMouseEnter:()=>R(xe),onMouseDown:Ye=>Ye.preventDefault(),onClick:()=>G(Ce),className:me("flex w-full cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 text-left transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",De&&"bg-interactive-selection text-interactive-selection-foreground",!De&&"hover:bg-interactive-hover/50",Ce.type==="directory"&&Ce.disabled&&"cursor-not-allowed opacity-45 hover:bg-transparent"),children:[Ce.type==="up"?s.jsx(I,{name:"arrow-left-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80"}):s.jsx(I,{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:Ce.name})}),Ce.type==="directory"&&Ce.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]},Ce.value)})})]})}),ie=s.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3",children:[ge,W]}),Me=s.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 typography-micro text-muted-foreground",children:[s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx(I,{name:"arrow-up-s",className:"h-3.5 w-3.5"}),s.jsx(I,{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(I,{name:"corner-down-left",className:"h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.select")]}),s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx("span",{children:fe}),s.jsx(I,{name:"corner-down-left",className:"h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.add")]})]}),Ve=()=>s.jsxs(s.Fragment,{children:[x?null:Me,s.jsxs("div",{className:me("flex w-full flex-row justify-end gap-2 sm:w-auto",x&&"justify-stretch"),children:[b?s.jsx(we,{variant:"ghost",size:"xs",onClick:Pe,disabled:L||B||z,children:n(B?"directoryExplorerDialog.actions.openingFinder":"directoryExplorerDialog.actions.openInFinder")}):null,s.jsx(we,{variant:"ghost",size:"xs",onClick:()=>ne(Ce=>!Ce),disabled:L||B,className:me(x&&"flex-1"),children:n(z?"directoryExplorerDialog.actions.addLocalProject":"directoryExplorerDialog.actions.cloneRepository")}),x?s.jsx(we,{size:"xs",onClick:()=>{pe(ve)},disabled:z?!Ie:!se,className:"flex-1",children:ke}):null]})]});return x?s.jsx(Pr,{open:t,onClose:be,title:n("directoryExplorerDialog.title"),className:"h-[88dvh] max-h-[720px] max-w-full",contentMaxHeightClassName:"flex-1",footer:s.jsx("div",{className:"flex flex-col gap-2",children:Ve()}),children:s.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-3",children:[s.jsx("div",{className:"flex justify-end",children:Ae}),ie]})}):s.jsx(ws,{open:t,onOpenChange:e,children:s.jsxs(vs,{className:"flex w-full max-w-xl flex-col gap-0 overflow-hidden p-0 sm:max-h-[80vh]",onOpenAutoFocus:Ce=>Ce.preventDefault(),children:[s.jsx(Cs,{className:"px-5 pb-2 pt-5",children:s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{children:[s.jsx(js,{children:n("directoryExplorerDialog.title")}),s.jsx(Rs,{className:"mt-2",children:n("directoryExplorerDialog.description")})]}),Ae]})}),s.jsx("div",{className:"min-h-0 flex-1 px-2 pb-0",children:ie}),s.jsx(Ks,{className:"flex w-full flex-col gap-3 px-5 py-3 sm:flex-row sm:items-center sm:justify-between",children:Ve()})]})})},fa=t=>t?s.jsx("span",{className:"text-foreground/80 dark:text-foreground/70",children:t}):void 0,kr=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},G6=()=>{const{t}=pt(),[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,h]=l.useState(!1),[b,f]=l.useState(!1),[v,x]=l.useState(!1),[g,w]=l.useState(new Set),y=Vt(se=>se.getWorktreeMetadata),k=Vt(se=>se.newSessionDraft),D=Vt(se=>se.setNewSessionDraftTarget),j=Vt(se=>se.setDraftBootstrapPendingDirectory),S=Dy,A=Ey,E=Vt(se=>se.deleteSessions),P=Vt(se=>se.archiveSessions),C=Te(se=>se.showDeletionDialog),N=Te(se=>se.setShowDeletionDialog),T=Vs(se=>se.currentDirectory),M=Vs(se=>se.homeDirectory),R=Vs(se=>se.isHomeReady),L=Fs(se=>se.projects),$=Fs(se=>se.activeProjectId),{isMobile:B,isTablet:O,hasTouchInput:_}=an(),ee=B||O||_,z=l.useMemo(()=>{const Ie=($?L.find(Ne=>Ne.id===$)??null:null)?.path??T;return kr(Ie)},[$,T,L]),ne=l.useCallback(se=>{const Ne=kr(se.projectDirectory)||z;return{id:(L.find(fe=>kr(fe.path)===Ne)??null)?.id??`path:${Ne}`,path:Ne}},[z,L]),re=v&&g.size>0,ue=l.useMemo(()=>{const se=i?.worktree;return se&&typeof se.branch=="string"&&se.branch.trim().length>0?!0:c.length>0&&c.every(({metadata:Ie})=>typeof Ie.branch=="string"&&Ie.branch.trim().length>0)},[i?.worktree,c]),Q=i?.mode==="worktree",de=Q,X=b||!Q||!ue,F=b||!Q;l.useEffect(()=>{r||!R||L.length>0||(a(!0),n(!0))},[r,R,L.length]);const V=l.useCallback(se=>{o({sessions:se.sessions,dateLabel:se.dateLabel,mode:se.mode??"session",worktree:se.worktree??null})},[]),q=l.useCallback(()=>{o(null),d([]),m(!1),h(!1),f(!1),x(!1),w(new Set)},[]),te=l.useCallback(async se=>{if(se.sessions.length===0)return;if(se.sessions.length===1){const fe=se.sessions[0];await S(fe.id)?H.success(t("sessions.sidebar.session.delete.success")):H.error(t("sessions.sidebar.session.delete.error"));return}const Ie=se.sessions.map(fe=>fe.id),{deletedIds:Ne,failedIds:Y}=await E(Ie);if(Ne.length>0){const fe=Y.length>0?Y.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:Y.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:Y.length}):se.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:se.dateLabel}):void 0;H.success(Ne.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:Ne.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:Ne.length}),{description:fa(fe)})}Y.length>0&&H.error(Y.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:Y.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:Y.length}),{description:fa(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))})},[S,E,t]);l.useEffect(()=>yr.onDeleteRequest(se=>{if(!C&&(se.mode??"session")==="session"){te(se);return}V(se)}),[V,C,te]),l.useEffect(()=>yr.onDirectoryRequest(()=>{n(!0)}),[]),l.useEffect(()=>{if(!i){d([]),m(!1),h(!1),x(!1),w(new Set);return}const se=i.sessions.map(Y=>{const fe=y(Y.id);return fe?{session:Y,metadata:fe}:null}).filter(Y=>!!Y);d(se),m(!1),x(!1),w(new Set);const Ie=new Map;if(i.worktree?.path&&Ie.set(kr(i.worktree.path),i.worktree),se.forEach(({metadata:Y})=>{Y.path&&Ie.set(kr(Y.path),Y)}),Ie.size===0){x(!0);return}let Ne=!1;return(async()=>{const Y=new Map,fe=new Set;await Promise.all(Array.from(Ie.entries()).map(async([ke,be])=>{try{const pe=await Ty(be.path);Y.set(ke,pe),pe?.isDirty&&fe.add(ke)}catch{be.status&&(Y.set(ke,be.status),be.status.isDirty&&fe.add(ke))}})).catch(ke=>{console.warn("Failed to inspect worktree status before deletion:",ke)}),!Ne&&(w(fe),x(!0),o(ke=>{if(!ke?.worktree?.path)return ke;const be=kr(ke.worktree.path),pe=Y.get(be);if(!pe)return ke;const Ee=ke.worktree.status;return Ee?.isDirty===pe.isDirty&&Ee?.ahead===pe.ahead&&Ee?.behind===pe.behind&&Ee?.upstream===pe.upstream?ke:{...ke,worktree:{...ke.worktree,status:pe}}}),d(ke=>ke.map(be=>{const pe=kr(be.metadata.path),Ee=Y.get(pe);return Ee?{session:be.session,metadata:{...be.metadata,status:Ee}}:be})))})(),()=>{Ne=!0}},[i,y]),l.useEffect(()=>{ue||m(!1)},[ue]);const U=l.useCallback(async(se,Ie)=>{const Ne=p&&ue,Y=ne(se),fe=kr(se.path),ke=kr(Y.path);try{await My(Y,se,{deleteRemoteBranch:Ne,deleteLocalBranch:Ie});const be=kr(k?.directoryOverride);return k?.open&&fe&&be===fe&&ke&&(j(null),D({projectId:Y.id,directoryOverride:ke},{force:!0})),kr(T)===fe&&ke&&Vs.getState().setDirectory(ke,{showOverlay:!1}),!0}catch(be){return H.error(t("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle"),{description:fa(be instanceof Error?be.message:t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),!1}},[ue,T,p,ne,k?.directoryOverride,k?.open,j,D,t]),ae=l.useCallback(async()=>{if(i){f(!0);try{const se=de,Ie=se&&p,Ne=se&&u;if(i.sessions.length===0&&Q&&i.worktree){if(!await U(i.worktree,Ne)){q();return}const ke=t(p&&ue?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.removed");H.success(t("sessions.sidebar.sessionDialogs.worktree.removedTitle"),{description:fa(ke)}),q();return}if(i.sessions.length===1){const Y=i.sessions[0];if(!(Q?await A(Y.id):await S(Y.id,{archiveWorktree:!1,deleteRemoteBranch:Ie,deleteLocalBranch:Ne}))){H.error(t(Q?"sessions.sidebar.session.archive.error":"sessions.sidebar.session.delete.error")),f(!1);return}const ke=!Q&&se?t(Ie?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.attachedArchived"):void 0;H.success(t(Q?"sessions.sidebar.session.archive.success":"sessions.sidebar.session.delete.success"),{description:fa(ke),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}else{const Y=i.sessions.map(be=>be.id);let fe=[],ke=[];if(Q){const be=await P(Y);fe=be.archivedIds,ke=be.failedIds}else{const be=await E(Y);fe=be.deletedIds,ke=be.failedIds}if(Q&&i.worktree&&ke.length===0&&await U(i.worktree,Ne),fe.length>0){const be=!Q&&se?t(Ie?"sessions.sidebar.sessionDialogs.worktree.archivedAndRemoteRemoved":"sessions.sidebar.sessionDialogs.worktree.attachedArchivedPlural"):void 0,Ee=[ke.length>0?Q?ke.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToArchive",{count:ke.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToArchive",{count:ke.length}):ke.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:ke.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:ke.length}):i.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:i.dateLabel}):void 0,be].filter(Boolean).join(" ");H.success(Q?fe.length===1?t("sessions.sidebar.bulkActions.archivedSingle",{count:fe.length}):t("sessions.sidebar.bulkActions.archivedPlural",{count:fe.length}):fe.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:fe.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:fe.length}),{description:fa(Ee||void 0),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}if(ke.length>0&&(H.error(Q?ke.length===1?t("sessions.sidebar.bulkActions.failedArchiveSingle",{count:ke.length}):t("sessions.sidebar.bulkActions.failedArchivePlural",{count:ke.length}):ke.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:ke.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:ke.length}),{description:fa(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),fe.length===0)){f(!1);return}}Q&&i.sessions.length===1&&i.worktree&&await U(i.worktree,Ne),q()}finally{f(!1)}}},[i,p,u,S,E,A,P,q,de,Q,ue,U,t]),je=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}):"",ve=i?s.jsxs("div",{className:me(Q?"space-y-3":"space-y-2"),children:[i.sessions.length>0&&s.jsxs("div",{className:me(Q?"rounded-lg bg-muted/30 p-3":"space-y-1.5 rounded-xl border border-border/40 bg-sidebar/60 p-3"),children:[Q&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-meta font-medium text-foreground",children:i.sessions.length===1?t("sessions.sidebar.sessionDialogs.linkedSessionSingle"):t("sessions.sidebar.sessionDialogs.linkedSessionPlural")}),s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:i.sessions.length})]}),s.jsxs("ul",{className:me(Q?"mt-2 space-y-1":"space-y-0.5"),children:[i.sessions.slice(0,5).map(se=>s.jsxs("li",{className:me(Q?"flex items-center gap-2 rounded-md px-2.5 py-1.5 text-sm text-muted-foreground":"typography-micro text-muted-foreground/80"),children:[s.jsx("span",{className:me(!Q&&"hidden"),children:"•"}),s.jsx("span",{className:"truncate",children:se.title||t("sessions.sidebar.session.untitled")})]},se.id)),i.sessions.length>5&&s.jsx("li",{className:me(Q?"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})})]})]}),Q?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(I,{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")}),je?.label?s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:je.label}):null]}),s.jsx("p",{className:"typography-micro text-muted-foreground/80 break-all",children:je?Hi(je.path,M):t("sessions.sidebar.sessionDialogs.worktree.pathUnavailable")}),re&&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,K=Q?ue?s.jsxs("button",{type:"button",onClick:()=>{X||m(se=>!se)},disabled:X,className:me("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",X?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[p?s.jsx(I,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(I,{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,ce=Q?s.jsxs("button",{type:"button",onClick:()=>{F||h(se=>!se)},disabled:F,className:me("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",F?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[u?s.jsx(I,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(I,{name:"checkbox-blank",className:"size-4"}),t("sessions.sidebar.sessionDialogs.actions.deleteLocalBranch")]}):null,Z=Q?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:[ce,K]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(we,{variant:"ghost",onClick:q,disabled:b,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(we,{variant:"destructive",onClick:ae,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(!C),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":!C,children:[C?s.jsx(I,{name:"checkbox-blank",className:"size-4"}):s.jsx(I,{name:"checkbox",className:"size-4 text-primary"}),t("sessions.sidebar.dialogs.neverAsk")]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(we,{variant:"ghost",onClick:q,disabled:b,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(we,{variant:"destructive",onClick:ae,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")})]})]}),le=Q?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:[ee?s.jsx(Pr,{open:!!i,onClose:()=>{b||q()},title:le,footer:s.jsx("div",{className:"flex justify-end gap-2",children:Z}),children:s.jsxs("div",{className:"space-y-2 pb-2",children:[oe&&s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:oe}),ve]})}):s.jsx(ws,{open:!!i,onOpenChange:se=>{if(!se){if(b)return;q()}},children:s.jsxs(vs,{className:me(Q?"max-w-xl max-h-[70vh] flex flex-col overflow-hidden gap-3":"max-w-[min(520px,100vw-2rem)] space-y-2 pb-2"),children:[s.jsxs(Cs,{children:[s.jsxs(js,{className:me(Q&&"flex items-center gap-2"),children:[Q&&s.jsx(I,{name:"delete-bin",className:"h-5 w-5"}),le]}),oe&&s.jsx(Rs,{children:oe})]}),s.jsx("div",{className:me(Q&&"flex-1 min-h-0 overflow-y-auto space-y-2"),children:ve}),s.jsx(Ks,{className:"mt-2 gap-2 pt-1 pb-1",children:Z})]})}),s.jsx(H6,{open:e,onOpenChange:n})]})},wd=t=>t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").substring(0,50),q6=(t,e)=>{const n=wd(t),r=wd(e);return`${n}-${r}`.substring(0,60)},dh=(t,e)=>`${t}/${e}`,J6=()=>{const t=Fs.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=Vs.getState().currentDirectory??null;if(r&&r.trim().length>0){const a=r.replace(/\\/g,"/").replace(/\/+$/,"")||r;return{id:`path:${a}`,path:a}}return null},Oc=tr()(gi(t=>({isLoading:!1,error:null,createMultiRun:async e=>{const n=e.name.trim(),r=e.prompt.trim(),{models:a,agent:i,files:o,setupCommands:c}=e;if(!n)return t({error:"Group name is required"}),null;if(!r)return t({error:"Prompt is required"}),null;if(a.length<1)return t({error:"Select at least 1 model"}),null;if(a.length>5)return t({error:"Maximum 5 models allowed"}),null;t({isLoading:!0,error:null});try{const d=J6();if(!d)return t({error:"Select a project",isLoading:!1}),null;const p=d.path,u=await Uh(p)&&e.isolateRuns!==!1,h=wd(n),b=u?await to(p):void 0,f=u?await Ry(p):null,v=[],x=c?.filter(S=>S.trim().length>0)??[],g=new Map;for(const S of a){const A=`${S.providerID}:${S.modelID}`;g.set(A,(g.get(A)||0)+1)}const w=new Map;for(const S of a){const A=`${S.providerID}:${S.modelID}`,E=g.get(A)||1,P=(w.get(A)||0)+1;w.set(A,P);const C=q6(S.providerID,S.modelID),N=E>1?dh(h,`${C}/${P}`):dh(h,C);try{const T=E>1?`${h}/${S.providerID}/${S.modelID}/${P}`:`${h}/${S.providerID}/${S.modelID}`;if(!u){const $=await rn.withDirectory(p,()=>rn.createSession({title:T}));v.push({sessionId:$.id,worktreePath:p,providerID:S.providerID,modelID:S.modelID,variant:S.variant});continue}const M=await Fy(d,{preferredName:N,mode:"new",branchName:N,worktreeName:N,startRef:e.worktreeBaseBranch||"HEAD",setupCommands:x},{resolvedRootTrackingRemote:f}),R={...M,createdFromBranch:b,kind:"standard"},L=await rn.withDirectory(M.path,()=>rn.createSession({title:T}));Vt.getState().setWorktreeMetadata(L.id,R),v.push({sessionId:L.id,worktreePath:M.path,providerID:S.providerID,modelID:S.modelID,variant:S.variant})}catch(T){console.warn("[MultiRun] Failed to create session:",T)}}const y=c?.filter(S=>S.trim().length>0)??[];y.length>0&&Wh(d,y).catch(()=>{console.warn("[MultiRun] Failed to save worktree setup commands")});const k=v.map(S=>S.sessionId),D=v[0]?.sessionId??null;if(k.length===0)return t({error:"Failed to create any sessions",isLoading:!1}),null;const j=o?.map(S=>({type:"file",mime:S.mime,filename:S.filename,url:S.url}));return(async()=>{try{await Promise.allSettled(v.map(async S=>{try{await rn.withDirectory(S.worktreePath,()=>rn.sendMessage({id:S.sessionId,providerID:S.providerID,modelID:S.modelID,variant:S.variant,text:r,agent:i,files:j}))}catch(A){console.warn("[MultiRun] Failed to start run:",A)}}))}catch(S){console.warn("[MultiRun] Failed to start runs:",S)}})(),t({isLoading:!1}),{groupSlug:h,sessionIds:k,firstSessionId:D}}catch(d){return t({error:d instanceof Error?d.message:"Failed to create Multi-Run",isLoading:!1}),null}},clearError:()=>{t({error:null})}}),{name:"multirun-store"})),Q6="oc:lastWorktreeSourceBranch";function Dg(t){const e=at.c(30),{git:n}=_n(),r=Td(t),a=Dd(t),i=Md(t),o=Jh(t),c=nn(tA),d=nn(eA);let p,m;e[0]!==t||e[1]!==d||e[2]!==n||e[3]!==a||e[4]!==i?(p=()=>{!t||!n||a!==null||i||d(t,n,{silent:!0})},m=[t,n,d,a,i],e[0]=t,e[1]=d,e[2]=n,e[3]=a,e[4]=i,e[5]=p,e[6]=m):(p=e[5],m=e[6]),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 h=r?.all;let b;e[13]!==t||e[14]!==c||e[15]!==n||e[16]!==a||e[17]!==h?(b=[t,n,a,h,c],e[13]=t,e[14]=c,e[15]=n,e[16]=a,e[17]=h,e[18]=b):b=e[18],l.useEffect(u,b);const f=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(Z6).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(X6).map(Y6).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(f){y=null;break e}y=r?.all?!0:null}const k=y;let D;return e[25]!==k||e[26]!==f||e[27]!==x||e[28]!==w?(D={localBranches:x,remoteBranches:w,isLoading:f,isGitRepository:k},e[25]=k,e[26]=f,e[27]=x,e[28]=w,e[29]=D):D=e[29],D}function Y6(t){return t.replace(/^remotes\//,"")}function X6(t){return t.startsWith("remotes/")}function Z6(t){return!t.startsWith("remotes/")}function eA(t){return t.fetchStatus}function tA(t){return t.fetchBranches}const sA=({directory:t,value:e,onChange:n,className:r,disabled:a,id:i})=>{const{t:o}=pt(),{localBranches:c,remoteBranches:d,isLoading:p,isGitRepository:m}=Dg(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 f=t?await to(t).catch(()=>null):null,v=localStorage.getItem(Q6);v&&u.includes(v)?n(v):f&&u.includes(f)?n(f):u.includes("main")?n("main"):u.includes("master")?n("master"):u[0]&&n(u[0])}catch{}})()},[u,t,a,p,n,e]);const h=a||!m||p;return s.jsxs("div",{children:[s.jsxs(ds,{value:e,onValueChange:n,disabled:h,children:[s.jsx(us,{id:i,size:"lg",className:r??"w-fit typography-meta text-foreground",children:s.jsx(ys,{placeholder:o(p?"multiRun.branchSelector.status.loadingBranches":"multiRun.branchSelector.placeholder.selectSourceBranch")})}),s.jsx(ms,{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(Gc,{children:[s.jsx(Eu,{className:"font-semibold text-foreground",children:o("multiRun.branchSelector.groups.localBranches")}),c.map(b=>s.jsx(Lt,{value:b,className:"whitespace-normal break-all",children:b},b))]}),c.length>0&&d.length>0&&s.jsx(Ly,{}),d.length>0&&s.jsxs(Gc,{children:[s.jsx(Eu,{className:"font-semibold text-foreground",children:o("multiRun.branchSelector.groups.remoteBranches")}),d.map(b=>s.jsx(Lt,{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")})]})},nA=10*1024*1024,$c=5,Eo=t=>{const e=at.c(3),{children:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",tabIndex:-1,className:"inline-flex items-center justify-center text-muted-foreground/50 hover:text-muted-foreground transition-colors",children:s.jsx(I,{name:"information",className:"h-3.5 w-3.5"})})}),e[0]=r):r=e[0];let a;return e[1]!==n?(a=s.jsxs(kt,{children:[r,s.jsx(Pt,{side:"top",className:"max-w-[240px]",children:n})]}),e[1]=n,e[2]=a):a=e[2],a},qa=t=>{const e=at.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},rA=({initialPrompt:t,onCreated:e,onCancel:n,isWindowed:r=!1})=>{const{t:a}=pt(),[i,o]=l.useState(""),[c,d]=l.useState(()=>t??""),[p,m]=l.useState([]),[u,h]=l.useState(""),[b,f]=l.useState([]),[v,x]=l.useState(!1),[g,w]=l.useState([]),[y,k]=l.useState(!1),[D,j]=l.useState(!1),[S,A]=l.useState(!0),[E,P]=l.useState(!1),[C,N]=l.useState(""),[T,M]=l.useState(!1),[R,L]=l.useState(""),$=l.useRef(null),B=l.useRef(null),O=l.useRef(null),_=l.useRef(null),ee=Vs(Re=>Re.currentDirectory??null),z=Vs(Re=>Re.homeDirectory??null),ne=l.useMemo(()=>{if(typeof window>"u")return null;const Re=window.__VSCODE_CONFIG__?.workspaceFolder;return typeof Re=="string"&&Re.trim().length>0?Re.trim():null},[]),re=Fs(Re=>Re.activeProjectId),ue=Fs(Re=>Re.setActiveProjectIdOnly),Q=Fs(Re=>Re.projects),[de,X]=l.useState(()=>re??null);l.useEffect(()=>{if(re){X(re);return}!de&&Q.length>0&&X(Q[0].id)},[re,Q,de]);const F=l.useMemo(()=>de?Q.find(Re=>Re.id===de)??null:null,[Q,de]),V=F?.path??ee,q=l.useCallback(Re=>{X(Re),Re!==re&&ue(Re)},[re,ue]),{currentTheme:te}=jr(),U=l.useCallback(Re=>{const he=Re.label?.trim()||Da(Re.path,z),qe=no({id:Re.id,iconImage:Re.iconImage??null},{themeVariant:te.metadata.variant,iconColor:te.colors.surface.foreground}),et=Re.icon?Al[Re.icon]:null,Ke=Re.color?ro[Re.color]:void 0;return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[qe?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:Re.iconBackground?{backgroundColor:Re.iconBackground}:void 0,children:s.jsx("img",{src:qe,alt:"",className:"h-full w-full object-contain",draggable:!1})}):et?s.jsx(I,{name:et,className:"h-3.5 w-3.5 shrink-0",style:Ke?{color:Ke}:void 0}):s.jsx(I,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:Ke?{color:Ke}:void 0}),s.jsx("span",{className:"truncate",children:he})]})},[z,te.metadata.variant,te.colors.surface.foreground]),ae=l.useMemo(()=>{if(F?.path)return{id:F.id,path:F.path};const Re=ee??ne;return Re?{id:`path:${Re}`,path:Re}:null},[F,ee,ne]),[je,oe]=l.useState(()=>typeof window>"u"?!1:yn()),ve=l.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),K=wl();l.useEffect(()=>{typeof window>"u"||oe(yn())},[]);const ce=l.useMemo(()=>{if(typeof window>"u")return null;const Re=window.__OPENCHAMBER_MACOS_MAJOR__;if(typeof Re=="number"&&Number.isFinite(Re)&&Re>0)return Re;if(typeof navigator>"u")return null;const he=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!he)return null;const qe=Number.parseInt(he[1],10),et=Number.parseInt(he[2],10);return Number.isNaN(qe)?null:qe===10?et:qe},[]),Z=l.useMemo(()=>je&&ve||K?"pl-[5.5rem]":"pl-3",[je,ve,K]),le=l.useMemo(()=>!je||!ve||ce===null?"":ce>=26?"h-12":ce<=15?"h-14":"",[je,ve,ce]),se=l.useCallback(async Re=>{Re.target.closest("button, a, input, select, textarea")||Re.button===0&&je&&await ef()},[je]);l.useEffect(()=>{if(!n)return;const Re=he=>{he.key==="Escape"&&(he.preventDefault(),he.stopPropagation(),n())};return window.addEventListener("keydown",Re,!0),()=>window.removeEventListener("keydown",Re,!0)},[n]);const[Ie,Ne]=l.useState(""),{isLoading:Y,isGitRepository:fe}=Dg(V),ke=l.useRef(!1),be=fe===!0,pe=be&&S;l.useEffect(()=>{if(fe===!1){ke.current=!0,A(!1);return}fe===!0&&ke.current&&(ke.current=!1,A(!0))},[fe]);const Ee=Oc(Re=>Re.createMultiRun),ze=Oc(Re=>Re.error),G=Oc(Re=>Re.clearError);l.useEffect(()=>{typeof t=="string"&&t.trim().length>0&&d(Re=>Re.trim().length>0?Re:t)},[t]),l.useEffect(()=>{if(!ae)return;let Re=!1;return j(!0),(async()=>{try{const he=await $d(ae);Re||w(he)}catch{}finally{Re||j(!1)}})(),()=>{Re=!0}},[ae]);const Pe=Re=>{p.length>=$c||(m(he=>[...he,Re]),G())},Le=Re=>{m(he=>he.filter((qe,et)=>et!==Re)),G()},Ae=l.useCallback((Re,he)=>{m(qe=>qe.map((et,Ke)=>Ke===Re?he:et))},[]),ge=async Re=>{const he=Re.target.files;if(!he)return;let qe=0;for(let et=0;et<he.length;et++){const Ke=he[et];if(Ke.size>nA){H.error(a("multirun.launcher.toast.fileTooLarge",{fileName:Ke.name}));continue}try{const st=await new Promise((ye,Je)=>{const _e=new FileReader;_e.onload=()=>ye(_e.result),_e.onerror=Je,_e.readAsDataURL(Ke)}),nt={id:bl(),filename:Ke.name,mimeType:Ke.type||"application/octet-stream",size:Ke.size,dataUrl:st};f(ye=>[...ye,nt]),qe++}catch(st){console.error("File attach failed",st),H.error(a("multirun.launcher.toast.attachFailed",{fileName:Ke.name}))}}qe>0&&H.success(qe===1?a("multirun.launcher.toast.attachedSingle",{count:qe}):a("multirun.launcher.toast.attachedPlural",{count:qe})),$.current&&($.current.value="")},W=Re=>{f(he=>he.filter(qe=>qe.id!==Re))},ie=l.useCallback((Re,he)=>{if(Re.startsWith("/")){const Ke=Re.indexOf(" "),st=Re.indexOf(`
223
- `),nt=Math.min(Ke===-1?Re.length:Ke,st===-1?Re.length:st);if(he<=nt&&Ke===-1){L(Re.substring(1,nt)),M(!0),P(!1);return}}M(!1);const qe=Re.substring(0,he),et=qe.lastIndexOf("@");if(et!==-1){const Ke=et>0?qe[et-1]:null,st=qe.substring(et+1);(!Ke||/\s/.test(Ke))&&!st.includes(" ")&&!st.includes(`
224
- `)?(N(st),P(!0)):P(!1);return}P(!1)},[]),Me=l.useCallback(Re=>{if(T&&_.current&&(Re.key==="Enter"||Re.key==="ArrowUp"||Re.key==="ArrowDown"||Re.key==="Escape"||Re.key==="Tab")){Re.preventDefault(),_.current.handleKeyDown(Re.key);return}E&&O.current&&(Re.key==="Enter"||Re.key==="ArrowUp"||Re.key==="ArrowDown"||Re.key==="Escape"||Re.key==="Tab")&&(Re.preventDefault(),O.current.handleKeyDown(Re.key))},[T,E]),Ve=l.useCallback(Re=>{const qe=B.current?.selectionStart??c.length,Ke=c.substring(0,qe).lastIndexOf("@"),st=Re.relativePath&&Re.relativePath.trim().length>0?Re.relativePath.trim():Re.path||Re.name,nt=Ke!==-1?Ke:qe,ye=`${c.substring(0,nt)}@${st} ${c.substring(qe)}`,Je=nt+st.length+2;d(ye),P(!1),N(""),requestAnimationFrame(()=>{const _e=B.current;_e&&(_e.selectionStart=Je,_e.selectionEnd=Je,_e.focus()),ie(ye,Je)})},[c,ie]),Ce=l.useCallback(Re=>{const qe=B.current?.selectionStart??c.length,Ke=c.substring(0,qe).lastIndexOf("@"),st=Ke!==-1?Ke:qe,nt=`${c.substring(0,st)}@${Re} ${c.substring(qe)}`,ye=st+Re.length+2;d(nt),P(!1),N(""),requestAnimationFrame(()=>{const Je=B.current;Je&&(Je.selectionStart=ye,Je.selectionEnd=ye,Je.focus()),ie(nt,ye)})},[c,ie]),xe=l.useCallback(Re=>{const he=`/${Re.name} `;d(he),M(!1),L(""),requestAnimationFrame(()=>{const qe=B.current;qe&&(qe.focus(),qe.selectionStart=qe.value.length,qe.selectionEnd=qe.value.length),ie(he,he.length)})},[ie]),De=async Re=>{if(Re.preventDefault(),!!c.trim()&&!(p.length<2)){x(!0),G();try{de&&de!==re&&ue(de);const he=p.map(({instanceId:nt,...ye})=>ye),qe=b.map(nt=>({mime:nt.mimeType,filename:nt.filename,url:nt.dataUrl})),et=g.filter(nt=>nt.trim().length>0),Ke={name:i.trim(),prompt:c.trim(),models:he,agent:u||void 0,worktreeBaseBranch:pe?Ie:void 0,isolateRuns:pe,files:qe.length>0?qe:void 0,setupCommands:et.length>0?et:void 0},st=await Ee(Ke);st&&(st.firstSessionId&&Vt.getState().setCurrentSession(st.firstSessionId),e?.())}finally{x(!1)}}},Ye=!!(i.trim()&&c.trim()&&p.length>=2&&V&&!Y&&(fe===!1||!pe||Ie)),rt=g.filter(Re=>Re.trim()).length;return s.jsxs("form",{onSubmit:De,className:"flex flex-col h-full bg-background",children:[r?null:s.jsxs("header",{onMouseDown:se,className:me("relative flex h-12 shrink-0 items-center justify-center border-b app-region-drag select-none",Z,le),style:{borderColor:"var(--interactive-border)"},children:[s.jsx("h1",{className:"typography-ui-label font-medium",children:a("multirun.launcher.title")}),n&&s.jsx("div",{className:"absolute right-0 flex items-center pr-3",children:s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,"aria-label":a("multirun.launcher.actions.closeEsc"),className:"inline-flex h-9 w-9 items-center justify-center p-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary app-region-no-drag",children:s.jsx(I,{name:"close",className:"h-5 w-5"})})}),s.jsx(Pt,{children:s.jsx("p",{children:a("multirun.launcher.actions.closeEsc")})})]})})]}),s.jsx(eo,{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(qa,{htmlFor:"multirun-project",required:!0,children:a("multirun.launcher.project.label")}),Q.length>0?s.jsxs(ds,{value:de??void 0,onValueChange:q,children:[s.jsx(us,{id:"multirun-project",size:"lg",className:"w-fit max-w-full",children:F?s.jsx(ys,{children:U(F)}):s.jsx(ys,{placeholder:a("multirun.launcher.project.placeholder")})}),s.jsx(ms,{fitContent:!0,children:Q.map(Re=>s.jsx(Lt,{value:Re.id,className:"max-w-[24rem]",children:U(Re)},Re.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(qa,{htmlFor:"group-name",required:!0,info:s.jsx(Eo,{children:a("multirun.launcher.groupName.info")}),children:a("multirun.launcher.groupName.label")}),s.jsx(Kt,{id:"group-name",value:i,onChange:Re=>o(Re.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(qa,{htmlFor:"multirun-worktree-base-branch",info:s.jsx(Eo,{children:a("multirun.launcher.baseBranch.info")}),children:a("multirun.launcher.baseBranch.label")}),s.jsx(sA,{directory:V,value:Ie,onChange:Ne,disabled:!pe,id:"multirun-worktree-base-branch"}),s.jsxs("label",{className:"mt-1.5 flex w-fit items-center gap-1.5 typography-micro text-muted-foreground",children:[s.jsx(xs,{checked:S,onChange:A,disabled:!be,ariaLabel:a("multirun.launcher.isolateRuns.label")}),s.jsx("span",{children:a("multirun.launcher.isolateRuns.label")})]})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(qa,{htmlFor:"multirun-agent",info:s.jsx(Eo,{children:a("multirun.launcher.agent.info")}),children:a("multirun.launcher.agent.label")}),s.jsx(jg,{value:u,onChange:h,id:"multirun-agent"})]})]}),s.jsxs(ur,{open:y,onOpenChange:k,children:[s.jsxs(wr,{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(I,{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")}),rt>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:rt}),s.jsx(I,{name:"arrow-down-s",className:me("h-3.5 w-3.5 text-muted-foreground/50 transition-transform duration-200 ml-auto",y&&"rotate-180")})]}),s.jsx(mr,{children:s.jsx("div",{className:"pt-2 space-y-1.5",children:D?s.jsx("p",{className:"typography-meta text-muted-foreground/70 px-2",children:a("multirun.launcher.setupCommands.loading")}):s.jsxs(s.Fragment,{children:[g.map((Re,he)=>s.jsxs("div",{className:"flex gap-1.5",children:[s.jsx(Kt,{value:Re,onChange:qe=>{const et=[...g];et[he]=qe.target.value,w(et)},placeholder:a("multirun.launcher.setupCommands.commandPlaceholder"),className:"h-8 flex-1 font-mono text-xs"}),s.jsx("button",{type:"button",onClick:()=>{const qe=g.filter((et,Ke)=>Ke!==he);w(qe)},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(I,{name:"close",className:"h-3.5 w-3.5"})})]},`${Re}-${he}`)),s.jsxs("button",{type:"button",onClick:()=>w([...g,""]),className:"flex items-center gap-1 typography-meta text-muted-foreground hover:text-foreground transition-colors px-1",children:[s.jsx(I,{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(qa,{htmlFor:"prompt",required:!0,children:a("multirun.launcher.prompt.label")}),s.jsxs("div",{className:"relative",children:[s.jsx(bn,{id:"prompt",ref:B,value:c,onChange:Re=>{const he=Re.target.value;d(he);const qe=Re.target.selectionStart??he.length;ie(he,qe)},onKeyDown:Me,placeholder:a("multirun.launcher.prompt.placeholder"),className:"typography-meta min-h-[100px] max-h-[300px] resize-none overflow-y-auto field-sizing-content",required:!0}),T?s.jsx(Qh,{ref:_,searchQuery:R,onCommandSelect:xe,onClose:()=>M(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,E?s.jsx(Yh,{ref:O,searchQuery:C,onFileSelect:Ve,onAgentSelect:Ce,onClose:()=>P(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[s.jsx("input",{ref:$,type:"file",multiple:!0,className:"hidden",onChange:ge,accept:"*/*"}),s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>$.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(I,{name:"attachment-2",className:"h-3 w-3"}),a("multirun.launcher.attachments.attach")]})}),s.jsx(Pt,{children:a("multirun.launcher.attachments.tooltip")})]}),b.map(Re=>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:[Re.mimeType.startsWith("image/")?s.jsx(I,{name:"file-image",className:"h-3 w-3 text-muted-foreground"}):s.jsx(I,{name:"file",className:"h-3 w-3 text-muted-foreground"}),s.jsx("span",{className:"truncate max-w-[100px]",title:Re.filename,children:Re.filename}),s.jsx("button",{type:"button",onClick:()=>W(Re.id),className:"text-muted-foreground hover:text-destructive",children:s.jsx(I,{name:"close",className:"h-3 w-3"})})]},Re.id))]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(qa,{required:!0,info:s.jsx(Eo,{children:a("multirun.launcher.models.info",{max:$c})}),children:a("multirun.launcher.models.label")}),s.jsx(Sg,{selectedModels:p,onAdd:Pe,onRemove:Le,onUpdate:Ae,minModels:2,maxModels:$c})]}),ze&&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:ze})]})})}),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:[!pe&&fe!==null?s.jsxs("div",{className:"mr-auto flex min-w-0 items-center gap-1.5 typography-micro text-muted-foreground",children:[s.jsx(I,{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(we,{type:"button",variant:"ghost",size:"sm",onClick:n,children:a("multirun.launcher.actions.cancel")}),s.jsx(we,{type:"submit",size:"sm",disabled:!Ye||v,children:v?a("multirun.launcher.actions.creating"):s.jsx(s.Fragment,{children:a("multirun.launcher.actions.startWithModelCount",{count:p.length})})})]})})]})};class aA 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(tf,{className:"w-full max-w-md",children:[s.jsx(Oy,{className:"text-center",children:s.jsxs($y,{className:"flex items-center justify-center gap-2 text-destructive",children:[s.jsx(I,{name:"chat-3",className:"h-5 w-5"}),this.props.texts.title]})}),s.jsxs(By,{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(we,{onClick:this.handleReset,variant:"outline",className:"flex-1",children:[s.jsx(I,{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 iA(t){const e=at.c(22),{t:n}=pt();let r;e[0]!==n?(r=n("chat.errorBoundary.title"),e[0]=n,e[1]=r):r=e[1];let a;e[2]!==n?(a=n("chat.errorBoundary.description"),e[2]=n,e[3]=a):a=e[3];let i;e[4]!==n?(i=n("chat.errorBoundary.sessionLabel"),e[4]=n,e[5]=i):i=e[5];let 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(aA,{...t,texts:p}),e[19]=t,e[20]=p,e[21]=m):m=e[21],m}const jd=t=>{const e=at.c(5),{readOnly:n}=t,r=n===void 0?!1:n,i=Vt(oA)||void 0;let o;e[0]!==r?(o=s.jsx(_y,{readOnly:r}),e[0]=r,e[1]=o):o=e[1];let c;return e[2]!==i||e[3]!==o?(c=s.jsx(iA,{sessionId:i,children:o}),e[2]=i,e[3]=o,e[4]=c):c=e[4],c};function oA(t){return t.currentSessionId}const lA=Ur(()=>vr(()=>Promise.resolve().then(()=>P2),void 0).then(t=>({default:t.PlanView}))),uh=Ur(()=>vr(()=>Promise.resolve().then(()=>l0),void 0).then(t=>({default:t.GitView}))),cA=Ur(()=>vr(()=>Promise.resolve().then(()=>QN),void 0).then(t=>({default:t.DiffView}))),mh=Ur(()=>vr(()=>import("./TerminalView-CdCfCaFq.js"),__vite__mapDeps([5,0,1,2,3,4,6])).then(t=>({default:t.TerminalView}))),dA=Ur(()=>vr(()=>Promise.resolve().then(()=>j2),void 0).then(t=>({default:t.FilesView}))),uA=Ur(()=>vr(()=>Promise.resolve().then(()=>zC),void 0).then(t=>({default:t.SettingsView}))),mA=Ur(()=>vr(()=>import("./SettingsWindow-Dlfk0yzA.js"),__vite__mapDeps([7,0,1,2,3,4,6])).then(t=>({default:t.SettingsWindow}))),pA=Ur(()=>vr(()=>import("./MultiRunWindow-DezP_Pyy.js"),__vite__mapDeps([8,0,1,2,3,4,6])).then(t=>({default:t.MultiRunWindow}))),Ro=85,hA=250,fA=500,gA=400,xA=860,bA=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},yA=()=>{const{t}=pt(),e=1140,n=1220,r=640,a=700,i=Te(X=>X.isSidebarOpen),o=Te(X=>X.isRightSidebarOpen),c=Te(X=>X.isBottomTerminalOpen),d=Te(X=>X.setRightSidebarOpen),p=Te(X=>X.setBottomTerminalOpen),m=Te(X=>X.activeMainTab),u=Te(X=>X.setIsMobile),h=Te(X=>X.isSessionSwitcherOpen),b=Te(X=>X.isSettingsDialogOpen),f=Te(X=>X.setSettingsDialogOpen),v=Te(X=>X.isMultiRunLauncherOpen),x=Te(X=>X.setMultiRunLauncherOpen),g=Te(X=>X.multiRunLauncherPrefillPrompt),{isMobile:w,isTablet:y}=an(),k=l.useMemo(()=>yn(),[]),D=Te(X=>X.sidebarWidth),j=Te(X=>X.rightSidebarWidth),[S,A]=l.useState(null),E=Er()??"",P=l.useMemo(()=>bA(E),[E]),C=Te(X=>{if(!P)return!1;const F=X.contextPanelByDirectory[P],V=F?.tabs??[],q=V.find(te=>te.id===F?.activeTabId)??V[V.length-1];return!!(F?.isOpen&&q)}),N=Te(X=>X.setSidebarOpen),T=l.useRef(!1),M=l.useRef(!1),R=l.useRef(!1),[L,$]=l.useState(!1),B=l.useRef(!1),O=cu(0),_=Be.useRef(0),ee=cu(0),z=Be.useRef(0);Be.useEffect(()=>{w&&(_.current=window.innerWidth*(Ro/100),z.current=window.innerWidth*(Ro/100))},[w]),Be.useEffect(()=>{if(!w)return;const X=L?0:-_.current;du(O,X,{type:"spring",stiffness:400,damping:35,mass:.8})},[L,w,O]),Be.useEffect(()=>{if(!w)return;B.current=o;const X=o?0:z.current;du(ee,X,{type:"spring",stiffness:400,damping:35,mass:.8})},[w,o,ee]),Be.useEffect(()=>{w&&$(h)},[h,w]),Be.useEffect(()=>{!w||!b||($(!1),h&&Te.getState().setSessionSwitcherOpen(!1),o&&d(!1))},[w,b,h,o,d]),Be.useEffect(()=>{w&&(B.current=o)},[o,w]);const ne=ka(X=>X.checkForUpdates);l.useEffect(()=>{let te=!1,U=null;const ae=oe=>{const ve=Math.round(oe*1e3);return Math.max(3e5,Math.min(864e5,ve))},je=oe=>{te||(U=window.setTimeout(async()=>{const ve=await ne(),K=typeof ve=="number"&&Number.isFinite(ve)?ae(ve):36e5;je(K)},oe))};return je(3e3),()=>{te=!0,U!==null&&window.clearTimeout(U)}},[ne]),l.useEffect(()=>{Te.getState().isMobile!==w&&u(w)},[w,u]),l.useEffect(()=>{if(typeof window>"u")return;let X;const F=()=>{X!==void 0&&window.clearTimeout(X),X=window.setTimeout(()=>{Te.getState().updateProportionalSidebarWidths()},150)};return window.addEventListener("resize",F),()=>{window.removeEventListener("resize",F),X!==void 0&&window.clearTimeout(X)}},[]),l.useEffect(()=>{if(C){Te.getState().isSidebarOpen&&(N(!1),R.current=!0);return}R.current&&(N(!0),R.current=!1)},[C,N]),l.useEffect(()=>{if(typeof window>"u")return;let X;const F=()=>{const q=Te.getState(),te=window.innerWidth,U=window.innerHeight;if(!w&&!y){const ae=te<e,je=te>=n;ae?q.isRightSidebarOpen&&(d(!1),T.current=!0):je&&T.current&&(d(!0),T.current=!1);const oe=U<r,ve=U>=a;oe?q.isBottomTerminalOpen&&(p(!1),M.current=!0):ve&&M.current&&(p(!0),M.current=!1)}},V=()=>{X!==void 0&&window.clearTimeout(X),X=window.setTimeout(()=>{F()},100)};return F(),window.addEventListener("resize",V),()=>{window.removeEventListener("resize",V),X!==void 0&&window.clearTimeout(X)}},[w,y,p,d]),l.useEffect(()=>{if(typeof window>"u")return;const X=Te.subscribe((F,V)=>{const q=window.innerWidth,te=window.innerHeight,U=q>=n,ae=te>=a;F.isRightSidebarOpen!==V.isRightSidebarOpen&&U&&(T.current=!1),F.isBottomTerminalOpen!==V.isBottomTerminalOpen&&ae&&(M.current=!1)});return()=>{X()}},[w,y,p,d]);const re=l.useMemo(()=>{switch(m){case"plan":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(lA,{})});case"git":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(uh,{})});case"diff":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(cA,{})});case"terminal":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(mh,{})});case"files":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(dA,{})});default:return null}},[m]),ue=m==="chat",Q=l.useMemo(()=>Math.min(fA,Math.max(hA,D||Zc)),[D]),de=l.useMemo(()=>Math.min(xA,Math.max(gA,j||bf)),[j]);return s.jsx(xN,{children:s.jsxs("div",{"data-page-scroll-lock":"true",className:me("main-content-safe-area h-[100dvh]",w?"flex flex-col":"flex","bg-background"),children:[s.jsx(UC,{}),s.jsx(D4,{}),s.jsx(R4,{}),s.jsx(G6,{}),w?s.jsxs(Vy,{value:{leftDrawerOpen:L,rightDrawerOpen:o,toggleLeftDrawer:()=>{o&&d(!1),$(!L)},toggleRightDrawer:()=>{L&&$(!1),d(!o)},leftDrawerX:O,rightDrawerX:ee,leftDrawerWidth:_,rightDrawerWidth:z,setMobileLeftDrawerOpen:$,setRightSidebarOpen:d},children:[!b&&s.jsx(Zu,{onToggleLeftDrawer:()=>{o&&d(!1),$(!L)},onToggleRightDrawer:()=>{L&&$(!1),d(!o)},leftDrawerOpen:L,rightDrawerOpen:o}),s.jsx(zl.button,{type:"button",initial:!1,animate:{opacity:L||o?1:0,pointerEvents:L||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:()=>{$(!1),d(!1)},"aria-label":t("mainLayout.mobile.closeDrawerAria")}),s.jsx(zl.aside,{drag:"x",dragElastic:.08,dragMomentum:!1,dragConstraints:{left:-(_.current||window.innerWidth*.85),right:0},style:{width:`${Ro}%`,x:O},onDragEnd:(X,F)=>{const V=_.current||window.innerWidth*.85,q=V*.3,te=500,U=O.get(),ae=F.offset.x<-q||F.velocity.x<-te,je=F.offset.x>q||F.velocity.x>te;ae?(O.set(-V),$(!1)):je?(O.set(0),$(!0)):U>-V/2?O.set(0):O.set(-V)},className:me("fixed left-0 top-[var(--oc-header-height,56px)] z-50 h-[calc(100%-var(--oc-header-height,56px))] bg-background","cursor-grab active:cursor-grabbing"),"aria-hidden":!L,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(Xs,{children:s.jsx(lh,{mobileVariant:!0})})})})}),s.jsx(zl.aside,{drag:"x",dragElastic:.08,dragMomentum:!1,dragConstraints:{left:0,right:z.current||window.innerWidth*.85},style:{width:`${Ro}%`,x:ee},onDragEnd:(X,F)=>{const V=z.current||window.innerWidth*.85,q=V*.3,te=500,U=ee.get(),ae=F.offset.x>q||F.velocity.x>te,je=F.offset.x<-q||F.velocity.x<-te;ae?(ee.set(V),d(!1)):je?(ee.set(0),d(!0)):U<V/2?ee.set(0):ee.set(V)},className:me("fixed right-0 top-[var(--oc-header-height,56px)] z-50 h-[calc(100%-var(--oc-header-height,56px))] bg-background","cursor-grab active:cursor-grabbing"),"aria-hidden":!o,children:s.jsx("div",{className:"h-full overflow-hidden flex flex-col bg-background shadow-none drawer-safe-area","data-page-scroll-lock":"true",children:s.jsx(Xs,{children:s.jsx(l.Suspense,{fallback:null,children:s.jsx(uh,{})})})})}),s.jsx("div",{"data-page-scroll-lock":"true",className:me("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:me("absolute inset-0",!ue&&"invisible"),children:s.jsx(Xs,{children:s.jsx(jd,{})})}),re&&s.jsx("div",{className:"absolute inset-0",children:s.jsx(Xs,{children:re})}),v&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",children:s.jsx(Xs,{children:s.jsx(rA,{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(Xs,{children:s.jsx(l.Suspense,{fallback:null,children:s.jsx(uA,{onClose:()=>f(!1)})})})})]}):s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"flex flex-1 overflow-hidden relative",children:s.jsxs("div",{className:me("absolute inset-0 flex overflow-hidden","bg-sidebar"),"data-page-scroll-lock":"true",children:[i?s.jsxs(s.Fragment,{children:[s.jsx("div",{"aria-hidden":!0,className:me("pointer-events-none absolute top-0 z-0","bg-sidebar"),style:{left:`${Q}px`,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 100% 100%, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 100% 100%, transparent calc(10px - 1px), black 10px)"}}),s.jsx("div",{"aria-hidden":!0,className:me("pointer-events-none absolute bottom-0 z-0","bg-sidebar"),style:{left:`${Q}px`,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 100% 0%, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 100% 0%, transparent calc(10px - 1px), black 10px)"}})]}):null,o?s.jsxs(s.Fragment,{children:[s.jsx("div",{"aria-hidden":!0,className:me("pointer-events-none absolute top-0 z-0","bg-sidebar"),style:{right:`${de}px`,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 0 100%, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 0 100%, transparent calc(10px - 1px), black 10px)"}}),s.jsx("div",{"aria-hidden":!0,className:me("pointer-events-none absolute bottom-0 z-0","bg-sidebar"),style:{right:`${de}px`,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 0 0, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 0 0, transparent calc(10px - 1px), black 10px)"}})]}):null,s.jsx(_1,{isOpen:i,isMobile:w,className:"border-0",children:s.jsx(lh,{})}),s.jsxs("div",{className:me("relative flex flex-1 min-w-0 flex-col overflow-hidden","bg-sidebar",i&&"border-l border-border/50 rounded-tl-[10px] rounded-bl-[10px]",o&&"border-r border-border/50 rounded-tr-[10px] rounded-br-[10px]"),"data-page-scroll-lock":"true",children:[s.jsx(Zu,{desktopRightSidebarActionsHost:S}),s.jsx("div",{className:me("flex flex-1 min-h-0 overflow-hidden",i||ue?"":"border-l border-border/50",o?"":"border-r border-border/50"),"data-page-scroll-lock":"true",children:s.jsxs("div",{className:"relative flex flex-1 min-h-0 min-w-0 overflow-hidden","data-page-scroll-lock":"true",children:[s.jsxs("main",{className:"flex-1 overflow-hidden bg-background relative","data-page-scroll-lock":"true",children:[s.jsx("div",{className:me("absolute inset-0",!ue&&"invisible"),children:s.jsx(Xs,{children:s.jsx(jd,{})})}),re&&s.jsx("div",{className:"absolute inset-0",children:s.jsx(Xs,{children:re})})]}),s.jsx(hS,{})]})}),s.jsx(F1,{isOpen:c,isMobile:w,children:c?s.jsx(Xs,{children:s.jsx(l.Suspense,{fallback:null,children:s.jsx(mh,{})})}):null})]}),s.jsx(V1,{isOpen:o,className:"border-0",onTopActionsHostChange:A,children:s.jsx(Xs,{children:s.jsx(z0,{})})})]})}),s.jsx(l.Suspense,{fallback:null,children:s.jsx(mA,{open:b,onOpenChange:f})}),s.jsx(l.Suspense,{fallback:null,children:s.jsx(pA,{open:v,onOpenChange:x,initialPrompt:g})})]})]})})},vA=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`},or=t=>{const e=at.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},ph=t=>{const e=at.c(43),{title:n,snapshot:r,emptyLabel:a}=t,{t:i}=pt();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(NA,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?vA(r.durationMs):i("memoryDebugPanel.common.idle"),e[12]=r.durationMs,e[13]=r.startedAt,e[14]=i,e[15]=u):u=e[15];let h;e[16]!==u?(h=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:u}),e[16]=u,e[17]=h):h=e[17];let b;e[18]!==m||e[19]!==h?(b=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[m,h]}),e[18]=m,e[19]=h,e[20]=b):b=e[20];let f;e[21]!==i?(f=i("memoryDebugPanel.metric.metrics"),e[21]=i,e[22]=f):f=e[22];let v;e[23]!==r.entries.length||e[24]!==f?(v=s.jsx(or,{label:f,value:r.entries.length}),e[23]=r.entries.length,e[24]=f,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(or,{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 k;e[36]!==w||e[37]!==y?(k=s.jsx(or,{label:w,value:y}),e[36]=w,e[37]=y,e[38]=k):k=e[38];let D;e[39]!==g||e[40]!==k||e[41]!==v?(D=s.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[v,g,k]}),e[39]=g,e[40]=k,e[41]=v,e[42]=D):D=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,D,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(Ts,{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},wA=t=>{const e=at.c(101),{onClose:n}=t,{t:r}=pt(),[a,i]=l.useState("memory"),[o,c]=l.useState("idle"),d=Vt(SA),p=Zh(kA),m=Pl(),u=Vh(CA),h=cr(IA),[b,f]=l.useState(PA),[v,x]=l.useState(AA);let g;e[0]!==b.entries?(g=new Map,b.entries.forEach(Ne=>{g.set(Ne.metric,Ne.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 k;e[6]!==g?(k=g.get("ui.chat_message.render")??0,e[6]=g,e[7]=k):k=e[7];let D;e[8]!==g?(D=g.get("ui.chat_message.render.streaming")??0,e[8]=g,e[9]=D):D=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 A;e[14]!==w||e[15]!==y||e[16]!==k||e[17]!==D||e[18]!==j||e[19]!==S?(A={messageListRender:w,messageListRenderStreaming:y,chatMessageRender:k,chatMessageRenderStreaming:D,chatMessageRenderStaticDuringStream:j,chatMessageRenderStaticOutsideActiveTurnDuringStream:S},e[14]=w,e[15]=y,e[16]=k,e[17]=D,e[18]=j,e[19]=S,e[20]=A):A=e[20];const E=A;let P,C;e[21]===Symbol.for("react.memo_cache_sentinel")?(P=()=>{const Ne=()=>{f(Bo()),x(_o())};Ne();const Y=window.setInterval(Ne,500);return()=>window.clearInterval(Y)},C=[],e[21]=P,e[22]=C):(P=e[21],C=e[22]),l.useEffect(P,C);let N,T;e[23]!==o?(N=()=>{if(o==="idle")return;const Ne=window.setTimeout(()=>{c("idle")},1500);return()=>window.clearTimeout(Ne)},T=[o],e[23]=o,e[24]=N,e[25]=T):(N=e[24],T=e[25]),l.useEffect(N,T);let M=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]!==M){for(const Ne of R)M=M+(u[Ne]?.length??0);e[28]=u,e[29]=R,e[30]=M,e[31]=M}else M=e[31];const L=M;let $;if(e[32]!==d||e[33]!==u||e[34]!==p||e[35]!==m||e[36]!==r){let Ne;e[38]!==d||e[39]!==u||e[40]!==p||e[41]!==r?(Ne=Y=>{const fe=u[Y.id]?.length||0,ke=p.get(Y.id);return{id:Y.id,title:Y.title||r("memoryDebugPanel.common.untitled"),messageCount:fe,isStreaming:ke?.isStreaming||!1,isZombie:ke?.isZombie||!1,backgroundCount:ke?.backgroundMessageCount||0,lastAccessed:ke?.lastAccessedAt||0,isCurrent:Y.id===d}},e[38]=d,e[39]=u,e[40]=p,e[41]=r,e[42]=Ne):Ne=e[42],$=m.map(Ne).sort(DA),e[32]=d,e[33]=u,e[34]=p,e[35]=m,e[36]=r,e[37]=$}else $=e[37];const B=$;let O;e[43]!==u?(O=Object.keys(u),e[43]=u,e[44]=O):O=e[44];const _=O.length;let ee;e[45]===Symbol.for("react.memo_cache_sentinel")?(ee=async()=>{try{const Ne={generatedAt:new Date().toISOString(),ui:Bo(),vscode:_o()};await navigator.clipboard.writeText(JSON.stringify(Ne,null,2)),c("copied")}catch{c("error")}},e[45]=ee):ee=e[45];const z=ee;let ne;e[46]===Symbol.for("react.memo_cache_sentinel")?(ne={backgroundColor:"color-mix(in srgb, var(--surface-background) 94%, transparent)"},e[46]=ne):ne=e[46];let re;e[47]!==a?(re=a==="memory"?s.jsx(I,{name:"database-2",className:"h-4 w-4 text-[var(--surface-foreground)]"}):s.jsx(I,{name:"bar-chart-box",className:"h-4 w-4 text-[var(--surface-foreground)]"}),e[47]=a,e[48]=re):re=e[48];let ue;e[49]!==r?(ue=r("memoryDebugPanel.title"),e[49]=r,e[50]=ue):ue=e[50];let Q;e[51]!==ue?(Q=s.jsx("h3",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:ue}),e[51]=ue,e[52]=Q):Q=e[52];let de;e[53]!==re||e[54]!==Q?(de=s.jsxs("div",{className:"flex items-center gap-2",children:[re,Q]}),e[53]=re,e[54]=Q,e[55]=de):de=e[55];let X;e[56]!==a?(X=a==="streaming"?s.jsxs(s.Fragment,{children:[s.jsx(we,{size:"xs",variant:"ghost",onClick:z,children:s.jsx(I,{name:"file-copy",className:"h-3.5 w-3.5"})}),s.jsx(we,{size:"xs",variant:"ghost",onClick:()=>{Uy(),f(Bo()),x(_o())},children:s.jsx(I,{name:"refresh",className:"h-3.5 w-3.5"})})]}):null,e[56]=a,e[57]=X):X=e[57];let F;e[58]!==n?(F=n?s.jsx(we,{size:"icon",variant:"ghost",className:"h-6 w-6",onClick:n,children:s.jsx(I,{name:"close",className:"h-4 w-4"})}):null,e[58]=n,e[59]=F):F=e[59];let V;e[60]!==X||e[61]!==F?(V=s.jsxs("div",{className:"flex items-center gap-1",children:[X,F]}),e[60]=X,e[61]=F,e[62]=V):V=e[62];let q;e[63]!==de||e[64]!==V?(q=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-2",children:[de,V]}),e[63]=de,e[64]=V,e[65]=q):q=e[65];let te;e[66]===Symbol.for("react.memo_cache_sentinel")?(te={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[66]=te):te=e[66];const U=a==="memory"?"secondary":"ghost";let ae;e[67]===Symbol.for("react.memo_cache_sentinel")?(ae=()=>i("memory"),e[67]=ae):ae=e[67];let je;e[68]!==r?(je=r("memoryDebugPanel.tabs.memory"),e[68]=r,e[69]=je):je=e[69];let oe;e[70]!==U||e[71]!==je?(oe=s.jsx(we,{size:"sm",variant:U,className:"flex-1",onClick:ae,children:je}),e[70]=U,e[71]=je,e[72]=oe):oe=e[72];const ve=a==="streaming"?"secondary":"ghost";let K;e[73]===Symbol.for("react.memo_cache_sentinel")?(K=()=>i("streaming"),e[73]=K):K=e[73];let ce;e[74]!==r?(ce=r("memoryDebugPanel.tabs.streaming"),e[74]=r,e[75]=ce):ce=e[75];let Z;e[76]!==ve||e[77]!==ce?(Z=s.jsx(we,{size:"sm",variant:ve,className:"flex-1",onClick:K,children:ce}),e[76]=ve,e[77]=ce,e[78]=Z):Z=e[78];let le;e[79]!==oe||e[80]!==Z?(le=s.jsxs("div",{className:"mb-3 flex gap-1 rounded-md p-1",style:te,children:[oe,Z]}),e[79]=oe,e[80]=Z,e[81]=le):le=e[81];let se;e[82]!==a||e[83]!==_||e[84]!==o||e[85]!==d||e[86]!==u||e[87]!==p||e[88]!==B||e[89]!==m||e[90]!==E||e[91]!==b||e[92]!==r||e[93]!==h||e[94]!==L||e[95]!==v?(se=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(or,{label:r("memoryDebugPanel.metric.totalMessages"),value:L}),s.jsx(or,{label:r("memoryDebugPanel.metric.cachedSessions"),value:`${_} / ${Ru.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:zy()})})]}),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:Ru.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:h})]})]}),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(Ts,{outerClassName:"max-h-48",className:"space-y-1 pr-1",children:B.map(Ne=>s.jsxs("div",{className:"typography-meta flex items-center justify-between rounded p-1.5",style:{backgroundColor:Ne.isCurrent?"color-mix(in srgb, var(--interactive-selection) 22%, transparent)":"color-mix(in srgb, var(--surface-muted) 35%, transparent)"},children:[s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[s.jsx("span",{className:"truncate text-[var(--surface-foreground)]",children:Ne.title}),Ne.isStreaming?s.jsx(I,{name:"pulse",className:"h-3 w-3 animate-pulse text-[var(--status-info)]"}):null,Ne.isZombie?s.jsx("span",{className:"text-[var(--status-warning)]",children:"!"}):null]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"font-mono text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.msgsValue",{count:Ne.messageCount})}),Ne.backgroundCount>0?s.jsxs("span",{className:"text-[var(--status-info)]",children:["+",Ne.backgroundCount]}):null]})]},Ne.id))})]}),s.jsx("div",{className:"flex gap-2 border-t border-[var(--interactive-border)] pt-2",children:s.jsxs(kt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(we,{size:"sm",variant:"outline",className:"typography-meta",onClick:()=>{console.log("[DebugPanel] Session store state:",{sessions:m.map(TA),currentSessionId:d,cachedSessions:Object.keys(u),memoryStates:Object.fromEntries(p)})},children:r("memoryDebugPanel.actions.logState")})}),s.jsx(Pt,{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(we,{size:"xs",variant:"outline",onClick:z,children:r("memoryDebugPanel.actions.copyJson")})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[s.jsx(or,{label:r("memoryDebugPanel.metric.uiMetrics"),value:b.entries.length}),s.jsx(or,{label:r("memoryDebugPanel.metric.vscodeMetrics"),value:v.entries.length}),s.jsx(or,{label:r("memoryDebugPanel.metric.messageListRenders"),value:E.messageListRender}),s.jsx(or,{label:r("memoryDebugPanel.metric.messageListStreamRenders"),value:E.messageListRenderStreaming}),s.jsx(or,{label:r("memoryDebugPanel.metric.chatMessageRenders"),value:E.chatMessageRender}),s.jsx(or,{label:r("memoryDebugPanel.metric.chatMessageStreamRenders"),value:E.chatMessageRenderStreaming}),s.jsx(or,{label:r("memoryDebugPanel.metric.chatMessageStaticDuringStream"),value:E.chatMessageRenderStaticDuringStream}),s.jsx(or,{label:r("memoryDebugPanel.metric.chatMessageStaticOutsideActiveTurn"),value:E.chatMessageRenderStaticOutsideActiveTurnDuringStream})]}),s.jsx(ph,{title:r("memoryDebugPanel.section.uiStreamingMetrics"),snapshot:b,emptyLabel:r("memoryDebugPanel.section.noUiSamples")}),v.entries.length>0?s.jsx(ph,{title:r("memoryDebugPanel.section.vscodeBridgeMetrics"),snapshot:v,emptyLabel:r("memoryDebugPanel.section.noVscodeSamples")}):null]}),e[82]=a,e[83]=_,e[84]=o,e[85]=d,e[86]=u,e[87]=p,e[88]=B,e[89]=m,e[90]=E,e[91]=b,e[92]=r,e[93]=h,e[94]=L,e[95]=v,e[96]=se):se=e[96];let Ie;return e[97]!==q||e[98]!==le||e[99]!==se?(Ie=s.jsxs(tf,{className:"fixed bottom-4 right-4 z-50 w-[28rem] p-4 shadow-none bottom-safe-area",style:ne,children:[q,le,se]}),e[97]=q,e[98]=le,e[99]=se,e[100]=Ie):Ie=e[100],Ie},jA=wA;function NA(t,e){return t+e.count}function SA(t){return t.currentSessionId}function kA(t){return t.sessionMemoryState}function CA(t){return t.message}function IA(t){return t.totalRequestCount}function PA(){return Bo()}function AA(){return _o()}function DA(t,e){return e.lastAccessed-t.lastAccessed}function TA(t){return{id:t.id,title:t.title}}const MA=()=>{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()??"":""},EA=async()=>{const t=MA()||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")},hh="openchamber:menu-action",Bc="openchamber:check-for-updates",RA=t=>{const e=Vt(x=>x.openNewSessionDraft),n=Te(x=>x.toggleCommandPalette),r=Te(x=>x.setCommandPaletteOpen),a=Te(x=>x.toggleHelpDialog),i=Te(x=>x.toggleSidebar),o=Te(x=>x.setSessionSwitcherOpen),c=Te(x=>x.setActiveMainTab),d=Te(x=>x.setSettingsDialogOpen),p=Te(x=>x.setAboutDialogOpen),m=ka(x=>x.checkForUpdates),{setThemeMode:u}=jr(),h=l.useRef(!1),b=l.useCallback(()=>{h.current||(h.current=!0,m().then(()=>{const{available:x,error:g}=ka.getState();if(g){H.error("Failed to check for updates",{description:g});return}x||H.success("You are on the latest version")}).finally(()=>{h.current=!1}))},[m]),f=l.useCallback(()=>{yr.requestDirectoryDialog()},[]),v=l.useCallback(x=>{switch(x){case"about":p(!0);break;case"settings":d(!0);break;case"command-palette":n();break;case"quick-open":r(!0);break;case"new-session":c("chat"),o(!1),e();break;case"new-worktree-session":c("chat"),o(!1),Gh();break;case"change-workspace":f();break;case"open-git-tab":{const{activeMainTab:g}=Te.getState();c(g==="git"?"chat":"git");break}case"open-diff-tab":{const{activeMainTab:g}=Te.getState();c(g==="diff"?"chat":"diff");break}case"open-files-tab":{const{activeMainTab:g}=Te.getState();c(g==="files"?"chat":"files");break}case"open-terminal-tab":{const{activeMainTab:g}=Te.getState();c(g==="terminal"?"chat":"terminal");break}case"copy":{const g=new Event("openchamber:copy",{cancelable:!0});!window.dispatchEvent(g)||EA();break}case"theme-light":u("light");break;case"theme-dark":u("dark");break;case"theme-system":u("system");break;case"toggle-sidebar":i();break;case"toggle-memory-debug":t?.();break;case"help-dialog":a();break;case"download-logs":{Wy().catch(()=>{H.error("Failed to collect OpenCode status")});break}}},[f,t,e,p,c,o,r,d,u,n,a,i]);l.useEffect(()=>{const x=w=>{const y=w.detail;y&&v(y)},g=()=>{b()};return window.addEventListener(hh,x),window.addEventListener(Bc,g),()=>{window.removeEventListener(hh,x),window.removeEventListener(Bc,g)}},[v,b]),l.useEffect(()=>{if(typeof window>"u")return;const g=window.__TAURI__?.event?.listen;if(typeof g!="function")return;let w=null,y=null;return g("openchamber:menu-action",k=>{const D=k?.payload;typeof D=="string"&&v(D)}).then(k=>{w=k}).catch(()=>{}),g("openchamber:check-for-updates",()=>{window.dispatchEvent(new Event(Bc))}).then(k=>{y=k}).catch(()=>{}),()=>{(async()=>{try{const D=w?.();D instanceof Promise&&await D}catch{}try{const D=y?.();D instanceof Promise&&await D}catch{}})()}},[v])},FA=["chat","git","diff","terminal","files"],LA=["settings","agents","commands","skills","providers","usage","git-identities"],xr={SESSION:"session",TAB:"tab",SETTINGS:"settings",FILE:"file"};function fh(t){const e=OA();return{sessionId:$A(e),tab:BA(e),settingsPath:_A(e),diffFile:VA(e)}}function OA(){if(typeof window>"u")return new URLSearchParams;try{return new URLSearchParams(window.location.search)}catch{return new URLSearchParams}}function $A(t){const e=t.get(xr.SESSION);return!e||e.trim().length===0?null:e.trim()}function BA(t){const e=t.get(xr.TAB);if(!e)return null;const n=e.toLowerCase().trim();return FA.includes(n)?n:null}function _A(t){const e=t.get(xr.SETTINGS);if(!e)return null;const n=e.toLowerCase().trim();return n.length===0?null:n==="openchamber"||n==="general"||n==="preferences"?"home":(LA.includes(n),n)}function VA(t){const e=t.get(xr.FILE);if(!e||e.trim().length===0)return null;try{return decodeURIComponent(e.trim())}catch{return e.trim()}}function gh(){if(typeof window>"u")return!1;try{const t=new URLSearchParams(window.location.search);return t.has(xr.SESSION)||t.has(xr.TAB)||t.has(xr.SETTINGS)||t.has(xr.FILE)}catch{return!1}}const zA="chat";function Tg(t){const e=new URLSearchParams;if(t.sessionId&&t.sessionId.trim().length>0&&e.set(xr.SESSION,t.sessionId),t.isSettingsOpen){const n=t.settingsPath.trim().length>0?t.settingsPath:"home";return e.set(xr.SETTINGS,n),e}return t.tab!==zA&&e.set(xr.TAB,t.tab),t.tab==="diff"&&t.diffFile&&t.diffFile.trim().length>0&&e.set(xr.FILE,t.diffFile),e}function UA(t,e){const n=typeof window<"u"?window.location.pathname:"/",r=t.toString();return r?`${n}?${r}`:n}function WA(t){if(typeof window>"u")return!0;try{const e=new URLSearchParams(window.location.search),n=Tg(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 KA(t,e={}){if(!(typeof window>"u")&&!HA()&&!(!e.force&&WA(t)))try{const n=Tg(t),r=UA(n);e.replace?window.history.replaceState({...window.history.state,route:t},"",r):window.history.pushState({route:t},"",r)}catch{}}function HA(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function GA(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function qA(){const t=l.useMemo(()=>GA(),[]),e=l.useRef(!1),n=l.useRef(!1),r=Vt(u=>u.setCurrentSession),a=Te(u=>u.setActiveMainTab),i=Te(u=>u.setSettingsDialogOpen),o=Te(u=>u.setSettingsPage),c=Te(u=>u.navigateToDiff),d=l.useCallback(async u=>{if(!n.current){n.current=!0;try{if(u.sessionId){const h=Vt.getState().currentSessionId;u.sessionId!==h&&await r(u.sessionId)}if(u.settingsPath){o(Jf(u.settingsPath)),i(!0);return}Te.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=Vt.getState(),h=Te.getState();return{sessionId:u.currentSessionId,tab:h.activeMainTab,isSettingsOpen:h.isSettingsDialogOpen,settingsPath:h.settingsPage,diffFile:h.pendingDiffFile}},[]),m=l.useCallback((u={})=>{if(t||n.current)return;const h=p();KA(h,u)},[t,p]);l.useEffect(()=>{if(e.current||(e.current=!0,!gh()))return;const u=fh();(async()=>(await d(u),t||m({replace:!0})))()},[d,t,m]),l.useEffect(()=>{if(t)return;let u=Vt.getState().currentSessionId;return Vt.subscribe(b=>{const f=b.currentSessionId;f===u||n.current||(u=f,m())})},[t,m]),l.useEffect(()=>{if(t)return;let u=Te.getState().activeMainTab,h=Te.getState().isSettingsDialogOpen,b=Te.getState().settingsPage,f=Te.getState().pendingDiffFile;return Te.subscribe(x=>{if(n.current)return;const g=x.activeMainTab!==u,w=x.isSettingsDialogOpen!==h,y=x.settingsPage!==b,k=x.pendingDiffFile!==f&&x.activeMainTab==="diff";u=x.activeMainTab,h=x.isSettingsDialogOpen,b=x.settingsPage,f=x.pendingDiffFile,(g||w||y||k)&&m()})},[t,m]),l.useEffect(()=>{if(typeof window>"u"||t)return;const u=()=>{const h=fh();if(gh())d(h);else{const b=Te.getState();b.isSettingsDialogOpen&&i(!1),b.activeMainTab!=="chat"&&a("chat")}};return window.addEventListener("popstate",u),()=>{window.removeEventListener("popstate",u)}},[d,t,a,i])}const xh="pwa-install-toast-shown",JA=()=>{const t=at.c(6),{browserTab:e}=lg(),{t:n}=pt(),r=l.useRef(n);let a,i;t[0]!==n?(a=()=>{r.current=n},i=[n],t[0]=n,t[1]=a,t[2]=i):(a=t[1],i=t[2]),l.useEffect(a,i);let o,c;t[3]!==e?(o=()=>{if(typeof window>"u"||!sa()||!e)return;let d=null,p=null;const m=()=>{p!==null&&(H.dismiss(p),p=null)},u=async()=>{if(!d)return;const f=d;d=null,m(),await f.prompt();const{outcome:v}=await f.userChoice;v==="accepted"&&H.success(r.current("pwa.installPrompt.started"))},h=f=>{const v=f;if(typeof v.prompt!="function")return;v.preventDefault(),d=v;const x=Ah();x.getItem(xh)!=="true"&&p===null&&(x.setItem(xh,"true"),p=H.info(r.current("pwa.installPrompt.description"),{duration:1/0,action:{label:r.current("pwa.installPrompt.action"),onClick:()=>{u()}}}))},b=()=>{d=null,m(),H.success(r.current("pwa.installPrompt.installed"))};return window.addEventListener("beforeinstallprompt",h),window.addEventListener("appinstalled",b),()=>{m(),window.removeEventListener("beforeinstallprompt",h),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)},QA=["local","remote",null],YA=["ok","not-configured","unreachable","wrong-service","missing"];function Mg(t){if(!t||typeof t!="object")return{valid:!1};const e=t,n=e.target,r=e.status;if(n!==null&&(typeof n!="string"||!QA.includes(n)))return{valid:!1};if(typeof r!="string"||!YA.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 bh(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 XA(t){return t.isDesktopShell?t.bootOutcomeKnown?t.bootViewIsMain===!1?!0:t.isInitialized:!1:t.isInitialized}function ZA(t){return t.isTauriShell&&!t.isDesktopLocalOriginActive}function yh(){if(Nd()!=="valid")return null;const e=window.__OPENCHAMBER_DESKTOP_BOOT_OUTCOME__,n=Mg(e);return n.valid?n.outcome:null}function Nd(){if(typeof window>"u")return"not-injected";const t=window.__OPENCHAMBER_DESKTOP_BOOT_OUTCOME__;return t==null?"not-injected":Mg(t).valid?"valid":"malformed"}const eD=()=>{const t=at.c(5),[e,n]=l.useState(tD),{isUpdating:r,message:a}=e;let i,o;if(t[0]===Symbol.for("react.memo_cache_sentinel")?(i=()=>Hy(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 tD(){return Ky()}const sD=({open:t,onOpenChange:e})=>{const{t:n}=pt(),[r,a]=l.useState(null),[i,o]=l.useState(null),[c,d]=l.useState(!1),[p,m]=l.useState(!1),[u,h]=l.useState(null),[b,f]=l.useState(!1),v=l.useCallback(async()=>{if(!c){d(!0),m(!1);try{if(!u){H.error(n("aboutDialog.toast.copyFailed"),{description:n("aboutDialog.toast.diagnosticsNotReady")});return}const g=await Fu.copyTextToClipboard(u);g.ok?(m(!0),H.success(n("aboutDialog.toast.diagnosticsCopied"))):H.error(n("aboutDialog.toast.copyFailed"),{description:g.error})}catch(g){H.error(n("aboutDialog.toast.copyFailed")),console.error("Failed to copy diagnostics:",g)}finally{d(!1)}}},[u,c,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()){a(y.openchamberVersion);return}}}catch{}a(await Gy())})()},[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 k=await y.json().catch(()=>null),D=typeof k?.currentVersion=="string"?k.currentVersion.trim():"";!g&&D&&o(D)}catch{}})(),()=>{g=!0}},[t]),l.useEffect(()=>{if(!t){h(null),f(!1);return}let g=!1;return f(!0),Fu.buildDiagnosticsReport().then(w=>{g||h(w)}).catch(w=>{g||(console.error("Failed to prepare diagnostics:",w),h(null))}).finally(()=>{g||f(!1)}),()=>{g=!0}},[t]);const x=r;return s.jsx(ws,{open:t,onOpenChange:e,children:s.jsx(vs,{className:"max-w-xs p-6",children:s.jsxs("div",{className:"flex flex-col items-center text-center space-y-4",children:[s.jsx(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})}),i&&s.jsx("p",{children:n("aboutDialog.openCodeVersionLabel",{version:i})})]})]}),s.jsxs("div",{className:"flex flex-col items-center gap-2 pt-2",children:[s.jsx("button",{onClick:v,disabled:c||b||!u,className:me("typography-meta text-muted-foreground hover:text-foreground","underline-offset-2 hover:underline","disabled:opacity-50 disabled:cursor-not-allowed"),children:n(p?"aboutDialog.actions.diagnosticsCopied":b?"aboutDialog.actions.preparingDiagnostics":"aboutDialog.actions.copyDiagnostics")}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:n("aboutDialog.diagnosticsDescription")})]}),s.jsxs("div",{className:"flex items-center gap-4 pt-2",children:[s.jsxs("a",{href:"https://github.com/btriapitsyn/openchamber",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(I,{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(I,{name:"discord-fill",className:"h-4 w-4"}),s.jsx("span",{children:"Discord"})]}),s.jsxs("a",{href:"https://x.com/btriapitsyn",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(I,{name:"twitter-xfill",className:"h-4 w-4"}),s.jsx("span",{children:"@btriapitsyn"})]})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/60 pt-2",children:n("aboutDialog.footerNote")})]})})})},_c=(t,e)=>{const n=t.get(e);return typeof n!="string"?null:n.trim()||null},nD=(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},rD=()=>{const t=Nn(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=_c(i,"code"),c=eg(i),d=Qd(i),p=_c(i,"error"),m=_c(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 h=await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`);if(h.ok){const b=await h.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(nD(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(we,{type:"button",onClick:()=>{typeof window>"u"||window.location.replace("/")},children:"Return to OpenChamber"})})]})})},Fo="opencode-update-available",Lo="opencode-upgrade-progress",aD=5e3,iD=[1e4,6e4],Eg=()=>{const{t}=pt(),e=Te(o=>o.showOpenCodeUpdateNotifications),n=Be.useRef(new Set),r=Be.useRef(!1);Be.useEffect(()=>{e||H.dismiss(Fo)},[e]);const a=Be.useCallback(()=>{H.dismiss(Lo),si({message:t("opencodeUpdate.toast.reload.message"),mode:"projects",scopes:["all"]})},[t]),i=Be.useCallback(async()=>{if(!r.current){r.current=!0,H.dismiss(Fo),H.message(t("opencodeUpdate.toast.upgrading.title"),{id:Lo,description:t("opencodeUpdate.toast.upgrading.description"),duration:1/0,icon:s.jsx(I,{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:Lo,description:c?.version?t("opencodeUpdate.toast.updated.descriptionWithVersion",{version:c.version}):t("opencodeUpdate.toast.updated.description"),duration:1/0,icon:s.jsx(I,{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:Lo,description:o instanceof Error?o.message:t("opencodeUpdate.toast.failed.description"),duration:1/0})}finally{r.current=!1}}},[a,t]);return Be.useEffect(()=>{const o=u=>{if(!Te.getState().showOpenCodeUpdateNotifications){H.dismiss(Fo);return}u&&(n.current.has(u)||(n.current.add(u),H.info(t("opencodeUpdate.toast.available.title"),{id:Fo,description:t("opencodeUpdate.toast.available.description",{version:u}),duration:1/0,action:{label:t("opencodeUpdate.toast.actions.update"),onClick:i}})))},c=u=>{const h=typeof u.detail?.version=="string"?String(u.detail.version).trim():"";o(h)};let d=!1;const p=[],m=async u=>{try{const h=await fetch("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!h.ok)throw new Error(h.statusText||"OpenCode upgrade status check failed");const b=await h.json().catch(()=>null),f=typeof b?.latestVersion=="string"?b.latestVersion.trim():"";!d&&b?.available===!0&&f&&o(f)}catch{const h=iD[u];!d&&h!==void 0&&p.push(setTimeout(()=>{m(u+1)},h))}};return e&&p.push(setTimeout(()=>{m(0)},aD)),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},vh=Ur(()=>vr(()=>import("./OnboardingScreen-CeZMVgH8.js"),__vite__mapDeps([9,0,1,2,3,4])).then(t=>({default:t.OnboardingScreen}))),oD=()=>{const t=at.c(3),e=Te(pD),n=Te(hD);let r;return t[0]!==e||t[1]!==n?(r=s.jsx(sD,{open:e,onOpenChange:n}),t[0]=e,t[1]=n,t[2]=r):r=t[2],r},lD=t=>{const e=at.c(21),{onRetry:n,isRetrying:r}=t,{t:a}=pt();let i;e[0]!==a?(i=a("startup.initRecovery.title"),e[0]=a,e[1]=i):i=e[1];let 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(we,{type:"button",onClick:n,disabled:r,children:m}),e[14]=r,e[15]=n,e[16]=m,e[17]=u):u=e[17];let h;return e[18]!==p||e[19]!==u?(h=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]=h):h=e[20],h},wh=t=>t?t.replace(/\\/g,"/").replace(/\/+$/g,""):"",cD=()=>{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"}},dD=()=>typeof window>"u"?!1:window.location.pathname===Zf,uD=t=>{const e=at.c(23),{embeddedSessionChat:n,isVSCodeRuntime:r,embeddedBackgroundWorkEnabled:a}=t,i=Vs(fD),o=Vt(gD),c=Vt(xD),d=_d(),p=l.useRef(null);let m;e[0]!==n.directory?(m=wh(n.directory),e[0]=n.directory,e[1]=m):m=e[1];const u=m;let h;e[2]!==i?(h=wh(i),e[2]=i,e[3]=h):h=e[3];const b=h;let f,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?(f=()=>{if(r||u&&b!==u)return;const D=`${u}
225
- ${n.sessionId}`;p.current===D&&o===n.sessionId||(p.current=D,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]=f,e[13]=v):(f=e[12],v=e[13]),l.useEffect(f,v),u&&b!==u)return null;let x;e[14]!==a?(x=s.jsx(sf,{embeddedBackgroundWorkEnabled:a}),e[14]=a,e[15]=x):x=e[15];let g;e[16]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(Eg,{}),e[16]=g):g=e[16];let w;e[17]!==n.readOnly?(w=s.jsx(jd,{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(nf,{}),e[19]=y):y=e[19];let k;return e[20]!==x||e[21]!==w?(k=s.jsxs(s.Fragment,{children:[x,g,w,y]}),e[20]=x,e[21]=w,e[22]=k):k=e[22],k};function mD({apis:t}){const e=gt(F=>F.initializeApp),n=gt(F=>F.isInitialized),r=gt(F=>F.isConnected),a=gt(F=>F.providers.length),i=gt(F=>F.agents.length),o=gt(F=>F.loadProviders),c=gt(F=>F.loadAgents),d=Vt(F=>F.error),p=Vt(F=>F.clearError),m=Vs(F=>F.currentDirectory),u=Vs(F=>F.setDirectory),h=Vs(F=>F.isSwitchingDirectory),[b,f]=l.useState(!1),v=Kn(F=>F.refreshStatus),[x,g]=l.useState(()=>t.runtime.isVSCode),[w,y]=l.useState(!0),[k,D]=l.useState(!1),[j,S]=l.useState(0),[A,E]=l.useState(!1),P=Te(F=>F.wideChatLayoutEnabled),C=Te(F=>F.mobileKeyboardMode),N=l.useMemo(()=>yn(),[]),T=Pd(F=>F.setPlanModeEnabled),[M,R]=l.useState(()=>Nd()),[L,$]=l.useState(()=>{const F=yh();return F!==null?bh({isDesktopShell:!0,bootOutcome:F}):null}),B=l.useRef(!1),O=l.useMemo(()=>cD(),[]),_=!O||w,ee=l.useMemo(()=>dD(),[]);l.useEffect(()=>(Lu(b),()=>{Lu(!1)}),[b]),l.useEffect(()=>{qy(C)},[C]),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(()=>(Ou(t),()=>Ou(null)),[t]),l.useEffect(()=>{O||v(t.github,{force:!0})},[t.github,O,v]),Jy();const z=M==="valid",ne=L?.screen==="main";l.useEffect(()=>{if(!XA({isDesktopShell:N,isInitialized:n,bootOutcomeKnown:z,bootViewIsMain:ne}))return;const F=setTimeout(()=>{const V=document.getElementById("initial-loading");V&&(V.classList.add("fade-out"),setTimeout(()=>{V.remove()},300))},150);return()=>clearTimeout(F)},[N,n,z,ne]),l.useEffect(()=>{if(!N||M!=="malformed")return;const F=document.getElementById("initial-loading");F&&(F.textContent="Desktop startup failed — please restart the app.")},[N,M]),l.useEffect(()=>{if(N)return;const F=setTimeout(()=>{const V=document.getElementById("initial-loading");V&&!n&&(V.classList.add("fade-out"),setTimeout(()=>{V.remove()},300))},5e3);return()=>clearTimeout(F)},[N,n]),l.useEffect(()=>{let F=!1;return(async()=>{const q=await fetch("/health",{method:"GET"}).catch(()=>null);if(!q||!q.ok||F)return;const te=await q.json().catch(()=>null);if(!te||F)return;const U=te.planModeExperimentalEnabled;T(U===!0||U===1||U==="1"||U==="true")})(),()=>{F=!0}},[T]),l.useEffect(()=>{x||e()},[e,x]),l.useEffect(()=>{if(x||n)return;let F=!0,V,q=0;const te=10,U=1e3,ae=async()=>{if(!F)return;if(q>=te){D(!0);return}const je=gt.getState();if(je.isInitialized){D(!1);return}q+=1,await je.initializeApp();const oe=gt.getState();if(!F)return;if(oe.isInitialized){D(!1);return}if(q>=te){D(!0);return}const ve=Math.min(U*Math.pow(2,q-1),16e3);V=setTimeout(ae,ve)};return V=setTimeout(ae,U),()=>{F=!1,V&&clearTimeout(V)}},[j,n,x]),l.useEffect(()=>{n&&D(!1)},[n]),l.useEffect(()=>{if(!k)return;const F=document.getElementById("initial-loading");F&&(F.classList.add("fade-out"),setTimeout(()=>{F.remove()},300))},[k]),l.useEffect(()=>{if(x||!r||a>0&&i>0)return;let F=!0,V=0;const q=15,te=async()=>{const ae=gt.getState();if(!(ae.providers.length>0&&ae.agents.length>0))try{ae.providers.length===0&&await o(),gt.getState().agents.length===0&&await c()}catch{}};te();const U=setInterval(()=>{if(F){if(++V>=q){clearInterval(U);return}te()}},2e3);return()=>{F=!1,clearInterval(U)}},[r,x,c,o,a,i]),l.useEffect(()=>{h||x||r&&rn.setDirectory(m)},[m,h,r,x]),l.useEffect(()=>{if(!O||typeof window>"u")return;const F=te=>{const U=te?.visible===!0;y(U)},V=te=>{if(te.origin!==window.location.origin)return;const U=te.data;U?.type==="openchamber:embedded-visibility"&&F(U.payload)},q=window;return q.__openchamberSetEmbeddedVisibility=F,window.addEventListener("message",V),()=>{window.removeEventListener("message",V),q.__openchamberSetEmbeddedVisibility===F&&delete q.__openchamberSetEmbeddedVisibility}},[O]),l.useEffect(()=>{!O?.directory||x||m!==O.directory&&u(O.directory,{showOverlay:!1})},[m,O,x,u]),l.useEffect(()=>{if(!O||typeof window>"u")return;const F=V=>{V.storageArea===window.localStorage&&V.key==="ui-store"&&Te.persist.rehydrate()};return window.addEventListener("storage",F),()=>{window.removeEventListener("storage",F)}},[O]),l.useEffect(()=>{if(typeof window>"u")return;const F=V=>{const q=V.detail,te=typeof q?.sessionId=="string"?q.sessionId.trim():"";if(!te)return;const U=typeof q?.directory=="string"&&q.directory.trim().length>0?q.directory.trim():null;Te.getState().setActiveMainTab("chat"),Vt.getState().setCurrentSession(te,U)};return window.addEventListener("openchamber:open-session",F),()=>window.removeEventListener("openchamber:open-session",F)},[]),l.useEffect(()=>{if(typeof window>"u")return;const F=V=>{const q=V.detail,te=typeof q?.directory=="string"&&q.directory.trim().length>0?q.directory.trim():null,U=typeof q?.projectId=="string"&&q.projectId.trim().length>0?q.projectId.trim():null;Te.getState().setActiveMainTab("chat"),Te.getState().setSessionSwitcherOpen(!1),Vt.getState().openNewSessionDraft({selectedProjectId:U,directoryOverride:te,preserveDirectoryOverride:!!te})};return window.addEventListener("openchamber:open-draft-session",F),()=>window.removeEventListener("openchamber:open-draft-session",F)},[]),l.useEffect(()=>{if(typeof window>"u")return;const F=V=>{const q=V.detail,te=typeof q?.projectPath=="string"?q.projectPath.trim():"";if(!te)return;const U=Fs.getState(),ae=U.projects.find(je=>je.path===te);ae?U.setActiveProject(ae.id):U.addProject(te)};return window.addEventListener("openchamber:open-project",F),()=>window.removeEventListener("openchamber:open-project",F)},[]),l.useEffect(()=>{typeof window>"u"||!n||h||B.current||(B.current=!0,window.__openchamberAppReady=!0,window.dispatchEvent(new Event("openchamber:app-ready")))},[n,h]),Qy({enabled:_}),JA(),Yy(),qA();const re=l.useCallback(()=>{f(F=>!F)},[]);RA(re),l.useEffect(()=>{if(O)return;const F=V=>{Ad(V)&&V.shiftKey&&!V.altKey&&(V.code==="KeyD"||V.key.toLowerCase()==="d")&&(V.preventDefault(),f(te=>!te))};return window.addEventListener("keydown",F,!0),()=>window.removeEventListener("keydown",F,!0)},[O]),l.useEffect(()=>{O||d&&setTimeout(()=>p(),5e3)},[p,O,d]),l.useEffect(()=>{if(!N||M!=="not-injected")return;let F=!1,V=0;const q=200,te=2e3,U=50,ae=()=>{if(F)return;V++;const je=Nd();if(je!=="not-injected"){if(F=!0,R(je),je==="valid"){const ve=yh();ve&&$(bh({isDesktopShell:!0,bootOutcome:ve}))}return}const oe=Math.min(q*Math.pow(1.1,V),te);if(V>=U){const ve=document.getElementById("initial-loading");ve&&!ve.textContent?.includes("taking longer")&&(ve.textContent="Desktop startup is taking longer than expected...")}window.setTimeout(ae,oe)};return window.setTimeout(ae,q),()=>{F=!0}},[N,M]);const ue=l.useCallback(async()=>{if(ZA({isTauriShell:Ia(),isDesktopLocalOriginActive:Vr()})){await Kh();return}window.location.reload()},[]),Q=l.useCallback(async()=>{if(!A){D(!1),E(!0);try{await gt.getState().initializeApp()}finally{E(!1)}gt.getState().isInitialized||S(F=>F+1)}},[A]),de=F=>{if(F.screen==="recovery")return F.variant};if(N&&L&&L.screen!=="main"){if(L.screen==="chooser")return s.jsx(Xs,{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(vh,{mode:"first-launch",onCliAvailable:ue,onChooseRemote:()=>{}})})})});const F=de(L),V=L.screen==="recovery"&&"url"in L?L.url:void 0;return s.jsx(Xs,{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(vh,{mode:"recovery",recoveryVariant:F,recoveryHostUrl:V,recoveryHostLabel:void 0,onCliAvailable:ue})})})})}if(O)return s.jsx(Xs,{children:s.jsx($u,{sdk:rn.getSdkClient(),directory:m||"",children:s.jsx(Bu,{apis:t,children:s.jsx(_u,{delayDuration:300,skipDelayDuration:150,children:s.jsx("div",{className:"h-full text-foreground bg-background",children:s.jsx(uD,{embeddedSessionChat:O,isVSCodeRuntime:x,embeddedBackgroundWorkEnabled:_})})})})})});if(ee)return s.jsx(Xs,{children:s.jsx(rD,{})});if(k&&!n&&!x&&!O)return s.jsx(Xs,{children:s.jsx(lD,{onRetry:()=>{Q()},isRetrying:A})});const X=!n&&!N;return s.jsx(Xs,{children:s.jsx($u,{sdk:rn.getSdkClient(),directory:m||"",children:s.jsx(Bu,{apis:t,children:s.jsx(gw,{children:s.jsx(Xy,{children:s.jsx(_u,{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(sf,{embeddedBackgroundWorkEnabled:_}),s.jsx(Eg,{}),s.jsx(yA,{}),s.jsx(nf,{}),!X&&s.jsxs(s.Fragment,{children:[s.jsx(eD,{}),s.jsx(oD,{}),b&&s.jsx(jA,{onClose:()=>f(!1)})]})]})})})})})})})}function pD(t){return t.isAboutDialogOpen}function hD(t){return t.setAboutDialogOpen}function fD(t){return t.currentDirectory}function gD(t){return t.currentSessionId}function xD(t){return t.setCurrentSession}const bD=typeof window<"u"&&window.__OPENCHAMBER_RUNTIME_APIS__||(()=>{throw new Error("Runtime APIs not provided for legacy UI entrypoint.")})();Zy();ev().then(()=>{Promise.all([tv(),sv()]).catch(t=>{console.error("[main] settings init failed:",t)}),nv(),rv(),av()}).catch(t=>{console.error("[main] appearance init failed:",t)});const Rg=document.getElementById("root");if(!Rg)throw new Error("Root element not found");wx.createRoot(Rg).render(s.jsx(Be.StrictMode,{children:s.jsx(iv,{children:s.jsx(ov,{children:s.jsx(lv,{children:s.jsx(cv,{children:s.jsx(mD,{apis:bD})})})})})}));const ID=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"}));export{rA as M,Vo as P,Ar as S,EC as a,ID as m,cn as u};