@openchamber/web 1.10.3 → 1.10.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/dist/assets/{JsonTreeView-BhnwxlMV.js → JsonTreeView-DjN_Y61c.js} +1 -1
  2. package/dist/assets/{MarkdownRendererImpl-BL9AWfBg.js → MarkdownRendererImpl-D8Pj3Iy7.js} +3 -3
  3. package/dist/assets/{MultiRunWindow-C2H5hpiq.js → MultiRunWindow-BQtAxwtT.js} +1 -1
  4. package/dist/assets/{OnboardingScreen-B0qAcM9E.js → OnboardingScreen-Bm0_2bRQ.js} +2 -2
  5. package/dist/assets/{SettingsWindow-BPWLJy6K.js → SettingsWindow-DfL6vlAG.js} +1 -1
  6. package/dist/assets/{TerminalView-CSEtmbyD.js → TerminalView-DiV5PHoV.js} +1 -1
  7. package/dist/assets/{ToolOutputDialog-U8mr6h7H.js → ToolOutputDialog-D32OrEUX.js} +6 -6
  8. package/dist/assets/{es-RQYrOImo.js → es-B8ic5apd.js} +1 -1
  9. package/dist/assets/{index-pJeohTL6.css → index-4bBArO_M.css} +1 -1
  10. package/dist/assets/index-DqXJOAVZ.js +1 -0
  11. package/dist/assets/{ko-BqABW41E.js → ko-pXQ0SsBr.js} +1 -1
  12. package/dist/assets/main-BRTUWU3R.js +126 -0
  13. package/dist/assets/{main-DkIlaUcs.js → main-DXB_3esA.js} +2 -2
  14. package/dist/assets/miniChat-CZqOFY1k.js +2 -0
  15. package/dist/assets/{modelPrefsAutoSave-BHV5Gay8.js → modelPrefsAutoSave-DlTpduDU.js} +84 -84
  16. package/dist/assets/{pl-BFhTdei9.js → pl-DP_0oFey.js} +1 -1
  17. package/dist/assets/{pt-BR-Cw30xZ9f.js → pt-BR-BmQJZ1NW.js} +1 -1
  18. package/dist/assets/renderElectronMiniChatApp-DuNBYm_K.js +2 -0
  19. package/dist/assets/{uk-C6rZuAGS.js → uk-CrHgOUe5.js} +1 -1
  20. package/dist/assets/{vendor-.bun-kY4nnc4l.js → vendor-.bun-0geEbyBQ.js} +1 -1
  21. package/dist/assets/{zh-CN-bjbBXFpu.js → zh-CN-DyZ0csLN.js} +1 -1
  22. package/dist/index.html +4 -4
  23. package/dist/mini-chat.html +4 -4
  24. package/package.json +1 -1
  25. package/dist/assets/index-CX9TA5UH.js +0 -1
  26. package/dist/assets/main-Qzl_qZz0.js +0 -126
  27. package/dist/assets/miniChat-DO_5ziuU.js +0 -2
  28. package/dist/assets/renderElectronMiniChatApp-B6udecQK.js +0 -2
@@ -1,126 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-.bun-kY4nnc4l.js","assets/vendor--V65Sl9C2.css","assets/modelPrefsAutoSave-BHV5Gay8.js","assets/index-CX9TA5UH.js","assets/index-pJeohTL6.css","assets/TerminalView-CSEtmbyD.js","assets/JsonTreeView-BhnwxlMV.js","assets/SettingsWindow-BPWLJy6K.js","assets/MultiRunWindow-C2H5hpiq.js","assets/OnboardingScreen-B0qAcM9E.js"])))=>i.map(i=>d[i]);
2
- import{c as nt,R as l,u as Ol,a as yo,j as s,b as hu,C as gu,P as Ll,d as Ds,S as Id,e as cb,D as $l,f as Bl,g as Vl,i as wr,k as Xi,G as Ph,I as db,r as Oe,l as ub,m as mb,p as $o,n as lc,o as Nn,q as pb,s as fb,t as hb,v as Cs,B as br,w as Ys,x as Wr,T as gb,y as xu,K as Za,z as Dh,Y as xb,N as bb,M as yb,A as cc,E as ei,W as Ks,F as Hn,O as Vi,H as Ao,J as Sa,L as Gr,Q as Bo,U as zl,V as Zt,X as Kr,Z as ti,$ as _s,a0 as wa,a1 as Fn,a2 as dc,a3 as Th,a4 as Ad,a5 as Di,_ as Tr,a6 as si,a7 as zi,a8 as vb,a9 as Mh,aa as Ti,ab as bu,ac as wb,ad as vo,ae as Mi,af as po,ag as yu,ah as wl,ai as sn,aj as jb,ak as ui,al as _l,am as Nb,an as Pd,ao as Sb,ap as Yr,aq as qr,ar as Rh,as as vu,at as wu,au as ju,av as Eh,aw as Nu,ax as kb,ay as Cb,az as Ib,aA as Ab,aB as Pb,aC as Su,aD as ku,aE as Db,aF as Tb,aG as uc,aH as Ga,aI as Cu,aJ as Ir,aK as Mb,aL as qa,aM as Rb,aN as Wa,aO as Us,aP as Hr,aQ as Eb,aR as jr,aS as mc,aT as Ca,aU as Iu,aV as Qr,aW as Fh,aX as Fb,aY as Ob,aZ as Lb,a_ as $b,a$ as Bb,b0 as Vb,b1 as zb,b2 as _b,b3 as Oh,b4 as Ub,b5 as or,b6 as Wb,b7 as Zi,b8 as rm,b9 as Kb,ba as Hb,bb as Mc,bc as Gb,bd as qb,be as Qb,bf as am,bg as im,bh as Jb,bi as Lh,bj as $h,bk as Yb,bl as om,bm as Xb,bn as Zb,bo as ey,bp as ty,bq as sy,br as Au,bs as Pu,bt as ny,bu as ry,bv as Bh,bw as ay,bx as Dd,by as Vh,bz as zh,bA as Ii,bB as fo,bC as Td,bD as rt,bE as _h,bF as Uh,bG as iy,bH as oy,bI as ly,bJ as cy,bK as dy,bL as uy,bM as my,bN as py,bO as fy,bP as hy,bQ as Wh,bR as ni,bS as Kh,bT as Md,bU as Hh,bV as gy,bW as xy,bX as by,bY as yy,bZ as vy,b_ as zn,b$ as Mn,c0 as wy,c1 as jy,c2 as Du,c3 as ia,c4 as Ul,c5 as Gh,c6 as Ny,c7 as Tu,c8 as Rd,c9 as qh,ca as Qh,cb as Sy,cc as ky,cd as Rc,ce as lm,cf as Jh,cg as Cy,ch as Iy,ci as Ay,cj as Py,ck as jl,cl as Yh,cm as Xh,cn as Ed,co as Dy,cp as Ty,cq as My,cr as Zh,cs as Ry,ct as Ey,cu as Fy,cv as Oy,cw as Ly,cx as $y,cy as By,cz as eg,cA as tg,cB as Vy,cC as zy,cD as _y,cE as Fd,cF as Uy,cG as Wy,cH as Ai,cI as Ky,cJ as sg,cK as Hy,cL as Gy,cM as qy,cN as Qy,cO as Jy,cP as cm,cQ as Od,cR as Yy,cS as Xy,cT as Zy,cU as ev,cV as tv,cW as sv,cX as dm,cY as nv,cZ as rv,c_ as um,c$ as av,d0 as iv,d1 as ov,d2 as mm,d3 as Ri,d4 as Ei,d5 as pm,d6 as lv,d7 as cv,d8 as fm,d9 as hm,da as Ec,db as dv,dc as uv,dd as mv}from"./vendor-.bun-kY4nnc4l.js";import{a as pv,b as fv,f as hv}from"./index-CX9TA5UH.js";import{u as ut,a as Te,b as un,c as pe,d as Rs,i as yn,g as xr,T as Ct,M as Ar,e as St,f as kt,h as ba,s as Fc,r as Oc,j as Lc,k as Fs,o as Dn,l as Ws,m as ri,n as oa,p as gm,D as $t,q as gv,t as Wl,v as _n,w as q,x as Bs,y as En,z as Vs,A as zs,B as ng,C as xm,E as xv,F as bv,G as bm,H as yv,I as vv,J as wv,K as jv,L as Gn,N as kn,O as lr,P as Ld,Q as Bn,R as wo,S as Nv,U as yt,V as Wt,W as Sv,X as rg,Y as jo,Z as ag,_ as Zn,$ as Mu,a0 as pc,a1 as kv,a2 as ym,a3 as Cv,a4 as Iv,a5 as ig,a6 as Av,a7 as Pv,a8 as og,a9 as Ru,aa as Kl,ab as lg,ac as fc,ad as ra,ae as Eu,af as Nl,ag as rn,ah as cg,ai as dg,aj as Vt,ak as Es,al as _i,am as Dv,an as ug,ao as Is,ap as Ss,aq as je,ar as vs,as as ws,at as Ui,au as Tv,av as Mv,aw as el,ax as Vn,ay as mg,az as pg,aA as hc,aB as Rv,aC as Ev,aD as vm,aE as Sn,aF as bs,aG as Fv,aH as Ov,aI as Lv,aJ as $v,aK as Bv,aL as Vv,aM as zv,aN as Hs,aO as _v,aP as Uv,aQ as Os,aR as Wv,aS as Kv,aT as Hv,aU as Gv,aV as Pr,aW as Vo,aX as qv,aY as Qs,aZ as ps,a_ as fs,a$ as ys,b0 as hs,b1 as Ot,b2 as Qv,b3 as ai,b4 as Jv,b5 as Xr,b6 as fg,b7 as gc,b8 as Yv,b9 as Fu,ba as Xv,bb as Zv,bc as hg,bd as e1,be as pn,bf as zo,bg as Dr,bh as t1,bi as s1,bj as $c,bk as xc,bl as Ou,bm as Lu,bn as bc,bo as Xn,bp as $u,bq as ii,br as yc,bs as ho,bt as Wi,bu as Ki,bv as wm,bw as Hl,bx as Gl,by as Po,bz as Hi,bA as gg,bB as n1,bC as Rr,bD as r1,bE as jm,bF as ql,bG as _o,bH as xg,bI as a1,bJ as i1,bK as Uo,bL as o1,bM as Pi,bN as Do,bO as bg,bP as Gi,bQ as yg,bR as l1,bS as c1,bT as Bu,bU as ya,bV as Fi,bW as Qa,bX as vc,bY as Wo,bZ as Ko,b_ as $d,b$ as vg,c0 as Vu,c1 as wg,c2 as To,c3 as d1,c4 as u1,c5 as m1,c6 as p1,c7 as f1,c8 as No,c9 as Bc,ca as Nm,cb as h1,cc as g1,cd as x1,ce as b1,cf as Si,cg as Vc,ch as y1,ci as Sm,cj as ja,ck as v1,cl as km,cm as Cm,cn as Im,co as Am,cp as Sl,cq as Pm,cr as w1,cs as zc,ct as j1,cu as N1,cv as S1,cw as k1,cx as C1,cy as I1,cz as A1,cA as _c,cB as Dm,cC as P1,cD as D1,cE as T1,cF as M1,cG as R1,cH as Uc,cI as E1,cJ as F1,cK as O1,cL as jg,cM as L1,cN as ki,cO as $1,cP as Tm,cQ as B1,cR as Ng,cS as tl,cT as kl,cU as V1,cV as Sg,cW as z1,cX as _1,cY as Mm,cZ as Rm,c_ as kg,c$ as Cg,d0 as Wc,d1 as sl,d2 as U1,d3 as W1,d4 as K1,d5 as H1,d6 as Ig,d7 as Ag,d8 as Bd,d9 as zu,da as G1,db as ks,dc as Mo,dd as qi,de as Oi,df as Em,dg as rr,dh as q1,di as So,dj as Q1,dk as Pg,dl as J1,dm as Y1,dn as X1,dp as Dg,dq as Tg,dr as Z1,ds as ew,dt as tw,du as sw,dv as Fm,dw as nw,dx as rw,dy as aw,dz as iw,dA as ow,dB as Mg,dC as lw,dD as cw,dE as dw,dF as uw,dG as mw,dH as pw,dI as fw,dJ as hw,dK as gw,dL as xw,dM as bw,dN as yw,dO as vw,dP as ww,dQ as Vd,dR as Om,dS as jw,dT as Rg,dU as Nw,dV as Sw,dW as kw,dX as Cw,dY as ca,dZ as Iw,d_ as Lm,d$ as Aw,e0 as Cl,e1 as Il,e2 as Pw,e3 as Dw,e4 as Tw,e5 as Mw,e6 as Eg,e7 as $m,e8 as Rw,e9 as Bm,ea as Ew,eb as Vm,ec as Fw,ed as Ow,ee as Lw,ef as zm,eg as _m,eh as Um,ei as Wm,ej as Km,ek as $w,el as Bw,em as Vw,en as zw,eo as _w,ep as Uw,eq as Ww,er as Kw,es as Hw,et as Gw,eu as qw,ev as Qw}from"./modelPrefsAutoSave-BHV5Gay8.js";import{J as Jw}from"./JsonTreeView-BhnwxlMV.js";const Yw=({transform:t})=>({...t,y:0}),Xw=t=>{const e=nt.c(18),{id:n,children:r,className:a}=t;let i;e[0]!==n?(i={id:n},e[0]=n,e[1]=i):i=e[1];const{attributes:o,listeners:c,setNodeRef:d,transform:p,transition:m,isDragging:u}=hu(i);let h;e[2]!==p?(h=gu.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 y;e[7]!==a||e[8]!==f?(y=pe("h-full rounded-md",a,f),e[7]=a,e[8]=f,e[9]=y):y=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]!==y?(x=s.jsx("div",{ref:d,"data-sortable-tab-id":n,style:b,className:y,...o,...c,children:r}),e[10]=o,e[11]=r,e[12]=n,e[13]=c,e[14]=d,e[15]=b,e[16]=y,e[17]=x):x=e[17],x},Zw=t=>{const e=nt.c(6),{id:n,children:r,className:a}=t;let i;e[0]!==a?(i=pe("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},Br=t=>{const e=nt.c(121),{items:n,activeId:r,onSelect:a,onClose:i,onReorder:o,layoutMode:c,variant:d,activePillInsetClassName:p,activePillButtonClassName:m,inactiveTabsIconOnly:u,iconOnlyActiveTab:h,animateActivePill:b,activePillLowercase:f,className:y}=t,x=c===void 0?"scrollable":c,g=d===void 0?"default":d,w=u===void 0?!1:u,v=h===void 0?!1:h,S=f===void 0?!0:f,{t:A}=ut(),j=Te(ej),{isTablet:C}=un(),I=j||C,R=l.useRef(null);let k;e[0]===Symbol.for("react.memo_cache_sentinel")?(k={left:!1,right:!1},e[0]=k):k=e[0];const[P,N]=l.useState(k);let D;e[1]!==n?(D=n.map(tj),e[1]=n,e[2]=D):D=e[2];const T=D,M=x==="scrollable",$=g==="default",F=g==="active-pill",V=g==="animated",O=F||V,L=$,W=O||L,B=F&&M,ne=O,le=b??V,ee=typeof o=="function",ae=ee?Xw:Zw;let ge;e[3]===Symbol.for("react.memo_cache_sentinel")?(ge=new Map,e[3]=ge):ge=e[3];const te=l.useRef(ge),[E,z]=l.useState(null);let J;e[4]===Symbol.for("react.memo_cache_sentinel")?(J={activationConstraint:{distance:8}},e[4]=J):J=e[4];const H=Ol(yo(Ll,J)),re=sj;let ce;e[5]===Symbol.for("react.memo_cache_sentinel")?(ce=(lt,ye)=>{if(ye){te.current.set(lt,ye);return}te.current.delete(lt)},e[5]=ce):ce=e[5];const Ne=ce;let me;e[6]!==r||e[7]!==W?(me=()=>{if(!W||!r){z(nj);return}const lt=R.current,ye=te.current.get(r);if(!lt||!ye){z(rj);return}let Ge=0,$e=0,Ve=ye;for(;Ve&&Ve!==lt;)Ge=Ge+Ve.offsetLeft,$e=$e+Ve.offsetTop,Ve=Ve.offsetParent;const tt={left:Ge,top:$e,width:ye.offsetWidth,height:ye.offsetHeight};z(Qe=>re(Qe,tt)?Qe:tt)},e[6]=r,e[7]=W,e[8]=me):me=e[8];const we=me;let _;e[9]!==M?(_=()=>{if(!M){N({left:!1,right:!1});return}const lt=R.current;if(!lt){N({left:!1,right:!1});return}N({left:lt.scrollLeft>2,right:lt.scrollLeft+lt.clientWidth<lt.scrollWidth-2})},e[9]=M,e[10]=_):_=e[10];const ue=_;let Q;e[11]!==M||e[12]!==ue?(Q=()=>{if(!M){N({left:!1,right:!1});return}const lt=R.current;if(!lt)return;ue(),lt.addEventListener("scroll",ue,{passive:!0});const ye=new ResizeObserver(ue);return ye.observe(lt),()=>{lt.removeEventListener("scroll",ue),ye.disconnect()}},e[11]=M,e[12]=ue,e[13]=Q):Q=e[13];let oe;e[14]!==M||e[15]!==n.length||e[16]!==ue?(oe=[M,n.length,ue],e[14]=M,e[15]=n.length,e[16]=ue,e[17]=oe):oe=e[17],l.useEffect(Q,oe);let Z;e[18]!==r||e[19]!==we||e[20]!==W?(Z=()=>{if(!W){z(null);return}we();const lt=R.current;if(!lt)return;const ye=new ResizeObserver(we);if(ye.observe(lt),r){const Ge=te.current.get(r);Ge&&ye.observe(Ge)}return()=>{ye.disconnect()}},e[18]=r,e[19]=we,e[20]=W,e[21]=Z):Z=e[21];let Ie;e[22]!==r||e[23]!==n.length||e[24]!==we||e[25]!==W?(Ie=[r,n.length,we,W],e[22]=r,e[23]=n.length,e[24]=we,e[25]=W,e[26]=Ie):Ie=e[26],l.useEffect(Z,Ie);let Se;e[27]!==we?(Se=()=>{we()},e[27]=we,e[28]=Se):Se=e[28],l.useLayoutEffect(Se);let Y;e[29]!==r||e[30]!==M||e[31]!==ue?(Y=()=>{if(!M||!r)return;const lt=R.current;if(!lt)return;const ye=window.requestAnimationFrame(()=>{const Ge=typeof window.CSS?.escape=="function"?window.CSS.escape(r):r.replace(/"/g,'\\"'),$e=lt.querySelector(`[data-sortable-tab-id="${Ge}"]`);$e&&($e.scrollIntoView({block:"nearest",inline:"nearest"}),ue())});return()=>{window.cancelAnimationFrame(ye)}},e[29]=r,e[30]=M,e[31]=ue,e[32]=Y):Y=e[32];let fe;e[33]!==r||e[34]!==M||e[35]!==n.length||e[36]!==ue?(fe=[r,M,n.length,ue],e[33]=r,e[34]=M,e[35]=n.length,e[36]=ue,e[37]=fe):fe=e[37],l.useEffect(Y,fe);let ke;e[38]!==o?(ke=lt=>{if(!o)return;const{active:ye,over:Ge}=lt;!Ge||ye.id===Ge.id||o(String(ye.id),String(Ge.id))},e[38]=o,e[39]=ke):ke=e[39];const xe=ke;let he;e[40]!==y?(he=pe("relative flex h-full min-w-0 flex-1",y),e[40]=y,e[41]=he):he=e[41];let Pe;e[42]!==M||e[43]!==P||e[44]!==O?(Pe=M&&P.left?s.jsx("div",{className:pe("pointer-events-none absolute inset-y-0 left-0 z-20 bg-gradient-to-r to-transparent",O?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,e[42]=M,e[43]=P,e[44]=O,e[45]=Pe):Pe=e[45];let Be;e[46]!==M||e[47]!==P||e[48]!==O?(Be=M&&P.right?s.jsx("div",{className:pe("pointer-events-none absolute inset-y-0 right-0 z-20 bg-gradient-to-l to-transparent",O?"w-8 from-[var(--surface-background)]":"w-6 from-background")}):null,e[46]=M,e[47]=P,e[48]=O,e[49]=Be):Be=e[49];const G=O?"items-center overflow-x-hidden overflow-y-hidden":"items-stretch",be=O&&"@container/pill-tabs",De=O&&"pill-tabs__track",Ae=O&&(p??"gap-0.5 py-0.5"),ve=L&&"items-center overflow-y-hidden",U=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",de=M?"overflow-x-auto scrollbar-none":"overflow-x-hidden";let Re;e[50]!==G||e[51]!==be||e[52]!==De||e[53]!==Ae||e[54]!==ve||e[55]!==U||e[56]!==de?(Re=pe("relative flex h-full min-w-0 flex-1",G,be,De,Ae,ve,U,de),e[50]=G,e[51]=be,e[52]=De,e[53]=Ae,e[54]=ve,e[55]=U,e[56]=de,e[57]=Re):Re=e[57];let Le;e[58]!==M?(Le=M?{scrollbarWidth:"none",msOverflowStyle:"none"}:void 0,e[58]=M,e[59]=Le):Le=e[59];let se;e[60]!==A?(se=A("sortableTabsStrip.aria.tabs"),e[60]=A,e[61]=se):se=e[61];let ie;e[62]!==E||e[63]!==le||e[64]!==O?(ie=O&&E?s.jsx("div",{className:pe("pointer-events-none absolute left-0 top-0 z-0 rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] bg-[var(--surface-elevated)]","border border-border/60"),style:{transform:`translate3d(${E.left}px, ${E.top}px, 0)`,width:`${E.width}px`,height:`${E.height}px`,transition:le?"transform 300ms cubic-bezier(0.65, 0, 0.35, 1), width 300ms cubic-bezier(0.65, 0, 0.35, 1), height 300ms cubic-bezier(0.65, 0, 0.35, 1)":void 0}}):null,e[62]=E,e[63]=le,e[64]=O,e[65]=ie):ie=e[65];let K;e[66]!==E||e[67]!==L?(K=L&&E?s.jsx("div",{className:"pointer-events-none absolute left-0 -bottom-px z-10 h-[3px] rounded-t-[2px] bg-[var(--primary-base)]",style:{transform:`translate3d(${E.left}px, 0, 0)`,width:`${E.width}px`},"aria-hidden":!0}):null,e[66]=E,e[67]=L,e[68]=K):K=e[68];let _e;if(e[69]!==ae||e[70]!==r||e[71]!==m||e[72]!==S||e[73]!==I||e[74]!==v||e[75]!==w||e[76]!==F||e[77]!==j||e[78]!==M||e[79]!==n||e[80]!==i||e[81]!==a||e[82]!==B||e[83]!==O){let lt;e[85]!==ae||e[86]!==r||e[87]!==m||e[88]!==S||e[89]!==I||e[90]!==v||e[91]!==w||e[92]!==F||e[93]!==j||e[94]!==M||e[95]!==i||e[96]!==a||e[97]!==B||e[98]!==O?(lt=ye=>{const Ge=ye.id===r,$e=w&&O&&!Ge&&!!ye.icon,Ve=!$e,tt=!!ye.icon&&(!v||Ge),Qe=w&&O&&Ge&&!M&&!B,ze=ye.closable!==!1&&!!i,ht=ze&&!!ye.icon,_t=M||B?void 0:O?Qe?"flex-none basis-auto":j?"flex-1 basis-0 min-w-0":"flex-1 basis-0 min-w-fit":"min-w-0 flex-1 basis-0";return s.jsx(ae,{id:ye.id,className:_t,children:s.jsxs("div",{ref:Kt=>Ne(ye.id,Kt),className:pe("group flex h-full min-w-0 flex-nowrap items-center",M||B?"shrink-0":O?"w-full":"w-full min-w-0",O?"relative z-10 bg-transparent":Ge?"relative z-10 bg-transparent text-foreground":"relative z-10 bg-transparent text-muted-foreground hover:text-foreground"),children:[s.jsx("button",{type:"button",role:"tab","aria-selected":Ge,"aria-label":$e?ye.title??ye.label:void 0,onClick:()=>a(ye.id),className:pe(O?"animated-tabs__button pill-tabs__button relative z-10 flex flex-1 min-w-0 flex-nowrap items-center justify-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] text-sm font-medium transition-colors duration-150 !min-h-0":"flex h-full min-w-0 flex-nowrap items-center typography-micro",O&&S?"lowercase":null,O&&($e?"gap-0":"gap-1.5"),O?B?"shrink-0 whitespace-nowrap px-3 text-center":M?"max-w-56 shrink-0 px-3 text-center":$e?"px-2 !min-w-0 text-center":Qe?"shrink-0 whitespace-nowrap px-3 text-center":"px-3 text-center":M?"max-w-56 justify-start truncate px-3 text-left":"w-full justify-center truncate px-3 text-center",O?m??(F?j?"h-[38px]":"h-[31px]":"h-7"):null,O?Ge?"text-foreground":"text-muted-foreground hover:text-foreground":null,O?"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] focus-visible:ring-offset-1 focus-visible:ring-offset-background":null),title:ye.title??ye.label,children:O?s.jsxs(s.Fragment,{children:[tt?s.jsxs("span",{className:"relative flex h-4 w-4 shrink-0 items-center justify-center",children:[s.jsx("span",{className:pe("flex items-center justify-center transition-opacity",ht&&(I?"opacity-0":"group-hover:opacity-0")),children:ye.icon}),ht?s.jsx("span",{role:"button",tabIndex:-1,className:pe("absolute inset-0 z-20 flex !min-h-0 !min-w-0 items-center justify-center rounded-sm text-muted-foreground transition-opacity hover:text-foreground",I?"opacity-100":"opacity-0 group-hover:opacity-100"),onPointerDown:aj,onClick:Kt=>{Kt.stopPropagation(),i?.(ye.id)},"aria-label":ye.closeLabel??`Close ${ye.label} tab`,title:ye.closeLabel??`Close ${ye.label} tab`,children:s.jsx(Ds,{className:"h-3.5 w-3.5"})}):null]}):null,Ve?s.jsx("span",{className:"animated-tabs__label truncate",children:ye.label}):null]}):s.jsxs("span",{className:pe("flex min-w-0 flex-nowrap items-center gap-1.5",!M&&"justify-center"),children:[tt?s.jsxs("span",{className:pe("relative flex h-4 w-4 shrink-0 items-center justify-center transition-colors duration-200 ease-out",Ge?"text-[var(--primary-base)]":"text-muted-foreground"),children:[s.jsx("span",{className:pe("flex items-center justify-center transition-opacity",ht&&(I?"opacity-0":"group-hover:opacity-0")),children:ye.icon}),ht?s.jsx("span",{role:"button",tabIndex:-1,className:pe("absolute inset-0 z-20 flex !min-h-0 !min-w-0 items-center justify-center rounded-sm text-muted-foreground transition-opacity hover:text-foreground",I?"opacity-100":"opacity-0 group-hover:opacity-100"),onPointerDown:ij,onClick:Kt=>{Kt.stopPropagation(),i?.(ye.id)},"aria-label":ye.closeLabel??`Close ${ye.label} tab`,title:ye.closeLabel??`Close ${ye.label} tab`,children:s.jsx(Ds,{className:"h-3.5 w-3.5"})}):null]}):null,s.jsx("span",{className:"truncate leading-[1.2]",children:ye.label})]})}),ze&&!ht?s.jsx("button",{type:"button",onPointerDown:oj,onClick:Kt=>{Kt.stopPropagation(),i?.(ye.id)},className:pe("relative z-20 inline-flex !min-h-0 !min-w-0 items-center justify-center transition-opacity",O?"-ml-2.5 mr-1 h-[88%] w-5 self-center !aspect-auto rounded-md":"aspect-square h-[65%] min-h-4 max-h-5 rounded-sm mr-1",O?Ge?"text-muted-foreground hover:bg-transparent hover:text-foreground":"text-muted-foreground opacity-0 hover:bg-transparent hover:text-foreground group-hover:opacity-100":Ge?"text-muted-foreground hover:bg-interactive-hover/60 hover:text-foreground":"text-muted-foreground opacity-0 hover:bg-interactive-hover/80 hover:text-foreground group-hover:opacity-100"),"aria-label":ye.closeLabel??`Close ${ye.label} tab`,title:ye.closeLabel??`Close ${ye.label} tab`,children:s.jsx(Ds,{className:"h-3 w-3"})}):null]})},ye.id)},e[85]=ae,e[86]=r,e[87]=m,e[88]=S,e[89]=I,e[90]=v,e[91]=w,e[92]=F,e[93]=j,e[94]=M,e[95]=i,e[96]=a,e[97]=B,e[98]=O,e[99]=lt):lt=e[99],_e=n.map(lt),e[69]=ae,e[70]=r,e[71]=m,e[72]=S,e[73]=I,e[74]=v,e[75]=w,e[76]=F,e[77]=j,e[78]=M,e[79]=n,e[80]=i,e[81]=a,e[82]=B,e[83]=O,e[84]=_e}else _e=e[84];let He;e[100]!==Re||e[101]!==Le||e[102]!==se||e[103]!==ie||e[104]!==K||e[105]!==_e?(He=s.jsxs("div",{ref:R,className:Re,style:Le,role:"tablist","aria-label":se,children:[ie,K,_e]}),e[100]=Re,e[101]=Le,e[102]=se,e[103]=ie,e[104]=K,e[105]=_e,e[106]=He):He=e[106];let Ke;e[107]!==he||e[108]!==Pe||e[109]!==Be||e[110]!==He?(Ke=s.jsxs("div",{className:he,children:[Pe,Be,He]}),e[107]=he,e[108]=Pe,e[109]=Be,e[110]=He,e[111]=Ke):Ke=e[111];const Ze=Ke;if(!ee)return Ze;let Xe;e[112]===Symbol.for("react.memo_cache_sentinel")?(Xe=[Yw],e[112]=Xe):Xe=e[112];let mt;e[113]!==T||e[114]!==Ze?(mt=s.jsx(Id,{items:T,strategy:cb,children:Ze}),e[113]=T,e[114]=Ze,e[115]=mt):mt=e[115];let et;e[116]===Symbol.for("react.memo_cache_sentinel")?(et=s.jsx($l,{dropAnimation:null}),e[116]=et):et=e[116];let ct;return e[117]!==xe||e[118]!==H||e[119]!==mt?(ct=s.jsxs(Bl,{sensors:H,collisionDetection:Vl,onDragEnd:xe,modifiers:Xe,children:[mt,et]}),e[117]=xe,e[118]=H,e[119]=mt,e[120]=ct):ct=e[120],ct};function ej(t){return t.isMobile}function tj(t){return t.id}function sj(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 nj(t){return t===null?t:null}function rj(t){return t===null?t:null}function aj(t){t.stopPropagation()}function ij(t){t.stopPropagation()}function oj(t){t.stopPropagation()}function Hm(t){const e=nt.c(14);let n,r,a,i;e[0]!==t?({size:a,className:n,style:i,...r}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=a,e[4]=i):(n=e[1],r=e[2],a=e[3],i=e[4]);const o=typeof a=="number"?`${a}px`:a,c=typeof a=="number"?`${a}px`:a;let d;e[5]!==i||e[6]!==o||e[7]!==c?(d={width:o,height:c,...i},e[5]=i,e[6]=o,e[7]=c,e[8]=d):d=e[8];let p;e[9]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsx("path",{d:"M112,148a12,12,0,0,0-12,12v19L69.17,148.2A4,4,0,0,1,68,145.37V97.94a36,36,0,1,0-24,0v47.43a27.81,27.81,0,0,0,8.2,19.8L83,196H64a12,12,0,0,0,0,24h48a12,12,0,0,0,12-12V160A12,12,0,0,0,112,148ZM56,52A12,12,0,1,1,44,64,12,12,0,0,1,56,52ZM212,158.06V110.63a27.81,27.81,0,0,0-8.2-19.8L173,60h19a12,12,0,0,0,0-24H144a12,12,0,0,0-12,12V96a12,12,0,0,0,24,0V77l30.83,30.83a4,4,0,0,1,1.17,2.83v47.43a36,36,0,1,0,24,0ZM200,204a12,12,0,1,1,12-12A12,12,0,0,1,200,204Z"}),e[9]=p):p=e[9];let m;return e[10]!==n||e[11]!==r||e[12]!==d?(m=s.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 256 256",fill:"currentColor",className:n,style:d,...r,children:p}),e[10]=n,e[11]=r,e[12]=d,e[13]=m):m=e[13],m}const Jr=[{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"}];Jr.reduce((t,e)=>(t[e.id]=e,t),{});const lj=t=>typeof t!="number"||Number.isNaN(t)?null:Math.max(0,Math.min(100,Math.round(t))),cj=t=>typeof t!="number"||Number.isNaN(t)?"-":`${Math.round(t)}%`,Ro=(t,e)=>t??cj(e),Fg=t=>t===null?"safe":t>=80?"critical":t>=50?"warn":"safe",_u=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,dj=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},Eo=(t,e,n,r)=>{let a=n;if(a===null&&r&&(a=dj(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,y=b?"d":"h",x=a/f,g=Math.max(c/f,x*.01),w=t/g,v=Number.isFinite(w)?`${Math.min(999.9,Math.max(0,w)).toFixed(1)}%/${y}`:"-",S=u>100?`+${Math.round(u)}%`:`${Math.round(u)}%`;let A=null;const j=a/86400;return j>=7&&(A=100/j),{elapsedRatio:d,usageRatio:p,predictedFinalPercent:u,remainingSeconds:o,isExhausted:m,elapsedSeconds:c,totalSeconds:a,status:h,paceRateText:v,predictText:S,dailyAllocationPercent:A}},uj=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)"}},Gm=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`},aa=t=>Math.min(100,Math.max(0,t*100));function Ql(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 mj=[{id:"gemini-auth",label:"Gemini",matcher:t=>t.startsWith("gemini/"),order:1},{id:"antigravity-auth",label:"Antigravity",matcher:t=>t.startsWith("antigravity/"),order:2}],Og={google:mj};function Lg(t,e){const n=Og[e]??[];for(const r of n)if(r.matcher(t))return r;return null}function $g(t){return Og[t]??[]}function Bg(t){return[...t].sort((e,n)=>e.order-n.order)}function pj(t,e){const n=new Map;for(const r of Object.keys(t)){const i=Lg(r,e)?.id??null;n.has(i)||n.set(i,[]),n.get(i).push(r)}return n}function fj(t,e,n){const r=new Map;for(const a of t){const i=e(a),c=Lg(i,n)?.id??null;r.has(c)||r.set(c,[]),r.get(c).push(a)}return r}function hj(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 Uu=6e4,qm=t=>{const e=Jr.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))):Uu,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}},gj=async()=>{const t=xr()?.settings;if(t)try{const n=(await t.load())?.settings;return qm(n??null)}catch{}if(!yn()){const e=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(e.ok){const n=await e.json().catch(()=>null);return qm(n)}}return{autoRefresh:!1,refreshIntervalMs:Uu,displayMode:"usage",dropdownProviderIds:Jr.map(e=>e.id),selectedModels:{},expandedFamilies:{}}},$s=wr()(Xi((t,e)=>({results:[],selectedProviderId:null,isLoading:!1,isFetchingProvider:{},lastUpdated:null,error:null,autoRefresh:!1,refreshIntervalMs:Uu,displayMode:"usage",dropdownProviderIds:Jr.map(n=>n.id),selectedModels:{},expandedFamilies:{},loadSettings:async()=>{try{const n=await gj();t(n)}catch(n){console.warn("Failed to load usage settings:",n)}},fetchAllQuotas:async()=>{t({isLoading:!0,error:null});const n=Jr.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}})),Rs({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}}}),Rs({usageExpandedFamilies:e().expandedFamilies})},applyDefaultSelections:(n,r)=>{if((e().selectedModels[n]?.length??0)>0)return;const i=hj(n,r);i.length!==0&&(t(o=>({selectedModels:{...o.selectedModels,[n]:i}})),Rs({usageSelectedModels:e().selectedModels}))}}),{name:"quota-store"})),Vg=()=>{const t=nt.c(5),e=$s(xj),n=$s(bj),r=$s(yj);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 xj(t){return t.autoRefresh}function bj(t){return t.refreshIntervalMs}function yj(t){return t.fetchAllQuotas}const vj=t=>{const e=nt.c(110),{totalTokens:n,percentage:r,colorPercentage:a,contextLimit:i,outputLimit:o,size:c,isMobile:d,hideIcon:p,showPercentIcon:m,className:u,valueClassName:h,percentIconClassName:b,onClick:f,pressed:y}=t,x=c===void 0?"default":c,g=d===void 0?!1:d,w=p===void 0?!1:p,v=m===void 0?!1:m,S=y===void 0?!1:y,{t:A}=ut(),[j,C]=l.useState(!1),I=typeof a=="number"?a:r,R=wj,k=jj,P=typeof o=="number"?Math.max(o,0):0;let N;e[0]!==A||e[1]!==n?(N=A("contextUsage.tooltip.usedTokens",{tokens:R(n)}),e[0]=A,e[1]=n,e[2]=N):N=e[2];let D;e[3]!==i||e[4]!==A?(D=A("contextUsage.tooltip.contextLimit",{tokens:R(i)}),e[3]=i,e[4]=A,e[5]=D):D=e[5];let T;e[6]!==P||e[7]!==A?(T=A("contextUsage.tooltip.outputLimit",{tokens:R(P)}),e[6]=P,e[7]=A,e[8]=T):T=e[8];let M;e[9]!==N||e[10]!==D||e[11]!==T?(M=[N,D,T],e[9]=N,e[10]=D,e[11]=T,e[12]=M):M=e[12];const $=M,F=!g&&typeof f=="function";let V;e[13]!==w||e[14]!==g?(V=!g&&!w&&s.jsx(db,{className:"h-4 w-4 flex-shrink-0"}),e[13]=w,e[14]=g,e[15]=V):V=e[15];let O;e[16]!==h?(O=pe("font-medium inline-flex items-center gap-1.5",h),e[16]=h,e[17]=O):O=e[17];let L;e[18]!==I||e[19]!==b||e[20]!==r||e[21]!==v?(L=v?s.jsxs(s.Fragment,{children:[s.jsx(Ph,{className:pe("h-3.5 w-3.5",b,k(I)),"aria-hidden":"true"}),s.jsxs("span",{className:"text-foreground",children:[Math.min(r,999).toFixed(1),"%"]})]}):s.jsxs(s.Fragment,{children:[s.jsx("span",{className:k(I),children:Math.min(r,999).toFixed(1)}),"%"]}),e[18]=I,e[19]=b,e[20]=r,e[21]=v,e[22]=L):L=e[22];let W;e[23]!==O||e[24]!==L?(W=s.jsx("span",{className:O,children:L}),e[23]=O,e[24]=L,e[25]=W):W=e[25];let B;e[26]!==V||e[27]!==W?(B=s.jsxs(s.Fragment,{children:[V,W]}),e[26]=V,e[27]=W,e[28]=B):B=e[28];const ne=B,le=x==="compact"?"typography-micro":"typography-meta";let ee;e[29]!==u||e[30]!==F||e[31]!==le?(ee=pe("app-region-no-drag flex items-center gap-1.5 select-none",le,F?pe("rounded-md px-2 py-1.5 text-foreground transition-colors","hover:bg-interactive-hover","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"):"text-muted-foreground/60",u),e[29]=u,e[30]=F,e[31]=le,e[32]=ee):ee=e[32];const ae=ee;let ge;e[33]!==ne||e[34]!==F||e[35]!==g||e[36]!==f||e[37]!==S||e[38]!==ae||e[39]!==A?(ge=F?s.jsx("button",{type:"button",className:ae,"aria-label":A("contextUsage.aria.label"),"aria-pressed":S,onClick:f,children:ne}):s.jsx("div",{className:ae,"aria-label":A("contextUsage.aria.label"),onClick:g?()=>C(!0):void 0,children:ne}),e[33]=ne,e[34]=F,e[35]=g,e[36]=f,e[37]=S,e[38]=ae,e[39]=A,e[40]=ge):ge=e[40];const te=ge;if(g){let H;e[41]===Symbol.for("react.memo_cache_sentinel")?(H=()=>C(!1),e[41]=H):H=e[41];let re;e[42]!==A?(re=A("contextUsage.mobile.title"),e[42]=A,e[43]=re):re=e[43];let ce;e[44]!==A?(ce=A("contextUsage.mobile.usedTokens"),e[44]=A,e[45]=ce):ce=e[45];let Ne;e[46]!==ce?(Ne=s.jsx("span",{className:"typography-meta text-muted-foreground",children:ce}),e[46]=ce,e[47]=Ne):Ne=e[47];let me;e[48]!==n?(me=R(n),e[48]=n,e[49]=me):me=e[49];let we;e[50]!==me?(we=s.jsx("span",{className:"typography-meta text-foreground font-medium",children:me}),e[50]=me,e[51]=we):we=e[51];let _;e[52]!==Ne||e[53]!==we?(_=s.jsxs("div",{className:"flex justify-between items-center",children:[Ne,we]}),e[52]=Ne,e[53]=we,e[54]=_):_=e[54];let ue;e[55]!==A?(ue=A("contextUsage.mobile.contextLimit"),e[55]=A,e[56]=ue):ue=e[56];let Q;e[57]!==ue?(Q=s.jsx("span",{className:"typography-meta text-muted-foreground",children:ue}),e[57]=ue,e[58]=Q):Q=e[58];let oe;e[59]!==i?(oe=R(i),e[59]=i,e[60]=oe):oe=e[60];let Z;e[61]!==oe?(Z=s.jsx("span",{className:"typography-meta text-foreground font-medium",children:oe}),e[61]=oe,e[62]=Z):Z=e[62];let Ie;e[63]!==Q||e[64]!==Z?(Ie=s.jsxs("div",{className:"flex justify-between items-center",children:[Q,Z]}),e[63]=Q,e[64]=Z,e[65]=Ie):Ie=e[65];let Se;e[66]!==A?(Se=A("contextUsage.mobile.outputLimit"),e[66]=A,e[67]=Se):Se=e[67];let Y;e[68]!==Se?(Y=s.jsx("span",{className:"typography-meta text-muted-foreground",children:Se}),e[68]=Se,e[69]=Y):Y=e[69];let fe;e[70]!==P?(fe=R(P),e[70]=P,e[71]=fe):fe=e[71];let ke;e[72]!==fe?(ke=s.jsx("span",{className:"typography-meta text-foreground font-medium",children:fe}),e[72]=fe,e[73]=ke):ke=e[73];let xe;e[74]!==Y||e[75]!==ke?(xe=s.jsxs("div",{className:"flex justify-between items-center",children:[Y,ke]}),e[74]=Y,e[75]=ke,e[76]=xe):xe=e[76];let he;e[77]!==A?(he=A("contextUsage.mobile.usage"),e[77]=A,e[78]=he):he=e[78];let Pe;e[79]!==he?(Pe=s.jsx("span",{className:"typography-meta text-muted-foreground",children:he}),e[79]=he,e[80]=Pe):Pe=e[80];let Be;e[81]!==I?(Be=pe("typography-meta font-semibold",k(I)),e[81]=I,e[82]=Be):Be=e[82];const G=Math.min(r,999);let be;e[83]!==G?(be=G.toFixed(1),e[83]=G,e[84]=be):be=e[84];let De;e[85]!==Be||e[86]!==be?(De=s.jsxs("span",{className:Be,children:[be,"%"]}),e[85]=Be,e[86]=be,e[87]=De):De=e[87];let Ae;e[88]!==Pe||e[89]!==De?(Ae=s.jsxs("div",{className:"flex justify-between items-center pt-1 border-t border-border/40",children:[Pe,De]}),e[88]=Pe,e[89]=De,e[90]=Ae):Ae=e[90];let ve;e[91]!==_||e[92]!==Ie||e[93]!==xe||e[94]!==Ae?(ve=s.jsx("div",{className:"flex flex-col gap-1.5",children:s.jsxs("div",{className:"rounded-xl border border-border/40 bg-sidebar/30 px-3 py-2 space-y-1",children:[_,Ie,xe,Ae]})}),e[91]=_,e[92]=Ie,e[93]=xe,e[94]=Ae,e[95]=ve):ve=e[95];let U;e[96]!==j||e[97]!==re||e[98]!==ve?(U=s.jsx(Ar,{open:j,onClose:H,title:re,children:ve}),e[96]=j,e[97]=re,e[98]=ve,e[99]=U):U=e[99];let de;return e[100]!==te||e[101]!==U?(de=s.jsxs(s.Fragment,{children:[te,U]}),e[100]=te,e[101]=U,e[102]=de):de=e[102],de}let E;e[103]!==te?(E=s.jsx(St,{asChild:!0,children:te}),e[103]=te,e[104]=E):E=e[104];let z;e[105]!==$?(z=s.jsx(Ct,{children:s.jsx("div",{className:"space-y-0.5",children:$.map(Nj)})}),e[105]=$,e[106]=z):z=e[106];let J;return e[107]!==E||e[108]!==z?(J=s.jsxs(kt,{children:[E,z]}),e[107]=E,e[108]=z,e[109]=J):J=e[109],J};function wj(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}K`:t.toFixed(1).replace(/\.0$/,"")}function jj(t){return t>=90?"text-status-error":t>=75?"text-status-warning":"text-status-success"}function Nj(t){return s.jsx("p",{className:"typography-micro leading-tight",children:t},t)}const Jl=Oe.forwardRef((t,e)=>{const n=nt.c(11);let r,a;n[0]!==t?({className:r,...a}=t,n[0]=t,n[1]=r,n[2]=a):(r=n[1],a=n[2]);let i;n[3]!==r?(i=pe("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(ub,{className:pe("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(mb,{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});Jl.displayName="Switch";const nl=()=>{try{const e=Fs.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const n=Dn.getDirectory();if(n?.trim())return n.trim()}catch(t){console.warn("[McpConfigStore] Error resolving config directory:",t)}return null},Qm=t=>t?Object.entries(t).map(([e,n])=>({key:e,value:n})):[],Jm=t=>{const e=t.filter(n=>n.key.trim());if(e.length!==0)return Object.fromEntries(e.map(n=>[n.key.trim(),n.value]))},rl=t=>typeof t!="string"?void 0:t.trim()||void 0,Kc=800,Sj=5e3,kj="__default__",zd=new Map,Hc=new Map,zg=t=>t?.trim()||kj,Gc=t=>{zd.delete(zg(t))},Fo=wr()(Xi($o((t,e)=>({mcpServers:[],selectedMcpName:null,isLoading:!1,mcpDraft:null,setSelectedMcp:n=>t({selectedMcpName:n}),setMcpDraft:n=>t({mcpDraft:n}),loadMcpConfigs:async n=>{const r=nl(),a=zg(r),i=Date.now(),o=zd.get(a)??0,c=e().mcpServers.length>0;if(!n?.force&&c&&i-o<Sj)return!0;const d=Hc.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}),zd.set(a,Date.now()),!0}catch(m){return console.error("[McpConfigStore] Failed to load MCP configs:",m),t({isLoading:!1}),!1}})();Hc.set(a,p);try{return await p}finally{Hc.delete(a)}},createMcp:async n=>{Fc("Creating MCP server configuration…");let r=!1;try{const a=Ym(n),i=nl(),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 Gc(i),d?.requiresReload?(r=!0,await Oc({message:d.message,delayMs:d.reloadDelayMs??Kc,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||Lc()}},updateMcp:async(n,r)=>{Fc("Updating MCP server configuration…");let a=!1;try{const i=Ym(r),o=nl(),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 Gc(o),p?.requiresReload?(a=!0,await Oc({message:p.message,delayMs:p.reloadDelayMs??Kc,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||Lc()}},deleteMcp:async n=>{Fc("Deleting MCP server configuration…");let r=!1;try{const a=nl(),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 Gc(a),c?.requiresReload&&(r=!0,await Oc({message:c.message,delayMs:c.reloadDelayMs??Kc,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||Lc()}},getMcpByName:n=>e().mcpServers.find(r=>r.name===n)}),{name:"mcp-config-store",storage:lc(()=>ba()),partialize:t=>({selectedMcpName:t.selectedMcpName})}),{name:"mcp-config-store"}));function Ym(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=Jm(t.environment)??{}),t.headers!==void 0&&(e.headers=Jm(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:rl(t.oauthClientId),clientSecret:rl(t.oauthClientSecret),scope:rl(t.oauthScope),redirectUri:rl(t.oauthRedirectUri)};n.clientId||n.clientSecret||n.scope||n.redirectUri?e.oauth=n:t.oauthEnabled?e.oauth={}:e.oauth=!1}if(t.timeout!==void 0){const n=Number(t.timeout);Number.isFinite(n)&&n>0?e.timeout=n:e.timeout=null}return t.enabled!==void 0&&(e.enabled=t.enabled),e}const Cj={},Ij={},na=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},vi=t=>na(t)??"__global__",Ea=t=>{const e=na(t);return e?Dn.getScopedApiClient(e):Dn.getApiClient()},Pn=wr()(Xi((t,e)=>({byDirectory:{},diagnosticsByDirectory:{},loadingKeys:{},lastErrorKeys:{},getStatusForDirectory:n=>{const r=vi(n??Ws.getState().currentDirectory);return e().byDirectory[r]??Cj},getDiagnosticForDirectory:n=>{const r=vi(n??Ws.getState().currentDirectory);return e().diagnosticsByDirectory[r]??Ij},getErrorForDirectory:n=>{const r=vi(n??Ws.getState().currentDirectory);return e().lastErrorKeys[r]??null},refresh:async n=>{const r=na(n?.directory??Ws.getState().currentDirectory),a=vi(r);n?.silent||t(i=>({loadingKeys:{...i.loadingKeys,[a]:!0},lastErrorKeys:{...i.lastErrorKeys,[a]:null}}));try{const c=(await Ea(r).mcp.status()).data??{};t(d=>({byDirectory:{...d.byDirectory,[a]:c},diagnosticsByDirectory:{...d.diagnosticsByDirectory,[a]:Object.fromEntries(Object.entries(d.diagnosticsByDirectory[a]??{}).filter(([p])=>!c[p]))},loadingKeys:{...d.loadingKeys,[a]:!1},lastErrorKeys:{...d.lastErrorKeys,[a]:null}}))}catch(i){const o=i instanceof Error?i.message:"Failed to load MCP status";t(c=>({loadingKeys:{...c.loadingKeys,[a]:!1},lastErrorKeys:{...c.lastErrorKeys,[a]:o}}))}},connect:async(n,r)=>{const a=na(r??Ws.getState().currentDirectory),i=vi(a),o=Ea(a);try{await o.mcp.connect({name:n},{throwOnError:!0})}catch(c){const d=c instanceof Error?c.message:"Connection failed";throw t(p=>({diagnosticsByDirectory:{...p.diagnosticsByDirectory,[i]:{...p.diagnosticsByDirectory[i]??{},[n]:{status:"failed",error:d}}}})),c}await e().refresh({directory:a,silent:!0})},disconnect:async(n,r)=>{const a=na(r??Ws.getState().currentDirectory);await Ea(a).mcp.disconnect({name:n},{throwOnError:!0}),await e().refresh({directory:a,silent:!0})},startAuth:async(n,r)=>{const a=na(r??Ws.getState().currentDirectory),c=(await Ea(a).mcp.auth.start({name:n},{throwOnError:!0})).data?.authorizationUrl;if(!c)throw new Error("Authorization URL was not returned");return c},completeAuth:async(n,r,a)=>{const i=na(a??Ws.getState().currentDirectory);await Ea(i).mcp.auth.callback({name:n,code:r},{throwOnError:!0}),await e().refresh({directory:i,silent:!0})},clearAuth:async(n,r)=>{const a=na(r??Ws.getState().currentDirectory);await Ea(a).mcp.auth.remove({name:n},{throwOnError:!0}),await e().refresh({directory:a,silent:!0})},testConnection:async(n,r)=>{const a=na(r??Ws.getState().currentDirectory),i=vi(a),o=Ea(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 _g(t){const e=nt.c(4);let n,r;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx("path",{d:"M15.688 2.343a2.588 2.588 0 00-3.61 0l-9.626 9.44a.863.863 0 01-1.203 0 .823.823 0 010-1.18l9.626-9.44a4.313 4.313 0 016.016 0 4.116 4.116 0 011.204 3.54 4.3 4.3 0 013.609 1.18l.05.05a4.115 4.115 0 010 5.9l-8.706 8.537a.274.274 0 000 .393l1.788 1.754a.823.823 0 010 1.18.863.863 0 01-1.203 0l-1.788-1.753a1.92 1.92 0 010-2.754l8.706-8.538a2.47 2.47 0 000-3.54l-.05-.049a2.588 2.588 0 00-3.607-.003l-7.172 7.034-.002.002-.098.097a.863.863 0 01-1.204 0 .823.823 0 010-1.18l7.273-7.133a2.47 2.47 0 00-.003-3.537z"}),r=s.jsx("path",{d:"M14.485 4.703a.823.823 0 000-1.18.863.863 0 00-1.204 0l-7.119 6.982a4.115 4.115 0 000 5.9 4.314 4.314 0 006.016 0l7.12-6.982a.823.823 0 000-1.18.863.863 0 00-1.204 0l-7.119 6.982a2.588 2.588 0 01-3.61 0 2.47 2.47 0 010-3.54l7.12-6.982z"}),e[0]=n,e[1]=r):(n=e[0],r=e[1]);let a;return e[2]!==t?(a=s.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",fill:"currentColor",stroke:"currentColor",strokeWidth:"0.5",fillRule:"evenodd",viewBox:"-0.5 -0.5 25 25",...t,children:[n,r]}),e[2]=t,e[3]=a):a=e[3],a}const Aj=(t,e)=>{if(!t)return e("mcpDropdown.status.unknown");switch(t.status){case"connected":return e("mcpDropdown.status.connected");case"failed":return e("mcpDropdown.status.failed",{error:t.error||e("mcpDropdown.status.unknownError")});case"needs_auth":return e("mcpDropdown.status.needsAuth");case"needs_client_registration":return e("mcpDropdown.status.needsRegistration",{error:t.error||""});default:return t.status}},Pj=t=>{switch(t?.status){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"default"}},Ug=({active:t,className:e})=>{const{t:n}=ut(),a=Ws(g=>g.currentDirectory)??null,i=Pn(g=>g.getStatusForDirectory(a)),o=Pn(g=>g.refresh),c=Pn(g=>g.connect),d=Pn(g=>g.disconnect),p=Fo(g=>g.mcpServers),m=Fo(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 y=l.useMemo(()=>{const g=new Set(Object.keys(i));for(const w of p)w?.name&&g.add(w.name);return Array.from(g).sort((w,v)=>w.localeCompare(v))},[p,i]),x=l.useCallback(g=>{if(g?.preventDefault(),u)return;h(!0);const w=new Promise(v=>setTimeout(v,500));Promise.all([o({directory:a}),w]).finally(()=>{h(!1)})},[u,o,a]);return s.jsxs("div",{className:pe("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(Nn,{className:pe("h-4 w-4",u&&"animate-spin")})})]})}),s.jsxs("div",{className:"max-h-64 overflow-y-auto py-2",children:[y.map(g=>{const w=i[g],v=Pj(w),S=w?.status==="connected",A=b===g,j=Aj(w,n);return s.jsxs("div",{className:"flex items-center justify-between gap-2 px-4 py-1.5 rounded-lg hover:bg-interactive-hover/50",children:[s.jsx("div",{className:"min-w-0 flex-1",children:s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx("span",{className:pe("h-2 w-2 rounded-full flex-shrink-0",v==="success"&&"bg-status-success",v==="error"&&"bg-status-error",v==="warning"&&"bg-status-warning",v==="default"&&"bg-muted-foreground/40"),"aria-label":j})}),s.jsx(Ct,{side:"left",children:s.jsx("p",{children:j})})]}),s.jsx("span",{className:"typography-ui-label truncate",children:g})]})}),s.jsx(Jl,{checked:S,disabled:A,className:"data-[checked]:bg-status-info",onCheckedChange:async C=>{f(g);try{C?await c(g,a):await d(g,a)}finally{f(null)}}})]},g)}),y.length===0&&s.jsx("div",{className:"px-4 py-5 typography-ui-label text-muted-foreground text-center",children:n("mcpDropdown.empty.configureInConfig")})]})]})},Oo=t=>{const e=nt.c(20),{percent:n,tonePercent:r,className:a,expectedMarkerPercent:i}=t;let o;e[0]!==n?(o=lj(n)??0,e[0]=n,e[1]=o):o=e[1];const c=o,d=r??n;let p;e[2]!==d?(p=Fg(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=pe("relative h-2.5 rounded-full bg-[var(--interactive-border)] overflow-hidden",a),e[6]=a,e[7]=f):f=e[7];const y=`${c}%`;let x;e[8]!==b||e[9]!==y?(x={...b,width:y},e[8]=b,e[9]=y,e[10]=x):x=e[10];let g;e[11]!==c||e[12]!==x?(g=s.jsx("div",{className:"h-full transition-all duration-300",style:x,role:"progressbar","aria-valuenow":c,"aria-valuemin":0,"aria-valuemax":100}),e[11]=c,e[12]=x,e[13]=g):g=e[13];let w;e[14]!==u?(w=u!=null&&u>0&&u<100&&s.jsx("div",{className:"absolute top-0 h-full w-0.5 bg-foreground",style:{left:`${u}%`},title:`Expected usage if spread evenly: ${Math.round(u)}% of quota`,"aria-hidden":"true"}),e[14]=u,e[15]=w):w=e[15];let v;return e[16]!==f||e[17]!==g||e[18]!==w?(v=s.jsxs("div",{className:f,children:[g,w]}),e[16]=f,e[17]=g,e[18]=w,e[19]=v):v=e[19],v},Lo=t=>{const e=nt.c(67),{paceInfo:n,className:r,compact:a}=t,i=a===void 0?!1:a,{t:o}=ut();let c;e[0]!==n.status?(c=uj(n.status),e[0]=n.status,e[1]=c):c=e[1];const d=c;let p;e:{switch(n.status){case"on-track":{let C;e[2]!==o?(C=o("settings.usage.pace.status.onTrack"),e[2]=o,e[3]=C):C=e[3],p=C;break e}case"slightly-fast":{let C;e[4]!==o?(C=o("settings.usage.pace.status.slightlyFast"),e[4]=o,e[5]=C):C=e[5],p=C;break e}case"too-fast":{let C;e[6]!==o?(C=o("settings.usage.pace.status.tooFast"),e[6]=o,e[7]=C):C=e[7],p=C;break e}case"exhausted":{let C;e[8]!==o?(C=o("settings.usage.pace.status.usedUp"),e[8]=o,e[9]=C):C=e[9],p=C;break e}}p=void 0}const m=p;let u;e[10]!==n.predictText||e[11]!==o?(u=o("settings.usage.pace.predictionTooltip",{prediction:n.predictText}),e[10]=n.predictText,e[11]=o,e[12]=u):u=e[12];const h=u;if(i){let C;e[13]!==r?(C=pe("flex items-center gap-1.5",r),e[13]=r,e[14]=C):C=e[14];let I;e[15]!==d?(I={backgroundColor:d},e[15]=d,e[16]=I):I=e[16];let R;e[17]!==m||e[18]!==I?(R=s.jsx("div",{className:"h-2 w-2 rounded-full flex-shrink-0",style:I,title:m}),e[17]=m,e[18]=I,e[19]=R):R=e[19];let k;e[20]!==d?(k={color:d},e[20]=d,e[21]=k):k=e[21];const P=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:Gm(n.remainingSeconds)})}):s.jsx(s.Fragment,{children:o("settings.usage.pace.prediction",{prediction:n.predictText})}),e[22]=n.isExhausted,e[23]=n.predictText,e[24]=n.remainingSeconds,e[25]=o,e[26]=N):N=e[26];let D;e[27]!==N||e[28]!==k||e[29]!==P?(D=s.jsx("span",{className:"typography-micro tabular-nums",style:k,title:P,children:N}),e[27]=N,e[28]=k,e[29]=P,e[30]=D):D=e[30];let T;return e[31]!==D||e[32]!==C||e[33]!==R?(T=s.jsxs("div",{className:C,children:[R,D]}),e[31]=D,e[32]=C,e[33]=R,e[34]=T):T=e[34],T}let b;e[35]!==r?(b=pe("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 y;e[41]!==f?(y=s.jsx("div",{className:"flex items-center gap-1.5",children:f}),e[41]=f,e[42]=y):y=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:Gm(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 v;e[55]!==d?(v={backgroundColor:d},e[55]=d,e[56]=v):v=e[56];let S;e[57]!==m||e[58]!==v?(S=s.jsx("div",{className:"h-2 w-2 rounded-full flex-shrink-0",style:v,title:m}),e[57]=m,e[58]=v,e[59]=S):S=e[59];let A;e[60]!==w||e[61]!==S?(A=s.jsxs("div",{className:"flex items-center gap-1.5",children:[w,S]}),e[60]=w,e[61]=S,e[62]=A):A=e[62];let j;return e[63]!==A||e[64]!==b||e[65]!==y?(j=s.jsxs("div",{className:b,children:[y,A]}),e[63]=A,e[64]=b,e[65]=y,e[66]=j):j=e[66],j},yr=pb,Mr=t=>{const e=nt.c(14);let n,r,a,i;e[0]!==t?({className:a,asChild:n,children:r,...i}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=a,e[4]=i):(n=e[1],r=e[2],a=e[3],i=e[4]);let o;e[5]!==n||e[6]!==r?(o=n&&Oe.isValidElement(r)?{render:r}:{children:r},e[5]=n,e[6]=r,e[7]=o):o=e[7];const c=o;let d;e[8]!==a?(d=pe("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(fb,{className:d,...i,...c}),e[10]=i,e[11]=c,e[12]=d,e[13]=p):p=e[13],p},vr=t=>{const e=nt.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let a;e[3]!==n?(a=pe("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(hb,{className:a,...r}),e[5]=r,e[6]=a,e[7]=i):i=e[7],i},va=[{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"}],_d="finder",Ud=new Set(["finder","terminal"]),Wd=t=>t?va.find(e=>e.id===t)??null:null,qc=()=>va.filter(t=>Ud.has(t.id)).map(t=>({...t})),Dj=()=>{if(typeof window>"u")return _d;const t=window.localStorage.getItem("openInAppId");return t&&Wd(t)?t:_d};let Qc=!1,wi=!1,fa=!1,ha=0,ko=null;const Xm=()=>{ko&&(clearTimeout(ko),ko=null)},Lr=wr()((t,e)=>({selectedAppId:Dj(),availableApps:qc(),hasLoadedApps:!1,isCacheStale:!1,isScanning:!1,initialize:()=>{if(Qc||typeof window>"u")return;Qc=!0;const n=d=>{if(!Array.isArray(d)||d.length===0){t({availableApps:qc(),hasLoadedApps:!1});return}const p=new Set(d.map(b=>b.name)),m=new Map(d.map(b=>[b.name,b.iconDataUrl??void 0])),h=va.filter(b=>p.has(b.appName)||Ud.has(b.id)).map(b=>({...b,iconDataUrl:m.get(b.appName)}));t({availableApps:h,hasLoadedApps:!0})},r=async d=>{if(!ri()||!oa()||wi||e().hasLoadedApps&&!d)return;const m=va.map(u=>u.appName);Xm(),wi=!0,fa=!1,t({isScanning:!0});try{const{apps:u,success:h,hasCache:b,isCacheStale:f}=await gm(m,d);if(t({isCacheStale:b?f:!1}),n(u),h){if(!b&&u.length===0&&ha<3){const x=[800,1600,3200][ha]??3200;ha+=1,fa=!0,ko=setTimeout(()=>{r()},x);return}ha=0,fa=!1;return}if(ha<3){const x=[1e3,3e3,7e3][ha]??7e3;ha+=1,fa=!0,ko=setTimeout(()=>{r()},x)}}finally{wi=!1,fa||t({isScanning:!1})}};r();const a=d=>{const p=d.detail,m=p&&typeof p.openInAppId=="string"&&p.openInAppId.length>0&&Wd(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)&&(ha=3,fa=!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(Qc||e().initialize(),!ri()||!oa()||wi||e().hasLoadedApps&&!n)return;const a=va.map(i=>i.appName);Xm(),n&&t({hasLoadedApps:!1}),wi=!0,fa=!1,t({isScanning:!0});try{const{apps:i,hasCache:o,isCacheStale:c}=await gm(a,n),d=new Set(i.map(h=>h.name)),p=new Map(i.map(h=>[h.name,h.iconDataUrl??void 0])),u=va.filter(h=>d.has(h.appName)||Ud.has(h.id)).map(h=>({...h,iconDataUrl:p.get(h.appName)}));t({availableApps:u.length>0?u:qc(),hasLoadedApps:u.length>0,isCacheStale:o?c:!1})}finally{wi=!1,fa||t({isScanning:!1})}},selectApp:async n=>{Wd(n)&&(t({selectedAppId:n}),typeof window<"u"&&window.localStorage.setItem("openInAppId",n),await Rs({openInAppId:n}))}})),Tj="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAeGVYSWZNTQAqAAAACAAEARoABQAAAAEAAAA+ARsABQAAAAEAAABGASgAAwAAAAEAAgAAh2kABAAAAAEAAABOAAAAAAAAAJAAAAABAAAAkAAAAAEAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAIKADAAQAAAABAAAAIAAAAAB+C9pSAAAACXBIWXMAABYlAAAWJQFJUiTwAAABnWlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNi4wLjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczpleGlmPSJodHRwOi8vbnMuYWRvYmUuY29tL2V4aWYvMS4wLyI+CiAgICAgICAgIDxleGlmOlBpeGVsWERpbWVuc2lvbj4yNTY8L2V4aWY6UGl4ZWxYRGltZW5zaW9uPgogICAgICAgICA8ZXhpZjpQaXhlbFlEaW1lbnNpb24+MjU2PC9leGlmOlBpeGVsWURpbWVuc2lvbj4KICAgICAgPC9yZGY6RGVzY3JpcHRpb24+CiAgIDwvcmRmOlJERj4KPC94OnhtcG1ldGE+Cl6wHhsAAAXaSURBVFgJ7VddbBRVFP5mdme6dOnu2tZawOAPjfxU+bGQYCRAsvw8qNGEQPTRJ0I0amL0wfjgA/HBR8KLD8YgDxJEUkVFxSYYTSRii6DQQCMGIQqlW7p0u+zMzo/fuTuzO9Nt0Td94CRn7pl7z5zznZ977y5wh/7jDGiz+T979qD5Ujbfd90xlll+stOF1uI40B1+4HhkjnZk9CgLQ9iXp2/BdcbgVc/h0sAgduywudJEMwLY9Of4ugtW5p3CpL7W1jTN88VmjdQYvnDKF1mczkYuNZLeCVg3X8fa9u+nqzUB2HRpdN2pSseRQknPoUL1Jo2ICTrPGcCzdwPdHENcAnicKRqcAk7cpL5J1r0JlAtPYV1XDETM/FtH3m19r+f5by+XjNX/xnmCX3/cCzydi4CKiC7lw+PArhGgoPPFq/6E0+9vwM6d5VBNpuv03cLNfeNTRh9KnJIiV2/PvSngycC5RD+dE5zb3g7s6QESzAZc2l6wuY9SnWIAxv10r81uU85Vt1FvtpEtlc/SMFUkUofeZ2IBta0DWDmXgkfbyTRz1qAYAMczOz3p1elOxYPyEllj421hdELViPO6Kudk3ia3UGe5ABDbvtnJZ52SdYmCZ3stdeexBabFdeAbYopEowtagVUZqFapBrtAGqpiVaFrGgyjZlrmTD5yEqoEJj4iFMuA62i6L3WPZkAiuHgarZ/vbWSBkTzO2rfTR4XOJVJhjfX44MBn+OTocVWbcF5MalxXPeVL6zYonoGo44YOtDI7qHC1lkL5nHnOc+tJRi3K6iygLNGMjt1A1XVV6iUzOvVtAvMlS2I/yBYlRf8MgA6szmXQ1jDfKhSgjft6DRtrkgarAiAw5nI9v2WDSn+Zxfd9DawGxIlPPQUg0A2HGABfEIYlCDU4+q0d8O+jRzHCCFYy+nu4BaeYAoksBCDrPYsXQQ6iitgiSQaS1FHHtMzFil4DpxTl4UhORSn4WOaaiGsbu4iFRkMnYQlEV0oSJQGQ4FyYgSRDjpqPZcCR6EOOWonIEsBqArAIQOMLzw0VXRRERF2VoA6Atk1+MzsASekMJYgaFEeHR4Cr85lNGntYzgKCYd/NSNIDCXr0ZJ2jwTsjSvEMzFQCCVmKHBRahn2DNb4rDRx8pnbXOOIg0JELLMHOF1AUkaRj1V8c2TookkMS83WK9QCVpRwtf5wCykQWRKDyJ44Ytc452QUV6inmN9IDIv/6y2+YLDuqTywBEHxv8rsoxQC4Fpf4cZ2pbJ4/huxXr0EvFmoRCrAIVymLQ3Eid0GJYPsPfISBLwdwi79YQnCqBNS7LQDP5qYSAKEDypOrX4WVWYLsFy+i9cwh6CUmUKIJI2Gq5cSbnLLw849D2Ld3L4olC1u3P0c1ow5Ozgixa3puWChONG1D3eLZUQOglvng+Vp5dBfseesx5/yHyI4cBTL3wsssRGs2g6/ppHijiMLoNSSMNHofy6Nn6SPsAR02nUoTtrDTSrdoi8CTni55rlOsCf1ypaDxlFMNU1epCV5XL6Y6dmOq+BeS48NIlq7Anpjg5dOFbPdDWLQyj/aubnUKSkMKi3NhkUd4kieYtbRbYS0bFAOQKI8NO363z1RJHmamtnlwhGksxV2w/gl29WRtm8kWtWUnRShLnQvXgDOXmLg2HzlvbDiyHD8Y517YP2i4FtueFPbB9FFqKcyobk4A5y7zquUFa7IXojyHoeXmAFcY755vaI6A56Xsofm/7+cmblBTpOldQ5vs3PJDVS+RVSAaus2SpJTO80t4NTNSOQfCDrtFkBevA0ME6HGvPdDpFlekzm7rf3nFQNRQEwBZTL9warObWfx21Uv1+fx1ERqVNampGoOHpF1tsdp07RnoGMxK1vT97rbK4IP6+Tc+fWXVsahaYGL6VO09d//GXHXr7jVeqmuppqU6ff4x0RO6lqRxgxHJpWKSlcw5eWfjq5rq/CdhaL5l6JWxjDc6bP7w5sn+/uMs2B36H2bgb6v9raK0+o9IAAAAAElFTkSuQmCC",Mj="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAeGVYSWZNTQAqAAAACAAEARoABQAAAAEAAAA+ARsABQAAAAEAAABGASgAAwAAAAEAAgAAh2kABAAAAAEAAABOAAAAAAAAAJAAAAABAAAAkAAAAAEAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAIKADAAQAAAABAAAAIAAAAAB+C9pSAAAACXBIWXMAABYlAAAWJQFJUiTwAAABnWlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNi4wLjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczpleGlmPSJodHRwOi8vbnMuYWRvYmUuY29tL2V4aWYvMS4wLyI+CiAgICAgICAgIDxleGlmOlBpeGVsWERpbWVuc2lvbj4yNTY8L2V4aWY6UGl4ZWxYRGltZW5zaW9uPgogICAgICAgICA8ZXhpZjpQaXhlbFlEaW1lbnNpb24+MjU2PC9leGlmOlBpeGVsWURpbWVuc2lvbj4KICAgICAgPC9yZGY6RGVzY3JpcHRpb24+CiAgIDwvcmRmOlJERj4KPC94OnhtcG1ldGE+Cl6wHhsAAAQzSURBVFgJ7VZNbBNHFH67Xv9RxwnBDqlUoQglcZK6qSIEJIQWAYJQoVY9IE5RTzn20FMvqdpDesq9B24+NdwthAJCkZChJg1JSOXYQIwQKQIaBdtENbs73t2+N8miGWOcpFHUHniyd97OvJ9v3nv7ZgDe038cAeVd/jOZjC94sKdfU+Bj24G9igpexwYPyiu2bauKqqqirkOTqmrjnIOyFsoyUKDocSCj/7mU7ujoMER5l68JYOFZ4YSiwPjd9O0jjx7ch1KhAJZVAcdx0LxDv3XetYKjggr4I4bzHo8G4aYmONjZBYf6+2dUzfd9PNowJajUZmef/PX5zcWl0rmvvnbQHrra+f/M+S+dqYXs2t3Hz09Ve5UicCmZ3NPb1Zv66btv+65dSULA64WGxkbw+Xx8V9XK9d4pWowxeFUqgW6acHroC/j5l0sLD/PZY98MDf3t6mouQ+On3X1H7/2e7rtOztHpgbY2+CAUgperq+D3+7cNgtLSEA7D0+VluDF5FS7cSff2HT56DF1dd/3KhQTWJ/lclsc8jIrk9IfRURgZGQEvRqNSWa8D2t1W/liXXK8Ro0i0lF0ExaPEXec0SgAqhrm3VCzwdS9GQNd1GBsbg0AgAIlEAlpbW7EYLVF/U56AagieiGwbuhERlSQApmEE8c/XKXxU0fF4HNowFfPz81Aul7edBjLGbeHITANsZga4g42HVAM2Y74KM/kSIQ/izgcHB2FiYgJmZmZ4MZpYULRG5PF4+Bx/2cLDxuhhYUqFLwGoWCaQEBGhNjAa4+Pj/J3SQA6pHpqbm/kcNitIJpOgaZIZvlbrQbZNJvcjSZOZDKhwRKLic4l2Pjc3B8FgkE+trKxAVUN0RWuOZNtCHyJJACj/bgREIZcnA9PT029SQM63unuywSOwUWOuTQmAhfmnlluPxIjUk6u1RrbJh0jyV0Ap2OZnJhrbjOcRqEqBBMDCAtltAORDJAkAVj2mWS5CUXinPDUx+oxFkgBYjO0qANu2wKoqQgkAfgW7C4AiYMmfoQSgwpjj7GYRUh/Q66SAmdisNxql227FfP1bXrRlVExdtCNHwDRLdPkgwmi8OUREhe3y1NLJFpEfbWMNvBRtSI2o+KqYi+zbx4NQwptMCO8E1HjEHYjKm/HknG5FZIsCG4lEoLS2lhP1JAB3bt1KH//s+GJPd3dPJpvlN5kwXiYIhHukisr1eAItXsm6YzGItrTcn5+dvS3qSQBSqVQhFouNnj039CsaCC7mcqDjgbNT6op1AtrU8Wo3Ojk5KaVAOptdR8PDwxf3t7SMvXjxvJNOPP31a35Krt8CXKl3j2SUDip/IAjRaBRaP9z/cHW18GMikbhcrVUTAAm1t7d/NDAwcDIUCvVqmtqkyLe3ajtvvTtg4x3SLpbLa3+kUr9N5fP55beE3k/8HyLwDx2/HIx7q3WfAAAAAElFTkSuQmCC",Jc=t=>({...t,fallbackIconDataUrl:t.id==="finder"?Tj:t.id==="terminal"?Mj:void 0}),Zm=t=>{const e=nt.c(8),{label:n,iconDataUrl:r,fallbackIconDataUrl:a}=t,[i,o]=l.useState(!1);let c;e[0]!==n?(c=n.trim().slice(0,1).toUpperCase()||"?",e[0]=n,e[1]=c):c=e[1];const d=c,p=r||a;if(p&&!i){let 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=pe("h-4 w-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=m):m=e[5];let u;return e[6]!==d?(u=s.jsx("span",{className:m,children:d}),e[6]=d,e[7]=u):u=e[7],u},Rj=t=>{const e=nt.c(82),{directory:n,className:r}=t,{t:a}=ut(),i=Lr(Ej),o=Lr(Fj),c=Lr(Oj),d=Lr(Lj),p=Lr($j),m=Lr(Bj),u=Lr(Vj);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=ri()&&oa();let y;e:{let re;e[3]!==o||e[4]!==i?(re=o.find(me=>me.id===i)??o.find(zj)??o[0]??va[0],e[3]=o,e[4]=i,e[5]=re):re=e[5];const ce=re;if(ce){let me;e[6]!==ce?(me=Jc(ce),e[6]=ce,e[7]=me):me=e[7],y=me;break e}let Ne;e[8]===Symbol.for("react.memo_cache_sentinel")?(Ne=Jc(va[0]),e[8]=Ne):Ne=e[8],y=Ne}const x=y;if(!f||!n||o.length===0)return null;let g;e[9]!==n?(g=async re=>{await gv(n,re.id,re.appName)||await Wl(n,re.appName)},e[9]=n,e[10]=g):g=e[10];const w=g;let v;e[11]!==w||e[12]!==u?(v=async re=>{await u(re.id),await w(re)},e[11]=w,e[12]=u,e[13]=v):v=e[13];const S=v;let A;e[14]!==n||e[15]!==a?(A=async()=>{(await _n(n)).ok&&q.success(a("openInApp.toast.pathCopied"))},e[14]=n,e[15]=a,e[16]=A):A=e[16];const j=A;let C;e[17]!==r?(C=pe("app-region-no-drag inline-flex h-7 items-center self-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px]","bg-[var(--surface-elevated)] overflow-hidden","border border-border/60",r),e[17]=r,e[18]=C):C=e[18];let I;e[19]!==w||e[20]!==x?(I=()=>{w(x)},e[19]=w,e[20]=x,e[21]=I):I=e[21];let R;e[22]===Symbol.for("react.memo_cache_sentinel")?(R=pe("inline-flex h-full items-center gap-2 px-3 typography-ui-label font-medium","text-foreground hover:bg-interactive-hover transition-colors"),e[22]=R):R=e[22];let k;e[23]!==x.label||e[24]!==a?(k=a("openInApp.actions.openInAria",{app:x.label}),e[23]=x.label,e[24]=a,e[25]=k):k=e[25];let P;e[26]!==x.fallbackIconDataUrl||e[27]!==x.iconDataUrl||e[28]!==x.label?(P=s.jsx(Zm,{label:x.label,iconDataUrl:x.iconDataUrl,fallbackIconDataUrl:x.fallbackIconDataUrl}),e[26]=x.fallbackIconDataUrl,e[27]=x.iconDataUrl,e[28]=x.label,e[29]=P):P=e[29];const N=d?"animate-pulse text-muted-foreground":void 0;let D;e[30]!==N?(D=pe("header-open-label",N),e[30]=N,e[31]=D):D=e[31];let T;e[32]!==a?(T=a("openInApp.actions.open"),e[32]=a,e[33]=T):T=e[33];let M;e[34]!==D||e[35]!==T?(M=s.jsx("span",{className:D,children:T}),e[34]=D,e[35]=T,e[36]=M):M=e[36];let $;e[37]!==k||e[38]!==P||e[39]!==M||e[40]!==I?($=s.jsxs("button",{type:"button",onClick:I,className:R,"aria-label":k,children:[P,M]}),e[37]=k,e[38]=P,e[39]=M,e[40]=I,e[41]=$):$=e[41];let F;e[42]===Symbol.for("react.memo_cache_sentinel")?(F=pe("inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-muted-foreground","hover:bg-interactive-hover hover:text-foreground transition-colors"),e[42]=F):F=e[42];let V;e[43]!==a?(V=a("openInApp.actions.chooseAppAria"),e[43]=a,e[44]=V):V=e[44];let O;e[45]===Symbol.for("react.memo_cache_sentinel")?(O=s.jsx(Cs,{className:"h-4 w-4"}),e[45]=O):O=e[45];let L;e[46]!==V?(L=s.jsx(Bs,{asChild:!0,children:s.jsx("button",{type:"button",className:F,"aria-label":V,children:O})}),e[46]=V,e[47]=L):L=e[47];let W;e[48]===Symbol.for("react.memo_cache_sentinel")?(W={translate:"-30px 0"},e[48]=W):W=e[48];let B;e[49]!==j?(B=()=>{j()},e[49]=j,e[50]=B):B=e[50];let ne;e[51]===Symbol.for("react.memo_cache_sentinel")?(ne=s.jsx(br,{className:"h-4 w-4"}),e[51]=ne):ne=e[51];let le;e[52]!==a?(le=a("openInApp.actions.copyPath"),e[52]=a,e[53]=le):le=e[53];let ee;e[54]!==le?(ee=s.jsx("span",{className:"typography-ui-label text-foreground",children:le}),e[54]=le,e[55]=ee):ee=e[55];let ae;e[56]!==B||e[57]!==ee?(ae=s.jsxs($t,{className:"flex items-center gap-2",onClick:B,children:[ne,ee]}),e[56]=B,e[57]=ee,e[58]=ae):ae=e[58];let ge;e[59]===Symbol.for("react.memo_cache_sentinel")?(ge=s.jsx(En,{}),e[59]=ge):ge=e[59];let te;if(e[60]!==o||e[61]!==S||e[62]!==x.id){let re;e[64]!==S||e[65]!==x.id?(re=ce=>{const Ne=Jc(ce);return s.jsxs($t,{className:"flex items-center gap-2",onClick:()=>{S(ce)},children:[s.jsx(Zm,{label:ce.label,iconDataUrl:ce.iconDataUrl,fallbackIconDataUrl:Ne.fallbackIconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:ce.label}),x.id===ce.id?s.jsx(Ys,{className:"ml-auto h-4 w-4 text-primary"}):null]},ce.id)},e[64]=S,e[65]=x.id,e[66]=re):re=e[66],te=o.map(re),e[60]=o,e[61]=S,e[62]=x.id,e[63]=te}else te=e[63];let E;e[67]!==c||e[68]!==m||e[69]!==a?(E=c?s.jsxs($t,{className:"flex items-center gap-2",onClick:()=>{m(!0)},children:[s.jsx(Nn,{className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:a("openInApp.actions.refreshApps")})]}):null,e[67]=c,e[68]=m,e[69]=a,e[70]=E):E=e[70];let z;e[71]!==ae||e[72]!==te||e[73]!==E?(z=s.jsxs(Vs,{align:"center",className:"w-56 max-h-[70vh] overflow-y-auto",style:W,children:[ae,ge,te,E]}),e[71]=ae,e[72]=te,e[73]=E,e[74]=z):z=e[74];let J;e[75]!==L||e[76]!==z?(J=s.jsxs(zs,{children:[L,z]}),e[75]=L,e[76]=z,e[77]=J):J=e[77];let H;return e[78]!==$||e[79]!==J||e[80]!==C?(H=s.jsxs("div",{className:C,children:[$,J]}),e[78]=$,e[79]=J,e[80]=C,e[81]=H):H=e[81],H};function Ej(t){return t.selectedAppId}function Fj(t){return t.availableApps}function Oj(t){return t.isCacheStale}function Lj(t){return t.isScanning}function $j(t){return t.initialize}function Bj(t){return t.loadInstalledApps}function Vj(t){return t.selectApp}function zj(t){return t.id===_d}const _j=1e6,Uj="terminal-store";let ep=!1;const Yc=t=>typeof t=="object"&&t!==null,Wj=t=>{const e=/^tab-(\d+)$/.exec(t);if(!e)return null;const n=Number(e[1]);return Number.isFinite(n)?n:null};function Jn(t){let e=t.trim();for(;e.length>1&&e.endsWith("/");)e=e.slice(0,-1);return e}const Xc=(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}),Wg=/\x1b\[[0-9;]*m/g,Kj=/(https?:\/\/(?:localhost|127\.0\.0\.1|0\.0\.0\.0|\[(?:::1|::)\])(?::\d{2,5})?(?:\/[\w\-./~%!$&'()*+,;=:@?#[\]]*)?)/i,Hj=new Set([".",",",";",":","!","?"]),Gj=t=>{let e=t;for(;e.length>0;){const n=e[e.length-1];if(n===")"||n==="]"||n==="}"||n===">"){const r=n===")"?"(":n==="]"?"[":n==="}"?"{":"<",a=e.slice(0,-1),i=(a.match(new RegExp(`\\${r}`,"g"))||[]).length,o=(a.match(new RegExp(`\\${n}`,"g"))||[]).length;if(i>o)break;e=a;continue}if(Hj.has(n)){e=e.slice(0,-1);continue}break}return e},qj=t=>{if(!t)return null;const n=t.replace(Wg,"").match(Kj);if(!n?.[1])return null;let r=Gj(n[1]);return r=r.replace("0.0.0.0","127.0.0.1"),r=r.replace("[::1]","127.0.0.1"),r=r.replace("[::]","127.0.0.1"),r},Qj=t=>{if(!t)return null;const n=t.replace(Wg,"").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}/`},Zc=t=>({tabs:[t],activeTabId:t.id}),Fr=(t,e)=>t.tabs.findIndex(n=>n.id===e),gn=wr()(Xi($o((t,e)=>({sessions:new Map,projectActionRuns:{},nextChunkId:1,nextTabId:1,hasHydrated:typeof window>"u",ensureDirectory:n=>{const r=Jn(n);r&&t(a=>{if(a.sessions.has(r))return a;const i=new Map(a.sessions),o=`tab-${a.nextTabId}`,c=Xc(o,"Terminal");return i.set(r,Zc(c)),{sessions:i,nextTabId:a.nextTabId+1}})},getDirectoryState:n=>{const r=Jn(n);return e().sessions.get(r)},getActiveTab:n=>{const r=Jn(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=Jn(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=Xc(a,m);return c?o.set(r,{...c,tabs:[...c.tabs,u]}):o.set(r,Zc(u)),{sessions:o,nextTabId:d}}),a},setActiveTab:(n,r)=>{const a=Jn(n);t(i=>{const o=new Map(i.sessions),c=o.get(a);return!c||c.activeTabId===r||Fr(c,r)<0?i:(o.set(a,{...c,activeTabId:r}),{sessions:o})})},setTabLabel:(n,r,a)=>{const i=Jn(n),o=a.trim();o&&t(c=>{const d=new Map(c.sessions),p=d.get(i);if(!p)return c;const m=Fr(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=Jn(n);t(o=>{const c=new Map(o.sessions),d=c.get(i);if(!d)return o;const p=Fr(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=Jn(n),c=e().sessions.get(a)?.tabs.find(d=>d.id===r)?.terminalSessionId??null;if(c)try{await pv(c)}catch{}t(d=>{const p=new Map(d.sessions),m=p.get(a);if(!m)return d;const u=Fr(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=Xc(x,"Terminal");return p.set(a,Zc(g)),{sessions:p,nextTabId:d.nextTabId+1,...f?{projectActionRuns:b}:{}}}let y=m.activeTabId;return m.activeTabId===r&&(y=h[Math.min(u,h.length-1)]?.id??h[0]?.id??null),p.set(a,{...m,tabs:h,activeTabId:y}),{sessions:p,...f?{projectActionRuns:b}:{}}})},setTabSessionId:(n,r,a)=>{const i=Jn(n);t(o=>{const c=new Map(o.sessions),d=c.get(i);if(!d)return o;const p=Fr(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=Jn(n);t(o=>{const c=new Map(o.sessions),d=c.get(i);if(!d)return o;const p=Fr(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=Jn(n);t(o=>{const c=new Map(o.sessions),d=c.get(i);if(!d)return o;const p=Fr(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=Jn(n);t(o=>{const c=new Map(o.sessions),d=c.get(i);if(!d)return o;const p=Fr(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>_j&&b.length>1;){const w=b.shift();if(!w)break;f-=w.data.length}const y=m.previewUrlLocked?null:qj(a)??Qj(a),x=!!(y&&y!==m.previewUrl),g=[...d.tabs];return g[p]={...m,bufferChunks:b,bufferLength:f,...x?{previewUrl:y,previewAutoOpened:!1}:null},c.set(i,{...d,tabs:g}),{sessions:c,nextChunkId:u+1}})},setTabPreviewUrl:(n,r,a,i={})=>{const o=Jn(n);t(c=>{const d=new Map(c.sessions),p=d.get(o);if(!p)return c;const m=Fr(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=Jn(n);t(i=>{const o=new Map(i.sessions),c=o.get(a);if(!c)return i;const d=Fr(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=Jn(n);t(i=>{const o=new Map(i.sessions),c=o.get(a);if(!c)return i;const d=Fr(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=Jn(n);t(a=>{const i=new Map(a.sessions);i.delete(r);const o=Object.fromEntries(Object.entries(a.projectActionRuns).filter(([,c])=>c.directory!==r));return{sessions:i,projectActionRuns:o}})},clearAll:()=>{t({sessions:new Map,projectActionRuns:{},nextChunkId:1,nextTabId:1})}}),{name:Uj,storage:lc(()=>ng()),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(!Yc(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"||!Yc(p))continue;const m=Array.isArray(p.tabs)?p.tabs:[],u=[];for(const f of m){if(!Yc(f))continue;const y=typeof f.id=="string"?f.id:null;if(!y)continue;const x=Wj(y);x!==null&&(a=Math.max(a,x));const g=typeof f.terminalSessionId=="string"||f.terminalSessionId===null?f.terminalSessionId:null,w=f.lifecycle,v=w==="idle"||w==="running"||w==="exited"?w:g?"running":"idle";u.push({id:y,label:typeof f.label=="string"?f.label:"Terminal",iconKey:typeof f.iconKey=="string"?f.iconKey:null,terminalSessionId:g,lifecycle:v,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"&&!ep){ep=!0;const t=gn.persist,e=()=>{gn.getState().hasHydrated||gn.setState({hasHydrated:!0})};t?.hasHydrated?.()?e():t?.onFinishHydration?t.onFinishHydration(e):e()}const tp=(t,e)=>e.updatedAtMs-t.updatedAtMs,tn=wr((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([vv(),bm()]),a={};for(const i of r.sort(tp))a[i.id]=i;e().listenerReady||await wv(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 yv();t({importCandidates:n,isImportsLoading:!1})}catch(n){t({isImportsLoading:!1,error:n instanceof Error?n.message:String(n)})}}},refreshStatuses:async()=>{try{const n=await bm(),r={};for(const a of n.sort(tp))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 bv({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=jv(n,r);a&&a.trim()&&(i.nickname=a.trim()),await e().upsertInstance(i)},removeInstance:async n=>{await xm(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 xv(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 xm(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})})),Kg=[{key:"play",label:"Play",Icon:Wr},{key:"build",label:"Build",Icon:gb},{key:"lint",label:"Lint",Icon:xu},{key:"terminal",label:"Terminal",Icon:Za},{key:"tools",label:"Tools",Icon:Dh},{key:"bug",label:"Bug",Icon:xb},{key:"flask",label:"Flask",Icon:bb},{key:"rocket",label:"Rocket",Icon:yb},{key:"code",label:"Code",Icon:cc},{key:"server",label:"Server",Icon:ei},{key:"branch",label:"Branch",Icon:Ks},{key:"search",label:"Search",Icon:Hn},{key:"settings",label:"Settings",Icon:Vi},{key:"brain",label:"Brain",Icon:Ao},{key:"stack",label:"Stack",Icon:Sa},{key:"robot",label:"Robot",Icon:Gr},{key:"command",label:"Command",Icon:Bo},{key:"file",label:"File",Icon:zl}],Al=Object.fromEntries(Kg.map(t=>[t.key,t.Icon])),Kd="openchamber:project-actions-updated",Hg=t=>{const e=(t||"").trim().replace(/\\/g,"/");return e?e==="/"?"/":e.length>1?e.replace(/\/+$/,""):e:""},ga=(t,e)=>`${Hg(t)}::${e}`,Jj=t=>{const e=t.trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},sp=t=>{if(typeof t!="number"||!Number.isFinite(t))return null;const e=Math.round(t);return e<1||e>65535?null:e},Yj=(t,e)=>{if(!e.enabled||e.type!=="local")return null;const n=sp(e.localPort),r=sp(e.remotePort);if(!n||!r)return null;const a=Jj(e.localHost||t.localForward.bindHost||"127.0.0.1"),i=(e.remoteHost||"127.0.0.1").trim(),o=(t.nickname||t.id||"instance").trim();return{id:`${t.id}::${e.id}`,label:`${o} - ${a}:${n} -> ${i}:${r}`,url:`http://${a}:${n}`}},Gg=t=>{const e=[];for(const n of t)if(!(!n?.id||!Array.isArray(n.portForwards)))for(const r of n.portForwards){const a=Yj(n,r);a&&e.push(a)}return e},Xj=(t,e)=>{const n=(t||"").trim();return n&&Gg(e).find(i=>i.id===n)?.url||null},Zj=[{pattern:/^dev(:.*)?$/i},{pattern:/^start(:.*)?$/i},{pattern:/^preview(:.*)?$/i},{pattern:/^serve(:.*)?$/i},{pattern:/^develop(:.*)?$/i}],e0=["dev","start","preview","serve"];async function t0(t,e,n){if(!t)return null;const r=r0(e);if(r)return{command:r.command,label:r.name||"Start Preview",actionId:r.id};if(n){const a=a0(n);if(a){const i=await i0(t);return{command:`${i==="npm"?"npm run":i==="yarn"?"yarn":i==="pnpm"?"pnpm":i==="bun"?"bun run --shell=bun":"npm run"} ${a}`,label:`Start (${a})`}}}if(await s0(t)){const a=await n0(),i=typeof a=="number"&&Number.isFinite(a)&&a>0?a:8e3;return{command:`python3 -m http.server ${i}`,label:"Static preview",previewUrlHint:`http://127.0.0.1:${i}/`}}return null}async function s0(t){const e=`${t}/index.html`,n=await Yl(e);return typeof n=="string"&&n.trim().length>0}async function n0(){try{const t=await fetch("/api/system/free-port",{cache:"no-store"});if(!t.ok)return null;const e=await t.json().catch(()=>null),n=typeof e?.port=="number"?e.port:null;return n&&Number.isFinite(n)?n:null}catch{return null}}function r0(t){for(const e of t){const n=`${e.name} ${e.command}`.toLowerCase();if(e0.some(a=>n.includes(a)))return e}return t.length===1?t[0]:null}function a0(t){for(const{pattern:e}of Zj)for(const n of Object.keys(t))if(e.test(n))return n;return null}async function i0(t){const e=await Yl(`${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 Yl(`${t}/${r}`);if(typeof i=="string"&&i.trim().length>0)return a}return"npm"}async function Yl(t){const e=xr()?.files;if(e?.readFile)try{const n=await e.readFile(t,{optional:!0});return typeof n?.content=="string"?n.content:null}catch{return null}try{const n=await fetch(`/api/fs/read?path=${encodeURIComponent(t)}&optional=true`,{cache:"no-store"});return n.ok?n.text():null}catch{return null}}async function o0(t){try{const e=await Yl(`${t}/package.json`);return e==null?null:JSON.parse(e).scripts||null}catch{return null}}const l0=t=>new Promise(e=>{window.setTimeout(e,t)}),c0="\x1B",d0=new RegExp(`${c0}\\[[0-9;?]*[ -/]*[@-~]`,"g"),u0=/https?:\/\/[^\s<>'"`]+/gi,mr="__openchamber_auto_discover_preview__",m0=15e3,p0=t=>{let e="";for(let n=0;n<t.length;n+=1){const r=t.charCodeAt(n);r>=0&&r<=8||r===11||r===12||r>=14&&r<=31||r===127||(e+=t[n])}return e},f0=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}},h0=t=>{const n=t.replace(d0,"").match(u0);if(!n||n.length===0)return null;const r=n.map(i=>i.replace(/[),.;]+$/,"")).filter(Boolean);if(r.length===0)return null;const a=[];for(const i of r)try{const o=new URL(i);o.port&&o.port.length>0&&a.push({raw:i,parsed:o})}catch{}if(a.length>0){const i=o=>{const{parsed:c}=o,d=c.hostname.toLowerCase(),p=d==="localhost"||d==="127.0.0.1"||d==="0.0.0.0"||d==="::1",m=c.pathname||"/",u=m.split("/").filter(Boolean).length,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},g0=(t,e)=>{const n=t.trim();if(!n)return e;const r=n.split(/\s+/).filter(Boolean);if(r.length>=2){const a=r[0],i=r[1].slice(0,3),o=`${a} ${i}`.trim();return r.length>2||o.length<n.length?`${o}...`:o}return n.length>12?`${n.slice(0,9).trimEnd()}...`:n},np=({projectRef:t,directory:e,className:n,compact:r=!1,allowMobile:a=!1})=>{const{t:i}=ut(),{terminal:o,runtime:c}=Gn(),{isMobile:d}=un(),p=l.useMemo(()=>kn(),[]),m=tn(G=>G.instances),u=tn(G=>G.load),h=Te(G=>G.setBottomTerminalOpen),b=Te(G=>G.setActiveMainTab),f=Te(G=>G.setSettingsPage),y=Te(G=>G.setSettingsDialogOpen),x=Te(G=>G.setSettingsProjectsSelectedId),g=Te(G=>G.openContextPreview),w=gn(G=>G.sessions),v=gn(G=>G.ensureDirectory),S=gn(G=>G.setTabLabel),A=gn(G=>G.setTabIconKey),j=gn(G=>G.setActiveTab),C=gn(G=>G.setConnecting),I=gn(G=>G.setTabSessionId),R=gn(G=>G.setTabPreviewUrl),k=gn(G=>G.projectActionRuns),P=gn(G=>G.setProjectActionRun),N=gn(G=>G.updateProjectActionRunStatus),D=gn(G=>G.removeProjectActionRun),[T,M]=l.useState([]),[$,F]=l.useState(null),[V,O]=l.useState(!1),L=l.useRef({}),W=l.useRef({}),B=l.useRef({}),ne=l.useRef({}),le=l.useRef(0),ee=t?.id??null,ae=t?.path??"",ge=l.useMemo(()=>ee?{id:ee,path:ae}:null,[ee,ae]);l.useEffect(()=>{p&&u().catch(()=>{})},[p,u]);const te=l.useCallback(async G=>{await lr(G)},[]),E=l.useCallback(async()=>{if(!ge)return;const G=le.current+1;le.current=G,O(!0);try{const be=await Ld(ge);if(le.current!==G)return;const De=be.actions;M(De),F(Ae=>Ae===mr||Ae&&De.some(ve=>ve.id===Ae)?Ae:null)}catch{if(le.current!==G)return}finally{le.current===G&&O(!1)}},[ge]),z=l.useMemo(()=>Hg(e||ge?.path||""),[e,ge?.path]),J=l.useMemo(()=>$?T.find(G=>G.id===$)??null:null,[T,$]),H=l.useMemo(()=>({id:mr,name:i("projectActions.actions.autoDiscover"),command:"",icon:"search",autoOpenUrl:!0}),[i]),re=!d,ce=l.useMemo(()=>re?[H,...T]:T,[T,H,re]);l.useEffect(()=>{E()},[E]),l.useEffect(()=>{if(typeof window>"u")return;const G=be=>{const De=be.detail;ee&&(De?.projectId&&De.projectId!==ee||E())};return window.addEventListener(Kd,G),()=>{window.removeEventListener(Kd,G)}},[E,ee]),l.useEffect(()=>{$&&($===mr&&re||T.some(G=>G.id===$)||F(null))},[T,re,$]),l.useEffect(()=>{for(const[G,be]of Object.entries(k)){const Ae=w.get(be.directory)?.tabs.find(ve=>ve.id===be.tabId);(!Ae||Ae.terminalSessionId!==be.sessionId)&&D(G)}},[k,D,w]),l.useEffect(()=>{for(const[G,be]of Object.entries(k)){const De=W.current[G]??{lastSeenChunkId:null,openedUrl:!1,tail:"",openInPreview:!1};W.current[G]=De;const Ae=ce.find(K=>K.id===be.actionId);if(!Ae)continue;const U=w.get(be.directory)?.tabs.find(K=>K.id===be.tabId);if(!U||!Array.isArray(U.bufferChunks)||U.bufferChunks.length===0)continue;const de=U.bufferChunks.filter(K=>De.lastSeenChunkId===null?!0:K.id>De.lastSeenChunkId);if(de.length===0)continue;const Re=de.map(K=>K.data).join(""),Le=`${De.tail}${Re}`,se=!De.openedUrl&&Ae.autoOpenUrl===!0?h0(Le):null,ie=de[de.length-1]?.id??De.lastSeenChunkId;if(De.lastSeenChunkId=ie,De.tail=Le.slice(-512),se)if(De.openedUrl=!0,De.openInPreview){const K=k[G];K&&(R(K.directory,K.tabId,se,{locked:!1,autoOpened:!1}),K.status==="waiting-for-preview"&&N(G,"running"),window.clearTimeout(ne.current[G]),delete ne.current[G],g(K.directory,se))}else te(se),q.success(i("projectActions.toast.openedUrlFromOutput"));W.current[G]=De}for(const G of Object.keys(W.current))k[G]||(delete W.current[G],window.clearTimeout(ne.current[G]),delete ne.current[G])},[ce,g,te,k,R,i,w,N]);const Ne=l.useCallback(async(G,be={})=>{if(!z)throw new Error(i("projectActions.error.noActiveDirectory"));const De=ga(z,G.id);v(z);const Ae=gn.getState(),ve=Ae.getDirectoryState(z);let U=L.current[De]||null;const de=U?!!ve?.tabs.some(se=>se.id===U):!1;(!U||!de)&&(U=Ae.createTab(z),L.current[De]=U),S(z,U,`Action: ${G.name}`),A(z,U,G.icon||"play"),be.revealTerminal!==!1&&(j(z,U),h(!0),b("terminal"));const Le=gn.getState().getDirectoryState(z)?.tabs.find(se=>se.id===U);return{key:De,tabId:U,sessionId:Le?.terminalSessionId??null}},[v,z,b,j,h,A,S,i]),me=l.useCallback(async G=>{if(c.isVSCode||!a&&d)return;if(!z){q.error(i("projectActions.error.noActiveDirectoryForAction"));return}const be=ga(z,G.id),De=k[be];if(!(De&&De.status==="running"))try{const Ae=G.id===mr?await(async()=>{const[Ke,Ze]=await Promise.all([Ld({id:ge?.id??"",path:z}),o0(z)]),Xe=await t0(z,Ke.actions,Ze);if(!Xe)throw new Error(i("contextPanel.preview.noDevServer"));return{id:mr,name:i("projectActions.actions.autoDiscover"),command:Xe.command,icon:"search",autoOpenUrl:!0,openUrl:Xe.previewUrlHint||""}})():G,ve=Ae.autoOpenUrl===!0&&(Ae.openUrl||"").trim().length>0,{key:U,tabId:de,sessionId:Re}=await Ne(Ae,{revealTerminal:!ve&&G.id!==mr});let Le=Re,se=!1;if(!Le){C(z,de,!0);try{Le=(await o.createSession({cwd:z})).sessionId,se=!0,I(z,de,Le)}finally{C(z,de,!1)}}if(!Le)throw new Error(i("projectActions.error.failedToCreateTerminalSession"));se&&await l0(350),Ae.id===mr&&(B.current[U]?.(),C(z,de,!0),B.current[U]=fv(Le,Ke=>{Ke.type==="data"&&typeof Ke.data=="string"&&Ke.data.length>0&&gn.getState().appendToBuffer(z,de,Ke.data),Ke.type==="exit"&&(gn.getState().setTabLifecycle(z,de,"exited"),gn.getState().setConnecting(z,de,!1),gn.getState().removeProjectActionRun(U),delete W.current[U],B.current[U]?.(),delete B.current[U],window.clearTimeout(ne.current[U]),delete ne.current[U])},()=>{gn.getState().setConnecting(z,de,!1)},{maxRetries:60,initialRetryDelay:250,maxRetryDelay:2e3,connectionTimeout:5e3}));const ie=Ae.autoOpenUrl===!0&&p&&(Ae.desktopOpenSshForward||"").trim().length>0,K=Ae.autoOpenUrl?f0(Ae.openUrl):null,_e=Ae.autoOpenUrl&&p?Xj(Ae.desktopOpenSshForward,m):null;P({key:U,directory:z,actionId:Ae.id,tabId:de,sessionId:Le,status:Ae.id===mr&&!K?"waiting-for-preview":"running"}),window.clearTimeout(ne.current[U]),delete ne.current[U],Ae.id===mr&&!K&&(ne.current[U]=window.setTimeout(()=>{gn.getState().updateProjectActionRunStatus(U,"running"),delete ne.current[U]},m0)),_e?(R(z,de,null,{locked:!0}),te(_e),q.success(i("projectActions.toast.openedForwardedUrl"))):K?(R(z,de,K,{locked:!0,autoOpened:!0}),g(z,K),q.success(i("projectActions.toast.openedActionUrl"))):ve?(R(z,de,null,{locked:!0}),q.error(i("projectActions.error.invalidCustomUrlFormat"))):ie?(R(z,de,null,{locked:!0}),q.error(i("projectActions.error.selectedDesktopSshForwardUnavailable"))):R(z,de,null,{locked:!1,autoOpened:!1}),W.current[U]={lastSeenChunkId:null,openedUrl:!!_e||!!K||ve,tail:"",openInPreview:Ae.id===mr};const He=p0(Ae.command.trim().replace(/\r\n|\r/g,`
3
- `));await o.sendInput(Le,`${He}\r`)}catch(Ae){D(be),delete W.current[be],B.current[be]?.(),delete B.current[be],window.clearTimeout(ne.current[be]),delete ne.current[be],q.error(Ae instanceof Error?Ae.message:i("projectActions.error.failedToRunAction"))}},[m,Ne,a,d,p,z,te,g,k,c.isVSCode,D,C,P,R,I,ge?.id,i,o]),we=l.useCallback(async G=>{const be=ga(z,G.id),De=k[be];if(!De)return;N(be,"stopping");try{await o.sendInput(De.sessionId,"")}catch{}if(await new Promise(U=>{window.setTimeout(U,1e3)}),gn.getState().getDirectoryState(De.directory)?.tabs.find(U=>U.id===De.tabId)?.terminalSessionId===De.sessionId){if(typeof o.forceKill=="function")try{await o.forceKill({sessionId:De.sessionId})}catch{}else try{await o.close(De.sessionId)}catch{}I(De.directory,De.tabId,null)}D(be),delete W.current[be],B.current[be]?.(),delete B.current[be],window.clearTimeout(ne.current[be]),delete ne.current[be]},[z,k,D,I,o,N]),_=l.useCallback(()=>{const G=J??ce[0];if(!G)return;const be=ga(z,G.id),De=k[be];if(De?.status!=="stopping"){if(De){we(G);return}me(G)}},[ce,z,me,k,J,we]),ue=l.useCallback((G,be=!1)=>{if(F(G.id),!be){me(G);return}const De=ga(z,G.id),Ae=k[De];if(Ae?.status!=="stopping"){if(Ae){we(G);return}me(G)}},[z,me,k,we]),Q=l.useCallback(()=>{ge?.id&&(x(ge.id),f("projects"),y(!0))},[y,f,x,ge?.id]);if(c.isVSCode||!a&&d||!ge||!z)return null;const oe=J??ce[0]??null;if(!oe)return null;const Z=oe.icon||"play",Ie=oe.id===mr?Hn:Al[Z]||Wr,Se=g0(oe.name,i("projectActions.label.fallbackAction")),Y=ga(z,oe.id),fe=k[Y],ke=fe?.status==="stopping",xe=fe?.status==="waiting-for-preview",he=fe?w.get(fe.directory)?.tabs.find(G=>G.id===fe.tabId)?.previewUrl??null:null,Pe=!!(fe&&he),Be=()=>{!fe||!he||g(fe.directory,he)};return r?s.jsxs("div",{className:"inline-flex items-center",children:[s.jsx("button",{type:"button",disabled:V||ke,className:pe("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:_,"aria-label":fe?i("projectActions.actions.stopNamedAria",{name:oe.name}):i("projectActions.actions.runNamedAria",{name:oe.name}),children:ke||xe?s.jsx(Zt,{className:"h-5 w-5 animate-spin text-[var(--status-warning)]"}):fe?s.jsx(Kr,{className:"h-5 w-5 text-[var(--status-warning)]"}):s.jsx(Ie,{className:"h-5 w-5"})}),Pe?s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx("button",{type:"button",className:"app-region-no-drag -ml-1 inline-flex h-9 w-7 items-center justify-center rounded-[10px] text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":i("projectActions.actions.openPreview"),onClick:Be,children:s.jsx(ti,{className:"h-4 w-4"})})}),s.jsx(Ct,{sideOffset:6,children:i("projectActions.actions.openPreview")})]}):null,s.jsxs(zs,{children:[s.jsx(Bs,{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(Cs,{className:"h-3.5 w-3.5"})})}),s.jsxs(Vs,{align:"end",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs($t,{className:"flex items-center gap-2",onClick:Q,children:[s.jsx(_s,{className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("projectActions.actions.addNewAction")})]}),s.jsx(En,{}),ce.map(G=>{const be=G.icon||"play",De=G.id===mr?Hn:Al[be]||Wr,Ae=ga(z,G.id),ve=k[Ae],U=!!ve,de=ve?.status==="stopping";return s.jsxs($t,{className:"flex items-center gap-2",onClick:()=>{ue(G,!0)},children:[s.jsx(De,{className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:G.name}),de||ve?.status==="waiting-for-preview"?s.jsx(Zt,{className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):U?s.jsx(Kr,{className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},G.id)})]})]})]}):s.jsxs("div",{className:pe("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:_,disabled:V||ke,className:pe("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:oe.name}):i("projectActions.actions.runNamedAria",{name:oe.name}),children:[s.jsx("span",{className:"inline-flex h-4 w-4 shrink-0 items-center justify-center",children:ke||xe?s.jsx(Zt,{className:"h-4 w-4 animate-spin text-[var(--status-warning)]"}):fe?s.jsx(Kr,{className:"h-4 w-4 text-[var(--status-warning)]"}):s.jsx(Ie,{className:"h-4 w-4"})}),r?null:s.jsx("span",{className:"header-open-label whitespace-nowrap",children:Se})]}),Pe?s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Be,className:pe(r?"inline-flex h-full w-8 items-center justify-center":"inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-foreground","hover:bg-interactive-hover transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),"aria-label":i("projectActions.actions.openPreview"),children:s.jsx(ti,{className:"h-4 w-4"})})}),s.jsx(Ct,{sideOffset:6,children:i("projectActions.actions.openPreview")})]}):null,s.jsxs(zs,{children:[s.jsx(Bs,{asChild:!0,children:s.jsx("button",{type:"button",className:pe(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(Cs,{className:"h-4 w-4"})})}),s.jsxs(Vs,{align:"center",className:"w-52 max-h-[70vh] overflow-y-auto",style:{translate:"-30px 0"},children:[s.jsxs($t,{className:"flex items-center gap-2",onClick:Q,children:[s.jsx(_s,{className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("projectActions.actions.addNewAction")})]}),s.jsx(En,{}),ce.map(G=>{const be=G.icon||"play",De=G.id===mr?Hn:Al[be]||Wr,Ae=ga(z,G.id),ve=k[Ae],U=!!ve,de=ve?.status==="stopping";return s.jsxs($t,{className:"flex items-center gap-2",onClick:()=>{ue(G)},children:[s.jsx(De,{className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:G.name}),de||ve?.status==="waiting-for-preview"?s.jsx(Zt,{className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):U?s.jsx(Kr,{className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},G.id)})]})]})]})},wc="app-region-no-drag inline-flex h-8 w-8 items-center justify-center gap-2 rounded-md typography-ui-label font-medium text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:pointer-events-none disabled:opacity-50 hover:bg-interactive-hover transition-colors",x0="app-region-no-drag inline-flex h-9 w-9 items-center justify-center gap-2 p-2 rounded-md typography-ui-label font-medium text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:pointer-events-none disabled:opacity-50 hover:text-foreground hover:bg-interactive-hover transition-colors",al=l.memo(function(e){const n=nt.c(13),{visible:r,title:a,ariaLabel:i,onClick:o,className:c,Icon:d,iconClassName:p}=e;if(!(r===void 0?!0:r))return null;const u=c??wc,h=p??"h-[18px] w-[18px]";let b;n[0]!==d||n[1]!==h?(b=s.jsx(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(St,{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 y;n[8]!==a?(y=s.jsx(Ct,{children:s.jsx("p",{children:a})}),n[8]=a,n[9]=y):y=n[9];let x;return n[10]!==f||n[11]!==y?(x=s.jsxs(kt,{children:[f,y]}),n[10]=f,n[11]=y,n[12]=x):x=n[12],x}),b0=l.memo(function(e){const n=nt.c(42),{isMobile:r,githubAuthStatus:a,githubAccounts:i,githubAvatarUrl:o,githubLogin:c,isSwitchingGitHubAccount:d,handleGitHubAccountSwitch:p}=e,{t:m}=ut();if(!a?.connected||r)return null;if(i.length>1){let f;n[0]===Symbol.for("react.memo_cache_sentinel")?(f=pe(wc,"h-7 w-7 overflow-hidden rounded-full border border-border/60 bg-muted/80 p-0"),n[0]=f):f=n[0];let y;n[1]!==c||n[2]!==m?(y=c?m("header.github.connectedWithLogin",{login:c}):m("header.github.connected"),n[1]=c,n[2]=m,n[3]=y):y=n[3];let 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(wa,{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]!==y||n[10]!==x?(g=s.jsx(Bs,{asChild:!0,children:s.jsx("button",{type:"button",className:f,title:y,disabled:d,children:x})}),n[8]=d,n[9]=y,n[10]=x,n[11]=g):g=n[11];let w;n[12]!==m?(w=m("header.github.accountsTitle"),n[12]=m,n[13]=w):w=n[13];let v;n[14]!==w?(v=s.jsx(wo,{className:"typography-ui-header font-semibold text-foreground",children:w}),n[14]=w,n[15]=v):v=n[15];let S;n[16]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsx(En,{}),n[16]=S):S=n[16];let A;if(n[17]!==i||n[18]!==p||n[19]!==d||n[20]!==m){let I;n[22]!==p||n[23]!==d||n[24]!==m?(I=R=>{const k=R.user,P=!!R.current;return s.jsxs($t,{className:"gap-2",disabled:P||d,onSelect:()=>{P||p(R.id)},children:[k?.avatarUrl?s.jsx("img",{src:k.avatarUrl,alt:k.login?m("header.github.avatarWithLogin",{login:k.login}):m("header.github.avatar"),className:"h-6 w-6 rounded-full border border-border/60 bg-muted object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-6 w-6 items-center justify-center rounded-full border border-border/60 bg-muted",children:s.jsx(wa,{className:"h-3 w-3 text-muted-foreground"})}),s.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:k?.name?.trim()||k?.login||"GitHub"}),k?.login?s.jsx("span",{className:"truncate typography-micro font-mono text-muted-foreground",children:k.login}):null]}),P?s.jsx(Ys,{className:"h-4 w-4 text-primary"}):null]},R.id)},n[22]=p,n[23]=d,n[24]=m,n[25]=I):I=n[25],A=i.map(I),n[17]=i,n[18]=p,n[19]=d,n[20]=m,n[21]=A}else A=n[21];let j;n[26]!==v||n[27]!==A?(j=s.jsxs(Vs,{align:"end",className:"w-64",children:[v,S,A]}),n[26]=v,n[27]=A,n[28]=j):j=n[28];let C;return n[29]!==g||n[30]!==j?(C=s.jsxs(zs,{children:[g,j]}),n[29]=g,n[30]=j,n[31]=C):C=n[31],C}let u;n[32]!==c||n[33]!==m?(u=c?m("header.github.connectedWithLogin",{login:c}):m("header.github.connected"),n[32]=c,n[33]=m,n[34]=u):u=n[34];let 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(wa,{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}),y0=l.memo(function(e){const n=nt.c(76),{isDesktopApp:r,currentInstanceLabel:a,compactCurrentInstanceLabel:i,isDesktopServicesOpen:o,setIsDesktopServicesOpen:c,refreshCurrentInstanceLabel:d,desktopServicesTab:p,setDesktopServicesTab:m,quotaResultsLength:u,fetchAllQuotas:h,servicesTabItems:b,quotaLastUpdated:f,quotaDisplayMode:y,quotaDisplayTabItems:x,handleDisplayModeChange:g,handleUsageRefresh:w,isQuotaLoading:v,isUsageRefreshSpinning:S,hasRateLimits:A,rateLimitGroups:j,expandedFamilies:C,toggleFamilyExpanded:I,shortcutLabel:R,showDevShutdown:k,isDevShutdownInFlight:P,onDevShutdown:N}=e,{t:D}=ut();let T;n[0]!==p||n[1]!==h||n[2]!==u||n[3]!==d||n[4]!==c?(T=H=>{c(H),H&&(d(),p==="usage"&&u===0&&h())},n[0]=p,n[1]=h,n[2]=u,n[3]=d,n[4]=c,n[5]=T):T=n[5];let M;n[6]!==a||n[7]!==r||n[8]!==D?(M=r?D("header.services.openWithCurrent",{current:a}):D("header.services.open"),n[6]=a,n[7]=r,n[8]=D,n[9]=M):M=n[9];const $=r?"w-auto max-w-[14rem] justify-start gap-1.5 px-2.5":"h-8 w-8";let F;n[10]!==$?(F=pe(wc,$),n[10]=$,n[11]=F):F=n[11];let V;n[12]===Symbol.for("react.memo_cache_sentinel")?(V=s.jsx(Sa,{className:"h-[18px] w-[18px]"}),n[12]=V):V=n[12];let O;n[13]!==i||n[14]!==r?(O=r?s.jsx("span",{className:"truncate typography-ui-label font-medium text-foreground",children:i}):null,n[13]=i,n[14]=r,n[15]=O):O=n[15];let L;n[16]!==M||n[17]!==F||n[18]!==O?(L=s.jsx(St,{asChild:!0,children:s.jsx(Bs,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":M,className:F,children:[V,O]})})}),n[16]=M,n[17]=F,n[18]=O,n[19]=L):L=n[19];let W;n[20]!==a||n[21]!==r||n[22]!==R||n[23]!==D?(W=r?D("header.services.tooltip.currentInstanceWithShortcuts",{current:a,toggle:R("toggle_services_menu"),nextTab:R("cycle_services_tab")}):D("header.services.tooltip.servicesWithShortcuts",{toggle:R("toggle_services_menu"),nextTab:R("cycle_services_tab")}),n[20]=a,n[21]=r,n[22]=R,n[23]=D,n[24]=W):W=n[24];let B;n[25]!==W?(B=s.jsx(Ct,{children:s.jsx("p",{children:W})}),n[25]=W,n[26]=B):B=n[26];let ne;n[27]!==L||n[28]!==B?(ne=s.jsxs(kt,{children:[L,B]}),n[27]=L,n[28]=B,n[29]=ne):ne=n[29];let le;n[30]!==h||n[31]!==u||n[32]!==m?(le=H=>{const re=H;m(re),re==="usage"&&u===0&&h()},n[30]=h,n[31]=u,n[32]=m,n[33]=le):le=n[33];let ee;n[34]!==p||n[35]!==b||n[36]!==le?(ee=s.jsx("div",{className:"sticky top-0 z-20 px-2 pt-1.5 pb-px",children:s.jsx("div",{className:"h-9",children:s.jsx(Br,{items:b,activeId:p,onSelect:le,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]=le,n[37]=ee):ee=n[37];let ae;n[38]!==p||n[39]!==r||n[40]!==o||n[41]!==c?(ae=r&&p==="instance"?s.jsx(Nv,{embedded:!0,open:o&&p==="instance",onOpenChange:j0,onHostSwitched:()=>c(!1)}):null,n[38]=p,n[39]=r,n[40]=o,n[41]=c,n[42]=ae):ae=n[42];let ge;n[43]!==p||n[44]!==o?(ge=p==="mcp"?s.jsx(Ug,{active:o&&p==="mcp"}):null,n[43]=p,n[44]=o,n[45]=ge):ge=n[45];let te;n[46]!==p||n[47]!==C||n[48]!==g||n[49]!==w||n[50]!==A||n[51]!==v||n[52]!==S||n[53]!==y||n[54]!==x||n[55]!==f||n[56]!==j||n[57]!==D||n[58]!==I?(te=p==="usage"?s.jsxs("div",{className:"overflow-x-hidden",children:[s.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-[var(--interactive-border)] px-4 py-2.5",children:[s.jsxs("div",{className:"flex min-w-0 items-baseline gap-2",children:[s.jsx("span",{className:"typography-ui-header font-semibold text-foreground",children:D("header.services.rateLimits")}),s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:qg(f)})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("div",{className:"h-7 w-[10.5rem]",children:s.jsx(Br,{items:x,activeId:y,onSelect:H=>{g(H)},layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",className:"h-full"})}),s.jsx("button",{type:"button",className:pe("inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors","hover:text-foreground hover:bg-interactive-hover","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),onClick:w,disabled:v||S,"aria-label":D("header.services.refreshRateLimitsAria"),children:s.jsx(Nn,{className:pe("h-4 w-4",S&&"animate-spin")})})]})]}),A?null:s.jsx("div",{className:"px-4 py-5 text-center",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:D("header.services.noRateLimits")})}),s.jsx("div",{className:"py-2",children:j.map((H,re)=>{const ce=C[H.providerId]??[];return s.jsxs(l.Fragment,{children:[re>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(Bn,{providerId:H.providerId,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:H.providerName})]}),H.entries.length===0&&(!H.modelFamilies||H.modelFamilies.length===0)?s.jsx("div",{className:"px-4 pb-2",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:H.error??D("header.services.noRateLimitsReported")})}):s.jsxs("div",{className:"space-y-3 px-4 pb-2",children:[H.entries.map(Ne=>{const[me,we]=Ne,_=y==="remaining"?we.remainingPercent:we.usedPercent,ue=Eo(we.usedPercent,we.resetAt,we.windowSeconds,me),Q=ue?.dailyAllocationPercent!=null?y==="remaining"?100-aa(ue.elapsedRatio):aa(ue.elapsedRatio):null,oe=Ro(we.valueLabel,_);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:_u(me)}),we.resetAfterFormatted??we.resetAtFormatted?s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:we.resetAfterFormatted??we.resetAtFormatted}):null]}),s.jsx("span",{className:"typography-ui-label tabular-nums text-foreground",children:oe==="-"?"":oe})]}),s.jsx(Oo,{percent:_,tonePercent:we.usedPercent,className:"h-1.5",expectedMarkerPercent:Q}),ue?s.jsx(Lo,{paceInfo:ue,compact:!0}):null]},`${H.providerId}-${me}`)}),H.modelFamilies&&H.modelFamilies.length>0?s.jsx("div",{className:"space-y-0.5",children:H.modelFamilies.map(Ne=>{const me=Ne.familyId??"other",we=ce.includes(me);return s.jsxs(yr,{open:we,onOpenChange:()=>I(H.providerId,me),children:[s.jsxs(Mr,{className:"flex w-full items-center justify-between rounded-md px-1 py-1.5 text-left hover:bg-[var(--interactive-hover)]/50 transition-colors",children:[s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:Ne.familyLabel}),we?s.jsx(Cs,{className:"h-4 w-4 text-muted-foreground"}):s.jsx(Fn,{className:"h-4 w-4 text-muted-foreground"})]}),s.jsx(vr,{children:s.jsx("div",{className:"space-y-2.5 pb-1 pl-1 pt-1",children:Ne.models.map(_=>{const[ue,Q]=_,oe=y==="remaining"?Q.remainingPercent:Q.usedPercent,Z=Eo(Q.usedPercent,Q.resetAt,Q.windowSeconds),Ie=Z?.dailyAllocationPercent!=null?y==="remaining"?100-aa(Z.elapsedRatio):aa(Z.elapsedRatio):null,Se=Ro(Q.valueLabel,oe);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:Ql(ue)}),s.jsx("span",{className:"typography-ui-label tabular-nums text-foreground",children:Se==="-"?"":Se})]}),s.jsx(Oo,{percent:oe,tonePercent:Q.usedPercent,className:"h-1.5",expectedMarkerPercent:Ie}),Z?s.jsx(Lo,{paceInfo:Z,compact:!0}):null]},`${H.providerId}-${ue}`)})})})]},me)})}):null]})]},H.providerId)})})]}):null,n[46]=p,n[47]=C,n[48]=g,n[49]=w,n[50]=A,n[51]=v,n[52]=S,n[53]=y,n[54]=x,n[55]=f,n[56]=j,n[57]=D,n[58]=I,n[59]=te):te=n[59];let E;n[60]!==P||n[61]!==N||n[62]!==k||n[63]!==D?(E=k?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"mx-4 my-2 border-t border-[var(--interactive-border)]"}),s.jsx("div",{className:"px-2 pb-2",children:s.jsx($t,{disabled:P,onSelect:()=>{N()},children:D("header.services.shutdownDev")})})]}):null,n[60]=P,n[61]=N,n[62]=k,n[63]=D,n[64]=E):E=n[64];let z;n[65]!==ee||n[66]!==ae||n[67]!==ge||n[68]!==te||n[69]!==E?(z=s.jsxs(Vs,{align:"end",className:"w-[min(27rem,calc(100vw-2rem))] max-h-[75vh] overflow-y-auto bg-[var(--surface-elevated)] p-0",children:[ee,ae,ge,te,E]}),n[65]=ee,n[66]=ae,n[67]=ge,n[68]=te,n[69]=E,n[70]=z):z=n[70];let J;return n[71]!==o||n[72]!==T||n[73]!==ne||n[74]!==z?(J=s.jsxs(zs,{open:o,onOpenChange:T,children:[ne,z]}),n[71]=o,n[72]=T,n[73]=ne,n[74]=z,n[75]=J):J=n[75],J}),v0=(t,e)=>t===e?!0:!t||!e?!1:t.totalTokens===e.totalTokens&&t.percentage===e.percentage&&t.contextLimit===e.contextLimit&&(t.outputLimit??0)===(e.outputLimit??0)&&(t.normalizedOutput??0)===(e.normalizedOutput??0)&&t.thresholdLimit===e.thresholdLimit&&(t.lastMessageId??"")===(e.lastMessageId??""),w0=t=>{const e=t.trim();if(!e)return"";const n=e.split(/\s+/).filter(Boolean);if(n.length>=2){const r=n[0],a=n[1].slice(0,3),i=`${r} ${a}`.trim();return n.length>2||i.length<e.length?`${i}...`:i}return e.length>12?`${e.slice(0,9).trimEnd()}...`:e},qg=t=>{if(!t)return"-";try{return new Date(t).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"})}catch{return"-"}},Sr=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},il=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,rp=({onToggleLeftDrawer:t,onToggleRightDrawer:e,leftDrawerOpen:n,rightDrawerOpen:r,desktopRightSidebarActionsHost:a=null})=>{const{t:i}=ut(),o=Te(Fe=>Fe.setSessionSwitcherOpen),c=Te(Fe=>Fe.toggleSidebar),d=Te(Fe=>Fe.isSidebarOpen),p=Te(Fe=>Fe.isRightSidebarOpen),m=Te(Fe=>Fe.toggleBottomTerminal),u=Te(Fe=>Fe.toggleRightSidebar),h=Te(Fe=>Fe.openContextOverview),b=Te(Fe=>Fe.openContextPlan),f=Te(Fe=>Fe.closeContextPanel),y=Te(Fe=>Fe.contextPanelByDirectory),x=Te(Fe=>Fe.activeMainTab),g=Te(Fe=>Fe.setActiveMainTab),w=Te(Fe=>Fe.shortcutOverrides),v=yt(Fe=>Fe.getCurrentModel),S=Gn(),[A,j]=l.useState(!1),C=Wt(Fe=>Fe.getContextUsage),I=Wt(Fe=>Fe.openNewSessionDraft),R=Wt(Fe=>!!Fe.newSessionDraft?.open),k=Wt(Fe=>Fe.currentSessionId),P=Sv(k??""),N=rg(k??null),D=jo(Fe=>Fe.activeSessions),T=ag(),M=Fs(Fe=>Fe.activeProjectId?Fe.projects.find(Nt=>Nt.id===Fe.activeProjectId)??null:null),$=l.useMemo(()=>{if(!M)return null;const Fe=M.label?.trim();if(Fe)return Fe;const Nt=M.path.split(/[\\/]/).filter(Boolean);return Nt[Nt.length-1]??null},[M]),F=$s(Fe=>Fe.results),V=$s(Fe=>Fe.fetchAllQuotas),O=$s(Fe=>Fe.isLoading),L=$s(Fe=>Fe.lastUpdated),W=$s(Fe=>Fe.displayMode),B=$s(Fe=>Fe.dropdownProviderIds),ne=$s(Fe=>Fe.loadSettings),le=$s(Fe=>Fe.setDisplayMode),{isMobile:ee}=un(),ae=Zn(Fe=>Fe.status),ge=Zn(Fe=>Fe.setStatus),te=l.useRef(null),[E,z]=l.useState(()=>typeof window>"u"?!1:kn()),J=l.useMemo(()=>Mu(),[]),H=pc(),[re,ce]=l.useState(!1),Ne=l.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),me=l.useMemo(()=>{if(typeof window>"u")return null;const Fe=window.__OPENCHAMBER_MACOS_MAJOR__;if(typeof Fe=="number"&&Number.isFinite(Fe)&&Fe>0)return Fe;if(typeof navigator>"u")return null;const Nt=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!Nt)return null;const Ht=Number.parseInt(Nt[1],10),cs=Number.parseInt(Nt[2],10);return Number.isNaN(Ht)?null:Ht===10?cs:Ht},[]);Oe.useEffect(()=>{typeof window>"u"||z(kn())},[]);const we=v(),_=we&&typeof we.limit=="object"&&we.limit!==null?we.limit:null,ue=_&&typeof _.context=="number"?_.context:0,Q=_&&typeof _.output=="number"?_.output:0,oe=C(ue,Q),[Z,Ie]=l.useState(null),Se=!k||P;Oe.useEffect(()=>{if(!k){Ie(Fe=>Fe===null?Fe:null);return}if(oe&&oe.totalTokens>0){Ie(Fe=>v0(Fe,oe)?Fe:oe);return}Se&&Ie(Fe=>Fe===null?Fe:null)},[oe,k,Se]);const Y=Te(Fe=>Fe.isSessionSwitcherOpen),fe=ae?.connected?ae.user?.avatarUrl??null:null,ke=ae?.connected?ae.user?.login??null:null,xe=ae?.accounts??[],[he,Pe]=l.useState(!1),[Be,G]=l.useState(!1),[be,De]=l.useState(!1),[Ae,ve]=l.useState(!1),[U,de]=l.useState("Local"),Re=l.useMemo(()=>w0(U),[U]),[Le,se]=l.useState(E?"instance":"usage"),[ie,K]=l.useState("usage");Oe.useEffect(()=>{!E&&Le==="instance"&&se("usage")},[Le,E]);const _e=l.useMemo(()=>yn(),[]),He=l.useMemo(()=>ee?typeof t=="function"?!!n:Y:d,[ee,Y,d,n,t]),Ke=!_e&&x==="chat"&&!!Z&&Z.totalTokens>0,Ze=Z&&Z.contextLimit>0?Math.min(999,Z.totalTokens/Z.contextLimit*100):0,Xe=l.useCallback(async()=>{if(!(typeof window>"u"||!E))try{const Fe=await kv(),Nt=window.location.href,Ht=window.__OPENCHAMBER_LOCAL_ORIGIN__||window.location.origin;if(ym(Nt,Ht)){de("Local");return}const cs=Fe.hosts.find(Xs=>ym(Nt,Xs.url));if(cs?.label?.trim()){de(Cv(cs.label.trim()));return}de("Instance")}catch{de("Local")}},[E]);Oe.useEffect(()=>{Xe()},[Xe]),Vg();const mt=$s(Fe=>Fe.selectedModels),et=$s(Fe=>Fe.expandedFamilies),ct=$s(Fe=>Fe.toggleFamilyExpanded),lt=l.useMemo(()=>{const Fe=[];for(const Nt of Jr){if(!B.includes(Nt.id))continue;const Ht=F.find(en=>en.providerId===Nt.id),cs=Ht?.usage?.windows??{},Xs=Ht?.usage?.models,Zs=Object.entries(cs),Gs={providerId:Nt.id,providerName:Nt.name,entries:Zs,error:Ht&&!Ht.ok&&Ht.configured?Ht.error:void 0};if(Xs&&Object.keys(Xs).length>0){const en=mt[Nt.id]??[],hn=en.length>0,vn=pj(Xs,Nt.id),dr=$g(Nt.id),Zr=Bg(dr);Gs.modelFamilies=[];for(const Ln of Zr){const er=vn.get(Ln.id)??[];if(er.length===0)continue;const bn=hn?er.filter($n=>en.includes($n)):er;if(bn.length===0)continue;const qn=[];for(const $n of bn){const zr=Xs[$n];if(zr?.windows){const _r=Object.entries(zr.windows);_r.length>0&&qn.push([$n,_r[0][1]])}}qn.length>0&&Gs.modelFamilies.push({familyId:Ln.id,familyLabel:Ln.label,models:qn})}const ea=vn.get(null)??[],On=hn?ea.filter(Ln=>en.includes(Ln)):ea;if(On.length>0){const Ln=[];for(const er of On){const bn=Xs[er];if(bn?.windows){const qn=Object.entries(bn.windows);qn.length>0&&Ln.push([er,qn[0][1]])}}Ln.length>0&&Gs.modelFamilies.push({familyId:null,familyLabel:i("header.services.modelFamily.other"),models:Ln})}}(Zs.length>0||Gs.modelFamilies&&Gs.modelFamilies.length>0||Gs.error)&&Fe.push(Gs)}return Fe},[B,F,mt,i]),ye=lt.length>0;l.useEffect(()=>{ne()},[ne]);const Ge=l.useCallback(async Fe=>{le(Fe);try{await Rs({usageDisplayMode:Fe})}catch(Nt){console.warn("Failed to update usage display mode:",Nt)}},[le]),$e=l.useCallback(()=>{if(Ae)return;ve(!0);const Fe=new Promise(Nt=>setTimeout(Nt,500));Promise.all([V(),Fe]).finally(()=>{ve(!1)})},[V,Ae]),Ve=l.useMemo(()=>k?T.find(Fe=>Fe.id===k)??D.find(Fe=>Fe.id===k)??N??Iv().find(Fe=>Fe.id===k)??null:null,[k,N,D,T]),tt=l.useRef(null),[Qe,ze]=l.useState(0);l.useEffect(()=>{if(!k){tt.current&&(tt.current=null,ze(cs=>cs+1));return}if(Ve){tt.current={sessionId:k,session:Ve,expiresAt:Date.now()+2e3};return}const Fe=tt.current;if(!Fe||Fe.sessionId!==k)return;const Nt=Fe.expiresAt-Date.now();if(Nt<=0){tt.current=null,ze(cs=>cs+1);return}const Ht=window.setTimeout(()=>{tt.current?.sessionId===k&&(tt.current=null),ze(cs=>cs+1)},Nt);return()=>{window.clearTimeout(Ht)}},[k,Ve]);const ht=(()=>{if(Ve)return Ve;if(!k)return null;const Fe=tt.current;return Fe&&Fe.sessionId===k&&Fe.expiresAt>Date.now()?Fe.session:null})(),_t=Wt(Fe=>k?Fe.worktreeMetadata.get(k)?.path??"":""),Kt=Wt(Fe=>k?Fe.worktreeMetadata.get(k)?.branch?.trim()??null:null),Ut=ig(Fe=>k?Fe.getAttachment(k):void 0),jt=l.useMemo(()=>Ut?Av(Ut):null,[Ut]),Dt=l.useMemo(()=>Ut?Ut.legacy?"legacy":Ut.degraded?"degraded":Ut.worktreeStatus==="missing"?"missing":Ut.worktreeStatus==="invalid"?"invalid":Ut.attentionReason?"attention":null:null,[Ut]),ts=l.useMemo(()=>Sr(_t||""),[_t]),it=l.useMemo(()=>{const Fe=typeof ht?.directory=="string"?ht.directory:"";return Sr(Fe||"")},[ht?.directory]),Yt=Wt(Fe=>Fe.newSessionDraft?.open?Sr(Fe.newSessionDraft.bootstrapPendingDirectory??Fe.newSessionDraft.directoryOverride??""):""),Qt=l.useMemo(()=>ts||it||Yt,[Yt,it,ts]),Xt=Wt(Fe=>{const Nt=Sr(ts||it||"");if(!Nt)return null;for(const Ht of Fe.availableWorktreesByProject.values()){const Xs=Ht.find(Zs=>Sr(Zs.path)===Nt)?.branch?.trim();if(Xs)return Xs}return null}),ms=Pv(Qt||null)||Kt||Xt,gs=l.useMemo(()=>{if(!k)return $??"OpenChamber";const Fe=ht?.title?.trim();return Fe&&Fe.length>0?Fe:"Untitled Session"},[$,ht?.title,k]),ds=l.useMemo(()=>og(ht?.summary),[ht?.summary]),Ft=l.useMemo(()=>ds||{additions:0,deletions:0},[ds]),Ue=Ft.additions>0||Ft.deletions>0,Tt=l.useMemo(()=>Sr(Qt||M?.path||""),[M?.path,Qt]),At=l.useMemo(()=>M?{id:M.id,path:M.path}:null,[M]),vt=l.useRef(null);l.useEffect(()=>{!At||!Tt||(vt.current={projectRef:At,directory:Tt})},[Tt,At]);const Rt=l.useMemo(()=>At&&Tt?{projectRef:At,directory:Tt}:vt.current,[Tt,At]),ns=Ru(Fe=>Fe.planModeEnabled),As=Wt(Fe=>Fe.isSessionPlanAvailable),ft=ns&&k?As(k):!1,is=ft,es=l.useRef("");l.useEffect(()=>{if(!ns){Te.getState().activeMainTab==="plan"&&Te.getState().setActiveMainTab("chat");return}if(!k)return;const Fe=`${k||"none"}:${it||"none"}:${ht?.time?.created||0}:${ht?.slug||"none"}`;es.current!==Fe&&(es.current=Fe),!ft&&Te.getState().activeMainTab==="plan"&&Te.getState().setActiveMainTab("chat")},[ns,ft,ht?.slug,ht?.time?.created,k,it]);const Ts=l.useCallback(async Fe=>{if(!(!Fe||he)){Pe(!0);try{const Nt=S.github?await S.github.authActivate(Fe):await(async()=>{const Ht=await fetch("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:Fe})}),cs=await Ht.json().catch(()=>null);if(!Ht.ok||!cs)throw new Error(cs?.error||Ht.statusText);return cs})();ge(Nt)}catch(Nt){console.error("Failed to switch GitHub account:",Nt)}finally{Pe(!1)}}},[he,S.github,ge]),Ls=l.useCallback(()=>{if(typeof document>"u")return;const Fe=document.activeElement;if(!Fe)return;const Nt=Fe.tagName;(Nt==="INPUT"||Nt==="TEXTAREA"||Nt==="SELECT"||Fe.isContentEditable)&&Fe.blur()},[]),X=l.useCallback(()=>{if(ee){Ls(),o(!Y);return}c()},[Ls,ee,Y,o,c]),pt=l.useCallback(()=>{g("chat"),o(!1),I()},[I,g,o]),wt=l.useCallback(()=>{Kl("desktop_open_draft_mini_chat_window",{directory:Sr(Qt||M?.path||""),projectId:M?.id??null}).catch(Fe=>{console.warn("[header] failed to open draft mini chat window",Fe)})},[M?.id,M?.path,Qt]),zt=l.useCallback(()=>{k&&Kl("desktop_open_session_mini_chat_window",{sessionId:k,directory:Sr(Qt||M?.path||"")}).catch(Fe=>{console.warn("[header] failed to open session mini chat window",Fe)})},[M?.path,k,Qt]),ss=l.useCallback(()=>{const Fe=Sr(Qt||"");if(!Fe)return;const Nt=y[Fe];if(il(Nt)==="context"){f(Fe);return}h(Fe)},[f,y,h,Qt]),os=l.useMemo(()=>{const Fe=Sr(Qt||"");if(!Fe)return!1;const Nt=y[Fe];return il(Nt)==="context"},[y,Qt]),Ps=l.useCallback(()=>{const Fe=Sr(Qt||"");if(!Fe)return;const Nt=y[Fe];if(il(Nt)==="plan"){f(Fe);return}b(Fe)},[f,y,b,Qt]),Ms=l.useMemo(()=>{const Fe=Sr(Qt||"");if(!Fe)return!1;const Nt=y[Fe];return il(Nt)==="plan"},[y,Qt]),We=wc,gt=x0,Mt=l.useMemo(()=>!d&&(E&&Ne&&!re||H)?"pl-[5.5rem]":"pl-3",[E,re,Ne,d,H]);Oe.useEffect(()=>{if(!E||!Ne){ce(!1);return}let Fe=!1,Nt=null;const Ht=async()=>{try{const{getCurrentWindow:Xs}=await Tr(async()=>{const{getCurrentWindow:en}=await import("./vendor-.bun-kY4nnc4l.js").then(hn=>hn.fc);return{getCurrentWindow:en}},__vite__mapDeps([0,1])),Gs=await Xs().isFullscreen();Fe||ce(Gs)}catch{Fe||ce(!1)}},cs=async()=>{try{const{getCurrentWindow:Xs}=await Tr(async()=>{const{getCurrentWindow:Gs}=await import("./vendor-.bun-kY4nnc4l.js").then(en=>en.fc);return{getCurrentWindow:Gs}},__vite__mapDeps([0,1]));Nt=await Xs().onResized(()=>{Ht()})}catch{}};return Ht(),cs(),()=>{Fe=!0,Nt&&Nt()}},[E,Ne]);const Et=l.useMemo(()=>!E||!Ne||me===null?"":me>=26?"h-12":me<=15?"h-14":"",[E,Ne,me]),as=l.useMemo(()=>{if(!(E||_e))return{paddingLeft:H&&!d?"max(calc(0.75rem + var(--oc-wco-left-inset, 0px)), 5.5rem)":"calc(0.75rem + var(--oc-wco-left-inset, 0px))",paddingRight:"calc(0.75rem + var(--oc-wco-right-inset, 0px))",minHeight:"max(3rem, var(--oc-wco-titlebar-height, 0px))",height:"max(3rem, var(--oc-wco-titlebar-height, 0px))"}},[E,d,H,_e]),st=l.useCallback(()=>{if(typeof document>"u")return;const Fe=te.current?.getBoundingClientRect().height;Fe&&document.documentElement.style.setProperty("--oc-header-height",`${Fe}px`)},[]);Oe.useEffect(()=>{if(typeof window>"u")return;st();const Fe=te.current;if(!Fe||typeof ResizeObserver>"u")return()=>{};let Nt=0;const Ht=()=>{Nt||(Nt=requestAnimationFrame(()=>{Nt=0,st()}))},cs=new ResizeObserver(Ht);return cs.observe(Fe),window.addEventListener("resize",Ht),window.addEventListener("orientationchange",Ht),()=>{Nt&&cancelAnimationFrame(Nt),cs.disconnect(),window.removeEventListener("resize",Ht),window.removeEventListener("orientationchange",Ht)}},[st]),Oe.useEffect(()=>{st()},[st,ee,Et]);const Lt=l.useCallback(async Fe=>{const Nt=Fe.target;Nt.closest(".app-region-no-drag")||Nt.closest("button, a, input, select, textarea")||Fe.button===0&&E&&await lg()},[E]),ls=l.useMemo(()=>{if(ee){const Fe=[{id:"chat",label:i("layout.mainTab.chat"),icon:dc}];return is&&Fe.push({id:"plan",label:i("layout.mainTab.plan"),icon:zl}),Fe.push({id:"diff",label:i("layout.mainTab.diff"),icon:"diff"},{id:"files",label:i("layout.mainTab.files"),icon:Th},{id:"terminal",label:i("layout.mainTab.terminal"),icon:Za}),Fe}return[]},[ee,is,i]),rs=l.useCallback(Fe=>fc(ra(Fe,w)),[w]);Oe.useEffect(()=>{!ee&&(x==="git"||x==="terminal"||x==="diff"||x==="files")&&g("chat")},[x,ee,g]);const Bt=l.useMemo(()=>{const Fe=[];return E&&Fe.push({value:"instance",label:i("layout.services.instance"),icon:ei}),Fe.push({value:"usage",label:i("layout.services.usage"),icon:Ad},{value:"mcp",label:"MCP",icon:_g}),Fe},[E,i]),xs=l.useMemo(()=>Bt.map(Fe=>({id:Fe.value,label:Fe.label,icon:s.jsx(Fe.icon,{className:"h-3.5 w-3.5"})})),[Bt]),mn=l.useMemo(()=>{if(typeof window>"u"||E||_e)return!1;const Fe=window.location.hostname;return Fe==="localhost"||Fe==="127.0.0.1"||Fe==="::1"},[E,_e]),js=l.useCallback(async()=>{if(A)return;j(!0),De(!1);const Fe=[];let Nt=!1;try{try{for(const[,Ht]of gn.getState().sessions.entries())for(const cs of Ht.tabs)cs.previewUrl&&Fe.push(cs.previewUrl)}catch{}try{await hv({})}catch{}try{(await fetch("/api/system/dev-shutdown",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({previewUrls:Fe})})).ok?Nt=!0:Nt=(await fetch("/api/system/shutdown",{method:"POST"})).ok}catch{}}finally{Nt||j(!1)}},[A,De]),xn=l.useMemo(()=>[{value:"usage",label:i("header.services.used")},{value:"remaining",label:i("header.services.remaining")}],[i]),In=l.useMemo(()=>xn.map(Fe=>({id:Fe.value,label:Fe.label})),[xn]),an=l.useMemo(()=>[{id:"usage",label:i("layout.services.usage"),icon:s.jsx(Ad,{className:"h-3.5 w-3.5"})},{id:"mcp",label:"MCP",icon:s.jsx(Bo,{className:"h-3.5 w-3.5"})}],[i]);Oe.useEffect(()=>{const Fe=Nt=>{if(Eu(Nt)&&!Nt.shiftKey&&!Nt.altKey){const Ht=parseInt(Nt.key,10);Ht>=1&&Ht<=ls.length&&(Nt.preventDefault(),g(ls[Ht-1].id))}};return window.addEventListener("keydown",Fe),()=>window.removeEventListener("keydown",Fe)},[ls,g]),Oe.useEffect(()=>{const Fe=Nt=>{const Ht=ra("toggle_services_menu",w);if(Nl(Nt,Ht)){Nt.preventDefault(),be?De(!1):(De(!0),Xe(),Le==="usage"&&F.length===0&&V());return}const cs=ra("cycle_services_tab",w);if(Nl(Nt,cs)){Nt.preventDefault();const Zs=Bt.map(vn=>vn.value);if(Zs.length===0)return;const Gs=Zs.indexOf(Le),en=Gs===-1?0:(Gs+1)%Zs.length,hn=Zs[en];se(hn),De(!0),Xe(),hn==="usage"&&F.length===0&&V();return}const Xs=ra("toggle_context_plan",w);Nl(Nt,Xs)&&(Nt.preventDefault(),Ps())};return window.addEventListener("keydown",Fe),()=>window.removeEventListener("keydown",Fe)},[w,be,Le,Bt,F.length,V,Xe,Ps]);const An=Fe=>{const Nt=x===Fe.id,Ht=Fe.icon==="diff",cs=Ht?null:Fe.icon,Xs=Fe.id==="chat",Zs=en=>Ht?s.jsx(Hm,{size:en}):cs?s.jsx(cs,{size:en}):null,Gs=s.jsxs("button",{type:"button",onClick:()=>g(Fe.id),className:pe("relative flex h-8 items-center gap-2 px-3 rounded-lg typography-ui-label font-medium transition-colors",Nt?"app-region-no-drag bg-interactive-selection text-interactive-selection-foreground shadow-none":"app-region-no-drag text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",Xs&&!ee&&"min-w-[100px] justify-center"),"aria-label":Fe.label,"aria-selected":Nt,role:"tab",children:[ee?Zs(20):s.jsxs(s.Fragment,{children:[Zs(16),s.jsx("span",{className:"header-tab-label",children:Fe.label})]}),Fe.badge!==void 0&&Fe.badge>0&&s.jsx("span",{className:"header-tab-badge typography-micro text-status-info font-medium",children:Fe.badge})]});return s.jsx(l.Fragment,{children:Gs},Fe.id)},on=s.jsxs(s.Fragment,{children:[is&&s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":i("header.actions.openPlanAria"),onClick:Ps,className:pe(We,Ms&&"bg-[var(--interactive-hover)]"),children:s.jsx(zl,{className:"h-[18px] w-[18px]"})})}),s.jsx(Ct,{children:s.jsx("p",{children:i("header.actions.planWithShortcut",{shortcut:rs("toggle_context_plan")})})})]}),s.jsx(Rj,{directory:Tt,className:"mr-1"}),s.jsx(y0,{isDesktopApp:E,currentInstanceLabel:U,compactCurrentInstanceLabel:Re,isDesktopServicesOpen:be,setIsDesktopServicesOpen:De,refreshCurrentInstanceLabel:Xe,desktopServicesTab:Le,setDesktopServicesTab:se,quotaResultsLength:F.length,fetchAllQuotas:V,servicesTabItems:xs,quotaLastUpdated:L,quotaDisplayMode:W,quotaDisplayTabItems:In,handleDisplayModeChange:Ge,handleUsageRefresh:$e,isQuotaLoading:O,isUsageRefreshSpinning:Ae,hasRateLimits:ye,rateLimitGroups:lt,expandedFamilies:et,toggleFamilyExpanded:ct,shortcutLabel:rs,showDevShutdown:mn,isDevShutdownInFlight:A,onDevShutdown:js}),s.jsx(al,{title:i("header.actions.terminalPanelWithShortcut",{shortcut:rs("toggle_terminal")}),ariaLabel:i("header.actions.toggleTerminalPanelAria"),onClick:m,Icon:Za}),s.jsx(al,{title:i("header.actions.rightSidebarWithShortcut",{shortcut:rs("toggle_right_sidebar")}),ariaLabel:i("header.actions.toggleRightSidebarAria"),onClick:u,Icon:Di}),s.jsx(b0,{isMobile:ee,githubAuthStatus:ae,githubAccounts:xe,githubAvatarUrl:fe,githubLogin:ke,isSwitchingGitHubAccount:he,handleGitHubAccountSwitch:Ts})]}),ln=!p||!a,fn=()=>s.jsxs("div",{onMouseDown:Lt,className:pe("app-region-drag relative flex h-12 select-none items-center pr-3",Mt,Et),style:as,role:"tablist","aria-label":i("header.navigation.mainAria"),children:[s.jsx(al,{visible:!d,title:i("header.actions.openSessionsWithShortcut",{shortcut:rs("toggle_sidebar")}),ariaLabel:i("header.actions.openSessionsAria"),onClick:X,className:`${We} shrink-0`,Icon:si}),s.jsxs("div",{className:pe("flex min-w-0 flex-1 items-center",!d&&"pl-3"),children:[He?null:s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":i("header.actions.newSessionAria"),onClick:pt,className:pe(We,"mr-6 shrink-0"),children:s.jsx(Mh,{className:"h-[18px] w-[18px]"})})}),s.jsx(Ct,{children:s.jsx("p",{children:i("header.actions.newSessionWithShortcut",{shortcut:rs("new_chat")})})})]}),J&&!He?s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":i("header.actions.newMiniChatAria"),onClick:wt,className:pe(We,"mr-6 shrink-0"),children:s.jsx(Ti,{className:"h-[18px] w-[18px]"})})}),s.jsx(Ct,{children:s.jsx("p",{children:i("header.actions.newMiniChat")})})]}):null,Rt&&s.jsx(np,{projectRef:Rt.projectRef,directory:Rt.directory,className:"mr-2"}),R?null:s.jsxs("div",{className:"mr-3 min-w-0",children:[s.jsx("div",{className:"truncate pl-1 typography-ui-label text-[14px] font-normal leading-tight text-foreground",children:gs}),$||ms||Ue?s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 truncate pl-1 typography-micro text-[10.5px] font-normal leading-tight text-muted-foreground/75",children:[$?s.jsx("span",{className:"truncate",children:$}):null,ms?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(Ks,{className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:ms})]}):null,Ue?s.jsxs("span",{className:"inline-flex flex-shrink-0 items-center gap-0 text-[0.92em]",children:[s.jsxs("span",{className:"text-status-success/80",children:["+",Ft.additions]}),s.jsx("span",{className:"text-muted-foreground/60",children:"/"}),s.jsxs("span",{className:"text-status-error/65",children:["-",Ft.deletions]})]}):null,Dt?s.jsxs("span",{className:pe("inline-flex min-w-0 items-center gap-0.5",Dt==="attention"||Dt==="invalid"||Dt==="missing"?"text-status-warning":"text-muted-foreground/60"),children:[s.jsx(bu,{className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:jt})]}):null]}):null]}),ls.length>0&&s.jsx("div",{className:"flex items-center gap-1 rounded-lg bg-[var(--surface-muted)]/50 p-1",children:ls.map(Fe=>An(Fe))}),s.jsx("div",{className:"flex-1"}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[s.jsx(al,{visible:J&&!R&&!!k,title:i("header.actions.openSessionMiniChat"),ariaLabel:i("header.actions.openSessionMiniChatAria"),onClick:zt,className:`${We} mr-1`,Icon:wb}),Ke&&Z?s.jsx(vj,{totalTokens:Z.totalTokens,percentage:Ze,colorPercentage:Z.percentage,contextLimit:Z.contextLimit,outputLimit:Z.outputLimit??0,size:"compact",hideIcon:!0,showPercentIcon:!0,onClick:ss,pressed:os,className:ln?"mr-3.5":"",valueClassName:"typography-ui-label font-medium leading-none text-foreground",percentIconClassName:"h-5 w-5"}):null,ln?on:null,!ln&&a?vo.createPortal(on,a):null]})]})]}),cr=()=>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:pe(gt,n&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":i(n?"header.actions.closeSessionsAria":"header.actions.openSessionsAria"),children:s.jsx(si,{className:"h-5 w-5"})}):Y?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(zi,{className:"h-5 w-5"})}):s.jsx("button",{type:"button",onClick:X,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(vb,{className:"h-5 w-5"})}),Y&&s.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:i("header.sessions.title")})]}),!Y&&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:ls.map(Fe=>{const Nt=x===Fe.id,Ht=Fe.icon==="diff",cs=Ht?null:Fe.icon;return s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>{ee&&Ls(),g(Fe.id)},"aria-label":Fe.label,"aria-selected":Nt,role:"tab",className:pe(gt,"relative rounded-lg",Nt&&"bg-interactive-selection text-interactive-selection-foreground"),children:[Ht?s.jsx(Hm,{className:"h-5 w-5"}):cs?s.jsx(cs,{className:"h-5 w-5"}):null,Fe.badge!==void 0&&Fe.badge>0&&s.jsx("span",{className:"absolute -top-1 -right-1 text-[10px] font-semibold text-primary",children:Fe.badge}),Fe.showDot&&s.jsx("span",{className:"absolute top-1.5 right-1.5 h-2 w-2 rounded-full bg-primary","aria-label":i("header.changes.availableAria")})]})}),s.jsx(Ct,{children:s.jsx("p",{children:Fe.label})})]},Fe.id)})})})})}),s.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[Rt&&s.jsx(np,{projectRef:Rt.projectRef,directory:Rt.directory,compact:!0,allowMobile:!0,className:"h-9"}),s.jsxs(zs,{open:Be,onOpenChange:Fe=>{G(Fe),Fe&&F.length===0&&V()},children:[s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx(Bs,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":i("header.services.viewAria"),className:gt,children:s.jsx(Sa,{className:"h-5 w-5"})})})}),s.jsx(Ct,{children:s.jsx("p",{children:i("header.services.title")})})]}),s.jsx(Vs,{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(Br,{items:an,activeId:ie,onSelect:Fe=>{const Nt=Fe;K(Nt),Nt==="usage"&&F.length===0&&V()},layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",activePillButtonClassName:"h-8",className:"h-full"})}),s.jsx("button",{type:"button",onClick:()=>G(!1),className:"inline-flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover","aria-label":i("header.services.closeAria"),children:s.jsx(Ds,{className:"h-5 w-5"})})]})}),ie==="mcp"&&s.jsx(Ug,{active:Be&&ie==="mcp"}),ie==="usage"&&s.jsxs("div",{className:"flex-1 overflow-y-auto overflow-x-hidden pb-[calc(4rem+env(safe-area-inset-bottom))]",children:[s.jsx("div",{className:"border-b border-[var(--interactive-border)]",children:s.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-3",children:[s.jsxs("div",{className:"flex flex-col min-w-0 gap-0.5",children:[s.jsx("span",{className:"typography-ui-header font-semibold text-foreground",children:i("header.services.rateLimits")}),s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:qg(L)})]}),s.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[s.jsxs("div",{className:"flex items-center h-6",children:[s.jsx("button",{type:"button",onClick:()=>Ge("usage"),className:pe("typography-ui-label px-1 pb-0.5 transition-colors",W==="usage"?"text-foreground border-b-2 border-[var(--primary-base)]":"text-muted-foreground hover:text-foreground"),children:i("header.services.used")}),s.jsx("span",{className:"text-muted-foreground typography-ui-label px-0.5",children:"·"}),s.jsx("button",{type:"button",onClick:()=>Ge("remaining"),className:pe("typography-ui-label px-1 pb-0.5 transition-colors",W==="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:pe("inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors","hover:text-foreground hover:bg-interactive-hover","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),onClick:$e,disabled:O||Ae,"aria-label":i("header.services.refreshRateLimitsAria"),children:s.jsx(Nn,{className:pe("h-4 w-4",Ae&&"animate-spin")})})]})]})}),!ye&&s.jsx("div",{className:"px-4 py-6 text-center",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:i("header.services.noRateLimits")})}),s.jsx("div",{className:"py-1",children:lt.map((Fe,Nt)=>s.jsxs(l.Fragment,{children:[Nt>0?s.jsx("div",{className:"mx-4 my-1 border-t border-[var(--interactive-border)]"}):null,s.jsxs("div",{className:"flex items-center gap-2 px-4 py-2",children:[s.jsx(Bn,{providerId:Fe.providerId,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:Fe.providerName})]}),Fe.entries.length===0&&(!Fe.modelFamilies||Fe.modelFamilies.length===0)?s.jsx("div",{className:"px-4 pb-2",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:Fe.error??i("header.services.noRateLimitsReported")})}):s.jsxs("div",{className:"space-y-3 px-4 pb-2",children:[Fe.entries.map(([Ht,cs])=>{const Xs=W==="remaining"?cs.remainingPercent:cs.usedPercent,Zs=Eo(cs.usedPercent,cs.resetAt,cs.windowSeconds,Ht),Gs=Zs?.dailyAllocationPercent!=null?W==="remaining"?100-aa(Zs.elapsedRatio):aa(Zs.elapsedRatio):null,en=Ro(cs.valueLabel,Xs);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:_u(Ht)}),cs.resetAfterFormatted??cs.resetAtFormatted?s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:cs.resetAfterFormatted??cs.resetAtFormatted}):null]}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:en==="-"?"":en})]}),s.jsx(Oo,{percent:Xs,tonePercent:cs.usedPercent,className:"h-1.5",expectedMarkerPercent:Gs}),Zs?s.jsx(Lo,{paceInfo:Zs,compact:!0}):null]},`${Fe.providerId}-${Ht}`)}),Fe.modelFamilies&&Fe.modelFamilies.length>0&&s.jsx("div",{className:"space-y-0.5",children:Fe.modelFamilies.map(Ht=>{const Xs=(et[Fe.providerId]??[]).includes(Ht.familyId??"other");return s.jsxs(yr,{open:Xs,onOpenChange:()=>ct(Fe.providerId,Ht.familyId??"other"),children:[s.jsxs(Mr,{className:"flex w-full items-center justify-between rounded-md px-1 py-1.5 text-left hover:bg-[var(--interactive-hover)]/50 transition-colors",children:[s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:Ht.familyLabel}),Xs?s.jsx(Cs,{className:"h-4 w-4 text-muted-foreground"}):s.jsx(Fn,{className:"h-4 w-4 text-muted-foreground"})]}),s.jsx(vr,{children:s.jsx("div",{className:"space-y-2.5 pb-1 pl-1 pt-1",children:Ht.models.map(([Zs,Gs])=>{const en=W==="remaining"?Gs.remainingPercent:Gs.usedPercent,hn=Eo(Gs.usedPercent,Gs.resetAt,Gs.windowSeconds),vn=hn?.dailyAllocationPercent!=null?W==="remaining"?100-aa(hn.elapsedRatio):aa(hn.elapsedRatio):null,dr=Ro(Gs.valueLabel,en);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:Ql(Zs)}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:dr==="-"?"":dr})]}),s.jsx(Oo,{percent:en,tonePercent:Gs.usedPercent,className:"h-1.5",expectedMarkerPercent:vn}),hn?s.jsx(Lo,{paceInfo:hn,compact:!0}):null]},`${Fe.providerId}-${Zs}`)})})})]},Ht.familyId??"other")})})]})]},Fe.providerId))})]})]})})]}),e?s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx("button",{type:"button",onClick:e,className:pe(gt,"relative",r&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":r?"Close git sidebar":"Open git sidebar",children:s.jsx(Di,{className:"h-5 w-5"})})}),s.jsx(Ct,{children:s.jsx("p",{children:r?"Close git sidebar":"Open git sidebar"})})]}):null]})]})]}),Vr=pe("header-safe-area relative z-10",ee&&"border-b border-border/50","bg-background");return s.jsx("header",{ref:te,className:Vr,style:{"--padding-scale":"1"},children:ee?cr():fn()})};function j0(){}const ap=180,ip=640,N0=110,S0=t=>{const e=nt.c(44),{isOpen:n,isMobile:r,children:a}=t,{t:i}=ut(),o=Te(k0),c=Te(C0),d=Te(I0),p=Te(A0),[m,u]=l.useState(null),[h,b]=l.useState(!1),f=l.useRef(null),y=l.useRef(0),x=l.useRef(o||300),g=Math.min(ip,Math.max(ap,o||300));let w,v;e[0]!==n?(w=()=>{n||(u(null),b(!1))},v=[n],e[0]=n,e[1]=w,e[2]=v):(w=e[1],v=e[2]),l.useEffect(w,v);let S,A;e[3]!==c||e[4]!==r||e[5]!==n?(S=()=>{if(r||!n||!c)return;const le=()=>{const ge=f.current?.parentElement?.getBoundingClientRect().height;if(!ge||ge<=0)return;const te=Math.max(0,Math.round(ge));u(E=>E===te?E:te)};le();const ee=f.current?.parentElement;if(!ee)return;const ae=new ResizeObserver(le);return ae.observe(ee),()=>{ae.disconnect()}},A=[c,r,n],e[3]=c,e[4]=r,e[5]=n,e[6]=S,e[7]=A):(S=e[6],A=e[7]),l.useEffect(S,A);let j,C;if(e[8]!==c||e[9]!==r||e[10]!==h||e[11]!==d||e[12]!==p?(j=()=>{if(r||!h||c)return;const le=ae=>{const ge=y.current-ae.clientY,te=Math.min(ip,Math.max(ap,x.current+ge));d(te)},ee=()=>{b(!1),Te.getState().bottomTerminalHeight<=N0&&p(!1)};return window.addEventListener("pointermove",le),window.addEventListener("pointerup",ee,{once:!0}),()=>{window.removeEventListener("pointermove",le),window.removeEventListener("pointerup",ee)}},C=[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]=C):(j=e[13],C=e[14]),l.useEffect(j,C),r)return null;const I=n?c?Math.max(0,m??g):g:0,R=n&&c;let k;e[15]!==I||e[16]!==c||e[17]!==n?(k=le=>{!n||c||(b(!0),y.current=le.clientY,x.current=I,le.preventDefault())},e[15]=I,e[16]=c,e[17]=n,e[18]=k):k=e[18];const P=k,N=R?"absolute inset-x-0 bottom-0 z-40":"relative",D=h?"transition-none":"transition-[height] duration-300 ease-in-out",T=!n&&"border-t-0";let M;e[19]!==T||e[20]!==N||e[21]!==D?(M=pe("flex overflow-hidden border-t border-border bg-sidebar",N,D,T),e[19]=T,e[20]=N,e[21]=D,e[22]=M):M=e[22];let $;e[23]!==I||e[24]!==R?($=R?{top:"var(--oc-header-height, 48px)"}:{height:`${I}px`,minHeight:`${I}px`,maxHeight:`${I}px`},e[23]=I,e[24]=R,e[25]=$):$=e[25];const F=!n||!c&&I===0;let V;e[26]!==P||e[27]!==c||e[28]!==n||e[29]!==h||e[30]!==i?(V=n&&!c&&s.jsx("div",{className:pe("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:P,role:"separator","aria-orientation":"horizontal","aria-label":i("terminalView.bottomDock.resizeAria")}),e[26]=P,e[27]=c,e[28]=n,e[29]=h,e[30]=i,e[31]=V):V=e[31];const O=!n&&"pointer-events-none select-none opacity-0";let L;e[32]!==O?(L=pe("relative z-10 flex h-full min-h-0 w-full flex-col transition-opacity duration-300 ease-in-out",O),e[32]=O,e[33]=L):L=e[33];const W=!n;let B;e[34]!==a||e[35]!==L||e[36]!==W?(B=s.jsx("div",{className:L,"aria-hidden":W,children:a}),e[34]=a,e[35]=L,e[36]=W,e[37]=B):B=e[37];let ne;return e[38]!==M||e[39]!==$||e[40]!==F||e[41]!==V||e[42]!==B?(ne=s.jsxs("section",{ref:f,className:M,style:$,"aria-hidden":F,children:[V,B]}),e[38]=M,e[39]=$,e[40]=F,e[41]=V,e[42]=B,e[43]=ne):ne=e[43],ne};function k0(t){return t.bottomTerminalHeight}function C0(t){return t.isBottomTerminalExpanded}function I0(t){return t.setBottomTerminalHeight}function A0(t){return t.setBottomTerminalOpen}const Hd=280,op=280,lp=500,P0=({isOpen:t,isMobile:e,children:n,className:r})=>{const{t:a}=ut(),i=Te(S=>S.sidebarWidth),o=Te(S=>S.setSidebarWidth),[c,d]=l.useState(!1),p=l.useRef(0),m=l.useRef(i||Hd),u=l.useRef(null),h=l.useRef(null),b=l.useRef(null),f=l.useCallback(S=>Math.min(lp,Math.max(op,S)),[]),y=l.useCallback(S=>{const A=b.current;A&&A.style.setProperty("--oc-left-sidebar-width",`${S}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(lp,Math.max(op,i||Hd)):0,g=S=>{if(t){try{S.currentTarget.setPointerCapture(S.pointerId)}catch{}h.current=S.pointerId,d(!0),p.current=S.clientX,m.current=x,u.current=x,y(x),S.preventDefault()}},w=S=>{if(e||!c||h.current!==S.pointerId)return;const A=S.clientX-p.current,j=f(m.current+A);u.current!==j&&(u.current=j,y(j))},v=S=>{if(h.current!==S.pointerId||e)return;try{S.currentTarget.releasePointerCapture(S.pointerId)}catch{}const A=f(u.current??x);h.current=null,u.current=null,d(!1),o(A)};return s.jsxs("aside",{ref:b,className:pe("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:pe("absolute right-0 top-0 z-20 h-full w-[3px] cursor-col-resize hover:bg-[var(--interactive-border)]/80 transition-colors",c&&"bg-[var(--interactive-border)]"),onPointerDown:g,onPointerMove:w,onPointerUp:v,onPointerCancel:v,role:"separator","aria-orientation":"vertical","aria-label":a("sidebar.resize.leftPanelAria")}),s.jsx("div",{className:pe("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(rn,{children:n})})})]})},Qg=420,cp=400,dp=860,D0=({isOpen:t,children:e,className:n,onTopActionsHostChange:r})=>{const{t:a}=ut(),i=Te(R=>R.rightSidebarWidth),o=Te(R=>R.setRightSidebarWidth),c=l.useMemo(()=>kn(),[]),d=l.useMemo(()=>yn(),[]),p=pc(),[m,u]=l.useState(!1),h=l.useRef(0),b=l.useRef(i||420),f=l.useRef(null),y=l.useRef(null),x=l.useRef(null),g=l.useCallback(R=>Math.min(dp,Math.max(cp,R)),[]),w=l.useCallback(R=>{const k=x.current;k&&k.style.setProperty("--oc-right-sidebar-width",`${R}px`)},[]),v=t?Math.min(dp,Math.max(cp,i||Qg)):0,S=R=>{if(t){try{R.currentTarget.setPointerCapture(R.pointerId)}catch{}y.current=R.pointerId,u(!0),h.current=R.clientX,b.current=v,f.current=v,w(v),R.preventDefault()}},A=R=>{if(!m||y.current!==R.pointerId)return;const k=h.current-R.clientX,P=g(b.current+k);f.current!==P&&(f.current=P,w(P))},j=R=>{if(y.current!==R.pointerId)return;try{R.currentTarget.releasePointerCapture(R.pointerId)}catch{}const k=g(f.current??v);y.current=null,f.current=null,u(!1),o(k)};l.useEffect(()=>{m||(f.current=null,y.current=null)},[m]),l.useEffect(()=>{t||r?.(null)},[t,r]);const C=l.useCallback(async R=>{const k=R.target;k.closest(".app-region-no-drag")||k.closest("button, a, input, select, textarea")||R.button===0&&c&&await lg()},[c]),I=l.useMemo(()=>{if(!(c||d))return{paddingLeft:"calc(0.75rem + var(--oc-wco-left-inset, 0px))",paddingRight:"calc(0.75rem + var(--oc-wco-right-inset, 0px))",...p?{paddingTop:"var(--oc-safe-area-top, 0px)"}:null}},[c,p,d]);return s.jsxs("aside",{ref:x,className:pe("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??v:v}px`,overflowX:"clip"},"aria-hidden":!t||v===0,children:[t?s.jsx("div",{onMouseDown:C,className:pe("app-region-drag absolute inset-x-0 top-0 z-20 flex items-center justify-end px-3","h-[var(--oc-header-height,56px)]"),style:I,"aria-hidden":!0,children:s.jsx("div",{ref:r,className:"app-region-no-drag flex items-center gap-1"})}):null,t&&s.jsx("div",{className:pe("absolute left-0 top-0 z-20 h-full w-[3px] cursor-col-resize hover:bg-[var(--interactive-border)]/80 transition-colors",m&&"bg-[var(--interactive-border)]"),onPointerDown:S,onPointerMove:A,onPointerUp:j,onPointerCancel:j,role:"separator","aria-orientation":"vertical","aria-label":a("sidebar.resize.rightPanelAria")}),s.jsx("div",{className:pe("relative z-10 flex h-full min-h-0 w-full flex-col transition-opacity duration-300 ease-in-out",m&&"pointer-events-none",!t&&"pointer-events-none select-none opacity-0"),style:t?{paddingTop:"var(--oc-header-height, 56px)"}:void 0,"aria-hidden":!t,children:t?e:null})]})},T0=new Intl.NumberFormat("en-US",{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}),M0=t=>{if(typeof t!="number"||Number.isNaN(t))return"";if(t===0)return"0";const e=T0.format(t);return e.endsWith(".0")?e.slice(0,-2):e},Ho=({providerId:t,modelId:e,onChange:n,className:r,allowedProviderIds:a,placeholder:i})=>{const{t:o}=ut(),{isReady:c,isUnavailable:d}=cg(),p=yt(E=>E.providers),m=yt(E=>E.modelsMetadata),u=Te(E=>E.isMobile),h=Te(E=>E.hiddenModels),b=Te(E=>E.toggleFavoriteModel),f=Te(E=>E.isFavoriteModel),y=Te(E=>E.addRecentModel),{favoriteModelsList:x,recentModelsList:g}=dg(),{isMobile:w}=un(),v=u||w,[S,A]=l.useState(!1),[j,C]=l.useState(new Set),[I,R]=l.useState(!1),[k,P]=l.useState(""),[N,D]=l.useState(0),T=l.useRef([]),M=l.useMemo(()=>!Array.isArray(a)||a.length===0?null:new Set(a),[a]),$=l.useMemo(()=>(M?p.filter(z=>M.has(String(z.id))):p).map(z=>{const H=(Array.isArray(z.models)?z.models:[]).filter(re=>{const ce=typeof re?.id=="string"?re.id:"";return!h.some(Ne=>Ne.providerID===String(z.id)&&Ne.modelID===ce)});return{...z,models:H}}).filter(z=>z.models.length>0),[p,M,h]),F=()=>A(!1),V=E=>{C(z=>{const J=new Set(z);return J.has(E)?J.delete(E):J.add(E),J})};l.useEffect(()=>{I||(P(""),D(0))},[I]),l.useEffect(()=>{D(0)},[k]);const O=E=>{const z=E?.name||E?.id||"",J=String(z);return J.length>40?J.substring(0,37)+"...":J},L=(E,z)=>{const J=`${E}/${z}`;return m.get(J)},W=(E,z)=>{n(E,z),E&&z&&y(E,z),R(!1)},B=(E,z)=>{if(!k.trim())return!0;const J=k.toLowerCase();return E.toLowerCase().includes(J)||z.toLowerCase().includes(J)},ne=(E,z,J,H,re,ce)=>{const Ne=L(z,J),me=M0(Ne?.limit?.context),we=t===z&&e===J,_=f(z,J),ue=H==="fav"||H==="recent";return s.jsxs($t,{ref:Q=>{T.current[re]=Q},className:pe("group flex items-center gap-2",ce&&"bg-interactive-selection"),onSelect:()=>W(z,J),onMouseEnter:()=>D(re),children:[s.jsxs("div",{className:"flex items-center gap-1.5 flex-1 min-w-0",children:[ue&&s.jsx(Bn,{providerId:z,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"font-medium truncate",children:O(E)}),me?s.jsx("span",{className:"typography-micro text-muted-foreground flex-shrink-0",children:me}):null]}),s.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[we&&s.jsx(Ys,{className:"h-4 w-4 text-primary"}),s.jsx("button",{onClick:Q=>{Q.preventDefault(),Q.stopPropagation(),b(z,J)},className:pe("model-favorite-button flex h-4 w-4 items-center justify-center hover:text-primary/80",_?"text-primary":"text-muted-foreground"),"aria-label":o(_?"settings.agents.modelSelector.actions.unfavorite":"settings.agents.modelSelector.actions.favorite"),title:o(_?"settings.agents.modelSelector.actions.removeFromFavorites":"settings.agents.modelSelector.actions.addToFavorites"),children:_?s.jsx(po,{className:"h-3.5 w-3.5"}):s.jsx(wl,{className:"h-3.5 w-3.5"})})]})]},`${H}-${z}-${J}`)},le=x.filter(({model:E,providerID:z})=>{if(M&&!M.has(z))return!1;const H=p.find(ce=>ce.id===z)?.name||z,re=O(E);return B(re,H)}),ee=g.filter(({model:E,providerID:z})=>{if(M&&!M.has(z))return!1;const H=p.find(ce=>ce.id===z)?.name||z,re=O(E);return B(re,H)}),ae=$.map(E=>{const J=(Array.isArray(E.models)?E.models:[]).filter(H=>{const re=O(H);return B(re,E.name||E.id||"")});return{...E,models:J}}).filter(E=>E.models.length>0),ge=le.length>0||ee.length>0||ae.length>0,te=()=>v?s.jsx(Ar,{open:S,onClose:F,title:o("settings.agents.modelSelector.title"),children:s.jsxs("div",{className:"space-y-1",children:[x.length>0&&s.jsxs("div",{className:"rounded-xl border border-border/40 bg-[var(--surface-elevated)] mb-2",children:[s.jsx("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground uppercase tracking-wider",children:o("settings.agents.modelSelector.section.favorites")}),s.jsx("div",{className:"border-t border-border/20",children:x.map(({model:E,providerID:z,modelID:J})=>{const H=z===t&&J===e;return s.jsxs("div",{className:pe("flex w-full items-center justify-between px-2 py-1.5 text-left","typography-meta",H?"bg-primary/10 text-primary":"text-foreground"),children:[s.jsx("button",{type:"button",className:"flex-1 flex flex-col min-w-0 mr-2",onClick:()=>{W(z,J),F()},children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Bn,{providerId:z,className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"font-medium truncate",children:O(E)})]})}),s.jsx("button",{onClick:re=>{re.preventDefault(),re.stopPropagation(),b(z,J)},className:"model-favorite-button flex h-8 w-8 items-center justify-center text-primary hover:text-primary/80 active:scale-95 touch-manipulation","aria-label":o("settings.agents.modelSelector.actions.unfavorite"),children:s.jsx(po,{className:"h-4 w-4"})})]},`fav-mobile-${z}-${J}`)})})]}),g.length>0&&s.jsxs("div",{className:"rounded-xl border border-border/40 bg-[var(--surface-elevated)] mb-2",children:[s.jsx("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground uppercase tracking-wider",children:o("settings.agents.modelSelector.section.recents")}),s.jsx("div",{className:"border-t border-border/20",children:g.map(({model:E,providerID:z,modelID:J})=>{const H=z===t&&J===e;return s.jsxs("div",{className:pe("flex w-full items-center justify-between px-2 py-1.5 text-left","typography-meta",H?"bg-primary/10 text-primary":"text-foreground"),children:[s.jsx("button",{type:"button",className:"flex-1 flex flex-col min-w-0 mr-2",onClick:()=>{W(z,J),F()},children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Bn,{providerId:z,className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"font-medium truncate",children:O(E)})]})}),s.jsx("button",{onClick:re=>{re.preventDefault(),re.stopPropagation(),b(z,J)},className:"model-favorite-button flex h-8 w-8 items-center justify-center text-muted-foreground/50 hover:text-primary/80 active:scale-95 touch-manipulation","aria-label":o("settings.agents.modelSelector.actions.favorite"),children:s.jsx(wl,{className:"h-4 w-4"})})]},`recent-mobile-${z}-${J}`)})})]}),$.map(E=>{const z=Array.isArray(E.models)?E.models:[];if(z.length===0)return null;const J=E.id===t,H=j.has(E.id);return s.jsxs("div",{className:"rounded-xl border border-border/40 bg-[var(--surface-elevated)]",children:[s.jsxs("button",{type:"button",className:"flex w-full items-center justify-between gap-1.5 px-2 py-1.5 text-left",onClick:()=>V(E.id),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Bn,{providerId:E.id,className:"h-3.5 w-3.5"}),s.jsx("span",{className:"typography-meta font-medium text-foreground",children:E.name}),J&&s.jsx("span",{className:"typography-micro text-primary/80",children:o("settings.agents.modelSelector.badge.current")})]}),H?s.jsx(Cs,{className:"h-3 w-3 text-muted-foreground"}):s.jsx(Fn,{className:"h-3 w-3 text-muted-foreground"})]}),H&&s.jsx("div",{className:"border-t border-border/20",children:z.map(re=>{const ce=E.id===t&&re.id===e;return s.jsxs("div",{className:pe("flex w-full items-center justify-between px-2 py-1.5 text-left","typography-meta",ce?"bg-primary/10 text-primary":"text-foreground"),children:[s.jsx("button",{type:"button",className:"flex-1 flex flex-col min-w-0 mr-2",onClick:()=>{W(E.id,re.id),F()},children:s.jsx("span",{className:"font-medium truncate",children:O(re)})}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[s.jsx("button",{onClick:Ne=>{Ne.preventDefault(),Ne.stopPropagation(),b(E.id,re.id)},className:pe("flex h-8 w-8 items-center justify-center active:scale-95 touch-manipulation hover:text-primary/80",f(E.id,re.id)?"text-primary":"text-muted-foreground/50"),"aria-label":f(E.id,re.id)?o("settings.agents.modelSelector.actions.unfavorite"):o("settings.agents.modelSelector.actions.favorite"),children:f(E.id,re.id)?s.jsx(po,{className:"h-4 w-4"}):s.jsx(wl,{className:"h-4 w-4"})}),ce&&s.jsx("div",{className:"h-2 w-2 rounded-full bg-primary"})]})]},re.id)})})]},E.id)}),s.jsx("button",{type:"button",className:"flex w-full items-center justify-between rounded-lg border border-border/40 bg-[var(--surface-elevated)] px-2 py-1.5 text-left",onClick:()=>{W("",""),F()},children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:i||o("settings.agents.modelSelector.noModelOptional")})})]})}):null;return s.jsxs(s.Fragment,{children:[v?s.jsxs("button",{type:"button",onClick:c?()=>A(!0):void 0,disabled:!c,className:pe("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(Bn,{providerId:t,className:"h-3.5 w-3.5"}):s.jsx(Mi,{className:"h-3 w-3 text-muted-foreground"}):s.jsxs(s.Fragment,{children:[s.jsx(Zt,{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(Cs,{className:"h-3 w-3 text-muted-foreground"})]}):s.jsxs(zs,{open:c&&I,onOpenChange:c?R:void 0,children:[s.jsx(Bs,{asChild:!0,children:s.jsxs("div",{className:pe("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(Bn,{providerId:t,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx(Mi,{className:"h-3 w-3 text-primary/60 hidden"})]}):s.jsx(Mi,{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(Zt,{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(Cs,{className:"h-4 w-4 flex-shrink-0 text-muted-foreground/50"})]})}),s.jsx(Vs,{className:"w-[min(380px,calc(100vw-2rem))] p-0 flex flex-col",align:"start",children:(()=>{const E=[];le.forEach(({model:re,providerID:ce,modelID:Ne})=>{E.push({model:re,providerID:ce,modelID:Ne,section:"fav"})}),ee.forEach(({model:re,providerID:ce,modelID:Ne})=>{E.push({model:re,providerID:ce,modelID:Ne,section:"recent"})}),ae.forEach(re=>{re.models.forEach(ce=>{E.push({model:ce,providerID:re.id,modelID:ce.id,section:"provider"})})});const z=E.length,J=re=>{if(re.stopPropagation(),re.key==="ArrowDown"){re.preventDefault();const ce=(N+1)%Math.max(1,z);D(ce),setTimeout(()=>{T.current[ce]?.scrollIntoView({behavior:"smooth",block:"nearest"})},0)}else if(re.key==="ArrowUp"){re.preventDefault();const ce=(N-1+Math.max(1,z))%Math.max(1,z);D(ce),setTimeout(()=>{T.current[ce]?.scrollIntoView({behavior:"smooth",block:"nearest"})},0)}else if(re.key==="Enter"){re.preventDefault();const ce=E[N];ce&&W(ce.providerID,ce.modelID)}else re.key==="Escape"&&(re.preventDefault(),R(!1))};let H=0;return s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"p-2 border-b border-border/40",children:s.jsxs("div",{className:"relative",children:[s.jsx(Hn,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Vt,{type:"text",placeholder:o("settings.agents.modelSelector.searchPlaceholder"),value:k,onChange:re=>P(re.target.value),onKeyDown:J,className:"pl-8 h-8 typography-meta",autoFocus:!0})]})}),s.jsx(Es,{outerClassName:"max-h-[min(400px,calc(100dvh-12rem))] flex-1",children:s.jsxs("div",{className:"p-1",children:[s.jsxs($t,{className:pe("flex items-center gap-2"),onSelect:()=>W("",""),children:[s.jsx(Ds,{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(Ys,{className:"h-4 w-4 text-primary ml-auto"})]}),s.jsx(En,{}),!ge&&k&&s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:o("settings.agents.modelSelector.state.noModelsFound")}),le.length>0&&s.jsxs("div",{children:[s.jsxs(wo,{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(po,{className:"h-4 w-4 text-primary"}),o("settings.agents.modelSelector.section.favorites")]}),le.map(({model:re,providerID:ce,modelID:Ne})=>{const me=H++;return ne(re,ce,Ne,"fav",me,N===me)})]}),ee.length>0&&s.jsxs("div",{children:[le.length>0&&s.jsx(En,{}),s.jsxs(wo,{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(yu,{className:"h-4 w-4"}),o("settings.agents.modelSelector.section.recent")]}),ee.map(({model:re,providerID:ce,modelID:Ne})=>{const me=H++;return ne(re,ce,Ne,"recent",me,N===me)})]}),(le.length>0||ee.length>0)&&ae.length>0&&s.jsx(En,{}),ae.map((re,ce)=>s.jsxs("div",{children:[ce>0&&s.jsx(En,{}),s.jsxs(wo,{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(Bn,{providerId:re.id,className:"h-4 w-4 flex-shrink-0"}),re.name]}),re.models.map(Ne=>{const me=H++;return ne(Ne,re.id,Ne.id,"provider",me,N===me)})]},re.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")})]})})()})]}),te()]})},jc=t=>{const e=nt.c(34),{agentName:n,onChange:r,className:a,filter:i}=t,{t:o}=ut(),{isReady:c,isUnavailable:d}=cg(),p=yt(R0),m=_i(E0),u=_i(F0),h=yt(O0);let b;e:{if(Array.isArray(p)&&p.length>0){b=p;break e}let F;e[0]!==m?(F=Array.isArray(m)?m:[],e[0]=m,e[1]=F):F=e[1],b=F}const f=b;let y;if(e[2]!==i||e[3]!==f){const F=Dv(f);y=i?F.filter(i):F,e[2]=i,e[3]=f,e[4]=y}else y=e[4];const x=y,g=Te(L0),{isMobile:w}=un(),v=g||w,[S,A]=l.useState(!1);let j,C;e[5]!==u||e[6]!==h||e[7]!==f.length?(j=()=>{f.length>0||(h(),u())},C=[f.length,h,u],e[5]=u,e[6]=h,e[7]=f.length,e[8]=j,e[9]=C):(j=e[8],C=e[9]),l.useEffect(j,C);let I;e[10]===Symbol.for("react.memo_cache_sentinel")?(I=()=>A(!1),e[10]=I):I=e[10];const R=I;let k;e[11]!==r?(k=F=>{r(F)},e[11]=r,e[12]=k):k=e[12];const P=k;let N;e[13]!==n||e[14]!==x||e[15]!==P||e[16]!==v||e[17]!==S||e[18]!==o?(N=()=>v?s.jsx(Ar,{open:S,onClose:R,title:o("settings.commands.agentSelector.title"),children:s.jsxs("div",{className:"space-y-1",children:[s.jsxs("button",{type:"button",className:pe("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:()=>{P(""),R()},children:[s.jsx("span",{className:pe("typography-meta",n?"text-muted-foreground":"font-medium"),children:o("settings.commands.agentSelector.notSelected")}),!n&&s.jsx("div",{className:"h-2 w-2 rounded-full bg-primary"})]}),x.map(F=>{const V=F.name===n;return s.jsxs("button",{type:"button",className:pe("flex w-full items-center justify-between rounded-lg border border-border/40 bg-background/95 px-2 py-1.5 text-left",V?"bg-primary/10 text-primary":"text-foreground"),onClick:()=>{P(F.name),R()},children:[s.jsxs("div",{className:"flex flex-col",children:[s.jsx("span",{className:"typography-meta font-medium",children:F.name}),F.description&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:F.description})]}),V&&s.jsx("div",{className:"h-2 w-2 rounded-full bg-primary"})]},F.name)})]})}):null,e[13]=n,e[14]=x,e[15]=P,e[16]=v,e[17]=S,e[18]=o,e[19]=N):N=e[19];const D=N;let T;e[20]!==n||e[21]!==x||e[22]!==a||e[23]!==P||e[24]!==v||e[25]!==c||e[26]!==d||e[27]!==o?(T=v?s.jsxs("button",{type:"button",onClick:c?()=>A(!0):void 0,disabled:!c,className:pe("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(Gr,{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(Zt,{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(Cs,{className:"h-3 w-3 text-muted-foreground"})]}):c?s.jsxs(zs,{children:[s.jsx(Bs,{asChild:!0,children:s.jsxs("div",{className:pe("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(Gr,{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(Cs,{className:"h-3 w-3 flex-shrink-0 text-muted-foreground"})]})}),s.jsxs(Vs,{className:"max-w-[300px]",children:[s.jsx($t,{className:"typography-meta",onSelect:()=>P(""),children:s.jsx("span",{className:"text-muted-foreground",children:o("settings.commands.agentSelector.notSelected")})}),x.map(F=>s.jsx($t,{className:"typography-meta",onSelect:()=>P(F.name),children:s.jsx("span",{className:"font-medium",children:F.name})},F.name))]})]}):s.jsxs("div",{className:pe("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(Zt,{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]=P,e[24]=v,e[25]=c,e[26]=d,e[27]=o,e[28]=T):T=e[28];let M;e[29]!==D?(M=D(),e[29]=D,e[30]=M):M=e[30];let $;return e[31]!==T||e[32]!==M?($=s.jsxs(s.Fragment,{children:[T,M]}),e[31]=T,e[32]=M,e[33]=$):$=e[33],$};function R0(t){return t.agents}function E0(t){return t.agents}function F0(t){return t.loadAgents}function O0(t){return t.loadAgents}function L0(t){return t.isMobile}const up=t=>({providerID:t.providerID,modelID:t.modelID,variant:t.variant,agent:t.agent}),$0=t=>{const e=nt.c(38),{value:n,options:r,disabled:a,onChange:i}=t,{t:o}=ut();let c;e[0]!==o||e[1]!==n?(c=n||o("rightSidebar.contextNotesTodo.sendDialog.variant.default"),e[0]=o,e[1]=n,e[2]=c):c=e[2];const d=c,p=a?"cursor-not-allowed opacity-60":"cursor-pointer hover:bg-interactive-hover/30";let m;e[3]!==p?(m=pe("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(Cs,{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 y;e[11]!==f?(y=s.jsx(Bs,{asChild:!0,children:f}),e[11]=f,e[12]=y):y=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=pe("font-medium",g),e[15]=g,e[16]=w):w=e[16];let v;e[17]!==o?(v=o("rightSidebar.contextNotesTodo.sendDialog.variant.default"),e[17]=o,e[18]=v):v=e[18];let S;e[19]!==w||e[20]!==v?(S=s.jsx("span",{className:w,children:v}),e[19]=w,e[20]=v,e[21]=S):S=e[21];let A;e[22]!==S||e[23]!==x?(A=s.jsx($t,{className:"typography-meta",onSelect:x,children:S}),e[22]=S,e[23]=x,e[24]=A):A=e[24];let j;if(e[25]!==i||e[26]!==r||e[27]!==n){let R;e[29]!==i||e[30]!==n?(R=k=>s.jsx($t,{className:"typography-meta",onSelect:()=>i(k),children:s.jsx("span",{className:pe("font-medium capitalize",n===k&&"text-primary"),children:k})},k),e[29]=i,e[30]=n,e[31]=R):R=e[31],j=r.map(R),e[25]=i,e[26]=r,e[27]=n,e[28]=j}else j=e[28];let C;e[32]!==A||e[33]!==j?(C=s.jsxs(Vs,{align:"start",className:"max-w-[220px]",children:[A,j]}),e[32]=A,e[33]=j,e[34]=C):C=e[34];let I;return e[35]!==C||e[36]!==y?(I=s.jsxs(zs,{children:[y,C]}),e[35]=C,e[36]=y,e[37]=I):I=e[37],I};function Jg(t){const e=nt.c(99),{t:n}=ut(),{open:r,onOpenChange:a,target:i,projectDirectory:o,submitting:c,onConfirm:d}=t,p=c===void 0?!1:c,m=yt(q0),u=yt(G0),h=_i(H0),b=yt(K0),f=yt(W0),y=yt(U0),x=yt(_0),g=yt(z0);let w;e[0]!==g||e[1]!==y||e[2]!==f||e[3]!==x?(w=()=>up({providerID:f,modelID:y,variant:x,agent:g}),e[0]=g,e[1]=y,e[2]=f,e[3]=x,e[4]=w):w=e[4];const[v,S]=l.useState(w);let A,j;e[5]!==h||e[6]!==u||e[7]!==m||e[8]!==r||e[9]!==o?(A=()=>{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]=A,e[11]=j):(A=e[10],j=e[11]),l.useEffect(A,j);let C,I;e[12]!==g||e[13]!==y||e[14]!==f||e[15]!==x||e[16]!==r?(C=()=>{r&&S(up({providerID:f,modelID:y,variant:x,agent:g}))},I=[r,f,y,x,g],e[12]=g,e[13]=y,e[14]=f,e[15]=x,e[16]=r,e[17]=C,e[18]=I):(C=e[17],I=e[18]),l.useEffect(C,I);let R,k;e[19]!==v.modelID||e[20]!==v.providerID||e[21]!==r||e[22]!==b?(R=()=>{if(!r||b.length===0)return;const fe=b.find(Pe=>Pe.id===v.providerID)??b[0],ke=Array.isArray(fe?.models)?fe.models:[],xe=ke.some(Pe=>Pe.id===v.modelID),he=ke[0]?.id??"";fe?.id===v.providerID&&xe||S(Pe=>({...Pe,providerID:fe?.id??"",modelID:xe?Pe.modelID:he,variant:""}))},k=[r,b,v.providerID,v.modelID],e[19]=v.modelID,e[20]=v.providerID,e[21]=r,e[22]=b,e[23]=R,e[24]=k):(R=e[23],k=e[24]),l.useEffect(R,k);const P=V0;let N;if(e[25]!==v.modelID||e[26]!==v.providerID||e[27]!==b){let fe;e[29]!==v.providerID?(fe=xe=>xe.id===v.providerID,e[29]=v.providerID,e[30]=fe):fe=e[30],N=b.find(fe)?.models?.find(xe=>xe.id===v.modelID),e[25]=v.modelID,e[26]=v.providerID,e[27]=b,e[28]=N}else N=e[28];const D=N;let T;e[31]!==D?(T=D?.variants?Object.keys(D.variants):[],e[31]=D,e[32]=T):T=e[32];const M=T,$=M.length>0;let F,V;e[33]!==v.variant||e[34]!==$?(F=()=>{$||!v.variant||S(B0)},V=[$,v.variant],e[33]=v.variant,e[34]=$,e[35]=F,e[36]=V):(F=e[35],V=e[36]),l.useEffect(F,V);let O;e[37]!==v.modelID||e[38]!==v.providerID?(O=v.providerID.trim().length>0&&v.modelID.trim().length>0,e[37]=v.modelID,e[38]=v.providerID,e[39]=O):O=e[39];const L=O;let W;e[40]!==L||e[41]!==v||e[42]!==d||e[43]!==p?(W=()=>{!L||p||d(v)},e[40]=L,e[41]=v,e[42]=d,e[43]=p,e[44]=W):W=e[44];const B=W;let ne,le;e[45]!==B||e[46]!==r?(ne=()=>{if(!r)return;const fe=ke=>{(ke.metaKey||ke.ctrlKey)&&ke.key==="Enter"&&(ke.preventDefault(),B())};return window.addEventListener("keydown",fe),()=>window.removeEventListener("keydown",fe)},le=[r,B],e[45]=B,e[46]=r,e[47]=ne,e[48]=le):(ne=e[47],le=e[48]),l.useEffect(ne,le);let ee;e[49]!==n||e[50]!==i?(ee=n(i==="worktree"?"rightSidebar.contextNotesTodo.sendDialog.title.newWorktree":"rightSidebar.contextNotesTodo.sendDialog.title.newSession"),e[49]=n,e[50]=i,e[51]=ee):ee=e[51];const ae=ee;let ge;e[52]!==a||e[53]!==p?(ge=fe=>{p||a(fe)},e[52]=a,e[53]=p,e[54]=ge):ge=e[54];let te;e[55]!==ae?(te=s.jsx(Is,{children:s.jsx(Ss,{children:ae})}),e[55]=ae,e[56]=te):te=e[56];let E;e[57]===Symbol.for("react.memo_cache_sentinel")?(E=(fe,ke)=>{S(xe=>({...xe,providerID:fe,modelID:ke,variant:""}))},e[57]=E):E=e[57];let z;e[58]!==v.modelID||e[59]!==v.providerID?(z=s.jsx(Ho,{providerId:v.providerID,modelId:v.modelID,onChange:E}),e[58]=v.modelID,e[59]=v.providerID,e[60]=z):z=e[60];const J=!$;let H;e[61]===Symbol.for("react.memo_cache_sentinel")?(H=fe=>S(ke=>({...ke,variant:fe})),e[61]=H):H=e[61];let re;e[62]!==v.variant||e[63]!==J||e[64]!==M?(re=s.jsx($0,{value:v.variant,options:M,disabled:J,onChange:H}),e[62]=v.variant,e[63]=J,e[64]=M,e[65]=re):re=e[65];let ce;e[66]===Symbol.for("react.memo_cache_sentinel")?(ce=fe=>S(ke=>({...ke,agent:fe})),e[66]=ce):ce=e[66];let Ne;e[67]!==v.agent?(Ne=s.jsx(jc,{agentName:v.agent,filter:P,onChange:ce}),e[67]=v.agent,e[68]=Ne):Ne=e[68];let me;e[69]!==z||e[70]!==re||e[71]!==Ne?(me=s.jsxs("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-2",children:[z,re,Ne]}),e[69]=z,e[70]=re,e[71]=Ne,e[72]=me):me=e[72];let we;e[73]!==a?(we=()=>a(!1),e[73]=a,e[74]=we):we=e[74];let _;e[75]!==n?(_=n("rightSidebar.contextNotesTodo.sendDialog.actions.cancel"),e[75]=n,e[76]=_):_=e[76];let ue;e[77]!==p||e[78]!==we||e[79]!==_?(ue=s.jsx(je,{variant:"ghost",size:"sm",onClick:we,disabled:p,children:_}),e[77]=p,e[78]=we,e[79]=_,e[80]=ue):ue=e[80];const Q=!L||p;let oe;e[81]!==p||e[82]!==n?(oe=n(p?"rightSidebar.contextNotesTodo.sendDialog.actions.sending":"rightSidebar.contextNotesTodo.sendDialog.actions.send"),e[81]=p,e[82]=n,e[83]=oe):oe=e[83];let Z;e[84]!==B||e[85]!==Q||e[86]!==oe?(Z=s.jsx(je,{size:"sm",onClick:B,disabled:Q,children:oe}),e[84]=B,e[85]=Q,e[86]=oe,e[87]=Z):Z=e[87];let Ie;e[88]!==ue||e[89]!==Z?(Ie=s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[ue,Z]}),e[88]=ue,e[89]=Z,e[90]=Ie):Ie=e[90];let Se;e[91]!==te||e[92]!==me||e[93]!==Ie?(Se=s.jsxs(vs,{className:"max-w-lg",children:[te,me,Ie]}),e[91]=te,e[92]=me,e[93]=Ie,e[94]=Se):Se=e[94];let Y;return e[95]!==r||e[96]!==ge||e[97]!==Se?(Y=s.jsx(ws,{open:r,onOpenChange:ge,children:Se}),e[95]=r,e[96]=ge,e[97]=Se,e[98]=Y):Y=e[98],Y}function B0(t){return{...t,variant:""}}function V0(t){return ug(t.mode)}function z0(t){return t.currentAgentName||""}function _0(t){return t.currentVariant||""}function U0(t){return t.currentModelId}function W0(t){return t.currentProviderId}function K0(t){return t.providers}function H0(t){return t.loadAgents}function G0(t){return t.loadAgents}function q0(t){return t.loadProviders}const Q0=async(t,e)=>{const n=await Fv(t.path);return{...t,title:n?.title||t.path.split("/").pop()||e}},J0=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`todo_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,Y0=({projectRef:t,projectLabel:e,canCreateWorktree:n=!1,onActionComplete:r,className:a})=>{const{t:i}=ut(),[o,c]=l.useState(!1),[d,p]=l.useState(""),[m,u]=l.useState([]),[h,b]=l.useState(""),[f,y]=l.useState(null),[x,g]=l.useState(()=>new Set),[w,v]=l.useState([]),[S,A]=l.useState(null),[j,C]=l.useState(!1),[I,R]=l.useState(0),k=l.useRef(!1),P=l.useRef(""),N=Wt(Y=>Y.currentSessionId),D=Wt(Y=>Y.createSession),T=Wt(Y=>Y.initializeNewOpenChamberSession),M=Wt(Y=>Y.sendMessage),$=Wt(Y=>Y.setCurrentSession),F=Ui(Y=>Y.setPendingInputText),V=Ws(Y=>Y.currentDirectory),O=Te(Y=>Y.openContextPanelTab),L=Te(Y=>Y.setActiveMainTab),W=Te(Y=>Y.setSessionSwitcherOpen),B=l.useCallback(async(Y,fe)=>{if(!t)return!1;const ke=await Tv(t,{notes:Y,todos:fe});return ke||q.error(i("rightSidebar.contextNotesTodo.toast.saveNotesFailed")),ke},[t,i]);l.useEffect(()=>{if(!t){p(""),u([]),v([]),b(""),g(new Set);return}let Y=!1;return c(!0),(async()=>{try{const fe=await Mv(t),ke=await Promise.all(fe.plans.map(xe=>Q0(xe,i("rightSidebar.contextNotesTodo.plan.defaultTitle"))));if(Y)return;p(fe.notes),u(fe.todos),v(ke),P.current=fe.notes,k.current=!0,b(""),g(new Set)}catch{Y||(q.error(i("rightSidebar.contextNotesTodo.toast.loadNotesFailed")),p(""),u([]),v([]),P.current="",k.current=!0)}finally{Y||c(!1)}})(),()=>{Y=!0}},[I,t,i]),l.useEffect(()=>{if(!t)return;const Y=fe=>{const ke=fe.detail;ke?.projectId&&ke.projectId!==t.id||R(xe=>xe+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(()=>{P.current=d,B(d,m)},[d,B,m]);l.useEffect(()=>{if(!t||!k.current||d===P.current)return;const Y=window.setTimeout(()=>{P.current=d,B(d,m)},400);return()=>{window.clearTimeout(Y)}},[d,B,t,m]);const le=l.useCallback(()=>{const Y=h.trim();if(!Y)return;const fe=[...m,{id:J0(),text:Y.slice(0,el),completed:!1,createdAt:Date.now()}];u(fe),b(""),B(d,fe)},[h,d,B,m]),ee=l.useCallback(Y=>{g(fe=>{const ke=new Set(fe);return ke.has(Y)?ke.delete(Y):ke.add(Y),ke})},[]),ae=l.useCallback((Y,fe)=>{const ke=m.map(xe=>xe.id===Y?{...xe,completed:fe}:xe);u(ke),B(d,ke)},[d,B,m]),ge=l.useCallback(Y=>{const fe=m.filter(ke=>ke.id!==Y);u(fe),B(d,fe)},[d,B,m]),te=l.useCallback(()=>{const Y=m.filter(fe=>!fe.completed);Y.length!==m.length&&(u(Y),B(d,Y))},[d,B,m]),E=h.slice(0,el),z=m.reduce((Y,fe)=>Y+(fe.completed?1:0),0),J=l.useCallback(()=>{L("chat"),W(!1)},[L,W]),H=l.useCallback((Y,fe)=>{!t||f||A({kind:"session",todoId:Y,todoText:fe})},[t,f]),re=l.useCallback(Y=>{if(!N){q.error(i("rightSidebar.contextNotesTodo.toast.noActiveSession"));return}J();const fe=`\`\`\`md
4
- ${Y}
5
- \`\`\``;F(fe,"append"),q.success(i("rightSidebar.contextNotesTodo.toast.sentToCurrentSession")),r?.()},[N,r,J,F,i]),ce=l.useCallback((Y,fe)=>{if(!(!t||f)){if(!n){q.error(i("rightSidebar.contextNotesTodo.toast.worktreeRequiresGitRepo"));return}A({kind:"worktree",todoId:Y,todoText:fe})}},[n,t,f,i]),Ne=l.useCallback(async Y=>{if(!t||!S)return;const fe=await Vn("plan.todo.visible",{todo_text:S.todoText}),xe=[{synthetic:!0,text:await Vn("plan.todo.instructions",{todo_text:S.todoText})}];C(!0),y(S.todoId);try{J();let he=null,Pe=t.path;if(S.kind==="worktree"){if(!n){q.error(i("rightSidebar.contextNotesTodo.toast.worktreeRequiresGitRepo"));return}const G=await mg(t.path,pg());if(!G?.id)return;he=G.id,Pe=null}else{const G=await D(void 0,t.path,null);if(!G?.id){q.error(i("rightSidebar.contextNotesTodo.toast.createSessionFailed"));return}he=G.id,Pe=G.directory??t.path,T(G.id,yt.getState().agents??[])}if(!he)return;const Be=hc.getState();Be.saveSessionModelSelection(he,Y.providerID,Y.modelID),Y.agent.trim()&&(Be.saveSessionAgentSelection(he,Y.agent),Be.saveAgentModelForSession(he,Y.agent,Y.providerID,Y.modelID),Be.saveAgentModelVariantForSession(he,Y.agent,Y.providerID,Y.modelID,Y.variant||void 0)),$(he,Pe),await M(fe,Y.providerID,Y.modelID,Y.agent.trim()||void 0,void 0,void 0,xe,Y.variant||void 0),q.success(S.kind==="worktree"?i("rightSidebar.contextNotesTodo.toast.sentToNewWorktreeSession"):i("rightSidebar.contextNotesTodo.toast.sentToNewSession")),A(null),r?.()}catch(he){const Pe=he instanceof Error?he.message:void 0;q.error(i("rightSidebar.contextNotesTodo.toast.sendTodoFailed"),Pe?{description:Pe}:void 0)}finally{C(!1),y(null)}},[n,D,T,r,S,t,J,M,$,i]),me=l.useRef(null),[we,_]=l.useState(!1),[ue,Q]=l.useState(null),oe=l.useCallback(async Y=>{if(!(!t||ue)){Q(Y);try{if(!await Rv(t,Y)){q.error(i("rightSidebar.contextNotesTodo.toast.deletePlanFailed"));return}v(ke=>ke.filter(xe=>xe.id!==Y)),window.dispatchEvent(new CustomEvent("openchamber:project-plan-saved",{detail:{projectId:t.id}}))}finally{Q(null)}}},[ue,t,i]),Z=l.useCallback(()=>{!t||we||me.current?.click()},[we,t]),Ie=l.useCallback(async Y=>{if(!(!t||!Y)){_(!0);try{const fe=await Y.text();if(!fe.trim()){q.error(i("rightSidebar.contextNotesTodo.toast.planFileEmpty"));return}const ke=Y.name.replace(/\.(md|markdown|txt)$/i,"").trim();if(!await Ev(t,fe,ke)){q.error(i("rightSidebar.contextNotesTodo.toast.importPlanFailed"));return}window.dispatchEvent(new CustomEvent("openchamber:project-plan-saved",{detail:{projectId:t.id}})),q.success(i("rightSidebar.contextNotesTodo.toast.planImported"))}catch(fe){const ke=fe instanceof Error?fe.message:void 0;q.error(i("rightSidebar.contextNotesTodo.toast.readPlanFileFailed"),ke?{description:ke}:void 0)}finally{_(!1)}}},[t,i]),Se=l.useCallback(Y=>{const fe=t?.path?.trim(),ke=V?.trim()||fe;ke&&O(ke,{mode:"plan",targetPath:Y.path,dedupeKey:Y.path,label:Y.title})},[V,O,t]);return t?s.jsxs("div",{className:pe("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,"/",vm]})]}),s.jsx(Sn,{value:d,onChange:Y=>p(Y.target.value.slice(0,vm)),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:te,disabled:o||z===0,className:"typography-meta rounded-md px-1.5 py-0.5 text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50",children:i("rightSidebar.contextNotesTodo.todo.clearCompleted")})]}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[E.length,"/",el]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Vt,{value:E,onChange:Y=>b(Y.target.value.slice(0,el)),onKeyDown:Y=>{Y.key==="Enter"&&(Y.preventDefault(),le())},placeholder:i("rightSidebar.contextNotesTodo.todo.inputPlaceholder"),disabled:o,className:"h-8"}),s.jsx("button",{type:"button",onClick:le,disabled:o||E.trim().length===0,className:"inline-flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-md border border-border/70 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50","aria-label":i("rightSidebar.contextNotesTodo.todo.addAria"),title:i("rightSidebar.contextNotesTodo.todo.addAria"),children:s.jsx(_s,{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(bs,{checked:Y.completed,onChange:ke=>ae(Y.id,ke),ariaLabel:i("rightSidebar.contextNotesTodo.todo.actions.markComplete",{text:Y.text})})}),s.jsx("button",{type:"button",onClick:()=>ee(Y.id),className:pe("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:()=>ge(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(sn,{className:"h-3.5 w-3.5"})}),s.jsxs(zs,{children:[s.jsx(Bs,{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(jb,{className:"h-3.5 w-3.5"})})}),s.jsxs(Vs,{align:"end",className:"w-56",children:[s.jsx($t,{onClick:()=>re(Y.text),children:i("rightSidebar.contextNotesTodo.todo.sendMenu.currentSession")}),s.jsx($t,{onClick:()=>H(Y.id,Y.text),children:i("rightSidebar.contextNotesTodo.todo.sendMenu.newSession")}),s.jsx($t,{onClick:()=>{ce(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:me,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:Z,disabled:!t||we,className:"inline-flex h-6 w-6 items-center justify-center rounded-md border border-border/70 text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed disabled:opacity-50","aria-label":i("rightSidebar.contextNotesTodo.plans.importFromFile"),title:i("rightSidebar.contextNotesTodo.plans.importFromFile"),children:s.jsx(_s,{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:()=>Se(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:()=>{oe(Y.id)},disabled:ue===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(sn,{className:"h-3.5 w-3.5"})})]},Y.id))})})]}),s.jsx(Jg,{open:S!==null,onOpenChange:Y=>{!Y&&!j&&A(null)},target:S?.kind??"session",projectDirectory:t?.path??null,submitting:j,onConfirm:Ne})]}):s.jsx("div",{className:pe("w-full min-w-0 p-3",a),children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:i("rightSidebar.contextNotesTodo.empty.selectProject")})})},Yg=12,X0=[{id:"left",x:22,y:58,delay:0,radius:120,colorVar:"--status-success"},{id:"center",x:50,y:42,delay:120,radius:150,colorVar:"--primary-base"},{id:"right",x:78,y:55,delay:200,radius:130,colorVar:"--status-info"}],Z0=t=>{const e=nt.c(18),{isActive:n,burstKey:r,className:a,durationMs:i,bursts:o,onComplete:c}=t,d=r===void 0?0:r,p=i===void 0?900:i,m=o===void 0?X0:o,u=Oe.useRef(!1);let 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]),Oe.useEffect(h,b);let f;e[4]===Symbol.for("react.memo_cache_sentinel")?(f=Array.from({length:Yg},eN),e[4]=f):f=e[4];const y=f;if(!n)return null;let x;e[5]!==a?(x=pe("fireworks-overlay pointer-events-none",a),e[5]=a,e[6]=x):x=e[6];let g;if(e[7]!==d||e[8]!==m||e[9]!==p){let v;e[11]!==d||e[12]!==p?(v=S=>{const A={"--burst-delay":`${S.delay}ms`,"--burst-x":`${S.x}%`,"--burst-y":`${S.y}%`,"--firework-color":`var(${S.colorVar})`,"--firework-duration":`${p}ms`};return s.jsx("div",{className:"firework-burst",style:A,children:y.map((j,C)=>{const I=j.x*S.radius,R=j.y*S.radius,k={"--translate-x":`${I}px`,"--translate-y":`${R}px`,"--particle-delay":`${j.delay}ms`,color:`var(${S.colorVar})`};return s.jsx("span",{className:"firework-particle",style:k},`${S.id}-${C}-${d}`)})},`${S.id}-${d}`)},e[11]=d,e[12]=p,e[13]=v):v=e[13],g=m.map(v),e[7]=d,e[8]=m,e[9]=p,e[10]=g}else g=e[10];let w;return e[14]!==d||e[15]!==x||e[16]!==g?(w=s.jsx("div",{className:x,"aria-hidden":"true","data-burst-key":d,children:g}),e[14]=d,e[15]=x,e[16]=g,e[17]=w):w=e[17],w};function eN(t,e){const n=Math.PI*2*e/Yg;return{x:Math.cos(n),y:Math.sin(n),delay:e*18}}const tN=t=>{const e=nt.c(13);let n;e[0]!==t?(n={},e[0]=t,e[1]=n):n=e[1];const{durationMs:r}=n,a=r===void 0?3400:r;let i;e[2]===Symbol.for("react.memo_cache_sentinel")?(i={isActive:!1,cycle:0},e[2]=i):i=e[2];const[o,c]=Oe.useState(i),d=Oe.useRef(null);let p;e[3]===Symbol.for("react.memo_cache_sentinel")?(p=()=>{d.current&&(window.clearTimeout(d.current),d.current=null)},e[3]=p):p=e[3];const m=p;let u;e[4]===Symbol.for("react.memo_cache_sentinel")?(u=()=>{m(),c(sN)},e[4]=u):u=e[4];const h=u;let b;e[5]!==a?(b=()=>{m(),c(nN),d.current=window.setTimeout(()=>{c(rN),d.current=null},a)},e[5]=a,e[6]=b):b=e[6];const f=b;let y,x;e[7]===Symbol.for("react.memo_cache_sentinel")?(y=()=>()=>m(),x=[m],e[7]=y,e[8]=x):(y=e[7],x=e[8]),Oe.useEffect(y,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 sN(t){return t.isActive?{...t,isActive:!1}:t}function nN(t){return{isActive:!0,cycle:t.cycle+1}}function rN(t){return t.isActive?{...t,isActive:!1}:t}const Xg=l.createContext(void 0),aN=t=>{const e=nt.c(10),{children:n}=t,{isActive:r,burstKey:a,triggerFireworks:i,dismissFireworks:o}=tN();let c;e[0]!==o||e[1]!==i?(c={triggerFireworks:i,dismissFireworks:o},e[0]=o,e[1]=i,e[2]=c):c=e[2];const d=c;let p;e[3]!==a||e[4]!==r?(p=s.jsx(Z0,{isActive:r,burstKey:a}),e[3]=a,e[4]=r,e[5]=p):p=e[5];let m;return e[6]!==n||e[7]!==p||e[8]!==d?(m=s.jsxs(Xg.Provider,{value:d,children:[n,p]}),e[6]=n,e[7]=p,e[8]=d,e[9]=m):m=e[9],m},iN=()=>{const t=l.useContext(Xg);if(!t)throw new Error("useFireworksCelebration must be used within FireworksProvider");return t},ar=wr()(Xi($o((t,e)=>({selectedProfileId:null,defaultGitIdentityId:null,profiles:[],globalIdentity:null,discoveredCredentials:[],isLoading:!1,setSelectedProfile:n=>{t({selectedProfileId:n})},loadProfiles:async()=>{t({isLoading:!0});const n=e().profiles;try{const r=await zv();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 Vv();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 Bv();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=xr()?.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 Rs({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 $v(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 Lv(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 Ov(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:lc(()=>ba()),partialize:t=>({selectedProfileId:t.selectedProfileId})}),{name:"git-identities-store"}));typeof window<"u"&&(window.__zustand_git_identities_store__=ar);function oi(t){const e=nt.c(12);let n,r,a;e[0]!==t?({className:n,style:a,...r}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=a):(n=e[1],r=e[2],a=e[3]);let i;e[4]!==a?(i={color:"var(--surface-elevated-foreground)",...a},e[4]=a,e[5]=i):i=e[5];let o;e[6]!==n?(o=pe("flex h-full w-full flex-col overflow-hidden rounded-xl",n),e[6]=n,e[7]=o):o=e[7];let c;return e[8]!==r||e[9]!==i||e[10]!==o?(c=s.jsx(ui,{"data-slot":"command",style:i,className:o,...r}),e[8]=r,e[9]=i,e[10]=o,e[11]=c):c=e[11],c}const ka=Oe.forwardRef((t,e)=>{const n=nt.c(10);let r,a;n[0]!==t?({className:r,...a}=t,n[0]=t,n[1]=r,n[2]=a):(r=n[1],a=n[2]);let i;n[3]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx(Hn,{className:"size-4 shrink-0 opacity-50"}),n[3]=i):i=n[3];let o;n[4]!==r?(o=pe("placeholder:text-muted-foreground flex h-8 w-full rounded-lg bg-transparent py-2 typography-meta outline-none focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50",r),n[4]=r,n[5]=o):o=n[5];let c;return n[6]!==a||n[7]!==e||n[8]!==o?(c=s.jsxs("div",{"data-slot":"command-input-wrapper",className:"flex h-8 items-center gap-2 border-b px-3",children:[i,s.jsx(ui.Input,{ref:e,"data-slot":"command-input",className:o,...a})]}),n[6]=a,n[7]=e,n[8]=o,n[9]=c):c=n[9],c});ka.displayName="CommandInput";function li(t){const e=nt.c(14);let n,r,a,i,o;e[0]!==t?({className:r,children:n,scrollbarClassName:o,disableHorizontal:a,...i}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=a,e[4]=i,e[5]=o):(n=e[1],r=e[2],a=e[3],i=e[4],o=e[5]);let c;e[6]!==r?(c=pe("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(Es,{as:ui.List,"data-slot":"command-list",outerClassName:"max-h-[min(600px,calc(100vh-10rem))] overflow-x-hidden p-0 w-full h-full min-h-0",className:c,scrollbarClassName:d,disableHorizontal:p,...i,children:n}),e[8]=n,e[9]=i,e[10]=c,e[11]=d,e[12]=p,e[13]=m):m=e[13],m}function ci(t){const e=nt.c(4);let n;e[0]!==t?({...n}=t,e[0]=t,e[1]=n):n=e[1];let r;return e[2]!==n?(r=s.jsx(ui.Empty,{"data-slot":"command-empty",className:"py-6 text-center typography-ui-label",...n}),e[2]=n,e[3]=r):r=e[3],r}function Kn(t){const e=nt.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let a;e[3]!==n?(a=pe("text-foreground [&_[cmdk-group-heading]]:text-muted-foreground overflow-hidden p-1 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:typography-meta [&_[cmdk-group-heading]]:font-medium",n),e[3]=n,e[4]=a):a=e[4];let i;return e[5]!==r||e[6]!==a?(i=s.jsx(ui.Group,{"data-slot":"command-group",className:a,...r}),e[5]=r,e[6]=a,e[7]=i):i=e[7],i}function Ka(t){const e=nt.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let a;e[3]!==n?(a=pe("bg-border -mx-1 h-px",n),e[3]=n,e[4]=a):a=e[4];let i;return e[5]!==r||e[6]!==a?(i=s.jsx(ui.Separator,{"data-slot":"command-separator",className:a,...r}),e[5]=r,e[6]=a,e[7]=i):i=e[7],i}function Rn(t){const e=nt.c(8);let n,r;e[0]!==t?({className:n,...r}=t,e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]);let a;e[3]!==n?(a=pe("data-[selected=true]:bg-interactive-selection data-[selected=true]:text-interactive-selection-foreground data-[highlighted]:bg-interactive-hover hover:bg-interactive-hover [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 typography-meta outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",n),e[3]=n,e[4]=a):a=e[4];let i;return e[5]!==r||e[6]!==a?(i=s.jsx(ui.Item,{"data-slot":"command-item",className:a,...r}),e[5]=r,e[6]=a,e[7]=i):i=e[7],i}function oN(t){const e=nt.c(12);let n,r,a,i;if(e[0]!==t){const{className:c,...d}=t,p=cN,m=typeof d.children=="string"?d.children:"",u=m?m.split("+").map(lN).filter(Boolean):[];n="command-shortcut",e[5]!==c?(r=pe("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(Oe.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 lN(t){return t.trim()}function cN(t){const e=t.trim().toLowerCase();return e==="ctrl"||e==="control"?s.jsx("span",{className:"text-xs font-medium",children:"ctrl"}):e==="cmd"||e==="⌘"||e==="command"||e==="meta"?s.jsx(Bo,{className:"size-3.5"}):e==="shift"||e==="⇧"?s.jsx(_l,{className:"size-3.5"}):s.jsx("span",{className:"text-xs font-medium",children:t})}const Gd=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},dN=t=>{const e=Gd(t);if(!e)return null;const r=e.indexOf("/.git/worktrees/");return r>0&&e.slice(0,r)||null};function uN(t,e,n){const r=nt.c(5),[a,i]=l.useState();let o,c;return r[0]!==n||r[1]!==t||r[2]!==e?(o=()=>{if(e){i(void 0);return}if(!t){i(void 0);return}i(void 0);let d=!1;return(async()=>{const[p,m]=await Promise.all([Hs("git rev-parse --absolute-git-dir",t),Hs("git rev-parse --show-toplevel",t)]);if(d||!p.success||!m.success)return;const u=Gd((p.stdout||"").trim()),h=dN(u);if(!h)return;const b=Gd((m.stdout||"").trim());if(!b||b===h)return;const f=n||"",y=b.split("/").filter(Boolean).pop()||b;i({source:"sdk",path:b,projectDirectory:h,branch:f,label:f||y,name:y,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 ir=t=>{const e=t.trim();return e?`'${e.replace(/'/g,"'\\''")}'`:"''"},Qi=t=>(t||"").split(/\r?\n/).map(e=>e.trim()).filter(Boolean),la=t=>!!t.success,Nc=t=>(t.stdout||"").trim(),Ja=t=>(t.stderr||"").trim();async function mN(t){const n=((await Hs("git worktree list --porcelain",t)).stdout||"").split(/\r?\n/),r=[];let a=null;for(const i of n){if(i.startsWith("worktree ")){a&&r.push(a),a={path:i.slice(9).trim(),branchRef:null};continue}a&&i.startsWith("branch ")&&(a.branchRef=i.slice(7).trim())}return a&&r.push(a),r.filter(i=>!!i.path)}async function pN(t){const e=`refs/heads/${t.targetBranch}`,n=new Set(t.excludePaths),a=(await mN(t.repoRoot)).filter(o=>o.branchRef===e).map(o=>o.path).filter(o=>o&&!n.has(o)),i=[];for(const o of a){const c=await Hs("git status --porcelain",o);Nc(c)||i.push(o)}return i}async function Zg(t,e){for(const n of e)await Hs("git reset --hard",n).catch(()=>{})}async function fN(t,e){const n=e.trim();if(!n||n==="HEAD")return"HEAD";const r=await Hs(`git show-ref --verify --quiet ${ir(`refs/heads/${n}`)}`,t);if(la(r))return n;if(n.startsWith("remotes/")){const o=n.slice(8).split("/"),c=o[0]||"origin",d=o.slice(1).join("/");if(d)return await Hs(`git branch --track ${ir(d)} ${ir(`${c}/${d}`)}`,t),d}const a=await Hs(`git show-ref --verify --quiet ${ir(`refs/remotes/origin/${n}`)}`,t);return la(a)&&await Hs(`git branch --track ${ir(n)} ${ir(`origin/${n}`)}`,t),n}async function ao(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 fN(e,r),i=await Hs(`git cherry ${ir(a)} ${ir(n)}`,e),o=Qi(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 Hs(`git rev-list --reverse ${ir(`${a}..${n}`)}`,e),m=Qi(d.stdout).filter(u=>c.has(u));return{repoRoot:e,sourceBranch:n,targetBranch:a,commits:m}}async function hN(t,e){const n=await Hs('mkdir -p "$HOME/.config/openchamber/tmp"',t);if(!la(n))throw new Error(Ja(n)||"Failed to create temp directory parent");const r=await Hs('mktemp -d "$HOME/.config/openchamber/tmp/oc-integrate-XXXXXX"',t),a=Nc(r);if(!a)throw new Error(Ja(r)||"Failed to create temp directory");const i=await Hs(`git worktree add --force ${ir(a)} ${ir(e)}`,t);if(!la(i))throw new Error(Ja(i)||"Failed to create temp worktree");return a}async function Xl(t,e){await Hs(`git worktree remove --force ${ir(e)}`,t).catch(()=>{}),await Hs("git worktree prune",t).catch(()=>{})}async function gN(t){const e=await Hs("git rev-parse --abbrev-ref --symbolic-full-name @{u}",t),n=Nc(e);if(!n)return;await Hs("git fetch",t);const r=await Hs(`git merge --ff-only ${ir(n)}`,t);if(!la(r))throw new Error(Ja(r)||"Fast-forward failed")}async function Zl(t){const e=await Hs("git status --porcelain",t),n=await Hs("git diff --name-only --diff-filter=U",t),r=await Hs("git diff",t),a=await Hs("git show --no-patch --pretty=fuller CHERRY_PICK_HEAD",t),i=await Hs("git show CHERRY_PICK_HEAD",t);return{statusPorcelain:e.stdout||"",unmergedFiles:Qi(n.stdout),diff:r.stdout||r.stderr||"",currentPatchMeta:a.stdout||a.stderr||"",currentPatch:i.stdout||i.stderr||""}}async function xN(t){return Zl(t)}async function bN(t){const e=await Hs("git rev-parse --verify --quiet CHERRY_PICK_HEAD",t);return la(e)}async function yN(t){if(t.commits.length===0)return{kind:"noop",reason:"No commits to move"};const e=await hN(t.repoRoot,t.targetBranch);let n=[];try{await gN(e);const r=await Hs("git status --porcelain",e);if(Nc(r))throw new Error("Target branch has local changes; abort integration and retry");const a=await pN({repoRoot:t.repoRoot,targetBranch:t.targetBranch,excludePaths:[e]}).catch(()=>[]);for(n=[...t.commits];n.length>0;){const i=n[0],o=await Hs(`git cherry-pick ${ir(i)}`,e);if(la(o)){n.shift();continue}const c=await Hs("git diff --name-only --diff-filter=U",e);if(Qi(c.stdout).length>0){const p=await Zl(e);return{kind:"conflict",state:{repoRoot:t.repoRoot,tempWorktreePath:e,sourceBranch:t.sourceBranch,targetBranch:t.targetBranch,cleanTargetWorktrees:a,remainingCommits:n,currentCommit:i},details:p}}throw new Error(Ja(o)||"Cherry-pick failed")}return await Xl(t.repoRoot,e),await Zg(t.repoRoot,a).catch(()=>{}),{kind:"success",moved:t.commits.length}}catch(r){throw await Xl(t.repoRoot,e).catch(()=>{}),r}}async function vN(t){await Hs("git cherry-pick --abort",t.tempWorktreePath).catch(()=>{}),await Xl(t.repoRoot,t.tempWorktreePath)}async function wN(t){const e=await Hs("git cherry-pick --continue",t.tempWorktreePath);if(!la(e)){const i=await Hs("git diff --name-only --diff-filter=U",t.tempWorktreePath);if(Qi(i.stdout).length>0){const c=await Zl(t.tempWorktreePath);return{kind:"conflict",state:t,details:c}}throw new Error(Ja(e)||"Cherry-pick continue failed")}const n=t.tempWorktreePath,r=[...t.remainingCommits];r.length>0&&r[0]===t.currentCommit&&r.shift();const a=[...r];for(;a.length>0;){const i=a[0],o=await Hs(`git cherry-pick ${ir(i)}`,n);if(la(o)){a.shift();continue}const c=await Hs("git diff --name-only --diff-filter=U",n);if(Qi(c.stdout).length>0){const p=await Zl(n);return{kind:"conflict",state:{repoRoot:t.repoRoot,tempWorktreePath:n,sourceBranch:t.sourceBranch,targetBranch:t.targetBranch,cleanTargetWorktrees:t.cleanTargetWorktrees,remainingCommits:a,currentCommit:i},details:p}}throw new Error(Ja(o)||"Cherry-pick failed")}return await Xl(t.repoRoot,t.tempWorktreePath),await Zg(t.repoRoot,t.cleanTargetWorktrees).catch(()=>{}),{kind:"success",moved:t.remainingCommits.length}}const jN=({repoRoot:t,sourceBranch:e,worktreeMetadata:n,localBranches:r,defaultTargetBranch:a,refreshKey:i,onRefresh:o})=>{const{t:c}=ut(),d=Wt(O=>O.currentSessionId),p=Te(O=>O.setActiveMainTab),[m,u]=Oe.useState(!1),h=Oe.useRef(null),[b,f]=Oe.useState(a);Oe.useEffect(()=>{f(a)},[a]),Oe.useEffect(()=>{if(m){const O=setTimeout(()=>{h.current?.focus()},0);return()=>clearTimeout(O)}},[m]);const y=!!(t&&e&&b&&b!=="HEAD"&&e!==b),[x,g]=Oe.useState({kind:"idle"}),[w,v]=Oe.useState(!1),[S,A]=Oe.useState([]),j=Oe.useMemo(()=>d?`openchamber.integrate.conflict:${d}`:null,[d]);Oe.useEffect(()=>{if(!j||typeof window>"u")return;const O=window.localStorage.getItem(j);if(!O)return;let L=!1;try{const W=JSON.parse(O);if(!W?.tempWorktreePath||W.repoRoot!==t){window.localStorage.removeItem(j);return}(async()=>{const B=await bN(W.tempWorktreePath).catch(()=>!1);if(L)return;if(!B){window.localStorage.removeItem(j);return}const ne=await xN(W.tempWorktreePath).catch(()=>null);L||ne&&g({kind:"conflict",state:W,details:ne})})()}catch{window.localStorage.removeItem(j)}return()=>{L=!0}},[j,t]),Oe.useEffect(()=>{if(!y){g({kind:"idle"});return}let O=!1;return g({kind:"loading"}),(async()=>{try{const L=await ao({repoRoot:t,sourceBranch:e,targetBranch:b});if(O)return;if(g({kind:"ready",plan:L}),L.commits.length>0){const ne=L.commits.slice(-50).reverse().map(ge=>JSON.stringify(ge)).join(" "),ee=((await Hs(`git show -s --format=%H%x09%h%x09%s ${ne}`,t)).stdout||"").split(/\r?\n/).filter(Boolean),ae=[];for(const ge of ee){const[te,E,z]=ge.split(" ");!te||!E||ae.push({sha:te,short:E,subject:z||""})}O||(A(ae),v(!1))}else O||(A([]),v(!1))}catch{O||g({kind:"idle"})}})(),()=>{O=!0}},[y,t,e,b,i]);const C=Oe.useCallback(O=>{d&&Wt.getState().setWorktreeMetadata(d,{...n,createdFromBranch:O})},[d,n]),I=Wt(O=>O.openNewSessionDraft),R=Oe.useCallback(async O=>{const L=await Vn("git.integrate.cherrypick.resolve.visible",{current_commit:O.state.currentCommit,target_branch:O.state.targetBranch}),W=await Vn("git.integrate.cherrypick.resolve.instructions",{repo_root:O.state.repoRoot,temp_worktree_path:O.state.tempWorktreePath,source_branch:O.state.sourceBranch,target_branch:O.state.targetBranch,current_commit:O.state.currentCommit}),B=`Cherry-pick conflict context (JSON)
6
- ${JSON.stringify({repoRoot:O.state.repoRoot,tempWorktreePath:O.state.tempWorktreePath,sourceBranch:O.state.sourceBranch,targetBranch:O.state.targetBranch,currentCommit:O.state.currentCommit,remainingCommits:O.state.remainingCommits,statusPorcelain:O.details.statusPorcelain,unmergedFiles:O.details.unmergedFiles,currentPatchMeta:O.details.currentPatchMeta,currentPatch:O.details.currentPatch,diff:O.details.diff},null,2)}`;return{visibleText:L,instructionsText:W,payloadText:B}},[]),k=Ui(O=>O.setPendingInputText),P=Ui(O=>O.setPendingSyntheticParts),N=Oe.useCallback(async(O,L)=>{const W=await R(O);if(L){I({directoryOverride:O.state.tempWorktreePath,initialPrompt:W.visibleText,syntheticParts:[{text:W.instructionsText,synthetic:!0},{text:W.payloadText,synthetic:!0}]}),p("chat");return}if(!d){q.error(c("gitView.integrate.noActiveSession"),{description:c("gitView.integrate.noActiveSessionDescription")});return}k(W.visibleText,"replace"),P([{text:W.instructionsText,synthetic:!0},{text:W.payloadText,synthetic:!0}]),p("chat")},[d,p,R,I,k,P,c]),D=Oe.useCallback(async()=>{if(x.kind==="ready"){if(x.plan.commits.length===0){q.message(c("gitView.integrate.noCommitsToMoveToast"));return}g({kind:"running",plan:x.plan});try{const O=await yN(x.plan);if(O.kind==="success"){q.success(c("gitView.integrate.commitsMovedToast"),{description:O.moved===1?c("gitView.integrate.commitsMovedDescriptionSingle",{count:O.moved,branch:x.plan.targetBranch}):c("gitView.integrate.commitsMovedDescriptionPlural",{count:O.moved,branch:x.plan.targetBranch})});const L=await ao(x.plan);g({kind:"ready",plan:L}),o?.();return}O.kind==="conflict"&&(q.error(c("gitView.integrate.cherryPickConflictToast"),{description:c("gitView.integrate.cherryPickConflictDescription")}),g({kind:"conflict",state:O.state,details:O.details}),j&&typeof window<"u"&&window.localStorage.setItem(j,JSON.stringify(O.state)))}catch(O){const L=O instanceof Error?O.message:String(O);q.error(c("gitView.integrate.failedToMoveToast"),{description:L});const W=await ao({repoRoot:t,sourceBranch:e,targetBranch:b}).catch(()=>null);g(W?{kind:"ready",plan:W}:{kind:"idle"})}}},[x,o,t,e,b,j,c]),T=Oe.useCallback(async()=>{if(x.kind==="conflict")try{await vN(x.state),q.message(c("gitView.integrate.cherryPickAbortedToast")),j&&typeof window<"u"&&window.localStorage.removeItem(j)}finally{const O=await ao({repoRoot:t,sourceBranch:e,targetBranch:b}).catch(()=>null);g(O?{kind:"ready",plan:O}:{kind:"idle"})}},[x,t,e,b,j,c]),M=Oe.useCallback(async()=>{if(x.kind==="conflict")try{const O=await wN(x.state);if(O.kind==="success"){q.success(c("gitView.integrate.cherryPickFinishedToast"));const L=await ao({repoRoot:t,sourceBranch:e,targetBranch:b}).catch(()=>null);g(L?{kind:"ready",plan:L}:{kind:"idle"}),j&&typeof window<"u"&&window.localStorage.removeItem(j),o?.();return}O.kind==="conflict"&&(g({kind:"conflict",state:O.state,details:O.details}),j&&typeof window<"u"&&window.localStorage.setItem(j,JSON.stringify(O.state)))}catch(O){const L=O instanceof Error?O.message:String(O);q.error(c("gitView.integrate.cherryPickContinueFailedToast"),{description:L})}},[x,t,e,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(Nb,{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(Zt,{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(zs,{open:m,onOpenChange:u,children:[s.jsx(Bs,{asChild:!0,children:s.jsxs(je,{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(Cs,{className:"size-4 opacity-60"})]})}),s.jsx(Vs,{align:"end",className:"w-72 p-0 max-h-[var(--available-height)] flex flex-col overflow-hidden",children:s.jsxs(oi,{className:"h-full min-h-0",children:[s.jsx(ka,{ref:h,placeholder:c("gitView.branch.searchPlaceholder")}),s.jsxs(li,{className:"h-full min-h-0",scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[s.jsx(ci,{children:c("gitView.branch.empty")}),s.jsx(Kn,{heading:c("gitView.branch.localBranches"),children:r.map(O=>s.jsx(Rn,{value:O,onSelect:()=>{f(O),C(O),u(!1)},children:O},O))})]})]})})]}),x.kind==="ready"?s.jsx(je,{size:"sm",onClick:()=>{D()},disabled:!y||x.plan.commits.length===0,children:c("gitView.integrate.move")}):x.kind==="loading"?s.jsx(je,{size:"sm",variant:"outline",disabled:!0,children:c("gitView.integrate.checking")}):x.kind==="running"?s.jsx(je,{size:"sm",variant:"outline",disabled:!0,children:c("gitView.integrate.moving")}):null]}),x.kind==="ready"&&x.plan.commits.length===0&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:c("gitView.integrate.noCommitsToMove")}),x.kind==="ready"&&x.plan.commits.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"typography-meta text-foreground",children:[c("gitView.integrate.commitsToMove"),s.jsxs("span",{className:"text-muted-foreground",children:[" (",x.plan.commits.length,")"]})]}),S.length>0&&x.plan.commits.length>5&&s.jsx("button",{type:"button",onClick:()=>v(O=>!O),className:"typography-micro text-muted-foreground hover:text-foreground",children:c(w?"gitView.integrate.showLess":"gitView.integrate.showAll")})]}),s.jsxs("div",{className:"space-y-1",children:[(w?S:S.slice(0,5)).map(O=>s.jsxs("div",{className:"flex items-baseline gap-2 min-w-0",children:[s.jsx("span",{className:"font-mono text-xs text-muted-foreground flex-shrink-0",children:O.short}),s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:O.subject||O.sha})]},O.sha)),S.length===0&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:c("gitView.integrate.previewUnavailable")}),x.plan.commits.length>S.length&&s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:c("gitView.integrate.showingFirstCommits",{count:S.length})})]})]}),x.kind==="conflict"&&s.jsxs("div",{className:"rounded-md border border-border/60 bg-background/60 p-3 space-y-2",children:[s.jsx("div",{className:"typography-meta text-foreground",children:c("gitView.integrate.conflictsInFiles",{count:x.details.unmergedFiles.length})}),s.jsxs("div",{className:"typography-micro text-muted-foreground/80",children:[c("gitView.integrate.currentCommit"),": ",s.jsx("span",{className:"font-mono",children:x.state.currentCommit.slice(0,7)})]}),s.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[x.details.unmergedFiles.slice(0,6).map(O=>s.jsx("span",{className:"font-mono text-xs px-2 py-0.5 rounded bg-muted/40 text-muted-foreground",children:O},O)),x.details.unmergedFiles.length>6&&s.jsx("span",{className:"text-xs text-muted-foreground",children:c("gitView.integrate.moreFiles",{count:x.details.unmergedFiles.length-6})})]}),s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsx(je,{size:"sm",variant:"ghost",className:"typography-meta",onClick:()=>{T()},children:c("gitView.operation.abort")}),s.jsxs(je,{size:"sm",variant:"secondary",className:"typography-meta gap-1",disabled:!d,onClick:()=>{N({state:x.state,details:x.details},!1)},children:[s.jsx(Pd,{className:"size-3.5"}),c("gitView.integrate.currentSession")]}),s.jsxs(je,{size:"sm",variant:"secondary",className:"typography-meta gap-1",onClick:()=>{N({state:x.state,details:x.details},!0)},children:[s.jsx(Pd,{className:"size-3.5"}),c("gitView.integrate.newSession")]}),s.jsx(je,{size:"sm",className:"typography-meta",onClick:()=>{M()},children:c("gitView.operation.continue")})]})]})]})]})},NN=t=>t.trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._/-]/g,"-").replace(/-+/g,"-").replace(/\/{2,}/g,"/").replace(/\/-+/g,"/").replace(/-+\//g,"/").replace(/^[-/]+/,"").replace(/[-/]+$/,""),SN=({currentBranch:t,localBranches:e,remoteBranches:n,branchInfo:r,onCheckout:a,onCreate:i,remotes:o=[],disabled:c=!1})=>{const{t:d}=ut(),[p,m]=l.useState(!1),[u,h]=l.useState(""),[b,f]=l.useState(!1),[y,x]=l.useState(!1),[g,w]=l.useState(""),[v,S]=l.useState(!1),A=l.useRef(null),j=l.useCallback(F=>{F.stopPropagation()},[]),C=o.length>1,I=l.useMemo(()=>NN(g),[g]),R=l.useMemo(()=>{const F=u.toLowerCase();return F?e.filter(V=>V.toLowerCase().includes(F)):e},[u,e]),k=l.useMemo(()=>{const F=u.toLowerCase();return F?n.filter(V=>V.toLowerCase().includes(F)):n},[u,n]),P=F=>{if(F===t){m(!1);return}a(F),m(!1),h("")},N=()=>{f(!0),setTimeout(()=>A.current?.focus(),50)},D=async()=>{if(!(!I||v)){if(C){x(!0);return}S(!0);try{await i(I,o[0]),w(""),f(!1),m(!1)}finally{S(!1)}}},T=async F=>{if(!(!I||v)){S(!0);try{await i(I,F),w(""),f(!1),x(!1),m(!1)}finally{S(!1)}}},M=()=>{x(!1)},$=()=>{w(""),f(!1),x(!1)};return l.useEffect(()=>{p||(h(""),f(!1),x(!1),w(""))},[p]),s.jsxs(zs,{open:p,onOpenChange:m,children:[s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx(Bs,{asChild:!0,children:s.jsxs(je,{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(Ks,{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(Cs,{className:"size-4 opacity-60"})]})})}),s.jsx(Ct,{sideOffset:8,children:d("gitView.branch.currentBranchTooltip")})]}),s.jsx(Vs,{align:"start",className:"w-72 p-0 max-h-[60vh] flex flex-col",children:s.jsxs(oi,{className:"h-full min-h-0",children:[s.jsx(ka,{placeholder:d("gitView.branch.searchPlaceholder"),value:u,onValueChange:h}),s.jsxs(li,{scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[s.jsx(ci,{children:d("gitView.branch.empty")}),s.jsx(Kn,{children:y?s.jsxs("div",{className:"px-2 py-1.5",children:[s.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[s.jsx("button",{type:"button",onClick:M,disabled:v,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:s.jsx(Sb,{className:"size-4"})}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[d("gitView.branch.pushToPrefix")," ",s.jsx("span",{className:"text-foreground font-medium",children:I})," ",d("gitView.branch.pushToSuffix")]})]}),s.jsx("div",{className:"flex flex-col gap-1",children:o.map(F=>s.jsxs("button",{type:"button",onClick:()=>T(F),disabled:v,className:"flex flex-col items-start gap-0.5 px-2 py-1.5 rounded-md text-left hover:bg-accent disabled:opacity-50",children:[s.jsxs("span",{className:"typography-ui-label text-foreground",children:[v?s.jsx(Zt,{className:"inline size-3 mr-1.5 animate-spin"}):null,F.name]}),s.jsx("span",{className:"typography-micro text-muted-foreground truncate max-w-full",children:F.pushUrl})]},F.name))})]}):b?s.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded-lg",children:[s.jsx("input",{ref:A,placeholder:d("gitView.branch.newBranchPlaceholder"),value:g,onChange:F=>w(F.target.value),onClick:F=>F.stopPropagation(),onKeyDown:F=>{j(F),F.key==="Enter"?(F.preventDefault(),D()):F.key==="Escape"&&(F.preventDefault(),$())},className:"flex-1 min-w-0 bg-transparent typography-meta outline-none placeholder:text-muted-foreground"}),s.jsx("button",{type:"button",onClick:D,disabled:!I||v,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:v?s.jsx(Zt,{className:"size-4 animate-spin"}):s.jsx(_s,{className:"size-4"})}),s.jsx("button",{type:"button",onClick:$,disabled:v,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:s.jsx(Ds,{className:"size-4"})})]}):s.jsxs(Rn,{onSelect:N,children:[s.jsx(_s,{className:"size-4"}),s.jsx("span",{children:d("gitView.branch.create")})]})}),s.jsx(Ka,{}),s.jsxs(Kn,{heading:d("gitView.branch.localBranches"),children:[R.map(F=>s.jsxs(Rn,{onSelect:()=>P(F),children:[s.jsxs("span",{className:"flex flex-1 flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:F}),(r?.[F]?.ahead||r?.[F]?.behind)&&s.jsxs("span",{className:"typography-micro text-muted-foreground",children:[r[F].ahead||0," ahead ·"," ",r[F].behind||0," behind"]})]}),t===F&&s.jsx("span",{className:"typography-micro text-primary",children:d("gitView.branch.currentBadge")})]},`local-${F}`)),R.length===0&&s.jsx(Rn,{disabled:!0,className:"justify-center",children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:d("gitView.branch.noLocalBranches")})})]}),s.jsx(Ka,{}),s.jsxs(Kn,{heading:d("gitView.branch.remoteBranches"),children:[k.map(F=>s.jsx(Rn,{onSelect:()=>P(F),children:s.jsx("span",{className:"typography-ui-label text-foreground",children:F})},`remote-${F}`)),k.length===0&&s.jsx(Rn,{disabled:!0,className:"justify-center",children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:d("gitView.branch.noRemoteBranches")})})]})]})]})})]})},kN=t=>t.trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._/-]/g,"-").replace(/-+/g,"-").replace(/\/{2,}/g,"/").replace(/\/-+/g,"/").replace(/-+\//g,"/").replace(/^[-/]+/,"").replace(/[-/]+$/,""),CN=({currentBranch:t,onRename:e,showEditButton:n=!0})=>{const{t:r}=ut(),[a,i]=l.useState(!1),[o,c]=l.useState(t||""),[d,p]=l.useState(!1),m=l.useRef(null),u=()=>{!t||!e||(c(t),i(!0),setTimeout(()=>m.current?.focus(),0))},h=async()=>{if(!t||!e||!o.trim())return;const y=kN(o);if(y===t){i(!1);return}p(!0);try{await e(t,y),i(!1),c("")}finally{p(!1)}},b=()=>{i(!1),c("")},f=y=>{y.key==="Enter"?(y.preventDefault(),h()):y.key==="Escape"&&(y.preventDefault(),b())};return a?s.jsx("div",{className:"flex items-center gap-2 rounded-md bg-primary/12 px-2 py-1 h-8",children:s.jsxs("form",{className:"flex w-full items-center gap-2",onSubmit:y=>{y.preventDefault(),h()},children:[s.jsx(Ks,{className:"size-4 text-primary"}),s.jsx("input",{ref:m,value:o,onChange:y=>c(y.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",placeholder:r("gitView.branch.namePlaceholder"),onKeyDown:f,autoFocus:!0}),s.jsx("button",{type:"submit",disabled:d,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:d?s.jsx(Zt,{className:"size-4 animate-spin"}):s.jsx(Ys,{className:"size-4"})}),s.jsx("button",{type:"button",onClick:b,disabled:d,className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:s.jsx(Ds,{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(Ks,{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(je,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 shrink-0",onClick:u,title:r("gitView.branch.renameTitle"),children:s.jsx(Yr,{className:"size-4"})})]})]})},IN=t=>{const e=nt.c(41),{syncAction:n,remotes:r,onFetch:a,onSync:i,onRemoveRemote:o,disabled:c,removingRemoteName:d,aheadCount:p,behindCount:m,trackingRemoteName:u,hasUncommittedChanges:h}=t,b=r===void 0?[]:r,f=d===void 0?null:d,y=p===void 0?0:p,x=m===void 0?0:m,g=h===void 0?!1:h,{t:w}=ut(),v=l.useRef(!1),S=!!f,A=b.find(_=>_.name===u)??b[0],j=x>0&&g,C=c||n!==null||S||!A||j,I=c||n!==null||S||b.length===0,R=y>0||x>0;let k;e[0]!==w?(k=w("gitView.sync.sync"),e[0]=w,e[1]=k):k=e[1];const P=x>0?`↓${x}`:null,N=y>0?`↑${y}`:null;let D;e[2]!==k||e[3]!==P||e[4]!==N?(D=[k,P,N].filter(Boolean),e[2]=k,e[3]=P,e[4]=N,e[5]=D):D=e[5];const T=D.join(" "),M=j?w("gitView.sync.commitOrStashTooltip"):A?R?w("gitView.sync.syncChangesTooltip",{ahead:y,behind:x}):w("gitView.sync.syncChanges"):w("gitView.sync.noRemoteTooltip"),$=()=>{A&&i(A)},F="inline-flex items-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] border border-border/60 bg-[var(--surface-elevated)] overflow-hidden";let V;e[6]===Symbol.for("react.memo_cache_sentinel")?(V=pe("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]=V):V=e[6];let O;e[7]!==w?(O=w("gitView.sync.syncChanges"),e[7]=w,e[8]=O):O=e[8];let L;e[9]!==n?(L=n==="sync"?s.jsx(Zt,{className:"size-4 animate-spin"}):s.jsx(Nn,{className:"size-4"}),e[9]=n,e[10]=L):L=e[10];let W;e[11]!==T?(W=s.jsx("span",{className:"whitespace-nowrap tabular-nums",children:T}),e[11]=T,e[12]=W):W=e[12];let B;e[13]!==$||e[14]!==C||e[15]!==O||e[16]!==L||e[17]!==W?(B=s.jsx(St,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:$,disabled:C,className:V,"aria-label":O,children:[L,W]})}),e[13]=$,e[14]=C,e[15]=O,e[16]=L,e[17]=W,e[18]=B):B=e[18];let ne;e[19]!==M?(ne=s.jsx(Ct,{sideOffset:8,children:M}),e[19]=M,e[20]=ne):ne=e[20];let le;e[21]!==B||e[22]!==ne?(le=s.jsxs(kt,{children:[B,ne]}),e[21]=B,e[22]=ne,e[23]=le):le=e[23];const ee=zs;let ae;e[24]===Symbol.for("react.memo_cache_sentinel")?(ae=pe("inline-flex h-7 w-6 items-center justify-center border-l border-[var(--interactive-border)] text-muted-foreground","transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50"),e[24]=ae):ae=e[24];let ge;e[25]!==w?(ge=w("gitView.sync.moreActionsAria"),e[25]=w,e[26]=ge):ge=e[26];let te;e[27]===Symbol.for("react.memo_cache_sentinel")?(te=s.jsx(Cs,{className:"size-4"}),e[27]=te):te=e[27];let E;e[28]!==I||e[29]!==ge?(E=s.jsx(Bs,{asChild:!0,children:s.jsx("button",{type:"button",className:ae,disabled:I,"aria-label":ge,children:te})}),e[28]=I,e[29]=ge,e[30]=E):E=e[30];const z=Vs,J="start",H=-40,re="w-[min(360px,calc(100vw-2rem))] max-h-[320px] overflow-y-auto",ce=b.map(_=>s.jsx($t,{onSelect:ue=>{if(v.current){ue.preventDefault(),v.current=!1;return}a(_)},children:s.jsxs("div",{className:"flex w-full items-center gap-2",children:[s.jsx(Nn,{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:_.name})}),s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:_.fetchUrl})]})}),o&&_.name!==u?s.jsx(je,{type:"button",variant:"destructive",size:"xs",className:"h-6 w-6 px-0",disabled:n!==null||S,onPointerDown:ue=>{v.current=!0,ue.preventDefault(),ue.stopPropagation()},onClick:ue=>{v.current=!0,ue.preventDefault(),ue.stopPropagation(),o(_)},"aria-label":w("gitView.header.removeRemoteAria",{name:_.name}),title:w("gitView.header.removeRemoteTitle",{name:_.name}),children:f===_.name?s.jsx(Zt,{className:"size-3.5 animate-spin"}):s.jsx(Ds,{className:"size-3.5"})}):null]})},_.name));let Ne;e[31]!==z||e[32]!==ce?(Ne=s.jsx(z,{align:J,alignOffset:H,className:re,children:ce}),e[31]=z,e[32]=ce,e[33]=Ne):Ne=e[33];let me;e[34]!==ee||e[35]!==E||e[36]!==Ne?(me=s.jsxs(ee,{children:[E,Ne]}),e[34]=ee,e[35]=E,e[36]=Ne,e[37]=me):me=e[37];let we;return e[38]!==le||e[39]!==me?(we=s.jsxs("div",{className:F,children:[le,me]}),e[38]=le,e[39]=me,e[40]=we):we=e[40],we},AN={branch:Ks,briefcase:ju,house:wu,graduation:vu,code:cc,heart:Rh,user:qr},PN={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)",success:"var(--status-success)",info:"var(--status-info)",warning:"var(--status-warning)"};function ex(t){return t&&PN[t]||"var(--primary)"}const mp=t=>{const e=nt.c(8),{icon:n,className:r,colorToken:a}=t,i=AN[n??"branch"]??qr;let o;e[0]!==a?(o=ex(a),e[0]=a,e[1]=o):o=e[1];let c;e[2]!==o?(c={color:o},e[2]=o,e[3]=c):c=e[3];let d;return e[4]!==i||e[5]!==r||e[6]!==c?(d=s.jsx(i,{className:r,style:c}),e[4]=i,e[5]=r,e[6]=c,e[7]=d):d=e[7],d},tx=t=>{const e=nt.c(35),{activeProfile:n,identities:r,onSelect:a,isApplying:i,iconOnly:o}=t,c=o===void 0?!1:o,{t:d}=ut(),p=i||r.length===0,m=n?.color;let u;e[0]!==m?(u=ex(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(Zt,{className:"size-4 animate-spin"}):s.jsx(mp,{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 y;e[12]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx(Cs,{className:"size-4 opacity-60"}),e[12]=y):y=e[12];let x;e[13]!==p||e[14]!==h||e[15]!==b||e[16]!==f?(x=s.jsx(St,{asChild:!0,children:s.jsx(Bs,{asChild:!0,children:s.jsxs(je,{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,y]})})}),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(Ct,{sideOffset:8,children:g}),e[20]=g,e[21]=w):w=e[21];let v;e[22]!==w||e[23]!==x?(v=s.jsxs(kt,{children:[x,w]}),e[22]=w,e[23]=x,e[24]=v):v=e[24];let S;e[25]!==n?.id||e[26]!==r||e[27]!==a||e[28]!==d?(S=r.length===0?s.jsx("div",{className:"px-2 py-1.5",children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:d("gitView.header.noProfiles")})}):r.map(C=>{const I=n?.id===C.id;return s.jsx($t,{onSelect:()=>a(C),children:s.jsxs("span",{className:"flex items-center gap-2",children:[s.jsx(mp,{icon:C.icon,colorToken:C.color,className:"size-4"}),s.jsxs("span",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:C.name}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:C.userEmail})]}),I?s.jsx(Ys,{className:"ml-auto size-4 text-foreground"}):null]})},C.id)}),e[25]=n?.id,e[26]=r,e[27]=a,e[28]=d,e[29]=S):S=e[29];let A;e[30]!==S?(A=s.jsx(Vs,{align:"end",className:"w-64",children:S}),e[30]=S,e[31]=A):A=e[31];let j;return e[32]!==v||e[33]!==A?(j=s.jsxs(zs,{children:[v,A]}),e[32]=v,e[33]=A,e[34]=j):j=e[34],j},DN=t=>{const e=nt.c(48),{status:n,localBranches:r,remoteBranches:a,branchInfo:i,syncAction:o,remotes:c,onFetch:d,onSync:p,onRemoveRemote:m,removingRemoteName:u,onCheckoutBranch:h,onCreateBranch:b,onRenameBranch:f,activeIdentityProfile:y,availableIdentities:x,onSelectIdentity:g,isApplyingIdentity:w,isWorktreeMode:v,onOpenHistory:S,actionTabItems:A,activeActionTab:j,onSelectActionTab:C}=t,{t:I}=ut();if(!n)return null;let R;e[0]!==S||e[1]!==I?(R=S?s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx(je,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0",onClick:S,children:s.jsx(Eh,{className:"size-4"})})}),s.jsx(Ct,{sideOffset:8,children:I("gitView.history.title")})]}):null,e[0]=S,e[1]=I,e[2]=R):R=e[2];let k;e[3]!==R?(k=s.jsx("div",{className:"flex items-center gap-1 shrink-0",children:R}),e[3]=R,e[4]=k):k=e[4];const P=k,N=!n;let D;e[5]!==n.tracking?(D=n.tracking?.split("/")[0],e[5]=n.tracking,e[6]=D):D=e[6];const T=(n.files?.length??0)>0;let M;e[7]!==d||e[8]!==m||e[9]!==p||e[10]!==c||e[11]!==u||e[12]!==n.ahead||e[13]!==n.behind||e[14]!==o||e[15]!==N||e[16]!==D||e[17]!==T?(M=s.jsx(IN,{syncAction:o,remotes:c,onFetch:d,onSync:p,onRemoveRemote:m,removingRemoteName:u,disabled:N,iconOnly:!0,aheadCount:n.ahead,behindCount:n.behind,trackingRemoteName:D,hasUncommittedChanges:T}),e[7]=d,e[8]=m,e[9]=p,e[10]=c,e[11]=u,e[12]=n.ahead,e[13]=n.behind,e[14]=o,e[15]=N,e[16]=D,e[17]=T,e[18]=M):M=e[18];const $=M;let F;e[19]!==y||e[20]!==x||e[21]!==w||e[22]!==g?(F=s.jsx(tx,{activeProfile:y,identities:x,onSelect:g,isApplying:w,iconOnly:!0}),e[19]=y,e[20]=x,e[21]=w,e[22]=g,e[23]=F):F=e[23];const V=F;let O;e[24]!==i||e[25]!==v||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:v?s.jsx(CN,{currentBranch:n.current,onRename:f}):s.jsx(SN,{currentBranch:n.current,localBranches:r,remoteBranches:a,branchInfo:i,onCheckout:h,onCreate:b,remotes:c})}),e[24]=i,e[25]=v,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 L;e[34]!==V||e[35]!==P?(L=s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[P,V]}),e[34]=V,e[35]=P,e[36]=L):L=e[36];let W;e[37]!==O||e[38]!==L?(W=s.jsxs("div",{className:"flex items-center justify-between gap-2 min-w-0",children:[O,L]}),e[37]=O,e[38]=L,e[39]=W):W=e[39];let B;e[40]!==A||e[41]!==j||e[42]!==C||e[43]!==$?(B=A&&j&&C?s.jsxs("div",{className:"mt-3 flex h-8 min-w-0 items-center gap-2",children:[s.jsx("div",{className:"min-w-0 flex-1",children:s.jsx(Br,{items:A,activeId:j,onSelect:C,layoutMode:"fit",variant:"active-pill",iconOnlyActiveTab:!0,activePillButtonClassName:"h-7",className:"h-full"})}),s.jsx("div",{className:"shrink-0",children:$})]}):null,e[40]=A,e[41]=j,e[42]=C,e[43]=$,e[44]=B):B=e[44];let ne;return e[45]!==W||e[46]!==B?(ne=s.jsxs("header",{className:"@container/git-header px-3 py-2 bg-transparent",children:[W,B]}),e[45]=W,e[46]=B,e[47]=ne):ne=e[47],ne},TN=({open:t,onOpenChange:e,directory:n,hasUncommittedChanges:r,uncommittedFileCount:a,onChanged:i})=>{const{t:o}=ut(),[c,d]=l.useState([]),[p,m]=l.useState(!1),[u,h]=l.useState(""),[b,f]=l.useState(""),[y,x]=l.useState(null),[g,w]=l.useState({}),v=l.useCallback(async()=>{if(n){m(!0);try{const R=await _v(n);d(R.stashes),w({})}catch(R){q.error(R instanceof Error?R.message:o("gitView.stashes.toast.loadFailed"))}finally{m(!1)}}},[n,o]);l.useEffect(()=>{t&&v()},[v,t]),l.useEffect(()=>{if(!t||!n||c.length===0)return;let R=!1;const k=c.map(P=>P.ref);return Uv(n,k).then(P=>{R||w(P.counts)}).catch(()=>{}),()=>{R=!0}},[n,t,c]);const S=l.useMemo(()=>{const R=u.trim().toLowerCase();return R?c.filter(k=>`${k.ref} ${k.message} ${k.relativeTime}`.toLowerCase().includes(R)):c},[u,c]),A=l.useCallback(async()=>{await v(),await i?.()},[v,i]),j=async()=>{if(!(!n||y)){x("create");try{(await Wv(n,{message:b.trim()||void 0})).created?(q.success(o("gitView.stashes.toast.created")),f("")):q.info(o("gitView.stashes.toast.noChanges")),await A()}catch(R){q.error(R instanceof Error?R.message:o("gitView.stashes.toast.createFailed"))}finally{x(null)}}},C=async(R,k)=>{if(!(!n||y)&&!(k==="drop"&&!window.confirm(o("gitView.stashes.confirm.drop",{ref:R.ref})))){x(`${k}:${R.ref}`);try{k==="apply"&&await Kv(n,{ref:R.ref}),k==="pop"&&await Hv(n,{ref:R.ref}),k==="drop"&&await Gv(n,{ref:R.ref});const P=k==="apply"?"gitView.stashes.toast.applySuccess":k==="pop"?"gitView.stashes.toast.popSuccess":"gitView.stashes.toast.dropSuccess";q.success(o(P)),await A()}catch(P){const N=k==="apply"?"gitView.stashes.toast.applyFailed":k==="pop"?"gitView.stashes.toast.popFailed":"gitView.stashes.toast.dropFailed";q.error(P instanceof Error?P.message:o(N)),await A()}finally{x(null)}}},I=y!==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(Is,{children:[s.jsxs(Ss,{className:"flex items-center gap-2",children:[s.jsx(Nu,{className:"h-5 w-5"}),o("gitView.stashes.title")]}),s.jsx(Os,{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(Vt,{value:b,onChange:R=>f(R.target.value),placeholder:o("gitView.stashes.messagePlaceholder"),disabled:I||!r,className:"flex-1"}),s.jsxs(je,{onClick:j,disabled:!r||I||!n,children:[y==="create"?s.jsx(Zt,{className:"size-4 animate-spin"}):s.jsx(kb,{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(Hn,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),s.jsx(Vt,{value:u,onChange:R=>h(R.target.value),placeholder:o("gitView.stashes.searchPlaceholder"),className:"pl-9"})]}),s.jsx("div",{className:"flex-1 overflow-y-auto",children:p?s.jsx("div",{className:"flex items-center justify-center py-10 text-muted-foreground",children:s.jsx(Zt,{className:"size-5 animate-spin"})}):S.length===0?s.jsx("div",{className:"py-8 text-center text-muted-foreground",children:o(u?"gitView.stashes.empty.search":"gitView.stashes.empty.list")}):S.map((R,k)=>s.jsxs("div",{className:"group flex items-center gap-2 rounded py-1.5 transition-colors hover:bg-interactive-hover/30",children:[s.jsxs("div",{className:"min-w-0 flex-1 pl-2",children:[s.jsx("p",{className:"typography-small truncate text-foreground",children:R.message||o("gitView.stashes.untitled")}),s.jsxs("p",{className:"typography-meta truncate text-muted-foreground",children:[s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx("span",{children:k===0&&!u.trim()?o("gitView.stashes.latestLabel"):o("gitView.stashes.itemNumber",{number:k+1})})}),s.jsx(Ct,{sideOffset:6,children:R.ref})]})," · ",R.relativeTime," · ",typeof g[R.ref]=="number"?o("gitView.stashes.fileCount",{count:g[R.ref]}):o("gitView.stashes.fileCountLoading")]})]}),s.jsxs("div",{className:"mr-2 flex shrink-0 items-center gap-1 opacity-100 sm:opacity-0 sm:group-hover:opacity-100",children:[s.jsx(ed,{label:o("gitView.stashes.actions.apply"),loading:y===`apply:${R.ref}`,onClick:()=>C(R,"apply"),disabled:I,children:s.jsx(Cb,{className:"size-4"})}),s.jsx(ed,{label:o("gitView.stashes.actions.pop"),loading:y===`pop:${R.ref}`,onClick:()=>C(R,"pop"),disabled:I,children:s.jsx(Ib,{className:"size-4"})}),s.jsx(ed,{label:o("gitView.stashes.actions.drop"),loading:y===`drop:${R.ref}`,onClick:()=>C(R,"drop"),disabled:I,destructive:!0,children:s.jsx(sn,{className:"size-4"})})]})]},R.ref))})]})})},ed=t=>{const e=nt.c(15),{label:n,loading:r,disabled:a,destructive:i,onClick:o,children:c}=t,d=i?"text-[var(--status-error)] hover:text-[var(--status-error)]":"text-muted-foreground hover:text-foreground";let p;e[0]!==d?(p=pe("flex h-6 w-6 items-center justify-center transition-colors disabled:opacity-50",d),e[0]=d,e[1]=p):p=e[1];let m;e[2]!==c||e[3]!==r?(m=r?s.jsx(Zt,{className:"size-4 animate-spin"}):c,e[2]=c,e[3]=r,e[4]=m):m=e[4];let u;e[5]!==a||e[6]!==o||e[7]!==p||e[8]!==m?(u=s.jsx(St,{asChild:!0,children:s.jsx("button",{type:"button",className:p,onClick:o,disabled:a,children:m})}),e[5]=a,e[6]=o,e[7]=p,e[8]=m,e[9]=u):u=e[9];let h;e[10]!==n?(h=s.jsx(Ct,{sideOffset:6,children:n}),e[10]=n,e[11]=h):h=e[11];let b;return e[12]!==u||e[13]!==h?(b=s.jsxs(kt,{children:[u,h]}),e[12]=u,e[13]=h,e[14]=b):b=e[14],b},sx={"?":{code:"?",color:"var(--status-info)",description:"Untracked file"},A:{code:"A",color:"var(--status-success)",description:"New file"},D:{code:"D",color:"var(--status-error)",description:"Deleted file"},R:{code:"R",color:"var(--status-info)",description:"Renamed file"},C:{code:"C",color:"var(--status-info)",description:"Copied file"},M:{code:"M",color:"var(--status-warning)",description:"Modified file"}},MN=sx.M;function RN(t){const e=t.index?.trim(),n=t.working_dir?.trim();return e&&e!=="?"?e.charAt(0):n?n.charAt(0):e?.charAt(0)||n?.charAt(0)||"M"}function EN(t){const e=RN(t);return sx[e]??MN}const pp=l.memo(function(e){const n=nt.c(71),{file:r,checked:a,onToggle:i,onViewDiff:o,onRevert:c,isReverting:d,stats:p,rowPaddingClassName:m,indentPx:u}=e,h=u===void 0?0:u;let b;n[0]!==r?(b=EN(r),n[0]=r,n[1]=b):b=n[1];const f=b,{t:y}=ut(),x=f.description,g=p?.insertions??0,w=p?.deletions??0;let v;n[2]!==i||n[3]!==o?(v=E=>{E.key===" "?(E.preventDefault(),i()):E.key==="Enter"&&(E.preventDefault(),o())},n[2]=i,n[3]=o,n[4]=v):v=n[4];const S=v;let A;n[5]!==c?(A=E=>{E.preventDefault(),E.stopPropagation(),c()},n[5]=c,n[6]=A):A=n[6];const j=A,C=`group flex items-center gap-2 py-1.5 hover:bg-sidebar/40 cursor-pointer ${m??"px-3"}`;let I;n[7]!==h?(I=h>0?{paddingLeft:`${h}px`}:void 0,n[7]=h,n[8]=I):I=n[8];let R;n[9]!==i?(R=()=>i(),n[9]=i,n[10]=R):R=n[10];let k;n[11]!==r.path||n[12]!==y?(k=y("gitView.changes.selectFileAria",{path:r.path}),n[11]=r.path,n[12]=y,n[13]=k):k=n[13];let P;n[14]!==a||n[15]!==R||n[16]!==k?(P=s.jsx("div",{className:"flex size-5 shrink-0 items-center justify-center",onClick:FN,children:s.jsx(bs,{size:"sm",checked:a,onChange:R,ariaLabel:k})}),n[14]=a,n[15]=R,n[16]=k,n[17]=P):P=n[17];let N;n[18]!==f.color?(N={color:f.color},n[18]=f.color,n[19]=N):N=n[19];let D;n[20]!==f.code||n[21]!==x||n[22]!==N?(D=s.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:N,title:x,"aria-label":x,children:f.code}),n[20]=f.code,n[21]=x,n[22]=N,n[23]=D):D=n[23];let T;n[24]!==r.path?(T=s.jsx(Pr,{filePath:r.path,className:"h-3.5 w-3.5 shrink-0"}),n[24]=r.path,n[25]=T):T=n[25];let M;if(n[26]!==r.path){e:{const E=r.path.lastIndexOf("/");if(E===-1){let me;n[28]===Symbol.for("react.memo_cache_sentinel")?(me={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},n[28]=me):me=n[28],M=s.jsx("span",{className:"flex-1 min-w-0 truncate typography-ui-label text-foreground",style:me,title:r.path,children:r.path});break e}const z=r.path.slice(0,E),J=r.path.slice(E);let H;n[29]===Symbol.for("react.memo_cache_sentinel")?(H={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},n[29]=H):H=n[29];let re;n[30]===Symbol.for("react.memo_cache_sentinel")?(re=s.jsx("span",{className:"text-muted-foreground",children:"/"}),n[30]=re):re=n[30];const ce=s.jsx("span",{className:"text-foreground",children:J.slice(1)});let Ne;n[31]!==ce?(Ne=s.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[re,ce]}),n[31]=ce,n[32]=Ne):Ne=n[32],M=s.jsxs("span",{className:"flex-1 min-w-0 flex items-baseline overflow-hidden",title:r.path,children:[s.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:H,children:z}),Ne]})}n[26]=r.path,n[27]=M}else M=n[27];let $;n[33]===Symbol.for("react.memo_cache_sentinel")?($={color:"var(--status-success)"},n[33]=$):$=n[33];let F;n[34]!==g?(F=s.jsxs("span",{style:$,children:["+",g]}),n[34]=g,n[35]=F):F=n[35];let V,O;n[36]===Symbol.for("react.memo_cache_sentinel")?(V=s.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),O={color:"var(--status-error)"},n[36]=V,n[37]=O):(V=n[36],O=n[37]);let L;n[38]!==w?(L=s.jsxs("span",{style:O,children:["-",w]}),n[38]=w,n[39]=L):L=n[39];let W;n[40]!==F||n[41]!==L?(W=s.jsxs("span",{className:"shrink-0 typography-micro",children:[F,V,L]}),n[40]=F,n[41]=L,n[42]=W):W=n[42];let B;n[43]!==r.path||n[44]!==y?(B=y("gitView.changes.revertFileAria",{path:r.path}),n[43]=r.path,n[44]=y,n[45]=B):B=n[45];let ne;n[46]!==d?(ne=d?s.jsx(Zt,{className:"size-3.5 animate-spin"}):s.jsx(Ab,{className:"size-3.5"}),n[46]=d,n[47]=ne):ne=n[47];let le;n[48]!==j||n[49]!==d||n[50]!==B||n[51]!==ne?(le=s.jsx(St,{asChild:!0,children:s.jsx("button",{type:"button",onClick:j,disabled:d,className:"flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50","aria-label":B,children:ne})}),n[48]=j,n[49]=d,n[50]=B,n[51]=ne,n[52]=le):le=n[52];let ee;n[53]!==y?(ee=y("gitView.changes.revertFileTooltip"),n[53]=y,n[54]=ee):ee=n[54];let ae;n[55]!==ee?(ae=s.jsx(Ct,{sideOffset:8,children:ee}),n[55]=ee,n[56]=ae):ae=n[56];let ge;n[57]!==le||n[58]!==ae?(ge=s.jsxs(kt,{children:[le,ae]}),n[57]=le,n[58]=ae,n[59]=ge):ge=n[59];let te;return n[60]!==S||n[61]!==o||n[62]!==D||n[63]!==T||n[64]!==M||n[65]!==W||n[66]!==ge||n[67]!==C||n[68]!==I||n[69]!==P?(te=s.jsxs("div",{className:C,role:"button",tabIndex:0,onClick:o,onKeyDown:S,style:I,children:[P,D,T,M,W,ge]}),n[60]=S,n[61]=o,n[62]=D,n[63]=T,n[64]=M,n[65]=W,n[66]=ge,n[67]=C,n[68]=I,n[69]=P,n[70]=te):te=n[70],te});function FN(t){t.stopPropagation()}const ON=120,LN=34,fp=14,nx=t=>t.replace(/\\/g,"/").replace(/^\/+/,"").trim(),hp=(t,e)=>({id:`dir:${t}`,path:t,name:e,children:new Map,directFiles:[],files:[]}),$N=t=>{const e=hp("","");for(const n of t){const r=nx(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=hp(c,d);m.files.push(n),o.children.set(d,m),o=m}}o.directFiles.push(n)}return e},BN=(t,e)=>{const n=[],r=(a,i)=>{const o=Array.from(a.children.values()).sort((d,p)=>d.path.localeCompare(p.path));for(const d of o)n.push({key:d.id,kind:"directory",depth:i,directory:d}),e.has(d.path)&&r(d,i+1);const c=[...a.directFiles].sort((d,p)=>d.path.localeCompare(p.path));for(const d of c)n.push({key:`file:${nx(d.path)}`,kind:"file",depth:i,file:d})};return r(t,0),n},gp=(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"},VN=({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}=ut(),y=l.useRef(null),g=Te(te=>te.gitChangesViewMode)==="tree",w=e.size,v=t.length,[S,A]=l.useState(!1),j=l.useMemo(()=>$N(t),[t]),[C,I]=l.useState(new Set),R=l.useMemo(()=>Array.from(j.children.values()).map(te=>te.path),[j]);l.useEffect(()=>{g&&I(te=>{const E=new Set,z=new Set(R);return te.forEach(J=>{if(J.includes("/")){E.add(J);return}z.has(J)&&E.add(J)}),R.forEach(J=>E.add(J)),E})},[g,R]);const k=l.useMemo(()=>BN(j,C),[C,j]),P=l.useMemo(()=>g?k:t,[t,g,k]),N=P.length,D=N>=ON,T=w>0,M=v>0&&w===v,$=T&&!M,F=Pb({count:N,getScrollElement:()=>y.current,estimateSize:()=>LN,overscan:10,enabled:D});l.useEffect(()=>{if(!D)return;const te=y.current;if(!te)return;const E=new ResizeObserver(()=>{F.measure()});return E.observe(te),()=>E.disconnect()},[D,F]);const V=F.getTotalSize(),O=l.useMemo(()=>D&&V>=0?F.getVirtualItems():[],[D,F,V]);l.useEffect(()=>{if(!h)return;if(N===0){h([]);return}const te=E=>{if(!g)return E.path;const z=E;return z.kind==="file"?z.file.path:null};if(!D){h(P.slice(0,Math.min(30,N)).map(E=>te(E)).filter(E=>!!E));return}h(O.map(E=>P[E.index]).map(E=>E?te(E):null).filter(E=>!!E))},[g,h,N,P,D,O]);const L="flex flex-col flex-1 min-h-0",W="flex items-center justify-between gap-2 px-0 py-3 border-b border-border/40",B=`flex-1 min-h-0 pr-0 ${u??""}`.trim(),ne="pl-0 pr-2",le=l.useCallback(te=>{I(E=>{const z=new Set(E);return z.has(te)?z.delete(te):z.add(te),z})},[]),ee=l.useCallback(te=>{const z=gp(te,e)!=="all";for(const J of te.files){const H=e.has(J.path);(z&&!H||!z&&H)&&a(J.path)}},[a,e]),ae=l.useCallback(te=>{if(!g){const re=te;return s.jsx(pp,{file:re,checked:e.has(re.path),stats:n?.[re.path],onToggle:()=>a(re.path),onViewDiff:()=>d(re.path),onRevert:()=>p(re.path),isReverting:r.has(re.path)||m,rowPaddingClassName:ne})}const E=te;if(E.kind==="file"){const re=E.file;return s.jsx(pp,{file:re,checked:e.has(re.path),stats:n?.[re.path],onToggle:()=>a(re.path),onViewDiff:()=>d(re.path),onRevert:()=>p(re.path),isReverting:r.has(re.path)||m,rowPaddingClassName:ne,indentPx:E.depth*fp})}const z=E.directory,J=C.has(z.path),H=gp(z,e);return s.jsxs("div",{className:pe("group flex items-center gap-2 py-1.5 hover:bg-sidebar/40",ne),style:{paddingLeft:`${E.depth*fp}px`},children:[s.jsx("div",{className:"flex size-5 shrink-0 items-center justify-center",children:s.jsx(bs,{size:"sm",checked:H==="all",indeterminate:H==="partial",onChange:()=>ee(z),ariaLabel:f("gitView.changes.toggleDirectorySelectionAria",{path:z.path})})}),s.jsxs("button",{type:"button",onClick:()=>le(z.path),className:"flex min-w-0 flex-1 items-center gap-2 rounded text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":J?f("gitView.changes.collapseDirectoryAria",{path:z.path}):f("gitView.changes.expandDirectoryAria",{path:z.path}),children:[J?s.jsx(Su,{className:"h-4 w-4 flex-shrink-0 text-primary/60"}):s.jsx(ku,{className:"h-4 w-4 flex-shrink-0 text-primary/60"}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label text-foreground",title:z.path,children:z.name}),s.jsx("span",{className:"ml-auto shrink-0 typography-micro text-muted-foreground",children:z.files.length})]})]})},[n,C,m,g,p,a,d,r,ne,e,f,le,ee]),ge=l.useCallback(async()=>{!c||m||t.length===0||(await c(t.map(te=>te.path)),A(!1))},[t,m,c]);return s.jsxs(s.Fragment,{children:[s.jsxs("section",{className:L,children:[s.jsxs("header",{className:W,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")}),v>0?s.jsxs("div",{className:pe("inline-flex h-6 items-center gap-1 rounded px-1.5",m&&"cursor-not-allowed opacity-50"),children:[s.jsx(bs,{size:"sm",checked:T,indeterminate:$,disabled:m,onChange:()=>M?o():i(),ariaLabel:f(M?"gitView.changes.clearSelectionAria":"gitView.changes.selectAllAria")}),s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[w,"/",v]})]}):null,b?s.jsx(je,{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(Nu,{className:"size-4"})}):null]}),s.jsx("div",{className:"flex items-center gap-2 pr-1",children:v>0&&c?s.jsx(je,{variant:"destructive",size:"xs",onClick:()=>A(!0),disabled:m,children:f("gitView.changes.revertAll")}):null})]}),s.jsxs("div",{className:pe("relative flex flex-col min-h-0 w-full overflow-hidden",B),children:[s.jsx(Vo,{ref:y,className:"overlay-scrollbar-target overlay-scrollbar-container flex-1 min-h-0 w-full overflow-y-auto overflow-x-hidden",children:D?s.jsx("div",{className:"relative w-full",style:{height:`${F.getTotalSize()}px`},children:O.map(te=>{const E=P[te.index];if(!E)return null;const z=g?E.key:`file:${E.path}`;return s.jsx("div",{ref:F.measureElement,"data-index":te.index,className:pe("absolute left-0 top-0 w-full",te.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(${te.start}px)`},children:ae(E)},z)})}):s.jsx("div",{role:"list","aria-label":f("gitView.changes.changedFilesAria"),children:P.map((te,E)=>s.jsx("div",{className:pe("relative",E>0&&"before:pointer-events-none before:absolute before:left-0 before:right-2 before:top-0 before:border-t before:border-border/60"),children:ae(te)},g?te.key:`file:${te.path}`))})}),s.jsx(qv,{containerRef:y,disableHorizontal:!0})]})]}),s.jsx(ws,{open:S,onOpenChange:te=>{m||A(te)},children:s.jsxs(vs,{className:"max-w-md",children:[s.jsxs(Is,{children:[s.jsx(Ss,{children:f("gitView.changes.revertAllDialogTitle")}),s.jsx(Os,{children:v===1?f("gitView.changes.revertAllDescriptionSingle",{count:v}):f("gitView.changes.revertAllDescriptionPlural",{count:v})})]}),s.jsxs(Qs,{children:[s.jsx(je,{variant:"outline",size:"sm",onClick:()=>A(!1),disabled:m,children:f("gitView.common.cancel")}),s.jsx(je,{variant:"destructive",size:"sm",onClick:()=>{ge()},disabled:m,children:f(m?"gitView.changes.reverting":"gitView.changes.revertAll")})]})]})})]})},td=38,ol=200,zN=t=>{const e=nt.c(20),{value:n,onChange:r,placeholder:a,disabled:i,hasTouchInput:o,isMobile:c}=t,d=i===void 0?!1:i,p=o===void 0?!1:o,m=c===void 0?!1:c,{t:u}=ut(),h=l.useRef(null),b=Te(_N);let f;e[0]===Symbol.for("react.memo_cache_sentinel")?(f=()=>{const R=h.current;if(!R)return;const k=document.activeElement===R,P=()=>{R.style.height=`${td}px`;const D=R.scrollHeight,T=Math.min(Math.max(D,td),ol);R.style.height=`${T}px`,R.style.overflowY=D>ol?"auto":"hidden",D>ol&&!k&&(R.scrollTop=R.scrollHeight)};P();const N=window.requestAnimationFrame(P);return()=>{window.cancelAnimationFrame(N)}},e[0]=f):f=e[0];let y;e[1]!==n?(y=[n],e[1]=n,e[2]=y):y=e[2],l.useLayoutEffect(f,y);let x;e[3]!==r?(x=R=>r(R.target.value),e[3]=r,e[4]=x):x=e[4];let g;e[5]!==a||e[6]!==u?(g=a??u("gitView.commit.messagePlaceholder"),e[5]=a,e[6]=u,e[7]=g):g=e[7];const w=p?"on":"off",v=p?"sentences":"off",S=m||b,A=d&&"opacity-50";let j;e[8]!==A?(j=pe("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)]",A),e[8]=A,e[9]=j):j=e[9];let C;e[10]===Symbol.for("react.memo_cache_sentinel")?(C={minHeight:td,maxHeight:ol},e[10]=C):C=e[10];let I;return e[11]!==d||e[12]!==S||e[13]!==j||e[14]!==x||e[15]!==g||e[16]!==w||e[17]!==v||e[18]!==n?(I=s.jsx("textarea",{ref:h,value:n,onChange:x,placeholder:g,rows:1,disabled:d,autoCorrect:w,autoCapitalize:v,spellCheck:S,className:j,style:C}),e[11]=d,e[12]=S,e[13]=j,e[14]=x,e[15]=g,e[16]=w,e[17]=v,e[18]=n,e[19]=I):I=e[19],I};function _N(t){return t.inputSpellcheckEnabled}const UN=t=>{const e=nt.c(30),{highlights:n,onInsert:r}=t,{t:a}=ut();if(n.length===0)return null;let i;e[0]!==n||e[1]!==r?(i=()=>{r(n)},e[0]=n,e[1]=r,e[2]=i):i=e[2];const o=i;let c;e[3]!==a?(c=a("gitView.commit.aiHighlights.title"),e[3]=a,e[4]=c):c=e[4];let d;e[5]!==c?(d=s.jsx("p",{className:"typography-micro text-muted-foreground",children:c}),e[5]=c,e[6]=d):d=e[6];let p;e[7]!==a?(p=a("gitView.commit.aiHighlights.insertAria"),e[7]=a,e[8]=p):p=e[8];let m;e[9]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(Db,{className:"size-4"}),e[9]=m):m=e[9];let u;e[10]!==o||e[11]!==p?(u=s.jsx(St,{asChild:!0,children:s.jsx(je,{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(Ct,{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 y;e[20]!==d||e[21]!==f?(y=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[d,f]}),e[20]=d,e[21]=f,e[22]=y):y=e[22];let x;e[23]!==n?(x=n.map(WN),e[23]=n,e[24]=x):x=e[24];let g;e[25]!==x?(g=s.jsx("ul",{className:"space-y-1",children:x}),e[25]=x,e[26]=g):g=e[26];let w;return e[27]!==y||e[28]!==g?(w=s.jsxs("div",{className:"space-y-2 rounded-xl border border-border/60 bg-transparent px-3 py-2",children:[y,g]}),e[27]=y,e[28]=g,e[29]=w):w=e[29],w};function WN(t,e){return s.jsx("li",{className:"typography-meta text-foreground",children:t},`${t}-${e}`)}const KN=t=>{const e=nt.c(72),{selectedCount:n,commitMessage:r,onCommitMessageChange:a,generatedHighlights:i,onInsertHighlights:o,onGenerateMessage:c,isGeneratingMessage:d,onCommit:p,onCommitAndPush:m,commitAction:u,gitmojiEnabled:h,onOpenGitmojiPicker:b}=t,{t:f}=ut(),y=n>0;let x;e[0]!==u||e[1]!==r||e[2]!==y?(x=r.trim()&&y&&u===null,e[0]=u,e[1]=r,e[2]=y,e[3]=x):x=e[3];const g=x,{isMobile:w,hasTouchInput:v}=un();let S;e[4]!==f?(S=f("gitView.commit.title"),e[4]=f,e[5]=S):S=e[5];let A;e[6]!==S?(A=s.jsx("div",{className:"flex w-full items-center justify-between px-0 pt-2 pb-1",children:s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:S})}),e[6]=S,e[7]=A):A=e[7];let j;e[8]!==y||e[9]!==f?(j=y?null:s.jsx("p",{className:"typography-meta text-muted-foreground",children:f("gitView.commit.selectFilesHint")}),e[8]=y,e[9]=f,e[10]=j):j=e[10];let C;e[11]!==i||e[12]!==o?(C=s.jsx(UN,{highlights:i,onInsert:o}),e[11]=i,e[12]=o,e[13]=C):C=e[13];let I;e[14]!==f?(I=f("gitView.commit.messagePlaceholder"),e[14]=f,e[15]=I):I=e[15];const R=u!==null;let k;e[16]!==r||e[17]!==v||e[18]!==w||e[19]!==a||e[20]!==I||e[21]!==R?(k=s.jsx(zN,{value:r,onChange:a,placeholder:I,disabled:R,hasTouchInput:v,isMobile:w}),e[16]=r,e[17]=v,e[18]=w,e[19]=a,e[20]=I,e[21]=R,e[22]=k):k=e[22];let P;e[23]!==h||e[24]!==b||e[25]!==f?(P=h&&s.jsxs(je,{variant:"outline",size:"sm",onClick:b,className:"w-fit",type:"button",children:[s.jsx(Tb,{className:"size-4"}),f("gitView.commit.addGitmoji")]}),e[23]=h,e[24]=b,e[25]=f,e[26]=P):P=e[26];const N=d||u!==null||n===0;let D;e[27]!==f?(D=f("gitView.commit.generateAria"),e[27]=f,e[28]=D):D=e[28];let T;e[29]!==d?(T=d?s.jsx(Zt,{className:"size-4 animate-spin"}):s.jsx(Ga,{className:"size-4 text-primary"}),e[29]=d,e[30]=T):T=e[30];let M;e[31]!==f?(M=f("gitView.commit.generate"),e[31]=f,e[32]=M):M=e[32];let $;e[33]!==M?($=s.jsx("span",{className:"commit-actions__label",children:M}),e[33]=M,e[34]=$):$=e[34];let F;e[35]!==c||e[36]!==N||e[37]!==D||e[38]!==T||e[39]!==$?(F=s.jsxs(je,{variant:"outline",size:"sm",onClick:c,disabled:N,type:"button","aria-label":D,className:"commit-actions__btn",children:[T,$]}),e[35]=c,e[36]=N,e[37]=D,e[38]=T,e[39]=$,e[40]=F):F=e[40];let V;e[41]===Symbol.for("react.memo_cache_sentinel")?(V=s.jsx("div",{className:"flex-1"}),e[41]=V):V=e[41];const O=!g||d;let L;e[42]!==f?(L=f("gitView.commit.commitAria"),e[42]=f,e[43]=L):L=e[43];let W;e[44]!==u||e[45]!==f?(W=u==="commit"?s.jsxs(s.Fragment,{children:[s.jsx(Zt,{className:"size-4 animate-spin"}),s.jsx("span",{className:"commit-actions__label",children:f("gitView.commit.committing")})]}):s.jsxs(s.Fragment,{children:[s.jsx(uc,{className:"size-4"}),s.jsx("span",{className:"commit-actions__label",children:f("gitView.commit.commit")})]}),e[44]=u,e[45]=f,e[46]=W):W=e[46];let B;e[47]!==p||e[48]!==O||e[49]!==L||e[50]!==W?(B=s.jsx(je,{size:"sm",variant:"outline",onClick:p,disabled:O,className:"commit-actions__btn whitespace-nowrap","aria-label":L,children:W}),e[47]=p,e[48]=O,e[49]=L,e[50]=W,e[51]=B):B=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(St,{asChild:!0,children:s.jsx(je,{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(Zt,{className:"size-4 animate-spin"}):s.jsx(_l,{className:"size-3.5"})})}),s.jsx(Ct,{side:"top",children:s.jsx("p",{children:f("gitView.commit.push")})})]}):s.jsx(je,{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(Zt,{className:"size-4 animate-spin"}),s.jsx("span",{className:"commit-actions__label",children:f("gitView.commit.pushing")})]}):s.jsxs(s.Fragment,{children:[s.jsx(_l,{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 le;e[59]!==F||e[60]!==B||e[61]!==ne?(le=s.jsxs("div",{className:"@container/commit-actions flex items-center gap-2 min-w-0",children:[F,V,B,ne]}),e[59]=F,e[60]=B,e[61]=ne,e[62]=le):le=e[62];let ee;e[63]!==le||e[64]!==j||e[65]!==C||e[66]!==k||e[67]!==P?(ee=s.jsxs("div",{className:"flex flex-col gap-3 px-0 pt-1 pb-3",children:[j,C,k,P,le]}),e[63]=le,e[64]=j,e[65]=C,e[66]=k,e[67]=P,e[68]=ee):ee=e[68];let ae;return e[69]!==ee||e[70]!==A?(ae=s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[A,ee]}),e[69]=ee,e[70]=A,e[71]=ae):ae=e[71],ae},HN=t=>{const e=nt.c(16),{onOpenStashes:n}=t,{t:r}=ut();let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=s.jsx(uc,{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(je,{type:"button",variant:"outline",size:"sm",onClick:n,className:"gap-1.5",children:[s.jsx(Nu,{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 xp(t){const e=new Date(t);return Number.isNaN(e.getTime())?t:e.toLocaleString(void 0,{hour12:!1,year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function GN(t){switch(t){case"A":return"text-[var(--status-success)]";case"D":return"text-[var(--status-error)]";case"M":return"text-[var(--status-warning)]";case"R":return"text-[var(--status-info)]";default:return"text-muted-foreground"}}const qN=l.memo(t=>{const e=nt.c(55),{entry:n,isExpanded:r,onToggle:a,files:i,isLoadingFiles:o,onCopyHash:c}=t,{t:d}=ut(),p=r?"bg-sidebar/90":"hover:bg-sidebar/40";let m;e[0]!==p?(m=pe("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 y;e[8]!==n.date?(y=xp(n.date),e[8]=n.date,e[9]=y):y=e[9];let x;e[10]!==n.date?(x=xp(n.date),e[10]=n.date,e[11]=x):x=e[11];let g;e[12]!==y||e[13]!==x?(g=s.jsx("span",{className:"truncate min-w-0",title:y,children:x}),e[12]=y,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 v;e[18]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx("span",{className:"shrink-0",children:"·"}),e[18]=v):v=e[18];let S;e[19]!==n.hash?(S=n.hash.slice(0,8),e[19]=n.hash,e[20]=S):S=e[20];let A;e[21]!==S?(A=s.jsx("code",{className:"shrink-0 font-mono",children:S}),e[21]=S,e[22]=A):A=e[22];let j;e[23]!==n.hash||e[24]!==c?(j=F=>{F.stopPropagation(),c(n.hash)},e[23]=n.hash,e[24]=c,e[25]=j):j=e[25];let C;e[26]===Symbol.for("react.memo_cache_sentinel")?(C=s.jsx(br,{className:"size-3"}),e[26]=C):C=e[26];let I;e[27]!==j?(I=s.jsx(St,{asChild:!0,children:s.jsx(je,{variant:"ghost",size:"sm",className:"h-5 px-1 shrink-0",onClick:j,children:C})}),e[27]=j,e[28]=I):I=e[28];let R;e[29]!==d?(R=d("gitView.history.copySha"),e[29]=d,e[30]=R):R=e[30];let k;e[31]!==R?(k=s.jsx(Ct,{sideOffset:8,children:R}),e[31]=R,e[32]=k):k=e[32];let P;e[33]!==I||e[34]!==k?(P=s.jsxs(kt,{children:[I,k]}),e[33]=I,e[34]=k,e[35]=P):P=e[35];let N;e[36]!==w||e[37]!==A||e[38]!==P?(N=s.jsxs("div",{className:"flex items-center gap-1 typography-meta text-muted-foreground",children:[w,v,A,P]}),e[36]=w,e[37]=A,e[38]=P,e[39]=N):N=e[39];let D;e[40]!==N||e[41]!==h?(D=s.jsxs("div",{className:"min-w-0 flex-1",children:[h,N]}),e[40]=N,e[41]=h,e[42]=D):D=e[42];let T;e[43]!==a||e[44]!==m||e[45]!==D?(T=s.jsxs("button",{type:"button",onClick:a,className:m,children:[u,D]}),e[43]=a,e[44]=m,e[45]=D,e[46]=T):T=e[46];let M;e[47]!==i||e[48]!==r||e[49]!==o||e[50]!==d?(M=r&&s.jsx("div",{className:"px-3 pb-2 pl-8 border-t border-border/40",children:o?s.jsxs("div",{className:"flex items-center gap-2 py-2",children:[s.jsx(Zt,{className:"size-4 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:d("gitView.history.loadingFiles")})]}):i.length===0?s.jsx("p",{className:"typography-micro text-muted-foreground py-2",children:d("gitView.history.noFiles")}):s.jsx("ul",{className:"space-y-0.5 py-2",children:i.map(F=>s.jsxs("li",{className:"flex items-center gap-2 typography-micro",children:[s.jsx("span",{className:pe("font-semibold w-3 text-center",GN(F.changeType)),children:F.changeType}),s.jsx("span",{className:"truncate text-foreground min-w-0",title:F.path,children:F.path}),!F.isBinary&&s.jsxs("span",{className:"shrink-0",children:[s.jsxs("span",{style:{color:"var(--status-success)"},children:["+",F.insertions]}),s.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),s.jsxs("span",{style:{color:"var(--status-error)"},children:["-",F.deletions]})]}),F.isBinary&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:d("gitView.history.binary")})]},F.path))})}),e[47]=i,e[48]=r,e[49]=o,e[50]=d,e[51]=M):M=e[51];let $;return e[52]!==T||e[53]!==M?($=s.jsxs("li",{children:[T,M]}),e[52]=T,e[53]=M,e[54]=$):$=e[54],$}),QN=[{labelKey:"gitView.history.logSize25",value:25},{labelKey:"gitView.history.logSize50",value:50},{labelKey:"gitView.history.logSize100",value:100}],JN=t=>{const e=nt.c(54),{log:n,isLogLoading:r,logMaxCount:a,onLogMaxCountChange:i,expandedCommitHashes:o,onToggleCommit:c,commitFilesMap:d,loadingCommitHashes:p,onCopyHash:m,showHeader:u,contentMaxHeightClassName:h,branchDivider:b}=t,f=u===void 0?!0:u,y=h===void 0?"max-h-[50vh]":h,x=b===void 0?null:b,{t:g}=ut(),[w,v]=l.useState(!0);if(!n)return null;const S=x!==null&&x.insertBeforeIndex>0&&x.insertBeforeIndex<n.all.length,A=x!==null&&x.insertBeforeIndex===n.all.length,j=S||A;let C;e[0]!==x||e[1]!==S||e[2]!==A||e[3]!==n.all?(C=S?n.all.slice(0,x.insertBeforeIndex):A?n.all:[],e[0]=x,e[1]=S,e[2]=A,e[3]=n.all,e[4]=C):C=e[4];const I=C;let R;if(e[5]!==x||e[6]!==d||e[7]!==y||e[8]!==o||e[9]!==S||e[10]!==j||e[11]!==p||e[12]!==n.all||e[13]!==m||e[14]!==c||e[15]!==g||e[16]!==I){const O=S?n.all.slice(x.insertBeforeIndex):[];let L;e[18]!==x?.direction?(L=x?.direction==="down"?s.jsx(Cs,{className:"size-3.5"}):s.jsx(_l,{className:"size-3.5"}),e[18]=x?.direction,e[19]=L):L=e[19];const W=L;let B;e[20]!==d||e[21]!==o||e[22]!==p||e[23]!==m||e[24]!==c?(B=le=>s.jsx("ul",{className:"divide-y divide-border/60",children:le.map(ee=>s.jsx(qN,{entry:ee,isExpanded:o.has(ee.hash),onToggle:()=>c(ee.hash),files:d.get(ee.hash)??[],isLoadingFiles:p.has(ee.hash),onCopyHash:m},ee.hash))}),e[20]=d,e[21]=o,e[22]=p,e[23]=m,e[24]=c,e[25]=B):B=e[25];const ne=B;R=s.jsx(Es,{outerClassName:`min-h-0 ${y}`,className:"h-full w-full",children:n.all.length===0?s.jsx("div",{className:"flex h-full items-center justify-center p-4",children:s.jsx("p",{className:"typography-ui-label text-muted-foreground",children:g("gitView.history.noCommits")})}):j&&x?s.jsxs("div",{className:"flex flex-col gap-0",children:[I.length>0?s.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:ne(I)}):null,s.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5","aria-hidden":!0,children:[s.jsx("span",{className:"h-px flex-1 bg-border/60"}),s.jsxs("span",{className:"inline-flex max-w-[80%] items-center gap-1 typography-micro text-muted-foreground",children:[s.jsx("span",{className:"truncate",title:x.branchName,children:x.branchName}),W]}),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]=y,e[8]=o,e[9]=S,e[10]=j,e[11]=p,e[12]=n.all,e[13]=m,e[14]=c,e[15]=g,e[16]=I,e[17]=R}else R=e[17];const k=R;if(!f){if(j){let L;return e[26]!==k?(L=s.jsx("section",{className:"h-full min-h-0",children:k}),e[26]=k,e[27]=L):L=e[27],L}let O;return e[28]!==k?(O=s.jsx("section",{className:"h-full min-h-0 rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:k}),e[28]=k,e[29]=O):O=e[29],O}let P;e[30]!==g?(P=g("gitView.history.title"),e[30]=g,e[31]=P):P=e[31];let N;e[32]!==P?(N=s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:P}),e[32]=P,e[33]=N):N=e[33];let D;e[34]!==r||e[35]!==w||e[36]!==a||e[37]!==i||e[38]!==g?(D=w&&s.jsx("div",{onClick:YN,onPointerDown:XN,children:s.jsxs(ps,{value:String(a),onValueChange:O=>i(Number(O)),disabled:r,children:[s.jsx(fs,{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(hs,{children:QN.map(O=>s.jsx(Ot,{value:String(O.value),children:g(O.labelKey)},O.value))})]})}),e[34]=r,e[35]=w,e[36]=a,e[37]=i,e[38]=g,e[39]=D):D=e[39];let T;e[40]!==w?(T=w?s.jsx(Cu,{className:"size-4 text-muted-foreground"}):s.jsx(Cs,{className:"size-4 text-muted-foreground"}),e[40]=w,e[41]=T):T=e[41];let M;e[42]!==D||e[43]!==T?(M=s.jsxs("div",{className:"flex items-center gap-2",children:[D,T]}),e[42]=D,e[43]=T,e[44]=M):M=e[44];let $;e[45]!==M||e[46]!==N?($=s.jsxs(Mr,{className:"flex w-full items-center justify-between px-3 h-10 hover:bg-transparent",children:[N,M]}),e[45]=M,e[46]=N,e[47]=$):$=e[47];let F;e[48]!==k?(F=s.jsx(vr,{children:k}),e[48]=k,e[49]=F):F=e[49];let V;return e[50]!==w||e[51]!==$||e[52]!==F?(V=s.jsxs(yr,{open:w,onOpenChange:v,className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[$,F]}),e[50]=w,e[51]=$,e[52]=F,e[53]=V):V=e[53],V};function YN(t){return t.stopPropagation()}function XN(t){return t.stopPropagation()}const ZN=9e4,e2=15e3,t2=5*6e4,s2=[2e3,5e3],n2=6e4,r2=2*6e4,a2=5*6e4,i2=720*6e4,o2="openchamber.github-pr-status",l2=t=>t==="closed"||t==="merged",c2=t=>{const e=t?.checks;return e?e.state==="pending"||e.pending>0:!1},Co=(t,e,n)=>`${t}::${e}`,ll=new Map,cl=new Map,io=new Set,bp=new Map,go=()=>({status:null,isLoading:!1,error:null,isInitialStatusResolved:!1,lastRefreshAt:0,lastDiscoveryPollAt:0,watchers:0,params:null,identity:null,resolvedRemoteName:null}),ec=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,Wu=t=>{const e=ec(t);return!e?.directory||!e.branch?null:`${e.directory}::${e.branch}`},rx=(t,e)=>Object.entries(t).filter(([,n])=>Wu(n)===e).map(([n])=>n),d2=(t,e)=>{const n=e.remoteName??t.params?.remoteName??t.resolvedRemoteName??t.identity?.remoteName??null;return{...t,params:t.params?{...t.params,...e,remoteName:n}:{...e,remoteName:n},identity:{directory:e.directory,branch:e.branch,remoteName:n}}},dl=t=>!t?.params?.canShow||!t.params.github?.prStatus?null:{...t.params,remoteName:t.params.remoteName??t.resolvedRemoteName??t.identity?.remoteName??null},u2=(t,e,n)=>{const r=rx(t,e),a=r.map(d=>dl(t[d])).filter(d=>!!d);if(a.length===0)return null;const i=dl(t[n]);if(i&&Wu(t[n])===e)return i;const o=r.map(d=>t[d]).find(d=>!!(d?.resolvedRemoteName&&dl(d)));if(o)return dl(o);const c=a.find(d=>!!d.remoteName);return c||(a[0]??null)},m2=t=>({status:t.status,isInitialStatusResolved:t.isInitialStatusResolved,lastRefreshAt:t.lastRefreshAt,lastDiscoveryPollAt:t.lastDiscoveryPollAt,identity:ec(t),resolvedRemoteName:t.resolvedRemoteName??t.status?.resolvedRemoteName??null}),p2=t=>({...go(),status:t?.status??null,isInitialStatusResolved:t?.isInitialStatusResolved??!1,lastRefreshAt:t?.lastRefreshAt??0,lastDiscoveryPollAt:t?.lastDiscoveryPollAt??0,identity:t?.identity??null,resolvedRemoteName:t?.resolvedRemoteName??t?.status?.resolvedRemoteName??null}),gr=wr()($o((t,e)=>({entries:{},activeRequestCount:0,totalRequestCount:0,ensureEntry:n=>{t(r=>r.entries[n]?r:{entries:{...r.entries,[n]:go()}})},setParams:(n,r)=>{t(a=>{const i=a.entries[n]??go();return{entries:{...a.entries,[n]:d2(i,r)}}})},startWatching:n=>{if(t(i=>{const o=i.entries[n]??go();return{entries:{...i.entries,[n]:{...o,watchers:o.watchers+1}}}}),ll.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=cl.get(n)??[];c.push(o),cl.set(n,c)};e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0}),s2.forEach(i=>r(i));const a=window.setInterval(()=>{if(typeof document<"u"&&document.visibilityState!=="visible")return;const i=e().entries[n];if(!i||i.watchers<=0)return;if(!!!i.status?.pr){const p=Date.now();if(p-i.lastDiscoveryPollAt<t2)return;t(m=>{const u=m.entries[n];return u?{entries:{...m.entries,[n]:{...u,lastDiscoveryPollAt:p}}}:m}),e().refresh(n,{force:!0,silent:!0,markInitialResolved:!0});return}if(l2(i.status?.pr?.state))return;const c=Date.now()-i.lastRefreshAt,d=c2(i.status)?n2:i.status?.checks&&i.status.checks.state!=="pending"?a2:r2;c<d||e().refresh(n,{force:!0,onlyExistingPr:!0,silent:!0,markInitialResolved:!0})},e2);ll.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=ll.get(n);typeof a=="number"&&window.clearInterval(a),ll.delete(n);const i=cl.get(n);i&&i.length>0&&i.forEach(o=>{window.clearTimeout(o)}),cl.delete(n)},refresh:async(n,r)=>{const a=e(),i=a.entries[n],o=Wu(i);if(!i||!o)return;const c=rx(a.entries,o),d=c.some(u=>!!a.entries[u]?.status?.pr);if(r?.onlyExistingPr&&!d)return;const p=bp.get(o)??0;if(!r?.force&&Date.now()-p<ZN||io.has(o))return;const m=u2(a.entries,o,n);if(m){if(io.add(o),bp.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}}),io.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}}),io.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 y=b[f];if(!y)return;const x=y.status?.pr,g=u.pr,v=!!(g&&x&&g.number===x.number&&(!g.body||!g.body.trim())&&typeof x.body=="string"&&x.body.trim().length>0)&&g&&x?.body?{...u,pr:{...g,body:x.body}}:u,S=v.resolvedRemoteName??y.resolvedRemoteName??m.remoteName??null,A=ec(y)??{directory:m.directory,branch:m.branch,remoteName:m.remoteName??null};b[f]={...y,status:v,error:null,isLoading:r?.silent?y.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?y.isInitialStatusResolved:!0,resolvedRemoteName:S,identity:{...A,remoteName:S??A.remoteName??null}}}),{entries:b}})}catch(u){const h=u instanceof Error?u.message:String(u);t(b=>{const f={...b.entries};return c.forEach(y=>{const x=f[y];x&&(f[y]={...x,error:h||"Failed to load PR status",isLoading:r?.silent?x.isLoading:!1,isInitialStatusResolved:r?.markInitialResolved===!1?x.isInitialStatusResolved:!0})}),{entries:f}})}finally{io.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:Co(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]??go();return{entries:{...a.entries,[n]:{...i,status:r(i.status)}}}})}}),{name:o2,storage:lc(()=>ba()),partialize:t=>({entries:Object.fromEntries(Object.entries(t.entries).filter(([,e])=>{const n=ec(e);if(!n?.directory||!n.branch)return!1;const r=Math.max(e.lastRefreshAt,e.lastDiscoveryPollAt);return r===0||Date.now()-r<i2}).map(([e,n])=>[e,m2(n)]))}),merge:(t,e)=>{const n=t?.entries??{};return{...e,entries:Object.fromEntries(Object.entries(n).map(([a,i])=>[a,p2(i)]))}}})),f2=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"},h2=t=>{const e=f2(t.status??null),n=t.status?.pr;return!e||!n?.number?null:{number:n.number,visualState:e,prState:n.state,draft:!!n.draft,title:typeof n.title=="string"&&n.title.trim().length>0?n.title:null,url:typeof n.url=="string"&&n.url.trim().length>0?n.url:null,base:typeof n.base=="string"&&n.base.trim().length>0?n.base:null,head:typeof n.head=="string"&&n.head.trim().length>0?n.head:null,checks:t.status?.checks?{state:t.status.checks.state,total:t.status.checks.total,success:t.status.checks.success,failure:t.status.checks.failure,pending:t.status.checks.pending}:null,canMerge:typeof t.status?.canMerge=="boolean"?t.status.canMerge:null,mergeableState:typeof n.mergeableState=="string"?n.mergeableState:null,repo:t.status?.repo?{owner:t.status.repo.owner,repo:t.status.repo.repo}:null}},g2=t=>`${t.number}:${t.visualState}:${t.prState}:${t.draft}:${t.title??""}:${t.url??""}:${t.base??""}:${t.head??""}:${t.canMerge??""}:${t.mergeableState??""}:${t.checks?.state??""}:${t.checks?.total??""}:${t.checks?.success??""}:${t.checks?.failure??""}:${t.checks?.pending??""}:${t.repo?.owner??""}:${t.repo?.repo??""}`;let sd=new Map,yp=new Map;const x2=t=>{const e=nt.c(2);let n;return e[0]!==t?(n=r=>{const a=new Map,i=new Map;for(const o of t){const c=r.entries[o];if(!c)continue;const d=h2(c);if(!d)continue;const p=g2(d);a.set(o,p),i.set(o,d)}if(a.size===sd.size){let o=!0;for(const[c,d]of a)if(sd.get(c)!==d){o=!1;break}if(o)return yp}return sd=a,yp=i,i},e[0]=t,e[1]=n):n=e[1],gr(n)},b2=t=>{switch(t){case"success":return"bg-[color:var(--status-success)]";case"failure":return"bg-[color:var(--status-error)]";case"pending":return"bg-[color:var(--status-warning)]";default:return"bg-muted-foreground/40"}},y2=t=>{const e=t?.pr;if(!e)return null;if(e.state==="merged")return"merged";if(e.state==="closed")return"closed";if(e.draft)return"draft";const n=t?.checks?.state==="failure",r=typeof e.mergeableState=="string"?e.mergeableState:"",a=e.mergeable===!1||r==="blocked"||r==="dirty";return n||a?"blocked":"open"},v2=[2e3,5e3],vp=t=>t.replace(/^refs\/heads\//,"").replace(/[-_]+/g," ").replace(/\s+/g," ").trim().replace(/\b\w/g,e=>e.toUpperCase()),xa=t=>{let e=t.trim();return e?(e.startsWith("refs/heads/")&&(e=e.slice(11)),e.startsWith("heads/")&&(e=e.slice(6)),e.startsWith("remotes/")&&(e=e.slice(8)),e):""},w2=(t,e)=>{const n=xa(t);if(!n||n.includes("->"))return"";if(e){const a=`${e}/`;return n.startsWith(a)?n.slice(a.length).trim():""}const r=n.indexOf("/");return r>0?n.slice(r+1).trim():n},j2=(t,e)=>`${t}::${e}`,Ku=t=>{const e=String(t||"").trim();if(!e)return"";const n=e.indexOf("/");return n<=0?"":e.slice(0,n).trim()},nd=(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=Ku(e.trackingBranch);if(r){const i=r==="origin"?t.find(c=>c.name==="upstream"):null;if(i)return i;const o=t.find(c=>c.name===r);if(o)return o}const a=t.find(i=>i.name==="origin");return a||(t[0]??null)},N2=t=>t.startsWith("pr-"),S2=(t,e)=>{const n=Ku(e),r=new Map(t.map(o=>[o.name,o])),a=[],i=o=>{o&&(a.some(c=>c.name===o.name)||a.push(o))};return n&&i(r.get(n)),i(r.get("upstream")),i(r.get("origin")),t.filter(o=>!N2(o.name)).forEach(o=>i(o)),t.forEach(o=>i(o)),a},rd=new Map,ad=lr;function k2(t,e){const[n,r]=l.useState(null),[a,i]=l.useState([]),o=l.useRef(null);return l.useEffect(()=>{r(null),i([])},[t]),l.useEffect(()=>{if(!t||!e?.repoUpstream||o.current===t)return;o.current=t;let c=!1;return(async()=>{try{const d=await e.repoUpstream(t);if(c||!d?.isFork||!d.upstream||(r(d.upstream),!e.repoBranches))return;try{const p=await e.repoBranches(d.upstream.owner,d.upstream.repo);c||i(p)}catch{}}catch{}})(),()=>{c=!0}},[t,e]),{detectedUpstream:n,upstreamBranches:a}}const C2=({directory:t,branch:e,baseBranch:n,trackingBranch:r,remotes:a=[],remoteBranches:i=[],onGeneratedDescription:o})=>{const{t:c}=ut(),{github:d}=Gn(),p=Zn(We=>We.status),m=Zn(We=>We.hasChecked),u=Te(We=>We.setSettingsDialogOpen),h=Te(We=>We.setSettingsPage),b=Te(We=>We.setActiveMainTab),f=Wt(We=>We.currentSessionId),{isMobile:y,hasTouchInput:x}=un(),g=l.useCallback(()=>{h("github"),u(!0)},[u,h]),w=l.useMemo(()=>j2(t,e),[t,e]),v=l.useMemo(()=>rd.get(w)??null,[w]),S=gr(We=>We.ensureEntry),A=gr(We=>We.setParams),j=gr(We=>We.startWatching),C=gr(We=>We.stopWatching),I=gr(We=>We.refresh),R=gr(We=>We.updateStatus),[k,P]=l.useState(()=>v?.title??vp(e)),[N,D]=l.useState(()=>v?.body??""),[T,M]=l.useState(()=>v?.draft??!1),[$,F]=l.useState(()=>v?.additionalContext??""),[V,O]=l.useState(()=>{const We=typeof v?.targetBaseBranch=="string"?xa(v.targetBaseBranch):"";return We||xa(n)}),[L,W]=l.useState("squash"),[B,ne]=l.useState(!1),[le,ee]=l.useState(!1),[ae,ge]=l.useState(!1),[te,E]=l.useState(!1),[z,J]=l.useState(!1),[H,re]=l.useState(!1),[ce,Ne]=l.useState(null),[me,we]=l.useState(""),[_,ue]=l.useState(""),[Q,oe]=l.useState(!1),[Z,Ie]=l.useState(!1),[Se,Y]=l.useState(()=>nd(a,{selectedRemoteName:v?.selectedRemoteName,trackingBranch:r})),[fe,ke]=l.useState(!1),{detectedUpstream:xe,upstreamBranches:he}=k2(t,d);l.useEffect(()=>{ke(!1)},[t]);const Pe=a.some(We=>We.name==="upstream"),G=!!(t&&e&&n&&(e!==n||(Pe||xe!==null))),be=l.useMemo(()=>Co(t,e),[t,e]),De=gr(We=>We.entries[be]),Ae=De?.isLoading??!1,ve=De?.status??null,U=De?.error??null,de=De?.isInitialStatusResolved??!1,Re=l.useMemo(()=>{const We=fe?null:Se?.name?.trim()||null,gt=new Set;for(const as of i){const st=w2(as,We);!st||st==="HEAD"||gt.add(st)}if(fe)for(const as of he)as&&as!=="HEAD"&&gt.add(as);const Mt=xa(n);Mt&&Mt!=="HEAD"&&gt.add(Mt);const Et=xa(V);return Et&&Et!=="HEAD"&&gt.add(Et),Array.from(gt).sort((as,st)=>as.localeCompare(st))},[n,i,Se?.name,V,he,fe]);l.useEffect(()=>{if(a.length===0){Se&&Y(null);return}(!Se||!a.some(We=>We.name===Se.name))&&Y(nd(a,{selectedRemoteName:v?.selectedRemoteName,trackingBranch:r}))},[v?.selectedRemoteName,a,Se,r]),l.useEffect(()=>{const We=xa(n);if(!V&&We){O(We);return}if(Re.length!==0&&!Re.includes(V)){const gt=Re.includes(We)?We:Re[0];gt&&O(gt)}},[Re,n,V]);const[Le,se]=l.useState(!1),[ie,K]=l.useState(null),[_e,He]=l.useState(!1),[Ke,Ze]=l.useState(new Set),[Xe,mt]=l.useState(!1),[et,ct]=l.useState(null),[lt,ye]=l.useState(!1),Ge=l.useRef(new Set),$e=l.useRef(null),Ve=l.useRef(!1),tt=l.useRef(new Set),Qe=l.useRef([]);l.useEffect(()=>{xe&&!Pe&&ke(!0)},[xe,Pe]),l.useEffect(()=>{fe&&xe?.defaultBranch&&O(xe.defaultBranch)},[fe,xe?.defaultBranch]);const ze=ve?.pr??null,ht=ze?`${t}#${ze.number}`:null,_t=!!(ht&&ce===ht);l.useEffect(()=>{if(!d?.prContext||!ze||typeof ze.body=="string"&&ze.body.length>0)return;const We=`${t}#${ze.number}`;if(Ge.current.has(We))return;Ge.current.add(We),Ne(We);let gt=!1;return d.prContext(t,ze.number,{includeDiff:!1,includeCheckDetails:!1}).then(Mt=>{if(gt)return;const Et=Mt?.pr;Et&&R(be,as=>!as?.pr||as.pr.number!==ze.number?as:{...as,pr:{...as.pr,body:Et.body||""}})}).catch(()=>{}).finally(()=>{gt||Ne(Mt=>Mt===We?null:Mt)}),()=>{gt=!0}},[t,d,ze,be,R]),l.useEffect(()=>{if(!ze){re(!1),we(""),ue(""),$e.current=null;return}const We=$e.current!==null&&$e.current!==ze.number;We&&re(!1),(!H||We)&&(we(ze.title||""),ue(ze.body||"")),$e.current=ze.number},[H,ze]);const Kt=l.useCallback(async()=>{if(!d?.prContext){q.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(ze){se(!0),Ze(new Set),He(!0);try{const We=await d.prContext(t,ze.number,{includeDiff:!1,includeCheckDetails:!0});K(We)}catch(We){const gt=We instanceof Error?We.message:String(We);q.error(c("gitView.pr.toast.loadCheckDetailsFailed"),{description:gt})}finally{He(!1)}}},[t,d,ze,c]),Ut=l.useCallback(async()=>{if(!d?.prContext){q.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(ze){mt(!0),ye(!0);try{const We=await d.prContext(t,ze.number,{includeDiff:!1,includeCheckDetails:!1});ct(We)}catch(We){const gt=We instanceof Error?We.message:String(We);q.error(c("gitView.pr.toast.loadCommentsFailed"),{description:gt})}finally{ye(!1)}}},[t,d,ze,c]),jt=l.useCallback(We=>{if(!We)return"";const gt=Date.parse(We);return Number.isFinite(gt)?new Date(gt).toLocaleString():We},[]),Dt=l.useMemo(()=>{const We=p?.user?.login;return typeof We=="string"?We.trim():""},[p]),ts=l.useMemo(()=>"[&_a[href*='oc-self-mention=1']]:!text-[var(--primary-base)] [&_a[href*='oc-self-mention=1']]:font-semibold [&_a[href*='oc-self-mention=1']]:!no-underline [&_a[href*='oc-self-mention=1']:hover]:!text-[var(--primary-hover)]",[]),it=l.useCallback(We=>{const gt=Dt.toLowerCase(),Mt=/(^|[^\w`])@([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,38}))/g;return We.replace(Mt,(Et,as,st)=>{const Lt=`@${st}`,ls=st.toLowerCase();return`${as}[${Lt}](https://github.com/${ls}${gt&&ls===gt?"?oc-self-mention=1":""})`})},[Dt]),Yt=l.useMemo(()=>{const We=(et?.issueComments??[]).map(Et=>({id:`issue-${Et.id}`,body:Et.body||"",authorName:Et.author?.name||Et.author?.login||c("gitView.pr.comments.unknownAuthor"),authorLogin:Et.author?.login||null,avatarUrl:Et.author?.avatarUrl||null,createdAt:Et.createdAt,context:c("gitView.pr.comments.generalContext"),path:null,line:null})),gt=(et?.reviewComments??[]).map(Et=>({id:`review-${Et.id}`,body:Et.body||"",authorName:Et.author?.name||Et.author?.login||c("gitView.pr.comments.unknownAuthor"),authorLogin:Et.author?.login||null,avatarUrl:Et.author?.avatarUrl||null,createdAt:Et.createdAt,context:c("gitView.pr.comments.reviewContext"),path:Et.path||null,line:Et.line??null})),Mt=[...We,...gt];return Mt.sort((Et,as)=>{const st=Et.createdAt?Date.parse(Et.createdAt):0,Lt=as.createdAt?Date.parse(as.createdAt):0,ls=Number.isFinite(st)?st:0,rs=Number.isFinite(Lt)?Lt:0;return ls-rs}),Mt},[et,c]),Qt=l.useCallback(()=>{if(!f)return q.error(c("gitView.pr.toast.noActiveSession"),{description:c("gitView.pr.toast.noActiveSessionDescription")}),null;const{currentProviderId:We,currentModelId:gt,currentAgentName:Mt,currentVariant:Et}=yt.getState(),as=hc.getState().lastUsedProvider,st=We||as?.providerID,Lt=gt||as?.modelID;return!st||!Lt?(q.error(c("gitView.pr.toast.noModelSelected")),null):{sessionId:f,providerID:st,modelID:Lt,currentAgentName:Mt??null,currentVariant:Et??null}},[f,c]),Xt=l.useCallback((We,gt,Mt,Et)=>{Wt.getState().sendMessage(gt,We.providerID,We.modelID,We.currentAgentName??void 0,void 0,void 0,[{text:Mt,synthetic:!0},{text:Et,synthetic:!0}],We.currentVariant??void 0).catch(as=>{const st=as instanceof Error?as.message:String(as);q.error(c("gitView.pr.toast.sendMessageFailed"),{description:st})})},[c]),us=l.useCallback(We=>{const gt=We.status||"unknown",Mt=We.conclusion??void 0,Et=Mt?`${gt} / ${Mt}`:gt,as=We.app?.name||We.app?.slug;return s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-start justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label text-foreground truncate",children:We.name}),s.jsx("div",{className:"typography-micro text-muted-foreground truncate",children:as?`${as} · ${Et}`:Et})]}),We.detailsUrl?s.jsx(je,{variant:"outline",size:"sm",asChild:!0,className:"flex-shrink-0",children:s.jsxs("a",{href:We.detailsUrl,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(Ir,{className:"size-4"}),"Open"]})}):null]}),We.output?.title?s.jsx("div",{className:"typography-micro text-foreground",children:We.output.title}):null,We.output?.summary?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap",children:We.output.summary}):null,We.output?.text?s.jsx("div",{className:"rounded border border-border/40 bg-transparent px-2 py-2 typography-micro text-muted-foreground whitespace-pre-wrap max-h-48 overflow-y-auto",children:We.output.text}):null,Array.isArray(We.annotations)&&We.annotations.length>0?s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"typography-micro text-muted-foreground",children:["Failed annotations",We.annotations.length>20?` (showing 20/${We.annotations.length})`:""]}),s.jsx("div",{className:"space-y-1",children:We.annotations.slice(0,20).map((st,Lt)=>s.jsxs("div",{className:"rounded border border-[var(--status-error-border)] bg-[var(--status-error-background)]/40 px-2 py-2",children:[s.jsxs("div",{className:"typography-micro text-[var(--status-error)]",children:[st.title||st.level||"Issue",st.path?` · ${st.path}`:"",typeof st.startLine=="number"?`:${st.startLine}`:"",typeof st.endLine=="number"&&st.endLine!==st.startLine?`-${st.endLine}`:""]}),s.jsx("div",{className:"typography-micro text-foreground whitespace-pre-wrap mt-1",children:st.message}),st.rawDetails?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap mt-1",children:st.rawDetails}):null]},`${st.path||"file"}:${st.startLine||Lt}:${Lt}`))})]}):null,We.job?.steps&&We.job.steps.length>0?s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.checks.steps")}),s.jsx("div",{className:"space-y-1",children:We.job.steps.map((st,Lt)=>{const ls=(st.conclusion||"").toLowerCase(),rs=ls&&!["success","neutral","skipped"].includes(ls),Bt=`${We.id??"run"}:${We.job?.jobId??"job"}:${st.number??Lt}:${st.name}`,xs=Ke.has(Bt);return rs?s.jsxs(yr,{open:xs,children:[s.jsxs("button",{type:"button",onClick:()=>{Ze(mn=>{const js=new Set(mn);return js.has(Bt)?js.delete(Bt):js.add(Bt),js})},className:"typography-micro flex w-full items-center gap-2 rounded px-2 py-1 text-left "+(rs?"bg-destructive/10 text-destructive":"text-muted-foreground"),children:[xs?s.jsx(Cs,{className:"size-4"}):s.jsx(Fn,{className:"size-4"}),s.jsx("span",{className:"truncate",children:st.name}),st.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:st.conclusion}):null]}),s.jsx(vr,{children:s.jsxs("div",{className:"ml-6 mt-1 rounded border border-border/40 bg-transparent px-2 py-2 typography-micro text-muted-foreground space-y-1",children:[typeof st.number=="number"?s.jsxs("div",{children:[c("gitView.pr.checks.stepLabel"),": ",st.number]}):null,st.status?s.jsxs("div",{children:[c("gitView.pr.checks.statusLabel"),": ",st.status]}):null,st.conclusion?s.jsxs("div",{children:[c("gitView.pr.checks.conclusionLabel"),": ",st.conclusion]}):null,st.startedAt?s.jsxs("div",{children:[c("gitView.pr.checks.startedLabel"),": ",jt(st.startedAt)]}):null,st.completedAt?s.jsxs("div",{children:[c("gitView.pr.checks.completedLabel"),": ",jt(st.completedAt)]}):null]})})]},Bt):s.jsxs("div",{className:"typography-micro flex w-full items-center gap-2 rounded px-2 py-1 text-muted-foreground",children:[s.jsx("span",{className:"truncate",children:st.name}),st.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:st.conclusion}):null]},Bt)})})]}):null]})},[Ke,jt,c]),ms=l.useCallback(async()=>{if(b("chat"),!d?.prContext){q.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!ze)return;const We=Qt();if(We)try{const gt=await d.prContext(t,ze.number,{includeDiff:!1,includeCheckDetails:!0}),Et=(gt.checkRuns??[]).filter(rs=>{const Bt=typeof rs.conclusion=="string"?rs.conclusion.toLowerCase():"";return Bt?!["success","neutral","skipped"].includes(Bt):!1});if(Et.length===0){q.message(c("gitView.pr.toast.noFailedChecks"));return}const as=await Vn("github.pr.checks.review.visible"),st=await Vn("github.pr.checks.review.instructions"),Lt=Et.flatMap(rs=>(Array.isArray(rs.annotations)?rs.annotations:[]).map(xs=>({run:rs.name,level:xs.level,title:xs.title,path:xs.path,startLine:xs.startLine,endLine:xs.endLine,message:xs.message,rawDetails:xs.rawDetails}))),ls=`GitHub PR failed checks (JSON)
7
- ${JSON.stringify({repo:gt.repo??null,pr:gt.pr??null,failedChecks:Et,failedAnnotations:Lt},null,2)}`;Xt(We,as,st,ls)}catch(gt){const Mt=gt instanceof Error?gt.message:String(gt);q.error(c("gitView.pr.toast.loadChecksFailed"),{description:Mt})}},[t,Xt,d,ze,Qt,b,c]),gs=l.useCallback(async()=>{if(b("chat"),!d?.prContext){q.error(c("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!ze)return;const We=Qt();if(We)try{const gt=await d.prContext(t,ze.number,{includeDiff:!1,includeCheckDetails:!1}),Mt=gt.issueComments??[],Et=gt.reviewComments??[];if(Mt.length+Et.length===0){q.message(c("gitView.pr.toast.noPrComments"));return}const st=await Vn("github.pr.comments.review.visible"),Lt=await Vn("github.pr.comments.review.instructions"),ls=`GitHub PR comments (JSON)
8
- ${JSON.stringify({repo:gt.repo??null,pr:gt.pr??null,issueComments:Mt,reviewComments:Et},null,2)}`;Xt(We,st,Lt,ls)}catch(gt){const Mt=gt instanceof Error?gt.message:String(gt);q.error(c("gitView.pr.toast.loadPrCommentsFailed"),{description:Mt})}},[t,Xt,d,ze,Qt,b,c]),ds=l.useCallback(async We=>{mt(!1),b("chat");const gt=Qt();if(!gt)return;const Mt=await Vn("github.pr.comment.single.visible"),Et=await Vn("github.pr.comment.single.instructions"),as=`GitHub PR comment (JSON)
9
- ${JSON.stringify({repo:et?.repo??null,pr:et?.pr??ze??null,comment:We},null,2)}`;Xt(gt,Mt,Et,as)},[et,Xt,ze,Qt,b]),Ft=l.useCallback(async We=>{await I(be,We)},[be,I]),Ue=l.useCallback(()=>{Qe.current.forEach(We=>{window.clearTimeout(We)}),Qe.current=v2.map(We=>window.setTimeout(()=>{Ft({force:!0,silent:!0,markInitialResolved:!0})},We))},[Ft]);l.useEffect(()=>{if(!d?.prStatus||!G||a.length<=1||Ve.current||ve?.pr)return;const We=`${w}::${Se?.name??""}`;if(tt.current.has(We))return;tt.current.add(We);const gt=S2(a,r).filter(as=>as.name!==Se?.name);if(gt.length===0)return;let Mt=!1;return(async()=>{for(const as of gt){if(Mt)return;try{if(!(await d.prStatus(t,e,as.name))?.pr)continue;if(Mt)return;Y(Lt=>Lt?.name===as.name?Lt:as);return}catch{}}})(),()=>{Mt=!0}},[e,G,t,d,a,Se?.name,w,ve?.pr,r]),l.useEffect(()=>{S(be),A(be,{directory:t,branch:e,remoteName:Se?.name??null,canShow:G,github:d,githubAuthChecked:m,githubConnected:p?.connected??null})},[e,G,t,S,d,m,p?.connected,be,Se?.name,A]),l.useEffect(()=>(j(be),()=>{C(be)}),[be,j,C]),l.useEffect(()=>{const We=rd.get(w)??null;P(We?.title??vp(e)),D(We?.body??""),M(We?.draft??!1),O(We?.targetBaseBranch?xa(We.targetBaseBranch):xa(n));const gt=nd(a,{selectedRemoteName:We?.selectedRemoteName,trackingBranch:r});Y(Mt=>Mt?.name===gt?.name?Mt:gt)},[n,e,a,w,r]),l.useEffect(()=>{Ft({markInitialResolved:!0})},[be,Ft]),l.useEffect(()=>{!G||!Se?.name||Ft({force:!0,silent:!0,markInitialResolved:!0})},[G,Ft,Se?.name]),l.useEffect(()=>{const We=ve?.resolvedRemoteName?.trim();if(!We||Ve.current)return;const gt=a.find(Mt=>Mt.name===We);gt&&Y(Mt=>Mt?.name===gt.name?Mt:gt)},[a,ve?.resolvedRemoteName]),l.useEffect(()=>{const We=ve?.pr?.state==="closed"||ve?.pr?.state==="merged",gt=De?.lastRefreshAt??0,Mt=Date.now()-gt>6e4,Et=!We&&Mt,as=()=>{Et&&Ft({force:!0,silent:!0})},st=()=>{document.visibilityState==="visible"&&Et&&Ft({force:!0,silent:!0})};return window.addEventListener("focus",as),document.addEventListener("visibilitychange",st),()=>{window.removeEventListener("focus",as),document.removeEventListener("visibilitychange",st)}},[Ft,ve?.pr?.state,De?.lastRefreshAt]),l.useEffect(()=>{m&&p?.connected===!1&&Ft({force:!0,silent:!0,markInitialResolved:!0})},[m,p,Ft]),l.useEffect(()=>{!t||!e||rd.set(w,{title:k,body:N,draft:T,additionalContext:$,targetBaseBranch:V,selectedRemoteName:Se?.name})},[w,k,N,T,$,V,Se?.name,t,e]),l.useEffect(()=>{const We=Qe.current;return()=>{We.forEach(gt=>{window.clearTimeout(gt)}),Qe.current=[]}},[]);const Tt=l.useCallback(async()=>{if(!B&&t){ne(!0);try{const gt={base:fe&&xe?.defaultBranchSha?xe.defaultBranchSha:V,head:e};$&&(gt.context=$);const Mt=await Qv(t,gt);Mt.title?.trim()&&P(Mt.title.trim()),Mt.body?.trim()&&D(Mt.body.trim()),o?.()}catch(We){const gt=We instanceof Error?We.message:String(We);q.error(c("gitView.pr.toast.generateDescriptionFailed"),{description:gt})}finally{ne(!1)}}},[$,e,xe?.defaultBranchSha,t,B,o,V,c,fe]),At=l.useCallback(async()=>{if(!d?.prCreate){q.error(c("gitView.pr.toast.githubApiUnavailable"));return}const We=k.trim();if(!We){q.error(c("gitView.pr.toast.titleRequired"));return}const gt=V.trim();if(!gt){q.error(c("gitView.pr.toast.baseBranchRequired"));return}if(!fe&&gt===e){q.error(c("gitView.pr.toast.baseMustDifferFromHead"));return}ee(!0);try{const Mt=Ku(r),Et=fe&&xe,as=await d.prCreate({directory:t,title:We,head:e,base:gt,...N.trim()?{body:N}:{},draft:T,...Et?{targetRepo:{owner:xe.owner,repo:xe.repo},headRemote:"origin"}:{...Se?{remote:Se.name}:{},...Mt&&Mt!==Se?.name?{headRemote:Mt}:{}}});q.success(c("gitView.pr.toast.prCreated")),R(be,st=>st&&{...st,pr:as}),await Ft({force:!0}),Ue()}catch(Mt){const Et=Mt instanceof Error?Mt.message:String(Mt);q.error(c("gitView.pr.toast.createPrFailed"),{description:Et})}finally{ee(!1)}},[N,e,xe,t,T,d,be,Ft,Ue,Se,V,k,r,R,fe,c]),vt=l.useCallback(async We=>{if(!d?.prMerge){q.error(c("gitView.pr.toast.githubApiUnavailable"));return}E(!0);try{const gt=await d.prMerge({directory:t,number:We.number,method:L});gt.merged?q.success(c("gitView.pr.toast.prMerged")):q.message(c("gitView.pr.toast.prNotMerged"),{description:gt.message||c("gitView.pr.notMergeable")}),await Ft({force:!0}),Ue()}catch(gt){const Mt=gt instanceof Error?gt.message:String(gt);q.error(c("gitView.pr.toast.mergeFailed"),{description:Mt}),We.url&&ad(We.url)}finally{E(!1)}},[t,d,L,Ft,Ue,c]),Rt=l.useCallback(async We=>{if(!d?.prReady){q.error(c("gitView.pr.toast.githubApiUnavailable"));return}J(!0);try{await d.prReady({directory:t,number:We.number}),q.success(c("gitView.pr.toast.markedReady")),await Ft({force:!0}),Ue()}catch(gt){const Mt=gt instanceof Error?gt.message:String(gt);q.error(c("gitView.pr.toast.markReadyFailed"),{description:Mt}),We.url&&ad(We.url)}finally{J(!1)}},[t,d,Ft,Ue,c]),ns=l.useCallback(async We=>{if(!d?.prUpdate){q.error(c("gitView.pr.toast.githubApiUnavailable"));return}const gt=me.trim();if(!gt){q.error(c("gitView.pr.toast.titleRequired"));return}ge(!0);try{const Mt=await d.prUpdate({directory:t,number:We.number,title:gt,body:_});R(be,Et=>Et&&{...Et,pr:{...Et.pr??We,...Mt}}),re(!1),q.success(c("gitView.pr.toast.prUpdated")),await Ft({force:!0}),Ue()}catch(Mt){const Et=Mt instanceof Error?Mt.message:String(Mt);q.error(c("gitView.pr.toast.updatePrFailed"),{description:Et})}finally{ge(!1)}},[t,_,me,d,be,Ft,Ue,R,c]);if(!G)return s.jsx("section",{className:"border-0 bg-transparent rounded-none",children:s.jsxs("div",{className:"space-y-1 pt-3",children:[s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:c("gitView.pullRequest.title")}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pullRequest.availableOnFeatureBranches")})]})});const As=ve?.repo?.url||null,ft=fe&&xe?.url?xe.url:As,is=ve?.checks??null,es=!!ve?.canMerge,Ts=!!ve?.connected,Ls=m&&ve?.connected===!1,X=y2(ve),pt=X?`var(--pr-${X})`:"var(--status-info)",wt=X==="draft"?Mb:X==="merged"?qa:X==="closed"?Rb:Wa,zt=ze?[`${ze.state}${ze.draft?" (draft)":""}`,ze.mergeable===!1?c("gitView.pr.notMergeable"):null,ze.state==="open"&&typeof ze.mergeableState=="string"&&ze.mergeableState&&ze.mergeableState!=="unknown"?ze.mergeableState:null].filter(Boolean).join(" · "):"",ss=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:[ze?s.jsxs(kt,{children:[s.jsx(St,{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:()=>{ad(ze.url)},"aria-label":c("gitView.pr.actions.openOnGitHubAria"),children:s.jsx(wt,{className:"size-4 shrink-0",style:{color:pt}})})}),s.jsx(Ct,{children:s.jsx("p",{children:c("gitView.pr.actions.openOnGitHub")})})]}):s.jsx(wt,{className:"size-4 shrink-0",style:{color:"var(--surface-muted-foreground)"}}),s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground truncate",children:c("gitView.pullRequest.title")}),ze?s.jsxs("span",{className:"typography-meta text-muted-foreground truncate",children:["#",ze.number]}):null]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Ae?s.jsx(Zt,{className:"size-4 animate-spin text-muted-foreground"}):null,s.jsxs(kt,{children:[s.jsx(St,{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:()=>{Ft({force:!0})},"aria-label":c("gitView.pr.actions.refreshAria"),children:s.jsx(Nn,{className:"size-3.5 text-muted-foreground"})})}),s.jsx(Ct,{children:s.jsx("p",{children:c("gitView.pr.actions.refresh")})})]})]})]}),ze?s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 typography-micro text-muted-foreground",children:[s.jsx("span",{style:{color:pt},children:zt}),is?s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx("span",{className:`h-2 w-2 rounded-full ${b2(is.state)}`}),ss]}):null,r&&Se&&r.split("/")[0]!==Se.name?s.jsxs("span",{className:"min-w-0 truncate",children:[r.split("/")[0]," → ",Se.name]}):null]}):null]}),s.jsxs("div",{className:"flex flex-col gap-3 py-3",children:[Ls?s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-meta text-muted-foreground",children:c("gitView.pr.githubNotConnected")}),s.jsx(je,{variant:"outline",size:"sm",onClick:g,className:"w-fit",children:c("gitView.pr.actions.openSettings")})]}):null,U?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:U}),ft?s.jsx(je,{variant:"outline",size:"sm",asChild:!0,className:"w-fit",children:s.jsxs("a",{href:ft,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(Ir,{className:"size-4"}),"Open Repo"]})}):null]}):null,!ze&&!de&&!U&&!Ls?s.jsxs("div",{className:"flex items-center gap-2 typography-micro text-muted-foreground",children:[s.jsx(Zt,{className:"size-4 animate-spin"}),c("gitView.pr.checkingStatus")]}):ze?s.jsx("div",{className:"flex flex-col gap-2",children:s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsxs("div",{className:"min-w-0",children:[H?s.jsxs("div",{className:"space-y-2",children:[s.jsx(Vt,{value:me,onChange:We=>we(We.target.value),placeholder:c("gitView.pr.placeholder.title"),autoCorrect:x?"on":"off",autoCapitalize:x?"sentences":"off",spellCheck:x}),s.jsx(Sn,{value:_,onChange:We=>ue(We.target.value),className:"min-h-[120px] bg-background/80",placeholder:c("gitView.pr.placeholder.description"),autoCorrect:x?"on":"off",autoCapitalize:x?"sentences":"off",spellCheck:x})]}):s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"typography-markdown text-xl font-semibold text-foreground break-words leading-snug",children:ze.title}),ze.body?.trim()?s.jsx(ai,{content:ze.body,className:"typography-markdown-body text-muted-foreground break-words mt-1"}):s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap break-words mt-1",children:c(_t?"gitView.pr.loadingDescription":"gitView.pr.noDescription")})]}),es&&ze.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:[ze.state==="open"?H?s.jsxs(s.Fragment,{children:[s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx(je,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>{re(!1),we(ze.title||""),ue(ze.body||"")},disabled:ae,"aria-label":c("gitView.pr.actions.cancelEditingAria"),children:s.jsx(Ds,{className:"size-4"})})}),s.jsx(Ct,{children:s.jsx("p",{children:c("gitView.pr.actions.cancelEditing")})})]}),s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx(je,{size:"sm",className:"h-7 w-7 px-0",onClick:()=>ns(ze),disabled:ae||!me.trim(),"aria-label":c("gitView.pr.actions.savePrAria"),children:ae?s.jsx(Zt,{className:"size-4 animate-spin"}):s.jsx(Ys,{className:"size-4"})})}),s.jsx(Ct,{children:s.jsx("p",{children:c("gitView.pr.actions.savePr")})})]})]}):s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx(je,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>re(!0),"aria-label":c("gitView.pr.actions.editPrAria"),children:s.jsx(Yr,{className:"size-4"})})}),s.jsx(Ct,{children:s.jsx("p",{children:c("gitView.pr.actions.editPr")})})]}):null,is?s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx(je,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:Kt,disabled:_e,"aria-label":c("gitView.pr.actions.openChecksAria"),children:_e?s.jsx(Zt,{className:"size-4 animate-spin"}):s.jsx(Us,{className:"size-4"})})}),s.jsx(Ct,{children:s.jsx("p",{children:c("gitView.pr.actions.openChecks")})})]}):null,is?.failure?s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx(je,{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:ms,"aria-label":c("gitView.pr.actions.resolveFailedChecksAria"),children:s.jsx(Hr,{className:"size-4"})})}),s.jsx(Ct,{children:s.jsx("p",{children:c("gitView.pr.actions.resolveFailedChecks")})})]}):null,s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx(je,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:Ut,"aria-label":c("gitView.pr.actions.openCommentsAria"),children:s.jsx(dc,{className:"size-4"})})}),s.jsx(Ct,{children:s.jsx("p",{children:c("gitView.pr.actions.openComments")})})]}),s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx(je,{variant:"outline",size:"sm",className:"h-7 w-7 px-0 border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",onClick:gs,"aria-label":c("gitView.pr.actions.shareCommentsAria"),children:s.jsx(Ga,{className:"size-4"})})}),s.jsx(Ct,{children:s.jsx("p",{children:c("gitView.pr.actions.shareComments")})})]}),es&&ze.draft&&ze.state==="open"?s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx(je,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>Rt(ze),disabled:z||te||ae||H,"aria-label":c("gitView.pr.actions.markReadyAria"),children:z?s.jsx(Zt,{className:"size-4 animate-spin"}):s.jsx(xu,{className:"size-4"})})}),s.jsx(Ct,{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(ps,{value:L,onValueChange:We=>W(We),disabled:te||ze.state!=="open",children:[s.jsx(fs,{size:"lg",className:"h-7 w-auto min-w-0",children:s.jsx(ys,{})}),s.jsxs(hs,{children:[s.jsx(Ot,{value:"squash",children:c("gitView.pr.mergeMethod.squash")}),s.jsx(Ot,{value:"merge",children:c("gitView.pr.mergeMethod.merge")}),s.jsx(Ot,{value:"rebase",children:c("gitView.pr.mergeMethod.rebase")})]})]}),s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx(je,{size:"sm",className:"h-7 w-7 px-0",onClick:()=>vt(ze),disabled:te||z||ze.state!=="open"||ze.draft||ae||H,"aria-label":c("gitView.pr.actions.mergePrAria"),children:te?s.jsx(Zt,{className:"size-4 animate-spin"}):s.jsx(qa,{className:"size-4"})})}),s.jsx(Ct,{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)"})," → ",V," ",s.jsxs("span",{className:"opacity-60",children:["(",fe&&xe?"upstream":"remote",")"]})]})]}),ft?s.jsx(je,{variant:"outline",size:"sm",asChild:!0,children:s.jsxs("a",{href:ft,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(Ir,{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(Vt,{value:k,onChange:We=>P(We.target.value),placeholder:c("gitView.pr.placeholder.title"),autoCorrect:x?"on":"off",autoCapitalize:x?"sentences":"off",spellCheck:x})]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.field.baseBranch")}),Re.length>0?s.jsxs(ps,{value:V,onValueChange:O,children:[s.jsx(fs,{className:"h-9",children:s.jsx(ys,{placeholder:c("gitView.pr.placeholder.selectBaseBranch")})}),s.jsx(hs,{children:Re.map(We=>s.jsx(Ot,{value:We,children:We},We))})]}):s.jsx(Vt,{value:V,onChange:We=>O(We.target.value),placeholder:c("gitView.pr.placeholder.main")})]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.field.description")}),s.jsx(Sn,{value:N,onChange:We=>D(We.target.value),className:"min-h-[110px]",placeholder:c("gitView.pr.placeholder.whatChanged"),autoCorrect:x?"on":"off",autoCapitalize:x?"sentences":"off",spellCheck:x})]}),s.jsxs("div",{className:"flex items-center gap-2 cursor-pointer",role:"button",tabIndex:0,"aria-pressed":T,onClick:()=>M(We=>!We),onKeyDown:We=>{(We.key===" "||We.key==="Enter")&&(We.preventDefault(),M(gt=>!gt))},children:[s.jsx(bs,{size:"sm",checked:T,onChange:We=>M(We),ariaLabel:c("gitView.pr.actions.toggleDraftAria")}),s.jsx("span",{className:"typography-ui-label text-foreground select-none",children:c("gitView.pr.field.draft")})]}),y?s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.additionalContext.optional")}),s.jsx(je,{variant:"outline",size:"sm",onClick:()=>Ie(!0),children:$.trim()?c("gitView.pr.actions.edit"):c("gitView.pr.actions.add")})]}),$.trim()&&s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("span",{className:"inline-flex items-center rounded-full bg-[var(--interactive-selection)] px-2 py-0.5 text-xs text-[var(--interactive-selection-foreground)]",children:c("gitView.pr.additionalContext.added")})})]}):s.jsxs(yr,{open:Q,onOpenChange:oe,children:[s.jsxs(Mr,{className:"flex w-full items-center justify-between rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-3 py-2 hover:bg-[var(--interactive-hover)]",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.additionalContext.optional")}),s.jsx("span",{className:"typography-micro text-[var(--primary-base)]",children:Q?c("gitView.pr.actions.hide"):$.trim()?c("gitView.pr.actions.edit"):c("gitView.pr.actions.add")})]}),s.jsx(vr,{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(Sn,{value:$,onChange:We=>F(We.target.value),className:"min-h-[100px] bg-transparent",placeholder:c("gitView.pr.placeholder.additionalContext")}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.additionalContext.hint")})]})})]}),s.jsx(Ar,{open:Z,onClose:()=>Ie(!1),title:c("gitView.pr.additionalContext.title"),footer:s.jsx(je,{size:"sm",onClick:()=>Ie(!1),className:"w-full",children:c("gitView.common.done")}),children:s.jsxs("div",{className:"space-y-3",children:[s.jsx(Sn,{value:$,onChange:We=>F(We.target.value),className:"min-h-[200px] bg-transparent",placeholder:c("gitView.pr.placeholder.additionalContext"),autoFocus:!0}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:c("gitView.pr.additionalContext.hint")})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(je,{variant:"outline",size:"sm",onClick:Tt,disabled:B||le,children:[B?s.jsx(Zt,{className:"size-4 animate-spin"}):s.jsx(Ga,{className:"size-4 text-primary"}),c("gitView.commit.generate")]}),s.jsx("div",{className:"flex-1"}),s.jsxs(je,{size:"sm",className:"min-w-[7.5rem] justify-center gap-2",onClick:At,disabled:le||!Ts||!V.trim()||!fe&&V.trim()===e,children:[s.jsx("span",{className:"inline-flex size-4 items-center justify-center",children:le?s.jsx(Zt,{className:"size-4 animate-spin"}):s.jsx(Wa,{className:"size-4"})}),s.jsx("span",{children:c("gitView.pr.actions.createPr")})]})]})]})]}),s.jsx(ws,{open:Le,onOpenChange:se,children:s.jsxs(vs,{className:"max-w-2xl max-h-[70vh] flex flex-col min-h-0",children:[s.jsxs(Is,{children:[s.jsxs(Ss,{className:"flex items-center gap-2",children:[s.jsx(Wa,{className:"h-5 w-5"}),c("gitView.pr.checkDetails.title")]}),s.jsx(Os,{children:ze?c("gitView.pr.numberLabel",{number:ze.number}):c("gitView.pullRequest.title")})]}),s.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto mt-2",children:[_e?s.jsxs("div",{className:"text-center text-muted-foreground py-8 flex items-center justify-center gap-2",children:[s.jsx(Zt,{className:"h-4 w-4 animate-spin"}),c("gitView.loading.loading")]}):null,_e?null:s.jsx("div",{className:"space-y-3",children:Array.isArray(ie?.checkRuns)&&ie?.checkRuns.length>0?ie.checkRuns.map((We,gt)=>{const Mt=`${We.id??"run"}:${We.job?.jobId??"job"}:${We.name}:${gt}`;return s.jsx("div",{className:"p-1",children:us(We)},Mt)}):s.jsx("div",{className:"text-center text-muted-foreground py-8",children:c("gitView.pr.checkDetails.empty")})})]})]})}),s.jsx(ws,{open:Xe,onOpenChange:mt,children:s.jsxs(vs,{className:"max-w-2xl max-h-[82vh] min-h-[38rem] flex flex-col gap-2",children:[s.jsx(Is,{children:s.jsxs(Ss,{className:"flex items-center gap-2",children:[s.jsx(Wa,{className:"h-5 w-5"}),c("gitView.pr.comments.title"),ze?s.jsx("span",{className:"typography-meta text-muted-foreground",children:c("gitView.pr.numberLabel",{number:ze.number})}):null]})}),s.jsxs(Vo,{className:"mt-2 max-h-[66vh] overflow-y-auto overlay-scrollbar-target overlay-scrollbar-container",children:[lt?s.jsxs("div",{className:"text-center text-muted-foreground py-8 flex items-center justify-center gap-2",children:[s.jsx(Zt,{className:"h-4 w-4 animate-spin"}),c("gitView.loading.loading")]}):null,lt?null:s.jsx("div",{className:"space-y-4",children:Yt.length>0?s.jsx("div",{className:"relative pl-3",children:s.jsx("div",{children:Yt.map((We,gt)=>{const Mt=(We.authorName||"?").charAt(0).toUpperCase(),Et=gt===Yt.length-1;return s.jsxs("div",{className:"relative pl-10 pb-5 last:pb-0",children:[Et?null:s.jsx("div",{className:"absolute left-4 top-[2.375rem] bottom-[0.375rem] w-px bg-border/60"}),s.jsx("div",{className:"absolute left-0 top-0 z-10 flex size-8 items-center justify-center overflow-hidden rounded-full border border-border/60 bg-surface-elevated text-xs text-muted-foreground",children:We.avatarUrl?s.jsx("img",{src:We.avatarUrl,alt:We.authorName,className:"h-full w-full object-cover"}):s.jsx("span",{children:Mt})}),s.jsxs("div",{className:"rounded-lg bg-surface-elevated px-3 pt-0 pb-3 space-y-2",children:[s.jsxs("div",{className:"flex flex-col items-start gap-1 typography-micro text-muted-foreground sm:flex-row sm:flex-wrap sm:items-center sm:gap-x-1 sm:gap-y-1",children:[s.jsxs("span",{className:"text-foreground whitespace-nowrap",children:[We.authorName,We.authorLogin&&We.authorLogin!==We.authorName?` · @${We.authorLogin}`:""]}),We.createdAt?s.jsx("span",{className:"whitespace-nowrap",children:jt(We.createdAt)}):null,s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsxs(je,{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:()=>{ds(We)},"aria-label":c("gitView.pr.actions.sendCommentToAgentAria"),children:[s.jsx(Ga,{className:"size-3.5"}),c("gitView.pr.actions.sendToAgent")]})}),s.jsx(Ct,{children:s.jsx("p",{children:c("gitView.pr.actions.sendCommentToAgent")})})]})]}),s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[We.context,We.path?` · ${We.path}`:"",We.line?`:${We.line}`:""]}),s.jsx(ai,{content:it(We.body),className:["typography-markdown-body text-foreground break-words [&_a]:no-underline [&_a:hover]:no-underline",ts].filter(Boolean).join(" ")})]})]},We.id)})})}):s.jsx("div",{className:"text-center text-muted-foreground py-8",children:c("gitView.pr.comments.empty")})})]})]})})]})},I2=t=>{const e=nt.c(150),{open:n,onOpenChange:r,conflictFiles:a,directory:i,operation:o,onAbort:c,onClearState:d}=t;let p;e[0]!==a?(p=a===void 0?[]:a,e[0]=a,e[1]=p):p=e[1];const m=p,{t:u}=ut(),h=Wt(A2),b=Wt(P2),f=Ui(D2),y=Ui(T2),x=Te(M2),[g,w]=l.useState(!1),[v,S]=l.useState(null),[A,j]=l.useState(null);let C,I;e[2]!==i||e[3]!==n||e[4]!==u?(C=()=>{!n||!i||(w(!0),j(null),S(null),Jv(i).then(ke=>{S(ke)}).catch(ke=>{const xe=ke instanceof Error?ke.message:u("gitView.conflict.loadFailed");j(xe)}).finally(()=>{w(!1)}))},I=[n,i,u],e[2]=i,e[3]=n,e[4]=u,e[5]=C,e[6]=I):(C=e[5],I=e[6]),l.useEffect(C,I);let R;e[7]!==v||e[8]!==i||e[9]!==o?(R=async()=>{if(!v)return null;const ke=o==="merge"?"merge":"rebase",xe=v.headInfo||(o==="merge"?"MERGE_HEAD":"REBASE_HEAD"),he=o==="merge"?"git commit --no-edit":"git rebase --continue",Pe=await Vn("git.conflict.resolve.visible",{operation_label:ke,head_ref:xe}),Be=await Vn("git.conflict.resolve.instructions",{operation_label:ke,directory:i,operation:o,head_info:v.headInfo||"N/A",continue_cmd:he}),G=`${ke} conflict context (JSON)
10
- ${JSON.stringify({directory:i,operation:v.operation,headInfo:v.headInfo,statusPorcelain:v.statusPorcelain,unmergedFiles:v.unmergedFiles,diff:v.diff},null,2)}`;return{visibleText:Pe,instructionsText:Be,payloadText:G}},e[7]=v,e[8]=i,e[9]=o,e[10]=R):R=e[10];const k=R;let P;e[11]!==c||e[12]!==r?(P=()=>{c(),r(!1)},e[11]=c,e[12]=r,e[13]=P):P=e[13];const N=P;let D;e[14]!==d||e[15]!==r?(D=()=>{d?.(),r(!1)},e[14]=d,e[15]=r,e[16]=D):D=e[16];const T=D;let M;e[17]!==k||e[18]!==b||e[19]!==d||e[20]!==r||e[21]!==x||e[22]!==f||e[23]!==y||e[24]!==u?(M=async()=>{const ke=await k();if(!ke){q.error(u("gitView.conflict.noDetailsAvailable"));return}if(!b){q.error(u("gitView.conflict.noActiveSession"),{description:u("gitView.conflict.noActiveSessionDescription")});return}f(ke.visibleText,"replace"),y([{text:ke.instructionsText,synthetic:!0},{text:ke.payloadText,synthetic:!0}]),x("chat"),d?.(),r(!1)},e[17]=k,e[18]=b,e[19]=d,e[20]=r,e[21]=x,e[22]=f,e[23]=y,e[24]=u,e[25]=M):M=e[25];const $=M;let F;e[26]!==k||e[27]!==i||e[28]!==d||e[29]!==r||e[30]!==h||e[31]!==x||e[32]!==u?(F=async()=>{const ke=await k();if(!ke){q.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]=k,e[27]=i,e[28]=d,e[29]=r,e[30]=h,e[31]=x,e[32]=u,e[33]=F):F=e[33];const V=F;let O,L,W,B,ne,le,ee,ae,ge,te,E,z,J,H,re,ce,Ne,me,we,_,ue,Q;if(e[34]!==v||e[35]!==m||e[36]!==b||e[37]!==N||e[38]!==T||e[39]!==$||e[40]!==V||e[41]!==g||e[42]!==A||e[43]!==r||e[44]!==n||e[45]!==o||e[46]!==u){const ke=u(o==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),xe=v?.unmergedFiles||m;W=ws,ue=n,Q=r,L=vs,_="max-w-md w-[calc(100vw-2rem)]",H="flex flex-col gap-4 overflow-hidden";let he;e[69]===Symbol.for("react.memo_cache_sentinel")?(he=s.jsx(bu,{className:"size-5 shrink-0 text-[var(--status-warning)]"}),e[69]=he):he=e[69];const Pe=s.jsxs("div",{className:"flex items-center gap-2",children:[he,s.jsx(Ss,{children:u("gitView.conflict.detectedTitle",{operation:ke})})]});let Be;e[70]!==o||e[71]!==u?(Be=u("gitView.conflict.detectedDescription",{operation:o}),e[70]=o,e[71]=u,e[72]=Be):Be=e[72];let G;e[73]!==Be?(G=s.jsx(Os,{children:Be}),e[73]=Be,e[74]=G):G=e[74],e[75]!==Pe||e[76]!==G?(re=s.jsxs(Is,{children:[Pe,G]}),e[75]=Pe,e[76]=G,e[77]=re):re=e[77],e[78]!==g||e[79]!==u?(ce=g&&s.jsxs("div",{className:"flex items-center justify-center gap-2 py-4 text-muted-foreground",children:[s.jsx(Zt,{className:"size-4 animate-spin"}),s.jsx("span",{className:"typography-meta",children:u("gitView.conflict.loading")})]}),e[78]=g,e[79]=u,e[80]=ce):ce=e[80],e[81]!==A||e[82]!==u?(Ne=A&&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:A})}),e[81]=A,e[82]=u,e[83]=Ne):Ne=e[83],e[84]!==xe||e[85]!==u?(me=xe.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:xe.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:xe.map(R2)})})]}),e[84]=xe,e[85]=u,e[86]=me):me=e[86],e[87]!==v||e[88]!==u?(we=v?.headInfo&&s.jsxs("div",{className:"space-y-1 overflow-hidden",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:u("gitView.conflict.headInfo")}),s.jsx("div",{className:"typography-micro text-foreground font-mono bg-[var(--surface-elevated)] rounded-lg p-3 max-h-24 overflow-y-auto break-words whitespace-pre-wrap",children:v.headInfo})]}),e[87]=v,e[88]=u,e[89]=we):we=e[89],E="flex flex-col gap-2 pt-2";let be;e[90]!==V?(be=()=>{V()},e[90]=V,e[91]=be):be=e[91];const De=g||!v;let Ae;e[92]!==g?(Ae=g?s.jsx(Zt,{className:"size-4 animate-spin"}):s.jsx(_s,{className:"size-4"}),e[92]=g,e[93]=Ae):Ae=e[93];let ve;e[94]!==u?(ve=u("gitView.conflict.resolveNewSession"),e[94]=u,e[95]=ve):ve=e[95],e[96]!==be||e[97]!==De||e[98]!==Ae||e[99]!==ve?(z=s.jsxs(je,{variant:"default",onClick:be,disabled:De,className:"w-full gap-2",children:[Ae,ve]}),e[96]=be,e[97]=De,e[98]=Ae,e[99]=ve,e[100]=z):z=e[100];let U;e[101]!==$?(U=()=>{$()},e[101]=$,e[102]=U):U=e[102];const de=g||!v||!b;let Re;e[103]!==g?(Re=g?s.jsx(Zt,{className:"size-4 animate-spin"}):s.jsx(Eb,{className:"size-4"}),e[103]=g,e[104]=Re):Re=e[104];let Le;e[105]!==u?(Le=u("gitView.conflict.resolveCurrentSession"),e[105]=u,e[106]=Le):Le=e[106],e[107]!==U||e[108]!==de||e[109]!==Re||e[110]!==Le?(J=s.jsxs(je,{variant:"outline",onClick:U,disabled:de,className:"w-full gap-2",children:[Re,Le]}),e[107]=U,e[108]=de,e[109]=Re,e[110]=Le,e[111]=J):J=e[111],ge="flex gap-2 pt-1";let se;e[112]!==u?(se=u("gitView.conflict.continueLater"),e[112]=u,e[113]=se):se=e[113],e[114]!==T||e[115]!==se?(te=s.jsx(je,{variant:"ghost",size:"sm",onClick:T,className:"flex-1",children:se}),e[114]=T,e[115]=se,e[116]=te):te=e[116],O=je,B="destructive",ne="sm",le=N,ee="flex-1",ae=u("gitView.conflict.abortOperation",{operation:ke}),e[34]=v,e[35]=m,e[36]=b,e[37]=N,e[38]=T,e[39]=$,e[40]=V,e[41]=g,e[42]=A,e[43]=r,e[44]=n,e[45]=o,e[46]=u,e[47]=O,e[48]=L,e[49]=W,e[50]=B,e[51]=ne,e[52]=le,e[53]=ee,e[54]=ae,e[55]=ge,e[56]=te,e[57]=E,e[58]=z,e[59]=J,e[60]=H,e[61]=re,e[62]=ce,e[63]=Ne,e[64]=me,e[65]=we,e[66]=_,e[67]=ue,e[68]=Q}else O=e[47],L=e[48],W=e[49],B=e[50],ne=e[51],le=e[52],ee=e[53],ae=e[54],ge=e[55],te=e[56],E=e[57],z=e[58],J=e[59],H=e[60],re=e[61],ce=e[62],Ne=e[63],me=e[64],we=e[65],_=e[66],ue=e[67],Q=e[68];let oe;e[117]!==O||e[118]!==B||e[119]!==ne||e[120]!==le||e[121]!==ee||e[122]!==ae?(oe=s.jsx(O,{variant:B,size:ne,onClick:le,className:ee,children:ae}),e[117]=O,e[118]=B,e[119]=ne,e[120]=le,e[121]=ee,e[122]=ae,e[123]=oe):oe=e[123];let Z;e[124]!==ge||e[125]!==te||e[126]!==oe?(Z=s.jsxs("div",{className:ge,children:[te,oe]}),e[124]=ge,e[125]=te,e[126]=oe,e[127]=Z):Z=e[127];let Ie;e[128]!==E||e[129]!==z||e[130]!==J||e[131]!==Z?(Ie=s.jsxs("div",{className:E,children:[z,J,Z]}),e[128]=E,e[129]=z,e[130]=J,e[131]=Z,e[132]=Ie):Ie=e[132];let Se;e[133]!==H||e[134]!==re||e[135]!==ce||e[136]!==Ne||e[137]!==me||e[138]!==we||e[139]!==Ie?(Se=s.jsxs("div",{className:H,children:[re,ce,Ne,me,we,Ie]}),e[133]=H,e[134]=re,e[135]=ce,e[136]=Ne,e[137]=me,e[138]=we,e[139]=Ie,e[140]=Se):Se=e[140];let Y;e[141]!==L||e[142]!==_||e[143]!==Se?(Y=s.jsx(L,{className:_,children:Se}),e[141]=L,e[142]=_,e[143]=Se,e[144]=Y):Y=e[144];let fe;return e[145]!==W||e[146]!==ue||e[147]!==Q||e[148]!==Y?(fe=s.jsx(W,{open:ue,onOpenChange:Q,children:Y}),e[145]=W,e[146]=ue,e[147]=Q,e[148]=Y,e[149]=fe):fe=e[149],fe};function A2(t){return t.openNewSessionDraft}function P2(t){return t.currentSessionId}function D2(t){return t.setPendingInputText}function T2(t){return t.setPendingSyntheticParts}function M2(t){return t.setActiveMainTab}function R2(t){return s.jsx("li",{className:"typography-micro text-foreground font-mono truncate block",title:t,children:t},t)}const E2=({open:t,onOpenChange:e,operation:n,targetBranch:r,onConfirm:a})=>{const{t:i}=ut(),[o,c]=l.useState(!0),[d,p]=l.useState(!1),m=i(n==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),u=async()=>{p(!0);try{await a(o),e(!1)}catch(b){const f=b instanceof Error?b.message:`Failed to ${n}`;q.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(Is,{children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(bu,{className:"size-5 text-[var(--status-warning)]"}),s.jsx(Ss,{children:i("gitView.stash.title")})]}),s.jsx(Os,{children:i("gitView.stash.description",{operation:n})})]}),s.jsxs("div",{className:"py-2",children:[s.jsx("p",{className:"typography-meta text-muted-foreground mb-3",children:i("gitView.stash.thisWill")}),s.jsxs("ol",{className:"list-decimal list-inside space-y-1 typography-meta text-foreground",children:[s.jsx("li",{children:i("gitView.stash.stepStash")}),s.jsxs("li",{children:[i(n==="merge"?"gitView.operation.merge":"gitView.operation.rebase")," ",i(n==="merge"?"gitView.stash.mergeWith":"gitView.stash.rebaseOnto")," ",s.jsx("span",{className:"font-mono text-primary",children:r})]}),o&&s.jsx("li",{children:i("gitView.stash.stepRestore")})]})]}),s.jsxs("div",{className:"flex items-center gap-2 py-2",children:[s.jsx(bs,{checked:o,onChange:c,disabled:d,ariaLabel:i("gitView.stash.restoreAria")}),s.jsx("span",{className:"typography-ui-label text-foreground cursor-pointer select-none",onClick:()=>!d&&c(!o),children:i("gitView.stash.restoreAfterOperation",{operation:n})})]}),s.jsxs(Qs,{className:"gap-2",children:[s.jsx(je,{variant:"ghost",size:"sm",onClick:h,disabled:d,children:i("gitView.common.cancel")}),s.jsx(je,{variant:"default",size:"sm",onClick:u,disabled:d,className:"gap-1.5",children:d?s.jsxs(s.Fragment,{children:[s.jsx(Zt,{className:"size-4 animate-spin"}),i("gitView.common.processing")]}):i("gitView.stash.confirmButton",{operation:m})})]})]})})},F2=({mergeInProgress:t,rebaseInProgress:e,onContinue:n,onAbort:r,onResolveWithAI:a,hasUnresolvedConflicts:i=!1,isLoading:o=!1})=>{const{t:c}=ut(),[d,p]=l.useState(null),m=t&&t.head,u=e&&(e.headName||e.onto),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)}},y=d!==null,x=c(h==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),g=h==="merge"?qa:Ks;let w="";return t?w=t.message?c("gitView.operation.mergingMessage",{message:t.message}):c("gitView.operation.mergeInProgressWithHead",{head:t.head}):e&&(w=e.headName?c("gitView.operation.rebasingOnto",{headName:e.headName,onto:e.onto||""}):c("gitView.operation.rebaseInProgress")),s.jsx("div",{className:"bg-[var(--status-warning-bg)] border border-[var(--status-warning)] rounded-lg p-3 mx-3 mt-3",children:s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsxs("div",{className:"flex items-start gap-2 min-w-0",children:[s.jsx(g,{className:"size-4 text-[var(--status-warning)] shrink-0"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:"typography-label text-[var(--status-warning)]",children:c("gitView.operation.inProgressTitle",{operation:x})}),w&&s.jsx("p",{className:"typography-micro text-muted-foreground truncate",children:w})]})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i&&a&&s.jsxs(je,{variant:"outline",size:"sm",onClick:a,disabled:y||o,className:"gap-1.5",children:[s.jsx(Pd,{className:"size-4"}),c("gitView.operation.resolveWithAi")]}),d!=="continue"&&s.jsxs(je,{variant:"ghost",size:"sm",onClick:f,disabled:y||o,className:"gap-1.5",children:[d==="abort"?s.jsx(Zt,{className:"size-4 animate-spin"}):s.jsx(Ds,{className:"size-4"}),c("gitView.operation.abort")]}),!i&&s.jsxs(je,{variant:"default",size:"sm",onClick:b,disabled:y||o,className:"gap-1.5",children:[d==="continue"?s.jsx(Zt,{className:"size-4 animate-spin"}):s.jsx(Ys,{className:"size-4"}),c("gitView.operation.continue")]})]}),i&&s.jsx("p",{className:"typography-micro text-[var(--status-warning)]",children:c("gitView.operation.resolveConflictsHint")})]})})},O2=t=>{const e=nt.c(104),{currentBranch:n,localBranches:r,remoteBranches:a,onMerge:i,onRebase:o,disabled:c,isOperating:d,operationLogs:p,onOperationComplete:m,mode:u,defaultTargetBranch:h}=t,b=c===void 0?!1:c,f=d===void 0?!1:d,y=p===void 0?[]:p,x=u===void 0?"dialog":u,{t:g}=ut(),[w,v]=l.useState(!1),[S,A]=l.useState("merge"),[j,C]=l.useState(null),[I,R]=l.useState(!1),[k,P]=l.useState(""),N=l.useRef(null),D=l.useRef(null),T=b||f,M=n||g("gitView.branch.currentBranchFallback"),$=y.length>0&&y.every(L2),F=y.some($2);let V;e[0]===Symbol.for("react.memo_cache_sentinel")?(V=()=>{D.current&&(D.current.scrollTop=D.current.scrollHeight)},e[0]=V):V=e[0],l.useEffect(V,[y]);let O;if(e[1]!==k||e[2]!==n||e[3]!==r||e[4]!==a){e:{const U=k.toLowerCase();let de;e[6]!==a?(de=new Set(a.map(B2).filter(Boolean)),e[6]=a,e[7]=de):de=e[7];const Re=de;let Le;e[8]!==n||e[9]!==Re?(Le=ie=>ie!==n&&!Re.has(ie),e[8]=n,e[9]=Re,e[10]=Le):Le=e[10];const se=r.filter(Le);if(!U){O=se;break e}O=se.filter(ie=>ie.toLowerCase().includes(U))}e[1]=k,e[2]=n,e[3]=r,e[4]=a,e[5]=O}else O=e[5];const L=O;let W;if(e[11]!==k||e[12]!==a){e:{const U=k.toLowerCase();if(!U){W=a;break e}W=a.filter(de=>de.toLowerCase().includes(U))}e[11]=k,e[12]=a,e[13]=W}else W=e[13];const B=W;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 le=ne;let ee;e[18]!==le||e[19]!==v?(ee=()=>{v(!0),C(le()),A("merge"),P("")},e[18]=le,e[19]=v,e[20]=ee):ee=e[20];const ae=ee;let ge;e[21]===Symbol.for("react.memo_cache_sentinel")?(ge=U=>{C(U),R(!1),P("")},e[21]=ge):ge=e[21];const te=ge;let E;e[22]!==i||e[23]!==o||e[24]!==S||e[25]!==j?(E=()=>{j&&(S==="merge"?i(j):o(j))},e[22]=i,e[23]=o,e[24]=S,e[25]=j,e[26]=E):E=e[26];const z=E;let J;e[27]!==f||e[28]!==v?(J=()=>{f||(C(null),A("merge"),P(""),v(!1))},e[27]=f,e[28]=v,e[29]=J):J=e[29];const H=J,re=()=>{f&&!$||($&&m?.(),C(null),A("merge"),P(""),v(!1))};let ce,Ne;e[30]!==I?(ce=()=>{I||P("")},Ne=[I],e[30]=I,e[31]=ce,e[32]=Ne):(ce=e[31],Ne=e[32]),l.useEffect(ce,Ne);let me,we;e[33]!==x||e[34]!==le||e[35]!==j?(me=()=>{x!=="inline"||j||C(le())},we=[x,le,j],e[33]=x,e[34]=le,e[35]=j,e[36]=me,e[37]=we):(me=e[36],we=e[37]),l.useEffect(me,we);const Q=f?s.jsxs("div",{className:"space-y-3",children:[s.jsx("div",{ref:D,className:"rounded-lg border border-border bg-muted/30 p-3 max-h-48 overflow-y-auto",children:s.jsx("div",{className:"space-y-2",children:y.map(V2)})}),$?x==="dialog"?s.jsx(Qs,{children:s.jsx(je,{variant:"default",size:"sm",onClick:re,children:g(F?"gitView.common.close":"gitView.common.done")})}):s.jsx("div",{className:"flex justify-end",children:s.jsx(je,{variant:"default",size:"sm",onClick:re,children:g(F?"gitView.common.close":"gitView.common.done")})}):null]}):s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:g("gitView.branch.operation")}),s.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[s.jsxs("button",{type:"button",onClick:()=>A("merge"),className:pe("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",S==="merge"?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(qa,{className:pe("size-4",S==="merge"?"text-primary":"text-muted-foreground")}),s.jsx("span",{className:pe("typography-ui-label",S==="merge"?"text-foreground":"text-muted-foreground"),children:g("gitView.operation.merge")})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:g("gitView.branch.mergeDescription")})]}),s.jsxs("button",{type:"button",onClick:()=>A("rebase"),className:pe("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",S==="rebase"?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Ks,{className:pe("size-4",S==="rebase"?"text-primary":"text-muted-foreground")}),s.jsx("span",{className:pe("typography-ui-label",S==="rebase"?"text-foreground":"text-muted-foreground"),children:g("gitView.operation.rebase")})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:g("gitView.branch.rebaseDescription")})]})]})]}),s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:S==="merge"?g("gitView.branch.branchToMergeInto",{branch:M}):g("gitView.branch.branchToRebaseOnto")}),s.jsxs(zs,{open:I,onOpenChange:R,modal:!1,children:[s.jsx(Bs,{asChild:!0,children:s.jsxs(je,{variant:"outline",size:"lg",className:"w-full justify-between",children:[s.jsx("span",{className:pe("truncate",!j&&"text-muted-foreground"),children:j||g("gitView.branch.selectBranch")}),s.jsx(Cs,{className:"size-4 opacity-60 shrink-0"})]})}),s.jsx(Vs,{align:"start",sideOffset:6,className:"w-[var(--anchor-width)] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden",children:s.jsxs(oi,{className:"h-full min-h-0",children:[s.jsx(ka,{ref:N,placeholder:g("gitView.branch.searchPlaceholder"),value:k,onValueChange:P,onKeyDown:z2}),s.jsxs(li,{className:"h-full min-h-0",disableHorizontal:!0,children:[s.jsx(ci,{children:g("gitView.branch.empty")}),L.length>0&&s.jsx(Kn,{heading:g("gitView.branch.localBranches"),children:L.map(U=>s.jsx(Rn,{onSelect:()=>te(U),children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:U})},`local-${U}`))}),L.length>0&&B.length>0?s.jsx(Ka,{}):null,B.length>0&&s.jsx(Kn,{heading:g("gitView.branch.remoteBranches"),children:B.map(U=>s.jsx(Rn,{onSelect:()=>te(U),children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:U})},`remote-${U}`))})]})]})})]})]}),j?s.jsx("div",{className:"rounded-lg bg-muted/50 p-3",children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:S==="merge"?s.jsxs(s.Fragment,{children:[g("gitView.branch.summaryMergePrefix")," ",s.jsx("span",{className:"font-mono text-foreground",children:j})," ",g("gitView.branch.summaryMergeInfix")," ",s.jsx("span",{className:"font-mono text-foreground",children:M})]}):s.jsxs(s.Fragment,{children:[g("gitView.branch.summaryRebasePrefix")," ",s.jsx("span",{className:"font-mono text-foreground",children:M})," ",g("gitView.branch.summaryRebaseInfix")," ",s.jsx("span",{className:"font-mono text-foreground",children:j})]})})}):null,x==="dialog"?s.jsxs(Qs,{className:"gap-2 pt-1",children:[s.jsx(je,{variant:"ghost",size:"sm",onClick:H,children:g("gitView.common.cancel")}),s.jsx(je,{variant:"default",size:"sm",onClick:z,disabled:!j,className:"gap-1.5",children:S==="merge"?s.jsxs(s.Fragment,{children:[s.jsx(qa,{className:"size-4"}),g("gitView.operation.merge")]}):s.jsxs(s.Fragment,{children:[s.jsx(Ks,{className:"size-4"}),g("gitView.operation.rebase")]})})]}):s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsx(je,{variant:"destructive",size:"sm",onClick:H,disabled:T,children:g("gitView.common.reset")}),s.jsx("div",{className:"flex-1"}),s.jsx(je,{variant:"default",size:"sm",onClick:z,disabled:T||!j,children:g(S==="merge"?"gitView.operation.merge":"gitView.operation.rebase")})]})]});if(x==="inline"){let U;e[38]!==g?(U=g("gitView.branch.updateTitle"),e[38]=g,e[39]=U):U=e[39];let de;e[40]!==U?(de=s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:U}),e[40]=U,e[41]=de):de=e[41];let Re;e[42]!==g?(Re=g("gitView.branch.updateDescriptionPrefix"),e[42]=g,e[43]=Re):Re=e[43];let Le;e[44]!==M?(Le=s.jsx("span",{className:"font-mono text-foreground",children:M}),e[44]=M,e[45]=Le):Le=e[45];let se;e[46]!==Re||e[47]!==Le?(se=s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[Re," ",Le,"."]}),e[46]=Re,e[47]=Le,e[48]=se):se=e[48];let ie;e[49]!==de||e[50]!==se?(ie=s.jsx("header",{className:"border-b border-border/40 px-0 py-3",children:s.jsxs("div",{className:"space-y-1",children:[de,se]})}),e[49]=de,e[50]=se,e[51]=ie):ie=e[51];let K;e[52]!==Q?(K=s.jsx("div",{className:"pt-3",children:Q}),e[52]=Q,e[53]=K):K=e[53];let _e;return e[54]!==ie||e[55]!==K?(_e=s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[ie,K]}),e[54]=ie,e[55]=K,e[56]=_e):_e=e[56],_e}let oe;e[57]!==f?(oe=f?s.jsx(Zt,{className:"size-4 animate-spin"}):s.jsx(qa,{className:"size-4"}),e[57]=f,e[58]=oe):oe=e[58];let Z;e[59]!==g?(Z=g("gitView.branch.mergeRebase"),e[59]=g,e[60]=Z):Z=e[60];let Ie;e[61]!==Z?(Ie=s.jsx("span",{children:Z}),e[61]=Z,e[62]=Ie):Ie=e[62];let Se;e[63]!==ae||e[64]!==T||e[65]!==oe||e[66]!==Ie?(Se=s.jsx(St,{asChild:!0,children:s.jsxs(je,{variant:"outline",size:"sm",className:"gap-1.5",onClick:ae,disabled:T,children:[oe,Ie]})}),e[63]=ae,e[64]=T,e[65]=oe,e[66]=Ie,e[67]=Se):Se=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(Ct,{sideOffset:8,children:Y}),e[70]=Y,e[71]=fe):fe=e[71];let ke;e[72]!==Se||e[73]!==fe?(ke=s.jsxs(kt,{children:[Se,fe]}),e[72]=Se,e[73]=fe,e[74]=ke):ke=e[74];let xe;e[75]!==re||e[76]!==v?(xe=U=>{U?v(!0):re()},e[75]=re,e[76]=v,e[77]=xe):xe=e[77];let he;e[78]!==g?(he=g("gitView.branch.updateTitle"),e[78]=g,e[79]=he):he=e[79];let Pe;e[80]!==he?(Pe=s.jsx(Ss,{children:he}),e[80]=he,e[81]=Pe):Pe=e[81];let Be;e[82]!==F||e[83]!==f||e[84]!==S||e[85]!==$||e[86]!==g||e[87]!==M?(Be=f?g($?F?"gitView.branch.operationFailed":"gitView.branch.operationCompleted":S==="merge"?"gitView.branch.mergingInProgress":"gitView.branch.rebasingInProgress"):s.jsxs(s.Fragment,{children:[g("gitView.branch.dialogDescriptionPrefix")," ",s.jsx("span",{className:"font-mono text-foreground",children:M}),"."]}),e[82]=F,e[83]=f,e[84]=S,e[85]=$,e[86]=g,e[87]=M,e[88]=Be):Be=e[88];let G;e[89]!==Be?(G=s.jsx(Os,{children:Be}),e[89]=Be,e[90]=G):G=e[90];let be;e[91]!==Pe||e[92]!==G?(be=s.jsxs(Is,{children:[Pe,G]}),e[91]=Pe,e[92]=G,e[93]=be):be=e[93];let De;e[94]!==Q||e[95]!==be?(De=s.jsxs(vs,{className:"max-w-md",children:[be,Q]}),e[94]=Q,e[95]=be,e[96]=De):De=e[96];let Ae;e[97]!==w||e[98]!==xe||e[99]!==De?(Ae=s.jsx(ws,{open:w,onOpenChange:xe,children:De}),e[97]=w,e[98]=xe,e[99]=De,e[100]=Ae):Ae=e[100];let ve;return e[101]!==ke||e[102]!==Ae?(ve=s.jsxs(s.Fragment,{children:[ke,Ae]}),e[101]=ke,e[102]=Ae,e[103]=ve):ve=e[103],ve};function L2(t){return t.status==="done"||t.status==="error"}function $2(t){return t.status==="error"}function B2(t){return t.slice(t.indexOf("/")+1)}function V2(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(Zt,{className:"size-3.5 animate-spin text-primary"}),t.status==="done"&&s.jsx(Ys,{className:"size-3.5 text-success"}),t.status==="error"&&s.jsx(Ds,{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:pe("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 z2(t){return t.stopPropagation()}const wp="oc.git.actionTab",_2=t=>t==="commit"||t==="branch"||t==="pr",ax="gitmojiCache",U2=1e3*60*60*24*7,ix="1",W2=40,K2=20,H2="https://raw.githubusercontent.com/carloscuesta/gitmoji/master/packages/gitmojis/src/gitmojis.json",jp={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:"},ox=t=>{if(!t||typeof t!="object")return!1;const e=t;return typeof e.emoji=="string"&&typeof e.code=="string"&&typeof e.description=="string"},G2=()=>{if(typeof window>"u")return null;try{const t=localStorage.getItem(ax);if(!t)return null;const e=JSON.parse(t);return!e||e.version!==ix||typeof e.fetchedAt!="number"||!Array.isArray(e.gitmojis)?null:{gitmojis:e.gitmojis.filter(ox),fetchedAt:e.fetchedAt,version:e.version}}catch{return null}},q2=t=>{if(!(typeof window>"u"))try{const e={gitmojis:t,fetchedAt:Date.now(),version:ix};localStorage.setItem(ax,JSON.stringify(e))}catch{return}},Q2=t=>Date.now()-t.fetchedAt<U2,J2=(t,e)=>{const n=t.toLowerCase(),r=/^([a-z]+)(?:\(.*\))?!?:/,a=n.match(r);if(a){const c=a[1],d=jp[c];if(d)return e.find(p=>p.code===d)||null}const i=n.split(" ")[0],o=jp[i];return o&&e.find(c=>c.code===o)||null},Np=new Map,Fa=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),lx=()=>{const{t}=ut(),{git:e}=Gn(),n=Xr(),[r,a]=l.useState(null),[i,o]=l.useState(!1),c=Wt(Ee=>Ee.currentSessionId),d=Wt(Ee=>Ee.newSessionDraft),p=Wt(Ee=>Ee.setDraftBootstrapPendingDirectory),m=Wt(Ee=>Ee.worktreeMetadata),u=Wt(Ee=>Ee.availableWorktrees),h=Fa(n),b=l.useMemo(()=>{if(!h)return;const Ee=u.find(Je=>Fa(Je.path)===h);if(Ee)return Ee;for(const Je of m.values())if(Fa(Je.path)===h)return Je},[u,h,m]),f=l.useMemo(()=>{if(c)return m.get(c)??b;if(d?.open)return b},[c,b,d?.open,m]),{profiles:y,globalIdentity:x,defaultGitIdentityId:g,loadProfiles:w,loadGlobalIdentity:v,loadDefaultGitIdentityId:S}=ar(jr(Ee=>({profiles:Ee.profiles,globalIdentity:Ee.globalIdentity,defaultGitIdentityId:Ee.defaultGitIdentityId,loadProfiles:Ee.loadProfiles,loadGlobalIdentity:Ee.loadGlobalIdentity,loadDefaultGitIdentityId:Ee.loadDefaultGitIdentityId}))),A=fg(n??null),j=gc(n??null),C=ig(Ee=>c?Ee.getAttachment(c):void 0),I=C?Yv(C):[],R=C&&!C.degraded&&!C.legacy?C.worktreeRoot??void 0:void 0,k=uN(n,f,j?.current??void 0),P=Fu(n??null),N=Xv(n??null),D=Zv(n??null),T=hg(n??null),M=e1(n??null),$=pn(Ee=>Ee.setActiveDirectory),F=pn(Ee=>Ee.fetchAll),V=pn(Ee=>Ee.ensureAll),O=pn(Ee=>Ee.fetchStatus),L=pn(Ee=>Ee.fetchBranches),W=pn(Ee=>Ee.fetchLog),B=pn(Ee=>Ee.fetchIdentity),ne=pn(Ee=>Ee.prefetchDiffs),le=pn(Ee=>Ee.setLogMaxCount),ee=Te(Ee=>Ee.isMobile),ae=Te(Ee=>Ee.openContextDiff),ge=Te(Ee=>Ee.navigateToDiff),te=Te(Ee=>Ee.setRightSidebarOpen),E=l.useRef(null);l.useEffect(()=>{if(!n){a(null),o(!1);return}let Ee=!1,Je=null;const Ye=async()=>{try{const at=await s1(n);if(Ee)return;a(at.status),at.status==="pending"&&(Je=window.setTimeout(()=>{Ye()},500))}catch{Ee||a(null)}};return Ye(),()=>{Ee=!0,Je!==null&&window.clearTimeout(Je)}},[n]),l.useEffect(()=>{const Ee=E.current;E.current=r,!(!n||!e)&&(Ee==="pending"&&r==="ready"&&(o(!0),F(n,e).finally(()=>{window.setTimeout(()=>{o(!1)},1200)})),r==="failed"&&(p(null),o(!1)))},[n,F,e,p,r]);const z=Fa(d?.bootstrapPendingDirectory??null),J=!!(n&&z&&z===Fa(n)),re=!!(n&&(r==="pending"||J))||i,ce=l.useMemo(()=>n?Np.get(n)??null:null,[n]),Ne=yt(Ee=>Ee.settingsGitmojiEnabled),[me,we]=l.useState(null);l.useEffect(()=>{const Ee=R||k?.projectDirectory;if(!Ee){we(null);return}let Je=!1;return zo(Ee).then(Ye=>{if(Je)return;const at=Ye.trim();we(at&&at!=="HEAD"?at:null)}).catch(()=>{Je||we(null)}),()=>{Je=!0}},[R,k?.projectDirectory]);const[_,ue]=l.useState(ce?.commitMessage??""),[Q,oe]=l.useState([]),[Z,Ie]=l.useState(!1),Se=l.useRef(null),[Y,fe]=l.useState(null),[ke,xe]=l.useState(!1),[he,Pe]=l.useState(null),[Be,G]=l.useState(25),[be,De]=l.useState(!1),{triggerFireworks:Ae}=iN(),ve=l.useRef(new Map),U=l.useRef(0),de=l.useCallback(()=>{U.current+=1,De(!0)},[]),Re=l.useCallback(()=>{U.current=Math.max(0,U.current-1),U.current===0&&De(!1)},[]),[Le,se]=l.useState(()=>new Set(ce?.selectedPaths??[])),[ie,K]=l.useState(!1),[_e,He]=l.useState(new Set),[Ke,Ze]=l.useState(!1),[Xe,mt]=l.useState(0),[et,ct]=l.useState(!1),[lt,ye]=l.useState(ce?.generatedHighlights??[]),Ge=l.useCallback(()=>{const Ee=Se.current;Ee&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{Ee.scrollTo({top:Ee.scrollHeight,behavior:"smooth"})})})},[]),$e=R||k?.projectDirectory||null,Ve=j?.current||null,tt=l.useMemo(()=>{const Ee=j?.tracking;return Ee?Ee.startsWith("origin/"):!0},[j?.tracking]),Qe=l.useMemo(()=>{const Ee=k?.createdFromBranch,Je=typeof Ee=="string"?Ee.trim():"",Ye=typeof j?.current=="string"?j.current.trim():"",at=typeof me=="string"?me.trim():"";return Je?Je===Ye&&Je.startsWith("opencode/")&&at.length>0&&at!==Je?at:Je:at||Ye||"HEAD"},[k?.createdFromBranch,j,me]),ze=l.useCallback(()=>{ye([])},[]),[ht,_t]=l.useState(new Set),[Kt,Ut]=l.useState(new Map),[jt,Dt]=l.useState(new Set),[ts,it]=l.useState(null),[Yt,Qt]=l.useState(null),[Xt,us]=l.useState([]),[ms,gs]=l.useState(""),[ds,Ft]=l.useState(!1),Ue=l.useMemo(()=>[{id:"commit",label:t("gitView.tabs.commit"),icon:s.jsx(uc,{className:"h-3.5 w-3.5"})},{id:"branch",label:t("gitView.tabs.update"),icon:s.jsx(qa,{className:"h-3.5 w-3.5"})},{id:"pr",label:t("gitView.tabs.pr"),icon:s.jsx(Wa,{className:"h-3.5 w-3.5"})}],[t]),[Tt,At]=l.useState(()=>{if(typeof window>"u")return"commit";const Ee=window.localStorage.getItem(wp);return Ee==="worktree"?"branch":_2(Ee)?Ee:"commit"}),[vt,Rt]=l.useState([]),[ns,As]=l.useState(null),[ft,is]=l.useState(null),[es,Ts]=l.useState([]),[Ls,X]=l.useState(!1),[pt,wt]=l.useState([]),[zt,ss]=l.useState("merge"),os=l.useMemo(()=>c?`openchamber.conflict:${c}`:null,[c]),Ps=l.useCallback((Ee,Je,Ye)=>{if(!os||typeof window>"u")return;const at={directory:Ee,conflictFiles:Je,operation:Ye};window.localStorage.setItem(os,JSON.stringify(at))},[os]),Ms=l.useCallback(()=>{!os||typeof window>"u"||window.localStorage.removeItem(os)},[os]);l.useEffect(()=>{typeof window>"u"||window.localStorage.setItem(wp,Tt)},[Tt]),l.useEffect(()=>{if(!os||typeof window>"u"||!n)return;const Ee=window.localStorage.getItem(os);if(Ee)try{const Je=JSON.parse(Ee);if(Je.directory!==n){window.localStorage.removeItem(os);return}wt(Je.conflictFiles??[]),ss(Je.operation??"merge"),X(!0)}catch{window.localStorage.removeItem(os)}},[os,n]);const[We,gt]=l.useState(!1),[Mt,Et]=l.useState("merge"),[as,st]=l.useState(""),Lt=l.useCallback(Ee=>{_n(Ee).then(Je=>{if(Je.ok){q.success(t("gitView.toast.commitHashCopied"));return}q.error(t("gitView.toast.copyFailed"))})},[t]),ls=l.useCallback(Ee=>{_t(Je=>{const Ye=new Set(Je);return Ye.has(Ee)?Ye.delete(Ee):Ye.add(Ee),Ye})},[]);l.useEffect(()=>{if(!n||!e)return;const Ee=Array.from(ht).filter(Je=>!Kt.has(Je)&&!jt.has(Je));if(Ee.length!==0){Dt(Je=>{const Ye=new Set(Je);for(const at of Ee)Ye.add(at);return Ye});for(const Je of Ee)e.getCommitFiles(n,Je).then(Ye=>{Ut(at=>new Map(at).set(Je,Ye.files))}).catch(Ye=>{console.error("Failed to fetch commit files:",Ye),Ut(at=>new Map(at).set(Je,[]))}).finally(()=>{Dt(Ye=>{const at=new Set(Ye);return at.delete(Je),at})})}},[ht,n,e,Kt,jt]),l.useEffect(()=>{n&&Np.set(n,{directory:n,selectedPaths:Array.from(Le),commitMessage:_,generatedHighlights:lt})},[_,n,Le,lt]),l.useEffect(()=>{w(),v(),S()},[w,v,S]),l.useEffect(()=>{if(!n||!e?.getRemoteUrl){Qt(null);return}e.getRemoteUrl(n).then(Qt).catch(()=>Qt(null))},[n,e]);const rs=l.useCallback(async()=>{if(!n||!e?.getRemotes){Rt([]);return}try{const Ee=await e.getRemotes(n);Rt(Ee)}catch{Rt([])}},[n,e]);l.useEffect(()=>{rs()},[rs]),l.useEffect(()=>{if(!Ne){us([]);return}let Ee=!1;const Je=G2();return Je&&(us(Je.gitmojis),Q2(Je))?()=>{Ee=!0}:((async()=>{try{const at=await fetch(H2);if(!at.ok)throw new Error(`Failed to load gitmojis: ${at.statusText}`);const It=await at.json(),Jt=Array.isArray(It.gitmojis)?It.gitmojis.filter(ox):[];Ee||(us(Jt),q2(Jt))}catch(at){Ee||console.warn("Failed to load gitmoji list:",at)}})(),()=>{Ee=!0})},[Ne]),l.useEffect(()=>{n&&($(n),V(n,e))},[n,$,V,e]),l.useEffect(()=>{if(n)return Dr.onGitRefreshHint(Ee=>{Fa(Ee.directory)===Fa(n)&&O(n,e)})},[n,O,e]);const Bt=l.useCallback(async(Ee=!0)=>{if(n)try{await Promise.all([O(n,e),L(n,e)])}catch(Je){if(Ee){const Ye=Je instanceof Error?Je.message:t("gitView.toast.refreshRepositoryFailed");q.error(Ye)}}},[n,e,O,L,t]),xs=l.useCallback(async()=>{n&&await W(n,e,Be)},[n,e,W,Be]),mn=l.useCallback(async()=>{n&&await B(n,e)},[n,e,B]);l.useEffect(()=>{if(!n||!e?.hasLocalIdentity||A!==!0)return;const Ee=typeof g=="string"?g.trim():"";if(!Ee||Ee==="global"||ve.current.get(n)===Ee)return;let Ye=!1;return(async()=>{try{const It=await e.hasLocalIdentity?.(n);if(Ye||It===!0)return;de(),await e.setGitIdentity(n,Ee),ve.current.set(n,Ee),await mn()}catch(It){console.warn("Failed to auto-apply default git identity:",It)}finally{Ye||Re()}})(),()=>{Ye=!0}},[de,n,g,Re,e,A,mn]);const js=l.useMemo(()=>{if(!j)return[];const Ee=j.files??[],Je=new Map;for(const Ye of Ee)Je.set(Ye.path,Ye);return Array.from(Je.values()).sort((Ye,at)=>Ye.path.localeCompare(at.path))},[j]);l.useEffect(()=>{if(!n||js.length===0)return;const Ee=[],Je=new Set,Ye=It=>{!It||Je.has(It)||(Je.add(It),Ee.push(It))};if(Array.from(Le).forEach(Ye),Q.forEach(Ye),js.slice(0,K2).forEach(It=>Ye(It.path)),Ee.length===0)return;const at=window.setTimeout(()=>{ne(n,e,Ee,{maxFiles:W2})},120);return()=>{window.clearTimeout(at)}},[js,n,e,ne,Le,Q]),l.useEffect(()=>{if(!j||js.length===0){se(new Set),K(!1);return}se(Ee=>{const Je=new Set,Ye=Ee??new Set;for(const at of js)Ye.has(at.path)?Je.add(at.path):ie||Je.add(at.path);return Je})},[j,js,ie]);const xn=async(Ee,Je)=>{if(n){fe(Ee);try{const Ye=at=>{const It=`${at.name}/`,Jt=j?.tracking?.startsWith(It)?j.tracking.slice(It.length):void 0;return{remote:at.name,branch:Jt,rebase:!0}};if(Ee==="fetch"){if(!Je)throw new Error("No remote available for fetch");await e.gitFetch(n,{remote:Je.name}),q.success(t("gitView.toast.fetchedFromRemote",{name:Je.name}))}else if(Ee==="pull"){if(!Je)throw new Error("No remote available for pull");const at=await e.gitPull(n,Ye(Je));q.success(at.files.length===1?t("gitView.toast.pulledFilesSingle",{count:at.files.length,name:Je.name}):t("gitView.toast.pulledFilesPlural",{count:at.files.length,name:Je.name}))}else if(Ee==="push")await e.gitPush(n),q.success(t("gitView.toast.pushedToUpstream"));else if(Ee==="sync"){if(!Je)throw new Error("No remote available for sync");let at=0,It=!1;await e.gitFetch(n,{remote:Je.name});const Jt=await e.getGitStatus(n);if((Jt.behind??0)>0){if((Jt.files?.length??0)>0){q.error(t("gitView.toast.commitOrStashBeforeSync"));return}at=(await e.gitPull(n,Ye(Je))).files.length}((await e.getGitStatus(n)).ahead??0)>0&&(await e.gitPush(n),It=!0),at>0&&It?q.success(at===1?t("gitView.toast.syncedPulledSingleAndPushed",{count:at,name:Je.name}):t("gitView.toast.syncedPulledPluralAndPushed",{count:at,name:Je.name})):at>0?q.success(at===1?t("gitView.toast.pulledFilesSingle",{count:at,name:Je.name}):t("gitView.toast.pulledFilesPlural",{count:at,name:Je.name})):It?q.success(t("gitView.toast.pushedToUpstream")):q.success(t("gitView.toast.alreadyUpToDate"))}await Bt(!1),await xs()}catch(Ye){const at=Ye instanceof Error?Ye.message:t("gitView.toast.syncActionFailed",{action:Ee==="sync"?t("gitView.sync.syncChanges"):Ee==="pull"?t("gitView.sync.pull"):Ee});q.error(at)}finally{fe(null)}}},In=l.useCallback(async Ee=>{if(!n)return;const Je=Ee.name.trim();if(!Je){q.error(t("gitView.toast.remoteNameRequired"));return}if(Je==="origin"){q.error(t("gitView.toast.cannotRemoveOriginRemote"));return}As(Je);try{await e.removeRemote(n,{remote:Je}),q.success(t("gitView.toast.removedRemote",{name:Je})),await Promise.all([Bt(!1),rs()])}catch(Ye){const at=Ye instanceof Error?Ye.message:`Failed to remove ${Je}`;q.error(at)}finally{As(null)}},[n,e,rs,Bt,t]),an=async(Ee={})=>{if(!n)return;if(!_.trim()){q.error(t("gitView.toast.enterCommitMessage"));return}const Je=Array.from(Le).sort();if(Je.length===0){q.error(t("gitView.toast.selectFileToCommit"));return}const Ye=Ee.pushAfter?"commitAndPush":"commit";Pe(Ye);try{if(await e.createGitCommit(n,_.trim(),{files:Je}),q.success(t("gitView.toast.commitCreated")),ue(""),se(new Set),K(!1),ze(),await Bt(),Ee.pushAfter){fe("sync");const at=j?.tracking?.split("/")[0],It=Ht.find(Un=>Un.name===at)??Ht[0];if(!It)throw new Error("No remote available for sync");const Jt=`${It.name}/`,Js=j?.tracking?.startsWith(Jt)?j.tracking.slice(Jt.length):void 0;let cn=0,Nr=!1;await e.gitFetch(n,{remote:It.name}),((await e.getGitStatus(n)).behind??0)>0&&(cn=(await e.gitPull(n,{remote:It.name,branch:Js,rebase:!0})).files.length),((await e.getGitStatus(n)).ahead??0)>0&&(await e.gitPush(n),Nr=!0),cn>0&&Nr?q.success(cn===1?t("gitView.toast.syncedPulledSingleAndPushed",{count:cn,name:It.name}):t("gitView.toast.syncedPulledPluralAndPushed",{count:cn,name:It.name})):cn>0?q.success(cn===1?t("gitView.toast.pulledFilesSingle",{count:cn,name:It.name}):t("gitView.toast.pulledFilesPlural",{count:cn,name:It.name})):Nr?q.success(t("gitView.toast.pushedToUpstream")):q.success(t("gitView.toast.alreadyUpToDate")),Ae(),await Bt(!1)}else await Bt(!1);await xs(),mt(at=>at+1)}catch(at){const It=at instanceof Error?at.message:t("gitView.toast.createCommitFailed");q.error(It)}finally{Pe(null),Ee.pushAfter&&fe(null)}},An=l.useCallback(async()=>{if(n){if(Le.size===0){q.error(t("gitView.toast.selectFileToDescribe"));return}console.error("[git-generation][browser] generate button clicked",{directory:n,selectedFiles:Le.size}),ct(!0);try{const{message:Ee}=await t1(n,Array.from(Le)),Je=Ee.subject?.trim()??"",Ye=Array.isArray(Ee.highlights)?Ee.highlights:[];if(Je){let at=Je;if(Ne&&Xt.length>0){const It=J2(Je,Xt);if(It){const{code:Jt,emoji:Js}=It;!Je.startsWith(Jt)&&!Je.startsWith(Js)&&(at=`${Jt} ${Je}`)}}ue(at)}ye(Ye),Ge()}catch(Ee){console.error("[git-generation][browser] GitView generate handler failed",{message:Ee instanceof Error?Ee.message:String(Ee),error:Ee});const Je=Ee instanceof Error?Ee.message:t("gitView.toast.generateCommitMessageFailed");q.error(Je)}finally{ct(!1)}}},[n,Le,Ne,Xt,Ge,t]),on=Ee=>Ee.reason==="attention"?`${Ee.attentionReason} in progress`:Ee.reason==="missing"?"worktree is missing":"worktree is invalid",ln=async(Ee,Je)=>{if(!n||!j)return;const Ye=$c(C);if(Ye.length>0){q.error(t("gitView.toast.cannotCreateBranch",{reason:on(Ye[0])}));return}const at=j.current??null,It=Je?.name??"origin";try{await e.createBranch(n,Ee,at??"HEAD"),q.success(t("gitView.toast.createdBranch",{name:Ee})),await e.checkoutBranch(n,Ee);let Jt=!1;try{await e.gitPush(n,{remote:It,branch:Ee,options:["--set-upstream"]}),Jt=!0}catch(Js){const cn=Js instanceof Error?Js.message:`Unable to push new branch to ${It}.`;q.warning(t("gitView.toast.branchCreatedLocally"),{description:s.jsxs("span",{className:"text-foreground/80 dark:text-foreground/70",children:["Upstream setup failed: ",cn]})})}await Bt(),await xs(),Jt&&q.success(t("gitView.toast.upstreamSet",{branch:Ee,remote:It}))}catch(Jt){const Js=Jt instanceof Error?Jt.message:t("gitView.toast.createBranchFailed");throw q.error(Js),Jt}},fn=async(Ee,Je)=>{if(!n)return;const Ye=$c(C);if(Ye.length>0){q.error(t("gitView.toast.cannotRenameBranch",{reason:on(Ye[0])}));return}try{await e.renameBranch(n,Ee,Je),q.success(t("gitView.toast.renamedBranch",{oldName:Ee,newName:Je})),await Bt(),await xs()}catch(at){const It=at instanceof Error?at.message:t("gitView.toast.renameBranchFailed",{oldName:Ee,newName:Je});q.error(It)}},cr=async Ee=>{if(!n)return;const Je=$c(C);if(Je.length>0){q.error(t("gitView.toast.cannotCheckout",{reason:on(Je[0])}));return}const Ye=Ee.replace(/^remotes\//,"");if(j?.current!==Ye)try{await e.checkoutBranch(n,Ye),q.success(t("gitView.toast.checkedOut",{name:Ye})),await Bt(),await xs()}catch(at){const It=at instanceof Error?at.message:t("gitView.toast.checkoutFailed",{name:Ye});q.error(It)}},Vr=async Ee=>{if(n){de();try{await e.setGitIdentity(n,Ee.id),q.success(t("gitView.toast.appliedIdentity",{name:Ee.name})),await mn()}catch(Je){const Ye=Je instanceof Error?Je.message:t("gitView.toast.applyIdentityFailed");q.error(Ye)}finally{Re()}}},Fe=l.useMemo(()=>P?.all?P.all.filter(Ee=>!Ee.startsWith("remotes/")).sort():[],[P]),Nt=l.useMemo(()=>P?.all?P.all.filter(Ee=>Ee.startsWith("remotes/")).map(Ee=>Ee.replace(/^remotes\//,"")).sort():[],[P]),Ht=l.useMemo(()=>{if(vt.length>0)return vt;const Ee=new Set,Je=j?.tracking?.trim();Je&&Je.includes("/")&&Ee.add(Je.split("/")[0]);for(const Ye of Nt){const at=Ye.indexOf("/");at>0&&Ee.add(Ye.slice(0,at))}return Ee.size===0&&Yt&&Ee.add("origin"),Array.from(Ee).map(Ye=>({name:Ye,fetchUrl:Yt??"",pushUrl:Yt??""}))},[vt,Nt,Yt,j?.tracking]),cs=l.useMemo(()=>{const Ee=new Set(Ht.map(It=>It.name)),Je=It=>{if(!It)return"";let Jt=It.trim();if(!Jt||Jt==="HEAD")return"";if(Fe.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 Js=Jt.indexOf("/");if(Js>0){const cn=Jt.slice(0,Js);if(Ee.has(cn)){const Nr=Jt.slice(Js+1).trim();Nr&&(Jt=Nr)}}return Jt},Ye=Je(typeof k?.createdFromBranch=="string"?k.createdFromBranch:"");if(Ye)return Ye;const at=Je(typeof me=="string"?me:"");return at||(Fe.includes("main")?"main":Fe.includes("master")?"master":Fe.includes("develop")?"develop":"main")},[Ht,Fe,me,k?.createdFromBranch]),Xs=l.useMemo(()=>Ht.map(Ye=>Ye.name).map(Ye=>`${Ye}/${cs}`).find(Ye=>Nt.includes(Ye))??cs,[cs,Ht,Nt]),Zs=l.useMemo(()=>{const Ee=new Map;x&&Ee.set(x.id,x);let Je=null;if(Yt)try{let Ye=Yt.trim();Ye.startsWith("git@")&&(Ye=`https://${Ye.slice(4).replace(":","/")}`),Ye.endsWith(".git")&&(Ye=Ye.slice(0,-4));const at=new URL(Ye);Je=at.hostname+at.pathname}catch{}for(const Ye of y){if(Ye.authType!=="token"){Ee.set(Ye.id,Ye);continue}const at=Ye.host;if(!at){Ee.set(Ye.id,Ye);continue}if(!at.includes("/")){Ee.set(Ye.id,Ye);continue}Je&&Je===at&&Ee.set(Ye.id,Ye)}return Array.from(Ee.values())},[y,x,Yt]),Gs=l.useMemo(()=>{if(D?.userName&&D?.userEmail){const Ee=y.find(Je=>Je.userName===D.userName&&Je.userEmail===D.userEmail);return Ee||(x&&x.userName===D.userName&&x.userEmail===D.userEmail?x:{id:"local-config",name:D.userName,userName:D.userName,userEmail:D.userEmail,sshKey:D.sshCommand?.replace("ssh -i ","")??null,color:"info",icon:"user"})}return x??null},[D,y,x]),en=Le.size,hn=T||Y!==null||he!==null,vn=j?.current??null,dr=!!(k&&$e&&Ve&&tt),Zr=!!(n&&vn),ea=!!vn,On=dr&&$e&&Ve&&k?{repoRoot:$e,sourceBranch:Ve,worktreeMetadata:k}:null,Ln=l.useMemo(()=>!Zr||!n||!vn?null:{directory:n,branch:vn},[Zr,vn,n]);l.useEffect(()=>{if(!n||!e||!N?.all?.length||!vn||!cs||vn===cs){it(null);return}let Ee=!1;return(async()=>{try{const Ye=await e.getGitLog(n,{from:cs,to:"HEAD",maxCount:Be});if(Ee)return;const at=new Set((Ye?.all??[]).map(Jt=>Jt.hash).filter(Jt=>typeof Jt=="string"&&Jt.length>0));if(at.size===0){it(null);return}const It=N.all.findIndex(Jt=>!at.has(Jt.hash));if(It===0){it(null);return}if(It===-1){it({insertBeforeIndex:N.all.length,branchName:vn,direction:"up"});return}it({insertBeforeIndex:It,branchName:vn,direction:"up"})}catch{Ee||it(null)}})(),()=>{Ee=!0}},[cs,vn,n,e,N,Be]);const er=Ee=>{se(Je=>{const Ye=new Set(Je);return Ye.has(Ee)?Ye.delete(Ee):Ye.add(Ee),Ye}),K(!0)},bn=()=>{const Ee=new Set(js.map(Je=>Je.path));se(Ee),K(!0)},qn=()=>{se(new Set),K(!0)},$n=l.useCallback(async Ee=>{if(n){He(Je=>{const Ye=new Set(Je);return Ye.add(Ee),Ye});try{await e.revertGitFile(n,Ee),q.success(t("gitView.toast.revertedFile",{path:Ee})),await Bt(!1)}catch(Je){const Ye=Je instanceof Error?Je.message:t("gitView.toast.revertFailed");q.error(Ye)}finally{He(Je=>{const Ye=new Set(Je);return Ye.delete(Ee),Ye})}}},[n,Bt,e,t]),zr=l.useCallback(async Ee=>{if(!n||Ee.length===0||Ke)return;const Je=Array.from(new Set(Ee));Ze(!0),He(at=>{const It=new Set(at);return Je.forEach(Jt=>It.add(Jt)),It});const Ye=[];try{if(await Promise.all(Je.map(async at=>{try{await e.revertGitFile(n,at)}catch(It){Ye.push({path:at,message:It instanceof Error?It.message:t("gitView.toast.revertFailed")})}})),await Bt(!1),Ye.length===0)q.success(Je.length===1?t("gitView.toast.revertedFilesSingle",{count:Je.length}):t("gitView.toast.revertedFilesPlural",{count:Je.length}));else if(Ye.length===Je.length)q.error(Ye[0]?.message||t("gitView.toast.revertFailed"));else{const at=Je.length-Ye.length;q.warning(at===1?t("gitView.toast.revertedSomeSingle",{success:at,failed:Ye.length}):t("gitView.toast.revertedSomePlural",{success:at,failed:Ye.length}))}}finally{He(at=>{const It=new Set(at);return Je.forEach(Jt=>It.delete(Jt)),It}),Ze(!1)}},[n,e,Ke,Bt,t]),_r=l.useCallback(Ee=>{if(Ee.length===0)return;const Je=Ee.map(Ye=>Ye.trim()).filter(Boolean);if(Je.length===0){ze();return}ue(Ye=>{const at=Ye.trim(),It=at.length>0?`
11
-
12
- `:"";return`${at}${It}${Je.join(`
13
- `)}`.trim()}),ze()},[ze]),Ia=l.useCallback((Ee,Je)=>{const Ye=Je||Ee;ue(at=>{const It=at.trimStart();return It.startsWith(Ee)||Je&&It.startsWith(Je)?at:`${Ye.endsWith(" ")?Ye:`${Ye} `}${at}`.trimStart()}),gs(""),Ie(!1)},[]),Aa=l.useCallback(Ee=>{G(Ee),n&&(le(n,Ee),W(n,e,Ee))},[n,le,W,e]),ur=l.useCallback(Ee=>{const Je=Ee instanceof Error?Ee.message.toLowerCase():"";return Je.includes("uncommitted changes")||Je.includes("local changes")||Je.includes("your local changes would be overwritten")||Je.includes("please commit your changes or stash them")||Je.includes("cannot rebase: you have unstaged changes")||Je.includes("error: cannot pull with rebase")},[]),tr=l.useCallback((Ee,Je)=>{Ts(Ye=>[...Ye,{message:Ee,status:Je,timestamp:Date.now()}])},[]),qs=l.useCallback((Ee,Je)=>{Ts(Ye=>{if(Ye.length===0)return Ye;const at=[...Ye];return at[at.length-1]={...at[at.length-1],status:Ee,...Je?{message:Je}:{}},at})},[]),Cn=l.useCallback(()=>{Ts([])},[]),mi=l.useCallback(()=>{Ts([]),is(null)},[]),Er=l.useCallback(Ee=>{const Je=Ee.trim(),Ye=new Set(Ht.map(It=>It.name)),at=Je.indexOf("/");if(at>0){const It=Je.slice(0,at),Jt=Je.slice(at+1);if(Ye.has(It)&&Jt)return{branch:Je,remote:It,remoteBranch:Jt}}for(const It of Ht){const Jt=`${It.name}/${Je}`;if(Nt.includes(Jt))return{branch:Jt,remote:It.name,remoteBranch:Je}}return{branch:Je,remote:null,remoteBranch:null}},[Ht,Nt]),da=l.useCallback(async Ee=>{if(!n)return;is("merge"),Cn();const Je=j?.current,Ye=Er(Ee);try{Ye.remote&&Ye.remoteBranch&&(tr(`Fetching ${Ye.remote}/${Ye.remoteBranch}...`,"running"),await e.gitFetch(n,{remote:Ye.remote,branch:Ye.remoteBranch}),qs("done",`Fetched ${Ye.remote}/${Ye.remoteBranch}`)),tr(`Merging ${Ye.branch} into ${Je}...`,"running");const at=await e.merge(n,{branch:Ye.branch});at.conflict?(qs("error","Merge conflicts detected"),wt(at.conflictFiles??[]),ss("merge"),X(!0),Ps(n,at.conflictFiles??[],"merge")):(qs("done",`Merged ${Ye.branch} into ${Je}`),Ms(),tr("Refreshing repository status...","running"),await Bt(),await xs(),qs("done","Repository status updated"))}catch(at){if(ur(at))qs("error","Uncommitted changes detected"),Et("merge"),st(Ye.branch),gt(!0);else{const It=at instanceof Error?at.message:`Failed to merge ${Ye.branch}`;qs("error",It)}}},[n,e,j,Er,Bt,xs,ur,Ps,Ms,tr,qs,Cn]),pi=l.useCallback(async Ee=>{if(!n)return;is("rebase"),Cn();const Je=j?.current,Ye=Er(Ee);try{Ye.remote&&Ye.remoteBranch&&(tr(`Fetching ${Ye.remote}/${Ye.remoteBranch}...`,"running"),await e.gitFetch(n,{remote:Ye.remote,branch:Ye.remoteBranch}),qs("done",`Fetched ${Ye.remote}/${Ye.remoteBranch}`)),tr(`Rebasing ${Je} onto ${Ye.branch}...`,"running");const at=await e.rebase(n,{onto:Ye.branch});at.conflict?(qs("error","Rebase conflicts detected"),wt(at.conflictFiles??[]),ss("rebase"),X(!0),Ps(n,at.conflictFiles??[],"rebase")):(qs("done",`Rebased ${Je} onto ${Ye.branch}`),Ms(),tr("Refreshing repository status...","running"),await Bt(),await xs(),qs("done","Repository status updated"))}catch(at){if(ur(at))qs("error","Uncommitted changes detected"),Et("rebase"),st(Ye.branch),gt(!0);else{const It=at instanceof Error?at.message:`Failed to rebase onto ${Ye.branch}`;qs("error",It)}}},[n,e,j,Er,Bt,xs,ur,Ps,Ms,tr,qs,Cn]),Qn=l.useCallback(async()=>{if(n)try{zt==="merge"?(await e.abortMerge(n),q.success(t("gitView.toast.mergeAborted"))):(await e.abortRebase(n),q.success(t("gitView.toast.rebaseAborted"))),Ms(),await Bt(),await xs()}catch(Ee){const Je=Ee instanceof Error?Ee.message:`Failed to abort ${zt}`;q.error(Je)}},[n,e,zt,Bt,xs,Ms,t]),Pa=l.useMemo(()=>j?.files?j.files.some(Ee=>Ee.index==="U"||Ee.working_dir==="U"||Ee.index==="A"&&Ee.working_dir==="A"||Ee.index==="D"&&Ee.working_dir==="D"):!1,[j?.files]),to=l.useCallback(async()=>{if(n)try{const Ee=!!j?.mergeInProgress?.head,Je=!!(j?.rebaseInProgress?.headName||j?.rebaseInProgress?.onto);if(Ee){const Ye=await e.continueMerge(n);Ye.conflict?(wt(Ye.conflictFiles??[]),ss("merge"),X(!0),Ps(n,Ye.conflictFiles??[],"merge"),q.error(t("gitView.toast.mergeConflictsDetected"))):(Ms(),q.success(t("gitView.toast.mergeCompleted")),await Bt(),await xs())}else if(Je){const Ye=await e.continueRebase(n);Ye.conflict?(wt(Ye.conflictFiles??[]),ss("rebase"),X(!0),Ps(n,Ye.conflictFiles??[],"rebase"),q.error(t("gitView.toast.rebaseConflictsDetected"))):(Ms(),q.success(t("gitView.toast.rebaseStepCompleted")),await Bt(),await xs())}}catch(Ee){const Je=Ee instanceof Error?Ee.message:t("gitView.toast.continueOperationFailed");q.error(Je)}},[n,e,j,Bt,xs,Ps,Ms,t]),fi=l.useCallback(async()=>{if(n)try{!!j?.mergeInProgress?.head?(await e.abortMerge(n),q.success(t("gitView.toast.mergeAborted"))):(await e.abortRebase(n),q.success(t("gitView.toast.rebaseAborted"))),Ms(),await Bt(),await xs()}catch(Ee){const Je=Ee instanceof Error?Ee.message:t("gitView.toast.abortOperationFailed");q.error(Je)}},[n,e,j,Bt,xs,Ms,t]),Da=l.useCallback(()=>{if(!n)return;const Je=!!j?.mergeInProgress?.head?"merge":"rebase",Ye=j?.files?.filter(at=>at.index==="U"||at.working_dir==="U").map(at=>at.path)??[];Ye.length>0&&wt(Ye),ss(Je),X(!0)},[n,j]),sr=l.useCallback(async Ee=>{if(!n)return;const Je=j?.current,Ye=Mt,at=as;try{await e.stash(n,{message:`Auto-stash before ${Ye} with ${at}`,includeUntracked:!0})}catch(Js){const cn=Js instanceof Error?Js.message:"Failed to stash changes";q.error(cn);return}let It=!1,Jt=!1;try{if(Ye==="merge"){const Js=await e.merge(n,{branch:at});Js.conflict?(Jt=!0,wt(Js.conflictFiles??[]),ss("merge"),X(!0)):(It=!0,q.success(t("gitView.toast.mergedIntoBranch",{branch:at,currentBranch:Je||""})))}else{const Js=await e.rebase(n,{onto:at});Js.conflict?(Jt=!0,wt(Js.conflictFiles??[]),ss("rebase"),X(!0)):(It=!0,q.success(t("gitView.toast.rebasedOntoBranch",{currentBranch:Je||"",branch:at})))}if(Ee&&It)try{await e.stashPop(n),q.success(t("gitView.toast.stashedRestored"))}catch(Js){const cn=Js instanceof Error?Js.message:t("gitView.toast.restoreStashFailed");q.error(cn)}else Ee&&Jt&&q.info(t("gitView.toast.restoreStashManually"));await Bt(),await xs()}catch(Js){if(Ee)try{await e.stashPop(n)}catch{}throw Js}},[n,e,j,Mt,as,Bt,xs,t]);return n?T&&A===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(Zt,{className:"size-4 animate-spin"}),s.jsx("span",{className:"typography-ui-label",children:t("gitView.loading.checkingRepository")})]})}):A===!1?re?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-4 text-center",children:[s.jsx(Zt,{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(Ks,{className:"mb-3 size-6 text-muted-foreground"}),s.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:t("gitView.empty.notGitRepository")}),s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:t("gitView.empty.notGitRepositoryDescription")}),I.includes("open-without-worktree-features")?s.jsx("p",{className:"typography-meta mt-2 text-muted-foreground",children:t("gitView.empty.worktreeFeaturesUnavailable")}):null]}):s.jsxs("div",{className:pe("flex h-full flex-col overflow-hidden","bg-sidebar"),children:[s.jsx(DN,{status:j,localBranches:Fe,remoteBranches:Nt,branchInfo:P?.branches,syncAction:Y,remotes:Ht,onFetch:Ee=>xn("fetch",Ee),onSync:Ee=>xn("sync",Ee),onRemoveRemote:In,removingRemoteName:ns,onCheckoutBranch:cr,onCreateBranch:ln,onRenameBranch:fn,activeIdentityProfile:Gs,availableIdentities:Zs,onSelectIdentity:Vr,isApplyingIdentity:be,isWorktreeMode:!!k,onOpenHistory:()=>Ft(!0),actionTabItems:Ue,activeActionTab:Tt,onSelectActionTab:Ee=>At(Ee)}),n&&(j?.mergeInProgress?.head||j?.rebaseInProgress?.headName||j?.rebaseInProgress?.onto)&&s.jsx(F2,{mergeInProgress:j?.mergeInProgress,rebaseInProgress:j?.rebaseInProgress,onContinue:to,onAbort:fi,onResolveWithAI:Da,hasUnresolvedConflicts:Pa,isLoading:T}),s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:s.jsx("div",{className:"h-full min-h-0 flex flex-col",children:s.jsx("div",{className:pe("min-w-0 min-h-0 h-full flex flex-col","bg-sidebar"),children:s.jsxs(Es,{as:Vo,ref:Se,outerClassName:"flex-1 min-h-0",className:pe("px-4","pt-1 pb-4"),disableHorizontal:!0,preventOverscroll:!0,children:[Tt==="commit"?s.jsx("div",{className:"space-y-4",children:(js?.length??0)>0?s.jsxs(s.Fragment,{children:[s.jsx(VN,{maxListHeightClassName:"max-h-[40vh]",changeEntries:js,onVisiblePathsChange:oe,selectedPaths:Le,diffStats:j?.diffStats,revertingPaths:_e,onToggleFile:er,onSelectAll:bn,onClearSelection:qn,onRevertAll:zr,onViewDiff:Ee=>{if(n&&!ee){ae(n,Ee);return}ge(Ee),ee&&te(!1)},onRevertFile:$n,isRevertingAll:Ke,onOpenStashes:()=>xe(!0)}),s.jsx(KN,{selectedCount:en,commitMessage:_,onCommitMessageChange:ue,generatedHighlights:lt,onInsertHighlights:_r,onGenerateMessage:An,isGeneratingMessage:et,onCommit:()=>an({pushAfter:!1}),onCommitAndPush:()=>an({pushAfter:!0}),commitAction:he,gitmojiEnabled:Ne,onOpenGitmojiPicker:()=>Ie(!0)})]}):s.jsx(HN,{onOpenStashes:()=>xe(!0)})}):null,Tt==="branch"?s.jsx("div",{className:"space-y-4",children:ea?s.jsxs(s.Fragment,{children:[s.jsx(O2,{mode:"inline",currentBranch:j?.current,localBranches:Fe,remoteBranches:Nt,defaultTargetBranch:Xs,onMerge:da,onRebase:pi,disabled:hn,isOperating:ft!==null,operationLogs:es,onOperationComplete:mi}),On?s.jsx(jN,{repoRoot:On.repoRoot,sourceBranch:On.sourceBranch,worktreeMetadata:On.worktreeMetadata,localBranches:Fe,defaultTargetBranch:Qe,refreshKey:Xe,onRefresh:()=>{n&&(O(n,e),L(n,e),W(n,e,Be))}},On.worktreeMetadata.path):null]}):s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("gitView.branch.actionsUnavailable")})}):null,Tt==="pr"?s.jsx("div",{className:"space-y-4",children:Ln?s.jsx(C2,{directory:Ln.directory,branch:Ln.branch,baseBranch:cs,trackingBranch:j?.tracking??void 0,remotes:vt,remoteBranches:Nt,onGeneratedDescription:Ge}):s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:t("gitView.pullRequest.title")}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:t("gitView.pullRequest.createHint")})]})}):null]})})})}),s.jsx(ws,{open:ds,onOpenChange:Ft,children:s.jsxs(vs,{className:"max-w-5xl h-[90vh] max-h-[90vh] flex flex-col overflow-hidden",children:[s.jsxs(Is,{children:[s.jsx(Ss,{children:t("gitView.history.title")}),s.jsx(Os,{children:t("gitView.history.dialogDescription")})]}),s.jsx("div",{className:"flex-1 min-h-0",children:s.jsx(JN,{log:N,isLogLoading:M,logMaxCount:Be,onLogMaxCountChange:Aa,expandedCommitHashes:ht,onToggleCommit:ls,commitFilesMap:Kt,loadingCommitHashes:jt,onCopyHash:Lt,showHeader:!1,contentMaxHeightClassName:"h-full max-h-none",branchDivider:ts})})]})}),s.jsx(TN,{open:ke,onOpenChange:xe,directory:n,hasUncommittedChanges:(j?.files?.length??0)>0,uncommittedFileCount:j?.files?.length??0,onChanged:async()=>{await Bt(!1),await xs()}}),s.jsx(ws,{open:Z,onOpenChange:Ie,children:s.jsxs(vs,{className:"max-w-md p-0 overflow-hidden",children:[s.jsx(Is,{className:"px-4 pt-4",children:s.jsx(Ss,{children:t("gitView.gitmoji.title")})}),s.jsxs(oi,{className:"h-[420px]",children:[s.jsx(ka,{placeholder:t("gitView.gitmoji.searchPlaceholder"),value:ms,onValueChange:gs}),s.jsxs(li,{children:[s.jsx(ci,{children:t("gitView.gitmoji.empty")}),s.jsx(Kn,{children:(Xt.length===0?[]:Xt.filter(Ee=>{const Je=ms.trim().toLowerCase();return Je?Ee.emoji.includes(Je)||Ee.code.toLowerCase().includes(Je)||Ee.description.toLowerCase().includes(Je):!0})).map(Ee=>s.jsxs(Rn,{onSelect:()=>Ia(Ee.emoji,Ee.code),children:[s.jsx("span",{className:"text-lg",children:Ee.emoji}),s.jsx("span",{className:"typography-ui-label text-foreground",children:Ee.code}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:Ee.description})]},Ee.code))})]})]})]})}),n&&s.jsx(I2,{open:Ls,onOpenChange:X,conflictFiles:pt,directory:n,operation:zt,onAbort:Qn,onClearState:Ms}),s.jsx(E2,{open:We,onOpenChange:gt,operation:Mt,targetBranch:as,onConfirm:sr})]}):s.jsx("div",{className:"flex h-full items-center justify-center px-4 text-center",children:s.jsx("p",{className:"typography-ui-label text-muted-foreground",children:t("gitView.empty.selectSessionOrDirectory")})})},Y2=Object.freeze(Object.defineProperty({__proto__:null,GitView:lx},Symbol.toStringTag,{value:"Module"})),qd=5e3,X2=(t,e)=>{if(!t)return 1;let n=1;for(let r=0;r<t.length;r+=1)if(t.charCodeAt(r)===10&&(n+=1,n>e))return n;return n},Z2=t=>{const n=(t instanceof Error?t.message:String(t??"")).toLowerCase();return n.includes("file not found")||n.includes("not found")||n.includes("enoent")||n.includes("no such file")||n.includes("does not exist")?"missing":"unreadable"},eS=async(t,e)=>{if(t.readFile)return(await t.readFile(e,{allowOutsideWorkspace:!0,optional:!0})).content??"";const n=new URLSearchParams({path:e,allowOutsideWorkspace:"true",optional:"true"}),r=await fetch(`/api/fs/read?${n.toString()}`,{cache:"no-store"});if(!r.ok){const a=await r.json().catch(()=>({error:r.statusText}));throw new Error(a.error||"Failed to read file")}return r.text()},Hu=async(t,e)=>{try{const n=await eS(t,e);return X2(n,qd)>qd?{ok:!1,reason:"too-large"}:{ok:!0}}catch(n){return{ok:!1,reason:Z2(n)}}},Gu=t=>t==="too-large"?`File is too large to open (>${qd.toLocaleString()} lines)`:t==="missing"?"File not found":"Failed to open file",tS=t=>t.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),Yn=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},cx=(t,e)=>{const n=Yn(e),r=Yn(t).replace(/\/+$/,"");return n===r?".":!r||!n.startsWith(`${r}/`)?n:n.slice(r.length+1)},sS=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),nS=new Set(["node_modules"]),rS=t=>nS.has(t),aS=t=>{const e=Yn(t);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},dx=(t,e)=>s.jsx(Pr,{filePath:t,extension:e}),iS=t=>{const e=nt.c(3),{status:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={open:"var(--status-info)",modified:"var(--status-warning)","git-modified":"var(--status-warning)","git-added":"var(--status-success)","git-deleted":"var(--status-error)"},e[0]=r):r=e[0];const a=r[n];let i;return e[1]!==a?(i=s.jsx("span",{className:"h-2 w-2 rounded-full",style:{backgroundColor:a}}),e[1]=a,e[2]=i):i=e[2],i},oS=t=>{const e=nt.c(63),{node:n,root:r,isExpanded:a,isActive:i,status:o,badge:c,permissions:d,downloadFile:p,contextMenuPath:m,setContextMenuPath:u,onSelect:h,onToggle:b,onRevealPath:f,onOpenDialog:y}=t,{t:x}=ut(),g=n.type==="directory",{canRename:w,canCreateFile:v,canCreateFolder:S,canDelete:A,canReveal:j}=d;let C;e[0]!==v||e[1]!==S||e[2]!==A||e[3]!==w||e[4]!==j||e[5]!==n.path||e[6]!==u?(C=le=>{!w&&!v&&!S&&!A&&!j||(le?.preventDefault(),u(n.path))},e[0]=v,e[1]=S,e[2]=A,e[3]=w,e[4]=j,e[5]=n.path,e[6]=u,e[7]=C):C=e[7];const I=C;let R;e[8]!==g||e[9]!==n||e[10]!==h||e[11]!==b?(R=()=>{g?b(n.path):h(n)},e[8]=g,e[9]=n,e[10]=h,e[11]=b,e[12]=R):R=e[12];const k=R;let P;e[13]!==n.path||e[14]!==u?(P=le=>{le.stopPropagation(),u(n.path)},e[13]=n.path,e[14]=u,e[15]=P):P=e[15];const N=P;let D;e[16]!==n.path||e[17]!==r?(D=le=>{const ee=cx(r,n.path);!ee||ee==="."||(le.dataTransfer.setData("application/x-openchamber-file-path",ee),le.dataTransfer.effectAllowed="copy")},e[16]=n.path,e[17]=r,e[18]=D):D=e[18];const T=D,M=i?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let $;e[19]!==M?($=pe("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",M,"cursor-grab active:cursor-grabbing"),e[19]=M,e[20]=$):$=e[20];let F;e[21]!==g||e[22]!==a||e[23]!==n.extension||e[24]!==n.path?(F=g?a?s.jsx(Su,{className:"h-4 w-4 flex-shrink-0 text-primary/60"}):s.jsx(ku,{className:"h-4 w-4 flex-shrink-0 text-primary/60"}):dx(n.path,n.extension),e[21]=g,e[22]=a,e[23]=n.extension,e[24]=n.path,e[25]=F):F=e[25];let V;e[26]!==n.name||e[27]!==n.path?(V=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]=V):V=e[28];let O;e[29]!==g||e[30]!==o?(O=!g&&o&&s.jsx(iS,{status:o}),e[29]=g,e[30]=o,e[31]=O):O=e[31];let L;e[32]!==c||e[33]!==g?(L=g&&c&&s.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[c.modified>0&&s.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",c.modified]}),c.added>0&&s.jsxs("span",{className:"text-[var(--status-success)]",children:["+",c.added]})]}),e[32]=c,e[33]=g,e[34]=L):L=e[34];let W;e[35]!==I||e[36]!==T||e[37]!==k||e[38]!==L||e[39]!==$||e[40]!==F||e[41]!==V||e[42]!==O?(W=s.jsxs("button",{type:"button",onClick:k,onContextMenu:I,draggable:!0,onDragStart:T,className:$,children:[F,V,O,L]}),e[35]=I,e[36]=T,e[37]=k,e[38]=L,e[39]=$,e[40]=F,e[41]=V,e[42]=O,e[43]=W):W=e[43];let B;e[44]!==v||e[45]!==S||e[46]!==A||e[47]!==w||e[48]!==j||e[49]!==m||e[50]!==p||e[51]!==N||e[52]!==g||e[53]!==n||e[54]!==y||e[55]!==f||e[56]!==u||e[57]!==x?(B=(w||v||S||A||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(zs,{open:m===n.path,onOpenChange:le=>u(le?n.path:null),children:[s.jsx(Bs,{asChild:!0,children:s.jsx(je,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:N,children:s.jsx(Iu,{className:"h-4 w-4"})})}),s.jsxs(Vs,{align:"end",side:"bottom",onCloseAutoFocus:()=>u(null),children:[w&&s.jsxs($t,{onClick:le=>{le.stopPropagation(),y("rename",n)},children:[s.jsx(Yr,{className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.rename")]}),s.jsxs($t,{onClick:le=>{le.stopPropagation(),_n(n.path).then(ee=>{if(ee.ok){q.success(x("sidebarFilesTree.toast.pathCopied"));return}q.error(x("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(br,{className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.copyPath")]}),!g&&p&&s.jsxs($t,{onClick:le=>{le.stopPropagation(),p(n.path)},children:[s.jsx(Qr,{className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.save")]}),j&&s.jsxs($t,{onClick:le=>{le.stopPropagation(),f(n.path)},children:[s.jsx(Fh,{className:"mr-2 h-4 w-4"})," ",x($u())]}),g&&(v||S)&&s.jsxs(s.Fragment,{children:[s.jsx(En,{}),v&&s.jsxs($t,{onClick:le=>{le.stopPropagation(),y("createFile",n)},children:[s.jsx(mc,{className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.newFile")]}),S&&s.jsxs($t,{onClick:le=>{le.stopPropagation(),y("createFolder",n)},children:[s.jsx(Ca,{className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.newFolder")]})]}),A&&s.jsxs(s.Fragment,{children:[s.jsx(En,{}),s.jsxs($t,{onClick:le=>{le.stopPropagation(),y("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(sn,{className:"mr-2 h-4 w-4"})," ",x("sidebarFilesTree.menu.delete")]})]})]})]})}),e[44]=v,e[45]=S,e[46]=A,e[47]=w,e[48]=j,e[49]=m,e[50]=p,e[51]=N,e[52]=g,e[53]=n,e[54]=y,e[55]=f,e[56]=u,e[57]=x,e[58]=B):B=e[58];let ne;return e[59]!==I||e[60]!==W||e[61]!==B?(ne=s.jsxs("div",{className:"group relative flex items-center",onContextMenu:I,children:[W,B]}),e[59]=I,e[60]=W,e[61]=B,e[62]=ne):ne=e[62],ne},lS=()=>{const t=nt.c(240),{t:e}=ut(),{files:n,runtime:r}=Gn(),a=Xr()??"";let i;t[0]!==a?(i=Yn(a.trim()),t[0]=a,t[1]=i):i=t[1];const o=i,c=xc(),d=Ou(),p=Lu(cS),m=Te(dS),u=gc(a),[h,b]=l.useState(""),f=bc(h,200),y=l.useRef(null);let x;t[2]===Symbol.for("react.memo_cache_sentinel")?(x=[],t[2]=x):x=t[2];const[g,w]=l.useState(x),[v,S]=l.useState(!1);let A;t[3]===Symbol.for("react.memo_cache_sentinel")?(A={},t[3]=A):A=t[3];const[j,C]=l.useState(A);let I;t[4]===Symbol.for("react.memo_cache_sentinel")?(I=new Set,t[4]=I):I=t[4];const R=l.useRef(I);let k;t[5]===Symbol.for("react.memo_cache_sentinel")?(k=new Set,t[5]=k):k=t[5];const P=l.useRef(k);let N;t[6]===Symbol.for("react.memo_cache_sentinel")?(N=[],t[6]=N):N=t[6];const D=N;let T;t[7]===Symbol.for("react.memo_cache_sentinel")?(T=[],t[7]=T):T=t[7];const M=T;let $;t[8]!==o?($=X=>o?X.byRoot[o]?.expandedPaths??D:D,t[8]=o,t[9]=$):$=t[9];const F=Xn($);let V;t[10]!==o?(V=X=>o?X.byRoot[o]?.selectedPath??null:null,t[10]=o,t[11]=V):V=t[11];const O=Xn(V),L=Xn(uS),W=Xn(mS),B=Xn(pS),ne=Xn(fS);let le;t[12]!==o?(le=X=>o?X.contextPanelByDirectory[o]?.tabs??M:M,t[12]=o,t[13]=le):le=t[13];const ee=Te(le);let ae;t[14]!==ee?(ae=new Set(ee.map(hS).filter(gS).map(xS)),t[14]=ee,t[15]=ae):ae=t[15];const ge=ae,[te,E]=l.useState(null),[z,J]=l.useState(null),[H,re]=l.useState(null),[ce,Ne]=l.useState(""),[me,we]=l.useState(!1),_=!!n.writeFile,ue=!!n.createDirectory,Q=!!n.rename,oe=!!n.delete,Z=!!n.revealPath;let Ie;t[16]!==_||t[17]!==ue||t[18]!==oe||t[19]!==Q||t[20]!==Z?(Ie={canRename:Q,canCreateFile:_,canCreateFolder:ue,canDelete:oe,canReveal:Z},t[16]=_,t[17]=ue,t[18]=oe,t[19]=Q,t[20]=Z,t[21]=Ie):Ie=t[21];const Se=Ie;let Y;t[22]!==n||t[23]!==e?(Y=X=>{n.revealPath&&n.revealPath(X).catch(()=>{q.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=(X,pt)=>{J(X),re(pt),Ne(X==="rename"&&pt.name||""),we(!1)},t[25]=ke):ke=t[25];const xe=ke;let he;t[26]!==d||t[27]!==c?(he=(X,pt)=>{const wt=pt.filter(bS).filter(zt=>c||!zt.name.startsWith(".")).filter(zt=>d||!rS(zt.name)).map(zt=>{const ss=zt.name,os=Yn(zt.path||""),Ps=os?sS(os)?os:Yn(`${X}/${os}`):Yn(`${X}/${ss}`),Ms=zt.isDirectory?"directory":"file",We=Ms==="file"&&ss.includes(".")?ss.split(".").pop()?.toLowerCase():void 0;return{name:ss,path:Ps,type:Ms,extension:We}});return tS(wt)},t[26]=d,t[27]=c,t[28]=he):he=t[28];const Pe=he;let Be;t[29]!==n||t[30]!==Pe||t[31]!==r.isDesktop||t[32]!==d?(Be=async X=>{const pt=Yn(X.trim());if(!pt||R.current.has(pt)||P.current.has(pt))return;P.current=new Set(P.current),P.current.add(pt);const wt=!d;await(r.isDesktop?n.listDirectory(pt,{respectGitignore:wt}).then(vS):Dn.listLocalDirectory(pt,{respectGitignore:wt}).then(jS)).then(ss=>{const os=Pe(pt,ss);R.current=new Set(R.current),R.current.add(pt),C(Ps=>({...Ps,[pt]:os}))}).catch(()=>{C(ss=>({...ss,[pt]:ss[pt]??[]}))}).finally(()=>{P.current=new Set(P.current),P.current.delete(pt)})},t[29]=n,t[30]=Pe,t[31]=r.isDesktop,t[32]=d,t[33]=Be):Be=t[33];const G=Be;let be;t[34]!==G||t[35]!==o?(be=async()=>{o&&(R.current=new Set,P.current=new Set,C(NS),await G(o))},t[34]=G,t[35]=o,t[36]=be):be=t[36];const De=be;let Ae;t[37]!==G||t[38]!==De?(Ae=async X=>{if(!X){await De();return}const pt=Yn(X);R.current=new Set(R.current),R.current.delete(pt),P.current=new Set(P.current),P.current.delete(pt),await G(pt)},t[37]=G,t[38]=De,t[39]=Ae):Ae=t[39];const ve=Ae;let U;t[40]!==G||t[41]!==o?(U=()=>{o&&(R.current=new Set,P.current=new Set,C(SS),G(o))},t[40]=G,t[41]=o,t[42]=U):U=t[42];let de;t[43]!==G||t[44]!==o||t[45]!==d||t[46]!==c?(de=[G,o,c,d],t[43]=G,t[44]=o,t[45]=d,t[46]=c,t[47]=de):de=t[47],l.useEffect(U,de);let Re,Le;t[48]!==F||t[49]!==G||t[50]!==o?(Re=()=>{if(!o||F.length===0)return;const X=F.map(kS).filter(wt=>!!wt&&wt!==o&&wt.startsWith(`${o}/`)&&!R.current.has(wt)&&!P.current.has(wt)).sort(CS);if(X.length===0)return;let pt=!1;return(async()=>{for(let wt=0;wt<X.length&&!pt;wt=wt+3,wt){const zt=X.slice(wt,wt+3);await Promise.all(zt.map(ss=>G(ss)))}})(),()=>{pt=!0}},Le=[F,G,o],t[48]=F,t[49]=G,t[50]=o,t[51]=Re,t[52]=Le):(Re=t[51],Le=t[52]),l.useEffect(Re,Le);let se,ie;t[53]!==a||t[54]!==f||t[55]!==p||t[56]!==d||t[57]!==c?(se=()=>{if(!a){w([]),S(!1);return}const X=f.trim();if(!X){w([]),S(!1);return}let pt=!1;return S(!0),p(a,X,150,{includeHidden:c,respectGitignore:!d,type:"file"}).then(wt=>{if(pt)return;const ss=wt.filter(os=>d||!aS(os.path)).map(IS);w(ss)}).catch(()=>{pt||w([])}).finally(()=>{pt||S(!1)}),()=>{pt=!0}},ie=[a,f,p,c,d],t[53]=a,t[54]=f,t[55]=p,t[56]=d,t[57]=c,t[58]=se,t[59]=ie):(se=t[58],ie=t[59]),l.useEffect(se,ie);let K;t[60]!==u||t[61]!==ge||t[62]!==o?(K=X=>{if(ge.has(X))return"open";if(u?.files){const pt=X.startsWith(o+"/")?X.slice(o.length+1):X,wt=u.files.find(zt=>zt.path===pt);if(wt){if(wt.index==="A"||wt.working_dir==="?")return"git-added";if(wt.index==="D")return"git-deleted";if(wt.index==="M"||wt.working_dir==="M")return"git-modified"}}return null},t[60]=u,t[61]=ge,t[62]=o,t[63]=K):K=t[63];const _e=K;let He;t[64]!==u||t[65]!==o?(He=X=>{if(!u?.files)return null;const pt=X.startsWith(o+"/")?X.slice(o.length+1):X,wt=pt?`${pt}/`:"";let zt=0,ss=0;for(const os of u.files)os.path.startsWith(wt)&&((os.index==="M"||os.working_dir==="M")&&zt++,(os.index==="A"||os.working_dir==="?")&&ss++);return zt+ss>0?{modified:zt,added:ss}:null},t[64]=u,t[65]=o,t[66]=He):He=t[66];const Ke=He;let Ze;t[67]!==W||t[68]!==n||t[69]!==m||t[70]!==o||t[71]!==L?(Ze=async X=>{if(!o)return;const pt=await Hu(n,X.path);if(!pt.ok){q.error(Gu(pt.reason));return}L(o,X.path),W(o,X.path),m(o,X.path)},t[67]=W,t[68]=n,t[69]=m,t[70]=o,t[71]=L,t[72]=Ze):Ze=t[72];const Xe=Ze;let mt;t[73]!==G||t[74]!==o||t[75]!==ne?(mt=async X=>{const pt=Yn(X);o&&(ne(o,pt),R.current.has(pt)||await G(pt))},t[73]=G,t[74]=o,t[75]=ne,t[76]=mt):mt=t[76];const et=mt;let ct;t[77]!==z||t[78]!==H||t[79]!==ce||t[80]!==n||t[81]!==ve||t[82]!==B||t[83]!==o||t[84]!==O||t[85]!==L||t[86]!==e?(ct=async X=>{if(X?.preventDefault(),!H||!z)return;we(!0);const pt=()=>we(!1),wt=()=>J(null);if(z==="createFile"){if(!ce.trim()){q.error(e("sidebarFilesTree.toast.filenameRequired")),pt();return}if(!n.writeFile){q.error(e("sidebarFilesTree.toast.writeNotSupported")),pt();return}const zt=H.path,ss=zt?`${zt}/`:"",os=Yn(`${ss}${ce.trim()}`);await n.writeFile(os,"").then(async Ps=>{Ps.success&&(q.success(e("sidebarFilesTree.toast.fileCreated")),await ve(zt)),wt()}).catch(()=>q.error(e("sidebarFilesTree.toast.operationFailed"))).finally(pt);return}if(z==="createFolder"){if(!ce.trim()){q.error(e("sidebarFilesTree.toast.folderNameRequired")),pt();return}const zt=H.path,ss=zt?`${zt}/`:"",os=Yn(`${ss}${ce.trim()}`);await n.createDirectory(os).then(async Ps=>{Ps.success&&(q.success(e("sidebarFilesTree.toast.folderCreated")),await ve(zt)),wt()}).catch(()=>q.error(e("sidebarFilesTree.toast.operationFailed"))).finally(pt);return}if(z==="rename"){if(!ce.trim()){q.error(e("sidebarFilesTree.toast.nameRequired")),pt();return}if(!n.rename){q.error(e("sidebarFilesTree.toast.renameNotSupported")),pt();return}const zt=H.path,ss=zt.split("/").slice(0,-1).join("/"),os=ss?`${ss}/`:"",Ps=Yn(`${os}${ce.trim()}`);await n.rename(zt,Ps).then(async Ms=>{Ms.success&&(q.success(e("sidebarFilesTree.toast.renamedSuccessfully")),await ve(ss),o&&B(o,zt),(O===zt||O&&O.startsWith(`${zt}/`))&&L(o,null)),wt()}).catch(()=>q.error(e("sidebarFilesTree.toast.operationFailed"))).finally(pt);return}if(z==="delete"){if(!n.delete){q.error(e("sidebarFilesTree.toast.deleteNotSupported")),pt();return}const zt=H.path,ss=zt.split("/").slice(0,-1).join("/");await n.delete(zt).then(async os=>{os.success&&(q.success(e("sidebarFilesTree.toast.deletedSuccessfully")),await ve(ss),o&&B(o,zt),(O===zt||O&&O.startsWith(zt+"/"))&&L(o,null)),wt()}).catch(()=>q.error(e("sidebarFilesTree.toast.operationFailed"))).finally(pt);return}pt()},t[77]=z,t[78]=H,t[79]=ce,t[80]=n,t[81]=ve,t[82]=B,t[83]=o,t[84]=O,t[85]=L,t[86]=e,t[87]=ct):ct=t[87];const lt=ct;let ye,Ge,$e,Ve,tt,Qe,ze;if(t[88]!==_||t[89]!==ue||t[90]!==j||t[91]!==te||t[92]!==a||t[93]!==F||t[94]!==Se||t[95]!==n.downloadFile||t[96]!==_e||t[97]!==Ke||t[98]!==Xe||t[99]!==fe||t[100]!==De||t[101]!==o||t[102]!==h||t[103]!==g||t[104]!==v||t[105]!==O||t[106]!==e||t[107]!==et){let X=function(Lt,ls){const rs=j[Lt]??[];return rs.map((Bt,xs)=>{const mn=Bt.type==="directory",js=mn&&F.includes(Bt.path),xn=O===Bt.path,In=xs===rs.length-1;return s.jsxs("li",{className:"relative",children:[ls>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),In&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-sidebar/50"})]}),s.jsx(oS,{node:Bt,root:o,isExpanded:js,isActive:xn,status:mn?void 0:_e(Bt.path),badge:mn?Ke(Bt.path):void 0,permissions:Se,downloadFile:n.downloadFile,contextMenuPath:te,setContextMenuPath:E,onSelect:Xe,onToggle:et,onRevealPath:fe,onOpenDialog:xe}),mn&&js&&s.jsx("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:X(Bt.path,ls+1)})]},Bt.path)})};const pt=!!(o&&j[o]);Qe="flex h-full min-h-0 flex-col overflow-hidden bg-sidebar";let wt;t[115]===Symbol.for("react.memo_cache_sentinel")?(wt=s.jsx(Hn,{className:"pointer-events-none absolute left-2 top-2 h-4 w-4 text-muted-foreground"}),t[115]=wt):wt=t[115];let zt;t[116]===Symbol.for("react.memo_cache_sentinel")?(zt=Lt=>b(Lt.target.value),t[116]=zt):zt=t[116];let ss;t[117]!==e?(ss=e("sidebarFilesTree.search.placeholder"),t[117]=e,t[118]=ss):ss=t[118];let os;t[119]!==h||t[120]!==ss?(os=s.jsx(Vt,{ref:y,value:h,onChange:zt,placeholder:ss,className:"h-8 pl-8 pr-8 typography-meta"}),t[119]=h,t[120]=ss,t[121]=os):os=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(""),y.current?.focus()},children:s.jsx(Ds,{className:"h-4 w-4"})}):null,t[122]=h,t[123]=e,t[124]=Ps):Ps=t[124];let Ms;t[125]!==os||t[126]!==Ps?(Ms=s.jsxs("div",{className:"relative min-w-0 flex-1",children:[wt,os,Ps]}),t[125]=os,t[126]=Ps,t[127]=Ms):Ms=t[127];let We;t[128]!==_||t[129]!==a||t[130]!==e?(We=_&&s.jsx(je,{variant:"ghost",size:"sm",onClick:()=>xe("createFile",{path:a,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:e("sidebarFilesTree.actions.newFileTitle"),children:s.jsx(mc,{className:"h-4 w-4"})}),t[128]=_,t[129]=a,t[130]=e,t[131]=We):We=t[131];let gt;t[132]!==ue||t[133]!==a||t[134]!==e?(gt=ue&&s.jsx(je,{variant:"ghost",size:"sm",onClick:()=>xe("createFolder",{path:a,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:e("sidebarFilesTree.actions.newFolderTitle"),children:s.jsx(Ca,{className:"h-4 w-4"})}),t[132]=ue,t[133]=a,t[134]=e,t[135]=gt):gt=t[135];let Mt;t[136]!==De?(Mt=()=>{De()},t[136]=De,t[137]=Mt):Mt=t[137];let Et;t[138]!==e?(Et=e("sidebarFilesTree.actions.refreshTitle"),t[138]=e,t[139]=Et):Et=t[139];let as;t[140]===Symbol.for("react.memo_cache_sentinel")?(as=s.jsx(Nn,{className:"h-4 w-4"}),t[140]=as):as=t[140];let st;t[141]!==Mt||t[142]!==Et?(st=s.jsx(je,{variant:"ghost",size:"sm",onClick:Mt,className:"h-8 w-8 p-0 flex-shrink-0",title:Et,children:as}),t[141]=Mt,t[142]=Et,t[143]=st):st=t[143],t[144]!==Ms||t[145]!==We||t[146]!==gt||t[147]!==st?(ze=s.jsxs("div",{className:"flex items-center gap-2 border-b border-border/40 px-3 py-2",children:[Ms,We,gt,st]}),t[144]=Ms,t[145]=We,t[146]=gt,t[147]=st,t[148]=ze):ze=t[148],ye=Es,Ve="flex-1 min-h-0",tt="p-2",Ge="flex flex-col",$e=v?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(Zt,{className:"h-4 w-4 animate-spin"}),e("sidebarFilesTree.state.searching")]}):g.length>0?g.map(Lt=>{const ls=O===Lt.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>Xe(Lt),draggable:!0,onDragStart:rs=>{const Bt=Lt.relativePath||cx(o??"",Lt.path);!Bt||Bt==="."||(rs.dataTransfer.setData("application/x-openchamber-file-path",Bt),rs.dataTransfer.effectAllowed="copy")},className:pe("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",ls?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),title:Lt.path,children:[dx(Lt.path,Lt.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},children:Lt.relativePath??Lt.path})]})},Lt.path)}):pt&&o?X(o,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:e("sidebarFilesTree.state.loading")}),t[88]=_,t[89]=ue,t[90]=j,t[91]=te,t[92]=a,t[93]=F,t[94]=Se,t[95]=n.downloadFile,t[96]=_e,t[97]=Ke,t[98]=Xe,t[99]=fe,t[100]=De,t[101]=o,t[102]=h,t[103]=g,t[104]=v,t[105]=O,t[106]=e,t[107]=et,t[108]=ye,t[109]=Ge,t[110]=$e,t[111]=Ve,t[112]=tt,t[113]=Qe,t[114]=ze}else ye=t[108],Ge=t[109],$e=t[110],Ve=t[111],tt=t[112],Qe=t[113],ze=t[114];let ht;t[149]!==Ge||t[150]!==$e?(ht=s.jsx("ul",{className:Ge,children:$e}),t[149]=Ge,t[150]=$e,t[151]=ht):ht=t[151];let _t;t[152]!==ye||t[153]!==Ve||t[154]!==tt||t[155]!==ht?(_t=s.jsx(ye,{outerClassName:Ve,className:tt,children:ht}),t[152]=ye,t[153]=Ve,t[154]=tt,t[155]=ht,t[156]=_t):_t=t[156];const Kt=!!z;let Ut;t[157]===Symbol.for("react.memo_cache_sentinel")?(Ut=X=>!X&&J(null),t[157]=Ut):Ut=t[157];let jt;t[158]!==z||t[159]!==e?(jt=z==="createFile"&&e("sidebarFilesTree.dialog.createFile.title"),t[158]=z,t[159]=e,t[160]=jt):jt=t[160];let Dt;t[161]!==z||t[162]!==e?(Dt=z==="createFolder"&&e("sidebarFilesTree.dialog.createFolder.title"),t[161]=z,t[162]=e,t[163]=Dt):Dt=t[163];let ts;t[164]!==z||t[165]!==e?(ts=z==="rename"&&e("sidebarFilesTree.dialog.rename.title"),t[164]=z,t[165]=e,t[166]=ts):ts=t[166];let it;t[167]!==z||t[168]!==e?(it=z==="delete"&&e("sidebarFilesTree.dialog.delete.title"),t[167]=z,t[168]=e,t[169]=it):it=t[169];let Yt;t[170]!==jt||t[171]!==Dt||t[172]!==ts||t[173]!==it?(Yt=s.jsxs(Ss,{children:[jt,Dt,ts,it]}),t[170]=jt,t[171]=Dt,t[172]=ts,t[173]=it,t[174]=Yt):Yt=t[174];let Qt;t[175]!==z||t[176]!==H?.path||t[177]!==e?(Qt=z==="createFile"&&e("sidebarFilesTree.dialog.createFile.description",{path:H?.path??e("sidebarFilesTree.dialog.rootFallback")}),t[175]=z,t[176]=H?.path,t[177]=e,t[178]=Qt):Qt=t[178];let Xt;t[179]!==z||t[180]!==H?.path||t[181]!==e?(Xt=z==="createFolder"&&e("sidebarFilesTree.dialog.createFolder.description",{path:H?.path??e("sidebarFilesTree.dialog.rootFallback")}),t[179]=z,t[180]=H?.path,t[181]=e,t[182]=Xt):Xt=t[182];let us;t[183]!==z||t[184]!==H?.name||t[185]!==e?(us=z==="rename"&&e("sidebarFilesTree.dialog.rename.description",{name:H?.name??""}),t[183]=z,t[184]=H?.name,t[185]=e,t[186]=us):us=t[186];let ms;t[187]!==z||t[188]!==H?.name||t[189]!==e?(ms=z==="delete"&&e("sidebarFilesTree.dialog.delete.description",{name:H?.name??""}),t[187]=z,t[188]=H?.name,t[189]=e,t[190]=ms):ms=t[190];let gs;t[191]!==Qt||t[192]!==Xt||t[193]!==us||t[194]!==ms?(gs=s.jsxs(Os,{children:[Qt,Xt,us,ms]}),t[191]=Qt,t[192]=Xt,t[193]=us,t[194]=ms,t[195]=gs):gs=t[195];let ds;t[196]!==Yt||t[197]!==gs?(ds=s.jsxs(Is,{children:[Yt,gs]}),t[196]=Yt,t[197]=gs,t[198]=ds):ds=t[198];let Ft;t[199]!==z||t[200]!==ce||t[201]!==lt||t[202]!==e?(Ft=z!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(Vt,{value:ce,onChange:X=>Ne(X.target.value),placeholder:e(z==="rename"?"sidebarFilesTree.dialog.rename.placeholder":"sidebarFilesTree.dialog.namePlaceholder"),onKeyDown:X=>{X.key==="Enter"&&lt()},autoFocus:!0})}),t[199]=z,t[200]=ce,t[201]=lt,t[202]=e,t[203]=Ft):Ft=t[203];let Ue;t[204]===Symbol.for("react.memo_cache_sentinel")?(Ue=()=>J(null),t[204]=Ue):Ue=t[204];let Tt;t[205]!==e?(Tt=e("sidebarFilesTree.dialog.cancel"),t[205]=e,t[206]=Tt):Tt=t[206];let At;t[207]!==me||t[208]!==Tt?(At=s.jsx(je,{variant:"outline",onClick:Ue,disabled:me,children:Tt}),t[207]=me,t[208]=Tt,t[209]=At):At=t[209];const vt=z==="delete"?"destructive":"default";let Rt;t[210]!==lt?(Rt=()=>{lt()},t[210]=lt,t[211]=Rt):Rt=t[211];let ns;t[212]!==z||t[213]!==ce||t[214]!==me?(ns=me||z!=="delete"&&!ce.trim(),t[212]=z,t[213]=ce,t[214]=me,t[215]=ns):ns=t[215];let As;t[216]!==z||t[217]!==me||t[218]!==e?(As=me?s.jsx(Zt,{className:"animate-spin"}):e(z==="delete"?"sidebarFilesTree.dialog.delete.confirm":"sidebarFilesTree.dialog.confirm"),t[216]=z,t[217]=me,t[218]=e,t[219]=As):As=t[219];let ft;t[220]!==vt||t[221]!==Rt||t[222]!==ns||t[223]!==As?(ft=s.jsx(je,{variant:vt,onClick:Rt,disabled:ns,children:As}),t[220]=vt,t[221]=Rt,t[222]=ns,t[223]=As,t[224]=ft):ft=t[224];let is;t[225]!==At||t[226]!==ft?(is=s.jsxs(Qs,{children:[At,ft]}),t[225]=At,t[226]=ft,t[227]=is):is=t[227];let es;t[228]!==ds||t[229]!==Ft||t[230]!==is?(es=s.jsxs(vs,{children:[ds,Ft,is]}),t[228]=ds,t[229]=Ft,t[230]=is,t[231]=es):es=t[231];let Ts;t[232]!==Kt||t[233]!==es?(Ts=s.jsx(ws,{open:Kt,onOpenChange:Ut,children:es}),t[232]=Kt,t[233]=es,t[234]=Ts):Ts=t[234];let Ls;return t[235]!==Qe||t[236]!==ze||t[237]!==_t||t[238]!==Ts?(Ls=s.jsxs("section",{className:Qe,children:[ze,_t,Ts]}),t[235]=Qe,t[236]=ze,t[237]=_t,t[238]=Ts,t[239]=Ls):Ls=t[239],Ls};function cS(t){return t.searchFiles}function dS(t){return t.openContextFile}function uS(t){return t.setSelectedPath}function mS(t){return t.addOpenPath}function pS(t){return t.removeOpenPathsByPrefix}function fS(t){return t.toggleExpandedPath}function hS(t){return t.mode==="file"?t.targetPath:null}function gS(t){return typeof t=="string"&&t.length>0}function xS(t){return Yn(t)}function bS(t){return t&&typeof t.name=="string"&&t.name.length>0}function yS(t){return{name:t.name,path:t.path,isDirectory:t.isDirectory}}function vS(t){return t.entries.map(yS)}function wS(t){return{name:t.name,path:t.path,isDirectory:t.isDirectory}}function jS(t){return t.map(wS)}function NS(t){return Object.keys(t).length===0?t:{}}function SS(t){return Object.keys(t).length===0?t:{}}function kS(t){return Yn(t)}function CS(t,e){return t.split("/").length-e.split("/").length}function IS(t){return{name:t.name,path:Yn(t.path),type:"file",extension:t.extension,relativePath:t.relativePath}}function AS(t,e){const n=nt.c(6),{git:r}=Gn(),a=pn(PS);let i,o;n[0]!==t||n[1]!==a||n[2]!==r||n[3]!==e?(i=()=>{if(!t||!r||!e)return;a(t,r);const c=setInterval(()=>{typeof document<"u"&&document.hidden||a(t,r)},1e4);return()=>clearInterval(c)},o=[t,r,e,a],n[0]=t,n[1]=a,n[2]=r,n[3]=e,n[4]=i,n[5]=o):(i=n[4],o=n[5]),l.useEffect(i,o)}function PS(t){return t.ensureStatus}const DS=()=>{const t=nt.c(17),e=Fs(MS),n=Fs(RS),r=Ws(ES),a=pn(FS);let i;e:{if(e){let f;t[0]!==e||t[1]!==n?(f=n.find(y=>y.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()||ii(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(Y0,{projectRef:d,projectLabel:m,canCreateWorktree:h})}),t[13]=h,t[14]=m,t[15]=d,t[16]=b):b=t[16],b},TS=()=>{const t=nt.c(38),{t:e}=ut(),n=Te(OS),r=Te(LS),a=Te($S),i=Xr();AS(i,a);let o;t[0]!==e?(o=e("layout.rightSidebar.git"),t[0]=e,t[1]=o):o=t[1];let c;t[2]===Symbol.for("react.memo_cache_sentinel")?(c=s.jsx(Ks,{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(Fb,{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(Ob,{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 y;t[15]!==d||t[16]!==u||t[17]!==f?(y=[d,u,f],t[15]=d,t[16]=u,t[17]=f,t[18]=y):y=t[18];const x=y;let g;t[19]!==r?(g=I=>r(I),t[19]=r,t[20]=g):g=t[20];let w;t[21]!==n||t[22]!==g||t[23]!==x?(w=s.jsx("div",{className:"h-9 bg-sidebar pt-1 px-2",children:s.jsx(Br,{items:x,activeId:n,onSelect:g,layoutMode:"fit",variant:"active-pill",className:"h-full"})}),t[21]=n,t[22]=g,t[23]=x,t[24]=w):w=t[24];let v;t[25]!==n?(v=n==="git"&&s.jsx(lx,{}),t[25]=n,t[26]=v):v=t[26];let S;t[27]!==n?(S=n==="files"&&s.jsx(lS,{}),t[27]=n,t[28]=S):S=t[28];let A;t[29]!==n?(A=n==="context"&&s.jsx(DS,{}),t[29]=n,t[30]=A):A=t[30];let j;t[31]!==v||t[32]!==S||t[33]!==A?(j=s.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden",children:[v,S,A]}),t[31]=v,t[32]=S,t[33]=A,t[34]=j):j=t[34];let C;return t[35]!==w||t[36]!==j?(C=s.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden bg-sidebar",children:[w,j]}),t[35]=w,t[36]=j,t[37]=C):C=t[37],C};function MS(t){return t.activeProjectId}function RS(t){return t.projects}function ES(t){return t.homeDirectory}function FS(t){return t.directories}function OS(t){return t.rightSidebarTab}function LS(t){return t.setRightSidebarTab}function $S(t){return t.isRightSidebarOpen}function ux(t){const e=nt.c(63),{draft:n,onEdit:r,onDelete:a,className:i,maxWidth:o}=t,{t:c}=ut(),p=yc()?.currentTheme,[m,u]=Oe.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 y;e[2]!==i?(y=pe("rounded-lg border shadow-none w-full max-w-[min(100%,calc(var(--oc-context-panel-width,100vw)-var(--oc-editor-gutter-width,0px)))] overflow-hidden transition-all duration-200",i),e[2]=i,e[3]=y):y=e[3];const x=p?.colors?.surface?.elevated,g=p?.colors?.interactive?.border,w=o?`${Math.max(200,Math.floor(o))}px`:void 0;let v;e[4]!==x||e[5]!==g||e[6]!==w?(v={backgroundColor:x,borderColor:g,maxWidth:w},e[4]=x,e[5]=g,e[6]=w,e[7]=v):v=e[7];let S;e[8]!==n.fileLabel?(S=s.jsx("span",{className:"truncate max-w-[200px]",title:n.fileLabel,children:n.fileLabel}),e[8]=n.fileLabel,e[9]=S):S=e[9];let A;e[10]===Symbol.for("react.memo_cache_sentinel")?(A=s.jsx("span",{children:"•"}),e[10]=A):A=e[10];let j;e[11]!==n.endLine||e[12]!==n.startLine||e[13]!==c?(j=c("inlineComment.range.lines",{start:n.startLine,end:n.endLine}),e[11]=n.endLine,e[12]=n.startLine,e[13]=c,e[14]=j):j=e[14];let C;e[15]!==j?(C=s.jsx("span",{children:j}),e[15]=j,e[16]=C):C=e[16];let I;e[17]!==n.side?(I=n.side&&s.jsxs("span",{children:["(",n.side,")"]}),e[17]=n.side,e[18]=I):I=e[18];let R;e[19]!==C||e[20]!==I||e[21]!==S?(R=s.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground mb-1.5",children:[S,A,C,I]}),e[19]=C,e[20]=I,e[21]=S,e[22]=R):R=e[22];const k=m||!f,P=!m&&f&&"line-clamp-3";let N;e[23]!==P?(N=pe("text-sm whitespace-pre-wrap break-words leading-relaxed",P),e[23]=P,e[24]=N):N=e[24];let D;e[25]!==h||e[26]!==N?(D=s.jsx("div",{className:N,children:h}),e[25]=h,e[26]=N,e[27]=D):D=e[27];let T;e[28]!==f||e[29]!==m||e[30]!==c?(T=f&&s.jsx(Mr,{asChild:!0,children:s.jsx(je,{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(Cu,{className:"size-3 mr-1"}),c("inlineComment.actions.showLess")]}):s.jsxs(s.Fragment,{children:[s.jsx(Cs,{className:"size-3 mr-1"}),c("inlineComment.actions.showMore")]})})}),e[28]=f,e[29]=m,e[30]=c,e[31]=T):T=e[31];let M;e[32]===Symbol.for("react.memo_cache_sentinel")?(M=s.jsx(vr,{}),e[32]=M):M=e[32];let $;e[33]!==k||e[34]!==D||e[35]!==T?($=s.jsxs(yr,{open:k,onOpenChange:u,children:[D,T,M]}),e[33]=k,e[34]=D,e[35]=T,e[36]=$):$=e[36];let F;e[37]!==R||e[38]!==$?(F=s.jsxs("div",{className:"flex-1 min-w-0",children:[R,$]}),e[37]=R,e[38]=$,e[39]=F):F=e[39];let V;e[40]===Symbol.for("react.memo_cache_sentinel")?(V=s.jsx(Bs,{asChild:!0,children:s.jsx(je,{variant:"ghost",size:"icon",className:"h-6 w-6 -mr-1 text-muted-foreground hover:text-foreground",children:s.jsx(Lb,{className:"size-4"})})}),e[40]=V):V=e[40];let O;e[41]===Symbol.for("react.memo_cache_sentinel")?(O=s.jsx(Yr,{className:"size-4 mr-2"}),e[41]=O):O=e[41];let L;e[42]!==c?(L=c("inlineComment.actions.editComment"),e[42]=c,e[43]=L):L=e[43];let W;e[44]!==r||e[45]!==L?(W=s.jsxs($t,{onClick:r,children:[O,L]}),e[44]=r,e[45]=L,e[46]=W):W=e[46];let B;e[47]===Symbol.for("react.memo_cache_sentinel")?(B=s.jsx(sn,{className:"size-4 mr-2"}),e[47]=B):B=e[47];let ne;e[48]!==c?(ne=c("inlineComment.actions.deleteComment"),e[48]=c,e[49]=ne):ne=e[49];let le;e[50]!==a||e[51]!==ne?(le=s.jsxs($t,{onClick:a,className:"text-destructive",children:[B,ne]}),e[50]=a,e[51]=ne,e[52]=le):le=e[52];let ee;e[53]!==W||e[54]!==le?(ee=s.jsxs(zs,{children:[V,s.jsxs(Vs,{align:"end",children:[W,le]})]}),e[53]=W,e[54]=le,e[55]=ee):ee=e[55];let ae;e[56]!==F||e[57]!==ee?(ae=s.jsxs("div",{className:"flex items-start justify-between gap-2 p-3",children:[F,ee]}),e[56]=F,e[57]=ee,e[58]=ae):ae=e[58];let ge;return e[59]!==y||e[60]!==ae||e[61]!==v?(ge=s.jsx("div",{className:y,style:v,"data-comment-card":"true",children:ae}),e[59]=y,e[60]=ae,e[61]=v,e[62]=ge):ge=e[62],ge}function tc(t){const e=nt.c(57),{initialText:n,onSave:r,onCancel:a,fileLabel:i,lineRange:o,isEditing:c,className:d,maxWidth:p}=t,m=n===void 0?"":n,u=c===void 0?!1:c,{t:h}=ut(),f=yc()?.currentTheme,{isMobile:y}=un(),[x,g]=l.useState(m),w=Oe.useRef(null),v=Oe.useRef(o);let S,A;e[0]!==o?(S=()=>{o&&(v.current=o)},A=[o],e[0]=o,e[1]=S,e[2]=A):(S=e[1],A=e[2]),Oe.useEffect(S,A);const j=KS,C=j(o);let I,R;e[3]!==y?(I=()=>{const ue=w.current;if(!ue)return;const Q=ue.closest(".overlay-scrollbar-container"),oe=Q?.scrollTop??window.scrollY,Z=Q?.scrollLeft??window.scrollX;if(y){ue.scrollIntoView({behavior:"auto",block:"nearest"});try{ue.focus({preventScroll:!0})}catch{ue.focus()}return}try{ue.focus({preventScroll:!0})}catch{ue.focus()}const Ie=ue.value.length;try{ue.setSelectionRange(Ie,Ie)}catch{}requestAnimationFrame(()=>{Q?(Q.scrollTop=oe,Q.scrollLeft=Z):window.scrollTo({top:oe,left:Z})})},R=[y],e[3]=y,e[4]=I,e[5]=R):(I=e[4],R=e[5]),Oe.useEffect(I,R);let k;e[6]!==a||e[7]!==r||e[8]!==x?(k=ue=>{(ue.metaKey||ue.ctrlKey)&&ue.key==="Enter"?(ue.preventDefault(),x.trim()&&r(x,j(v.current))):ue.key==="Escape"&&(ue.preventDefault(),a())},e[6]=a,e[7]=r,e[8]=x,e[9]=k):k=e[9];const P=k;let N;e[10]!==r||e[11]!==x?(N=ue=>{ue.stopPropagation(),x.trim()&&r(x,j(v.current))},e[10]=r,e[11]=x,e[12]=N):N=e[12];const D=N;let T;e[13]!==d?(T=pe("rounded-lg border shadow-none w-full max-w-[min(100%,calc(var(--oc-context-panel-width,100vw)-var(--oc-editor-gutter-width,0px)))] overflow-hidden animate-in fade-in zoom-in-95 duration-200",d),e[13]=d,e[14]=T):T=e[14];const M=f?.colors?.surface?.elevated,$=f?.colors?.interactive?.border,F=p?`${Math.max(200,Math.floor(p))}px`:void 0;let V;e[15]!==M||e[16]!==$||e[17]!==F?(V={backgroundColor:M,borderColor:$,maxWidth:F},e[15]=M,e[16]=$,e[17]=F,e[18]=V):V=e[18];const O="true",L=WS,W=US,B="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:"•"}),C&&s.jsx("span",{children:h("inlineComment.range.lines",{start:C.start,end:C.end})})]});let le;e[19]===Symbol.for("react.memo_cache_sentinel")?(le=ue=>g(ue.target.value),e[19]=le):le=e[19];let ee;e[20]!==h?(ee=h("inlineComment.input.placeholder"),e[20]=h,e[21]=ee):ee=e[21];let ae;e[22]!==P||e[23]!==ee||e[24]!==x?(ae=s.jsx(Sn,{simple:!0,ref:w,value:x,onChange:le,onKeyDown:P,placeholder:ee,outerClassName:"rounded-[var(--radius-xl)] bg-[var(--surface-subtle)] ring-1 ring-inset ring-border/60 focus-within:ring-2 focus-within:ring-[var(--interactive-focus-ring)]",className:"min-h-[80px] px-3 py-2.5 text-sm resize-y"}),e[22]=P,e[23]=ee,e[24]=x,e[25]=ae):ae=e[25];let ge;e[26]!==h?(ge=h("inlineComment.actions.cancel"),e[26]=h,e[27]=ge):ge=e[27];let te;e[28]!==a||e[29]!==ge?(te=s.jsx(je,{variant:"ghost",size:"sm",onClick:a,onPointerDown:_S,onTouchStart:zS,className:"h-8 text-muted-foreground hover:text-foreground",children:ge}),e[28]=a,e[29]=ge,e[30]=te):te=e[30];let E;e[31]!==x?(E=x.trim(),e[31]=x,e[32]=E):E=e[32];const z=!E,J=f?.colors?.status?.success,H=f?.colors?.status?.successForeground;let re;e[33]!==J||e[34]!==H?(re={backgroundColor:J,color:H},e[33]=J,e[34]=H,e[35]=re):re=e[35];let ce;e[36]!==u||e[37]!==h?(ce=h(u?"inlineComment.actions.save":"inlineComment.actions.comment"),e[36]=u,e[37]=h,e[38]=ce):ce=e[38];let Ne;e[39]!==D||e[40]!==z||e[41]!==re||e[42]!==ce?(Ne=s.jsx(je,{size:"sm",onClick:D,onPointerDown:VS,onTouchStart:BS,disabled:z,className:"h-8 min-w-[80px]",style:re,children:ce}),e[39]=D,e[40]=z,e[41]=re,e[42]=ce,e[43]=Ne):Ne=e[43];let me;e[44]!==te||e[45]!==Ne?(me=s.jsxs("div",{className:"flex items-center justify-end gap-2 mt-3",children:[te,Ne]}),e[44]=te,e[45]=Ne,e[46]=me):me=e[46];let we;e[47]!==ne||e[48]!==ae||e[49]!==me?(we=s.jsxs("div",{className:B,children:[ne,ae,me]}),e[47]=ne,e[48]=ae,e[49]=me,e[50]=we):we=e[50];let _;return e[51]!==V||e[52]!==L||e[53]!==W||e[54]!==we||e[55]!==T?(_=s.jsx("div",{className:T,style:V,"data-comment-input":O,onPointerDown:L,onTouchStart:W,children:we}),e[51]=V,e[52]=L,e[53]=W,e[54]=we,e[55]=T,e[56]=_):_=e[56],_}function BS(t){return t.stopPropagation()}function VS(t){return t.stopPropagation()}function zS(t){return t.stopPropagation()}function _S(t){return t.stopPropagation()}function US(t){return t.stopPropagation()}function WS(t){return t.stopPropagation()}function KS(t){if(!t)return;const e=Math.min(t.start,t.end),n=Math.max(t.start,t.end);return{...t,start:e,end:n}}const HS=t=>{const e=Math.min(t.startLine,t.endLine),n=Math.max(t.startLine,t.endLine);return{...t,startLine:e,endLine:n}},sc=t=>{const e=Math.min(t.start,t.end),n=Math.max(t.start,t.end);return{...t,start:e,end:n}};function qu(t){const e=nt.c(40),{t:n}=ut(),{source:r,fileLabel:a,language:i,getCodeForRange:o,toStoreRange:c,fromDraftRange:d}=t,p=Wt(XS),m=Wt(YS),u=ho(JS),h=ho(QS),b=ho(qS),f=ho(GS),[y,x]=l.useState(null),[g,w]=l.useState(""),[v,S]=l.useState(null),A=p??(m?"draft":null);let j;e:{if(!A||!a){let B;e[0]===Symbol.for("react.memo_cache_sentinel")?(B=[],e[0]=B):B=e[0],j=B;break e}let O;e[1]!==f||e[2]!==A?(O=f[A]??[],e[1]=f,e[2]=A,e[3]=O):O=e[3];const L=O;let W;if(e[4]!==a||e[5]!==L||e[6]!==r){let B;e[8]!==a||e[9]!==r?(B=ne=>ne.source===r&&ne.fileLabel===a,e[8]=a,e[9]=r,e[10]=B):B=e[10],W=L.filter(B),e[4]=a,e[5]=L,e[6]=r,e[7]=W}else W=e[7];j=W}const C=j;let I;e[11]===Symbol.for("react.memo_cache_sentinel")?(I=()=>{x(null),w(""),S(null)},e[11]=I):I=e[11];const R=I;let k;e[12]===Symbol.for("react.memo_cache_sentinel")?(k=()=>{R()},e[12]=k):k=e[12];const P=k;let N;e[13]!==d?(N=O=>{const L=sc(d(O));x(L),w(O.text),S(O.id)},e[13]=d,e[14]=N):N=e[14];const D=N;let T;e[15]!==v||e[16]!==b?(T=O=>{b(O.sessionKey,O.id),v===O.id&&R()},e[15]=v,e[16]=b,e[17]=T):T=e[17];const M=T;let $;e[18]!==u||e[19]!==v||e[20]!==a||e[21]!==o||e[22]!==i||e[23]!==y||e[24]!==A||e[25]!==r||e[26]!==n||e[27]!==c||e[28]!==h?($=(O,L)=>{const W=L??y,B=O.trim();if(!W||!B||!a)return;if(!A){q.error(n("inlineComment.toast.selectSessionToSave"));return}const ne=sc(W),le=HS(c(ne)),ee=o(ne);v?h(A,v,{fileLabel:a,startLine:le.startLine,endLine:le.endLine,side:le.side,code:ee,language:i,text:B}):u({sessionKey:A,source:r,fileLabel:a,startLine:le.startLine,endLine:le.endLine,side:le.side,code:ee,language:i,text:B}),R()},e[18]=u,e[19]=v,e[20]=a,e[21]=o,e[22]=i,e[23]=y,e[24]=A,e[25]=r,e[26]=n,e[27]=c,e[28]=h,e[29]=$):$=e[29];const F=$;let V;return e[30]!==g||e[31]!==M||e[32]!==C||e[33]!==v||e[34]!==d||e[35]!==F||e[36]!==y||e[37]!==A||e[38]!==D?(V={sessionKey:A,drafts:C,selection:y,setSelection:x,commentText:g,setCommentText:w,editingDraftId:v,setEditingDraftId:S,reset:R,cancel:P,startEdit:D,deleteDraft:M,saveComment:F,fromDraftRange:d},e[30]=g,e[31]=M,e[32]=C,e[33]=v,e[34]=d,e[35]=F,e[36]=y,e[37]=A,e[38]=D,e[39]=V):V=e[39],V}function GS(t){return t.drafts}function qS(t){return t.removeDraft}function QS(t){return t.updateDraft}function JS(t){return t.addDraft}function YS(t){return t.newSessionDraft?.open}function XS(t){return t.currentSessionId}function mx(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 y=d(f);if(f.id===n){b.push({afterLine:y.end,id:`edit-${f.id}`,content:s.jsx(tc,{initialText:r,fileLabel:o,lineRange:y,isEditing:!0,onSave:p,onCancel:m},`edit-${f.id}`)});continue}b.push({afterLine:y.end,id:`card-${f.id}`,content:s.jsx(ux,{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(tc,{initialText:r,fileLabel:o,lineRange:f,isEditing:!1,onSave:p,onCancel:m},c)})}return b}const Pl=t=>{if(t.type==="new"){const e=Math.min(t.selection.start,t.selection.end),n=Math.max(t.selection.start,t.selection.end);return`new-comment-${t.selection.side??"additions"}-${e}-${n}`}return`draft-${t.draft.id}`},ZS=t=>{const{drafts:e,editingDraftId:n,selection:r}=t,a=[];for(const i of e){if(!Number.isFinite(i.endLine))continue;const o=Math.max(1,Math.floor(i.endLine)),c=i.side==="original"?"deletions":"additions";a.push({lineNumber:o,side:c,metadata:{type:i.id===n?"edit":"saved",draft:i}})}return r&&!n&&a.push({lineNumber:Math.max(r.start,r.end),side:r.side??"additions",metadata:{type:"new",selection:r}}),a};function ek(t){const e=t.trim();if(!e)return null;if(/^-?\d+(\.\d+)?$/.test(e)){const n=Number.parseFloat(e);return Number.isFinite(n)?n:null}if(e.endsWith("px")){const n=Number.parseFloat(e.slice(0,-2));return Number.isFinite(n)?n:null}return null}function Sp(t){if(!(!t||t<=0))return Math.max(200,Math.floor(t))}function tk(t){const{diffRootRef:e,drafts:n,selection:r,editingDraftId:a,commentText:i,fileLabel:o,onSave:c,onCancel:d,onEdit:p,onDelete:m}=t,[u,h]=l.useState(0),[b,f]=l.useState(null),y=l.useMemo(()=>!r||a?null:Pl({type:"new",selection:r}),[a,r]),x=l.useMemo(()=>{const v=n.map(S=>Pl({type:S.id===a?"edit":"saved",draft:S}));return y&&v.push(y),v},[n,a,y]),g=l.useCallback(v=>{const S=e.current;if(!S)return null;const A=S.querySelector("diffs-container");if(!(A instanceof HTMLElement))return null;const j=A.querySelector(`[data-annotation-id="${v}"]`);if(j instanceof HTMLElement)return j;const C=A.shadowRoot;return C?C.querySelector(`[data-annotation-id="${v}"]`):null},[e]);l.useEffect(()=>{if(x.length===0)return;let v=!1,S=0;const A=12,j=()=>{v||x.every(I=>!!g(I))||S>=A||(S+=1,requestAnimationFrame(()=>{v||(h(I=>I+1),j())}))};return j(),()=>{v=!0}},[x,g]),l.useEffect(()=>{const v=e.current;if(!v)return;const S=()=>{const j=getComputedStyle(v),C=ek(j.getPropertyValue("--oc-context-panel-width")),I=v.getBoundingClientRect(),R=C??I.width;f(R>0?R:null)};S();const A=new ResizeObserver(()=>{S()});return A.observe(v),window.addEventListener("resize",S),()=>{A.disconnect(),window.removeEventListener("resize",S)}},[e]);const w=l.useCallback(v=>{const A=e.current?.getBoundingClientRect(),j=v.closest("[data-annotation-content]"),C=j instanceof HTMLElement?j.getBoundingClientRect():v.getBoundingClientRect(),I=[C.width];A&&I.push(A.right-C.left);const R=I.filter(k=>Number.isFinite(k)&&k>0);return R.length>0?Sp(Math.min(...R)):Sp(b)},[e,b]);return s.jsxs(s.Fragment,{children:[n.map(v=>{const S=Pl({type:v.id===a?"edit":"saved",draft:v}),A=g(S);if(!A)return null;const j=w(A);return v.id===a?vo.createPortal(s.jsx(tc,{initialText:i,fileLabel:o,lineRange:{start:v.startLine,end:v.endLine,side:v.side==="original"?"deletions":"additions"},isEditing:!0,onSave:c,onCancel:d,maxWidth:j}),A,`draft-edit-${v.id}`):vo.createPortal(s.jsx(ux,{draft:v,onEdit:()=>p(v),onDelete:()=>m(v),maxWidth:j}),A,`draft-card-${v.id}`)}),r&&!a&&y&&(()=>{const v=g(y);if(!v)return null;const S=w(v);return vo.createPortal(s.jsx(tc,{initialText:i,fileLabel:o,lineRange:r,isEditing:!1,onSave:c,onCancel:d,maxWidth:S}),v,y)})()]})}function sk(){return new Worker($b,{type:"module"})}const nk=["typescript","javascript","tsx","jsx","json","markdown"],Qd={unified:{poolSize:1,totalASTLRUCacheSize:24,lineDiffType:"none"},split:{poolSize:2,totalASTLRUCacheSize:56,lineDiffType:"word-alt"}};let kp,Cp;const Ip=t=>{const e=Qd[t],n=new Bb({workerFactory:sk,poolSize:e.poolSize,totalASTLRUCacheSize:e.totalASTLRUCacheSize},{theme:{light:"pierre-light",dark:"pierre-dark"},langs:nk,lineDiffType:e.lineDiffType,preferredHighlighter:"shiki-wasm"});return n.initialize(),n},rk=t=>{if(!(typeof window>"u"))return t==="split"?(Cp??=Ip("split"),Cp):(kp??=Ip("unified"),kp)},ak=t=>{const e=nt.c(7),{children:n,renderTheme:r}=t,a=Jd("unified"),i=Jd("split");let o,c;e[0]!==r||e[1]!==i||e[2]!==a?(o=()=>{a&&a.setRenderOptions({theme:r,lineDiffType:Qd.unified.lineDiffType}),i&&i.setRenderOptions({theme:r,lineDiffType:Qd.split.lineDiffType})},c=[r,i,a],e[0]=r,e[1]=i,e[2]=a,e[3]=o,e[4]=c):(o=e[3],c=e[4]),Oe.useEffect(o,c);let d;return e[5]!==n?(d=s.jsx(s.Fragment,{children:n}),e[5]=n,e[6]=d):d=e[6],d},ik=t=>{const e=nt.c(11),{children:n}=t,r=yc();let a,i;if(e[0]!==r?.availableThemes||e[1]!==r?.darkThemeId||e[2]!==r?.lightThemeId){const p=Wi(!1),m=Wi(!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,Ki(i),Ki(a),e[0]=r?.availableThemes,e[1]=r?.darkThemeId,e[2]=r?.lightThemeId,e[3]=a,e[4]=i}else a=e[3],i=e[4];let o;e[5]!==a.metadata.id||e[6]!==i.metadata.id?(o={light:i.metadata.id,dark:a.metadata.id},e[5]=a.metadata.id,e[6]=i.metadata.id,e[7]=o):o=e[7];const c=o;let d;return e[8]!==n||e[9]!==c?(d=s.jsx(ak,{renderTheme:c,children:n}),e[8]=n,e[9]=c,e[10]=d):d=e[10],d},Jd=t=>{const e=nt.c(2),n=t===void 0?"unified":t;let r;return e[0]!==n?(r=rk(n),e[0]=n,e[1]=r):r=e[1],r},ok=5e5,lk=`
15
- :host {
16
- font-family: var(--font-mono);
17
- font-size: var(--text-code);
18
- }
19
-
20
- pre, [data-code] {
21
- font-family: var(--font-mono);
22
- font-size: var(--text-code);
23
- }
24
-
25
- /* Mobile touch selection support */
26
- [data-line-number] {
27
- touch-action: manipulation;
28
- -webkit-tap-highlight-color: transparent;
29
- cursor: pointer;
30
- }
31
-
32
- /* Ensure interactive line numbers work on touch */
33
- pre[data-interactive-line-numbers] [data-line-number] {
34
- touch-action: manipulation;
35
- }
36
-
37
- [data-diff-header],
38
- [data-diff] {
39
- [data-separator] {
40
- height: 24px !important;
41
- }
42
- }
43
- `;function ck(t){let e=2166136261;for(let n=0;n<t.length;n+=1)e^=t.charCodeAt(n),e=e+((e<<1)+(e<<4)+(e<<7)+(e<<8)+(e<<24))>>>0;return e.toString(16)}function Ap(t){const e=t.length>400?`${t.slice(0,200)}${t.slice(-200)}`:t;return`${t.length}:${ck(e)}`}const dk=(t,e,n)=>{const i=(n.side==="deletions"?t:e).split(`
44
- `),o=Math.min(n.start,n.end),c=Math.max(n.start,n.end),d=Math.max(1,o),p=Math.min(i.length,c);return d>p?"":i.slice(d-1,p).join(`
45
- `)},uk=(t,e)=>t===e?!0:!t||!e?!1:t.start===e.start&&t.end===e.end&&t.side===e.side,ul=new WeakMap,mk={lineHeight:24,hunkSeparatorHeight:24,fileGap:0};function pk(t){const e=t.closest("[data-diff-virtual-root]");if(e instanceof HTMLElement){const n=e.querySelector("[data-diff-virtual-content]");return{key:e,root:e,content:n instanceof HTMLElement?n:void 0}}return{key:document,root:document,content:void 0}}function fk(t){if(typeof document>"u")return null;const e=pk(t);let n=ul.get(e.key);if(!n){const a=new _b;a.setup(e.root,e.content),n={virtualizer:a,refs:0},ul.set(e.key,n)}n.refs+=1;let r=!1;return{virtualizer:n.virtualizer,release:()=>{if(r)return;r=!0;const a=ul.get(e.key);a&&(a.refs-=1,!(a.refs>0)&&(a.virtualizer.cleanUp(),ul.delete(e.key)))}}}const px=({original:t,modified:e,language:n,fileName:r,renderSideBySide:a,wrapLines:i,layout:o="fill"})=>{const c=yc(),d=c?.currentTheme.metadata.variant==="dark",p=c?.availableThemes.find(J=>J.metadata.id===c.lightThemeId)??Wi(!1),m=c?.availableThemes.find(J=>J.metadata.id===c.darkThemeId)??Wi(!0),{isMobile:u}=un(),h=qu({source:"diff",fileLabel:r||"unknown",language:n,getCodeForRange:J=>dk(t,e,J),toStoreRange:J=>({startLine:J.start,endLine:J.end,side:J.side==="deletions"?"original":"modified"}),fromDraftRange:J=>({start:J.startLine,end:J.endLine,side:J.side==="original"?"deletions":"additions"})}),{drafts:b,selection:f,setSelection:y,commentText:x,setCommentText:g,editingDraftId:w,saveComment:v,cancel:S,startEdit:A,deleteDraft:j}=h,C=Oe.useRef(null),I=Oe.useRef(null),R=Oe.useRef(!1),k=Oe.useRef(null);Oe.useEffect(()=>{C.current=f},[f]),Oe.useEffect(()=>{I.current=w},[w]);const P=Oe.useCallback(J=>{if(R.current)return;const H=C.current;if(u&&H&&J&&J.side===H.side){const re=Math.min(H.start,J.start),ce=Math.max(H.end,J.end);y({...J,start:re,end:ce})}else y(J);J&&(I.current||g(""))},[u,g,y]),N=Oe.useCallback(()=>{S()},[S]),D=Oe.useCallback(J=>{const H=document.createElement("div");H.style.position="relative";const re=Pl(J.metadata);return H.dataset.annotationId=re,H.dataset.annotationSide=J.side,H.dataset.annotationLine=String(J.lineNumber),H},[]),T=Oe.useCallback((J,H)=>{v(J,H??f??void 0)},[v,f]),M=Oe.useCallback(J=>{y(J);const H=L.current;if(H)try{R.current=!0,H.setSelectedLines(J),k.current=J}catch{}finally{R.current=!1}},[y]),$=Oe.useCallback(J=>{const H=J.closest("[data-line-type]")?.getAttribute("data-line-type")??J.getAttribute("data-line-type");if(H==="change-deletion")return"deletions";if(H==="change-addition")return"additions";const re=J.getAttribute("data-column-side")??J.getAttribute("data-side")??J.closest("[data-column-side]")?.getAttribute("data-column-side");if(re==="deletions"||re==="left"||re==="original")return"deletions";if(re==="additions"||re==="right"||re==="modified")return"additions";const ce=J.closest("[data-line-type]");if(ce instanceof HTMLElement){const Ne=ce.getBoundingClientRect(),me=J.getBoundingClientRect(),we=Ne.left+Ne.width/2;return me.left+me.width/2<we?"deletions":"additions"}return"additions"},[]);Ki(p),Ki(m);const F=`${p.metadata.id}:${m.metadata.id}:${d?"dark":"light"}`,V=Oe.useRef(null),O=Oe.useRef(null),L=Oe.useRef(null),W=Oe.useRef(null),[,B]=l.useReducer(J=>J+1,0),ne=Jd(a?"split":"unified"),le=Oe.useMemo(()=>wm(p),[p]),ee=Oe.useMemo(()=>wm(m),[m]);l.useLayoutEffect(()=>{const J=V.current;if(!J)return;const H=J.querySelector("diffs-container");if(!H)return;const re=d?ee:le,ce=(Y,fe)=>Y.colors?.[fe],Ne=ce(le,"terminal.ansiGreen"),me=ce(le,"terminal.ansiRed"),we=ce(le,"terminal.ansiBlue"),_=ce(ee,"terminal.ansiGreen"),ue=ce(ee,"terminal.ansiRed"),Q=ce(ee,"terminal.ansiBlue");H.style.setProperty("--shiki-light",le.fg),H.style.setProperty("--shiki-light-bg",le.bg),Ne&&H.style.setProperty("--shiki-light-addition-color",Ne),me&&H.style.setProperty("--shiki-light-deletion-color",me),we&&H.style.setProperty("--shiki-light-modified-color",we),H.style.setProperty("--shiki-dark",ee.fg),H.style.setProperty("--shiki-dark-bg",ee.bg),_&&H.style.setProperty("--shiki-dark-addition-color",_),ue&&H.style.setProperty("--shiki-dark-deletion-color",ue),Q&&H.style.setProperty("--shiki-dark-modified-color",Q),H.style.setProperty("--diffs-bg",re.bg),H.style.setProperty("--diffs-fg",re.fg);const oe=d?_:Ne,Z=d?ue:me,Ie=d?Q:we;oe&&H.style.setProperty("--diffs-addition-color-override",oe),Z&&H.style.setProperty("--diffs-deletion-color-override",Z),Ie&&H.style.setProperty("--diffs-modified-color-override",Ie);const Se=H.shadowRoot?.querySelector("pre");Se&&(Se.style.setProperty("--shiki-light",le.fg),Se.style.setProperty("--shiki-light-bg",le.bg),Ne&&Se.style.setProperty("--shiki-light-addition-color",Ne),me&&Se.style.setProperty("--shiki-light-deletion-color",me),we&&Se.style.setProperty("--shiki-light-modified-color",we),Se.style.setProperty("--shiki-dark",ee.fg),Se.style.setProperty("--shiki-dark-bg",ee.bg),_&&Se.style.setProperty("--shiki-dark-addition-color",_),ue&&Se.style.setProperty("--shiki-dark-deletion-color",ue),Q&&Se.style.setProperty("--shiki-dark-modified-color",Q),Se.style.setProperty("--diffs-bg",re.bg),Se.style.setProperty("--diffs-fg",re.fg),oe&&Se.style.setProperty("--diffs-addition-color-override",oe),Z&&Se.style.setProperty("--diffs-deletion-color-override",Z),Ie&&Se.style.setProperty("--diffs-modified-color-override",Ie))},[ee,F,d,le]);const ae=Oe.useMemo(()=>Math.max(t.length,e.length)>ok,[t.length,e.length]),ge=Oe.useMemo(()=>({theme:{dark:m.metadata.id,light:p.metadata.id},themeType:d?"dark":"light",diffStyle:a?"split":"unified",diffIndicators:"none",hunkSeparators:"line-info-basic",lineDiffType:"none",maxLineDiffLength:ae?0:1e3,maxLineLengthForHighlighting:ae?1:1e3,expansionLineCount:20,overflow:i?"wrap":"scroll",disableFileHeader:!0,enableLineSelection:!0,enableHoverUtility:!1,onLineSelected:P,unsafeCSS:lk,renderAnnotation:D}),[m.metadata.id,d,ae,p.metadata.id,a,i,P,D]),te=Oe.useMemo(()=>ZS({drafts:b,editingDraftId:w,selection:f}),[w,b,f]),E=Oe.useRef(te);if(Oe.useEffect(()=>{E.current=te},[te]),Oe.useEffect(()=>{if(typeof window>"u")return;const J=O.current;if(!J||!ne)return;L.current?.cleanUp(),L.current=null,W.current?.release(),W.current=null,J.innerHTML="";const H=fk(J);W.current=H;const re=H?new Vb(ge,H.virtualizer,mk,ne):new zb(ge,ne);L.current=re,k.current=null;const ce={name:r||"",contents:t,lang:n,cacheKey:`old:${F}:${r}:${Ap(t)}`},Ne={name:r||"",contents:e,lang:n,cacheKey:`new:${F}:${r}:${Ap(e)}`};return re.render({oldFile:ce,newFile:Ne,lineAnnotations:E.current,containerWrapper:J}),requestAnimationFrame(()=>{B()}),()=>{re.cleanUp(),L.current===re&&(L.current=null),H?.release(),H&&W.current===H&&(W.current=null),J.innerHTML=""}},[F,r,n,e,ge,t,ne]),Oe.useEffect(()=>{const J=L.current;if(J){try{J.setLineAnnotations(te)}catch(H){console.error("Failed to apply diff line annotations",H);try{J.setLineAnnotations([])}catch{}}requestAnimationFrame(()=>{if(L.current===J){try{J.rerender()}catch{}B()}})}},[te]),Oe.useEffect(()=>{const J=L.current;if(!J||f!==null)return;const H=k.current;if(!uk(f,H))try{R.current=!0,J.setSelectedLines(f),k.current=f}catch{}finally{R.current=!1}},[f]),Oe.useEffect(()=>{const J=O.current;if(!J)return;let H=null,re=()=>{};const ce=()=>{const me=J.querySelector("diffs-container")?.shadowRoot;if(!me){H=requestAnimationFrame(ce);return}const we=_=>{if(!(_ instanceof MouseEvent)||_.button!==0||!(_.target instanceof Element))return;const ue=_.target.closest("[data-column-number]");if(!(ue instanceof HTMLElement))return;const Q=ue.getAttribute("data-column-number"),oe=Q?parseInt(Q,10):NaN;if(Number.isNaN(oe))return;const Z=$(ue);P({start:oe,end:oe,side:Z}),_.preventDefault(),_.stopPropagation()};me.addEventListener("click",we,!0),re=()=>{me.removeEventListener("click",we,!0)}};return ce(),()=>{H!==null&&cancelAnimationFrame(H),re()}},[F,r,P,$]),Oe.useEffect(()=>{const J=O.current;if(!J)return;let H=null,re=null;const Ne=setTimeout(()=>{const me=J.querySelector("diffs-container");if(!(me instanceof HTMLElement))return;const we=me.shadowRoot;H=new MutationObserver(()=>{re&&cancelAnimationFrame(re),re=requestAnimationFrame(()=>{B(),re=null})}),H.observe(me,{childList:!0,subtree:!0}),we&&H.observe(we,{childList:!0,subtree:!0})},100);return()=>{clearTimeout(Ne),re&&cancelAnimationFrame(re),H?.disconnect()}},[F,r]),typeof window>"u")return null;const z=s.jsx(tk,{diffRootRef:V,drafts:b,selection:f,editingDraftId:w,commentText:x,fileLabel:r?.split("/").pop()??"",onSave:T,onCancel:N,onEdit:J=>{M({start:J.startLine,end:J.endLine,side:J.side==="original"?"deletions":"additions"}),A(J)},onDelete:j});return o==="fill"?s.jsx("div",{className:pe("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(Es,{outerClassName:"pierre-diff-wrapper size-full",disableHorizontal:!1,fillContainer:!0,"data-diff-virtual-content":!0,children:s.jsx("div",{ref:V,className:"size-full relative",children:s.jsx("div",{ref:O,className:"size-full"})})}),z]})}):s.jsxs("div",{className:pe("relative","w-full"),children:[s.jsx("div",{ref:V,className:"pierre-diff-wrapper w-full overflow-x-auto overflow-y-visible relative",children:s.jsx("div",{ref:O,className:"w-full"})}),z]})},hk=1100,Yd=15e3,Pp=500,gk=t=>t<=6?t:t<=12?6:t<=25?4:2,fx=l.memo(()=>{const t=nt.c(4),{t:e}=ut();let n;t[0]!==e?(n=e("diffView.binary.unavailable"),t[0]=e,t[1]=n):n=t[1];let r;return t[2]!==n?(r=s.jsx("div",{className:"rounded-lg border border-border/60 bg-background px-3 py-2",children:s.jsx("div",{className:"typography-meta text-muted-foreground",children:n})}),t[2]=n,t[3]=r):r=t[3],r}),hx={"?":{code:"?",color:"var(--status-info)",descriptionKey:"diffView.change.untracked"},A:{code:"A",color:"var(--status-success)",descriptionKey:"diffView.change.new"},D:{code:"D",color:"var(--status-error)",descriptionKey:"diffView.change.deleted"},R:{code:"R",color:"var(--status-info)",descriptionKey:"diffView.change.renamed"},C:{code:"C",color:"var(--status-info)",descriptionKey:"diffView.change.copied"},M:{code:"M",color:"var(--status-warning)",descriptionKey:"diffView.change.modified"}},xk=hx.M,Dl=[{value:"single",labelKey:"diffView.mode.single.label",descriptionKey:"diffView.mode.single.description"},{value:"stacked",labelKey:"diffView.mode.stacked.label",descriptionKey:"diffView.mode.stacked.description"}],bk=t=>{const e=t.index?.trim(),n=t.working_dir?.trim();return e&&e!=="?"?e.charAt(0):n?n.charAt(0):e?.charAt(0)||n?.charAt(0)||"M"},gx=t=>{const e=bk(t);return hx[e]??xk},yk=t=>{const{index:e,working_dir:n}=t;return e==="A"||n==="A"||e==="?"||n==="?"},vk=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),wk=(t,e)=>{const n=t.replace(/\\/g,"/").replace(/\/+$/g,""),r=e.replace(/\\/g,"/");if(vk(r))return r;const a=r.replace(/^\/+/,"");return n?`${n}/${a}`:a},Dp=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),Tp=(t,e)=>{const n=t.split(`
46
- `),r=e.split(`
47
- `),a=Math.min(n.length,r.length);for(let i=0;i<a;i+=1)if(n[i]!==r[i])return i+1;return r.length>n.length?n.length+1:n.length>r.length?Math.max(1,r.length):1},jk=t=>{if(!t)return null;const e=t.match(/@@\s*-\d+(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s*@@/m);if(!e)return null;const n=Number.parseInt(e[1],10);return!Number.isFinite(n)||n<1?null:n},nc=(t,e)=>{const n=t??0,r=e??0;return!n&&!r?null:s.jsxs("span",{className:"typography-meta flex flex-shrink-0 items-center gap-1 text-xs whitespace-nowrap",children:[n?s.jsxs("span",{style:{color:"var(--status-success)"},children:["+",n]}):null,r?s.jsxs("span",{style:{color:"var(--status-error)"},children:["-",r]}):null]})},Nk=l.memo(t=>{const e=nt.c(29),{changedFiles:n,selectedFile:r,selectedFileEntry:a,onSelectFile:i,isMobile:o,showModeSelector:c,mode:d,onModeChange:p}=t,m=c===void 0?!1:c,{t:u}=ut();let h;e[0]!==o?(h=C=>{if(!o)return C;const I=C.lastIndexOf("/");return I>=0?C.slice(I+1):C},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(Pr,{filePath:a.path,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",children:b(a.path)}),nc(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 y;e[6]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx(Cs,{className:"size-4 opacity-50"}),e[6]=y):y=e[6];let x;e[7]!==f?(x=s.jsx(Bs,{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,y]})}),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(wo,{className:"typography-meta text-muted-foreground",children:u("diffView.selector.viewMode")}),s.jsx(Hl,{value:d,onValueChange:C=>p(C),children:Dl.map(C=>s.jsx(Gl,{value:C.value,className:"items-center",children:s.jsx("span",{className:"typography-meta text-foreground",children:u(C.labelKey)})},C.value))}),s.jsx(En,{})]}):null,e[9]=d,e[10]=p,e[11]=m,e[12]=u,e[13]=g):g=e[13];const w=r??"";let v;if(e[14]!==n||e[15]!==b){let C;e[17]!==b?(C=I=>s.jsx(Gl,{value:I.path,children:s.jsxs("div",{className:"flex w-full min-w-0 items-center gap-3",children:[s.jsx(Pr,{filePath:I.path,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",children:b(I.path)}),s.jsx("span",{className:"ml-auto",children:nc(I.insertions,I.deletions)})]})},I.path),e[17]=b,e[18]=C):C=e[18],v=n.map(C),e[14]=n,e[15]=b,e[16]=v}else v=e[16];let S;e[19]!==i||e[20]!==w||e[21]!==v?(S=s.jsx(Hl,{value:w,onValueChange:i,children:v}),e[19]=i,e[20]=w,e[21]=v,e[22]=S):S=e[22];let A;e[23]!==g||e[24]!==S?(A=s.jsxs(Vs,{className:"max-h-[70vh] min-w-[320px] overflow-y-auto",children:[g,S]}),e[23]=g,e[24]=S,e[25]=A):A=e[25];let j;return e[26]!==A||e[27]!==x?(j=s.jsxs(zs,{children:[x,A]}),e[26]=A,e[27]=x,e[28]=j):j=e[28],j}),Sk=l.memo(t=>{const e=nt.c(31),{mode:n,onModeChange:r}=t,{t:a}=ut();let i,o,c,d,p,m;if(e[0]!==n||e[1]!==a){const v=Dl.find(S=>S.value===n)??Dl[0];o=zs,i=Bs,m=!0,p="flex h-7 items-center gap-2 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground outline-none hover:bg-interactive-hover hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring",c="min-w-0 truncate typography-meta",d=a(v.labelKey),e[0]=n,e[1]=a,e[2]=i,e[3]=o,e[4]=c,e[5]=d,e[6]=p,e[7]=m}else i=e[2],o=e[3],c=e[4],d=e[5],p=e[6],m=e[7];let u;e[8]!==c||e[9]!==d?(u=s.jsx("span",{className:c,children:d}),e[8]=c,e[9]=d,e[10]=u):u=e[10];let h;e[11]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(Cs,{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 y;e[19]!==r?(y=v=>r(v),e[19]=r,e[20]=y):y=e[20];let x;e[21]!==a?(x=Dl.map(v=>s.jsx(Gl,{value:v.value,children:s.jsx("span",{className:"typography-meta text-foreground",children:a(v.labelKey)})},v.value)),e[21]=a,e[22]=x):x=e[22];let g;e[23]!==n||e[24]!==x||e[25]!==y?(g=s.jsx(Vs,{className:"min-w-[140px]",children:s.jsx(Hl,{value:n,onValueChange:y,children:x})}),e[23]=n,e[24]=x,e[25]=y,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}),kk=l.memo(t=>{const e=nt.c(11),{changedFiles:n,selectedFile:r,onSelectFile:a}=t,{t:i}=ut();if(n.length===0)return null;let o;if(e[0]!==n||e[1]!==a||e[2]!==r||e[3]!==i){let d;e[5]!==a||e[6]!==r||e[7]!==i?(d=p=>{const m=gx(p),u=r===p.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>a(p.path),className:pe("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left transition-colors",u?"bg-interactive-selection text-interactive-selection-foreground":"text-muted-foreground hover:bg-interactive-hover hover:text-foreground"),children:[s.jsx(Pr,{filePath:p.path,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:{color:m.color},title:i(m.descriptionKey),"aria-label":i(m.descriptionKey),children:m.code}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},title:p.path,children:p.path}),nc(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(Es,{outerClassName:"flex-1 min-h-0",className:"px-2 py-2",children:s.jsx("ul",{className:"flex flex-col gap-1",children:o})}),e[9]=o,e[10]=c):c=e[10],c}),Ck=l.memo(t=>{const e=nt.c(21),{filePath:n,diff:r,isVisible:a,renderSideBySide:i}=t,{t:o}=ut(),c=r.original.length>0,d=r.modified.length>0;if(!a){let y;return e[0]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx("div",{className:"absolute inset-0 hidden"}),e[0]=y):y=e[0],y}const p=i?"flex flex-row gap-6 items-start justify-center h-full":"flex flex-col gap-4 items-center",m=i?"flex flex-col items-center gap-2 flex-1 min-w-0 h-full":"flex flex-col items-center gap-2";let u;e[1]===Symbol.for("react.memo_cache_sentinel")?(u={contain:"size layout"},e[1]=u):u=e[1];let 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}),Ik=l.memo(t=>{const e=nt.c(20),{filePath:n,diff:r,renderSideBySide:a}=t,{t:i}=ut(),o=r.original.length>0,c=r.modified.length>0,d=a?"flex flex-row gap-6 items-start justify-center":"flex flex-col gap-4 items-center",p=a?"flex flex-col items-center gap-2 flex-1 min-w-0":"flex flex-col items-center gap-2";let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m={contain:"layout"},e[0]=m):m=e[0];let u;e[1]!==r.original||e[2]!==n||e[3]!==o||e[4]!==p||e[5]!==a||e[6]!==i?(u=o&&s.jsxs("div",{className:p,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:i("diffView.image.original")}),s.jsx("img",{src:r.original,alt:i("diffView.image.originalAlt",{path:n}),className:a?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[1]=r.original,e[2]=n,e[3]=o,e[4]=p,e[5]=a,e[6]=i,e[7]=u):u=e[7];let 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}),Ak=l.memo(t=>{const e=nt.c(15),{filePath:n,diff:r,renderSideBySide:a,wrapLines:i}=t;let o;e[0]!==n?(o=Po(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(fx,{}),e[2]=m):m=e[2],m}if(Hi(n)){let m;return e[3]!==r||e[4]!==n||e[5]!==a?(m=s.jsx(Ik,{filePath:n,diff:r,renderSideBySide:a}),e[3]=r,e[4]=n,e[5]=a,e[6]=m):m=e[6],m}let d;e[7]===Symbol.for("react.memo_cache_sentinel")?(d={contain:"layout"},e[7]=d):d=e[7];let p;return e[8]!==r.modified||e[9]!==r.original||e[10]!==n||e[11]!==c||e[12]!==a||e[13]!==i?(p=s.jsx("div",{className:"w-full",style:d,children:s.jsx(px,{original:r.original,modified:r.modified,language:c,fileName:n,renderSideBySide:a,wrapLines:i,layout:"inline"})}),e[8]=r.modified,e[9]=r.original,e[10]=n,e[11]=c,e[12]=a,e[13]=i,e[14]=p):p=e[14],p}),Pk=l.memo(t=>{const e=nt.c(15),{filePath:n,diff:r,isVisible:a,renderSideBySide:i,wrapLines:o}=t;let c;e[0]!==n?(c=Po(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(fx,{}),e[2]=m):m=e[2],m}if(!a)return null;if(Hi(n)){let m;return e[3]!==r||e[4]!==n||e[5]!==a||e[6]!==i?(m=s.jsx(Ck,{filePath:n,diff:r,isVisible:a,renderSideBySide:i}),e[3]=r,e[4]=n,e[5]=a,e[6]=i,e[7]=m):m=e[7],m}let p;return e[8]!==r.modified||e[9]!==r.original||e[10]!==n||e[11]!==d||e[12]!==i||e[13]!==o?(p=s.jsx(Es,{outerClassName:"absolute inset-0",disableHorizontal:!1,observeMutations:!1,preventOverscroll:!0,"data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:s.jsx(px,{original:r.original,modified:r.modified,language:d,fileName:n,renderSideBySide:i,wrapLines:o,layout:"inline"})}),e[8]=r.modified,e[9]=r.original,e[10]=n,e[11]=d,e[12]=i,e[13]=o,e[14]=p):p=e[14],p}),Dk=l.memo(t=>{const e=nt.c(122),{directory:n,file:r,layout:a,wrapLines:i,scrollRootRef:o,isSelected:c,onSelect:d,registerSectionRef:p,defaultCollapsed:m,expandRequestPath:u,expandRequestNonce:h,showOpenInEditorAction:b,isOpeningInEditor:f,onOpenInEditor:y}=t,x=m===void 0?!1:m,g=u===void 0?null:u,w=h===void 0?0:h,v=b===void 0?!1:b,S=f===void 0?!1:f,{t:A}=ut(),{git:j}=Gn();let C;e[0]!==n||e[1]!==r.path?(C=Xe=>Xe.directories.get(n)?.diffCache.get(r.path)??null,e[0]=n,e[1]=r.path,e[2]=C):C=e[2];const I=pn(C),R=pn(Mk),k=Te(Rk),[P,N]=l.useState(!x),[D,T]=l.useState(!1),[M,$]=l.useState(0),[F,V]=l.useState(null),[O,L]=l.useState(!1),[W,B]=l.useState(!1),ne=l.useRef(null),le=l.useRef(null);let ee;e[3]!==r?(ee=gx(r),e[3]=r,e[4]=ee):ee=e[4];const ae=ee,ge=a==="side-by-side";let te;e:{if(!I){te=null;break e}let Xe;e[5]!==I.isBinary||e[6]!==I.modified||e[7]!==I.original?(Xe={original:I.original,modified:I.modified,isBinary:I.isBinary},e[5]=I.isBinary,e[6]=I.modified,e[7]=I.original,e[8]=Xe):Xe=e[8],te=Xe}const E=te;let z;e[9]!==r.path||e[10]!==p?(z=Xe=>{le.current=Xe,p(r.path,Xe)},e[9]=r.path,e[10]=p,e[11]=z):z=e[11];const J=z;let H;e[12]===Symbol.for("react.memo_cache_sentinel")?(H=Xe=>{N(Xe),Xe&&T(!0)},e[12]=H):H=e[12];const re=H;let ce;e[13]!==r.path||e[14]!==d?(ce=()=>{d(r.path)},e[13]=r.path,e[14]=d,e[15]=ce):ce=e[15];const Ne=ce;let me,we;e[16]!==D||e[17]!==P||e[18]!==o?(me=()=>{if(!P||D)return;const Xe=le.current;if(!Xe)return;if(!o.current||typeof IntersectionObserver>"u"){T(!0);return}const mt=new IntersectionObserver(et=>{et.some(Ek)&&(T(!0),mt.disconnect())},{root:o.current,rootMargin:"200px 0px",threshold:.1});return mt.observe(Xe),()=>mt.disconnect()},we=[D,P,o],e[16]=D,e[17]=P,e[18]=o,e[19]=me,e[20]=we):(me=e[19],we=e[20]),l.useEffect(me,we);let _,ue;e[21]!==w||e[22]!==g||e[23]!==r.path?(_=()=>{w<=0||g!==r.path||(N(!0),T(!0))},ue=[w,g,r.path],e[21]=w,e[22]=g,e[23]=r.path,e[24]=_,e[25]=ue):(_=e[24],ue=e[25]),l.useEffect(_,ue);let Q,oe;e[26]!==E||e[27]!==M||e[28]!==n||e[29]!==r.path||e[30]!==j||e[31]!==D||e[32]!==P||e[33]!==R?(Q=()=>{if(!P||!D)return;if(!n||E){ne.current=null,L(!1);return}const Xe=`${n}::${r.path}::${M}`;if(ne.current===Xe)return;ne.current=Xe,V(null),L(!0);let mt=!1;const et=j.getGitFileDiff(n,{path:r.path}),ct=new Promise(Fk);return Promise.race([et,ct]).then(lt=>{mt||(R(n,r.path,{original:lt.original??"",modified:lt.modified??"",isBinary:lt.isBinary}),L(!1))}).catch(lt=>{if(mt)return;const ye=lt instanceof Error?lt.message:String(lt);V(ye),L(!1)}),()=>{mt=!0,ne.current===Xe&&(ne.current=null)}},oe=[n,E,M,r.path,j,D,P,R],e[26]=E,e[27]=M,e[28]=n,e[29]=r.path,e[30]=j,e[31]=D,e[32]=P,e[33]=R,e[34]=Q,e[35]=oe):(Q=e[34],oe=e[35]),l.useEffect(Q,oe);let Z;e[36]!==Ne||e[37]!==P?(Z=()=>{re(!P),Ne()},e[36]=Ne,e[37]=P,e[38]=Z):Z=e[38];const Ie=Z,Se=P?"rounded-b-none":"rounded-b-xl",Y=c?"ring-1 ring-inset ring-[var(--interactive-selection)]":null;let fe;e[39]!==Se||e[40]!==Y?(fe=pe("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",Se,"text-muted-foreground hover:text-foreground",Y),e[39]=Se,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 xe;e[43]!==P?(xe=s.jsx("span",{className:"flex size-5 items-center justify-center opacity-70 group-hover/header:opacity-100",children:P?s.jsx(Cs,{className:"size-4"}):s.jsx(Fn,{className:"size-4"})}),e[43]=P,e[44]=xe):xe=e[44];let he;e[45]!==ae.color?(he={color:ae.color},e[45]=ae.color,e[46]=he):he=e[46];let Pe;e[47]!==ae.descriptionKey||e[48]!==A?(Pe=A(ae.descriptionKey),e[47]=ae.descriptionKey,e[48]=A,e[49]=Pe):Pe=e[49];let Be;e[50]!==ae.descriptionKey||e[51]!==A?(Be=A(ae.descriptionKey),e[50]=ae.descriptionKey,e[51]=A,e[52]=Be):Be=e[52];let G;e[53]!==ae.code||e[54]!==he||e[55]!==Pe||e[56]!==Be?(G=s.jsx("span",{className:"typography-micro font-semibold leading-none w-4 text-center uppercase",style:he,title:Pe,"aria-label":Be,children:ae.code}),e[53]=ae.code,e[54]=he,e[55]=Pe,e[56]=Be,e[57]=G):G=e[57];const be=r.path;let De;e[58]!==r.path?(De=s.jsx(Pr,{filePath:r.path,className:"h-3.5 w-3.5 flex-shrink-0 align-middle"}),e[58]=r.path,e[59]=De):De=e[59];let Ae;if(e[60]!==r.path){e:{const Xe=r.path.lastIndexOf("/");if(Xe===-1){let Ve;e[62]===Symbol.for("react.memo_cache_sentinel")?(Ve={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},e[62]=Ve):Ve=e[62],Ae=s.jsx("span",{className:"block min-w-0 truncate typography-ui-label text-foreground",style:Ve,children:r.path});break e}const mt=r.path.slice(0,Xe),et=r.path.slice(Xe+1);let ct;e[63]===Symbol.for("react.memo_cache_sentinel")?(ct={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},e[63]=ct):ct=e[63];let lt;e[64]!==mt?(lt=s.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:ct,children:mt}),e[64]=mt,e[65]=lt):lt=e[65];let ye;e[66]===Symbol.for("react.memo_cache_sentinel")?(ye=s.jsx("span",{className:"text-muted-foreground",children:"/"}),e[66]=ye):ye=e[66];let Ge;e[67]!==et?(Ge=s.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[ye,s.jsx("span",{className:"text-foreground",children:et})]}),e[67]=et,e[68]=Ge):Ge=e[68];let $e;e[69]!==lt||e[70]!==Ge?($e=s.jsxs("span",{className:"flex min-w-0 items-baseline overflow-hidden",children:[lt,Ge]}),e[69]=lt,e[70]=Ge,e[71]=$e):$e=e[71],Ae=$e}e[60]=r.path,e[61]=Ae}else Ae=e[61];let ve;e[72]!==De||e[73]!==Ae?(ve=s.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[De,Ae]}),e[72]=De,e[73]=Ae,e[74]=ve):ve=e[74];let U;e[75]!==r.path||e[76]!==ve?(U=s.jsx("span",{className:"min-w-0 flex-1 overflow-hidden typography-ui-label",title:be,children:ve}),e[75]=r.path,e[76]=ve,e[77]=U):U=e[77];let de;e[78]!==xe||e[79]!==G||e[80]!==U?(de=s.jsxs("div",{className:"relative flex min-w-0 flex-1 items-center gap-2",children:[xe,G,U]}),e[78]=xe,e[79]=G,e[80]=U,e[81]=de):de=e[81];let Re;e[82]!==r.deletions||e[83]!==r.insertions?(Re=nc(r.insertions,r.deletions),e[82]=r.deletions,e[83]=r.insertions,e[84]=Re):Re=e[84];let Le;e[85]!==E||e[86]!==r.path||e[87]!==S||e[88]!==y||e[89]!==v||e[90]!==A?(Le=v&&y?s.jsx(je,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",title:A("diffView.actions.openFileInEditorAtChange"),onClick:Xe=>{Xe.stopPropagation(),y(r.path,E)},disabled:S,children:S?s.jsx(Zt,{className:"size-3.5 animate-spin"}):s.jsx(Yr,{className:"size-3.5"})}):null,e[85]=E,e[86]=r.path,e[87]=S,e[88]=y,e[89]=v,e[90]=A,e[91]=Le):Le=e[91];const se=ge?"side-by-side":"unified";let ie;e[92]!==r.path||e[93]!==k?(ie=Xe=>{const mt=Xe==="side-by-side"?"side-by-side":"inline";k(r.path,mt)},e[92]=r.path,e[93]=k,e[94]=ie):ie=e[94];let K;e[95]!==se||e[96]!==ie?(K=s.jsx(gg,{mode:se,onModeChange:ie,className:"opacity-70"}),e[95]=se,e[96]=ie,e[97]=K):K=e[97];let _e;e[98]!==Re||e[99]!==Le||e[100]!==K?(_e=s.jsxs("div",{className:"relative flex items-center gap-2",children:[Re,Le,K]}),e[98]=Re,e[99]=Le,e[100]=K,e[101]=_e):_e=e[101];let He;e[102]!==Ie||e[103]!==fe||e[104]!==de||e[105]!==_e?(He=s.jsx("div",{className:"sticky top-0 z-10 bg-background",children:s.jsxs("button",{type:"button",onClick:Ie,className:fe,children:[ke,de,_e]})}),e[102]=Ie,e[103]=fe,e[104]=de,e[105]=_e,e[106]=He):He=e[106];let Ke;e[107]!==E||e[108]!==F||e[109]!==r.deletions||e[110]!==r.insertions||e[111]!==r.path||e[112]!==W||e[113]!==P||e[114]!==O||e[115]!==ge||e[116]!==i?(Ke=P&&s.jsxs("div",{className:"relative border border-t-0 border-border/60 bg-background rounded-b-xl overflow-hidden",children:[F?s.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[s.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:"Failed to load diff"}),s.jsx("div",{className:"typography-meta text-muted-foreground max-w-[32rem] text-center",children:F}),s.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>$(Ok),children:"Retry"})]}):null,O&&!E&&!F?s.jsxs("div",{className:"flex items-center justify-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[s.jsx(Zt,{size:16,className:"animate-spin"}),"Loading diff…"]}):null,E&&!W&&r.insertions+r.deletions>Pp?s.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[s.jsxs("div",{className:"typography-ui-label font-semibold text-foreground",children:["Large diff (",r.insertions+r.deletions," changed lines)"]}),s.jsx("div",{className:"typography-meta text-muted-foreground",children:"Rendering may be slow. You can still view the diff by clicking below."}),s.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>B(!0),children:"Render anyway"})]}):null,E&&(W||r.insertions+r.deletions<=Pp)?s.jsx(Ak,{filePath:r.path,diff:E,renderSideBySide:ge,wrapLines:i}):null]}),e[107]=E,e[108]=F,e[109]=r.deletions,e[110]=r.insertions,e[111]=r.path,e[112]=W,e[113]=P,e[114]=O,e[115]=ge,e[116]=i,e[117]=Ke):Ke=e[117];let Ze;return e[118]!==J||e[119]!==He||e[120]!==Ke?(Ze=s.jsxs("div",{ref:J,className:"scroll-mt-4",children:[He,Ke]}),e[118]=J,e[119]=He,e[120]=Ke,e[121]=Ze):Ze=e[121],Ze}),xx=({hideStackedFileSidebar:t=!1,stackedDefaultCollapsedAll:e=!1,hideFileSelector:n=!1,pinSelectedFileHeaderToTopOnNavigate:r=!1,showOpenInEditorAction:a=!1})=>{const{t:i}=ut(),{git:o,files:c}=Gn(),d=Xr(),{screenWidth:p,isMobile:m}=un(),u=fg(d??null),h=gc(d??null),b=hg(d??null),f=pn(de=>de.setActiveDirectory),y=pn(de=>de.ensureStatus),x=pn(de=>de.fetchStatus),g=pn(de=>de.setDiff),[w,v]=l.useState(null),[S,A]=l.useState(null),[j,C]=l.useState(0),[I,R]=l.useState(null),[k,P]=l.useState(0),[N,D]=l.useState(null),T=l.useRef(null),M=Te(de=>de.pendingDiffFile),$=Te(de=>de.setPendingDiffFile),F=Te(de=>de.diffLayoutPreference),V=Te(de=>de.diffFileLayout),O=Te(de=>de.setDiffFileLayout),L=Te(de=>de.diffWrapLines),W=Te(de=>de.setDiffWrapLines),B=Te(de=>de.diffViewMode),ne=Te(de=>de.setDiffViewMode),le=Te(de=>de.openContextFileAtLine),ee=L,ae=B==="stacked",ge=m||p<=768,te=!t&&!ge&&p>=1024,E=l.useRef(null),z=l.useRef(new Map),J=l.useRef(null),H=l.useRef(null),re=l.useRef(!1);l.useEffect(()=>{if(!r||!ae||!I)return;const de=E.current;if(!de)return;let Re=null,Le=!1,se=0;const ie=Date.now()+1200;let K=0;const _e=()=>{Le||(Le=!0,R(null))},He=()=>{_e()},Ke=()=>{if(K>0){K-=1;return}_e()};window.addEventListener("wheel",He,{passive:!0,capture:!0}),window.addEventListener("touchstart",He,{passive:!0,capture:!0}),window.addEventListener("pointerdown",He,{capture:!0}),window.addEventListener("keydown",He,{capture:!0}),de.addEventListener("scroll",Ke,{passive:!0});const Ze=()=>{if(Le||Date.now()>ie){_e();return}const Xe=E.current,mt=z.current.get(I);if(!Xe||!mt){_e();return}const et=Xe.getBoundingClientRect(),lt=mt.getBoundingClientRect().top-et.top;if(Math.abs(lt)<=1){if(se+=1,se>=2){_e();return}}else{se=0;const ye=Math.max(0,Xe.scrollHeight-Xe.clientHeight),Ge=Math.min(ye,Math.max(0,Xe.scrollTop+lt));if(Math.abs(Ge-Xe.scrollTop)<=.5){_e();return}K+=1,Xe.scrollTop=Ge}Re=window.requestAnimationFrame(Ze)};return Re=window.requestAnimationFrame(Ze),()=>{Le=!0,Re!==null&&window.cancelAnimationFrame(Re),window.removeEventListener("wheel",He,!0),window.removeEventListener("touchstart",He,!0),window.removeEventListener("pointerdown",He,!0),window.removeEventListener("keydown",He,!0),de.removeEventListener("scroll",Ke)}},[ae,r,I]);const ce=l.useMemo(()=>{if(!h?.files)return[];const de=h.diffStats??{};return h.files.map(Re=>({...Re,insertions:de[Re.path]?.insertions??0,deletions:de[Re.path]?.deletions??0,isNew:yk(Re)})).sort((Re,Le)=>Re.path.localeCompare(Le.path))},[h]),Ne=l.useMemo(()=>w?ce.find(de=>de.path===w)??null:null,[ce,w]),me=l.useCallback(de=>{const Re=V[de.path];if(Re)return Re;if(F==="inline")return"inline";if(F==="side-by-side")return"side-by-side";const Le=p<hk;return de.isNew||Le?"inline":"side-by-side"},[V,F,p]),we=l.useMemo(()=>Ne?me(Ne):null,[me,Ne]);l.useEffect(()=>{d&&(f(d),y(d,o))},[d,f,y,o]),l.useEffect(()=>{if(d)return Dr.onGitRefreshHint(de=>{Dp(de.directory)===Dp(d)&&x(d,o)})},[d,x,o]),l.useEffect(()=>{M&&(v(M),$(null),ae&&(re.current=!0,J.current=M,A(M),C(de=>de+1)))},[ae,M,$]),l.useEffect(()=>{!w&&!M&&ce.length>0&&v(ce[0].path)},[ce,w,M]),l.useEffect(()=>{w&&ce.length>0&&(ce.some(Re=>Re.path===w)||v(ce[0]?.path??null))},[ce,w]);const _=l.useCallback((de,Re)=>{const Le=z.current;Re?Le.set(de,Re):Le.delete(de)},[]),ue=l.useCallback(de=>{const Re=z.current.get(de),Le=E.current;if(!Re||!Le)return{ok:!1,aligned:!1,didMove:!1,atScrollLimit:!1,delta:0};const se=Le.getBoundingClientRect(),K=Re.getBoundingClientRect().top-se.top,_e=Math.max(0,Le.scrollHeight-Le.clientHeight),He=Le.scrollTop+K,Ke=Math.min(_e,Math.max(0,He)),Ze=Math.abs(Ke-Le.scrollTop)>.5;Le.scrollTop=Ke;const Xe=Math.abs(K)<=1,mt=Ke<=.5||Ke>=_e-.5;return{ok:!0,aligned:Xe,didMove:Ze,atScrollLimit:mt,delta:K}},[]);l.useEffect(()=>{if(!ae){J.current=null,re.current=!1,H.current!==null&&(window.cancelAnimationFrame(H.current),H.current=null);return}if(!J.current)return;let Re=0;const Le=120;let se=!1,ie=0,K=!1,_e=0;const He=Date.now()+2e3,Ke=()=>{K||(K=!0,window.removeEventListener("wheel",Xe,!0),window.removeEventListener("touchstart",Xe,!0),window.removeEventListener("pointerdown",Xe,!0),window.removeEventListener("keydown",Xe,!0),et?.removeEventListener("scroll",mt))},Ze=()=>{se||(se=!0,Ke(),J.current=null,re.current=!1,H.current!==null&&(window.cancelAnimationFrame(H.current),H.current=null))},Xe=()=>{Ze()},mt=()=>{if(ie>0){ie-=1;return}Ze()},et=E.current;window.addEventListener("wheel",Xe,{passive:!0,capture:!0}),window.addEventListener("touchstart",Xe,{passive:!0,capture:!0}),window.addEventListener("pointerdown",Xe,{capture:!0}),window.addEventListener("keydown",Xe,{capture:!0}),et?.addEventListener("scroll",mt,{passive:!0});const ct=()=>{if(Date.now()>He){Ze(),H.current=null;return}if(se){H.current=null;return}const lt=J.current;if(!lt){Ze(),H.current=null;return}ie+=1;const ye=ue(lt);if(!ye.ok){ie=Math.max(0,ie-1),Re+=1,Re<Le?H.current=window.requestAnimationFrame(ct):(Ze(),H.current=null);return}if(!ye.aligned){if(Re+=1,ye.didMove){if(_e=0,Re<Le){H.current=window.requestAnimationFrame(ct);return}}else if(_e+=1,_e<6&&(ye.atScrollLimit||Math.abs(ye.delta)>1)){H.current=window.requestAnimationFrame(ct);return}}r&&re.current&&R(lt),Ze()};return H.current=window.requestAnimationFrame(ct),()=>{se=!0,Ke(),H.current!==null&&(window.cancelAnimationFrame(H.current),H.current=null)}},[ae,r,ue,w,j]);const Q=l.useCallback(de=>{v(de)},[]),oe=l.useCallback(de=>{if(H.current!==null&&(window.cancelAnimationFrame(H.current),H.current=null),J.current=null,v(de),!ae){re.current=!1;return}re.current=!0,J.current=de,ue(de)},[ae,ue]),Z=l.useCallback(de=>{ne(de),de==="stacked"&&w&&(ue(w).aligned||(J.current=w))},[ue,w,ne]),Ie=l.useCallback(de=>{const Re=de==="side-by-side"?"side-by-side":"inline";if(ae){ce.forEach(Le=>{O(Le.path,Re)});return}Ne&&O(Ne.path,Re)},[ce,ae,Ne,O]),Se=(we??"side-by-side")==="side-by-side",Y=!n&&(!ae||!te),fe=pn(l.useCallback(de=>!d||!w?null:de.directories.get(d)?.diffCache.get(w)??null,[d,w])),ke=l.useMemo(()=>fe?{original:fe.original,modified:fe.modified,isBinary:fe.isBinary}:null,[fe]),[xe,he]=l.useState(null),Pe=l.useCallback(async(de,Re)=>{if(!(!d||!de)){he(de);try{let Le=null;if(Re&&!Re.isBinary&&!Hi(de)&&(Le=Tp(Re.original,Re.modified)),Le===null)try{const He=await o.getGitDiff(d,{path:de,contextLines:3});Le=jk(He.diff)}catch{Le=null}let se=Re;if(Le===null||!se){const He=await o.getGitFileDiff(d,{path:de});se={original:He.original??"",modified:He.modified??"",isBinary:He.isBinary},g(d,de,se)}const ie=Le??(se.isBinary||Hi(de)?1:Tp(se.original,se.modified)),K=wk(d,de),_e=await Hu(c,K);if(!_e.ok){q.error(Gu(_e.reason));return}le(d,K,ie,1)}finally{he(Le=>Le===de?null:Le)}}},[d,c,o,le,g]),Be=l.useCallback(async()=>{w&&await Pe(w,ke)},[Pe,ke,w]),G=!!(w&&xe===w),be=!!fe,De=!ae&&!!w&&!be;l.useEffect(()=>{if(ae)return;if(D(null),!d||!w){T.current=null;return}if(fe){T.current=null;return}const de=`${d}::${w}::${k}`;if(T.current===de)return;T.current=de;let Re=!1;const Le=o.getGitFileDiff(d,{path:w}),se=Yd,ie=new Promise((K,_e)=>{setTimeout(()=>_e(new Error(`Timed out after ${se}ms`)),se)});return Promise.race([Le,ie]).then(K=>{Re||g(d,w,{original:K.original??"",modified:K.modified??"",isBinary:K.isBinary})}).catch(K=>{if(Re)return;const _e=K instanceof Error?K.message:String(K);D(_e)}),()=>{Re=!0,T.current===de&&(T.current=null)}},[d,ae,w,fe,o,g,k]);const Ae=()=>!d||!w||!ke?null:s.jsx(Pk,{filePath:w,diff:ke,isVisible:!0,renderSideBySide:Se,wrapLines:ee},w),ve=()=>{if(!d)return null;const de=gk(ce.length);return s.jsxs("div",{className:"flex flex-1 min-h-0 h-full gap-3 px-3 pb-3 pt-2",children:[te&&s.jsxs("section",{className:"hidden lg:flex w-72 flex-col rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[s.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 border-b border-border/40",children:[s.jsx("span",{className:"typography-ui-header font-semibold text-foreground",children:i("diffView.section.files")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:ce.length})]}),s.jsx(kk,{changedFiles:ce,selectedFile:w,onSelectFile:oe})]}),s.jsx(Es,{ref:E,outerClassName:"flex-1 min-h-0 h-full",className:"pr-2",disableHorizontal:!0,observeMutations:!1,preventOverscroll:!0,"data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:s.jsx("div",{className:"flex flex-col gap-3",children:ce.map((Re,Le)=>s.jsx(Dk,{directory:d,file:Re,layout:me(Re),wrapLines:ee,scrollRootRef:E,isSelected:Re.path===w,onSelect:Q,registerSectionRef:_,defaultCollapsed:e?!0:Le>=de,expandRequestPath:S,expandRequestNonce:j,showOpenInEditorAction:a,isOpeningInEditor:xe===Re.path,onOpenInEditor:(se,ie)=>{Pe(se,ie)}},Re.path))})})]})},U=()=>d?b&&!h?s.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[s.jsx(Zt,{size:16,className:"animate-spin"}),i("diffView.state.loadingRepositoryStatus")]}):u===!1?s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:i("diffView.state.notGitRepository")}):ce.length===0?s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:i("diffView.state.cleanWorkingTree")}):ae?ve():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(),De&&!be&&s.jsx("div",{className:"absolute inset-0 flex items-center justify-center gap-2 text-sm text-muted-foreground",children:N?s.jsxs("div",{className:"flex flex-col items-center gap-2",children:[s.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:i("diffView.state.failedToLoadDiff")}),s.jsx("div",{className:"typography-meta text-muted-foreground max-w-[32rem] text-center",children:N}),s.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>{D(null),P(de=>de+1)},children:i("diffView.actions.retry")})]}):s.jsxs(s.Fragment,{children:[s.jsx(Zt,{size:16,className:"animate-spin"}),i("diffView.state.loadingDiff")]})})]}):s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:i("diffView.state.selectSessionDirectory")});return s.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background",children:[s.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 bg-background",children:[!m&&s.jsxs("div",{className:"flex items-center gap-1 rounded-md px-2 py-1 text-muted-foreground shrink-0",children:[s.jsx(uc,{size:16}),s.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:b&&!h?i("diffView.state.loadingChanges"):ce.length===1?i("diffView.summary.changedFilesSingle",{count:ce.length}):i("diffView.summary.changedFilesPlural",{count:ce.length})})]}),!ge&&s.jsx(Sk,{mode:B,onModeChange:Z}),Y&&s.jsx(Nk,{changedFiles:ce,selectedFile:w,selectedFileEntry:Ne,onSelectFile:oe,isMobile:ge,showModeSelector:ge,mode:B,onModeChange:Z}),s.jsx("div",{className:"flex-1"}),Ne&&s.jsx(je,{variant:"ghost",size:"sm",onClick:()=>W(!L),className:pe("h-5 w-5 p-0 transition-opacity",ee?"text-foreground opacity-100":"text-muted-foreground opacity-60 hover:opacity-100"),title:i(ee?"diffView.actions.disableLineWrap":"diffView.actions.enableLineWrap"),children:s.jsx(Oh,{className:"size-4"})}),a&&Ne&&!ae&&s.jsx(je,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",onClick:()=>{Be()},disabled:G,title:i("diffView.actions.openFileAtFirstChangedLine"),children:G?s.jsx(Zt,{className:"size-3.5 animate-spin"}):s.jsx(Yr,{className:"size-3.5"})}),Ne&&we&&s.jsx(gg,{mode:we==="side-by-side"?"side-by-side":"unified",onModeChange:Ie})]}),U()]})},Tk=()=>{const t=nt.c(6),{git:e}=Gn(),n=Xr(),r=pn(Lk),a=pn($k),i=n1(n??null);let o,c;return t[0]!==n||t[1]!==a||t[2]!==e||t[3]!==r?(o=()=>{n&&(r(n),a(n,e))},c=[n,r,a,e],t[0]=n,t[1]=a,t[2]=e,t[3]=r,t[4]=o,t[5]=c):(o=t[4],c=t[5]),l.useEffect(o,c),i};function Mk(t){return t.setDiff}function Rk(t){return t.setDiffFileLayout}function Ek(t){return t.isIntersecting}function Fk(t,e){setTimeout(()=>e(new Error(`Timed out after ${Yd}ms`)),Yd)}function Ok(t){return t+1}function Lk(t){return t.setActiveDirectory}function $k(t){return t.ensureStatus}const Bk=Object.freeze(Object.defineProperty({__proto__:null,DiffView:xx,useDiffFileCount:Tk},Symbol.toStringTag,{value:"Module"})),Vk={next:"Next match",prev:"Previous match",select:"Select all matches",replace:"Replace",replaceAll:"Replace all",close:"Close"},zk={case:"Match case",re:"Regular expression",word:"Match whole word"};function _k(t){const e=t.querySelector(".cm-search");if(e){for(const[n,r]of Object.entries(Vk)){const a=e.querySelector(`button[name="${n}"]`);a&&!a.title&&(a.title=r)}for(const[n,r]of Object.entries(zk)){const i=e.querySelector(`input[name="${n}"]`)?.parentElement;i&&!i.title&&(i.title=r)}}}const Mp=new Zi,Rp=new Zi,Ep=new Zi,Fp=new Zi,Op=new Zi,Lp=new Zi,$p=t=>t,id=Xb,Uk=Zb,Wk=ey;class Kk extends ty{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 Bp=(t,e)=>!t||t.length===0?[]:Yb.define({create(n){const r=new Lh,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,$h.widget({widget:new Kk(i.id,e),block:!0,side:1}))}return r.finish()},update(n,r){return n.map(r.changes)},provide:n=>or.decorations.from(n)}),Vp=t=>{if(!t)return[];const e=Math.max(1,t.start),n=Math.max(e,t.end);return Jb.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 Lh;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,$h.line({class:"oc-cm-selected-line"}))}return a.finish()}},{decorations:r=>r.decorations})};function Xd({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),y=l.useRef(t),x=l.useRef(e),g=l.useRef(c),w=l.useRef(d),v=l.useRef(h),S=l.useRef(p),A=l.useRef(new Map),[j,C]=l.useState([]),I=l.useCallback(k=>{const P=(k??[]).map(N=>{const D=A.current.get(N.id);return D?{id:N.id,content:N.content,container:D}:null}).filter(N=>N!==null);C(N=>N.length===P.length&&N.every((D,T)=>{const M=P[T];return D.id===M.id&&D.content===M.content&&D.container===M.container})?N:P)},[]),R=l.useCallback(k=>{const P=b.current,N=k??f.current;if(!P||!N)return;const D=N.dom.querySelector(".cm-gutters"),T=D instanceof HTMLElement?D.getBoundingClientRect().width:0;P.style.setProperty("--oc-editor-gutter-width",`${T}px`)},[]);return l.useEffect(()=>{y.current=t},[t]),l.useEffect(()=>{x.current=e},[e]),l.useEffect(()=>{g.current=c,w.current=d},[c,d]),l.useEffect(()=>{v.current=h},[h]),l.useEffect(()=>{S.current=p,I(p)},[p,I]),l.useEffect(()=>{if(!b.current)return;const k=(()=>{if(typeof document>"u")return null;const N=document.querySelector('meta[name="csp-nonce"]')?.getAttribute("content");if(N)return N;const D=window.__OPENCHAMBER_CSP_NONCE__;return typeof D=="string"&&D.length>0?D:null})(),P=Ub.create({doc:y.current,extensions:[...k?[or.cspNonce.of(k)]:[],Wb({fixed:!0}),Mp.of(rm(i)),Kb(),Hb.of(" "),Mc.of([Gb,...qb,...Qb]),or.updateListener.of(N=>{R(N.view),(N.viewportChanged||N.geometryChanged)&&I(S.current);const D=am(N.startState),T=am(N.state);if(D!==T&&v.current?.(T),!N.docChanged)return;const M=N.state.doc.toString();y.current=M,x.current(M),I(S.current)}),Rp.of(or.editable.of(!a)),Ep.of(n??[]),Fp.of(Vp(o)),Op.of(Bp(p,A.current)),Lp.of(m?[im({top:!0}),Mc.of($p(om))]:[])]});return f.current=new or({state:P,parent:b.current}),id(f.current,f.current.state.doc.length,200),f.current.requestMeasure(),requestAnimationFrame(()=>{R(f.current),I(S.current)}),f.current&&g.current?.(f.current),()=>{w.current?.(),f.current?.destroy(),f.current=null,C([])}},[S,R,I]),l.useEffect(()=>{const k=f.current;k&&(k.dispatch({effects:[Mp.reconfigure(rm(i)),Rp.reconfigure(or.editable.of(!a)),Ep.reconfigure(n??[]),Fp.reconfigure(Vp(o)),Op.reconfigure(Bp(p,A.current)),Lp.reconfigure(m?[im({top:!0}),Mc.of($p(om))]:[])]}),id(k,k.state.doc.length,200),k.requestMeasure(),requestAnimationFrame(()=>{R(k),I(S.current)}))},[n,o,i,a,p,m,R,I]),l.useEffect(()=>{const k=f.current;!k||m===!1||(u?(Uk(k),requestAnimationFrame(()=>{_k(k.dom)})):Wk(k))},[u,m]),l.useEffect(()=>{const k=f.current;if(!k)return;const P=k.state.doc.toString();P!==t&&(k.dispatch({changes:{from:0,to:P.length,insert:t}}),id(k,k.state.doc.length,300),k.requestMeasure(),requestAnimationFrame(()=>R(k)))},[t,R]),s.jsxs(s.Fragment,{children:[s.jsx("div",{ref:b,className:pe("h-full w-full","[&_.cm-editor]:h-full [&_.cm-editor]:w-full","[&_.cm-scroller]:font-mono [&_.cm-scroller]:text-[var(--text-code)] [&_.cm-scroller]:leading-6","[&_.cm-lineNumbers]:text-[var(--tools-edit-line-number)]",r)}),j.map(k=>vo.createPortal(k.content,k.container,k.id))]})}const Hk=(t,e)=>{if(!e)return null;const n=Number.parseInt(t.trim(),10);return!Number.isFinite(n)||n<1?null:Math.min(n,e.state.doc.lines)},zp=(t,e)=>{const n=t.state.doc.lineAt(e.main.head);return{lineNumber:n.number,character:e.main.head-n.from+1,selection:e}},_p=(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:sy.cursor(i),effects:or.scrollIntoView(i,{y:"center"})})};function Gk({open:t,onOpenChange:e,view:n,variant:r="overlay"}){const{t:a}=ut(),[i,o]=l.useState(""),c=l.useRef(null),d=l.useRef(!1),p=l.useRef(null),m=l.useRef(null),u=l.useMemo(()=>Hk(i,n),[i,n]);l.useEffect(()=>{!t||!n||(d.current=!1,c.current=zp(n,n.state.selection),o(""))},[t,n]),l.useEffect(()=>{t&&window.requestAnimationFrame(()=>{m.current?.focus(),m.current?.select()})},[t]),l.useEffect(()=>{if(!(!t||!n||!c.current)){if(u===null){const{selection:x}=c.current;n.dispatch({selection:x,effects:or.scrollIntoView(x.main.from,{y:"center"})});return}_p(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:or.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,_p(n,u,c.current.character),e(!1),n.focus())},[u,e,n]);l.useEffect(()=>{if(!t)return;const x=w=>{const v=p.current,S=w.target;!v||!(S instanceof Node)||v.contains(S)||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 y=l.useMemo(()=>{if(!n)return a("goToLineDialog.helper.editorUnavailable");if(u===null){const x=c.current??zp(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(Vt,{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(je,{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:pe("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(Vt,{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:y})]})})}const Zd=t=>{const e=nt.c(11),{currentMode:n,onToggle:r}=t,a=n==="preview",i=a?"Switch to edit mode":"Switch to preview mode",o=a?"Edit":"Preview";let c;e[0]!==a?(c=a?s.jsx(Au,{className:"size-4","aria-hidden":"true"}):s.jsx(Pu,{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(St,{asChild:!0,children:s.jsx(je,{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(Ct,{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},eu=ny.define(ry);function qk(t){const e=t.trim().toLowerCase();switch(e){case"bash":case"sh":case"zsh":case"shell":case"shellsession":case"console":return eu;case"json":case"jsonc":case"json5":return zh().language;case"js":case"javascript":return Ii().language;case"jsx":return Ii({jsx:!0}).language;case"ts":case"typescript":return Ii({typescript:!0}).language;case"tsx":return Ii({typescript:!0,jsx:!0}).language;case"html":return Dd().language;case"css":return Vh().language;case"py":case"python":return Bh().language;case"heex":case"eex":case"leex":return Dd().language;default:return _h.matchLanguageName(Uh,e,!0)}}const bx=t=>t.split("/").pop()?.toLowerCase()??"",Qk=t=>{const e=bx(t);return e?_h.matchFilename(Uh,e):null},Jk=()=>fo(Td.define([{tag:[rt.heading1,rt.heading2,rt.heading3,rt.heading4,rt.heading5,rt.heading6],fontWeight:"600"},{tag:rt.strong,fontWeight:"600"},{tag:rt.emphasis,fontStyle:"italic"},{tag:rt.strikethrough,textDecoration:"line-through"},{tag:[rt.link,rt.url],color:"var(--markdown-link, currentColor)",textDecoration:"underline"},{tag:rt.monospace,color:"var(--markdown-inline-code, currentColor)",backgroundColor:"var(--markdown-inline-code-bg, transparent)"},{tag:rt.quote,color:"var(--markdown-blockquote, currentColor)",fontStyle:"italic"},{tag:rt.list,color:"color-mix(in srgb, var(--muted-foreground) 40%, var(--foreground) 60%)"},{tag:rt.heading,color:"var(--markdown-heading1, currentColor)"}]));function yx(t){const e=t.toLowerCase();switch(bx(e)){case"makefile":case"gnumakefile":return eu}const r=e.lastIndexOf("."),a=r>=0?e.slice(r+1):"";switch(a){case"ts":case"tsx":case"mts":case"cts":return Ii({typescript:!0,jsx:a==="tsx"});case"js":case"jsx":case"mjs":case"cjs":return Ii({typescript:!1,jsx:a==="jsx"});case"json":case"jsonc":case"json5":case"jsonl":case"ndjson":case"geojson":return zh();case"css":case"scss":case"sass":case"less":return Vh();case"html":case"htm":return Dd();case"md":case"mdx":case"markdown":case"mdown":case"mkd":return[ay({codeLanguages:qk}),Jk()];case"sh":case"bash":case"zsh":case"fish":case"env":return eu;case"py":case"pyw":case"pyi":return Bh();default:return null}}async function Yk(t){const e=Qk(t);if(!e)return null;if(e.support)return e.support;try{return await e.load()}catch{return null}}function tu(t){const e=t.metadata.variant==="dark",n=t.config?.fonts?.mono||"monospace",r=t.colors.syntax.highlights||{},a=t.colors.syntax.tokens||{},i=or.theme({"&":{backgroundColor:"var(--background)",color:t.colors.syntax.base.foreground,fontSize:"var(--text-code)",lineHeight:"1.5rem",position:"relative"},".cm-scroller":{fontFamily:n,backgroundColor:"var(--background)"},".cm-comment":{color:t.colors.syntax.base.comment},".cm-keyword":{color:t.colors.syntax.base.keyword},".cm-string":{color:t.colors.syntax.base.string},".cm-string-2":{color:a.stringEscape||t.colors.syntax.base.string},".cm-number":{color:t.colors.syntax.base.number},".cm-operator":{color:t.colors.syntax.base.operator},".cm-punctuation":{color:a.punctuation||t.colors.syntax.base.comment},".cm-atom":{color:a.boolean||t.colors.syntax.base.number},".cm-builtin":{color:a.functionCall||t.colors.syntax.base.function},".cm-def":{color:a.variableGlobal||t.colors.syntax.base.variable},".cm-attribute":{color:a.variableOther||a.variableProperty||t.colors.syntax.base.operator},".cm-meta":{color:t.colors.syntax.base.comment},".cm-property":{color:a.variableProperty||t.colors.syntax.base.keyword},".cm-variable":{color:t.colors.syntax.base.variable},".cm-variable-2":{color:a.variableOther||t.colors.syntax.base.function},".cm-variable-3":{color:a.variableGlobal||t.colors.syntax.base.type},".cm-tag":{color:a.tag||t.colors.syntax.base.keyword},".cm-link":{color:a.url||t.colors.syntax.base.keyword,textDecoration:"underline"},".cm-content":{caretColor:t.colors.interactive.cursor},".cm-cursor, .cm-dropCursor":{borderLeftColor:t.colors.interactive.cursor},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, ::selection":{backgroundColor:t.colors.interactive.selection},".cm-gutters":{backgroundColor:"var(--background)",color:r.lineNumber||t.colors.syntax.base.comment,borderRight:`1px solid ${t.colors.interactive.border}`,position:"sticky",paddingRight:"8px",left:0,zIndex:2,boxShadow:"0 0 0 var(--background)"},".cm-gutter":{backgroundColor:"var(--background)"},".cm-gutterElement":{backgroundColor:"var(--background)"},".cm-lineNumbers":{backgroundColor:"var(--background)"},".cm-lineNumbers .cm-gutterElement":{paddingLeft:"8px",paddingRight:"8px",minWidth:"42px"},".cm-activeLineGutter":{color:r.lineNumberActive||t.colors.syntax.base.foreground},".cm-activeLine":{backgroundColor:t.colors.surface.overlay},".cm-panels":{backgroundColor:"transparent",color:t.colors.surface.foreground,position:"absolute",top:"0",right:"0",left:"auto",width:"auto",zIndex:10,pointerEvents:"none"},".cm-panels-top":{borderBottom:"none",position:"absolute",top:"6px",right:"14px",left:"auto",width:"auto"},".cm-panel.cm-search":{pointerEvents:"auto",padding:"4px",backgroundColor:`color-mix(in srgb, ${t.colors.surface.elevated} 85%, transparent)`,border:`1px solid ${t.colors.interactive.border}`,borderRadius:"10px",boxShadow:`0 2px 8px color-mix(in srgb, ${t.colors.surface.background} 60%, transparent)`,width:"auto",minWidth:"360px",maxWidth:"480px"},".cm-search":{display:"flex",flexWrap:"wrap",alignItems:"center",gap:"0",width:"100%",color:t.colors.surface.foreground,fontFamily:"inherit",fontSize:"13px",lineHeight:"1"},".cm-search br":{display:"none"},".cm-search .cm-textfield":{appearance:"none",height:"26px",margin:0,padding:"0 8px",borderRadius:"6px !important",border:`1px solid ${t.colors.interactive.border}`,backgroundColor:t.colors.surface.background,color:t.colors.surface.foreground,fontFamily:"inherit",fontSize:"12px",lineHeight:"1",outline:"none",transition:"border-color 150ms ease"},".cm-search .cm-textfield::placeholder":{color:t.colors.surface.mutedForeground,opacity:1},".cm-search .cm-textfield:focus":{borderColor:t.colors.primary.base},'.cm-search .cm-textfield[name="search"]':{order:1,flex:"1 1 120px",maxWidth:"calc(100% - 142px)",minWidth:"100px"},".cm-search label":{order:2,display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:0,marginLeft:"1px",padding:0,borderRadius:"4px",border:"1px solid transparent",backgroundColor:"transparent",color:"transparent",cursor:"pointer",userSelect:"none",fontSize:"1px",lineHeight:"0",overflow:"hidden",position:"relative",transition:"background-color 120ms ease, border-color 120ms ease"},".cm-search label:hover":{backgroundColor:t.colors.interactive.hover},'.cm-search label:has(input[type="checkbox"]:checked)':{backgroundColor:t.colors.interactive.hover,borderColor:t.colors.interactive.border},'.cm-search [type="checkbox"]':{appearance:"none",WebkitAppearance:"none",width:"0",height:"0",margin:"0",padding:"0",border:"none",position:"absolute",opacity:"0",pointerEvents:"none"},".cm-search label::after":{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",fontSize:"13px",fontWeight:"600",lineHeight:"1",fontFamily:"inherit",color:t.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search label:hover::after":{color:t.colors.surface.foreground},'.cm-search label:has(input[type="checkbox"]:checked)::after':{color:t.colors.surface.foreground},'.cm-search label:has(input[name="case"])::after':{content:'"Aa"',fontSize:"12px",letterSpacing:"-0.5px"},'.cm-search label:has(input[name="re"])::after':{content:'".*"',fontSize:"13px",fontFamily:"monospace"},'.cm-search label:has(input[name="word"])::after':{content:'"ab"',fontSize:"12px",textDecoration:"underline",textUnderlineOffset:"2px"},".cm-search .cm-search-message":{order:3,color:t.colors.surface.mutedForeground,backgroundColor:"transparent",border:"none",borderRadius:"0",padding:"0 6px",fontSize:"11px",whiteSpace:"nowrap",lineHeight:"26px"},".cm-search .cm-button":{appearance:"none",WebkitAppearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:0,marginLeft:"1px",padding:0,borderRadius:"4px",border:"none",backgroundColor:"transparent",backgroundImage:"none",color:"transparent",cursor:"pointer",fontSize:"1px",fontWeight:"400",lineHeight:"0",overflow:"hidden",position:"relative",boxShadow:"none",transition:"background-color 120ms ease"},".cm-search .cm-button::after":{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",fontSize:"15px",lineHeight:"1",color:t.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search .cm-button:hover":{backgroundColor:t.colors.interactive.hover},".cm-search .cm-button:hover::after":{color:t.colors.surface.foreground},".cm-search .cm-button:active":{backgroundColor:t.colors.interactive.active},".cm-search .cm-button:focus-visible":{outline:"none",boxShadow:`0 0 0 1px ${t.colors.interactive.focusRing}`},".cm-search .cm-button:disabled":{opacity:.4,cursor:"default",pointerEvents:"none"},'.cm-search .cm-button[name="prev"]':{order:21,marginTop:"2px"},'.cm-search .cm-button[name="prev"]::after':{content:'"↑"'},'.cm-search .cm-button[name="next"]':{order:22,marginTop:"2px"},'.cm-search .cm-button[name="next"]::after':{content:'"↓"'},'.cm-search .cm-button[name="select"]':{order:23,marginTop:"2px"},'.cm-search .cm-button[name="select"]::after':{content:'"≡"',fontSize:"17px"},'.cm-panel.cm-search button[name="close"]':{order:5,appearance:"none",WebkitAppearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:"0 0 0 auto",padding:"0",borderRadius:"4px",border:"none",backgroundColor:"transparent",backgroundImage:"none",color:t.colors.surface.mutedForeground,cursor:"pointer",fontSize:"16px",lineHeight:"1",boxShadow:"none",position:"relative",overflow:"visible",transition:"background-color 120ms ease, color 120ms ease"},'.cm-panel.cm-search button[name="close"]:hover':{backgroundColor:t.colors.interactive.hover,color:t.colors.surface.foreground},'.cm-search .cm-button[name="replace"]':{order:24,marginTop:"2px"},'.cm-search .cm-button[name="replace"]::after':{content:'"⇄"'},'.cm-search .cm-button[name="replaceAll"], .cm-search .cm-button[name="replace-all"]':{order:25,marginTop:"2px"},'.cm-search .cm-button[name="replaceAll"]::after, .cm-search .cm-button[name="replace-all"]::after':{content:'"⇉"'},'.cm-search .cm-textfield[name="replace"]':{order:20,flex:"1 1 100%",maxWidth:"calc(100% - 142px)",minWidth:"80px",marginTop:"2px"},".cm-searchMatch":{backgroundColor:t.colors.status.infoBackground,boxShadow:`inset 0 0 0 1px ${t.colors.status.infoBorder}`,borderRadius:"2px"},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:t.colors.interactive.selection,color:t.colors.interactive.selectionForeground,boxShadow:`inset 0 0 0 1px ${t.colors.interactive.borderFocus}`},"&.cm-focused":{outline:"none"}},{dark:e}),o=Td.define([{tag:[rt.comment,rt.docComment,rt.meta,rt.documentMeta],class:"cm-comment"},{tag:[rt.keyword,rt.controlKeyword,rt.moduleKeyword,rt.definitionKeyword,rt.modifier],class:"cm-keyword"},{tag:[rt.operatorKeyword,rt.operator,rt.derefOperator,rt.updateOperator,rt.definitionOperator,rt.typeOperator,rt.controlOperator,rt.logicOperator,rt.bitwiseOperator,rt.arithmeticOperator,rt.compareOperator],class:"cm-operator"},{tag:[rt.punctuation,rt.separator,rt.bracket,rt.paren,rt.brace,rt.squareBracket,rt.angleBracket],class:"cm-punctuation"},{tag:[rt.string,rt.regexp,rt.attributeValue,rt.special(rt.string),rt.monospace],class:"cm-string"},{tag:rt.escape,class:"cm-string-2"},{tag:[rt.number,rt.bool,rt.atom,rt.null,rt.self],class:"cm-number"},{tag:[rt.function(rt.variableName),rt.function(rt.definition(rt.variableName)),rt.function(rt.propertyName),rt.standard(rt.variableName),rt.special(rt.variableName)],class:"cm-builtin"},{tag:rt.definition(rt.variableName),class:"cm-def"},{tag:[rt.variableName,rt.local(rt.variableName),rt.constant(rt.variableName),rt.literal],class:"cm-variable"},{tag:rt.propertyName,class:"cm-property"},{tag:rt.attributeName,class:"cm-attribute"},{tag:[rt.className,rt.typeName,rt.namespace],class:"cm-variable-3"},{tag:[rt.tagName,rt.labelName,rt.annotation,rt.macroName],class:"cm-tag"},{tag:rt.link,class:"cm-link"},{tag:[rt.heading,rt.heading1,rt.heading2,rt.heading3,rt.heading4,rt.heading5,rt.heading6],class:"cm-keyword"}]),c=Td.define([{tag:[rt.comment,rt.docComment,rt.meta,rt.documentMeta],color:t.colors.syntax.base.comment},{tag:[rt.keyword,rt.controlKeyword,rt.moduleKeyword,rt.definitionKeyword,rt.modifier],color:t.colors.syntax.base.keyword},{tag:[rt.operatorKeyword,rt.operator,rt.derefOperator,rt.updateOperator,rt.definitionOperator,rt.typeOperator,rt.controlOperator,rt.logicOperator,rt.bitwiseOperator,rt.arithmeticOperator,rt.compareOperator],color:t.colors.syntax.base.operator},{tag:[rt.string,rt.regexp,rt.attributeValue,rt.special(rt.string),rt.monospace],color:t.colors.syntax.base.string},{tag:rt.escape,color:a.stringEscape||t.colors.syntax.base.string},{tag:[rt.number,rt.bool,rt.atom,rt.null,rt.self],color:t.colors.syntax.base.number},{tag:[rt.function(rt.variableName),rt.function(rt.definition(rt.variableName)),rt.function(rt.propertyName),rt.standard(rt.variableName),rt.special(rt.variableName)],color:t.colors.syntax.base.function},{tag:rt.definition(rt.variableName),color:a.variableGlobal||t.colors.syntax.base.variable},{tag:[rt.variableName,rt.local(rt.variableName),rt.constant(rt.variableName),rt.literal],color:t.colors.syntax.base.variable},{tag:rt.propertyName,color:a.variableProperty||t.colors.syntax.base.variable},{tag:rt.attributeName,color:a.variableOther||t.colors.syntax.base.variable},{tag:[rt.className,rt.typeName,rt.namespace],color:t.colors.syntax.base.type},{tag:[rt.tagName,rt.labelName,rt.annotation,rt.macroName],color:a.tag||t.colors.syntax.base.keyword},{tag:rt.link,color:a.url||t.colors.syntax.base.function,textDecoration:"underline"},{tag:[rt.punctuation,rt.separator,rt.bracket,rt.paren,rt.brace,rt.squareBracket,rt.angleBracket],color:a.punctuation||t.colors.syntax.base.comment}]);return[i,fo(iy,{fallback:!0}),fo(oy),fo(o),fo(c)]}const Xk=t=>{const e=wn(t);if(!e)return"";if(e==="/"||/^[A-Za-z]:\/$/.test(e))return e;const n=e.lastIndexOf("/");if(n<0)return e;if(n===0)return"/";const r=e.slice(0,n);return/^[A-Za-z]:$/.test(r)?`${r}/`:r},Zk=t=>{const e=nt.c(8),{label:n,iconDataUrl:r}=t,[a,i]=l.useState(!1);let o;e[0]!==n?(o=n.trim().slice(0,1).toUpperCase()||"?",e[0]=n,e[1]=o):o=e[1];const c=o;if(r&&!a){let m;e[2]===Symbol.for("react.memo_cache_sentinel")?(m=()=>i(!0),e[2]=m):m=e[2];let u;return e[3]!==r?(u=s.jsx("img",{src:r,alt:"",className:"h-4 w-4 rounded-sm",onError:m}),e[3]=r,e[4]=u):u=e[4],u}let d;e[5]===Symbol.for("react.memo_cache_sentinel")?(d=pe("h-4 w-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=d):d=e[5];let p;return e[6]!==c?(p=s.jsx("span",{className:d,children:c}),e[6]=c,e[7]=p):p=e[7],p},e3=t=>t.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),wn=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+/g,"/");n&&!r.startsWith("//")&&(r=`/${r}`);const a=r==="/",i=/^[A-Za-z]:\/$/.test(r);return!a&&!i&&(r=r.replace(/\/+$/,"")),r},t3=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),Up=t=>/^[A-Za-z]:\//.test(t)?t.toLowerCase():t,rc=(t,e)=>{const n=wn(e),r=wn(t);if(!n||!r)return!1;const a=Up(n),i=Up(r);return i===a||i.startsWith(`${a}/`)},Wp=(t,e)=>{const n=wn(e),r=wn(t);if(!rc(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},su=(t,e)=>{if(!e)return"";const n=wn(e);if(!t||!rc(n,t))return n;const r=n.slice(t.length);return r.startsWith("/")?r.slice(1):r},s3=new Set(["node_modules"]),n3=t=>{const e=nt.c(3),{status:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={open:"var(--status-info)",modified:"var(--status-warning)","git-modified":"var(--status-warning)","git-added":"var(--status-success)","git-deleted":"var(--status-error)"},e[0]=r):r=e[0];const a=r[n];let i;return e[1]!==a?(i=s.jsx("span",{className:"h-2 w-2 rounded-full",style:{backgroundColor:a}}),e[1]=a,e[2]=i):i=e[2],i},r3=t=>s3.has(t),a3=t=>{const e=wn(t);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},i3=t=>{const n=(t instanceof Error?t.message:String(t??"")).toLowerCase();return n.includes("is a directory")||n.includes("eisdir")},oo=2e5,vx="openchamber:files:auto-save-enabled",o3=()=>{if(typeof window>"u")return!0;try{return window.localStorage.getItem(vx)!=="false"}catch{return!0}},wx=(t,e)=>s.jsx(Pr,{filePath:t,extension:e}),l3=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="md"||e==="markdown"},c3=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="json"||e==="jsonc"||e==="json5"||e==="geojson"},od=t=>{if(!t)return!1;const e=t.toLowerCase().split(".").pop();return e==="html"||e==="htm"},d3=t=>{const e=nt.c(62),{node:n,root:r,isExpanded:a,isActive:i,isMobile:o,alwaysShowActions:c,status:d,badge:p,permissions:m,downloadFile:u,contextMenuPath:h,setContextMenuPath:b,onSelect:f,onToggle:y,onRevealPath:x,onOpenDialog:g}=t,{t:w}=ut(),v=n.type==="directory",{canRename:S,canCreateFile:A,canCreateFolder:j,canDelete:C,canReveal:I}=m;let R;e[0]!==A||e[1]!==j||e[2]!==C||e[3]!==S||e[4]!==I||e[5]!==n.path||e[6]!==b?(R=ae=>{!S&&!A&&!j&&!C&&!I||(ae?.preventDefault(),b(n.path))},e[0]=A,e[1]=j,e[2]=C,e[3]=S,e[4]=I,e[5]=n.path,e[6]=b,e[7]=R):R=e[7];const k=R;let P;e[8]!==v||e[9]!==n||e[10]!==f||e[11]!==y?(P=()=>{v?y(n.path):f(n)},e[8]=v,e[9]=n,e[10]=f,e[11]=y,e[12]=P):P=e[12];const N=P;let D;e[13]!==n.path||e[14]!==b?(D=ae=>{ae.stopPropagation(),b(n.path)},e[13]=n.path,e[14]=b,e[15]=D):D=e[15];const T=D,M=o?void 0:k,$=o?void 0:k,F=i?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let V;e[16]!==F?(V=pe("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",F),e[16]=F,e[17]=V):V=e[17];let O;e[18]!==v||e[19]!==a||e[20]!==n.extension||e[21]!==n.path?(O=v?a?s.jsx(Su,{className:"h-4 w-4 flex-shrink-0 text-primary/60"}):s.jsx(ku,{className:"h-4 w-4 flex-shrink-0 text-primary/60"}):wx(n.path,n.extension),e[18]=v,e[19]=a,e[20]=n.extension,e[21]=n.path,e[22]=O):O=e[22];let L;e[23]!==n.name||e[24]!==n.path?(L=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:n.path,children:n.name}),e[23]=n.name,e[24]=n.path,e[25]=L):L=e[25];let W;e[26]!==v||e[27]!==d?(W=!v&&d&&s.jsx(n3,{status:d}),e[26]=v,e[27]=d,e[28]=W):W=e[28];let B;e[29]!==p||e[30]!==v?(B=v&&p&&s.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[p.modified>0&&s.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",p.modified]}),p.added>0&&s.jsxs("span",{className:"text-[var(--status-success)]",children:["+",p.added]})]}),e[29]=p,e[30]=v,e[31]=B):B=e[31];let ne;e[32]!==N||e[33]!==W||e[34]!==B||e[35]!==$||e[36]!==V||e[37]!==O||e[38]!==L?(ne=s.jsxs("button",{type:"button",onClick:N,onContextMenu:$,className:V,children:[O,L,W,B]}),e[32]=N,e[33]=W,e[34]=B,e[35]=$,e[36]=V,e[37]=O,e[38]=L,e[39]=ne):ne=e[39];let le;e[40]!==c||e[41]!==A||e[42]!==j||e[43]!==C||e[44]!==S||e[45]!==I||e[46]!==h||e[47]!==u||e[48]!==T||e[49]!==v||e[50]!==o||e[51]!==n||e[52]!==g||e[53]!==x||e[54]!==r||e[55]!==b||e[56]!==w?(le=(S||A||j||C||I)&&s.jsx("div",{className:pe("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(zs,{open:h===n.path,onOpenChange:ae=>b(ae?n.path:null),children:[s.jsx(Bs,{asChild:!0,children:s.jsx(je,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:T,children:s.jsx(Iu,{className:"h-4 w-4"})})}),s.jsxs(Vs,{align:"end",side:"bottom",onCloseAutoFocus:()=>b(null),children:[S&&s.jsxs($t,{onClick:ae=>{ae.stopPropagation(),g("rename",n)},children:[s.jsx(Yr,{className:"mr-2 h-4 w-4"})," ",w("sidebarFilesTree.menu.rename")]}),s.jsxs($t,{onClick:ae=>{ae.stopPropagation(),_n(n.path).then(ge=>{if(ge.ok){q.success(w("sidebarFilesTree.toast.pathCopied"));return}q.error(w("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(br,{className:"mr-2 h-4 w-4"})," ",w("sidebarFilesTree.menu.copyPath")]}),s.jsxs($t,{onClick:ae=>{ae.stopPropagation();const ge=su(r,n.path)||n.path;_n(ge).then(te=>{if(te.ok){q.success(w("filesView.toast.relativePathCopied"));return}q.error(w("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(Kh,{className:"mr-2 h-4 w-4"})," ",w("filesView.tree.menu.copyRelativePath")]}),!v&&u&&s.jsxs($t,{onClick:ae=>{ae.stopPropagation(),u(n.path)},children:[s.jsx(Qr,{className:"mr-2 h-4 w-4"})," ",w("sidebarFilesTree.menu.save")]}),I&&s.jsxs($t,{onClick:ae=>{ae.stopPropagation(),x(n.path)},children:[s.jsx(Fh,{className:"mr-2 h-4 w-4"})," ",w($u())]}),v&&(A||j)&&s.jsxs(s.Fragment,{children:[s.jsx(En,{}),A&&s.jsxs($t,{onClick:ae=>{ae.stopPropagation(),g("createFile",n)},children:[s.jsx(mc,{className:"mr-2 h-4 w-4"})," ",w("sidebarFilesTree.menu.newFile")]}),j&&s.jsxs($t,{onClick:ae=>{ae.stopPropagation(),g("createFolder",n)},children:[s.jsx(Ca,{className:"mr-2 h-4 w-4"})," ",w("sidebarFilesTree.menu.newFolder")]})]}),C&&s.jsxs(s.Fragment,{children:[s.jsx(En,{}),s.jsxs($t,{onClick:ae=>{ae.stopPropagation(),g("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(sn,{className:"mr-2 h-4 w-4"})," ",w("sidebarFilesTree.menu.delete")]})]})]})]})}),e[40]=c,e[41]=A,e[42]=j,e[43]=C,e[44]=S,e[45]=I,e[46]=h,e[47]=u,e[48]=T,e[49]=v,e[50]=o,e[51]=n,e[52]=g,e[53]=x,e[54]=r,e[55]=b,e[56]=w,e[57]=le):le=e[57];let ee;return e[58]!==ne||e[59]!==le||e[60]!==M?(ee=s.jsxs("div",{className:"group relative flex items-center",onContextMenu:M,children:[ne,le]}),e[58]=ne,e[59]=le,e[60]=M,e[61]=ee):ee=e[61],ee},jx=({mode:t="full"})=>{const{t:e}=ut(),{files:n,runtime:r}=Gn(),{currentTheme:a,availableThemes:i,lightThemeId:o,darkThemeId:c}=Rr(),{isMobile:d,isTablet:p,screenWidth:m}=un(),u=d||p,h=xc(),b=Ou(),f=Xr()??"",y=wn(f.trim()),x=d||t!=="editor-only",g=t==="editor-only"&&!d,w=Lu(Ce=>Ce.searchFiles),v=gc(f),[S,A]=l.useState(""),j=bc(S,200),C=l.useRef(null),[I,R]=l.useState(!1),[k,P]=l.useState(!0),[N,D]=l.useState(!1),[T,M]=l.useState(!1),[$,F]=l.useState(!1),V=l.useRef(null),O=l.useRef(0),L=l.useCallback(Ce=>{O.current=Math.max(0,O.current+(Ce?1:-1))},[]),W=l.useCallback(Ce=>Ce instanceof Element?Ce.closest('[data-slot="dropdown-menu-content"], [data-slot="dropdown-menu-item"]')!==null:!1,[]);l.useEffect(()=>{if(!$)return;const Ce=qe=>{O.current>0||W(qe.target)||V.current&&!V.current.contains(qe.target)&&F(!1)};return document.addEventListener("mousedown",Ce),()=>document.removeEventListener("mousedown",Ce)},[W,$]);const[B,ne]=l.useState("edit"),[le,ee]=l.useState("edit"),[ae,ge]=l.useState("tree"),[te,E]=l.useState("edit"),z=l.useRef({}),J=l.useRef({}),H=l.useRef({}),re=l.useMemo(()=>i.find(Ce=>Ce.metadata.id===o)??Wi(!1),[i,o]),ce=l.useMemo(()=>i.find(Ce=>Ce.metadata.id===c)??Wi(!0),[i,c]);l.useEffect(()=>{Ki(re),Ki(ce)},[re,ce]);const Ne=l.useMemo(()=>[],[]),me=Xn(Ce=>y?Ce.byRoot[y]?.openPaths??Ne:Ne),we=Xn(Ce=>y?Ce.byRoot[y]?.selectedPath??null:null),_=Xn(Ce=>y?Ce.byRoot[y]?.expandedPaths??Ne:Ne),ue=Xn(Ce=>Ce.addOpenPath),Q=Xn(Ce=>Ce.removeOpenPath),oe=Xn(Ce=>Ce.removeOpenPathsByPrefix),Z=Xn(Ce=>Ce.setSelectedPath),Ie=Xn(Ce=>Ce.toggleExpandedPath),Se=Xn(Ce=>Ce.expandPaths),Y=l.useCallback(Ce=>{const qe=wn(Ce),dt=qe.split("/"),bt=dt[dt.length-1]||qe,Pt=bt.includes(".")?bt.split(".").pop()?.toLowerCase():void 0;return{name:bt,path:qe,type:"file",extension:Pt}},[]),fe=l.useMemo(()=>me.map(Y),[me,Y]),ke=l.useMemo(()=>we??me[0]??null,[me,we]),xe=l.useMemo(()=>ke?Y(ke):null,[ke,Y]),he=xe?.path??"",Pe=!!(y&&he&&!rc(he,y)),Be=l.useMemo(()=>({allowOutsideWorkspace:t==="editor-only"&&Pe}),[t,Pe]),G=l.useRef(null),[be,De]=l.useState({left:!1,right:!1}),Ae=l.useCallback(()=>{const Ce=G.current;Ce&&De({left:Ce.scrollLeft>2,right:Ce.scrollLeft+Ce.clientWidth<Ce.scrollWidth-2})},[]);l.useEffect(()=>{const Ce=G.current;if(!Ce)return;Ae(),Ce.addEventListener("scroll",Ae,{passive:!0});const qe=new ResizeObserver(Ae);return qe.observe(Ce),()=>{Ce.removeEventListener("scroll",Ae),qe.disconnect()}},[Ae,fe.length]);const[ve,U]=l.useState({}),de=l.useRef(new Set),Re=l.useRef(new Set),Le=l.useRef(new Map),se=l.useRef(0),[ie,K]=l.useState([]),[_e,He]=l.useState(!1),[Ke,Ze]=l.useState(""),[Xe,mt]=l.useState(!1),[et,ct]=l.useState(null),[lt,ye]=l.useState(""),[Ge,$e]=l.useState(null),[Ve,tt]=l.useState(""),[Qe,ze]=l.useState(!1),ht=l.useRef(null),_t=l.useRef(null),[Kt,Ut]=l.useState("idle"),[jt,Dt]=l.useState(o3),[ts,it]=l.useState(!1),Yt=l.useRef(null),Qt=l.useRef(null),Xt=l.useRef(null),us=l.useRef(!1),ms=l.useRef(null),gs=l.useRef(null),ds=l.useRef(null),Ft=l.useRef(null),[Ue,Tt]=l.useState(0),At=l.useRef(null),vt=l.useRef({key:"",attempts:0});l.useEffect(()=>()=>{At.current!==null&&typeof window<"u"&&(window.cancelAnimationFrame(At.current),At.current=null)},[]);const[Rt,ns]=l.useState(null),[As,ft]=l.useState(null),[is,es]=l.useState(""),[Ts,Ls]=l.useState(!1),[X,pt]=l.useState(null),[wt,zt]=l.useState(!1),[ss,os]=l.useState(!1),[Ps,Ms]=l.useState(!1),We=!!n.writeFile,gt=!!n.createDirectory,Mt=!!n.rename,Et=!!n.delete,as=!!n.revealPath,st=Lr(Ce=>Ce.availableApps),Lt=Lr(Ce=>Ce.isCacheStale),ls=Lr(Ce=>Ce.initialize),rs=Lr(Ce=>Ce.loadInstalledApps);l.useEffect(()=>{ls()},[ls]);const Bt=l.useCallback(Ce=>{n.revealPath&&n.revealPath(Ce).catch(()=>{q.error(e("sidebarFilesTree.toast.revealFailed"))})},[n,e]),xs=l.useCallback(async Ce=>{if(!xe?.path||await r1(xe.path,Ce.id,Ce.appName)||await Wl(xe.path,Ce.appName))return;const bt=Xk(xe.path)||y;bt&&await Wl(bt,Ce.appName)||q.error(e("filesView.toast.openInAppFailed",{app:Ce.appName}))},[y,xe?.path,e]),mn=l.useCallback((Ce,qe)=>{ns(Ce),ft(qe),es(Ce==="rename"&&qe.name||""),Ls(!1)},[]),[js,xn]=l.useState(null),In=l.useRef(!1),an=l.useRef(null),[An,on]=l.useState(!1),ln=Te(Ce=>Ce.setMainTabGuard),fn=Te(Ce=>Ce.pendingFileNavigation),cr=Te(Ce=>Ce.setPendingFileNavigation),Vr=Te(Ce=>Ce.pendingFileFocusPath),Fe=Te(Ce=>Ce.setPendingFileFocusPath),Nt=Te(Ce=>Ce.shortcutOverrides),Ht=yt(Ce=>Ce.settingsDefaultFileViewerPreview);l.useEffect(()=>{const Ce=()=>{In.current=!1,an.current=null,on(!1)};return document.addEventListener("mouseup",Ce),()=>document.removeEventListener("mouseup",Ce)},[]),l.useEffect(()=>()=>{ms.current!==null&&window.clearTimeout(ms.current),gs.current!==null&&window.clearTimeout(gs.current)},[]);const cs=l.useCallback((Ce,qe)=>{const dt=Ce.split(`
48
- `),bt=Math.max(1,qe.start),Pt=Math.min(dt.length,qe.end);return bt>Pt?"":dt.slice(bt-1,Pt).join(`
49
- `)},[]),Xs=qu({source:"file",fileLabel:xe?.path??null,language:xe?.path&&Po(xe.path)||"text",getCodeForRange:Ce=>cs(Ke,sc(Ce)),toStoreRange:Ce=>({startLine:Ce.start,endLine:Ce.end}),fromDraftRange:Ce=>({start:Ce.startLine,end:Ce.endLine})}),{drafts:Zs,commentText:Gs,editingDraftId:en,setSelection:hn,saveComment:vn,cancel:dr,reset:Zr,startEdit:ea,deleteDraft:On}=Xs;l.useEffect(()=>{xn(null),Zr(),ln(null),tt(""),ze(!1)},[xe?.path,Zr,ln]),l.useEffect(()=>{hn(js)},[js,hn]),l.useEffect(()=>{if(!js&&!en)return;const Ce=dt=>{const bt=dt.target;bt.closest('[data-comment-input="true"]')||bt.closest('[data-comment-card="true"]')||bt.closest(".cm-gutterElement")||bt.closest("[data-sonner-toast]")||bt.closest("[data-sonner-toaster]")||(xn(null),dr())},qe=setTimeout(()=>{document.addEventListener("click",Ce)},100);return()=>{clearTimeout(qe),document.removeEventListener("click",Ce)}},[dr,en,js]);const Ln=l.useCallback((Ce,qe)=>{const dt=qe??js??void 0;qe&&xn(qe),vn(Ce,dt),xn(null)},[js,vn]),er=l.useCallback((Ce,qe)=>{const dt=qe.filter(bt=>bt&&typeof bt.name=="string"&&bt.name.length>0).filter(bt=>h||!bt.name.startsWith(".")).filter(bt=>b||!r3(bt.name)).map(bt=>{const Pt=bt.name,qt=wn(bt.path||""),Ns=qt?t3(qt)?qt:wn(`${Ce}/${qt}`):wn(`${Ce}/${Pt}`),nn=bt.isDirectory?"directory":"file",nr=nn==="file"&&Pt.includes(".")?Pt.split(".").pop()?.toLowerCase():void 0;return{name:Pt,path:Ns,type:nn,extension:nr}});return e3(dt)},[b,h]),bn=l.useCallback(async Ce=>{const qe=wn(Ce.trim());if(!qe||de.current.has(qe)||Re.current.has(qe))return;Re.current=new Set(Re.current),Re.current.add(qe);const dt=se.current+1;se.current=dt,Le.current=new Map(Le.current),Le.current.set(qe,dt);const bt=()=>Le.current.get(qe)===dt,Pt=!b;await(r.isDesktop?n.listDirectory(qe,{respectGitignore:Pt}).then(Ns=>Ns.entries.map(nn=>({name:nn.name,path:nn.path,isDirectory:nn.isDirectory}))):Dn.listLocalDirectory(qe,{respectGitignore:Pt}).then(Ns=>Ns.map(nn=>({name:nn.name,path:nn.path,isDirectory:nn.isDirectory})))).then(Ns=>{if(!bt())return;const nn=er(qe,Ns);de.current=new Set(de.current),de.current.add(qe),U(nr=>({...nr,[qe]:nn}))}).catch(()=>{bt()&&U(Ns=>({...Ns,[qe]:Ns[qe]??[]}))}).finally(()=>{bt()&&(Le.current=new Map(Le.current),Le.current.delete(qe),Re.current=new Set(Re.current),Re.current.delete(qe))})},[n,er,r.isDesktop,b]),qn=l.useCallback(async()=>{y&&(de.current=new Set,Re.current=new Set,Le.current=new Map,U(Ce=>Object.keys(Ce).length===0?Ce:{}),await bn(y))},[bn,y]),$n=l.useCallback(async Ce=>{if(!Ce){await qn();return}const qe=wn(Ce);de.current=new Set(de.current),de.current.delete(qe),Re.current=new Set(Re.current),Re.current.delete(qe),await bn(qe)},[bn,qn]),zr=l.useRef(""),_r=l.useRef("");l.useEffect(()=>{if(!y)return;const Ce=`${y}|h${h?"1":"0"}|g${b?"1":"0"}`,qe=zr.current!==y,dt=_r.current!==Ce;!qe&&!dt||(qe&&(zr.current=y,Ze(""),ct(null),ye(""),$e(null),R(!1)),dt&&(_r.current=Ce,de.current=new Set,Re.current=new Set,Le.current=new Map,U(bt=>Object.keys(bt).length===0?bt:{}),bn(y)))},[bn,y,b,h]),l.useEffect(()=>{if(!n.listDirectory)return;const Ce=()=>{if(!document.hidden&&_.length>0)for(const qe of _)$n(qe)};return document.addEventListener("visibilitychange",Ce),()=>document.removeEventListener("visibilitychange",Ce)},[_,n.listDirectory,$n]),l.useEffect(()=>{if(!n.listDirectory||_.length===0)return;const Ce=setInterval(()=>{if(!document.hidden)for(const qe of _)$n(qe)},8e3);return()=>clearInterval(Ce)},[_,n.listDirectory,$n]);const Ia=l.useCallback(async Ce=>{if(Ce?.preventDefault(),!As||!Rt)return;Ls(!0);const qe=()=>{ns(null)},dt=Pt=>{q.error(Pt)},bt=()=>{Ls(!1)};if(Rt==="createFile"){if(!is.trim()){dt(e("sidebarFilesTree.toast.filenameRequired")),bt();return}if(!n.writeFile){dt(e("sidebarFilesTree.toast.writeNotSupported")),bt();return}const Pt=As.path,qt=Pt?`${Pt}/`:"",Ns=wn(`${qt}${is.trim()}`);await n.writeFile(Ns,"").then(async nn=>{nn.success&&(q.success(e("sidebarFilesTree.toast.fileCreated")),await $n(Pt)),qe()}).catch(()=>dt(e("sidebarFilesTree.toast.operationFailed"))).finally(bt);return}if(Rt==="createFolder"){if(!is.trim()){dt(e("sidebarFilesTree.toast.folderNameRequired")),bt();return}const Pt=As.path,qt=Pt?`${Pt}/`:"",Ns=wn(`${qt}${is.trim()}`);await n.createDirectory(Ns).then(async nn=>{nn.success&&(q.success(e("sidebarFilesTree.toast.folderCreated")),await $n(Pt)),qe()}).catch(()=>dt(e("sidebarFilesTree.toast.operationFailed"))).finally(bt);return}if(Rt==="rename"){if(!is.trim()){dt(e("sidebarFilesTree.toast.nameRequired")),bt();return}if(!n.rename){dt(e("sidebarFilesTree.toast.renameNotSupported")),bt();return}const Pt=As.path,qt=Pt.split("/").slice(0,-1).join("/"),Ns=qt?`${qt}/`:"",nn=wn(`${Ns}${is.trim()}`);await n.rename(Pt,nn).then(async nr=>{nr.success&&(q.success(e("sidebarFilesTree.toast.renamedSuccessfully")),await $n(qt),y&&oe(y,Pt),(xe?.path===Pt||xe?.path.startsWith(`${Pt}/`))&&(y&&Z(y,null),Ze(""),ct(null),ye(""),$e(null),d&&R(!1))),qe()}).catch(()=>dt(e("sidebarFilesTree.toast.operationFailed"))).finally(bt);return}if(Rt==="delete"){if(!n.delete){dt(e("sidebarFilesTree.toast.deleteNotSupported")),bt();return}const Pt=As.path,qt=Pt.split("/").slice(0,-1).join("/");await n.delete(Pt).then(async Ns=>{Ns.success&&(q.success(e("sidebarFilesTree.toast.deletedSuccessfully")),await $n(qt),y&&oe(y,Pt),(xe?.path===Pt||xe?.path.startsWith(`${Pt}/`))&&(y&&Z(y,null),Ze(""),ct(null),ye(""),$e(null),d&&R(!1))),qe()}).catch(()=>dt(e("sidebarFilesTree.toast.operationFailed"))).finally(bt);return}bt()},[Rt,As,is,n,$n,d,oe,y,xe?.path,Z,e]);l.useEffect(()=>{if(!f){K([]),He(!1);return}const Ce=j.trim();if(!Ce){K([]),He(!1);return}let qe=!1;return He(!0),w(f,Ce,150,{includeHidden:h,respectGitignore:!b,type:"file"}).then(dt=>{if(qe)return;const Pt=dt.filter(qt=>b||!a3(qt.path)).map(qt=>({name:qt.name,path:wn(qt.path),type:"file",extension:qt.extension,relativePath:qt.relativePath}));K(Pt)}).catch(()=>{qe||K([])}).finally(()=>{qe||He(!1)}),()=>{qe=!0}},[f,j,w,h,b]);const Aa=l.useCallback(async(Ce,qe)=>{if(n.readFile)return(await n.readFile(Ce,qe)).content??"";const dt=new URLSearchParams({path:Ce});qe?.allowOutsideWorkspace&&dt.set("allowOutsideWorkspace","true"),qe?.optional&&dt.set("optional","true");const bt=await fetch(`/api/fs/read?${dt.toString()}`,{cache:qe?.optional?"no-store":"default"});if(!bt.ok){const Pt=await bt.json().catch(()=>({error:bt.statusText}));throw new Error(Pt.error||e("filesView.error.readFileFailed"))}return bt.text()},[n,e]),ur=l.useCallback(async(Ce,qe)=>{if(n.statFile){const dt=await n.statFile(Ce,qe);return{path:dt.path,size:dt.size,mtimeMs:dt.mtimeMs}}return null},[n]),tr=l.useMemo(()=>Ke.length>oo?`${Ke.slice(0,oo)}
50
-
51
- … truncated …`:Ke,[Ke]),qs=l.useMemo(()=>Ve!==tr,[Ve,tr]),Cn=l.useCallback(async()=>{if(!xe||!n.writeFile){q.error(e("filesView.toast.savingNotSupported"));return}qs&&(ze(!0),await n.writeFile(xe.path,Ve).then(Ce=>{if(!Ce?.success){q.error(e("filesView.toast.writeFileFailed"));return}Ze(Ve),ur(xe.path).then(qe=>{qe&&(_t.current=qe)}).catch(()=>{})}).catch(Ce=>{q.error(Ce instanceof Error?Ce.message:e("filesView.toast.saveFailed"))}).finally(()=>{ze(!1)}))},[Ve,n,qs,ur,xe,e]);l.useEffect(()=>{if(!qs){ln(null);return}const Ce=qe=>us.current?(us.current=!1,!0):(it(!0),Qt.current=qe,!1);return ln(Ce),()=>{Te.getState().mainTabGuard===Ce&&ln(null)}},[qs,ln]),l.useEffect(()=>{try{window.localStorage.setItem(vx,jt?"true":"false")}catch{}},[jt]),l.useEffect(()=>{jt||(Ut("idle"),ht.current&&(clearTimeout(ht.current),ht.current=null))},[jt]);const mi=1500;l.useEffect(()=>{const Ce=!!(xe&&n.writeFile);if(!(!jt||!qs||!Ce||Qe))return ht.current=setTimeout(()=>{Cn().then(()=>{Ut("saved"),setTimeout(()=>Ut("idle"),2e3)})},mi),()=>{ht.current&&(clearTimeout(ht.current),ht.current=null)}},[jt,Ve,qs,xe,n.writeFile,Qe,Cn]),l.useEffect(()=>{Ut("idle")},[xe?.path]),l.useEffect(()=>{const Ce=qe=>{Eu(qe)&&(qe.key.toLowerCase()==="s"?(qe.preventDefault(),ht.current&&(clearTimeout(ht.current),ht.current=null),Qe||Cn().then(()=>{Ut("saved"),setTimeout(()=>Ut("idle"),2e3)})):qe.key.toLowerCase()==="f"&&(qe.preventDefault(),M(!0)))};return window.addEventListener("keydown",Ce),()=>window.removeEventListener("keydown",Ce)},[Qe,Cn]);const Er=l.useCallback(async Ce=>{ct(null),ye(""),$e(null);const qe=Hi(Ce.path),dt=Ce.path.toLowerCase().endsWith(".svg");if(d&&R(!0),r.isDesktop&&qe&&!dt){Ze(""),tt(""),mt(!0);return}if(!r.isDesktop&&qe&&!dt){Ze(""),tt(""),$e(Ce.path),mt(!1);return}mt(!0);const bt={allowOutsideWorkspace:t==="editor-only"&&!!y&&!rc(Ce.path,y)};await Aa(Ce.path,bt).then(Pt=>{Ze(Pt),tt(Pt.length>oo?`${Pt.slice(0,oo)}
52
-
53
- … truncated …`:Pt),$e(Ce.path),ur(Ce.path,bt).then(qt=>{qt&&(_t.current=qt)}).catch(()=>{})}).catch(Pt=>{if(i3(Pt)){if(y&&Z(y,null),ct(null),Ze(""),tt(""),$e(null),_t.current=null,S.trim().length>0&&A(""),d&&R(!1),y){const Ns=[...Wp(Ce.path,y),Ce.path];Ns.length>0&&Se(y,Ns);for(const nn of Ns)de.current.has(nn)||bn(nn)}return}Ze(""),tt(""),ct(Pt instanceof Error?Pt.message:e("filesView.error.readFileFailed")),_t.current=null}).finally(()=>{mt(!1)})},[Se,d,bn,t,Aa,ur,y,r.isDesktop,S,Z,e]),da=l.useCallback(async(Ce,qe)=>{if(!y)return;const dt=Wp(Ce,y),bt=qe?[...dt,Ce]:dt;bt.length>0&&Se(y,bt);for(const Pt of bt)de.current.has(Pt)||await bn(Pt)},[Se,bn,y]),pi=l.useCallback((Ce,qe)=>{const dt=qe.findIndex(bt=>bt.path===Ce);return dt===-1||qe.length<=1?null:qe[dt+1]??qe[dt-1]??null},[]),Qn=l.useCallback(async Ce=>{if(us.current)us.current=!1;else if(qs){it(!0),Yt.current=Ce;return}y&&(Z(y,Ce.path),ue(y,Ce.path),da(Ce.path,!1)),ct(null),ye(""),Ze(""),tt(""),$e(null),d&&R(!0)},[ue,da,qs,d,y,Z]);l.useEffect(()=>{xe?.path&&da(xe.path,!1)},[da,xe?.path]),l.useEffect(()=>{xe&&Ge!==xe.path&&Er(xe)},[Er,Ge,xe]);const Pa=l.useRef(qs);Pa.current=qs,l.useEffect(()=>{if(!xe?.path||Ge!==xe.path)return;let Ce=!1;const qe=window.setInterval(()=>{document.hidden||ur(xe.path,Be).then(dt=>{if(Ce||!dt)return;const bt=_t.current;if(!bt||bt.path!==xe.path){_t.current=dt;return}const Pt=dt.mtimeMs!==void 0&&bt.mtimeMs!==void 0&&dt.mtimeMs!==bt.mtimeMs,qt=dt.size!==bt.size;!Pt&&!qt||Pa.current||(_t.current=dt,$e(null))}).catch(()=>{})},2e3);return()=>{Ce=!0,window.clearInterval(qe)}},[Ge,ur,xe?.path,Be]);const to=l.useCallback(()=>{const Ce=Yt.current,qe=Qt.current,dt=Xt.current;if(Yt.current=null,Qt.current=null,Xt.current=null,us.current=!0,it(!1),tt(tr),dt){y&&Q(y,dt),xe?.path===dt&&(Ce?Qn(Ce):(y&&Z(y,null),Ze(""),ct(null),ye(""),$e(null),d&&R(!1)));return}if(Ce){Qn(Ce);return}qe&&(ln(null),Te.getState().setActiveMainTab(qe))},[tr,Qn,d,Q,y,xe?.path,ln,Z]),fi=l.useCallback(async()=>{const Ce=Yt.current,qe=Qt.current,dt=Xt.current;if(Yt.current=null,Qt.current=null,Xt.current=null,us.current=!0,it(!1),await Cn(),dt){y&&Q(y,dt),xe?.path===dt&&(Ce?await Qn(Ce):(y&&Z(y,null),Ze(""),ct(null),ye(""),$e(null),d&&R(!1)));return}if(Ce){await Qn(Ce);return}qe&&(ln(null),Te.getState().setActiveMainTab(qe))},[Qn,d,Q,y,Cn,xe?.path,ln,Z]),Da=l.useCallback(Ce=>{const qe=xe?.path===Ce,dt=pi(Ce,fe);if(qe&&qs){it(!0),Yt.current=dt,Xt.current=Ce;return}if(y&&Q(y,Ce),!!qe){if(dt){Qn(dt);return}y&&Z(y,null),Ze(""),ct(null),ye(""),$e(null),d&&R(!1)}},[pi,Qn,qs,d,fe,Q,y,xe?.path,Z]),sr=l.useCallback(Ce=>{if(me.includes(Ce))return"open";if(v?.files){const qe=Ce.startsWith(y+"/")?Ce.slice(y.length+1):Ce,dt=v.files.find(bt=>bt.path===qe);if(dt){if(dt.index==="A"||dt.working_dir==="?")return"git-added";if(dt.index==="D")return"git-deleted";if(dt.index==="M"||dt.working_dir==="M")return"git-modified"}}return null},[me,v,y]),Ee=l.useCallback(Ce=>{if(!v?.files)return null;const qe=Ce.startsWith(y+"/")?Ce.slice(y.length+1):Ce,dt=qe?`${qe}/`:"";let bt=0,Pt=0;for(const qt of v.files)qt.path.startsWith(dt)&&((qt.index==="M"||qt.working_dir==="M")&&bt++,(qt.index==="A"||qt.working_dir==="?")&&Pt++);return bt+Pt>0?{modified:bt,added:Pt}:null},[v,y]),Je=l.useCallback(async Ce=>{const qe=wn(Ce);y&&(Ie(y,qe),de.current.has(qe)||await bn(qe))},[bn,y,Ie]),Ye=l.useMemo(()=>({canRename:Mt,canCreateFile:We,canCreateFolder:gt,canDelete:Et,canReveal:as}),[Mt,We,gt,Et,as]);function at(Ce,qe){const dt=ve[Ce]??[];return dt.map((bt,Pt)=>{const qt=bt.type==="directory",Ns=qt&&_.includes(bt.path),nn=xe?.path===bt.path,nr=Pt===dt.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"}),nr&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-background"})]}),s.jsx(d3,{node:bt,root:y,isExpanded:Ns,isActive:nn,isMobile:d,alwaysShowActions:u,status:qt?void 0:sr(bt.path),badge:qt?Ee(bt.path):void 0,permissions:Ye,downloadFile:n.downloadFile,contextMenuPath:X,setContextMenuPath:pt,onSelect:Qn,onToggle:Je,onRevealPath:Bt,onOpenDialog:mn}),qt&&Ns&&s.jsx("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:at(bt.path,qe+1)})]},bt.path)})}const It=!!(xe?.path&&Hi(xe.path)),Jt=!!(xe?.path&&xe.path.toLowerCase().endsWith(".svg")),Js=l.useMemo(()=>wn(fn?.path??""),[fn?.path]),cn=!!(fn&&Js&&he&&he===Js&&!Xe&&!et&&!It),Nr=l.useMemo(()=>su(y,he),[he,y]),kc=!!(xe&&(!It||Jt)&&Ke.length>0),qo=!!(xe&&Nr.length>0),Un=!!(xe&&!Pe&&!It&&n.writeFile&&Ke.length<=oo),Ta=!!(xe?.path&&l3(xe.path)),ua=!!(xe?.path&&c3(xe.path)),hi=!!(xe?.path&&od(xe.path)),so=!!(xe&&!It)&&!Ta&&!(hi&&te==="preview"),gi=l.useMemo(()=>he?yx(he):null,[he]),[xi,ma]=l.useState(null);l.useEffect(()=>{let Ce=!1;const qe=xe?.path;if(!qe||gi){ma(null);return}return ma(null),Yk(qe).then(dt=>{Ce||ma(dt)}),()=>{Ce=!0}},[xe?.path,gi]),l.useEffect(()=>{!Un&&B==="edit"&&ne("view")},[Un,B]);const dn="openchamber:files:md-viewer-mode",bi="openchamber:files:html-viewer-mode",yi="openchamber:files:json-viewer-mode";l.useEffect(()=>{const Ce=xe?.path;if(!Ce)return;const qe=Ht?"view":"edit";ne(z.current[Ce]??qe);let dt=Ht?"preview":"edit";try{const qt=localStorage.getItem(dn);(qt==="preview"||qt==="edit")&&(dt=qt)}catch{}ee(J.current[Ce]??dt);let bt=Ht?"preview":"edit";try{const qt=localStorage.getItem(bi);(qt==="preview"||qt==="edit")&&(bt=qt)}catch{}E(H.current[Ce]??bt);let Pt=Ht?"tree":"text";try{const qt=localStorage.getItem(yi);(qt==="tree"||qt==="text")&&(Pt=qt)}catch{}ge(Pt)},[xe?.path,Ht]);const Ic=l.useCallback(Ce=>{const qe=xe?.path;qe&&(z.current[qe]=Ce),ne(Ce)},[xe?.path]),Ac=l.useCallback(Ce=>{const qe=xe?.path;qe&&(J.current[qe]=Ce),ee(Ce);try{localStorage.setItem(dn,Ce)}catch{}},[xe?.path]),Ur=l.useCallback(()=>le,[le]),Tn=l.useCallback(Ce=>{ge(Ce);try{localStorage.setItem(yi,Ce)}catch{}},[]),Pc=l.useCallback(Ce=>{const qe=xe?.path;qe&&(H.current[qe]=Ce),E(Ce);try{localStorage.setItem(bi,Ce)}catch{}},[xe?.path]),Qo=l.useCallback(()=>te,[te]);l.useEffect(()=>{if(!fn||!y)return;const Ce=()=>{typeof window>"u"||At.current===null&&(At.current=window.requestAnimationFrame(()=>{At.current=null,Tt(ta=>ta+1)}))},qe=(ta,Ra)=>{if(ta.state.doc.length!==Ra.length)return!1;if(Ra.length===0)return!0;const Tc=Math.min(128,Ra.length);if(ta.state.sliceDoc(0,Tc)!==Ra.slice(0,Tc))return!1;const nm=Math.max(0,Ra.length-Tc);return ta.state.sliceDoc(nm,Ra.length)===Ra.slice(nm)},dt=wn(fn.path);if(!dt){cr(null),vt.current={key:"",attempts:0};return}const bt=`${dt}:${fn.line}:${fn.column??1}`;if(vt.current.key!==bt&&(vt.current={key:bt,attempts:0}),xe?.path!==dt){we!==dt&&Z(y,dt);return}if(Xe||Ge!==dt)return;if(et||It){cr(null),vt.current={key:"",attempts:0};return}if(!Un)return;if(B!=="edit"){ne("edit");return}const Pt=ds.current;if(!Pt){Ce();return}if(!qe(Pt,Ve)){Ce();return}const qt=Math.max(1,Math.min(fn.line,Pt.state.doc.lines)),Ns=Pt.state.doc.line(qt),nn=Math.max(1,fn.column||1),nr=Math.max(0,Ns.to-Ns.from),lb=Math.min(nr,nn-1),ro=Ns.from+lb;if(!(Pt.state.selection.main.head===ro)||vt.current.attempts===0){vt.current.attempts+=1,Pt.dispatch({selection:{anchor:ro},effects:or.scrollIntoView(ro,{y:"center"})}),Pt.focus(),Ce();return}typeof window<"u"&&window.requestAnimationFrame(()=>{const ta=ds.current;ta&&(ta.dispatch({selection:{anchor:ro},effects:or.scrollIntoView(ro,{y:"center"})}),ta.focus())}),cr(null),vt.current={key:"",attempts:0}},[Un,Ve,Ue,et,Xe,It,Ge,fn,y,xe?.path,we,cr,Z,B]),l.useEffect(()=>{if(!Vr||!y)return;const Ce=wn(Vr);if(!Ce){Fe(null);return}if(xe?.path!==Ce){we!==Ce&&Z(y,Ce);return}if(!(Xe||Ge!==Ce||et||It)){if(Un&&B==="edit"){const qe=ds.current;if(!qe)return;qe.focus()}Fe(null)}},[Un,et,Xe,It,Ge,Vr,y,xe?.path,we,Fe,Z,B]);const pa=l.useCallback(Ce=>{if(!d||!Ce||!Ce.hasFocus||typeof window>"u")return;const qe=window.visualViewport;if(!qe)return;const dt=document.documentElement.clientHeight||window.innerHeight;if(Math.max(0,dt-(qe.offsetTop+qe.height))<=0)return;const Pt=Ce.state.selection.main.head,qt=Ce.coordsAtPos(Pt);if(!qt)return;const Ns=Math.round(qe.offsetTop+qe.height),nr=qt.bottom+20-Ns;nr<=0||(Ce.scrollDOM.scrollTop+=nr)},[d]);l.useEffect(()=>{if(!d||typeof window>"u")return;const Ce=()=>{window.requestAnimationFrame(()=>{pa(ds.current)})},qe=window.visualViewport;return qe?.addEventListener("resize",Ce),qe?.addEventListener("scroll",Ce),document.addEventListener("selectionchange",Ce),()=>{qe?.removeEventListener("resize",Ce),qe?.removeEventListener("scroll",Ce),document.removeEventListener("selectionchange",Ce)}},[d,pa]),l.useEffect(()=>{if(!Un||B!=="edit"||d)return;const Ce=ra("open_go_to_line",Nt),qe=dt=>{const bt=dt.target;if(bt?.closest('[role="dialog"]'))return;const Pt=!!bt?.closest(".cm-editor");bt?.closest('input, textarea, [contenteditable="true"], [role="textbox"]')&&!Pt||!document.activeElement?.closest(".cm-editor")||Nl(dt,Ce)&&(dt.preventDefault(),Ms(!0))};return window.addEventListener("keydown",qe),()=>window.removeEventListener("keydown",qe)},[Un,d,Nt,B]);const Jo=l.useMemo(()=>{if(!xe?.path)return[tu(a)];const Ce=[tu(a)],qe=gi??xi;return qe&&Ce.push(qe),k&&Ce.push(or.lineWrapping),d&&Ce.push(or.updateListener.of(dt=>{dt.view.hasFocus&&(dt.selectionSet||dt.focusChanged||dt.viewportChanged||dt.geometryChanged)&&window.requestAnimationFrame(()=>{pa(dt.view)})})),Ce},[a,xe?.path,gi,xi,k,d,pa]),Yo=l.useMemo(()=>({light:re.metadata.id,dark:ce.metadata.id}),[re.metadata.id,ce.metadata.id]),Ma=xe?.path&&It?r.isDesktop?Jt?`data:${jm(xe.path)};utf8,${encodeURIComponent(Ke)}`:lt:Jt?`data:${jm(xe.path)};utf8,${encodeURIComponent(Ke)}`:`/api/fs/raw?${new URLSearchParams({path:xe.path,...Be.allowOutsideWorkspace?{allowOutsideWorkspace:"true"}:{}}).toString()}`:"";l.useEffect(()=>{let Ce=!1;return(async()=>{if(!r.isDesktop||!xe?.path||!It||Jt){ye("");return}ct(null),await(n.readFileBinary?n.readFileBinary(xe.path,Be).then(bt=>bt.dataUrl):Promise.resolve(cy(xe.path,"asset"))).then(bt=>{Ce||(ye(bt),$e(xe.path))}).catch(bt=>{Ce||(ye(""),ct(bt instanceof Error?bt.message:e("filesView.error.readFileFailed")),$e(null))}).finally(()=>{Ce||mt(!1)})})(),()=>{Ce=!0}},[n,It,Jt,r.isDesktop,xe?.path,Be,e]);const no=()=>s.jsx(ws,{open:!!Rt,onOpenChange:Ce=>!Ce&&ns(null),children:s.jsxs(vs,{children:[s.jsxs(Is,{children:[s.jsxs(Ss,{children:[Rt==="createFile"&&e("filesView.dialog.createFile.title"),Rt==="createFolder"&&e("filesView.dialog.createFolder.title"),Rt==="rename"&&e("filesView.dialog.rename.title"),Rt==="delete"&&e("filesView.dialog.delete.title")]}),s.jsxs(Os,{children:[Rt==="createFile"&&e("filesView.dialog.createFile.description",{path:As?.path??e("filesView.dialog.rootFallback")}),Rt==="createFolder"&&e("filesView.dialog.createFolder.description",{path:As?.path??e("filesView.dialog.rootFallback")}),Rt==="rename"&&e("filesView.dialog.rename.description",{name:As?.name??""}),Rt==="delete"&&e("filesView.dialog.delete.description",{name:As?.name??""})]})]}),Rt!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(Vt,{value:is,onChange:Ce=>es(Ce.target.value),placeholder:e(Rt==="rename"?"filesView.dialog.rename.placeholder":"filesView.dialog.namePlaceholder"),onKeyDown:Ce=>{Ce.key==="Enter"&&Ia()},autoFocus:!0})}),s.jsxs(Qs,{children:[s.jsx(je,{variant:"outline",onClick:()=>ns(null),disabled:Ts,children:e("filesView.dialog.cancel")}),s.jsx(je,{variant:Rt==="delete"?"destructive":"default",onClick:()=>{Ia()},disabled:Ts||Rt!=="delete"&&!is.trim(),children:Ts?s.jsx(Zt,{className:"animate-spin"}):e(Rt==="delete"?"filesView.dialog.delete.confirm":"filesView.dialog.confirm")})]})]})}),Dc=l.useMemo(()=>mx({drafts:Zs,editingDraftId:en,commentText:Gs,selection:js,isDragging:An,fileLabel:xe?.path??"",newWidgetId:"files-new-comment-input",mapDraftToRange:Ce=>({start:Ce.startLine,end:Ce.endLine}),onSave:Ln,onCancel:()=>{xn(null),dr()},onEdit:Ce=>{ea(Ce),xn({start:Ce.startLine,end:Ce.endLine})},onDelete:On}),[dr,Gs,On,en,Zs,Ln,An,js,xe?.path,ea]),Xo=l.useCallback((Ce,qe)=>s.jsx("div",{className:"h-full",children:s.jsx(ly,{file:{name:Ce.name,contents:qe,lang:Po(Ce.path)||void 0},options:{disableFileHeader:!0,overflow:k?"wrap":"scroll",theme:Yo,themeType:a.metadata.variant==="dark"?"dark":"light"},className:"block h-full w-full",style:{height:"100%"}})}),[a.metadata.variant,Yo,k]),Zo=({exitFullscreenOnly:Ce=!1}={})=>xe?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:[Un&&B==="edit"&&s.jsxs(s.Fragment,{children:[Qe?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-muted-foreground typography-meta",children:[s.jsx(Zt,{className:"h-3.5 w-3.5 animate-spin"}),e("filesView.editor.saving")]}):jt&&Kt==="saved"&&!qs?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-[color:var(--status-success)] typography-meta",children:[s.jsx(Ys,{className:"h-3.5 w-3.5"}),e("filesView.editor.saved")]}):qs?s.jsx(je,{variant:"ghost",size:"sm",onClick:()=>{Cn()},className:"h-6 gap-1 px-1 text-muted-foreground opacity-80 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:e(jt?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:`${ql()}+S`}),"aria-label":e("filesView.editor.saveAria",{shortcut:`${ql()}+S`}),children:s.jsx(dy,{className:"h-4 w-4"})}):null,s.jsx(je,{variant:"ghost",size:"sm",onClick:()=>Dt(qe=>!qe),className:pe("h-6 w-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",jt?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(jt?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),"aria-label":e(jt?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),children:jt?s.jsx(uy,{className:"size-4"}):s.jsx(my,{className:"size-4"})})]}),s.jsxs(zs,{onOpenChange:L,children:[s.jsx(Bs,{asChild:!0,children:s.jsx(je,{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(py,{className:"h-4 w-4"})})}),s.jsxs(Vs,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[st.map(qe=>s.jsxs($t,{className:"flex items-center gap-2",onClick:()=>{xs(qe)},children:[s.jsx(Zk,{label:qe.label,iconDataUrl:qe.iconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:qe.label})]},qe.id)),Lt?s.jsxs($t,{className:"flex items-center gap-2",onClick:()=>{rs(!0)},children:[s.jsx(Nn,{className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:e("filesView.editor.refreshApps")})]}):null]})]}),!It&&s.jsxs(s.Fragment,{children:[s.jsx(je,{variant:"ghost",size:"sm",onClick:()=>P(!k),className:pe("h-6 w-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",k?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(k?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),children:s.jsx(Oh,{className:"size-4"})}),B==="edit"&&s.jsxs(s.Fragment,{children:[s.jsx(je,{variant:"ghost",size:"sm",onClick:qe=>{M(!T),qe.currentTarget.blur()},className:"h-6 w-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.findInFile"),children:s.jsx(Hn,{className:"size-4"})}),s.jsx(je,{variant:"ghost",size:"sm",onClick:qe=>{Ms(dt=>!dt),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(fy,{className:"size-4"})}),s.jsx(Gk,{open:Ps,onOpenChange:Ms,view:ds.current,variant:"inline"})]})]}),so&&Un&&!ua&&!hi&&s.jsx(Zd,{currentMode:B==="view"?"preview":"edit",onToggle:()=>{Ic(B==="view"?"edit":"view")}}),(Ta||od(xe?.path??""))&&s.jsx(Zd,{currentMode:Ta?Ur():Qo(),onToggle:()=>{od(xe?.path??"")?Pc(Qo()==="preview"?"edit":"preview"):Ac(Ur()==="preview"?"edit":"preview")}}),ua&&s.jsx(je,{variant:"ghost",size:"sm",onClick:()=>Tn(ae==="tree"?"text":"tree"),className:"h-6 w-6 p-0 text-muted-foreground opacity-65 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:e(ae==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),children:ae==="tree"?s.jsx(hy,{className:"size-4"}):s.jsx(Wh,{className:"size-4"})}),kc&&s.jsx(je,{variant:"ghost",size:"sm",onClick:async()=>{(await _n(Ke)).ok?(zt(!0),ms.current!==null&&window.clearTimeout(ms.current),ms.current=window.setTimeout(()=>{zt(!1)},1200)):q.error(e("filesView.toast.copyFailed"))},className:"h-6 w-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.copyFileContents"),"aria-label":e("filesView.editor.copyFileContents"),children:wt?s.jsx(Ys,{className:"h-4 w-4 text-[color:var(--status-success)]"}):s.jsx(ni,{className:"h-4 w-4"})}),qo&&s.jsx(je,{variant:"ghost",size:"sm",onClick:async()=>{(await _n(Nr)).ok?(os(!0),gs.current!==null&&window.clearTimeout(gs.current),gs.current=window.setTimeout(()=>{os(!1)},1200)):q.error(e("filesView.toast.copyFailed"))},className:"h-6 w-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.copyFilePathTitle",{path:Nr}),"aria-label":e("filesView.editor.copyFilePathTitle",{path:Nr}),children:ss?s.jsx(Ys,{className:"h-4 w-4 text-[color:var(--status-success)]"}):s.jsx(Kh,{className:"h-4 w-4"})}),n.downloadFile&&s.jsx(je,{variant:"ghost",size:"sm",onClick:()=>{const qe=n.downloadFile;qe&&qe(xe.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(Qr,{className:"h-4 w-4"})}),Ce?s.jsx(je,{variant:"ghost",size:"sm",onClick:()=>D(!1),className:"h-6 w-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.exitFullscreen"),"aria-label":e("filesView.editor.exitFullscreen"),children:s.jsx(Md,{className:"h-4 w-4"})}):!d&&t==="full"&&s.jsx(je,{variant:"ghost",size:"sm",onClick:()=>D(!N),className:"h-6 w-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e(N?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),"aria-label":e(N?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),children:N?s.jsx(Md,{className:"h-4 w-4"}):s.jsx(Hh,{className:"h-4 w-4"})})]}):null,Me=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:ts,onOpenChange:Ce=>{Ce||it(!0)},children:s.jsxs(vs,{showCloseButton:!1,className:"max-w-md",children:[s.jsxs(Is,{children:[s.jsx(Ss,{children:e("filesView.unsaved.title")}),s.jsx(Os,{children:e("filesView.unsaved.description")})]}),s.jsxs(Qs,{children:[s.jsx(je,{variant:"outline",onClick:()=>{fi()},disabled:Qe,className:"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)] hover:bg-[rgb(var(--status-success)/0.2)]",children:e("filesView.unsaved.saveChanges")}),s.jsx(je,{variant:"destructive",onClick:to,children:e("filesView.unsaved.discard")})]})]})}),s.jsx("div",{className:pe("flex flex-col flex-shrink-0",x&&"border-b border-border/40"),children:x?s.jsxs("div",{className:"flex min-w-0 items-center px-3 py-1.5",children:[d&&I&&s.jsx("button",{type:"button",onClick:()=>R(!1),"aria-label":e("filesView.editor.back"),className:"inline-flex h-7 w-7 flex-shrink-0 items-center justify-center mr-1 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(zi,{className:"h-5 w-5"})}),d?xe?s.jsxs(zs,{children:[s.jsx(Bs,{asChild:!0,children:s.jsxs("button",{type:"button",className:"inline-flex min-w-0 max-w-full items-center gap-1 text-left typography-ui-label font-medium","aria-label":e("filesView.editor.openFilesAria"),children:[s.jsx(Pr,{filePath:xe.path,extension:xe.extension,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:xe.name}),s.jsx(Cs,{className:"h-4 w-4 flex-shrink-0 text-muted-foreground"})]})}),s.jsx(Vs,{align:"start",className:"min-w-[16rem]",children:fe.map(Ce=>{const qe=xe?.path===Ce.path;return s.jsxs($t,{onSelect:dt=>{if(dt.target.closest("[data-close-open-file]")){dt.preventDefault();return}qe||Qn(Ce)},className:pe("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(Pr,{filePath:Ce.path,extension:Ce.extension,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:Ce.name})]}),s.jsx("button",{type:"button","data-close-open-file":!0,onPointerDown:dt=>{dt.preventDefault(),dt.stopPropagation()},onClick:dt=>{dt.preventDefault(),dt.stopPropagation(),Da(Ce.path)},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]","aria-label":e("filesView.editor.closeFileAria",{name:Ce.name}),children:s.jsx(Ds,{className:"h-3.5 w-3.5"})})]},Ce.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:[be.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"}),be.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(Ce=>{const qe=xe?.path===Ce.path;return s.jsxs("div",{title:su(y,Ce.path),className:pe("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(Pr,{filePath:Ce.path,extension:Ce.extension,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("button",{type:"button",onClick:()=>{qe||Qn(Ce)},className:"max-w-[12rem] truncate text-left",children:Ce.name}),s.jsx("button",{type:"button",onClick:dt=>{dt.stopPropagation(),Da(Ce.path)},className:pe("rounded-sm p-0.5 text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]",!qe&&!u&&"opacity-0 group-hover:opacity-100"),"aria-label":e("filesView.editor.closeFileAria",{name:Ce.name}),children:s.jsx(Ds,{size:14})})]},Ce.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")})]}):null}),s.jsxs("div",{className:"flex-1 min-h-0 min-w-0 relative",children:[xe&&!T&&s.jsx("div",{ref:V,className:"absolute right-3 top-3 z-30",onMouseEnter:()=>F(!0),onMouseLeave:()=>{O.current>0||F(!1)},children:$?Zo():s.jsx(je,{variant:"ghost",size:"sm",onClick:()=>F(!0),className:"h-8 w-8 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-0 text-muted-foreground shadow-sm hover:text-foreground","aria-label":e("filesView.editor.showControlsAria"),title:e("filesView.editor.controlsTitle"),children:s.jsx(Iu,{className:"h-4 w-4"})})}),s.jsx(Es,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:xe?Xe?g?s.jsx("div",{className:"p-3"}):s.jsxs("div",{className:"p-3 flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(Zt,{className:"h-4 w-4 animate-spin"}),e("filesView.state.loading")]}):et?s.jsx("div",{className:"p-3 typography-ui text-[color:var(--status-error)]",children:et}):It?s.jsx("div",{className:"flex h-full items-center justify-center p-3",children:s.jsx("img",{src:Ma,alt:xe?.name??e("filesView.editor.imageAltFallback"),className:"max-w-full max-h-[70vh] object-contain rounded-md border border-border/30 bg-primary/10"})}):xe&&ua&&ae==="tree"?s.jsx(rn,{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(Jw,{jsonString:Ke,maxHeight:"100%",initiallyExpandedDepth:2})})}):xe&&Ta&&Ur()==="preview"?s.jsxs("div",{className:"h-full overflow-auto p-3",children:[Ke.length>500*1024&&s.jsx("div",{className:"mb-3 rounded-md border border-status-warning/20 bg-status-warning/10 px-3 py-2 text-sm text-status-warning",children:e("filesView.warning.largeFilePreviewLimited",{sizeKb:Math.round(Ke.length/1024)})}),s.jsx(rn,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToEditMode")})]}),children:s.jsx(ai,{content:Ke,className:"typography-markdown-body",stripFrontmatter:!0})})]}):xe&&hi&&te==="preview"?s.jsx("div",{className:"h-full overflow-hidden",children:s.jsx("iframe",{srcDoc:(()=>{const Ce=xe.path.substring(0,xe.path.lastIndexOf("/")+1);if(!Ce)return Ke;const qe=`<base href="${r.isDesktop,Ce}">`;return Ke.replace(/<head([^>]*)>/i,`<head$1>${qe}`)})(),className:"w-full h-full border-none",sandbox:"allow-scripts allow-same-origin allow-forms",title:e("filesView.editor.htmlPreviewTitle")})}):xe&&so&&B==="view"?Xo(xe,Ve):s.jsxs("div",{className:pe("relative h-full",cn&&"overflow-hidden"),ref:Ft,children:[s.jsx("div",{className:pe("h-full",cn&&"invisible"),children:s.jsx(Xd,{value:Ve,onChange:tt,readOnly:!Un,extensions:Jo,className:"h-full",blockWidgets:Dc,onViewReady:Ce=>{ds.current=Ce,Tt(qe=>qe+1),window.requestAnimationFrame(()=>{pa(Ce)})},onViewDestroy:()=>{ds.current&&(ds.current=null),Tt(Ce=>Ce+1)},enableSearch:!0,searchOpen:T,onSearchOpenChange:M,highlightLines:js?{start:Math.min(js.start,js.end),end:Math.max(js.start,js.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(Ce,qe,dt)=>{if(!(dt instanceof MouseEvent)||dt.button!==0)return!1;dt.preventDefault();const bt=Ce.state.doc.lineAt(qe.from).number;if(d&&js&&!dt.shiftKey){const Pt=Math.min(js.start,js.end,bt),qt=Math.max(js.start,js.end,bt);return xn({start:Pt,end:qt}),In.current=!1,an.current=null,on(!1),!0}if(In.current=!0,an.current=bt,on(!0),js&&dt.shiftKey){const Pt=Math.min(js.start,bt),qt=Math.max(js.end,bt);xn({start:Pt,end:qt})}else xn({start:bt,end:bt});return!0},mouseover:(Ce,qe,dt)=>{if(!(dt instanceof MouseEvent)||dt.buttons!==1||!In.current||an.current===null)return!1;const bt=Ce.state.doc.lineAt(qe.from).number,Pt=Math.min(an.current,bt),qt=Math.max(an.current,bt);return xn({start:Pt,end:qt}),on(!0),!1},mouseup:()=>(In.current=!1,an.current=null,on(!1),!1)}}})}),cn&&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(Zt,{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")})})]})]}),xt=!!(y&&ve[y]),ot=s.jsxs("section",{className:pe("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:pe("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(Hn,{className:"pointer-events-none absolute left-2 top-2 h-4 w-4 text-muted-foreground"}),s.jsx(Vt,{ref:C,value:S,onChange:Ce=>A(Ce.target.value),placeholder:e("filesView.tree.search.placeholder"),className:"h-8 pl-8 pr-8 typography-meta"}),S.trim().length>0&&s.jsx("button",{type:"button","aria-label":e("filesView.tree.search.clearAria"),className:"absolute right-2 top-2 inline-flex h-4 w-4 items-center justify-center text-muted-foreground hover:text-foreground",onClick:()=>{A(""),C.current?.focus()},children:s.jsx(Ds,{className:"h-4 w-4"})})]}),s.jsx(je,{variant:"ghost",size:"sm",onClick:()=>mn("createFile",{path:f,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFileTitle"),children:s.jsx(mc,{className:"h-4 w-4"})}),s.jsx(je,{variant:"ghost",size:"sm",onClick:()=>mn("createFolder",{path:f,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFolderTitle"),children:s.jsx(Ca,{className:"h-4 w-4"})}),s.jsx(je,{variant:"ghost",size:"sm",onClick:()=>{qn()},className:"h-8 w-8 p-0 flex-shrink-0",children:s.jsx(Nn,{className:"h-4 w-4"})})]})}),s.jsx(Es,{outerClassName:"flex-1 min-h-0",className:pe("py-2",d?"px-3":"px-2"),children:s.jsx("ul",{className:"flex flex-col",children:_e?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(Zt,{className:"h-4 w-4 animate-spin"}),e("filesView.tree.search.searching")]}):ie.length>0?ie.map(Ce=>{const qe=xe?.path===Ce.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>{Qn(Ce)},className:pe("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:[wx(Ce.path,Ce.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},title:Ce.path,children:Ce.relativePath??Ce.path})]})},Ce.path)}):xt?at(y,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:e("filesView.state.loading")})})})]}),Gt=t==="full"&&N&&xe&&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:Zo({exitFullscreenOnly:!0})}),s.jsx(Es,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:Xe?g?s.jsx("div",{className:"p-4"}):s.jsxs("div",{className:"p-4 flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(Zt,{className:"h-4 w-4 animate-spin"}),"Loading…"]}):et?s.jsx("div",{className:"p-4 typography-ui text-[color:var(--status-error)]",children:et}):It?s.jsx("div",{className:"flex h-full items-center justify-center p-4",children:s.jsx("img",{src:Ma,alt:xe.name,className:"max-w-full max-h-full object-contain rounded-md border border-border/30 bg-primary/10"})}):Ta&&Ur()==="preview"?s.jsxs("div",{className:"h-full overflow-auto p-4",children:[Ke.length>500*1024&&s.jsx("div",{className:"mb-3 rounded-md border border-status-warning/20 bg-status-warning/10 px-3 py-2 text-sm text-status-warning",children:e("filesView.warning.largeFilePreviewLimited",{sizeKb:Math.round(Ke.length/1024)})}),s.jsx(rn,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToEditMode")})]}),children:s.jsx(ai,{content:Ke,className:"typography-markdown-body",stripFrontmatter:!0})})]}):so&&B==="view"?Xo(xe,Ve):s.jsxs("div",{className:pe("relative h-full",cn&&"overflow-hidden"),children:[s.jsx("div",{className:pe("h-full",cn&&"invisible"),children:s.jsx(Xd,{value:Ve,onChange:tt,readOnly:!Un,extensions:Jo,className:"h-full",onViewReady:Ce=>{ds.current=Ce,window.requestAnimationFrame(()=>{pa(Ce)})},onViewDestroy:()=>{ds.current&&(ds.current=null)}})}),cn&&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(Zt,{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:[no(),Gt,d?I?Me:ot: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:Me})}):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:ot}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden rounded-xl border border-border/60 bg-background",children:Me})]})]})},u3=Object.freeze(Object.defineProperty({__proto__:null,FilesView:jx},Symbol.toStringTag,{value:"Module"})),$r=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},ld=(t,e)=>{const n=$r(t),r=e.replace(/\\/g,"/").replace(/^\/+/,"").replace(/\/+$/,"");return!n||n==="/"?`/${r}`:`${n}/${r}`},m3=(t,e,n)=>ld(ld(ld(t,".opencode"),"plans"),`${e}-${n}.md`),p3=(t,e)=>`~/.opencode/plans/${t}-${e}.md`,f3=(t,e)=>{const n=t.trim();return n.startsWith("~")?n==="~"?e||n:(n.startsWith("~/")||n.startsWith("~\\"))&&e?`${e}${n.slice(1)}`:n:n},h3=(t,e)=>{const n=$r(e.currentDirectory),r=$r(e.homeDirectory),a=$r(t);return n&&a.startsWith(n+"/")?a.slice(n.length+1):r&&a===r?"~":r&&a.startsWith(r+"/")?`~${a.slice(r.length)}`:a},g3=(t,e,n)=>{const r=$r(t.trim());if(!r)return null;const a=n?e.find(o=>o.id===n)??null:null;if(a?.path){const o=$r(a.path);if(r===o||r.startsWith(`${o}/`))return{id:a.id,path:a.path}}const i=e.filter(o=>{const c=$r(o.path);return r===c||r.startsWith(`${c}/`)}).sort((o,c)=>$r(c.path).length-$r(o.path).length)[0];return i?{id:i.id,path:i.path}:null},Nx=({targetPath:t=null})=>{const{t:e}=ut(),n=Wt(ve=>ve.currentSessionId),r=Wt(ve=>ve.createSession),a=Wt(ve=>ve.initializeNewOpenChamberSession),i=Wt(ve=>ve.sendMessage),o=Wt(ve=>ve.setCurrentSession),c=_o(),d=Ws(ve=>ve.homeDirectory),p=Ru(ve=>ve.planModeEnabled),m=Fs(ve=>ve.projects),u=Fs(ve=>ve.activeProjectId),h=pn(ve=>ve.directories),b=Xr()??"",f=Te(ve=>ve.setActiveMainTab),y=Te(ve=>ve.setSessionSwitcherOpen),x=Gn(),{isMobile:g}=un(),{currentTheme:w}=Rr();l.useMemo(()=>xg(w),[w]);const v=l.useMemo(()=>n?c.find(ve=>ve.id===n)??null:null,[n,c]),S=l.useMemo(()=>{const ve=typeof v?.directory=="string"?v.directory:"";return $r(ve||"")},[v?.directory]),A=l.useMemo(()=>$r(b||S),[b,S]),j=l.useMemo(()=>g3(A,m,u),[u,A,m]),C=l.useMemo(()=>j?h.get(j.path)?.isGitRepo===!0:!1,[j,h]),[I,R]=l.useState(null),[k,P]=l.useState(!1),[N,D]=l.useState(null),T=l.useMemo(()=>!N||!S||!d?N:h3(N,{currentDirectory:S,homeDirectory:d}),[N,S,d]),[M,$]=l.useState(""),[F,V]=l.useState(null),O=l.useMemo(()=>T&&T.split("/").pop()||e("planView.file.defaultName"),[T,e]),L=l.useMemo(()=>M.trim()&&a1(M).title||e("planView.title.default"),[M,e]),W=l.useMemo(()=>L.trim()||e("planView.title.default"),[L,e]),[B,ne]=l.useState(!1),[le,ee]=l.useState(!1),[ae,ge]=l.useState("edit"),te=l.useRef(null),[E,z]=l.useState(null),J=l.useRef(null),H=l.useRef(null),re="openchamber:plan:md-viewer-mode";l.useEffect(()=>{try{const ve=localStorage.getItem(re);if(!ve)return;const U=JSON.parse(ve);(U==="preview"||U==="edit")&&ge(U)}catch{}},[]);const ce=l.useCallback(ve=>{ge(ve);try{localStorage.setItem(re,JSON.stringify(ve))}catch{}},[]),Ne=l.useRef(!1),me=l.useRef(null),[we,_]=l.useState(!1);l.useEffect(()=>{const ve=()=>{Ne.current=!1,me.current=null,_(!1)};return document.addEventListener("mouseup",ve),()=>document.removeEventListener("mouseup",ve)},[]);const ue=l.useCallback((ve,U)=>{const de=ve.split(`
54
- `),Re=Math.max(1,U.start),Le=Math.min(de.length,U.end);return Re>Le?"":de.slice(Re-1,Le).join(`
55
- `)},[]),Q=qu({source:"plan",fileLabel:O,language:N&&Po(N)||"markdown",getCodeForRange:ve=>ue(M,sc(ve)),toStoreRange:ve=>({startLine:ve.start,endLine:ve.end}),fromDraftRange:ve=>({start:ve.startLine,end:ve.endLine})}),{drafts:oe,commentText:Z,editingDraftId:Ie,setSelection:Se,saveComment:Y,cancel:fe,reset:ke,startEdit:xe,deleteDraft:he}=Q;l.useEffect(()=>{z(null),ke()},[M,ke]),l.useEffect(()=>{Se(E)},[E,Se]);const Pe=l.useCallback(()=>{z(null),fe()},[fe]),Be=l.useCallback((ve,U)=>{U&&z(U),Y(ve,U??E??void 0),z(null)},[E,Y]);l.useEffect(()=>{if(!E)return;const ve=de=>{const Re=de.target;Re.closest('[data-comment-card="true"]')||Re.closest('[data-comment-input="true"]')||Re.closest(".oc-block-widget")||Re.closest(".cm-gutterElement")||Re.closest("[data-sonner-toast]")||Re.closest("[data-sonner-toaster]")||(z(null),fe())},U=window.setTimeout(()=>{document.addEventListener("click",ve)},100);return()=>{window.clearTimeout(U),document.removeEventListener("click",ve)}},[fe,Ie,g,E]);const G=l.useMemo(()=>{const ve=[tu(w)],U=yx(N||"plan.md");return U&&ve.push(U),ve.push(or.lineWrapping),ve},[w,N]);l.useEffect(()=>{if(!p&&!t){D(null),$(""),ne(!1);return}let ve=!1;const U=async Re=>{if(x.files?.readFile)return(await x.files.readFile(Re))?.content??"";const Le=xr()?.files;if(Le?.readFile)return(await Le.readFile(Re,{optional:!0}))?.content??"";const se=await fetch(`/api/fs/read?path=${encodeURIComponent(Re)}&optional=true`,{cache:"no-store"});if(!se.ok)throw new Error(`Failed to read plan file (${se.status})`);return se.text()};return(async()=>{if(D(null),$(""),V(null),t){ne(!0);try{const Re=await U(t);if(ve)return;D(t),$(Re)}catch{if(ve)return;D(null),$("")}finally{ve||ne(!1)}return}if(!v?.slug||!v?.time?.created||!S){D(null),$("");return}ne(!0);try{const Re=m3(S,v.time.created,v.slug),Le=f3(p3(v.time.created,v.slug),d||null);let se=null,ie=null;try{ie=await U(Re),se=Re}catch{}if(!se)try{ie=await U(Le),se=Le}catch{}if(ve)return;if(!se||ie===null){D(null),$("");return}D(se),$(ie)}catch{if(ve)return;D(null),$("")}finally{ve||ne(!1)}})(),()=>{ve=!0}},[d,p,x.files,S,v?.slug,v?.time?.created,t]),l.useEffect(()=>{if(!N){V(null);return}const ve=window.setTimeout(async()=>{V(null);try{if(x.files?.writeFile){if(!(await x.files.writeFile(N,M))?.success)throw new Error(e("planView.error.writeFailed"))}else{const U=await fetch("/api/fs/write",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:N,content:M})});if(!U.ok)throw new Error(e("planView.error.writePlanFileFailed",{status:U.status}))}}catch(U){V(U instanceof Error?U.message:e("planView.error.saveFailed"))}},350);return()=>{window.clearTimeout(ve)}},[M,N,x.files,e]),l.useEffect(()=>()=>{te.current!==null&&window.clearTimeout(te.current)},[]);const be=l.useCallback(()=>{f("chat"),y(!1)},[f,y]),De=l.useCallback(async ve=>{if(!j||!I)return;const U=await Vn(I.action==="improve"?"plan.improve.visible":"plan.implement.visible",{plan_title:W}),Re=[{synthetic:!0,text:await Vn(I.action==="improve"?"plan.improve.instructions":"plan.implement.instructions",{plan_title:W,plan_path:N??""})}];P(!0);try{be();let Le=null,se=j.path;if(I.target==="worktree"){if(!C)return;const K=await mg(j.path,pg());if(!K?.id)return;Le=K.id,se=null}else{const K=await r(void 0,j.path,null);if(!K?.id)return;Le=K.id,se=K.directory??j.path,a(K.id,yt.getState().agents??[])}if(!Le)return;const ie=hc.getState();ie.saveSessionModelSelection(Le,ve.providerID,ve.modelID),ve.agent.trim()&&(ie.saveSessionAgentSelection(Le,ve.agent),ie.saveAgentModelForSession(Le,ve.agent,ve.providerID,ve.modelID),ie.saveAgentModelVariantForSession(Le,ve.agent,ve.providerID,ve.modelID,ve.variant||void 0)),o(Le,se),await i(U,ve.providerID,ve.modelID,ve.agent.trim()||void 0,void 0,void 0,Re,ve.variant||void 0),R(null)}finally{P(!1)}},[C,r,j,a,I,N,be,i,W,o]),Ae=l.useMemo(()=>mx({drafts:oe,editingDraftId:Ie,commentText:Z,selection:E,isDragging:we,fileLabel:O,newWidgetId:"plan-new-comment-input",mapDraftToRange:ve=>({start:ve.startLine,end:ve.endLine}),onSave:Be,onCancel:Pe,onEdit:ve=>{xe(ve),z({start:ve.startLine,end:ve.endLine})},onDelete:he}),[Z,he,Ie,Pe,Be,we,E,oe,O,xe]);return s.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden bg-background",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2 border-b border-border/40 px-3 py-1.5 flex-shrink-0",children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"typography-ui-label font-medium truncate",children:L}),F?s.jsx("div",{className:"typography-micro text-[color:var(--status-error)] truncate",title:F,children:e("planView.error.saveFailed")}):null]}),N?s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs(zs,{children:[s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx(Bs,{asChild:!0,children:s.jsx(je,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0","aria-label":e("planView.actions.improvePlanAria"),disabled:!M.trim(),children:s.jsx(gy,{className:"size-4"})})})}),s.jsx(Ct,{sideOffset:8,children:e("planView.actions.improve")})]}),s.jsxs(Vs,{align:"end",children:[s.jsx($t,{onClick:()=>R({action:"improve",target:"session"}),children:e("planView.actions.sendToNewSession")}),s.jsx($t,{onClick:()=>R({action:"improve",target:"worktree"}),disabled:!C,children:e("planView.actions.sendToNewWorktreeSession")})]})]}),s.jsxs(zs,{children:[s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx(Bs,{asChild:!0,children:s.jsx(je,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0","aria-label":e("planView.actions.implementPlanAria"),disabled:!M.trim(),children:s.jsx(xy,{className:"size-4"})})})}),s.jsx(Ct,{sideOffset:8,children:e("planView.actions.implement")})]}),s.jsxs(Vs,{align:"end",children:[s.jsx($t,{onClick:()=>R({action:"implement",target:"session"}),children:e("planView.actions.sendToNewSession")}),s.jsx($t,{onClick:()=>R({action:"implement",target:"worktree"}),disabled:!C,children:e("planView.actions.sendToNewWorktreeSession")})]})]}),s.jsx(Zd,{currentMode:ae,onToggle:()=>ce(ae==="preview"?"edit":"preview")}),s.jsx(je,{variant:"ghost",size:"sm",onClick:async()=>{(await _n(M)).ok&&(ee(!0),te.current!==null&&window.clearTimeout(te.current),te.current=window.setTimeout(()=>{ee(!1)},1200))},className:"h-5 w-5 p-0",title:e("planView.actions.copyPlanContents"),"aria-label":e("planView.actions.copyPlanContents"),children:le?s.jsx(Ys,{className:"h-4 w-4 text-[color:var(--status-success)]"}):s.jsx(ni,{className:"h-4 w-4"})})]}):null]}),s.jsx(Jg,{open:I!==null,onOpenChange:ve=>{!ve&&!k&&R(null)},target:I?.target??"session",projectDirectory:j?.path??null,submitting:k,onConfirm:De}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 relative",children:s.jsx(Es,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:B?s.jsx("div",{className:"p-3 typography-ui text-muted-foreground",children:e("planView.state.loading")}):s.jsx("div",{className:"relative h-full",children:s.jsx("div",{className:"h-full",children:ae==="preview"?s.jsx("div",{className:"h-full overflow-auto p-3",children:s.jsx(rn,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("planView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("planView.error.switchToEditMode")})]}),children:s.jsx(ai,{content:M,className:"typography-markdown-body"})})}):s.jsx("div",{className:"relative h-full",ref:H,children:s.jsx(Xd,{value:M,onChange:$,readOnly:!1,className:"h-full",extensions:G,onViewReady:ve=>{J.current=ve},onViewDestroy:()=>{J.current=null},blockWidgets:Ae,highlightLines:E?{start:Math.min(E.start,E.end),end:Math.max(E.start,E.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(ve,U,de)=>{if(!(de instanceof MouseEvent)||de.button!==0)return!1;de.preventDefault();const Re=ve.state.doc.lineAt(U.from).number;if(g&&E&&!de.shiftKey){const Le=Math.min(E.start,E.end,Re),se=Math.max(E.start,E.end,Re);return z({start:Le,end:se}),Ne.current=!1,me.current=null,_(!1),!0}if(Ne.current=!0,me.current=Re,_(!0),E&&de.shiftKey){const Le=Math.min(E.start,Re),se=Math.max(E.end,Re);z({start:Le,end:se})}else z({start:Re,end:Re});return!0},mouseover:(ve,U,de)=>{if(!(de instanceof MouseEvent)||de.buttons!==1||!Ne.current||me.current===null)return!1;const Re=ve.state.doc.lineAt(U.from).number,Le=Math.min(me.current,Re),se=Math.max(me.current,Re);return z({start:Le,end:se}),_(!0),!1},mouseup:()=>(Ne.current=!1,me.current=null,_(!1),!1)}}})})})})})})]})},x3=Object.freeze(Object.defineProperty({__proto__:null,PlanView:Nx},Symbol.toStringTag,{value:"Module"})),nu={input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:0},Tl={user:0,assistant:0,tool:0,other:0},Va=t=>typeof t!="number"||!Number.isFinite(t)||t<0?0:t,Kp=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{...nu,total:Va(n)};if(!n||typeof n!="object")return nu;const r=n,a=Va(r.input),i=Va(r.output),o=Va(r.reasoning),c=Va(r.cache?.read),d=Va(r.cache?.write);return{input:a,output:i,reasoning:o,cacheRead:c,cacheWrite:d,total:a+i+o+c+d}},b3=(...t)=>{for(const e of t)if(typeof e=="string"&&e.trim().length>0)return e;return""},pr=t=>typeof t=="string"?t.length:typeof t=="number"||typeof t=="boolean"?String(t).length:Array.isArray(t)?t.reduce((e,n)=>e+pr(n),0):t&&typeof t=="object"?Object.values(t).reduce((e,n)=>e+pr(n),0):0,y3=(t,e)=>{const n=t,r=typeof n.type=="string"?n.type:"";if(r==="reasoning")return{...Tl,assistant:pr(n.text)+pr(n.content)};const a=b3(n.text,n.content,n.value,n.source?.value,n.source?.text?.value);return r==="tool"||e==="tool"?{user:0,assistant:0,tool:pr(n.input)+pr(n.output)+pr(n.error)+pr(n.call?.input)+pr(n.call?.output)+pr(n.call?.error)+pr(n.raw)+Math.round(pr(n.metadata)*.25)+Math.round(pr(n.state)*.1),other:0}:e==="user"?{user:a.length,assistant:0,tool:0,other:0}:e==="assistant"?{user:0,assistant:a.length,tool:0,other:0}:{user:0,assistant:0,tool:0,other:a.length}},Hp=(t,e)=>({user:t.user+e.user,assistant:t.assistant+e.assistant,tool:t.tool+e.tool,other:t.other+e.other}),v3=t=>{const e=Uo(t.info);return e.isUser?"user":e.role==="assistant"?"assistant":e.role==="tool"?"tool":"other"},w3=(t,e)=>{if(t.length===0)return{...Tl};const n=t.reduce((r,a)=>{const i=v3(a);let o={...Tl};for(const c of a.parts)o=Hp(o,y3(c,i));return Hp(r,o)},{...Tl});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)}},Ci=t=>t.toLocaleString(),j3=t=>!Number.isFinite(t)||t<=0?"$0.00":t<.01?`$${t.toFixed(4)}`:`$${t.toFixed(2)}`,N3=t=>!t||!Number.isFinite(t)?"-":new Date(t).toLocaleString(void 0,{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"}),S3=t=>!t||!Number.isFinite(t)?"-":new Date(t).toLocaleString(void 0,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}),k3=t=>t&&`${t[0].toUpperCase()}${t.slice(1)}`,C3=(t,e,n)=>{const r=t.find(i=>i.id===e),a=r?.models?.find(i=>i.id===n);return{providerName:r?.name||e||"-",modelName:a?.name||n||"-",contextLimit:typeof a?.limit?.context=="number"?a.limit.context:null}},I3=()=>{const t=nt.c(199),{t:e}=ut(),{currentTheme:n}=Rr();let r;t[0]!==n?(r=xg(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=Wt(A3),h=_o(),b=i1(u??""),f=yt(P3);let y;t[3]===Symbol.for("react.memo_cache_sentinel")?(y=()=>{m.current!==null&&(window.clearTimeout(m.current),m.current=null),c(D3),p(null)},t[3]=y):y=t[3];let x;t[4]!==u?(x=[u],t[4]=u,t[5]=x):x=t[5],l.useEffect(y,x);let g,w;t[6]===Symbol.for("react.memo_cache_sentinel")?(g=()=>()=>{m.current!==null&&(window.clearTimeout(m.current),m.current=null)},w=[],t[6]=g,t[7]=w):(g=t[6],w=t[7]),l.useEffect(g,w);let v;t[8]===Symbol.for("react.memo_cache_sentinel")?(v=async(jt,Dt)=>{(await _n(Dt)).ok?(p(jt),m.current!==null&&window.clearTimeout(m.current),m.current=window.setTimeout(()=>{p(it=>it===jt?null:it),m.current=null},2e3)):p(null)},t[8]=v):v=t[8];const S=v;let A;t[9]!==u||t[10]!==h?(A=u?h.find(jt=>jt.id===u)??null:null,t[9]=u,t[10]=h,t[11]=A):A=t[11];const j=A;let C,I,R,k,P;if(t[12]!==f||t[13]!==b){C=b.filter(T3);let jt;t[19]!==b?(jt=b.filter(M3),t[19]=b,t[20]=jt):jt=t[20],P=jt;let Dt=null;for(let it=C.length-1;it>=0;it=it-1,it){const Yt=C[it];if(Kp(Yt).total>0){Dt=Yt;break}}R=Dt?Kp(Dt):nu,k=C.reduce(R3,0);const ts=Dt?.info??null;I=C3(f,ts?.providerID||"",ts?.modelID||""),t[12]=f,t[13]=b,t[14]=C,t[15]=I,t[16]=R,t[17]=k,t[18]=P}else C=t[14],I=t[15],R=t[16],k=t[17],P=t[18];const N=I,D=N.contextLimit,T=D&&D>0?Math.min(999,R.total/D*100):0;let M;if(t[21]!==b){const jt=[...b].reverse().find(E3)?.info?.system||"";M=w3(b,jt),t[21]=b,t[22]=M}else M=t[22];const $=M,F=$.user,V=$.assistant,O=$.tool,L=Math.max(0,R.input-F-V-O),W=F+V+O+L,B=b[0]?.info?.time?.created,ne=b.length>0?b[b.length-1]?.info?.time?.created:null;let le;t[23]!==j?.title||t[24]!==e?(le=j?.title||e("contextSidebar.session.untitled"),t[23]=j?.title,t[24]=e,t[25]=le):le=t[25];const ee=j?.time?.created??B??null,ae=ne??j?.time?.created??null;let ge;t[26]!==V||t[27]!==L||t[28]!==O||t[29]!==F?(ge={user:F,assistant:V,tool:O,other:L},t[26]=V,t[27]=L,t[28]=O,t[29]=F,t[30]=ge):ge=t[30];let te;t[31]!==C.length||t[32]!==W||t[33]!==D||t[34]!==N||t[35]!==b.length||t[36]!==le||t[37]!==ee||t[38]!==ae||t[39]!==ge||t[40]!==R||t[41]!==k||t[42]!==T||t[43]!==P.length?(te={sessionTitle:le,messagesCount:b.length,userMessagesCount:P.length,assistantMessagesCount:C.length,createdAt:ee,lastActivityAt:ae,providerModel:N,tokenBreakdown:R,usagePercent:T,totalAssistantCost:k,contextLimit:D,breakdown:ge,breakdownTotal:W},t[31]=C.length,t[32]=W,t[33]=D,t[34]=N,t[35]=b.length,t[36]=le,t[37]=ee,t[38]=ae,t[39]=ge,t[40]=R,t[41]=k,t[42]=T,t[43]=P.length,t[44]=te):te=t[44];const E=te;if(!u){let jt;t[45]!==e?(jt=e("contextSidebar.empty.openSession"),t[45]=e,t[46]=jt):jt=t[46];let Dt;return t[47]!==jt?(Dt=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]=Dt):Dt=t[48],Dt}let z;t[49]!==e?(z=e("contextSidebar.breakdown.user"),t[49]=e,t[50]=z):z=t[50];let J;t[51]!==z||t[52]!==E.breakdown.user?(J={key:"user",label:z,value:E.breakdown.user,color:"var(--status-success)"},t[51]=z,t[52]=E.breakdown.user,t[53]=J):J=t[53];let H;t[54]!==e?(H=e("contextSidebar.breakdown.assistant"),t[54]=e,t[55]=H):H=t[55];let re;t[56]!==H||t[57]!==E.breakdown.assistant?(re={key:"assistant",label:H,value:E.breakdown.assistant,color:"var(--primary-base)"},t[56]=H,t[57]=E.breakdown.assistant,t[58]=re):re=t[58];let ce;t[59]!==e?(ce=e("contextSidebar.breakdown.toolCalls"),t[59]=e,t[60]=ce):ce=t[60];let Ne;t[61]!==ce||t[62]!==E.breakdown.tool?(Ne={key:"tool",label:ce,value:E.breakdown.tool,color:"var(--status-warning)"},t[61]=ce,t[62]=E.breakdown.tool,t[63]=Ne):Ne=t[63];let me;t[64]!==e?(me=e("contextSidebar.breakdown.other"),t[64]=e,t[65]=me):me=t[65];let we;t[66]!==me||t[67]!==E.breakdown.other?(we={key:"other",label:me,value:E.breakdown.other,color:"var(--surface-muted-foreground)"},t[66]=me,t[67]=E.breakdown.other,t[68]=we):we=t[68];let _;t[69]!==J||t[70]!==re||t[71]!==Ne||t[72]!==we?(_=[J,re,Ne,we],t[69]=J,t[70]=re,t[71]=Ne,t[72]=we,t[73]=_):_=t[73];const ue=_;let Q;t[74]!==E.sessionTitle?(Q=s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:E.sessionTitle}),t[74]=E.sessionTitle,t[75]=Q):Q=t[75];let oe;t[76]!==E.providerModel.modelName||t[77]!==E.providerModel.providerName?(oe=s.jsxs("span",{children:[E.providerModel.providerName," / ",E.providerModel.modelName]}),t[76]=E.providerModel.modelName,t[77]=E.providerModel.providerName,t[78]=oe):oe=t[78];let Z;t[79]!==E.createdAt?(Z=E.createdAt&&s.jsxs(s.Fragment,{children:[s.jsx("span",{children:"·"}),s.jsx("span",{children:N3(E.createdAt)})]}),t[79]=E.createdAt,t[80]=Z):Z=t[80];let Ie;t[81]!==oe||t[82]!==Z?(Ie=s.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-2 gap-y-0.5 typography-micro text-muted-foreground/70",children:[oe,Z]}),t[81]=oe,t[82]=Z,t[83]=Ie):Ie=t[83];let Se;t[84]!==Q||t[85]!==Ie?(Se=s.jsxs("div",{className:"mb-6",children:[Q,Ie]}),t[84]=Q,t[85]=Ie,t[86]=Se):Se=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]!==E.tokenBreakdown.total?(ke=Ci(E.tokenBreakdown.total),t[91]=E.tokenBreakdown.total,t[92]=ke):ke=t[92];let xe;t[93]!==E.contextLimit?(xe=E.contextLimit?` / ${Ci(E.contextLimit)}`:"",t[93]=E.contextLimit,t[94]=xe):xe=t[94];let he;t[95]!==ke||t[96]!==xe?(he=s.jsxs("span",{className:"typography-micro tabular-nums text-muted-foreground/70",children:[ke,xe]}),t[95]=ke,t[96]=xe,t[97]=he):he=t[97];let Pe;t[98]!==fe||t[99]!==he?(Pe=s.jsxs("div",{className:"flex items-baseline justify-between",children:[fe,he]}),t[98]=fe,t[99]=he,t[100]=Pe):Pe=t[100];let Be;t[101]!==E.usagePercent?(Be=E.usagePercent>0&&s.jsx("div",{className:"rounded-full transition-all duration-300",style:{width:`${Math.max(.5,E.usagePercent)}%`,backgroundColor:E.usagePercent>80?"var(--status-warning)":"var(--primary-base)"}}),t[101]=E.usagePercent,t[102]=Be):Be=t[102];let G;t[103]!==Be?(G=s.jsx("div",{className:"mt-2.5 flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:Be}),t[103]=Be,t[104]=G):G=t[104];let be;t[105]!==e||t[106]!==E.usagePercent?(be=e("contextSidebar.context.percentUsed",{percent:E.usagePercent.toFixed(1)}),t[105]=e,t[106]=E.usagePercent,t[107]=be):be=t[107];let De;t[108]!==be?(De=s.jsx("div",{className:"mt-1.5 typography-micro font-medium tabular-nums text-foreground/80",children:be}),t[108]=be,t[109]=De):De=t[109];let Ae;t[110]!==Pe||t[111]!==G||t[112]!==De?(Ae=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[Pe,G,De]}),t[110]=Pe,t[111]=G,t[112]=De,t[113]=Ae):Ae=t[113];let ve;t[114]!==e?(ve=e("contextSidebar.stats.messages"),t[114]=e,t[115]=ve):ve=t[115];let U;t[116]!==E.messagesCount?(U=Ci(E.messagesCount),t[116]=E.messagesCount,t[117]=U):U=t[117];let de;t[118]!==ve||t[119]!==U?(de={label:ve,value:U},t[118]=ve,t[119]=U,t[120]=de):de=t[120];let Re;t[121]!==e?(Re=e("contextSidebar.stats.user"),t[121]=e,t[122]=Re):Re=t[122];let Le;t[123]!==E.userMessagesCount?(Le=Ci(E.userMessagesCount),t[123]=E.userMessagesCount,t[124]=Le):Le=t[124];let se;t[125]!==Re||t[126]!==Le?(se={label:Re,value:Le},t[125]=Re,t[126]=Le,t[127]=se):se=t[127];let ie;t[128]!==e?(ie=e("contextSidebar.stats.assistant"),t[128]=e,t[129]=ie):ie=t[129];let K;t[130]!==E.assistantMessagesCount?(K=Ci(E.assistantMessagesCount),t[130]=E.assistantMessagesCount,t[131]=K):K=t[131];let _e;t[132]!==ie||t[133]!==K?(_e={label:ie,value:K},t[132]=ie,t[133]=K,t[134]=_e):_e=t[134];let He;t[135]!==e?(He=e("contextSidebar.stats.cost"),t[135]=e,t[136]=He):He=t[136];let Ke;t[137]!==E.totalAssistantCost?(Ke=j3(E.totalAssistantCost),t[137]=E.totalAssistantCost,t[138]=Ke):Ke=t[138];let Ze;t[139]!==He||t[140]!==Ke?(Ze={label:He,value:Ke},t[139]=He,t[140]=Ke,t[141]=Ze):Ze=t[141];let Xe;t[142]!==de||t[143]!==se||t[144]!==_e||t[145]!==Ze?(Xe=[de,se,_e,Ze],t[142]=de,t[143]=se,t[144]=_e,t[145]=Ze,t[146]=Xe):Xe=t[146];const mt=Xe;let et;t[147]!==mt?(et=s.jsx("div",{className:"mb-5 grid grid-cols-2 gap-2",children:mt.map(F3)}),t[147]=mt,t[148]=et):et=t[148];let ct;t[149]!==e?(ct=e("contextSidebar.section.lastAssistantMessage"),t[149]=e,t[150]=ct):ct=t[150];let lt;t[151]!==ct?(lt=s.jsx("div",{className:"typography-micro text-muted-foreground",children:ct}),t[151]=ct,t[152]=lt):lt=t[152];let ye;t[153]!==e||t[154]!==E.tokenBreakdown.cacheRead||t[155]!==E.tokenBreakdown.cacheWrite||t[156]!==E.tokenBreakdown.input||t[157]!==E.tokenBreakdown.output||t[158]!==E.tokenBreakdown.reasoning?(ye=s.jsx("div",{className:"mt-2.5 grid grid-cols-3 gap-x-4 gap-y-2.5",children:[{label:e("contextSidebar.tokens.input"),value:E.tokenBreakdown.input},{label:e("contextSidebar.tokens.output"),value:E.tokenBreakdown.output},{label:e("contextSidebar.tokens.reasoning"),value:E.tokenBreakdown.reasoning},{label:e("contextSidebar.tokens.cacheRead"),value:E.tokenBreakdown.cacheRead},{label:e("contextSidebar.tokens.cacheWrite"),value:E.tokenBreakdown.cacheWrite}].map(O3)}),t[153]=e,t[154]=E.tokenBreakdown.cacheRead,t[155]=E.tokenBreakdown.cacheWrite,t[156]=E.tokenBreakdown.input,t[157]=E.tokenBreakdown.output,t[158]=E.tokenBreakdown.reasoning,t[159]=ye):ye=t[159];let Ge;t[160]!==lt||t[161]!==ye?(Ge=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[lt,ye]}),t[160]=lt,t[161]=ye,t[162]=Ge):Ge=t[162];let $e;t[163]!==ue||t[164]!==E.breakdownTotal?($e=s.jsx("div",{className:"flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:ue.map(jt=>jt.value<=0||E.breakdownTotal<=0?null:s.jsx("div",{style:{width:`${jt.value/E.breakdownTotal*100}%`,backgroundColor:jt.color}},jt.key))}),t[163]=ue,t[164]=E.breakdownTotal,t[165]=$e):$e=t[165];let Ve;t[166]!==ue||t[167]!==E.breakdownTotal?(Ve=s.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-x-4 gap-y-1",children:ue.map(jt=>{const Dt=E.breakdownTotal>0?jt.value/E.breakdownTotal*100:0;return s.jsxs("div",{className:"inline-flex items-center gap-1.5",children:[s.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{backgroundColor:jt.color}}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70",children:[jt.label," ",s.jsxs("span",{className:"tabular-nums",children:[Dt.toFixed(0),"%"]})]})]},jt.key)})}),t[166]=ue,t[167]=E.breakdownTotal,t[168]=Ve):Ve=t[168];let tt;t[169]!==$e||t[170]!==Ve?(tt=s.jsxs("div",{className:"mb-6",children:[$e,Ve]}),t[169]=$e,t[170]=Ve,t[171]=tt):tt=t[171];let Qe;t[172]!==e?(Qe=e("contextSidebar.section.rawMessages"),t[172]=e,t[173]=Qe):Qe=t[173];let ze;t[174]!==Qe?(ze=s.jsx("div",{className:"typography-micro text-muted-foreground",children:Qe}),t[174]=Qe,t[175]=ze):ze=t[175];let ht;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=Dt=>{const ts=Uo(Dt.info).role,it=o[Dt.info.id]===!0,Yt=d===Dt.info.id,Qt=Dt.info.time?.created??null,Xt=it?JSON.stringify({info:Dt.info,parts:Dt.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":it,onClick:()=>{c(us=>({...us,[Dt.info.id]:us[Dt.info.id]!==!0}))},children:s.jsxs("div",{className:"flex items-center justify-between gap-2 whitespace-nowrap overflow-hidden",children:[s.jsxs("span",{className:"min-w-0 inline-flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:k3(ts)}),s.jsx("span",{className:"min-w-0 truncate typography-micro text-muted-foreground",children:Dt.info.id})]}),s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:S3(Qt)})]})}),it&&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:us=>{us.stopPropagation(),S(Dt.info.id,Xt)},"aria-label":e(Yt?"contextSidebar.actions.copied":"contextSidebar.actions.copyJson"),title:e(Yt?"contextSidebar.actions.copied":"contextSidebar.actions.copy"),children:Yt?s.jsx(Ys,{className:"size-3.5"}):s.jsx(br,{className:"size-3.5"})})}),s.jsx(by,{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:Xt})]})})]},Dt.info.id)},t[182]=d,t[183]=o,t[184]=a,t[185]=e,t[186]=jt):jt=t[186],ht=[...b].reverse().map(jt),t[176]=d,t[177]=o,t[178]=b,t[179]=a,t[180]=e,t[181]=ht}else ht=t[181];let _t;t[187]!==ht?(_t=s.jsx("div",{className:"mt-2.5 space-y-1",children:ht}),t[187]=ht,t[188]=_t):_t=t[188];let Kt;t[189]!==ze||t[190]!==_t?(Kt=s.jsxs("div",{children:[ze,_t]}),t[189]=ze,t[190]=_t,t[191]=Kt):Kt=t[191];let Ut;return t[192]!==Se||t[193]!==Ae||t[194]!==et||t[195]!==Ge||t[196]!==tt||t[197]!==Kt?(Ut=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:[Se,Ae,et,Ge,tt,Kt]})}),t[192]=Se,t[193]=Ae,t[194]=et,t[195]=Ge,t[196]=tt,t[197]=Kt,t[198]=Ut):Ut=t[198],Ut};function A3(t){return t.currentSessionId}function P3(t){return t.providers}function D3(t){return Object.keys(t).length>0?{}:t}function T3(t){return Uo(t.info).role==="assistant"}function M3(t){return Uo(t.info).isUser}function R3(t,e){const n=Va(e.info.cost);return t+n}function E3(t){return Uo(t.info).isUser&&typeof t.info.system=="string"}function F3(t){return s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 px-3 py-2.5",children:[s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:t.label}),s.jsx("div",{className:"mt-0.5 typography-ui-label tabular-nums text-foreground",children:t.value})]},t.label)}function O3(t){return s.jsxs("div",{children:[s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:t.label}),s.jsx("div",{className:"mt-0.5 typography-ui-label tabular-nums text-foreground",children:Ci(t.value)})]},t.label)}const L3=360,$3=1400,Sx=600,B3=24,Gp=200,V3=(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",qp=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"},z3=({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
- `)},_3=async(t,e)=>{const n=typeof window<"u"?window.__TAURI__:void 0;if(typeof n?.core?.invoke=="function")try{const r=t.getBoundingClientRect(),a=await n.core.invoke("desktop_capture_page_rect",{x:r.left,y:r.top,width:r.width,height:r.height}),i=new Image;await new Promise((y,x)=>{i.onload=()=>y(),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(y=>m.toBlob(y,"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},U3=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+$/g,"");return r=r.replace(/\/+/g,"/"),n&&!r.startsWith("//")&&(r=`/${r}`),r===""?e.startsWith("/")?"/":"":r},Qp=t=>Number.isFinite(t)?Math.min($3,Math.max(L3,Math.round(t))):Sx,W3=(t,e)=>{if(!t)return"";const n=t.replace(/\\/g,"/"),r=e.replace(/\\/g,"/").replace(/\/+$/,"");return r&&n.startsWith(r+"/")?n.slice(r.length+1):n},K3=(t,e)=>e(t==="chat"?"contextPanel.mode.chat":t==="file"?"contextPanel.mode.files":t==="diff"?"contextPanel.mode.diff":t==="plan"?"contextPanel.mode.plan":t==="preview"?"contextPanel.mode.preview":"contextPanel.mode.context"),H3=t=>{if(!t)return null;const e=t.replace(/\\/g,"/").trim();if(!e)return null;const n=e.split("/").filter(Boolean);return n.length===0?e:n[n.length-1]||null},G3=(t,e)=>{if(t.label)return t.label;if(t.mode==="file")return H3(t.targetPath)||e("contextPanel.mode.files");if(t.mode==="preview"){const n=t.targetPath;if(n)try{const r=new URL(n);return r.host||r.hostname||e("contextPanel.mode.preview")}catch{}return e("contextPanel.mode.preview")}return K3(t.mode,e)},q3=t=>{if(t.mode==="file")return t.targetPath?s.jsx(Pr,{filePath:t.targetPath,className:"h-3.5 w-3.5"}):void 0;if(t.mode==="diff")return s.jsx(yy,{className:"h-3.5 w-3.5"});if(t.mode==="plan")return s.jsx(zl,{className:"h-3.5 w-3.5"});if(t.mode==="context")return s.jsx(Ph,{className:"h-3.5 w-3.5"});if(t.mode==="chat")return s.jsx(dc,{className:"h-3.5 w-3.5"});if(t.mode==="preview")return s.jsx(ti,{className:"h-3.5 w-3.5 text-[var(--status-info)]"})},Q3=t=>!t||!t.startsWith("session:")?null:t.slice(8).trim()||null,J3=(t,e)=>{if(typeof window>"u")return"";const n=new URL(window.location.pathname,window.location.origin);return n.searchParams.set("ocPanel","session-chat"),n.searchParams.set("sessionId",t),e&&e.trim().length>0?n.searchParams.set("directory",e):n.searchParams.delete("directory"),n.hash="",n.toString()},Y3=(t,e)=>t.length<=e?t:`${t.slice(0,e-3)}...`,_a=new Map,X3=3e4,Z3=t=>{const e=_a.get(t);return e?e.expiresAt-Date.now()<=X3?(_a.delete(t),null):e:null},e5=({rawUrl:t,onNavigate:e})=>{const{t:n}=ut(),{currentTheme:r}=Rr(),[a,i]=l.useReducer(me=>me+1,0),[o,c]=l.useReducer(me=>me+1,0),[d,p]=l.useState({status:"idle"}),m=l.useRef(null),u=l.useRef(1),[h,b]=l.useState(!1),[f,y]=l.useState(!1),[x,g]=l.useState("all"),[w,v]=l.useState([]),[S,A]=l.useState(!1),[j,C]=l.useState(null),I=Wt(me=>me.currentSessionId),R=Wt(me=>me.newSessionDraft?.open),k=ho(me=>me.addDraft),P=Ui(me=>me.addAttachedFile);let N=null;try{N=t?new URL(t):null}catch{N=null}const D=N?N.hostname==="localhost"||N.hostname==="127.0.0.1"||N.hostname==="::1"||N.hostname==="[::1]"||N.hostname==="0.0.0.0":!1,T=N?N.hostname==="0.0.0.0"?new URL(N.toString().replace("0.0.0.0","127.0.0.1")):N:null,M=T?T.toString():"",$=r.metadata.variant;l.useEffect(()=>{if(!M||!D){p({status:"idle"});return}const me=Z3(M);if(me){p({status:"ready",proxyBasePath:me.proxyBasePath,expiresAt:me.expiresAt});return}let we=!1;return p({status:"loading"}),(async()=>{try{const _=await fetch("/api/preview/targets",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({url:M})});if(!_.ok){_a.delete(M);const Z=await _.json().catch(()=>({})),Ie=typeof Z?.error=="string"?Z.error:`HTTP ${_.status}`;we||p({status:"error",message:Ie});return}const ue=await _.json(),Q=typeof ue.proxyBasePath=="string"?ue.proxyBasePath:"",oe=typeof ue.expiresAt=="number"?ue.expiresAt:0;if(!Q){_a.delete(M),we||p({status:"error",message:n("contextPanel.preview.proxyError")});return}_a.set(M,{proxyBasePath:Q,expiresAt:oe}),we||p({status:"ready",proxyBasePath:Q,expiresAt:oe})}catch(_){if(_a.delete(M),!we){const ue=_ instanceof Error?_.message:String(_);p({status:"error",message:ue})}}})(),()=>{we=!0}},[D,o,n,M]);const F=T&&(T.protocol==="http:"||T.protocol==="https:")?T.toString():"",V=D&&d.status==="ready"&&T?(()=>{const me=T.pathname||"/",we=new URLSearchParams(T.search);we.set("ocPreview",String(a));const _=we.toString(),ue=T.hash||"";return`${d.proxyBasePath}${me}${_?`?${_}`:""}${ue}`})():"",O=D?V:F,L=O||F,W=D&&(d.status==="loading"||d.status==="idle"),B=D&&d.status==="error",ne=l.useCallback(me=>{const we=I??(R?"draft":null);if(!we){q.error(n("contextPanel.preview.inspect.attachNoSession"));return}const _=t||O||"",ue=typeof window<"u"?{width:window.innerWidth,height:window.innerHeight}:{width:0,height:0},Q=typeof window<"u"?window.devicePixelRatio:1;(async()=>{let oe=!1;try{const Z=m.current,Ie=Z?await _3(Z,me):null;Ie&&(await P(Ie),oe=!0)}catch{oe=!1}k({sessionKey:we,source:"preview-annotation",fileLabel:_||"preview",startLine:1,endLine:1,code:z3({pageUrl:_,viewport:ue,devicePixelRatio:Q,target:me,screenshotAttached:oe,intro:n("contextPanel.preview.inspect.attachAnnotation")}),language:"markdown",text:""}),q.success(n("contextPanel.preview.inspect.attached"))})()},[P,k,I,O,R,t,n]);l.useEffect(()=>{b(!1),v([]),y(!1),g("all"),A(!1),C(null),u.current=1},[O]),l.useEffect(()=>{const me=m.current?.contentWindow;!h||!me||me.postMessage({source:"openchamber-preview-parent",version:1,type:"set-inspect-mode",enabled:S},window.location.origin)},[h,S]),l.useEffect(()=>{const me=m.current?.contentWindow;!h||!me||me.postMessage({source:"openchamber-preview-parent",version:1,type:"set-color-scheme",scheme:$},window.location.origin)},[h,$]),l.useEffect(()=>{if(!S||typeof window>"u")return;const me=we=>{we.key==="Escape"&&(we.preventDefault(),we.stopImmediatePropagation(),A(!1))};return window.addEventListener("keydown",me,!0),()=>window.removeEventListener("keydown",me,!0)},[S]),l.useEffect(()=>{if(!D||typeof window>"u")return;const me=ue=>{if(typeof ue=="string")return ue;if(ue==null)return"";try{return JSON.stringify(ue)}catch{return String(ue)}},we=ue=>{const Q=u.current;u.current+=1,v(oe=>{const Z=[...oe,{...ue,id:Q}];return Z.length>Gp?Z.slice(Z.length-Gp):Z})},_=ue=>{if(ue.source!==m.current?.contentWindow)return;const Q=ue.data;if(!(!Q||Q.source!=="openchamber-preview-bridge"||Q.version!==1)){if(Q.type==="ready"){b(!0);return}if(Q.type==="console"){const oe=Q.level==="error"||Q.level==="warn"||Q.level==="info"||Q.level==="debug"?Q.level:"log",Z=Array.isArray(Q.args)?Q.args.map(me).filter(Boolean):[];we({level:oe,message:Z.join(" "),ts:typeof Q.ts=="number"?Q.ts:Date.now()});return}if(Q.type==="runtime-error"){const oe=me(Q.filename),Z=typeof Q.line=="number"?Q.line:null,Ie=typeof Q.column=="number"?Q.column:null,Se=oe?`${oe}${Z!==null?`:${Z}${Ie!==null?`:${Ie}`:""}`:""}`:"",Y=me(Q.stack);we({level:"runtime",message:me(Q.message)||n("contextPanel.preview.console.runtimeError"),details:[Se,Y].filter(Boolean).join(`
57
- `),ts:typeof Q.ts=="number"?Q.ts:Date.now()});return}if(Q.type==="resource-error"){const oe=me(Q.tag)||"resource",Z=me(Q.url);we({level:"resource",message:Z?`${oe}: ${Z}`:oe,details:me(Q.outerHTML),ts:typeof Q.ts=="number"?Q.ts:Date.now()});return}if(Q.type==="hover"){C(qp(Q.target)?Q.target:null);return}if(Q.type==="select"&&qp(Q.target)){C(Q.target),A(!1),ne(Q.target);return}if(Q.type==="navigate-preview"){const oe=typeof Q.url=="string"?Q.url:"",Z=Q.navigation==="external"?"external":"proxy";if(oe&&Z==="external"){lr(oe);return}oe&&e(oe)}}};return window.addEventListener("message",_),()=>{window.removeEventListener("message",_)}},[ne,D,e,n]);const le=w.filter(me=>me.level==="error"||me.level==="runtime"||me.level==="resource").length,ee=w.filter(me=>V3(me,x)),ae=l.useCallback(()=>{const me=[`Preview URL: ${t||O||""}`,`Events: ${w.length}`,""].join(`
58
- `),we=w.map(_=>{const ue=new Date(_.ts).toISOString(),Q=_.details?`
59
- ${_.details}`:"";return`[${ue}] [${_.level}] ${_.message}${Q}`}).join(`
60
- `);_n(`${me}${we}`).then(_=>{_.ok?q.success(n("contextPanel.preview.console.copied")):q.error(n("contextPanel.preview.console.copyFailed"))})},[w,O,t,n]),ge=l.useCallback(()=>{const me=I??(R?"draft":null);if(!me){q.error(n("contextPanel.preview.console.attachNoSession"));return}const we=[`Preview URL: ${t||O||""}`,`Events: ${w.length}`,""].join(`
61
- `),_=w.map(ue=>{const Q=new Date(ue.ts).toISOString(),oe=ue.details?`
62
- ${ue.details}`:"";return`[${Q}] [${ue.level}] ${ue.message}${oe}`}).join(`
63
- `);k({sessionKey:me,source:"preview-console",fileLabel:t||O||"preview",startLine:1,endLine:Math.max(1,w.length),code:`${we}${_}`,language:"text",text:n("contextPanel.preview.console.attachAnnotation")}),q.success(n("contextPanel.preview.console.attached"))},[k,w,I,O,R,t,n]),[te,E]=l.useState("unknown"),z=l.useRef(0),J=l.useRef(0),H=15e3;l.useEffect(()=>{if(!V){E("unknown"),z.current=0,J.current=0;return}let me=!1;return z.current||(z.current=Date.now(),J.current=0),E("unknown"),(async()=>{const _=await(async()=>{try{return await fetch(V,{method:"GET",credentials:"include",cache:"no-store",redirect:"manual"})}catch{return null}})();if(me)return;if(!_){E("unreachable");return}if(_.status===403||_.status===404){_a.delete(M),p({status:"loading"}),c();return}if(_.status!==502){E("reachable");return}const ue=z.current||Date.now();if(Date.now()-ue<H){E("starting"),J.current+=1;const oe=J.current,Z=Math.min(2e3,250*Math.pow(2,Math.min(4,oe)));setTimeout(()=>{me||i()},Z).unref?.();return}E("unreachable")})(),()=>{me=!0}},[V,a,M]);const re=D&&d.status==="ready"&&(te==="unknown"||te==="starting"),ce=D&&d.status==="ready"&&te==="unreachable",Ne=l.useCallback(me=>{if(!D||d.status!=="ready"||typeof window>"u")return;const we=me.currentTarget.contentWindow;if(we)try{const _=we.location;if(_.origin!==window.location.origin||_.pathname.startsWith(d.proxyBasePath))return;const ue=`${d.proxyBasePath}${_.pathname}${_.search}${_.hash}`;we.location.replace(ue)}catch{}},[D,d]);return s.jsxs("div",{className:"absolute inset-0 flex flex-col",children:[s.jsxs("div",{className:"flex items-center gap-1 border-b border-border/40 bg-[var(--surface-background)] px-2 py-1",children:[s.jsx("div",{className:"min-w-0 flex-1 truncate typography-micro text-muted-foreground",title:L||t,children:L||t||n("contextPanel.preview.empty")}),s.jsx(je,{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(Nn,{className:"h-3.5 w-3.5"})}),s.jsx(je,{type:"button",size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{F&&lr(F)},title:n("contextPanel.preview.actions.openExternal"),"aria-label":n("contextPanel.preview.actions.openExternal"),disabled:!F,children:s.jsx(Ir,{className:"h-3.5 w-3.5"})}),D?s.jsx(je,{type:"button",size:"sm",variant:S?"secondary":"ghost",className:"h-7 gap-1 px-2",onClick:()=>A(me=>!me),title:n("contextPanel.preview.inspect.toggle"),"aria-label":n("contextPanel.preview.inspect.toggle"),disabled:!h,children:s.jsx(vy,{className:"h-3.5 w-3.5"})}):null,D?s.jsxs(je,{type:"button",size:"sm",variant:f?"secondary":"ghost",className:"h-7 gap-1 px-2",onClick:()=>y(me=>!me),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(Za,{className:"h-3.5 w-3.5"}),le>0?s.jsx("span",{className:"typography-micro text-status-error",children:le}):null]}):null]}),s.jsxs("div",{className:"relative min-h-0 flex-1 bg-background",children:[re?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center text-sm text-muted-foreground",children:[s.jsx("div",{children:n("contextPanel.preview.startingServer")}),s.jsx("div",{className:"text-xs opacity-70",children:n("contextPanel.preview.startingServerHint")})]}):ce?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center text-sm text-muted-foreground",children:[s.jsx("div",{children:n("contextPanel.preview.upstreamUnreachable")}),s.jsx("div",{className:"text-xs opacity-70",children:n("contextPanel.preview.upstreamUnreachableHint")}),s.jsx(je,{type:"button",size:"sm",variant:"outline",onClick:()=>i(),children:n("contextPanel.preview.actions.retry")})]}):O&&(!D||te==="reachable")?s.jsxs("div",{className:"relative h-full w-full",children:[s.jsx("iframe",{ref:m,src:O,title:n("contextPanel.preview.iframeTitle"),className:"h-full w-full border-0",style:{colorScheme:$},onLoad:Ne,sandbox:D?"allow-scripts allow-same-origin allow-forms allow-popups allow-downloads":"allow-scripts allow-forms"},`${O}:${a}`),S&&j?s.jsx("div",{className:"pointer-events-none absolute rounded-sm border-2 border-[var(--interactive-focus-ring)] bg-[var(--interactive-focus-ring)]/35",style:{left:j.bounds.x,top:j.bounds.y,width:j.bounds.width,height:j.bounds.height},children:s.jsxs("div",{className:"absolute -top-6 left-0 max-w-64 truncate rounded bg-[var(--surface-elevated)] px-2 py-0.5 typography-micro text-foreground shadow",children:[j.tag,j.text?` · ${j.text}`:""]})}):null]}):W?s.jsx("div",{className:"flex h-full items-center justify-center px-6 text-sm text-muted-foreground",children:n("contextPanel.preview.loading")}):B?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 px-6 text-sm text-muted-foreground",children:[s.jsx("div",{children:n("contextPanel.preview.proxyError")}),d.status==="error"?s.jsx("div",{className:"text-center text-xs opacity-70",children:d.message}):null]}):s.jsx("div",{className:"flex h-full items-center justify-center px-6 text-sm text-muted-foreground",children:n("contextPanel.preview.invalidUrl")}),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(je,{type:"button",size:"xs",variant:"ghost",onClick:ge,disabled:w.length===0,children:n("contextPanel.preview.console.attach")}),s.jsx(je,{type:"button",size:"xs",variant:"ghost",onClick:ae,disabled:w.length===0,children:n("contextPanel.preview.console.copy")}),s.jsx(je,{type:"button",size:"xs",variant:"ghost",onClick:()=>v([]),disabled:w.length===0,children:n("contextPanel.preview.console.clear")})]})]}),s.jsx("div",{className:"flex items-center gap-1 border-b border-border/30 px-3 py-1.5",children:["all","errors","warnings","logs"].map(me=>s.jsx(je,{type:"button",size:"xs",variant:x===me?"secondary":"ghost",onClick:()=>g(me),children:n(me==="all"?"contextPanel.preview.console.filter.all":me==="errors"?"contextPanel.preview.console.filter.errors":me==="warnings"?"contextPanel.preview.console.filter.warnings":"contextPanel.preview.console.filter.logs")},me))}),s.jsx("div",{className:"max-h-64 overflow-auto p-2 typography-code text-xs",children:w.length===0?s.jsx("div",{className:"px-2 py-3 text-muted-foreground",children:n("contextPanel.preview.console.empty")}):ee.length===0?s.jsx("div",{className:"px-2 py-3 text-muted-foreground",children:n("contextPanel.preview.console.noFilteredEvents")}):ee.map(me=>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:pe("shrink-0 uppercase",me.level==="error"||me.level==="runtime"||me.level==="resource"?"text-status-error":me.level==="warn"?"text-status-warning":"text-muted-foreground"),children:me.level}),s.jsx("span",{className:"min-w-0 break-words text-foreground",children:me.message})]})},me.id))})]}):null]})]})},t5=()=>{const{t}=ut(),e=Xr()??"",n=l.useMemo(()=>U3(e),[e]),r=Te(H=>n?H.contextPanelByDirectory[n]:void 0),a=Te(H=>H.closeContextPanel),i=Te(H=>H.closeContextPanelTab),o=Te(H=>H.toggleContextPanelExpanded),c=Te(H=>H.setContextPanelWidth),d=Te(H=>H.setActiveContextPanelTab),p=Te(H=>H.reorderContextPanelTabs),m=Te(H=>H.setPendingDiffFile),u=Xn(H=>H.setSelectedPath),h=Te(H=>H.openContextPreview),{themeMode:b,lightThemeId:f,darkThemeId:y,currentTheme:x}=Rr(),g=l.useMemo(()=>r?.tabs??[],[r?.tabs]),w=g.find(H=>H.id===r?.activeTabId)??g[g.length-1]??null,v=!!(r?.isOpen&&w),S=!!(v&&r?.expanded),A=Qp(r?.width??Sx),[j,C]=l.useState(!1),I=l.useRef(0),R=l.useRef(A),k=l.useRef(null),P=l.useRef(null),N=l.useRef(null),D=l.useRef(new Map),T=l.useRef(!1);l.useEffect(()=>{if(!v||T.current){T.current=v;return}const H=window.requestAnimationFrame(()=>{N.current?.focus({preventScroll:!0})});return T.current=!0,()=>window.cancelAnimationFrame(H)},[v]);const M=l.useCallback(H=>{const re=N.current;re&&re.style.setProperty("--oc-context-panel-width",`${H}px`)},[]),$=l.useCallback(H=>{if(!(!v||S||!n)){try{H.currentTarget.setPointerCapture(H.pointerId)}catch{}P.current=H.pointerId,C(!0),I.current=H.clientX,R.current=A,k.current=A,M(A),H.preventDefault()}},[M,n,S,v,A]),F=l.useCallback(H=>{if(!j||P.current!==H.pointerId)return;const re=I.current-H.clientX,ce=Qp(R.current+re);k.current!==ce&&(k.current=ce,M(ce))},[M,j]),V=l.useCallback(H=>{if(P.current!==H.pointerId||!n)return;try{H.currentTarget.releasePointerCapture(H.pointerId)}catch{}const re=k.current??A;C(!1),P.current=null,k.current=null,c(n,re)},[n,c,A]);l.useEffect(()=>{j||(k.current=null)},[j]);const O=l.useCallback(()=>{n&&a(n)},[a,n]),L=l.useCallback(()=>{n&&o(n)},[n,o]),W=l.useCallback(H=>{H.key==="Escape"&&(H.preventDefault(),H.stopPropagation(),O())},[O]);l.useEffect(()=>{if(!(!n||!w)){if(w.mode==="file"&&w.targetPath){u(n,w.targetPath);return}w.mode==="diff"&&w.targetPath&&m(w.targetPath)}},[w,n,m,u]);const B=w?.mode==="chat"?w.id:null,ne=l.useCallback(()=>{if(typeof window>"u")return;const H={themeMode:b,lightThemeId:f,darkThemeId:y,currentTheme:x};for(const re of D.current.values()){const ce=re.contentWindow;if(!ce)continue;const Ne=ce.__openchamberApplyThemeSync;if(typeof Ne=="function")try{Ne(H);continue}catch{}ce.postMessage({type:"openchamber:theme-sync",payload:H},window.location.origin)}},[x,y,f,b]),le=l.useCallback(()=>{if(!(typeof window>"u"))for(const[H,re]of D.current.entries()){const ce=re.contentWindow;if(!ce)continue;const Ne={visible:B===H},me=ce.__openchamberSetEmbeddedVisibility;if(typeof me=="function")try{me(Ne);continue}catch{}ce.postMessage({type:"openchamber:embedded-visibility",payload:Ne},window.location.origin)}},[B]);l.useLayoutEffect(()=>{g.some(re=>re.mode==="chat")&&(ne(),le())},[y,f,le,ne,g,b]);const ee=l.useMemo(()=>g.map(H=>{const re=G3(H,t),ce=Y3(re,B3),Ne=W3(H.targetPath,e);return{id:H.id,label:ce,icon:q3(H),title:Ne?`${re}: ${Ne}`:re,closeLabel:t("contextPanel.tab.closeTabAria",{label:ce})}}),[e,t,g]),ae=w?.mode==="diff"?s.jsx(xx,{hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!0,hideFileSelector:!0,pinSelectedFileHeaderToTopOnNavigate:!0,showOpenInEditorAction:!0}):w?.mode==="context"?s.jsx(I3,{}):w?.mode==="plan"?s.jsx(Nx,{targetPath:w.targetPath}):w?.mode==="preview"?s.jsx(e5,{rawUrl:w.targetPath??"",onNavigate:H=>h(e,H)}):s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[s.jsx(ti,{className:"h-12 w-12 text-muted-foreground/50"}),s.jsx("div",{className:"typography-ui-header text-foreground",children:t("contextPanel.preview.title")}),s.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:t("contextPanel.preview.description")})]}),ge=l.useMemo(()=>g.filter(H=>H.mode==="chat"),[g]),te=l.useMemo(()=>g.some(H=>H.mode==="file"),[g]),E=w?.mode==="file",z=s.jsxs("header",{className:"flex h-8 items-stretch border-b border-transparent",children:[s.jsx(Br,{items:ee,activeId:w?.id??null,onSelect:H=>{n&&d(n,H)},onClose:H=>{n&&i(n,H)},onReorder:(H,re)=>{n&&p(n,H,re)},layoutMode:"scrollable",variant:"default"}),s.jsxs("div",{className:"flex items-center gap-1 px-1.5",children:[s.jsx(je,{type:"button",variant:"ghost",size:"sm",onClick:L,className:"h-7 w-7 p-0",title:t(S?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),"aria-label":t(S?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),children:S?s.jsx(Md,{className:"h-3.5 w-3.5"}):s.jsx(Hh,{className:"h-3.5 w-3.5"})}),s.jsx(je,{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(Ds,{className:"h-3.5 w-3.5"})})]})]});if(!v)return null;const J=S?{"--oc-context-panel-width":"100%",width:"100%",minWidth:"100%",maxWidth:"100%"}:{width:"var(--oc-context-panel-width)",minWidth:"var(--oc-context-panel-width)",maxWidth:"var(--oc-context-panel-width)","--oc-context-panel-width":`${j?k.current??A:A}px`};return s.jsxs("aside",{ref:N,"data-context-panel":"true",tabIndex:-1,className:pe("flex min-h-0 flex-col overflow-hidden bg-background",!S&&"border-l border-border/40",S?"absolute inset-0 z-20 min-w-0":"relative h-full flex-shrink-0",j?"transition-none":"transition-[width] duration-200 ease-in-out"),onKeyDownCapture:W,style:J,children:[!S&&s.jsx("div",{className:pe("absolute left-0 top-0 z-20 h-full w-[3px] cursor-col-resize transition-colors hover:bg-[var(--interactive-border)]/80",j&&"bg-[var(--interactive-border)]"),onPointerDown:$,onPointerMove:F,onPointerUp:V,onPointerCancel:V,role:"separator","aria-orientation":"vertical","aria-label":t("contextPanel.actions.resizePanelAria")}),z,s.jsxs("div",{className:pe("relative min-h-0 flex-1 overflow-hidden",j&&"pointer-events-none"),children:[te?s.jsx("div",{className:pe("absolute inset-0",E?"block":"hidden"),children:s.jsx(jx,{mode:"editor-only"})}):null,ge.map(H=>{const re=Q3(H.dedupeKey);if(!re)return null;const ce=J3(re,n||null);return ce?s.jsx("iframe",{ref:Ne=>{if(!Ne){D.current.delete(H.id);return}D.current.set(H.id,Ne)},src:ce,title:t("contextPanel.iframe.sessionChatTitle",{sessionID:re}),className:pe("absolute inset-0 h-full w-full border-0 bg-background",B===H.id?"block":"hidden"),onLoad:()=>{ne(),le()}},H.id):null}),w?.mode!=="chat"&&!E?ae:null]})]})},Qu=[{slug:"home",title:"Settings",group:"general",kind:"single",description:"Search and jump to common pages.",keywords:["search","settings"]},{slug:"projects",title:"Projects",group:"projects",kind:"split",keywords:["project","projects","worktree","worktrees","repo","repository","directory"]},{slug:"remote-instances",title:"Remote Instances",group:"projects",kind:"split",keywords:["ssh","remote","instances","tunnels","forwarding","connection"],isAvailable:t=>t.isDesktop&&!t.isWeb&&!t.isVSCode},{slug:"providers",title:"Providers",group:"opencode",kind:"split",keywords:["provider","providers","models","model","api key","api keys","openai","anthropic","ollama","credentials"]},{slug:"usage",title:"Usage",group:"usage",kind:"split",keywords:["quota","billing","tokens","usage","limits"]},{slug:"agents",title:"Agents",group:"opencode",kind:"split",keywords:["agent","agents","prompts","tools","permissions"]},{slug:"behavior",title:"Behavior",group:"opencode",kind:"single",keywords:["behavior","agents.md","system prompt","global rules","instructions","override"]},{slug:"commands",title:"Commands",group:"opencode",kind:"split",keywords:["command","commands","slash","macros","automation"]},{slug:"mcp",title:"MCP",group:"opencode",kind:"split",keywords:["mcp","model context protocol","servers","tools","remote","stdio"]},{slug:"skills.installed",title:"Skills",group:"skills",kind:"split",keywords:["skill","skills","instructions","install","catalog"]},{slug:"skills.catalog",title:"Skills Catalog",group:"skills",kind:"single",keywords:["install","catalog","external","repository","skills catalog"]},{slug:"git",title:"Git",group:"git",kind:"single",keywords:["git","github","identity","identities","ssh","profiles","credentials","keys","commit","gitmoji","oauth","prs","issues"],isAvailable:t=>!t.isVSCode},{slug:"appearance",title:"Appearance",group:"appearance",kind:"single",keywords:["theme","font","spacing","padding","corner radius","radius","input bar","keyboard","viewport","mobile","terminal","pwa","install name","app shortcuts"]},{slug:"chat",title:"Chat",group:"general",kind:"single",keywords:["tools","diff","reasoning","dotfiles","draft","queue","output","copy","image","split messages","message actions"]},{slug:"shortcuts",title:"Shortcuts",group:"general",kind:"single",keywords:["keyboard","hotkeys","shortcuts","bindings"],isAvailable:t=>!t.isVSCode},{slug:"sessions",title:"Sessions",group:"general",kind:"single",keywords:["defaults","default agent","default model","retention","memory","limits","zen"]},{slug:"magic-prompts",title:"Magic Prompts",group:"general",kind:"split",keywords:["prompts","templates","git","github","review","commit","pull request"],isAvailable:t=>!t.isVSCode},{slug:"notifications",title:"Notifications",group:"general",kind:"single",keywords:["alerts","native","summary","summarization"]},{slug:"voice",title:"Voice",group:"advanced",kind:"single",keywords:["tts","speech","voice"],isAvailable:t=>!t.isVSCode},{slug:"tunnel",title:"Remote Tunnel",group:"advanced",kind:"single",keywords:["tunnel","cloudflare","qr","remote","mobile","share"],isAvailable:t=>!t.isVSCode}],s5={sessions:"sessions",agents:"agents",commands:"commands",mcp:"mcp",skills:"skills.installed",providers:"providers",usage:"usage","git-identities":"git",settings:"home"};function xo(t){const e=t.trim().toLowerCase();return Qu.find(n=>n.slug===e)??null}function kx(t){const e=(t??"").trim().toLowerCase();if(!e)return"home";const n=s5[e];if(n)return n;const r=xo(e);return r?r.slug:"home"}const Cx=t=>t.replace(/[-_]/g," ").replace(/\b\w/g,e=>e.toUpperCase()),Go=t=>{const e=nt.c(39),{className:n}=t,{t:r}=ut(),a=Fs(n5),i=Fs(r5),o=Fs(a5),c=yn();let d;e[0]!==a?(d=[...a].sort(i5),e[0]=a,e[1]=d):d=e[1];const p=d;let m;e:{if(p.length===0){m=null;break e}let T;e[2]!==i||e[3]!==p?(T=p.find(M=>M.id===i)??p[0],e[2]=i,e[3]=p,e[4]=T):T=e[4],m=T}const u=m;if(c||p.length===0)return null;let 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=Cx(b),e[8]=b,e[9]=f):f=e[9];const y=f;let x;e[10]!==n?(x=pe(n),e[10]=n,e[11]=x):x=e[11];let g;e[12]!==r?(g=r("settings.shared.projectSelector.switchProjectAria"),e[12]=r,e[13]=g):g=e[13];let w;e[14]!==r?(w=r("settings.shared.projectSelector.switchProjectTitle"),e[14]=r,e[15]=w):w=e[15];let v,S;e[16]===Symbol.for("react.memo_cache_sentinel")?(v=pe("text-foreground border border-border/80 appearance-none flex h-8 w-full min-w-0 rounded-lg bg-transparent px-3 py-1 outline-none","hover:border-input focus-visible:ring-1 focus-visible:ring-primary/50 focus-visible:border-primary/70","flex items-center gap-1.5 text-left"),S=s.jsx(zn,{className:"h-4 w-4 opacity-70"}),e[16]=v,e[17]=S):(v=e[16],S=e[17]);let A;e[18]!==y?(A=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium",children:y}),e[18]=y,e[19]=A):A=e[19];let j;e[20]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(Cs,{className:"size-4 opacity-50"}),e[20]=j):j=e[20];let C;e[21]!==A||e[22]!==g||e[23]!==w?(C=s.jsx(Bs,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":g,title:w,className:v,children:[S,A,j]})}),e[21]=A,e[22]=g,e[23]=w,e[24]=C):C=e[24];const I=u?.id??"";let R;e[25]!==o?(R=T=>{T&&o(T)},e[25]=o,e[26]=R):R=e[26];let k;e[27]!==p?(k=p.map(o5),e[27]=p,e[28]=k):k=e[28];let P;e[29]!==I||e[30]!==R||e[31]!==k?(P=s.jsx(Vs,{align:"start",className:"w-auto",children:s.jsx(Hl,{value:I,onValueChange:R,children:k})}),e[29]=I,e[30]=R,e[31]=k,e[32]=P):P=e[32];let N;e[33]!==C||e[34]!==P?(N=s.jsxs(zs,{children:[C,P]}),e[33]=C,e[34]=P,e[35]=N):N=e[35];let D;return e[36]!==N||e[37]!==x?(D=s.jsx("div",{className:x,children:N}),e[36]=N,e[37]=x,e[38]=D):D=e[38],D};function n5(t){return t.projects}function r5(t){return t.activeProjectId}function a5(t){return t.setActiveProject}function i5(t,e){return(t.label||t.path).localeCompare(e.label||e.path)}function o5(t){const e=t.label?.trim()?t.label.trim():t.path.split("/").filter(Boolean).pop()||t.path,n=Cx(e);return s.jsx(Gl,{value:t.id,children:s.jsx("span",{className:"min-w-0 truncate typography-ui",children:n})},t.id)}function l5(t,e){return`opencode:sidebar-group:${t}:${e}`}const ru=t=>{const e=nt.c(30),{label:n,count:r,storageKey:a,defaultExpanded:i,children:o}=t,c=i===void 0?!0:i;let d;e[0]!==n||e[1]!==a?(d=l5(a,n),e[0]=n,e[1]=a,e[2]=d):d=e[2];const p=d;let m;e[3]!==c||e[4]!==p?(m=()=>{try{const R=localStorage.getItem(p);if(R!==null)return R==="true"}catch{}return c},e[3]=c,e[4]=p,e[5]=m):m=e[5];const[u,h]=Oe.useState(m);let b,f;e[6]!==u||e[7]!==p?(b=()=>{try{localStorage.setItem(p,String(u))}catch{}},f=[p,u],e[6]=u,e[7]=p,e[8]=b,e[9]=f):(b=e[8],f=e[9]),Oe.useEffect(b,f);let y,x;e[10]===Symbol.for("react.memo_cache_sentinel")?(y=()=>h(c5),x=pe("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[10]=y,e[11]=x):(y=e[10],x=e[11]);const g=!u&&"-rotate-90";let w;e[12]!==g?(w=pe("h-3.5 w-3.5 flex-shrink-0 transition-transform duration-200",g),e[12]=g,e[13]=w):w=e[13];let v;e[14]!==w?(v=s.jsx(Cs,{className:w}),e[14]=w,e[15]=v):v=e[15];let S;e[16]!==n?(S=s.jsx("span",{className:"flex-1 truncate",children:n}),e[16]=n,e[17]=S):S=e[17];let A;e[18]!==r?(A=s.jsx("span",{className:"ml-1 tabular-nums opacity-60",children:r}),e[18]=r,e[19]=A):A=e[19];let j;e[20]!==v||e[21]!==S||e[22]!==A?(j=s.jsxs("button",{type:"button",onClick:y,className:x,children:[v,S,A]}),e[20]=v,e[21]=S,e[22]=A,e[23]=j):j=e[23];let C;e[24]!==o||e[25]!==u?(C=u&&s.jsx("div",{className:"mt-0.5 space-y-0.5 ml-2 pl-3 border-l-2 border-[var(--interactive-border)]",children:o}),e[24]=o,e[25]=u,e[26]=C):C=e[26];let I;return e[27]!==j||e[28]!==C?(I=s.jsxs("div",{children:[j,C]}),e[27]=j,e[28]=C,e[29]=I):I=e[29],I};function c5(t){return!t}const d5=t=>{if(!Array.isArray(t))return[];const e=[];for(const n of t){if(!n||typeof n!="object")continue;const r=n;typeof r.permission!="string"||typeof r.pattern!="string"||typeof r.action!="string"||r.action!=="allow"&&r.action!=="ask"&&r.action!=="deny"||e.push({permission:r.permission,pattern:r.pattern,action:r.action})}return e},u5=t=>{const e=new Map;for(const n of t)!n.permission||n.permission==="invalid"||n.pattern&&e.set(`${n.permission}::${n.pattern}`,n);return Array.from(e.values())},Jp=t=>{const e=u5(d5(t));if(e.length===0)return;const n={};for(const a of e)a.permission&&((n[a.permission]||={})[a.pattern]=a.action);const r={};for(const[a,i]of Object.entries(n)){const o=Object.keys(i);if(o.length===1&&o[0]==="*"){r[a]=i["*"];continue}r[a]=i}return Object.keys(r).length>0?r:void 0},m5=({onItemSelect:t})=>{const{t:e}=ut(),[n,r]=l.useState(null),[a,i]=l.useState(""),[o,c]=l.useState(null),[d,p]=l.useState(null),[m,u]=l.useState(!1),[h,b]=l.useState(null),{selectedAgentName:f,agents:y,setSelectedAgent:x,setAgentDraft:g,createAgent:w,deleteAgent:v,loadAgents:S}=_i(jr(L=>({selectedAgentName:L.selectedAgentName,agents:L.agents,setSelectedAgent:L.setSelectedAgent,setAgentDraft:L.setAgentDraft,createAgent:L.createAgent,deleteAgent:L.deleteAgent,loadAgents:L.loadAgents})));l.useEffect(()=>{S()},[S]);const A="bg-background",j=()=>{const L="new-agent";let W=L,B=1;for(;y.some(ne=>ne.name===W);)W=`${L}-${B}`,B++;g({name:W,scope:"user"}),x(W),t?.()},C=async L=>{if(Pi(L)){q.error(e("settings.agents.sidebar.toast.builtInCannotDelete"));return}c(L),p("delete")},I=async L=>{Pi(L)&&(c(L),p("reset"))},R=()=>{c(null),p(null)},k=async()=>{if(!o||!d)return;u(!0),await v(o.name)?(d==="delete"?q.success(e("settings.agents.sidebar.toast.agentDeleted",{name:o.name})):q.success(e("settings.agents.sidebar.toast.agentReset",{name:o.name})),R()):d==="delete"?q.error(e("settings.agents.sidebar.toast.deleteFailed")):q.error(e("settings.agents.sidebar.toast.resetFailed")),u(!1)},P=L=>{const W=L.name;let B=1,ne=`${W}-copy`;for(;y.some(ge=>ge.name===ne);)B++,ne=`${W}-copy-${B}`;const le=L,ee=L.model?.providerID&&L.model?.modelID?`${L.model.providerID}/${L.model.modelID}`:null,ae=L;g({name:ne,scope:le.scope||"user",description:L.description,model:ee,temperature:L.temperature,top_p:L.topP,prompt:L.prompt,mode:L.mode,permission:Jp(L.permission),disable:ae.disable}),x(ne)},N=L=>{i(L.name),r(L)},D=async()=>{if(!n)return;const L=a.trim().replace(/\s+/g,"-");if(!L){q.error(e("settings.agents.sidebar.toast.agentNameRequired"));return}if(L===n.name){r(null);return}if(y.some(le=>le.name===L)){q.error(e("settings.agents.sidebar.toast.agentExists"));return}const W=n.model?.providerID&&n.model?.modelID?`${n.model.providerID}/${n.model.modelID}`:null,B=n;await w({name:L,description:n.description,model:W,temperature:n.temperature,top_p:n.topP,prompt:n.prompt,mode:n.mode,permission:Jp(n.permission),disable:B.disable,scope:B.scope})?await v(n.name)?(q.success(`Agent renamed to "${L}"`),x(L)):q.error(e("settings.agents.sidebar.toast.removeOldAfterRenameFailed")):q.error(e("settings.agents.sidebar.toast.renameFailed")),r(null)},T=L=>{switch(L){case"primary":return s.jsx(Du,{className:"h-3 w-3 text-primary"});case"all":return s.jsx(jy,{className:"h-3 w-3 text-primary"});case"subagent":return s.jsx(wy,{className:"h-3 w-3 text-primary"});default:return null}},M=y.filter(L=>!o1(L)),$=M.filter(Pi),F=M.filter(L=>!Pi(L)),{groupedCustomAgents:V,ungroupedCustomAgents:O}=Oe.useMemo(()=>{const L={},W=[];for(const ne of F){const le=ne;le.group?(L[le.group]||(L[le.group]=[]),L[le.group].push(ne)):W.push(ne)}return{groupedCustomAgents:Object.keys(L).sort((ne,le)=>ne.localeCompare(le)).map(ne=>({name:ne,agents:L[ne]})),ungroupedCustomAgents:W}},[F]);return s.jsxs("div",{className:pe("flex h-full flex-col",A),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(Go,{className:"mb-3"}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.agents.sidebar.total",{count:M.length})}),s.jsx(je,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:j,children:s.jsx(_s,{className:"h-3.5 w-3.5"})})]})]}),s.jsx(Es,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:M.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(Gr,{className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:e("settings.agents.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.agents.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[$.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.agents.sidebar.section.builtIn")}),$.map(L=>s.jsx(cd,{agent:L,isSelected:f===L.name,onSelect:()=>{x(L.name),t?.()},onReset:()=>I(L),onDuplicate:()=>P(L),getAgentModeIcon:T,isMenuOpen:h===L.name,onMenuOpenChange:W=>b(W?L.name:null)},L.name))]}),F.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.agents.sidebar.section.custom")}),V.map(({name:L,agents:W})=>s.jsx(ru,{label:L,count:W.length,storageKey:"agents",children:W.map(B=>s.jsx(cd,{agent:B,isSelected:f===B.name,onSelect:()=>{x(B.name),t?.()},onRename:()=>N(B),onDelete:()=>C(B),onDuplicate:()=>P(B),getAgentModeIcon:T,isMenuOpen:h===B.name,onMenuOpenChange:ne=>b(ne?B.name:null)},B.name))},L)),O.map(L=>s.jsx(cd,{agent:L,isSelected:f===L.name,onSelect:()=>{x(L.name),t?.()},onRename:()=>N(L),onDelete:()=>C(L),onDuplicate:()=>P(L),getAgentModeIcon:T,isMenuOpen:h===L.name,onMenuOpenChange:W=>b(W?L.name:null)},L.name))]})]})}),s.jsx(ws,{open:o!==null&&d!==null,onOpenChange:L=>{!L&&!m&&R()},children:s.jsxs(vs,{className:"max-w-md",children:[s.jsxs(Is,{children:[s.jsx(Ss,{children:e(d==="delete"?"settings.agents.sidebar.dialog.deleteTitle":"settings.agents.sidebar.dialog.resetTitle")}),s.jsx(Os,{children:d==="delete"?e("settings.agents.sidebar.dialog.deleteDescription",{name:o?.name??""}):e("settings.agents.sidebar.dialog.resetDescription",{name:o?.name??""})})]}),s.jsxs(Qs,{children:[s.jsx(je,{size:"sm",variant:"ghost",onClick:R,disabled:m,children:e("settings.common.actions.cancel")}),s.jsx(je,{size:"sm",onClick:k,disabled:m,children:e(d==="delete"?"settings.common.actions.delete":"settings.common.actions.reset")})]})]})}),s.jsx(ws,{open:n!==null,onOpenChange:L=>!L&&r(null),children:s.jsxs(vs,{children:[s.jsxs(Is,{children:[s.jsx(Ss,{children:e("settings.agents.sidebar.renameDialog.title")}),s.jsx(Os,{children:e("settings.agents.sidebar.renameDialog.description",{name:n?.name??""})})]}),s.jsx(Vt,{value:a,onChange:L=>i(L.target.value),placeholder:e("settings.agents.sidebar.renameDialog.placeholder"),className:"text-foreground placeholder:text-muted-foreground",onKeyDown:L=>{L.key==="Enter"&&D()}}),s.jsxs(Qs,{children:[s.jsx(je,{size:"sm",variant:"ghost",onClick:()=>r(null),children:e("settings.common.actions.cancel")}),s.jsx(je,{size:"sm",onClick:D,children:e("settings.common.actions.rename")})]})]})})]})},cd=t=>{const e=nt.c(58),{agent:n,isSelected:r,onSelect:a,onDelete:i,onReset:o,onRename:c,onDuplicate:d,getAgentModeIcon:p,isMenuOpen:m,onMenuOpenChange:u}=t,{t:h}=ut(),b=n;let f;e[0]===Symbol.for("react.memo_cache_sentinel")?(f=Do(),e[0]=f):f=e[0];const y=f,x=r?"bg-interactive-selection":"hover:bg-interactive-hover";let g;e[1]!==x?(g=pe("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=y?void 0:W=>{W.preventDefault(),u(!0)},e[3]=u,e[4]=w):w=e[4];let v;e[5]!==n.name?(v=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n.name}),e[5]=n.name,e[6]=v):v=e[6];let S;e[7]!==n.mode||e[8]!==p?(S=p(n.mode),e[7]=n.mode,e[8]=p,e[9]=S):S=e[9];let A;e[10]!==n||e[11]!==b.scope||e[12]!==h?(A=(b.scope||Pi(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:Pi(n)?h("settings.agents.sidebar.badge.system"):b.scope}),e[10]=n,e[11]=b.scope,e[12]=h,e[13]=A):A=e[13];let j;e[14]!==v||e[15]!==S||e[16]!==A?(j=s.jsxs("div",{className:"flex items-center gap-1.5",children:[v,S,A]}),e[14]=v,e[15]=S,e[16]=A,e[17]=j):j=e[17];let C;e[18]!==n.description?(C=n.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n.description}),e[18]=n.description,e[19]=C):C=e[19];let I;e[20]!==a||e[21]!==j||e[22]!==C?(I=s.jsxs("button",{onClick:a,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[j,C]}),e[20]=a,e[21]=j,e[22]=C,e[23]=I):I=e[23];let R;e[24]===Symbol.for("react.memo_cache_sentinel")?(R=s.jsx(Bs,{asChild:!0,children:s.jsx(je,{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(ia,{className:"h-3.5 w-3.5"})})}),e[24]=R):R=e[24];let k;e[25]!==c||e[26]!==h?(k=c&&s.jsxs($t,{onClick:W=>{W.stopPropagation(),c()},children:[s.jsx(Yr,{className:"h-4 w-4 mr-px"}),h("settings.common.actions.rename")]}),e[25]=c,e[26]=h,e[27]=k):k=e[27];let P;e[28]!==d?(P=W=>{W.stopPropagation(),d()},e[28]=d,e[29]=P):P=e[29];let N;e[30]===Symbol.for("react.memo_cache_sentinel")?(N=s.jsx(br,{className:"h-4 w-4 mr-px"}),e[30]=N):N=e[30];let D;e[31]!==h?(D=h("settings.common.actions.duplicate"),e[31]=h,e[32]=D):D=e[32];let T;e[33]!==P||e[34]!==D?(T=s.jsxs($t,{onClick:P,children:[N,D]}),e[33]=P,e[34]=D,e[35]=T):T=e[35];let M;e[36]!==o||e[37]!==h?(M=o&&s.jsxs($t,{onClick:W=>{W.stopPropagation(),o()},children:[s.jsx(Mn,{className:"h-4 w-4 mr-px"}),h("settings.common.actions.reset")]}),e[36]=o,e[37]=h,e[38]=M):M=e[38];let $;e[39]!==i||e[40]!==h?($=i&&s.jsxs($t,{onClick:W=>{W.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[s.jsx(sn,{className:"h-4 w-4 mr-px"}),h("settings.common.actions.delete")]}),e[39]=i,e[40]=h,e[41]=$):$=e[41];let F;e[42]!==k||e[43]!==T||e[44]!==M||e[45]!==$?(F=s.jsxs(Vs,{align:"end",className:"w-fit min-w-20",children:[k,T,M,$]}),e[42]=k,e[43]=T,e[44]=M,e[45]=$,e[46]=F):F=e[46];let V;e[47]!==m||e[48]!==u||e[49]!==F?(V=s.jsxs(zs,{open:m,onOpenChange:u,children:[R,F]}),e[47]=m,e[48]=u,e[49]=F,e[50]=V):V=e[50];let O;e[51]!==I||e[52]!==V?(O=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[I,V]}),e[51]=I,e[52]=V,e[53]=O):O=e[53];let L;return e[54]!==O||e[55]!==g||e[56]!==w?(L=s.jsx("div",{className:g,onContextMenu:w,children:O}),e[54]=O,e[55]=g,e[56]=w,e[57]=L):L=e[57],L};function Yp(t,e,n){return Math.min(n,Math.max(e,t))}function p5(t){if(!Number.isFinite(t))return 0;const e=String(t);if(e.includes("e-")){const[,r]=e.split("e-");return Number(r)||0}const n=e.split(".");return n.length===2?n[1].length:0}function Xp(t,e){const n=p5(e);return n<=0?t:Number(t.toFixed(n))}const jn=Oe.forwardRef((t,e)=>{const n=nt.c(125);let r,a,i,o,c,d,p,m,u,h,b,f,y;n[0]!==t?({value:y,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]=y):(r=n[1],a=n[2],i=n[3],o=n[4],c=n[5],d=n[6],p=n[7],m=n[8],u=n[9],h=n[10],b=n[11],f=n[12],y=n[13]);const x=u===void 0?-1/0:u,g=h===void 0?1/0:h,w=b===void 0?1:b,v=f===void 0?"—":f,{t:S}=ut();let A;n[14]!==y?(A=()=>y===void 0?"":String(y),n[14]=y,n[15]=A):A=n[15];const[j,C]=Oe.useState(A),{isMobile:I}=un(),R=Oe.useRef(!1),k=Oe.useRef(null);let P;n[16]===Symbol.for("react.memo_cache_sentinel")?(P=()=>{if(typeof document>"u"||typeof window>"u")return;k.current?.();const ke=Pe=>{Pe.preventDefault(),Pe.stopPropagation(),Pe.stopImmediatePropagation?.(),k.current?.()},xe=window.setTimeout(()=>{k.current?.()},700),he=()=>{window.clearTimeout(xe),document.removeEventListener("click",ke,!0),k.current=null};k.current=he,document.addEventListener("click",ke,!0)},n[16]=P):P=n[16];const N=P;let D,T;n[17]===Symbol.for("react.memo_cache_sentinel")?(D=()=>()=>{k.current?.()},T=[],n[17]=D,n[18]=T):(D=n[17],T=n[18]),Oe.useEffect(D,T);let M,$;n[19]!==y?($=()=>{C(y===void 0?"":String(y))},M=[y],n[19]=y,n[20]=M,n[21]=$):(M=n[20],$=n[21]),Oe.useEffect($,M);let F;e:{if(y!==void 0){F=y;break e}if(o!==void 0){F=o;break e}if(Number.isFinite(x)){F=x;break e}F=0}const V=F;let O;n[22]!==g||n[23]!==x||n[24]!==p||n[25]!==w?(O=ke=>{const xe=Yp(ke,x,g);p(Xp(xe,w))},n[22]=g,n[23]=x,n[24]=p,n[25]=w,n[26]=O):O=n[26];const L=O;let W;n[27]!==L||n[28]!==d?(W=ke=>{const xe=ke.target.value;if(C(xe),xe.trim()===""){d?.();return}const he=Number(xe);Number.isFinite(he)&&L(he)},n[27]=L,n[28]=d,n[29]=W):W=n[29];const B=W;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]!==y?(ne=ke=>{if(j.trim()===""){d||C(y===void 0?"":String(y)),c?.(ke);return}const xe=Number(j);if(!Number.isFinite(xe))C(y===void 0?"":String(y));else{const he=Yp(xe,x,g),Pe=Xp(he,w);Pe!==y&&p(Pe),C(String(Pe))}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]=y,n[38]=ne):ne=n[38];const le=ne,ee=!!(i||V>=g),ae=!!(i||V<=x);let ge;n[39]!==V||n[40]!==L||n[41]!==ae||n[42]!==w?(ge=()=>{ae||L(V-w)},n[39]=V,n[40]=L,n[41]=ae,n[42]=w,n[43]=ge):ge=n[43];const te=ge;let E;n[44]!==V||n[45]!==L||n[46]!==ee||n[47]!==w?(E=()=>{ee||L(V+w)},n[44]=V,n[45]=L,n[46]=ee,n[47]=w,n[48]=E):E=n[48];const z=E;let J;if(n[49]!==r||n[50]!==a||n[51]!==ae||n[52]!==j||n[53]!==v||n[54]!==te||n[55]!==z||n[56]!==ee||n[57]!==I||n[58]!==S||n[59]!==y){J=Symbol.for("react.early_return_sentinel");e:{const ke=he=>Pe=>{Pe.preventDefault(),Pe.stopPropagation(),R.current=!0,N(),he()},xe=he=>Pe=>{if(R.current){R.current=!1,Pe.preventDefault(),Pe.stopPropagation();return}he()};if(I){let he;n[61]!==a?(he=pe("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]=he):he=n[62];let Pe;n[63]!==S?(Pe=S("numberInput.actions.decreaseAria"),n[63]=S,n[64]=Pe):Pe=n[64];const Be=ke(te),G=xe(te),be=!ae&&"active:bg-interactive-hover";let De;n[65]!==be?(De=pe("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",be),n[65]=be,n[66]=De):De=n[66];let Ae;n[67]===Symbol.for("react.memo_cache_sentinel")?(Ae=s.jsx(Ul,{className:"block h-4 w-4"}),n[67]=Ae):Ae=n[67];const ve=s.jsx("button",{type:"button","aria-label":Pe,disabled:ae,onTouchStart:Be,onClick:G,className:De,children:Ae});let U;n[68]!==r?(U=pe("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]=U):U=n[69];const de=y===void 0?v:j;let Re;n[70]!==U||n[71]!==de?(Re=s.jsx("div",{className:U,"aria-live":"polite",children:de}),n[70]=U,n[71]=de,n[72]=Re):Re=n[72];let Le;n[73]!==S?(Le=S("numberInput.actions.increaseAria"),n[73]=S,n[74]=Le):Le=n[74];const se=ke(z),ie=xe(z),K=!ee&&"active:bg-interactive-hover";let _e;n[75]!==K?(_e=pe("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",K),n[75]=K,n[76]=_e):_e=n[76];let He;n[77]===Symbol.for("react.memo_cache_sentinel")?(He=s.jsx(_s,{className:"block h-4 w-4"}),n[77]=He):He=n[77];const Ke=s.jsx("button",{type:"button","aria-label":Le,disabled:ee,onTouchStart:se,onClick:ie,className:_e,children:He});let Ze;n[78]!==he||n[79]!==ve||n[80]!==Re||n[81]!==Ke?(Ze=s.jsxs("div",{className:he,children:[ve,Re,Ke]}),n[78]=he,n[79]=ve,n[80]=Re,n[81]=Ke,n[82]=Ze):Ze=n[82],J=Ze;break e}}n[49]=r,n[50]=a,n[51]=ae,n[52]=j,n[53]=v,n[54]=te,n[55]=z,n[56]=ee,n[57]=I,n[58]=S,n[59]=y,n[60]=J}else J=n[60];if(J!==Symbol.for("react.early_return_sentinel"))return J;let H;n[83]!==a?(H=pe("flex h-7 shrink-0 items-stretch overflow-x-hidden overflow-y-hidden rounded-lg border border-border bg-transparent","disabled:pointer-events-none disabled:opacity-50",a),n[83]=a,n[84]=H):H=n[84];let re;n[85]!==S?(re=S("numberInput.actions.decreaseAria"),n[85]=S,n[86]=re):re=n[86];let ce;n[87]!==V||n[88]!==L||n[89]!==w?(ce=()=>L(V-w),n[87]=V,n[88]=L,n[89]=w,n[90]=ce):ce=n[90];let Ne,me;n[91]===Symbol.for("react.memo_cache_sentinel")?(Ne=pe("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"),me=s.jsx(Ul,{className:"block h-3.5 w-3.5"}),n[91]=Ne,n[92]=me):(Ne=n[91],me=n[92]);let we;n[93]!==ae||n[94]!==re||n[95]!==ce?(we=s.jsx("button",{type:"button","aria-label":re,disabled:ae,onClick:ce,className:Ne,children:me}),n[93]=ae,n[94]=re,n[95]=ce,n[96]=we):we=n[96];const _=m.inputMode??"numeric";let ue;n[97]!==r?(ue=pe("h-full min-w-0 w-14 bg-transparent px-1.5 text-center typography-ui-label leading-none text-foreground [font-variant-numeric:tabular-nums]","placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground","appearance-none outline-none [appearance:textfield] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden","disabled:pointer-events-none disabled:cursor-not-allowed",r),n[97]=r,n[98]=ue):ue=n[98];let Q;n[99]!==i||n[100]!==j||n[101]!==le||n[102]!==B||n[103]!==m||n[104]!==e||n[105]!==_||n[106]!==ue?(Q=s.jsx("input",{...m,ref:e,type:"text",inputMode:_,value:j,onChange:B,onBlur:le,disabled:i,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",className:ue}),n[99]=i,n[100]=j,n[101]=le,n[102]=B,n[103]=m,n[104]=e,n[105]=_,n[106]=ue,n[107]=Q):Q=n[107];let oe;n[108]!==S?(oe=S("numberInput.actions.increaseAria"),n[108]=S,n[109]=oe):oe=n[109];let Z;n[110]!==V||n[111]!==L||n[112]!==w?(Z=()=>L(V+w),n[110]=V,n[111]=L,n[112]=w,n[113]=Z):Z=n[113];let Ie,Se;n[114]===Symbol.for("react.memo_cache_sentinel")?(Ie=pe("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"),Se=s.jsx(_s,{className:"block h-3.5 w-3.5"}),n[114]=Ie,n[115]=Se):(Ie=n[114],Se=n[115]);let Y;n[116]!==ee||n[117]!==oe||n[118]!==Z?(Y=s.jsx("button",{type:"button","aria-label":oe,disabled:ee,onClick:Z,className:Ie,children:Se}),n[116]=ee,n[117]=oe,n[118]=Z,n[119]=Y):Y=n[119];let fe;return n[120]!==H||n[121]!==we||n[122]!==Q||n[123]!==Y?(fe=s.jsxs("div",{className:H,children:[we,Q,Y]}),n[120]=H,n[121]=we,n[122]=Q,n[123]=Y,n[124]=fe):fe=n[124],fe});jn.displayName="NumberInput";const Zp=["*","read","edit","glob","grep","list","bash","task","skill","lsp","todoread","todowrite","webfetch","websearch","codesearch","external_directory","doom_loop","question","plan_enter","plan_exit"],Ml=t=>t==="allow"||t==="ask"||t==="deny",Ua=(t,e)=>`${t}::${e}`,di=t=>{const e=new Map;for(const n of t)!n.permission||n.permission==="invalid"||n.pattern&&Ml(n.action)&&e.set(Ua(n.permission,n.pattern),{permission:n.permission,pattern:n.pattern,action:n.action});return Array.from(e.values())},ml=t=>{const e=new Map;for(const n of di(t))e.set(Ua(n.permission,n.pattern),n);return e},ef=t=>[...t].sort((e,n)=>{const r=e.permission.localeCompare(n.permission);return r!==0?r:e.pattern.localeCompare(n.pattern)}),f5=(t,e)=>{const n=ef(di(t)),r=ef(di(e));return n.length!==r.length?!1:n.every((a,i)=>{const o=r[i];return a.permission===o.permission&&a.pattern===o.pattern&&a.action===o.action})},h5=t=>t.find(n=>n.permission==="*"&&n.pattern==="*")?.action??"allow",g5=(t,e)=>di(t).filter(n=>!(n.permission==="*"&&n.pattern==="*")).filter(n=>n.pattern!=="*"||n.action!==e),x5=t=>{if(Ml(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(Ml(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))Ml(i)&&e.push({permission:n,pattern:a,action:i})}return e},b5=(t,e)=>{const n=di(e),r={};for(const i of n)(r[i.permission]||={})[i.pattern]=i.action;const a={"*":t};for(const[i,o]of Object.entries(r))if(i!=="*"){if(Object.keys(o).length===1&&o["*"]){a[i]=o["*"];continue}a[i]=o}return a},y5=()=>{const{t}=ut(),{isMobile:e}=un(),{selectedAgentName:n,getAgentByName:r,createAgent:a,updateAgent:i,agents:o,agentDraft:c,setAgentDraft:d}=_i(jr(he=>({selectedAgentName:he.selectedAgentName,getAgentByName:he.getAgentByName,createAgent:he.createAgent,updateAgent:he.updateAgent,agents:he.agents,agentDraft:he.agentDraft,setAgentDraft:he.setAgentDraft}))),p=n?r(n):null,m=!!(c&&c.name===n&&!p),[u,h]=l.useState(""),[b,f]=l.useState("user"),[y,x]=l.useState(""),[g,w]=l.useState("subagent"),[v,S]=l.useState(""),[A,j]=l.useState(void 0),[C,I]=l.useState(void 0),[R,k]=l.useState(""),[P,N]=l.useState("allow"),[D,T]=l.useState([]),[M,$]=l.useState([]),[F,V]=l.useState(""),[O,L]=l.useState("*"),[W,B]=l.useState(!1),[ne,le]=l.useState(!1),ee=l.useRef(null),ae=Ws(he=>he.currentDirectory??null),[ge,te]=l.useState([]),E=bg(he=>he.permission);l.useEffect(()=>{let he=!1;return(async()=>{const Be=await Dn.listToolIds({directory:ae});if(he)return;const G=new Set(["write","patch","multiedit"]),be=Be.map(De=>typeof De=="string"?De.trim():"").filter(Boolean).filter(De=>De!=="*").filter(De=>De!=="invalid").filter(De=>!G.has(De));te(Array.from(new Set(be)).sort((De,Ae)=>De.localeCompare(Ae)))})(),()=>{he=!0}},[ae]);const z=l.useMemo(()=>{const he=new Set;for(const Pe of o){const Be=di(Array.isArray(Pe.permission)?Pe.permission:[]);for(const G of Be)G.permission&&G.permission!=="*"&&G.permission!=="invalid"&&he.add(G.permission)}for(const Pe of Object.values(E))for(const Be of Pe){const G=Be.permission?.trim();G&&G!=="invalid"&&he.add(G)}for(const Pe of ge)he.add(Pe);return Array.from(he).sort((Pe,Be)=>Pe.localeCompare(Be))},[o,E,ge]),J=l.useMemo(()=>ml(D),[D]),H=l.useMemo(()=>ml(M),[M]),re=l.useCallback(he=>H.get(Ua(he,"*"))?.action,[H]),ce=l.useCallback(he=>M.filter(Pe=>Pe.permission===he&&Pe.pattern!=="*").sort((Pe,Be)=>Pe.pattern.localeCompare(Be.pattern)),[M]),Ne=l.useMemo(()=>{const he=new Set;for(const Pe of Zp)he.add(Pe);for(const Pe of z)he.add(Pe);return Array.from(he).sort((Pe,Be)=>Pe.localeCompare(Be))},[z]),me=l.useCallback(he=>{const Pe=he==="*"?P:re(he)??P,Be=ce(he),G=!1,be=Be.reduce((Ae,ve)=>(Ae[ve.action]=(Ae[ve.action]??0)+1,Ae),{allow:0,ask:0,deny:0}),De=["allow","ask","deny"].filter(Ae=>be[Ae]>0).map(Ae=>`${be[Ae]} ${Ae}`).join(", ");return{defaultAction:Pe,patternRulesCount:Be.length,patternSummary:De,hasDefaultHint:G}},[ce,re,P]),we=l.useCallback(he=>t(he==="allow"?"settings.common.permission.allow":he==="deny"?"settings.common.permission.deny":"settings.common.permission.ask"),[t]),_=l.useCallback(he=>he==="global"?t("settings.common.scope.global"):we(he),[we,t]),ue=l.useMemo(()=>{const he=new Set;for(const Pe of Zp)he.add(Pe);for(const Pe of z)he.add(Pe);return Array.from(he).sort((Pe,Be)=>Pe.localeCompare(Be))},[z]),Q=l.useCallback((he,Pe,Be)=>{$(G=>{const be=ml(G);return be.set(Ua(he,Pe),{permission:he,pattern:Pe,action:Be}),Array.from(be.values())})},[]),oe=l.useCallback((he,Pe)=>{$(Be=>{const G=ml(Be);return G.delete(Ua(he,Pe)),Array.from(G.values())})},[]),Z=l.useCallback((he,Pe)=>{const Be=J.get(Ua(he,Pe));if(Be){Q(he,Pe,Be.action);return}oe(he,Pe)},[J,oe,Q]),Ie=l.useCallback((he,Pe,Be)=>{Q(he,Pe,Be)},[Q]),Se=l.useCallback(he=>{N(he),$(Pe=>Pe.filter(Be=>!(Be.pattern==="*"&&Be.action===he)))},[]),Y=l.useCallback(he=>{const Pe=F.trim();if(!Pe){q.error(t("settings.agents.page.toast.permissionNameRequired"));return}const Be=O.trim()||"*";if(Pe==="*"&&Be==="*"){Se(he),V(""),L("*");return}Be==="*"&&Pe!=="*"&&he===P?oe(Pe,"*"):Q(Pe,Be,he),V(""),L("*")},[P,F,O,oe,Se,t,Q]),fe=l.useCallback(he=>he==="*"?t("settings.agents.page.permissions.defaultLabel"):he==="webfetch"?"WebFetch":he==="websearch"?"WebSearch":he==="codesearch"?"CodeSearch":he==="doom_loop"?"Doom Loop":he==="external_directory"?"External Directory":he==="todowrite"?"TodoWrite":he==="todoread"?"TodoRead":he.split(/[_-]+/g).filter(Boolean).map(Pe=>Pe.charAt(0).toUpperCase()+Pe.slice(1)).join(" "),[t]);l.useEffect(()=>{V(""),L("*");const he=Pe=>{const Be=di(Pe),G=h5(Be),be=g5(Be,G);return N(G),T(be),$(be),{global:G,rules:be}};if(m&&c){const Pe=c.name||"",Be=c.scope||"user",G=c.description||"",be=c.mode||"subagent",De=c.model||"",Ae=c.temperature,ve=c.top_p,U=c.prompt||"";h(Pe),f(Be),x(G),w(be),S(De),j(Ae),I(ve),k(U);const de=x5(c.permission),Re=he(de);ee.current={draftName:Pe,draftScope:Be,description:G,mode:be,model:De,temperature:Ae,topP:ve,prompt:U,globalPermission:Re.global,permissionRules:Re.rules};return}if(p&&n===p.name){const Pe=p.description||"",Be=p.mode||"subagent",G=p.model?.providerID&&p.model?.modelID?`${p.model.providerID}/${p.model.modelID}`:"",be=p.temperature,De=p.topP,Ae=p.prompt||"";x(Pe),w(Be),S(G),j(be),I(De),k(Ae);const ve=he(Array.isArray(p.permission)?p.permission:[]);ee.current={draftName:"",draftScope:"user",description:Pe,mode:Be,model:G,temperature:be,topP:De,prompt:Ae,globalPermission:ve.global,permissionRules:ve.rules}}},[c,m,p,n]);const ke=l.useMemo(()=>{const he=ee.current;return he?!!(m&&(u!==he.draftName||b!==he.draftScope)||y!==he.description||g!==he.mode||v!==he.model||A!==he.temperature||C!==he.topP||R!==he.prompt||P!==he.globalPermission||!f5(M,he.permissionRules)):!1},[y,u,b,P,m,g,v,M,R,A,C]),xe=async()=>{const he=m?u.trim().replace(/\s+/g,"-"):n?.trim();if(!he){q.error(t("settings.agents.sidebar.toast.agentNameRequired"));return}if(m&&o.some(Pe=>Pe.name===he)){q.error(t("settings.agents.sidebar.toast.agentExists"));return}le(!0);try{const Pe=v.trim(),Be=b5(P,M),G={name:he,description:y.trim()||void 0,mode:g,model:Pe===""?null:Pe,temperature:A,top_p:C,prompt:R.trim()||void 0,permission:Be,scope:m?b:void 0};let be;m?(be=await a(G),be&&d(null)):be=await i(he,G),be?q.success(t(m?"settings.agents.page.toast.created":"settings.agents.page.toast.updated")):q.error(t(m?"settings.agents.page.toast.createFailed":"settings.agents.page.toast.updateFailed"))}catch(Pe){console.error("Error saving agent:",Pe);const Be=Pe instanceof Error&&Pe.message?Pe.message:t("settings.agents.page.toast.saveUnexpectedError");q.error(Be)}finally{le(!1)}};return n?s.jsx(Es,{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(Vt,{value:u,onChange:he=>h(he.target.value),placeholder:t("settings.agents.page.field.agentNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(ps,{value:b,onValueChange:he=>f(he),children:[s.jsx(fs,{className:"w-fit min-w-[100px]",children:s.jsx(ys,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(hs,{align:"end",children:[s.jsx(Ot,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(qr,{className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(Ot,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(zn,{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(Sn,{value:y,onChange:he=>x(he.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(St,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{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(je,{variant:"chip",size:"xs","aria-pressed":g==="primary",onClick:()=>w("primary"),className:"!font-normal",children:t("settings.agents.page.mode.primary")}),s.jsx(je,{variant:"chip",size:"xs","aria-pressed":g==="subagent",onClick:()=>w("subagent"),className:"!font-normal",children:t("settings.agents.page.mode.subagent")}),s.jsx(je,{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(Ho,{providerId:Gi(v)?.providerId??"",modelId:Gi(v)?.modelId??"",onChange:(he,Pe)=>{S(he&&Pe?`${he}/${Pe}`:"")}})})]}),s.jsxs("div",{className:pe("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsxs("div",{className:pe("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(St,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{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:pe("flex items-center gap-2",e?"w-full":"w-fit"),children:[s.jsx(jn,{value:A,fallbackValue:.7,onValueChange:j,onClear:()=>j(void 0),min:0,max:2,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),A!==void 0&&s.jsx(je,{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(Ds,{className:"h-3.5 w-3.5"})})]})]}),s.jsxs("div",{className:pe("py-1.5",e?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsxs("div",{className:pe("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(St,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{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:pe("flex items-center gap-2",e?"w-full":"w-fit"),children:[s.jsx(jn,{value:C,fallbackValue:.9,onValueChange:I,onClear:()=>I(void 0),min:0,max:1,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:"w-16"}),C!==void 0&&s.jsx(je,{size:"sm",type:"button",variant:"ghost",onClick:()=>I(void 0),className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":t("settings.agents.page.field.clearTopPAria"),title:t("settings.common.actions.clear"),children:s.jsx(Ds,{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(Sn,{value:R,onChange:he=>k(he.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(je,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>B(he=>!he),children:t(W?"settings.agents.page.permissions.hideEditor":"settings.agents.page.permissions.advancedEditor")})]}),W?s.jsxs("div",{className:"space-y-6 px-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-4 py-1.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.agents.page.permissions.globalDefault")}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono",children:"*"})]}),s.jsxs(ps,{value:P,onValueChange:he=>Se(he),children:[s.jsx(fs,{className:"w-[100px]",children:s.jsx(ys,{children:we(P)})}),s.jsxs(hs,{children:[s.jsx(Ot,{value:"allow",children:t("settings.common.permission.allow")}),s.jsx(Ot,{value:"ask",children:t("settings.common.permission.ask")}),s.jsx(Ot,{value:"deny",children:t("settings.common.permission.deny")})]})]})]}),s.jsx("div",{className:"space-y-4",children:Ne.filter(he=>he!=="*").map(he=>{const Pe=fe(he),{defaultAction:Be,patternRulesCount:G}=me(he),be=re(he),De=be??"global",Ae=ce(he),ve=["allow","ask","deny"].filter(U=>U!==P);return s.jsxs("div",{className:"border-t border-[var(--surface-subtle)] pt-2",children:[s.jsxs("div",{className:"flex items-center justify-between py-1",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:Pe}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono",children:he})]}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:G>0?t("settings.agents.page.permissions.globalSummary",{summary:Be}):Be})]}),s.jsxs("div",{className:"space-y-1 pl-2 mt-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 py-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:t("settings.agents.page.permissions.pattern")}),s.jsx("span",{className:"typography-micro font-mono text-foreground bg-[var(--surface-muted)] px-1 rounded",children:"*"}),be&&s.jsx(je,{size:"sm",variant:"ghost",onClick:()=>Z(he,"*"),className:"px-1.5 py-0 h-5",children:s.jsx(Ul,{className:"h-3.5 w-3.5 text-muted-foreground hover:text-foreground"})})]}),s.jsxs(ps,{value:De,onValueChange:U=>{if(U==="global"){oe(he,"*");return}Q(he,"*",U)},children:[s.jsx(fs,{className:"w-[90px]",children:s.jsx(ys,{children:_(De)})}),s.jsxs(hs,{children:[s.jsx(Ot,{value:"global",children:t("settings.common.scope.global")}),ve.map(U=>s.jsx(Ot,{value:U,className:"capitalize",children:we(U)},U))]})]})]}),Ae.map(U=>{const de=Ua(U.permission,U.pattern),Re=J.get(de),Le=!Re,se=!!(Re&&Re.action!==U.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:U.pattern}),Le&&s.jsx("span",{className:"typography-micro text-[var(--status-success)]",children:t("settings.common.badge.new")}),se&&s.jsx("span",{className:"typography-micro text-[var(--status-warning)]",children:t("settings.common.badge.modified")}),(Le||se)&&s.jsx(je,{size:"sm",variant:"ghost",onClick:()=>Le?oe(U.permission,U.pattern):Z(U.permission,U.pattern),className:"px-1.5 py-0 h-5",children:s.jsx(Ul,{className:"h-3.5 w-3.5 text-muted-foreground hover:text-foreground"})})]}),s.jsxs(ps,{value:U.action,onValueChange:ie=>Ie(U.permission,U.pattern,ie),children:[s.jsx(fs,{className:"w-[90px]",children:s.jsx(ys,{children:we(U.action)})}),s.jsxs(hs,{children:[s.jsx(Ot,{value:"allow",children:t("settings.common.permission.allow")}),s.jsx(Ot,{value:"ask",children:t("settings.common.permission.ask")}),s.jsx(Ot,{value:"deny",children:t("settings.common.permission.deny")})]})]})]},de)})]})]},he)})}),s.jsxs("div",{className:"border-t border-[var(--surface-subtle)] pt-3",children:[s.jsx("h4",{className:"typography-ui-label text-foreground mb-2",children:t("settings.agents.page.permissions.addCustomRule")}),s.jsxs("div",{className:"flex flex-col sm:flex-row items-end sm:items-center gap-2",children:[s.jsxs(ps,{value:F,onValueChange:V,children:[s.jsx(fs,{className:"w-full sm:w-[160px]",children:F?s.jsx("span",{className:"truncate",children:fe(F)}):s.jsx("span",{className:"text-muted-foreground",children:t("settings.agents.page.permissions.permissionPlaceholder")})}),s.jsx(hs,{children:ue.map(he=>s.jsx(Ot,{value:he,children:s.jsx("div",{className:"flex items-center justify-between gap-2 w-full",children:s.jsx("span",{children:fe(he)})})},he))})]}),s.jsx(Vt,{value:O,onChange:he=>L(he.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(je,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Y("allow"),children:t("settings.common.permission.allow")}),s.jsx(je,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Y("ask"),children:t("settings.common.permission.ask")}),s.jsx(je,{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:Ne.map((he,Pe)=>{const{defaultAction:Be,patternRulesCount:G,patternSummary:be,hasDefaultHint:De}=me(he),Ae=fe(he),ve=De?`${Be} (env blocked)`:Be;return s.jsxs("div",{className:pe("flex flex-col gap-1 py-1.5 sm:flex-row sm:items-center sm:justify-between sm:gap-8",Pe>0&&"border-t border-[var(--surface-subtle)]"),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:Ae}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 font-mono hidden sm:inline-block",children:he})]}),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:ve})}):s.jsx("span",{className:pe("typography-micro capitalize px-1.5 py-0.5 rounded",ve==="allow"?"text-[var(--status-success)] bg-[var(--status-success)]/10":ve==="deny"?"text-[var(--status-error)] bg-[var(--status-error)]/10":"text-[var(--status-warning)] bg-[var(--status-warning)]/10"),children:ve}),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:be})})]})]},he)})})]}),s.jsx("div",{className:"px-2 py-1",children:s.jsx(je,{onClick:xe,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(Gr,{className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.agents.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.agents.page.empty.description")})]})})},v5="~/.config/opencode/AGENTS.md",Ix=async(t,e)=>{const n=await t.json().catch(()=>null);return typeof n?.error=="string"&&n.error.trim()?n.error:e},w5=t=>t.length>0&&!t.endsWith(`
64
- `)?`${t}
65
- `:t,pl={prompt:"",responseStyleEnabled:!1,responseStylePreset:"concise",responseStyleCustomInstructions:""},j5=(t,e)=>t==="custom"?e:c1(t),N5=t=>t==="custom"?"custom":yg(t)?t:"concise",tf={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"},sf=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 Ix(n,e))},S5=()=>{const{t}=ut(),[e,n]=l.useState(""),[r,a]=l.useState(pl.responseStyleEnabled),[i,o]=l.useState(pl.responseStylePreset),[c,d]=l.useState(pl.responseStyleCustomInstructions),[p,m]=l.useState(!0),[u,h]=l.useState(!1),[b,f]=l.useState(""),y=l.useRef(null);l.useEffect(()=>{const v=new AbortController;return(async()=>{try{const[A,j]=await Promise.all([fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},signal:v.signal}),fetch("/api/behavior/agents-md",{method:"GET",headers:{Accept:"application/json"},signal:v.signal})]);let C=pl;if(A.ok){const I=await A.json();C={...C,responseStyleEnabled:I.responseStyleEnabled===!0,responseStylePreset:N5(I.responseStylePreset),responseStyleCustomInstructions:typeof I.responseStyleCustomInstructions=="string"?I.responseStyleCustomInstructions:""},typeof I.globalBehaviorPrompt=="string"&&(C={...C,prompt:I.globalBehaviorPrompt})}if(!C.prompt.trim()&&j.ok){const I=await j.json();typeof I.content=="string"&&(C={...C,prompt:I.content})}n(C.prompt),a(C.responseStyleEnabled),o(C.responseStylePreset),d(C.responseStyleCustomInstructions),f(C.prompt),y.current={enabled:C.responseStyleEnabled,preset:C.responseStylePreset,custom:C.responseStyleCustomInstructions}}catch(A){A.name!=="AbortError"&&console.warn("Failed to load behavior settings:",A)}finally{m(!1)}})(),()=>v.abort()},[]),l.useEffect(()=>{if(p)return;const v=y.current;if(v&&v.enabled===r&&v.preset===i&&v.custom===c)return;const S={enabled:r,preset:i,custom:c},A=setTimeout(async()=>{try{await sf({responseStyleEnabled:S.enabled,responseStylePreset:S.preset,responseStyleCustomInstructions:S.custom},t("settings.behavior.page.toast.saveFailed")),y.current=S}catch(j){const C=j instanceof Error?j.message:t("settings.behavior.page.toast.saveFailed");q.error(C)}},400);return()=>clearTimeout(A)},[r,i,c,p,t]);const x=j5(i,c),g=e!==b,w=async()=>{h(!0);try{const v=w5(e),S=await fetch("/api/behavior/agents-md",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({content:v})});if(!S.ok)throw new Error(await Ix(S,t("settings.behavior.page.toast.saveFailed")));await sf({globalBehaviorPrompt:v},t("settings.behavior.page.toast.saveFailed")),n(v),f(v),q.success(t("settings.behavior.page.toast.saved"))}catch(v){console.error("Failed to save behavior:",v);const S=v instanceof Error?v.message:t("settings.behavior.page.toast.saveFailed");q.error(S)}finally{h(!1)}};return s.jsx(Es,{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(St,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"font-medium text-foreground",children:t("settings.behavior.page.warning.title")}),s.jsx("p",{children:t("settings.behavior.page.warning.description",{path:v5})})]})})]})]})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsx(Sn,{value:e,onChange:v=>n(v.target.value),placeholder:t("settings.behavior.page.field.systemPromptPlaceholder"),rows:12,disabled:p,outerClassName:"min-h-[160px] max-h-[70vh]",className:"w-full font-mono typography-meta bg-transparent"}),s.jsx(je,{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(St,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:t("settings.behavior.page.responseStyle.tooltip")})]})]})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsxs("label",{className:"flex items-center gap-2 typography-ui-label text-foreground",children:[s.jsx(bs,{checked:r,onChange:a,disabled:p,ariaLabel:t("settings.behavior.page.responseStyle.enableAria")}),t("settings.behavior.page.responseStyle.enable")]}),s.jsxs(ps,{value:i,onValueChange:v=>o(v),disabled:p||!r,children:[s.jsx(fs,{className:"w-full sm:w-56",size:"lg",children:s.jsx(ys,{children:v=>v==="custom"?t("settings.behavior.page.responseStyle.option.custom"):yg(v)?t(tf[v]):null})}),s.jsxs(hs,{children:[l1.map(v=>s.jsx(Ot,{value:v,children:t(tf[v])},v)),s.jsx(Ot,{value:"custom",children:t("settings.behavior.page.responseStyle.option.custom")})]})]}),s.jsx(Sn,{value:x,onChange:v=>d(v.target.value),placeholder:t("settings.behavior.page.responseStyle.customPlaceholder"),rows:5,disabled:p||!r||i!=="custom",outerClassName:"min-h-[120px]",className:"w-full font-mono typography-meta bg-transparent"})]})]})]})})},k5=t=>{const e=nt.c(169),{onItemSelect:n}=t,{t:r}=ut(),[a,i]=l.useState(null),[o,c]=l.useState(""),[d,p]=l.useState(null),[m,u]=l.useState(null),[h,b]=l.useState(!1),[f,y]=l.useState(null),{selectedCommandName:x,commands:g,setSelectedCommand:w,setCommandDraft:v,createCommand:S,deleteCommand:A,loadCommands:j}=Bu(jr(C5)),C=ya(I5),I=ya(A5);let R,k;e[0]!==j||e[1]!==I?(R=()=>{j(),I()},k=[j,I],e[0]=j,e[1]=I,e[2]=R,e[3]=k):(R=e[2],k=e[3]),l.useEffect(R,k);let P;e[4]!==C?(P=new Set(C.map(P5)),e[4]=C,e[5]=P):P=e[5];const N=P;let D;if(e[6]!==g||e[7]!==N){let $e;e[9]!==N?($e=Ve=>!N.has(Ve.name),e[9]=N,e[10]=$e):$e=e[10],D=g.filter($e),e[6]=g,e[7]=N,e[8]=D}else D=e[8];const T=D;let M,$;e[11]!==x||e[12]!==w||e[13]!==N?(M=()=>{x&&N.has(x)&&w(null)},$=[x,w,N],e[11]=x,e[12]=w,e[13]=N,e[14]=M,e[15]=$):(M=e[14],$=e[15]),l.useEffect(M,$);let F;e[16]!==g||e[17]!==n||e[18]!==v||e[19]!==w?(F=()=>{let $e="new-command",Ve=1;for(;g.some(tt=>tt.name===$e);)$e=`new-command-${Ve}`,Ve++;v({name:$e,scope:"user"}),w($e),n?.()},e[16]=g,e[17]=n,e[18]=v,e[19]=w,e[20]=F):F=e[20];const V=F;let O;e[21]!==r?(O=async $e=>{if(Fi($e)){q.error(r("settings.commands.sidebar.toast.builtInCannotDelete"));return}p($e),u("delete")},e[21]=r,e[22]=O):O=e[22];const L=O;let W;e[23]===Symbol.for("react.memo_cache_sentinel")?(W=async $e=>{Fi($e)&&(p($e),u("reset"))},e[23]=W):W=e[23];const B=W;let ne;e[24]===Symbol.for("react.memo_cache_sentinel")?(ne=()=>{p(null),u(null)},e[24]=ne):ne=e[24];const le=ne;let ee;e[25]!==d||e[26]!==m||e[27]!==A||e[28]!==r?(ee=async()=>{if(!d||!m)return;b(!0),await A(d.name)?(m==="delete"?q.success(r("settings.commands.sidebar.toast.commandDeleted",{name:d.name})):q.success(r("settings.commands.sidebar.toast.commandReset",{name:d.name})),le()):m==="delete"?q.error(r("settings.commands.sidebar.toast.deleteFailed")):q.error(r("settings.commands.sidebar.toast.resetFailed")),b(!1)},e[25]=d,e[26]=m,e[27]=A,e[28]=r,e[29]=ee):ee=e[29];const ae=ee;let ge;e[30]!==g||e[31]!==v||e[32]!==w?(ge=$e=>{const Ve=$e.name;let tt=1,Qe=`${Ve}-copy`;for(;g.some(ze=>ze.name===Qe);)tt++,Qe=`${Ve}-copy-${tt}`;v({name:Qe,scope:$e.scope||"user",description:$e.description,template:$e.template,agent:$e.agent,model:$e.model}),w(Qe)},e[30]=g,e[31]=v,e[32]=w,e[33]=ge):ge=e[33];const te=ge;let E;e[34]===Symbol.for("react.memo_cache_sentinel")?(E=$e=>{c($e.name),i($e)},e[34]=E):E=e[34];const z=E;let J;e[35]!==g||e[36]!==S||e[37]!==A||e[38]!==a||e[39]!==o||e[40]!==w||e[41]!==r?(J=async()=>{if(!a)return;const $e=o.trim().replace(/\s+/g,"-");if(!$e){q.error(r("settings.commands.sidebar.toast.commandNameRequired"));return}if($e===a.name){i(null);return}if(g.some(tt=>tt.name===$e)){q.error(r("settings.commands.sidebar.toast.commandExists"));return}await S({name:$e,description:a.description,template:a.template,agent:a.agent,model:a.model})?await A(a.name)?(q.success(`Command renamed to "${$e}"`),w($e)):q.error(r("settings.commands.sidebar.toast.removeOldAfterRenameFailed")):q.error(r("settings.commands.sidebar.toast.renameFailed")),i(null)},e[35]=g,e[36]=S,e[37]=A,e[38]=a,e[39]=o,e[40]=w,e[41]=r,e[42]=J):J=e[42];const H=J;let re,ce,Ne,me,we,_;if(e[43]!==T||e[44]!==V||e[45]!==L||e[46]!==te||e[47]!==n||e[48]!==f||e[49]!==x||e[50]!==w||e[51]!==r){const $e=T.filter(Fi),Ve=T.filter(D5);e[58]===Symbol.for("react.memo_cache_sentinel")?(we=pe("flex h-full flex-col","bg-background"),e[58]=we):we=e[58];let tt;e[59]!==r?(tt=r("settings.commands.sidebar.title"),e[59]=r,e[60]=tt):tt=e[60];let Qe;e[61]!==tt?(Qe=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:tt}),e[61]=tt,e[62]=Qe):Qe=e[62];let ze;e[63]===Symbol.for("react.memo_cache_sentinel")?(ze=s.jsx(Go,{className:"mb-3"}),e[63]=ze):ze=e[63];let ht;e[64]!==T.length||e[65]!==r?(ht=r("settings.commands.sidebar.total",{count:T.length}),e[64]=T.length,e[65]=r,e[66]=ht):ht=e[66];let _t;e[67]!==ht?(_t=s.jsx("span",{className:"typography-meta text-muted-foreground",children:ht}),e[67]=ht,e[68]=_t):_t=e[68];let Kt;e[69]===Symbol.for("react.memo_cache_sentinel")?(Kt=s.jsx(_s,{className:"h-3.5 w-3.5"}),e[69]=Kt):Kt=e[69];let Ut;e[70]!==V?(Ut=s.jsx(je,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:V,children:Kt}),e[70]=V,e[71]=Ut):Ut=e[71];let jt;e[72]!==_t||e[73]!==Ut?(jt=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[_t,Ut]}),e[72]=_t,e[73]=Ut,e[74]=jt):jt=e[74],e[75]!==Qe||e[76]!==jt?(_=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[Qe,ze,jt]}),e[75]=Qe,e[76]=jt,e[77]=_):_=e[77],re=Es,ce="flex-1 min-h-0",Ne="space-y-1 px-3 py-2",me=T.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(Za,{className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:r("settings.commands.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:r("settings.commands.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[$e.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:r("settings.commands.sidebar.section.builtIn")}),[...$e].sort(T5).map(Dt=>s.jsx(nf,{command:Dt,isSelected:x===Dt.name,onSelect:()=>{w(Dt.name),n?.()},onReset:()=>B(Dt),onDuplicate:()=>te(Dt),isMenuOpen:f===Dt.name,onMenuOpenChange:ts=>y(ts?Dt.name:null)},Dt.name))]}),Ve.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")}),[...Ve].sort(M5).map(Dt=>s.jsx(nf,{command:Dt,isSelected:x===Dt.name,onSelect:()=>{w(Dt.name),n?.()},onRename:()=>z(Dt),onDelete:()=>L(Dt),onDuplicate:()=>te(Dt),isMenuOpen:f===Dt.name,onMenuOpenChange:ts=>y(ts?Dt.name:null)},Dt.name))]})]}),e[43]=T,e[44]=V,e[45]=L,e[46]=te,e[47]=n,e[48]=f,e[49]=x,e[50]=w,e[51]=r,e[52]=re,e[53]=ce,e[54]=Ne,e[55]=me,e[56]=we,e[57]=_}else re=e[52],ce=e[53],Ne=e[54],me=e[55],we=e[56],_=e[57];let ue;e[78]!==re||e[79]!==ce||e[80]!==Ne||e[81]!==me?(ue=s.jsx(re,{outerClassName:ce,className:Ne,children:me}),e[78]=re,e[79]=ce,e[80]=Ne,e[81]=me,e[82]=ue):ue=e[82];const Q=d!==null&&m!==null;let oe;e[83]!==h?(oe=$e=>{!$e&&!h&&le()},e[83]=h,e[84]=oe):oe=e[84];let Z;e[85]!==m||e[86]!==r?(Z=r(m==="delete"?"settings.commands.sidebar.dialog.deleteTitle":"settings.commands.sidebar.dialog.resetTitle"),e[85]=m,e[86]=r,e[87]=Z):Z=e[87];let Ie;e[88]!==Z?(Ie=s.jsx(Ss,{children:Z}),e[88]=Z,e[89]=Ie):Ie=e[89];let Se;e[90]!==d?.name||e[91]!==m||e[92]!==r?(Se=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]=Se):Se=e[93];let Y;e[94]!==Se?(Y=s.jsx(Os,{children:Se}),e[94]=Se,e[95]=Y):Y=e[95];let fe;e[96]!==Ie||e[97]!==Y?(fe=s.jsxs(Is,{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 xe;e[101]!==h||e[102]!==ke?(xe=s.jsx(je,{size:"sm",variant:"ghost",onClick:le,disabled:h,children:ke}),e[101]=h,e[102]=ke,e[103]=xe):xe=e[103];let he;e[104]!==m||e[105]!==r?(he=r(m==="delete"?"settings.common.actions.delete":"settings.common.actions.reset"),e[104]=m,e[105]=r,e[106]=he):he=e[106];let Pe;e[107]!==ae||e[108]!==h||e[109]!==he?(Pe=s.jsx(je,{size:"sm",onClick:ae,disabled:h,children:he}),e[107]=ae,e[108]=h,e[109]=he,e[110]=Pe):Pe=e[110];let Be;e[111]!==xe||e[112]!==Pe?(Be=s.jsxs(Qs,{children:[xe,Pe]}),e[111]=xe,e[112]=Pe,e[113]=Be):Be=e[113];let G;e[114]!==fe||e[115]!==Be?(G=s.jsxs(vs,{className:"max-w-md",children:[fe,Be]}),e[114]=fe,e[115]=Be,e[116]=G):G=e[116];let be;e[117]!==Q||e[118]!==oe||e[119]!==G?(be=s.jsx(ws,{open:Q,onOpenChange:oe,children:G}),e[117]=Q,e[118]=oe,e[119]=G,e[120]=be):be=e[120];const De=a!==null;let Ae;e[121]===Symbol.for("react.memo_cache_sentinel")?(Ae=$e=>!$e&&i(null),e[121]=Ae):Ae=e[121];let ve;e[122]!==r?(ve=r("settings.commands.sidebar.renameDialog.title"),e[122]=r,e[123]=ve):ve=e[123];let U;e[124]!==ve?(U=s.jsx(Ss,{children:ve}),e[124]=ve,e[125]=U):U=e[125];const de=a?.name??"";let Re;e[126]!==r||e[127]!==de?(Re=r("settings.commands.sidebar.renameDialog.description",{name:de}),e[126]=r,e[127]=de,e[128]=Re):Re=e[128];let Le;e[129]!==Re?(Le=s.jsx(Os,{children:Re}),e[129]=Re,e[130]=Le):Le=e[130];let se;e[131]!==U||e[132]!==Le?(se=s.jsxs(Is,{children:[U,Le]}),e[131]=U,e[132]=Le,e[133]=se):se=e[133];let ie;e[134]===Symbol.for("react.memo_cache_sentinel")?(ie=$e=>c($e.target.value),e[134]=ie):ie=e[134];let K;e[135]!==r?(K=r("settings.commands.sidebar.renameDialog.placeholder"),e[135]=r,e[136]=K):K=e[136];let _e;e[137]!==H?(_e=$e=>{$e.key==="Enter"&&H()},e[137]=H,e[138]=_e):_e=e[138];let He;e[139]!==o||e[140]!==K||e[141]!==_e?(He=s.jsx(Vt,{value:o,onChange:ie,placeholder:K,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:_e}),e[139]=o,e[140]=K,e[141]=_e,e[142]=He):He=e[142];let Ke;e[143]===Symbol.for("react.memo_cache_sentinel")?(Ke=()=>i(null),e[143]=Ke):Ke=e[143];let Ze;e[144]!==r?(Ze=r("settings.common.actions.cancel"),e[144]=r,e[145]=Ze):Ze=e[145];let Xe;e[146]!==Ze?(Xe=s.jsx(je,{size:"sm",variant:"ghost",onClick:Ke,children:Ze}),e[146]=Ze,e[147]=Xe):Xe=e[147];let mt;e[148]!==r?(mt=r("settings.common.actions.rename"),e[148]=r,e[149]=mt):mt=e[149];let et;e[150]!==H||e[151]!==mt?(et=s.jsx(je,{size:"sm",onClick:H,children:mt}),e[150]=H,e[151]=mt,e[152]=et):et=e[152];let ct;e[153]!==Xe||e[154]!==et?(ct=s.jsxs(Qs,{children:[Xe,et]}),e[153]=Xe,e[154]=et,e[155]=ct):ct=e[155];let lt;e[156]!==se||e[157]!==He||e[158]!==ct?(lt=s.jsxs(vs,{children:[se,He,ct]}),e[156]=se,e[157]=He,e[158]=ct,e[159]=lt):lt=e[159];let ye;e[160]!==De||e[161]!==lt?(ye=s.jsx(ws,{open:De,onOpenChange:Ae,children:lt}),e[160]=De,e[161]=lt,e[162]=ye):ye=e[162];let Ge;return e[163]!==we||e[164]!==_||e[165]!==ue||e[166]!==be||e[167]!==ye?(Ge=s.jsxs("div",{className:we,children:[_,ue,be,ye]}),e[163]=we,e[164]=_,e[165]=ue,e[166]=be,e[167]=ye,e[168]=Ge):Ge=e[168],Ge},nf=t=>{const e=nt.c(53),{command:n,isSelected:r,onSelect:a,onDelete:i,onReset:o,onRename:c,onDuplicate:d,isMenuOpen:p,onMenuOpenChange:m}=t,{t:u}=ut();let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=Do(),e[0]=h):h=e[0];const b=h,f=r?"bg-interactive-selection":"hover:bg-interactive-hover";let y;e[1]!==f?(y=pe("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",f),e[1]=f,e[2]=y):y=e[2];let x;e[3]!==m?(x=b?void 0:V=>{V.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||Fi(n))&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:Fi(n)?u("settings.agents.sidebar.badge.system"):n.scope}),e[7]=n,e[8]=u,e[9]=w):w=e[9];let v;e[10]!==g||e[11]!==w?(v=s.jsxs("div",{className:"flex items-center gap-2",children:[g,w]}),e[10]=g,e[11]=w,e[12]=v):v=e[12];let S;e[13]!==n.description?(S=n.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n.description}),e[13]=n.description,e[14]=S):S=e[14];let A;e[15]!==a||e[16]!==v||e[17]!==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:[v,S]}),e[15]=a,e[16]=v,e[17]=S,e[18]=A):A=e[18];let j;e[19]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(Bs,{asChild:!0,children:s.jsx(je,{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(ia,{className:"h-3.5 w-3.5"})})}),e[19]=j):j=e[19];let C;e[20]!==c||e[21]!==u?(C=c&&s.jsxs($t,{onClick:V=>{V.stopPropagation(),c()},children:[s.jsx(Yr,{className:"h-4 w-4 mr-px"}),u("settings.common.actions.rename")]}),e[20]=c,e[21]=u,e[22]=C):C=e[22];let I;e[23]!==d?(I=V=>{V.stopPropagation(),d()},e[23]=d,e[24]=I):I=e[24];let R;e[25]===Symbol.for("react.memo_cache_sentinel")?(R=s.jsx(br,{className:"h-4 w-4 mr-px"}),e[25]=R):R=e[25];let k;e[26]!==u?(k=u("settings.common.actions.duplicate"),e[26]=u,e[27]=k):k=e[27];let P;e[28]!==I||e[29]!==k?(P=s.jsxs($t,{onClick:I,children:[R,k]}),e[28]=I,e[29]=k,e[30]=P):P=e[30];let N;e[31]!==o||e[32]!==u?(N=o&&s.jsxs($t,{onClick:V=>{V.stopPropagation(),o()},children:[s.jsx(Mn,{className:"h-4 w-4 mr-px"}),u("settings.common.actions.reset")]}),e[31]=o,e[32]=u,e[33]=N):N=e[33];let D;e[34]!==i||e[35]!==u?(D=i&&s.jsxs($t,{onClick:V=>{V.stopPropagation(),i()},className:"text-destructive focus:text-destructive",children:[s.jsx(sn,{className:"h-4 w-4 mr-px"}),u("settings.common.actions.delete")]}),e[34]=i,e[35]=u,e[36]=D):D=e[36];let T;e[37]!==C||e[38]!==P||e[39]!==N||e[40]!==D?(T=s.jsxs(Vs,{align:"end",className:"w-fit min-w-20",children:[C,P,N,D]}),e[37]=C,e[38]=P,e[39]=N,e[40]=D,e[41]=T):T=e[41];let M;e[42]!==p||e[43]!==m||e[44]!==T?(M=s.jsxs(zs,{open:p,onOpenChange:m,children:[j,T]}),e[42]=p,e[43]=m,e[44]=T,e[45]=M):M=e[45];let $;e[46]!==M||e[47]!==A?($=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[A,M]}),e[46]=M,e[47]=A,e[48]=$):$=e[48];let F;return e[49]!==$||e[50]!==y||e[51]!==x?(F=s.jsx("div",{className:y,onContextMenu:x,children:$}),e[49]=$,e[50]=y,e[51]=x,e[52]=F):F=e[52],F};function C5(t){return{selectedCommandName:t.selectedCommandName,commands:t.commands,setSelectedCommand:t.setSelectedCommand,setCommandDraft:t.setCommandDraft,createCommand:t.createCommand,deleteCommand:t.deleteCommand,loadCommands:t.loadCommands}}function I5(t){return t.skills}function A5(t){return t.loadSkills}function P5(t){return t.name}function D5(t){return!Fi(t)}function T5(t,e){return t.name.localeCompare(e.name)}function M5(t,e){return t.name.localeCompare(e.name)}const R5=()=>{const{t}=ut(),{selectedCommandName:e,getCommandByName:n,createCommand:r,updateCommand:a,commands:i,commandDraft:o,setCommandDraft:c}=Bu(jr(P=>({selectedCommandName:P.selectedCommandName,getCommandByName:P.getCommandByName,createCommand:P.createCommand,updateCommand:P.updateCommand,commands:P.commands,commandDraft:P.commandDraft,setCommandDraft:P.setCommandDraft}))),d=e?n(e):null,p=!!(o&&o.name===e&&!d),[m,u]=l.useState(""),[h,b]=l.useState("user"),[f,y]=l.useState(""),[x,g]=l.useState(""),[w,v]=l.useState(""),[S,A]=l.useState(""),[j,C]=l.useState(!1),I=l.useRef(null);l.useEffect(()=>{if(p&&o){const P=o.name||"",N=o.scope||"user",D=o.description||"",T=o.agent||"",M=o.model||"",$=o.template||"";u(P),b(N),y(D),g(T),v(M),A($),I.current={draftName:P,draftScope:N,description:D,agent:T,model:M,template:$}}else if(d){const P=d.description||"",N=d.agent||"",D=d.model||"",T=d.template||"";y(P),g(N),v(D),A(T),I.current={draftName:"",draftScope:"user",description:P,agent:N,model:D,template:T}}},[d,p,e,i,o]);const R=l.useMemo(()=>{const P=I.current;return P?!!(p&&(m!==P.draftName||h!==P.draftScope)||f!==P.description||x!==P.agent||w!==P.model||S!==P.template):!1},[x,f,m,h,p,w,S]),k=async()=>{const P=p?m.trim().replace(/\s+/g,"-"):e?.trim();if(!P){q.error(t("settings.commands.sidebar.toast.commandNameRequired"));return}if(!S.trim()){q.error(t("settings.commands.page.toast.templateRequired"));return}if(p&&i.some(N=>N.name===P)){q.error(t("settings.commands.sidebar.toast.commandExists"));return}C(!0);try{const N=x.trim(),D=w.trim(),T=S.trim(),M={name:P,description:f.trim()||void 0,agent:N===""?null:N,model:D===""?null:D,template:T,scope:p?h:void 0};let $;p?($=await r(M),$&&c(null)):$=await a(P,M),$?q.success(t(p?"settings.commands.page.toast.created":"settings.commands.page.toast.updated")):q.error(t(p?"settings.commands.page.toast.createFailed":"settings.commands.page.toast.updateFailed"))}catch(N){console.error("Error saving command:",N),q.error(t("settings.commands.page.toast.saveUnexpectedError"))}finally{C(!1)}};return e?s.jsx(Es,{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(Vt,{value:m,onChange:P=>u(P.target.value),placeholder:t("settings.commands.page.field.commandNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(ps,{value:h,onValueChange:P=>b(P),children:[s.jsx(fs,{className:"w-fit min-w-[100px]",children:s.jsx(ys,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(hs,{align:"end",children:[s.jsx(Ot,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(qr,{className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(Ot,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(zn,{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(Sn,{value:f,onChange:P=>y(P.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(jc,{agentName:x,onChange:P=>g(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.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(Ho,{providerId:Gi(w)?.providerId??"",modelId:Gi(w)?.modelId??"",onChange:(P,N)=>{v(P&&N?`${P}/${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(Sn,{value:S,onChange:P=>A(P.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(je,{onClick:k,disabled:j||!R,size:"xs",className:"!font-normal",children:t(j?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(Za,{className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.commands.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.commands.page.empty.description")})]})})},rf=t=>{switch(t){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"idle"}},af=t=>{const e=nt.c(5),{tone:n,enabled:r}=t;if(!r){let o;return e[0]===Symbol.for("react.memo_cache_sentinel")?(o=s.jsx("span",{className:"inline-block h-2 w-2 rounded-full bg-muted-foreground/30 flex-shrink-0"}),e[0]=o):o=e[0],o}let a;e[1]!==n?(a=pe("inline-block h-2 w-2 rounded-full flex-shrink-0",{success:"bg-[var(--status-success)]",error:"bg-[var(--status-error)]",warning:"bg-[var(--status-warning)]",idle:"bg-muted-foreground/40"}[n]),e[1]=n,e[2]=a):a=e[2];let i;return e[3]!==a?(i=s.jsx("span",{className:a}),e[3]=a,e[4]=i):i=e[4],i},E5=t=>{const e=nt.c(116),{onItemSelect:n}=t,{t:r}=ut(),{mcpServers:a,selectedMcpName:i,setSelectedMcp:o,setMcpDraft:c,loadMcpConfigs:d,deleteMcp:p}=Fo(jr(F5)),m=Ws(O5);let u;e[0]!==m?(u=ve=>ve.getStatusForDirectory(m??null),e[0]=m,e[1]=u):u=e[1];const h=Pn(u),b=Pn(L5),f=Pn($5),[y,x]=l.useState(null),[g,w]=l.useState(!1),[v,S]=l.useState(null),[A,j]=l.useState(!1);let C;e[2]!==a?(C=a.filter(B5),e[2]=a,e[3]=C):C=e[3];const I=C;let R;e[4]!==a?(R=a.filter(V5),e[4]=a,e[5]=R):R=e[5];const k=R;let P,N;e[6]!==d?(P=()=>{d()},N=[d],e[6]=d,e[7]=P,e[8]=N):(P=e[7],N=e[8]),l.useEffect(P,N);let D;e[9]!==m||e[10]!==f||e[11]!==A||e[12]!==b?(D=()=>{if(A)return;j(!0);const ve=new Promise(z5);Promise.all([b({directory:m,silent:!0}),ve]).then(()=>{const U=f(m);U&&q.error(U)}).finally(()=>{j(!1)})},e[9]=m,e[10]=f,e[11]=A,e[12]=b,e[13]=D):D=e[13];const T=D;let M;e[14]!==a||e[15]!==n||e[16]!==c||e[17]!==o?(M=()=>{let ve="new-mcp-server",U=1;for(;a.some(Re=>Re.name===ve);)ve=`new-mcp-server-${U}`,U++;c({name:ve,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),o(ve),n?.()},e[14]=a,e[15]=n,e[16]=c,e[17]=o,e[18]=M):M=e[18];const $=M;let F;e[19]!==p||e[20]!==y||e[21]!==r?(F=async()=>{if(!y)return;w(!0);const ve=await p(y.name);ve.ok?ve.reloadFailed?q.warning(ve.message||`MCP server "${y.name}" deleted, but OpenCode reload failed`,{description:ve.warning||r("settings.mcp.sidebar.toast.refreshListIfStale")}):q.success(ve.message||r("settings.mcp.sidebar.toast.serverDeleted",{name:y.name})):q.error(r("settings.mcp.sidebar.toast.deleteFailed")),x(null),w(!1)},e[19]=p,e[20]=y,e[21]=r,e[22]=F):F=e[22];const V=F;let O;e[23]===Symbol.for("react.memo_cache_sentinel")?(O=pe("flex h-full flex-col","bg-background"),e[23]=O):O=e[23];let L;e[24]!==r?(L=r("settings.mcp.sidebar.title"),e[24]=r,e[25]=L):L=e[25];let W;e[26]!==L?(W=s.jsx("h2",{className:"text-base font-semibold text-foreground",children:L}),e[26]=L,e[27]=W):W=e[27];let B;e[28]!==r?(B=r("settings.mcp.sidebar.actions.refreshStatusAria"),e[28]=r,e[29]=B):B=e[29];let ne;e[30]!==r?(ne=r("settings.mcp.sidebar.actions.refreshStatusTitle"),e[30]=r,e[31]=ne):ne=e[31];const le=A&&"animate-spin";let ee;e[32]!==le?(ee=pe("h-4 w-4",le),e[32]=le,e[33]=ee):ee=e[33];let ae;e[34]!==ee?(ae=s.jsx(Nn,{className:ee}),e[34]=ee,e[35]=ae):ae=e[35];let ge;e[36]!==T||e[37]!==A||e[38]!==B||e[39]!==ne||e[40]!==ae?(ge=s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",disabled:A,onClick:T,"aria-label":B,title:ne,children:ae}),e[36]=T,e[37]=A,e[38]=B,e[39]=ne,e[40]=ae,e[41]=ge):ge=e[41];let te;e[42]!==W||e[43]!==ge?(te=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[W,ge]}),e[42]=W,e[43]=ge,e[44]=te):te=e[44];let E;e[45]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx(Go,{className:"mb-3"}),e[45]=E):E=e[45];let z;e[46]!==a.length||e[47]!==r?(z=r("settings.mcp.sidebar.total",{count:a.length}),e[46]=a.length,e[47]=r,e[48]=z):z=e[48];let J;e[49]!==z?(J=s.jsx("span",{className:"typography-meta text-muted-foreground",children:z}),e[49]=z,e[50]=J):J=e[50];let H;e[51]!==r?(H=r("settings.mcp.sidebar.actions.addServerTitle"),e[51]=r,e[52]=H):H=e[52];let re;e[53]===Symbol.for("react.memo_cache_sentinel")?(re=s.jsx(_s,{className:"h-3.5 w-3.5"}),e[53]=re):re=e[53];let ce;e[54]!==$||e[55]!==H?(ce=s.jsx(je,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:$,title:H,children:re}),e[54]=$,e[55]=H,e[56]=ce):ce=e[56];let Ne;e[57]!==J||e[58]!==ce?(Ne=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[J,ce]}),e[57]=J,e[58]=ce,e[59]=Ne):Ne=e[59];let me;e[60]!==te||e[61]!==Ne?(me=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[te,E,Ne]}),e[60]=te,e[61]=Ne,e[62]=me):me=e[62];let we;e[63]!==a.length||e[64]!==h||e[65]!==n||e[66]!==v||e[67]!==I||e[68]!==i||e[69]!==c||e[70]!==o||e[71]!==r||e[72]!==k?(we=s.jsx(Es,{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(Gh,{className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:r("settings.mcp.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:r("settings.mcp.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[I.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:r("settings.mcp.sidebar.group.projectServers")}),I.map(ve=>{const U=h[ve.name],de=rf(U?.status),Re=i===ve.name,Le=Do();return s.jsxs("div",{className:pe("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",Re?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:Le?void 0:se=>{se.preventDefault(),S(ve.name)},children:[s.jsxs("button",{onClick:()=>{o(ve.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(af,{tone:de,enabled:ve.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:ve.name}),s.jsx("span",{title:ve.type==="local"?r("settings.mcp.sidebar.serverType.localTitle"):r("settings.mcp.sidebar.serverType.remoteTitle"),children:ve.type==="local"?s.jsx(ei,{className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(ti,{className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"})})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight pl-4",children:ve.type==="local"?ve.command?.join(" ")??"":ve.url??""})]}),s.jsxs(zs,{open:v===ve.name,onOpenChange:se=>S(se?ve.name:null),children:[s.jsx(Bs,{asChild:!0,children:s.jsx(je,{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(ia,{className:"h-3.5 w-3.5"})})}),s.jsx(Vs,{align:"end",className:"w-fit min-w-20",children:s.jsxs($t,{onClick:se=>{se.stopPropagation(),x(ve)},className:"text-destructive focus:text-destructive",children:[s.jsx(sn,{className:"h-4 w-4 mr-px"}),r("settings.common.actions.delete")]})})]})]},ve.name)})]}),k.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:r("settings.mcp.sidebar.group.userServers")}),k.map(ve=>{const U=h[ve.name],de=rf(U?.status),Re=i===ve.name,Le=Do();return s.jsxs("div",{className:pe("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",Re?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:Le?void 0:se=>{se.preventDefault(),S(ve.name)},children:[s.jsxs("button",{onClick:()=>{o(ve.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(af,{tone:de,enabled:ve.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:ve.name}),s.jsx("span",{title:ve.type==="local"?r("settings.mcp.sidebar.serverType.localTitle"):r("settings.mcp.sidebar.serverType.remoteTitle"),children:ve.type==="local"?s.jsx(ei,{className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(ti,{className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"})})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight pl-4",children:ve.type==="local"?ve.command?.join(" ")??"":ve.url??""})]}),s.jsxs(zs,{open:v===ve.name,onOpenChange:se=>S(se?ve.name:null),children:[s.jsx(Bs,{asChild:!0,children:s.jsx(je,{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(ia,{className:"h-3.5 w-3.5"})})}),s.jsx(Vs,{align:"end",className:"w-fit min-w-20",children:s.jsxs($t,{onClick:se=>{se.stopPropagation(),x(ve)},className:"text-destructive focus:text-destructive",children:[s.jsx(sn,{className:"h-4 w-4 mr-px"}),r("settings.common.actions.delete")]})})]})]},ve.name)})]})]})}),e[63]=a.length,e[64]=h,e[65]=n,e[66]=v,e[67]=I,e[68]=i,e[69]=c,e[70]=o,e[71]=r,e[72]=k,e[73]=we):we=e[73];const _=y!==null;let ue;e[74]!==g?(ue=ve=>{!ve&&!g&&x(null)},e[74]=g,e[75]=ue):ue=e[75];let Q;e[76]!==r?(Q=r("settings.mcp.sidebar.deleteDialog.title"),e[76]=r,e[77]=Q):Q=e[77];let oe;e[78]!==Q?(oe=s.jsx(Ss,{children:Q}),e[78]=Q,e[79]=oe):oe=e[79];const Z=y?.name||"";let Ie;e[80]!==r||e[81]!==Z?(Ie=r("settings.mcp.sidebar.deleteDialog.descriptionPrefix",{name:Z}),e[80]=r,e[81]=Z,e[82]=Ie):Ie=e[82];let Se;e[83]===Symbol.for("react.memo_cache_sentinel")?(Se=s.jsx("code",{className:"text-foreground",children:"opencode.json"}),e[83]=Se):Se=e[83];let Y;e[84]!==Ie?(Y=s.jsxs(Os,{children:[Ie," ",Se,"."]}),e[84]=Ie,e[85]=Y):Y=e[85];let fe;e[86]!==oe||e[87]!==Y?(fe=s.jsxs(Is,{children:[oe,Y]}),e[86]=oe,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 xe;e[90]!==r?(xe=r("settings.common.actions.cancel"),e[90]=r,e[91]=xe):xe=e[91];let he;e[92]!==g||e[93]!==xe?(he=s.jsx(je,{size:"sm",variant:"ghost",onClick:ke,disabled:g,children:xe}),e[92]=g,e[93]=xe,e[94]=he):he=e[94];let Pe;e[95]!==g||e[96]!==r?(Pe=r(g?"settings.mcp.sidebar.actions.deleting":"settings.common.actions.delete"),e[95]=g,e[96]=r,e[97]=Pe):Pe=e[97];let Be;e[98]!==V||e[99]!==g||e[100]!==Pe?(Be=s.jsx(je,{size:"sm",onClick:V,disabled:g,children:Pe}),e[98]=V,e[99]=g,e[100]=Pe,e[101]=Be):Be=e[101];let G;e[102]!==he||e[103]!==Be?(G=s.jsxs(Qs,{children:[he,Be]}),e[102]=he,e[103]=Be,e[104]=G):G=e[104];let be;e[105]!==fe||e[106]!==G?(be=s.jsxs(vs,{className:"max-w-md",children:[fe,G]}),e[105]=fe,e[106]=G,e[107]=be):be=e[107];let De;e[108]!==_||e[109]!==ue||e[110]!==be?(De=s.jsx(ws,{open:_,onOpenChange:ue,children:be}),e[108]=_,e[109]=ue,e[110]=be,e[111]=De):De=e[111];let Ae;return e[112]!==me||e[113]!==we||e[114]!==De?(Ae=s.jsxs("div",{className:O,children:[me,we,De]}),e[112]=me,e[113]=we,e[114]=De,e[115]=Ae):Ae=e[115],Ae};function F5(t){return{mcpServers:t.mcpServers,selectedMcpName:t.selectedMcpName,setSelectedMcp:t.setSelectedMcp,setMcpDraft:t.setMcpDraft,loadMcpConfigs:t.loadMcpConfigs,deleteMcp:t.deleteMcp}}function O5(t){return t.currentDirectory}function L5(t){return t.refresh}function $5(t){return t.getErrorForDirectory}function B5(t){return t.scope==="project"}function V5(t){return t.scope!=="project"}function z5(t){return setTimeout(t,500)}function Na(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function lo(t){return Array.isArray(t)&&t.every(e=>typeof e=="string")}function Oa(t,e){return e!==void 0?{ok:!1,error:t,parsed:e}:{ok:!1,error:t}}function dd(t,e,n){const r=_5(n),a=typeof n.url=="string"?n.url.trim():"",i=of(n,"env","environment"),o=of(n,"headers"),c=U5(n),d=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.clientId??"").trim():"",p=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.clientSecret??"").trim():"",m=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.scope??"").trim():"",u=typeof n.oauth=="object"&&n.oauth!==null?String(n.oauth.redirectUri??"").trim():"",h=W5(n),b=K5(n);return{ok:!0,name:t,type:e,command:r,url:a,environment:i,headers:o,oauthEnabled:c,oauthClientId:d,oauthClientSecret:p,oauthScope:m,oauthRedirectUri:u,timeout:h,enabled:b}}function _5(t){const e=t.command,n=t.args;if(lo(e)&&lo(n))return[...e,...n];if(lo(e))return e;if(typeof e=="string"&&e.trim()){const r=e.trim().split(/\s+/);return lo(n)?[...r,...n]:r}return lo(n)?n:[]}function of(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 U5(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 W5(t){const e=t.timeout;if(typeof e=="number"&&Number.isFinite(e)&&e>0)return String(Math.floor(e));if(typeof e=="string"&&e.trim()){const n=Number(e);if(Number.isFinite(n)&&n>0)return String(Math.floor(n))}return""}function K5(t){return"disabled"in t&&t.disabled===!0?!1:"enabled"in t?!!t.enabled:!0}function H5(t){const e=t.mcpServers;if(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(Ax(a))return{name:r,entry:a}}return null}function Ax(t){return t.type==="local"||t.type==="remote"||Array.isArray(t.command)||typeof t.url=="string"||Array.isArray(t.args)}function G5(t,e){let n;try{const o=t.trim();if(!o)return Oa("No JSON content provided");n=JSON.parse(o)}catch(o){return Oa(o instanceof Error?`Invalid JSON: ${o.message}`:"Invalid JSON")}if(!Na(n))return Oa("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 Oa("mcpServers object is empty",n);if(o.length>1)return Oa("Paste one server at a time. Found "+o.length+" servers in mcpServers",n);const c=o[0],d=a[c];return Na(d)?dd(c,ud(d),d):Oa("Server entry is not a valid object",n)}const i=H5(r);if(i)return dd(i.name,ud(i.entry),i.entry);if(Ax(r)){const o=ud(r),c=typeof r.name=="string"&&r.name.trim()?r.name.trim():e?.fallbackName;return dd(c,o,r)}return Oa("No recognizable MCP server configuration found in JSON",n)}function ud(t){return t.type==="remote"?"remote":t.type==="local"?"local":typeof t.url=="string"&&t.url.trim()?"remote":(Array.isArray(t.command)||typeof t.command=="string"||Array.isArray(t.args),"local")}function q5(t,e,n){const r=n?.isNewServer??!1,a=t.name,i=r&&a?a:e.name??"";return{...e,name:i,type:t.type,command:t.type==="local"?t.command:[],url:t.type==="remote"?t.url:"",environment:t.environment,headers:t.type==="remote"?t.headers:[],oauthEnabled:t.type==="remote"?t.oauthEnabled:!1,oauthClientId:t.type==="remote"?t.oauthClientId:"",oauthClientSecret:t.type==="remote"?t.oauthClientSecret:"",oauthScope:t.type==="remote"?t.oauthScope:"",oauthRedirectUri:t.type==="remote"?t.oauthRedirectUri:"",timeout:t.type==="remote"?t.timeout:"",enabled:t.enabled}}const Px="/mcp/oauth/callback",Q5=t=>{if(typeof window>"u")return null;try{const e=t.replace(/-/g,"+").replace(/_/g,"/"),n=e.length%4===0?"":"=".repeat(4-e.length%4),r=window.atob(e+n),a=Uint8Array.from(r,i=>i.charCodeAt(0));return new TextDecoder().decode(a)}catch{return null}},Dx=t=>{const e=J5(t.get("state"));if(e)return e;const n=t.get("server");if(typeof n!="string"||!n.trim())return null;const r=t.get("directory");return{name:n.trim(),directory:typeof r=="string"&&r.trim()?r.trim():null}},Ju=t=>{const e=t.get("state");return typeof e!="string"?null:e.trim()||null},J5=t=>{if(typeof t!="string"||!t.trim())return null;const e=Q5(t.trim());if(!e)return null;try{const n=JSON.parse(e);return n?.v!==1||typeof n.n!="string"||!n.n.trim()?null:{name:n.n.trim(),directory:typeof n.d=="string"&&n.d.trim()?n.d.trim():null}}catch{return null}};function Y5(t){const e=[];let n="",r=!1,a=!1;for(let i=0;i<t.length;i++){const o=t[i];if(o==="'"&&!a){r=!r;continue}if(o==='"'&&!r){a=!a;continue}if((o===" "||o===" ")&&!r&&!a){n&&(e.push(n),n="");continue}n+=o}return n&&e.push(n),e}function X5(t){const e=t.trim();if(!e)return{code:null,context:null,stateKey:null};try{const n=new URL(e),r=n.searchParams.get("code");if(typeof r=="string"&&r.trim())return{code:r.trim(),context:Dx(n.searchParams),stateKey:Ju(n.searchParams)}}catch{}return{code:e,context:null,stateKey:null}}const Z5=({value:t,onChange:e,pasteCommandTitle:n,pasteCommandLabel:r,pasteSuccess:a,clipboardReadFailed:i,preview:o})=>{const[c,d]=l.useState(()=>t.join(`
66
- `)),p=l.useRef(t);l.useEffect(()=>{JSON.stringify(p.current)!==JSON.stringify(t)&&(p.current=t,d(t.join(`
67
- `)))},[t]);const m=h=>{const b=h.split(`
68
- `).filter(f=>f.trim().length>0);e(b)},u=async()=>{try{const b=(await navigator.clipboard.readText()).trim(),f=b.includes(`
69
- `)?b.split(`
70
- `).filter(y=>y.trim()):Y5(b);d(f.join(`
71
- `)),e(f),q.success(a(f.length))}catch{q.error(i)}};return s.jsxs("div",{className:"space-y-2","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",children:[s.jsx("div",{className:"flex items-center justify-end gap-2",children:s.jsxs(je,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:u,type:"button",title:n,children:[s.jsx(ni,{className:"h-3 w-3"}),r]})}),s.jsx(Sn,{value:c,onChange:h=>{d(h.target.value),m(h.target.value)},onBlur:()=>{const h=c.split(`
72
- `).map(b=>b.trimEnd()).join(`
73
- `);d(h),m(h)},placeholder:`npx
74
- -y
75
- @modelcontextprotocol/server-postgres
76
- postgresql://user:pass@host/db`,rows:Math.max(4,t.length+1),className:"font-mono typography-meta resize-y min-h-[80px]",spellCheck:!1}),t.length>0&&s.jsxs("details",{className:"group",children:[s.jsx("summary",{className:"typography-micro text-muted-foreground/60 cursor-pointer select-none hover:text-muted-foreground",children:o(t.length)}),s.jsx("div",{className:"mt-1 rounded-md bg-[var(--surface-elevated)] px-3 py-2 overflow-x-auto",children:s.jsx("code",{className:"typography-micro text-foreground/80 whitespace-pre",children:t.map((h,b)=>s.jsxs("span",{className:"block",children:[s.jsxs("span",{className:"text-muted-foreground select-none mr-2",children:["[",b,"]"]}),h]},b))})})]})]})},eC=t=>t.toUpperCase().replace(/[^A-Z0-9_]/g,"_"),lf=({value:t,onChange:e,keyTransform:n=eC,keyPlaceholder:r="API_KEY",keyInputClassName:a="w-36 shrink-0 font-mono typography-meta uppercase",pasteLabel:i="Paste .env",pasteTitle:o="Paste KEY=VALUE lines from clipboard",noPairsFoundError:c,importSuccess:d,clipboardReadFailed:p,keyLabel:m,valueLabel:u,valuePlaceholder:h,hideValueTitle:b,showValueTitle:f,addVariable:y,plainTextWarning:x,removeVariableAria:g})=>{const[w,v]=l.useState(new Set),S=()=>e([...t,{key:"",value:""}]),A=k=>{e(t.filter((P,N)=>N!==k)),v(P=>{const N=new Set(P);return N.delete(k),N})},j=(k,P,N)=>{const D=[...t];D[k]={...D[k],[P]:N},e(D)},C=k=>{v(P=>{const N=new Set(P);return N.has(k)?N.delete(k):N.add(k),N})},I=async()=>{try{const k=await navigator.clipboard.readText(),P=[];for(const D of k.split(`
77
- `)){const T=D.trim();if(!T||T.startsWith("#"))continue;const M=T.indexOf("=");if(M===-1)continue;const $=T.slice(0,M).trim();let F=T.slice(M+1).trim();(F.startsWith('"')&&F.endsWith('"')||F.startsWith("'")&&F.endsWith("'"))&&(F=F.slice(1,-1)),$&&P.push({key:$,value:F})}if(P.length===0){q.error(c);return}const N=[...t];for(const D of P){const T=N.findIndex(M=>M.key===D.key);T!==-1?N[T]=D:N.push(D)}e(N),q.success(d(P.length))}catch{q.error(p)}},R=t.some(k=>k.value.length>0);return s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("span",{className:"typography-micro text-muted-foreground w-32 shrink-0",children:m}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:u})]}),s.jsxs(je,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:I,type:"button",title:o,children:[s.jsx(ni,{className:"h-3 w-3"}),i]})]}),s.jsx("div",{className:"space-y-1.5",children:t.map((k,P)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Vt,{value:k.key,onChange:N=>j(P,"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(Vt,{type:w.has(P)?"text":"password",value:k.value,onChange:N=>j(P,"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:()=>C(P),className:"absolute right-2 text-muted-foreground/60 hover:text-muted-foreground",title:w.has(P)?b:f,children:w.has(P)?s.jsx(Pu,{className:"h-3.5 w-3.5"}):s.jsx(Au,{className:"h-3.5 w-3.5"})})]}),s.jsx(je,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 shrink-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>A(P),"aria-label":g,children:s.jsx(sn,{className:"h-3.5 w-3.5"})})]},P))}),s.jsxs(je,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:S,type:"button",children:[s.jsx(_s,{className:"h-3.5 w-3.5"}),y]}),R&&s.jsx("p",{className:"typography-micro text-muted-foreground/60",children:x})]})},cf=t=>{const e=nt.c(14),{status:n,enabled:r,getStatusLabel:a,variant:i}=t,o=i===void 0?"compact":i;if(!r||!n)return null;let c,d;if(e[0]!==a||e[1]!==n||e[2]!==o){d=Symbol.for("react.early_return_sentinel");e:{const 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=pe("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=pe("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},tC=(t,e,n)=>{switch(t){case"connected":return e("settings.mcp.page.status.description.connected");case"failed":return n?.trim()||e("settings.mcp.page.status.description.failedDefault");case"needs_auth":return e("settings.mcp.page.status.description.needsAuth");case"needs_client_registration":return n?.trim()||e("settings.mcp.page.status.description.needsClientRegistrationDefault");case"disabled":return e("settings.mcp.page.status.description.disabled");default:return e("settings.mcp.page.status.description.default")}},sC=t=>{switch(t){case"failed":return"border-[var(--status-error-border)] bg-[var(--status-error-background)]";case"needs_auth":case"needs_client_registration":return"border-[var(--status-warning-border)] bg-[var(--status-warning-background)]";default:return"border-[var(--interactive-border)] bg-[var(--surface-elevated)]"}},nC=(t,e,n,r)=>!!(t==="failed"||t==="needs_auth"||t==="needs_client_registration"||e||n||r),df=(t,e)=>{if(typeof window>"u")return null;const n=new URL(Px,window.location.origin);return typeof t=="string"&&t.trim()&&n.searchParams.set("server",t.trim()),typeof e=="string"&&e.trim()&&n.searchParams.set("directory",e.trim()),n.toString()},rC=async t=>{const e=await fetch("/api/mcp/auth/pending",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({state:t.state,name:t.name,directory:typeof t.directory=="string"&&t.directory.trim()?t.directory.trim():null})});if(!e.ok){const n=await e.json().catch(()=>null);throw new Error(n?.error||"Failed to prepare MCP authorization callback")}},aC=async t=>{const e=await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(t)}`);if(!e.ok)return null;const n=await e.json().catch(()=>null);return n?.name?.trim()?{name:n.name.trim(),directory:typeof n.directory=="string"&&n.directory.trim()?n.directory.trim():null}:null},co=async t=>{typeof t!="string"||!t.trim()||await fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(t.trim())}`,{method:"DELETE"}).catch(()=>{})},md=(t,e,n)=>{const r=t instanceof Error?t.message:e;return/oauth state required/i.test(r)?n("settings.mcp.page.toast.authSessionExpired"):r},iC=(t,e)=>{const n=typeof e=="string"&&e.trim()?e.trim():"__global__";return`${t??"__none__"}::${n}`},oC=()=>{const{t}=ut(),e=l.useCallback((Ue,Tt)=>t(Ue,Tt),[t]),{selectedMcpName:n,mcpServers:r,mcpDraft:a,setMcpDraft:i,setSelectedMcp:o,getMcpByName:c,createMcp:d,updateMcp:p,deleteMcp:m}=Fo(jr(Ue=>({selectedMcpName:Ue.selectedMcpName,mcpServers:Ue.mcpServers,mcpDraft:Ue.mcpDraft,setMcpDraft:Ue.setMcpDraft,setSelectedMcp:Ue.setSelectedMcp,getMcpByName:Ue.getMcpByName,createMcp:Ue.createMcp,updateMcp:Ue.updateMcp,deleteMcp:Ue.deleteMcp}))),u=Ws(Ue=>Ue.currentDirectory),h=l.useMemo(()=>yn(),[]),b=Pn(Ue=>Ue.getStatusForDirectory(u??null)),f=Pn(Ue=>Ue.getDiagnosticForDirectory(u??null)),y=Pn(Ue=>Ue.refresh),x=Pn(Ue=>Ue.connect),g=Pn(Ue=>Ue.disconnect),w=Pn(Ue=>Ue.startAuth),v=Pn(Ue=>Ue.completeAuth),S=Pn(Ue=>Ue.clearAuth),A=Pn(Ue=>Ue.testConnection),j=n?c(n):null,C=!!(a&&a.name===n&&!j),[I,R]=l.useState(""),[k,P]=l.useState("user"),[N,D]=l.useState("local"),[T,M]=l.useState([]),[$,F]=l.useState(""),[V,O]=l.useState([]),[L,W]=l.useState([]),[B,ne]=l.useState(!0),[le,ee]=l.useState(""),[ae,ge]=l.useState(""),[te,E]=l.useState(""),[z,J]=l.useState(""),[H,re]=l.useState(""),[ce,Ne]=l.useState(!0),[me,we]=l.useState(!1),[_,ue]=l.useState(!1),[Q,oe]=l.useState(!1),[Z,Ie]=l.useState(!1),[Se,Y]=l.useState(!1),[fe,ke]=l.useState(!1),[xe,he]=l.useState(!1),[Pe,Be]=l.useState(!1),[G,be]=l.useState(null),[De,Ae]=l.useState(null),[ve,U]=l.useState(""),[de,Re]=l.useState(!1),Le=l.useRef(0),se=l.useRef(!1),[ie,K]=l.useState(!1),[_e,He]=l.useState(!1),[Ke,Ze]=l.useState(""),[Xe,mt]=l.useState(null),et=l.useMemo(()=>iC(n,u),[u,n]),ct=l.useRef(et),lt=l.useRef(null),ye=l.useCallback(()=>{be(null),Ae(null),U(""),Re(!1),Le.current=0,Be(!1),Y(!1),ke(!1),se.current=!1},[]),Ge=l.useCallback(()=>{Ze(""),mt(null),He(!0)},[]),$e=l.useCallback(async()=>{try{const Ue=await navigator.clipboard.readText();Ze(Ue),mt(null)}catch{q.error(t("settings.mcp.page.toast.clipboardReadFailed"))}},[t]),Ve=l.useCallback(()=>{const Ue=G5(Ke,{fallbackName:I});if(!Ue.ok){mt(Ue.error);return}const At=q5(Ue,{name:I,scope:k,type:N,command:T,url:$,environment:V,headers:L,oauthEnabled:B,oauthClientId:le,oauthClientSecret:ae,oauthScope:te,oauthRedirectUri:z,timeout:H,enabled:ce},{isNewServer:C});R(At.name),D(At.type),M(At.command??[]),F(At.url??""),O(At.environment??[]),W(At.headers??[]),ne(At.oauthEnabled??!1),ee(At.oauthClientId??""),ge(At.oauthClientSecret??""),E(At.oauthScope??""),J(At.oauthRedirectUri??""),re(At.timeout??""),Ne(At.enabled??!0),He(!1),Ze(""),mt(null),q.success(t("settings.mcp.page.toast.configImported"))},[Ke,I,k,N,T,$,V,L,B,le,ae,te,z,H,ce,C,t]);l.useEffect(()=>{if(C&&a){R(a.name),P(a.scope||"user"),D(a.type),M(a.command),F(a.url),O(a.environment),W(a.headers),ne(a.oauthEnabled),ee(a.oauthClientId),ge(a.oauthClientSecret),E(a.oauthScope),J(a.oauthRedirectUri),re(a.timeout),Ne(a.enabled),K(!1),lt.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){P(j.scope==="project"?"project":"user");const Ue=Qm(j.environment),Tt=j.type==="remote"?j:null,At=Qm(Tt?.headers),vt=Tt?.oauth,Rt=vt&&typeof vt=="object"?vt:null,ns=vt!==!1,As=j.type,ft=As==="local"?j.command??[]:[],is=As==="remote"?j.url??"":"",es=typeof Tt?.timeout=="number"&&Number.isFinite(Tt.timeout)?String(Tt.timeout):"";D(As),M(ft),F(is),O(Ue),W(At),ne(ns),ee(ns?Rt?.clientId??"":""),ge(ns?Rt?.clientSecret??"":""),E(ns?Rt?.scope??"":""),J(ns?Rt?.redirectUri??"":""),re(es),Ne(j.enabled),K(!1),lt.current={mcpType:As,command:ft,url:is,envEntries:Ue,headerEntries:At,oauthEnabled:ns,oauthClientId:ns?Rt?.clientId??"":"",oauthClientSecret:ns?Rt?.clientSecret??"":"",oauthScope:ns?Rt?.scope??"":"",oauthRedirectUri:ns?Rt?.redirectUri??"":"",timeout:es,enabled:j.enabled}}},[j,C,a]);const tt=l.useMemo(()=>{const Ue=lt.current;return Ue?N!==Ue.mcpType||ce!==Ue.enabled||JSON.stringify(T)!==JSON.stringify(Ue.command)||$!==Ue.url||JSON.stringify(V)!==JSON.stringify(Ue.envEntries)||JSON.stringify(L)!==JSON.stringify(Ue.headerEntries)||B!==Ue.oauthEnabled||le!==Ue.oauthClientId||ae!==Ue.oauthClientSecret||te!==Ue.oauthScope||z!==Ue.oauthRedirectUri||H!==Ue.timeout:!1},[N,T,$,V,L,B,le,ae,te,z,H,ce]),Qe=async()=>{const Ue=C?I.trim():n??"";if(!Ue){q.error(t("settings.mcp.page.toast.nameRequired"));return}if(C&&r.some(At=>At.name===Ue)){q.error(t("settings.mcp.page.toast.serverNameExists"));return}if(N==="local"&&T.filter(Boolean).length===0){q.error(t("settings.mcp.page.toast.localCommandRequired"));return}if(N==="remote"&&!$.trim()){q.error(t("settings.mcp.page.toast.remoteUrlRequired"));return}const Tt={name:Ue,scope:k,type:N,command:T,url:$,environment:V,headers:L,oauthEnabled:B,oauthClientId:le,oauthClientSecret:ae,oauthScope:te,oauthRedirectUri:z,timeout:H,enabled:ce};we(!0);try{const At=C?await d(Tt):await p(Ue,Tt);At.ok?(await co(De),ye(),C&&(i(null),o(Ue)),await y({directory:u,silent:!0}),At.reloadFailed?q.warning(At.message||t(C?"settings.mcp.page.toast.serverCreatedReloadFailed":"settings.mcp.page.toast.savedReloadFailed"),{description:At.warning||t("settings.mcp.page.toast.retryRefreshHint")}):q.success(At.message||t(C?"settings.mcp.page.toast.serverCreatedReloading":"settings.mcp.page.toast.savedReloading"))):q.error(t("settings.mcp.page.toast.saveFailed"))}catch(At){q.error(At instanceof Error?At.message:t("settings.mcp.page.toast.unexpectedError"))}finally{we(!1)}},ze=async()=>{if(!n)return;oe(!0);const Ue=await m(n);Ue.ok?(await co(De),ye(),Ue.reloadFailed?q.warning(Ue.message||t("settings.mcp.page.toast.serverDeletedReloadFailed",{name:n}),{description:Ue.warning||t("settings.mcp.page.toast.refreshListIfStale")}):q.success(Ue.message||t("settings.mcp.page.toast.serverDeleted",{name:n})),ue(!1)):q.error(t("settings.mcp.page.toast.deleteFailed")),oe(!1)},ht=async()=>{if(n){Ie(!0);try{if(b[n]?.status==="connected")await g(n,u),q.success(t("settings.mcp.page.toast.disconnected"));else{await x(n,u),await y({directory:u,silent:!0});const Tt=Pn.getState().getStatusForDirectory(u??null)[n];Tt?.status==="connected"?q.success(t("settings.mcp.page.toast.connected")):Tt?.status==="needs_auth"?q.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):Tt?.status==="needs_client_registration"?q.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):Tt?.status==="failed"?q.error(Tt.error||t("settings.mcp.page.toast.connectionFailed")):q.message(t("settings.mcp.page.toast.connectionAttemptFinished"));return}await y({directory:u,silent:!0})}catch(Ue){q.error(Ue instanceof Error?Ue.message:t("settings.mcp.page.toast.connectionFailed"))}finally{Ie(!1)}}},_t=l.useCallback(()=>C?(q.error(t("settings.mcp.page.toast.createServerBeforeLiveActions")),!1):tt?(q.error(t("settings.mcp.page.toast.saveBeforeLiveActions")),!1):!0,[tt,C,t]),Kt=l.useCallback(async(Ue=!1)=>{try{await y({directory:u,silent:Ue})}catch(Tt){Ue||q.error(Tt instanceof Error?Tt.message:t("settings.mcp.page.toast.refreshStatusFailed"))}},[u,y,t]);l.useEffect(()=>{Kt(!0)},[Kt]),l.useEffect(()=>{ct.current=et,Ie(!1),he(!1),ye()},[ye,et]);const Ut=l.useCallback(async()=>{if(!n||N!=="remote"||!_t())return;Y(!0);const Ue=et;let Tt=null;try{const At=Pn.getState().getStatusForDirectory(u??null)[n]?.status;se.current=At==="needs_auth"||At==="needs_client_registration";const vt=df(n,u);if(!vt)throw new Error(t("settings.mcp.page.toast.oauthRedirectUrlBuildFailed"));if(!z.trim()&&!h){const ft=await p(n,{oauthEnabled:B,oauthClientId:le,oauthClientSecret:ae,oauthScope:te,oauthRedirectUri:vt});if(!ft.ok)throw new Error(t("settings.mcp.page.toast.oauthBrowserCallbackSaveFailed"));if(ft.reloadFailed)throw new Error(ft.warning||ft.message||t("settings.mcp.page.toast.openCodeReloadFailedAfterCallbackSave"));if(ct.current!==Ue)return;J(vt),lt.current=lt.current?{...lt.current,oauthRedirectUri:vt}:lt.current}const Rt=await w(n,u),ns=Ju(new URL(Rt).searchParams);if(ns&&(Tt=ns,await rC({state:ns,name:n,directory:u})),ct.current!==Ue)return;be(Rt),Ae(ns??null),Re(!0),Le.current=0;const As=await lr(Rt);if(ct.current!==Ue)return;As?q.message(t(h?"settings.mcp.page.toast.completeAuthorizationInBrowserWithPaste":"settings.mcp.page.toast.completeAuthorizationInBrowser")):q.error(t("settings.mcp.page.toast.openAuthorizationUrlFailed"))}catch(At){await co(Tt),ct.current===Ue&&q.error(md(At,t("settings.mcp.page.toast.authorizationStartFailed"),e))}finally{ct.current===Ue&&Y(!1)}},[u,h,N,le,ae,B,z,te,_t,et,n,w,t,e,p]),jt=l.useCallback(async()=>{if(!n||!_t())return;ke(!0);const Ue=et;try{if(await S(n,u),ct.current!==Ue)return;be(null),Ae(null),U(""),Re(!1),Le.current=0,await co(De),q.success(t("settings.mcp.page.toast.savedAuthorizationRemoved"))}catch(Tt){ct.current===Ue&&q.error(md(Tt,t("settings.mcp.page.toast.clearAuthorizationFailed"),e))}finally{ct.current===Ue&&ke(!1)}},[De,S,u,_t,et,n,t,e]),Dt=l.useCallback(async()=>{if(!G)return;if((await _n(G)).ok){q.success(t("settings.mcp.page.toast.authorizationUrlCopied"));return}q.error(t("settings.mcp.page.toast.authorizationUrlCopyFailed"))},[G,t]),ts=l.useCallback(async()=>{const Ue=X5(ve);if(!Ue.code){q.error(t("settings.mcp.page.toast.pasteCallbackOrCodeFirst"));return}const Tt=Ue.stateKey?await aC(Ue.stateKey):null,At=Ue.context??Tt,vt=At?.name??n,Rt=At?.directory??u;if(!vt){q.error(t("settings.mcp.page.toast.missingServerDetails"));return}if(!At&&!_t())return;Be(!0);const ns=et;try{if(await v(vt,Ue.code,Rt),await co(Ue.stateKey??De),ct.current!==ns)return;U(""),be(null),Ae(null),Re(!1),Le.current=0,q.success(vt===n?t("settings.mcp.page.toast.authorizationCompleted"):t("settings.mcp.page.toast.authorizationCompletedFor",{name:vt}))}catch(As){ct.current===ns&&q.error(md(As,t("settings.mcp.page.toast.authorizationCompleteFailed"),e))}finally{ct.current===ns&&Be(!1)}},[ve,De,v,u,_t,et,n,t,e]),it=l.useCallback(async()=>{if(!(!n||!_t())){if(!ce){q.error(t("settings.mcp.page.toast.enableServerBeforeTest"));return}he(!0);try{const Ue=await A(n,u),Tt=Ue.status?.status;Ue.warning?q.warning(Ue.warning):Tt==="connected"?q.success(t("settings.mcp.page.toast.connectionTestSucceeded")):Tt==="needs_auth"?q.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):Tt==="needs_client_registration"?q.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):Tt==="failed"?q.error(Ue.status?.error||Ue.error||t("settings.mcp.page.toast.connectionTestFailed")):Ue.error?q.error(Ue.error):q.message(t("settings.mcp.page.toast.connectionTestFinished"))}catch(Ue){q.error(Ue instanceof Error?Ue.message:t("settings.mcp.page.toast.connectionTestFailed"))}finally{he(!1)}}},[u,ce,_t,n,t,A]);if(l.useEffect(()=>{if(!de||!n)return;const Ue=window.setInterval(()=>{(async()=>{Le.current+=1,await y({directory:u,silent:!0});const Tt=Pn.getState().getStatusForDirectory(u??null)[n];if(Tt){if(se.current&&Tt.status!=="needs_auth"&&Tt.status!=="needs_client_registration"){Re(!1),Le.current=0,se.current=!1,be(null),U(""),Tt.status==="connected"&&q.success(t("settings.mcp.page.toast.authorizationCompleted"));return}if(!se.current&&Tt.status==="failed"){Re(!1),Le.current=0,se.current=!1,q.error(Tt.error||t("settings.mcp.page.toast.authorizationFailed"));return}Le.current>=30&&(Re(!1),Le.current=0,se.current=!1,q.message(t("settings.mcp.page.toast.authorizationStillInProgress")))}})()},2e3);return()=>{window.clearInterval(Ue)}},[u,de,y,n,t]),!n)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(Gh,{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 Yt=b[n],Qt=n?f[n]:void 0,Xt=Yt??Qt,us=Yt?.status==="connected",ms=Yt?.status==="needs_auth"||Yt?.status==="needs_client_registration",gs=h?null:df(n,u),ds=tC(Xt?.status,e,Xt&&"error"in Xt?Xt.error:void 0),Ft=Ue=>{switch(Ue){case"connected":return t("settings.mcp.page.status.label.connected");case"failed":return t("settings.mcp.page.status.label.failed");case"needs_auth":return t("settings.mcp.page.status.label.needsAuth");case"needs_client_registration":return t("settings.mcp.page.status.label.needsRegistration");default:return Ue}};return s.jsxs(Es,{outerClassName:"h-full",className:"w-full",children:[s.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[s.jsx("div",{className:"mb-4",children:s.jsxs("div",{className:"min-w-0",children:[C?s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:t("settings.mcp.page.header.newServer")}):s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:n}),s.jsx(cf,{status:Xt?.status,enabled:ce,getStatusLabel:Ft,variant:"pill"})]}),s.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:C?t("settings.mcp.page.header.configureNewServer"):t("settings.mcp.page.header.transport",{type:t(N==="local"?"settings.mcp.page.transport.local":"settings.mcp.page.transport.remote")})}),!C&&s.jsxs(s.Fragment,{children:[s.jsx(je,{variant:us?"outline":"default",size:"xs",className:"!font-normal",onClick:ht,disabled:Z||!ce,children:t(Z?"settings.mcp.page.actions.working":us?"settings.mcp.page.actions.disconnect":"settings.mcp.page.actions.connect")}),N==="remote"&&s.jsxs(s.Fragment,{children:[s.jsx(je,{variant:ms?"default":"outline",size:"xs",className:"!font-normal",onClick:()=>{Ut()},disabled:Se||!ce,children:t(Se?"settings.mcp.page.actions.starting":ms?"settings.mcp.page.actions.authorize":"settings.mcp.page.actions.reauthorize")}),s.jsx(je,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{jt()},disabled:fe||!ce,children:t(fe?"settings.mcp.page.actions.clearing":"settings.mcp.page.actions.clearAuth")})]}),us&&s.jsx(je,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{it()},disabled:xe||!ce,children:t(xe?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.test")})]})]})]})}),!C&&nC(Xt?.status,G,ms,de)&&s.jsx("div",{className:"mb-6 px-2",children:s.jsxs("div",{className:pe("rounded-lg border p-3",sC(Xt?.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(cf,{status:Xt?.status,enabled:ce,getStatusLabel:Ft})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:ds}),s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:k==="project"?t("settings.mcp.page.status.projectScopedTo",{directory:u??t("settings.mcp.page.status.activeProject")}):t("settings.mcp.page.status.userScoped")})]}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:!us&&s.jsx(je,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{it()},disabled:xe||!ce,children:t(xe?"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(je,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{lr(G)},children:[s.jsx(Ir,{className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.openInBrowser")]}),s.jsxs(je,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Dt()},children:[s.jsx(ni,{className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.copyLink")]})]})]})}),N==="remote"&&(ms||de||G)&&s.jsx("div",{className:"rounded-md border border-[var(--interactive-border)] bg-[var(--surface-background)] px-3 py-3",children:s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:t("settings.mcp.page.auth.manualFallbackTitle")}),s.jsx("p",{className:"mt-1 typography-micro text-muted-foreground",children:t("settings.mcp.page.auth.manualFallbackDescription")})]}),s.jsx(Sn,{value:ve,onChange:Ue=>U(Ue.target.value),placeholder:t("settings.mcp.page.auth.callbackInputPlaceholder"),rows:3,className:"font-mono typography-meta resize-y","data-bwignore":"true","data-1p-ignore":"true",spellCheck:!1}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:s.jsx(je,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ts()},disabled:Pe,children:t(Pe?"settings.mcp.page.actions.completing":"settings.mcp.page.actions.completeAuthorization")})})]})})]}),de&&s.jsx("p",{className:"mt-4 typography-micro text-muted-foreground",children:t("settings.mcp.page.auth.waitingForOpenCode")})]})}),s.jsxs("div",{className:"mb-6",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.mcp.page.server.title")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[C&&s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.mcp.page.server.name")})}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:[s.jsx(Vt,{value:I,onChange:Ue=>R(Ue.target.value.toLowerCase().replace(/[^a-z0-9_-]/g,"-")),placeholder:t("settings.mcp.page.server.namePlaceholder"),className:"h-7 w-48 font-mono px-2",autoFocus:!0}),s.jsxs(ps,{value:k,onValueChange:Ue=>P(Ue),children:[s.jsx(fs,{className:"!h-7 !w-7 !min-w-0 !px-0 !py-0 justify-center [&>svg:last-child]:hidden",title:t(k==="user"?"settings.common.scope.global":"settings.common.scope.project"),children:k==="user"?s.jsx(qr,{className:"h-3.5 w-3.5"}):s.jsx(zn,{className:"h-3.5 w-3.5"})}),s.jsxs(hs,{align:"end",children:[s.jsx(Ot,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(qr,{className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(Ot,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(zn,{className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]})]}),C&&s.jsx("div",{className:"py-1.5",children:s.jsxs(je,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:Ge,type:"button",title:t("settings.mcp.page.server.importJsonTitle"),children:[s.jsx(Ny,{className:"h-3.5 w-3.5"}),t("settings.mcp.page.server.importJson")]})}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":ce,onClick:()=>Ne(!ce),onKeyDown:Ue=>{(Ue.key===" "||Ue.key==="Enter")&&(Ue.preventDefault(),Ne(!ce))},children:[s.jsx(bs,{checked:ce,onChange:Ne,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(je,{variant:"chip",size:"xs","aria-pressed":N==="local",onClick:()=>D("local"),className:"!font-normal",children:t("settings.mcp.page.transport.local")}),s.jsx(je,{variant:"chip",size:"xs","aria-pressed":N==="remote",onClick:()=>D("remote"),className:"!font-normal",children:t("settings.mcp.page.transport.remote")})]})]})})]})]}),s.jsxs("div",{className:"mb-6",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t(N==="local"?"settings.mcp.page.connection.command":"settings.mcp.page.connection.serverUrl")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:N==="local"?s.jsx(Z5,{value:T,onChange:M,pasteCommandTitle:t("settings.mcp.page.connection.pasteCommandTitle"),pasteCommandLabel:t("settings.mcp.page.connection.pasteCommand"),pasteSuccess:Ue=>t("settings.mcp.page.toast.pastedArgumentsCount",{count:Ue}),clipboardReadFailed:t("settings.mcp.page.toast.clipboardReadFailed"),preview:Ue=>t("settings.mcp.page.connection.previewArgs",{count:Ue})}):s.jsx(Vt,{value:$,onChange:Ue=>F(Ue.target.value),placeholder:t("settings.mcp.page.connection.serverUrlPlaceholder"),className:"font-mono typography-meta"})})]}),N==="remote"&&s.jsxs("div",{className:"mb-6",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.mcp.page.advanced.title")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsxs(yr,{open:ie,onOpenChange:K,children:[s.jsxs(Mr,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:t("settings.mcp.page.advanced.configure")}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",t(B?"settings.mcp.page.advanced.autoDetect":"settings.mcp.page.advanced.custom")," · ",L.length," ",t("settings.mcp.page.advanced.headers"),H?` · ${H}ms`:"",")"]})]}),ie?s.jsx(Cs,{className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(Fn,{className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(vr,{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(Vt,{type:"number",min:"1",step:"1",value:H,onChange:Ue=>re(Ue.target.value),placeholder:"5000",className:"h-7 w-32 font-mono px-2","data-bwignore":"true","data-1p-ignore":"true"})})]}),s.jsx("p",{className:"typography-micro text-muted-foreground sm:pl-64",children:t("settings.mcp.page.advanced.timeoutHint")})]}),s.jsxs("div",{children:[s.jsxs("div",{className:"mb-2 typography-ui-label text-foreground",children:[t("settings.mcp.page.advanced.requestHeaders"),L.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",L.length,")"]})]}),s.jsx(lf,{value:L,onChange:W,keyTransform:Ue=>Ue.trimStart(),keyPlaceholder:t("settings.mcp.page.advanced.headerNamePlaceholder"),keyInputClassName:"w-36 shrink-0 font-mono typography-meta",pasteLabel:t("settings.mcp.page.advanced.pasteHeaders"),pasteTitle:t("settings.mcp.page.advanced.pasteHeadersTitle"),noPairsFoundError:t("settings.mcp.page.toast.noKeyValuePairsFound"),importSuccess:Ue=>t("settings.mcp.page.toast.importedVariablesCount",{count:Ue}),clipboardReadFailed:t("settings.mcp.page.toast.clipboardReadFailed"),keyLabel:t("settings.mcp.page.env.key"),valueLabel:t("settings.mcp.page.env.value"),valuePlaceholder:t("settings.mcp.page.env.valuePlaceholder"),hideValueTitle:t("settings.mcp.page.env.hide"),showValueTitle:t("settings.mcp.page.env.show"),addVariable:t("settings.mcp.page.env.addVariable"),plainTextWarning:t("settings.mcp.page.env.plainTextWarning"),removeVariableAria:t("settings.mcp.page.env.removeVariableAria")})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":B,onClick:()=>ne(!B),onKeyDown:Ue=>{(Ue.key===" "||Ue.key==="Enter")&&(Ue.preventDefault(),ne(!B))},children:[s.jsx(bs,{checked:B,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(Vt,{value:le,onChange:Ue=>ee(Ue.target.value),placeholder:t("settings.mcp.page.advanced.oauthClientIdPlaceholder"),className:"font-mono typography-meta",disabled:!B,"data-bwignore":"true","data-1p-ignore":"true"}),s.jsx(Vt,{value:ae,onChange:Ue=>ge(Ue.target.value),placeholder:t("settings.mcp.page.advanced.oauthClientSecretPlaceholder"),className:"font-mono typography-meta",disabled:!B,"data-bwignore":"true","data-1p-ignore":"true"}),s.jsx(Vt,{value:te,onChange:Ue=>E(Ue.target.value),placeholder:t("settings.mcp.page.advanced.oauthScopesPlaceholder"),className:"font-mono typography-meta",disabled:!B,"data-bwignore":"true","data-1p-ignore":"true"}),s.jsx(Vt,{value:z,onChange:Ue=>J(Ue.target.value),placeholder:t("settings.mcp.page.advanced.oauthRedirectUriPlaceholder"),className:"font-mono typography-meta",disabled:!B,"data-bwignore":"true","data-1p-ignore":"true"})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("settings.mcp.page.advanced.oauthHint")}),gs&&s.jsxs("p",{className:"typography-micro text-muted-foreground",children:[t("settings.mcp.page.advanced.oauthCallbackHint"),s.jsx("span",{className:"mt-1 block break-all font-mono text-foreground/80",children:gs})]})]})]})})]})})]}),s.jsxs("div",{className:"mb-2",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("h3",{className:"typography-ui-header font-medium text-foreground",children:[t("settings.mcp.page.env.title"),V.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",V.length,")"]})]})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:V.length===0?s.jsxs(je,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:()=>O([{key:"",value:""}]),children:[s.jsx(_s,{className:"h-3.5 w-3.5"}),t("settings.mcp.page.env.addEnvironmentVariable")]}):s.jsx(lf,{value:V,onChange:O,keyPlaceholder:t("settings.mcp.page.env.keyPlaceholder"),pasteLabel:t("settings.mcp.page.env.pasteEnv"),pasteTitle:t("settings.mcp.page.env.pasteEnvTitle"),noPairsFoundError:t("settings.mcp.page.toast.noKeyValuePairsFound"),importSuccess:Ue=>t("settings.mcp.page.toast.importedVariablesCount",{count:Ue}),clipboardReadFailed:t("settings.mcp.page.toast.clipboardReadFailed"),keyLabel:t("settings.mcp.page.env.key"),valueLabel:t("settings.mcp.page.env.value"),valuePlaceholder:t("settings.mcp.page.env.valuePlaceholder"),hideValueTitle:t("settings.mcp.page.env.hide"),showValueTitle:t("settings.mcp.page.env.show"),addVariable:t("settings.mcp.page.env.addVariable"),plainTextWarning:t("settings.mcp.page.env.plainTextWarning"),removeVariableAria:t("settings.mcp.page.env.removeVariableAria")})})]}),s.jsxs("div",{className:"flex items-center gap-2 px-2 py-1",children:[s.jsx(je,{onClick:Qe,disabled:me||!tt&&!C,size:"xs",className:"!font-normal",children:t(me?"settings.common.actions.saving":C?"settings.common.actions.create":"settings.common.actions.saveChanges")}),!C&&s.jsx(je,{variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>ue(!0),children:t("settings.common.actions.delete")})]})]}),s.jsx(ws,{open:_e,onOpenChange:Ue=>{Ue||(He(!1),Ze(""),mt(null))},children:s.jsxs(vs,{className:"max-w-md",children:[s.jsxs(Is,{children:[s.jsx(Ss,{children:t("settings.mcp.page.importDialog.title")}),s.jsx(Os,{children:t("settings.mcp.page.importDialog.description")})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsx(Sn,{value:Ke,onChange:Ue=>{Ze(Ue.target.value),mt(null)},placeholder:`{
78
- "mcpServers": {
79
- "postgres": {
80
- "command": "npx",
81
- "args": ["-y", "@modelcontextprotocol/server-postgres"]
82
- }
83
- }
84
- }`,rows:8,className:"font-mono typography-meta resize-y",spellCheck:!1,"data-bwignore":"true","data-1p-ignore":"true"}),Xe&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:Xe}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:s.jsxs(je,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:$e,type:"button",children:[s.jsx(ni,{className:"h-3.5 w-3.5"}),t("settings.mcp.page.importDialog.pasteFromClipboard")]})})]}),s.jsxs(Qs,{children:[s.jsx(je,{variant:"outline",onClick:()=>{He(!1),Ze(""),mt(null)},className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(je,{onClick:Ve,disabled:!Ke.trim(),size:"sm",children:t("settings.common.actions.import")})]})]})}),s.jsx(ws,{open:_,onOpenChange:Ue=>{!Ue&&!Q&&ue(!1)},children:s.jsxs(vs,{className:"max-w-md",children:[s.jsxs(Is,{children:[s.jsx(Ss,{children:t("settings.mcp.page.deleteDialog.title",{name:n??""})}),s.jsxs(Os,{children:[t("settings.mcp.page.deleteDialog.descriptionPrefix")," ",s.jsx("code",{className:"text-foreground",children:"opencode.json"}),"."," ",t("settings.mcp.page.deleteDialog.descriptionSuffix")]})]}),s.jsxs(Qs,{children:[s.jsx(je,{variant:"outline",onClick:()=>ue(!1),disabled:Q,className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(je,{variant:"destructive",size:"sm",onClick:ze,disabled:Q,children:t(Q?"settings.mcp.page.actions.deleting":"settings.common.actions.delete")})]})]})})]})},lC=t=>{const e=nt.c(150),{onItemSelect:n}=t,{t:r}=ut(),[a,i]=l.useState(null),[o,c]=l.useState(""),[d,p]=l.useState(null),[m,u]=l.useState(!1),[h,b]=l.useState(null),{selectedSkillName:f,skills:y,setSelectedSkill:x,setSkillDraft:g,createSkill:w,deleteSkill:v,getSkillDetail:S}=ya(jr(cC));let A;e[0]!==n||e[1]!==x||e[2]!==g||e[3]!==y?(A=()=>{let $e="new-skill",Ve=1;for(;y.some(tt=>tt.name===$e);)$e=`new-skill-${Ve}`,Ve++;g({name:$e,scope:"user",source:"opencode",description:""}),x($e),n?.()},e[0]=n,e[1]=x,e[2]=g,e[3]=y,e[4]=A):A=e[4];const j=A;let C;e[5]===Symbol.for("react.memo_cache_sentinel")?(C=async $e=>{p($e)},e[5]=C):C=e[5];const I=C;let R;e[6]!==d||e[7]!==v||e[8]!==r?(R=async()=>{if(!d)return;u(!0),await v(d.name)?(q.success(r("settings.skills.sidebar.toast.skillDeleted",{name:d.name})),p(null)):q.error(r("settings.skills.sidebar.toast.deleteSkillFailed")),u(!1)},e[6]=d,e[7]=v,e[8]=r,e[9]=R):R=e[9];const k=R;let P;e[10]!==S||e[11]!==x||e[12]!==g||e[13]!==y||e[14]!==r?(P=async $e=>{const Ve=$e.name;let tt=1,Qe=`${Ve}-copy`;for(;y.some(ht=>ht.name===Qe);)tt++,Qe=`${Ve}-copy-${tt}`;const ze=await S($e.name);if(!ze){q.error(r("settings.skills.sidebar.toast.duplicateLoadFailed"));return}g({name:Qe,scope:$e.scope||"user",source:$e.source||"opencode",description:(ze.sources.md.fields.includes("description"),""),instructions:""}),x(Qe)},e[10]=S,e[11]=x,e[12]=g,e[13]=y,e[14]=r,e[15]=P):P=e[15];const N=P;let D;e[16]===Symbol.for("react.memo_cache_sentinel")?(D=$e=>{c($e.name),i($e)},e[16]=D):D=e[16];const T=D;let M;e[17]!==w||e[18]!==v||e[19]!==S||e[20]!==a||e[21]!==o||e[22]!==x||e[23]!==y||e[24]!==r?(M=async()=>{if(!a)return;const $e=o.trim().replace(/\s+/g,"-").toLowerCase();if(!$e){q.error(r("settings.skills.page.toast.skillNameRequired"));return}if($e===a.name){i(null);return}if(y.some(Qe=>Qe.name===$e)){q.error(r("settings.skills.page.toast.skillExists"));return}if(!await S(a.name)){q.error(r("settings.skills.sidebar.toast.renameLoadFailed")),i(null);return}await w({name:$e,description:"Renamed skill",scope:a.scope,source:a.source})?await v(a.name)?(q.success(`Skill renamed to "${$e}"`),x($e)):q.error(r("settings.skills.sidebar.toast.removeOldAfterRenameFailed")):q.error(r("settings.skills.sidebar.toast.renameFailed")),i(null)},e[17]=w,e[18]=v,e[19]=S,e[20]=a,e[21]=o,e[22]=x,e[23]=y,e[24]=r,e[25]=M):M=e[25];const $=M;let F;e[26]!==y?(F=y.filter(dC),e[26]=y,e[27]=F):F=e[27];const V=F;let O;e[28]!==y?(O=y.filter(uC),e[28]=y,e[29]=O):O=e[29];const L=O;let W;e[30]===Symbol.for("react.memo_cache_sentinel")?(W=function(Ve){const tt={},Qe=[];for(const ht of Ve)ht.group?(tt[ht.group]||(tt[ht.group]=[]),tt[ht.group].push(ht)):Qe.push(ht);const ze=Object.keys(tt).sort(mC).map(ht=>({name:ht,skills:[...tt[ht]].sort(pC)}));return Qe.sort(fC),{sortedGroups:ze,ungrouped:Qe}},e[30]=W):W=e[30];const B=W;let ne;e[31]!==V?(ne=B(V),e[31]=V,e[32]=ne):ne=e[32];const le=ne;let ee;e[33]!==L?(ee=B(L),e[33]=L,e[34]=ee):ee=e[34];const ae=ee;let ge;e[35]===Symbol.for("react.memo_cache_sentinel")?(ge=pe("flex h-full flex-col","bg-background"),e[35]=ge):ge=e[35];let te;e[36]!==r?(te=r("settings.skills.sidebar.title"),e[36]=r,e[37]=te):te=e[37];let E;e[38]!==te?(E=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:te}),e[38]=te,e[39]=E):E=e[39];let z;e[40]===Symbol.for("react.memo_cache_sentinel")?(z=s.jsx(Go,{className:"mb-3"}),e[40]=z):z=e[40];let J;e[41]!==y.length||e[42]!==r?(J=r("settings.skills.sidebar.total",{count:y.length}),e[41]=y.length,e[42]=r,e[43]=J):J=e[43];let H;e[44]!==J?(H=s.jsx("span",{className:"typography-meta text-muted-foreground",children:J}),e[44]=J,e[45]=H):H=e[45];let re;e[46]===Symbol.for("react.memo_cache_sentinel")?(re=s.jsx(_s,{className:"h-3.5 w-3.5"}),e[46]=re):re=e[46];let ce;e[47]!==j?(ce=s.jsx(je,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:j,children:re}),e[47]=j,e[48]=ce):ce=e[48];let Ne;e[49]!==H||e[50]!==ce?(Ne=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[H,ce]}),e[49]=H,e[50]=ce,e[51]=Ne):Ne=e[51];let me;e[52]!==E||e[53]!==Ne?(me=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[E,z,Ne]}),e[52]=E,e[53]=Ne,e[54]=me):me=e[54];let we;e[55]!==le||e[56]!==ae||e[57]!==N||e[58]!==n||e[59]!==h||e[60]!==V||e[61]!==f||e[62]!==x||e[63]!==y.length||e[64]!==r||e[65]!==L?(we=s.jsx(Es,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:y.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(Tu,{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:[V.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:r("settings.skills.sidebar.section.project")}),le.sortedGroups.map($e=>{const{name:Ve,skills:tt}=$e;return s.jsx(ru,{label:Ve,count:tt.length,storageKey:"project-skills",children:tt.map(Qe=>s.jsx(fl,{skill:Qe,isSelected:f===Qe.name,onSelect:()=>{x(Qe.name),n?.()},onRename:()=>T(Qe),onDelete:()=>I(Qe),onDuplicate:()=>N(Qe),isMenuOpen:h===Qe.name,onMenuOpenChange:ze=>b(ze?Qe.name:null)},Qe.name))},Ve)}),le.ungrouped.map($e=>s.jsx(fl,{skill:$e,isSelected:f===$e.name,onSelect:()=>{x($e.name),n?.()},onRename:()=>T($e),onDelete:()=>I($e),onDuplicate:()=>N($e),isMenuOpen:h===$e.name,onMenuOpenChange:Ve=>b(Ve?$e.name:null)},$e.name))]}),L.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:r("settings.skills.sidebar.section.user")}),ae.sortedGroups.map($e=>{const{name:Ve,skills:tt}=$e;return s.jsx(ru,{label:Ve,count:tt.length,storageKey:"user-skills",children:tt.map(Qe=>s.jsx(fl,{skill:Qe,isSelected:f===Qe.name,onSelect:()=>{x(Qe.name),n?.()},onRename:()=>T(Qe),onDelete:()=>I(Qe),onDuplicate:()=>N(Qe),isMenuOpen:h===Qe.name,onMenuOpenChange:ze=>b(ze?Qe.name:null)},Qe.name))},Ve)}),ae.ungrouped.map($e=>s.jsx(fl,{skill:$e,isSelected:f===$e.name,onSelect:()=>{x($e.name),n?.()},onRename:()=>T($e),onDelete:()=>I($e),onDuplicate:()=>N($e),isMenuOpen:h===$e.name,onMenuOpenChange:Ve=>b(Ve?$e.name:null)},$e.name))]})]})}),e[55]=le,e[56]=ae,e[57]=N,e[58]=n,e[59]=h,e[60]=V,e[61]=f,e[62]=x,e[63]=y.length,e[64]=r,e[65]=L,e[66]=we):we=e[66];const _=d!==null;let ue;e[67]!==m?(ue=$e=>{!$e&&!m&&p(null)},e[67]=m,e[68]=ue):ue=e[68];let Q;e[69]!==r?(Q=r("settings.skills.sidebar.deleteDialog.title"),e[69]=r,e[70]=Q):Q=e[70];let oe;e[71]!==Q?(oe=s.jsx(Ss,{children:Q}),e[71]=Q,e[72]=oe):oe=e[72];const Z=d?.name??"";let Ie;e[73]!==r||e[74]!==Z?(Ie=r("settings.skills.sidebar.deleteDialog.description",{name:Z}),e[73]=r,e[74]=Z,e[75]=Ie):Ie=e[75];let Se;e[76]!==Ie?(Se=s.jsx(Os,{children:Ie}),e[76]=Ie,e[77]=Se):Se=e[77];let Y;e[78]!==oe||e[79]!==Se?(Y=s.jsxs(Is,{children:[oe,Se]}),e[78]=oe,e[79]=Se,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 xe;e[84]!==m||e[85]!==ke?(xe=s.jsx(je,{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]=xe):xe=e[86];let he;e[87]!==r?(he=r("settings.common.actions.delete"),e[87]=r,e[88]=he):he=e[88];let Pe;e[89]!==k||e[90]!==m||e[91]!==he?(Pe=s.jsx(je,{size:"sm",onClick:k,disabled:m,children:he}),e[89]=k,e[90]=m,e[91]=he,e[92]=Pe):Pe=e[92];let Be;e[93]!==xe||e[94]!==Pe?(Be=s.jsxs(Qs,{children:[xe,Pe]}),e[93]=xe,e[94]=Pe,e[95]=Be):Be=e[95];let G;e[96]!==Y||e[97]!==Be?(G=s.jsxs(vs,{className:"max-w-md",children:[Y,Be]}),e[96]=Y,e[97]=Be,e[98]=G):G=e[98];let be;e[99]!==_||e[100]!==ue||e[101]!==G?(be=s.jsx(ws,{open:_,onOpenChange:ue,children:G}),e[99]=_,e[100]=ue,e[101]=G,e[102]=be):be=e[102];const De=a!==null;let Ae;e[103]===Symbol.for("react.memo_cache_sentinel")?(Ae=$e=>!$e&&i(null),e[103]=Ae):Ae=e[103];let ve;e[104]!==r?(ve=r("settings.skills.sidebar.renameDialog.title"),e[104]=r,e[105]=ve):ve=e[105];let U;e[106]!==ve?(U=s.jsx(Ss,{children:ve}),e[106]=ve,e[107]=U):U=e[107];const de=a?.name??"";let Re;e[108]!==r||e[109]!==de?(Re=r("settings.skills.sidebar.renameDialog.description",{name:de}),e[108]=r,e[109]=de,e[110]=Re):Re=e[110];let Le;e[111]!==Re?(Le=s.jsx(Os,{children:Re}),e[111]=Re,e[112]=Le):Le=e[112];let se;e[113]!==U||e[114]!==Le?(se=s.jsxs(Is,{children:[U,Le]}),e[113]=U,e[114]=Le,e[115]=se):se=e[115];let ie;e[116]===Symbol.for("react.memo_cache_sentinel")?(ie=$e=>c($e.target.value),e[116]=ie):ie=e[116];let K;e[117]!==r?(K=r("settings.skills.sidebar.renameDialog.placeholder"),e[117]=r,e[118]=K):K=e[118];let _e;e[119]!==$?(_e=$e=>{$e.key==="Enter"&&$()},e[119]=$,e[120]=_e):_e=e[120];let He;e[121]!==o||e[122]!==K||e[123]!==_e?(He=s.jsx(Vt,{value:o,onChange:ie,placeholder:K,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:_e}),e[121]=o,e[122]=K,e[123]=_e,e[124]=He):He=e[124];let Ke;e[125]===Symbol.for("react.memo_cache_sentinel")?(Ke=()=>i(null),e[125]=Ke):Ke=e[125];let Ze;e[126]!==r?(Ze=r("settings.common.actions.cancel"),e[126]=r,e[127]=Ze):Ze=e[127];let Xe;e[128]!==Ze?(Xe=s.jsx(je,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:Ke,children:Ze}),e[128]=Ze,e[129]=Xe):Xe=e[129];let mt;e[130]!==r?(mt=r("settings.common.actions.rename"),e[130]=r,e[131]=mt):mt=e[131];let et;e[132]!==$||e[133]!==mt?(et=s.jsx(je,{size:"sm",onClick:$,children:mt}),e[132]=$,e[133]=mt,e[134]=et):et=e[134];let ct;e[135]!==Xe||e[136]!==et?(ct=s.jsxs(Qs,{children:[Xe,et]}),e[135]=Xe,e[136]=et,e[137]=ct):ct=e[137];let lt;e[138]!==se||e[139]!==He||e[140]!==ct?(lt=s.jsxs(vs,{children:[se,He,ct]}),e[138]=se,e[139]=He,e[140]=ct,e[141]=lt):lt=e[141];let ye;e[142]!==De||e[143]!==lt?(ye=s.jsx(ws,{open:De,onOpenChange:Ae,children:lt}),e[142]=De,e[143]=lt,e[144]=ye):ye=e[144];let Ge;return e[145]!==me||e[146]!==we||e[147]!==be||e[148]!==ye?(Ge=s.jsxs("div",{className:ge,children:[me,we,be,ye]}),e[145]=me,e[146]=we,e[147]=be,e[148]=ye,e[149]=Ge):Ge=e[149],Ge},fl=t=>{const e=nt.c(63),{skill:n,isSelected:r,onSelect:a,onDelete:i,onRename:o,onDuplicate:c,isMenuOpen:d,onMenuOpenChange:p}=t,{t:m}=ut();let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u=Do(),e[0]=u):u=e[0];const h=u,b=r?"bg-interactive-selection":"hover:bg-interactive-hover";let f;e[1]!==b?(f=pe("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 y;e[3]!==p?(y=h?void 0:ne=>{ne.preventDefault(),p(!0)},e[3]=p,e[4]=y):y=e[4];let x;e[5]!==n.name?(x=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:n.name}),e[5]=n.name,e[6]=x):x=e[6];let g;e[7]!==n.scope?(g=s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:n.scope}),e[7]=n.scope,e[8]=g):g=e[8];let w;e[9]!==n.source||e[10]!==m?(w=n.source==="claude"&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:m("settings.skills.sidebar.badge.claude")}),e[9]=n.source,e[10]=m,e[11]=w):w=e[11];let v;e[12]!==n.source||e[13]!==m?(v=n.source==="agents"&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:m("settings.skills.sidebar.badge.agents")}),e[12]=n.source,e[13]=m,e[14]=v):v=e[14];let S;e[15]!==x||e[16]!==g||e[17]!==w||e[18]!==v?(S=s.jsxs("div",{className:"flex items-center gap-1.5",children:[x,g,w,v]}),e[15]=x,e[16]=g,e[17]=w,e[18]=v,e[19]=S):S=e[19];let A;e[20]!==a||e[21]!==S?(A=s.jsx("button",{onClick:a,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:S}),e[20]=a,e[21]=S,e[22]=A):A=e[22];let j;e[23]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(Bs,{asChild:!0,children:s.jsx(je,{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(ia,{className:"h-3.5 w-3.5"})})}),e[23]=j):j=e[23];let C;e[24]!==o?(C=ne=>{ne.stopPropagation(),o()},e[24]=o,e[25]=C):C=e[25];let I;e[26]===Symbol.for("react.memo_cache_sentinel")?(I=s.jsx(Yr,{className:"h-4 w-4 mr-px"}),e[26]=I):I=e[26];let R;e[27]!==m?(R=m("settings.common.actions.rename"),e[27]=m,e[28]=R):R=e[28];let k;e[29]!==C||e[30]!==R?(k=s.jsxs($t,{onClick:C,children:[I,R]}),e[29]=C,e[30]=R,e[31]=k):k=e[31];let P;e[32]!==c?(P=ne=>{ne.stopPropagation(),c()},e[32]=c,e[33]=P):P=e[33];let N;e[34]===Symbol.for("react.memo_cache_sentinel")?(N=s.jsx(br,{className:"h-4 w-4 mr-px"}),e[34]=N):N=e[34];let D;e[35]!==m?(D=m("settings.common.actions.duplicate"),e[35]=m,e[36]=D):D=e[36];let T;e[37]!==P||e[38]!==D?(T=s.jsxs($t,{onClick:P,children:[N,D]}),e[37]=P,e[38]=D,e[39]=T):T=e[39];let M;e[40]!==i?(M=ne=>{ne.stopPropagation(),i()},e[40]=i,e[41]=M):M=e[41];let $;e[42]===Symbol.for("react.memo_cache_sentinel")?($=s.jsx(sn,{className:"h-4 w-4 mr-px"}),e[42]=$):$=e[42];let F;e[43]!==m?(F=m("settings.common.actions.delete"),e[43]=m,e[44]=F):F=e[44];let V;e[45]!==M||e[46]!==F?(V=s.jsxs($t,{onClick:M,className:"text-destructive focus:text-destructive",children:[$,F]}),e[45]=M,e[46]=F,e[47]=V):V=e[47];let O;e[48]!==k||e[49]!==T||e[50]!==V?(O=s.jsxs(Vs,{align:"end",className:"w-fit min-w-20",children:[k,T,V]}),e[48]=k,e[49]=T,e[50]=V,e[51]=O):O=e[51];let L;e[52]!==d||e[53]!==p||e[54]!==O?(L=s.jsxs(zs,{open:d,onOpenChange:p,children:[j,O]}),e[52]=d,e[53]=p,e[54]=O,e[55]=L):L=e[55];let W;e[56]!==A||e[57]!==L?(W=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[A,L]}),e[56]=A,e[57]=L,e[58]=W):W=e[58];let B;return e[59]!==W||e[60]!==f||e[61]!==y?(B=s.jsx("div",{className:f,onContextMenu:y,children:W}),e[59]=W,e[60]=f,e[61]=y,e[62]=B):B=e[62],B};function cC(t){return{selectedSkillName:t.selectedSkillName,skills:t.skills,setSelectedSkill:t.setSelectedSkill,setSkillDraft:t.setSkillDraft,createSkill:t.createSkill,deleteSkill:t.deleteSkill,getSkillDetail:t.getSkillDetail}}function dC(t){return t.scope==="project"}function uC(t){return t.scope==="user"}function mC(t,e){return t.localeCompare(e)}function pC(t,e){return t.name.localeCompare(e.name)}function fC(t,e){return t.name.localeCompare(e.name)}const hC=()=>`custom:${Date.now()}-${Math.random().toString(16).slice(2)}`,gC=t=>{const e=t.trim(),n=e.match(/^git@github\.com:([^/\s]+)\/([^\s#]+)$/i);if(n)return`${n[1]}/${n[2].replace(/\.git$/i,"")}`;const r=e.match(/^https?:\/\/github\.com\/([^/\s]+)\/([^\s#]+)$/i);if(r)return`${r[1]}/${r[2].replace(/\.git$/i,"")}`;const a=e.match(/^([^/\s]+)\/([^/\s]+)(?:\/.+)?$/);return a?`${a[1]}/${a[2].replace(/\.git$/i,"")}`:e},xC=async()=>{try{const t=xr()?.settings;if(t)return(await t.load())?.settings||{};const e=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});return e.ok?await e.json().catch(()=>null):null}catch{return null}},bC=t=>{const e=nt.c(158),{open:n,onOpenChange:r}=t,{t:a}=ut(),i=Qa(yC),o=Qa(vC),c=Qa(wC),d=ar(jC),p=ar(NC),[m,u]=l.useState(""),[h,b]=l.useState(""),[f,y]=l.useState("");let x;e[0]===Symbol.for("react.memo_cache_sentinel")?(x=[],e[0]=x):x=e[0];const[g,w]=l.useState(x),[v,S]=l.useState(null),[A,j]=l.useState(!1);let C;e[1]===Symbol.for("react.memo_cache_sentinel")?(C=[],e[1]=C):C=e[1];const[I,R]=l.useState(C),[k,P]=l.useState(null),N=l.useRef(0);let D;e[2]===Symbol.for("react.memo_cache_sentinel")?(D=ye=>{N.current=N.current+1,j(!1),S(null),ye?.clearIdentity&&(R([]),P(null))},e[2]=D):D=e[2];const T=D;let M,$;e[3]!==p||e[4]!==n?(M=()=>{n&&(N.current=N.current+1,u(""),b(""),y(""),S(null),j(!1),R([]),P(null),p(),(async()=>{const ye=await xC(),Ge=Array.isArray(ye?.skillCatalogs)?ye?.skillCatalogs:[];w(Ge||[])})())},$=[n,p],e[3]=p,e[4]=n,e[5]=M,e[6]=$):(M=e[5],$=e[6]),l.useEffect(M,$);let F;e[7]!==h?(F=h.trim(),e[7]=h,e[8]=F):F=e[8];const V=F;let O;e[9]!==f?(O=f.trim(),e[9]=f,e[10]=O):O=e[10];const L=O;let W;if(e[11]!==g||e[12]!==V||e[13]!==L){let ye;e[15]!==V||e[16]!==L?(ye=Ge=>{const $e=(Ge.source||"").trim(),Ve=(Ge.subpath||"").trim();return $e===V&&Ve===L},e[15]=V,e[16]=L,e[17]=ye):ye=e[17],W=g.some(ye),e[11]=g,e[12]=V,e[13]=L,e[14]=W}else W=e[14];const B=W;let ne;e[18]!==d||e[19]!==k||e[20]!==m||e[21]!==i||e[22]!==h||e[23]!==f||e[24]!==a?(ne=async()=>{const ye=h.trim();if(!ye){q.error(a("settings.skills.catalog.add.toast.repositoryRequired"));return}m.trim()||u(gC(ye)),j(!1),S(null);const Ge=N.current+1;N.current=Ge;const $e=await i({source:ye,subpath:f.trim()||void 0,gitIdentityId:k||void 0});if(N.current!==Ge)return;if(!$e.ok){if($e.error?.kind==="authRequired"){if(yn()){q.error(a("settings.skills.catalog.shared.toast.privateRepoNotSupportedVsCode"));return}const tt=$e.error.identities||[];if(R(tt),!k&&tt.length>0){const Qe=d&&d!=="global"&&tt.some(ze=>ze.id===d)?d:tt[0].id;P(Qe)}q.error(a("settings.skills.catalog.add.toast.authenticationRequiredScan"));return}q.error($e.error?.message||a("settings.skills.catalog.add.toast.scanFailed"));return}const Ve=$e.items?.length||0;if(S(Ve),Ve===0){q.error(a("settings.skills.catalog.add.toast.noSkillsFound")),j(!1);return}R([]),j(!0),q.success(a("settings.skills.catalog.shared.toast.foundSkills",{count:Ve}))},e[18]=d,e[19]=k,e[20]=m,e[21]=i,e[22]=h,e[23]=f,e[24]=a,e[25]=ne):ne=e[25];const le=ne;let ee;e[26]!==g||e[27]!==k||e[28]!==B||e[29]!==m||e[30]!==o||e[31]!==r||e[32]!==A||e[33]!==h||e[34]!==f||e[35]!==a?(ee=async()=>{const ye=m.trim(),Ge=h.trim(),$e=f.trim();if(!ye){q.error(a("settings.skills.catalog.add.toast.catalogNameRequired"));return}if(!Ge){q.error(a("settings.skills.catalog.add.toast.repositoryRequired"));return}if(!A){q.error(a("settings.skills.catalog.add.toast.scanBeforeAdd"));return}if(B){q.error(a("settings.skills.catalog.add.toast.catalogAlreadyExists"));return}const Ve={id:hC(),label:ye,source:Ge,...$e?{subpath:$e}:{},...k?{gitIdentityId:k}:{}},tt=[...g,Ve];try{await Rs({skillCatalogs:tt}),w(tt),q.success(a("settings.skills.catalog.add.toast.catalogAdded")),await o({refresh:!0}),r(!1)}catch(Qe){const ze=Qe;q.error(ze instanceof Error?ze.message:a("settings.skills.catalog.add.toast.saveFailed"))}},e[26]=g,e[27]=k,e[28]=B,e[29]=m,e[30]=o,e[31]=r,e[32]=A,e[33]=h,e[34]=f,e[35]=a,e[36]=ee):ee=e[36];const ae=ee;let ge;e[37]!==a?(ge=a("settings.skills.catalog.add.title"),e[37]=a,e[38]=ge):ge=e[38];let te;e[39]!==ge?(te=s.jsx(Ss,{children:ge}),e[39]=ge,e[40]=te):te=e[40];let E;e[41]!==a?(E=a("settings.skills.catalog.add.descriptionPrefix"),e[41]=a,e[42]=E):E=e[42];let z;e[43]===Symbol.for("react.memo_cache_sentinel")?(z=s.jsx("code",{className:"font-mono",children:"SKILL.md"}),e[43]=z):z=e[43];let J;e[44]!==a?(J=a("settings.skills.catalog.add.descriptionSuffix"),e[44]=a,e[45]=J):J=e[45];let H;e[46]!==E||e[47]!==J?(H=s.jsxs(Os,{children:[E," ",z,J]}),e[46]=E,e[47]=J,e[48]=H):H=e[48];let re;e[49]!==te||e[50]!==H?(re=s.jsxs(Is,{children:[te,H]}),e[49]=te,e[50]=H,e[51]=re):re=e[51];let ce;e[52]!==a?(ce=a("settings.skills.catalog.add.field.catalogName"),e[52]=a,e[53]=ce):ce=e[53];let Ne;e[54]!==ce?(Ne=s.jsx("label",{className:"typography-ui-label text-foreground",children:ce}),e[54]=ce,e[55]=Ne):Ne=e[55];let me;e[56]===Symbol.for("react.memo_cache_sentinel")?(me=ye=>u(ye.target.value),e[56]=me):me=e[56];let we;e[57]!==a?(we=a("settings.skills.catalog.add.field.catalogNamePlaceholder"),e[57]=a,e[58]=we):we=e[58];let _;e[59]!==m||e[60]!==we?(_=s.jsx(Vt,{value:m,onChange:me,placeholder:we}),e[59]=m,e[60]=we,e[61]=_):_=e[61];let ue;e[62]!==Ne||e[63]!==_?(ue=s.jsxs("div",{className:"space-y-2",children:[Ne,_]}),e[62]=Ne,e[63]=_,e[64]=ue):ue=e[64];let Q;e[65]!==a?(Q=a("settings.skills.catalog.add.field.repository"),e[65]=a,e[66]=Q):Q=e[66];let oe;e[67]!==Q?(oe=s.jsx("label",{className:"typography-ui-label text-foreground",children:Q}),e[67]=Q,e[68]=oe):oe=e[68];let Z;e[69]===Symbol.for("react.memo_cache_sentinel")?(Z=ye=>{b(ye.target.value),T({clearIdentity:!0})},e[69]=Z):Z=e[69];let Ie;e[70]!==a?(Ie=a("settings.skills.catalog.shared.field.repositoryPlaceholder"),e[70]=a,e[71]=Ie):Ie=e[71];let Se;e[72]!==h||e[73]!==Ie?(Se=s.jsx(Vt,{value:h,onChange:Z,placeholder:Ie}),e[72]=h,e[73]=Ie,e[74]=Se):Se=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]!==oe||e[80]!==Se||e[81]!==fe?(ke=s.jsxs("div",{className:"space-y-2",children:[oe,Se,fe]}),e[79]=oe,e[80]=Se,e[81]=fe,e[82]=ke):ke=e[82];let xe;e[83]!==a?(xe=a("settings.skills.catalog.add.field.optionalSubpath"),e[83]=a,e[84]=xe):xe=e[84];let he;e[85]!==xe?(he=s.jsx("label",{className:"typography-ui-label text-foreground",children:xe}),e[85]=xe,e[86]=he):he=e[86];let Pe;e[87]===Symbol.for("react.memo_cache_sentinel")?(Pe=ye=>{y(ye.target.value),T({clearIdentity:!0})},e[87]=Pe):Pe=e[87];let Be;e[88]!==a?(Be=a("settings.skills.catalog.shared.field.subpathPlaceholder"),e[88]=a,e[89]=Be):Be=e[89];let G;e[90]!==f||e[91]!==Be?(G=s.jsx(Vt,{value:f,onChange:Pe,placeholder:Be}),e[90]=f,e[91]=Be,e[92]=G):G=e[92];let be;e[93]!==he||e[94]!==G?(be=s.jsxs("div",{className:"space-y-2",children:[he,G]}),e[93]=he,e[94]=G,e[95]=be):be=e[95];let De;e[96]!==k||e[97]!==I||e[98]!==a?(De=I.length>0&&!yn()?s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{children:[s.jsx("span",{className:"typography-ui-label text-[var(--status-warning)]",children:a("settings.skills.catalog.shared.auth.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground ml-2",children:a("settings.skills.catalog.shared.auth.description")})]}),s.jsxs(ps,{value:k||"",onValueChange:ye=>{P(ye),T()},children:[s.jsx(fs,{className:"w-fit",children:s.jsx("span",{children:I.find(ye=>ye.id===k)?.name||a("settings.skills.catalog.shared.auth.chooseIdentity")})}),s.jsx(hs,{align:"start",children:I.map(SC)})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:a("settings.skills.catalog.shared.auth.footerHint")})]}):null,e[96]=k,e[97]=I,e[98]=a,e[99]=De):De=e[99];let Ae;e[100]!==v||e[101]!==a?(Ae=v!==null?s.jsx("div",{className:"typography-meta text-muted-foreground",children:a("settings.skills.catalog.add.scanResult",{count:v})}):null,e[100]=v,e[101]=a,e[102]=Ae):Ae=e[102];let ve;e[103]!==B||e[104]!==a?(ve=B?s.jsx("div",{className:"typography-meta text-muted-foreground",children:a("settings.skills.catalog.add.duplicateMessage")}):null,e[103]=B,e[104]=a,e[105]=ve):ve=e[105];let U;e[106]!==ue||e[107]!==ke||e[108]!==be||e[109]!==De||e[110]!==Ae||e[111]!==ve?(U=s.jsxs("div",{className:"space-y-4",children:[ue,ke,be,De,Ae,ve]}),e[106]=ue,e[107]=ke,e[108]=be,e[109]=De,e[110]=Ae,e[111]=ve,e[112]=U):U=e[112];let de;e[113]!==r?(de=()=>r(!1),e[113]=r,e[114]=de):de=e[114];let Re;e[115]!==a?(Re=a("settings.common.actions.cancel"),e[115]=a,e[116]=Re):Re=e[116];let Le;e[117]!==de||e[118]!==Re?(Le=s.jsx(je,{size:"sm",variant:"ghost",onClick:de,children:Re}),e[117]=de,e[118]=Re,e[119]=Le):Le=e[119];let se;e[120]!==le?(se=()=>{le()},e[120]=le,e[121]=se):se=e[121];let ie;e[122]!==c||e[123]!==h?(ie=c||!h.trim(),e[122]=c,e[123]=h,e[124]=ie):ie=e[124];let K;e[125]===Symbol.for("react.memo_cache_sentinel")?(K=s.jsx(Rd,{className:"h-4 w-4"}),e[125]=K):K=e[125];let _e;e[126]!==c||e[127]!==a?(_e=a(c?"settings.skills.catalog.shared.actions.scanning":"settings.skills.catalog.shared.actions.scan"),e[126]=c,e[127]=a,e[128]=_e):_e=e[128];let He;e[129]!==se||e[130]!==ie||e[131]!==_e?(He=s.jsxs(je,{size:"sm",className:"gap-2",variant:"ghost",onClick:se,disabled:ie,children:[K,_e]}),e[129]=se,e[130]=ie,e[131]=_e,e[132]=He):He=e[132];let Ke;e[133]!==ae?(Ke=()=>{ae()},e[133]=ae,e[134]=Ke):Ke=e[134];let Ze;e[135]!==B||e[136]!==m||e[137]!==A||e[138]!==h?(Ze=!A||B||!m.trim()||!h.trim(),e[135]=B,e[136]=m,e[137]=A,e[138]=h,e[139]=Ze):Ze=e[139];let Xe;e[140]!==a?(Xe=a("settings.skills.catalog.add.actions.addCatalog"),e[140]=a,e[141]=Xe):Xe=e[141];let mt;e[142]!==Ke||e[143]!==Ze||e[144]!==Xe?(mt=s.jsx(je,{size:"sm",onClick:Ke,disabled:Ze,children:Xe}),e[142]=Ke,e[143]=Ze,e[144]=Xe,e[145]=mt):mt=e[145];let et;e[146]!==Le||e[147]!==He||e[148]!==mt?(et=s.jsxs(Qs,{children:[Le,He,mt]}),e[146]=Le,e[147]=He,e[148]=mt,e[149]=et):et=e[149];let ct;e[150]!==re||e[151]!==U||e[152]!==et?(ct=s.jsxs(vs,{className:"max-w-xl",children:[re,U,et]}),e[150]=re,e[151]=U,e[152]=et,e[153]=ct):ct=e[153];let lt;return e[154]!==r||e[155]!==n||e[156]!==ct?(lt=s.jsx(ws,{open:n,onOpenChange:r,children:ct}),e[154]=r,e[155]=n,e[156]=ct,e[157]=lt):lt=e[157],lt};function yC(t){return t.scanRepo}function vC(t){return t.loadCatalog}function wC(t){return t.isScanning}function jC(t){return t.defaultGitIdentityId}function NC(t){return t.loadDefaultGitIdentityId}function SC(t){return s.jsx(Ot,{value:t.id,children:t.name},t.id)}const kC=t=>{const e=nt.c(85),{open:n,onOpenChange:r,conflicts:a,onConfirm:i}=t,{t:o}=ut();let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c={},e[0]=c):c=e[0];const[d,p]=l.useState(c);let m,u;e[1]!==a||e[2]!==n?(m=()=>{if(!n)return;const te={};for(const E of a)te[E.skillName]="skip";p(te)},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=te=>{const E={};for(const z of a)E[z.skillName]=te;p(E)},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(te=>d[te.skillName]),e[7]=a,e[8]=d,e[9]=f):f=e[9];const y=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(Ss,{children:x}),e[12]=x,e[13]=g):g=e[13];let w;e[14]!==o?(w=o("settings.skills.catalog.conflicts.description"),e[14]=o,e[15]=w):w=e[15];let v;e[16]!==w?(v=s.jsx(Os,{children:w}),e[16]=w,e[17]=v):v=e[17];let S;e[18]!==g||e[19]!==v?(S=s.jsxs(Is,{children:[g,v]}),e[18]=g,e[19]=v,e[20]=S):S=e[20];let A;e[21]!==a.length||e[22]!==o?(A=o("settings.skills.catalog.conflicts.count",{count:a.length}),e[21]=a.length,e[22]=o,e[23]=A):A=e[23];let j;e[24]!==A?(j=s.jsx("span",{className:"typography-meta text-muted-foreground",children:A}),e[24]=A,e[25]=j):j=e[25];let C;e[26]!==b?(C=()=>b("skip"),e[26]=b,e[27]=C):C=e[27];let I;e[28]!==o?(I=o("settings.skills.catalog.conflicts.actions.skipAll"),e[28]=o,e[29]=I):I=e[29];let R;e[30]!==C||e[31]!==I?(R=s.jsx(je,{variant:"outline",size:"xs",className:"!font-normal",onClick:C,children:I}),e[30]=C,e[31]=I,e[32]=R):R=e[32];let k;e[33]!==b?(k=()=>b("overwrite"),e[33]=b,e[34]=k):k=e[34];let P;e[35]!==o?(P=o("settings.skills.catalog.conflicts.actions.overwriteAll"),e[35]=o,e[36]=P):P=e[36];let N;e[37]!==k||e[38]!==P?(N=s.jsx(je,{variant:"outline",size:"xs",className:"!font-normal",onClick:k,children:P}),e[37]=k,e[38]=P,e[39]=N):N=e[39];let D;e[40]!==R||e[41]!==N?(D=s.jsxs("div",{className:"flex items-center gap-2",children:[R,N]}),e[40]=R,e[41]=N,e[42]=D):D=e[42];let T;e[43]!==j||e[44]!==D?(T=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[j,D]}),e[43]=j,e[44]=D,e[45]=T):T=e[45];let M;if(e[46]!==a||e[47]!==d||e[48]!==o){let te;e[50]!==d||e[51]!==o?(te=E=>s.jsxs("div",{className:"flex items-center justify-between gap-3 py-1.5",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label truncate",children:E.skillName}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:o("settings.skills.catalog.conflicts.installedIn",{scope:E.scope==="project"?o("settings.skills.catalog.conflicts.scope.project"):o("settings.skills.catalog.conflicts.scope.user"),source:E.source==="agents"?o("settings.skills.catalog.conflicts.source.agents"):o("settings.skills.catalog.conflicts.source.opencode")})})]}),s.jsxs(ps,{value:d[E.skillName]||"skip",onValueChange:z=>p(J=>({...J,[E.skillName]:z})),children:[s.jsx(fs,{className:"w-fit",children:s.jsx("span",{className:"capitalize",children:(d[E.skillName]||"skip")==="overwrite"?o("settings.skills.catalog.conflicts.decision.overwrite"):o("settings.skills.catalog.conflicts.decision.skip")})}),s.jsxs(hs,{align:"end",children:[s.jsx(Ot,{value:"skip",className:"pr-2 [&>span:first-child]:hidden",children:o("settings.skills.catalog.conflicts.decision.skip")}),s.jsx(Ot,{value:"overwrite",className:"pr-2 [&>span:first-child]:hidden",children:o("settings.skills.catalog.conflicts.decision.overwrite")})]})]})]},E.skillName),e[50]=d,e[51]=o,e[52]=te):te=e[52],M=a.map(te),e[46]=a,e[47]=d,e[48]=o,e[49]=M}else M=e[49];let $;e[53]!==M?($=s.jsx("div",{className:"space-y-2",children:M}),e[53]=M,e[54]=$):$=e[54];let F;e[55]!==T||e[56]!==$?(F=s.jsxs("div",{className:"space-y-3",children:[T,$]}),e[55]=T,e[56]=$,e[57]=F):F=e[57];let V;e[58]!==r?(V=()=>r(!1),e[58]=r,e[59]=V):V=e[59];let O;e[60]!==o?(O=o("settings.common.actions.cancel"),e[60]=o,e[61]=O):O=e[61];let L;e[62]!==V||e[63]!==O?(L=s.jsx(je,{size:"sm",variant:"ghost",onClick:V,children:O}),e[62]=V,e[63]=O,e[64]=L):L=e[64];let W;e[65]!==d||e[66]!==i?(W=()=>i(d),e[65]=d,e[66]=i,e[67]=W):W=e[67];const B=!y;let ne;e[68]!==o?(ne=o("settings.skills.catalog.conflicts.actions.continue"),e[68]=o,e[69]=ne):ne=e[69];let le;e[70]!==W||e[71]!==B||e[72]!==ne?(le=s.jsx(je,{size:"sm",onClick:W,disabled:B,children:ne}),e[70]=W,e[71]=B,e[72]=ne,e[73]=le):le=e[73];let ee;e[74]!==L||e[75]!==le?(ee=s.jsxs(Qs,{children:[L,le]}),e[74]=L,e[75]=le,e[76]=ee):ee=e[76];let ae;e[77]!==S||e[78]!==F||e[79]!==ee?(ae=s.jsxs(vs,{className:"max-w-2xl",children:[S,F,ee]}),e[77]=S,e[78]=F,e[79]=ee,e[80]=ae):ae=e[80];let ge;return e[81]!==r||e[82]!==n||e[83]!==ae?(ge=s.jsx(ws,{open:n,onOpenChange:r,children:ae}),e[81]=r,e[82]=n,e[83]=ae,e[84]=ge):ge=e[84],ge},Yu=[{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 Io(t,e){return t==="project"&&e==="agents"?"project-agents":t==="project"?"project-opencode":e==="agents"?"user-agents":"user-opencode"}function Tx(t){const e=Yu.find(n=>n.value===t);return e?{scope:e.scope,source:e.source}:{scope:"user",source:"opencode"}}const CC=t=>{const e=nt.c(124),{open:n,onOpenChange:r,item:a}=t,{t:i}=ut(),o=Qa(IC),c=Qa(AC),[d,p]=l.useState("user"),[m,u]=l.useState("opencode"),h=Fs(PC),b=Fs(DC),[f,y]=l.useState(null),[x,g]=l.useState(!1);let w;e[0]===Symbol.for("react.memo_cache_sentinel")?(w=[],e[0]=w):w=e[0];const[v,S]=l.useState(w),[A,j]=l.useState(null);let C,I;e[1]!==b||e[2]!==n?(C=()=>{n&&(p("user"),u("opencode"),y(b),g(!1),S([]),j(null))},I=[n,b],e[1]=b,e[2]=n,e[3]=C,e[4]=I):(C=e[3],I=e[4]),l.useEffect(C,I);let R;e[5]!==i?(R=Ae=>{switch(Ae){case"project-opencode":return i("settings.skills.location.option.projectOpencode.label");case"user-agents":return i("settings.skills.location.option.userAgents.label");case"project-agents":return i("settings.skills.location.option.projectAgents.label");default:return i("settings.skills.location.option.userOpencode.label")}},e[5]=i,e[6]=R):R=e[6];const k=R;let P;e[7]!==i?(P=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]=P):P=e[8];const N=P;let D;e:{if(h.length===0){D=null;break e}if(f&&h.some(Ae=>Ae.id===f)){D=f;break e}if(b&&h.some(Ae=>Ae.id===b)){D=b;break e}D=h[0]?.id??null}const T=D;let M;e:{if(d!=="project"){M=null;break e}const Ae=T;if(!Ae){M=null;break e}let ve;if(e[9]!==Ae||e[10]!==h){let de;e[12]!==Ae?(de=Re=>Re.id===Ae,e[12]=Ae,e[13]=de):de=e[13],ve=h.find(de),e[9]=Ae,e[10]=h,e[11]=ve}else ve=e[11];M=ve?.path??null}const $=M;let F;e[14]!==o||e[15]!==a||e[16]!==r||e[17]!==i?(F=async Ae=>{const ve={skillDir:Ae.skillDir};a?.clawdhub&&(ve.clawdhub={slug:a.clawdhub.slug,version:a.clawdhub.version});const U=await o({source:Ae.source,subpath:Ae.subpath,gitIdentityId:a?.gitIdentityId,scope:Ae.scope,targetSource:Ae.targetSource,selections:[ve],conflictPolicy:"prompt",conflictDecisions:Ae.conflictDecisions},{directory:Ae.directoryOverride??null});if(U.ok){q.success(i("settings.skills.catalog.installSkill.toast.installed")),r(!1);return}if(U.error?.kind==="conflicts"){j({source:Ae.source,subpath:Ae.subpath,scope:Ae.scope,targetSource:Ae.targetSource,skillDir:Ae.skillDir,directoryOverride:Ae.directoryOverride??null}),S(U.error.conflicts),g(!0);return}if(U.error?.kind==="authRequired"){q.error(U.error.message||i("settings.skills.catalog.installSkill.toast.authRequired"));return}q.error(U.error?.message||i("settings.skills.catalog.installSkill.toast.installFailed"))},e[14]=o,e[15]=a,e[16]=r,e[17]=i,e[18]=F):F=e[18];const V=F;if(!a)return null;let O;e[19]!==i?(O=i("settings.skills.catalog.installSkill.title"),e[19]=i,e[20]=O):O=e[20];let L;e[21]!==O?(L=s.jsx(Ss,{children:O}),e[21]=O,e[22]=L):L=e[22];let W;e[23]!==i?(W=i("settings.skills.catalog.installSkill.descriptionPrefix"),e[23]=i,e[24]=W):W=e[24];let B;e[25]!==a.skillName?(B=s.jsx("span",{className:"font-semibold text-foreground",children:a.skillName}),e[25]=a.skillName,e[26]=B):B=e[26];let ne;e[27]!==i?(ne=i("settings.skills.catalog.installSkill.descriptionSuffix"),e[27]=i,e[28]=ne):ne=e[28];let le;e[29]!==W||e[30]!==B||e[31]!==ne?(le=s.jsxs(Os,{children:[W," ",B," ",ne]}),e[29]=W,e[30]=B,e[31]=ne,e[32]=le):le=e[32];let ee;e[33]!==L||e[34]!==le?(ee=s.jsxs(Is,{children:[L,le]}),e[33]=L,e[34]=le,e[35]=ee):ee=e[35];let ae;e[36]!==i?(ae=i("settings.skills.catalog.installSkill.field.destination"),e[36]=i,e[37]=ae):ae=e[37];let ge;e[38]!==ae?(ge=s.jsx("span",{className:"typography-ui-label text-foreground",children:ae}),e[38]=ae,e[39]=ge):ge=e[39];let te;e[40]!==d||e[41]!==m?(te=Io(d,m),e[40]=d,e[41]=m,e[42]=te):te=e[42];let E;e[43]===Symbol.for("react.memo_cache_sentinel")?(E=Ae=>{const ve=Tx(Ae);p(ve.scope),u(ve.source==="agents"?"agents":"opencode")},e[43]=E):E=e[43];let z;e[44]!==d?(z=d==="user"?s.jsx(qr,{className:"h-3.5 w-3.5"}):s.jsx(zn,{className:"h-3.5 w-3.5"}),e[44]=d,e[45]=z):z=e[45];let J;e[46]!==m?(J=m==="agents"?s.jsx(Gr,{className:"h-3.5 w-3.5"}):null,e[46]=m,e[47]=J):J=e[47];let H;e[48]!==k||e[49]!==d||e[50]!==m?(H=k(Io(d,m)),e[48]=k,e[49]=d,e[50]=m,e[51]=H):H=e[51];let re;e[52]!==H?(re=s.jsx("span",{children:H}),e[52]=H,e[53]=re):re=e[53];let ce;e[54]!==z||e[55]!==J||e[56]!==re?(ce=s.jsxs(fs,{className:"w-fit gap-1.5",children:[z,J,re]}),e[54]=z,e[55]=J,e[56]=re,e[57]=ce):ce=e[57];let Ne;e[58]!==N||e[59]!==k?(Ne=Yu.map(Ae=>s.jsx(Ot,{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(qr,{className:"h-3.5 w-3.5"}):s.jsx(zn,{className:"h-3.5 w-3.5"}),Ae.source==="agents"?s.jsx(Gr,{className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:k(Ae.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-5",children:N(Ae.value)})]})},Ae.value)),e[58]=N,e[59]=k,e[60]=Ne):Ne=e[60];let me;e[61]!==Ne?(me=s.jsx(hs,{align:"start",children:Ne}),e[61]=Ne,e[62]=me):me=e[62];let we;e[63]!==te||e[64]!==ce||e[65]!==me?(we=s.jsxs(ps,{value:te,onValueChange:E,children:[ce,me]}),e[63]=te,e[64]=ce,e[65]=me,e[66]=we):we=e[66];let _;e[67]!==ge||e[68]!==we?(_=s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[ge,we]}),e[67]=ge,e[68]=we,e[69]=_):_=e[69];let ue;e[70]!==h||e[71]!==T||e[72]!==d||e[73]!==i?(ue=d==="project"&&s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.skills.catalog.installSkill.field.project")}),h.length===0?s.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.skills.catalog.installSkill.field.noProjects")}):s.jsxs(ps,{value:T??"",onValueChange:Ae=>y(Ae),disabled:h.length===1,children:[s.jsx(fs,{className:"w-fit",children:s.jsx(ys,{placeholder:i("settings.skills.catalog.installSkill.field.chooseProjectPlaceholder")})}),s.jsx(hs,{align:"start",children:h.map(TC)})]})]}),e[70]=h,e[71]=T,e[72]=d,e[73]=i,e[74]=ue):ue=e[74];let Q;e[75]!==a.warnings?(Q=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]=Q):Q=e[76];let oe;e[77]!==_||e[78]!==ue||e[79]!==Q?(oe=s.jsxs("div",{className:"mt-2 space-y-3",children:[_,ue,Q]}),e[77]=_,e[78]=ue,e[79]=Q,e[80]=oe):oe=e[80];let Z;e[81]!==r?(Z=()=>r(!1),e[81]=r,e[82]=Z):Z=e[82];let Ie;e[83]!==i?(Ie=i("settings.common.actions.cancel"),e[83]=i,e[84]=Ie):Ie=e[84];let Se;e[85]!==Z||e[86]!==Ie?(Se=s.jsx(je,{size:"sm",variant:"ghost",onClick:Z,children:Ie}),e[85]=Z,e[86]=Ie,e[87]=Se):Se=e[87];const Y=c||!a.installable||d==="project"&&!$;let fe;e[88]!==$||e[89]!==V||e[90]!==a.repoSource||e[91]!==a.repoSubpath||e[92]!==a.skillDir||e[93]!==d||e[94]!==m?(fe=()=>{V({source:a.repoSource,subpath:a.repoSubpath,scope:d,targetSource:m,skillDir:a.skillDir,directoryOverride:$})},e[88]=$,e[89]=V,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 xe;e[99]!==Y||e[100]!==fe||e[101]!==ke?(xe=s.jsx(je,{size:"sm",disabled:Y,onClick:fe,children:ke}),e[99]=Y,e[100]=fe,e[101]=ke,e[102]=xe):xe=e[102];let he;e[103]!==Se||e[104]!==xe?(he=s.jsxs(Qs,{children:[Se,xe]}),e[103]=Se,e[104]=xe,e[105]=he):he=e[105];let Pe;e[106]!==ee||e[107]!==oe||e[108]!==he?(Pe=s.jsxs(vs,{className:"max-w-md",children:[ee,oe,he]}),e[106]=ee,e[107]=oe,e[108]=he,e[109]=Pe):Pe=e[109];let Be;e[110]!==r||e[111]!==n||e[112]!==Pe?(Be=s.jsx(ws,{open:n,onOpenChange:r,children:Pe}),e[110]=r,e[111]=n,e[112]=Pe,e[113]=Be):Be=e[113];let G;e[114]!==A||e[115]!==V?(G=Ae=>{A&&(V({source:A.source,subpath:A.subpath,scope:A.scope,targetSource:A.targetSource,skillDir:A.skillDir,conflictDecisions:Ae,directoryOverride:A.directoryOverride??null}),g(!1))},e[114]=A,e[115]=V,e[116]=G):G=e[116];let be;e[117]!==v||e[118]!==x||e[119]!==G?(be=s.jsx(kC,{open:x,onOpenChange:g,conflicts:v,onConfirm:G}),e[117]=v,e[118]=x,e[119]=G,e[120]=be):be=e[120];let De;return e[121]!==Be||e[122]!==be?(De=s.jsxs(s.Fragment,{children:[Be,be]}),e[121]=Be,e[122]=be,e[123]=De):De=e[123],De};function IC(t){return t.installSkills}function AC(t){return t.isInstalling}function PC(t){return t.projects}function DC(t){return t.activeProjectId}function TC(t){return s.jsx(Ot,{value:t.id,children:t.label||t.path},t.id)}const MC=async()=>{try{const t=xr()?.settings;if(t)return(await t.load())?.settings||{};const e=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});return e.ok?await e.json().catch(()=>null):null}catch{return null}},RC=({mode:t,onModeChange:e,showModeTabs:n=!0})=>{const{t:r}=ut(),{sources:a,itemsBySource:i,selectedSourceId:o,setSelectedSource:c,loadCatalog:d,loadSource:p,loadMoreClawdHub:m,isLoadingCatalog:u,isLoadingSource:h,isLoadingMore:b,loadedSourceIds:f,clawdhubHasMoreBySource:y,lastCatalogError:x}=Qa(jr(L=>({sources:L.sources,itemsBySource:L.itemsBySource,selectedSourceId:L.selectedSourceId,setSelectedSource:L.setSelectedSource,loadCatalog:L.loadCatalog,loadSource:L.loadSource,loadMoreClawdHub:L.loadMoreClawdHub,isLoadingCatalog:L.isLoadingCatalog,isLoadingSource:L.isLoadingSource,isLoadingMore:L.isLoadingMore,loadedSourceIds:L.loadedSourceIds,clawdhubHasMoreBySource:L.clawdhubHasMoreBySource,lastCatalogError:L.lastCatalogError}))),[g,w]=l.useState(""),[v,S]=l.useState(!1),[A,j]=l.useState(!1),[C,I]=l.useState(null),[R,k]=l.useState(!1),[P,N]=l.useState(!1);l.useEffect(()=>{d()},[d]),l.useEffect(()=>{o&&(f[o]||p(o))},[o,f,p]);const D=l.useMemo(()=>o?i[o]||[]:[],[i,o]),T=l.useMemo(()=>{const L=g.trim().toLowerCase();return L?D.filter(W=>{const B=W.skillName.toLowerCase(),ne=(W.description||"").toLowerCase(),le=(W.frontmatterName||"").toLowerCase();return B.includes(L)||ne.includes(L)||le.includes(L)}):D},[D,g]),M=l.useMemo(()=>a.find(L=>L.id===o)||null,[a,o]),$=!!(o&&o.startsWith("custom:")),F=M?.source==="clawdhub:registry"||M?.sourceType==="clawdhub",V=!!(o&&(y[o]??!0)),O=async()=>{if(!(!o||!$)){k(!0);try{const L=await MC(),B=(Array.isArray(L?.skillCatalogs)?L?.skillCatalogs:[]).filter(ne=>ne.id!==o);await Rs({skillCatalogs:B}),await d({refresh:!0}),N(!1)}finally{k(!1)}}};return s.jsx(Es,{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(Br,{items:[{id:"manual",label:r("settings.skills.catalog.page.mode.manual")},{id:"external",label:r("settings.skills.catalog.page.mode.external")}],activeId:t,onSelect:L=>e(L),layoutMode:"fit",variant:"animated",animateActivePill:!1,className:"h-full"})})}),s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground px-1",children:r("settings.skills.catalog.page.title")})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:r("settings.skills.catalog.page.section.sourceRepository")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2 py-1.5",children:[s.jsxs(ps,{value:o||"",onValueChange:L=>c(L),children:[s.jsx(fs,{className:"w-fit",children:s.jsx(ys,{placeholder:r("settings.skills.catalog.page.field.selectSourcePlaceholder")})}),s.jsx(hs,{align:"start",children:a.map(L=>s.jsx(Ot,{value:L.id,children:L.label},L.id))})]}),s.jsx(je,{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(Nn,{className:pe("h-3.5 w-3.5",(u||h)&&"animate-spin")})}),$&&s.jsx(je,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0 text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>N(!0),disabled:R,title:r("settings.skills.catalog.page.actions.removeCatalogTitle"),children:s.jsx(sn,{className:"h-3.5 w-3.5"})}),s.jsxs(je,{size:"xs",className:"!font-normal gap-1",onClick:()=>S(!0),children:[s.jsx(_s,{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(Hn,{className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Vt,{value:g,onChange:L=>w(L.target.value),placeholder:r("settings.skills.catalog.shared.field.searchSkillsPlaceholder"),className:"h-7 pl-8 w-full sm:w-64"})]}),s.jsx("span",{className:"typography-meta text-muted-foreground mt-1 block",children:u?r("settings.skills.catalog.page.loading.catalog"):r("settings.skills.catalog.page.foundCount",{count:T.length})})]})]})]}),x&&s.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-4 py-3",children:[s.jsx("div",{className:"typography-ui-label font-medium text-[var(--status-error)]",children:r("settings.skills.catalog.page.error.catalogTitle")}),s.jsx("div",{className:"typography-meta text-[var(--status-error)]/80 mt-1",children:x.message})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("section",{className:"px-2 pb-2 pt-0",children:T.length===0&&!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(Nn,{className:"mx-auto mb-3 h-5 w-5 animate-spin opacity-50"}),s.jsx("p",{className:"typography-meta",children:r("settings.skills.catalog.page.loading.skills")})]}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:T.map(L=>{const W=L.installed?.isInstalled,B=L.installed?.scope;return s.jsx("div",{className:"py-2",children:s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label font-medium text-foreground truncate",children:L.skillName}),W&&s.jsx("span",{className:"typography-micro text-[var(--status-success)] bg-[var(--status-success)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:r("settings.skills.catalog.page.badge.installed",{scope:B||r("settings.skills.catalog.page.badge.unknown")})}),!L.installable&&s.jsx("span",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:r("settings.skills.catalog.page.badge.notInstallable")})]}),L.description?s.jsx("div",{className:"typography-meta text-muted-foreground mt-0.5 line-clamp-2",children:L.description}):s.jsx("div",{className:"typography-meta text-muted-foreground/50 mt-0.5 italic",children:r("settings.skills.catalog.shared.noDescription")}),L.clawdhub&&s.jsxs("div",{className:"typography-micro text-muted-foreground mt-1.5 flex items-center gap-3",children:[L.clawdhub.owner&&s.jsxs("span",{children:[r("settings.skills.catalog.page.byOwnerPrefix")," ",s.jsx("span",{className:"font-medium text-foreground/80",children:L.clawdhub.owner})]}),s.jsxs("span",{className:"flex items-center gap-1",children:[s.jsx(Qr,{className:"h-3 w-3"}),L.clawdhub.downloads?.toLocaleString()??0]}),(L.clawdhub.stars??0)>0&&s.jsxs("span",{className:"flex items-center gap-1",children:[s.jsx(wl,{className:"h-3 w-3"}),L.clawdhub.stars]}),s.jsxs("span",{className:"bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:["v",L.clawdhub.version]})]}),L.warnings?.length?s.jsx("div",{className:"typography-micro text-[var(--status-warning)] mt-1.5 bg-[var(--status-warning)]/10 px-2 py-1 rounded w-fit",children:L.warnings.join(" · ")}):null]}),s.jsx(je,{variant:"outline",size:"xs",className:"!font-normal shrink-0",disabled:!L.installable,onClick:()=>{I(L),j(!0)},children:r("settings.skills.catalog.shared.actions.install")})]})},`${L.sourceId}:${L.skillDir}`)})})}),F&&V&&!h&&T.length>0&&s.jsx("div",{className:"flex justify-center mt-2 px-2",children:s.jsx(je,{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(bC,{open:v,onOpenChange:S}),s.jsx(CC,{open:A,onOpenChange:j,item:C}),s.jsx(ws,{open:P,onOpenChange:L=>{R||N(L)},children:s.jsxs(vs,{className:"max-w-md",children:[s.jsxs(Is,{children:[s.jsx(Ss,{children:r("settings.skills.catalog.page.removeDialog.title")}),s.jsx(Os,{children:r("settings.skills.catalog.page.removeDialog.description")})]}),s.jsxs(Qs,{children:[s.jsx(je,{size:"sm",variant:"ghost",onClick:()=>N(!1),disabled:R,children:r("settings.common.actions.cancel")}),s.jsx(je,{size:"sm",variant:"destructive",onClick:()=>{O()},disabled:R,children:r("settings.skills.catalog.page.actions.removeCatalog")})]})]})})]})})},EC=()=>{const t=nt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(RC,{mode:"external",onModeChange:OC,showModeTabs:!1}),t[0]=e):e=t[0],e},FC=()=>{const{t}=ut(),{selectedSkillName:e,getSkillByName:n,getSkillDetail:r,createSkill:a,updateSkill:i,skills:o,skillDraft:c,setSkillDraft:d,setSelectedSkill:p}=ya(jr(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(""),[y,x]=l.useState("user"),[g,w]=l.useState("opencode"),[v,S]=l.useState(""),[A,j]=l.useState(""),[C,I]=l.useState([]),[R,k]=l.useState([]),[P,N]=l.useState(!1),[D,T]=l.useState(!1),[M,$]=l.useState(""),[F,V]=l.useState(""),[O,L]=l.useState(!1),[W,B]=l.useState(""),[ne,le]=l.useState(""),[ee,ae]=l.useState(null),[ge,te]=l.useState(!1),[E,z]=l.useState(""),[J,H]=l.useState(null),[re,ce]=l.useState(!1),Ne=u?b.trim()!==""||v.trim()!==""||A.trim()!==""||R.length>0:v!==M||A!==F,me=ee?ne!==E:W.trim()!=="",we=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]),_=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"),S(c.description||""),j(c.instructions||""),$(""),V(""),I([]),k(c.pendingFiles||[]);else if(e&&m){T(!0);try{const fe=await r(e);if(fe){const ke=fe.sources.md;S(ke.description||""),j(ke.instructions||""),$(ke.description||""),V(ke.instructions||""),I(ke.supportingFiles||[])}}catch(fe){console.error("Failed to load skill details:",fe)}finally{T(!1)}}})()},[m,u,e,o,c,r]);const ue=async()=>{const Y=u?b.trim().replace(/\s+/g,"-").toLowerCase():e?.trim();if(!Y){q.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){q.error(t("settings.skills.page.toast.invalidSkillName"));return}if(!v.trim()){q.error(t("settings.skills.page.toast.descriptionRequired"));return}if(u&&o.some(fe=>fe.name===Y)){q.error(t("settings.skills.page.toast.skillExists"));return}N(!0);try{const fe={name:Y,description:v.trim(),instructions:A.trim()||void 0,scope:u?y:void 0,source:u?g:void 0,supportingFiles:u&&R.length>0?R:void 0};let ke;u?(ke=await a(fe),ke&&(d(null),k([]),p(Y))):(ke=await i(Y,fe),ke&&($(v.trim()),V(A.trim()))),ke?q.success(t(u?"settings.skills.page.toast.skillCreated":"settings.skills.page.toast.skillUpdated")):q.error(t(u?"settings.skills.page.toast.createSkillFailed":"settings.skills.page.toast.updateSkillFailed"))}catch(fe){console.error("Error saving skill:",fe),q.error(t("settings.skills.page.toast.saveUnexpectedError"))}finally{N(!1)}},Q=()=>{ae(null),B(""),le(""),z(""),L(!0)},oe=async Y=>{if(ae(Y),B(Y),u){const ke=R.find(xe=>xe.path===Y)?.content||"";le(ke),z(ke),L(!0);return}if(e){te(!0),L(!0);try{const{readSupportingFile:fe}=ya.getState(),ke=await fe(e,Y);le(ke||""),z(ke||"")}catch{q.error(t("settings.skills.page.toast.loadFileContentFailed")),le(""),z("")}finally{te(!1)}}},Z=async()=>{if(!W.trim()){q.error(t("settings.skills.page.toast.fileNameRequired"));return}const Y=W.trim(),fe=ee!==null;if(u){if(fe)k(he=>he.map(Pe=>Pe.path===ee?{path:Y,content:ne}:Pe)),q.success(t("settings.skills.page.toast.fileUpdated",{path:Y}));else{if(R.some(he=>he.path===Y)){q.error(t("settings.skills.page.toast.fileExists"));return}k(he=>[...he,{path:Y,content:ne}]),q.success(t("settings.skills.page.toast.fileAdded",{path:Y}))}L(!1),ae(null);return}if(!e){q.error(t("settings.skills.page.toast.noSkillSelected"));return}const{writeSupportingFile:ke}=ya.getState();if(await ke(e,Y,ne)){q.success(fe?t("settings.skills.page.toast.fileUpdated",{path:Y}):t("settings.skills.page.toast.fileCreated",{path:Y})),L(!1),ae(null);const he=await r(e);he&&I(he.sources.md.supportingFiles||[])}else q.error(t(fe?"settings.skills.page.toast.updateFileFailed":"settings.skills.page.toast.createFileFailed"))},Ie=Y=>{if(u){k(fe=>fe.filter(ke=>ke.path!==Y)),q.success(t("settings.skills.page.toast.fileRemoved",{path:Y}));return}e&&H(Y)},Se=async()=>{if(!J||!e)return;ce(!0);const{deleteSupportingFile:Y}=ya.getState();if(await Y(e,J)){q.success(t("settings.skills.page.toast.fileDeleted",{path:J}));const ke=await r(e);ke&&I(ke.sources.md.supportingFiles||[]),H(null)}else q.error(t("settings.skills.page.toast.deleteFileFailed"));ce(!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(Tu,{className:"mx-auto mb-3 h-10 w-10 sm:h-12 sm:w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.skills.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.skills.page.empty.description")})]})}):D?s.jsx("div",{className:"flex h-full items-center justify-center px-4",children:s.jsx("div",{className:"text-center text-muted-foreground",children:s.jsx("p",{className:"typography-body",children:t("settings.skills.page.loading.details")})})}):s.jsxs(Es,{outerClassName:"h-full",className:"w-full",children:[s.jsxs("div",{className:"mx-auto w-full max-w-3xl p-3 sm:p-6 sm:pt-8",children:[s.jsx("div",{className:"mb-4",children:s.jsxs("div",{className:"min-w-0",children:[s.jsxs("h2",{className:"typography-ui-header font-semibold text-foreground truncate flex items-center gap-2",children:[u?t("settings.skills.page.title.newSkill"):e,m?.source==="claude"&&s.jsx("span",{className:"typography-micro font-normal bg-[var(--surface-muted)] text-muted-foreground px-1.5 py-0.5 rounded",children:t("settings.skills.page.badge.claudeCompatible")})]}),s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:m?t("settings.skills.page.subtitle.skillLocation",{location:we(Io(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(Vt,{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(ps,{value:Io(y,g),onValueChange:Y=>{const fe=Tx(Y);x(fe.scope),w(fe.source==="agents"?"agents":"opencode")},children:[s.jsxs(fs,{className:"w-fit gap-1.5",children:[y==="user"?s.jsx(qr,{className:"h-3.5 w-3.5"}):s.jsx(zn,{className:"h-3.5 w-3.5"}),g==="agents"?s.jsx(Gr,{className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:we(Io(y,g))})]}),s.jsx(hs,{align:"start",children:Yu.map(Y=>s.jsx(Ot,{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(qr,{className:"h-3.5 w-3.5"}):s.jsx(zn,{className:"h-3.5 w-3.5"}),Y.source==="agents"?s.jsx(Gr,{className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:we(Y.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-6",children:_(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(Sn,{value:v,onChange:Y=>S(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(Sn,{value:A,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(je,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:Q,children:[s.jsx(_s,{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?R:C;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:()=>oe(fe.path),children:[s.jsx(qh,{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(je,{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(sn,{className:"h-3 w-3"})})]},fe.path))})})()})]}),s.jsx("div",{className:"px-2 py-1",children:s.jsx(je,{onClick:ue,disabled:P||!Ne,size:"xs",className:"!font-normal",children:t(P?"settings.common.actions.saving":u?"settings.skills.page.actions.createSkill":"settings.common.actions.saveChanges")})})]}),s.jsx(ws,{open:J!==null,onOpenChange:Y=>{!Y&&!re&&H(null)},children:s.jsxs(vs,{className:"max-w-md",children:[s.jsxs(Is,{children:[s.jsx(Ss,{children:t("settings.skills.page.deleteFileDialog.title")}),s.jsx(Os,{children:t("settings.skills.page.deleteFileDialog.description",{path:J??""})})]}),s.jsxs(Qs,{children:[s.jsx(je,{size:"sm",variant:"ghost",onClick:()=>H(null),disabled:re,children:t("settings.common.actions.cancel")}),s.jsx(je,{size:"sm",variant:"destructive",onClick:Se,disabled:re,children:t("settings.common.actions.delete")})]})]})}),s.jsx(ws,{open:O,onOpenChange:Y=>{L(Y),Y||ae(null)},children:s.jsxs(vs,{className:"max-w-3xl max-h-[85vh] flex flex-col",children:[s.jsxs(Is,{className:"flex-shrink-0",children:[s.jsx(Ss,{children:t(ee?"settings.skills.page.fileDialog.titleEdit":"settings.skills.page.fileDialog.titleAdd")}),s.jsx(Os,{children:t(ee?"settings.skills.page.fileDialog.descriptionEdit":"settings.skills.page.fileDialog.descriptionAdd")})]}),ge?s.jsx("div",{className:"flex-1 flex items-center justify-center py-8",children:s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.skills.page.loading.fileContent")})}):s.jsxs("div",{className:"space-y-4 flex-1 min-h-0 flex flex-col pt-2",children:[s.jsxs("div",{className:"space-y-2 flex-shrink-0",children:[s.jsx("label",{className:"typography-ui-label font-medium text-foreground",children:t("settings.skills.page.fileDialog.field.filePath")}),s.jsx(Vt,{value:W,onChange:Y=>B(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:ee!==null}),!ee&&s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("settings.skills.page.fileDialog.field.filePathHint")})]}),s.jsxs("div",{className:"space-y-2 flex-1 min-h-0 flex flex-col",children:[s.jsx("label",{className:"typography-ui-label font-medium text-foreground flex-shrink-0",children:t("settings.skills.page.fileDialog.field.content")}),s.jsx(Sn,{value:ne,onChange:Y=>le(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(Qs,{className:"mt-4",children:[s.jsx(je,{size:"sm",variant:"ghost",onClick:()=>{L(!1),ae(null)},children:t("settings.common.actions.cancel")}),s.jsx(je,{size:"sm",onClick:Z,disabled:ge||!me,children:t(ee?"settings.common.actions.saveChanges":"settings.skills.page.actions.createFile")})]})]})})]})},uf=t=>{const e=nt.c(2),{view:n}=t,r=n===void 0?"installed":n;let a;return e[0]!==r?(a=r==="catalog"?s.jsx(EC,{}):s.jsx(FC,{}),e[0]=r,e[1]=a):a=e[1],a};function OC(){}const Mx=t=>{const e=nt.c(26),{header:n,footer:r,children:a,className:i,variant:o}=t,c=o===void 0?"sidebar":o,d=yn(),p=l.useRef(null),[m,u]=l.useState(!1),[h,b]=l.useState(!1),f=c==="background"||d?"bg-background":"bg-sidebar",y=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 v;e[2]!==a?(v=[a,g],e[2]=a,e[3]=v):v=e[3],l.useEffect(w,v);let S,A;e[4]===Symbol.for("react.memo_cache_sentinel")?(S=()=>{const N=p.current;if(!N)return;const D=()=>g();return N.addEventListener("scroll",D,{passive:!0}),()=>N.removeEventListener("scroll",D)},A=[g],e[4]=S,e[5]=A):(S=e[4],A=e[5]),l.useEffect(S,A);let j;e[6]!==f||e[7]!==i?(j=pe("flex h-full flex-col",f,i),e[6]=f,e[7]=i,e[8]=j):j=e[8];let C;e[9]!==a?(C=s.jsx(Es,{ref:p,outerClassName:"flex-1 min-h-0",className:"space-y-0.5 px-3 py-2 overflow-x-hidden",children:a}),e[9]=a,e[10]=C):C=e[10];let I;e[11]!==y||e[12]!==m?(I=m&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 h-4",style:{background:`linear-gradient(to bottom, ${y} 0%, transparent 100%)`}}),e[11]=y,e[12]=m,e[13]=I):I=e[13];let R;e[14]!==y||e[15]!==h?(R=h&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-6",style:{background:`linear-gradient(to top, ${y} 0%, transparent 100%)`}}),e[14]=y,e[15]=h,e[16]=R):R=e[16];let k;e[17]!==R||e[18]!==C||e[19]!==I?(k=s.jsxs("div",{className:"relative flex flex-1 min-h-0 flex-col",children:[C,I,R]}),e[17]=R,e[18]=C,e[19]=I,e[20]=k):k=e[20];let P;return e[21]!==r||e[22]!==n||e[23]!==k||e[24]!==j?(P=s.jsxs("div",{className:j,children:[n,k,r]}),e[21]=r,e[22]=n,e[23]=k,e[24]=j,e[25]=P):P=e[25],P},Rx=t=>{const e=nt.c(23),{title:n,metadata:r,selected:a,onSelect:i,icon:o,actions:c,className:d}=t,p=a===void 0?!1:a,m=c&&c.length>0,u=p?"bg-interactive-selection":"hover:bg-interactive-hover";let h;e[0]!==d||e[1]!==u?(h=pe("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 y;e[8]!==r?(y=r&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:r}),e[8]=r,e[9]=y):y=e[9];let x;e[10]!==i||e[11]!==f||e[12]!==y?(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,y]}),e[10]=i,e[11]=f,e[12]=y,e[13]=x):x=e[13];let g;e[14]!==c||e[15]!==m?(g=m&&s.jsxs(zs,{children:[s.jsx(Bs,{asChild:!0,children:s.jsx(je,{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(ia,{className:"h-3.5 w-3.5"})})}),s.jsx(Vs,{align:"end",className:"w-fit min-w-20",children:c.map(LC)})]}),e[14]=c,e[15]=m,e[16]=g):g=e[16];let w;e[17]!==x||e[18]!==g?(w=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[x,g]}),e[17]=x,e[18]=g,e[19]=w):w=e[19];let v;return e[20]!==h||e[21]!==w?(v=s.jsx("div",{className:h,children:w}),e[20]=h,e[21]=w,e[22]=v):v=e[22],v};function LC(t){const e=t.icon;return s.jsxs($t,{onClick:n=>{n.stopPropagation(),t.onClick()},className:pe(t.destructive&&"text-destructive focus:text-destructive"),children:[e&&s.jsx(e,{className:"h-4 w-4 mr-px"}),t.label]},t.label)}const $C=t=>{const e=nt.c(41),{onItemSelect:n}=t,{t:r}=ut(),a=Fs(BC),i=Te(VC),o=Te(zC),{currentTheme:c}=Rr();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=yn(),e[1]=u):u=e[1];const h=u,b=_C;let f,y;e[2]!==a||e[3]!==i||e[4]!==o?(f=()=>{if(a.length===0){i!==null&&o(null);return}i&&a.some(k=>k.id===i)||o(a[0].id)},y=[a,i,o],e[2]=a,e[3]=i,e[4]=o,e[5]=f,e[6]=y):(f=e[5],y=e[6]),l.useEffect(f,y);let x;e[7]===Symbol.for("react.memo_cache_sentinel")?(x=pe("border-b px-3","pt-4 pb-3"),e[7]=x):x=e[7];let g;e[8]!==r?(g=r("settings.page.projects.title"),e[8]=r,e[9]=g):g=e[9];let w;e[10]!==g?(w=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:g}),e[10]=g,e[11]=w):w=e[11];let v;e[12]!==a.length||e[13]!==r?(v=r("settings.projects.sidebar.total",{count:a.length}),e[12]=a.length,e[13]=r,e[14]=v):v=e[14];let S;e[15]!==v?(S=s.jsx("span",{className:"typography-meta text-muted-foreground",children:v}),e[15]=v,e[16]=S):S=e[16];let A;e[17]!==r?(A=!h&&s.jsx(je,{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(_s,{className:"size-4"})}),e[17]=r,e[18]=A):A=e[18];let j;e[19]!==A||e[20]!==S?(j=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[S,A]}),e[19]=A,e[20]=S,e[21]=j):j=e[21];let C;e[22]!==j||e[23]!==w?(C=s.jsxs("div",{className:x,children:[w,j]}),e[22]=j,e[23]=w,e[24]=C):C=e[24];let I;if(e[25]!==p||e[26]!==c||e[27]!==n||e[28]!==a||e[29]!==i||e[30]!==o){let k;e[32]!==p||e[33]!==c||e[34]!==n||e[35]!==i||e[36]!==o?(k=P=>{const N=P.id===i,D=P.icon?vc[P.icon]:null,T=`${P.id}:${P.iconImage?.updatedAt??0}`,M=p.has(T)?null:Wo(P,{themeVariant:c.metadata.variant,iconColor:c.colors.surface.foreground}),$=P.color?Ko[P.color]??null:null,F=M?s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center overflow-hidden rounded-[2px]",style:P.iconBackground?{backgroundColor:P.iconBackground}:void 0,children:s.jsx("img",{src:M,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>{m(V=>{if(V.has(T))return V;const O=new Set(V);return O.add(T),O})}})}):D?s.jsx(D,{className:pe("h-4 w-4",N?"text-foreground":"text-muted-foreground/70"),style:$?{color:$}:void 0}):s.jsx(zn,{className:pe("h-4 w-4",N?"text-foreground":"text-muted-foreground/70"),style:$?{color:$}:void 0});return s.jsx(Rx,{title:P.label||P.path,icon:F,selected:N,onSelect:()=>{o(P.id),n?.()}},P.id)},e[32]=p,e[33]=c,e[34]=n,e[35]=i,e[36]=o,e[37]=k):k=e[37],I=a.map(k),e[25]=p,e[26]=c,e[27]=n,e[28]=a,e[29]=i,e[30]=o,e[31]=I}else I=e[31];let R;return e[38]!==C||e[39]!==I?(R=s.jsx(Mx,{variant:"background",header:C,children:I}),e[38]=C,e[39]=I,e[40]=R):R=e[40],R};function BC(t){return t.projects}function VC(t){return t.settingsProjectsSelectedId}function zC(t){return t.setSettingsProjectsSelectedId}function _C(){Dr.requestDirectoryDialog()}const UC=({projectRef:t=null})=>{const{t:e}=ut(),{isMobile:n,isTablet:r}=un(),a=n||r,i=Fs(D=>D.getActiveProject()),o=t?.path??i?.path??null,c=Wt(D=>D.getWorktreeMetadata),d=_o(),p=Ws(D=>D.homeDirectory),[m,u]=l.useState([]),[h,b]=l.useState(!1),[f,y]=l.useState(null),[x,g]=l.useState([]),[w,v]=l.useState(!1),S=l.useMemo(()=>t?.id&&t?.path?{id:t.id,path:t.path}:!i?.id||!o?null:{id:i.id,path:o},[i?.id,o,t?.id,t?.path]),A=l.useCallback(async()=>{if(!(!S||f===!1))try{const D=await $d(S);g(D)}catch{}},[S,f]);l.useEffect(()=>{if(!o)return;let D=!1;return y(null),(async()=>{try{const T=await vg(o);if(D)return;y(T)}catch{}})(),()=>{D=!0}},[o]),l.useEffect(()=>{if(!S){g([]),v(!1);return}if(f===!1){g([]),v(!1);return}let D=!1;return v(!0),g([]),(async()=>{try{const T=await $d(S);if(D)return;g(T)}catch{}finally{D||v(!1)}})(),()=>{D=!0}},[S,f]),l.useEffect(()=>{if(!S)return;let D=!1;return b(!0),(async()=>{try{const T=await Vu(S);D||u(T.length>0?T:[""])}catch{D||u([""])}finally{D||b(!1)}})(),()=>{D=!0}},[S]);const j=l.useCallback((D,T)=>{u(M=>{const $=[...M];return $[D]=T,$})},[]),C=l.useCallback(()=>{u(D=>[...D,""])},[]),I=l.useCallback(async D=>{if(!S)return;const T=D.filter(M=>M.trim().length>0);await wg(S,T)},[S]),R=l.useCallback(D=>{u(T=>{const M=T.filter(($,F)=>F!==D);return I(M),M.length>0?M:[""]})},[I]),k=l.useCallback(()=>{I(m)},[I,m]),P=l.useCallback(D=>{const T=B=>B.replace(/\\/g,"/").replace(/\/+$/,""),M=T(D.path),$=d.filter(B=>{const ne=c(B.id);if(ne?.path&&T(ne.path)===M)return!0;const le=B.directory;return!!(le&&T(le)===M)}),F=new Set($.map(B=>B.id)),V=B=>{const ne=d.filter(ee=>{const ae=ee.parentID;return ae&&B.has(ae)});if(ne.length===0)return[];const le=new Set(ne.map(ee=>ee.id));return[...ne,...V(le)]},O=V(F),L=new Set,W=[...$,...O].filter(B=>L.has(B.id)?!1:(L.add(B.id),!0));Dr.requestDelete({sessions:W,mode:"worktree",worktree:D})},[d,c]),N=l.useMemo(()=>d.map(D=>D.id).join(","),[d]);return l.useEffect(()=>{f&&o&&A()},[N,f,o,A]),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(St,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsxs(Ct,{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((D,T)=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(Vt,{value:D,onChange:M=>j(T,M.target.value),onBlur:k,placeholder:e("settings.openchamber.worktrees.setup.commandPlaceholder"),className:"h-7 w-[30rem] max-w-full font-mono text-xs"}),s.jsx("button",{type:"button",onClick:()=>{R(T)},className:"flex-shrink-0 flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("settings.openchamber.worktrees.setup.removeCommandAria"),children:s.jsx(Ds,{className:"h-4 w-4"})})]},T)),s.jsxs(je,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:C,children:[s.jsx(_s,{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(St,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:e("settings.openchamber.worktrees.list.tooltip")})]})]})}),w?s.jsx("p",{className:"typography-meta text-muted-foreground px-1",children:e("settings.openchamber.worktrees.list.loading")}):x.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground/70 px-1",children:e("settings.openchamber.worktrees.list.empty")}):s.jsx("div",{className:"space-y-1 px-1 max-w-[32.5rem]",children:x.map(D=>s.jsxs("div",{className:"group flex w-full items-center gap-2 py-1.5",children:[s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx("p",{className:"typography-meta text-foreground truncate min-w-0",children:D.label||D.branch||e("settings.openchamber.worktrees.list.detachedHead")}),s.jsx("span",{className:"typography-micro text-muted-foreground/60 px-1.5 py-[1px] rounded bg-sidebar-accent/40 flex-shrink-0 self-center leading-none",children:"OpenCode"})]}),s.jsx("p",{className:"typography-micro text-muted-foreground/60 truncate",children:To(D.path,p)})]}),s.jsx("button",{type:"button",onClick:()=>P(D),className:pe("flex-shrink-0 flex h-7 w-7 items-center justify-center rounded text-muted-foreground/50 hover:text-destructive hover:bg-destructive/10 transition-opacity focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",a?"opacity-100":"opacity-0 group-hover:opacity-100"),"aria-label":e("settings.openchamber.worktrees.list.deleteWorktreeAria",{name:D.branch||D.label||D.path}),children:s.jsx(sn,{className:"h-4 w-4"})})]},D.path))})]})]}):s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.openchamber.worktrees.state.selectProject")})},WC=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`action_${Date.now()}_${Math.random().toString(36).slice(2,7)}`,KC=()=>({id:WC(),name:"",command:"",icon:"play"}),HC=({projectRef:t})=>{const{t:e}=ut(),n=l.useMemo(()=>kn(),[]),r=tn(C=>C.instances),a=tn(C=>C.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 C=!1;return d(!0),(async()=>{try{const I=await Ld(t);if(C)return;o(I.actions),h(JSON.stringify({actions:I.actions}))}catch{if(C)return;o([]),h(JSON.stringify({actions:[]}))}finally{C||d(!1)}})(),()=>{C=!0}},[t]);const y=l.useMemo(()=>n?Gg(r):[],[r,n]),x=l.useMemo(()=>i.some(I=>I.name.trim().length===0||I.command.trim().length===0)?e("settings.projects.actions.validation.fillNameAndCommand"):null,[i,e]),g=l.useMemo(()=>u===null?!1:u!==JSON.stringify({actions:i}),[i,u]),w=l.useCallback(()=>{const C=KC();o(I=>[...I,C]),f(I=>({...I,[C.id]:!0}))},[]),v=l.useCallback(C=>{o(I=>I.filter(R=>R.id!==C)),f(I=>{const R={...I};return delete R[C],R})},[]),S=l.useCallback((C,I)=>{o(R=>R.map(k=>k.id===C?I(k):k))},[]),A=l.useCallback(async()=>{if(x){q.error(x);return}m(!0);try{if(!await d1(t,{actions:i,primaryActionId:null})){q.error(e("settings.projects.actions.toast.saveFailed"));return}h(JSON.stringify({actions:i})),typeof window<"u"&&window.dispatchEvent(new CustomEvent(Kd,{detail:{projectId:t.id}})),q.success(e("settings.projects.actions.toast.saved"))}catch{q.error(e("settings.projects.actions.toast.saveFailed"))}finally{m(!1)}},[i,t,e,x]),j=!p&&!c&&g&&!x;return s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 flex items-start justify-between gap-2",children:[s.jsxs("div",{children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:e("settings.projects.actions.title")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.description")})]}),s.jsxs(je,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:w,children:[s.jsx(_s,{className:"h-3.5 w-3.5"}),e("settings.projects.actions.actions.add")]})]}),s.jsxs("section",{className:"pb-2 pt-0 space-y-2",children:[c?s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.state.loading")}):i.length===0?s.jsx("div",{className:"py-2",children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.state.empty")})}):s.jsx("div",{className:"space-y-0 max-w-[30rem]",children:i.map(C=>{const I=C.icon||"play",R=Al[I]||Wr,k=b[C.id]??!1,P=C.name.trim()||e("settings.projects.actions.state.untitled");return s.jsxs(yr,{open:k,onOpenChange:N=>{f(D=>({...D,[C.id]:N}))},className:pe("py-1.5"),children:[s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs(Mr,{className:"group flex-1 justify-start gap-2 rounded-md px-0 pr-1 py-1 hover:bg-[var(--interactive-hover)] focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",children:[k?s.jsx(Cs,{className:"h-4 w-4 text-muted-foreground"}):s.jsx(Fn,{className:"h-4 w-4 text-muted-foreground"}),s.jsx(R,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),s.jsx("div",{className:"min-w-0 flex-1",children:s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:P})})})]}),s.jsx(je,{type:"button",variant:"ghost",size:"xs",className:"!font-normal h-7 w-7 px-0 text-muted-foreground hover:text-[var(--status-error)]",onClick:()=>v(C.id),children:s.jsx(sn,{className:"h-3.5 w-3.5"})})]}),s.jsx(vr,{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(zs,{children:[s.jsx(Bs,{asChild:!0,children:s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md border border-[var(--interactive-border)] text-foreground hover:bg-[var(--interactive-hover)]","aria-label":e("settings.projects.actions.field.selectIconAria"),children:s.jsx(R,{className:"h-4 w-4"})})}),s.jsx(Vs,{align:"start",className:"w-56 p-2",children:s.jsx("div",{className:"grid grid-cols-6 gap-1",children:Kg.map(N=>{const D=N.Icon,T=(C.icon||"play")===N.key;return s.jsx("button",{type:"button",onClick:()=>S(C.id,M=>({...M,icon:N.key})),className:pe("inline-flex h-8 w-8 items-center justify-center rounded-md border border-transparent text-foreground hover:bg-[var(--interactive-hover)]",T&&"border-[var(--primary-base)] bg-[var(--primary-base)]/10 text-[var(--primary-base)]"),"aria-label":e("settings.projects.actions.field.iconAria",{icon:N.label}),children:s.jsx(D,{className:"h-4 w-4"})},N.key)})})})]}),s.jsx(Vt,{value:C.name,onChange:N=>S(C.id,D=>({...D,name:N.target.value})),placeholder:e("settings.projects.actions.field.actionNamePlaceholder"),className:"h-7 max-w-[14rem]"})]}),s.jsxs("div",{className:"py-1",children:[s.jsx("p",{className:"typography-meta mb-0.5 text-muted-foreground",children:e("settings.projects.actions.field.command")}),s.jsx(Sn,{value:C.command,onChange:N=>S(C.id,D=>({...D,command:N.target.value})),placeholder:e("settings.projects.actions.field.commandPlaceholder"),className:"min-h-[88px] max-w-[30rem] font-mono text-xs"})]}),s.jsxs("div",{className:"py-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:e("settings.projects.actions.field.autoOpenUrl")}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2",role:"button",tabIndex:0,"aria-pressed":C.autoOpenUrl===!0,onClick:()=>S(C.id,N=>({...N,...N.autoOpenUrl===!0?{autoOpenUrl:void 0}:{autoOpenUrl:!0}})),onKeyDown:N=>{(N.key===" "||N.key==="Enter")&&(N.preventDefault(),S(C.id,D=>({...D,...D.autoOpenUrl===!0?{autoOpenUrl:void 0}:{autoOpenUrl:!0}})))},children:[s.jsx(bs,{checked:C.autoOpenUrl===!0,onChange:N=>S(C.id,D=>({...D,...N?{autoOpenUrl:!0}:{autoOpenUrl:void 0}})),ariaLabel:e("settings.projects.actions.field.autoOpenUrlForAria",{title:P})}),s.jsx("span",{className:"typography-ui-label font-normal text-foreground/80",children:e("settings.projects.actions.field.autoOpenUrlDescription")})]})]}),C.autoOpenUrl===!0?s.jsxs("div",{className:"mt-1",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Vt,{value:C.openUrl||"",onChange:N=>S(C.id,D=>({...D,openUrl:N.target.value})),placeholder:e("settings.projects.actions.field.overrideUrlPlaceholder"),className:"h-7 w-full max-w-[24rem]"}),s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:e("settings.projects.actions.field.overrideUrlTooltip")})]})]}),n?s.jsxs("div",{className:"mt-2",children:[s.jsx("p",{className:"typography-meta mb-0.5 text-muted-foreground",children:e("settings.projects.actions.field.desktopSshForward")}),y.length>0?s.jsxs(ps,{value:C.desktopOpenSshForward&&y.some(N=>N.id===C.desktopOpenSshForward)?C.desktopOpenSshForward:"__none__",onValueChange:N=>{S(C.id,D=>({...D,...N==="__none__"?{desktopOpenSshForward:void 0}:{desktopOpenSshForward:N}}))},children:[s.jsx(fs,{className:"h-7 w-full max-w-[30rem]",children:s.jsx(ys,{placeholder:e("settings.projects.actions.field.useOutputManualUrl")})}),s.jsxs(hs,{children:[s.jsx(Ot,{value:"__none__",children:e("settings.projects.actions.field.useOutputManualUrl")}),y.map(N=>s.jsx(Ot,{value:N.id,children:N.label},N.id))]})]}):s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.projects.actions.state.noDesktopSshForwards")})]}):null]}):null]})]})})]},C.id)})}),s.jsxs("div",{className:"pt-3",children:[x?s.jsx("p",{className:"typography-meta mb-2 text-[var(--status-warning)]",children:x}):null,s.jsx(je,{type:"button",size:"xs",className:"!font-normal",onClick:A,disabled:!j,children:e(p?"settings.common.actions.saving":"settings.projects.actions.actions.save")})]})]})]})},GC=()=>{const t=nt.c(201),{t:e}=ut(),n=Fs(qC),r=Fs(QC),a=Fs(JC),i=Fs(YC),o=Fs(XC),c=Te(ZC),d=Te(e4),{currentTheme:p}=Rr();let m;e:{if(!c){m=null;break e}let vt;t[0]!==n||t[1]!==c?(vt=n.find(Rt=>Rt.id===c)??null,t[0]=n,t[1]=c,t[2]=vt):vt=t[2],m=vt}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(vt=>vt.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,y]=l.useState(""),[x,g]=l.useState(null),[w,v]=l.useState(null),[S,A]=l.useState(null),[j,C]=l.useState(!1),[I,R]=l.useState(!1),[k,P]=l.useState(!1),[N,D]=l.useState(!1),[T,M]=l.useState(null),[$,F]=l.useState(null),[V,O]=l.useState(!1),L=l.useRef(null);let W;t[8]===Symbol.for("react.memo_cache_sentinel")?(W=()=>{M(null),F(t4)},t[8]=W):W=t[8];const B=W;let ne;e:{if(!u){ne=null;break e}let vt;t[9]!==u.id||t[10]!==u.path?(vt={id:u.id,path:u.path},t[9]=u.id,t[10]=u.path,t[11]=vt):vt=t[11],ne=vt}const le=ne;let ee,ae;t[12]!==u?(ee=()=>{if(!u){y(""),g(null),v(null),A(null);return}y(u.label??""),g(u.icon??null),v(u.color??null),A(u.iconBackground??null),D(!1),B(),O(!1)},ae=[u,B],t[12]=u,t[13]=ee,t[14]=ae):(ee=t[13],ae=t[14]),l.useEffect(ee,ae);let ge,te;t[15]===Symbol.for("react.memo_cache_sentinel")?(ge=()=>()=>{B()},te=[B],t[15]=ge,t[16]=te):(ge=t[15],te=t[16]),l.useEffect(ge,te);let E;t[17]!==w||t[18]!==x||t[19]!==S||t[20]!==f||t[21]!==N||t[22]!==T||t[23]!==u?(E=!!u&&(f.trim()!==(u?.label??"").trim()||x!==(u?.icon??null)||w!==(u?.color??null)||S!==(u?.iconBackground??null)||N||!!T),t[17]=w,t[18]=x,t[19]=S,t[20]=f,t[21]=N,t[22]=T,t[23]=u,t[24]=E):E=t[24];const z=E;let J;t[25]!==w||t[26]!==x||t[27]!==S||t[28]!==f||t[29]!==N||t[30]!==T||t[31]!==i||t[32]!==u||t[33]!==e||t[34]!==r||t[35]!==a?(J=async()=>{if(!u)return;if(T){C(!0);const Rt=await a(u.id,T);if(C(!1),!Rt.ok){q.error(Rt.error||e("settings.projects.page.toast.uploadIconFailed"));return}q.success(e("settings.projects.page.toast.iconUpdated")),B(),D(!1)}const vt=N&&!!u.iconImage;if(vt){R(!0);const Rt=await i(u.id);if(R(!1),!Rt.ok){q.error(Rt.error||e("settings.projects.page.toast.removeIconFailed"));return}q.success(e("settings.projects.page.toast.iconRemoved")),D(!1),A(null)}r(u.id,{label:f.trim(),icon:x,color:w,iconBackground:vt?null:S})},t[25]=w,t[26]=x,t[27]=S,t[28]=f,t[29]=N,t[30]=T,t[31]=i,t[32]=u,t[33]=e,t[34]=r,t[35]=a,t[36]=J):J=t[36];const H=J,re=w?Ko[w]??null:null,ce=!!u?.iconImage,Ne=!!(T&&$),me=u?.iconImage?.source==="custom",we=ce&&!N||Ne,_=we;let ue;t[37]!==p||t[38]!==Ne||t[39]!==ce||t[40]!==N||t[41]!==$||t[42]!==V||t[43]!==u?(ue=V?null:Ne?$:u&&ce&&!N?Wo(u,{themeVariant:p.metadata.variant,iconColor:p.colors.surface.foreground}):null,t[37]=p,t[38]=Ne,t[39]=ce,t[40]=N,t[41]=$,t[42]=V,t[43]=u,t[44]=ue):ue=t[44];const Q=ue;let oe;t[45]!==j||t[46]!==u?(oe=vt=>{!u||!vt||j||(D(!1),O(!1),M(vt),F(Rt=>(Rt&&URL.revokeObjectURL(Rt),URL.createObjectURL(vt))))},t[45]=j,t[46]=u,t[47]=oe):oe=t[47];const Z=oe;let Ie;t[48]!==Ne||t[49]!==_||t[50]!==ce||t[51]!==I||t[52]!==u?(Ie=()=>{!u||!_||I||(Ne&&B(),D(!!ce),O(!1))},t[48]=Ne,t[49]=_,t[50]=ce,t[51]=I,t[52]=u,t[53]=Ie):Ie=t[53];const Se=Ie;let Y;t[54]!==o||t[55]!==k||t[56]!==u||t[57]!==e?(Y=async()=>{!u||k||(B(),D(!1),O(!1),P(!0),o(u.id).then(vt=>{if(!vt.ok){q.error(vt.error||e("settings.projects.page.toast.discoverIconFailed"));return}if(vt.skipped){q.success(e("settings.projects.page.toast.customIconAlreadySet"));return}q.success(e("settings.projects.page.toast.iconDiscovered"))}).finally(()=>{P(!1)}))},t[54]=o,t[55]=k,t[56]=u,t[57]=e,t[58]=Y):Y=t[58];const fe=Y;if(!u){let vt;t[59]!==e?(vt=e("settings.projects.page.empty.noProjects"),t[59]=e,t[60]=vt):vt=t[60];let Rt;return t[61]!==vt?(Rt=s.jsx(Es,{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:vt})})}),t[61]=vt,t[62]=Rt):Rt=t[62],Rt}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 xe;t[66]!==ke?(xe=s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:ke}),t[66]=ke,t[67]=xe):xe=t[67];let he;t[68]!==u.path?(he=s.jsx("p",{className:"typography-meta text-muted-foreground truncate",title:u.path,children:u.path}),t[68]=u.path,t[69]=he):he=t[69];let Pe;t[70]!==xe||t[71]!==he?(Pe=s.jsx("div",{className:"mb-4 flex items-center justify-between gap-4",children:s.jsxs("div",{className:"min-w-0",children:[xe,he]})}),t[70]=xe,t[71]=he,t[72]=Pe):Pe=t[72];let Be;t[73]!==e?(Be=e("settings.projects.page.field.projectName"),t[73]=e,t[74]=Be):Be=t[74];let G;t[75]!==Be?(G=s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:Be})}),t[75]=Be,t[76]=G):G=t[76];let be;t[77]===Symbol.for("react.memo_cache_sentinel")?(be=vt=>y(vt.target.value),t[77]=be):be=t[77];let De;t[78]!==e?(De=e("settings.projects.page.field.projectNamePlaceholder"),t[78]=e,t[79]=De):De=t[79];let Ae;t[80]!==f||t[81]!==De?(Ae=s.jsx("div",{className:"mt-1.5 flex min-w-0 items-center gap-2",children:s.jsx(Vt,{value:f,onChange:be,placeholder:De,className:"h-7 min-w-0 w-full sm:max-w-[19rem]"})}),t[80]=f,t[81]=De,t[82]=Ae):Ae=t[82];let ve;t[83]!==G||t[84]!==Ae?(ve=s.jsxs("div",{className:"py-1.5",children:[G,Ae]}),t[83]=G,t[84]=Ae,t[85]=ve):ve=t[85];let U;t[86]!==e?(U=e("settings.projects.page.field.accentColor"),t[86]=e,t[87]=U):U=t[87];let de;t[88]!==U?(de=s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:U})}),t[88]=U,t[89]=de):de=t[89];let Re;t[90]===Symbol.for("react.memo_cache_sentinel")?(Re=()=>v(null),t[90]=Re):Re=t[90];const Le=w===null?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-border/40 hover:border-border hover:bg-[var(--surface-muted)]";let se;t[91]!==Le?(se=pe("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",Le),t[91]=Le,t[92]=se):se=t[92];let ie;t[93]!==e?(ie=e("settings.projects.page.field.none"),t[93]=e,t[94]=ie):ie=t[94];let K;t[95]===Symbol.for("react.memo_cache_sentinel")?(K=s.jsx(Ds,{className:"h-4 w-4 text-muted-foreground"}),t[95]=K):K=t[95];let _e;t[96]!==se||t[97]!==ie?(_e=s.jsx("button",{type:"button",onClick:Re,className:se,title:ie,children:K}),t[96]=se,t[97]=ie,t[98]=_e):_e=t[98];let He;t[99]!==w?(He=u1.map(vt=>s.jsx("button",{type:"button",onClick:()=>v(vt.key),className:pe("h-7 w-7 rounded-md border transition-colors",w===vt.key?"border-2 border-foreground ring-1 ring-[var(--primary-base)]/40":"border-transparent hover:border-border/70"),style:{backgroundColor:vt.cssVar},title:vt.label},vt.key)),t[99]=w,t[100]=He):He=t[100];let Ke;t[101]!==_e||t[102]!==He?(Ke=s.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-2",children:[_e,He]}),t[101]=_e,t[102]=He,t[103]=Ke):Ke=t[103];let Ze;t[104]!==de||t[105]!==Ke?(Ze=s.jsxs("div",{className:"py-1.5",children:[de,Ke]}),t[104]=de,t[105]=Ke,t[106]=Ze):Ze=t[106];let Xe;t[107]!==e?(Xe=e("settings.projects.page.field.projectIcon"),t[107]=e,t[108]=Xe):Xe=t[108];let mt;t[109]!==Xe?(mt=s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:Xe})}),t[109]=Xe,t[110]=mt):mt=t[110];let et;t[111]!==Z?(et=s.jsx("input",{ref:L,type:"file",accept:"image/png,image/jpeg,image/svg+xml,.png,.jpg,.jpeg,.svg",className:"hidden",onChange:vt=>{const Rt=vt.target.files?.[0]??null;Z(Rt),vt.currentTarget.value=""}}),t[111]=Z,t[112]=et):et=t[112];let ct;t[113]===Symbol.for("react.memo_cache_sentinel")?(ct=()=>g(null),t[113]=ct):ct=t[113];const lt=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]!==lt?(ye=pe("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",lt),t[114]=lt,t[115]=ye):ye=t[115];let Ge;t[116]!==e?(Ge=e("settings.projects.page.field.none"),t[116]=e,t[117]=Ge):Ge=t[117];let $e;t[118]===Symbol.for("react.memo_cache_sentinel")?($e=s.jsx(Ds,{className:"h-4 w-4 text-muted-foreground"}),t[118]=$e):$e=t[118];let Ve;t[119]!==ye||t[120]!==Ge?(Ve=s.jsx("button",{type:"button",onClick:ct,className:ye,title:Ge,children:$e}),t[119]=ye,t[120]=Ge,t[121]=Ve):Ve=t[121];let tt;t[122]!==re||t[123]!==x?(tt=m1.map(vt=>{const Rt=vt.Icon;return s.jsx("button",{type:"button",onClick:()=>g(vt.key),className:pe("h-7 w-7 rounded-md border transition-colors flex items-center justify-center",x===vt.key?"border-2 border-foreground bg-[var(--primary-base)]/10":"border-transparent hover:border-border hover:bg-[var(--surface-muted)]"),title:vt.label,children:s.jsx(Rt,{className:"w-4 h-4",style:re&&x===vt.key?{color:re}:void 0})},vt.key)}),t[122]=re,t[123]=x,t[124]=tt):tt=t[124];let Qe;t[125]!==Ve||t[126]!==tt?(Qe=s.jsxs("div",{className:"mt-1.5 flex max-w-[22rem] flex-wrap items-center gap-2",children:[Ve,tt]}),t[125]=Ve,t[126]=tt,t[127]=Qe):Qe=t[127];let ze;t[128]!==we||t[129]!==S||t[130]!==Q||t[131]!==e?(ze=we&&Q&&s.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.projects.page.field.preview")}),s.jsx("span",{className:"inline-flex h-7 w-7 items-center justify-center rounded-md border border-border/60 bg-[var(--surface-elevated)] p-1",children:s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center overflow-hidden rounded-[2px]",style:S?{backgroundColor:S}:void 0,children:s.jsx("img",{src:Q,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>O(!0)})})})]}),t[128]=we,t[129]=S,t[130]=Q,t[131]=e,t[132]=ze):ze=t[132];let ht;t[133]!==we||t[134]!==S||t[135]!==e?(ht=we&&s.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[s.jsx("input",{type:"color",value:S??"#000000",onChange:vt=>A(vt.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(Vt,{value:S??"",onChange:vt=>A(vt.target.value),placeholder:"#000000",className:"h-7 w-[8rem]"}),s.jsx(je,{type:"button",size:"xs",variant:"outline",onClick:()=>A(null),className:"h-7 w-7 p-0","aria-label":e("settings.projects.page.field.clearIconBackgroundAria"),title:e("settings.projects.page.field.clearBackground"),disabled:!S,children:s.jsx(Ds,{className:"h-3.5 w-3.5"})})]}),t[133]=we,t[134]=S,t[135]=e,t[136]=ht):ht=t[136];let _t;t[137]!==fe||t[138]!==me||t[139]!==k||t[140]!==j||t[141]!==e?(_t=!me&&s.jsxs(s.Fragment,{children:[s.jsx(je,{size:"xs",className:"h-6 !font-normal",onClick:()=>L.current?.click(),disabled:j,children:e(j?"settings.projects.page.actions.uploading":"settings.projects.page.actions.uploadIcon")}),s.jsx(je,{size:"xs",className:"h-6 !font-normal",variant:"outline",onClick:()=>{fe()},disabled:k,children:e(k?"settings.projects.page.actions.discovering":"settings.projects.page.actions.discoverFavicon")})]}),t[137]=fe,t[138]=me,t[139]=k,t[140]=j,t[141]=e,t[142]=_t):_t=t[142];let Kt;t[143]!==Se||t[144]!==_||t[145]!==I||t[146]!==e?(Kt=_&&s.jsx(je,{size:"xs",className:"!font-normal",variant:"outline",onClick:()=>{Se()},disabled:I,children:e(I?"settings.projects.page.actions.removing":"settings.projects.page.actions.removeProjectIcon")}),t[143]=Se,t[144]=_,t[145]=I,t[146]=e,t[147]=Kt):Kt=t[147];let Ut;t[148]!==I||t[149]!==N||t[150]!==e?(Ut=N&&s.jsx(je,{size:"xs",className:"!font-normal",variant:"outline",onClick:()=>D(!1),disabled:I,children:e("settings.projects.page.actions.undoRemove")}),t[148]=I,t[149]=N,t[150]=e,t[151]=Ut):Ut=t[151];let jt;t[152]!==_t||t[153]!==Kt||t[154]!==Ut?(jt=s.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[_t,Kt,Ut]}),t[152]=_t,t[153]=Kt,t[154]=Ut,t[155]=jt):jt=t[155];let Dt;t[156]!==mt||t[157]!==et||t[158]!==Qe||t[159]!==ze||t[160]!==ht||t[161]!==jt?(Dt=s.jsxs("div",{className:"py-1.5",children:[mt,et,Qe,ze,ht,jt]}),t[156]=mt,t[157]=et,t[158]=Qe,t[159]=ze,t[160]=ht,t[161]=jt,t[162]=Dt):Dt=t[162];let ts;t[163]!==ve||t[164]!==Ze||t[165]!==Dt?(ts=s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[ve,Ze,Dt]}),t[163]=ve,t[164]=Ze,t[165]=Dt,t[166]=ts):ts=t[166];let it;t[167]!==z||t[168]!==I||t[169]!==j||t[170]!==f?(it=!z||f.trim().length===0||j||I,t[167]=z,t[168]=I,t[169]=j,t[170]=f,t[171]=it):it=t[171];let Yt;t[172]!==e?(Yt=e("settings.common.actions.saveChanges"),t[172]=e,t[173]=Yt):Yt=t[173];let Qt;t[174]!==H||t[175]!==it||t[176]!==Yt?(Qt=s.jsx("div",{className:"mt-0.5 px-2 py-1",children:s.jsx(je,{onClick:H,disabled:it,size:"xs",className:"!font-normal",children:Yt})}),t[174]=H,t[175]=it,t[176]=Yt,t[177]=Qt):Qt=t[177];let Xt;t[178]!==ts||t[179]!==Qt?(Xt=s.jsxs("div",{className:"mb-8",children:[ts,Qt]}),t[178]=ts,t[179]=Qt,t[180]=Xt):Xt=t[180];let us;t[181]!==le?(us=le&&s.jsx(HC,{projectRef:le}),t[181]=le,t[182]=us):us=t[182];let ms;t[183]!==us?(ms=s.jsx("div",{className:"mb-8",children:s.jsx("section",{className:"px-2 pb-2 pt-0",children:us})}),t[183]=us,t[184]=ms):ms=t[184];let gs;t[185]!==e?(gs=e("settings.projects.page.section.worktree"),t[185]=e,t[186]=gs):gs=t[186];let ds;t[187]!==gs?(ds=s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:gs})}),t[187]=gs,t[188]=ds):ds=t[188];let Ft;t[189]!==le?(Ft=le&&s.jsx(UC,{projectRef:le}),t[189]=le,t[190]=Ft):Ft=t[190];let Ue;t[191]!==Ft?(Ue=s.jsx("section",{className:"px-2 pb-2 pt-0",children:Ft}),t[191]=Ft,t[192]=Ue):Ue=t[192];let Tt;t[193]!==ds||t[194]!==Ue?(Tt=s.jsxs("div",{className:"mb-8",children:[ds,Ue]}),t[193]=ds,t[194]=Ue,t[195]=Tt):Tt=t[195];let At;return t[196]!==Pe||t[197]!==Xt||t[198]!==ms||t[199]!==Tt?(At=s.jsx(Es,{outerClassName:"h-full",className:"w-full bg-background",children:s.jsxs("div",{className:"mx-auto w-full max-w-4xl p-3 sm:p-6 sm:pt-8",children:[Pe,Xt,ms,Tt]})}),t[196]=Pe,t[197]=Xt,t[198]=ms,t[199]=Tt,t[200]=At):At=t[200],At};function qC(t){return t.projects}function QC(t){return t.updateProjectMeta}function JC(t){return t.uploadProjectIcon}function YC(t){return t.removeProjectIcon}function XC(t){return t.discoverProjectIcon}function ZC(t){return t.settingsProjectsSelectedId}function e4(t){return t.setSettingsProjectsSelectedId}function t4(t){return t&&URL.revokeObjectURL(t),null}const s4=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`,n4=()=>Math.floor(2e4+Math.random()*3e4),r4=t=>{const e=(t instanceof Error?t.message:String(t)).toLowerCase();return e.includes("address already in use")||e.includes("eaddrinuse")||e.includes("port already in use")},a4=t=>{switch(t){case"ready":return"settings.remoteInstances.sidebar.phase.ready";case"error":return"settings.remoteInstances.sidebar.phase.error";case"degraded":return"settings.remoteInstances.sidebar.phase.reconnect";case"installing":return"settings.remoteInstances.sidebar.phase.installing";case"updating":return"settings.remoteInstances.sidebar.phase.updating";case"forwarding":return"settings.remoteInstances.sidebar.phase.forwarding";case"server_starting":return"settings.remoteInstances.sidebar.phase.starting";case"master_connecting":return"settings.remoteInstances.sidebar.phase.connecting";default:return"settings.remoteInstances.sidebar.phase.idle"}},i4=({onItemSelect:t})=>{const{t:e}=ut(),n=tn(g=>g.instances),r=tn(g=>g.statusesById),a=tn(g=>g.isLoading),i=tn(g=>g.load),o=tn(g=>g.loadImports),c=tn(g=>g.createFromCommand),d=tn(g=>g.connect),p=tn(g=>g.disconnect),m=tn(g=>g.retry),u=tn(g=>g.removeInstance),h=tn(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 y=l.useCallback(async()=>{const g=s4();try{await c(g,"ssh user@example.com",e("settings.remoteInstances.sidebar.newSshInstanceName")),f(g),t?.()}catch(w){q.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(!r4(w)||!window.confirm(e("settings.remoteInstances.sidebar.confirm.localPortInUseRetry")))throw w;const S={...g,localForward:{...g.localForward,preferredLocalPort:n4()}};await h(S),await d(S.id),q.success(e("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[d,e,h]);return s.jsx(Mx,{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(je,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:()=>{y()},"aria-label":e("settings.remoteInstances.sidebar.actions.addSshInstance"),children:s.jsx(_s,{className:"size-4"})})]})]}),children:n.map(g=>{const w=r[g.id],v=g.id===b,S=g.nickname?.trim()||g.sshParsed?.destination||g.id,A=`${e(a4(w?.phase))}${w?.localUrl?` · ${w.localUrl}`:""}`,j=w?.phase==="ready",C=w?.phase==="error"||w?.phase==="degraded";return s.jsx(Rx,{title:S,metadata:A,selected:v,onSelect:()=>{f(g.id),t?.()},actions:[{label:e(j?"settings.remoteInstances.sidebar.actions.disconnect":"settings.remoteInstances.sidebar.actions.connect"),icon:j?Kr:Qh,onClick:()=>{(j?p(g.id):x(g)).catch(R=>{q.error(e(j?"settings.remoteInstances.sidebar.toast.disconnectFailed":"settings.remoteInstances.sidebar.toast.connectFailed"),{description:R instanceof Error?R.message:String(R)})})}},{label:e("settings.remoteInstances.sidebar.actions.retry"),icon:Nn,onClick:()=>{C&&m(g.id).catch(I=>{q.error(e("settings.remoteInstances.sidebar.toast.retryFailed"),{description:I instanceof Error?I.message:String(I)})})}},{label:e("settings.remoteInstances.sidebar.actions.remove"),icon:sn,destructive:!0,onClick:()=>{u(g.id).then(()=>{if(b===g.id){const I=n.find(R=>R.id!==g.id);f(I?.id||null)}}).catch(I=>{q.error(e("settings.remoteInstances.sidebar.toast.removeFailed"),{description:I instanceof Error?I.message:String(I)})})}}]},g.id)})})},mf=t=>{const e=nt.c(10),{children:n,className:r,outerClassName:a}=t;let i;e[0]!==a?(i=pe("h-full",a),e[0]=a,e[1]=i):i=e[1];let o;e[2]!==r?(o=pe("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(Es,{outerClassName:i,className:"w-full",children:c}),e[7]=i,e[8]=c,e[9]=d):d=e[9],d},au=()=>Math.floor(2e4+Math.random()*3e4),o4=t=>{const e=(t instanceof Error?t.message:String(t)).toLowerCase();return e.includes("address already in use")||e.includes("eaddrinuse")||e.includes("port already in use")},l4=t=>{switch(t){case"config_resolved":return"settings.remoteInstances.page.phase.resolvingConfiguration";case"auth_check":return"settings.remoteInstances.page.phase.checkingAuth";case"master_connecting":return"settings.remoteInstances.page.phase.establishingSsh";case"remote_probe":return"settings.remoteInstances.page.phase.probingRemote";case"installing":return"settings.remoteInstances.page.phase.installingOpenChamber";case"updating":return"settings.remoteInstances.page.phase.updatingOpenChamber";case"server_detecting":return"settings.remoteInstances.page.phase.detectingServer";case"server_starting":return"settings.remoteInstances.page.phase.startingServer";case"forwarding":return"settings.remoteInstances.page.phase.forwardingPorts";case"ready":return"settings.remoteInstances.sidebar.phase.ready";case"degraded":return"settings.remoteInstances.page.phase.reconnecting";case"error":return"settings.remoteInstances.sidebar.phase.error";default:return"settings.remoteInstances.sidebar.phase.idle"}},c4=new Set(["config_resolved","auth_check","master_connecting","remote_probe","installing","updating","server_detecting","server_starting","forwarding"]),Ex=t=>!!(t&&c4.has(t)),d4=t=>t==="ready"?"bg-[var(--status-success)] animate-pulse":t==="error"?"bg-[var(--status-error)] animate-pulse":t==="degraded"||Ex(t)?"bg-[var(--status-warning)] animate-pulse":"bg-muted-foreground/40",u4=t=>t.type==="dynamic"?`${t.localHost||"127.0.0.1"}:${t.localPort||0}`:t.type==="remote"?`${t.remoteHost||"127.0.0.1"}:${t.remotePort||0} -> ${t.localHost||"127.0.0.1"}:${t.localPort||0}`:`${t.localHost||"127.0.0.1"}:${t.localPort||0} -> ${t.remoteHost||"127.0.0.1"}:${t.remotePort||0}`,m4=()=>({id:`forward-${Date.now()}-${Math.random().toString(16).slice(2)}`,enabled:!0,type:"local",localHost:"127.0.0.1",localPort:au(),remoteHost:"127.0.0.1",remotePort:80}),p4=t=>t.trim().replace(/\*/g,"host").replace(/\?/g,"x")||"user@host",sa=t=>{const e=nt.c(8),{label:n,hint:r}=t;let a;e[0]!==n?(a=s.jsx("span",{children:n}),e[0]=n,e[1]=a):a=e[1];let i;e[2]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx(St,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),e[2]=i):i=e[2];let o;e[3]!==r?(o=s.jsxs(kt,{children:[i,s.jsx(Ct,{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},f4=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"}},pf=(t,e)=>{const n=(t||"").trim();return`${!n||n==="127.0.0.1"||n==="::1"?"localhost":n}:${e||0}`},h4=t=>{const e=(t||"").trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},g4=t=>{const e=t.match(/^\[(\d{10,})\]\s*(?:\[([A-Z]+)\]\s*)?(.*)$/);if(!e)return t;const n=Number(e[1]),r=Number.isFinite(n)?new Date(n).toISOString():e[1],a=(e[2]||"INFO").toUpperCase(),i=e[3]||"";return`[${r}] [${a}] ${i}`},x4=t=>{const e=t.trim();if(e)try{window.location.assign(e)}catch{window.location.href=e}},b4=t=>{const e=t.sshCommand.trim(),n=t.nickname?.trim(),r=t.portForwards.map(a=>({...a,localHost:a.localHost?.trim()||"127.0.0.1",localPort:typeof a.localPort=="number"?Math.max(1,Math.min(65535,Math.round(a.localPort))):void 0,remoteHost:a.remoteHost?.trim(),remotePort:typeof a.remotePort=="number"?Math.max(1,Math.min(65535,Math.round(a.remotePort))):void 0}));return{...t,sshCommand:e,...n?{nickname:n}:{nickname:void 0},connectionTimeoutSec:Math.max(5,Math.min(240,Math.round(t.connectionTimeoutSec||60))),localForward:{...t.localForward,bindHost:t.localForward.bindHost==="localhost"||t.localForward.bindHost==="0.0.0.0"?t.localForward.bindHost:"127.0.0.1",preferredLocalPort:typeof t.localForward.preferredLocalPort=="number"?Math.max(1,Math.min(65535,Math.round(t.localForward.preferredLocalPort))):void 0},remoteOpenchamber:{...t.remoteOpenchamber,preferredPort:typeof t.remoteOpenchamber.preferredPort=="number"?Math.max(1,Math.min(65535,Math.round(t.remoteOpenchamber.preferredPort))):void 0},portForwards:r}},y4=()=>{const{t}=ut(),e=tn(U=>U.instances),n=tn(U=>U.statusesById),r=tn(U=>U.importCandidates),a=tn(U=>U.isImportsLoading),i=tn(U=>U.isSaving),o=tn(U=>U.error),c=tn(U=>U.load),d=tn(U=>U.loadImports),p=tn(U=>U.refreshStatuses),m=tn(U=>U.upsertInstance),u=tn(U=>U.createFromCommand),h=tn(U=>U.removeInstance),b=tn(U=>U.connect),f=tn(U=>U.disconnect),y=tn(U=>U.retry),x=Te(U=>U.settingsRemoteInstancesSelectedId),g=Te(U=>U.setSettingsRemoteInstancesSelectedId),w=l.useMemo(()=>x&&e.find(U=>U.id===x)||null,[e,x]),[v,S]=l.useState(null),[A,j]=l.useState(!1),[C,I]=l.useState(!1),[R,k]=l.useState(null),[P,N]=l.useState([]),[D,T]=l.useState(null),[M,$]=l.useState(""),[F,V]=l.useState(!1),[O,L]=l.useState({}),[W,B]=l.useState(!1),[ne,le]=l.useState(!1),[ee,ae]=l.useState(()=>Date.now());l.useEffect(()=>{c(),d()},[c,d]),l.useEffect(()=>{S(w)},[w]),l.useEffect(()=>{if(!x)return;const U=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||p()},2e3);return()=>{window.clearInterval(U)}},[p,x]),l.useEffect(()=>{let U=null,de=Date.now();const Re=()=>{const se=Date.now();se-de>=1e3&&(ae(se),de=se),U=requestAnimationFrame(Re)};(typeof document>"u"||document.visibilityState==="visible")&&(U=requestAnimationFrame(Re));const Le=()=>{document.visibilityState==="visible"&&U===null?U=requestAnimationFrame(Re):document.visibilityState!=="visible"&&U!==null&&(cancelAnimationFrame(U),U=null)};return document.addEventListener("visibilitychange",Le),()=>{document.removeEventListener("visibilitychange",Le),U!==null&&cancelAnimationFrame(U)}},[]);const ge=x?n[x]:null,te=ge?.phase,E=te==="ready",z=te==="degraded",J=Ex(te),re=E||(J||z),ce=ge?Math.max(0,ee-ge.updatedAtMs):0,Ne=z&&ce>12e3,me=l.useMemo(()=>!v||!w?!1:JSON.stringify(v)!==JSON.stringify(w),[v,w]),we=l.useCallback(U=>{S(de=>de&&U(de))},[]),_=l.useCallback(async()=>{if(!v)return;const U=b4(v);if(!U.sshCommand.trim()){q.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}if(!(U.localForward.bindHost==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces")))){if(U.auth.sshPassword?.enabled&&U.auth.sshPassword.value?.trim()&&U.auth.sshPassword.store!=="settings"){const de=window.confirm(t("settings.remoteInstances.page.confirm.storeSshPasswordPlaintext"));U.auth.sshPassword.store=de?"settings":"never",de||(U.auth.sshPassword.value=void 0)}if(U.auth.openchamberPassword?.enabled&&U.auth.openchamberPassword.value?.trim()&&U.auth.openchamberPassword.store!=="settings"){const de=window.confirm(t("settings.remoteInstances.page.confirm.storeUiPasswordPlaintext"));U.auth.openchamberPassword.store=de?"settings":"never",de||(U.auth.openchamberPassword.value=void 0)}try{await m(U),q.success(t("settings.remoteInstances.page.toast.instanceSaved"))}catch(de){q.error(t("settings.remoteInstances.page.toast.saveFailed"),{description:de instanceof Error?de.message:String(de)})}}},[v,t,m]),ue=l.useCallback(async(U,de)=>{const Re=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{return await u(Re,`ssh ${de}`,U),g(Re),q.success(t("settings.remoteInstances.page.toast.instanceCreated")),!0}catch(Le){return q.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:Le instanceof Error?Le.message:String(Le)}),!1}},[u,g,t]),Q=l.useCallback(()=>{F||(T(null),$(""))},[F]),oe=l.useCallback((U,de)=>{if(de){T(U),$(p4(U));return}ue(U,U)},[ue]),Z=l.useCallback(async()=>{const U=D,de=M.trim();if(U){if(!de){q.error(t("settings.remoteInstances.page.toast.destinationRequired"));return}V(!0);try{await ue(U,de)&&(T(null),$(""))}finally{V(!1)}}},[ue,M,D,t]),Ie=l.useCallback(async()=>{if(w)try{await b(w.id);return}catch(U){if(!o4(U)||!window.confirm(t("settings.remoteInstances.sidebar.confirm.localPortInUseRetry")))throw U;const Re={...w,localForward:{...w.localForward,preferredLocalPort:au()}};await m(Re),await b(Re.id),q.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[b,w,t,m]),Se=l.useCallback(async U=>(await p1(U,600)).map(Re=>g4(Re)),[]),Y=l.useCallback(async()=>{if(v){j(!0),I(!0),k(null);try{const U=await Se(v.id);N(U)}catch(U){N([]),k(U instanceof Error?U.message:String(U))}finally{I(!1)}}},[v,Se]);l.useEffect(()=>{if(!A||!v)return;let U=!1;const de=async()=>{try{const Le=await Se(v.id);U||(N(Le),k(null))}catch(Le){U||k(Le instanceof Error?Le.message:String(Le))}};de();const Re=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||de()},1e3);return()=>{U=!0,window.clearInterval(Re)}},[v,A,Se]);const fe=l.useMemo(()=>P.join(`
85
- `),[P]),ke=l.useCallback(()=>{if(!fe.trim()){q.error(t("settings.remoteInstances.page.toast.noLogsToCopy"));return}_n(fe).then(U=>{U.ok&&q.success(t("settings.remoteInstances.page.toast.logsCopied"))})},[fe,t]),xe=l.useCallback(async()=>{if(v)try{await f1(v.id),N([]),q.success(t("settings.remoteInstances.page.toast.logsCleared"))}catch(U){q.error(t("settings.remoteInstances.page.toast.clearLogsFailed"),{description:U instanceof Error?U.message:String(U)})}},[v,t]),he=l.useCallback(async()=>{if(!ge?.localUrl){q.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}const U=ge.localUrl.trim();if(!U){q.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}x4(U)},[ge?.localUrl,t]),Pe=l.useCallback(()=>{if(!v)return;B(!0),(re?f(v.id):Ie()).catch(de=>{const Re=re?E?"settings.remoteInstances.page.toast.disconnectFailed":"settings.remoteInstances.page.toast.cancelConnectionFailed":"settings.remoteInstances.page.toast.connectFailed";q.error(t(Re),{description:de instanceof Error?de.message:String(de)})}).finally(()=>{B(!1)})},[re,Ie,f,v,E,t]),Be=l.useCallback(()=>{if(!v||J)return;le(!0),(z?f(v.id).then(()=>Ie()):y(v.id)).catch(de=>{q.error(t("settings.remoteInstances.page.toast.retryFailed"),{description:de instanceof Error?de.message:String(de)})}).finally(()=>{le(!1)})},[Ie,f,v,J,z,y,t]),G=t(J?"settings.remoteInstances.page.actions.connecting":z?Ne?"settings.remoteInstances.page.actions.reconnectNow":"settings.remoteInstances.page.actions.reconnecting":"settings.remoteInstances.sidebar.actions.retry"),be=!W&&!ne&&(te==="error"||te==="idle"||!te||z&&Ne)&&!J,De=t(E?"settings.remoteInstances.sidebar.actions.disconnect":re?"settings.remoteInstances.page.actions.cancel":"settings.remoteInstances.sidebar.actions.connect");if(!v)return s.jsxs(mf,{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(U=>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:[U.host,U.pattern?` ${t("settings.remoteInstances.page.import.patternSuffix")}`:""]}),s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[U.source," config"]})]}),s.jsx(je,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{oe(U.host,U.pattern)},children:t("settings.remoteInstances.page.actions.create")})]},`${U.source}:${U.host}`))})})]}),s.jsx(ws,{open:!!D,onOpenChange:U=>{U||Q()},children:s.jsxs(vs,{className:"sm:max-w-md",children:[s.jsxs(Is,{children:[s.jsx(Ss,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Os,{children:D?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:D}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:U=>{U.preventDefault(),Z()},children:[s.jsx(Vt,{value:M,onChange:U=>$(U.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(je,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Q,disabled:F,children:t("settings.common.actions.cancel")}),s.jsx(je,{type:"submit",size:"xs",className:"!font-normal",disabled:F,children:t("settings.remoteInstances.page.actions.create")})]})]})]})})]});const Ae=v.remoteOpenchamber.mode==="managed",ve=v.nickname?.trim()||v.sshParsed?.destination||v.id;return s.jsxs(mf,{children:[s.jsxs("div",{className:"mb-6 px-1",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:ve}),s.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx("span",{className:`h-2.5 w-2.5 rounded-full ${d4(te)}`}),s.jsx("span",{children:t(l4(te))}),ge?.localUrl?s.jsx("span",{className:"font-mono text-foreground/80",children:ge.localUrl}):null,Ne?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(je,{type:"button",variant:re?"outline":"default",size:"xs",className:"!font-normal",onClick:Pe,disabled:W||ne,children:[re?s.jsx(Kr,{className:"h-3.5 w-3.5"}):s.jsx(Qh,{className:"h-3.5 w-3.5"}),De]}),s.jsxs(je,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Be,disabled:!be,children:[s.jsx(Nn,{className:`h-3.5 w-3.5 ${J||z&&!Ne?"animate-spin":""}`}),G]}),s.jsxs(je,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Y()},children:[s.jsx(Sy,{className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.logs")]}),s.jsxs(je,{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(v.id).then(()=>{g(null),q.success(t("settings.remoteInstances.page.toast.instanceRemoved"))}).catch(de=>{q.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:de instanceof Error?de.message:String(de)})})},children:[s.jsx(sn,{className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.remove")]})]}),ge?.localUrl?s.jsxs("div",{className:"flex flex-wrap items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx("span",{children:t("settings.remoteInstances.page.status.currentLocalUrl")}),s.jsx("span",{className:"font-mono text-foreground/90",children:ge.localUrl})]}):null]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.section.instance")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.section.instanceDescription")})]}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.sshCommand")}),s.jsx(Vt,{className:"h-7 md:max-w-xl",value:v.sshCommand,onChange:U=>we(de=>({...de,sshCommand:U.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(Vt,{className:"h-7 md:max-w-sm",value:v.nickname||"",onChange:U=>we(de=>({...de,nickname:U.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(jn,{containerClassName:"w-fit",min:5,max:240,step:1,className:"w-16 tabular-nums",value:v.connectionTimeoutSec,onValueChange:U=>{we(de=>({...de,connectionTimeoutSec:Number.isFinite(U)?U:de.connectionTimeoutSec}))}})]})]})]}),s.jsxs("div",{className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[s.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.section.remoteServer")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.section.remoteServerDescription")})]}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("div",{className:"w-56 shrink-0",children:s.jsx(sa,{label:t("settings.remoteInstances.page.field.mode"),hint:t("settings.remoteInstances.page.field.modeHint")})}),s.jsxs(ps,{value:v.remoteOpenchamber.mode,onValueChange:U=>we(de=>({...de,remoteOpenchamber:{...de.remoteOpenchamber,mode:U==="external"?"external":"managed"}})),children:[s.jsx(fs,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(ys,{placeholder:t("settings.remoteInstances.page.field.modePlaceholder")})}),s.jsxs(hs,{children:[s.jsx(Ot,{value:"managed",children:t("settings.remoteInstances.page.field.modeManaged")}),s.jsx(Ot,{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(sa,{label:t("settings.remoteInstances.page.field.preferredRemotePort"),hint:t("settings.remoteInstances.page.field.preferredRemotePortHint")})}),s.jsx(jn,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-20 tabular-nums",value:v.remoteOpenchamber.preferredPort,onValueChange:U=>{we(de=>({...de,remoteOpenchamber:{...de.remoteOpenchamber,preferredPort:Number.isFinite(U)&&U>0?U:void 0}}))},onClear:()=>{we(U=>({...U,remoteOpenchamber:{...U.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(sa,{label:t("settings.remoteInstances.page.field.installMethod"),hint:t("settings.remoteInstances.page.field.installMethodHint")})}),s.jsxs(ps,{value:v.remoteOpenchamber.installMethod,onValueChange:U=>we(de=>({...de,remoteOpenchamber:{...de.remoteOpenchamber,installMethod:U==="npm"||U==="download_release"||U==="upload_bundle"?U:"bun"}})),children:[s.jsx(fs,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(ys,{placeholder:t("settings.remoteInstances.page.field.selectInstallMethodPlaceholder")})}),s.jsxs(hs,{children:[s.jsx(Ot,{value:"bun",children:"bun"}),s.jsx(Ot,{value:"npm",children:"npm"}),s.jsx(Ot,{value:"download_release",children:t("settings.remoteInstances.page.field.installMethodDownloadRelease")}),s.jsx(Ot,{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(sa,{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(Jl,{checked:v.remoteOpenchamber.keepRunning,onCheckedChange:U=>we(de=>({...de,remoteOpenchamber:{...de.remoteOpenchamber,keepRunning:U}}))})})]}):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(sa,{label:t("settings.remoteInstances.page.field.bindHost"),hint:t("settings.remoteInstances.page.field.bindHostHint")})}),s.jsxs(ps,{value:v.localForward.bindHost,onValueChange:U=>{U==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces"))||we(de=>({...de,localForward:{...de.localForward,bindHost:U==="localhost"||U==="0.0.0.0"?U:"127.0.0.1"}}))},children:[s.jsx(fs,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(ys,{placeholder:t("settings.remoteInstances.page.field.selectBindHostPlaceholder")})}),s.jsxs(hs,{children:[s.jsx(Ot,{value:"127.0.0.1",children:"127.0.0.1"}),s.jsx(Ot,{value:"localhost",children:"localhost"}),s.jsx(Ot,{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(sa,{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(jn,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-20 tabular-nums",value:v.localForward.preferredLocalPort,onValueChange:U=>{we(de=>({...de,localForward:{...de.localForward,preferredLocalPort:Number.isFinite(U)&&U>0?U:void 0}}))},onClear:()=>{we(U=>({...U,localForward:{...U.localForward,preferredLocalPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")}),s.jsx(je,{type:"button",variant:"outline",size:"xs",className:"!font-normal h-7 w-7 px-0",title:t("settings.remoteInstances.page.actions.pickRandomPort"),onClick:()=>we(U=>({...U,localForward:{...U.localForward,preferredLocalPort:au()}})),children:s.jsx(ky,{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(Vt,{className:"h-7 md:max-w-sm",type:"password",value:v.auth.sshPassword?.value||"",onChange:U=>we(de=>({...de,auth:{...de.auth,sshPassword:{enabled:U.target.value.trim().length>0,value:U.target.value,store:de.auth.sshPassword?.store||"never"}}})),placeholder:t("settings.remoteInstances.page.field.sshPasswordPlaceholder")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5 py-1.5 md:flex-row md:items-center md:gap-8",children:[s.jsx("span",{className:"typography-ui-label text-foreground w-56 shrink-0",children:t("settings.remoteInstances.page.field.uiPasswordOptional")}),s.jsx(Vt,{className:"h-7 md:max-w-sm",type:"password",value:v.auth.openchamberPassword?.value||"",onChange:U=>we(de=>({...de,auth:{...de.auth,openchamberPassword:{enabled:U.target.value.trim().length>0,value:U.target.value,store:de.auth.openchamberPassword?.store||"never"}}})),placeholder:t("settings.remoteInstances.page.field.uiPasswordPlaceholder")})]})]})]}),s.jsxs("div",{className:"mb-8 border-t border-[var(--surface-subtle)] pt-8",children:[s.jsxs("div",{className:"mb-1 px-1 space-y-0.5",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.remoteInstances.page.section.portForwards")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.section.portForwardsDescription")})]}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[v.portForwards.length===0?s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:t("settings.remoteInstances.page.empty.noExtraForwards")}):null,v.portForwards.map((U,de)=>{const Re=et=>{we(ct=>({...ct,portForwards:ct.portForwards.map((lt,ye)=>ye===de?et(lt):lt)}))},Le=U.type==="remote"?"Local target":"Local listen",se=U.type==="remote"?"Local host and port on your machine that receives traffic from remote -R listener.":"Local host and port where this forward listens on your machine.",ie=U.type==="remote"?"Remote listen":"Remote target",K=U.type==="remote"?"Remote host and port where SSH creates the -R listener.":"Remote host and port that receives traffic from local -L listener.",_e=pf(U.localHost||"localhost",U.localPort),He=pf(U.remoteHost||"localhost",U.remotePort),Ke=U.type==="local"&&typeof U.localPort=="number"&&U.localPort>0,Ze=Ke?`http://${h4(U.localHost)}:${U.localPort}`:"",Xe=!!O[U.id],mt=U.type==="local"?t("settings.remoteInstances.page.forwardType.local"):U.type==="remote"?t("settings.remoteInstances.page.forwardType.remote"):t("settings.remoteInstances.page.forwardType.dynamic");return s.jsxs(yr,{open:Xe,onOpenChange:et=>{L(ct=>({...ct,[U.id]:et}))},className:`${de>0?"border-t border-[var(--surface-subtle)]":""} py-2`,children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("div",{className:"min-w-0 flex items-center gap-2",children:s.jsxs(Mr,{className:"flex items-center gap-2 group",children:[s.jsx(Cs,{className:`h-4 w-4 text-muted-foreground transition-transform ${Xe?"rotate-180":""}`}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:u4(U)}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:mt})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Jl,{checked:U.enabled,onCheckedChange:et=>Re(ct=>({...ct,enabled:et})),"aria-label":t("settings.remoteInstances.page.actions.enableForwardAria")}),s.jsx(je,{type:"button",variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0 text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>we(et=>({...et,portForwards:et.portForwards.filter(ct=>ct.id!==U.id)})),children:s.jsx(sn,{className:"h-3.5 w-3.5"})})]})]}),s.jsx(vr,{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(f4(U.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(sa,{label:t("settings.remoteInstances.page.field.forwardType"),hint:t("settings.remoteInstances.page.field.forwardTypeHint")})}),s.jsxs(ps,{value:U.type,onValueChange:et=>Re(ct=>({...ct,type:et==="dynamic"||et==="remote"?et:"local"})),children:[s.jsx(fs,{className:"h-7 w-fit min-w-[140px]",children:s.jsx(ys,{placeholder:t("settings.remoteInstances.page.field.typePlaceholder")})}),s.jsxs(hs,{children:[s.jsx(Ot,{value:"local",children:t("settings.remoteInstances.page.forwardType.local")}),s.jsx(Ot,{value:"remote",children:t("settings.remoteInstances.page.forwardType.remote")}),s.jsx(Ot,{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(sa,{label:Le,hint:se})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Vt,{className:"h-7 w-32",value:U.localHost||"127.0.0.1",onChange:et=>Re(ct=>({...ct,localHost:et.target.value})),placeholder:t("settings.remoteInstances.page.field.localHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(jn,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-16 tabular-nums",value:U.localPort,onValueChange:et=>{Re(ct=>({...ct,localPort:Number.isFinite(et)&&et>0?et:void 0}))},onClear:()=>{Re(et=>({...et,localPort:void 0}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]})]}),U.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(sa,{label:ie,hint:K})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Vt,{className:"h-7 w-32",value:U.remoteHost||"",onChange:et=>Re(ct=>({...ct,remoteHost:et.target.value})),placeholder:t("settings.remoteInstances.page.field.remoteHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(jn,{containerClassName:"w-fit",min:1,max:65535,step:1,className:"w-16 tabular-nums",value:U.remotePort,onValueChange:et=>{Re(ct=>({...ct,remotePort:Number.isFinite(et)&&et>0?et:void 0}))},onClear:()=>{Re(et=>({...et,remotePort:void 0}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]})]}):null,s.jsxs("div",{className:"mt-2 flex flex-wrap items-center justify-between gap-2 rounded-md bg-[var(--surface-subtle)] p-2",children:[s.jsx("div",{className:"flex flex-wrap items-center gap-1 typography-micro text-muted-foreground/80",children:U.type==="dynamic"?s.jsxs(s.Fragment,{children:[s.jsx(Rc,{className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:_e}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.localSocks5")})]}):U.type==="remote"?s.jsxs(s.Fragment,{children:[s.jsx(ei,{className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:He}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")}),s.jsx(lm,{className:"h-3.5 w-3.5"}),s.jsx(Rc,{className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:_e}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")})]}):s.jsxs(s.Fragment,{children:[s.jsx(Rc,{className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:_e}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")}),s.jsx(lm,{className:"h-3.5 w-3.5"}),s.jsx(ei,{className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:He}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")})]})}),Ke?s.jsxs(je,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{lr(Ze).then(et=>{et||q.error(t("settings.remoteInstances.page.toast.openLocalEndpointFailed"))})},children:[s.jsx(Ir,{className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.openLocal")]}):null]})]})})]},U.id)}),s.jsxs(je,{type:"button",variant:"outline",size:"xs",className:"!font-normal mt-1",onClick:()=>{const U=m4();we(de=>({...de,portForwards:[...de.portForwards,U]})),L(de=>({...de,[U.id]:!0}))},children:[s.jsx(_s,{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((U,de)=>s.jsxs("div",{className:`flex items-center justify-between gap-2 px-1 py-2 ${de>0?"border-t border-[var(--surface-subtle)]":""}`,children:[s.jsxs("div",{className:"min-w-0",children:[s.jsxs("div",{className:"typography-ui-label text-foreground truncate",children:[U.host,U.pattern?" (pattern)":""]}),s.jsx("div",{className:"typography-micro text-muted-foreground truncate",children:U.sshCommand})]}),s.jsx(je,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{oe(U.host,U.pattern)},children:t("settings.common.actions.import")})]},`${U.source}:${U.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(je,{type:"button",size:"xs",className:"!font-normal",onClick:()=>{_()},disabled:!me||i,children:t("settings.common.actions.saveChanges")}),ge?.localUrl?s.jsxs(s.Fragment,{children:[s.jsxs(je,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{_n(ge.localUrl||"").then(U=>{U.ok&&q.success(t("settings.remoteInstances.page.toast.localUrlCopied"))})},children:[s.jsx(br,{className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.copyLocalUrl")]}),s.jsxs(je,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{he()},children:[s.jsx(Ir,{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:A,onOpenChange:j,children:s.jsxs(vs,{className:"sm:max-w-2xl",children:[s.jsxs(Is,{children:[s.jsx(Ss,{children:t("settings.remoteInstances.page.logsDialog.title")}),s.jsx(Os,{children:v?.nickname?.trim()||v?.sshParsed?.destination||v?.id||t("settings.remoteInstances.page.logsDialog.selectedInstanceFallback")})]}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsxs(je,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:ke,disabled:C||!fe.trim(),children:[s.jsx(br,{className:"h-3.5 w-3.5"}),t("settings.common.actions.copyAll")]}),s.jsxs(je,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{xe()},disabled:C,children:[s.jsx(sn,{className:"h-3.5 w-3.5"}),t("settings.common.actions.clear")]})]}),C?s.jsx("div",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.logsDialog.loading")}):R?s.jsx("div",{className:"typography-meta text-[var(--status-error)]",children:R}):s.jsx("pre",{className:"max-h-[55vh] overflow-auto rounded-md border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3 typography-micro text-foreground whitespace-pre-wrap break-words",children:P.length>0?P.join(`
86
- `):t("settings.remoteInstances.page.logsDialog.empty")})]})}),s.jsx(ws,{open:!!D,onOpenChange:U=>{U||Q()},children:s.jsxs(vs,{className:"sm:max-w-md",children:[s.jsxs(Is,{children:[s.jsx(Ss,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx(Os,{children:D?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:D}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:U=>{U.preventDefault(),Z()},children:[s.jsx(Vt,{value:M,onChange:U=>$(U.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(je,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Q,disabled:F,children:t("settings.common.actions.cancel")}),s.jsx(je,{type:"submit",size:"xs",className:"!font-normal",disabled:F,children:t("settings.common.actions.create")})]})]})]})})]})},v4="__add_provider__",w4=()=>{const t=Dn.getDirectory();return typeof t=="string"&&t.trim().length>0?t.trim():null},j4=({onItemSelect:t})=>{const{t:e}=ut(),n=yt(h=>h.providers),r=yt(h=>h.selectedProviderId),a=yt(h=>h.setSelectedProvider),i=Fs(h=>h.activeProjectId),[o,c]=l.useState({}),d=l.useMemo(()=>w4(),[i]);l.useEffect(()=>{if(n.length===0){c({});return}let h=!1;return(async()=>{const f=n.map(async y=>{try{const x=d?`?directory=${encodeURIComponent(d)}`:"",g=await fetch(`/api/provider/${encodeURIComponent(y.id)}/source${x}`,{method:"GET",headers:{Accept:"application/json"}});if(!g.ok)return;const w=await g.json().catch(()=>null),v=w?.sources??w?.data?.sources;if(!v||h)return;c(S=>({...S,[y.id]:v}))}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:pe("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(Go,{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(je,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:()=>{a(v4),t?.()},"aria-label":e("settings.providers.sidebar.actions.connectProviderAria"),title:e("settings.providers.sidebar.actions.connectProviderTitle"),children:s.jsx(_s,{className:"h-3.5 w-3.5"})})]})]}),s.jsx(Es,{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(Sa,{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(ff,{provider:h,selectedProviderId:r,onSelect:()=>{a(h.id),t?.()}},h.id))]}),m.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:pe("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(ff,{provider:h,selectedProviderId:r,onSelect:()=>{a(h.id),t?.()}},h.id))]})]})})]})},ff=t=>{const e=nt.c(17),{provider:n,selectedProviderId:r,onSelect:a}=t,i=Array.isArray(n.models)?n.models.length:0,o=n.id===r,c=n.id,d=o?"bg-interactive-selection":"hover:bg-interactive-hover";let p;e[0]!==d?(p=pe("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(Bn,{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 y;return e[13]!==n.id||e[14]!==p||e[15]!==f?(y=s.jsx("div",{className:p,children:f},c),e[13]=n.id,e[14]=p,e[15]=f,e[16]=y):y=e[16],y},N4=new Intl.NumberFormat("en-US",{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}),hf=t=>{if(typeof t!="number"||Number.isNaN(t))return null;if(t===0)return"0";const e=N4.format(t);return e.endsWith(".0")?e.slice(0,-2):e},hl="__add_provider__",Ji=t=>typeof t=="object"&&t!==null,gf=t=>{const e=typeof t.type=="string"?t.type:"",n=`${t.name??""} ${t.label??""}`.toLowerCase(),r=`${e} ${n}`.toLowerCase();return r.includes("oauth")?"oauth":r.includes("api")?"api":e.toLowerCase()},S4=t=>{if(!Ji(t))return{};const e={};for(const[n,r]of Object.entries(t))Array.isArray(r)&&(e[n]=r.filter(a=>Ji(a)));return e},k4=t=>{if(typeof t=="string")return{id:t};if(!Ji(t))return null;const e=typeof t.id=="string"&&t.id||typeof t.providerID=="string"&&t.providerID||typeof t.slug=="string"&&t.slug||typeof t.name=="string"&&t.name;if(!e)return null;const n=typeof t.name=="string"?t.name:void 0;return{id:e,name:n}},C4=t=>{let e=[];Array.isArray(t)?e=t:Ji(t)&&(Array.isArray(t.all)?e=t.all:Array.isArray(t.providers)&&(e=t.providers));const n=e.map(a=>k4(a)).filter(a=>!!a),r=new Set;return n.filter(a=>r.has(a.id)?!1:(r.add(a.id),!0))},I4=()=>{const{t}=ut(),e=yt(Q=>Q.providers),n=yt(Q=>Q.selectedProviderId),r=yt(Q=>Q.setSelectedProvider),a=yt(Q=>Q.getModelMetadata),i=Te(Q=>Q.hiddenModels),o=Te(Q=>Q.toggleHiddenModel),c=Te(Q=>Q.hideAllModels),d=Te(Q=>Q.showAllModels),[p,m]=l.useState({}),[u,h]=l.useState(!1),[b,f]=l.useState({}),[y,x]=l.useState(null),[g,w]=l.useState(""),[v,S]=l.useState(null),[A,j]=l.useState({}),[C,I]=l.useState({}),[R,k]=l.useState([]),[P,N]=l.useState(!1),[D,T]=l.useState(null),[M,$]=l.useState(""),[F,V]=l.useState(""),[O,L]=l.useState(!1),[W,B]=l.useState({}),[ne,le]=l.useState(!1);l.useEffect(()=>{!n&&e.length>0&&r(e[0].id)},[e,n,r]),l.useEffect(()=>{let Q=!0;return(async()=>{h(!0);try{const Z=await fetch("/api/provider/auth",{method:"GET",headers:{Accept:"application/json"}});if(!Z.ok)throw new Error(`Auth methods request failed (${Z.status})`);const Ie=await Z.json().catch(()=>({}));if(!Q)return;m(S4(Ie))}catch(Z){if(!Q)return;console.error("Failed to load provider auth methods:",Z),q.error(t("settings.providers.page.toast.authMethodsLoadFailed"))}finally{Q&&h(!1)}})(),()=>{Q=!1}},[t]),l.useEffect(()=>{let Q=!0;return(async()=>{N(!0),T(null);try{const Z=await fetch("/api/provider",{method:"GET",headers:{Accept:"application/json"}});if(!Z.ok)throw new Error(`Provider list request failed (${Z.status})`);const Ie=await Z.json().catch(()=>({}));if(!Q)return;k(C4(Ie))}catch(Z){if(!Q)return;console.error("Failed to load available providers:",Z),T(t("settings.providers.page.state.unableToLoadProviderList"))}finally{Q&&N(!1)}})(),()=>{Q=!1}},[t]);const ee=l.useMemo(()=>new Set(e.map(Q=>Q.id)),[e]),ae=l.useMemo(()=>R.filter(Q=>!ee.has(Q.id)).sort((Q,oe)=>{const Z=(Q.name||Q.id).toLowerCase(),Ie=(oe.name||oe.id).toLowerCase();return Z.localeCompare(Ie)}),[R,ee]);l.useEffect(()=>{n===hl&&M&&!ae.some(Q=>Q.id===M)&&$("")},[n,M,ae]),l.useEffect(()=>{if(n===hl){le(!0);return}le(!1)},[n,t]),l.useEffect(()=>{if(!n||n===hl)return;let Q=!1;return(async()=>{try{const Z=await fetch(`/api/provider/${encodeURIComponent(n)}/source`,{method:"GET",headers:{Accept:"application/json"}}),Ie=await Z.json().catch(()=>null);if(!Z.ok)throw new Error(Ie?.error||t("settings.providers.page.toast.providerSourcesLoadFailed"));const Se=Ie?.sources??Ie?.data?.sources;!Q&&Se&&B(Y=>({...Y,[n]:Se}))}catch(Z){Q||console.error("Failed to load provider sources:",Z)}})(),()=>{Q=!0}},[n,t]);const ge=e.find(Q=>Q.id===n),te=n?W[n]:void 0,E=async Q=>{const oe=b[Q]?.trim()??"";if(!oe){q.error(t("settings.providers.page.toast.apiKeyRequired"));return}const Z=`api:${Q}`;x(Z);try{const Ie=await fetch(`/api/auth/${encodeURIComponent(Q)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"api",key:oe})}),Se=await Ie.json().catch(()=>null);if(!Ie.ok){const Y=Se?.error||t("settings.providers.page.toast.apiKeySaveFailed");throw new Error(Y)}q.success(t("settings.providers.page.toast.apiKeySaved")),f(Y=>({...Y,[Q]:""})),await No({scopes:["providers"],mode:"active"}),r(Q)}catch(Ie){console.error("Failed to save API key:",Ie),q.error(t("settings.providers.page.toast.apiKeySaveFailed"))}finally{x(null)}},z=async(Q,oe)=>{const Z=`oauth:${Q}:${oe}`;x(Z);try{const Ie=await fetch(`/api/provider/${encodeURIComponent(Q)}/oauth/authorize`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({method:oe})}),Se=await Ie.json().catch(()=>null);if(!Ie.ok){const Be=Se?.error||t("settings.providers.page.toast.oauthStartFailed");throw new Error(Be)}const Y=Ji(Se)?Se:{},fe=Ji(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,xe=typeof fe.instructions=="string"&&fe.instructions||typeof fe.message=="string"&&fe.message||void 0,he=typeof fe.user_code=="string"&&fe.user_code||typeof fe.code=="string"&&fe.code||typeof fe.userCode=="string"&&fe.userCode||void 0;if(!ke&&!xe&&!he)throw new Error(t("settings.providers.page.toast.oauthDetailsMissing"));const Pe=`${Q}:${oe}`;I(Be=>({...Be,[Pe]:{url:ke,instructions:xe,userCode:he}})),ke&&lr(ke),S({providerId:Q,methodIndex:oe}),q.message(t("settings.providers.page.toast.completeOAuthInBrowser"))}catch(Ie){console.error("Failed to start OAuth flow:",Ie),q.error(t("settings.providers.page.toast.oauthStartFailed"))}finally{x(null)}},J=async(Q,oe)=>{const Z=`${Q}:${oe}`,Ie=A[Z]?.trim(),Se=`oauth-complete:${Q}:${oe}`;x(Se);try{const Y={method:oe};Ie&&(Y.code=Ie);const fe=await fetch(`/api/provider/${encodeURIComponent(Q)}/oauth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Y)}),ke=await fe.json().catch(()=>null);if(!fe.ok){const xe=ke?.error||t("settings.providers.page.toast.oauthCompleteFailed");throw new Error(xe)}q.success(t("settings.providers.page.toast.oauthCompleted")),j(xe=>({...xe,[Z]:""})),S(null),await No({scopes:["providers"],mode:"active"}),r(Q)}catch(Y){console.error("Failed to complete OAuth flow:",Y),q.error(t("settings.providers.page.toast.oauthCompleteFailed"))}finally{x(null)}},H=async Q=>{const oe=await _n(Q);if(oe.ok){q.success(t("settings.providers.page.toast.oauthLinkCopied"));return}console.error("Failed to copy OAuth link:",oe.error),q.error(t("settings.providers.page.toast.oauthLinkCopyFailed"))},re=async Q=>{const oe=await _n(Q);if(oe.ok){q.success(t("settings.providers.page.toast.deviceCodeCopied"));return}console.error("Failed to copy device code:",oe.error),q.error(t("settings.providers.page.toast.deviceCodeCopyFailed"))},ce=async Q=>{const oe=`disconnect:${Q}`;x(oe);try{const Z=await fetch(`/api/provider/${encodeURIComponent(Q)}/auth?scope=all`,{method:"DELETE",headers:{"Content-Type":"application/json"}}),Ie=await Z.json().catch(()=>null);if(!Z.ok){const Se=Ie?.error||t("settings.providers.page.toast.providerDisconnectFailed");throw new Error(Se)}q.success(t("settings.providers.page.toast.providerDisconnected")),await No({scopes:["providers"],mode:"active"})}catch(Z){console.error("Failed to disconnect provider:",Z),q.error(t("settings.providers.page.toast.providerDisconnectFailed"))}finally{x(null)}},Ne=n===hl;if(!Ne&&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(Sa,{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(Ne)return s.jsx(Es,{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")}),P?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.state.loading")}):D?s.jsx("p",{className:"typography-meta text-muted-foreground",children:D}):ae.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.connect.allProvidersConnected")}):s.jsxs(zs,{open:O,onOpenChange:Q=>{L(Q),Q||V("")},children:[s.jsx(Bs,{asChild:!0,children:s.jsxs("button",{type:"button",className:pe("flex items-center justify-between gap-2 rounded-lg border border-input bg-transparent px-2 py-2 typography-ui-label whitespace-nowrap shadow-none outline-none hover:bg-interactive-hover h-6 w-fit"),children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[M?s.jsx(Bn,{providerId:M,className:"h-3.5 w-3.5 flex-shrink-0"}):null,s.jsx("span",{className:pe("truncate typography-ui-label font-normal",M?"text-foreground":"text-muted-foreground"),children:M?ae.find(Q=>Q.id===M)?.name||M:t("settings.providers.page.connect.selectProviderPlaceholder")})]}),s.jsx(Cs,{className:"h-4 w-4 flex-shrink-0 text-muted-foreground/50"})]})}),s.jsxs(Vs,{align:"start",className:"w-[280px] p-0",onCloseAutoFocus:Q=>Q.preventDefault(),children:[s.jsxs("div",{className:"flex items-center gap-2 border-b border-[var(--surface-subtle)] px-3 py-2",onKeyDown:Q=>Q.stopPropagation(),children:[s.jsx(Hn,{className:"h-4 w-4 text-muted-foreground"}),s.jsx("input",{type:"text",value:F,onChange:Q=>V(Q.target.value),onKeyDown:Q=>Q.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(Es,{outerClassName:"max-h-[240px]",className:"p-1",children:(()=>{const Q=ae.filter(oe=>{const Z=F.toLowerCase();return(oe.name||oe.id).toLowerCase().includes(Z)||oe.id.toLowerCase().includes(Z)});return Q.length===0?s.jsx("p",{className:"py-4 text-center typography-meta text-muted-foreground",children:t("settings.providers.page.connect.noProvidersFound")}):Q.map(oe=>s.jsxs($t,{onSelect:()=>{$(oe.id),L(!1),V("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(Bn,{providerId:oe.id,className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:oe.name||oe.id})]}),M===oe.id&&s.jsx(Ys,{className:"h-4 w-4 text-[var(--primary-base)]"})]},oe.id))})()})]})]})]})})]}),M&&s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h2",{className:"typography-ui-header font-medium text-foreground",children:t("settings.providers.page.auth.title")})}),u?s.jsx("p",{className:"typography-meta text-muted-foreground px-2",children:t("settings.providers.page.auth.loadingMethods")}):s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-4",children:[s.jsxs("div",{className:"py-1.5",children:[s.jsxs("label",{className:"typography-ui-label text-foreground flex items-center gap-1.5",children:[t("settings.providers.page.auth.apiKeyLabel"),s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{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(Vt,{type:"password",value:b[M]??"",onChange:Q=>f(oe=>({...oe,[M]:Q.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(je,{size:"xs",className:"!font-normal shrink-0",onClick:()=>E(M),disabled:y===`api:${M}`,children:y===`api:${M}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}),(()=>{const oe=(p[M]??[]).filter(Z=>gf(Z)==="oauth");return oe.length===0?null:s.jsx("div",{className:"space-y-4 border-t border-[var(--surface-subtle)] pt-2",children:oe.map((Z,Ie)=>{const Se=Z.label||Z.name||t("settings.providers.page.auth.oauthMethodFallback",{index:String(Ie+1)}),Y=`${M}:${Ie}`,fe=v?.providerId===M&&v?.methodIndex===Ie;return s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:Se}),(Z.description||Z.help)&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:String(Z.description||Z.help)})]}),s.jsx(je,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>z(M,Ie),disabled:y===`oauth:${M}:${Ie}`,children:t("settings.providers.page.actions.connect")})]}),C[Y]?.instructions&&s.jsx("p",{className:"typography-meta text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-2 py-1.5 rounded",children:C[Y]?.instructions}),C[Y]?.userCode&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Vt,{value:C[Y]?.userCode,readOnly:!0,className:"font-mono text-center tracking-widest"}),s.jsx(je,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>re(C[Y]?.userCode??""),children:t("settings.providers.page.actions.copyCode")})]}),C[Y]?.url&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Vt,{value:C[Y]?.url,readOnly:!0,className:"text-xs text-muted-foreground"}),s.jsxs("div",{className:"flex gap-1 shrink-0",children:[s.jsx(je,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>lr(C[Y]?.url??""),children:t("settings.providers.page.actions.open")}),s.jsx(je,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>H(C[Y]?.url??""),children:t("settings.providers.page.actions.copy")})]})]}),fe&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Vt,{value:A[Y]??"",onChange:ke=>j(xe=>({...xe,[Y]:ke.target.value})),placeholder:t("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs"}),s.jsx(je,{size:"xs",className:"!font-normal",onClick:()=>J(M,Ie),disabled:y===`oauth-complete:${M}:${Ie}`,children:y===`oauth-complete:${M}:${Ie}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.complete")})]})]},`${M}-${Se}`)})})})()]})]})]})});if(!ge)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(Sa,{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 me=Array.isArray(ge.models)?ge.models:[],_=(p[ge.id]??[]).filter(Q=>gf(Q)==="oauth"),ue=me.filter(Q=>{const oe=typeof Q?.name=="string"?Q.name:"",Z=typeof Q?.id=="string"?Q.id:"",Ie=g.trim().toLowerCase();return Ie?oe.toLowerCase().includes(Ie)||Z.toLowerCase().includes(Ie):!0});return s.jsx(Es,{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(Bn,{providerId:ge.id,className:"h-5 w-5 shrink-0"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:ge.name||ge.id}),s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:s.jsx("span",{className:"font-mono",children:ge.id})})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 px-1 flex items-center justify-between gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.providers.page.auth.title")}),s.jsx(je,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>le(Q=>!Q),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(St,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{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(Vt,{type:"password",value:b[ge.id]??"",onChange:Q=>f(oe=>({...oe,[ge.id]:Q.target.value})),placeholder:t("settings.providers.page.auth.apiKeyPlaceholder"),className:"flex-1 font-mono text-xs"}),s.jsx(je,{size:"xs",className:"!font-normal shrink-0",onClick:()=>E(ge.id),disabled:y===`api:${ge.id}`,children:y===`api:${ge.id}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}),_.length>0&&s.jsx("div",{className:"space-y-4 border-t border-[var(--surface-subtle)] pt-2",children:_.map((Q,oe)=>{const Z=Q.label||Q.name||t("settings.providers.page.auth.oauthMethodFallback",{index:String(oe+1)}),Ie=`${ge.id}:${oe}`,Se=v?.providerId===ge.id&&v?.methodIndex===oe;return s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:Z}),(Q.description||Q.help)&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:String(Q.description||Q.help)})]}),s.jsx(je,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>z(ge.id,oe),disabled:y===`oauth:${ge.id}:${oe}`,children:t("settings.providers.page.actions.connect")})]}),C[Ie]?.instructions&&s.jsx("p",{className:"typography-meta text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-2 py-1.5 rounded",children:C[Ie]?.instructions}),C[Ie]?.userCode&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Vt,{value:C[Ie]?.userCode,readOnly:!0,className:"font-mono text-center tracking-widest"}),s.jsx(je,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>re(C[Ie]?.userCode??""),children:t("settings.providers.page.actions.copyCode")})]}),C[Ie]?.url&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Vt,{value:C[Ie]?.url,readOnly:!0,className:"text-xs text-muted-foreground"}),s.jsxs("div",{className:"flex gap-1 shrink-0",children:[s.jsx(je,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>lr(C[Ie]?.url??""),children:t("settings.providers.page.actions.open")}),s.jsx(je,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>H(C[Ie]?.url??""),children:t("settings.providers.page.actions.copy")})]})]}),Se&&s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[s.jsx(Vt,{value:A[Ie]??"",onChange:Y=>j(fe=>({...fe,[Ie]:Y.target.value})),placeholder:t("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs"}),s.jsx(je,{size:"xs",className:"!font-normal",onClick:()=>J(ge.id,oe),disabled:y===`oauth-complete:${ge.id}:${oe}`,children:y===`oauth-complete:${ge.id}:${oe}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.complete")})]})]},`${ge.id}-${Z}`)})})]}):s.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[s.jsx(Ys,{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:te&&(te.auth.exists||te.user.exists||te.project.exists||te.custom?.exists)?s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[t("settings.providers.page.connectionDetails.configuredIn")," ",[te.auth.exists?t("settings.providers.page.connectionDetails.source.authCredentials"):null,te.user.exists?t("settings.providers.page.connectionDetails.source.userConfig"):null,te.project.exists?t("settings.providers.page.connectionDetails.source.projectConfig"):null,te.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(je,{variant:"ghost",size:"xs",className:"!font-normal text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>ce(ge.id),disabled:y===`disconnect:${ge.id}`,children:y===`disconnect:${ge.id}`?t("settings.providers.page.actions.disconnecting"):t("settings.providers.page.actions.disconnect")})]})})]}),s.jsxs("div",{className:"mb-8",children:[s.jsxs("div",{className:"mb-1 px-1 flex items-center justify-between gap-2",children:[s.jsxs("h3",{className:"typography-ui-header font-medium text-foreground",children:[t("settings.providers.page.models.title"),me.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",me.length,")"]})]}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(je,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const Q=me.map(oe=>typeof oe?.id=="string"?oe.id:"").filter(oe=>oe.length>0);c(ge.id,Q)},children:t("settings.providers.page.actions.hideAll")}),s.jsx(je,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>d(ge.id),children:t("settings.providers.page.actions.showAll")})]})]}),s.jsxs("section",{className:"px-2 pb-2 pt-0",children:[s.jsxs("div",{className:"relative mb-2",children:[s.jsx(Hn,{className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Vt,{value:g,onChange:Q=>w(Q.target.value),placeholder:t("settings.providers.page.models.filterPlaceholder"),className:"h-7 pl-8 w-full"})]}),ue.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground py-4 text-center",children:t("settings.providers.page.models.noModelsMatchFilter")}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:ue.map(Q=>{const oe=typeof Q?.id=="string"?Q.id:"",Z=typeof Q?.name=="string"?Q.name:oe,Ie=oe?a(ge.id,oe):void 0,Se=i.some(xe=>xe.providerID===ge.id&&xe.modelID===oe),Y=hf(Ie?.limit?.context),fe=hf(Ie?.limit?.output),ke=[];return Ie?.tool_call&&ke.push({key:"tools",icon:Dh,label:t("settings.providers.page.models.capability.toolCalling")}),Ie?.reasoning&&ke.push({key:"reasoning",icon:Ao,label:t("settings.providers.page.models.capability.reasoning")}),Ie?.attachment&&ke.push({key:"image",icon:Jh,label:t("settings.providers.page.models.capability.imageInput")}),s.jsx("div",{className:"py-1.5",children:s.jsxs("div",{className:pe("flex items-center gap-3",Se&&"opacity-50"),children:[s.jsx("span",{className:"typography-meta font-medium text-foreground truncate flex-1 min-w-0",children:Z}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[(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:xe,icon:he,label:Pe})=>s.jsx("span",{className:"flex h-5 w-5 rounded items-center justify-center text-muted-foreground bg-[var(--surface-muted)]",title:Pe,"aria-label":Pe,children:s.jsx(he,{className:"h-3 w-3"})},xe))}),s.jsx("button",{type:"button",onClick:()=>o(ge.id,oe),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(Se?"settings.providers.page.models.actions.showModelInSelectors":"settings.providers.page.models.actions.hideModelFromSelectors"),"aria-label":t(Se?"settings.providers.page.models.actions.showModel":"settings.providers.page.models.actions.hideModel"),children:Se?s.jsx(Pu,{className:"h-3.5 w-3.5"}):s.jsx(Au,{className:"h-3.5 w-3.5"})})]})]})},oe)})})]})]})]})})},A4=t=>{const e=t?.windows??{},n=Object.values(e).map(r=>r.usedPercent).filter(r=>typeof r=="number");return n.length===0?null:Math.max(...n)},P4=t=>{const e=nt.c(106),{onItemSelect:n}=t,{t:r}=ut(),a=$s(D4),i=$s(T4),o=$s(M4),c=$s(R4),d=$s(E4),p=$s(F4),m=$s(O4),u=$s(L4),h=$s($4),b=$s(B4),f=$s(V4),y=$s(z4);let x,g;e[0]!==y?(x=()=>{y()},g=[y],e[0]=y,e[1]=x,e[2]=g):(x=e[1],g=e[2]),l.useEffect(x,g);const w=_4;let v;e[3]!==h?(v=he=>{h(he),w({usageAutoRefresh:he})},e[3]=h,e[4]=v):v=e[4];const S=v;let A;e[5]!==b?(A=he=>{const Pe=Number(he);Number.isFinite(Pe)&&(b(Pe),w({usageRefreshIntervalMs:Pe}))},e[5]=b,e[6]=A):A=e[6];const j=A;let C;e[7]!==f?(C=he=>{he!=="usage"&&he!=="remaining"||(f(he),w({usageDisplayMode:he}))},e[7]=f,e[8]=C):C=e[8];const I=C;let R;e[9]===Symbol.for("react.memo_cache_sentinel")?(R=pe("flex h-full flex-col","bg-background"),e[9]=R):R=e[9];let k;e[10]!==r?(k=r("settings.usage.sidebar.title"),e[10]=r,e[11]=k):k=e[11];let P;e[12]!==k?(P=s.jsx("h2",{className:"text-base font-semibold text-foreground mb-3",children:k}),e[12]=k,e[13]=P):P=e[13];let N;e[14]!==r?(N=r("settings.usage.sidebar.total",{count:Jr.length}),e[14]=r,e[15]=N):N=e[15];let D;e[16]!==N?(D=s.jsx("span",{className:"typography-meta text-muted-foreground",children:N}),e[16]=N,e[17]=D):D=e[17];let T;e[18]!==r?(T=r("settings.usage.sidebar.actions.toggleAutoRefreshAria"),e[18]=r,e[19]=T):T=e[19];let M;e[20]!==S||e[21]!==T||e[22]!==p?(M=s.jsx(St,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(bs,{checked:p,onChange:S,ariaLabel:T})})}),e[20]=S,e[21]=T,e[22]=p,e[23]=M):M=e[23];let $;e[24]!==r?($=r("settings.usage.sidebar.tooltip.autoRefresh"),e[24]=r,e[25]=$):$=e[25];let F;e[26]!==$?(F=s.jsx(Ct,{side:"bottom",children:$}),e[26]=$,e[27]=F):F=e[27];let V;e[28]!==M||e[29]!==F?(V=s.jsxs(kt,{children:[M,F]}),e[28]=M,e[29]=F,e[30]=V):V=e[30];const O=String(m),L=!p;let W;e[31]!==r?(W=r("settings.usage.sidebar.field.intervalPlaceholder"),e[31]=r,e[32]=W):W=e[32];let B;e[33]!==W?(B=s.jsx(fs,{className:"w-fit",children:s.jsx(ys,{placeholder:W})}),e[33]=W,e[34]=B):B=e[34];let ne;e[35]===Symbol.for("react.memo_cache_sentinel")?(ne=s.jsxs(hs,{children:[s.jsx(Ot,{value:"30000",children:"30s"}),s.jsx(Ot,{value:"60000",children:"1m"}),s.jsx(Ot,{value:"300000",children:"5m"})]}),e[35]=ne):ne=e[35];let le;e[36]!==j||e[37]!==O||e[38]!==L||e[39]!==B?(le=s.jsxs(ps,{value:O,onValueChange:j,disabled:L,children:[B,ne]}),e[36]=j,e[37]=O,e[38]=L,e[39]=B,e[40]=le):le=e[40];let ee;e[41]!==c?(ee=()=>c(),e[41]=c,e[42]=ee):ee=e[42];let ae;e[43]!==r?(ae=r("settings.usage.sidebar.actions.refreshAria"),e[43]=r,e[44]=ae):ae=e[44];let ge;e[45]!==r?(ge=r("settings.usage.sidebar.actions.refreshTitle"),e[45]=r,e[46]=ge):ge=e[46];const te=d&&"animate-spin";let E;e[47]!==te?(E=pe("h-3.5 w-3.5",te),e[47]=te,e[48]=E):E=e[48];let z;e[49]!==E?(z=s.jsx(Nn,{className:E}),e[49]=E,e[50]=z):z=e[50];let J;e[51]!==d||e[52]!==ee||e[53]!==ae||e[54]!==ge||e[55]!==z?(J=s.jsx(je,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 text-muted-foreground",onClick:ee,"aria-label":ae,title:ge,disabled:d,children:z}),e[51]=d,e[52]=ee,e[53]=ae,e[54]=ge,e[55]=z,e[56]=J):J=e[56];let H;e[57]!==V||e[58]!==le||e[59]!==J?(H=s.jsxs("div",{className:"flex items-center gap-2",children:[V,le,J]}),e[57]=V,e[58]=le,e[59]=J,e[60]=H):H=e[60];let re;e[61]!==D||e[62]!==H?(re=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[D,H]}),e[61]=D,e[62]=H,e[63]=re):re=e[63];let ce;e[64]!==r?(ce=r("settings.usage.sidebar.field.display"),e[64]=r,e[65]=ce):ce=e[65];let Ne;e[66]!==ce?(Ne=s.jsx("span",{className:"typography-micro text-muted-foreground",children:ce}),e[66]=ce,e[67]=Ne):Ne=e[67];let me;e[68]!==r?(me=r("settings.usage.sidebar.field.displayModePlaceholder"),e[68]=r,e[69]=me):me=e[69];let we;e[70]!==me?(we=s.jsx(fs,{className:"w-fit",children:s.jsx(ys,{placeholder:me})}),e[70]=me,e[71]=we):we=e[71];let _;e[72]!==r?(_=r("settings.usage.sidebar.field.displayModeUsage"),e[72]=r,e[73]=_):_=e[73];let ue;e[74]!==_?(ue=s.jsx(Ot,{value:"usage",children:_}),e[74]=_,e[75]=ue):ue=e[75];let Q;e[76]!==r?(Q=r("settings.usage.sidebar.field.displayModeRemaining"),e[76]=r,e[77]=Q):Q=e[77];let oe;e[78]!==Q?(oe=s.jsx(Ot,{value:"remaining",children:Q}),e[78]=Q,e[79]=oe):oe=e[79];let Z;e[80]!==ue||e[81]!==oe?(Z=s.jsxs(hs,{children:[ue,oe]}),e[80]=ue,e[81]=oe,e[82]=Z):Z=e[82];let Ie;e[83]!==I||e[84]!==we||e[85]!==Z||e[86]!==u?(Ie=s.jsxs(ps,{value:u,onValueChange:I,children:[we,Z]}),e[83]=I,e[84]=we,e[85]=Z,e[86]=u,e[87]=Ie):Ie=e[87];let Se;e[88]!==Ne||e[89]!==Ie?(Se=s.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[Ne,Ie]}),e[88]=Ne,e[89]=Ie,e[90]=Se):Se=e[90];let Y;e[91]!==re||e[92]!==Se||e[93]!==P?(Y=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[P,re,Se]}),e[91]=re,e[92]=Se,e[93]=P,e[94]=Y):Y=e[94];let fe;e[95]!==n||e[96]!==a||e[97]!==i||e[98]!==o||e[99]!==r?(fe=Jr.map(he=>{const Pe=a.find(ve=>ve.providerId===he.id),Be=A4(Pe?.usage),G=Fg(Be),be=he.id===i,De=Pe?.configured??!1,Ae=De?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:pe("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",be?"bg-interactive-selection":"hover:bg-interactive-hover"),children:s.jsxs("button",{type:"button",onClick:()=>{o(he.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(Bn,{providerId:he.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:he.name}),!De&&s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:r("settings.usage.sidebar.status.notSet")})]})},he.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(Es,{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 xe;return e[103]!==Y||e[104]!==ke?(xe=s.jsxs("div",{className:R,children:[Y,ke]}),e[103]=Y,e[104]=ke,e[105]=xe):xe=e[105],xe};function D4(t){return t.results}function T4(t){return t.selectedProviderId}function M4(t){return t.setSelectedProvider}function R4(t){return t.fetchAllQuotas}function E4(t){return t.isLoading}function F4(t){return t.autoRefresh}function O4(t){return t.refreshIntervalMs}function L4(t){return t.displayMode}function $4(t){return t.setAutoRefresh}function B4(t){return t.setRefreshInterval}function V4(t){return t.setDisplayMode}function z4(t){return t.loadSettings}async function _4(t){try{await Rs(t)}catch(e){console.warn("Failed to save usage settings:",e)}}const pd=t=>{const e=nt.c(49),{title:n,window:r,subtitle:a,showToggle:i,toggleEnabled:o,onToggle:c}=t,d=i===void 0?!1:i,p=o===void 0?!1:o,m=$s(U4),u=m==="remaining"?r.remainingPercent:r.usedPercent,h=m==="remaining"?"remaining":"used";let b;e[0]!==u||e[1]!==r.valueLabel?(b=Ro(r.valueLabel,u),e[0]=u,e[1]=r.valueLabel,e[2]=b):b=e[2];const f=b,y=r.resetAfterFormatted??r.resetAtFormatted??"";let x;e[3]!==n?(x=_u(n),e[3]=n,e[4]=x):x=e[4];const g=x;let w;e[5]!==n||e[6]!==r.resetAt||e[7]!==r.usedPercent||e[8]!==r.windowSeconds?(w=Eo(r.usedPercent,r.resetAt,r.windowSeconds,n),e[5]=n,e[6]=r.resetAt,e[7]=r.usedPercent,e[8]=r.windowSeconds,e[9]=w):w=e[9];const v=w;let S;e:{if(!v||v.dailyAllocationPercent===null){S=null;break e}const B=aa(v.elapsedRatio);S=m==="remaining"?100-B:B}const A=S;let j;e[10]!==c||e[11]!==d||e[12]!==p?(j=d&&s.jsx(bs,{checked:p,onChange:B=>c?.(B),ariaLabel:"Show in dropdown"}),e[10]=c,e[11]=d,e[12]=p,e[13]=j):j=e[13];let C;e[14]!==g?(C=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:g}),e[14]=g,e[15]=C):C=e[15];let I;e[16]!==a?(I=a&&s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:a}),e[16]=a,e[17]=I):I=e[17];let R;e[18]!==C||e[19]!==I?(R=s.jsxs("div",{className:"min-w-0 flex flex-col",children:[C,I]}),e[18]=C,e[19]=I,e[20]=R):R=e[20];let k;e[21]!==R||e[22]!==j?(k=s.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[j,R]}),e[21]=R,e[22]=j,e[23]=k):k=e[23];const P=f==="-"?"":f;let N;e[24]!==P?(N=s.jsx("div",{className:"typography-ui-label text-foreground tabular-nums flex items-center justify-end",children:P}),e[24]=P,e[25]=N):N=e[25];let D;e[26]!==k||e[27]!==N?(D=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[k,N]}),e[26]=k,e[27]=N,e[28]=D):D=e[28];let T;e[29]!==u||e[30]!==A||e[31]!==r.usedPercent?(T=s.jsx(Oo,{percent:u,tonePercent:r.usedPercent,expectedMarkerPercent:A,className:"h-1.5"}),e[29]=u,e[30]=A,e[31]=r.usedPercent,e[32]=T):T=e[32];const M=y?`Resets ${y}`:"";let $;e[33]!==M?($=s.jsx("span",{className:"typography-micro text-muted-foreground",children:M}),e[33]=M,e[34]=$):$=e[34];let F;e[35]!==h?(F=s.jsx("span",{className:"typography-micro text-muted-foreground",children:h}),e[35]=h,e[36]=F):F=e[36];let V;e[37]!==$||e[38]!==F?(V=s.jsxs("div",{className:"mt-1 flex items-center justify-between",children:[$,F]}),e[37]=$,e[38]=F,e[39]=V):V=e[39];let O;e[40]!==T||e[41]!==V?(O=s.jsxs("div",{className:"mt-2.5",children:[T,V]}),e[40]=T,e[41]=V,e[42]=O):O=e[42];let L;e[43]!==v?(L=v&&s.jsx("div",{className:"mt-1.5",children:s.jsx(Lo,{paceInfo:v})}),e[43]=v,e[44]=L):L=e[44];let W;return e[45]!==D||e[46]!==O||e[47]!==L?(W=s.jsxs("div",{className:"py-3",children:[D,O,L]}),e[45]=D,e[46]=O,e[47]=L,e[48]=W):W=e[48],W};function U4(t){return t.displayMode}const W4=t=>{if(!t)return"-";try{return new Date(t).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"})}catch{return"-"}},K4=()=>{const{t}=ut(),e=$s(N=>N.results),n=$s(N=>N.selectedProviderId),r=$s(N=>N.setSelectedProvider),a=$s(N=>N.loadSettings),i=$s(N=>N.fetchAllQuotas),o=$s(N=>N.isLoading),c=$s(N=>N.lastUpdated),d=$s(N=>N.error),p=$s(N=>N.dropdownProviderIds),m=$s(N=>N.setDropdownProviderIds),u=$s(N=>N.selectedModels),h=$s(N=>N.toggleModelSelected),b=$s(N=>N.applyDefaultSelections);Vg(),l.useEffect(()=>{a(),i()},[a,i]),l.useEffect(()=>{if(n||e.length===0)return;const N=e.find(D=>D.configured)?.providerId;r(N??Jr[0]?.id??null)},[e,n,r]);const f=e.find(N=>N.providerId===n)??null,x=Jr.find(N=>N.id===n)?.name??n??t("settings.usage.sidebar.title"),g=f?.usage,w=n?p.includes(n):!1,v=l.useCallback(N=>{if(!n)return;const D=N?Array.from(new Set([...p,n])):p.filter(T=>T!==n);m(D),Rs({usageDropdownProviders:D})},[p,n,m]),S=l.useMemo(()=>g?.models?Object.entries(g.models).map(([N,D])=>({name:N,windows:D})).filter(N=>Object.keys(N.windows.windows).length>0):[],[g?.models]);l.useEffect(()=>{n&&S.length>0&&b(n,S.map(N=>N.name))},[n,S,b]);const A=l.useMemo(()=>!n||S.length===0?new Map:fj(S,N=>N.name,n),[S,n]),j=l.useMemo(()=>{if(!n)return[];const N=$g(n);return Bg(N)},[n]),[C,I]=l.useState(()=>({})),R=l.useCallback(N=>{I(D=>({...D,[N]:!D[N]}))},[]),k=l.useCallback(N=>{if(!n)return;h(n,N);const D=u[n]??[],M=D.includes(N)?D.filter(F=>F!==N):[...D,N],$={...u,[n]:M};Rs({usageSelectedModels:$})},[n,u,h]),P=n?u[n]??[]:[];return n?s.jsx(Es,{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(Bn,{providerId:n,className:"h-5 w-5 shrink-0"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:t("settings.usage.page.header.providerUsage",{provider:x})}),s.jsx("p",{className:"typography-meta text-muted-foreground truncate",children:o?s.jsx("span",{className:"animate-pulse",children:t("settings.usage.page.header.refreshing")}):t("settings.usage.page.header.lastUpdated",{time:W4(c)})})]})]}),s.jsx("div",{className:"mb-8 px-2",children:s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":w,onClick:()=>v(!w),onKeyDown:N=>{(N.key===" "||N.key==="Enter")&&(N.preventDefault(),v(!w))},children:[s.jsx(bs,{checked:w,onChange:v,ariaLabel:t("settings.usage.page.options.showInHeaderAria")}),s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.usage.page.options.showInHeader")}),s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{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,D])=>s.jsx(pd,{title:N,window:D},N))})})}),S.length>0&&s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.usage.page.section.modelQuotas")})}),s.jsxs("div",{className:"space-y-3",children:[j.map(N=>{const D=A.get(N.id)??[];if(D.length===0)return null;const T=C[N.id]??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(yr,{open:!T,onOpenChange:()=>R(N.id),children:[s.jsxs(Mr,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:N.label}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",D.length,")"]})]}),T?s.jsx(Fn,{className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(Cs,{className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(vr,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:D.map(M=>{const $=Object.entries(M.windows.windows);if($.length===0)return null;const[F,V]=$[0],O=P.includes(M.name);return s.jsx(pd,{title:F,subtitle:Ql(M.name),window:V,showToggle:!0,toggleEnabled:O,onToggle:()=>k(M.name)},M.name)})})})]})},N.id)}),(()=>{const N=A.get(null)??[];if(N.length===0)return null;const D=C.other??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(yr,{open:!D,onOpenChange:()=>R("other"),children:[s.jsxs(Mr,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:t("settings.usage.page.section.otherModels")}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",N.length,")"]})]}),D?s.jsx(Fn,{className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(Cs,{className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(vr,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:N.map(T=>{const M=Object.entries(T.windows.windows);if(M.length===0)return null;const[$,F]=M[0],V=P.includes(T.name);return s.jsx(pd,{title:$,subtitle:Ql(T.name),window:F,showToggle:!0,toggleEnabled:V,onToggle:()=>k(T.name)},T.name)})})})]})})})()]})]}),f?.configured&&g&&Object.keys(g.windows??{}).length===0&&S.length===0&&s.jsxs("div",{className:"mb-8 px-2",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.usage.page.state.noQuotaWindowsTitle")}),s.jsx("p",{className:"typography-meta text-muted-foreground mt-1",children:t("settings.usage.page.state.noQuotaWindowsDescription")})]})]})}):s.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground",children:s.jsx("p",{className:"typography-body",children:t("settings.usage.page.empty.selectProvider")})})},H4="git.commit.generate",iu=wr(t=>({selectedPromptId:H4,setSelectedPromptId:e=>{t(n=>n.selectedPromptId===e?n:{selectedPromptId:e})}})),G4=t=>{const e=nt.c(23),{onItemSelect:n}=t,{t:r}=ut(),a=iu(q4),i=iu(Q4);let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o={groupKey:"settings.magicPrompts.sidebar.group.git",items:[{id:"git.commit.generate",titleKey:"settings.magicPrompts.sidebar.item.gitCommitGenerate"},{id:"git.pr.generate",titleKey:"settings.magicPrompts.sidebar.item.gitPrGenerate"},{id:"git.conflict.resolve",titleKey:"settings.magicPrompts.sidebar.item.gitConflictResolve"},{id:"git.integrate.cherrypick.resolve",titleKey:"settings.magicPrompts.sidebar.item.gitCherrypickConflictResolve"}]},e[0]=o):o=e[0];let c;e[1]===Symbol.for("react.memo_cache_sentinel")?(c={groupKey:"settings.magicPrompts.sidebar.group.github",items:[{id:"github.pr.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrReview"},{id:"github.issue.review",titleKey:"settings.magicPrompts.sidebar.item.githubIssueReview"},{id:"github.pr.checks.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrFailedChecksReview"},{id:"github.pr.comments.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrCommentsReview"},{id:"github.pr.comment.single",titleKey:"settings.magicPrompts.sidebar.item.githubSinglePrCommentReview"}]},e[1]=c):c=e[1];let d;e[2]===Symbol.for("react.memo_cache_sentinel")?(d={groupKey:"settings.magicPrompts.sidebar.group.planning",items:[{id:"plan.todo",titleKey:"settings.magicPrompts.sidebar.item.planTodo"},{id:"plan.improve",titleKey:"settings.magicPrompts.sidebar.item.planImprove"},{id:"plan.implement",titleKey:"settings.magicPrompts.sidebar.item.planImplement"}]},e[2]=d):d=e[2];let p;e[3]===Symbol.for("react.memo_cache_sentinel")?(p=[o,c,d,{groupKey:"settings.magicPrompts.sidebar.group.session",items:[{id:"session.summary",titleKey:"settings.magicPrompts.sidebar.item.sessionSummary"},{id:"session.review",titleKey:"settings.magicPrompts.sidebar.item.sessionWorkspaceReview"}]}],e[3]=p):p=e[3];const m=p;let u;e[4]!==r?(u=r("settings.magicPrompts.sidebar.title"),e[4]=r,e[5]=u):u=e[5];let 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 y;e[12]!==h||e[13]!==f?(y=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[h,f]}),e[12]=h,e[13]=f,e[14]=y):y=e[14];let x;e[15]!==n||e[16]!==a||e[17]!==i||e[18]!==r?(x=s.jsx(Es,{outerClassName:"flex-1 min-h-0",className:"space-y-3 px-3 py-2 overflow-x-hidden",children:m.map(w=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro px-1 text-muted-foreground",children:r(w.groupKey)}),w.items.map(v=>{const S=a===v.id;return s.jsx("button",{type:"button",onClick:()=>{i(v.id),n?.()},className:pe("flex w-full items-center rounded-md px-2 py-1.5 text-left transition-colors",S?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-ui-label truncate font-normal",children:r(v.titleKey)})},v.id)})]},w.groupKey))}),e[15]=n,e[16]=a,e[17]=i,e[18]=r,e[19]=x):x=e[19];let g;return e[20]!==x||e[21]!==y?(g=s.jsxs("div",{className:"flex h-full flex-col bg-background",children:[y,x]}),e[20]=x,e[21]=y,e[22]=g):g=e[22],g};function q4(t){return t.selectedPromptId}function Q4(t){return t.setSelectedPromptId}const xf={"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"}]}},bf=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),yf=t=>t.endsWith(".visible"),J4=()=>{const{t}=ut(),e=l.useCallback(j=>t(j),[t]),n=iu(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 I=await b1();if(!j)return;o(I)}catch(I){console.warn("Failed to load magic prompts:",I),q.error(t("settings.magicPrompts.page.toast.loadFailed"))}finally{j&&a(!1)}})(),()=>{j=!1}},[t]);const y=xf[n]??xf["git.commit.generate"],x=l.useCallback(j=>bf(i,j)?i[j]:Bc(j),[i]),g=l.useCallback(j=>c[j]??x(j),[c,x]),w=l.useCallback((j,C)=>{d(I=>I[j]===C?I:{...I,[j]:C})},[]),v=l.useCallback(async j=>{const C=g(j);if(yf(j)&&C.trim().length===0){q.error(t("settings.magicPrompts.page.toast.visiblePromptRequired"));return}m(I=>({...I,[j]:!0}));try{const I=C===Bc(j)?await Nm(j):await h1(j,C);o(I.overrides),q.success(t("settings.magicPrompts.page.toast.saved"))}catch(I){const R=I instanceof Error?I.message:String(I);q.error(t("settings.magicPrompts.page.toast.saveFailed"),{description:R})}finally{m(I=>({...I,[j]:!1}))}},[g,t]),S=l.useCallback(async j=>{h(C=>({...C,[j]:!0}));try{const C=await Nm(j);o(C.overrides),d(I=>({...I,[j]:Bc(j)})),q.success(t("settings.magicPrompts.page.toast.resetSuccess"))}catch(C){const I=C instanceof Error?C.message:String(C);q.error(t("settings.magicPrompts.page.toast.resetFailed"),{description:I})}finally{h(C=>({...C,[j]:!1}))}},[t]),A=l.useCallback(async()=>{f(!0);try{const j=await g1();o(j.overrides),d({}),q.success(t("settings.magicPrompts.page.toast.resetAllSuccess"))}catch(j){const C=j instanceof Error?j.message:String(j);q.error(t("settings.magicPrompts.page.toast.resetAllFailed"),{description:C})}finally{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(y.titleKey)}),s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:e(y.descriptionKey)})]})]})}),s.jsx(je,{variant:"outline",size:"sm",onClick:()=>{A()},disabled:b||Object.keys(i).length===0,children:t(b?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetAllOverrides")})]}),y.blocks.map((j,C)=>{const I=x1(j.id),R=x(j.id),k=g(j.id),P=bf(i,j.id),N=k!==R,D=yf(j.id)&&k.trim().length===0,T=p[j.id]===!0,M=u[j.id]===!0;return s.jsxs("section",{className:C>0?"space-y-3 pt-5 border-t border-border":"space-y-3",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-label text-foreground",children:e(j.titleKey)}),s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:I.description})]})]}),I.placeholders&&I.placeholders.length>0&&s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[t("settings.magicPrompts.page.placeholdersLabel")," ",I.placeholders.map($=>`{{${$.key}}}`).join(", ")]})]}),s.jsx(Sn,{value:k,onChange:$=>w(j.id,$.target.value),className:"min-h-[220px] font-mono text-sm"}),D&&s.jsx("div",{className:"typography-micro text-[var(--status-error)]",children:t("settings.magicPrompts.page.validation.visiblePromptRequired")}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:t(N?"settings.magicPrompts.page.status.unsavedChanges":P?"settings.magicPrompts.page.status.usingSavedOverride":"settings.magicPrompts.page.status.usingBuiltinDefault")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(je,{variant:"outline",size:"sm",onClick:()=>{S(j.id)},disabled:!P||T||M,children:t(M?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetToDefault")}),s.jsx(je,{size:"sm",onClick:()=>{v(j.id)},disabled:!N||T||M||D,children:t(T?"settings.common.actions.saving":"settings.magicPrompts.page.actions.save")})]})]})]},j.id)})]})})},Fx=()=>{const{t}=ut(),e=yt(u=>u.settingsGitmojiEnabled),n=yt(u=>u.setSettingsGitmojiEnabled),r=Ou(),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=xr()?.settings;if(b)try{const y=(await b.load())?.settings;y&&(h={gitmojiEnabled:typeof y.gitmojiEnabled=="boolean"?y.gitmojiEnabled:void 0,gitChangesViewMode:y.gitChangesViewMode==="flat"||y.gitChangesViewMode==="tree"?y.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 Rs({gitmojiEnabled:u})}catch(h){console.warn("Failed to save gitmoji setting:",h)}},[n]),m=l.useCallback(u=>{u!==a&&(i(u),Rs({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(Si,{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(bs,{checked:e,onChange:u=>{p(u)},ariaLabel:t("settings.openchamber.git.enableGitmojiAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.git.enableGitmoji")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":r,onClick:()=>Vc(!r),onKeyDown:u=>{(u.key===" "||u.key==="Enter")&&(u.preventDefault(),Vc(!r))},children:[s.jsx(bs,{checked:r,onChange:Vc,ariaLabel:t("settings.openchamber.git.showGitignoredAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.git.showGitignored")})]})]})]})},Ox=()=>{const{t}=ut(),{isMobile:e}=un(),n=xr()?.github,r=Zn(I=>I.status),a=Zn(I=>I.isLoading),i=Zn(I=>I.hasChecked),o=Zn(I=>I.refreshStatus),c=Zn(I=>I.setStatus),d=l.useCallback(async I=>{await lr(I)},[]),[p,m]=l.useState(!1),[u,h]=l.useState(null),[b,f]=l.useState(null),y=l.useRef(null),x=l.useCallback(()=>{y.current!=null&&(window.clearInterval(y.current),y.current=null),f(null)},[]);l.useEffect(()=>((async()=>{try{i||await o(n)}catch(I){console.warn("Failed to load GitHub auth status:",I)}})(),()=>{x()}),[i,o,n,x]);const g=l.useCallback(async()=>{m(!0);try{const I=n?await n.authStart():await(async()=>{const k=await fetch("/api/github/auth/start",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),P=await k.json().catch(()=>null);if(!k.ok||!P||!("deviceCode"in P))throw new Error(P?.error||k.statusText);return P})();h(I),f(Math.max(1,I.interval)*1e3);const R=I.verificationUriComplete||I.verificationUri;d(R)}catch(I){console.error("Failed to start GitHub connect:",I),q.error(t("settings.github.page.toast.startConnectFailed"))}finally{m(!1)}},[d,n,t]),w=l.useCallback(async I=>{if(n)return n.authComplete(I);const R=await fetch("/api/github/auth/complete",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({deviceCode:I})}),k=await R.json().catch(()=>null);if(!R.ok||!k)throw new Error(k?.error||R.statusText);return k},[n]);l.useEffect(()=>{if(!(!u?.deviceCode||!b)&&y.current==null)return y.current=window.setInterval(()=>{(async()=>{try{const I=await w(u.deviceCode);if(I.connected){q.success(t("settings.github.page.toast.connected")),h(null),x(),await o(n,{force:!0});return}I.status==="slow_down"&&f(R=>R?R+5e3:5e3),(I.status==="expired_token"||I.status==="access_denied")&&(q.error(I.error||t("settings.github.page.toast.authorizationFailed")),h(null),x())}catch(I){console.warn("GitHub polling failed:",I)}})()},b),()=>{y.current!=null&&(window.clearInterval(y.current),y.current=null)}},[u,b,w,o,n,x,t]);const v=l.useCallback(async()=>{m(!0);try{if(x(),h(null),n)await n.authDisconnect();else{const I=await fetch("/api/github/auth",{method:"DELETE",headers:{Accept:"application/json"}});if(!I.ok)throw new Error(I.statusText)}q.success(t("settings.github.page.toast.disconnected")),await o(n,{force:!0})}catch(I){console.error("Failed to disconnect GitHub:",I),q.error(t("settings.github.page.toast.disconnectFailed"))}finally{m(!1)}},[o,n,x,t]),S=l.useCallback(async I=>{if(I){m(!0);try{const R=n?await n.authActivate(I):await(async()=>{const k=await fetch("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:I})}),P=await k.json().catch(()=>null);if(!k.ok||!P)throw new Error(P?.error||k.statusText);return P})();c(R),q.success(t("settings.github.page.toast.accountSwitched"))}catch(R){console.error("Failed to switch GitHub account:",R),q.error(t("settings.github.page.toast.accountSwitchFailed"))}finally{m(!1)}}},[n,c,t]);if(a)return null;const A=!!r?.connected,j=r?.user,C=r?.accounts??[];return s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-3 px-1 flex items-start justify-between gap-4",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:"GitHub"}),s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{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:[A?s.jsxs("div",{className:pe("px-4 py-3",e?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[s.jsxs("div",{className:pe("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:pe("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",e?"flex-wrap":"truncate"),children:[s.jsx(wa,{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(je,{size:"sm",variant:"outline",onClick:v,disabled:p,className:pe("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(je,{size:"sm",variant:"default",onClick:g,disabled:p,children:t("settings.github.page.actions.connect")})]}),C.length>1&&s.jsxs("div",{className:"mt-2 border-t border-[var(--surface-subtle)] pt-2 px-2 pb-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground mb-2 px-1",children:t("settings.github.page.label.otherAccounts")}),s.jsx("div",{className:"space-y-1",children:C.map(I=>{const R=I.user,k=!!I.current;return s.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-[var(--surface-subtle)] bg-[var(--surface-muted)] px-3 py-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[R?.avatarUrl?s.jsx("img",{src:R.avatarUrl,alt:R.login?t("settings.github.page.avatarAlt.withLogin",{login:R.login}):t("settings.github.page.avatarAlt.fallback"),className:"h-6 w-6 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:s.jsx(wa,{className:"h-3 w-3 text-muted-foreground"})}),s.jsxs("div",{className:"min-w-0 flex flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:R?.name?.trim()||R?.login||"GitHub"}),R?.login&&s.jsx("span",{className:"typography-micro text-muted-foreground truncate font-mono",children:R.login})]})]}),k?s.jsx("span",{className:"typography-micro text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-1.5 py-0.5 rounded",children:t("settings.github.page.status.active")}):s.jsx(je,{size:"sm",variant:"ghost",onClick:()=>S(I.id),disabled:p,children:t("settings.github.page.actions.switchTo")})]},I.id)})})]})]}),A&&s.jsx("div",{className:"mt-2 px-2 pb-2",children:s.jsx(je,{size:"sm",variant:"outline",onClick:g,disabled:p,className:pe(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(je,{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(je,{size:"sm",variant:"ghost",disabled:p,onClick:()=>{x(),h(null)},children:t("settings.common.actions.cancel")})]})]})]})},vf=[{key:"keyword",label:"Green",cssVar:"var(--syntax-keyword)"},{key:"error",label:"Red",cssVar:"var(--status-error)"},{key:"string",label:"Cyan",cssVar:"var(--syntax-string)"},{key:"function",label:"Orange",cssVar:"var(--syntax-function)"},{key:"type",label:"Yellow",cssVar:"var(--syntax-type)"}],Y4=[{key:"branch",Icon:Ks,label:"Branch"},{key:"briefcase",Icon:ju,label:"Work"},{key:"house",Icon:wu,label:"Personal"},{key:"graduation",Icon:vu,label:"School"},{key:"code",Icon:cc,label:"Code"}],X4=({open:t,onOpenChange:e,profileId:n,importData:r})=>{const{t:a}=ut(),i=ar(B=>B.getProfileById),o=ar(B=>B.createProfile),c=ar(B=>B.updateProfile),d=ar(B=>B.deleteProfile),p=l.useMemo(()=>n&&n!=="new"&&!r?i(n):null,[n,i,r]),m=n==="new"||r!=null,u=n==="global",[h,b]=l.useState(""),[f,y]=l.useState(""),[x,g]=l.useState(""),[w,v]=l.useState("ssh"),[S,A]=l.useState(""),[j,C]=l.useState(""),[I,R]=l.useState("keyword"),[k,P]=l.useState("branch"),[N,D]=l.useState(!1),[T,M]=l.useState(!1),[$,F]=l.useState(!1);l.useEffect(()=>{if(t){if(r){const B=r.host.split("/"),ne=B.length>=3?B[B.length-1]:r.host;b(ne),y(r.username),g(""),v("token"),A(""),C(r.host),R("string"),P("code")}else if(m)b(""),y(""),g(""),v("ssh"),A(""),C(""),R("keyword"),P("branch");else if(p)b(p.name),y(p.userName),g(p.userEmail),v(p.authType||"ssh"),A(p.sshKey||""),C(p.host||""),R(p.color||"keyword"),P(p.icon||"branch");else if(u){const B=i("global");B&&(b(B.name),y(B.userName),g(B.userEmail),v(B.authType||"ssh"),A(B.sshKey||""),C(B.host||""),R(B.color||"keyword"),P(B.icon||"branch"))}}},[t,n,p,m,r,u,i]);const V=async()=>{if(!f.trim()||!x.trim()){q.error(a("settings.gitIdentities.editor.toast.userNameEmailRequired"));return}if(w==="token"&&!j.trim()){q.error(a("settings.gitIdentities.editor.toast.hostRequiredForToken"));return}D(!0);try{const B={name:h.trim()||f.trim(),userName:f.trim(),userEmail:x.trim(),authType:w,sshKey:w==="ssh"&&S.trim()||null,host:w==="token"&&j.trim()||null,color:I,icon:k};let ne;if(m)ne=await o(B);else if(n)ne=await c(n,B);else return;ne?(q.success(a(m?"settings.gitIdentities.editor.toast.profileCreated":"settings.gitIdentities.editor.toast.profileUpdated")),e(!1)):q.error(a(m?"settings.gitIdentities.editor.toast.createProfileFailed":"settings.gitIdentities.editor.toast.updateProfileFailed"))}catch(B){console.error("Error saving profile:",B),q.error(a("settings.gitIdentities.editor.toast.saveUnexpectedError"))}finally{D(!1)}},O=async()=>{if(!(!n||m)){F(!0);try{await d(n)?(q.success(a("settings.gitIdentities.editor.toast.profileDeleted")),M(!1),e(!1)):q.error(a("settings.gitIdentities.editor.toast.deleteProfileFailed"))}catch(B){console.error("Error deleting profile:",B),q.error(a("settings.gitIdentities.editor.toast.deleteUnexpectedError"))}finally{F(!1)}}},L=l.useMemo(()=>vf.find(ne=>ne.key===I)?.cssVar||"var(--syntax-keyword)",[I]),W=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(Is,{children:[s.jsx(Ss,{children:W}),s.jsx(Os,{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(Vt,{value:h,onChange:B=>b(B.target.value),placeholder:a("settings.gitIdentities.editor.field.profileNamePlaceholder"),className:"h-8"})]}),s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.gitIdentities.editor.field.color")}),s.jsx("div",{className:"flex gap-1.5",children:vf.map(B=>s.jsx("button",{type:"button",onClick:()=>R(B.key),className:pe("w-6 h-6 rounded-md border-2 transition-all cursor-pointer",I===B.key?"border-foreground scale-110":"border-transparent hover:border-border"),style:{backgroundColor:B.cssVar},title:B.label},B.key))})]}),s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.gitIdentities.editor.field.icon")}),s.jsx("div",{className:"flex gap-1.5",children:Y4.map(B=>{const ne=B.Icon;return s.jsx("button",{type:"button",onClick:()=>P(B.key),className:pe("w-7 h-7 rounded-md border-2 transition-all flex items-center justify-center cursor-pointer",k===B.key?"border-[var(--interactive-border)] bg-[var(--surface-muted)]":"border-transparent hover:border-[var(--interactive-border)] hover:bg-[var(--surface-muted)]/50"),title:B.label,children:s.jsx(ne,{className:"w-3.5 h-3.5",style:{color:k===B.key?L:"var(--surface-muted-foreground)"}})},B.key)})})]})]}),!u&&s.jsx("div",{className:"border-t border-border/40"}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:a("settings.gitIdentities.editor.field.userName")}),!u&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:a("settings.gitIdentities.editor.field.userNameTooltip")})]})]}),s.jsx(Vt,{value:f,onChange:B=>y(B.target.value),placeholder:a("settings.gitIdentities.editor.field.userNamePlaceholder"),required:!u,readOnly:u,disabled:u,className:"h-8"})]}),s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:a("settings.gitIdentities.editor.field.emailAddress")}),!u&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:a("settings.gitIdentities.editor.field.emailAddressTooltip")})]})]}),s.jsx(Vt,{type:"email",value:x,onChange:B=>g(B.target.value),placeholder:a("settings.gitIdentities.editor.field.emailAddressPlaceholder"),required:!u,readOnly:u,disabled:u,className:"h-8"})]})]}),!u&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"border-t border-border/40"}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:a("settings.gitIdentities.editor.field.authMethod")}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs(je,{size:"sm",type:"button",variant:"chip","aria-pressed":w==="ssh",onClick:()=>v("ssh"),children:[s.jsx(Cy,{className:"w-3.5 h-3.5 mr-1"})," SSH"]}),s.jsxs(je,{size:"sm",type:"button",variant:"chip","aria-pressed":w==="token",onClick:()=>v("token"),children:[s.jsx(Iy,{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(St,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:a("settings.gitIdentities.editor.field.sshKeyPathTooltip")})]})]}),s.jsx(Vt,{value:S,onChange:B=>A(B.target.value),placeholder:a("settings.gitIdentities.editor.field.sshKeyPathPlaceholder"),className:"h-8 font-mono text-xs"})]}),w==="token"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:a("settings.gitIdentities.editor.field.host")}),s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:a("settings.gitIdentities.editor.field.hostTooltip")})]})]}),s.jsx(Vt,{value:j,onChange:B=>C(B.target.value),placeholder:a("settings.gitIdentities.editor.field.hostPlaceholder"),required:!0,className:"h-8 font-mono text-xs"})]})]})]})]}),s.jsxs(Qs,{className:"gap-2",children:[!u&&!m&&s.jsxs(je,{variant:"outline",size:"sm",onClick:()=>M(!0),className:"text-[var(--status-error)] hover:text-[var(--status-error)] border-[var(--status-error)]/30 hover:bg-[var(--status-error)]/10 mr-auto",children:[s.jsx(sn,{className:"w-3.5 h-3.5 mr-1"})," ",a("settings.common.actions.delete")]}),s.jsx(je,{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(je,{size:"sm",onClick:V,disabled:N,children:a(N?"settings.common.actions.saving":m?"settings.gitIdentities.editor.actions.create":"settings.gitIdentities.editor.actions.save")})]})]})}),s.jsx(ws,{open:T,onOpenChange:B=>{$||M(B)},children:s.jsxs(vs,{className:"max-w-md",children:[s.jsxs(Is,{children:[s.jsx(Ss,{children:a("settings.gitIdentities.page.deleteDialog.title")}),s.jsx(Os,{children:a("settings.gitIdentities.page.deleteDialog.description",{name:p?.name||h})})]}),s.jsxs(Qs,{children:[s.jsx(je,{variant:"ghost",onClick:()=>M(!1),disabled:$,children:a("settings.common.actions.cancel")}),s.jsx(je,{size:"sm",variant:"destructive",onClick:()=>{O()},disabled:$,children:a("settings.common.actions.delete")})]})]})})]})},Z4={branch:Ks,briefcase:ju,house:wu,graduation:vu,code:cc,heart:Rh},e6={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)"},t6=()=>{const t=nt.c(116),{t:e}=ut(),{profiles:n,globalIdentity:r,defaultGitIdentityId:a,deleteProfile:i,loadProfiles:o,loadGlobalIdentity:c,loadDiscoveredCredentials:d,loadDefaultGitIdentityId:p,setDefaultGitIdentityId:m,getUnimportedCredentials:u}=ar(jr(n6)),[h,b]=l.useState(!1),[f,y]=l.useState(null),[x,g]=l.useState(null),[w,v]=l.useState(null),[S,A]=l.useState(!1);let j,C;t[0]!==p||t[1]!==d||t[2]!==c||t[3]!==o?(j=()=>{o(),c(),d(),p()},C=[o,c,d,p],t[0]=p,t[1]=d,t[2]=c,t[3]=o,t[4]=j,t[5]=C):(j=t[4],C=t[5]),l.useEffect(j,C);let I,R,k,P,N,D,T,M,$,F,V,O,L;if(t[6]!==a||t[7]!==w||t[8]!==i||t[9]!==u||t[10]!==r||t[11]!==n||t[12]!==m||t[13]!==e){const Y=u();let fe;t[27]===Symbol.for("react.memo_cache_sentinel")?(fe=(U,de)=>{y(U),g(de??null),b(!0)},t[27]=fe):fe=t[27];const ke=fe;let xe;t[28]!==a||t[29]!==m||t[30]!==e?(xe=async U=>{const de=a===U?null:U;if(!await m(de)){q.error(e("settings.gitIdentities.page.toast.updateDefaultFailed"));return}q.success(e(de?"settings.gitIdentities.page.toast.defaultUpdated":"settings.gitIdentities.page.toast.defaultUnset"))},t[28]=a,t[29]=m,t[30]=e,t[31]=xe):xe=t[31];const he=xe;let Pe;t[32]!==w||t[33]!==i||t[34]!==e?(Pe=async()=>{if(!w)return;A(!0),await i(w.id)?(q.success(e("settings.gitIdentities.page.toast.profileDeleted",{name:w.name})),v(null)):q.error(e("settings.gitIdentities.page.toast.deleteProfileFailed")),A(!1)},t[32]=w,t[33]=i,t[34]=e,t[35]=Pe):Pe=t[35],R=Pe,I=Es,P="h-full",N="w-full bg-background",L="mx-auto w-full max-w-3xl space-y-6 p-3 sm:p-6 sm:pt-8",t[36]===Symbol.for("react.memo_cache_sentinel")?(k=s.jsx(Ox,{}),t[36]=k):k=t[36],V="border-t border-border/40 pt-6";let Be;t[37]!==e?(Be=e("settings.gitIdentities.page.section.title"),t[37]=e,t[38]=Be):Be=t[38];let G;t[39]!==Be?(G=s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:Be})}),t[39]=Be,t[40]=G):G=t[40];let be,De;t[41]===Symbol.for("react.memo_cache_sentinel")?(be=()=>ke("new"),De=s.jsx(_s,{className:"w-3.5 h-3.5 mr-1"}),t[41]=be,t[42]=De):(be=t[41],De=t[42]);let Ae;t[43]!==e?(Ae=e("settings.common.badge.new"),t[43]=e,t[44]=Ae):Ae=t[44];let ve;t[45]!==Ae?(ve=s.jsxs(je,{size:"sm",variant:"outline",onClick:be,children:[De," ",Ae]}),t[45]=Ae,t[46]=ve):ve=t[46],t[47]!==G||t[48]!==ve?(O=s.jsxs("div",{className:"mb-3 px-1 flex items-start justify-between gap-4",children:[G,ve]}),t[47]=G,t[48]=ve,t[49]=O):O=t[49],D="rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",T=r&&s.jsx(wf,{profile:r,isDefault:a==="global",onEdit:()=>ke("global"),onToggleDefault:()=>he("global"),isReadOnly:!0,hasBorder:n.length>0||Y.length>0}),M=n.map((U,de)=>s.jsx(wf,{profile:U,isDefault:a===U.id,onEdit:()=>ke(U.id),onToggleDefault:()=>he(U.id),onDelete:()=>v(U),hasBorder:de<n.length-1||Y.length>0},U.id)),$=!r&&n.length===0&&Y.length===0&&s.jsxs("div",{className:"py-8 px-4 text-center text-muted-foreground",children:[s.jsx(Ay,{className:"mx-auto mb-2 h-8 w-8 opacity-40"}),s.jsx("p",{className:"typography-ui-label",children:e("settings.gitIdentities.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.gitIdentities.page.empty.description")})]}),F=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((U,de)=>s.jsx(s6,{credential:U,onImport:()=>ke("new",{host:U.host,username:U.username}),hasBorder:de<Y.length-1},`${U.host}-${U.username}`))]}),t[6]=a,t[7]=w,t[8]=i,t[9]=u,t[10]=r,t[11]=n,t[12]=m,t[13]=e,t[14]=I,t[15]=R,t[16]=k,t[17]=P,t[18]=N,t[19]=D,t[20]=T,t[21]=M,t[22]=$,t[23]=F,t[24]=V,t[25]=O,t[26]=L}else I=t[14],R=t[15],k=t[16],P=t[17],N=t[18],D=t[19],T=t[20],M=t[21],$=t[22],F=t[23],V=t[24],O=t[25],L=t[26];let W;t[50]!==D||t[51]!==T||t[52]!==M||t[53]!==$||t[54]!==F?(W=s.jsxs("div",{className:D,children:[T,M,$,F]}),t[50]=D,t[51]=T,t[52]=M,t[53]=$,t[54]=F,t[55]=W):W=t[55];let B;t[56]!==W||t[57]!==V||t[58]!==O?(B=s.jsxs("div",{className:V,children:[O,W]}),t[56]=W,t[57]=V,t[58]=O,t[59]=B):B=t[59];let ne;t[60]===Symbol.for("react.memo_cache_sentinel")?(ne=s.jsx(Fx,{}),t[60]=ne):ne=t[60];let le;t[61]!==k||t[62]!==B||t[63]!==L?(le=s.jsxs("div",{className:L,children:[k,B,ne]}),t[61]=k,t[62]=B,t[63]=L,t[64]=le):le=t[64];let ee;t[65]!==I||t[66]!==P||t[67]!==N||t[68]!==le?(ee=s.jsx(I,{outerClassName:P,className:N,children:le}),t[65]=I,t[66]=P,t[67]=N,t[68]=le,t[69]=ee):ee=t[69];let ae;t[70]!==x||t[71]!==h||t[72]!==f?(ae=s.jsx(X4,{open:h,onOpenChange:b,profileId:f,importData:x}),t[70]=x,t[71]=h,t[72]=f,t[73]=ae):ae=t[73];const ge=w!==null;let te;t[74]!==S?(te=Y=>{S||Y||v(null)},t[74]=S,t[75]=te):te=t[75];let E;t[76]!==e?(E=e("settings.gitIdentities.page.deleteDialog.title"),t[76]=e,t[77]=E):E=t[77];let z;t[78]!==E?(z=s.jsx(Ss,{children:E}),t[78]=E,t[79]=z):z=t[79];const J=w?.name??"";let H;t[80]!==e||t[81]!==J?(H=e("settings.gitIdentities.page.deleteDialog.description",{name:J}),t[80]=e,t[81]=J,t[82]=H):H=t[82];let re;t[83]!==H?(re=s.jsx(Os,{children:H}),t[83]=H,t[84]=re):re=t[84];let ce;t[85]!==z||t[86]!==re?(ce=s.jsxs(Is,{children:[z,re]}),t[85]=z,t[86]=re,t[87]=ce):ce=t[87];let Ne;t[88]===Symbol.for("react.memo_cache_sentinel")?(Ne=()=>v(null),t[88]=Ne):Ne=t[88];let me;t[89]!==e?(me=e("settings.common.actions.cancel"),t[89]=e,t[90]=me):me=t[90];let we;t[91]!==S||t[92]!==me?(we=s.jsx(je,{variant:"ghost",onClick:Ne,disabled:S,children:me}),t[91]=S,t[92]=me,t[93]=we):we=t[93];let _;t[94]!==R?(_=()=>{R()},t[94]=R,t[95]=_):_=t[95];let ue;t[96]!==e?(ue=e("settings.common.actions.delete"),t[96]=e,t[97]=ue):ue=t[97];let Q;t[98]!==S||t[99]!==_||t[100]!==ue?(Q=s.jsx(je,{size:"sm",variant:"destructive",onClick:_,disabled:S,children:ue}),t[98]=S,t[99]=_,t[100]=ue,t[101]=Q):Q=t[101];let oe;t[102]!==we||t[103]!==Q?(oe=s.jsxs(Qs,{children:[we,Q]}),t[102]=we,t[103]=Q,t[104]=oe):oe=t[104];let Z;t[105]!==ce||t[106]!==oe?(Z=s.jsxs(vs,{className:"max-w-md",children:[ce,oe]}),t[105]=ce,t[106]=oe,t[107]=Z):Z=t[107];let Ie;t[108]!==ge||t[109]!==te||t[110]!==Z?(Ie=s.jsx(ws,{open:ge,onOpenChange:te,children:Z}),t[108]=ge,t[109]=te,t[110]=Z,t[111]=Ie):Ie=t[111];let Se;return t[112]!==ee||t[113]!==ae||t[114]!==Ie?(Se=s.jsxs(s.Fragment,{children:[ee,ae,Ie]}),t[112]=ee,t[113]=ae,t[114]=Ie,t[115]=Se):Se=t[115],Se},wf=t=>{const e=nt.c(54),{profile:n,isDefault:r,onEdit:a,onToggleDefault:i,onDelete:o,isReadOnly:c,hasBorder:d}=t,{t:p}=ut(),m=Z4[n.icon||"branch"]||Ks,u=e6[n.color||""],h=n.authType||"ssh",b=d&&"border-b border-[var(--surface-subtle)]";let f;e[0]!==b?(f=pe("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 y;e[2]!==a?(y=V=>{(V.key==="Enter"||V.key===" ")&&a()},e[2]=a,e[3]=y):y=e[3];let x;e[4]!==u?(x={color:u},e[4]=u,e[5]=x):x=e[5];let g;e[6]!==m||e[7]!==x?(g=s.jsx(m,{className:"w-4 h-4 shrink-0",style:x}),e[6]=m,e[7]=x,e[8]=g):g=e[8];let w;e[9]!==n.name?(w=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:n.name}),e[9]=n.name,e[10]=w):w=e[10];let v;e[11]!==h?(v=s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:h}),e[11]=h,e[12]=v):v=e[12];let S;e[13]!==r||e[14]!==p?(S=r&&s.jsx("span",{className:"typography-micro text-primary bg-primary/12 px-1 rounded flex-shrink-0 leading-none pb-px border border-primary/25",children:p("settings.gitIdentities.page.badge.default")}),e[13]=r,e[14]=p,e[15]=S):S=e[15];let A;e[16]!==c||e[17]!==p?(A=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]=A):A=e[18];let j;e[19]!==w||e[20]!==v||e[21]!==S||e[22]!==A?(j=s.jsxs("div",{className:"flex items-center gap-1.5",children:[w,v,S,A]}),e[19]=w,e[20]=v,e[21]=S,e[22]=A,e[23]=j):j=e[23];const C=h==="token"&&n.host?n.host:n.userEmail;let I;e[24]!==C?(I=s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:C}),e[24]=C,e[25]=I):I=e[25];let R;e[26]!==j||e[27]!==I?(R=s.jsxs("div",{className:"min-w-0",children:[j,I]}),e[26]=j,e[27]=I,e[28]=R):R=e[28];let k;e[29]!==R||e[30]!==g?(k=s.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[g,R]}),e[29]=R,e[30]=g,e[31]=k):k=e[31];let P;e[32]===Symbol.for("react.memo_cache_sentinel")?(P=s.jsx(Bs,{asChild:!0,children:s.jsx(je,{size:"icon",variant:"ghost",className:"h-6 w-6 shrink-0 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",onClick:r6,children:s.jsx(ia,{className:"h-3.5 w-3.5"})})}),e[32]=P):P=e[32];let N;e[33]!==i?(N=V=>{V.stopPropagation(),i()},e[33]=i,e[34]=N):N=e[34];let D;e[35]!==r||e[36]!==p?(D=p(r?"settings.gitIdentities.page.actions.unsetDefault":"settings.gitIdentities.page.actions.setAsDefault"),e[35]=r,e[36]=p,e[37]=D):D=e[37];let T;e[38]!==N||e[39]!==D?(T=s.jsx($t,{onClick:N,children:D}),e[38]=N,e[39]=D,e[40]=T):T=e[40];let M;e[41]!==c||e[42]!==o||e[43]!==p?(M=!c&&o&&s.jsxs($t,{onClick:V=>{V.stopPropagation(),o()},className:"text-destructive focus:text-destructive",children:[s.jsx(sn,{className:"h-4 w-4 mr-px"}),p("settings.common.actions.delete")]}),e[41]=c,e[42]=o,e[43]=p,e[44]=M):M=e[44];let $;e[45]!==T||e[46]!==M?($=s.jsxs(zs,{children:[P,s.jsxs(Vs,{align:"end",className:"w-fit min-w-28",children:[T,M]})]}),e[45]=T,e[46]=M,e[47]=$):$=e[47];let F;return e[48]!==a||e[49]!==k||e[50]!==f||e[51]!==$||e[52]!==y?(F=s.jsxs("div",{className:f,onClick:a,role:"button",tabIndex:0,onKeyDown:y,children:[k,$]}),e[48]=a,e[49]=k,e[50]=f,e[51]=$,e[52]=y,e[53]=F):F=e[53],F},s6=t=>{const e=nt.c(21),{credential:n,onImport:r,hasBorder:a}=t,{t:i}=ut();let o;e[0]!==n.host?(o=n.host.split("/"),e[0]=n.host,e[1]=o):o=e[1];const c=o,d=c.length>=3?c[c.length-1]:n.host,p=n.host.includes("/"),m=a&&"border-b border-[var(--surface-subtle)]";let u;e[2]!==m?(u=pe("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 y;e[8]!==h||e[9]!==f?(y=s.jsxs("div",{className:"min-w-0",children:[h,f]}),e[8]=h,e[9]=f,e[10]=y):y=e[10];let x;e[11]===Symbol.for("react.memo_cache_sentinel")?(x=s.jsx(Qr,{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(je,{size:"sm",variant:"ghost",onClick:r,className:"gap-1 shrink-0",children:[x,g]}),e[14]=r,e[15]=g,e[16]=w):w=e[16];let v;return e[17]!==w||e[18]!==u||e[19]!==y?(v=s.jsxs("div",{className:u,children:[y,w]}),e[17]=w,e[18]=u,e[19]=y,e[20]=v):v=e[20],v};function n6(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 r6(t){return t.stopPropagation()}const Lx=()=>{const t=y1();return{displayMode:t,installed:t!=="browser",browserTab:t==="browser"}},$x=()=>{const t=nt.c(2),[e,n]=l.useState(a6);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(Lx())};o();for(const c of i)c.addEventListener("change",o);return window.addEventListener("appinstalled",o),window.addEventListener("focus",o),()=>{for(const c of i)c.removeEventListener("change",o);window.removeEventListener("appinstalled",o),window.removeEventListener("focus",o)}},a=[],t[0]=r,t[1]=a):(r=t[0],a=t[1]),l.useEffect(r,a),e};function a6(){return Lx()}const i6=[{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"}],o6=[{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"}],l6=[{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"}],c6=[{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"}],uo="OpenChamber - AI Coding Assistant",jf=[{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"}],Nf=[{id:"native",labelKey:"settings.openchamber.visual.option.mobileKeyboardMode.native.label",descriptionKey:"settings.openchamber.visual.option.mobileKeyboardMode.native.description"},{id:"resize-content",labelKey:"settings.openchamber.visual.option.mobileKeyboardMode.resizeContent.label",descriptionKey:"settings.openchamber.visual.option.mobileKeyboardMode.resizeContent.description"}],fd=t=>t==="portrait"||t==="landscape"?t:"system",d6=[{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"}],u6=[{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"}],Sf=[{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"}],m6=[{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"}],kf=[{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"}],Cf=[{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"}],p6=t=>t==="markdown"?"markdown":"plain",Xu=({visibleSettings:t})=>{const{locale:e,locales:n,setLocale:r,label:a,t:i}=ut(),o=l.useCallback(X=>i(X),[i]),{isMobile:c}=un(),{browserTab:d}=$x(),p=xc(),m=Te(X=>X.showReasoningTraces),u=Te(X=>X.setShowReasoningTraces),h=Te(X=>X.mermaidRenderingMode),b=Te(X=>X.setMermaidRenderingMode),f=Te(X=>X.userMessageRenderingMode),y=Te(X=>X.setUserMessageRenderingMode),x=Te(X=>X.stickyUserHeader),g=Te(X=>X.setStickyUserHeader),w=Te(X=>X.wideChatLayoutEnabled),v=Te(X=>X.setWideChatLayoutEnabled),S=Te(X=>X.chatRenderMode),A=Te(X=>X.setChatRenderMode),j=Te(X=>X.activityRenderMode),C=Te(X=>X.setActivityRenderMode),I=Te(X=>X.fontSize),R=Te(X=>X.setFontSize),k=Te(X=>X.terminalFontSize),P=Te(X=>X.setTerminalFontSize),N=Te(X=>X.uiFont),D=Te(X=>X.setUiFont),T=Te(X=>X.monoFont),M=Te(X=>X.setMonoFont),$=Te(X=>X.padding),F=Te(X=>X.setPadding),V=Te(X=>X.inputBarOffset),O=Te(X=>X.setInputBarOffset),L=Te(X=>X.mobileKeyboardMode),W=Te(X=>X.setMobileKeyboardMode),B=Te(X=>X.diffLayoutPreference),ne=Te(X=>X.setDiffLayoutPreference),le=Te(X=>X.diffViewMode),ee=Te(X=>X.setDiffViewMode),ae=Te(X=>X.showTerminalQuickKeysOnDesktop),ge=Te(X=>X.setShowTerminalQuickKeysOnDesktop),te=Sm(X=>X.queueModeEnabled),E=Sm(X=>X.setQueueMode),z=Te(X=>X.persistChatDraft),J=Te(X=>X.setPersistChatDraft),H=Te(X=>X.inputSpellcheckEnabled),re=Te(X=>X.setInputSpellcheckEnabled),ce=Te(X=>X.showToolFileIcons),Ne=Te(X=>X.setShowToolFileIcons),me=Te(X=>X.showExpandedBashTools),we=Te(X=>X.setShowExpandedBashTools),_=Te(X=>X.showExpandedEditTools),ue=Te(X=>X.setShowExpandedEditTools),Q=Te(X=>X.timeFormatPreference),oe=Te(X=>X.setTimeFormatPreference),Z=Te(X=>X.weekStartPreference),Ie=Te(X=>X.setWeekStartPreference),Se=Te(X=>X.showSplitAssistantMessageActions),Y=Te(X=>X.setShowSplitAssistantMessageActions),fe=Te(X=>X.showMobileSessionStatusBar),ke=Te(X=>X.setShowMobileSessionStatusBar),xe=yt(X=>X.settingsMessageStreamTransport),he=yt(X=>X.setSettingsMessageStreamTransport),Pe=Te(X=>X.isSettingsDialogOpen),{themeMode:Be,setThemeMode:G,availableThemes:be,customThemesLoading:De,reloadCustomThemes:Ae,lightThemeId:ve,darkThemeId:U,setLightThemePreference:de,setDarkThemePreference:Re}=Rr(),[Le,se]=l.useState(!1),[ie,K]=l.useState(0),_e=Te(X=>X.reportUsage),He=Te(X=>X.setReportUsage),Ke=l.useCallback(X=>{He(X),Rs({reportUsage:X})},[He]),Ze=Pe&&(t?t.includes("chatRenderMode"):!0);l.useEffect(()=>{if(!Ze)return;let X=null,pt=Date.now();const wt=()=>{const ss=Date.now();ss-pt>=420&&(K(os=>(os+1)%24),pt=ss),X=requestAnimationFrame(wt)};(typeof document>"u"||document.visibilityState==="visible")&&(X=requestAnimationFrame(wt));const zt=()=>{document.visibilityState==="visible"&&X===null?X=requestAnimationFrame(wt):document.visibilityState!=="visible"&&X!==null&&(cancelAnimationFrame(X),X=null)};return document.addEventListener("visibilitychange",zt),()=>{document.removeEventListener("visibilitychange",zt),X!==null&&cancelAnimationFrame(X)}},[Ze]);const Xe=l.useCallback(X=>{y(X),Rs({userMessageRenderingMode:X})},[y]),mt=l.useCallback(X=>{g(X),Rs({stickyUserHeader:X})},[g]),et=l.useCallback(X=>{v(X),Rs({wideChatLayoutEnabled:X})},[v]),ct=l.useCallback(X=>{Y(X),Rs({showSplitAssistantMessageActions:X})},[Y]),lt=l.useCallback(X=>{re(X),Rs({inputSpellcheckEnabled:X})},[re]),ye=l.useCallback(X=>{A(X),Rs({chatRenderMode:X})},[A]),Ge=l.useCallback(X=>{he(X),Rs({messageStreamTransport:X})},[he]),$e=l.useCallback(X=>{C(X),Rs({activityRenderMode:X})},[C]),Ve=l.useCallback(X=>{b(X),Rs({mermaidRenderingMode:X})},[b]),tt=l.useCallback(X=>{Ne(X),Rs({showToolFileIcons:X})},[Ne]),Qe=l.useCallback(X=>{we(X),Rs({showExpandedBashTools:X})},[we]),ze=l.useCallback(X=>{ue(X),Rs({showExpandedEditTools:X})},[ue]),ht=l.useCallback(X=>{oe(X),Rs({timeFormatPreference:X})},[oe]),_t=l.useCallback(X=>{Ie(X),Rs({weekStartPreference:X})},[Ie]),Kt=l.useMemo(()=>be.filter(X=>X.metadata.variant==="light").sort((X,pt)=>X.metadata.name.localeCompare(pt.metadata.name)),[be]),Ut=l.useMemo(()=>be.filter(X=>X.metadata.variant==="dark").sort((X,pt)=>X.metadata.name.localeCompare(pt.metadata.name)),[be]),jt=l.useMemo(()=>Kt.find(X=>X.metadata.id===ve)??Kt[0],[Kt,ve]),Dt=l.useMemo(()=>Ut.find(X=>X.metadata.id===U)??Ut[0],[Ut,U]),ts=l.useCallback((X,pt)=>{const wt=pt==="dark"?" Dark":" Light";return X.endsWith(wt)?X.slice(0,-wt.length):X},[]),it=X=>t?t.includes(X):!0,Yt=yn(),Qt=it("theme")&&!Yt,Xt=it("theme")||it("timeFormat")||it("weekStart"),us=Yt?Xt:it("theme")||it("pwaInstallName")||it("pwaOrientation")||it("timeFormat")||it("weekStart"),ms=it("fontSize")||it("terminalFontSize")||it("spacing")||it("inputBarOffset"),gs=it("terminalQuickKeys")&&!c,ds=it("mermaidRendering")||it("userMessageRendering")||it("chatRenderMode")||it("messageTransport")||it("activityRenderMode")&&S==="sorted"||it("stickyUserHeader")||it("wideChatLayout")||it("splitAssistantMessageActions")||it("diffLayout")||it("mobileStatusBar")&&c||it("dotfiles")||it("reasoning")||it("queueMode")||it("persistDraft")||it("showToolFileIcons")||it("expandedTools")||!c&&it("inputSpellcheck"),Ft=it("pwaInstallName")&&ja()&&d&&!kn()&&!Yt,Ue=it("pwaOrientation")&&ja()&&!kn()&&!Yt,Tt=it("mobileKeyboardMode")&&ja()&&!kn()&&!Yt&&v1(),[At,vt]=l.useState(""),[Rt,ns]=l.useState("system"),As=l.useMemo(()=>{const X=kf.find(pt=>pt.id===Q);return o(X?.labelKey??"settings.openchamber.visual.option.timeFormat.auto.label")},[Q,o]),ft=l.useMemo(()=>{const X=Cf.find(pt=>pt.id===Z);return o(X?.labelKey??"settings.openchamber.visual.option.weekStart.auto.label")},[Z,o]),is=l.useMemo(()=>{const X=jf.find(pt=>pt.id===Rt);return X?o(X.labelKey):void 0},[Rt,o]),es=l.useMemo(()=>{const X=Nf.find(pt=>pt.id===L);return X?o(X.labelKey):void 0},[L,o]),Ts=l.useCallback(async X=>{if(typeof window>"u")return;const pt=window,zt=X.trim().replace(/\s+/g," ").slice(0,64);if(await Rs({pwaAppName:zt}),typeof pt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__=="function"){const ss=pt.__OPENCHAMBER_SET_PWA_INSTALL_NAME__(zt);vt(ss);return}vt(zt||uo),pt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]),Ls=l.useCallback(async X=>{if(typeof window>"u")return;const pt=window,wt=fd(X);if(await Rs({pwaOrientation:wt}),typeof pt.__OPENCHAMBER_SET_PWA_ORIENTATION__=="function"){const zt=pt.__OPENCHAMBER_SET_PWA_ORIENTATION__(wt);ns(zt);return}ns(wt),pt.__OPENCHAMBER_UPDATE_PWA_MANIFEST__?.()},[]);return l.useEffect(()=>{if(typeof window>"u"||!Ft&&!Ue&&!Tt)return;let X=!1;return(async()=>{try{const wt=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},cache:"no-store"});if(!wt.ok){X||vt(uo);return}const zt=await wt.json().catch(()=>({})),os=(typeof zt?.pwaAppName=="string"?zt.pwaAppName:"").trim().replace(/\s+/g," ").slice(0,64),Ps=fd(zt?.pwaOrientation),Ms=Pm(zt?.mobileKeyboardMode);X||(Ft&&vt(os||uo),Ue&&ns(Ps),Tt&&W(Ms))}catch{X||(Ft&&vt(uo),Ue&&ns("system"),Tt&&W("native"))}})(),()=>{X=!0}},[W,Tt,Ft,Ue]),s.jsxs("div",{className:"space-y-8",children:[us&&s.jsxs("div",{className:"mb-8 space-y-6",children:[Qt&&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:i6.map(X=>s.jsx(je,{variant:"chip",size:"xs","aria-pressed":Be===X.value,className:"!font-normal",onClick:()=>G(X.value),children:o(X.labelKey)},X.value))})]}),s.jsxs("div",{className:"grid grid-cols-1 gap-2 py-1.5 md:grid-cols-[14rem_auto] md:gap-x-8 md:gap-y-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:i("settings.openchamber.visual.field.lightTheme")}),s.jsxs(ps,{value:jt?.metadata.id??"",onValueChange:de,children:[s.jsx(fs,{"aria-label":i("settings.openchamber.visual.field.selectLightThemeAria"),className:"w-fit",children:s.jsx(ys,{placeholder:i("settings.openchamber.visual.field.selectThemePlaceholder"),children:jt?ts(jt.metadata.name,"light"):void 0})}),s.jsx(hs,{children:Kt.map(X=>s.jsx(Ot,{value:X.metadata.id,children:ts(X.metadata.name,"light")},X.metadata.id))})]})]}),s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:i("settings.openchamber.visual.field.darkTheme")}),s.jsxs(ps,{value:Dt?.metadata.id??"",onValueChange:Re,children:[s.jsx(fs,{"aria-label":i("settings.openchamber.visual.field.selectDarkThemeAria"),className:"w-fit",children:s.jsx(ys,{placeholder:i("settings.openchamber.visual.field.selectThemePlaceholder"),children:Dt?ts(Dt.metadata.name,"dark"):void 0})}),s.jsx(hs,{children:Ut.map(X=>s.jsx(Ot,{value:X.metadata.id,children:ts(X.metadata.name,"dark")},X.metadata.id))})]})]})]}),s.jsxs("div",{className:"flex items-center gap-2 py-1.5",children:[s.jsx("button",{type:"button",disabled:De||Le,onClick:()=>{const X=Date.now();se(!0),Ae().finally(()=>{const pt=Date.now()-X;if(pt<500){window.setTimeout(()=>{se(!1)},500-pt);return}se(!1)})},className:"inline-flex items-center typography-ui-label font-normal text-foreground underline decoration-[1px] underline-offset-2 hover:text-foreground/80 disabled:cursor-not-allowed disabled:text-muted-foreground/60",children:i(Le?"settings.openchamber.visual.actions.reloadingThemes":"settings.openchamber.visual.actions.reloadThemes")}),s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx("button",{type:"button",className:"flex items-center justify-center rounded-md p-1 text-muted-foreground/70 hover:text-foreground","aria-label":i("settings.openchamber.visual.field.themeImportInfoAria"),children:s.jsx(Us,{className:"h-3.5 w-3.5"})})}),s.jsx(Ct,{sideOffset:8,children:i("settings.openchamber.visual.field.themeImportInfoTooltip")})]})]})]}),Xt&&s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.localization")}),s.jsxs("div",{className:"grid grid-cols-1 gap-2 py-1.5 md:grid-cols-[14rem_auto] md:gap-x-8 md:gap-y-2",children:[s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:i("settings.appearance.language.label")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.appearance.language.description")})]}),s.jsxs(ps,{value:e,onValueChange:X=>r(X),children:[s.jsx(fs,{"aria-label":i("settings.appearance.language.select"),className:"w-fit",children:s.jsx(ys,{children:a(e)})}),s.jsx(hs,{children:n.map(X=>s.jsx(Ot,{value:X,children:a(X)},X))})]})]}),!Yt&&(it("timeFormat")||it("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:[it("timeFormat")&&s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:i("settings.openchamber.visual.field.timeFormat")}),s.jsxs(ps,{value:Q,onValueChange:X=>ht(X),children:[s.jsx(fs,{"aria-label":i("settings.openchamber.visual.field.selectTimeFormatAria"),className:"w-fit",children:s.jsx(ys,{children:As})}),s.jsx(hs,{children:kf.map(X=>s.jsx(Ot,{value:X.id,children:o(X.labelKey)},X.id))})]})]}),it("weekStart")&&s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground shrink-0",children:i("settings.openchamber.visual.field.weekStartsOn")}),s.jsxs(ps,{value:Z,onValueChange:X=>_t(X),children:[s.jsx(fs,{"aria-label":i("settings.openchamber.visual.field.selectWeekStartAria"),className:"w-fit",children:s.jsx(ys,{children:ft})}),s.jsx(hs,{children:Cf.map(X=>s.jsx(Ot,{value:X.id,children:o(X.labelKey)},X.id))})]})]})]})]}),(Ft||Ue||Tt)&&s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[Ft&&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(Vt,{value:At,onChange:X=>{vt(X.target.value)},onBlur:()=>{Ts(At)},onKeyDown:X=>{X.key==="Enter"&&(X.preventDefault(),Ts(At))},className:"h-7",maxLength:64,"aria-label":i("settings.openchamber.visual.field.pwaInstallAppNameAria")}),s.jsx(je,{size:"sm",type:"button",variant:"ghost",onClick:()=>{vt(uo),Ts("")},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(Mn,{className:"h-3.5 w-3.5"})})]})]}),Ue&&s.jsxs("div",{className:"py-1.5 space-y-1.5",children:[s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.installOrientation")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.openchamber.visual.field.installOrientationHint")})]}),s.jsxs("div",{className:"flex w-full max-w-[18rem] items-center gap-2",children:[s.jsxs(ps,{value:Rt,onValueChange:X=>{const pt=fd(X);ns(pt),Ls(pt)},children:[s.jsx(fs,{"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(hs,{children:jf.map(X=>s.jsx(Ot,{value:X.id,children:o(X.labelKey)},X.id))})]}),s.jsx(je,{size:"sm",type:"button",variant:"ghost",onClick:()=>{ns("system"),Ls("system")},disabled:Rt==="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(Mn,{className:"h-3.5 w-3.5"})})]})]}),Tt&&s.jsxs("div",{className:"py-1.5 space-y-1.5",children:[s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.mobileKeyboardMode")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:i("settings.openchamber.visual.field.mobileKeyboardModeHint")})]}),s.jsxs("div",{className:"flex w-full max-w-[18rem] items-center gap-2",children:[s.jsxs(ps,{value:L,onValueChange:X=>{const pt=Pm(X);W(pt),Rs({mobileKeyboardMode:pt})},children:[s.jsx(fs,{"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(hs,{children:Nf.map(X=>s.jsx(Ot,{value:X.id,children:o(X.labelKey)},X.id))})]}),s.jsx(je,{size:"sm",type:"button",variant:"ghost",onClick:()=>{W("native"),Rs({mobileKeyboardMode:"native"})},disabled:L==="native",className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetMobileKeyboardModeAria"),title:i("settings.common.actions.reset"),children:s.jsx(Mn,{className:"h-3.5 w-3.5"})})]})]})]})]}),ms&&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:[it("fontSize")&&!c&&s.jsxs("div",{className:"flex items-center gap-8 py-1",children:[s.jsx("div",{className:"flex min-w-0 flex-col w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.interfaceFont")})}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[s.jsxs(ps,{value:N,onValueChange:X=>D(X),children:[s.jsx(fs,{"aria-label":i("settings.openchamber.visual.field.selectInterfaceFontAria"),className:"w-[13rem]",children:s.jsx(ys,{children:km.find(X=>X.id===N)?.label})}),s.jsx(hs,{children:km.map(X=>s.jsx(Ot,{value:X.id,children:s.jsx("span",{style:{fontFamily:X.stack},children:X.label})},X.id))})]}),s.jsx(je,{size:"sm",type:"button",variant:"ghost",onClick:()=>D(Cm),disabled:N===Cm,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(Mn,{className:"h-3.5 w-3.5"})})]})]}),it("terminalFontSize")&&s.jsxs("div",{className:pe("py-1",c?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsx("div",{className:pe("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:pe("flex items-center gap-2",c?"w-full":"w-fit"),children:[s.jsxs(ps,{value:T,onValueChange:X=>M(X),children:[s.jsx(fs,{"aria-label":i("settings.openchamber.visual.field.selectCodeFontAria"),className:"w-[13rem]",children:s.jsx(ys,{children:Im.find(X=>X.id===T)?.label})}),s.jsx(hs,{children:Im.map(X=>s.jsx(Ot,{value:X.id,children:s.jsx("span",{style:{fontFamily:X.stack},children:X.label})},X.id))})]}),s.jsx(je,{size:"sm",type:"button",variant:"ghost",onClick:()=>M(Am),disabled:T===Am,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(Mn,{className:"h-3.5 w-3.5"})})]})]}),it("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(jn,{value:I,onValueChange:R,min:50,max:200,step:5,"aria-label":i("settings.openchamber.visual.field.fontSizePercentageAria"),className:"w-16"}),s.jsx(je,{size:"sm",type:"button",variant:"ghost",onClick:()=>R(100),disabled:I===100,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetFontSizeAria"),title:i("settings.common.actions.reset"),children:s.jsx(Mn,{className:"h-3.5 w-3.5"})})]})]}),it("terminalFontSize")&&s.jsxs("div",{className:pe("py-1",c?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsx("div",{className:pe("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:pe("flex items-center gap-2",c?"w-full":"w-fit"),children:[s.jsx(jn,{value:k,onValueChange:P,min:9,max:52,step:1,className:"w-16"}),s.jsx(je,{size:"sm",type:"button",variant:"ghost",onClick:()=>P(13),disabled:k===13,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetTerminalFontSizeAria"),title:i("settings.common.actions.reset"),children:s.jsx(Mn,{className:"h-3.5 w-3.5"})})]})]}),it("spacing")&&s.jsxs("div",{className:pe("py-1",c?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsx("div",{className:pe("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:pe("flex items-center gap-2",c?"w-full":"w-fit"),children:[s.jsx(jn,{value:$,onValueChange:F,min:50,max:200,step:5,className:"w-16"}),s.jsx(je,{size:"sm",type:"button",variant:"ghost",onClick:()=>F(100),disabled:$===100,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":i("settings.openchamber.visual.actions.resetSpacingAria"),title:i("settings.common.actions.reset"),children:s.jsx(Mn,{className:"h-3.5 w-3.5"})})]})]}),it("inputBarOffset")&&s.jsxs("div",{className:pe("py-1",c?"flex flex-col gap-3":"flex items-center gap-8"),children:[s.jsx("div",{className:pe("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(St,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:i("settings.openchamber.visual.field.inputBarOffsetTooltip")})]})]})}),s.jsxs("div",{className:pe("flex items-center gap-2",c?"w-full":"w-fit"),children:[s.jsx(jn,{value:V,onValueChange:O,min:0,max:100,step:5,className:"w-16"}),s.jsx(je,{size:"sm",type:"button",variant:"ghost",onClick:()=>O(0),disabled:V===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(Mn,{className:"h-3.5 w-3.5"})})]})]})]})]})}),gs&&s.jsx("div",{className:"space-y-3",children:s.jsxs("section",{className:"px-2 pb-2 pt-0",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.navigation")}),it("terminalQuickKeys")&&!c&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":ae,onClick:()=>ge(!ae),onKeyDown:X=>{(X.key===" "||X.key==="Enter")&&(X.preventDefault(),ge(!ae))},children:[s.jsx(bs,{checked:ae,onChange:ge,ariaLabel:i("settings.openchamber.visual.field.terminalQuickKeysAria")}),s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.terminalQuickKeys")}),s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:i("settings.openchamber.visual.field.terminalQuickKeysTooltip")})]})]})]})]})}),ds&&s.jsxs("div",{className:"space-y-3",children:[(it("userMessageRendering")||it("mermaidRendering")||it("chatRenderMode")||it("messageTransport")||it("activityRenderMode")&&S==="sorted"||it("diffLayout")&&!Yt)&&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:[it("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:u6.map(X=>{const pt=S===X.id,wt=ie%12;return s.jsxs("button",{type:"button",onClick:()=>ye(X.id),"aria-pressed":pt,className:pe("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",pt?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[s.jsx("span",{className:pe("typography-ui-label",pt?"text-foreground":"text-muted-foreground"),children:o(X.labelKey)}),s.jsx("div",{className:"mt-2 w-full rounded-md border border-border/60 bg-muted/30 p-2",children:X.id==="live"?s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(zt=>{const ss=zt*3+1,os=wt-ss+1,Ps=os<=0?0:os===1?42:os===2?68:92,Ms=Ps>0;return s.jsxs("div",{className:pe("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",Ms?"translate-y-0 opacity-100":"translate-y-1 opacity-0"),children:[s.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full bg-muted-foreground/55"}),s.jsx("span",{className:"h-1.5 rounded bg-muted-foreground/30 transition-all duration-300 motion-reduce:transition-none",style:{width:`${Ps}%`}})]},zt)})}):s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(zt=>{const ss=wt>=(zt+1)*3;return s.jsxs("div",{className:pe("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",ss?"translate-y-0 opacity-100":"translate-y-1 opacity-0"),children:[s.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full bg-muted-foreground/55"}),s.jsx("span",{className:"h-1.5 rounded bg-muted-foreground/30",style:{width:"92%"}})]},zt)})})})]},X.id)})})]}),it("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:Sf.map(X=>s.jsx(je,{variant:"chip",size:"xs","aria-pressed":xe===X.id,className:"!font-normal",onClick:()=>Ge(X.id),children:o(X.labelKey)},X.id))}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:(()=>{const X=Sf.find(pt=>pt.id===xe);return X?.descriptionKey?o(X.descriptionKey):""})()})]})]}),it("activityRenderMode")&&S==="sorted"&&s.jsxs("section",{className:"p-2 md:col-span-2",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground",children:i("settings.openchamber.visual.section.activityDefault")}),s.jsx("div",{role:"radiogroup","aria-label":i("settings.openchamber.visual.section.activityDefaultAria"),className:"mt-0.5 space-y-0",children:m6.map(X=>{const pt=j===X.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":pt,onClick:()=>$e(X.id),onKeyDown:wt=>{(wt.key===" "||wt.key==="Enter")&&(wt.preventDefault(),$e(X.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Si,{checked:pt,onChange:()=>$e(X.id),ariaLabel:i("settings.openchamber.visual.field.activityDefaultModeAria",{option:o(X.labelKey)})}),s.jsx("span",{className:pe("typography-ui-label font-normal",pt?"text-foreground":"text-foreground/50"),children:o(X.labelKey)})]},X.id)})})]}),it("expandedTools")&&s.jsxs("section",{className:"p-2 md:col-span-2 space-y-0.5",children:[s.jsx("div",{className:"typography-ui-header font-medium text-foreground py-1.5",children:i("settings.openchamber.visual.section.showToolsOpenedByDefault")}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":me,onClick:()=>Qe(!me),onKeyDown:X=>{(X.key===" "||X.key==="Enter")&&(X.preventDefault(),Qe(!me))},children:[s.jsx(bs,{checked:me,onChange:Qe,ariaLabel:i("settings.openchamber.visual.field.showExpandedBashToolsAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.bash")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":_,onClick:()=>ze(!_),onKeyDown:X=>{(X.key===" "||X.key==="Enter")&&(X.preventDefault(),ze(!_))},children:[s.jsx(bs,{checked:_,onChange:ze,ariaLabel:i("settings.openchamber.visual.field.showExpandedEditToolsAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.editTools")})]})]}),it("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:d6.map(X=>{const pt=p6(f)===X.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":pt,onClick:()=>Xe(X.id),onKeyDown:wt=>{(wt.key===" "||wt.key==="Enter")&&(wt.preventDefault(),Xe(X.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Si,{checked:pt,onChange:()=>Xe(X.id),ariaLabel:i("settings.openchamber.visual.field.userMessageRenderingAria",{option:o(X.labelKey)})}),s.jsx("span",{className:pe("typography-ui-label font-normal",pt?"text-foreground":"text-foreground/50"),children:o(X.labelKey)})]},X.id)})})]}),it("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:c6.map(X=>{const pt=h===X.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":pt,onClick:()=>Ve(X.id),onKeyDown:wt=>{(wt.key===" "||wt.key==="Enter")&&(wt.preventDefault(),Ve(X.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Si,{checked:pt,onChange:()=>Ve(X.id),ariaLabel:i("settings.openchamber.visual.field.mermaidRenderingAria",{option:o(X.labelKey)})}),s.jsx("span",{className:pe("typography-ui-label font-normal",pt?"text-foreground":"text-foreground/50"),children:o(X.labelKey)})]},X.id)})})]}),it("diffLayout")&&!Yt&&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:o6.map(X=>{const pt=B===X.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":pt,onClick:()=>ne(X.id),onKeyDown:wt=>{(wt.key===" "||wt.key==="Enter")&&(wt.preventDefault(),ne(X.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Si,{checked:pt,onChange:()=>ne(X.id),ariaLabel:i("settings.openchamber.visual.field.diffLayoutAria",{option:o(X.labelKey)})}),s.jsx("span",{className:pe("typography-ui-label font-normal",pt?"text-foreground":"text-foreground/50"),children:o(X.labelKey)})]},X.id)})})]}),it("diffLayout")&&!Yt&&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:l6.map(X=>{const pt=le===X.id;return s.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":pt,onClick:()=>ee(X.id),onKeyDown:wt=>{(wt.key===" "||wt.key==="Enter")&&(wt.preventDefault(),ee(X.id))},className:"flex w-full items-center gap-2 py-0 text-left",children:[s.jsx(Si,{checked:pt,onChange:()=>ee(X.id),ariaLabel:i("settings.openchamber.visual.field.diffViewModeAria",{option:o(X.labelKey)})}),s.jsx("span",{className:pe("typography-ui-label font-normal",pt?"text-foreground":"text-foreground/50"),children:o(X.labelKey)})]},X.id)})})]})]}),(it("stickyUserHeader")||it("wideChatLayout")||it("splitAssistantMessageActions")||it("mobileStatusBar")&&c||it("dotfiles")||it("queueMode")||it("persistDraft")||it("showToolFileIcons")||!c&&it("inputSpellcheck")||it("reasoning"))&&s.jsxs("section",{className:"p-2 space-y-0.5",children:[it("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:X=>{(X.key===" "||X.key==="Enter")&&(X.preventDefault(),u(!m))},children:[s.jsx(bs,{checked:m,onChange:u,ariaLabel:i("settings.openchamber.visual.field.showReasoningTracesAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showReasoningTraces")})]}),it("stickyUserHeader")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":x,onClick:()=>mt(!x),onKeyDown:X=>{(X.key===" "||X.key==="Enter")&&(X.preventDefault(),mt(!x))},children:[s.jsx(bs,{checked:x,onChange:mt,ariaLabel:i("settings.openchamber.visual.field.stickyUserHeaderAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.stickyUserHeader")})]}),it("wideChatLayout")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":w,onClick:()=>et(!w),onKeyDown:X=>{(X.key===" "||X.key==="Enter")&&(X.preventDefault(),et(!w))},children:[s.jsx(bs,{checked:w,onChange:et,ariaLabel:i("settings.openchamber.visual.field.wideChatLayoutAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.wideChatLayout")})]}),it("splitAssistantMessageActions")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":Se,onClick:()=>ct(!Se),onKeyDown:X=>{(X.key===" "||X.key==="Enter")&&(X.preventDefault(),ct(!Se))},children:[s.jsx(bs,{checked:Se,onChange:ct,ariaLabel:i("settings.openchamber.visual.field.showSplitAssistantMessageActionsAria")}),s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showSplitAssistantMessageActions")}),s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 cursor-help text-muted-foreground/60"})}),s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:i("settings.openchamber.visual.field.showSplitAssistantMessageActionsTooltip")})]})]})]}),it("showToolFileIcons")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":ce,onClick:()=>tt(!ce),onKeyDown:X=>{(X.key===" "||X.key==="Enter")&&(X.preventDefault(),tt(!ce))},children:[s.jsx(bs,{checked:ce,onChange:tt,ariaLabel:i("settings.openchamber.visual.field.showToolFileIconsAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showToolFileIcons")})]}),it("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:X=>{(X.key===" "||X.key==="Enter")&&(X.preventDefault(),ke(!fe))},children:[s.jsx(bs,{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")})]}),it("dotfiles")&&!yn()&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":p,onClick:()=>Sl(!p),onKeyDown:X=>{(X.key===" "||X.key==="Enter")&&(X.preventDefault(),Sl(!p))},children:[s.jsx(bs,{checked:p,onChange:Sl,ariaLabel:i("settings.openchamber.visual.field.showDotfilesAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.showDotfiles")})]}),it("queueMode")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":te,onClick:()=>E(!te),onKeyDown:X=>{(X.key===" "||X.key==="Enter")&&(X.preventDefault(),E(!te))},children:[s.jsx(bs,{checked:te,onChange:E,ariaLabel:i("settings.openchamber.visual.field.queueMessagesByDefaultAria")}),s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.queueMessagesByDefault")}),s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:i("settings.openchamber.visual.field.queueMessagesByDefaultTooltip",{modifier:ql()})})]})]})]}),it("persistDraft")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-0.5",role:"button",tabIndex:0,"aria-pressed":z,onClick:()=>J(!z),onKeyDown:X=>{(X.key===" "||X.key==="Enter")&&(X.preventDefault(),J(!z))},children:[s.jsx(bs,{checked:z,onChange:J,ariaLabel:i("settings.openchamber.visual.field.persistDraftMessagesAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.persistDraftMessages")})]}),!c&&it("inputSpellcheck")&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":H,onClick:()=>lt(!H),onKeyDown:X=>{(X.key===" "||X.key==="Enter")&&(X.preventDefault(),lt(!H))},children:[s.jsx(bs,{checked:H,onChange:lt,ariaLabel:i("settings.openchamber.visual.field.enableSpellcheckInTextInputsAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.openchamber.visual.field.enableSpellcheckInTextInputs")})]})]})]}),it("reportUsage")&&s.jsx("div",{className:"space-y-3",children:s.jsxs("section",{className:"px-2 pb-2 pt-0",children:[s.jsx("h4",{className:"typography-ui-header font-medium text-foreground mb-2",children:i("settings.openchamber.visual.section.privacy")}),s.jsxs("div",{className:"flex items-start gap-2 py-1.5",children:[s.jsx(bs,{checked:_e,onChange:Ke,ariaLabel:i("settings.openchamber.visual.field.sendAnonymousUsageReportsAria")}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-0.5",children:[s.jsx("div",{className:"group flex cursor-pointer",role:"button",tabIndex:0,"aria-pressed":_e,onClick:()=>Ke(!_e),onKeyDown:X=>{(X.key===" "||X.key==="Enter")&&(X.preventDefault(),Ke(!_e))},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 f6(){if(typeof window>"u")return"unknown";try{const{deviceType:t}=S1();return t}catch{return"unknown"}}function h6(){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 g6(){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 x6(t){const e=Te.getState().reportUsage,n=new URLSearchParams({reportUsage:e?"true":"false"});return n.set("deviceClass",f6()),n.set("arch",h6()),n.set("platform",g6()),t==="desktop"?(n.set("appType",N1()?"desktop-electron":"desktop-tauri"),n.set("instanceMode",oa()?"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 hd(t,e){try{const n=x6(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 b6(){return ri()?oa()?"desktop":"web":yn()?"vscode":ja()?"web":null}const If={checking:!1,available:!1,downloading:!1,downloaded:!1,info:null,progress:null,error:null,runtimeType:null,lastChecked:null,nextCheckInSec:null},Ya=wr()((t,e)=>({...If,checkForUpdates:async()=>{const n=b6();if(!n)return null;t({checking:!0,error:null,runtimeType:n});try{let r=null,a=null;if(n==="desktop"){let i=await zc();t({checking:!1,available:i?.available??!1,info:i,lastChecked:Date.now(),nextCheckInSec:null});const o=await hd("desktop",i?.currentVersion);if(a=o?.nextSuggestedCheckInSec??null,o?.available&&!i?.available){const c=await zc();c&&(i=c)}if(o){const c={...i??{available:!1,currentVersion:o.currentVersion??"unknown"},...o,currentVersion:i?.currentVersion??o.currentVersion??"unknown",available:o.available};t({available:c.available,info:c,nextCheckInSec:a})}else t({nextCheckInSec:a});return a}else n==="web"?(r=await hd("web"),a=r?.nextSuggestedCheckInSec??null):n==="vscode"&&(a=(await hd("vscode"))?.nextSuggestedCheckInSec??null);return t({checking:!1,available:n==="vscode"?!1:r?.available??!1,info:n==="vscode"?null:r,lastChecked:Date.now(),nextCheckInSec:a}),a}catch(r){return t({checking:!1,error:r instanceof Error?r.message:"Failed to check for updates"}),null}},downloadUpdate:async()=>{const{available:n,runtimeType:r}=e();if(!(r!=="desktop"||!n)){t({downloading:!0,error:null,progress:null});try{const a=await zc();if(!a?.available)throw new Error("Update detected, but desktop package is not ready yet. Retry in a moment.");if(t(o=>({info:o.info?{...o.info,...a,body:o.info.body||a.body,available:o.info.available}:a})),!await j1(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 w1())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(If)}})),Af="https://github.com/btriapitsyn/openchamber/releases";function y6(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 v6(t){return t.replace(/^## \[[^\]]+\] - \d{4}-\d{2}-\d{2}\s*\n?/,"").trim()}function Pf(t){return t.replace(/(^|[^a-zA-Z0-9])@([a-zA-Z0-9-]+)/g,"$1[@$2](https://github.com/$2)")}function w6(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 j6(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 Df=2e3,N6=600*1e3;async function S6(){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 k6(){try{return(await fetch("/health",{method:"GET",headers:{Accept:"application/json"}})).ok}catch{return!1}}async function C6(t,e=Math.ceil(N6/Df),n=Df){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 k6())return!0}catch{}await new Promise(a=>setTimeout(a,n))}return!1}const ou=({open:t,onOpenChange:e,info:n,downloading:r,downloaded:a,progress:i,error:o,onDownload:c,onRestart:d,runtimeType:p="desktop"})=>{const{t:m}=ut(),[u,h]=Oe.useState(!1),[b,f]=Oe.useState("idle"),[y,x]=Oe.useState(null),g=n?.version?`${Af}/tag/v${n.version}`:Af,w=i?.total?Math.round(i.downloaded/i.total*100):0,v=p==="web",S=n?.updateCommand||"openchamber update";Oe.useEffect(()=>{t||(f("idle"),x(null))},[t]);const A=async()=>{(await _n(S)).ok&&(h(!0),setTimeout(()=>h(!1),2e3))},j=Oe.useCallback(async k=>{await lr(k)},[]),C=Oe.useCallback(async()=>{f("updating"),x(null);const k=await S6();if(!k.success){f("error"),x(k.error||m("updateDialog.error.updateFailed"));return}k.autoRestart&&(f("restarting"),await new Promise(N=>setTimeout(N,2e3))),f("reconnecting"),await C6(n?.currentVersion)?window.location.reload():(f("error"),x(m("updateDialog.error.takingLonger")))},[n?.currentVersion,m]),I=b!=="idle"&&b!=="error",R=Oe.useMemo(()=>{if(!n?.body)return null;const k=n.body.trim();if(!k)return null;const P=j6(k);if(P.length===0)return{kind:"raw",title:m("updateDialog.changelog.title"),content:Pf(k)};const N=[...P].sort((D,T)=>w6(D.version,T.version));return{kind:"sections",title:m("updateDialog.changelog.title"),sections:N.map(D=>({version:D.version,dateLabel:y6(D.date),content:Pf(v6(D.raw)||k)}))}},[n?.body,m]);return s.jsx(ws,{open:t,onOpenChange:I?void 0:e,children:s.jsxs(vs,{className:"max-w-4xl p-5 bg-background border-[var(--interactive-border)]",showCloseButton:!0,children:[s.jsxs("div",{className:"flex items-center mb-1",children:[s.jsxs(Ss,{className:"flex items-center gap-2.5",children:[s.jsx(Py,{className:"h-5 w-5 text-[var(--primary-base)]"}),s.jsx("span",{className:"text-lg font-semibold text-foreground",children:m(b==="restarting"||b==="reconnecting"?"updateDialog.header.updating":"updateDialog.header.updateAvailable")})]}),(n?.currentVersion||n?.version)&&s.jsxs("div",{className:"flex items-center gap-2 font-mono text-sm ml-3",children:[n?.currentVersion&&s.jsx("span",{className:"text-muted-foreground",children:n.currentVersion}),n?.currentVersion&&n?.version&&s.jsx("span",{className:"text-muted-foreground/50",children:"→"}),n?.version&&s.jsx("span",{className:"text-[var(--primary-base)] font-medium",children:n.version})]})]}),s.jsxs("div",{className:"space-y-2",children:[v&&I&&s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/30 p-5 border border-[var(--surface-subtle)]",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx(jl,{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")})]}),R&&!I&&s.jsx("div",{className:"rounded-lg border border-[var(--surface-subtle)] bg-[var(--surface-elevated)]/20 overflow-hidden",children:s.jsx(Es,{className:"max-h-[400px] p-0",fillContainer:!1,children:R.kind==="raw"?s.jsx("div",{className:"p-4 typography-markdown-body text-foreground leading-relaxed break-words [&_a]:!text-[var(--primary-base)] [&_a]:!no-underline hover:[&_a]:!underline",onClickCapture:k=>{const N=k.target.closest("a");N&&N.href&&(k.preventDefault(),k.stopPropagation(),j(N.href))},children:s.jsx(ai,{content:R.content,disableLinkSafety:!0})}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:R.sections.map(k=>s.jsxs("div",{className:"p-4 hover:bg-background/40 transition-colors",children:[s.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[s.jsxs("span",{className:"typography-ui-label font-mono text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-1.5 py-0.5 rounded",children:["v",k.version]}),s.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:k.dateLabel})]}),s.jsx("div",{className:"typography-markdown-body text-foreground leading-relaxed break-words [&_a]:!text-[var(--primary-base)] [&_a]:!no-underline hover:[&_a]:!underline",onClickCapture:P=>{const D=P.target.closest("a");D&&D.href&&(P.preventDefault(),P.stopPropagation(),j(D.href))},children:s.jsx(ai,{content:k.content,disableLinkSafety:!0})})]},k.version))})})}),v&&b==="error"&&s.jsxs("div",{className:"space-y-2 mt-4",children:[s.jsxs("div",{className:"flex items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx(Yh,{className:"h-4 w-4"}),s.jsx("span",{children:m("updateDialog.fallback.updateViaTerminal")})]}),s.jsxs("div",{className:"flex items-center gap-2 p-1 pl-3 bg-[var(--surface-elevated)]/50 rounded-md border border-[var(--surface-subtle)]",children:[s.jsx("code",{className:"flex-1 font-mono text-sm text-foreground overflow-x-auto whitespace-nowrap",children:S}),s.jsx("button",{onClick:A,className:pe("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(Ys,{className:"h-4 w-4"}):s.jsx(ni,{className:"h-4 w-4"})})]})]}),!v&&r&&s.jsxs("div",{className:"space-y-2 mt-4",children:[s.jsxs("div",{className:"flex items-center justify-between text-sm",children:[s.jsx("span",{className:"text-muted-foreground",children:m("updateDialog.status.downloadingPayload")}),s.jsxs("span",{className:"font-mono text-foreground",children:[w,"%"]})]}),s.jsx("div",{className:"h-1.5 bg-[var(--surface-subtle)] rounded-full overflow-hidden",children:s.jsx("div",{className:"h-full bg-[var(--primary-base)] transition-all duration-300",style:{width:`${w}%`}})})]}),(o||y)&&s.jsx("div",{className:"p-3 mt-4 bg-[var(--status-error-background)] border border-[var(--status-error-border)] rounded-lg",children:s.jsx("p",{className:"text-sm text-[var(--status-error)]",children:o||y})})]}),s.jsxs("div",{className:"mt-4 flex items-center justify-between gap-4",children:[s.jsxs("a",{href: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(Ir,{className:"h-4 w-4"}),"GitHub"]}),s.jsxs("div",{className:"flex-1 flex justify-end",children:[!v&&!a&&!r&&s.jsxs("button",{onClick:c,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)] text-[var(--primary-foreground)] hover:opacity-90 transition-opacity",children:[s.jsx(Qr,{className:"h-4 w-4"}),m("updateDialog.actions.downloadUpdate")]}),!v&&r&&s.jsxs("button",{disabled:!0,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)]/50 text-[var(--primary-foreground)] cursor-not-allowed",children:[s.jsx(jl,{className:"h-4 w-4 animate-spin"}),m("updateDialog.status.downloading")]}),!v&&a&&s.jsxs("button",{onClick:d,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--status-success)] text-white hover:opacity-90 transition-opacity",children:[s.jsx(Mn,{className:"h-4 w-4"}),m("updateDialog.actions.restartToUpdate")]}),v&&!I&&s.jsxs("button",{onClick:C,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)] text-[var(--primary-foreground)] hover:opacity-90 transition-opacity",children:[s.jsx(Qr,{className:"h-4 w-4"}),m("updateDialog.actions.updateNow")]}),v&&I&&s.jsxs("button",{disabled:!0,className:"flex items-center justify-center gap-2 px-5 py-2 rounded-md text-sm font-medium bg-[var(--primary-base)]/50 text-[var(--primary-foreground)] cursor-not-allowed",children:[s.jsx(jl,{className:"h-4 w-4 animate-spin"}),m("updateDialog.status.updating")]})]})]})]})})},Tf="https://github.com/btriapitsyn/openchamber",I6=800,A6=()=>{const t=nt.c(103),{t:e}=ut(),[n,r]=l.useState(!1),[a,i]=l.useState(!1),o=Ya(jr(P6)),{isMobile:c}=un(),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 V=setTimeout(()=>{i(!1),p.current&&!o.available&&!o.error&&(q.success(e("settings.openchamber.about.toast.latestVersion")),p.current=!1)},I6);return()=>clearTimeout(V)}},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 V;t[7]!==d?(V=s.jsxs("span",{className:"typography-meta text-muted-foreground",children:["v",d]}),t[7]=d,t[8]=V):V=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:pe("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 L;t[13]!==h||t[14]!==e||t[15]!==o.available?(L=!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(Qr,{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]=L):L=t[16];let W;t[17]!==V||t[18]!==O||t[19]!==L?(W=s.jsxs("div",{className:"flex items-center justify-between",children:[V,O,L]}),t[17]=V,t[18]=O,t[19]=L,t[20]=W):W=t[20];let B;t[21]!==o.error?(B=o.error&&s.jsx("p",{className:"typography-micro text-[var(--status-error)] truncate",children:o.error}),t[21]=o.error,t[22]=B):B=t[22];let ne;t[23]===Symbol.for("react.memo_cache_sentinel")?(ne=s.jsxs("a",{href:Tf,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(wa,{className:"h-3.5 w-3.5"}),s.jsx("span",{children:"GitHub"})]}),t[23]=ne):ne=t[23];let le;t[24]===Symbol.for("react.memo_cache_sentinel")?(le=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(Xh,{className:"h-3.5 w-3.5"}),s.jsx("span",{children:"Discord"})]}),t[24]=le):le=t[24];let ee;t[25]===Symbol.for("react.memo_cache_sentinel")?(ee=s.jsxs("div",{className:"flex items-center gap-3",children:[ne,le,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(Ed,{className:"h-3.5 w-3.5"}),s.jsx("span",{children:"@btriapitsyn"})]})]}),t[25]=ee):ee=t[25];let ae;t[26]!==n||t[27]!==o.downloadUpdate||t[28]!==o.downloaded||t[29]!==o.downloading||t[30]!==o.error||t[31]!==o.info||t[32]!==o.progress||t[33]!==o.restartToUpdate||t[34]!==o.runtimeType?(ae=s.jsx(ou,{open:n,onOpenChange:r,info:o.info,downloading:o.downloading,downloaded:o.downloaded,progress:o.progress,error:o.error,onDownload:o.downloadUpdate,onRestart:o.restartToUpdate,runtimeType:o.runtimeType}),t[26]=n,t[27]=o.downloadUpdate,t[28]=o.downloaded,t[29]=o.downloading,t[30]=o.error,t[31]=o.info,t[32]=o.progress,t[33]=o.restartToUpdate,t[34]=o.runtimeType,t[35]=ae):ae=t[35];let ge;return t[36]!==ae||t[37]!==W||t[38]!==B?(ge=s.jsxs("div",{className:"w-full space-y-2",children:[W,B,ee,ae]}),t[36]=ae,t[37]=W,t[38]=B,t[39]=ge):ge=t[39],ge}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 y;t[44]!==e?(y=e("settings.openchamber.about.field.version"),t[44]=e,t[45]=y):y=t[45];let x;t[46]!==y?(x=s.jsx("span",{className:"typography-ui-label text-foreground",children:y}),t[46]=y,t[47]=x):x=t[47];let g;t[48]!==d?(g=s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:d}),t[48]=d,t[49]=g):g=t[49];let w;t[50]!==x||t[51]!==g?(w=s.jsxs("div",{className:"flex min-w-0 flex-col",children:[x,g]}),t[50]=x,t[51]=g,t[52]=w):w=t[52];let v;t[53]!==e||t[54]!==o.checking?(v=o.checking&&s.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[s.jsx(jl,{className:"h-4 w-4 animate-spin"}),s.jsx("span",{className:"typography-meta",children:e("settings.openchamber.about.state.checking")})]}),t[53]=e,t[54]=o.checking,t[55]=v):v=t[55];let S;t[56]!==e||t[57]!==o.available||t[58]!==o.checking||t[59]!==o.info?.version?(S=!o.checking&&o.available&&s.jsxs(je,{size:"sm",variant:"default",onClick:()=>r(!0),children:[s.jsx(Qr,{className:"h-4 w-4 mr-1"}),e("settings.openchamber.about.actions.updateToVersion",{version:o.info?.version||""})]}),t[56]=e,t[57]=o.available,t[58]=o.checking,t[59]=o.info?.version,t[60]=S):S=t[60];let A;t[61]!==e||t[62]!==o.available||t[63]!==o.checking||t[64]!==o.error?(A=!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]=A):A=t[65];let j;t[66]!==o?(j=()=>o.checkForUpdates(),t[66]=o,t[67]=j):j=t[67];const C=o.checking;let I;t[68]!==e?(I=e("settings.openchamber.about.actions.checkForUpdates"),t[68]=e,t[69]=I):I=t[69];let R;t[70]!==j||t[71]!==I||t[72]!==o.checking?(R=s.jsx(je,{size:"sm",variant:"outline",onClick:j,disabled:C,children:I}),t[70]=j,t[71]=I,t[72]=o.checking,t[73]=R):R=t[73];let k;t[74]!==A||t[75]!==R||t[76]!==v||t[77]!==S?(k=s.jsxs("div",{className:"flex items-center gap-3",children:[v,S,A,R]}),t[74]=A,t[75]=R,t[76]=v,t[77]=S,t[78]=k):k=t[78];let P;t[79]!==k||t[80]!==w?(P=s.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4 px-4 py-3 border-b border-[var(--surface-subtle)]",children:[w,k]}),t[79]=k,t[80]=w,t[81]=P):P=t[81];let N;t[82]!==o.error?(N=o.error&&s.jsx("div",{className:"px-3 py-2 border-b border-[var(--surface-subtle)]",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:o.error})}),t[82]=o.error,t[83]=N):N=t[83];let D;t[84]===Symbol.for("react.memo_cache_sentinel")?(D=s.jsxs("a",{href:Tf,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(wa,{className:"h-4 w-4"}),s.jsx("span",{children:"GitHub"})]}),t[84]=D):D=t[84];let T;t[85]===Symbol.for("react.memo_cache_sentinel")?(T=s.jsxs("div",{className:"flex items-center gap-4 px-4 py-4",children:[D,s.jsxs("a",{href:"https://x.com/btriapitsyn",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 text-muted-foreground hover:text-foreground typography-meta transition-colors",children:[s.jsx(Ed,{className:"h-4 w-4"}),s.jsx("span",{children:"@btriapitsyn"})]})]}),t[85]=T):T=t[85];let M;t[86]!==P||t[87]!==N?(M=s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[P,N,T]}),t[86]=P,t[87]=N,t[88]=M):M=t[88];let $;t[89]!==n||t[90]!==o.downloadUpdate||t[91]!==o.downloaded||t[92]!==o.downloading||t[93]!==o.error||t[94]!==o.info||t[95]!==o.progress||t[96]!==o.restartToUpdate||t[97]!==o.runtimeType?($=s.jsx(ou,{open:n,onOpenChange:r,info:o.info,downloading:o.downloading,downloaded:o.downloaded,progress:o.progress,error:o.error,onDownload:o.downloadUpdate,onRestart:o.restartToUpdate,runtimeType:o.runtimeType}),t[89]=n,t[90]=o.downloadUpdate,t[91]=o.downloaded,t[92]=o.downloading,t[93]=o.error,t[94]=o.info,t[95]=o.progress,t[96]=o.restartToUpdate,t[97]=o.runtimeType,t[98]=$):$=t[98];let F;return t[99]!==M||t[100]!==$||t[101]!==f?(F=s.jsxs("div",{className:"mb-8",children:[f,M,$]}),t[99]=M,t[100]=$,t[101]=f,t[102]=F):F=t[102],F};function P6(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 D6=1,T6=365,Mf=30,M6=[{value:"archive",labelKey:"settings.openchamber.sessionRetention.action.archive"},{value:"delete",labelKey:"settings.openchamber.sessionRetention.action.delete"}],Bx=()=>{const t=nt.c(113),{t:e}=ut(),n=Te(R6),r=Te(E6),a=Te(F6),i=Te(O6),o=Te(L6),c=Te($6);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}=k1(d),b=p.length;let f;t[1]!==u||t[2]!==e?(f=async()=>{const Z=await u({force:!0});if(Z.completedIds.length===0&&Z.failedIds.length===0){q.message(Z.action==="archive"?e("settings.openchamber.sessionRetention.toast.noneEligibleArchive"):e("settings.openchamber.sessionRetention.toast.noneEligibleDelete"));return}Z.completedIds.length>0&&q.success(Z.action==="archive"?e("settings.openchamber.sessionRetention.toast.archivedCount",{count:Z.completedIds.length}):e("settings.openchamber.sessionRetention.toast.deletedCount",{count:Z.completedIds.length})),Z.failedIds.length>0&&q.error(Z.action==="archive"?e("settings.openchamber.sessionRetention.toast.failedArchiveCount",{count:Z.failedIds.length}):e("settings.openchamber.sessionRetention.toast.failedDeleteCount",{count:Z.failedIds.length}))},t[1]=u,t[2]=e,t[3]=f):f=t[3];const y=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(St,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t[8]=w):w=t[8];let v;t[9]!==e?(v=e("settings.openchamber.sessionRetention.tooltip"),t[9]=e,t[10]=v):v=t[10];let S;t[11]!==v?(S=s.jsxs(kt,{children:[w,s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:v})]}),t[11]=v,t[12]=S):S=t[12];let A;t[13]!==g||t[14]!==S?(A=s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[g,S]})}),t[13]=g,t[14]=S,t[15]=A):A=t[15];let j,C;t[16]!==n||t[17]!==i?(j=()=>i(!n),C=Z=>{(Z.key===" "||Z.key==="Enter")&&(Z.preventDefault(),i(!n))},t[16]=n,t[17]=i,t[18]=j,t[19]=C):(j=t[18],C=t[19]);let I;t[20]!==e?(I=e("settings.openchamber.sessionRetention.field.enableAutoCleanupAria"),t[20]=e,t[21]=I):I=t[21];let R;t[22]!==n||t[23]!==i||t[24]!==I?(R=s.jsx(bs,{checked:n,onChange:i,ariaLabel:I}),t[22]=n,t[23]=i,t[24]=I,t[25]=R):R=t[25];let k;t[26]!==e?(k=e("settings.openchamber.sessionRetention.field.enableAutoCleanup"),t[26]=e,t[27]=k):k=t[27];let P;t[28]!==k?(P=s.jsx("span",{className:"typography-ui-label text-foreground",children:k}),t[28]=k,t[29]=P):P=t[29];let N;t[30]!==n||t[31]!==R||t[32]!==P||t[33]!==j||t[34]!==C?(N=s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":n,onClick:j,onKeyDown:C,children:[R,P]}),t[30]=n,t[31]=R,t[32]=P,t[33]=j,t[34]=C,t[35]=N):N=t[35];let D;t[36]!==e?(D=e("settings.openchamber.sessionRetention.field.retentionPeriod"),t[36]=e,t[37]=D):D=t[37];let T;t[38]!==D?(T=s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:D})}),t[38]=D,t[39]=T):T=t[39];let M;t[40]!==e?(M=e("settings.openchamber.sessionRetention.field.retentionPeriodAria"),t[40]=e,t[41]=M):M=t[41];let $;t[42]!==r||t[43]!==o||t[44]!==M?($=s.jsx(jn,{value:r,onValueChange:o,min:D6,max:T6,step:1,"aria-label":M,className:"w-20 tabular-nums"}),t[42]=r,t[43]=o,t[44]=M,t[45]=$):$=t[45];let F;t[46]!==e?(F=e("settings.openchamber.sessionRetention.field.days"),t[46]=e,t[47]=F):F=t[47];let V;t[48]!==F?(V=s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:F}),t[48]=F,t[49]=V):V=t[49];let O;t[50]!==o?(O=()=>o(Mf),t[50]=o,t[51]=O):O=t[51];const L=r===Mf;let W;t[52]!==e?(W=e("settings.openchamber.sessionRetention.actions.resetRetentionAria"),t[52]=e,t[53]=W):W=t[53];let B;t[54]!==e?(B=e("settings.common.actions.reset"),t[54]=e,t[55]=B):B=t[55];let ne;t[56]===Symbol.for("react.memo_cache_sentinel")?(ne=s.jsx(Mn,{className:"h-3.5 w-3.5"}),t[56]=ne):ne=t[56];let le;t[57]!==O||t[58]!==L||t[59]!==W||t[60]!==B?(le=s.jsx(je,{size:"sm",type:"button",variant:"ghost",onClick:O,disabled:L,className:"h-7 w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":W,title:B,children:ne}),t[57]=O,t[58]=L,t[59]=W,t[60]=B,t[61]=le):le=t[61];let ee;t[62]!==$||t[63]!==V||t[64]!==le?(ee=s.jsxs("div",{className:"flex items-center gap-2 sm:w-fit",children:[$,V,le]}),t[62]=$,t[63]=V,t[64]=le,t[65]=ee):ee=t[65];let ae;t[66]!==T||t[67]!==ee?(ae=s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[T,ee]}),t[66]=T,t[67]=ee,t[68]=ae):ae=t[68];let ge;t[69]!==e?(ge=e("settings.openchamber.sessionRetention.field.whenSessionsExpire"),t[69]=e,t[70]=ge):ge=t[70];let te;t[71]!==ge?(te=s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:ge})}),t[71]=ge,t[72]=te):te=t[72];let E;t[73]!==a||t[74]!==c||t[75]!==e?(E=M6.map(Z=>s.jsx(je,{type:"button",variant:"chip",size:"xs","aria-pressed":a===Z.value,className:"!font-normal",onClick:()=>c(Z.value),children:e(Z.labelKey)},Z.value)),t[73]=a,t[74]=c,t[75]=e,t[76]=E):E=t[76];let z;t[77]!==E?(z=s.jsx("div",{className:"flex flex-wrap items-center gap-1 sm:w-fit",children:E}),t[77]=E,t[78]=z):z=t[78];let J;t[79]!==te||t[80]!==z?(J=s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[te,z]}),t[79]=te,t[80]=z,t[81]=J):J=t[81];let H;t[82]!==N||t[83]!==ae||t[84]!==J?(H=s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[N,ae,J]}),t[82]=N,t[83]=ae,t[84]=J,t[85]=H):H=t[85];let re;t[86]!==e?(re=e("settings.openchamber.sessionRetention.manualCleanup.title"),t[86]=e,t[87]=re):re=t[87];let ce;t[88]!==re?(ce=s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("p",{className:"typography-meta text-foreground font-medium",children:re})}),t[88]=re,t[89]=ce):ce=t[89];let Ne;t[90]!==m||t[91]!==e?(Ne=e(m?"settings.openchamber.sessionRetention.actions.cleaningUp":"settings.openchamber.sessionRetention.actions.runCleanupNow"),t[90]=m,t[91]=e,t[92]=Ne):Ne=t[92];let me;t[93]!==y||t[94]!==m||t[95]!==Ne?(me=s.jsx("div",{className:"flex items-center gap-2 sm:w-fit",children:s.jsx(je,{type:"button",variant:"outline",size:"xs",onClick:y,disabled:m,className:"!font-normal",children:Ne})}),t[93]=y,t[94]=m,t[95]=Ne,t[96]=me):me=t[96];let we;t[97]!==ce||t[98]!==me?(we=s.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-8",children:[ce,me]}),t[97]=ce,t[98]=me,t[99]=we):we=t[99];let _;t[100]!==h||t[101]!==b||t[102]!==e?(_=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]=_):_=t[103];let ue;t[104]!==_?(ue=s.jsx("p",{className:"typography-meta text-muted-foreground",children:_}),t[104]=_,t[105]=ue):ue=t[105];let Q;t[106]!==we||t[107]!==ue?(Q=s.jsxs("div",{className:"mt-1 px-2 py-1.5 space-y-1",children:[we,ue]}),t[106]=we,t[107]=ue,t[108]=Q):Q=t[108];let oe;return t[109]!==H||t[110]!==Q||t[111]!==A?(oe=s.jsxs("div",{className:"mb-8",children:[A,H,Q]}),t[109]=H,t[110]=Q,t[111]=A,t[112]=oe):oe=t[112],oe};function R6(t){return t.autoDeleteEnabled}function E6(t){return t.autoDeleteAfterDays}function F6(t){return t.sessionRetentionAction}function O6(t){return t.setAutoDeleteEnabled}function L6(t){return t.setAutoDeleteAfterDays}function $6(t){return t.setSessionRetentionAction}const Rf=(t,e)=>!t||!Number.isFinite(t)?e:new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"}).format(t),Vx=()=>{const{t}=ut(),[e,n]=l.useState(!1),[r,a]=l.useState(!0),[i,o]=l.useState(!1),[c,d]=l.useState(null),[p,m]=l.useState(!1),[u,h]=l.useState([]),[b,f]=l.useState(C1),[y,x]=l.useState(""),g=l.useMemo(()=>I1(),[]),w=l.useCallback(async()=>{a(!0),x("");try{const j=await A1();h(j)}catch(j){const C=j instanceof Error?j.message:t("settings.openchamber.passkeys.toast.loadFailed");x(C)}finally{a(!1)}},[t]);l.useEffect(()=>{let j=!1;return(async()=>{try{if(!g.supported){j||(n(!1),a(!1));return}j||n(!0)}catch{j||n(!1)}if(!j){const C=await _c();if(f(C),!C.enabled){h([]),a(!1);return}await w()}})(),()=>{j=!0,Dm()}},[w,g.supported]);const v=l.useCallback(async()=>{if(!b.enabled){const j=t("settings.openchamber.passkeys.toast.enableUiPasswordFirst");x(j),q.message(j);return}if(!e){x(g.reason),q.message(g.reason);return}if(i){Dm(),o(!1);return}x(""),o(!0);try{await P1(),f(await _c()),await w(),q.success(t("settings.openchamber.passkeys.toast.added"))}catch(j){if(D1(j)){q.message(t("settings.openchamber.passkeys.toast.setupCanceled"));return}const C=j instanceof Error?j.message:t("settings.openchamber.passkeys.toast.addFailed");x(C),q.error(C)}finally{o(!1)}},[i,w,b.enabled,g.reason,e,t]),S=l.useCallback(async j=>{d(j),x("");try{await T1(j),f(await _c()),await w(),q.success(t("settings.openchamber.passkeys.toast.removed"))}catch(C){const I=C instanceof Error?C.message:t("settings.openchamber.passkeys.toast.removeFailed");x(I),q.error(I)}finally{d(null)}},[w,t]),A=l.useCallback(async()=>{m(!0),x("");try{await M1(),window.location.reload()}catch(j){const C=j instanceof Error?j.message:t("settings.openchamber.passkeys.toast.clearAuthFailed");x(C),q.error(C),m(!1)}},[t]);return s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.openchamber.passkeys.title")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-2",children:[s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.passkeys.field.currentDevice")})}),s.jsxs("div",{className:"flex items-center gap-2 sm:w-fit",children:[s.jsx(je,{type:"button",variant:i?"secondary":"outline",size:"xs",onClick:()=>{v()},disabled:r||p,className:"!font-normal",children:t(i?"settings.openchamber.passkeys.actions.cancelSetup":"settings.openchamber.passkeys.actions.add")}),s.jsx(je,{type:"button",variant:"ghost",size:"xs",onClick:()=>{A()},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:Rf(j.lastUsedAt,t("settings.openchamber.passkeys.time.neverUsed"))}):t("settings.openchamber.passkeys.item.added",{time:Rf(j.createdAt,t("settings.openchamber.passkeys.time.neverUsed"))})}),s.jsx(je,{type:"button",variant:"ghost",size:"xs",onClick:()=>{S(j.id)},disabled:c===j.id,className:"!font-normal text-muted-foreground hover:text-foreground",children:c===j.id?t("settings.openchamber.passkeys.actions.removing"):t("settings.common.actions.delete")})]})]},j.id))})]}),y&&s.jsx("div",{className:"mt-1 px-2 py-1.5",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:y})})]})},B6=t=>{const e=Gi(t);return e||{providerId:"",modelId:""}},zx=()=>{const{t}=ut(),e=yt(T=>T.setProvider),n=yt(T=>T.setModel),r=yt(T=>T.setAgent),a=yt(T=>T.setCurrentVariant),i=yt(T=>T.setSettingsDefaultModel),o=yt(T=>T.setSettingsDefaultVariant),c=yt(T=>T.setSettingsDefaultAgent),d=yt(T=>T.setSettingsDefaultFileViewerPreview),p=yt(T=>T.settingsDefaultFileViewerPreview),m=Te(T=>T.showDeletionDialog),u=Te(T=>T.setShowDeletionDialog),h=yt(T=>T.providers),[b,f]=l.useState(),[y,x]=l.useState(),[g,w]=l.useState(),[v,S]=l.useState(!0),A=l.useMemo(()=>B6(b),[b]);l.useEffect(()=>{(async()=>{try{let M=null;if(!M){const $=xr()?.settings;if($)try{const V=(await $.load())?.settings;V&&(M={defaultModel:typeof V.defaultModel=="string"?V.defaultModel:void 0,defaultVariant:typeof V.defaultVariant=="string"?V.defaultVariant:void 0,defaultAgent:typeof V.defaultAgent=="string"?V.defaultAgent:void 0})}catch{}}if(!M){const $=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});$.ok&&(M=await $.json())}if(M){const $=typeof M.defaultModel=="string"&&M.defaultModel.trim().length>0?M.defaultModel.trim():void 0,F=typeof M.defaultVariant=="string"&&M.defaultVariant.trim().length>0?M.defaultVariant.trim():void 0,V=typeof M.defaultAgent=="string"&&M.defaultAgent.trim().length>0?M.defaultAgent.trim():void 0;$!==void 0&&f($),F!==void 0&&x(F),V!==void 0&&w(V)}}catch(M){console.warn("Failed to load defaults settings:",M)}finally{S(!1)}})()},[]);const j=l.useCallback(async(T,M)=>{const $=T&&M?`${T}/${M}`:void 0;f($),x(void 0),o(void 0),a(void 0),i($),T&&M&&h.find(V=>V.id===T)&&(e(T),n(M));try{await Rs({defaultModel:$??"",defaultVariant:""});const F=await fetch("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({defaultModel:$})});F.ok||console.warn("Failed to save default model to server:",F.status,F.statusText)}catch(F){console.warn("Failed to save default model:",F)}},[h,a,n,e,i,o]),C="__default__",I=l.useCallback(T=>T===C?t("settings.openchamber.defaults.option.default"):T.charAt(0).toUpperCase()+T.slice(1),[t]),R=l.useCallback(async T=>{const M=T===C?void 0:T||void 0;x(M),o(M),a(M);try{await Rs({defaultVariant:M??""})}catch($){console.warn("Failed to save default variant:",$)}},[a,o]),k=l.useCallback(async T=>{const M=T||void 0;w(M),c(M),T&&r(T);try{await Rs({defaultAgent:M??""})}catch($){console.warn("Failed to save default agent:",$)}},[r,c]),P=l.useCallback(()=>{const T=!p;d(T),Rs({defaultFileViewerPreview:T}).catch(console.warn)},[p,d]),N=l.useMemo(()=>{if(!A.providerId||!A.modelId)return[];const $=h.find(F=>F.id===A.providerId)?.models.find(F=>F.id===A.modelId)?.variants;return $?Object.keys($):[]},[A.modelId,A.providerId,h]),D=N.length>0;return l.useEffect(()=>{!D&&y&&(x(void 0),o(void 0),a(void 0),Rs({defaultVariant:""}).catch(()=>{}))},[y,a,o,D]),v?null:s.jsxs("div",{className:"mb-6",children:[s.jsx("div",{className:"mb-0.5 px-1",children:s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.openchamber.defaults.title")})})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[s.jsxs("div",{className:"mt-0 mb-1 typography-meta text-muted-foreground",children:[t("settings.openchamber.defaults.summaryPrefix")," ",A.providerId?s.jsxs("span",{className:"text-foreground",children:[A.providerId,"/",A.modelId,D?` (${y??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:pe("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(Ho,{providerId:A.providerId,modelId:A.modelId,onChange:j})})]}),s.jsxs("div",{className:"flex flex-col gap-2 py-1 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.defaults.field.defaultThinking")})}),s.jsx("div",{className:"flex items-center gap-2 sm:w-fit",children:s.jsxs(ps,{value:y??C,onValueChange:R,disabled:!D,children:[s.jsx(fs,{className:"w-fit min-w-[120px]",children:s.jsx(ys,{placeholder:t("settings.openchamber.defaults.field.thinkingPlaceholder"),children:I(y??C)})}),s.jsxs(hs,{children:[s.jsx(Ot,{value:C,children:t("settings.openchamber.defaults.option.default")}),N.map(T=>s.jsx(Ot,{value:T,children:I(T)},T))]})]})})]}),s.jsxs("div",{className:"flex flex-col gap-2 py-1 sm:flex-row sm:items-center sm:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.defaults.field.defaultAgent")})}),s.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:s.jsx(jc,{agentName:g||"",onChange:k})})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1",role:"button",tabIndex:0,"aria-pressed":m,onClick:()=>u(!m),onKeyDown:T=>{(T.key===" "||T.key==="Enter")&&(T.preventDefault(),u(!m))},children:[s.jsx(bs,{checked:m,onChange:u,ariaLabel:t("settings.openchamber.defaults.field.showDeletionDialogAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.defaults.field.showDeletionDialog")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1",role:"button",tabIndex:0,"aria-pressed":p,onClick:P,onKeyDown:T=>{(T.key===" "||T.key==="Enter")&&(T.preventDefault(),P())},children:[s.jsx(bs,{checked:p,onChange:d,ariaLabel:t("settings.openchamber.defaults.field.openFilesPreviewAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.defaults.field.openFilesPreview")})]})]})]})},Ef={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"}},V6={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"},Ff="big-pickle",gd="__not_selected__",Of=200,Lf=100,$f=250,z6=()=>{const{t}=ut(),{isMobile:e}=un(),n=l.useMemo(()=>kn(),[]),r=l.useMemo(()=>yn(),[]),a=!n&&!r,i=Te(_=>_.nativeNotificationsEnabled),o=Te(_=>_.setNativeNotificationsEnabled),c=Te(_=>_.notificationMode),d=Te(_=>_.setNotificationMode),p=Te(_=>_.notifyOnSubtasks),m=Te(_=>_.setNotifyOnSubtasks),u=Te(_=>_.notifyOnCompletion),h=Te(_=>_.setNotifyOnCompletion),b=Te(_=>_.notifyOnError),f=Te(_=>_.setNotifyOnError),y=Te(_=>_.notifyOnQuestion),x=Te(_=>_.setNotifyOnQuestion),g=Te(_=>_.notificationTemplates),w=Te(_=>_.setNotificationTemplates),v=Te(_=>_.summarizeLastMessage),S=Te(_=>_.setSummarizeLastMessage),A=Te(_=>_.summaryThreshold),j=Te(_=>_.setSummaryThreshold),C=Te(_=>_.summaryLength),I=Te(_=>_.setSummaryLength),R=Te(_=>_.maxLastMessageLength),k=Te(_=>_.setMaxLastMessageLength),P=yt(_=>_.settingsZenModel),N=yt(_=>_.setSettingsZenModel),[D,T]=l.useState("default"),[M,$]=l.useState(!1),[F,V]=l.useState(!1),[O,L]=l.useState(!1),[W,B]=l.useState([]);l.useEffect(()=>{const _=new AbortController;return fetch("/api/zen/models",{method:"GET",headers:{Accept:"application/json"},signal:_.signal}).then(async ue=>{if(!ue.ok)return[];const Q=await ue.json().catch(()=>({}));return(Array.isArray(Q?.models)?Q.models:[]).map(Z=>{const Ie=typeof Z?.id=="string"?Z.id.trim():"";return Ie?{id:Ie,name:Ie}:null}).filter(Z=>Z!==null)}).then(ue=>{B(ue)}).catch(ue=>{ue?.name!=="AbortError"&&console.warn("Failed to load zen utility models:",ue)}),()=>{_.abort()}},[]);const ne=l.useMemo(()=>W,[W]),le=l.useMemo(()=>P&&ne.some(_=>_.id===P)?P:ne.some(_=>_.id===Ff)?Ff:ne[0]?.id??"",[P,ne]),ee=l.useCallback(async _=>{const ue=_===gd?void 0:_;N(ue);try{await Rs({zenModel:ue??"",gitProviderId:"",gitModelId:""})}catch(Q){console.warn("Failed to save utility model setting:",Q)}},[N]);l.useEffect(()=>{if(!a){$(!1),V(!1);return}typeof Notification<"u"&&T(Notification.permission);const _=typeof window<"u"&&"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window;$(_),(async()=>{if(!_){V(!1);return}try{const Q=await navigator.serviceWorker.getRegistration();if(!Q){V(!1);return}const oe=await Q.pushManager.getSubscription();V(!!oe)}catch{V(!1)}})()},[a]);const ae=async _=>{if(n){o(_);return}if(!a){o(_);return}if(_&&typeof Notification<"u"&&Notification.permission==="default")try{const ue=await Notification.requestPermission();T(ue),ue==="granted"?o(!0):q.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.description")})}catch(ue){console.error("Failed to request notification permission:",ue),q.error(t("settings.notifications.page.toast.requestPermissionFailed"))}else o(!!(_&&D==="granted"))},ge=n||r||a&&typeof Notification<"u"&&Notification.permission==="granted",te=(_,ue,Q)=>{w({...g,[_]:{...g[_],[ue]:Q}})},E=_=>{const ue="=".repeat((4-_.length%4)%4),Q=(_+ue).replace(/-/g,"+").replace(/_/g,"/"),oe=atob(Q),Z=new Uint8Array(oe.length);for(let Ie=0;Ie<oe.length;Ie+=1)Z[Ie]=oe.charCodeAt(Ie);return Z},z=async(_,ue,Q)=>{let oe=null;const Z=new Promise((Ie,Se)=>{oe=setTimeout(()=>{Se(new Error(Q))},ue)});try{return await Promise.race([_,Z])}finally{oe&&clearTimeout(oe)}},J=async _=>{if(_.active)return;const ue=_.installing||_.waiting;ue&&ue.state!=="activated"&&await z(new Promise(Q=>{const oe=()=>{ue.state==="activated"&&(ue.removeEventListener("statechange",oe),Q())};ue.addEventListener("statechange",oe),oe()}),15e3,"Service worker activation timed out")},H=async()=>{if(typeof navigator.serviceWorker.register!="function")throw new Error("navigator.serviceWorker.register unavailable");const _=[{label:"no-options",opts:null},{label:"scope-root",opts:{scope:"/"}},{label:"type-classic",opts:{type:"classic"}},{label:"type-classic-scope",opts:{type:"classic",scope:"/"}},{label:"updateViaCache-none",opts:{type:"classic",updateViaCache:"none",scope:"/"}}];let ue=null;for(const Q of _)try{const oe=Q.opts?navigator.serviceWorker.register("/sw.js",Q.opts):navigator.serviceWorker.register("/sw.js");return await z(oe,1e4,`Service worker registration timed out (${Q.label})`)}catch(oe){ue=oe}throw ue instanceof Error?ue:new Error("Service worker registration failed")},re=async()=>{if(!("serviceWorker"in navigator))throw new Error("Service worker not supported");const _=await navigator.serviceWorker.getRegistration();if(_)return _;const ue=await H();try{await ue.update()}catch{}return await J(ue),ue},ce=_=>{const ue=_,Q=[`type=${typeof _}`,`toString=${String(_)}`,`name=${String(ue?.name??"")}`,`message=${String(ue?.message??"")}`];let oe="";try{oe=JSON.stringify(_)}catch{}return{summary:Q.filter(Boolean).join(" | "),json:oe,stack:typeof ue?.stack=="string"?ue.stack:""}},Ne=async()=>{const _=xr();if(!_?.notifications){q.error(t("settings.notifications.page.toast.notificationsApiUnavailable"));return}try{await _.notifications.notifyAgentCompletion({title:t("settings.notifications.page.testNotification.title"),body:t("settings.notifications.page.testNotification.body"),tag:"openchamber-test"})?q.success(t("settings.notifications.page.toast.testNotificationSent")):q.error(t("settings.notifications.page.toast.testNotificationFailed"))}catch(ue){console.error("Test notification failed:",ue),q.error(t("settings.notifications.page.toast.testNotificationFailed"))}},me=async()=>{if(!M){q.error(t("settings.notifications.page.toast.pushUnsupported"));return}const _=xr();if(!_?.push){q.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}L(!0);try{if(typeof Notification<"u"&&Notification.permission==="default"){const fe=await Notification.requestPermission();if(T(fe),fe!=="granted"){q.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}}if(typeof Notification<"u"&&Notification.permission!=="granted"){q.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}const ue=await _.push.getVapidPublicKey();if(!ue?.publicKey){q.error(t("settings.notifications.page.toast.pushKeyLoadFailed"));return}const Q=await re();await J(Q);const oe=await Q.pushManager.getSubscription();if(!("pushManager"in Q)||!Q.pushManager)throw new Error("PushManager unavailable (requires installed PWA + iOS 16.4+)");const Ie=(oe??await z(Q.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:E(ue.publicKey)}),15e3,"Push subscription timed out")).toJSON(),Se=Ie.keys;if(!Ie.endpoint||!Se?.p256dh||!Se.auth)throw new Error("Push subscription missing keys");if(!(await z(_.push.subscribe({endpoint:Ie.endpoint,keys:{p256dh:Se.p256dh,auth:Se.auth},origin:typeof window<"u"?window.location.origin:void 0}),15e3,"Push subscribe request timed out"))?.ok){q.error(t("settings.notifications.page.toast.enableBackgroundFailed"));return}V(!0),q.success(t("settings.notifications.page.toast.backgroundEnabled"))}catch(ue){console.error("[Push] Enable failed:",ue);const Q=ce(ue);q.error(t("settings.notifications.page.toast.enableBackgroundFailed"),{description:Q.summary})}finally{L(!1)}},we=async()=>{if(!M){V(!1);return}const _=xr();if(!_?.push){q.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}L(!0);try{const Q=await(await re()).pushManager.getSubscription();if(!Q){V(!1);return}const oe=Q.endpoint;await Q.unsubscribe(),await _.push.unsubscribe({endpoint:oe}),V(!1),q.success(t("settings.notifications.page.toast.backgroundDisabled"))}finally{L(!1)}};return s.jsxs("div",{className:"space-y-8",children:[s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.notifications.page.delivery.title")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":i&&ge,onClick:()=>{ae(!(i&&ge))},onKeyDown:_=>{(_.key===" "||_.key==="Enter")&&(_.preventDefault(),ae(!(i&&ge)))},children:[s.jsx(bs,{checked:i&&ge,onChange:_=>{ae(_)},ariaLabel:t("settings.notifications.page.delivery.enableAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.delivery.enableLabel")})]}),i&&ge&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":c==="always",onClick:()=>d(c==="always"?"hidden-only":"always"),onKeyDown:_=>{(_.key===" "||_.key==="Enter")&&(_.preventDefault(),d(c==="always"?"hidden-only":"always"))},children:[s.jsx(bs,{checked:c==="always",onChange:_=>d(_?"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(je,{type:"button",variant:"outline",size:"sm",onClick:()=>{Ne()},children:t("settings.notifications.page.delivery.testAction")})})]})]}),a&&s.jsxs("div",{className:"mt-1 px-2",children:[s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.notifications.page.delivery.browserPermissionHint")}),D==="denied"&&s.jsx("p",{className:"typography-meta text-[var(--status-error)] mt-1",children:t("settings.notifications.page.delivery.permissionDenied")}),D==="granted"&&!i&&s.jsx("p",{className:"typography-meta text-muted-foreground/70 mt-1",children:t("settings.notifications.page.delivery.permissionGrantedButDisabled")})]}),r&&s.jsx("div",{className:"mt-1 px-2",children:s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.notifications.page.delivery.vscodeHint")})})]}),i&&ge&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.notifications.page.events.title")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":u,onClick:()=>h(!u),onKeyDown:_=>{(_.key===" "||_.key==="Enter")&&(_.preventDefault(),h(!u))},children:[s.jsx(bs,{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:_=>{(_.key===" "||_.key==="Enter")&&(_.preventDefault(),m(!p))},children:[s.jsx(bs,{checked:p,onChange:m,ariaLabel:t("settings.notifications.page.events.subtaskAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.events.subtaskLabel")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":b,onClick:()=>f(!b),onKeyDown:_=>{(_.key===" "||_.key==="Enter")&&(_.preventDefault(),f(!b))},children:[s.jsx(bs,{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":y,onClick:()=>x(!y),onKeyDown:_=>{(_.key===" "||_.key==="Enter")&&(_.preventDefault(),x(!y))},children:[s.jsx(bs,{checked:y,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(_=>s.jsxs("section",{className:"p-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground font-normal capitalize block",children:t(V6[_])}),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(Vt,{value:g[_].title,onChange:ue=>te(_,"title",ue.target.value),className:"h-7",placeholder:t(Ef[_].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(Vt,{value:g[_].message,onChange:ue=>te(_,"message",ue.target.value),className:"h-7",placeholder:t(Ef[_].messageKey)})]})]})]},_))})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.notifications.page.summary.title")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":v,onClick:()=>S(!v),onKeyDown:_=>{(_.key===" "||_.key==="Enter")&&(_.preventDefault(),S(!v))},children:[s.jsx(bs,{checked:v,onChange:S,ariaLabel:t("settings.notifications.page.summary.toggleAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.summary.toggleLabel")})]}),s.jsx("div",{className:"pl-6 pb-1",children:s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[t("settings.notifications.page.summary.requiresTemplateVariable")," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{last_message}"}),"."]})}),s.jsxs("div",{className:pe("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(St,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:t("settings.notifications.page.summary.modelTooltip")})]})]})}),s.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:s.jsxs(ps,{value:le||gd,onValueChange:ee,children:[s.jsx(fs,{className:"w-fit min-w-[220px]",children:s.jsx(ys,{placeholder:t("settings.notifications.page.summary.notSelected")})}),s.jsxs(hs,{children:[s.jsx(Ot,{value:gd,children:t("settings.notifications.page.summary.notSelected")}),ne.map(_=>s.jsx(Ot,{value:_.id,children:_.name},_.id))]})]})})]}),v?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex items-center gap-8 py-1.5 mt-1 border-t border-[var(--surface-subtle)]",children:[s.jsxs("div",{className:"flex min-w-0 flex-col w-56 shrink-0",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.notifications.page.summary.thresholdLabel")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.notifications.page.summary.thresholdHint")})]}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[s.jsx(jn,{value:A,onValueChange:j,min:50,max:2e3,step:50,className:"w-20 tabular-nums"}),s.jsx(je,{size:"sm",type:"button",variant:"ghost",onClick:()=>j(Of),disabled:A===Of,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(Mn,{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(jn,{value:C,onValueChange:I,min:20,max:500,step:10,className:"w-20 tabular-nums"}),s.jsx(je,{size:"sm",type:"button",variant:"ghost",onClick:()=>I(Lf),disabled:C===Lf,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(Mn,{className:"h-3.5 w-3.5"})})]})]})]}):s.jsxs("div",{className:pe("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:pe("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:pe("flex items-center gap-2",e?"w-full":"w-fit"),children:[s.jsx(jn,{value:R,onValueChange:k,min:50,max:1e3,step:10,className:"w-20 tabular-nums"}),s.jsx(je,{size:"sm",type:"button",variant:"ghost",onClick:()=>k($f),disabled:R===$f,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(Mn,{className:"h-3.5 w-3.5"})})]})]})]})]})]}),a&&s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.notifications.page.push.title")})}),s.jsx("section",{className:"px-2 pb-2 pt-0",children:s.jsxs("div",{className:"flex items-start gap-2 py-1.5",children:[s.jsx(bs,{checked:M?F:!1,disabled:!M||O,onChange:_=>{_?me():we()},ariaLabel:t("settings.notifications.page.push.enableAria")}),s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:pe("typography-ui-label",M?"text-foreground":"text-muted-foreground"),children:t("settings.notifications.page.push.enableLabel")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t(M?"settings.notifications.page.push.supportedHint":"settings.notifications.page.push.unsupportedHint")})]}),O&&s.jsx("div",{className:"pt-0.5 text-muted-foreground",children:s.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-current animate-busy-pulse","aria-label":t("settings.notifications.page.push.loadingAria")})})]})})]})]})},_6=[{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:"Українська"}],U6=[{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"}],W6=()=>{const{t}=ut(),{isMobile:e}=un(),{isSupported:n,language:r,setLanguage:a}=R1(),i=yt(K=>K.voiceProvider),o=yt(K=>K.setVoiceProvider),c=yt(K=>K.speechRate),d=yt(K=>K.setSpeechRate),p=yt(K=>K.speechPitch),m=yt(K=>K.setSpeechPitch),u=yt(K=>K.speechVolume),h=yt(K=>K.setSpeechVolume),b=yt(K=>K.sayVoice),f=yt(K=>K.setSayVoice),y=yt(K=>K.browserVoice),x=yt(K=>K.setBrowserVoice),g=yt(K=>K.openaiVoice),w=yt(K=>K.setOpenaiVoice),v=yt(K=>K.openaiApiKey),S=yt(K=>K.setOpenaiApiKey),A=yt(K=>K.openaiCompatibleUrl),j=yt(K=>K.setOpenaiCompatibleUrl),C=yt(K=>K.openaiCompatibleVoice),I=yt(K=>K.setOpenaiCompatibleVoice),R=yt(K=>K.openaiCompatibleTtsModel),k=yt(K=>K.setOpenaiCompatibleTtsModel),P=yt(K=>K.showMessageTTSButtons),N=yt(K=>K.sttProvider),D=yt(K=>K.setSttProvider),T=yt(K=>K.sttServerUrl),M=yt(K=>K.setSttServerUrl),$=yt(K=>K.sttModel),F=yt(K=>K.setSttModel),V=yt(K=>K.sttLanguage),O=yt(K=>K.setSttLanguage),L=yt(K=>K.sttSilenceThresholdDb),W=yt(K=>K.setSttSilenceThresholdDb),B=yt(K=>K.sttSilenceHoldMs),ne=yt(K=>K.setSttSilenceHoldMs),le=yt(K=>K.setShowMessageTTSButtons),ee=yt(K=>K.voiceModeEnabled),ae=yt(K=>K.setVoiceModeEnabled),ge=yt(K=>K.summarizeMessageTTS),te=yt(K=>K.setSummarizeMessageTTS),E=yt(K=>K.summarizeVoiceConversation),z=yt(K=>K.setSummarizeVoiceConversation),J=yt(K=>K.summarizeCharacterThreshold),H=yt(K=>K.setSummarizeCharacterThreshold),re=yt(K=>K.summarizeMaxLength),ce=yt(K=>K.setSummarizeMaxLength),[Ne,me]=Oe.useState(!1),[we,_]=Oe.useState([]),[ue,Q]=Oe.useState(!1),[oe,Z]=Oe.useState(null),[Ie,Se]=Oe.useState(!1),[Y,fe]=Oe.useState(!1),[ke,xe]=Oe.useState(null),[he,Pe]=Oe.useState(!1),[Be,G]=Oe.useState(null),[be,De]=Oe.useState([]),[Ae,ve]=Oe.useState(!1);Oe.useEffect(()=>((async()=>{const _e=await Uc.waitForVoices();De(_e)})(),"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=()=>{De(window.speechSynthesis.getVoices())}),()=>{"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=null)}),[]);const U=Oe.useMemo(()=>be.filter(K=>K.lang).sort((K,_e)=>{const He=K.lang.startsWith("en"),Ke=_e.lang.startsWith("en");if(He&&!Ke)return-1;if(!He&&Ke)return 1;const Ze=K.lang.localeCompare(_e.lang);return Ze!==0?Ze:K.name.localeCompare(_e.name)}),[be]),de=Oe.useCallback(()=>{if(Ae){Uc.cancelSpeech(),ve(!1);return}const K=be.find(Ze=>Ze.name===y),_e=K?.name??t("settings.voice.page.preview.browserVoiceFallback"),He=t("settings.voice.page.preview.voiceLine",{voiceName:_e});ve(!0);const Ke=new SpeechSynthesisUtterance(He);Ke.rate=c,Ke.pitch=p,Ke.volume=u,K&&(Ke.voice=K,Ke.lang=K.lang),Ke.onend=()=>ve(!1),Ke.onerror=()=>ve(!1),window.speechSynthesis.cancel(),window.speechSynthesis.speak(Ke)},[y,be,c,p,u,Ae,t]);Oe.useEffect(()=>()=>{Ae&&Uc.cancelSpeech()},[Ae]),Oe.useEffect(()=>{if(!ee||i!=="openai"&&i!=="openai-compatible"){Se(v.trim().length>0);return}(async()=>{try{const Ke=(await(await fetch("/api/tts/status")).json()).available,Ze=v.trim().length>0;Se(Ke||Ze)}catch{Se(v.trim().length>0)}})()},[v,ee,i]),Oe.useEffect(()=>{if(!ee){me(!1),_([]);return}fetch("/api/tts/say/status").then(K=>K.json()).then(K=>{if(me(K.available),K.voices){const _e=K.voices.filter((He,Ke,Ze)=>Ze.findIndex(Xe=>Xe.name===He.name)===Ke).sort((He,Ke)=>He.name.localeCompare(Ke.name));_(_e)}}).catch(()=>{me(!1)})},[ee]);const Re=Oe.useCallback(async()=>{if(oe){oe.pause(),oe.currentTime=0,Z(null),Q(!1);return}Q(!0);try{const K=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(!K.ok)throw new Error("Preview failed");const _e=await K.blob(),He=URL.createObjectURL(_e),Ke=new Audio(He);Ke.onended=()=>{URL.revokeObjectURL(He),Z(null),Q(!1)},Ke.onerror=()=>{URL.revokeObjectURL(He),Z(null),Q(!1)},Z(Ke),await Ke.play()}catch{Q(!1)}},[b,c,oe,t]);Oe.useEffect(()=>()=>{oe&&oe.pause()},[oe]);const Le=Oe.useCallback(async()=>{if(ke){ke.pause(),ke.currentTime=0,xe(null),fe(!1);return}fe(!0);try{const K=await fetch("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:g}),voice:g,speed:c,apiKey:v||void 0})});if(!K.ok){const Ze=await K.json().catch(()=>({error:"Unknown error"}));throw new Error(Ze.error||`HTTP ${K.status}`)}const _e=await K.blob(),He=URL.createObjectURL(_e),Ke=new Audio(He);Ke.onended=()=>{URL.revokeObjectURL(He),xe(null),fe(!1)},Ke.onerror=()=>{URL.revokeObjectURL(He),xe(null),fe(!1)},xe(Ke),await Ke.play()}catch{fe(!1)}},[g,c,ke,v,t]);Oe.useEffect(()=>()=>{ke&&ke.pause()},[ke]);const se=Oe.useCallback(async()=>{if(Be){Be.pause(),Be.currentTime=0,G(null),Pe(!1);return}if(A.trim()){Pe(!0);try{const K=await fetch("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.customServerLine"),voice:C,model:R||void 0,speed:c,baseURL:A})});if(!K.ok){const Ze=await K.json().catch(()=>({error:"Unknown error"}));throw new Error(Ze.error||`HTTP ${K.status}`)}const _e=await K.blob(),He=URL.createObjectURL(_e),Ke=new Audio(He);Ke.onended=()=>{URL.revokeObjectURL(He),G(null),Pe(!1)},Ke.onerror=()=>{URL.revokeObjectURL(He),G(null),Pe(!1)},G(Ke),await Ke.play()}catch{Pe(!1)}}},[A,C,R,c,Be,t]);Oe.useEffect(()=>()=>{Be&&Be.pause()},[Be]);const ie="flex-1 min-w-0 h-1.5 bg-[var(--interactive-border)] rounded-full appearance-none cursor-pointer [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:w-4 [&::-webkit-slider-thumb]:h-4 [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:bg-[var(--primary-base)] [&::-moz-range-thumb]:w-4 [&::-moz-range-thumb]:h-4 [&::-moz-range-thumb]:rounded-full [&::-moz-range-thumb]:bg-[var(--primary-base)] [&::-moz-range-thumb]:border-0 disabled:opacity-50";return s.jsxs("div",{className:"space-y-8",children:[s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.voice.page.section.voiceSetup")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":ee,onClick:()=>ae(!ee),onKeyDown:K=>{(K.key===" "||K.key==="Enter")&&(K.preventDefault(),ae(!ee))},children:[s.jsx(bs,{checked:ee,onChange:ae,ariaLabel:t("settings.voice.page.field.enableVoiceModeAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.enableVoiceMode")})]}),ee&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"pb-1.5 pt-0.5",children:s.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.provider")}),s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{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(je,{variant:"chip",size:"xs","aria-pressed":i==="browser",onClick:()=>o("browser"),className:"!font-normal",children:t("settings.voice.page.provider.browser")}),s.jsx(je,{variant:"chip",size:"xs","aria-pressed":i==="openai",onClick:()=>o("openai"),className:"!font-normal",children:"OpenAI"}),s.jsx(je,{variant:"chip",size:"xs","aria-pressed":i==="openai-compatible",onClick:()=>o("openai-compatible"),className:"!font-normal",children:t("settings.voice.page.provider.custom")}),Ne&&s.jsxs(je,{variant:"chip",size:"xs","aria-pressed":i==="say",onClick:()=>o("say"),className:"!font-normal",children:[s.jsx(Dy,{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:pe("typography-ui-label text-foreground",!Ie&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.apiKey")}),s.jsx("span",{className:pe("typography-meta ml-2",Ie?"text-muted-foreground":"text-[var(--status-error)]/80"),children:t(Ie&&!v?"settings.voice.page.field.apiKeyHintUsingConfig":Ie?"settings.voice.page.field.apiKeyHintProvide":"settings.voice.page.field.apiKeyHintRequired")}),s.jsxs("div",{className:"relative mt-1.5 max-w-xs",children:[s.jsx("input",{type:"password",value:v,onChange:K=>S(K.target.value),placeholder:"sk-...",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),v&&s.jsx("button",{type:"button",onClick:()=>S(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(Ds,{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:pe("typography-ui-label text-foreground",!A.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:A,onChange:K=>j(K.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"}),A&&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(Ds,{className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.model")}),s.jsx("div",{className:"relative mt-1.5 max-w-xs",children:s.jsx("input",{type:"text",value:R,onChange:K=>k(K.target.value),placeholder:"speaches-ai/Kokoro-82M-v1.0-ONNX",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})})]}),s.jsxs("div",{children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.voice")}),s.jsx("span",{className:"typography-meta ml-2 text-muted-foreground",children:t("settings.voice.page.field.voiceIdentifierHint")}),s.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[s.jsx("div",{className:"relative max-w-xs flex-1",children:s.jsx("input",{type:"text",value:C,onChange:K=>I(K.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(je,{size:"xs",variant:"ghost",onClick:se,title:t("settings.voice.page.actions.preview"),disabled:!A.trim(),children:he?s.jsx(Kr,{className:"w-3.5 h-3.5"}):s.jsx(Wr,{className:"w-3.5 h-3.5"})})]})]})]}),s.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:t("settings.voice.page.field.voice")}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[i==="openai"&&Ie&&s.jsxs(s.Fragment,{children:[s.jsxs(ps,{value:g,onValueChange:w,children:[s.jsx(fs,{className:"w-fit",children:s.jsx(ys,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(hs,{children:U6.map(K=>s.jsx(Ot,{value:K.value,children:K.label},K.value))})]}),s.jsx(je,{size:"xs",variant:"ghost",onClick:Le,title:t("settings.voice.page.actions.preview"),children:Y?s.jsx(Kr,{className:"w-3.5 h-3.5"}):s.jsx(Wr,{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"&&Ne&&we.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(ps,{value:b,onValueChange:f,children:[s.jsx(fs,{className:"w-fit",children:s.jsx(ys,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(hs,{children:we.map(K=>s.jsx(Ot,{value:K.name,children:K.name},K.name))})]}),s.jsx(je,{size:"xs",variant:"ghost",onClick:Re,title:t("settings.voice.page.actions.preview"),children:ue?s.jsx(Kr,{className:"w-3.5 h-3.5"}):s.jsx(Wr,{className:"w-3.5 h-3.5"})})]}),i==="browser"&&U.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(ps,{value:y||"__auto__",onValueChange:K=>x(K==="__auto__"?"":K),children:[s.jsx(fs,{className:"w-fit max-w-[200px]",children:s.jsx(ys,{placeholder:t("settings.voice.page.field.auto")})}),s.jsxs(hs,{children:[s.jsx(Ot,{value:"__auto__",children:t("settings.voice.page.field.auto")}),U.map(K=>s.jsxs(Ot,{value:K.name,children:[K.name," (",K.lang,")"]},K.name))]})]}),s.jsx(je,{size:"xs",variant:"ghost",onClick:de,title:t("settings.voice.page.actions.preview"),children:Ae?s.jsx(Kr,{className:"w-3.5 h-3.5"}):s.jsx(Wr,{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:K=>d(Number(K.target.value)),disabled:!n,className:ie}),s.jsx(jn,{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:K=>m(Number(K.target.value)),disabled:!n,className:ie}),s.jsx(jn,{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:K=>h(Number(K.target.value)),disabled:!n,className:ie}),e?s.jsx(jn,{value:Math.round(u*100),onValueChange:K=>h(K/100),min:0,max:100,step:10,className:"w-16 tabular-nums"}):s.jsxs("span",{className:"typography-ui-label text-foreground tabular-nums min-w-[3rem] text-right",children:[Math.round(u*100),"%"]})]})]}),s.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:t("settings.voice.page.field.language")}),s.jsx("div",{className:"flex items-center gap-2 w-fit",children:s.jsxs(ps,{value:r,onValueChange:a,disabled:!n,children:[s.jsx(fs,{className:"w-fit",children:s.jsx(ys,{placeholder:t("settings.voice.page.field.selectLanguagePlaceholder")})}),s.jsx(hs,{children:_6.map(K=>s.jsx(Ot,{value:K.value,children:K.label},K.value))})]})})]})]})]})]}),ee&&s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.voice.page.section.speechRecognition")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[s.jsx("div",{className:"pb-1.5 pt-0.5",children:s.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.provider")}),s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsx(Ct,{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(je,{variant:"chip",size:"xs","aria-pressed":N==="browser",onClick:()=>D("browser"),className:"!font-normal",children:t("settings.voice.page.provider.browser")}),s.jsx(je,{variant:"chip",size:"xs","aria-pressed":N==="server",onClick:()=>D("server"),className:"!font-normal",children:t("settings.voice.page.provider.server")})]})]})}),N==="server"&&s.jsxs("div",{className:"py-1.5 space-y-2",children:[!E1.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:pe("typography-ui-label text-foreground",!T.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx("span",{className:"typography-meta ml-2 text-muted-foreground",children:t("settings.voice.page.field.sttServerUrlHint")}),s.jsxs("div",{className:"relative mt-1.5 max-w-xs",children:[s.jsx("input",{type:"text",value:T,onChange:K=>M(K.target.value),placeholder:"http://localhost:8001/v1",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),T&&s.jsx("button",{type:"button",onClick:()=>M(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(Ds,{className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.model")}),s.jsx("div",{className:"relative mt-1.5 max-w-xs",children:s.jsx("input",{type:"text",value:$,onChange:K=>F(K.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:V,onChange:K=>O(K.target.value),placeholder:"auto",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})})]}),s.jsxs("div",{className:"flex items-center gap-8 py-0.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:t("settings.voice.page.field.silenceThreshold")}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[!e&&s.jsx("input",{type:"range",min:-60,max:-20,step:1,value:L,onChange:K=>W(Number(K.target.value)),className:ie}),s.jsxs("span",{className:"typography-ui-label text-foreground tabular-nums min-w-[3.5rem] text-right",children:[L," dB"]})]})]}),s.jsxs("div",{className:"flex items-center gap-8 py-0.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:t("settings.voice.page.field.silenceHold")}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[!e&&s.jsx("input",{type:"range",min:500,max:3e3,step:100,value:B,onChange:K=>ne(Number(K.target.value)),className:ie}),s.jsx(jn,{value:B,onValueChange:ne,min:500,max:3e3,step:100,className:"w-20 tabular-nums"}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.voice.page.field.millisecondsUnit")})]})]})]})]})]}),s.jsxs("div",{className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:t("settings.voice.page.section.playbackAndSummary")})}),s.jsxs("section",{className:"px-2 pb-2 pt-0 space-y-0",children:[s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":P,onClick:()=>le(!P),onKeyDown:K=>{(K.key===" "||K.key==="Enter")&&(K.preventDefault(),le(!P))},children:[s.jsx(bs,{checked:P,onChange:le,ariaLabel:t("settings.voice.page.field.messageReadAloudButtonAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.messageReadAloudButton")})]}),s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":ge,onClick:()=>te(!ge),onKeyDown:K=>{(K.key===" "||K.key==="Enter")&&(K.preventDefault(),te(!ge))},children:[s.jsx(bs,{checked:ge,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")})]}),ee&&s.jsxs("div",{className:"group flex cursor-pointer items-center gap-2 py-1.5",role:"button",tabIndex:0,"aria-pressed":E,onClick:()=>z(!E),onKeyDown:K=>{(K.key===" "||K.key==="Enter")&&(K.preventDefault(),z(!E))},children:[s.jsx(bs,{checked:E,onChange:z,ariaLabel:t("settings.voice.page.field.summarizeVoiceModeResponsesAria")}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.voice.page.field.summarizeVoiceModeResponses")})]}),(ge||E)&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:t("settings.voice.page.field.summarizationThreshold")}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[!e&&s.jsx("input",{type:"range",min:50,max:2e3,step:50,value:J,onChange:K=>H(Number(K.target.value)),className:ie}),s.jsx(jn,{value:J,onValueChange:H,min:50,max:2e3,step:50,className:"w-16 tabular-nums"})]})]}),s.jsxs("div",{className:"flex items-center gap-8 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground sm:w-56 shrink-0",children:t("settings.voice.page.field.summaryMaxLength")}),s.jsxs("div",{className:"flex items-center gap-2 w-fit",children:[!e&&s.jsx("input",{type:"range",min:50,max:2e3,step:50,value:re,onChange:K=>ce(Number(K.target.value)),className:ie}),s.jsx(jn,{value:re,onValueChange:ce,min:50,max:2e3,step:50,className:"w-16 tabular-nums"})]})]})]})]}),ee&&n&&s.jsx("div",{className:"mt-2 px-2",children:s.jsxs("p",{className:"typography-meta text-muted-foreground",children:[t("settings.voice.page.hint.shiftClickPrefix")," ",s.jsx("kbd",{className:"px-1 py-0.5 mx-0.5 rounded border border-[var(--interactive-border)] bg-background typography-mono text-[10px]",children:"Shift"})," + ",s.jsx("kbd",{className:"px-1 py-0.5 mx-0.5 rounded border border-[var(--interactive-border)] bg-background typography-mono text-[10px]",children:"Click"})," ",t("settings.voice.page.hint.shiftClickSuffix")]})})]})]})},xd=[{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}],bd=[{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}],K6="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/get-started/create-remote-tunnel/",H6="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/do-more-with-tunnels/local-management/configuration-file/",Bf=[{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"}],G6=[".yml",".yaml",".json"],q6="settings.openchamber.tunnel.error.invalidConfigExtension",mo=t=>{const e=t.trim().toLowerCase();return G6.some(n=>e.endsWith(n))},_x=t=>t==="cloudflare"?"Cloudflare":t,Vf=t=>{const e=nt.c(11),{provider:n}=t;let r;e[0]!==n?(r=_x(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=pe("size-4 shrink-0",o),e[2]=o,e[3]=c):c=e[3];let d;e[4]!==c?(d=s.jsx(Zh,{className:c}),e[4]=c,e[5]=d):d=e[5];let p;e[6]!==a?(p=s.jsx("span",{children:a}),e[6]=a,e[7]=p):p=e[7];let m;return e[8]!==d||e[9]!==p?(m=s.jsxs("span",{className:"flex items-center gap-2",children:[d,p]}),e[8]=d,e[9]=p,e[10]=m):m=e[10],m},La=t=>t==="quick"?"quick":t==="managed-remote"?"managed-remote":t==="managed-local"?"managed-local":"quick",zf=(t,e,n)=>t.find(a=>a.ms===e)?.value||n,_f=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`},Q6=t=>new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"}),Rl=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()}},J6=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=Rl(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},Y6=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2,10)}`,X6=()=>{const{t}=ut(),e=l.useCallback(ye=>t(ye),[t]),[n,r]=l.useState("checking"),[a,i]=l.useState(null),[o,c]=l.useState(null),[d,p]=l.useState(null),[m,u]=l.useState(null),[h,b]=l.useState(null),[f,y]=l.useState(!1),[x,g]=l.useState(!1),[w,v]=l.useState(!1),[S,A]=l.useState("cloudflare"),[j,C]=l.useState([]),[I,R]=l.useState("quick"),[k,P]=l.useState(null),[N,D]=l.useState([]),[T,M]=l.useState({}),[$,F]=l.useState(""),[V,O]=l.useState({}),[L,W]=l.useState(new Set),[B,ne]=l.useState(!1),[le,ee]=l.useState(""),[ae,ge]=l.useState(""),[te,E]=l.useState(""),[z,J]=l.useState(1800*1e3),[H,re]=l.useState(480*60*1e3),[ce,Ne]=l.useState(""),[me,we]=l.useState([]),[_,ue]=l.useState(()=>Date.now()),[Q,oe]=l.useState(null),Z=t(q6),Ie=l.useRef(null),Se=l.useMemo(()=>k?!mo(k):!1,[k]),Y=l.useMemo(()=>N.find(ye=>ye.id===$)||N[0]||null,[N,$]),fe=l.useMemo(()=>me.map(ye=>{const Ge=ye.expiresAt<=_,$e=ye.status==="active"&&!Ge,Ve=$e?_f(ye.expiresAt-_):ye.inactiveReason==="expired"||Ge?"expired":"inactive",tt=Ve==="expired"?t("settings.openchamber.tunnel.state.expired"):ye.inactiveReason==="tunnel-revoked"?t("settings.openchamber.tunnel.state.revoked"):t("settings.openchamber.tunnel.state.inactive"),Qe=La(ye.mode);return{...ye,isActive:$e,mode:Qe,remainingTextForSession:Ve,inactiveLabel:tt}}),[_,me,t]),ke=l.useMemo(()=>a?.connectUrl?a.bootstrapExpiresAt===null?!0:a.bootstrapExpiresAt>_:!1,[_,a?.bootstrapExpiresAt,a?.connectUrl]),xe=l.useMemo(()=>!a||n!=="active"&&n!=="stopping"?!1:o===I,[o,n,a,I]),he=l.useMemo(()=>!a||n!=="active"||!o?!1:o!==I,[o,n,a,I]),Pe=l.useMemo(()=>{if(typeof Q=="number"&&Number.isFinite(Q)&&Q>0)return Q;if(typeof window>"u")return null;const ye=Number(window.location.port);return Number.isFinite(ye)&&ye>0?ye:null},[Q]),Be=l.useCallback(async ye=>{await lr(ye)},[]),G=l.useCallback(async ye=>{try{const[Ge,$e,Ve,tt]=await Promise.all([fetch("/api/openchamber/tunnel/check",{signal:ye}),fetch("/api/openchamber/tunnel/status",{signal:ye}),fetch("/api/config/settings",{signal:ye,headers:{Accept:"application/json"}}),fetch("/api/openchamber/tunnel/providers",{signal:ye})]),Qe=await Ge.json(),ze=await $e.json(),ht=Ve.ok?await Ve.json():{},_t=tt.ok?await tt.json():{},Kt=ze.ttlConfig?.bootstrapTtlMs??(ht?.tunnelBootstrapTtlMs===null?null:typeof ht?.tunnelBootstrapTtlMs=="number"?ht.tunnelBootstrapTtlMs:1800*1e3),Ut=typeof ze.ttlConfig?.sessionTtlMs=="number"?ze.ttlConfig.sessionTtlMs:typeof ht?.tunnelSessionTtlMs=="number"?ht.tunnelSessionTtlMs:480*60*1e3,jt=La(ze.mode??ht?.tunnelMode),Dt=typeof ht?.tunnelProvider=="string"&&ht.tunnelProvider.trim().length>0?ht.tunnelProvider.trim().toLowerCase():"cloudflare",ts=typeof ht?.managedLocalTunnelConfigPath=="string"&&ht.managedLocalTunnelConfigPath.trim()||null,it=J6(ze?.managedRemoteTunnelPresets),Yt=typeof ze.managedRemoteTunnelHostname=="string"?ze.managedRemoteTunnelHostname:"",Qt=it.length>0?it:Yt?[{id:`legacy-${Rl(Yt)}`,name:Yt,hostname:Rl(Yt)}]:[],Xt=Qt[0]?.id||"";if(J(Kt),re(Ut),A(Dt),C(Array.isArray(_t?.providers)?_t.providers:[]),R(jt),P(ts),D(Qt),F(Xt),we(Array.isArray(ze.activeSessions)?ze.activeSessions:[]),c(ze.activeTunnelMode?La(ze.activeTunnelMode):ze.active&&ze.mode?La(ze.mode):null),W(new Set(Array.isArray(ze.managedRemoteTunnelTokenPresetIds)?ze.managedRemoteTunnelTokenPresetIds:[])),oe(typeof ze.localPort=="number"?ze.localPort:null),ze.active&&ze.url){i({url:ze.url,connectUrl:null,bootstrapExpiresAt:typeof ze.bootstrapExpiresAt=="number"?ze.bootstrapExpiresAt:null}),r("active");return}r(Qe.available?"idle":"not-available")}catch{ye.aborted||(r("error"),u(t("settings.openchamber.tunnel.toast.checkAvailabilityFailed")))}},[t]);l.useEffect(()=>{const ye=new AbortController;return G(ye.signal),()=>ye.abort()},[G]),l.useEffect(()=>{if(!a?.connectUrl){p(null);return}let ye=!1;return Ty.toDataURL(a.connectUrl,{width:256,margin:2,color:{dark:"#000000",light:"#ffffff"}}).then(Ge=>{ye||p(Ge)}).catch(()=>{ye||p(null)}),()=>{ye=!0}},[a?.connectUrl]),l.useEffect(()=>{if(!a?.bootstrapExpiresAt){Ne(t("settings.openchamber.tunnel.state.noExpiry"));return}let ye=null,Ge=Date.now();const $e=()=>{const Qe=a.bootstrapExpiresAt?a.bootstrapExpiresAt-Date.now():0;Qe<=0?Ne(t("settings.openchamber.tunnel.state.expired")):Ne(_f(Qe))},Ve=()=>{const Qe=Date.now();Qe-Ge>=1e3&&($e(),Ge=Qe),ye=requestAnimationFrame(Ve)};$e(),(typeof document>"u"||document.visibilityState==="visible")&&(ye=requestAnimationFrame(Ve));const tt=()=>{document.visibilityState==="visible"&&ye===null?ye=requestAnimationFrame(Ve):document.visibilityState!=="visible"&&ye!==null&&(cancelAnimationFrame(ye),ye=null)};return document.addEventListener("visibilitychange",tt),()=>{document.removeEventListener("visibilitychange",tt),ye!==null&&cancelAnimationFrame(ye)}},[t,a?.bootstrapExpiresAt]),l.useEffect(()=>{let ye=null,Ge=Date.now();const $e=()=>{const tt=Date.now();tt-Ge>=1e3&&(ue(tt),Ge=tt),ye=requestAnimationFrame($e)};(typeof document>"u"||document.visibilityState==="visible")&&(ye=requestAnimationFrame($e));const Ve=()=>{document.visibilityState==="visible"&&ye===null?ye=requestAnimationFrame($e):document.visibilityState!=="visible"&&ye!==null&&(cancelAnimationFrame(ye),ye=null)};return document.addEventListener("visibilitychange",Ve),()=>{document.removeEventListener("visibilitychange",Ve),ye!==null&&cancelAnimationFrame(ye)}},[]),l.useEffect(()=>{if(n==="starting"||n==="stopping"||n==="checking")return;let ye=!1;const Ge=async()=>{try{const Ve=await fetch("/api/openchamber/tunnel/status");if(!Ve.ok||ye)return;const tt=await Ve.json();if(ye)return;we(Array.isArray(tt.activeSessions)?tt.activeSessions:[]),W(new Set(Array.isArray(tt.managedRemoteTunnelTokenPresetIds)?tt.managedRemoteTunnelTokenPresetIds:[])),oe(typeof tt.localPort=="number"?tt.localPort:null)}catch{}},$e=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||Ge()},5e3);return()=>{ye=!0,window.clearInterval($e)}},[n]);const be=l.useCallback(async ye=>{v(!0);try{await Rs(ye),Object.prototype.hasOwnProperty.call(ye,"tunnelMode")&&ye.tunnelMode&&R(ye.tunnelMode),Object.prototype.hasOwnProperty.call(ye,"tunnelProvider")&&typeof ye.tunnelProvider=="string"&&A(ye.tunnelProvider),Object.prototype.hasOwnProperty.call(ye,"managedLocalTunnelConfigPath")&&P(ye.managedLocalTunnelConfigPath??null),Object.prototype.hasOwnProperty.call(ye,"managedRemoteTunnelPresets")&&ye.managedRemoteTunnelPresets&&D(ye.managedRemoteTunnelPresets)}catch{q.error(t("settings.openchamber.tunnel.toast.saveSettingsFailed"))}finally{v(!1)}},[t]),De=l.useCallback(async(ye,Ge)=>{g(!0);try{await Rs({tunnelBootstrapTtlMs:ye,tunnelSessionTtlMs:Ge})}catch{q.error(t("settings.openchamber.tunnel.toast.saveTtlFailed"))}finally{g(!1)}},[t]),Ae=l.useCallback(async ye=>{const Ge=ye.token.trim();if(Ge)try{const $e={...V,[ye.presetId]:Ge};await Rs({managedRemoteTunnelPresetTokens:$e}),W(Ve=>{const tt=new Set(Ve);return tt.add(ye.presetId),tt})}catch{q.error(t("settings.openchamber.tunnel.toast.saveTokenFailed"))}},[V,t]),ve=l.useCallback(async ye=>{b(null),u(null),await be({tunnelProvider:ye})},[be]),U=l.useCallback(async()=>{const ye=await F1({filters:[{name:"Config",extensions:["yml","yaml","json"]}]});if(ye.success&&typeof ye.path=="string"&&ye.path.trim().length>0){const Ge=ye.path.trim();if(!mo(Ge)){q.error(Z);return}P(Ge),await be({managedLocalTunnelConfigPath:Ge});return}Ie.current?.click()},[Z,be]),de=l.useCallback(ye=>{const Ge=ye.trim();P(Ge.length>0?Ge:null)},[]),Re=l.useCallback(async()=>{if(k&&!mo(k)){q.error(Z);return}await be({managedLocalTunnelConfigPath:k})},[Z,k,be]),Le=l.useCallback(async()=>{P(null),await be({managedLocalTunnelConfigPath:null})},[be]),se=l.useCallback(async ye=>{const Ge=ye.target.files?.[0];if(!Ge)return;const $e=Ge.name.trim();if($e.length!==0){if(!mo($e)){q.error(Z);return}P($e),await be({managedLocalTunnelConfigPath:$e}),ye.target.value=""}},[Z,be]),ie=l.useCallback(async()=>{if(u(null),b(null),I==="managed-local"&&k&&!mo(k)){u(Z),q.error(Z);return}r("starting");try{let ye="",Ge="";if(I==="managed-remote"){if(!Y){r("idle"),b(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst")),q.error(t("settings.openchamber.tunnel.toast.selectOrAddManagedRemoteFirst"));return}ye=Y.hostname,Ge=(V[Y.id]||"").trim(),await be({tunnelMode:"managed-remote",managedRemoteTunnelPresets:N})}const $e=await fetch("/api/openchamber/tunnel/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:S,mode:I,...I==="managed-remote"&&Y?{managedRemoteTunnelPresetId:Y.id,managedRemoteTunnelPresetName:Y.name}:{},...I==="managed-remote"&&ye?{managedRemoteTunnelHostname:ye}:{},...I==="managed-remote"&&Ge?{managedRemoteTunnelToken:Ge}:{},...I==="managed-local"&&k?{configPath:k}:{}})}),Ve=await $e.json();if(!$e.ok||!Ve.ok){if(I==="managed-remote"&&typeof Ve.error=="string"&&Ve.error.includes("Managed remote tunnel token is required")){r("idle"),b(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequiredBeforeStarting")),q.error(t("settings.openchamber.tunnel.toast.addManagedRemoteTokenBeforeStarting"));return}r("error"),u(Ve.error||t("settings.openchamber.tunnel.toast.startFailed")),q.error(Ve.error||t("settings.openchamber.tunnel.toast.startFailed"));return}const tt=typeof Ve.url=="string"?Ve.url:"";if(!tt){r("error"),u(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl")),q.error(t("settings.openchamber.tunnel.toast.startedButNoPublicUrl"));return}if(i({url:tt,connectUrl:typeof Ve.connectUrl=="string"?Ve.connectUrl:null,bootstrapExpiresAt:typeof Ve.bootstrapExpiresAt=="number"?Ve.bootstrapExpiresAt:null}),c(Ve.activeTunnelMode?La(Ve.activeTunnelMode):Ve.mode?La(Ve.mode):I),we(Array.isArray(Ve.activeSessions)?Ve.activeSessions:[]),Array.isArray(Ve.managedRemoteTunnelTokenPresetIds)&&W(new Set(Ve.managedRemoteTunnelTokenPresetIds)),typeof Ve.localPort=="number"&&oe(Ve.localPort),typeof Ve.mode=="string"&&R(La(Ve.mode)),r("active"),Ve.replacedTunnel){const Qe=typeof Ve.revokedBootstrapCount=="number"?Ve.revokedBootstrapCount:0,ze=typeof Ve.invalidatedSessionCount=="number"?Ve.invalidatedSessionCount:0;Qe===1&&ze===1?q.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleSingle")):Qe===1?q.warning(t("settings.openchamber.tunnel.toast.replacedTunnelSingleManySessions",{invalidatedSessionCount:ze})):ze===1?q.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyLinksSingleSession",{revokedBootstrapCount:Qe})):q.warning(t("settings.openchamber.tunnel.toast.replacedTunnelManyMany",{revokedBootstrapCount:Qe,invalidatedSessionCount:ze}))}else q.success(t("settings.openchamber.tunnel.toast.linkReady"))}catch{r("error"),u(t("settings.openchamber.tunnel.toast.startFailed")),q.error(t("settings.openchamber.tunnel.toast.startFailed"))}},[Z,N,be,Y,V,t,S,I,k]),K=l.useCallback(async()=>{r("stopping");try{await fetch("/api/openchamber/tunnel/stop",{method:"POST"});const ye=await fetch("/api/openchamber/tunnel/status");if(ye.ok){const Ge=await ye.json();we(Array.isArray(Ge.activeSessions)?Ge.activeSessions:[]),W(new Set(Array.isArray(Ge.managedRemoteTunnelTokenPresetIds)?Ge.managedRemoteTunnelTokenPresetIds:[])),oe(typeof Ge.localPort=="number"?Ge.localPort:null)}i(null),c(null),p(null),r("idle"),q.success(t("settings.openchamber.tunnel.toast.stopped"))}catch{r("error"),u(t("settings.openchamber.tunnel.toast.stopFailed")),q.error(t("settings.openchamber.tunnel.toast.stopFailed"))}},[t]),_e=l.useCallback(async()=>{if(a?.connectUrl)try{await navigator.clipboard.writeText(a.connectUrl),y(!0),q.success(t("settings.openchamber.tunnel.toast.connectLinkCopied")),setTimeout(()=>y(!1),2e3)}catch{q.error(t("settings.openchamber.tunnel.toast.copyUrlFailed"))}},[t,a?.connectUrl]),He=l.useCallback(async ye=>{const Ge=xd.find($e=>$e.value===ye);Ge&&(J(Ge.ms),await De(Ge.ms,H))},[De,H]),Ke=l.useCallback(async ye=>{const Ge=bd.find($e=>$e.value===ye);!Ge||Ge.ms===null||(re(Ge.ms),await De(z,Ge.ms))},[z,De]),Ze=l.useCallback(async ye=>{b(null),u(null),n!=="active"&&n!=="stopping"&&n!=="starting"&&r("idle"),await be({tunnelMode:ye,managedRemoteTunnelPresets:N})},[N,be,n]),Xe=l.useCallback(async(ye,Ge)=>{try{await Rs({managedRemoteTunnelPresets:Ge})}catch{q.error(t("settings.openchamber.tunnel.toast.saveSelectedManagedRemoteFailed"))}},[t]),mt=l.useCallback(ye=>{const Ge=N.find($e=>$e.id===ye);Ge&&(F(Ge.id),b(null),Xe(Ge,N))},[N,Xe]),et=l.useCallback(async()=>{const ye=le.trim(),Ge=Rl(ae),$e=te.trim();if(!ye){q.error(t("settings.openchamber.tunnel.toast.tunnelNameRequired"));return}if(!Ge){q.error(t("settings.openchamber.tunnel.toast.managedRemoteHostnameRequired"));return}if(!$e){q.error(t("settings.openchamber.tunnel.toast.managedRemoteTokenRequired"));return}if(N.some(Qe=>Qe.hostname===Ge)){q.error(t("settings.openchamber.tunnel.toast.hostnameAlreadyExists"));return}const Ve={id:Y6(),name:ye,hostname:Ge},tt=[...N,Ve];D(tt),F(Ve.id),M(Qe=>({...Qe,[Ve.id]:!0})),O(Qe=>({...Qe,[Ve.id]:$e})),b(null),ne(!1),ee(""),ge(""),E(""),await be({tunnelMode:"managed-remote",managedRemoteTunnelPresets:tt,managedRemoteTunnelPresetTokens:{...V,[Ve.id]:$e}}),await Ae({presetId:Ve.id,presetName:Ve.name,hostname:Ve.hostname,token:$e}),q.success(t("settings.openchamber.tunnel.toast.managedRemoteSaved"))},[N,ae,le,te,Ae,be,V,t]),ct=l.useCallback(async ye=>{const Ge=N.find(ze=>ze.id===ye);if(!Ge)return;const $e=N.filter(ze=>ze.id!==Ge.id),Ve=$e[0]?.id||"",tt=$===Ge.id?Ve:$,Qe=Object.fromEntries(Object.entries(V).filter(([ze,ht])=>ze!==Ge.id&&ht.trim().length>0));D($e),F(tt),M(ze=>{const ht={...ze};return delete ht[Ge.id],ht}),O(ze=>{const ht={...ze};return delete ht[Ge.id],ht}),W(ze=>{const ht=new Set(ze);return ht.delete(Ge.id),ht}),b(null),await be({managedRemoteTunnelPresets:$e,managedRemoteTunnelPresetTokens:Qe}),q.success(t("settings.openchamber.tunnel.toast.managedRemoteRemoved"))},[N,be,$,V,t]),lt="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(Us,{className:"size-4 text-[var(--status-info)]"}),s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.tunnel.section.redeemedAccessLinks")})]}),s.jsx("div",{className:"space-y-1",children:fe.map(ye=>{const Ge=ye.mode==="quick",$e=ye.mode==="managed-remote",Ve=Ge?"border-[var(--status-warning-border)] bg-[var(--status-warning-background)] text-[var(--status-warning)]":$e?"border-[var(--status-info-border)] bg-[var(--status-info-background)] text-[var(--status-info)]":"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",tt=ye.isActive?Ge?"text-[var(--status-warning)]":$e?"text-[var(--status-info)]":"text-[var(--status-success)]":"text-muted-foreground/50",Qe=t(Ge?"settings.openchamber.tunnel.badge.quick":$e?"settings.openchamber.tunnel.badge.remote":"settings.openchamber.tunnel.badge.local");return s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 rounded border border-[var(--surface-subtle)] bg-[var(--surface-elevated)] px-2 py-1.5",children:[s.jsx(My,{className:pe("size-2.5 shrink-0",tt)}),s.jsx("span",{className:pe("typography-micro rounded border px-1.5 py-0.5 uppercase",Ve),children:Qe}),s.jsx("span",{className:"typography-meta text-muted-foreground/80",children:t("settings.openchamber.tunnel.session.redeemedAt",{time:Q6(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(Hr,{className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"typography-meta font-medium text-foreground",children:t("settings.openchamber.tunnel.notAvailable.cloudflaredNotFound")}),s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.openchamber.tunnel.notAvailable.installHint")}),s.jsx("code",{className:"typography-code block rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:"brew install cloudflared"})]})]})}),n!=="not-available"&&s.jsxs("section",{className:"space-y-4 px-2 pb-2 pt-0",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.tunnel.field.provider")}),s.jsxs(ps,{value:S,onValueChange:ye=>{ve(ye)},disabled:w||n==="starting"||n==="stopping",children:[s.jsx(fs,{className:"max-w-[16rem]",children:s.jsx(ys,{placeholder:t("settings.openchamber.tunnel.field.providerPlaceholder"),children:_x(S)})}),s.jsxs(hs,{children:[j.length>0?j.map(ye=>s.jsx(Ot,{value:ye.provider,children:s.jsx(Vf,{provider:ye.provider})},ye.provider)):s.jsx(Ot,{value:"cloudflare",children:s.jsx(Vf,{provider:"cloudflare"})}),s.jsx(Ot,{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:Bf.map(ye=>s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx(je,{variant:"chip",size:"xs","aria-pressed":I===ye.value,className:"!font-normal",onClick:()=>{Ze(ye.value)},disabled:w||n==="starting"||n==="stopping",children:e(ye.labelKey)})}),s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:e(ye.tooltipKey)})]},ye.value))})]})]}),s.jsxs("div",{className:"mt-2 grid grid-cols-1 gap-2 py-1.5 md:grid-cols-[14rem_auto] md:gap-x-8 md:gap-y-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label shrink-0 text-foreground",children:t("settings.openchamber.tunnel.field.connectLinkTtl")}),s.jsxs(ps,{value:zf(xd,z,"1800000"),onValueChange:ye=>{He(ye)},disabled:x||w||n==="starting"||n==="stopping",children:[s.jsx(fs,{className:"max-w-[11rem] min-w-0",children:s.jsx(ys,{className:"truncate"})}),s.jsx(hs,{children:xd.map(ye=>s.jsx(Ot,{value:ye.value,children:ye.label},ye.value))})]})]}),s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label shrink-0 text-foreground",children:t("settings.openchamber.tunnel.field.tunnelSessionTtl")}),s.jsxs(ps,{value:zf(bd,H,"28800000"),onValueChange:ye=>{Ke(ye)},disabled:x||w||n==="starting"||n==="stopping",children:[s.jsx(fs,{className:"max-w-[11rem] min-w-0",children:s.jsx(ys,{className:"truncate"})}),s.jsx(hs,{children:bd.map(ye=>s.jsx(Ot,{value:ye.value,children:ye.label},ye.value))})]})]})]}),I==="quick"&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning)]/35 bg-[var(--status-warning)]/10 p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(Hr,{className:"mt-0.5 size-4 shrink-0 text-[var(--status-warning)]"}),s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.option.mode.quick.tooltip")}),s.jsx("p",{className:"typography-meta mt-1 text-[var(--status-warning)]",children:t("settings.openchamber.tunnel.warning.quickModeReliability")})]})]})}),I==="managed-remote"&&s.jsxs("div",{className:"space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:[typeof Pe=="number"&&s.jsx("div",{className:"rounded-md border border-[var(--status-info-border)] bg-[var(--status-info-background)]/35 px-2 py-1.5",children:s.jsxs("p",{className:"typography-meta text-[var(--status-info)]",children:[t("settings.openchamber.tunnel.note.cloudflareConnectorTarget")," ",s.jsxs("code",{children:["http://localhost:",Pe]})]})}),s.jsxs("div",{className:"mb-1 flex items-center justify-between gap-3",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.tunnel.section.savedManagedRemoteTunnels")}),s.jsxs(je,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>ne(ye=>!ye),disabled:n==="starting"||n==="stopping"||w,children:[s.jsx(_s,{className:"h-3.5 w-3.5"}),t("settings.common.actions.create")]})]}),N.length>0?s.jsx("div",{className:"overflow-hidden rounded-md border border-[var(--surface-subtle)]",children:N.map((ye,Ge)=>{const $e=V[ye.id]||"",Ve=L.has(ye.id),tt=T[ye.id]??!1;return s.jsx("div",{className:pe(Ge<N.length-1&&"border-b border-[var(--surface-subtle)]"),children:s.jsxs(yr,{open:tt,onOpenChange:Qe=>{M(ze=>({...ze,[ye.id]:Qe})),Qe&&mt(ye.id)},className:"py-1.5",children:[s.jsxs("div",{className:"flex items-start gap-2 px-3",children:[s.jsxs(Mr,{type:"button",className:"group flex-1 justify-start gap-2 rounded-md px-0 py-1 pr-1 text-left hover:bg-[var(--interactive-hover)]",disabled:n==="starting"||n==="stopping"||w,children:[tt?s.jsx(Cs,{className:"h-4 w-4 text-muted-foreground"}):s.jsx(Fn,{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(je,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:text-[var(--status-error)]","aria-label":t("settings.openchamber.tunnel.actions.removePresetAria",{name:ye.name}),onClick:()=>{ct(ye.id)},disabled:n==="starting"||n==="stopping"||w,children:s.jsx(sn,{className:"h-3.5 w-3.5"})})]}),s.jsx(vr,{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(Vt,{type:"password",value:$e,onChange:Qe=>{const ze=Qe.target.value;b(null),O(ht=>({...ht,[ye.id]:ze}))},onBlur:Qe=>{const ze=Qe.currentTarget.value.trim();ze&&Ae({presetId:ye.id,presetName:ye.name,hostname:ye.hostname,token:ze})},placeholder:t(Ve?"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(je,{variant:"ghost",size:"xs",className:"!font-normal",disabled:n==="starting"||n==="stopping"||$e.trim().length===0,onClick:()=>{Ae({presetId:ye.id,presetName:ye.name,hostname:ye.hostname,token:$e})},children:t("settings.openchamber.tunnel.actions.saveToken")})})]})})]})},ye.id)})}):s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.openchamber.tunnel.empty.noManagedRemoteTunnels")}),B&&s.jsxs("div",{className:"space-y-2 rounded-md border border-[var(--surface-subtle)] p-2",children:[s.jsx(Vt,{value:le,onChange:ye=>ee(ye.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetNamePlaceholder"),className:"h-7",disabled:w||n==="starting"||n==="stopping"}),s.jsx(Vt,{value:ae,onChange:ye=>ge(ye.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetHostnamePlaceholder"),className:"h-7",disabled:w||n==="starting"||n==="stopping"}),s.jsx(Vt,{type:"password",value:te,onChange:ye=>E(ye.target.value),placeholder:t("settings.openchamber.tunnel.field.newPresetTokenPlaceholder"),className:"h-7",disabled:w||n==="starting"||n==="stopping"}),typeof Pe=="number"&&s.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[t("settings.openchamber.tunnel.note.cloudflareConnectorTargetUse")," ",s.jsxs("code",{children:["http://localhost:",Pe]}),"."]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(je,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{et()},disabled:w||n==="starting"||n==="stopping",children:t("settings.common.actions.saveChanges")}),s.jsx(je,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{ne(!1),ee(""),ge(""),E("")},disabled:w||n==="starting"||n==="stopping",children:t("settings.common.actions.cancel")})]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:t("settings.openchamber.tunnel.note.tokensSavedPerTunnel")}),s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx("button",{type:"button",className:"rounded p-0.5 text-muted-foreground/70 hover:text-foreground","aria-label":t("settings.openchamber.tunnel.field.managedRemoteTokenInfoAria"),children:s.jsx(Us,{className:"h-3.5 w-3.5"})})}),s.jsx(Ct,{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})]}),I==="managed-local"&&s.jsx("div",{className:"space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.tunnel.field.configurationFile")}),s.jsx("input",{ref:Ie,type:"file",accept:".yml,.yaml,.json",className:"hidden",onChange:ye=>{se(ye)}}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Vt,{value:k||"",onChange:ye=>{de(ye.target.value)},onBlur:()=>{Re()},placeholder:t("settings.openchamber.tunnel.field.configurationFilePlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"||w}),s.jsx(je,{variant:"outline",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.browseConfigFileAria"),onClick:()=>{U()},disabled:n==="starting"||n==="stopping"||w,children:s.jsx(zn,{className:"size-3.5"})}),k&&s.jsx(je,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.tunnel.actions.clearConfigFileAria"),onClick:()=>{Le()},disabled:n==="starting"||n==="stopping"||w,children:s.jsx(Ds,{className:"size-3.5"})})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t(k?"settings.openchamber.tunnel.note.customConfigUsed":"settings.openchamber.tunnel.note.defaultConfigUsed")}),Se&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Z})]})}),!xe&&s.jsxs("div",{className:"space-y-6",children:[s.jsx("div",{className:"rounded-lg border border-[var(--status-info-border)] bg-[var(--status-info-background)] p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(Us,{className:"mt-0.5 size-4 shrink-0 text-[var(--status-info)]"}),s.jsxs("div",{className:"space-y-1",children:[I==="managed-remote"&&s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.openchamber.tunnel.note.managedRemoteRequiresDomain")}),s.jsxs("button",{type:"button",className:"typography-meta inline-flex items-center gap-1 text-[var(--status-info)] underline underline-offset-2 hover:opacity-90",onClick:()=>{Be(K6)},children:[t("settings.openchamber.tunnel.actions.openManagedRemoteDocs"),s.jsx(Ir,{className:"size-3.5"})]})]}),I==="managed-local"&&s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.openchamber.tunnel.note.managedLocalUsesConfig")}),s.jsxs("button",{type:"button",className:"typography-meta inline-flex items-center gap-1 text-[var(--status-info)] underline underline-offset-2 hover:opacity-90",onClick:()=>{Be(H6)},children:[t("settings.openchamber.tunnel.actions.openManagedLocalDocs"),s.jsx(Ir,{className:"size-3.5"})]})]}),s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.openchamber.tunnel.note.startModeAndGenerateLink",{mode:e(Bf.find(ye=>ye.value===I)?.labelKey??"settings.openchamber.tunnel.option.mode.quick.label")})})]})]})}),I==="managed-remote"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.tunnel.field.managedRemoteTunnelToConnect")}),s.jsxs(ps,{value:$||(N[0]?.id??""),onValueChange:ye=>{mt(ye)},disabled:w||n==="starting"||n==="stopping"||N.length<=1,children:[s.jsx(fs,{children:s.jsx(ys,{placeholder:t("settings.openchamber.tunnel.field.selectSavedTunnelPlaceholder"),children:Y?.name})}),s.jsx(hs,{fitContent:!0,children:N.map(ye=>s.jsx(Ot,{value:ye.id,children:ye.name},ye.id))})]})]}),he&&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(Hr,{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(je,{size:"sm",variant:"outline",onClick:ie,disabled:n==="starting"||w||I==="managed-remote"&&!Y||I==="managed-local"&&Se,className:pe(lt,n==="starting"&&"opacity-70"),children:n==="starting"?s.jsxs(s.Fragment,{children:[s.jsx(Zt,{className:"size-3.5 animate-spin"})," ",t("settings.openchamber.tunnel.actions.startingTunnel")]}):t("settings.openchamber.tunnel.actions.startTunnel")})]})]}),xe&&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(je,{size:"sm",variant:"ghost",onClick:_e,className:"shrink-0 gap-1.5",children:[f?s.jsx(Ys,{className:"size-3.5 text-[var(--status-success)]"}):s.jsx(br,{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?ce:t("settings.openchamber.tunnel.state.never")]})]}),s.jsxs("div",{className:"flex flex-col items-center gap-2 rounded-lg border border-border/50 bg-[var(--surface-elevated)] p-4",children:[d?s.jsx("img",{src:d,alt:t("settings.openchamber.tunnel.field.connectQrAlt"),className:"size-48"}):s.jsx("div",{className:"size-48 rounded bg-muted/30"}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.openchamber.tunnel.note.scanQrToConnect")})]})]})]}),s.jsx("div",{className:"pt-1",children:s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(je,{size:"sm",variant:"outline",onClick:ie,disabled:n==="stopping"||w||I==="managed-local"&&Se,className:lt,children:[s.jsx(Mn,{className:"size-3.5"}),t("settings.openchamber.tunnel.actions.newConnectLink")]}),s.jsx(je,{size:"sm",variant:"ghost",onClick:K,disabled:n==="stopping"||w,className:"gap-2 text-[var(--status-error)]",children:n==="stopping"?s.jsxs(s.Fragment,{children:[s.jsx(Zt,{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(je,{size:"sm",variant:"ghost",onClick:ie,children:t("settings.openchamber.tunnel.actions.retry")})]})]})},Ux=()=>{const{t}=ut(),[e,n]=Oe.useState(""),[r,a]=Oe.useState(!0),[i,o]=Oe.useState(!1);Oe.useEffect(()=>{let p=!1;return(async()=>{try{const m=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!m.ok)return;const u=await m.json().catch(()=>null);if(p||!u)return;const h=typeof u.opencodeBinary=="string"?u.opencodeBinary.trim():"";n(h)}catch{}finally{p||a(!1)}})(),()=>{p=!0}},[]);const c=Oe.useCallback(async()=>{if(typeof window>"u"||!kn()||!ri())return;const p=window.__TAURI__;if(p?.dialog?.open)try{const m=await p.dialog.open({title:t("settings.openchamber.opencodeCli.dialog.selectBinaryTitle"),multiple:!1,directory:!1});typeof m=="string"&&m.trim().length>0&&n(m.trim())}catch{}},[t]),d=Oe.useCallback(async()=>{o(!0);try{await Rs({opencodeBinary:e.trim()}),await No({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(St,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),s.jsxs(Ct,{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(Vt,{value:e,onChange:p=>n(p.target.value),placeholder:t("settings.openchamber.opencodeCli.field.binaryPathPlaceholder"),disabled:r||i,className:"h-7 min-w-0 flex-1 font-mono text-xs"}),s.jsx(je,{type:"button",variant:"outline",size:"xs",onClick:c,disabled:r||i||!kn()||!ri(),className:"h-7 w-7 p-0","aria-label":t("settings.openchamber.opencodeCli.actions.browseAria"),title:t("settings.openchamber.opencodeCli.actions.browse"),children:s.jsx(zn,{className:"h-4 w-4"})})]})]}),s.jsx("div",{className:"py-1.5",children:s.jsxs("div",{className:"typography-micro text-muted-foreground/70",children:[t("settings.openchamber.opencodeCli.tipPrefix")," ",s.jsx("span",{className:"font-mono",children:"OPENCODE_BINARY"})," ",t("settings.openchamber.opencodeCli.tipMiddle")," ",s.jsx("span",{className:"font-mono",children:"~/.config/openchamber/settings.json"}),"."]})}),s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(je,{type:"button",size:"xs",onClick:d,disabled:r||i,className:"shrink-0 !font-normal",children:t(i?"settings.common.actions.saving":"settings.openchamber.opencodeCli.actions.saveAndReload")})})]})]})},Wx=()=>{const{t}=ut(),e=kn()&&oa(),[n,r]=Oe.useState(!1),[a,i]=Oe.useState(!1),[o,c]=Oe.useState(!0),[d,p]=Oe.useState(!1),[m,u]=Oe.useState(null),[h,b]=Oe.useState(null);Oe.useEffect(()=>{if(!e){c(!1);return}let v=!1;return(async()=>{try{const S=await fetch("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!S.ok)throw new Error(t("settings.openchamber.desktopNetwork.error.loadFailed"));const A=await S.json().catch(()=>null);if(v)return;const j=A?.desktopLanAccessEnabled===!0;r(j),i(j),u(null)}catch(S){v||u(S instanceof Error?S.message:t("settings.openchamber.desktopNetwork.error.loadFailed"))}finally{v||c(!1)}})(),()=>{v=!0}},[e,t]),Oe.useEffect(()=>{if(!e||!a){b(null);return}let v=!1;return(async()=>{const S=await O1();v||b(S)})(),()=>{v=!0}},[a,e]);const f=a!==n,y=Oe.useMemo(()=>{if(typeof window>"u")return null;const v=Number(window.location.port);return Number.isFinite(v)&&v>0?v:null},[]),x=a&&h&&y?`http://${h}:${y}`:null,g=Oe.useCallback(()=>{i(v=>!v)},[]),w=Oe.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 jg())throw new Error(t("settings.openchamber.desktopNetwork.error.savedRestartFailed"))}catch(v){u(v instanceof Error?v.message:t("settings.openchamber.desktopNetwork.error.saveFailed")),p(!1)}}},[a,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:v=>{(v.key==="Enter"||v.key===" ")&&(v.preventDefault(),g())},children:[s.jsx(bs,{checked:a,onChange:g,ariaLabel:t("settings.openchamber.desktopNetwork.field.allowLanAccessAria"),disabled:o||d}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:t("settings.openchamber.desktopNetwork.field.allowLanAccess")}),s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:t("settings.openchamber.desktopNetwork.field.allowLanAccessDescription")}),s.jsx("div",{className:"typography-micro text-[var(--status-warning)]/85",children:t("settings.openchamber.desktopNetwork.field.warning")})]})]}),m?s.jsx("div",{className:"px-2 typography-micro text-[var(--status-error)]",children:m}):null,x?s.jsxs("div",{className:"px-2 typography-micro text-muted-foreground/80",children:[t(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(je,{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},Z6=new Set(["shift","control","alt","meta"]),eI=t=>{if(Z6.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=$1(t.key);return n?(e.push(n),ki(e.join("+"))):null},tI=()=>{const t=nt.c(58),{t:e}=ut();let n;t[0]!==e?(n=te=>e(te),t[0]=e,t[1]=n):n=t[1];const r=n,a=Te(sI),i=Te(nI),o=Te(rI),c=Te(aI);let d;t[2]===Symbol.for("react.memo_cache_sentinel")?(d=L1(),t[2]=d):d=t[2];const p=d;let m;t[3]!==r?(m=(te,E)=>{const z=`settings.openchamber.keyboardShortcuts.action.${te}.label`,J=r(z);return J===z?E:J},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[y,x]=l.useState(f),[g,w]=l.useState(""),[v,S]=l.useState(""),[A,j]=l.useState(null);let C;t[6]!==a?(C=(te,E)=>{const z=ki(E);for(const J of p){if(J.id===te)continue;const H=ra(J.id,a);if(ki(H)===z)return J.id}return null},t[6]=a,t[7]=C):C=t[7];const I=C;let R;t[8]!==I||t[9]!==i||t[10]!==e?(R=(te,E)=>{const z=ki(E),J=I(te,z);if(J){j({actionId:te,combo:z,conflictActionId:J}),w("");return}i(te,z),j(null),w(""),S(Tm(z)?e("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut"):""),x(H=>{const re={...H};return delete re[te],re})},t[8]=I,t[9]=i,t[10]=e,t[11]=R):R=t[11];const k=R;let P;t[12]!==A||t[13]!==i||t[14]!==e?(P=()=>{A&&(i(A.conflictActionId,B1),i(A.actionId,A.combo),j(null),w(""),S(Tm(A.combo)?e("settings.openchamber.keyboardShortcuts.warning.riskyBrowserShortcut"):""),x(te=>{const E={...te};return delete E[A.actionId],E}))},t[12]=A,t[13]=i,t[14]=e,t[15]=P):P=t[15];const N=P;let D;t[16]!==o?(D=te=>{o(te),x(E=>{const z={...E};return delete z[te],z}),j(null),w(""),S("")},t[16]=o,t[17]=D):D=t[17];const T=D;let M;t[18]!==e?(M=e("settings.openchamber.keyboardShortcuts.title"),t[18]=e,t[19]=M):M=t[19];let $;t[20]!==M?($=s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:M}),t[20]=M,t[21]=$):$=t[21];let F;t[22]!==c?(F=()=>{c(),x({}),j(null),w(""),S("")},t[22]=c,t[23]=F):F=t[23];let V;t[24]!==e?(V=e("settings.openchamber.keyboardShortcuts.actions.resetAll"),t[24]=e,t[25]=V):V=t[25];let O;t[26]!==F||t[27]!==V?(O=s.jsx(je,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:F,children:V}),t[26]=F,t[27]=V,t[28]=O):O=t[28];let L;t[29]===Symbol.for("react.memo_cache_sentinel")?(L=s.jsx(St,{asChild:!0,children:s.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground/60 cursor-help"})}),t[29]=L):L=t[29];let W;t[30]!==e?(W=e("settings.openchamber.keyboardShortcuts.tooltip"),t[30]=e,t[31]=W):W=t[31];let B;t[32]!==W?(B=s.jsxs(kt,{children:[L,s.jsx(Ct,{sideOffset:8,className:"max-w-xs",children:W})]}),t[32]=W,t[33]=B):B=t[33];let ne;t[34]!==O||t[35]!==B||t[36]!==$?(ne=s.jsx("div",{className:"mb-1 px-1",children:s.jsxs("div",{className:"flex items-center gap-2",children:[$,O,B]})}),t[34]=O,t[35]=B,t[36]=$,t[37]=ne):ne=t[37];let le;t[38]!==N||t[39]!==g||t[40]!==A||t[41]!==e||t[42]!==v?(le=(g||v||A)&&s.jsxs("div",{className:"mb-2 space-y-2 px-1",children:[A&&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(je,{type:"button",size:"xs",className:"!font-normal",onClick:N,children:e("settings.openchamber.keyboardShortcuts.actions.overwrite")}),s.jsx(je,{type:"button",size:"xs",className:"!font-normal",variant:"ghost",onClick:()=>j(null),children:e("settings.common.actions.cancel")})]})]}),g&&s.jsx("div",{className:"rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] p-3 typography-meta text-foreground",children:g}),v&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3 typography-meta text-foreground",children:v})]}),t[38]=N,t[39]=g,t[40]=A,t[41]=e,t[42]=v,t[43]=le):le=t[43];let ee;t[44]!==u||t[45]!==h||t[46]!==y||t[47]!==T||t[48]!==k||t[49]!==a||t[50]!==e?(ee=p.map((te,E)=>{const z=ra(te.id,a),J=y[te.id],H=J??z,re=typeof J=="string"&&ki(J)!==ki(z);return s.jsxs("div",{className:pe("flex flex-col gap-2 py-1.5 sm:flex-row sm:items-center sm:gap-8",E>0&&"border-t border-[var(--surface-subtle)]"),children:[s.jsx("div",{className:"flex min-w-0 flex-col sm:w-56 shrink-0",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:u(te.id,te.label)})}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 sm:w-fit sm:flex-initial",children:[s.jsx(Vt,{readOnly:!0,value:h===te.id?e("settings.openchamber.keyboardShortcuts.field.pressKeys"):fc(H),onFocus:()=>{b(te.id),w("")},onBlur:()=>{h===te.id&&b(null)},onKeyDown:ce=>{if(ce.preventDefault(),ce.stopPropagation(),ce.key==="Escape"){b(null);return}const Ne=eI(ce);Ne&&(x(me=>({...me,[te.id]:Ne})),b(null),j(null),w(""))},className:"h-7 w-40 min-w-0 typography-ui-label text-center"}),s.jsx(je,{type:"button",variant:"secondary",size:"xs",className:"!font-normal",onClick:()=>{const ce=y[te.id];if(!ce){w(e("settings.openchamber.keyboardShortcuts.error.captureFirst"));return}k(te.id,ce)},disabled:!re,children:e("settings.common.actions.saveChanges")}),s.jsx(je,{type:"button",size:"xs",className:"!font-normal",variant:"ghost",onClick:()=>T(te.id),children:e("settings.common.actions.reset")})]})]},te.id)}),t[44]=u,t[45]=h,t[46]=y,t[47]=T,t[48]=k,t[49]=a,t[50]=e,t[51]=ee):ee=t[51];let ae;t[52]!==ee?(ae=s.jsx("section",{className:"px-2 pb-2 pt-0 space-y-0.5",children:ee}),t[52]=ee,t[53]=ae):ae=t[53];let ge;return t[54]!==ne||t[55]!==le||t[56]!==ae?(ge=s.jsxs("div",{className:"mb-8",children:[ne,le,ae]}),t[54]=ne,t[55]=le,t[56]=ae,t[57]=ge):ge=t[57],ge};function sI(t){return t.shortcutOverrides}function nI(t){return t.setShortcutOverride}function rI(t){return t.clearShortcutOverride}function aI(t){return t.resetAllShortcutOverrides}const iI=t=>{const e=nt.c(20),{section:n}=t,{isMobile:r}=un();let a;e[0]!==r?(a=r&&ja(),e[0]=r,e[1]=a):a=e[1];const i=a;let o;e[2]===Symbol.for("react.memo_cache_sentinel")?(o=yn(),e[2]=o):o=e[2];const c=o;let d;e[3]===Symbol.for("react.memo_cache_sentinel")?(d=kn()&&oa(),e[3]=d):d=e[3];const p=d;if(!n){let f;e[4]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx(Xu,{}),e[4]=f):f=e[4];let y,x,g;e[5]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(zx,{})}),x=!c&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Ux,{})}),g=p&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Wx,{})}),e[5]=y,e[6]=x,e[7]=g):(y=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(Bx,{})}),e[8]=w):w=e[8];let v;e[9]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Vx,{})}),e[9]=v):v=e[9];let S;e[10]!==i?(S=i&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(A6,{})}),e[10]=i,e[11]=S):S=e[11];let A;return e[12]!==S?(A=s.jsx(Es,{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,y,x,g,w,v,S]})}),e[12]=S,e[13]=A):A=e[13],A}let m;e[14]!==n?(m=()=>{switch(n){case"visual":return s.jsx(lI,{});case"chat":return s.jsx(cI,{});case"sessions":return s.jsx(dI,{});case"shortcuts":return s.jsx(oI,{});case"git":return s.jsx(uI,{});case"github":return s.jsx(mI,{});case"notifications":return s.jsx(pI,{});case"voice":return s.jsx(fI,{});case"tunnel":return s.jsx(hI,{});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(Es,{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},oI=()=>{const t=nt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(tI,{}),t[0]=e):e=t[0],e},lI=()=>{const t=nt.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=yn(),t[0]=e):e=t[0];const n=e;let r;return t[1]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(Xu,{visibleSettings:["theme","pwaInstallName","pwaOrientation","mobileKeyboardMode","timeFormat","weekStart","fontSize","terminalFontSize","spacing","inputBarOffset",...n?[]:["terminalQuickKeys"],"reportUsage"]}),t[1]=r):r=t[1],r},cI=()=>{const t=nt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Xu,{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},dI=()=>{const t=nt.c(7);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=yn(),t[0]=e):e=t[0];const n=e;let r;t[1]===Symbol.for("react.memo_cache_sentinel")?(r=kn()&&oa(),t[1]=r):r=t[1];const a=r;let i,o,c;t[2]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx(zx,{}),o=!n&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Ux,{})}),c=a&&s.jsx("div",{className:"border-t border-border/40 pt-6",children:s.jsx(Wx,{})}),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(Bx,{})}),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(Vx,{})})]}),t[6]=p):p=t[6],p},uI=()=>{const t=nt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx("div",{className:"space-y-6",children:s.jsx(Fx,{})}),t[0]=e):e=t[0],e},mI=()=>{const t=nt.c(1);if(yn())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Ox,{}),t[0]=e):e=t[0],e},pI=()=>{const t=nt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(z6,{}),t[0]=e):e=t[0],e},fI=()=>{const t=nt.c(1);if(yn())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(W6,{}),t[0]=e):e=t[0],e},hI=()=>{const t=nt.c(1);if(yn())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(X6,{}),t[0]=e):e=t[0],e},Uf=176,Wf=280,gI=["appearance","chat","notifications","sessions","shortcuts","git","magic-prompts","projects","remote-instances","agents","behavior","commands","mcp","providers","usage","skills.installed","skills.catalog","voice","tunnel"];function xI(t){const e=yn(),n=!t&&ja();return{isVSCode:e,isWeb:n,isDesktop:t}}function Kf(t,e){return t.isAvailable?t.isAvailable(e):!0}function Zu(t){switch(t){case"projects":return Vy;case"remote-instances":return ei;case"appearance":return tg;case"chat":return eg;case"magic-prompts":return Ga;case"notifications":return By;case"shortcuts":return Bo;case"sessions":return $y;case"providers":return Zh;case"agents":return Du;case"behavior":return Ly;case"commands":return Oy;case"mcp":return _g;case"skills.installed":return Tu;case"skills.catalog":return Fy;case"git":return Ks;case"usage":return Ey;case"voice":return Ry;case"tunnel":return ti;case"home":return null;default:return Gr}}const yd=t=>{const e=nt.c(95),{onOpen:n}=t,{t:r}=ut();let a;e[0]!==r?(a=r("settings.view.home.title"),e[0]=r,e[1]=a):a=e[1];let i;e[2]!==a?(i=s.jsx("h1",{className:"typography-ui-header font-semibold text-foreground",children:a}),e[2]=a,e[3]=i):i=e[3];let o;e[4]!==r?(o=r("settings.view.home.description"),e[4]=r,e[5]=o):o=e[5];let c;e[6]!==o?(c=s.jsx("p",{className:"typography-ui text-muted-foreground",children:o}),e[6]=o,e[7]=c):c=e[7];let d;e[8]!==i||e[9]!==c?(d=s.jsxs("div",{className:"space-y-1",children:[i,c]}),e[8]=i,e[9]=c,e[10]=d):d=e[10];let p;e[11]!==n?(p=()=>n("providers"),e[11]=n,e[12]=p):p=e[12];let m;e[13]===Symbol.for("react.memo_cache_sentinel")?(m=pe("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 y;e[22]!==f||e[23]!==p||e[24]!==h?(y=s.jsxs("button",{type:"button",onClick:p,className:m,children:[h,f]}),e[22]=f,e[23]=p,e[24]=h,e[25]=y):y=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=pe("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[28]=g):g=e[28];let w;e[29]!==r?(w=r("settings.view.home.cards.agents.title"),e[29]=r,e[30]=w):w=e[30];let v;e[31]!==w?(v=s.jsx("div",{className:"typography-ui-label text-foreground",children:w}),e[31]=w,e[32]=v):v=e[32];let S;e[33]!==r?(S=r("settings.view.home.cards.agents.description"),e[33]=r,e[34]=S):S=e[34];let A;e[35]!==S?(A=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:S}),e[35]=S,e[36]=A):A=e[36];let j;e[37]!==x||e[38]!==v||e[39]!==A?(j=s.jsxs("button",{type:"button",onClick:x,className:g,children:[v,A]}),e[37]=x,e[38]=v,e[39]=A,e[40]=j):j=e[40];let C;e[41]!==n?(C=()=>n("skills.catalog"),e[41]=n,e[42]=C):C=e[42];let I;e[43]===Symbol.for("react.memo_cache_sentinel")?(I=pe("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[43]=I):I=e[43];let R;e[44]!==r?(R=r("settings.view.home.cards.skillsCatalog.title"),e[44]=r,e[45]=R):R=e[45];let k;e[46]!==R?(k=s.jsx("div",{className:"typography-ui-label text-foreground",children:R}),e[46]=R,e[47]=k):k=e[47];let P;e[48]!==r?(P=r("settings.view.home.cards.skillsCatalog.description"),e[48]=r,e[49]=P):P=e[49];let N;e[50]!==P?(N=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:P}),e[50]=P,e[51]=N):N=e[51];let D;e[52]!==C||e[53]!==k||e[54]!==N?(D=s.jsxs("button",{type:"button",onClick:C,className:I,children:[k,N]}),e[52]=C,e[53]=k,e[54]=N,e[55]=D):D=e[55];let T;e[56]!==n?(T=()=>n("mcp"),e[56]=n,e[57]=T):T=e[57];let M;e[58]===Symbol.for("react.memo_cache_sentinel")?(M=pe("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[58]=M):M=e[58];let $;e[59]!==r?($=r("settings.view.home.cards.mcp.title"),e[59]=r,e[60]=$):$=e[60];let F;e[61]!==$?(F=s.jsx("div",{className:"typography-ui-label text-foreground",children:$}),e[61]=$,e[62]=F):F=e[62];let V;e[63]!==r?(V=r("settings.view.home.cards.mcp.description"),e[63]=r,e[64]=V):V=e[64];let O;e[65]!==V?(O=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:V}),e[65]=V,e[66]=O):O=e[66];let L;e[67]!==T||e[68]!==F||e[69]!==O?(L=s.jsxs("button",{type:"button",onClick:T,className:M,children:[F,O]}),e[67]=T,e[68]=F,e[69]=O,e[70]=L):L=e[70];let W;e[71]!==n?(W=()=>n("usage"),e[71]=n,e[72]=W):W=e[72];let B;e[73]===Symbol.for("react.memo_cache_sentinel")?(B=pe("rounded-lg border border-border bg-[var(--surface-elevated)] p-4 text-left","hover:bg-[var(--interactive-hover)] transition-colors"),e[73]=B):B=e[73];let ne;e[74]!==r?(ne=r("settings.view.home.cards.usage.title"),e[74]=r,e[75]=ne):ne=e[75];let le;e[76]!==ne?(le=s.jsx("div",{className:"typography-ui-label text-foreground",children:ne}),e[76]=ne,e[77]=le):le=e[77];let ee;e[78]!==r?(ee=r("settings.view.home.cards.usage.description"),e[78]=r,e[79]=ee):ee=e[79];let ae;e[80]!==ee?(ae=s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:ee}),e[80]=ee,e[81]=ae):ae=e[81];let ge;e[82]!==W||e[83]!==le||e[84]!==ae?(ge=s.jsxs("button",{type:"button",onClick:W,className:B,children:[le,ae]}),e[82]=W,e[83]=le,e[84]=ae,e[85]=ge):ge=e[85];let te;e[86]!==y||e[87]!==j||e[88]!==D||e[89]!==L||e[90]!==ge?(te=s.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[y,j,D,L,ge]}),e[86]=y,e[87]=j,e[88]=D,e[89]=L,e[90]=ge,e[91]=te):te=e[91];let E;return e[92]!==te||e[93]!==d?(E=s.jsx("div",{className:"h-full overflow-auto",children:s.jsxs("div",{className:"mx-auto w-full max-w-3xl px-6 py-6 space-y-6",children:[d,te]})}),e[92]=te,e[93]=d,e[94]=E):E=e[94],E},bI=t=>{const e=nt.c(99),{onClose:n,forceMobile:r,isWindowed:a}=t,{t:i}=ut(),o=un(),c=r??o.isMobile,d=Te(yI),p=Te(vI),m=Te(wI);let u;e[0]!==d?(u=kx(d),e[0]=d,e[1]=u):u=e[1];const h=u,[b,f]=l.useState("nav"),y=l.useRef(null),[x,g]=l.useState(216),[w,v]=l.useState(!1),[S,A]=l.useState(!1),j=l.useRef(0),C=l.useRef(x),I=l.useRef(null);let R;e[2]===Symbol.for("react.memo_cache_sentinel")?(R=kn(),e[2]=R):R=e[2];const k=R;let P;e[3]===Symbol.for("react.memo_cache_sentinel")?(P=xI(k),e[3]=P):P=e[3];const N=P;let D;if(e[4]!==c){let be;e[6]===Symbol.for("react.memo_cache_sentinel")?(be=Ae=>Kf(Ae,N),e[6]=be):be=e[6];let De;e[7]===Symbol.for("react.memo_cache_sentinel")?(De=Ae=>!(N.isVSCode&&Ae.slug==="projects"),e[7]=De):De=e[7],D=Qu.filter(jI).filter(be).filter(De).filter(Ae=>!(c&&Ae.slug==="shortcuts")),e[4]=c,e[5]=D}else D=e[5];const T=D;let M;e[8]===Symbol.for("react.memo_cache_sentinel")?(M=new Map(gI.map(NI)),e[8]=M):M=e[8];const $=M;let F;if(e[9]!==T){let be;e[11]===Symbol.for("react.memo_cache_sentinel")?(be=(De,Ae)=>($.get(De.slug)??999)-($.get(Ae.slug)??999),e[11]=be):be=e[11],F=T.slice().sort(be),e[9]=T,e[10]=F}else F=e[10];const V=F,O=Fs(SI);let L,W;e[12]!==w?(L=()=>{if(typeof window>"u")return;const be=()=>{if(!w){const De=Math.min(Wf,Math.max(Uf,Math.floor(window.innerWidth*.12)));g(De)}};return window.addEventListener("resize",be),()=>window.removeEventListener("resize",be)},W=[w],e[12]=w,e[13]=L,e[14]=W):(L=e[13],W=e[14]),l.useEffect(L,W);let B,ne;e[15]!==S?(ne=()=>{if(!S)return;const be=Ae=>{const ve=Ae.clientX-j.current,U=Math.min(Wf,Math.max(Uf,C.current+ve));g(U),v(!0)},De=()=>A(!1);return window.addEventListener("pointermove",be),window.addEventListener("pointerup",De,{once:!0}),()=>{window.removeEventListener("pointermove",be),window.removeEventListener("pointerup",De)}},B=[S],e[15]=S,e[16]=B,e[17]=ne):(B=e[16],ne=e[17]),l.useEffect(ne,B);let le;e[18]!==x?(le=be=>{A(!0),j.current=be.clientX,C.current=x,be.preventDefault()},e[18]=x,e[19]=le):le=e[19];const ee=le;let ae;e[20]!==p||e[21]!==h?(ae=()=>{if(!(!p&&!N.isVSCode)){if(h==="agents"){_i.getState().loadAgents();return}if(h==="commands"){Bu.getState().loadCommands();return}if(h==="mcp"){Fo.getState().loadMcpConfigs();return}(h==="skills.installed"||h==="skills.catalog")&&(ya.getState().loadSkills(),Qa.getState().loadCatalog())}},e[20]=p,e[21]=h,e[22]=ae):ae=e[22];let ge;e[23]!==O||e[24]!==p||e[25]!==h?(ge=[O,p,N.isVSCode,h],e[23]=O,e[24]=p,e[25]=h,e[26]=ge):ge=e[26],l.useEffect(ae,ge);let te;e[27]!==c||e[28]!==m?(te=be=>{if(m(be),y.current=be,!c)return;const De=xo(be);if(!De||De.slug==="home"){f("nav");return}f(De.kind==="split"?"page-sidebar":"page-content")},e[27]=c,e[28]=m,e[29]=te):te=e[29];const E=te;let z;e[30]!==h?(z=xo(h),e[30]=h,e[31]=z):z=e[31];const J=z;let H;e[32]===Symbol.for("react.memo_cache_sentinel")?(H={appearance:"visual",chat:"chat",shortcuts:"shortcuts",sessions:"sessions",notifications:"notifications",voice:"voice",tunnel:"tunnel"},e[32]=H):H=e[32];const re=H;let ce;e[33]!==i?(ce=be=>{switch(be){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[33]=i,e[34]=ce):ce=e[34];const Ne=ce;let me;e[35]!==i?(me=()=>s.jsx("div",{className:"flex h-full items-center justify-center px-6",children:s.jsxs("div",{className:"max-w-md text-center",children:[s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:i("settings.view.unavailable.title")}),s.jsx("p",{className:"typography-ui text-muted-foreground mt-1",children:i("settings.view.unavailable.description")})]})}),e[35]=i,e[36]=me):me=e[36];const we=me,_=kI;let ue;e[37]!==E||e[38]!==we?(ue=be=>{const De=xo(be);if(De&&!Kf(De,N))return we();switch(be){case"home":return s.jsx(yd,{onOpen:E});case"projects":return s.jsx(GC,{});case"remote-instances":return s.jsx(y4,{});case"agents":return s.jsx(y5,{});case"behavior":return s.jsx(S5,{});case"commands":return s.jsx(R5,{});case"mcp":return s.jsx(oC,{});case"skills.installed":return s.jsx(uf,{view:"installed"});case"skills.catalog":return s.jsx(uf,{view:"catalog"});case"providers":return s.jsx(I4,{});case"usage":return s.jsx(K4,{});case"magic-prompts":return s.jsx(J4,{});case"git":return s.jsx(t6,{});case"appearance":case"chat":case"shortcuts":case"sessions":case"notifications":case"voice":case"tunnel":{const Ae=re[be]??"visual";return s.jsx(iI,{section:Ae})}default:return s.jsx(yd,{onOpen:E})}},e[37]=E,e[38]=we,e[39]=ue):ue=e[39];const Q=ue;let oe,Z;e[40]!==c||e[41]!==b||e[42]!==h?(oe=()=>{if(!c||b!=="nav"||h==="home"||y.current===h)return;const be=xo(h);!be||be.slug==="home"||(y.current=h,f(be.kind==="split"?"page-sidebar":"page-content"))},Z=[c,b,h],e[40]=c,e[41]=b,e[42]=h,e[43]=oe,e[44]=Z):(oe=e[43],Z=e[44]),l.useEffect(oe,Z);const Ie=c&&b!=="nav";let Se,Y,fe,ke,xe,he,Pe;if(e[45]!==J||e[46]!==Ne||e[47]!==c||e[48]!==a||e[49]!==b||e[50]!==n||e[51]!==E||e[52]!==Q||e[53]!==h||e[54]!==Ie||e[55]!==V||e[56]!==i){const be=ql();let De;e[64]===Symbol.for("react.memo_cache_sentinel")?(De=()=>{f("nav")},e[64]=De):De=e[64];const Ae=De;let ve;e[65]===Symbol.for("react.memo_cache_sentinel")?(ve=()=>{f("page-sidebar")},e[65]=ve):ve=e[65];const U=ve;let de;e[66]!==Ne||e[67]!==E||e[68]!==h||e[69]!==V||e[70]!==i?(de=()=>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:V.map(se=>{const ie=h===se.slug,K=Zu(se.slug);return K?s.jsx(kt,{children:s.jsx(St,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>E(se.slug),className:pe("flex h-8 items-center gap-2 rounded-md px-2 overflow-hidden",ie?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:[s.jsx(K,{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:Ne(se.slug)}),(se.slug==="voice"||se.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")})]})]})})},se.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(St,{asChild:!0,children:s.jsxs("button",{type:"button",className:pe("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:CI,children:[s.jsx(Mn,{className:"h-4 w-4 shrink-0"}),s.jsx("span",{children:i("settings.view.actions.reloadOpenCode")})]})}),s.jsx(Ct,{children:i("settings.view.actions.reloadOpenCodeTooltip")})]})})})]}),e[66]=Ne,e[67]=E,e[68]=h,e[69]=V,e[70]=i,e[71]=de):de=e[71],fe=de;let Re;e[72]!==J||e[73]!==b||e[74]!==Q||e[75]!==fe||e[76]!==h?(Re=()=>{if(b==="nav")return s.jsx("div",{className:pe("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(rn,{children:fe()})})});if(!J)return s.jsx("div",{className:"flex-1 bg-background"});if(b==="page-sidebar"){if(J.kind!=="split"){const ie=Q(h);return s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:s.jsx(rn,{children:ie})})}return s.jsx("div",{className:pe("flex-1 min-h-0 overflow-hidden",N.isVSCode?"bg-background":"bg-sidebar"),children:s.jsx(rn,{children:_(h,{onItemSelect:()=>f("page-content")})})})}const se=Q(h);return s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:s.jsx(rn,{children:se})})},e[72]=J,e[73]=b,e[74]=Q,e[75]=fe,e[76]=h,e[77]=Re):Re=e[77],Y=Re;let Le;e[78]!==J||e[79]!==E||e[80]!==Q||e[81]!==h?(Le=()=>!J||h==="home"?s.jsx(yd,{onOpen:E}):J.kind==="split"?s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden",children:[s.jsx("div",{className:pe("w-[264px] min-w-[264px] border-r",N.isVSCode?"bg-background":"bg-sidebar"),style:{borderColor:"var(--interactive-border)"},children:s.jsx(rn,{children:_(h,{})})}),s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:s.jsx(rn,{children:Q(h)})})]}):s.jsx("div",{className:"h-full min-h-0 overflow-hidden bg-background",children:s.jsx(rn,{children:Q(h)})}),e[78]=J,e[79]=E,e[80]=Q,e[81]=h,e[82]=Le):Le=e[82],Se=Le,ke=I,xe="true",e[83]===Symbol.for("react.memo_cache_sentinel")?(he=pe("relative flex h-full min-h-0 flex-col overflow-hidden bg-background"),e[83]=he):he=e[83],Pe=c?s.jsxs("div",{className:pe("flex items-center gap-2 px-3 py-2 border-b","bg-background"),style:{borderColor:"var(--interactive-border)"},children:[s.jsx("button",{type:"button",onClick:Ie?Ae:n,"aria-label":i(Ie?"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(zi,{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"):J?Ne(J.slug):i("settings.view.home.title")}),b==="page-content"&&J?.kind==="split"&&s.jsx("button",{type:"button",onClick:U,"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(zy,{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:be}),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(Ds,{className:"h-5 w-5"})})]}):s.jsxs(s.Fragment,{children:[Ie&&s.jsx("div",{className:pe("absolute left-3 z-50",a?"top-2":"top-3"),children:s.jsx("button",{type:"button",onClick:Ae,"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(zi,{className:"h-5 w-5"})})}),n&&s.jsx("div",{className:pe("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:be}),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(Ds,{className:"h-5 w-5"})})})]}),e[45]=J,e[46]=Ne,e[47]=c,e[48]=a,e[49]=b,e[50]=n,e[51]=E,e[52]=Q,e[53]=h,e[54]=Ie,e[55]=V,e[56]=i,e[57]=Se,e[58]=Y,e[59]=fe,e[60]=ke,e[61]=xe,e[62]=he,e[63]=Pe}else Se=e[57],Y=e[58],fe=e[59],ke=e[60],xe=e[61],he=e[62],Pe=e[63];let Be;e[84]!==ee||e[85]!==c||e[86]!==S||e[87]!==x||e[88]!==Se||e[89]!==Y||e[90]!==fe||e[91]!==i?(Be=s.jsx("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:c?Y():s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:pe("relative flex h-full min-h-0 flex-col overflow-hidden border-r",k?"bg-sidebar":N.isVSCode?"bg-background":"bg-sidebar",S?"":"transition-[width,min-width] duration-200 ease-[cubic-bezier(0.25,0.1,0.25,1)]"),style:{width:`${x}px`,minWidth:`${x}px`,borderColor:"var(--interactive-border)"},children:[s.jsx("div",{className:pe("absolute right-0 top-0 z-20 h-full w-[6px] -mr-[3px] cursor-col-resize",S?"bg-primary/30":"bg-transparent hover:bg-primary/20"),onPointerDown:ee,role:"separator","aria-orientation":"vertical","aria-label":i("settings.view.actions.resizeNavigation")}),s.jsx(rn,{children:fe()})]}),s.jsx("div",{className:"flex-1 overflow-hidden bg-background",children:Se()})]})}),e[84]=ee,e[85]=c,e[86]=S,e[87]=x,e[88]=Se,e[89]=Y,e[90]=fe,e[91]=i,e[92]=Be):Be=e[92];let G;return e[93]!==ke||e[94]!==xe||e[95]!==he||e[96]!==Pe||e[97]!==Be?(G=s.jsxs("div",{ref:ke,"data-settings-view":xe,className:he,children:[Pe,Be]}),e[93]=ke,e[94]=xe,e[95]=he,e[96]=Pe,e[97]=Be,e[98]=G):G=e[98],G};function yI(t){return t.settingsPage}function vI(t){return t.isSettingsDialogOpen}function wI(t){return t.setSettingsPage}function jI(t){return t.slug!=="home"}function NI(t,e){return[t,e]}function SI(t){return t.activeProjectId}function kI(t,e){switch(t){case"projects":return s.jsx($C,{onItemSelect:e.onItemSelect});case"remote-instances":return s.jsx(i4,{onItemSelect:e.onItemSelect});case"agents":return s.jsx(m5,{onItemSelect:e.onItemSelect});case"commands":return s.jsx(k5,{onItemSelect:e.onItemSelect});case"mcp":return s.jsx(E5,{onItemSelect:e.onItemSelect});case"skills.installed":return s.jsx(lC,{onItemSelect:e.onItemSelect});case"providers":return s.jsx(j4,{onItemSelect:e.onItemSelect});case"usage":return s.jsx(P4,{onItemSelect:e.onItemSelect});case"magic-prompts":return s.jsx(G4,{onItemSelect:e.onItemSelect});default:return null}}function CI(){No({message:"Restarting OpenCode…",mode:"projects",scopes:["all"]})}const II=Object.freeze(Object.defineProperty({__proto__:null,SettingsView:bI,getSettingsNavIcon:Zu},Symbol.toStringTag,{value:"Module"})),lu=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},AI=()=>{const t=nt.c(162),{t:e}=ut(),n=Te(PI),r=Te(DI),a=Te(TI),i=Te(MI),o=Te(RI),c=Te(EI),d=Te(FI),p=Te(OI),m=Te(LI),u=Te($I),h=Te(BI),b=Te(VI),f=Wt(zI),y=Wt(_I),x=jo(UI),g=Ws(WI),w=Fs(KI),v=Xr(),S=Lu(HI),{files:A,git:j}=Gn(),C=pn(GI),{isMobile:I}=un();let R;t[0]!==v?(R=v?lu(v):null,t[0]=v,t[1]=R):R=t[1];const k=R,[P,N]=l.useState(""),D=bc(P,200);let T;t[2]!==D?(T=D.trim(),t[2]=D,t[3]=T):T=t[3];const M=T;let $;t[4]!==P?($=P.trim(),t[4]=P,t[5]=$):$=t[5];const F=$;let V,O;t[6]!==n?(V=()=>{n&&N("")},O=[n],t[6]=n,t[7]=V,t[8]=O):(V=t[7],O=t[8]),l.useEffect(V,O);let L,W;t[9]!==x||t[10]!==C||t[11]!==j||t[12]!==n?(L=()=>{if(!n||!j)return;const Qe=setTimeout(()=>{const ze=new Set;for(const ht of x){const _t=kl(ht);!_t||ze.has(_t)||(ze.add(_t),C(_t,j))}},0);return()=>clearTimeout(Qe)},W=[n,x,j,C],t[9]=x,t[10]=C,t[11]=j,t[12]=n,t[13]=L,t[14]=W):(L=t[13],W=t[14]),l.useEffect(L,W);let B;t[15]!==r?(B=()=>r(!1),t[15]=r,t[16]=B):B=t[16];const ne=B;let le;t[17]!==ne?(le=Qe=>()=>{ne(),Qe()},t[17]=ne,t[18]=le):le=t[18];const ee=le;let ae;t[19]!==w?.id||t[20]!==w?.path||t[21]!==g||t[22]!==I||t[23]!==u||t[24]!==f||t[25]!==ee||t[26]!==a||t[27]!==c||t[28]!==i||t[29]!==e||t[30]!==m||t[31]!==p||t[32]!==d?(ae=()=>{const Qe=[{id:"new-session",title:e("commandPalette.item.newSession"),icon:s.jsx(_s,{className:"mr-2 h-4 w-4"}),shortcutId:"new_chat",searchText:e("commandPalette.item.newSession"),onSelect:ee(()=>{a("chat"),c(!1),f()})},{id:"new-worktree",title:e("commandPalette.item.newWorktreeDraft"),icon:s.jsx(Ks,{className:"mr-2 h-4 w-4"}),shortcutId:"new_chat_worktree",searchText:e("commandPalette.item.newWorktreeDraft"),onSelect:ee(qI)},{id:"add-project",title:e("commandPalette.item.addProject"),icon:s.jsx(Ca,{className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.addProject"),onSelect:ee(QI)},{id:"toggle-sidebar",title:e(I?"commandPalette.item.showSessionSwitcher":"commandPalette.item.toggleSidebar"),icon:s.jsx(si,{className:"mr-2 h-4 w-4"}),shortcutId:"toggle_sidebar",searchText:e(I?"commandPalette.item.showSessionSwitcher":"commandPalette.item.toggleSidebar"),onSelect:ee(()=>{if(I){const{isSessionSwitcherOpen:ze}=Te.getState();c(!ze)}else d()})},{id:"toggle-right-sidebar",title:e("commandPalette.item.toggleRightSidebar"),icon:s.jsx(Di,{className:"mr-2 h-4 w-4"}),shortcutId:"toggle_right_sidebar",searchText:e("commandPalette.item.toggleRightSidebar"),onSelect:ee(()=>p())},{id:"toggle-terminal",title:e("commandPalette.item.toggleTerminal"),icon:s.jsx(Za,{className:"mr-2 h-4 w-4"}),shortcutId:"toggle_terminal",searchText:e("commandPalette.item.toggleTerminal"),onSelect:ee(()=>m())},{id:"context-usage",title:e("commandPalette.item.showContextUsage"),icon:s.jsx(_y,{className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.showContextUsage"),onSelect:ee(()=>{g&&u(g)})},{id:"open-settings",title:e("commandPalette.item.openSettings"),icon:s.jsx(Vi,{className:"mr-2 h-4 w-4"}),shortcutId:"open_settings",searchText:e("commandPalette.item.openSettings"),onSelect:ee(()=>i(!0))}];return Mu()&&Qe.splice(1,0,{id:"new-mini-chat",title:e("commandPalette.item.newMiniChat"),icon:s.jsx(Ti,{className:"mr-2 h-4 w-4"}),shortcutId:"new_mini_chat",searchText:e("commandPalette.item.newMiniChat"),onSelect:ee(()=>{Kl("desktop_open_draft_mini_chat_window",{directory:lu(g||w?.path||""),projectId:w?.id??null}).catch(JI)})}),Qe},t[19]=w?.id,t[20]=w?.path,t[21]=g,t[22]=I,t[23]=u,t[24]=f,t[25]=ee,t[26]=a,t[27]=c,t[28]=i,t[29]=e,t[30]=m,t[31]=p,t[32]=d,t[33]=ae):ae=t[33],w?.id,w?.path;let ge;t[34]!==ae?(ge=ae(),t[34]=ae,t[35]=ge):ge=t[35];const te=ge;let E;t[36]===Symbol.for("react.memo_cache_sentinel")?(E=kn(),t[36]=E):E=t[36];const z=E;let J;t[37]===Symbol.for("react.memo_cache_sentinel")?(J={isVSCode:yn(),isWeb:!z&&ja(),isDesktop:z},t[37]=J):J=t[37];const H=J;let re;if(t[38]!==ee||t[39]!==i||t[40]!==o){let Qe;t[42]===Symbol.for("react.memo_cache_sentinel")?(Qe=ze=>ze.isAvailable?ze.isAvailable(H):!0,t[42]=Qe):Qe=t[42],re=Qu.filter(YI).filter(Qe).map(ze=>{const ht=Zu(ze.slug)??Vi,_t=(ze.keywords??[]).join(" ");return{id:`settings:${ze.slug}`,title:ze.title,icon:s.jsx(ht,{className:"mr-2 h-4 w-4"}),searchText:`${ze.title} ${ze.group} ${_t}`,onSelect:ee(()=>{o(ze.slug),i(!0)})}}),t[38]=ee,t[39]=i,t[40]=o,t[41]=re}else re=t[41];const ce=re,Ne=XI;let me;if(t[43]!==x){let Qe;t[45]===Symbol.for("react.memo_cache_sentinel")?(Qe=(ze,ht)=>Ne(ht)-Ne(ze),t[45]=Qe):Qe=t[45],me=[...x].sort(Qe),t[43]=x,t[44]=me}else me=t[44];const we=me,_=Ng(),ue=Wt(ZI);let Q;t[46]!==_||t[47]!==ue?(Q=(Qe,ze)=>{const ht=ue.get(Qe);return ht?.branch?ht.branch.trim()||null:ze&&_.get(ze)?.trim()||null},t[46]=_,t[47]=ue,t[48]=Q):Q=t[48];const oe=Q;let Z;t[49]===Symbol.for("react.memo_cache_sentinel")?(Z=[],t[49]=Z):Z=t[49];const[Ie,Se]=l.useState(Z),[Y,fe]=l.useState(!1);let ke,xe;t[50]!==k||t[51]!==n||t[52]!==S||t[53]!==M?(ke=()=>{if(!n){Se([]),fe(!1);return}if(!k||M.length===0){Se([]),fe(!1);return}let Qe=!1;return fe(!0),S(k,M,10,{type:"file"}).then(ze=>{Qe||Se(ze.map(eA))}).catch(()=>{Qe||Se([])}).finally(()=>{Qe||fe(!1)}),()=>{Qe=!0}},xe=[n,k,M,S],t[50]=k,t[51]=n,t[52]=S,t[53]=M,t[54]=ke,t[55]=xe):(ke=t[54],xe=t[55]),l.useEffect(ke,xe);const he=F.length>0;let Pe;e:{if(!he){let ze;t[56]!==te?(ze=te.map(tA),t[56]=te,t[57]=ze):ze=t[57],Pe=ze;break e}let Qe;t[58]!==te||t[59]!==F?(Qe=tl(te,F,sA,{limit:7,noFuzzy:!0}),t[58]=te,t[59]=F,t[60]=Qe):Qe=t[60],Pe=Qe}const Be=Pe;let G;e:{if(!he){let ze;t[61]===Symbol.for("react.memo_cache_sentinel")?(ze=[],t[61]=ze):ze=t[61],G=ze;break e}let Qe;t[62]!==F||t[63]!==ce?(Qe=tl(ce,F,nA,{limit:7,noFuzzy:!0}),t[62]=F,t[63]=ce,t[64]=Qe):Qe=t[64],G=Qe}const be=G;let De;e:{if(!he){let ze;t[65]!==we?(ze=we.slice(0,5).map(rA),t[65]=we,t[66]=ze):ze=t[66],De=ze;break e}let Qe;t[67]!==F||t[68]!==we?(Qe=tl(we,F,aA,{limit:7,threshold:.2}),t[67]=F,t[68]=we,t[69]=Qe):Qe=t[69],De=Qe}const Ae=De;let ve;e:{if(!he||Ie.length===0){let ze;t[70]===Symbol.for("react.memo_cache_sentinel")?(ze=[],t[70]=ze):ze=t[70],ve=ze;break e}let Qe;t[71]!==Ie||t[72]!==F?(Qe=tl(Ie,F,iA,{limit:10,threshold:.4}),t[71]=Ie,t[72]=F,t[73]=Qe):Qe=t[73],ve=Qe}const U=ve;let de,Re,Le,se,ie,K,_e,He,Ke,Ze,Xe,mt,et,ct,lt;if(t[74]!==oe||t[75]!==ne||t[76]!==k||t[77]!==A||t[78]!==he||t[79]!==n||t[80]!==h||t[81]!==P||t[82]!==Be||t[83]!==U||t[84]!==Ae||t[85]!==be||t[86]!==r||t[87]!==y||t[88]!==b||t[89]!==e){const Qe=Be.map(oA),ze=be.map(lA),ht=Ae.map(cA);lt=he?U.map(dA):[];let _t;e:{if(!he){_t=["commands","sessions"];break e}const Ft=uA,Ue=[{key:"commands",score:Ft(Be)},{key:"settings",score:Ft(be)},{key:"sessions",score:Ft(Ae)},{key:"files",score:Ft(U)}];Ue.sort(mA),_t=Ue.map(pA)}const Kt=_t;let Ut;t[105]!==ne||t[106]!==y?(Ut=Ft=>{ne(),y(Ft.id,kl(Ft))},t[105]=ne,t[106]=y,t[107]=Ut):Ut=t[107];const jt=Ut;let Dt;t[108]!==ne||t[109]!==k||t[110]!==A||t[111]!==h?(Dt=async Ft=>{if(!k)return;const Ue=await Hu(A,Ft);if(!Ue.ok){q.error(Gu(Ue.reason));return}h(k,Ft),ne()},t[108]=ne,t[109]=k,t[110]=A,t[111]=h,t[112]=Dt):Dt=t[112];const ts=Dt;let it;t[113]!==b?(it=Ft=>fc(ra(Ft,b)),t[113]=b,t[114]=it):it=t[114];const Yt=it;se=ws,mt=n,et=r;let Qt;t[115]!==e?(Qt=e("commandPalette.title"),t[115]=e,t[116]=Qt):Qt=t[116];let Xt;t[117]!==Qt?(Xt=s.jsx(Ss,{children:Qt}),t[117]=Qt,t[118]=Xt):Xt=t[118];let us;t[119]!==e?(us=e("commandPalette.description"),t[119]=e,t[120]=us):us=t[120];let ms;t[121]!==us?(ms=s.jsx(Os,{children:us}),t[121]=us,t[122]=ms):ms=t[122],t[123]!==Xt||t[124]!==ms?(ct=s.jsxs(Is,{className:"sr-only",children:[Xt,ms]}),t[123]=Xt,t[124]=ms,t[125]=ct):ct=t[125],Le=vs,Ze="overflow-hidden p-0",Xe=!0,Re=oi,_e=!1,He="[&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group]]:px-2 [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-input-wrapper]_svg]:h-4 [&_[cmdk-input-wrapper]_svg]:w-4 [&_[cmdk-input]]:h-8 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-1.5 [&_[cmdk-item]_svg]:h-4 [&_[cmdk-item]_svg]:w-4 [&_[cmdk-item]]:typography-meta";let gs;t[126]!==e?(gs=e("commandPalette.input.placeholder"),t[126]=e,t[127]=gs):gs=t[127],t[128]!==P||t[129]!==gs?(Ke=s.jsx(ka,{value:P,onValueChange:N,placeholder:gs}),t[128]=P,t[129]=gs,t[130]=Ke):Ke=t[130],de=li;let ds;t[131]!==e?(ds=e("commandPalette.empty.noResults"),t[131]=e,t[132]=ds):ds=t[132],t[133]!==ds?(ie=s.jsx(ci,{children:ds}),t[133]=ds,t[134]=ie):ie=t[134],K=Kt.map(Ft=>Ft==="commands"&&Qe.length>0?s.jsx(Kn,{children:Qe.map(Ue=>s.jsxs(Rn,{value:Ue.id,onSelect:Ue.onSelect,children:[Ue.icon,s.jsx("span",{children:Ue.title}),Ue.shortcutId?s.jsx(oN,{children:Yt(Ue.shortcutId)}):null]},Ue.id))},"commands"):Ft==="settings"&&ze.length>0?s.jsx(Kn,{children:ze.map(fA)},"settings"):Ft==="sessions"&&ht.length>0?s.jsx(Kn,{children:ht.map(Ue=>{const Tt=Ue.title||e("commandPalette.session.untitled"),At=kl(Ue),vt=oe(Ue.id,At);return s.jsxs(Rn,{value:`session:${Ue.id}`,onSelect:()=>jt(Ue),children:[s.jsx(eg,{className:"mr-2 h-4 w-4"}),s.jsx("span",{className:"truncate",children:Tt}),vt?s.jsxs("span",{className:"ml-auto inline-flex items-center gap-1 text-muted-foreground typography-meta",children:[s.jsx(Ks,{className:"h-3 w-3"}),s.jsx("span",{className:"truncate max-w-[160px]",children:vt})]}):null]},Ue.id)})},"sessions"):Ft==="files"&&lt.length>0?s.jsx(Kn,{children:lt.map(Ue=>{const Tt=V1(Ue.relativePath||Ue.name,{maxLength:80});return s.jsxs(Rn,{value:`file:${Ue.path}`,onSelect:()=>{ts(Ue.path)},children:[s.jsx(Pr,{filePath:Ue.path,className:"mr-2 size-4 shrink-0"}),s.jsx("span",{className:"truncate","aria-label":Ue.relativePath,children:Tt})]},`file:${Ue.path}`)})},"files"):null),t[74]=oe,t[75]=ne,t[76]=k,t[77]=A,t[78]=he,t[79]=n,t[80]=h,t[81]=P,t[82]=Be,t[83]=U,t[84]=Ae,t[85]=be,t[86]=r,t[87]=y,t[88]=b,t[89]=e,t[90]=de,t[91]=Re,t[92]=Le,t[93]=se,t[94]=ie,t[95]=K,t[96]=_e,t[97]=He,t[98]=Ke,t[99]=Ze,t[100]=Xe,t[101]=mt,t[102]=et,t[103]=ct,t[104]=lt}else de=t[90],Re=t[91],Le=t[92],se=t[93],ie=t[94],K=t[95],_e=t[96],He=t[97],Ke=t[98],Ze=t[99],Xe=t[100],mt=t[101],et=t[102],ct=t[103],lt=t[104];let ye;t[135]!==he||t[136]!==Y||t[137]!==e||t[138]!==lt?(ye=he&&Y&&lt.length===0?s.jsx("div",{className:"px-3 py-2 typography-meta text-muted-foreground",children:e("commandPalette.empty.searchingFiles")}):null,t[135]=he,t[136]=Y,t[137]=e,t[138]=lt,t[139]=ye):ye=t[139];let Ge;t[140]!==de||t[141]!==ie||t[142]!==K||t[143]!==ye?(Ge=s.jsxs(de,{children:[ie,K,ye]}),t[140]=de,t[141]=ie,t[142]=K,t[143]=ye,t[144]=Ge):Ge=t[144];let $e;t[145]!==Re||t[146]!==_e||t[147]!==He||t[148]!==Ke||t[149]!==Ge?($e=s.jsxs(Re,{shouldFilter:_e,className:He,children:[Ke,Ge]}),t[145]=Re,t[146]=_e,t[147]=He,t[148]=Ke,t[149]=Ge,t[150]=$e):$e=t[150];let Ve;t[151]!==Le||t[152]!==Ze||t[153]!==Xe||t[154]!==$e?(Ve=s.jsx(Le,{className:Ze,showCloseButton:Xe,children:$e}),t[151]=Le,t[152]=Ze,t[153]=Xe,t[154]=$e,t[155]=Ve):Ve=t[155];let tt;return t[156]!==se||t[157]!==mt||t[158]!==et||t[159]!==ct||t[160]!==Ve?(tt=s.jsxs(se,{open:mt,onOpenChange:et,children:[ct,Ve]}),t[156]=se,t[157]=mt,t[158]=et,t[159]=ct,t[160]=Ve,t[161]=tt):tt=t[161],tt};function PI(t){return t.isCommandPaletteOpen}function DI(t){return t.setCommandPaletteOpen}function TI(t){return t.setActiveMainTab}function MI(t){return t.setSettingsDialogOpen}function RI(t){return t.setSettingsPage}function EI(t){return t.setSessionSwitcherOpen}function FI(t){return t.toggleSidebar}function OI(t){return t.toggleRightSidebar}function LI(t){return t.toggleBottomTerminal}function $I(t){return t.openContextOverview}function BI(t){return t.openContextFile}function VI(t){return t.shortcutOverrides}function zI(t){return t.openNewSessionDraft}function _I(t){return t.setCurrentSession}function UI(t){return t.activeSessions}function WI(t){return t.currentDirectory}function KI(t){return t.getActiveProject()}function HI(t){return t.searchFiles}function GI(t){return t.ensureStatus}function qI(){Sg()}function QI(){Dr.requestDirectoryDialog()}function JI(t){console.warn("[command-palette] failed to open draft mini chat window",t)}function YI(t){return t.slug!=="home"}function XI(t){return(typeof t.time?.updated=="number"?t.time.updated:0)||(typeof t.time?.created=="number"?t.time.created:0)}function ZI(t){return t.worktreeMetadata}function eA(t){return{path:lu(t.path),name:t.name,relativePath:t.relativePath}}function tA(t){return{item:t,score:0}}function sA(t){return t.searchText}function nA(t){return t.searchText}function rA(t){return{item:t,score:0}}function aA(t){return t.title||""}function iA(t){return t.name}function oA(t){return t.item}function lA(t){return t.item}function cA(t){return t.item}function dA(t){return t.item}function uA(t){return t.length?t[0].score:1/0}function mA(t,e){return t.score-e.score}function pA(t){return t.key}function fA(t){return s.jsxs(Rn,{value:t.id,onSelect:t.onSelect,children:[t.icon,s.jsx("span",{children:t.title})]},t.id)}const Hf=(t,e,n)=>_1(t)?fc(ra(t,n)):e,hA=()=>{const t=nt.c(68),{t:e}=ut(),n=Te(gA),r=Te(xA),a=Te(bA);let i;t[0]===Symbol.for("react.memo_cache_sentinel")?(i=z1(),t[0]=i):i=t[0];const o=i;let c,d,p,m,u,h,b,f,y;if(t[1]!==n||t[2]!==r||t[3]!==a||t[4]!==e){const M=[{categoryKey:"helpDialog.section.navigationCommands",items:[{id:"open_command_palette",descriptionKey:"helpDialog.item.openCommandPalette",icon:Bo,keys:""},{id:"open_help",descriptionKey:"helpDialog.item.showKeyboardShortcuts",icon:Fd,keys:""},{id:"toggle_sidebar",descriptionKey:"helpDialog.item.toggleSessionSidebar",icon:si,keys:""},{keys:["Tab"],descriptionKey:"helpDialog.item.cycleAgent",icon:Du},{id:"open_model_selector",descriptionKey:"helpDialog.item.openModelSelector",icon:Ga,keys:""},{keys:["↑↓"],descriptionKey:"helpDialog.item.navigateModels",icon:Ga},{keys:["←→"],descriptionKey:"helpDialog.item.adjustThinkingMode",icon:Ao},{id:"cycle_thinking_variant",descriptionKey:"helpDialog.item.cycleThinkingVariant",icon:Ao,keys:""},{keys:[`Shift + Alt + ${o} + N`],descriptionKey:"helpDialog.item.newWindow",icon:Ti}]},{categoryKey:"helpDialog.section.sessionManagement",items:[{id:"new_chat",descriptionKey:"helpDialog.item.createNewSession",icon:_s,keys:""},{id:"new_chat_worktree",descriptionKey:"helpDialog.item.createNewWorktreeDraft",icon:Ks,keys:""},{id:"focus_input",descriptionKey:"helpDialog.item.focusChatInput",icon:Uy,keys:""},{id:"abort_run",descriptionKey:"helpDialog.item.abortActiveRun",icon:Wy,keys:""}]},{categoryKey:"helpDialog.section.panels",items:[{id:"toggle_right_sidebar",descriptionKey:"helpDialog.item.toggleRightSidebar",icon:Di,keys:""},{id:"open_right_sidebar_git",descriptionKey:"helpDialog.item.openRightSidebarGitTab",icon:Ks,keys:""},{id:"open_right_sidebar_files",descriptionKey:"helpDialog.item.openRightSidebarFilesTab",icon:Di,keys:""},{id:"cycle_right_sidebar_tab",descriptionKey:"helpDialog.item.cycleRightSidebarTab",icon:Di,keys:""},{id:"toggle_terminal",descriptionKey:"helpDialog.item.toggleTerminalDock",icon:Ti,keys:""},{id:"toggle_terminal_expanded",descriptionKey:"helpDialog.item.toggleTerminalExpanded",icon:Ti,keys:""},{id:"toggle_context_plan",descriptionKey:"helpDialog.item.togglePlanContextPanel",icon:yu,keys:""}]},{categoryKey:"helpDialog.section.interface",items:[{id:"cycle_theme",descriptionKey:"helpDialog.item.cycleTheme",icon:tg,keys:""},{keys:[`${o} + 1...9`],descriptionKey:"helpDialog.item.switchProject",icon:si},{id:"toggle_services_menu",descriptionKey:"helpDialog.item.toggleServicesMenu",icon:Sa,keys:""},{id:"cycle_services_tab",descriptionKey:"helpDialog.item.cycleServicesTab",icon:Sa,keys:""},{id:"open_settings",descriptionKey:"helpDialog.item.openSettings",icon:Vi,keys:""}]}];d=ws,f=n,y=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 $;t[14]===Symbol.for("react.memo_cache_sentinel")?($=s.jsx(Vi,{className:"h-5 w-5"}),t[14]=$):$=t[14];let F;t[15]!==e?(F=e("helpDialog.title"),t[15]=e,t[16]=F):F=t[16];let V;t[17]!==F?(V=s.jsxs(Ss,{className:"flex items-center gap-2",children:[$,F]}),t[17]=F,t[18]=V):V=t[18];let O;t[19]!==e?(O=e("helpDialog.description"),t[19]=e,t[20]=O):O=t[20];let L;t[21]!==O?(L=s.jsx(Os,{children:O}),t[21]=O,t[22]=L):L=t[22],t[23]!==V||t[24]!==L?(b=s.jsxs(Is,{children:[V,L]}),t[23]=V,t[24]=L,t[25]=b):b=t[25],u="flex-1 overflow-y-auto mt-3 pr-1",p="space-y-4",m=M.map(W=>s.jsxs("div",{children:[s.jsx("h3",{className:"typography-meta font-semibold text-muted-foreground uppercase tracking-wider mb-2",children:e(W.categoryKey)}),s.jsx("div",{className:"space-y-1",children:W.items.map(B=>{const ne=B.id?Hf(B.id,Array.isArray(B.keys)?B.keys[0]:B.keys,a):Array.isArray(B.keys)?B.keys:B.keys.split(" / ");return s.jsxs("div",{className:"flex items-center justify-between py-1 px-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[B.icon&&s.jsx(B.icon,{className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"typography-meta",children:e(B.descriptionKey)})]}),s.jsx("div",{className:"flex items-center gap-1",children:(Array.isArray(ne)?ne:[ne]).map((le,ee)=>s.jsxs(l.Fragment,{children:[ee>0&&s.jsx("span",{className:"typography-meta text-muted-foreground mx-1",children:e("helpDialog.keyCombiner.or")}),s.jsx("kbd",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 typography-meta font-mono bg-muted rounded border border-border/20",children:le})]},`${le}-${ee}`))})]},B.id||B.descriptionKey)})})]},W.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]=y}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],y=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(Fd,{className:"h-3.5 w-3.5 text-muted-foreground mt-0.5"}),t[29]=g):g=t[29];let w;t[30]!==e?(w=e("helpDialog.proTips.title"),t[30]=e,t[31]=w):w=t[31];let v;t[32]!==w?(v=s.jsx("p",{className:"font-medium mb-1",children:w}),t[32]=w,t[33]=v):v=t[33];let S;t[34]!==a||t[35]!==e?(S=e("helpDialog.proTips.commandPalette",{shortcut:Hf("open_command_palette",`${o} P`,a)}),t[34]=a,t[35]=e,t[36]=S):S=t[36];let A;t[37]!==S?(A=s.jsxs("li",{children:["• ",S]}),t[37]=S,t[38]=A):A=t[38];let j;t[39]!==e?(j=e("helpDialog.proTips.recentSessions"),t[39]=e,t[40]=j):j=t[40];let C;t[41]!==j?(C=s.jsxs("li",{children:["• ",j]}),t[41]=j,t[42]=C):C=t[42];let I;t[43]!==e?(I=e("helpDialog.proTips.themeCycling"),t[43]=e,t[44]=I):I=t[44];let R;t[45]!==I?(R=s.jsxs("li",{children:["• ",I]}),t[45]=I,t[46]=R):R=t[46];let k;t[47]!==A||t[48]!==C||t[49]!==R?(k=s.jsxs("ul",{className:"space-y-0.5 typography-meta",children:[A,C,R]}),t[47]=A,t[48]=C,t[49]=R,t[50]=k):k=t[50];let P;t[51]!==v||t[52]!==k?(P=s.jsx("div",{className:"mt-4 p-2 bg-muted/30 rounded-xl",children:s.jsxs("div",{className:"flex items-start gap-2",children:[g,s.jsxs("div",{className:"typography-meta text-muted-foreground",children:[v,k]})]})}),t[51]=v,t[52]=k,t[53]=P):P=t[53];let N;t[54]!==P||t[55]!==u||t[56]!==x?(N=s.jsxs("div",{className:u,children:[x,P]}),t[54]=P,t[55]=u,t[56]=x,t[57]=N):N=t[57];let D;t[58]!==c||t[59]!==N||t[60]!==h||t[61]!==b?(D=s.jsxs(c,{className:h,children:[b,N]}),t[58]=c,t[59]=N,t[60]=h,t[61]=b,t[62]=D):D=t[62];let T;return t[63]!==d||t[64]!==D||t[65]!==f||t[66]!==y?(T=s.jsx(d,{open:f,onOpenChange:y,children:D}),t[63]=d,t[64]=D,t[65]=f,t[66]=y,t[67]=T):T=t[67],T};function gA(t){return t.isHelpDialogOpen}function xA(t){return t.setHelpDialogOpen}function bA(t){return t.shortcutOverrides}const yA=()=>{const t=nt.c(32),{t:e}=ut(),n=Te(vA),r=Te(wA),a=Te(jA);let i;t[0]!==a||t[1]!==e?(i=async()=>{if(!a)return;if((await _n(a)).ok){q.success(e("openCodeStatusDialog.toast.copiedTitle"),{description:e("openCodeStatusDialog.toast.copiedDescription")});return}q.error(e("openCodeStatusDialog.toast.copyFailed"))},t[0]=a,t[1]=e,t[2]=i):i=t[2];const o=i;let c;t[3]!==e?(c=e("openCodeStatusDialog.title"),t[3]=e,t[4]=c):c=t[4];let d;t[5]!==c?(d=s.jsx(Ss,{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(Os,{children:p}),t[9]=p,t[10]=m):m=t[10];let u;t[11]!==d||t[12]!==m?(u=s.jsxs(Is,{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 y;t[22]!==f?(y=s.jsx("pre",{className:"max-h-[60vh] overflow-auto rounded-lg bg-surface-muted p-4 typography-code text-foreground whitespace-pre-wrap",children:f}),t[22]=f,t[23]=y):y=t[23];let x;t[24]!==u||t[25]!==b||t[26]!==y?(x=s.jsxs(vs,{className:"max-w-2xl",children:[u,b,y]}),t[24]=u,t[25]=b,t[26]=y,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 vA(t){return t.isOpenCodeStatusDialogOpen}function wA(t){return t.setOpenCodeStatusDialogOpen}function jA(t){return t.openCodeStatusText}const NA=180,Gf=600,SA=1,kA=6,CA=({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<SA&&i.current.length>0;){const p=i.current.shift();if(!p)break;Wt.getState().currentSessionId!==p&&(Mm(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"||Mm(p).renderable||o.current.has(p)||i.current.includes(p))return;i.current.length>=kA&&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()},NA);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))},Gf);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]))},Gf);return()=>window.clearTimeout(p)},[t,n,d]),l.useEffect(()=>{const p=a.current;return()=>{p.forEach(m=>{clearTimeout(m)}),p.clear(),i.current=[]}},[])};function qf(t){const{localBranches:e,remoteBranches:n,query:r}=t,a=r.trim();if(!a)return{matching:[],otherLocal:e,otherRemote:n};const i=Rm(e,a,m=>m),o=Rm(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 IA({open:t,onOpenChange:e,onSelect:n}){const{t:r}=ut(),a=Te(_=>_.isMobile),{github:i}=Gn(),o=Zn(_=>_.status),c=Zn(_=>_.hasChecked),d=Te(_=>_.setSettingsDialogOpen),p=Te(_=>_.setSettingsPage),m=Fs(_=>_.getActiveProject()),u=m?.path??null,h=Oe.useMemo(()=>u&&m?{id:m.id,path:u}:null,[m,u]),[b,f]=Oe.useState("issues"),[y,x]=Oe.useState(""),[g,w]=Oe.useState([]),[v,S]=Oe.useState([]),[A,j]=Oe.useState(!1),[C,I]=Oe.useState(!1),[R,k]=Oe.useState(null),[P,N]=Oe.useState(null),[D,T]=Oe.useState(null),[M,$]=Oe.useState(!1),[F,V]=Oe.useState(new Map),[O,L]=Oe.useState(1),[W,B]=Oe.useState(!1),ne=Oe.useCallback(async()=>{if(!(!u||!i)&&!(c&&o?.connected===!1)){j(!0),k(null),L(1),B(!1);try{if(b==="issues"&&i.issuesList){const _=await i.issuesList(u,{page:1});_.connected===!1?(k(r("session.githubIntegration.error.notConnected")),w([])):(w(_.issues??[]),L(_.page??1),B(!!_.hasMore))}else if(b==="prs"&&i.prsList){const _=await i.prsList(u,{page:1});_.connected===!1?(k(r("session.githubIntegration.error.notConnected")),S([])):(S(_.prs??[]),L(_.page??1),B(!!_.hasMore))}}catch(_){k(_ instanceof Error?_.message:r("session.githubIntegration.error.loadDataFailed"))}finally{j(!1)}}},[u,i,c,o,b,r]),le=Oe.useCallback(async()=>{if(!(!u||!i)&&!(A||C)&&W){I(!0);try{const _=O+1;if(b==="issues"&&i.issuesList){const ue=await i.issuesList(u,{page:_});ue.connected!==!1&&(w(Q=>[...Q,...ue.issues??[]]),L(ue.page??_),B(!!ue.hasMore))}else if(b==="prs"&&i.prsList){const ue=await i.prsList(u,{page:_});ue.connected!==!1&&(S(Q=>[...Q,...ue.prs??[]]),L(ue.page??_),B(!!ue.hasMore))}}catch{}finally{I(!1)}}},[u,i,b,O,W,A,C]);Oe.useEffect(()=>{if(!t){f("issues"),x(""),w([]),S([]),N(null),T(null),$(!1),k(null),V(new Map),L(1),B(!1);return}ne()},[t,ne]);const ee=Oe.useCallback(async _=>{if(!(!h||!_)&&!F.has(_))try{const Q=(await kg(h,{mode:"new",branchName:_,worktreeName:_})).errors.some(oe=>oe.code==="branch_in_use"||oe.code==="branch_exists");V(oe=>new Map(oe).set(_,{isValid:!Q,error:Q?r("session.githubIntegration.validation.branchAlreadyCheckedOut"):null}))}catch{V(ue=>new Map(ue).set(_,{isValid:!1,error:r("session.githubIntegration.validation.failed")}))}},[h,F,r]);Oe.useEffect(()=>{!t||b!=="prs"||v.forEach(_=>{_.head&&ee(_.head)})},[t,b,v,ee]);const ae=Oe.useMemo(()=>{const _=y.trim().toLowerCase();return _?g.filter(ue=>String(ue.number)===_.replace(/^#/,"")?!0:ue.title.toLowerCase().includes(_)):g},[g,y]),ge=Oe.useMemo(()=>{const _=y.trim().toLowerCase();return _?v.filter(ue=>String(ue.number)===_.replace(/^#/,"")?!0:ue.title.toLowerCase().includes(_)):v},[v,y]),te=c&&o?.connected===!0,E=()=>{p("github"),d(!0)},z=_=>{N(_),T(null)},J=_=>{T(_),N(null)},H=()=>{P?n({type:"issue",item:P}):D&&n({type:"pr",item:D,includeDiff:M}),e(!1)},re=()=>{N(null),T(null),$(!1)},ce=P||D&&F.get(D.head??"")?.isValid!==!1,Ne=_=>_.head?F.get(_.head)?.isValid===!1:!0,me=s.jsx(s.Fragment,{children:te?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"relative mt-2",children:[s.jsx(Hn,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),s.jsx(Vt,{value:y,onChange:_=>x(_.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:[A&&s.jsx("div",{className:"flex items-center justify-center h-full",children:s.jsx(Zt,{className:"h-5 w-5 animate-spin text-muted-foreground"})}),R&&s.jsx("div",{className:"flex items-center justify-center h-full",children:s.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-md bg-destructive/10 text-destructive",children:[s.jsx(Hr,{className:"h-4 w-4"}),s.jsx("span",{className:"typography-small",children:R})]})}),!A&&!R&&b==="issues"&&s.jsxs("div",{className:"space-y-0.5 min-h-full",children:[ae.length>0?ae.map(_=>s.jsx("button",{onClick:()=>z(_),className:pe("w-full text-left px-2 py-1.5 rounded transition-colors",P?.number===_.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:["#",_.number]}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("span",{className:"typography-small line-clamp-2",children:_.title}),_.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:[_.sourceRepo.owner,"/",_.sourceRepo.repo]}):null]})]})},`${_.sourceRepo?.owner??""}-${_.sourceRepo?.repo??""}-${_.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")}),W&&!C&&s.jsx("div",{className:"flex justify-center pt-2",children:s.jsx(je,{variant:"ghost",size:"sm",onClick:()=>{le()},className:"h-7 text-xs",children:r("session.githubIntegration.actions.loadMore")})}),C&&s.jsx("div",{className:"flex items-center justify-center py-2",children:s.jsx(Zt,{className:"h-4 w-4 animate-spin text-muted-foreground"})})]}),!A&&!R&&b==="prs"&&s.jsxs("div",{className:"space-y-0.5 min-h-full",children:[ge.length>0?ge.map(_=>{const ue=Ne(_),Q=_.head?F.get(_.head):void 0;return s.jsx("button",{onClick:()=>!ue&&J(_),disabled:ue,className:pe("w-full text-left px-2 py-1.5 rounded transition-colors",D?.number===_.number?"bg-interactive-selection text-interactive-selection-foreground":ue?"opacity-50 cursor-not-allowed":"hover:bg-interactive-hover"),children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs("span",{className:"text-muted-foreground shrink-0 typography-micro",children:["#",_.number]}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("span",{className:"typography-small line-clamp-1",children:_.title}),s.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[s.jsxs("span",{className:"typography-micro text-muted-foreground",children:[_.head," → ",_.base]}),_.sourceRepo?.source==="upstream"?s.jsxs("span",{className:"typography-micro px-1 py-0.5 rounded bg-status-info/10 text-status-info",children:[_.sourceRepo.owner,"/",_.sourceRepo.repo]}):null,ue&&Q?.error&&s.jsx("span",{className:"typography-micro text-destructive",children:Q.error})]})]})]})},`${_.sourceRepo?.owner??""}-${_.sourceRepo?.repo??""}-${_.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")}),W&&!C&&s.jsx("div",{className:"flex justify-center pt-2",children:s.jsx(je,{variant:"ghost",size:"sm",onClick:()=>{le()},className:"h-7 text-xs",children:r("session.githubIntegration.actions.loadMore")})}),C&&s.jsx("div",{className:"flex items-center justify-center py-2",children:s.jsx(Zt,{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(Ai,{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(je,{onClick:E,size:"sm",children:r("session.githubIntegration.connect.action")})]})}),we=s.jsxs("div",{className:pe("w-full",a?"flex flex-col gap-2":"flex flex-row items-center"),children:[s.jsxs("div",{className:pe("flex items-center gap-4",a?"w-full justify-center order-1":"flex-1"),children:[!a&&(P||D)&&s.jsxs("div",{className:"flex items-center gap-2 px-2 h-8 rounded-md bg-muted/50 border border-border/50",children:[s.jsx(Ys,{className:"h-3.5 w-3.5 text-status-success shrink-0"}),s.jsx("span",{className:"typography-small truncate max-w-[150px]",children:P?r("session.githubIntegration.selected.issueNumber",{number:P.number}):r("session.githubIntegration.selected.prNumber",{number:D?.number??""})}),s.jsx("button",{onClick:re,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:s.jsx(Ds,{className:"h-3.5 w-3.5"})})]}),b==="prs"&&D&&s.jsxs("label",{className:"flex items-center gap-2 cursor-pointer h-8",children:[s.jsx(bs,{checked:M,onChange:_=>$(_),ariaLabel:r("session.githubIntegration.includeDiffAria")}),s.jsx("span",{className:"typography-small text-foreground",children:r("session.githubIntegration.includeDiff")})]})]}),s.jsxs("div",{className:pe("flex gap-2",a?"w-full order-2":"justify-end"),children:[s.jsx(je,{variant:"outline",size:"sm",onClick:()=>e(!1),className:pe(a&&"flex-1"),children:r("session.githubIntegration.actions.cancel")}),s.jsx(je,{size:"sm",onClick:H,disabled:!ce,className:pe(a&&"flex-1"),children:r("session.githubIntegration.actions.select")})]})]});return s.jsx(s.Fragment,{children:a?s.jsx(Ar,{open:t,title:r("session.githubIntegration.title"),onClose:()=>e(!1),footer:te?we:void 0,renderHeader:_=>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")}),_]}),s.jsx("div",{className:"w-full",children:s.jsx(Br,{items:[{id:"issues",label:r("session.githubIntegration.tabs.issues"),icon:s.jsx(Ks,{className:"h-3.5 w-3.5"})},{id:"prs",label:r("session.githubIntegration.tabs.pullRequests"),icon:s.jsx(Wa,{className:"h-3.5 w-3.5"})}],activeId:b,onSelect:ue=>{f(ue),x("")},variant:"active-pill",layoutMode:"fit"})}),(P||D)&&s.jsxs("div",{className:"flex items-center gap-2 px-2 py-1 rounded-md bg-muted/50 border border-border/50",children:[s.jsx(Ys,{className:"h-3.5 w-3.5 text-status-success shrink-0"}),s.jsx("span",{className:"typography-small truncate flex-1",children:P?r("session.githubIntegration.selected.issueNumber",{number:P.number}):r("session.githubIntegration.selected.prNumber",{number:D?.number??""})}),s.jsx("button",{onClick:re,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:s.jsx(Ds,{className:"h-3.5 w-3.5"})})]})]}),children:me}):s.jsx(ws,{open:t,onOpenChange:e,children:s.jsxs(vs,{className:"max-w-2xl max-h-[70vh] flex flex-col",children:[s.jsx(Is,{className:"flex flex-row items-center justify-between",children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsxs(Ss,{className:"flex items-center gap-2 shrink-0",children:[s.jsx(Ai,{className:"h-5 w-5"}),r("session.githubIntegration.title")]}),s.jsx("div",{className:"w-[220px]",children:s.jsx(Br,{items:[{id:"issues",label:r("session.githubIntegration.tabs.issues"),icon:s.jsx(Ks,{className:"h-3.5 w-3.5"})},{id:"prs",label:r("session.githubIntegration.tabs.pullRequests"),icon:s.jsx(Wa,{className:"h-3.5 w-3.5"})}],activeId:b,onSelect:_=>{f(_),x("")},variant:"active-pill",layoutMode:"fit"})})]})}),me,s.jsx(Qs,{className:"mt-1",children:we})]})})})}const bo=t=>t.trim().replace(/^refs\/heads\//,"").replace(/^heads\//,"").replace(/\s+/g,"-").replace(/^\/+|\/+$/g,""),Wn=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),Qf="oc:lastWorktreeSourceBranch",AA=t=>String(t).trim().toLowerCase().replace(/[^a-z0-9._-]+/g,"-").replace(/-+/g,"-").replace(/^-+|-+$/g,"")||"pr-head",PA=(t,e)=>{const n=bo(t.head||"");if(!n)throw new Error("PR head branch is missing");const r=e.find(d=>{const p=d.indexOf("/");return p<=0||p>=d.length-1?!1:d.slice(p+1)===n});if(r){const d=r.indexOf("/"),p=r.slice(0,d);return{existingBranch:`remotes/${r}`,setUpstream:!0,upstreamRemote:p,upstreamBranch:n,ensureRemoteName:void 0,ensureRemoteUrl:void 0,sourceLabel:`${p}/${n}`}}const a=String(t.headLabel||"").split(":")[0]?.trim(),i=t.headRepo?.owner||a||"pr-head",o=`pr-${AA(i)}`,c=t.headRepo?.sshUrl||t.headRepo?.cloneUrl||"";if(!c)throw new Error("PR head repository URL is unavailable");return{existingBranch:`remotes/${o}/${n}`,setUpstream:!0,upstreamRemote:o,upstreamBranch:n,ensureRemoteName:o,ensureRemoteUrl:c,sourceLabel:`${o}/${n}`}},DA=t=>{const e={repo:t.repo??null,issue:t.issue,comments:t.comments};return`GitHub issue context (JSON)
87
- ${JSON.stringify(e,null,2)}`},TA=t=>`GitHub pull request context (JSON)
88
- ${JSON.stringify(t,null,2)}`;function MA({open:t,onOpenChange:e,onWorktreeCreated:n}){const{t:r}=ut(),{github:a,git:i}=Gn(),o=Te(ie=>ie.isMobile),c=Zn(ie=>ie.status),d=Zn(ie=>ie.hasChecked),p=Fs(ie=>ie.getActiveProject()),m=p?.path??null,u=Oe.useMemo(()=>m&&p?{id:p.id,path:m}:null,[p,m]),[h,b]=Oe.useState("new-branch"),[f,y]=Oe.useState({branchName:"",worktreeName:"",isSyncingWorktreeName:!0,sourceBranch:"",linkedIssue:null,linkedPr:null,includePrDiff:!1}),[x,g]=Oe.useState({selectedBranch:"",worktreeName:""}),w=Fu(m),v=Cg(m),S=pn(ie=>ie.fetchBranches),A=Oe.useMemo(()=>w?.all?w.all.filter(ie=>!ie.startsWith("remotes/")).sort():[],[w]),j=Oe.useMemo(()=>w?.all?w.all.filter(ie=>ie.startsWith("remotes/")).map(ie=>ie.replace(/^remotes\//,"")).sort():[],[w]),C=Wt(ie=>ie.availableWorktreesByProject),I=Oe.useMemo(()=>{if(!m)return new Set;const ie=C.get(m)??[];return new Set(ie.map(K=>K.name))},[C,m]),R=Oe.useCallback((ie=10)=>{for(let K=0;K<ie;K++){const _e=Wc();if(!I.has(_e))return _e}return`${Wc()}-${Date.now().toString(36).slice(-4)}`},[I]),[k,P]=Oe.useState(!1),[N,D]=Oe.useState(!1),[T,M]=Oe.useState(!1),[$,F]=Oe.useState(!1),[V,O]=Oe.useState(!1),[L,W]=Oe.useState(""),[B,ne]=Oe.useState(""),le=Oe.useRef(null),ee=Oe.useRef(null),ae=Oe.useRef(null),ge=Oe.useRef(null),te=Oe.useCallback(ie=>{let K=ie;for(;K&&K!==document.body;){const{overflowY:_e}=window.getComputedStyle(K);if((_e==="auto"||_e==="scroll")&&K.scrollHeight>K.clientHeight)return K;K=K.parentElement}return null},[]),E=Oe.useCallback(ie=>{ie&&(ie.scrollTop=0)},[]),z=Oe.useCallback(ie=>{const K=ie.current?.querySelector('[data-slot="command-list"]')??null;E(K)},[E]),J=Oe.useCallback(ie=>{const K=te(ie.current);E(K)},[te,E]),H=Oe.useMemo(()=>qf({localBranches:A,remoteBranches:j,query:L}),[A,j,L]),re=Oe.useMemo(()=>qf({localBranches:A,remoteBranches:j,query:B}),[A,j,B]),ce=L.trim().length>0,Ne=B.trim().length>0,me=H.matching.length>0,we=re.matching.length>0,_=!!(m&&i),ue=Oe.useCallback(()=>{!m||!i||S(m,i)},[m,i,S]);Oe.useEffect(()=>{!N&&!$&&W("")},[N,$]),Oe.useEffect(()=>{!T&&!V&&ne("")},[T,V]),Oe.useEffect(()=>{N&&z(le),$&&J(ae)},[N,$,L,z,J]),Oe.useEffect(()=>{T&&z(ee),V&&J(ge)},[T,V,B,z,J]);const[Q,oe]=Oe.useState({isValidating:!1,branchError:null,worktreeError:null,touched:!1}),[Z,Ie]=Oe.useState(!1),[Se,Y]=Oe.useState(null),fe=Oe.useCallback(()=>{const ie=yt.getState(),K=ie.getVisibleAgents();if(ie.settingsDefaultAgent){const _e=K.find(He=>He.name===ie.settingsDefaultAgent);if(_e)return _e.name}return K.find(_e=>_e.name==="build")?.name||K[0]?.name},[]),ke=Oe.useCallback(()=>{const ie=yt.getState(),K=ie.settingsDefaultModel;if(!K)return null;const _e=Gi(K);if(!_e)return null;const{providerId:He,modelId:Ke}=_e;return ie.getModelMetadata(He,Ke)?{providerID:He,modelID:Ke}:null},[]),xe=Oe.useCallback((ie,K)=>{const _e=yt.getState(),He=_e.settingsDefaultVariant;if(!He)return;const Xe=_e.providers.find(mt=>mt.id===ie)?.models.find(mt=>mt.id===K)?.variants;if(Xe&&Object.prototype.hasOwnProperty.call(Xe,He))return He},[]),he=Oe.useCallback(ie=>{const K=yt.getState();try{sl.getState().saveSessionModelSelection(ie.sessionId,ie.providerID,ie.modelID)}catch{}if(ie.agentName){try{K.setAgent(ie.agentName)}catch{}try{sl.getState().saveSessionAgentSelection(ie.sessionId,ie.agentName)}catch{}try{sl.getState().saveAgentModelForSession(ie.sessionId,ie.agentName,ie.providerID,ie.modelID)}catch{}if(ie.variant!==void 0){try{K.setCurrentVariant(ie.variant)}catch{}try{sl.getState().saveAgentModelVariantForSession(ie.sessionId,ie.agentName,ie.providerID,ie.modelID,ie.variant)}catch{}}}},[]),Pe=Oe.useCallback(async ie=>{if(!m||!a)return;const K=yt.getState(),_e=hc.getState().lastUsedProvider,He=ke(),Ke=He?.providerID||K.currentProviderId||_e?.providerID,Ze=He?.modelID||K.currentModelId||_e?.modelID,Xe=fe()||K.currentAgentName||void 0;if(!Ke||!Ze){q.error(r("session.newWorktree.error.noModelSelected"));return}const mt=xe(Ke,Ze);if(he({sessionId:ie.sessionId,providerID:Ke,modelID:Ze,agentName:Xe,variant:mt}),ie.issue){if(!a.issueGet||!a.issueComments)return;const et=await a.issueGet(m,ie.issue.number);if(et.connected===!1||!et.repo||!et.issue)throw new Error("Failed to load issue context");const ct=await a.issueComments(m,ie.issue.number);if(ct.connected===!1)throw new Error("Failed to load issue comments");const lt=await Vn("github.issue.review.visible",{issue_number:String(ie.issue.number)}),ye=await Vn("github.issue.review.instructions"),Ge=DA({repo:et.repo,issue:et.issue,comments:ct.comments??[]});await Dn.sendMessage({id:ie.sessionId,providerID:Ke,modelID:Ze,agent:Xe,variant:mt,text:lt,additionalParts:[{text:ye,synthetic:!0},{text:Ge,synthetic:!0}]}),q.success(r("session.newWorktree.toast.sessionFromIssue"));return}if(ie.pr){if(!a.prContext)return;const et=await a.prContext(m,ie.pr.number,{includeDiff:ie.includeDiff,includeCheckDetails:!1});if(et.connected===!1||!et.repo||!et.pr)throw new Error("Failed to load PR context");const ct=await Vn("github.pr.review.visible",{pr_number:String(ie.pr.number)}),lt=await Vn("github.pr.review.instructions"),ye=TA(et);await Dn.sendMessage({id:ie.sessionId,providerID:Ke,modelID:Ze,agent:Xe,variant:mt,text:ct,additionalParts:[{text:lt,synthetic:!0},{text:ye,synthetic:!0}]}),q.success(r("session.newWorktree.toast.sessionFromPr"))}},[he,a,m,fe,ke,xe,r]),Be=h==="new-branch"?f:x;Oe.useEffect(()=>{if(!w?.all||!m||f.sourceBranch)return;(async()=>{try{const K=await zo(m).catch(()=>null),_e=localStorage.getItem(Qf),He=_e&&w.all?.includes(_e)?_e:K&&w.all?.includes(K)?K:w.all?.includes("main")?"main":w.all?.includes("master")?"master":w.all?.[0]||"";He&&y(Ke=>({...Ke,sourceBranch:He}))}catch{}})()},[w,m,f.sourceBranch]),Oe.useEffect(()=>{if(!t)return;b("new-branch"),g({selectedBranch:"",worktreeName:""}),D(!1),M(!1),F(!1),O(!1),W(""),ne(""),oe({isValidating:!1,branchError:null,worktreeError:null,touched:!1});const ie=R();y({branchName:ie,worktreeName:ie,isSyncingWorktreeName:!0,sourceBranch:"",linkedIssue:null,linkedPr:null,includePrDiff:!1})},[t,R]),Oe.useEffect(()=>{if(h!=="new-branch"||!f.isSyncingWorktreeName)return;const ie=bo(f.branchName),K=Wn(ie);y(_e=>({..._e,worktreeName:K}))},[h,f.branchName,f.isSyncingWorktreeName]);const G=Oe.useCallback(async()=>{if(!u||!Q.touched||Z)return;Se&&Se.abort();const ie=new AbortController;Y(ie),oe(K=>({...K,isValidating:!0}));try{const K=h==="new-branch"?f.branchName:x.selectedBranch,_e=Be.worktreeName,He=bo(K),Ke=Wn(_e);let Ze=null,Xe=null;if(He||(Ze=r("session.newWorktree.error.branchNameRequired")),Ke||(Xe=r("session.newWorktree.error.worktreeDirectoryRequired")),He&&Ke){const mt=await kg(u,{mode:h==="existing-branch"?"existing":"new",branchName:He,worktreeName:Ke,existingBranch:h==="existing-branch"?He:void 0});if(ie.signal.aborted)return;mt.ok||mt.errors.forEach(et=>{if(et.code==="worktree_exists"){Xe=Xe??et.message;return}et.code.startsWith("branch_")&&(Ze=Ze??et.message)})}ie.signal.aborted||oe(mt=>({...mt,isValidating:!1,branchError:Ze,worktreeError:Xe}))}catch{ie.signal.aborted||oe(K=>({...K,isValidating:!1}))}},[u,h,f.branchName,x.selectedBranch,Be.worktreeName,Q.touched,Se,Z,r]),be=h==="new-branch"?f.branchName:x.selectedBranch;Oe.useEffect(()=>{if(!t||!u||!Q.touched||Z)return;const ie=setTimeout(()=>{G()},300);return()=>clearTimeout(ie)},[Be.worktreeName,be,t,u,G,Q.touched,Z]);const De=async()=>{if(!u||!m){q.error(r("session.newWorktree.error.noActiveProject"));return}oe(Ke=>({...Ke,touched:!0}));const ie=h==="new-branch"?f.branchName:x.selectedBranch,K=Be.worktreeName,_e=bo(ie),He=Wn(K);if(!_e){q.error(r("session.newWorktree.error.branchNameRequired"));return}if(!He){q.error(r("session.newWorktree.error.worktreeDirectoryRequired"));return}Se&&(Se.abort(),Y(null)),oe(Ke=>({...Ke,isValidating:!1,branchError:null,worktreeError:null})),Ie(!0);try{const Ke=await Vu(u),Ze=h==="new-branch"?f.linkedPr:null,Xe=f.sourceBranch;let mt="";const et=(()=>{if(Ze){const tt=PA(Ze,j);return mt=tt.sourceLabel,{preferredName:_e||He,mode:"existing",branchName:_e,worktreeName:He,existingBranch:tt.existingBranch,setupCommands:Ke,setUpstream:tt.setUpstream,upstreamRemote:tt.upstreamRemote,upstreamBranch:tt.upstreamBranch,...tt.ensureRemoteName?{ensureRemoteName:tt.ensureRemoteName}:{},...tt.ensureRemoteUrl?{ensureRemoteUrl:tt.ensureRemoteUrl}:{}}}return mt=h==="new-branch"?Xe:"",{preferredName:_e||He,mode:h==="existing-branch"?"existing":"new",branchName:h==="existing-branch"?void 0:_e,worktreeName:He,existingBranch:h==="existing-branch"?_e:void 0,setupCommands:Ke,...Xe&&h==="new-branch"?{startRef:Xe}:{}}})(),ct=await U1(m,et),lt=await W1(u,ct),ye=h==="new-branch"?f.linkedIssue:null,Ge=h==="new-branch"?f.linkedPr:null,$e=h==="new-branch"?f.includePrDiff:!1;let Ve=null;if(ye||Ge){const tt=ye?`#${ye.number} ${ye.title}`.trim():Ge?`#${Ge.number} ${Ge.title}`.trim():r("session.newWorktree.newSessionTitle"),Qe=await K1(tt,lt.path,null);if(!Qe?.id)throw new Error("Failed to create session");Ve=Qe.id,H1(Qe.id,tt).catch(()=>{});try{Wt.getState().initializeNewOpenChamberSession(Qe.id,yt.getState().agents)}catch{}}f.sourceBranch&&h==="new-branch"&&!f.linkedPr&&localStorage.setItem(Qf,f.sourceBranch),q.success(r("session.newWorktree.toast.worktreeCreated"),{description:r("session.newWorktree.toast.worktreeCreatedDescription",{target:`${lt.branch||lt.name}${mt?` ${r("session.newWorktree.fromSource",{source:mt})}`:""}`})}),e(!1),Ve?(n?.(lt.path,{sessionId:Ve}),Pe({sessionId:Ve,issue:ye,pr:Ge,includeDiff:$e}).catch(tt=>{const Qe=tt instanceof Error?tt.message:r("session.newWorktree.error.sendGitHubContextFailed");q.error(r("session.newWorktree.error.sendGitHubContextFailed"),{description:Qe})})):n?.(lt.path)}catch(Ke){const Ze=Ke instanceof Error?Ke.message:r("session.newWorktree.error.createWorktreeFailed");q.error(r("session.newWorktree.error.createWorktreeFailed"),{description:Ze})}finally{Ie(!1)}},Ae=ie=>{b(ie),oe(K=>({...K,touched:!1,branchError:null,worktreeError:null}))},ve=ie=>{if(!ie){y(K=>({...K,linkedIssue:null,linkedPr:null,includePrDiff:!1,branchName:""}));return}if(ie.type==="issue"){const K=ie.item,_e=`issue-${K.number}-${Wc()}`;y(He=>({...He,linkedIssue:K,linkedPr:null,includePrDiff:!1,branchName:_e,worktreeName:Wn(_e),isSyncingWorktreeName:!0}))}else if(ie.type==="pr"){const K=ie.item;y(_e=>({..._e,linkedPr:K,linkedIssue:null,includePrDiff:ie.includeDiff??!1,branchName:K.head,worktreeName:Wn(K.head),isSyncingWorktreeName:!0}))}},U=d&&c?.connected===!0,Re=(h==="existing-branch"?!!x.selectedBranch&&!!x.worktreeName&&!Q.branchError&&!Q.worktreeError:!!bo(f.branchName)&&!!f.worktreeName&&!Q.branchError&&!Q.worktreeError)&&!Z,Le=()=>{y(ie=>({...ie,linkedIssue:null,linkedPr:null,branchName:"",includePrDiff:!1,isSyncingWorktreeName:!0}))},se=s.jsxs("div",{className:pe("flex gap-2",o?"flex-col w-full":"flex-row items-center"),children:[s.jsx("div",{className:pe("flex items-center gap-1.5 text-destructive",o?"w-full justify-center order-first":"mr-auto"),children:Q.touched&&(Q.branchError||Q.worktreeError)&&s.jsxs(s.Fragment,{children:[s.jsx(Hr,{className:"h-3.5 w-3.5"}),s.jsx("span",{className:"typography-micro",children:Q.branchError||Q.worktreeError})]})}),s.jsxs("div",{className:pe("flex gap-2",o&&"w-full"),children:[s.jsx(je,{variant:"outline",size:"sm",onClick:()=>e(!1),disabled:Z,className:pe(o&&"flex-1"),children:r("session.newWorktree.actions.cancel")}),s.jsxs(je,{size:"sm",onClick:De,disabled:!Re||Z,className:pe("gap-1.5",o&&"flex-1"),children:[Z&&s.jsx(Zt,{className:"h-3.5 w-3.5 animate-spin"}),r(Z?"session.newWorktree.actions.creating":"session.newWorktree.actions.createWorktree")]})]})]});return s.jsxs(s.Fragment,{children:[o?s.jsxs(Ar,{open:t,title:r("session.newWorktree.title"),onClose:()=>e(!1),footer:se,children:[s.jsx("div",{className:"w-full mb-4",children:s.jsx(Br,{items:[{id:"new-branch",label:r("session.newWorktree.mode.newBranch"),icon:s.jsx(Ks,{className:"h-3.5 w-3.5"})},{id:"existing-branch",label:r("session.newWorktree.mode.existingBranch"),icon:s.jsx(Rd,{className:"h-3.5 w-3.5"})}],activeId:h,onSelect:ie=>Ae(ie),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(je,{variant:"outline",size:"sm",onClick:()=>F(!0),className:"flex-1 justify-between h-9",children:[s.jsx("span",{className:x.selectedBranch?"text-foreground":"text-muted-foreground",children:x.selectedBranch||r("session.newWorktree.chooseBranch")}),s.jsx(Ks,{className:"h-4 w-4 text-muted-foreground"})]}),s.jsx(je,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0 shrink-0",onClick:ue,disabled:!_||v,title:r("session.newWorktree.fetchBranches"),children:v?s.jsx(Zt,{className:"size-4 animate-spin"}):s.jsx(Nn,{className:"size-4"})})]}),s.jsx(Ar,{open:$,title:r("session.newWorktree.selectBranch"),onClose:()=>F(!1),children:s.jsxs("div",{className:"space-y-4",ref:ae,children:[s.jsx(Vt,{value:L,onChange:ie=>W(ie.target.value),placeholder:r("session.newWorktree.searchBranches"),className:"h-8"}),v?s.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:r("session.newWorktree.loadingBranches")}):A.length===0&&j.length===0?s.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noBranchesFound")}):s.jsxs("div",{className:"space-y-4",children:[ce&&me&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:r("session.newWorktree.matchingBranches")}),s.jsx("div",{className:"space-y-1",children:H.matching.map(ie=>s.jsx("button",{onClick:()=>{g(K=>({...K,selectedBranch:ie.value,worktreeName:Wn(ie.label)})),oe(K=>({...K,touched:!0})),F(!1)},className:pe("w-full text-left px-3 py-2.5 rounded-md transition-colors",x.selectedBranch===ie.value?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:ie.label})},`${ie.source}-${ie.value}`))})]}),ce&&!me&&s.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),H.otherLocal.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:r(ce?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches")}),s.jsx("div",{className:"space-y-1",children:H.otherLocal.map(ie=>s.jsx("button",{onClick:()=>{g(K=>({...K,selectedBranch:ie,worktreeName:Wn(ie)})),oe(K=>({...K,touched:!0})),F(!1)},className:pe("w-full text-left px-3 py-2.5 rounded-md transition-colors",x.selectedBranch===ie?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:ie})},ie))})]}),H.otherRemote.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:r(ce?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches")}),s.jsx("div",{className:"space-y-1",children:H.otherRemote.map(ie=>s.jsx("button",{onClick:()=>{g(K=>({...K,selectedBranch:`remotes/${ie}`,worktreeName:Wn(ie)})),oe(K=>({...K,touched:!0})),F(!1)},className:pe("w-full text-left px-3 py-2.5 rounded-md transition-colors",x.selectedBranch===`remotes/${ie}`?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:ie})},`remotes/${ie}`))})]})]})]})})]}):s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("div",{className:"flex flex-col items-start gap-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground block font-semibold",children:r("session.newWorktree.branchName")}),h==="new-branch"&&U&&s.jsxs(je,{variant:"outline",size:"sm",onClick:()=>P(!0),className:"gap-1.5 h-7",children:[s.jsx(Ai,{className:"size-4 text-status-success"}),f.linkedIssue||f.linkedPr?r("session.newWorktree.actions.change"):r("session.newWorktree.actions.startFromGitHubIssuePr")]})]}),s.jsx(Vt,{value:f.branchName,onChange:ie=>{y(K=>({...K,branchName:ie.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>oe(ie=>({...ie,touched:!0})),placeholder:r("session.newWorktree.branchNamePlaceholder"),disabled:!!f.linkedPr,className:pe("h-8",Q.touched&&Q.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(Ys,{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(Ys,{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 ie=Wn(h==="new-branch"?f.branchName:"");y(K=>({...K,worktreeName:ie,isSyncingWorktreeName:!0}))},disabled:!f.branchName||f.worktreeName===Wn(f.branchName),className:pe("flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded",f.worktreeName===Wn(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(Nn,{className:"h-3 w-3"}),s.jsx("span",{children:r("session.newWorktree.actions.reset")})]})]}),s.jsx(Vt,{value:Be.worktreeName,onChange:ie=>{h==="new-branch"?y(K=>({...K,worktreeName:ie.target.value,isSyncingWorktreeName:!1})):g(K=>({...K,worktreeName:ie.target.value}))},onBlur:()=>oe(ie=>({...ie,touched:!0})),placeholder:r("session.newWorktree.worktreeDirectoryPlaceholder"),className:pe("h-8",Q.touched&&Q.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(je,{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(Ks,{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(Ar,{open:V,title:r("session.newWorktree.selectSourceBranch"),onClose:()=>O(!1),children:s.jsxs("div",{className:"space-y-4",ref:ge,children:[s.jsx(Vt,{value:B,onChange:ie=>ne(ie.target.value),placeholder:r("session.newWorktree.searchBranches"),className:"h-8"}),v?s.jsx("div",{className:"px-2 py-8 text-center typography-small text-muted-foreground",children:r("session.newWorktree.loadingBranches")}):A.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:[Ne&&we&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-small font-semibold text-foreground px-2",children:r("session.newWorktree.matchingBranches")}),s.jsx("div",{className:"space-y-1",children:re.matching.map(ie=>s.jsx("button",{onClick:()=>{y(K=>({...K,sourceBranch:ie.value})),O(!1)},className:pe("w-full text-left px-3 py-2.5 rounded-md transition-colors",f.sourceBranch===ie.value?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:ie.label})},`${ie.source}-${ie.value}`))})]}),Ne&&!we&&s.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),re.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(Ne?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches")}),s.jsx("div",{className:"space-y-1",children:re.otherLocal.map(ie=>s.jsx("button",{onClick:()=>{y(K=>({...K,sourceBranch:ie})),O(!1)},className:pe("w-full text-left px-3 py-2.5 rounded-md transition-colors",f.sourceBranch===ie?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:ie})},ie))})]}),re.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(Ne?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches")}),s.jsx("div",{className:"space-y-1",children:re.otherRemote.map(ie=>s.jsx("button",{onClick:()=>{y(K=>({...K,sourceBranch:`remotes/${ie}`})),O(!1)},className:pe("w-full text-left px-3 py-2.5 rounded-md transition-colors",f.sourceBranch===`remotes/${ie}`?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-small break-all",children:ie})},`remotes/${ie}`))})]})]})]})})]}),(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(Ai,{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:ie=>ie.stopPropagation(),children:s.jsx(Ir,{className:"h-3 w-3"})}),s.jsx("button",{onClick:Le,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:s.jsx(Ds,{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(Is,{className:"flex flex-row items-center justify-between",children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsxs(Ss,{className:"flex items-center gap-2 shrink-0",children:[s.jsx(Ks,{className:"h-5 w-5"}),r("session.newWorktree.title")]}),s.jsx("div",{className:"w-[280px] shrink-0",children:s.jsx(Br,{items:[{id:"new-branch",label:r("session.newWorktree.mode.newBranch"),icon:s.jsx(Ks,{className:"h-3.5 w-3.5"})},{id:"existing-branch",label:r("session.newWorktree.mode.existingBranch"),icon:s.jsx(Rd,{className:"h-3.5 w-3.5"})}],activeId:h,onSelect:ie=>Ae(ie),variant:"active-pill",layoutMode:"fit",className:"w-full"})})]})}),s.jsxs("div",{className:"flex-1 overflow-y-auto mt-2 space-y-6",children:[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(zs,{open:N,onOpenChange:D,children:[s.jsx(Bs,{asChild:!0,children:s.jsxs(je,{variant:"outline",size:"sm",className:"h-9 min-w-[220px] max-w-full justify-between gap-2",children:[s.jsx("span",{className:pe("truncate",x.selectedBranch?"text-foreground":"text-muted-foreground"),children:x.selectedBranch||r("session.newWorktree.chooseBranch")}),s.jsx(Cs,{className:"h-4 w-4 shrink-0 text-muted-foreground"})]})}),s.jsx(Vs,{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:le,children:s.jsxs(oi,{shouldFilter:!1,children:[s.jsx(ka,{placeholder:r("session.newWorktree.searchBranches"),value:L,onValueChange:W}),s.jsx(li,{disableHorizontal:!0,children:v?s.jsx("div",{className:"px-2 py-4 text-center typography-small text-muted-foreground",children:r("session.newWorktree.loadingBranches")}):A.length===0&&j.length===0?s.jsx(ci,{children:r("session.newWorktree.noBranchesFound")}):s.jsxs(s.Fragment,{children:[ce&&me&&s.jsx(Kn,{heading:r("session.newWorktree.matchingBranches"),children:H.matching.map(ie=>s.jsx(Rn,{value:ie.value,onSelect:()=>{g(K=>({...K,selectedBranch:ie.value,worktreeName:Wn(ie.label)})),oe(K=>({...K,touched:!0})),D(!1)},children:s.jsx("span",{className:"typography-small break-all",children:ie.label})},`${ie.source}-${ie.value}`))}),ce&&!me&&s.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),H.otherLocal.length>0&&s.jsxs(s.Fragment,{children:[ce&&s.jsx(Ka,{}),s.jsx(Kn,{heading:r(ce?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches"),children:H.otherLocal.map(ie=>s.jsx(Rn,{value:ie,onSelect:()=>{g(K=>({...K,selectedBranch:ie,worktreeName:Wn(ie)})),oe(K=>({...K,touched:!0})),D(!1)},children:s.jsx("span",{className:"typography-small break-all",children:ie})},`local-${ie}`))})]}),H.otherRemote.length>0&&s.jsxs(s.Fragment,{children:[(H.otherLocal.length>0||ce)&&s.jsx(Ka,{}),s.jsx(Kn,{heading:r(ce?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches"),children:H.otherRemote.map(ie=>s.jsx(Rn,{value:`remotes/${ie}`,onSelect:()=>{g(K=>({...K,selectedBranch:`remotes/${ie}`,worktreeName:Wn(ie)})),oe(K=>({...K,touched:!0})),D(!1)},children:s.jsx("span",{className:"typography-small break-all",children:ie})},`remote-${ie}`))})]})]})})]})})]}),s.jsx(je,{variant:"ghost",size:"sm",className:"h-8 w-8 px-0 shrink-0",onClick:ue,disabled:!_||v,title:r("session.newWorktree.fetchBranches"),children:v?s.jsx(Zt,{className:"size-4 animate-spin"}):s.jsx(Nn,{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"&&U&&s.jsxs(je,{variant:"outline",size:"sm",onClick:()=>P(!0),className:"gap-1.5 h-7",children:[s.jsx(Ai,{className:"size-4 text-status-success"}),f.linkedIssue||f.linkedPr?r("session.newWorktree.actions.change"):r("session.newWorktree.actions.startFromGitHubIssuePr")]})]}),s.jsx(Vt,{value:f.branchName,onChange:ie=>{y(K=>({...K,branchName:ie.target.value,isSyncingWorktreeName:!0,linkedIssue:null,linkedPr:null}))},onBlur:()=>oe(ie=>({...ie,touched:!0})),placeholder:r("session.newWorktree.branchNamePlaceholder"),disabled:!!f.linkedPr,className:pe("h-8",Q.touched&&Q.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(Ys,{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(Ys,{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 ie=Wn(h==="new-branch"?f.branchName:"");y(K=>({...K,worktreeName:ie,isSyncingWorktreeName:!0}))},disabled:!f.branchName||f.worktreeName===Wn(f.branchName),className:pe("flex items-center gap-1 typography-micro transition-colors px-1.5 py-0.5 rounded",f.worktreeName===Wn(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(Nn,{className:"h-3 w-3"}),s.jsx("span",{children:r("session.newWorktree.actions.reset")})]})]}),s.jsx(Vt,{value:Be.worktreeName,onChange:ie=>{h==="new-branch"?y(K=>({...K,worktreeName:ie.target.value,isSyncingWorktreeName:!1})):g(K=>({...K,worktreeName:ie.target.value}))},onBlur:()=>oe(ie=>({...ie,touched:!0})),placeholder:r("session.newWorktree.worktreeDirectoryPlaceholder"),className:pe("h-8",Q.touched&&Q.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(zs,{open:T,onOpenChange:M,children:[s.jsx(Bs,{asChild:!0,children:s.jsxs(je,{variant:"outline",size:"sm",className:"h-9 min-w-[220px] max-w-full justify-between gap-2",children:[s.jsx("span",{className:pe("truncate",f.sourceBranch?"text-foreground":"text-muted-foreground"),children:f.sourceBranch||r("session.newWorktree.selectSourceBranchPlaceholder")}),s.jsx(Cs,{className:"h-4 w-4 shrink-0 text-muted-foreground"})]})}),s.jsx(Vs,{align:"start",portalToBody:!0,className:"w-[min(42rem,calc(100vw-2rem))] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden",ref:ee,children:s.jsxs(oi,{shouldFilter:!1,children:[s.jsx(ka,{placeholder:r("session.newWorktree.searchBranches"),value:B,onValueChange:ne}),s.jsx(li,{disableHorizontal:!0,children:v?s.jsx("div",{className:"px-2 py-4 text-center typography-small text-muted-foreground",children:r("session.newWorktree.loadingBranches")}):A.length===0&&j.length===0?s.jsx(ci,{children:r("session.newWorktree.noBranchesFound")}):s.jsxs(s.Fragment,{children:[Ne&&we&&s.jsx(Kn,{heading:r("session.newWorktree.matchingBranches"),children:re.matching.map(ie=>s.jsx(Rn,{value:ie.value,onSelect:()=>{y(K=>({...K,sourceBranch:ie.value})),M(!1)},children:s.jsx("span",{className:"typography-small break-all",children:ie.label})},`${ie.source}-${ie.value}`))}),Ne&&!we&&s.jsx("div",{className:"px-2 py-1 text-center typography-small text-muted-foreground",children:r("session.newWorktree.noMatchingBranches")}),re.otherLocal.length>0&&s.jsxs(s.Fragment,{children:[Ne&&s.jsx(Ka,{}),s.jsx(Kn,{heading:r(Ne?"session.newWorktree.otherLocalBranches":"session.newWorktree.localBranches"),children:re.otherLocal.map(ie=>s.jsx(Rn,{value:ie,onSelect:()=>{y(K=>({...K,sourceBranch:ie})),M(!1)},children:s.jsx("span",{className:"typography-small break-all",children:ie})},`local-${ie}`))})]}),re.otherRemote.length>0&&s.jsxs(s.Fragment,{children:[(re.otherLocal.length>0||Ne)&&s.jsx(Ka,{}),s.jsx(Kn,{heading:r(Ne?"session.newWorktree.otherRemoteBranches":"session.newWorktree.remoteBranches"),children:re.otherRemote.map(ie=>s.jsx(Rn,{value:`remotes/${ie}`,onSelect:()=>{y(K=>({...K,sourceBranch:`remotes/${ie}`})),M(!1)},children:s.jsx("span",{className:"typography-small break-all",children:ie})},`remote-${ie}`))})]})]})})]})})]}),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(Ai,{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:ie=>ie.stopPropagation(),children:s.jsx(Ir,{className:"h-3 w-3"})}),s.jsx("button",{onClick:Le,className:"text-muted-foreground hover:text-foreground shrink-0 p-0.5 rounded hover:bg-muted transition-colors",children:s.jsx(Ds,{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(Qs,{className:"mt-1 flex items-center justify-between",children:[s.jsx("div",{className:"flex items-center gap-1.5 text-destructive",children:Q.touched&&(Q.branchError||Q.worktreeError)&&s.jsxs(s.Fragment,{children:[s.jsx(Hr,{className:"h-3.5 w-3.5"}),s.jsx("span",{className:"typography-micro",children:Q.branchError||Q.worktreeError})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(je,{variant:"outline",size:"sm",onClick:()=>e(!1),disabled:Z,children:r("session.newWorktree.actions.cancel")}),s.jsxs(je,{size:"sm",onClick:De,disabled:!Re||Z,className:"gap-1.5",children:[Z&&s.jsx(Zt,{className:"h-3.5 w-3.5 animate-spin"}),r(Z?"session.newWorktree.actions.creating":"session.newWorktree.actions.createWorktree")]})]})]})]})}),s.jsx(IA,{open:k,onOpenChange:P,onSelect:ve})]})}let Li=null,$i=null,El=null,ac=0;const Xa=new Set,RA=3e4,EA=45e3,Kx=()=>{El&&(clearTimeout(El),El=null)},Hx=()=>{if($i||Xa.size===0)return;const t=Math.min(1e3*Math.pow(2,Math.min(ac,5)),RA);$i=setTimeout(()=>{$i=null,ac+=1,Gx()},t)},ic=()=>{Kx(),Li&&Li.close(),Li=null},Jf=()=>{Kx(),Xa.size!==0&&(El=setTimeout(()=>{ic(),Hx()},EA))},FA=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}},OA=t=>{if(t.type==="openchamber:event-stream-ready"){ac=0;return}if(t.type==="openchamber:heartbeat"||t.type!=="openchamber:scheduled-task-ran")return;const e=t.properties&&typeof t.properties=="object"?t.properties:null,n=typeof e?.projectId=="string"?e.projectId:"",r=typeof e?.taskId=="string"?e.taskId:"",a=typeof e?.ranAt=="number"?e.ranAt:Date.now(),i=e?.status,o=i==="running"||i==="error"?i:"success";if(!n||!r)return;const c={type:"scheduled-task-ran",projectId:n,taskId:r,ranAt:a,status:o,...typeof e?.sessionId=="string"&&e.sessionId.length>0?{sessionId:e.sessionId}:{}};for(const d of Xa)d(c)},Gx=()=>{if(typeof window>"u"||Xa.size===0||typeof EventSource!="function"||Li&&Li.readyState!==EventSource.CLOSED)return;ic();const t=new EventSource("/api/openchamber/events");t.onopen=()=>{Jf()},t.onmessage=e=>{Jf();const n=FA(e.data);n&&OA(n)},t.onerror=()=>{ic(),Hx()},Li=t},qx=t=>(Xa.add(t),Gx(),()=>{Xa.delete(t),Xa.size===0&&($i&&(clearTimeout($i),$i=null),ac=0,ic())}),Sc=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},Yi=t=>{const e=typeof t=="string"?t.trim():"";if(!e)throw new Error("projectId is required");return e},LA=async t=>{const e=Yi(t),n=await fetch(`/api/projects/${encodeURIComponent(e)}/scheduled-tasks`);if(!n.ok)throw new Error(await Sc(n,"Failed to load scheduled tasks"));const r=await n.json().catch(()=>null);return!r||!Array.isArray(r.tasks)?[]:r.tasks},Yf=async(t,e)=>{const n=Yi(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 Sc(r,"Failed to save scheduled task"));const a=await r.json().catch(()=>null);return!a||!Array.isArray(a.tasks)?[]:a.tasks},$A=async(t,e)=>{const n=Yi(t),r=Yi(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 Sc(a,"Failed to delete scheduled task"));const i=await a.json().catch(()=>null);return!i||!Array.isArray(i.tasks)?[]:i.tasks},BA=async(t,e)=>{const n=Yi(t),r=Yi(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 Sc(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}},Qx=[0,1,2,3,4,5,6],Xf=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"],Zf=()=>{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}`},Fl=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},eh=t=>{const e=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${e}-${n}-${r}`},VA=(t,e,n)=>{const r=Fl(t);return r?new Intl.DateTimeFormat(n,{month:"short",day:"numeric",year:"numeric"}).format(r):e},th=(t,e)=>new Date(t.getFullYear(),t.getMonth()+e,1),zA=(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},_A=t=>{const e=/^([01]\d|2[0-3]):([0-5]\d)$/.exec(t);if(!e)return{hour24:"00",hour12:"12",minute:"00",meridiem:"AM"};const n=Number(e[1]),r=e[2],a=n>=12?"PM":"AM",i=n%12===0?12:n%12;return{hour24:String(n).padStart(2,"0"),hour12:String(i).padStart(2,"0"),minute:r,meridiem:a}},$a=(t,e,n)=>{const r=Number(t),a=Number(e),i=Number.isFinite(r)?Math.min(12,Math.max(1,r)):12,o=Number.isFinite(a)?Math.min(59,Math.max(0,a)):0;let c=i%12;return n==="PM"&&(c+=12),`${String(c).padStart(2,"0")}:${String(o).padStart(2,"0")}`},eo=(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"},sh=t=>/^(0[1-9]|1[0-2])$/.test(t)?t:eo(t,{min:1,max:12}),gl=t=>/^[0-5][0-9]$/.test(t)?t:eo(t,{max:59}),UA=(t,e)=>eo(String(Number.parseInt(t,10)+e),{min:1,max:12,loop:!0}),nh=(t,e)=>eo(String(Number.parseInt(t,10)+e),{min:0,max:59,loop:!0}),WA=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}},KA=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}},HA=t=>{const e=new Intl.DateTimeFormat(t,{weekday:"short"}),n=new Date(2023,0,1);return Qx.map(r=>e.format(new Date(n.getFullYear(),n.getMonth(),n.getDate()+r)))},GA=(t,e)=>[...t.slice(e),...t.slice(0,e)],kr=t=>{const e=nt.c(6),{htmlFor:n,required:r,children:a}=t;let i;e[0]!==r?(i=r&&s.jsx("span",{className:"ml-0.5 text-destructive",children:"*"}),e[0]=r,e[1]=i):i=e[1];let o;return e[2]!==a||e[3]!==n||e[4]!==i?(o=s.jsx("div",{className:"flex items-center gap-1.5",children:s.jsxs("label",{htmlFor:n,className:"typography-meta font-medium text-foreground",children:[a,i]})}),e[2]=a,e[3]=n,e[4]=i,e[5]=o):o=e[5],o},rh=t=>{const e=nt.c(84),{value:n,onChange:r,use24Hour:a,hourAriaLabel:i,minuteAriaLabel:o,periodAriaLabel:c,amLabel:d,pmLabel:p}=t;let m;e[0]!==n?(m=_A(n),e[0]=n,e[1]=m):m=e[1];const u=m,h=Oe.useRef(null),b=Oe.useRef(null),[f,y]=Oe.useState(null),[x,g]=Oe.useState(null),w=Oe.useRef(null),v=Oe.useRef(null);let S;e[2]===Symbol.for("react.memo_cache_sentinel")?(S=Z=>{w.current=Z,y(Z)},e[2]=S):S=e[2];const A=S;let j;e[3]===Symbol.for("react.memo_cache_sentinel")?(j=Z=>{v.current=Z,g(Z)},e[3]=j):j=e[3];const C=j,I=ZA,R=eP,k=tP;let P;e[4]!==r||e[5]!==u.meridiem||e[6]!==u.minute||e[7]!==a?(P=Z=>{const Ie=Z.replace(/\D/g,"").slice(0,2);A(Ie),Ie.length===2&&(r(a?k(I(Ie),u.minute):$a(sh(Ie),u.minute,u.meridiem)),A(null),b.current?.focus())},e[4]=r,e[5]=u.meridiem,e[6]=u.minute,e[7]=a,e[8]=P):P=e[8];const N=P;let D;e[9]!==r||e[10]!==u.meridiem||e[11]!==u.minute||e[12]!==a?(D=()=>{const Z=w.current;if(Z!==null&&(A(null),Z.length!==0)){if(a){r(k(I(Z.padStart(2,"0")),u.minute));return}r($a(sh(Z.padStart(2,"0")),u.minute,u.meridiem))}},e[9]=r,e[10]=u.meridiem,e[11]=u.minute,e[12]=a,e[13]=D):D=e[13];const T=D;let M;e[14]!==r||e[15]!==u.hour12||e[16]!==u.hour24||e[17]!==u.meridiem||e[18]!==a?(M=Z=>{const Ie=Z.replace(/\D/g,"").slice(0,2);C(Ie),Ie.length===2&&(r(a?k(u.hour24,gl(Ie)):$a(u.hour12,gl(Ie),u.meridiem)),C(null))},e[14]=r,e[15]=u.hour12,e[16]=u.hour24,e[17]=u.meridiem,e[18]=a,e[19]=M):M=e[19];const $=M;let F;e[20]!==r||e[21]!==u.hour12||e[22]!==u.hour24||e[23]!==u.meridiem||e[24]!==a?(F=()=>{const Z=v.current;Z!==null&&(C(null),Z.length!==0&&r(a?k(u.hour24,gl(Z.padStart(2,"0"))):$a(u.hour12,gl(Z.padStart(2,"0")),u.meridiem)))},e[20]=r,e[21]=u.hour12,e[22]=u.hour24,e[23]=u.meridiem,e[24]=a,e[25]=F):F=e[25];const V=F;let O;e[26]!==r||e[27]!==u.hour12||e[28]!==u.hour24||e[29]!==u.meridiem||e[30]!==u.minute||e[31]!==a?(O=Z=>r(a?k(R(u.hour24,Z),u.minute):$a(UA(u.hour12,Z),u.minute,u.meridiem)),e[26]=r,e[27]=u.hour12,e[28]=u.hour24,e[29]=u.meridiem,e[30]=u.minute,e[31]=a,e[32]=O):O=e[32];const L=O;let W;e[33]!==r||e[34]!==u.hour12||e[35]!==u.hour24||e[36]!==u.meridiem||e[37]!==u.minute||e[38]!==a?(W=Z=>r(a?k(u.hour24,nh(u.minute,Z)):$a(u.hour12,nh(u.minute,Z),u.meridiem)),e[33]=r,e[34]=u.hour12,e[35]=u.hour24,e[36]=u.meridiem,e[37]=u.minute,e[38]=a,e[39]=W):W=e[39];const B=W;let ne;e[40]!==r||e[41]!==u.hour12||e[42]!==u.meridiem||e[43]!==u.minute?(ne=Z=>{Z!==u.meridiem&&r($a(u.hour12,u.minute,Z))},e[40]=r,e[41]=u.hour12,e[42]=u.meridiem,e[43]=u.minute,e[44]=ne):ne=e[44];const le=ne;let ee;e[45]!==T||e[46]!==L?(ee=Z=>{if(Z.key==="ArrowRight"){Z.preventDefault(),T(),b.current?.focus();return}(Z.key==="ArrowUp"||Z.key==="ArrowDown")&&(Z.preventDefault(),A(null),L(Z.key==="ArrowUp"?1:-1))},e[45]=T,e[46]=L,e[47]=ee):ee=e[47];const ae=ee;let ge;e[48]!==V||e[49]!==B?(ge=Z=>{if(Z.key==="ArrowLeft"&&(Z.currentTarget.selectionStart??0)===0){Z.preventDefault(),V(),h.current?.focus();return}(Z.key==="ArrowUp"||Z.key==="ArrowDown")&&(Z.preventDefault(),C(null),B(Z.key==="ArrowUp"?1:-1))},e[48]=V,e[49]=B,e[50]=ge):ge=e[50];const te=ge,E=a?"px-2":"pl-2 pr-1";let z;e[51]!==E?(z=pe("inline-flex h-9 w-fit items-center gap-1 rounded-md border border-border bg-background focus-within:ring-1 focus-within:ring-interactive-focusRing focus-within:border-interactive-focusRing",E),e[51]=E,e[52]=z):z=e[52];const J=f??(a?u.hour24:u.hour12);let H;e[53]!==N?(H=Z=>N(Z.target.value),e[53]=N,e[54]=H):H=e[54];let re;e[55]===Symbol.for("react.memo_cache_sentinel")?(re=()=>A(""),e[55]=re):re=e[55];let ce;e[56]!==T||e[57]!==i||e[58]!==ae||e[59]!==J||e[60]!==H?(ce=s.jsx("input",{ref:h,inputMode:"numeric",value:J,onChange:H,onKeyDown:ae,onFocus:re,onBlur:T,maxLength:2,"aria-label":i,className:"h-7 w-7 shrink-0 rounded-sm bg-transparent text-center font-mono text-sm tabular-nums text-foreground outline-none caret-transparent focus:bg-interactive-hover"}),e[56]=T,e[57]=i,e[58]=ae,e[59]=J,e[60]=H,e[61]=ce):ce=e[61];let Ne;e[62]===Symbol.for("react.memo_cache_sentinel")?(Ne=s.jsx("span",{className:"font-mono text-sm text-muted-foreground",children:":"}),e[62]=Ne):Ne=e[62];const me=x??u.minute;let we;e[63]!==$?(we=Z=>$(Z.target.value),e[63]=$,e[64]=we):we=e[64];let _;e[65]===Symbol.for("react.memo_cache_sentinel")?(_=()=>C(""),e[65]=_):_=e[65];let ue;e[66]!==V||e[67]!==o||e[68]!==te||e[69]!==me||e[70]!==we?(ue=s.jsx("input",{ref:b,inputMode:"numeric",value:me,onChange:we,onKeyDown:te,onFocus:_,onBlur:V,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]=V,e[67]=o,e[68]=te,e[69]=me,e[70]=we,e[71]=ue):ue=e[71];let Q;e[72]!==d||e[73]!==u.meridiem||e[74]!==c||e[75]!==p||e[76]!==le||e[77]!==a?(Q=a?null:s.jsxs(ps,{value:u.meridiem,onValueChange:Z=>le(Z),children:[s.jsx(fs,{"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(hs,{children:[s.jsx(Ot,{value:"AM",children:d}),s.jsx(Ot,{value:"PM",children:p})]})]}),e[72]=d,e[73]=u.meridiem,e[74]=c,e[75]=p,e[76]=le,e[77]=a,e[78]=Q):Q=e[78];let oe;return e[79]!==z||e[80]!==ce||e[81]!==ue||e[82]!==Q?(oe=s.jsxs("div",{className:z,children:[ce,Ne,ue,Q]}),e[79]=z,e[80]=ce,e[81]=ue,e[82]=Q,e[83]=oe):oe=e[83],oe},ah=t=>new Date(t.getFullYear(),t.getMonth(),1),qA=()=>{const t=new Date;return new Date(t.getFullYear(),t.getMonth(),t.getDate())},ih=(t,e)=>t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth()&&t.getDate()===e.getDate(),QA=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"]},oh=(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:QA(t),onceDate:typeof t.schedule.date=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(t.schedule.date)?t.schedule.date:Zf(),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:Zf(),onceTime:"09:00",weekdays:[1],timezone:n},execution:{prompt:"",providerID:e.providerID,modelID:e.modelID,variant:e.variant,agent:e.agent}}},JA=(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")},YA=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 XA(t){const{open:e,task:n,onOpenChange:r,onSave:a}=t,{t:i,locale:o}=ut(),c=yt(G=>G.loadProviders),d=yt(G=>G.loadAgents),p=yt(G=>G.providers),m=yt(G=>G.currentProviderId),u=yt(G=>G.currentModelId),h=yt(G=>G.currentVariant||""),b=yt(G=>G.currentAgentName||""),f=Te(G=>G.timeFormatPreference),y=Te(G=>G.weekStartPreference),x=Te(G=>G.isMobile),[g,w]=Oe.useState(()=>oh(n,{providerID:m,modelID:u,variant:h,agent:b})),[v,S]=Oe.useState(!1),[A,j]=Oe.useState(!1),[C,I]=Oe.useState(!1),[R,k]=Oe.useState(""),[P,N]=Oe.useState(!1),[D,T]=Oe.useState(""),[M,$]=Oe.useState(()=>{const G=Fl(n?.schedule?.date||"")||new Date;return new Date(G.getFullYear(),G.getMonth(),1)}),F=Oe.useRef(null),V=Oe.useRef(null),O=Oe.useRef(null),L=Oe.useRef(null),W=Oe.useMemo(()=>KA(o),[o]),B=Oe.useMemo(()=>WA(o),[o]),ne=Oe.useMemo(()=>f==="24h"?!0:f==="12h"?!1:W,[f,W]),le=Oe.useMemo(()=>y==="sunday"?0:y==="monday"?1:B,[y,B]),ee=Oe.useMemo(()=>{const G=HA(o);return GA(Qx.map(be=>({value:be,label:G[be]||""})),le)},[o,le]);Oe.useEffect(()=>{e&&(c(),d())},[e,c,d]),Oe.useEffect(()=>{if(!e)return;w(oh(n,{providerID:m,modelID:u,variant:h,agent:b}));const G=Fl(n?.schedule?.date||"")||new Date;$(new Date(G.getFullYear(),G.getMonth(),1)),j(!1),N(!1),I(!1),T(""),k("")},[e,n,m,u,h,b]),Oe.useEffect(()=>{if(!A)return;const G=be=>{F.current&&!F.current.contains(be.target)&&j(!1)};return document.addEventListener("mousedown",G),()=>{document.removeEventListener("mousedown",G)}},[A]);const ae=Oe.useMemo(()=>{const be=p.find(De=>De.id===g.execution.providerID)?.models?.find(De=>De.id===g.execution.modelID);return be?.variants?Object.keys(be.variants):[]},[p,g.execution.providerID,g.execution.modelID]),ge=ae.length>0,te=Oe.useMemo(()=>!ge||!g.execution.variant?"__default":ae.includes(g.execution.variant)?g.execution.variant:"__default",[g.execution.variant,ge,ae]);Oe.useEffect(()=>{ge||!g.execution.variant||w(G=>({...G,execution:{...G.execution,variant:""}}))},[ge,g.execution.variant]);const E=Oe.useCallback((G,be)=>{w(De=>{const Ae=new Set(De.schedule.weekdays);return be?Ae.add(G):Ae.delete(G),{...De,schedule:{...De.schedule,weekdays:Array.from(Ae).sort((ve,U)=>ve-U)}}})},[]),z=Oe.useCallback((G,be)=>{w(De=>{const Ae=De.schedule.times.slice();return Ae[G]=be,{...De,schedule:{...De.schedule,times:Ae}}})},[]),J=Oe.useCallback(G=>{w(be=>{const De=be.schedule.times.filter((Ae,ve)=>ve!==G);return{...be,schedule:{...be.schedule,times:De.length>0?De:["09:00"]}}})},[]),H=Oe.useCallback(()=>{w(G=>({...G,schedule:{...G.schedule,times:[...G.schedule.times,"12:00"]}}))},[]),re=Oe.useMemo(()=>qA(),[]),ce=Oe.useMemo(()=>ah(re),[re]),Ne=Oe.useMemo(()=>{const G=Fl(g.schedule.onceDate);return G?ih(G,re)?i("sessions.scheduledTasks.editor.date.today"):new Intl.DateTimeFormat(o,{weekday:"short"}).format(G):null},[g.schedule.onceDate,o,i,re]),me=Oe.useMemo(()=>ah(M).getTime()<=ce.getTime(),[M,ce]),we=Oe.useMemo(()=>ee.map(G=>G.label),[ee]),_=Oe.useCallback(G=>{w(be=>({...be,schedule:{...be.schedule,onceDate:G}}))},[]),ue=Oe.useCallback((G,be)=>{if(G.startsWith("/")){const ve=G.indexOf(" "),U=G.indexOf(`
89
- `),de=Math.min(ve===-1?G.length:ve,U===-1?G.length:U);if(be<=de&&ve===-1){T(G.substring(1,de)),N(!0),I(!1);return}}N(!1);const De=G.substring(0,be),Ae=De.lastIndexOf("@");if(Ae!==-1){const ve=Ae>0?De[Ae-1]:null,U=De.substring(Ae+1);(!ve||/\s/.test(ve))&&!U.includes(" ")&&!U.includes(`
90
- `)?(k(U),I(!0)):I(!1);return}I(!1)},[]),Q=Oe.useCallback(G=>{w(be=>({...be,execution:{...be.execution,prompt:G}}))},[]),oe=Oe.useCallback(G=>{const be=g.execution.prompt,Ae=V.current?.selectionStart??be.length,U=be.substring(0,Ae).lastIndexOf("@"),de=G.relativePath&&G.relativePath.trim().length>0?G.relativePath.trim():G.path||G.name,Re=U!==-1?U:Ae,Le=`${be.substring(0,Re)}@${de} ${be.substring(Ae)}`,se=Re+de.length+2;Q(Le),I(!1),k(""),requestAnimationFrame(()=>{const ie=V.current;ie&&(ie.selectionStart=se,ie.selectionEnd=se,ie.focus()),ue(Le,se)})},[g.execution.prompt,Q,ue]),Z=Oe.useCallback(G=>{const be=g.execution.prompt,Ae=V.current?.selectionStart??be.length,U=be.substring(0,Ae).lastIndexOf("@"),de=U!==-1?U:Ae,Re=`${be.substring(0,de)}@${G} ${be.substring(Ae)}`,Le=de+G.length+2;Q(Re),I(!1),k(""),requestAnimationFrame(()=>{const se=V.current;se&&(se.selectionStart=Le,se.selectionEnd=Le,se.focus()),ue(Re,Le)})},[g.execution.prompt,Q,ue]),Ie=Oe.useCallback(G=>{const be=`/${G.name} `;Q(be),N(!1),T(""),requestAnimationFrame(()=>{const De=V.current;De&&(De.focus(),De.selectionStart=De.value.length,De.selectionEnd=De.value.length),ue(be,be.length)})},[Q,ue]),Se=Oe.useCallback(G=>{if(P&&L.current&&(G.key==="Enter"||G.key==="ArrowUp"||G.key==="ArrowDown"||G.key==="Escape"||G.key==="Tab")){G.preventDefault(),L.current.handleKeyDown(G.key);return}C&&O.current&&(G.key==="Enter"||G.key==="ArrowUp"||G.key==="ArrowDown"||G.key==="Escape"||G.key==="Tab")&&(G.preventDefault(),O.current.handleKeyDown(G.key))},[P,C]),Y=Oe.useCallback(async()=>{const G=JA(g,i);if(G){q.error(G);return}const be=YA(g.schedule.times),De={...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:be,...g.schedule.kind==="weekly"?{weekdays:g.schedule.weekdays}:{}}},execution:{prompt:g.execution.prompt,providerID:g.execution.providerID,modelID:g.execution.modelID,...g.execution.variant.trim()?{variant:g.execution.variant.trim()}:{},...g.execution.agent.trim()?{agent:g.execution.agent.trim()}:{}},...g.state?{state:g.state}:{}};S(!0);try{await a(De),r(!1)}catch(Ae){q.error(Ae instanceof Error?Ae.message:i("sessions.scheduledTasks.editor.toast.saveFailed"))}finally{S(!1)}},[g,r,a,i]),fe=Oe.useId(),ke=Oe.useCallback(()=>typeof document>"u"?!1:!!document.querySelector('[data-slot="dropdown-menu-content"], [data-slot="select-content"]'),[]),xe=i(n?"sessions.scheduledTasks.editor.title.edit":"sessions.scheduledTasks.editor.title.new"),he=i("sessions.scheduledTasks.editor.description"),Pe=s.jsxs("div",{className:"flex flex-col gap-5",children:[s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(kr,{htmlFor:"sched-name",required:!0,children:i("sessions.scheduledTasks.editor.taskName.label")}),s.jsx(Vt,{id:"sched-name",value:g.name,onChange:G=>w(be=>({...be,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(kr,{children:i("sessions.scheduledTasks.editor.scheduleType.label")}),s.jsxs(ps,{value:g.schedule.kind,onValueChange:G=>{w(be=>({...be,schedule:{...be.schedule,kind:G}}))},children:[s.jsx(fs,{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(hs,{children:[s.jsx(Ot,{value:"daily",children:i("sessions.scheduledTasks.editor.scheduleType.daily")}),s.jsx(Ot,{value:"weekly",children:i("sessions.scheduledTasks.editor.scheduleType.weekly")}),s.jsx(Ot,{value:"once",children:i("sessions.scheduledTasks.editor.scheduleType.once")})]})]})]})]}),g.schedule.kind==="once"?s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex flex-col gap-1",ref:F,children:[s.jsx(kr,{children:i("sessions.scheduledTasks.editor.date.label")}),s.jsxs("div",{className:"relative",children:[s.jsxs("button",{type:"button",className:"inline-flex h-9 w-fit max-w-full items-center justify-between gap-2 rounded-md border border-border bg-background px-3 text-left hover:bg-interactive-hover",onClick:()=>j(G=>!G),children:[s.jsxs("span",{className:"inline-flex items-center gap-2",children:[s.jsx(Ky,{className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:VA(g.schedule.onceDate,i("sessions.scheduledTasks.editor.date.placeholder"),o)})]}),s.jsx(Cs,{className:"h-4 w-4 text-muted-foreground"})]}),A?s.jsxs("div",{className:"absolute left-0 top-[calc(100%+6px)] z-50 w-[288px] rounded-xl border border-border bg-background p-3 shadow-sm",children:[s.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-interactive-hover disabled:cursor-not-allowed disabled:opacity-40",onClick:()=>$(G=>th(G,-1)),"aria-label":i("sessions.scheduledTasks.editor.date.previousMonth"),disabled:me,children:s.jsx(zi,{className:"h-4 w-4"})}),s.jsx("div",{className:"typography-ui-label text-foreground",children:new Intl.DateTimeFormat(o,{month:"long",year:"numeric"}).format(M)}),s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-interactive-hover",onClick:()=>$(G=>th(G,1)),"aria-label":i("sessions.scheduledTasks.editor.date.nextMonth"),children:s.jsx(Fn,{className:"h-4 w-4"})})]}),s.jsx("div",{className:"mb-1 grid grid-cols-7 gap-1 px-1",children:we.map((G,be)=>s.jsx("div",{className:"py-1 text-center typography-micro text-muted-foreground",children:G},`${G}-${be}`))}),s.jsx("div",{className:"grid grid-cols-7 gap-1",children:zA(M,le).map(({date:G,inCurrentMonth:be})=>{const De=eh(G),Ae=De===g.schedule.onceDate,ve=ih(G,re),U=G.getTime()<re.getTime(),de=Ae?"bg-interactive-selection text-interactive-selection-foreground":U?"text-muted-foreground/40":be?"text-foreground hover:bg-interactive-hover":"text-muted-foreground/60 hover:bg-interactive-hover";return s.jsx("button",{type:"button",onClick:()=>{U||(_(De),j(!1))},disabled:U,className:["h-8 rounded-md typography-ui-label",de,ve&&!Ae?"ring-1 ring-inset ring-interactive-focusRing bg-interactive-hover/50":"",U?"cursor-not-allowed opacity-45":""].join(" "),children:G.getDate()},De)})}),s.jsxs("div",{className:"mt-2 flex items-center justify-between border-t border-border pt-2",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:Ne||""}),s.jsx(je,{type:"button",size:"xs",variant:"ghost",onClick:()=>{_(eh(re)),$(new Date(re.getFullYear(),re.getMonth(),1))},children:i("sessions.scheduledTasks.editor.date.jumpToToday")})]})]}):null]})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(kr,{children:i("sessions.scheduledTasks.editor.time.label")}),s.jsx(rh,{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(be=>({...be,schedule:{...be.schedule,onceTime:G}}))}),s.jsxs("div",{className:"mt-2 flex flex-col gap-1",children:[s.jsx(kr,{children:i("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(ps,{value:g.schedule.timezone,onValueChange:G=>{w(be=>({...be,schedule:{...be.schedule,timezone:G}}))},children:[s.jsx(fs,{className:"w-fit max-w-full",children:s.jsx(ys,{})}),s.jsx(hs,{children:Xf.map(G=>s.jsx(Ot,{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(kr,{children:i("sessions.scheduledTasks.editor.weekdays.label")}),s.jsx("div",{className:"flex flex-wrap gap-x-3 gap-y-2",children:ee.map(G=>{const be=g.schedule.weekdays.includes(G.value);return s.jsxs("button",{type:"button",onClick:()=>E(G.value,!be),className:["inline-flex items-center gap-1.5 px-0.5 py-0.5 typography-meta",be?"text-foreground":"text-muted-foreground","hover:text-foreground"].join(" "),children:[s.jsx(bs,{checked:be,onChange:De=>E(G.value,De),ariaLabel:G.label}),s.jsx("span",{children:G.label})]},G.value)})})]}):null,s.jsxs("div",{className:"flex flex-col gap-2",children:[s.jsx(kr,{children:i("sessions.scheduledTasks.editor.times.label")}),s.jsx("div",{className:"flex flex-col gap-2",children:g.schedule.times.map((G,be)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(rh,{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:De=>z(be,De)}),g.schedule.times.length>1?s.jsx(je,{type:"button",size:"icon",variant:"ghost",onClick:()=>J(be),"aria-label":i("sessions.scheduledTasks.editor.times.removeAria"),children:s.jsx(Ds,{className:"h-4 w-4"})}):null]},be))}),s.jsx("div",{children:s.jsxs(je,{type:"button",size:"sm",variant:"outline",onClick:H,children:[s.jsx(_s,{className:"mr-1 h-4 w-4"})," ",i("sessions.scheduledTasks.editor.times.add")]})})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(kr,{children:i("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(ps,{value:g.schedule.timezone,onValueChange:G=>{w(be=>({...be,schedule:{...be.schedule,timezone:G}}))},children:[s.jsx(fs,{className:"w-fit max-w-full",children:s.jsx(ys,{})}),s.jsx(hs,{children:Xf.map(G=>s.jsx(Ot,{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(kr,{required:!0,children:i("sessions.scheduledTasks.editor.model.label")}),s.jsx(Ho,{providerId:g.execution.providerID,modelId:g.execution.modelID,onChange:(G,be)=>{w(De=>({...De,execution:{...De.execution,providerID:G,modelID:be,variant:""}}))}})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(kr,{children:i("sessions.scheduledTasks.editor.thinkingLevel.label")}),s.jsxs(ps,{value:te,disabled:!ge,onValueChange:G=>{w(be=>({...be,execution:{...be.execution,variant:G==="__default"?"":G}}))},children:[s.jsx(fs,{className:"w-fit max-w-full",children:s.jsx(ys,{children:G=>G==="__default"?i("sessions.scheduledTasks.editor.thinkingLevel.default"):G})}),s.jsxs(hs,{children:[s.jsx(Ot,{value:"__default",children:i("sessions.scheduledTasks.editor.thinkingLevel.default")}),ae.map(G=>s.jsx(Ot,{value:G,children:G},G))]})]})]})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(kr,{children:i("sessions.scheduledTasks.editor.agent.label")}),s.jsx(jc,{agentName:g.execution.agent,filter:G=>ug(G.mode),onChange:G=>w(be=>({...be,execution:{...be.execution,agent:G}}))})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(kr,{htmlFor:"sched-prompt",required:!0,children:i("sessions.scheduledTasks.editor.prompt.label")}),s.jsxs("div",{className:"relative",children:[s.jsx(Sn,{id:"sched-prompt",ref:V,value:g.execution.prompt,onChange:G=>{const be=G.target.value;Q(be);const De=G.target.selectionStart??be.length;ue(be,De)},onKeyDown:Se,rows:8,placeholder:i("sessions.scheduledTasks.editor.prompt.placeholder"),className:"typography-meta min-h-[120px] max-h-[300px] resize-none overflow-y-auto"}),P?s.jsx(Ig,{ref:L,searchQuery:D,onCommandSelect:Ie,onClose:()=>N(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,C?s.jsx(Ag,{ref:O,searchQuery:R,onFileSelect:oe,onAgentSelect:Z,onClose:()=>I(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null]})]})]}),Be=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("label",{className:"inline-flex items-center gap-2",children:[s.jsx(bs,{checked:g.enabled,onChange:G=>w(be=>({...be,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(je,{type:"button",variant:"ghost",size:"sm",onClick:()=>r(!1),disabled:v,children:i("sessions.scheduledTasks.editor.actions.cancel")}),s.jsx(je,{type:"button",size:"sm",onClick:Y,disabled:v,children:i(v?"sessions.scheduledTasks.editor.actions.saving":"sessions.scheduledTasks.editor.actions.save")})]})]});return x?s.jsx(Ar,{open:e,title:xe,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:xe}),G]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:he})]}),footer:Be,children:Pe}):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(Os,{id:fe,className:"sr-only",children:he}),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(Ss,{className:"typography-ui-label font-medium text-foreground",children:xe}),s.jsx("p",{className:"typography-meta mt-0.5 text-muted-foreground",children:he})]})}),s.jsx(Vo,{className:"flex-1 min-h-0 overflow-auto [scrollbar-gutter:stable_both-edges]",size:64,hideTopShadow:!0,children:s.jsx("div",{className:"mx-auto w-full max-w-2xl px-4 sm:px-6 pb-5",children:Pe})}),s.jsx("div",{className:"shrink-0 px-4 sm:px-6 py-3",children:s.jsx("div",{className:"mx-auto w-full max-w-2xl",children:Be})})]})})}function ZA(t){return eo(t,{min:0,max:23})}function eP(t,e){return eo(String(Number.parseInt(t,10)+e),{min:0,max:23,loop:!0})}function tP(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 sP=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))},nP=(t,e)=>{const n=sP(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||""})},rP=t=>!t||!Number.isFinite(t)?"":new Date(t).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"}),lh=(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})},aP={success:{tone:"success",Icon:xu},error:{tone:"error",Icon:Hr},running:{tone:"warning",Icon:Zt,spin:!0},idle:{tone:"muted",Icon:sg}},iP=t=>({color:`var(--status-${t})`,backgroundColor:`var(--status-${t}-background)`,borderColor:`var(--status-${t}-border)`});function oP(){const{t}=ut(),e=Te(T=>T.isScheduledTasksDialogOpen),n=Te(T=>T.setScheduledTasksDialogOpen),r=Te(T=>T.isMobile),a=Fs(T=>T.projects),i=Fs(T=>T.getActiveProject()),o=Ws(T=>T.homeDirectory),{currentTheme:c}=Rr(),[d,p]=Oe.useState(""),[m,u]=Oe.useState([]),[h,b]=Oe.useState(!0),[f,y]=Oe.useState(!1),[x,g]=Oe.useState(null),[w,v]=Oe.useState(null),S=Oe.useMemo(()=>a.find(T=>T.id===d)||null,[a,d]),A=Oe.useCallback(T=>{const M=T.label?.trim()||ii(T.path,o||void 0),$=Wo({id:T.id,iconImage:T.iconImage??null},{themeVariant:c.metadata.variant,iconColor:c.colors.surface.foreground}),F=T.icon?vc[T.icon]:null,V=T.color?Ko[T.color]:void 0;return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[$?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:T.iconBackground?{backgroundColor:T.iconBackground}:void 0,children:s.jsx("img",{src:$,alt:"",className:"h-full w-full object-contain",draggable:!1})}):F?s.jsx(F,{className:"h-3.5 w-3.5 shrink-0",style:V?{color:V}:void 0}):s.jsx(zn,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:V?{color:V}:void 0}),s.jsx("span",{className:"truncate",children:M})]})},[o,c.metadata.variant,c.colors.surface.foreground]),j=Oe.useCallback(async(T,M)=>{if(!T){u([]);return}M?.silent||b(!0);try{const $=await LA(T);$.sort((F,V)=>{if(F.enabled!==V.enabled)return F.enabled?-1:1;const O=F.name.localeCompare(V.name);return O!==0?O:(F.state?.nextRunAt||Number.MAX_SAFE_INTEGER)-(V.state?.nextRunAt||Number.MAX_SAFE_INTEGER)}),u($)}catch($){q.error($ instanceof Error?$.message:t("sessions.scheduledTasks.dialog.toast.loadFailed")),M?.silent||u([])}finally{M?.silent||b(!1)}},[t]);Oe.useEffect(()=>{if(!e)return;const T=i?.id||a[0]?.id||"";p(T),T?j(T):(u([]),b(!1))},[e,i,a,j]),Oe.useEffect(()=>{if(!e)return;let T=null;const M=qx($=>{$.type==="scheduled-task-ran"&&$.projectId===d&&(T&&clearTimeout(T),T=setTimeout(()=>{j(d,{silent:!0})},400))});return()=>{T&&clearTimeout(T),M()}},[e,d,j]);const C=Oe.useCallback(async T=>{if(!d)throw new Error(t("sessions.scheduledTasks.dialog.error.chooseProjectFirst"));await Yf(d,T),await j(d),q.success(t("sessions.scheduledTasks.dialog.toast.saved"))},[d,j,t]),I=Oe.useCallback(async(T,M)=>{if(d){v(T.id),u($=>$.map(F=>F.id===T.id?{...F,enabled:M}:F));try{await Yf(d,{...T,enabled:M}),await j(d,{silent:!0})}catch($){q.error($ instanceof Error?$.message:t("sessions.scheduledTasks.dialog.toast.updateFailed")),await j(d,{silent:!0})}finally{v(null)}}},[d,j,t]),R=Oe.useCallback(async T=>{if(!(!d||!window.confirm(t("sessions.scheduledTasks.dialog.confirm.deleteTask",{taskName:T.name})))){v(T.id);try{await $A(d,T.id),await j(d,{silent:!0}),q.success(t("sessions.scheduledTasks.dialog.toast.deleted"))}catch($){q.error($ instanceof Error?$.message:t("sessions.scheduledTasks.dialog.toast.deleteFailed"))}finally{v(null)}}},[d,j,t]),k=Oe.useCallback(async T=>{if(d){v(T.id);try{await BA(d,T.id),await Promise.all([j(d,{silent:!0}),Bd()]),q.success(t("sessions.scheduledTasks.dialog.toast.started"))}catch(M){q.error(M instanceof Error?M.message:t("sessions.scheduledTasks.dialog.toast.runFailed"))}finally{v(null)}}},[d,j,t]),P=s.jsxs("div",{className:"flex flex-col items-start gap-1",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("sessions.scheduledTasks.dialog.project.label")}),s.jsxs(ps,{value:d||"__none",onValueChange:T=>{const M=T==="__none"?"":T;p(M),M?j(M):u([])},children:[s.jsx(fs,{className:r?"w-full":void 0,children:S?s.jsx(ys,{children:A(S)}):s.jsx(ys,{placeholder:t("sessions.scheduledTasks.dialog.project.placeholder")})}),s.jsxs(hs,{children:[a.length===0?s.jsx(Ot,{value:"__none",children:t("sessions.scheduledTasks.dialog.project.empty")}):null,a.map(T=>s.jsx(Ot,{value:T.id,children:A(T)},T.id))]})]})]}),N=()=>{g(null),y(!0)},D=s.jsxs("div",{className:"space-y-4",children:[r?P:s.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[P,s.jsxs(je,{onClick:N,disabled:!d,children:[s.jsx(_s,{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(Zt,{className:"h-4 w-4 animate-spin"})," ",t("sessions.scheduledTasks.dialog.loading")]}):m.length===0?s.jsx("div",{className:"rounded-lg border border-dashed border-border p-4 typography-meta text-muted-foreground",children:t(d?"sessions.scheduledTasks.dialog.empty.noTasks":"sessions.scheduledTasks.dialog.empty.selectProject")}):s.jsx("div",{className:"space-y-2.5",children:m.map(T=>{const M=w===T.id,$=T.state?.lastStatus||"idle",F=aP[$],V=t($==="success"?"sessions.scheduledTasks.dialog.status.success":$==="error"?"sessions.scheduledTasks.dialog.status.error":$==="running"?"sessions.scheduledTasks.dialog.status.running":"sessions.scheduledTasks.dialog.status.idle"),O=T.state?.nextRunAt,L=T.state?.lastRunAt;return s.jsxs("div",{className:pe("rounded-lg border border-border p-4 transition-opacity",!T.enabled&&"opacity-60"),children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-header truncate font-semibold text-foreground",children:T.name}),s.jsx("div",{className:"typography-micro truncate text-muted-foreground",children:nP(T,t)})]}),s.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-x-5 gap-y-1 typography-micro text-muted-foreground",children:[s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(Ad,{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:lh(O,t)}),s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:rP(O)})]}):s.jsx("span",{children:"—"})]}),s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(Eh,{className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-medium text-foreground",children:t("sessions.scheduledTasks.dialog.lastRun.label")}),$==="running"?s.jsxs("span",{className:"inline-flex items-center gap-1",style:{color:"var(--status-warning)"},children:[s.jsx(Zt,{className:"h-3.5 w-3.5 animate-spin"}),t("sessions.scheduledTasks.dialog.lastRun.runningNow")]}):L?s.jsxs(s.Fragment,{children:[F.tone!=="muted"?s.jsxs("span",{className:"inline-flex items-center gap-1",style:{color:`var(--status-${F.tone})`},children:[s.jsx(F.Icon,{className:"h-3.5 w-3.5"}),V]}):null,s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:lh(L,t)})]}):s.jsx("span",{children:t("sessions.scheduledTasks.dialog.lastRun.never")})]})]}),T.state?.lastError?s.jsxs("div",{className:"mt-3 flex items-start gap-2 rounded-md border p-2 typography-micro",style:iP("error"),children:[s.jsx(Hr,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"min-w-0 break-words",children:T.state.lastError})]}):null,s.jsxs("div",{className:"mt-4 flex flex-wrap items-center justify-between gap-2",children:[s.jsxs("label",{className:pe("inline-flex cursor-pointer items-center gap-2 typography-micro font-medium",T.enabled?"text-foreground":"text-muted-foreground",M&&"cursor-not-allowed opacity-50"),children:[s.jsx(bs,{checked:T.enabled,onChange:W=>{I(T,W)},ariaLabel:T.enabled?t("sessions.scheduledTasks.dialog.taskToggle.pauseAria",{taskName:T.name}):t("sessions.scheduledTasks.dialog.taskToggle.enableAria",{taskName:T.name}),disabled:M}),T.enabled?t("sessions.scheduledTasks.dialog.taskToggle.enabled"):t("sessions.scheduledTasks.dialog.taskToggle.paused")]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[s.jsxs(je,{variant:"outline",size:"sm",onClick:()=>{k(T)},disabled:M,children:[s.jsx(Wr,{className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.runNow")]}),s.jsxs(je,{variant:"outline",size:"sm",onClick:()=>{g(T),y(!0)},disabled:M,"aria-label":t("sessions.scheduledTasks.dialog.actions.editAria",{taskName:T.name}),children:[s.jsx(Hy,{className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.edit")]}),s.jsx(je,{variant:"destructive",size:"sm",onClick:()=>{R(T)},disabled:M,"aria-label":t("sessions.scheduledTasks.dialog.actions.deleteAria",{taskName:T.name}),children:s.jsx(sn,{className:"h-4 w-4"})})]})]})]},T.id)})})})]});return s.jsxs(s.Fragment,{children:[r?s.jsx(Ar,{open:e,title:t("sessions.scheduledTasks.dialog.title"),onClose:()=>n(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:T=>s.jsxs("div",{className:"flex flex-col gap-1 border-b border-border/40 px-3 py-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("h2",{className:"typography-ui-label font-semibold text-foreground",children:t("sessions.scheduledTasks.dialog.title")}),T]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("sessions.scheduledTasks.dialog.description")})]}),footer:s.jsxs(je,{className:"w-full",onClick:N,disabled:!d,children:[s.jsx(_s,{className:"mr-1 h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.newTask")]}),children:D}):s.jsx(ws,{open:e,onOpenChange:n,children:s.jsxs(vs,{className:"max-h-[85vh] max-w-2xl overflow-y-auto",children:[s.jsxs(Is,{children:[s.jsx(Ss,{children:t("sessions.scheduledTasks.dialog.title")}),s.jsx(Os,{children:t("sessions.scheduledTasks.dialog.description")})]}),D]})}),s.jsx(XA,{open:f,task:x,onOpenChange:y,onSave:C})]})}const lP=(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=>Mo(d,t.normalizedPath,r)))(e.archivedSessions),o=e.sessions.filter(c=>c.time?.archived||ks(c.directory??null)?!1:Mo(c,t.normalizedPath,r));return qi([...i,...o])},cP=t=>{const e=nt.c(12),{normalizedProjects:n,sessions:r,archivedSessions:a,availableWorktreesByProject:i,isVSCode:o,isSessionsLoading:c,foldersMap:d,createFolder:p,addSessionToFolder:m,cleanupSessions:u}=t;let 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 y=zu(f.normalizedPath),x=lP(f,{sessions:r,archivedSessions:a,availableWorktreesByProject:i,isVSCode:o}),g=new Set(x.map(dP)),w=d[y]??[],v=new Map(w.map(uP));x.forEach(S=>{const A=G1(S,f.normalizedPath),j=A.toLowerCase();let C=v.get(j);C||(C=p(y,A),v.set(j,C)),C.sessionIds.includes(S.id)||m(y,C.id,S.id)}),u(y,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 dP(t){return t.id}function uP(t){return[t.name.toLowerCase(),t]}const mP=t=>{const e=nt.c(41),{normalizedProjects:n,getSessionsForProject:r,getArchivedSessionsForProject:a,availableWorktreesByProject:i,projectRepoStatus:o,projectRootBranches:c,lastRepoStatus:d,buildGroupedSessions:p,hasSessionSearchQuery:m,normalizedSessionSearchQuery:u,filterSessionNodesForSearch:h,buildGroupSearchText:b,foldersMap:f}=t;let y;if(e[0]!==i||e[1]!==p||e[2]!==a||e[3]!==r||e[4]!==d||e[5]!==n||e[6]!==o||e[7]!==c){let k;e[9]!==i||e[10]!==p||e[11]!==a||e[12]!==r||e[13]!==d||e[14]!==o||e[15]!==c?(k=P=>{const N=qi([...r(P),...a(P)]),D=i.get(P.normalizedPath)??[],T=o.has(P.id)?!!o.get(P.id):d,M=p(N,P.normalizedPath,D,c.get(P.id)??null,T);return{project:P,groups:M}},e[9]=i,e[10]=p,e[11]=a,e[12]=r,e[13]=d,e[14]=o,e[15]=c,e[16]=k):k=e[16],y=n.map(k),e[0]=i,e[1]=p,e[2]=a,e[3]=r,e[4]=d,e[5]=n,e[6]=o,e[7]=c,e[8]=y}else y=e[8];const x=y,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 k=new WeakMap;if(!m){w=k;break e}const P=N=>N.reduce((D,T)=>D+1+P(T.children),0);g.forEach(N=>{N.groups.forEach(D=>{const T=h(D.sessions,u),M=P(T),$=b(D).includes(u),F=ks(D.directory??null),O=(F?f[F]??[]:[]).filter(L=>L.name.toLowerCase().includes(u)).length;k.set(D,{filteredNodes:T,matchedSessionCount:M,folderNameMatchCount:O,groupMatches:$,hasMatch:$||M>0||O>0})})}),w=k}e[17]=b,e[18]=h,e[19]=f,e[20]=m,e[21]=u,e[22]=g,e[23]=w}else w=e[23];const v=w;let S;e:{if(!m){S=g;break e}let k;if(e[24]!==v||e[25]!==g){let P;e[27]!==v?(P=N=>({...N,groups:N.groups.filter(D=>v.get(D)?.hasMatch===!0)}),e[27]=v,e[28]=P):P=e[28],k=g.map(P).filter(pP),e[24]=v,e[25]=g,e[26]=k}else k=e[26];S=k}const A=S,j=m?A:g;let C;e:{if(!m){C=0;break e}let k;if(e[29]!==v||e[30]!==j){let P;e[32]!==v?(P=(N,D)=>N+D.groups.reduce((T,M)=>{const $=v.get(M);if(!$)return T;const F=$.folderNameMatchCount+($.groupMatches?1:0);return T+$.matchedSessionCount+F},0),e[32]=v,e[33]=P):P=e[33],k=j.reduce(P,0),e[29]=v,e[30]=j,e[31]=k}else k=e[31];C=k}const I=C;let R;return e[34]!==v||e[35]!==x||e[36]!==I||e[37]!==A||e[38]!==j||e[39]!==g?(R={projectSections:x,visibleProjectSections:g,groupSearchDataByGroup:v,searchableProjectSections:A,sectionsForRender:j,searchMatchCount:I},e[34]=v,e[35]=x,e[36]=I,e[37]=A,e[38]=j,e[39]=g,e[40]=R):R=e[40],R};function pP(t){return t.groups.length>0}const fP=t=>{const e=nt.c(34),{projectSections:n,activeProjectId:r,activeSessionByProject:a,setActiveSessionByProject:i,currentSessionId:o,handleSessionSelect:c,newSessionDraftOpen:d,mobileVariant:p,openNewSessionDraft:m,setActiveMainTab:u,setSessionSwitcherOpen:h,sessions:b,worktreeMetadata:f}=t;let y,x;if(e[0]!==n){x=new Map,y=new Map;const P=(N,D,T,M)=>{x.has(N)||x.set(N,new Map);const $=x.get(N);M.forEach(F=>{const V=ks(F.worktree?.path??F.session.directory??T??D);$.set(F.session.id,{directory:V}),y.has(N)||y.set(N,{id:F.session.id,directory:V}),F.children.length>0&&P(N,D,V,F.children)})};n.forEach(N=>{N.groups.forEach(D=>{P(N.project.id,N.project.normalizedPath,D.directory,D.sessions)})}),e[0]=n,e[1]=y,e[2]=x}else y=e[1],x=e[2];let g;e[3]!==y||e[4]!==x?(g={metaByProject:x,firstSessionByProject:y},e[3]=y,e[4]=x,e[5]=g):g=e[5];const w=g,v=l.useRef(null);let S,A;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?(S=()=>{if(!r||d||v.current===r)return;const P=n.find(V=>V.project.id===r);if(!P)return;v.current=r;const N=w.metaByProject.get(r);if(o&&N&&N.has(o)){i(V=>{if(V.get(r)===o)return V;const O=new Map(V);return O.set(r,o),O});return}if(!N||N.size===0){u("chat"),p&&h(!1),m({directoryOverride:P.project.normalizedPath});return}const D=a.get(r),T=D&&N.has(D)?D:null,M=w.firstSessionByProject.get(r)?.id??null,$=T??M;if(!$||$===o)return;const F=N.get($)?.directory??null;c($,F,!1,r)},A=[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]=S,e[19]=A):(S=e[18],A=e[19]),l.useLayoutEffect(S,A);let j,C;e[20]!==r||e[21]!==o||e[22]!==w||e[23]!==i?(j=()=>{if(!r||!o)return;const P=w.metaByProject.get(r);!P||!P.has(o)||i(N=>{if(N.get(r)===o)return N;const D=new Map(N);return D.set(r,o),D})},C=[r,o,w,i],e[20]=r,e[21]=o,e[22]=w,e[23]=i,e[24]=j,e[25]=C):(j=e[24],C=e[25]),l.useEffect(j,C);let I;if(e[26]!==o||e[27]!==b||e[28]!==f){e:{if(!o){I=null;break e}const P=f.get(o)?.path;if(P){I=ks(P)??P;break e}let N;e[30]!==o?(N=T=>T.id===o,e[30]=o,e[31]=N):N=e[31];const D=b.find(N);if(!D){I=null;break e}I=ks(D.directory??null)}e[26]=o,e[27]=b,e[28]=f,e[29]=I}else I=e[29];const R=I;let k;return e[32]!==R?(k={currentSessionDirectory:R},e[32]=R,e[33]=k):k=e[33],k},hP=t=>{const e=nt.c(4);let n;e[0]!==t?(n=(i,o)=>{const c=t.get(i);if(!c||c.length===0)return o;const d=new Map(o.map(gP)),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 gP(t){return[t.id,t]}const xl=t=>!!t.time?.archived,xP=t=>{const{t:e}=ut(),n=l.useCallback(o=>[o.label,o.branch??"",o.description??"",o.directory??""].join(" ").toLowerCase(),[]),r=l.useCallback(o=>{const c=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=qi(o).sort((P,N)=>Oi(P,N,t.pinnedSessionIds)),b=new Map(h.map(P=>[P.id,P])),f=new Map;h.forEach(P=>{const N=P.parentID;if(!N)return;const D=b.get(N);if(!D||xl(D)!==xl(P))return;const T=f.get(N)??[];T.push(P),f.set(N,T)}),f.forEach(P=>P.sort((N,D)=>Oi(N,D,t.pinnedSessionIds)));const y=new Map;d.forEach(P=>{if(P.path){const N=ks(P.path)??P.path;y.set(N,P)}});const x=P=>{const N=ks(P.directory??null),D=t.worktreeMetadata.get(P.id)??null;if(D)return D;if(N){const T=y.get(N)??null;if(T&&N!==u)return T}return null},g=P=>{const N=f.get(P.id)??[];return{session:P,children:N.map(D=>g(D)),worktree:x(P)}},w=h.filter(P=>{const N=P.parentID;if(!N)return!0;const D=b.get(N);return D?xl(D)!==xl(P):!0}),v=new Map,S="__archived__",A=P=>{if(P.time?.archived)return S;const N=ks(t.worktreeMetadata.get(P.id)?.path??null),D=ks(P.directory??null);if(!N&&!D)return S;const T=ks(P.project?.worktree??null),M=N??D??T;return M?M!==u&&y.has(M)?M:M===u?u??"__project_root__":S:S};w.forEach(P=>{const N=g(P),D=A(P);v.has(D)||v.set(D,[]),v.get(D)?.push(N)});const j=u??"__project_root__",C=[{id:"root",label:m&&p&&p!=="HEAD"?e("sessions.sidebar.grouping.projectRootWithBranch",{branch:p}):e("sessions.sidebar.grouping.projectRoot"),branch:p??null,description:u?To(u,t.homeDirectory):null,isMain:!0,isArchivedBucket:!1,worktree:null,directory:u,folderScopeKey:u,sessions:v.get(j)??[]}],I=new Map;d.forEach(P=>{const N=ks(P.path)??P.path,D=v.get(N)??[],T=D.length>0,M=D.reduce(($,F)=>{const V=Number(F.session.time?.updated??F.session.time?.created??0);return Number.isFinite(V)?Math.max($,V):$},0);I.set(N,{hasActiveSession:T,lastUpdatedAt:M})}),[...d].sort((P,N)=>{const D=ks(P.path)??P.path,T=ks(N.path)??N.path,M=I.get(D)??{hasActiveSession:!1,lastUpdatedAt:0},$=I.get(T)??{hasActiveSession:!1,lastUpdatedAt:0};if(M.hasActiveSession!==$.hasActiveSession)return M.hasActiveSession?-1:1;if(M.hasActiveSession&&$.hasActiveSession)return $.lastUpdatedAt-M.lastUpdatedAt;const F=(P.label||P.branch||P.name||P.path||"").toLowerCase(),V=(N.label||N.branch||N.name||N.path||"").toLowerCase();return F.localeCompare(V)}).forEach(P=>{const N=ks(P.path)??P.path,D=t.gitBranches.get(N)?.trim()||null,T=P.branch?.trim()||null,$=!!(D&&T&&P.label&&Em(P.label)===Em(T))?D:P.label||P.name||ii(N,t.homeDirectory)||N;C.push({id:`worktree:${N}`,label:$,branch:D||T,description:To(N,t.homeDirectory),isMain:!1,isArchivedBucket:!1,worktree:P,directory:N,folderScopeKey:N,sessions:v.get(N)??[]})});const k=v.get(S)??[];return k.length>0&&C.push({id:"archived",label:e("sessions.sidebar.grouping.archived"),branch:null,description:e("sessions.sidebar.grouping.archivedDescription"),isMain:!1,isArchivedBucket:!0,worktree:null,directory:null,folderScopeKey:!t.isVSCode&&u?zu(u):null,sessions:k}),C},[t.homeDirectory,t.worktreeMetadata,t.pinnedSessionIds,t.gitBranches,t.isVSCode,e]);return{buildGroupSearchText:n,buildSessionSearchText:r,filterSessionNodesForSearch:a,buildGroupedSessions:i}},bP=t=>{const e=nt.c(9),{isSessionSearchOpen:n,setIsSessionSearchOpen:r,sessionSearchInputRef:a,sessionSearchContainerRef:i}=t;let o,c;e[0]!==n||e[1]!==a?(o=()=>{if(!n||typeof window>"u")return;const m=window.requestAnimationFrame(()=>{a.current?.focus(),a.current?.select()});return()=>window.cancelAnimationFrame(m)},c=[n,a],e[0]=n,e[1]=a,e[2]=o,e[3]=c):(o=e[2],c=e[3]),l.useEffect(o,c);let d,p;e[4]!==n||e[5]!==i||e[6]!==r?(d=()=>{if(!n||typeof document>"u")return;const m=u=>{i.current&&(i.current.contains(u.target)||r(!1))};return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},p=[n,r,i],e[4]=n,e[5]=i,e[6]=r,e[7]=d,e[8]=p):(d=e[7],p=e[8]),l.useEffect(d,p)},yP=t=>{const e=nt.c(42),{t:n}=ut(),[r,a]=l.useState(null),i=l.useRef(null);let o,c;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=()=>()=>{i.current&&clearTimeout(i.current)},c=[],e[0]=o,e[1]=c):(o=e[0],c=e[1]),l.useEffect(o,c);let d;e[2]!==t?(d=(M,$,F,V)=>{if(F)return;const O=()=>{!t.isSessionSearchOpen&&t.sessionSearchQuery.length===0||(t.setSessionSearchQuery(""),t.setIsSessionSearchOpen(!1))};if(V&&V!==t.activeProjectId&&t.setActiveProjectIdOnly(V),$&&$!==t.currentDirectory&&t.setDirectory($,{showOverlay:!1}),t.mobileVariant&&(t.setActiveMainTab("chat"),t.setSessionSwitcherOpen(!1)),M===t.currentSessionId){t.allowReselect&&t.onSessionSelected?.(M),O();return}t.setCurrentSession(M,$??null),t.onSessionSelected?.(M),O()},e[2]=t,e[3]=d):d=e[3];const p=d;let m;e[4]!==t?(m=()=>{t.setActiveMainTab("chat")},e[4]=t,e[5]=m):m=e[5];const u=m;let 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 y=f;let x;e[10]!==t||e[11]!==n?(x=async M=>{const $=await t.shareSession(M.id);$&&$.share?.url?q.success(n("sessions.sidebar.session.share.successTitle"),{description:n("sessions.sidebar.session.share.successDescription")}):q.error(n("sessions.sidebar.session.share.error"))},e[10]=t,e[11]=n,e[12]=x):x=e[12];const g=x;let w;e[13]!==n?(w=(M,$)=>{_n(M).then(F=>{if(!F.ok){q.error(n("sessions.sidebar.session.share.copyUrlError"));return}a($),i.current&&clearTimeout(i.current),i.current=window.setTimeout(()=>{a(null),i.current=null},2e3)}).catch(()=>{q.error(n("sessions.sidebar.session.share.copyUrlError"))})},e[13]=n,e[14]=w):w=e[14];const v=w;let S;e[15]!==t||e[16]!==n?(S=async M=>{await t.unshareSession(M)?q.success(n("sessions.sidebar.session.unshare.success")):q.error(n("sessions.sidebar.session.unshare.error"))},e[15]=t,e[16]=n,e[17]=S):S=e[17];const A=S;let j;e[18]!==t.childrenMap?(j=M=>{const $=[],F=V=>{(t.childrenMap.get(V)??[]).forEach(L=>{$.push(L),F(L.id)})};return F(M),$},e[18]=t.childrenMap,e[19]=j):j=e[19];const C=j;let I;e[20]!==t||e[21]!==C||e[22]!==n?(I=async(M,$)=>{const F=C(M.id),V=$?.archivedBucket===!0;if(F.length===0){(V?await t.deleteSession(M.id):await t.archiveSession(M.id))?q.success(n(V?"sessions.sidebar.session.delete.success":"sessions.sidebar.session.archive.success")):q.error(n(V?"sessions.sidebar.session.delete.error":"sessions.sidebar.session.archive.error"));return}const O=[M.id,...F.map(vP)];if(V){const{deletedIds:B,failedIds:ne}=await t.deleteSessions(O);B.length>0&&q.success(B.length===1?n("sessions.sidebar.bulkActions.deletedSingle",{count:B.length}):n("sessions.sidebar.bulkActions.deletedPlural",{count:B.length})),ne.length>0&&q.error(ne.length===1?n("sessions.sidebar.bulkActions.failedDeleteSingle",{count:ne.length}):n("sessions.sidebar.bulkActions.failedDeletePlural",{count:ne.length}));return}const{archivedIds:L,failedIds:W}=await t.archiveSessions(O);L.length>0&&q.success(L.length===1?n("sessions.sidebar.bulkActions.archivedSingle",{count:L.length}):n("sessions.sidebar.bulkActions.archivedPlural",{count:L.length})),W.length>0&&q.error(W.length===1?n("sessions.sidebar.bulkActions.failedArchiveSingle",{count:W.length}):n("sessions.sidebar.bulkActions.failedArchivePlural",{count:W.length}))},e[20]=t,e[21]=C,e[22]=n,e[23]=I):I=e[23];const R=I;let k;e[24]!==t||e[25]!==C||e[26]!==R?(k=(M,$)=>{const F=C(M.id);if(!t.showDeletionDialog){R(M,$);return}t.setDeleteSessionConfirm({session:M,descendantCount:F.length,archivedBucket:$?.archivedBucket===!0})},e[24]=t,e[25]=C,e[26]=R,e[27]=k):k=e[27];const P=k;let N;e[28]!==t||e[29]!==R?(N=async()=>{if(!t.deleteSessionConfirm)return;const{session:M,archivedBucket:$}=t.deleteSessionConfirm;t.setDeleteSessionConfirm(null),await R(M,{archivedBucket:$})},e[28]=t,e[29]=R,e[30]=N):N=e[30];const D=N;let T;return e[31]!==D||e[32]!==r||e[33]!==y||e[34]!==v||e[35]!==P||e[36]!==b||e[37]!==u||e[38]!==p||e[39]!==g||e[40]!==A?(T={copiedSessionId:r,handleSessionSelect:p,handleSessionDoubleClick:u,handleSaveEdit:b,handleCancelEdit:y,handleShareSession:g,handleCopyShareUrl:v,handleUnshareSession:A,handleDeleteSession:P,confirmDeleteSession:D},e[31]=D,e[32]=r,e[33]=y,e[34]=v,e[35]=P,e[36]=b,e[37]=u,e[38]=p,e[39]=g,e[40]=A,e[41]=T):T=e[41],T};function vP(t){return t.id}const wP=t=>{const e=nt.c(41),{isVSCode:n,hasLoadedGlobalSessions:r,safeStorage:a,keys:i,sessions:o,pinnedSessionIds:c,setPinnedSessionIds:d,groupOrderByProject:p,activeSessionByProject:m,collapsedGroups:u,setExpandedParents:h,setCollapsedProjects:b}=t,f=l.useRef(null),y=l.useRef(null);let x;e[0]!==n?(x=()=>{if(n)return;const O=y.current;if(y.current=null,f.current=null,!O)return;const{projects:L}=Fs.getState(),W=L.map(B=>({...B,sidebarCollapsed:O.has(B.id)}));Rs({projects:W}).catch(jP)},e[0]=n,e[1]=x):x=e[1];const g=x;let w;e[2]!==g||e[3]!==n?(w=O=>{typeof window>"u"||n||(y.current=O,f.current!==null&&window.clearTimeout(f.current),f.current=window.setTimeout(()=>{g()},700))},e[2]=g,e[3]=n,e[4]=w):w=e[4];const v=w;let S,A;e[5]===Symbol.for("react.memo_cache_sentinel")?(S=()=>()=>{typeof window<"u"&&f.current!==null&&window.clearTimeout(f.current),f.current=null,y.current=null},A=[],e[5]=S,e[6]=A):(S=e[5],A=e[6]),l.useEffect(S,A);let j,C;e[7]!==i.projectCollapse||e[8]!==i.sessionExpanded||e[9]!==a||e[10]!==b||e[11]!==h?(j=()=>{try{const O=a.getItem(i.sessionExpanded);if(O){const W=JSON.parse(O);Array.isArray(W)&&h(new Set(W.filter(NP)))}const L=a.getItem(i.projectCollapse);if(L){const W=JSON.parse(L);Array.isArray(W)&&b(new Set(W.filter(SP)))}}catch{}},C=[i.projectCollapse,i.sessionExpanded,a,b,h],e[7]=i.projectCollapse,e[8]=i.sessionExpanded,e[9]=a,e[10]=b,e[11]=h,e[12]=j,e[13]=C):(j=e[12],C=e[13]),l.useEffect(j,C);let I,R;e[14]!==r||e[15]!==o||e[16]!==d?(I=()=>{if(!r)return;const O=new Set(o.map(kP));d(L=>{let W=!1;const B=new Set;return L.forEach(ne=>{O.has(ne)?B.add(ne):W=!0}),W?B:L})},R=[r,o,d],e[14]=r,e[15]=o,e[16]=d,e[17]=I,e[18]=R):(I=e[17],R=e[18]),l.useEffect(I,R);let k,P;e[19]!==i.sessionPinned||e[20]!==c||e[21]!==a?(k=()=>{try{a.setItem(i.sessionPinned,JSON.stringify(Array.from(c)))}catch{}},P=[i.sessionPinned,c,a],e[19]=i.sessionPinned,e[20]=c,e[21]=a,e[22]=k,e[23]=P):(k=e[22],P=e[23]),l.useEffect(k,P);let N,D;e[24]!==p||e[25]!==i.groupOrder||e[26]!==a?(N=()=>{try{const O=Object.fromEntries(p.entries());a.setItem(i.groupOrder,JSON.stringify(O))}catch{}},D=[p,i.groupOrder,a],e[24]=p,e[25]=i.groupOrder,e[26]=a,e[27]=N,e[28]=D):(N=e[27],D=e[28]),l.useEffect(N,D);let T,M;e[29]!==m||e[30]!==i.projectActiveSession||e[31]!==a?(T=()=>{try{const O=Object.fromEntries(m.entries());a.setItem(i.projectActiveSession,JSON.stringify(O))}catch{}},M=[m,i.projectActiveSession,a],e[29]=m,e[30]=i.projectActiveSession,e[31]=a,e[32]=T,e[33]=M):(T=e[32],M=e[33]),l.useEffect(T,M);let $,F;e[34]!==u||e[35]!==i.groupCollapse||e[36]!==a?($=()=>{try{a.setItem(i.groupCollapse,JSON.stringify(Array.from(u)))}catch{}},F=[u,i.groupCollapse,a],e[34]=u,e[35]=i.groupCollapse,e[36]=a,e[37]=$,e[38]=F):($=e[37],F=e[38]),l.useEffect($,F);let V;return e[39]!==v?(V={scheduleCollapsedProjectsPersist:v},e[39]=v,e[40]=V):V=e[40],V};function jP(){}function NP(t){return typeof t=="string"}function SP(t){return typeof t=="string"}function kP(t){return t.id}const CP=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},IP=t=>{const e=nt.c(23),{normalizedProjects:n,gitRepoStatus:r,setProjectRepoStatus:a,setProjectRootBranches:i}=t,{git:o}=Gn(),c=pn(AP);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 CP(n,2,DP);x||i(v=>{const S=new Map(v);return w.forEach(A=>{const{id:j,branch:C}=A;C&&S.set(j,C)}),S})})(),()=>{x=!0}},e[16]=n,e[17]=i,e[18]=f):f=e[18];let y;e[19]!==n||e[20]!==b||e[21]!==i?(y=[n,b,i],e[19]=n,e[20]=b,e[21]=i,e[22]=y):y=e[22],l.useEffect(f,y)};function AP(t){return t.ensureStatus}function PP(){return null}async function DP(t){const e=await zo(t.normalizedPath).catch(PP);return{id:t.id,branch:e}}const TP=t=>{const e=nt.c(14),{isVSCode:n,sessions:r,archivedSessions:a,availableWorktreesByProject:i}=t;let o;e[0]!==r?(o=new Map,r.forEach(b=>{const f=ks(b.directory??null)??ks(b.project?.worktree??null);if(!f)return;const y=o.get(f)??[];y.push(b),o.set(f,y)}),e[0]=r,e[1]=o):o=e[1];const c=o;let d;e[2]!==i||e[3]!==n||e[4]!==c?(d=b=>{const f=n?[]:i.get(b.normalizedPath)??[],y=[b.normalizedPath,...f.map(MP).filter(RP)],x=new Set,g=[];return y.forEach(w=>{(c.get(w)??[]).forEach(S=>{x.has(S.id)||(x.add(S.id),g.push(S))})}),g},e[2]=i,e[3]=n,e[4]=c,e[5]=d):d=e[5];const p=d;let m;e[6]!==a||e[7]!==i||e[8]!==n||e[9]!==r?(m=b=>{if(n){const v=a.filter(A=>{const j=ks(A.directory??null),C=ks(A.project?.worktree??null);return j?j===b.normalizedPath:C===b.normalizedPath}),S=r.filter(A=>A.time?.archived||ks(A.directory??null)?!1:ks(A.project?.worktree??null)===b.normalizedPath);return qi([...v,...S])}const f=n?[]:i.get(b.normalizedPath)??[],y=new Set([b.normalizedPath,...f.map(EP).filter(FP)]),g=(v=>v.filter(S=>Mo(S,b.normalizedPath,y)))(a),w=r.filter(v=>{if(v.time?.archived||ks(v.directory??null))return!1;const A=ks(v.project?.worktree??null);return A?A===b.normalizedPath||A.startsWith(`${b.normalizedPath}/`):!1});return qi([...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 MP(t){return ks(t.path)??t.path}function RP(t){return!!t}function EP(t){return ks(t.path)??t.path}function FP(t){return!!t}const OP=t=>{const e=nt.c(9),{isSessionsLoading:n,sessions:r,archivedSessions:a,normalizedProjects:i,isVSCode:o,availableWorktreesByProject:c,cleanupSessions:d}=t;let p,m;e[0]!==a||e[1]!==c||e[2]!==d||e[3]!==n||e[4]!==o||e[5]!==i||e[6]!==r?(p=()=>{if(n)return;const u=new Map;r.forEach(f=>{const y=ks(f.directory??null);if(!y)return;const x=u.get(y);if(x){x.add(f.id);return}u.set(y,new Set([f.id]))}),i.forEach(f=>{const y=zu(f.normalizedPath),x=o?[]:c.get(f.normalizedPath)??[],g=new Set([f.normalizedPath,...x.map(LP).filter($P)]),w=qi([...a,...r.filter(v=>v.time?.archived||ks(v.directory??null)?!1:Mo(v,f.normalizedPath,g))]).filter(v=>Mo(v,f.normalizedPath,g));u.set(y,new Set(w.map(BP)))});const h=rr.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 LP(t){return ks(t.path)??t.path}function $P(t){return!!t}function BP(t){return t.id}const VP=t=>{const e=nt.c(8),{isDesktopShellRuntime:n,projectSections:r,projectHeaderSentinelRefs:a}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=new Set,e[0]=i):i=e[0];const[o,c]=l.useState(i);let d;e[1]!==n||e[2]!==a?(d=()=>{if(!n)return;const m=new IntersectionObserver(u=>{u.forEach(h=>{const b=h.target.dataset.projectId;b&&c(f=>{const y=new Set(f);return h.isIntersecting?y.delete(b):y.add(b),y})})},{threshold:0});return a.current.forEach(u=>{u&&m.observe(u)}),()=>m.disconnect()},e[1]=n,e[2]=a,e[3]=d):d=e[3];let p;return e[4]!==n||e[5]!==a||e[6]!==r?(p=[n,a,r],e[4]=n,e[5]=a,e[6]=r,e[7]=p):p=e[7],l.useEffect(d,p),o},zP=t=>{const e=nt.c(85),{folder:n,sessions:r,subFolderItems:a,isCollapsed:i,onToggle:o,onRename:c,onDelete:d,renderSessionNode:p,groupDirectory:m,projectId:u,mobileVariant:h,alwaysShowActions:b,isRenaming:f,renameDraft:y,onRenameDraftChange:x,onRenameSave:g,onRenameCancel:w,droppableRef:v,isDropTarget:S,onNewSession:A,onNewSubFolder:j,depth:C,hideActions:I,archivedBucket:R}=t,P=b===void 0?h===void 0?!1:h:b,N=f===void 0?!1:f,D=y===void 0?"":y,T=S===void 0?!1:S,M=C===void 0?0:C,$=I===void 0?!1:I,F=R===void 0?!1:R,{t:V}=ut(),[O,L]=l.useState(!1),[W,B]=l.useState(""),ne=l.useRef(null),le=N||O,ee=N?D:W;let ae;e[0]!==n.name?(ae=()=>{B(n.name),L(!0)},e[0]=n.name,e[1]=ae):ae=e[1];const ge=ae;let te;e[2]!==ee||e[3]!==n.name||e[4]!==N||e[5]!==c||e[6]!==g?(te=()=>{const de=ee.trim();de&&de!==n.name&&c(de),N&&g&&g(),L(!1),B("")},e[2]=ee,e[3]=n.name,e[4]=N,e[5]=c,e[6]=g,e[7]=te):te=e[7];const E=te;let z;e[8]!==N||e[9]!==w?(z=()=>{N&&w&&w(),L(!1),B("")},e[8]=N,e[9]=w,e[10]=z):z=e[10];const J=z;let H;e[11]!==N||e[12]!==x?(H=de=>{N&&x?x(de):B(de)},e[11]=N,e[12]=x,e[13]=H):H=e[13];const re=H;let ce,Ne;e[14]!==N?(ce=()=>{if(!N)return;const de=()=>{const se=ne.current;se&&(se.focus(),se.select())},Re=requestAnimationFrame(de),Le=window.setTimeout(de,0);return()=>{cancelAnimationFrame(Re),window.clearTimeout(Le)}},Ne=[N],e[14]=N,e[15]=ce,e[16]=Ne):(ce=e[15],Ne=e[16]),l.useEffect(ce,Ne);const me=i?zn:Gy,_=M>0&&"ml-3";let ue;e[17]!==_?(ue=pe("oc-folder",_),e[17]=_,e[18]=ue):ue=e[18];const Q=T&&"bg-primary/10 ring-1 ring-inset ring-primary/30";let oe;e[19]!==Q?(oe=pe("group/folder relative flex items-center justify-between gap-1.5 py-1 min-w-0 rounded-md","cursor-pointer",Q),e[19]=Q,e[20]=oe):oe=e[20];const Z=le?void 0:o,Ie=le?void 0:"button",Se=le?void 0:0;let Y;e[21]!==o||e[22]!==le?(Y=le?void 0:de=>{(de.key==="Enter"||de.key===" ")&&(de.preventDefault(),o())},e[21]=o,e[22]=le,e[23]=Y):Y=e[23];let fe;e[24]!==n.name||e[25]!==i||e[26]!==V?(fe=i?V("sessions.sidebar.folderItem.expandAria",{folderName:n.name}):V("sessions.sidebar.folderItem.collapseAria",{folderName:n.name}),e[24]=n.name,e[25]=i,e[26]=V,e[27]=fe):fe=e[27];const ke=F?P?"pr-7":"group-hover/folder:pr-7 group-focus-within/folder:pr-7":"";let xe;e[28]!==ke?(xe=pe("min-w-0 flex items-center gap-1.5 pl-1.5 flex-1 transition-[padding]",ke),e[28]=ke,e[29]=xe):xe=e[29];const he=T?"text-primary":"text-muted-foreground";let Pe;e[30]!==he?(Pe=pe("h-3.5 w-3.5 flex-shrink-0",he),e[30]=he,e[31]=Pe):Pe=e[31];let Be;e[32]!==me||e[33]!==Pe?(Be=s.jsx(me,{className:Pe}),e[32]=me,e[33]=Pe,e[34]=Be):Be=e[34];let G;e[35]!==ee||e[36]!==n.name||e[37]!==J||e[38]!==re||e[39]!==E||e[40]!==i||e[41]!==T||e[42]!==le||e[43]!==r||e[44]!==V?(G=le?s.jsxs("form",{className:"flex min-w-0 flex-1 items-center gap-1",onPointerDown:UP,onMouseDown:WP,onSubmit:de=>{de.preventDefault(),E()},children:[s.jsx("input",{ref:ne,value:ee,onChange:de=>re(de.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",autoFocus:!0,placeholder:V("sessions.sidebar.folderItem.namePlaceholder"),onClick:KP,onPointerDown:HP,onMouseDown:GP,onKeyDown:de=>{if(de.key==="Escape"){de.stopPropagation(),J();return}(de.key===" "||de.key==="Enter")&&de.stopPropagation()}}),s.jsx("button",{type:"submit",className:"shrink-0 text-muted-foreground hover:text-foreground",onClick:qP,onPointerDown:QP,onMouseDown:JP,children:s.jsx(Ys,{className:"size-4"})}),s.jsx("button",{type:"button",onClick:de=>{de.stopPropagation(),J()},onPointerDown:YP,onMouseDown:XP,className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(Ds,{className:"size-4"})})]}):s.jsxs("div",{className:"min-w-0 flex items-center gap-1.5 flex-1",children:[s.jsx("span",{className:pe("typography-ui-label font-semibold truncate",T?"text-primary":"text-muted-foreground"),children:n.name}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70 flex-shrink-0",children:["• ",r.length]}),i?s.jsx(Fn,{className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):s.jsx(Cs,{className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"})]}),e[35]=ee,e[36]=n.name,e[37]=J,e[38]=re,e[39]=E,e[40]=i,e[41]=T,e[42]=le,e[43]=r,e[44]=V,e[45]=G):G=e[45];let be;e[46]!==xe||e[47]!==Be||e[48]!==G?(be=s.jsxs("div",{className:xe,children:[Be,G]}),e[46]=xe,e[47]=Be,e[48]=G,e[49]=be):be=e[49];let De;e[50]!==P||e[51]!==F||e[52]!==M||e[53]!==n.name||e[54]!==ge||e[55]!==$||e[56]!==d||e[57]!==A||e[58]!==j||e[59]!==le||e[60]!==V?(De=!le&&(!$||F)?s.jsx("div",{className:"flex items-center gap-0.5 px-0.5",children:s.jsxs("div",{className:pe("flex items-center gap-0.5 transition-opacity",P?"opacity-100":"opacity-0 group-hover/folder:opacity-100 group-focus-within/folder:opacity-100",F&&"absolute right-0.5 top-1/2 z-10 -translate-y-1/2 px-0"),children:[!F&&A?s.jsx("button",{type:"button",onClick:de=>{de.stopPropagation(),A()},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":V("sessions.sidebar.folderItem.newSessionAria",{folderName:n.name}),title:V("sessions.sidebar.project.actions.newSession"),children:s.jsx(_s,{className:"h-3.5 w-3.5"})}):null,!F&&j&&M===0?s.jsx("button",{type:"button",onClick:de=>{de.stopPropagation(),j()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":V("sessions.sidebar.folderItem.newSubfolderAria",{folderName:n.name}),title:V("sessions.sidebar.folderItem.newSubfolder"),children:s.jsx(Ca,{className:"h-3.5 w-3.5"})}):null,F?null:s.jsx("button",{type:"button",onClick:de=>{de.stopPropagation(),ge()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":V("sessions.sidebar.folderItem.renameAria",{folderName:n.name}),children:s.jsx(Mi,{className:"h-3.5 w-3.5"})}),s.jsx("button",{type:"button",onClick:de=>{de.stopPropagation(),d()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":F?V("sessions.sidebar.folderItem.deleteArchivedInFolderAria",{folderName:n.name}):V("sessions.sidebar.folderItem.deleteFolderAria",{folderName:n.name}),children:s.jsx(sn,{className:"h-3.5 w-3.5"})})]})}):null,e[50]=P,e[51]=F,e[52]=M,e[53]=n.name,e[54]=ge,e[55]=$,e[56]=d,e[57]=A,e[58]=j,e[59]=le,e[60]=V,e[61]=De):De=e[61];let Ae;e[62]!==v||e[63]!==oe||e[64]!==Z||e[65]!==Ie||e[66]!==Se||e[67]!==Y||e[68]!==fe||e[69]!==be||e[70]!==De?(Ae=s.jsxs("div",{ref:v,className:oe,onClick:Z,role:Ie,tabIndex:Se,onKeyDown:Y,"aria-label":fe,children:[be,De]}),e[62]=v,e[63]=oe,e[64]=Z,e[65]=Ie,e[66]=Se,e[67]=Y,e[68]=fe,e[69]=be,e[70]=De,e[71]=Ae):Ae=e[71];let ve;e[72]!==F||e[73]!==m||e[74]!==i||e[75]!==u||e[76]!==p||e[77]!==r||e[78]!==a||e[79]!==V?(ve=i?null:s.jsxs("div",{className:"pb-1 pl-2",children:[a,r.length>0?r.map(de=>p(de,0,m??null,u??null,F)):a?null:s.jsx("div",{className:"py-1 pl-1.5 text-left typography-micro text-muted-foreground/70",children:V("sessions.sidebar.folderItem.emptyFolder")})]}),e[72]=F,e[73]=m,e[74]=i,e[75]=u,e[76]=p,e[77]=r,e[78]=a,e[79]=V,e[80]=ve):ve=e[80];let U;return e[81]!==ue||e[82]!==Ae||e[83]!==ve?(U=s.jsxs("div",{className:ue,children:[Ae,ve]}),e[81]=ue,e[82]=Ae,e[83]=ve,e[84]=U):U=e[84],U},_P=l.memo(zP);function UP(t){return t.stopPropagation()}function WP(t){return t.stopPropagation()}function KP(t){return t.stopPropagation()}function HP(t){return t.stopPropagation()}function GP(t){return t.stopPropagation()}function qP(t){return t.stopPropagation()}function QP(t){return t.stopPropagation()}function JP(t){return t.stopPropagation()}function YP(t){return t.stopPropagation()}function XP(t){return t.stopPropagation()}const ZP=t=>{const e=nt.c(15),{sessionId:n,sessionDirectory:r,sessionTitle:a,children:i}=t,o=`session-drag:${n}`;let c;e[0]!==r||e[1]!==n||e[2]!==a?(c={type:"session",sessionId:n,sessionDirectory:r,sessionTitle:a},e[0]=r,e[1]=n,e[2]=a,e[3]=c):c=e[3];let d;e[4]!==o||e[5]!==c?(d={id:o,data:c},e[4]=o,e[5]=c,e[6]=d):d=e[6];const{attributes:p,listeners:m,setNodeRef:u,isDragging:h}=qy(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,y=h?"opacity-30":void 0;let x;return e[9]!==p||e[10]!==i||e[11]!==f||e[12]!==u||e[13]!==y?(x=s.jsx("div",{ref:u,...p,onPointerDown:f,className:y,children:i}),e[9]=p,e[10]=i,e[11]=f,e[12]=u,e[13]=y,e[14]=x):x=e[14],x},eD=t=>{const e=nt.c(11),{folderId:n,children:r}=t,a=`folder-drop:${n}`;let i;e[0]!==n?(i={type:"folder",folderId:n},e[0]=n,e[1]=i):i=e[1];let o;e[2]!==a||e[3]!==i?(o={id:a,data:i},e[2]=a,e[3]=i,e[4]=o):o=e[4];const{setNodeRef:c,isOver:d}=Qy(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},tD=t=>{const e=nt.c(20),{scopeKey:n,hasFolders:r,onSessionDroppedOnFolder:a,children:i}=t;let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o={activationConstraint:{distance:8}},e[0]=o):o=e[0];const c=Ol(yo(Ll,o)),[d,p]=l.useState(null),[m,u]=l.useState("Session"),[h,b]=l.useState(null),[f,y]=l.useState(null);if(!n){let C;return e[1]!==i?(C=s.jsx(s.Fragment,{children:i}),e[1]=i,e[2]=C):C=e[2],C}let x;e[3]!==a?(x=C=>{p(null),b(null),y(null);const{active:I,over:R}=C;if(!R)return;const k=I.data.current,P=R.data.current;k?.type==="session"&&k.sessionId&&P?.type==="folder"&&P.folderId&&a(k.sessionId,P.folderId)},e[3]=a,e[4]=x):x=e[4];const g=x;let w,v;e[5]===Symbol.for("react.memo_cache_sentinel")?(w=C=>{const I=C.active.data.current;if(I?.type==="session"&&I.sessionId){p(I.sessionId),u(I.sessionTitle??"Session");const R=C.active.rect.current.initial?.width,k=C.active.rect.current.initial?.height;b(typeof R=="number"?R:null),y(typeof k=="number"?k:null)}},v=()=>{p(null),b(null),y(null)},e[5]=w,e[6]=v):(w=e[5],v=e[6]);let S;e[7]!==f||e[8]!==d||e[9]!==m||e[10]!==h||e[11]!==r?(S=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(Jy,{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]=S):S=e[12];let A;e[13]!==S?(A=s.jsx($l,{children:S}),e[13]=S,e[14]=A):A=e[14];let j;return e[15]!==i||e[16]!==g||e[17]!==c||e[18]!==A?(j=s.jsxs(Bl,{sensors:c,collisionDetection:Vl,onDragStart:w,onDragCancel:v,onDragEnd:g,children:[i,A]}),e[15]=i,e[16]=g,e[17]=c,e[18]=A,e[19]=j):j=e[19],j},Ha=wr()($o(t=>({displayMode:"default",showRecentSection:!0,setDisplayMode:e=>t({displayMode:e}),setShowRecentSection:e=>t({showRecentSection:e}),toggleRecentSection:()=>t(e=>({showRecentSection:!e.showRecentSection}))}),{name:"session-display-mode"}));function sD(t){const e=nt.c(289),{t:n}=ut(),{group:r,groupKey:a,projectId:i,hideGroupLabel:o,hasSessionSearchQuery:c,normalizedSessionSearchQuery:d,groupSearchDataByGroup:p,expandedSessionGroups:m,collapsedGroups:u,hideDirectoryControls:h,collapsedFolderIds:b,toggleFolderCollapse:f,renameFolder:y,deleteFolder:x,showDeletionDialog:g,setDeleteFolderConfirm:w,renderSessionNode:v,projectRepoStatus:S,lastRepoStatus:A,toggleGroupSessionLimit:j,mobileVariant:C,alwaysShowActions:I,activeProjectId:R,setActiveProjectIdOnly:k,setActiveMainTab:P,setSessionSwitcherOpen:N,openNewSessionDraft:D,addSessionToFolder:T,createFolderAndStartRename:M,renamingFolderId:$,renameFolderDraft:F,setRenameFolderDraft:V,setRenamingFolderId:O,pinnedSessionIds:L,sessionOrderIndex:W,prVisualStateByDirectoryBranch:B,onToggleCollapsedGroup:ne,dragHandleProps:le,compactBodyPadding:ee}=t,ae=ee===void 0?!1:ee;let ge;e[0]!==L||e[1]!==W?(ge=(st,Lt)=>{const ls=W.get(st.session.id),rs=W.get(Lt.session.id);if(ls!==void 0||rs!==void 0){if(ls===void 0)return 1;if(rs===void 0)return-1;if(ls!==rs)return ls-rs}return Oi(st.session,Lt.session,L)},e[0]=L,e[1]=W,e[2]=ge):ge=e[2];const te=ge;let E;e[3]!==r||e[4]!==p||e[5]!==c?(E=c?p.get(r):null,e[3]=r,e[4]=p,e[5]=c,e[6]=E):E=e[6];const z=E,J=Ha(uD),H=rr(dD),re=J==="minimal";let ce;e[7]!==m||e[8]!==a?(ce=m.has(a),e[7]=m,e[8]=a,e[9]=ce):ce=e[9];const Ne=ce;let me;e[10]!==u||e[11]!==a||e[12]!==c?(me=c?!1:u.has(a),e[10]=u,e[11]=a,e[12]=c,e[13]=me):me=e[13];const we=me,_=h?10:5,ue=c?z?.groupMatches===!0:!1,Q=c;z?.filteredNodes;let oe;e[14]!==te||e[15]!==r.sessions||e[16]!==z?.filteredNodes||e[17]!==Q?(oe=[...Q?z?.filteredNodes??[]:r.sessions].sort(te),e[14]=te,e[15]=r.sessions,e[16]=z?.filteredNodes,e[17]=Q,e[18]=oe):oe=e[18];const Z=oe;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 Se=Ie;let Y;e[22]!==Se||e[23]!==H?(Y=Se?H[Se]??[]:[],e[22]=Se,e[23]=H,e[24]=Y):Y=e[24];const fe=Y;let ke;if(e[25]!==Z){ke=new Map;const st=Lt=>{Lt.forEach(ls=>{ke.set(ls.session.id,ls),ls.children.length>0&&st(ls.children)})};st(Z),e[25]=Z,e[26]=ke}else ke=e[26];const xe=ke;let he;if(e[27]!==te||e[28]!==xe||e[29]!==fe){let st;e[31]!==te||e[32]!==xe?(st=Lt=>{const ls=Lt.sessionIds.map(rs=>xe.get(rs)).filter(cD).sort(te);return{folder:Lt,nodes:ls}},e[31]=te,e[32]=xe,e[33]=st):st=e[33],he=fe.map(st),e[27]=te,e[28]=xe,e[29]=fe,e[30]=he}else he=e[30];const Pe=he;let Be;if(e[34]!==Pe||e[35]!==r.isArchivedBucket||e[36]!==c||e[37]!==d){const st=new Map(Pe.map(lD)),Lt=new Map;for(const{folder:Bt}of Pe){if(!Bt.parentId)continue;const xs=Lt.get(Bt.parentId);xs?xs.push(Bt.id):Lt.set(Bt.parentId,[Bt.id])}const ls=new Map,rs=Bt=>{const xs=ls.get(Bt);if(xs!==void 0)return xs;const mn=st.get(Bt);if(!mn)return ls.set(Bt,!1),!1;const js=Lt.get(Bt)??[];if(r.isArchivedBucket&&mn.nodes.length===0){const an=js.some(An=>rs(An));return ls.set(Bt,an),an}if(!c||mn.folder.name.toLowerCase().includes(d)||mn.nodes.length>0)return ls.set(Bt,!0),!0;const In=js.some(an=>rs(an));return ls.set(Bt,In),In};Be=Pe.filter(Bt=>{const{folder:xs}=Bt;return rs(xs.id)}),e[34]=Pe,e[35]=r.isArchivedBucket,e[36]=c,e[37]=d,e[38]=Be}else Be=e[38];const G=Be;let be;e[39]!==G?(be=new Set(G.flatMap(oD)),e[39]=G,e[40]=be):be=e[40];const De=be;let Ae;if(e[41]!==De||e[42]!==Z){let st;e[44]!==De?(st=Lt=>!De.has(Lt.session.id),e[44]=De,e[45]=st):st=e[45],Ae=Z.filter(st),e[41]=De,e[42]=Z,e[43]=Ae}else Ae=e[43];const ve=Ae;let U;e[46]!==G?(U=G.filter(iD),e[46]=G,e[47]=U):U=e[47];const de=U;if(c&&!ue&&de.length===0&&ve.length===0)return null;const Re=ve.length;let Le;e[48]!==r.isArchivedBucket||e[49]!==c||e[50]!==Ne||e[51]!==_||e[52]!==ve?(Le=r.isArchivedBucket||c||Ne?ve:ve.slice(0,_),e[48]=r.isArchivedBucket,e[49]=c,e[50]=Ne,e[51]=_,e[52]=ve,e[53]=Le):Le=e[53];const se=Le,ie=Re-se.length,K=aD;let _e;e[54]!==Z?(_e=K(Z),e[54]=Z,e[55]=_e):_e=e[55];const He=_e;let Ke;e[56]!==A||e[57]!==i||e[58]!==S?(Ke=i&&S.has(i)?!!S.get(i):A,e[56]=A,e[57]=i,e[58]=S,e[59]=Ke):Ke=e[59];const Ze=Ke,Xe=r.directory??null;let mt;e[60]!==Xe?(mt=ks(Xe),e[60]=Xe,e[61]=mt):mt=e[61];const et=mt;let ct;e[62]!==r.branch?(ct=r.branch?.trim()??null,e[62]=r.branch,e[63]=ct):ct=e[63];const lt=ct;let ye,Ge,$e,Ve,tt,Qe,ze,ht;e[64]!==r.branch||e[65]!==r.isMain||e[66]!==lt||e[67]!==et||e[68]!==B||e[69]!==n?(Ve=et&&lt?B.get(`${et}::${lt}`)??null:null,ze=!!(Ve&&r.branch),Qe=!Ve&&!r.isMain&&!!r.branch,tt=Ve?.visualState??null,ye=Ve&&Ve.state==="open"&&Ve.checks?n("sessions.sidebar.group.pr.checksPassed",{success:Ve.checks.success,total:Ve.checks.total}):null,Ge=Ve&&Ve.state==="open"&&Ve.checks?[Ve.checks.failure>0?n("sessions.sidebar.group.pr.failingCount",{count:Ve.checks.failure}):null,Ve.checks.pending>0?n("sessions.sidebar.group.pr.pendingCount",{count:Ve.checks.pending}):null].filter(rD).join(", "):null,$e=Ve&&Ve.state==="open"?Ve.mergeableState==="blocked"||Ve.mergeableState==="dirty"?n("sessions.sidebar.group.pr.conflictsOrBlocked"):Ve.mergeableState==="clean"||Ve.canMerge===!0?n("sessions.sidebar.group.pr.mergeable"):null:null,ht=Ve&&Ve.state==="open"&&Ve.mergeableState?n("sessions.sidebar.group.pr.mergeState",{state:Ve.mergeableState}):null,e[64]=r.branch,e[65]=r.isMain,e[66]=lt,e[67]=et,e[68]=B,e[69]=n,e[70]=ye,e[71]=Ge,e[72]=$e,e[73]=Ve,e[74]=tt,e[75]=Qe,e[76]=ze,e[77]=ht):(ye=e[70],Ge=e[71],$e=e[72],Ve=e[73],tt=e[74],Qe=e[75],ze=e[76],ht=e[77]);const _t=ht,Kt=Ve?.base??null,Ut=Ve?.head??null;let jt;e:{if(!Ve){let st;e[78]!==r.branch||e[79]!==r.label?(st=r.branch&&q1(r.branch,r.label)?{label:r.branch,color:null}:null,e[78]=r.branch,e[79]=r.label,e[80]=st):st=e[80],jt=st;break e}switch(Ve.visualState){case"merged":{let st;e[81]!==n?(st=n("sessions.sidebar.group.pr.status.merged"),e[81]=n,e[82]=st):st=e[82];let Lt;e[83]!==st?(Lt={label:st,color:"var(--pr-merged)"},e[83]=st,e[84]=Lt):Lt=e[84],jt=Lt;break e}case"open":{let st;e[85]!==Ve.canMerge||e[86]!==Ve.checks?.state||e[87]!==Ve.mergeableState||e[88]!==n?(st=Ve.canMerge===!0||Ve.mergeableState==="clean"||Ve.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]=Ve.canMerge,e[86]=Ve.checks?.state,e[87]=Ve.mergeableState,e[88]=n,e[89]=st):st=e[89],jt=st;break e}case"blocked":{let st;e[90]!==Ve.mergeableState||e[91]!==n?(st=Ve.mergeableState==="dirty"?n("sessions.sidebar.group.pr.status.mergeConflicts"):n("sessions.sidebar.group.pr.status.mergeBlocked"),e[90]=Ve.mergeableState,e[91]=n,e[92]=st):st=e[92];let Lt;e[93]!==st?(Lt={label:st,color:"var(--pr-blocked)"},e[93]=st,e[94]=Lt):Lt=e[94],jt=Lt;break e}case"draft":{let st;e[95]!==n?(st=n("sessions.sidebar.group.pr.status.draft"),e[95]=n,e[96]=st):st=e[96];let Lt;e[97]!==st?(Lt={label:st,color:"var(--pr-draft)"},e[97]=st,e[98]=Lt):Lt=e[98],jt=Lt;break e}case"closed":{let st;e[99]!==n?(st=n("sessions.sidebar.group.pr.status.closed"),e[99]=n,e[100]=st):st=e[100];let Lt;e[101]!==st?(Lt={label:st,color:"var(--pr-closed)"},e[101]=st,e[102]=Lt):Lt=e[102],jt=Lt;break e}default:jt=null}}const Dt=jt,ts=Dt?.color??(tt?`var(--pr-${tt})`:void 0);let it;e[103]!==Ve?.url?(it=st=>{st.preventDefault(),st.stopPropagation();const Lt=Ve?.url;Lt&&lr(Lt)},e[103]=Ve?.url,e[104]=it):it=e[104];const Yt=it;let Qt,Xt,us,ms,gs,ds;if(e[105]!==R||e[106]!==T||e[107]!==G||e[108]!==I||e[109]!==b||e[110]!==M||e[111]!==x||e[112]!==Se||e[113]!==r.directory||e[114]!==r.isArchivedBucket||e[115]!==r.isMain||e[116]!==r.worktree||e[117]!==c||e[118]!==re||e[119]!==C||e[120]!==D||e[121]!==i||e[122]!==y||e[123]!==F||e[124]!==$||e[125]!==v||e[126]!==de||e[127]!==P||e[128]!==k||e[129]!==w||e[130]!==V||e[131]!==O||e[132]!==N||e[133]!==g||e[134]!==f){const st=(rs,Bt,xs)=>{const mn=G.filter(an=>{const{folder:An}=an;return An.parentId===rs.id}),js=mn.length>0?s.jsx(s.Fragment,{children:mn.map(an=>{const{folder:An,nodes:on}=an;return st(An,on,xs+1)})}):void 0,xn=an=>{const An=G.find(ln=>{const{folder:fn}=ln;return fn.id===an})?.nodes??[],on=G.filter(ln=>{const{folder:fn}=ln;return fn.parentId===an});return[...K(An),...on.flatMap(ln=>{const{folder:fn}=ln;return xn(fn.id)})]},In=r.isArchivedBucket?xn(rs.id):[];return s.jsx(eD,{folderId:rs.id,children:(an,An)=>s.jsx(_P,{folder:rs,sessions:Bt,subFolderItems:js,isCollapsed:c?!1:b.has(rs.id),onToggle:()=>f(rs.id),onRename:on=>{Se&&y(Se,rs.id,on)},onDelete:()=>{if(r.isArchivedBucket){Dr.requestDelete({sessions:In,mode:"session"});return}if(!Se)return;if(!g){x(Se,rs.id);return}const on=G.filter(fn=>{const{folder:cr}=fn;return cr.parentId===rs.id}).length,ln=Bt.length;w({scopeKey:Se,folderId:rs.id,folderName:rs.name,subFolderCount:on,sessionCount:ln})},renderSessionNode:v,groupDirectory:r.directory,projectId:i,mobileVariant:C,alwaysShowActions:I,isRenaming:$===rs.id,renameDraft:$===rs.id?F:void 0,onRenameDraftChange:on=>V(on),onRenameSave:()=>{const on=F.trim();on&&Se&&y(Se,rs.id,on),O(null),V("")},onRenameCancel:()=>{O(null),V("")},droppableRef:an,isDropTarget:An,depth:xs,onNewSession:()=>{i&&i!==R&&k(i),P("chat"),C&&N(!1),D({directoryOverride:r.directory,targetFolderId:rs.id})},onNewSubFolder:xs===0?()=>{Se&&M(Se,rs.id)}:void 0,hideActions:!1,archivedBucket:r.isArchivedBucket===!0})},rs.id)},Lt=()=>de.map(rs=>{const{folder:Bt,nodes:xs}=rs;return st(Bt,xs,0)}),ls=!!(!r.isMain&&r.worktree);Xt=I?ls?"pr-14":"pr-7":re?ls?"pr-2 group-hover/gh:pr-14 group-focus-within/gh:pr-14":"pr-2":ls?"pr-5 group-hover/gh:pr-14 group-focus-within/gh:pr-14":"pr-5",Qt=tD,us=Se,ms=G.length>0,e[141]!==T||e[142]!==Se?(gs=(rs,Bt)=>{Se&&T(Se,Bt,rs)},e[141]=T,e[142]=Se,e[143]=gs):gs=e[143],ds=Lt(),e[105]=R,e[106]=T,e[107]=G,e[108]=I,e[109]=b,e[110]=M,e[111]=x,e[112]=Se,e[113]=r.directory,e[114]=r.isArchivedBucket,e[115]=r.isMain,e[116]=r.worktree,e[117]=c,e[118]=re,e[119]=C,e[120]=D,e[121]=i,e[122]=y,e[123]=F,e[124]=$,e[125]=v,e[126]=de,e[127]=P,e[128]=k,e[129]=w,e[130]=V,e[131]=O,e[132]=N,e[133]=g,e[134]=f,e[135]=Qt,e[136]=Xt,e[137]=us,e[138]=ms,e[139]=gs,e[140]=ds}else Qt=e[135],Xt=e[136],us=e[137],ms=e[138],gs=e[139],ds=e[140];let Ft;if(e[144]!==r.directory||e[145]!==r.isArchivedBucket||e[146]!==i||e[147]!==v||e[148]!==se){let st;e[150]!==r.directory||e[151]!==r.isArchivedBucket||e[152]!==i||e[153]!==v?(st=Lt=>v(Lt,0,r.directory,i,r.isArchivedBucket===!0),e[150]=r.directory,e[151]=r.isArchivedBucket,e[152]=i,e[153]=v,e[154]=st):st=e[154],Ft=se.map(st),e[144]=r.directory,e[145]=r.isArchivedBucket,e[146]=i,e[147]=v,e[148]=se,e[149]=Ft}else Ft=e[149];let Ue;e[155]!==G.length||e[156]!==r.isArchivedBucket||e[157]!==n||e[158]!==Re?(Ue=Re===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]=Re,e[159]=Ue):Ue=e[159];let Tt;e[160]!==a||e[161]!==Ne||e[162]!==ie||e[163]!==n||e[164]!==j?(Tt=ie>0&&!Ne?s.jsx("button",{type:"button",onClick:()=>j(a),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:ie===1?n("sessions.sidebar.group.showMoreSingle",{count:ie}):n("sessions.sidebar.group.showMorePlural",{count:ie})}):null,e[160]=a,e[161]=Ne,e[162]=ie,e[163]=n,e[164]=j,e[165]=Tt):Tt=e[165];let At;e[166]!==a||e[167]!==Ne||e[168]!==_||e[169]!==n||e[170]!==j||e[171]!==Re?(At=Ne&&Re>_?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]=Ne,e[168]=_,e[169]=n,e[170]=j,e[171]=Re,e[172]=At):At=e[172];let vt;e[173]!==Qt||e[174]!==us||e[175]!==ms||e[176]!==gs||e[177]!==ds||e[178]!==Ft||e[179]!==Ue||e[180]!==Tt||e[181]!==At?(vt=s.jsxs(Qt,{scopeKey:us,hasFolders:ms,onSessionDroppedOnFolder:gs,children:[ds,Ft,Ue,Tt,At]}),e[173]=Qt,e[174]=us,e[175]=ms,e[176]=gs,e[177]=ds,e[178]=Ft,e[179]=Ue,e[180]=Tt,e[181]=At,e[182]=vt):vt=e[182];const Rt=vt,ns=ae?"pb-2 pl-1":"pb-3 pl-4";if(o){let st;e[183]!==ns?(st=pe("oc-group-body",ns),e[183]=ns,e[184]=st):st=e[184];let Lt;return e[185]!==Rt||e[186]!==st?(Lt=s.jsx("div",{className:"oc-group",children:s.jsx("div",{className:st,children:Rt})}),e[185]=Rt,e[186]=st,e[187]=Lt):Lt=e[187],Lt}let As;e[188]===Symbol.for("react.memo_cache_sentinel")?(As=pe("group/gh relative flex items-start justify-between gap-1 py-1 min-w-0 rounded-md","cursor-pointer"),e[188]=As):As=e[188];let ft;e[189]!==a||e[190]!==ne?(ft=()=>ne(a),e[189]=a,e[190]=ne,e[191]=ft):ft=e[191];let is;e[192]!==a||e[193]!==ne?(is=st=>{(st.key==="Enter"||st.key===" ")&&(st.preventDefault(),ne(a))},e[192]=a,e[193]=ne,e[194]=is):is=e[194];let es;e[195]!==r.label||e[196]!==we||e[197]!==n?(es=we?n("sessions.sidebar.group.expandAria",{label:r.label}):n("sessions.sidebar.group.collapseAria",{label:r.label}),e[195]=r.label,e[196]=we,e[197]=n,e[198]=es):es=e[198];const Ts=!we,Ls=le?.setActivatorNodeRef;let X;e[199]!==Xt?(X=pe("min-w-0 flex flex-1 items-start gap-1 overflow-hidden pl-0.5 transition-[padding] cursor-grab active:cursor-grabbing",Xt),e[199]=Xt,e[200]=X):X=e[200];let pt;e[201]!==le?.listeners?(pt=le?.listeners??{},e[201]=le?.listeners,e[202]=pt):pt=e[202];let wt;e[203]!==I||e[204]!==Kt||e[205]!==ts||e[206]!==ye||e[207]!==Ge||e[208]!==r.branch||e[209]!==r.isArchivedBucket||e[210]!==r.isMain||e[211]!==r.label||e[212]!==r.worktree||e[213]!==Yt||e[214]!==Ut||e[215]!==we||e[216]!==_t||e[217]!==$e||e[218]!==d||e[219]!==Ve||e[220]!==ze?(wt=ze&&Ve?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center",children:[s.jsxs(kt,{children:[s.jsx(St,{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(Ks,{className:pe("h-3.5 w-3.5 shrink-0",I?"hidden":"group-hover/gh:hidden"),style:ts?{color:ts}:void 0}),s.jsx("span",{className:pe("text-muted-foreground h-3.5 w-3.5 items-center justify-center",I?"inline-flex":"hidden group-hover/gh:inline-flex"),children:we?s.jsx(Fn,{className:"h-3.5 w-3.5"}):s.jsx(Cs,{className:"h-3.5 w-3.5"})})]}),Ve.url?s.jsxs("button",{type:"button",className:"inline-flex shrink-0 items-center leading-none",onMouseDown:nD,onClick:Yt,children:["#",Ve.number]}):s.jsxs("span",{className:"inline-flex shrink-0 items-center leading-none",children:["#",Ve.number]})]})}),s.jsx(Ct,{side:"top",sideOffset:6,align:"start",className:"max-w-sm",children:s.jsxs("div",{className:"space-y-1 text-xs",children:[Kt||Ut?s.jsx("div",{className:"text-muted-foreground truncate",children:Kt&&Ut?s.jsxs(s.Fragment,{children:[s.jsx("span",{children:Kt}),s.jsx(cm,{className:"mx-0.5 inline h-3 w-3 align-[-2px]"}),s.jsx("span",{children:Ut})]}):s.jsx("span",{children:Kt??Ut??""})}):null,_t?s.jsx("div",{className:"text-muted-foreground truncate",children:_t}):null,$e||ye?s.jsxs("div",{className:"text-muted-foreground truncate",children:[$e??"",$e&&ye?" • ":"",ye??"",Ge?` (${Ge})`:""]}):null]})})]}),s.jsx("span",{className:"ml-1 min-w-0 flex-1 truncate leading-none align-middle",children:r.branch})]}):r.isArchivedBucket?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx(Od,{className:pe("h-3.5 w-3.5 shrink-0 text-muted-foreground",I?"hidden":"group-hover/gh:hidden")}),s.jsx("span",{className:pe("text-muted-foreground h-3.5 w-3.5 items-center justify-center",I?"inline-flex":"hidden group-hover/gh:inline-flex"),children:we?s.jsx(Fn,{className:"h-3.5 w-3.5"}):s.jsx(Cs,{className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:So(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(Ks,{className:pe("h-3.5 w-3.5 shrink-0 text-muted-foreground",I?"hidden":"group-hover/gh:hidden"),style:ts?{color:ts}:void 0}),s.jsx("span",{className:pe("text-muted-foreground h-3.5 w-3.5 items-center justify-center",I?"inline-flex":"hidden group-hover/gh:inline-flex"),children:we?s.jsx(Fn,{className:"h-3.5 w-3.5"}):s.jsx(Cs,{className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:So(r.label,d)})]}):So(r.label,d),e[203]=I,e[204]=Kt,e[205]=ts,e[206]=ye,e[207]=Ge,e[208]=r.branch,e[209]=r.isArchivedBucket,e[210]=r.isMain,e[211]=r.label,e[212]=r.worktree,e[213]=Yt,e[214]=Ut,e[215]=we,e[216]=_t,e[217]=$e,e[218]=d,e[219]=Ve,e[220]=ze,e[221]=wt):wt=e[221];let zt;e[222]!==wt?(zt=s.jsx("p",{className:"text-[14px] font-normal truncate text-foreground/92",children:wt}),e[222]=wt,e[223]=zt):zt=e[223];let ss;e[224]!==Kt||e[225]!==ts||e[226]!==ye||e[227]!==Ge||e[228]!==r.isArchivedBucket||e[229]!==r.isMain||e[230]!==Ut||e[231]!==Ze||e[232]!==_t||e[233]!==$e||e[234]!==Ve||e[235]!==Qe||e[236]!==ze||e[237]!==Dt?(ss=Qe&&Dt?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5 leading-tight",children:[r.isArchivedBucket?s.jsx(Od,{className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):!r.isMain||Ze?ze&&Ve?s.jsxs(kt,{children:[s.jsx(St,{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(Ks,{className:"h-3.5 w-3.5 text-muted-foreground",style:ts?{color:ts}:void 0})})}),s.jsx(Ct,{side:"top",sideOffset:6,align:"start",className:"max-w-sm",children:s.jsxs("div",{className:"space-y-1 text-xs",children:[Kt||Ut?s.jsx("div",{className:"text-muted-foreground truncate",children:Kt&&Ut?s.jsxs(s.Fragment,{children:[s.jsx("span",{children:Kt}),s.jsx(cm,{className:"mx-0.5 inline h-3 w-3 align-[-2px]"}),s.jsx("span",{children:Ut})]}):s.jsx("span",{children:Kt??Ut??""})}):null,_t?s.jsx("div",{className:"text-muted-foreground truncate",children:_t}):null,$e||ye?s.jsxs("div",{className:"text-muted-foreground truncate",children:[$e??"",$e&&ye?" • ":"",ye??"",Ge?` (${Ge})`:""]}):null]})})]}):s.jsx(Ks,{className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground",style:ts?{color:ts}:void 0}):null,s.jsx("span",{className:pe("min-w-0 truncate text-[11px] font-medium",!Dt.color&&"text-muted-foreground/80"),style:Dt.color?{color:Dt.color}:void 0,children:Dt.label})]}):null,e[224]=Kt,e[225]=ts,e[226]=ye,e[227]=Ge,e[228]=r.isArchivedBucket,e[229]=r.isMain,e[230]=Ut,e[231]=Ze,e[232]=_t,e[233]=$e,e[234]=Ve,e[235]=Qe,e[236]=ze,e[237]=Dt,e[238]=ss):ss=e[238];let os;e[239]!==zt||e[240]!==ss?(os=s.jsxs("div",{className:"min-w-0 flex flex-1 flex-col justify-center gap-0.5 overflow-hidden",children:[zt,ss]}),e[239]=zt,e[240]=ss,e[241]=os):os=e[241];let Ps;e[242]!==Ls||e[243]!==X||e[244]!==pt||e[245]!==os?(Ps=s.jsx("div",{ref:Ls,className:X,...pt,children:os}),e[242]=Ls,e[243]=X,e[244]=pt,e[245]=os,e[246]=Ps):Ps=e[246];let Ms;e[247]!==He||e[248]!==I||e[249]!==r.isArchivedBucket||e[250]!==r.label||e[251]!==n?(Ms=r.isArchivedBucket&&He.length>0?s.jsx("div",{className:pe("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",I?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx("button",{type:"button",onClick:st=>{st.stopPropagation(),Dr.requestDelete({sessions:He,mode:"session"})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":n("sessions.sidebar.group.actions.deleteArchivedInGroupAria",{label:r.label}),children:s.jsx(sn,{className:"h-4 w-4"})})}),s.jsx(Ct,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.group.actions.deleteArchivedSessions")})})]})}):null,e[247]=He,e[248]=I,e[249]=r.isArchivedBucket,e[250]=r.label,e[251]=n,e[252]=Ms):Ms=e[252];let We;e[253]!==He||e[254]!==I||e[255]!==r.directory||e[256]!==r.isMain||e[257]!==r.label||e[258]!==r.worktree||e[259]!==n?(We=r.directory&&!r.isMain&&r.worktree?s.jsx("div",{className:pe("absolute right-7 top-1/2 -translate-y-1/2 z-10 transition-opacity",I?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx("button",{type:"button",onClick:st=>{st.stopPropagation(),Dr.requestDelete({sessions:He,mode:"worktree",worktree:r.worktree})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":n("sessions.sidebar.group.actions.deleteGroupAria",{label:r.label}),children:s.jsx(sn,{className:"h-4 w-4"})})}),s.jsx(Ct,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.group.actions.deleteWorktree")})})]})}):null,e[253]=He,e[254]=I,e[255]=r.directory,e[256]=r.isMain,e[257]=r.label,e[258]=r.worktree,e[259]=n,e[260]=We):We=e[260];let gt;e[261]!==R||e[262]!==I||e[263]!==r.directory||e[264]!==r.label||e[265]!==C||e[266]!==D||e[267]!==i||e[268]!==P||e[269]!==k||e[270]!==N||e[271]!==n?(gt=r.directory?s.jsx("div",{className:pe("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",I?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx("button",{type:"button",onClick:st=>{st.stopPropagation(),i&&i!==R&&k(i),P("chat"),C&&N(!1),D({directoryOverride:r.directory})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":n("sessions.sidebar.group.actions.newDraftInGroupAria",{label:r.label}),children:s.jsx(_s,{className:"h-4 w-4"})})}),s.jsx(Ct,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.project.actions.newDraftSession")})})]})}):null,e[261]=R,e[262]=I,e[263]=r.directory,e[264]=r.label,e[265]=C,e[266]=D,e[267]=i,e[268]=P,e[269]=k,e[270]=N,e[271]=n,e[272]=gt):gt=e[272];let Mt;e[273]!==ft||e[274]!==is||e[275]!==es||e[276]!==Ts||e[277]!==Ps||e[278]!==Ms||e[279]!==We||e[280]!==gt?(Mt=s.jsxs("div",{className:As,onClick:ft,role:"button",tabIndex:0,onKeyDown:is,"aria-label":es,"aria-expanded":Ts,children:[Ps,Ms,We,gt]}),e[273]=ft,e[274]=is,e[275]=es,e[276]=Ts,e[277]=Ps,e[278]=Ms,e[279]=We,e[280]=gt,e[281]=Mt):Mt=e[281];let Et;e[282]!==Rt||e[283]!==ns||e[284]!==we?(Et=we?null:s.jsx("div",{className:pe("oc-group-body",ns),children:Rt}),e[282]=Rt,e[283]=ns,e[284]=we,e[285]=Et):Et=e[285];let as;return e[286]!==Mt||e[287]!==Et?(as=s.jsxs("div",{className:"oc-group",children:[Mt,Et]}),e[286]=Mt,e[287]=Et,e[288]=as):as=e[288],as}function nD(t){return t.stopPropagation()}function rD(t){return!!t}function aD(t){const e=[],n=r=>{r.forEach(a=>{e.push(a.session),a.children.length>0&&n(a.children)})};return n(t),e}function iD(t){const{folder:e}=t;return!e.parentId}function oD(t){return t.folder.sessionIds}function lD(t){return[t.folder.id,t]}function cD(t){return!!t}function dD(t){return t.foldersMap}function uD(t){return t.displayMode}function mD(t){const e=nt.c(37),{t:n}=ut(),{hideDirectoryControls:r,handleOpenDirectoryDialog:a,handleNewSession:i,canOpenMultiRun:o,openMultiRunLauncher:c,headerActionIconClass:d,reserveHeaderActionsSpace:p,headerActionButtonClass:m,isSessionSearchOpen:u,setIsSessionSearchOpen:h,sessionSearchInputRef:b,sessionSearchQuery:f,setSessionSearchQuery:y,hasSessionSearchQuery:x,searchMatchCount:g,collapseAllProjects:w,expandAllProjects:v,openScheduledTasksDialog:S,selectionModeEnabled:A,onToggleSelectionMode:j,showSidebarToggle:C,onToggleSidebar:I,avoidWindowControlsOverlay:R}=t,k=C===void 0?!1:C,P=R===void 0?!1:R,N=Ha(xD),D=Ha(gD),T=Ha(hD),M=Ha(fD);if(r)return null;const $=k?P?"pl-[5.5rem] pr-3":"pl-3 pr-3":"px-2.5 py-1";let F;e[0]!==$?(F=pe("select-none flex-shrink-0",$),e[0]=$,e[1]=F):F=e[1];let V;e[2]!==P||e[3]!==k?(V=k&&P?{paddingTop:"var(--oc-safe-area-top, 0px)"}:void 0,e[2]=P,e[3]=k,e[4]=V):V=e[4];let O;e[5]!==P||e[6]!==o||e[7]!==w||e[8]!==N||e[9]!==v||e[10]!==i||e[11]!==a||e[12]!==x||e[13]!==m||e[14]!==d||e[15]!==u||e[16]!==j||e[17]!==I||e[18]!==c||e[19]!==S||e[20]!==p||e[21]!==g||e[22]!==A||e[23]!==b||e[24]!==f||e[25]!==T||e[26]!==h||e[27]!==y||e[28]!==D||e[29]!==k||e[30]!==n||e[31]!==M?(O=p?s.jsxs("div",{className:pe("flex h-auto flex-col gap-1",k?P?"min-h-[calc(var(--oc-header-height,56px)-var(--oc-safe-area-top,0px))] justify-center":"min-h-[var(--oc-header-height,56px)] justify-center":"min-h-8"),children:[s.jsxs("div",{className:"flex h-8 items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[k&&I?s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx("button",{type:"button",onClick:I,className:"inline-flex h-8 w-8 items-center justify-center rounded-md typography-ui-label font-medium text-foreground transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:pointer-events-none disabled:opacity-50","aria-label":n("sessions.sidebar.header.actions.closeSessions"),children:s.jsx(si,{className:"h-[18px] w-[18px]"})})}),s.jsx(Ct,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.closeSessions")})})]}):null,s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx("button",{type:"button",onClick:a,className:m,"aria-label":n("sessions.sidebar.header.actions.addProject"),children:s.jsx(Ca,{className:d})})}),s.jsx(Ct,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.addProject")})})]}),s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx("button",{type:"button",onClick:i,className:m,"aria-label":n("sessions.sidebar.header.actions.newSession"),children:s.jsx(Mh,{className:d})})}),s.jsx(Ct,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.newSession")})})]}),s.jsxs(kt,{children:[s.jsx(St,{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(Q1,{className:d})})}),s.jsx(Ct,{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(St,{asChild:!0,children:s.jsx("button",{type:"button",onClick:S,className:m,"aria-label":n("sessions.sidebar.header.actions.scheduledTasks"),children:s.jsx(Yy,{className:d})})}),s.jsx(Ct,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.scheduledTasks")})})]}),s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx("button",{type:"button",onClick:()=>h(pD),className:m,"aria-label":n("sessions.sidebar.header.actions.searchSessions"),"aria-expanded":u,children:s.jsx(Hn,{className:d})})}),s.jsx(Ct,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.actions.searchSessions")})})]}),s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx("button",{type:"button",onClick:j,className:pe(m,A&&"bg-interactive-hover text-primary"),"aria-label":n(A?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions"),"aria-pressed":A,children:s.jsx(Xy,{className:d})})}),s.jsx(Ct,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n(A?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions")})})]}),s.jsxs(zs,{children:[s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx(Bs,{asChild:!0,children:s.jsx("button",{type:"button",className:m,"aria-label":n("sessions.sidebar.header.actions.sessionDisplayMode"),children:s.jsx(Zy,{className:d})})})}),s.jsx(Ct,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:n("sessions.sidebar.header.displayMode.label")})})]}),s.jsxs(Vs,{align:"end",className:"min-w-[160px]",children:[s.jsxs($t,{onClick:()=>T("default"),className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.default")}),N==="default"?s.jsx(Ys,{className:"h-4 w-4 text-primary"}):null]}),s.jsxs($t,{onClick:()=>T("minimal"),className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.minimal")}),N==="minimal"?s.jsx(Ys,{className:"h-4 w-4 text-primary"}):null]}),s.jsx(En,{}),s.jsxs($t,{onClick:M,className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.showRecent")}),D?s.jsx(Ys,{className:"h-4 w-4 text-primary"}):null]}),s.jsx(En,{}),s.jsxs($t,{onClick:w,className:"flex items-center gap-2",children:[s.jsx(ev,{className:"h-4 w-4"}),s.jsx("span",{children:n("sessions.sidebar.header.displayMode.collapseAll")})]}),s.jsxs($t,{onClick:v,className:"flex items-center gap-2",children:[s.jsx(tv,{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(Hn,{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:W=>y(W.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:W=>{W.key==="Escape"&&(W.stopPropagation(),x?y(""):h(!1))}}),f.length>0?s.jsx("button",{type:"button",onClick:()=>y(""),className:"absolute right-1 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":n("sessions.sidebar.header.search.clear"),children:s.jsx(Ds,{className:"h-3.5 w-3.5"})}):null]})]}):null]}):null,e[5]=P,e[6]=o,e[7]=w,e[8]=N,e[9]=v,e[10]=i,e[11]=a,e[12]=x,e[13]=m,e[14]=d,e[15]=u,e[16]=j,e[17]=I,e[18]=c,e[19]=S,e[20]=p,e[21]=g,e[22]=A,e[23]=b,e[24]=f,e[25]=T,e[26]=h,e[27]=y,e[28]=D,e[29]=k,e[30]=n,e[31]=M,e[32]=O):O=e[32];let L;return e[33]!==F||e[34]!==V||e[35]!==O?(L=s.jsx("div",{className:F,style:V,children:O}),e[33]=F,e[34]=V,e[35]=O,e[36]=L):L=e[36],L}function pD(t){return!t}function fD(t){return t.toggleRecentSection}function hD(t){return t.setDisplayMode}function gD(t){return t.showRecentSection}function xD(t){return t.displayMode}const ch=7;function bD(t){const e=nt.c(20),{sections:n,renderSessionNode:r}=t,{t:a}=ut();let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=new Set,e[0]=i):i=e[0];const[o,c]=l.useState(i);let d;e[1]===Symbol.for("react.memo_cache_sentinel")?(d=new Set,e[1]=d):d=e[1];const[p,m]=l.useState(d);let u;e[2]===Symbol.for("react.memo_cache_sentinel")?(u=v=>{c(S=>{const A=new Set(S);return A.has(v)?A.delete(v):A.add(v),A})},e[2]=u):u=e[2];const h=u;let b;e[3]===Symbol.for("react.memo_cache_sentinel")?(b=v=>{m(S=>{const A=new Set(S);return A.has(v)?A.delete(v):A.add(v),A})},e[3]=b):b=e[3];const f=b;let y,x,g;if(e[4]!==o||e[5]!==p||e[6]!==r||e[7]!==n||e[8]!==a){g=Symbol.for("react.early_return_sentinel");e:{const v=n.filter(yD);if(v.length===0){g=null;break e}y="space-y-2 pb-2 pt-1";let S;e[12]!==o||e[13]!==p||e[14]!==r||e[15]!==a?(S=A=>{const j=o.has(A.key),C=p.has(A.key),I=C?A.items:A.items.slice(0,ch),R=A.items.length-I.length;return s.jsxs("div",{className:"space-y-1",children:[s.jsxs("button",{type:"button",onClick:()=>h(A.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(Fn,{className:"h-3.5 w-3.5"}):s.jsx(Cs,{className:"h-3.5 w-3.5"})}),s.jsx("span",{className:"text-[14px] font-normal text-foreground/95",children:A.title})]}),j?null:s.jsxs("div",{className:pe("space-y-0.5 pl-7"),children:[I.map(k=>r(k.node,0,k.groupDirectory,k.projectId,!1,k.secondaryMeta,"recent")),R>0&&!C?s.jsx("button",{type:"button",onClick:()=>f(A.key),className:"mt-0.5 flex items-center justify-start rounded-md px-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:R===1?a("sessions.sidebar.group.showMoreSingle",{count:R}):a("sessions.sidebar.group.showMorePlural",{count:R})}):null,C&&A.items.length>ch?s.jsx("button",{type:"button",onClick:()=>f(A.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]})]},A.key)},e[12]=o,e[13]=p,e[14]=r,e[15]=a,e[16]=S):S=e[16],x=v.map(S)}e[4]=o,e[5]=p,e[6]=r,e[7]=n,e[8]=a,e[9]=y,e[10]=x,e[11]=g}else y=e[9],x=e[10],g=e[11];if(g!==Symbol.for("react.early_return_sentinel"))return g;let w;return e[17]!==y||e[18]!==x?(w=s.jsx("div",{className:y,children:x}),e[17]=y,e[18]=x,e[19]=w):w=e[19],w}function yD(t){return t.items.length>0}const vd="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 vD(t){const e=nt.c(13),{onOpenSettings:n,onOpenShortcuts:r,onOpenAbout:a,onOpenUpdate:i,showRuntimeButtons:o,showUpdateButton:c}=t,d=o===void 0?!0:o,p=c===void 0?!0:c,{t:m}=ut();let u;e[0]!==a||e[1]!==n||e[2]!==r||e[3]!==d||e[4]!==m?(u=d?s.jsxs(s.Fragment,{children:[s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,className:vd,"aria-label":m("sessions.sidebar.footer.actions.settings"),children:s.jsx(Vi,{className:"h-4.5 w-4.5"})})}),s.jsx(Ct,{side:"top",sideOffset:4,children:s.jsx("p",{children:m("sessions.sidebar.footer.actions.settings")})})]}),s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx("button",{type:"button",onClick:r,className:vd,"aria-label":m("sessions.sidebar.footer.actions.shortcuts"),children:s.jsx(Fd,{className:"h-4.5 w-4.5"})})}),s.jsx(Ct,{side:"top",sideOffset:4,children:s.jsx("p",{children:m("sessions.sidebar.footer.actions.shortcuts")})})]}),s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx("button",{type:"button",onClick:a,className:vd,"aria-label":m("sessions.sidebar.footer.actions.aboutOpenChamber"),children:s.jsx(Us,{className:"h-4.5 w-4.5"})})}),s.jsx(Ct,{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(je,{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 wD=t=>{const e=nt.c(58),{id:n,projectLabel:r,projectDescription:a,projectIcon:i,projectColor:o,projectIconImage:c,projectIconBackground:d,isCollapsed:p,isActiveProject:m,isRepo:u,isDesktopShell:h,isStuck:b,hideDirectoryControls:f,alwaysShowActions:y,onToggle:x,onNewSession:g,onNewWorktreeSession:w,onRenameStart:v,onClose:S,sentinelRef:A,children:j,showCreateButtons:C,hideHeader:I,openSidebarMenuKey:R,setOpenSidebarMenuKey:k}=t,P=C===void 0?!0:C,N=I===void 0?!1:I,{t:D}=ut(),{currentTheme:T}=Rr();let M;e[0]!==n?(M={id:n},e[0]=n,e[1]=M):M=e[1];const{attributes:$,listeners:F,setNodeRef:V,transform:O,transition:L,isDragging:W}=hu(M),[B,ne]=l.useState(!1),le=l.useRef(!1),ee=`project:${n}`,ae=R===ee;let ge;e[2]===Symbol.for("react.memo_cache_sentinel")?(ge=()=>{ne(!1)},e[2]=ge):ge=e[2];const te=c?.updatedAt;let E;e[3]!==n||e[4]!==te?(E=[n,te],e[3]=n,e[4]=te,e[5]=E):E=e[5],l.useEffect(ge,E);const z=i?vc[i]:null,J=o?Ko[o]??null:null;let H;e[6]!==T||e[7]!==n||e[8]!==B||e[9]!==c?(H=B?null:Wo({id:n,iconImage:c},{themeVariant:T.metadata.variant,iconColor:T.colors.surface.foreground}),e[6]=T,e[7]=n,e[8]=B,e[9]=c,e[10]=H):H=e[10];const re=H;let ce;e[11]!==ee||e[12]!==k?(ce=he=>{k(he?ee:null)},e[11]=ee,e[12]=k,e[13]=ce):ce=e[13];const Ne=ce,me=SD,we=kD,_=CD;let ue;e[14]===Symbol.for("react.memo_cache_sentinel")?(ue=he=>{(he.button===2||he.button===0&&he.ctrlKey)&&(le.current=!0)},e[14]=ue):ue=e[14];const Q=ue;let oe;e[15]!==x?(oe=()=>{if(le.current){le.current=!1;return}x()},e[15]=x,e[16]=oe):oe=e[16];const Z=oe;let Ie;e[17]!==O?(Ie=gu.Transform.toString(O),e[17]=O,e[18]=Ie):Ie=e[18];let Se;e[19]!==Ie||e[20]!==L?(Se={transform:Ie,transition:L},e[19]=Ie,e[20]=L,e[21]=Se):Se=e[21];const Y=W&&"opacity-30";let fe;e[22]!==Y?(fe=pe("relative",Y),e[22]=Y,e[23]=fe):fe=e[23];let ke;e[24]!==z||e[25]!==y||e[26]!==$||e[27]!==Ne||e[28]!==Z||e[29]!==f||e[30]!==N||e[31]!==J||e[32]!==n||e[33]!==re||e[34]!==m||e[35]!==p||e[36]!==h||e[37]!==ae||e[38]!==u||e[39]!==b||e[40]!==F||e[41]!==S||e[42]!==g||e[43]!==w||e[44]!==v||e[45]!==a||e[46]!==d||e[47]!==r||e[48]!==A||e[49]!==P||e[50]!==D?(ke=N?null:s.jsxs(s.Fragment,{children:[h&&s.jsx("div",{ref:A,"data-project-id":n,className:"absolute top-0 h-px w-full pointer-events-none","aria-hidden":"true"}),s.jsx("div",{className:pe("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",...$,children:[s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsxs("button",{type:"button",onMouseDown:Q,onClick:Z,...F,className:pe("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?y?"pr-20":"pr-7 group-hover/project:pr-20 group-focus-within/project:pr-20":y?"pr-14":"pr-7 group-hover/project:pr-14 group-focus-within/project:pr-14"),children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 flex-shrink-0 items-center justify-center",children:[s.jsx("span",{className:pe("h-3.5 w-3.5 items-center justify-center text-muted-foreground",y?"inline-flex":"hidden group-hover/project:inline-flex group-focus-within/project:inline-flex"),children:p?s.jsx(Fn,{className:"h-3.5 w-3.5"}):s.jsx(Cs,{className:"h-3.5 w-3.5"})}),re?s.jsx("span",{className:pe("h-3.5 w-3.5 items-center justify-center overflow-hidden rounded-[3px]",y?"hidden":"inline-flex group-hover/project:hidden group-focus-within/project:hidden"),style:d?{backgroundColor:d}:void 0,children:s.jsx("img",{src:re,alt:"",className:"h-full w-full object-contain",draggable:!1,onError:()=>ne(!0)})}):z?s.jsx(z,{className:pe("h-3.5 w-3.5",y?"hidden":"group-hover/project:hidden group-focus-within/project:hidden"),style:J?{color:J}:void 0}):s.jsx(zn,{className:pe("h-3.5 w-3.5 text-muted-foreground/80",y?"hidden":"group-hover/project:hidden group-focus-within/project:hidden"),style:J?{color:J}:void 0})]}),s.jsx("span",{className:pe("text-[14px] font-normal truncate lowercase",m?"text-foreground":"text-foreground group-hover/project:text-foreground"),children:r})]})}),s.jsx(Ct,{side:"right",sideOffset:8,children:a})]}),s.jsxs("div",{className:pe("absolute top-1/2 z-10 flex -translate-y-1/2 items-center gap-1",P?"right-7":"right-0.5"),children:[P&&u&&!f&&w?s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx("button",{type:"button",onClick:he=>{he.stopPropagation(),w()},className:pe("inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 hover:text-foreground transition-opacity",y?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":D("sessions.sidebar.project.actions.newWorktree"),children:s.jsx(Wh,{className:"h-4 w-4"})})}),s.jsx(Ct,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:D("sessions.sidebar.project.actions.newWorktreeEllipsis")})})]}):null,s.jsxs(zs,{open:ae,onOpenChange:Ne,children:[s.jsx(Bs,{asChild:!0,children:s.jsx("button",{type:"button",className:pe("inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground transition-opacity focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 hover:text-foreground",ae?"opacity-100 pointer-events-auto":y?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":D("sessions.sidebar.project.actions.projectMenu"),onPointerDown:we,onMouseDown:_,onClick:me,children:s.jsx(ia,{className:"h-3.5 w-3.5"})})}),s.jsxs(Vs,{align:"end",className:"min-w-[180px]",children:[P&&!u&&!f&&g&&s.jsxs($t,{onClick:g,children:[s.jsx(_s,{className:"mr-1.5 h-4 w-4"}),D("sessions.sidebar.project.actions.newSession")]}),s.jsxs($t,{onClick:v,children:[s.jsx(Mi,{className:"mr-1.5 h-4 w-4"}),D("sessions.sidebar.session.menu.rename")]}),s.jsxs($t,{onClick:S,className:"text-destructive focus:text-destructive",children:[s.jsx(Ds,{className:"mr-1.5 h-4 w-4"}),D("sessions.sidebar.project.actions.closeProject")]})]})]})]}),P&&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(St,{asChild:!0,children:s.jsx("button",{type:"button",onClick:he=>{he.stopPropagation(),g()},className:pe("inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",y?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":D(u?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession"),children:s.jsx(_s,{className:"h-4 w-4"})})}),s.jsx(Ct,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:D(u?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession")})})]})}):null]})})]}),e[24]=z,e[25]=y,e[26]=$,e[27]=Ne,e[28]=Z,e[29]=f,e[30]=N,e[31]=J,e[32]=n,e[33]=re,e[34]=m,e[35]=p,e[36]=h,e[37]=ae,e[38]=u,e[39]=b,e[40]=F,e[41]=S,e[42]=g,e[43]=w,e[44]=v,e[45]=a,e[46]=d,e[47]=r,e[48]=A,e[49]=P,e[50]=D,e[51]=ke):ke=e[51];let xe;return e[52]!==j||e[53]!==V||e[54]!==Se||e[55]!==fe||e[56]!==ke?(xe=s.jsxs("div",{ref:V,style:Se,className:fe,children:[ke,j]}),e[52]=j,e[53]=V,e[54]=Se,e[55]=fe,e[56]=ke,e[57]=xe):xe=e[57],xe},jD=t=>{const e=nt.c(21),{id:n,disabled:r,children:a}=t,i=r===void 0?!1:r;let o;e[0]!==i||e[1]!==n?(o={id:n,disabled:i},e[0]=i,e[1]=n,e[2]=o):o=e[2];const{listeners:c,setNodeRef:d,setActivatorNodeRef:p,transform:m,transition:u,isDragging:h}=hu(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 y;e[6]!==m?(y=gu.Transform.toString(m),e[6]=m,e[7]=y):y=e[7];let x;e[8]!==y||e[9]!==u?(x={transform:y,transition:u},e[8]=y,e[9]=u,e[10]=x):x=e[10];const g=h&&"opacity-50";let w;e[11]!==g?(w=pe("space-y-0.5 rounded-md",g),e[11]=g,e[12]=w):w=e[12];let v;e[13]!==a||e[14]!==f?(v=typeof a=="function"?a(f):a,e[13]=a,e[14]=f,e[15]=v):v=e[15];let S;return e[16]!==d||e[17]!==x||e[18]!==w||e[19]!==v?(S=s.jsx("div",{ref:d,style:x,className:w,children:v}),e[16]=d,e[17]=x,e[18]=w,e[19]=v,e[20]=S):S=e[20],S},ND=l.memo(jD);function SD(t){t.stopPropagation()}function kD(t){t.stopPropagation()}function CD(t){t.stopPropagation()}function ID(t){const e=nt.c(25),{t:n}=ut();let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={activationConstraint:{distance:8}},e[0]=r):r=e[0];let a;e[1]===Symbol.for("react.memo_cache_sentinel")?(a={coordinateGetter:rv},e[1]=a):a=e[1];const i=Ol(yo(Ll,r),yo(sv,a));let o;e[2]===Symbol.for("react.memo_cache_sentinel")?(o={activationConstraint:{distance:8}},e[2]=o):o=e[2];const c=Ol(yo(Ll,o));if(t.projectSections.length===0){const h=(t.mobileVariant,"");let b;e[3]!==h?(b=pe("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(Es,{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=pe("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(Es,{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=pe("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(FD)??h.groups.find(ED)??h.groups.find(RD)??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(MD);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(Bl,{sensors:i,collisionDetection:Vl,onDragEnd:h=>{if(t.isInlineEditing)return;const{active:b,over:f}=h;if(!f||b.id===f.id)return;const y=t.sectionsForRender.findIndex(g=>g.project.id===b.id),x=t.sectionsForRender.findIndex(g=>g.project.id===f.id);y===-1||x===-1||y===x||t.reorderProjects(y,x)},children:[s.jsx(Id,{items:t.sectionsForRender.map(TD),strategy:dm,children:t.sectionsForRender.map(h=>{const b=h.project,f=b.id,y=Pg(b.label?.trim()||ii(b.normalizedPath,t.homeDirectory)||b.normalizedPath),x=To(b.normalizedPath,t.homeDirectory),g=t.collapsedProjects.has(f),w=f===t.activeProjectId,v=t.projectRepoStatus.get(f),S=t.getOrderedGroups(f,h.groups),A=S.find(DD)??null,j=A?S.filter(C=>C.id!==A.id):S;return s.jsx(wD,{id:f,projectLabel:y,projectDescription:x,projectIcon:b.icon,projectColor:b.color,projectIconImage:b.iconImage,projectIconBackground:b.iconBackground,isCollapsed:g,isActiveProject:w,isRepo:!!v,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:C=>{t.projectHeaderSentinelRefs.current.set(f,C)},showCreateButtons:!0,openSidebarMenuKey:t.openSidebarMenuKey,setOpenSidebarMenuKey:t.setOpenSidebarMenuKey,children:g?null:s.jsx("div",{className:"space-y-0 pt-0 pb-0.5 pl-3",children:h.groups.length>0?s.jsxs(Bl,{sensors:c,collisionDetection:Vl,onDragEnd:C=>{if(t.isInlineEditing)return;const{active:I,over:R}=C;if(!R||I.id===R.id)return;const k=j.findIndex(T=>T.id===I.id),P=j.findIndex(T=>T.id===R.id);if(k===-1||P===-1||k===P)return;const N=nv(j,k,P).map(PD),D=A?[A.id,...N]:N;t.setGroupOrderByProject(T=>{const M=new Map(T);return M.set(f,D),M})},children:[A?t.renderGroupSessions(A,`${f}:${A.id}`,f,!0):null,s.jsx(Id,{items:j.map(AD),strategy:dm,children:j.map(C=>{const I=`${f}:${C.id}`;return s.jsx(ND,{id:C.id,disabled:t.isInlineEditing,children:R=>t.renderGroupSessions(C,I,f,!1,R)},C.id)})}),s.jsx($l,{dropAnimation:null})]}):s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:n("sessions.sidebar.empty.noSessions.title")})})},f)})}),s.jsx($l,{dropAnimation:null})]})}),e[16]=c,e[17]=i,e[18]=t,e[19]=n,e[20]=m):m=e[20];let u;return e[21]!==t.topContent||e[22]!==p||e[23]!==m?(u=s.jsxs(Es,{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 AD(t){return t.id}function PD(t){return t.id}function DD(t){return t.isMain}function TD(t){return t.project.id}function MD(t){return t.isArchivedBucket}function RD(t){return t.isMain}function ED(t){return t.sessions.length>0}function FD(t){return t.isMain&&t.sessions.length>0}function OD(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 LD(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 $D(t){const e=t.info.role==="user"?"User":"Assistant",n=OD(t.info.time?.created),r=LD(t),a=n&&r?`${n} (${r})`:n||r;return a?`**${e}**
91
-
92
- *${a}*`:`**${e}**`}function BD(t){return t.filter(e=>e.type==="text"&&typeof e.text=="string").map(e=>e.text).join("")}function Jx(t){const e=$D(t),n=BD(t.parts).trim();return n?`${e}
93
-
94
- ${n}`:""}function Yx(t,e){const n="#".repeat(Math.min(e+1,6)),r=t.agent?` — ${t.agent}`:"",a=`${n} Sub-agent: ${t.title}${r}
95
-
96
- ---
97
-
98
- `,i=t.records.map(Jx).filter(Boolean).join(`
99
-
100
- ---
101
-
102
- `),o=[a+i];for(const c of t.children)o.push(Yx(c,e+1));return o.join(`
103
-
104
- ---
105
-
106
- `)}function VD(t,e,n){const r=e?.trim()||"Session",a=new Date().toISOString().split("T")[0],i=`# ${r}
107
-
108
- *Exported on ${a}*
109
-
110
- ---
111
-
112
- `,o=t.map(Jx).filter(Boolean).join(`
113
-
114
- ---
115
-
116
- `);let c=i+o;if(n&&n.length>0){const d=n.map(p=>Yx(p,1)).join(`
117
-
118
- ---
119
-
120
- `);c+=`
121
-
122
- ---
123
-
124
- `+d}return c}function zD(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 _D(t,e){const n=await J1(e,t);if(n)return n;if(!yn())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 UD(t){const e=xr()?.files;if(e?.revealPath)try{return!!(await e.revealPath(t))?.success}catch{return!1}return await Y1(t)?!0:Wl(t)}function WD(){return $u()}function KD(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 HD=(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},hr=wr()((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=HD(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}))}})),dh=t=>t.children.length===0?"":t.children.map(e=>`${e.session.id}:${e.children.length}`).join("|"),za=(t,e)=>{if(!e)return!1;if(t.session.id===e)return!0;for(const n of t.children)if(za(n,e))return!0;return!1},cu=(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(cu(i,e,n,r))return!0;return!1},GD=(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||dh(t.node)!==dh(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=za(t.node,t.currentSessionId),u=za(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=za(t.node,t.editingId),u=za(e.node,e.editingId);if(m||u)return!1}if(t.editTitle!==e.editTitle){const m=za(t.node,t.editingId),u=za(e.node,e.editingId);if(m||u)return!1}if(t.copiedSessionId===a!=(e.copiedSessionId===i))return!1;const o=cu(t.node,t.openSidebarMenuKey,t.renderContext??"project",t.archivedBucket??!1),c=cu(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 qD(t){const{t:e}=ut(),{node:n,depth:r=0,groupDirectory:a,projectId:i,archivedBucket:o=!1,directoryStatus:c,currentSessionId:d,pinnedSessionIds:p,expandedParents:m,hasSessionSearchQuery:u,normalizedSessionSearchQuery:h,notifyOnSubtasks:b,editingId:f,setEditingId:y,editTitle:x,setEditTitle:g,handleSaveEdit:w,handleCancelEdit:v,toggleParent:S,handleSessionSelect:A,handleSessionDoubleClick:j,togglePinnedSession:C,handleShareSession:I,copiedSessionId:R,handleCopyShareUrl:k,handleUnshareSession:P,openSidebarMenuKey:N,setOpenSidebarMenuKey:D,renamingFolderId:T,getFoldersForScope:M,getSessionFolderId:$,removeSessionFromFolder:F,addSessionToFolder:V,createFolderAndStartRename:O,openContextPanelTab:L,handleDeleteSession:W,mobileVariant:B,alwaysShowActions:ne,renderSessionNode:le,secondaryMeta:ee,renderContext:ae="project"}=t,ge=!!ee?.projectLabel,te=!!ee?.branchLabel,z=Ha(ft=>ft.displayMode)==="minimal",J=l.useMemo(()=>yn(),[]),H=l.useMemo(()=>Mu(),[]),re=J?"group-hover:opacity-100 group-hover:pointer-events-auto":"group-hover:opacity-100 group-hover:pointer-events-auto group-focus-within:opacity-100 group-focus-within:pointer-events-auto",ce=J?"group-hover:opacity-0":"group-hover:opacity-0 group-focus-within:opacity-0",Ne=!o&&!B,me=z?J?"group-hover:pr-2":"group-hover:pr-2 group-focus-within:pr-2":J?Ne?"group-hover:pr-12":"group-hover:pr-5":Ne?"group-hover:pr-12 group-focus-within:pr-12":"group-hover:pr-5 group-focus-within:pr-5",we=Ne?"pr-13":"pr-7",_=l.useRef(!1),[ue,Q]=l.useState(!1),oe=n.session,Ie=rg(oe.id)??oe,Se=ks(oe.directory??null)??ks(a??null),Y=X1(Se??void 0),fe=Dg(),ke=hr(ft=>ft.enabled),xe=hr(l.useCallback(ft=>ft.selectedIds.has(oe.id),[oe.id])),he=hr(ft=>ft.toggleSelected),Pe=hr(ft=>ft.setRange),Be=l.useCallback(ft=>{const is=[],es=Ts=>{Ts.children.forEach(Ls=>{is.push(Ls.session.id),es(Ls)})};return es(ft),is},[]),[G,be]=l.useState(!1),[De,Ae]=l.useState(!0),ve=`${ae}:${o?"archived":"active"}:${oe.id}`,U=Tg(l.useCallback(ft=>!!ft.sessionMemoryState.get(oe.id)?.isZombie,[oe.id])),de=Z1(oe.id),Re=ew(oe.id,Se??void 0),se=(Se?c.get(Se):null)==="missing",ie=d===oe.id,K=Ie.title||e("sessions.sidebar.session.untitled"),_e=n.children.length>0,He=p.has(oe.id),Ke=u?!0:m.has(oe.id),Ze=!!Ie.parentID,mt=tw(oe.id)>0&&(!Ze||b),et=Ie.summary,ct=og(et),lt=Ie.time?.updated||Ie.time?.created||Date.now(),ye=sw(lt),Ge=iw(lt),$e=N===ve,Ve=l.useMemo(()=>Be(n).length,[Be,n]),tt=l.useCallback(async ft=>{const is=[];let es=0;for(const Ts of ft)try{await fe.ensureSessionRenderable(Ts.session.id);const Ls=Fm(Y.getState(),Ts.session.id).list,X=Ts.session.title||e("sessions.sidebar.session.export.untitledSubagent"),pt=Ts.session.agent,wt=await tt(Ts.children);es+=wt.skipped,is.push({title:X,agent:pt,records:Ls,children:wt.children})}catch{es+=Be(Ts).length+1}return{children:is,skipped:es}},[Be,Y,fe,e]),Qe=l.useCallback(ft=>{ft<=0||q.warning(ft===1?e("sessions.sidebar.session.export.skippedSubtaskSingle",{count:ft}):e("sessions.sidebar.session.export.skippedSubtaskMany",{count:ft}))},[e]),ze=l.useCallback(async ft=>{if(!Se){q.error(e("sessions.sidebar.session.export.nothingToExport"));return}await fe.ensureSessionRenderable(oe.id);const is=Fm(Y.getState(),oe.id).list;if(is.length===0){q.error(e("sessions.sidebar.session.export.nothingToExport"));return}let es,Ts=0;if(ft&&n.children.length>0){const wt=await tt(n.children);es=wt.children,Ts=wt.skipped}const Ls=VD(is,Ie.title??null,es),X=KD(Ie.title??null),pt=await _D(Ls,X);if(pt){q.success(e("sessions.sidebar.session.export.success"),{action:{label:e(WD()),onClick:()=>{UD(pt).then(wt=>{wt||q.error(e("sessions.sidebar.session.export.failedRevealPath"))})}}}),Qe(Ts);return}zD(Ls,X),q.success(e("sessions.sidebar.session.export.success")),Qe(Ts)},[tt,Y,n.children,Ie.title,oe.id,Se,Qe,fe,e]),ht=l.useCallback(async()=>{if(n.children.length>0){Ae(!0),be(!0);return}await ze(!1)},[ze,n.children.length]),_t=l.useCallback(()=>{Se&&Kl("desktop_open_session_mini_chat_window",{sessionId:oe.id,directory:Se}).catch(ft=>{console.warn("[session-sidebar] failed to open mini chat window",ft)})},[oe.id,Se]);if(f===oe.id)return s.jsx("div",{className:pe("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(),v();return}(ft.key===" "||ft.key==="Enter")&&ft.stopPropagation()}}),s.jsx("button",{type:"submit",className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(Ys,{className:"size-4"})}),s.jsx("button",{type:"button",onClick:v,className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(Ds,{className:"size-4"})})]}),z?null:s.jsx("div",{className:"flex items-center justify-between gap-3 text-muted-foreground/60 min-w-0 overflow-hidden leading-tight",style:{fontSize:"calc(var(--text-ui-label) * 0.85)"},children:s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 overflow-hidden",children:[_e?s.jsx("span",{className:"inline-flex items-center justify-center flex-shrink-0",children:Ke?s.jsx(Cs,{className:"h-3 w-3"}):s.jsx(Fn,{className:"h-3 w-3"})}):null,s.jsx("span",{className:"flex-shrink-0",children:ye}),ct?s.jsxs("span",{className:"flex flex-shrink-0 items-center gap-0 text-[0.92em]",children:[s.jsxs("span",{className:"text-status-success/80",children:["+",ct.additions]}),s.jsxs("span",{className:"text-status-error/65",children:["/-",ct.deletions]})]}):null,ge?s.jsx("span",{className:"truncate",children:ee?.projectLabel}):null,te?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(Ks,{className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:ee?.branchLabel})]}):null]})})]})},oe.id);const Kt=de?.type??"idle",Ut=Kt==="busy"||Kt==="retry",jt=Re.length,ts=Ut||!Ut&&mt&&!ie,it=Ut?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")}),Yt=ts||He?s.jsxs("span",{className:pe("pointer-events-none absolute inline-flex h-3.5 items-center justify-center gap-0.5 transition-opacity",z?"top-1/2 -translate-y-1/2":"top-[14.5px] -translate-y-1/2",ts&&He?"left-[-18px] w-6":"left-[-10px] w-3.5",_e&&!ne?"opacity-100 group-hover:opacity-0 group-focus-within:opacity-0":""),children:[ts?it:null,He?s.jsx(um,{className:"h-3 w-3 flex-shrink-0 text-primary","aria-label":e("sessions.sidebar.session.status.pinned")}):null]}):null,Qt=_e?s.jsx("span",{role:"button",tabIndex:0,onClick:ft=>{ft.stopPropagation(),S(oe.id)},onKeyDown:ft=>{(ft.key==="Enter"||ft.key===" ")&&(ft.preventDefault(),ft.stopPropagation(),S(oe.id))},className:pe("absolute left-[-10px] inline-flex h-3.5 w-3.5 items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",z?"top-1/2 -translate-y-1/2":"top-[14.5px] -translate-y-1/2",z&&ts&&!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(Ke?"sessions.sidebar.session.subsessions.collapse":"sessions.sidebar.session.subsessions.expand"),children:Ke?s.jsx(Cs,{className:"h-3 w-3"}):s.jsx(Fn,{className:"h-3 w-3"})}):null,Xt=U?s.jsx(Hr,{className:"h-4 w-4 text-status-warning"}):null,us=ft=>{D(ft?ve:null)},ms=ft=>{ft.preventDefault(),ft.stopPropagation(),D($e?null:ve)},gs=ft=>{ft.preventDefault(),ft.stopPropagation()},ds=ft=>{ft.preventDefault(),ft.stopPropagation()},Ft=ft=>{ft.preventDefault(),ft.stopPropagation()},Ue=ft=>{ft.preventDefault(),ft.stopPropagation()},Tt=ft=>{ft.preventDefault(),ft.stopPropagation(),D(null),W(oe,{archivedBucket:o})},At=ft=>{if(_.current){_.current=!1;return}if(ke){if(ft?.preventDefault(),ft?.stopPropagation(),ft?.shiftKey){const es=(typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[]).map(X=>X.getAttribute("data-session-row")).filter(X=>typeof X=="string"&&X.length>0),Ts=hr.getState().anchorId,Ls=new Map;Ls.set(oe.id,Be(n)),Pe(Ts,oe.id,es,Se??null,Ls);return}he(oe.id,Se??null,Be(n));return}A(oe.id,Se,se,i)},vt=ft=>{(ft.button===2||ft.button===0&&ft.ctrlKey&&!ke)&&(_.current=!0)},Rt=ft=>{B&&ft.pointerType==="touch"&&Q(!0)},ns=ft=>{B&&ft.pointerType==="touch"&&Q(!1)},As=s.jsxs(Vs,{align:"end",className:"min-w-[180px]",onCloseAutoFocus:ft=>{T&&ft.preventDefault()},children:[s.jsxs($t,{onClick:()=>{y(oe.id),g(K)},className:"[&>svg]:mr-1",children:[s.jsx(Mi,{className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.rename")]}),s.jsxs($t,{onClick:()=>C(oe.id),className:"[&>svg]:mr-1",children:[He?s.jsx(av,{className:"mr-1 h-4 w-4"}):s.jsx(um,{className:"mr-1 h-4 w-4"}),e(He?"sessions.sidebar.session.menu.unpin":"sessions.sidebar.session.menu.pin")]}),Ie.share?s.jsxs(s.Fragment,{children:[s.jsx($t,{onClick:()=>{Ie.share?.url&&k(Ie.share.url,oe.id)},className:"[&>svg]:mr-1",children:R===oe.id?s.jsxs(s.Fragment,{children:[s.jsx(Ys,{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(br,{className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.copyLink")]})}),s.jsxs($t,{onClick:()=>P(oe.id),className:"[&>svg]:mr-1",children:[s.jsx(ov,{className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.unshare")]})]}):s.jsxs($t,{onClick:()=>I(Ie),className:"[&>svg]:mr-1",children:[s.jsx(iv,{className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.share")]}),s.jsxs($t,{onClick:()=>{ht()},className:"[&>svg]:mr-1",children:[s.jsx(Qr,{className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.exportMarkdown")]}),Se&&!o?(()=>{const ft=M(Se),is=$(Se,oe.id);return s.jsxs(s.Fragment,{children:[s.jsx(En,{}),s.jsxs(nw,{children:[s.jsxs(rw,{className:"[&>svg]:mr-1",children:[s.jsx(zn,{className:"h-4 w-4"}),e("sessions.sidebar.folders.moveToFolder")]}),s.jsxs(aw,{className:"min-w-[180px]",children:[ft.length===0?s.jsx($t,{disabled:!0,className:"text-muted-foreground",children:e("sessions.sidebar.folders.none")}):ft.map(es=>s.jsxs($t,{onClick:()=>{is===es.id?F(Se,oe.id):V(Se,es.id,oe.id)},children:[s.jsx("span",{className:"flex-1 truncate",children:es.name}),is===es.id?s.jsx(Ys,{className:"ml-2 h-3.5 w-3.5 text-primary flex-shrink-0"}):null]},es.id)),s.jsx(En,{}),s.jsxs($t,{onClick:()=>{const es=O(Se);es&&V(Se,es.id,oe.id)},children:[s.jsx(_s,{className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.newFolderEllipsis")]}),is?s.jsxs($t,{onClick:()=>{F(Se,oe.id)},className:"text-destructive focus:text-destructive",children:[s.jsx(Ds,{className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.removeFromFolder")]}):null]})]})]})})():null,J?null:s.jsxs($t,{disabled:!Se,onClick:()=>{Se&&L(Se,{mode:"chat",dedupeKey:`session:${oe.id}`,label:K})},className:"[&>svg]:mr-1",children:[s.jsx(dc,{className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:e("sessions.sidebar.session.menu.openInSidePanel")}),s.jsx("span",{className:"shrink-0 typography-micro px-1 rounded leading-none pb-px text-[var(--status-warning)] bg-[var(--status-warning)]/10",children:e("sessions.sidebar.session.menu.betaBadge")})]}),H?s.jsxs($t,{disabled:!Se,onClick:_t,className:"[&>svg]:mr-1",children:[s.jsx(Ti,{className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:e("sessions.sidebar.session.menu.openMiniChatWindow")})]}):null,s.jsx(En,{}),s.jsxs($t,{className:"text-destructive focus:text-destructive [&>svg]:mr-1",onClick:()=>W(oe,{archivedBucket:o}),children:[s.jsx(sn,{className:"mr-1 h-4 w-4"}),e(o?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive")]})]});return s.jsxs(l.Fragment,{children:[s.jsx(ZP,{sessionId:oe.id,sessionDirectory:Se??null,sessionTitle:K,children:s.jsxs("div",{"data-session-row":oe.id,"data-session-scope":Se??"","data-session-archived":o?"1":"0",className:pe("group relative my-0.5 flex items-center rounded-sm px-1.5 py-1",se?"opacity-75":"",r>0&&"pl-[20px]",xe&&"bg-primary/15"),children:[Yt,Qt,s.jsx("div",{className:"flex min-w-0 flex-1 items-center",children:z?s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx("button",{type:"button",disabled:se,onPointerDown:Rt,onPointerUp:ns,onPointerCancel:ns,onMouseDown:vt,onClick:ft=>At(ft),onDoubleClick:ft=>{ft.stopPropagation(),j()},className:pe("flex min-w-0 flex-1 cursor-pointer flex-col gap-0 overflow-hidden rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 text-foreground select-none disabled:cursor-not-allowed transition-[padding]",ue&&"bg-interactive-hover/70",ne?J?me:we:me),children:s.jsxs("div",{className:pe("flex w-full items-center min-w-0 flex-1 overflow-hidden","gap-1"),children:[s.jsx("div",{className:pe("block min-w-0 flex-1 truncate typography-ui-label font-normal",ie?"text-primary":"text-foreground"),children:So(K,h)}),ne?s.jsx("span",{className:"ml-2 flex-shrink-0 text-[0.72rem] text-muted-foreground/75",children:Ge}):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:pe("whitespace-nowrap text-right text-[0.72rem] text-muted-foreground/75 transition-opacity duration-150",$e?"opacity-0":ce),children:Ge})}),jt>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(mm,{className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:jt})]}):null]})})}),s.jsx(Ct,{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:pe("flex items-center gap-3 text-left text-muted-foreground",ee?.projectLabel?"justify-between":"justify-start"),children:[ee?.projectLabel?s.jsx("div",{className:"min-w-0 truncate",children:ee.projectLabel}):null,s.jsx("div",{className:"flex-shrink-0",children:ye})]}),ee?.branchLabel||ct?s.jsxs("div",{className:pe("flex items-center gap-3 text-left text-muted-foreground",ee?.branchLabel?"justify-between":"justify-start"),children:[ee?.branchLabel?s.jsx("div",{className:"flex min-w-0 items-center gap-1.5 overflow-hidden",children:s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(Ks,{className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:ee.branchLabel})]})}):null,ct?s.jsxs("span",{className:"flex flex-shrink-0 items-center gap-0.5",children:[s.jsxs("span",{className:"text-status-success",children:["+",ct.additions]}),s.jsxs("span",{className:"text-status-error",children:["-",ct.deletions]})]}):null]}):null]})})]}):s.jsxs("button",{type:"button",disabled:se,onPointerDown:Rt,onPointerUp:ns,onPointerCancel:ns,onMouseDown:vt,onClick:ft=>At(ft),onDoubleClick:ft=>{ft.stopPropagation(),j()},className:pe("flex min-w-0 flex-1 cursor-pointer flex-col gap-0 overflow-hidden rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 text-foreground select-none disabled:cursor-not-allowed transition-[padding]",ue&&"bg-interactive-hover/70",ne?J?me:we:me),children:[s.jsxs("div",{className:pe("flex w-full items-center min-w-0 flex-1 overflow-hidden","gap-1"),children:[s.jsx("div",{className:pe("block min-w-0 flex-1 truncate typography-ui-label font-normal",ie?"text-primary":"text-foreground"),children:So(K,h)}),jt>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(mm,{className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:jt})]}):null]}),z?null:s.jsx("div",{className:"flex items-center justify-between gap-3 text-muted-foreground/60 min-w-0 overflow-hidden leading-tight",style:{fontSize:"calc(var(--text-ui-label) * 0.85)"},children:s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 overflow-hidden",children:[s.jsx("span",{className:"flex-shrink-0",children:ye}),ct?s.jsxs("span",{className:"flex flex-shrink-0 items-center gap-0 text-[0.92em]",children:[s.jsxs("span",{className:"text-status-success/80",children:["+",ct.additions]}),s.jsx("span",{className:"text-muted-foreground/60",children:"/"}),s.jsxs("span",{className:"text-status-error/65",children:["-",ct.deletions]})]}):null,ge?s.jsx("span",{className:"truncate",children:ee?.projectLabel}):null,te?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(Ks,{className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:ee?.branchLabel})]}):null]})})]})}),Xt&&!B?s.jsx("div",{className:pe("absolute top-1/2 -translate-y-1/2 z-10",z?"right-0":"right-[30px]"),children:Xt}):null,s.jsxs("div",{className:pe("absolute right-0 top-1/2 z-10 flex -translate-y-1/2 items-center gap-0.5 transition-opacity",$e||ne&&!J?"opacity-100":pe("opacity-0",re)),children:[Ne?s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx("button",{type:"button",className:pe("inline-flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",z&&!ne?"h-4 w-4":"h-6 w-6"),"aria-label":e("sessions.sidebar.bulkActions.archive"),onPointerDown:Ft,onMouseDown:Ue,onClick:Tt,onKeyDown:ft=>ft.stopPropagation(),children:s.jsx(Od,{className:pe(z&&!ne?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),s.jsx(Ct,{side:"left",sideOffset:8,children:e("sessions.sidebar.bulkActions.archive")})]}):null,s.jsxs(zs,{open:$e,onOpenChange:us,children:[s.jsx(Bs,{asChild:!0,children:s.jsx("button",{type:"button",className:pe("inline-flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",z&&!ne?$e?"h-4 w-4 opacity-100":pe("h-4 w-4 opacity-0",re):"h-6 w-6 opacity-100"),"aria-label":e("sessions.sidebar.session.menu.label"),onPointerDown:gs,onMouseDown:ds,onClick:ms,onKeyDown:ft=>ft.stopPropagation(),children:s.jsx(ia,{className:pe(z&&!ne?"h-2.5 w-2.5":"h-3.5 w-3.5")})})}),As]})]})]})}),_e&&Ke?n.children.map(ft=>le(ft,r+1,Se??a,i,o,void 0,ae)):null,s.jsx(ws,{open:G,onOpenChange:be,children:s.jsxs(vs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[s.jsxs(Is,{children:[s.jsx(Ss,{children:e("sessions.sidebar.session.export.dialog.title")}),s.jsx(Os,{children:Ve===1?e("sessions.sidebar.session.export.dialog.descriptionSingle",{count:Ve}):e("sessions.sidebar.session.export.dialog.descriptionMany",{count:Ve})})]}),s.jsxs("label",{className:"flex items-center gap-2 typography-ui-label cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:De,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(Qs,{children:[s.jsx(je,{type:"button",onClick:()=>be(!1),variant:"outline",size:"sm",children:e("sessions.sidebar.dialogs.cancel")}),s.jsx(je,{type:"button",onClick:()=>{be(!1),ze(De)},size:"sm",children:e("sessions.sidebar.session.export.dialog.confirm")})]})]})})]},oe.id)}const QD=l.memo(qD,GD);function JD(t){const e=nt.c(71),{t:n}=ut(),{value:r,setValue:a,showDeletionDialog:i,setShowDeletionDialog:o,onConfirm:c}=t;let d,p,m,u,h,b,f,y,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=W=>{W||a(null)},e[13]=a,e[14]=g):g=e[14],m=vs,f=!1,y="max-w-sm gap-5",p=Is;let L;e[15]!==n||e[16]!==r?.archivedBucket?(L=r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.title"):n("sessions.sidebar.dialogs.archiveSession.title"),e[15]=n,e[16]=r?.archivedBucket,e[17]=L):L=e[17],e[18]!==L?(b=s.jsx(Ss,{children:L}),e[18]=L,e[19]=b):b=e[19],d=Os,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]=y,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],y=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 v;e[23]!==p||e[24]!==b||e[25]!==w?(v=s.jsxs(p,{children:[b,w]}),e[23]=p,e[24]=b,e[25]=w,e[26]=v):v=e[26];let S;e[27]!==o||e[28]!==i?(S=()=>o(!i),e[27]=o,e[28]=i,e[29]=S):S=e[29];const A=!i;let j;e[30]!==i?(j=i?s.jsx(Ei,{className:"h-4 w-4"}):s.jsx(Ri,{className:"h-4 w-4 text-primary"}),e[30]=i,e[31]=j):j=e[31];let C;e[32]!==n?(C=n("sessions.sidebar.dialogs.neverAsk"),e[32]=n,e[33]=C):C=e[33];let I;e[34]!==j||e[35]!==C||e[36]!==S||e[37]!==A?(I=s.jsxs("button",{type:"button",onClick:S,className:"inline-flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":A,children:[j,C]}),e[34]=j,e[35]=C,e[36]=S,e[37]=A,e[38]=I):I=e[38];let R;e[39]!==a?(R=()=>a(null),e[39]=a,e[40]=R):R=e[40];let k;e[41]!==n?(k=n("sessions.sidebar.dialogs.cancel"),e[41]=n,e[42]=k):k=e[42];let P;e[43]!==R||e[44]!==k?(P=s.jsx("button",{type:"button",onClick:R,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:k}),e[43]=R,e[44]=k,e[45]=P):P=e[45];let N;e[46]!==c?(N=()=>{c()},e[46]=c,e[47]=N):N=e[47];let D;e[48]!==n||e[49]!==r?.archivedBucket?(D=r?.archivedBucket?n("sessions.sidebar.bulkActions.delete"):n("sessions.sidebar.bulkActions.archive"),e[48]=n,e[49]=r?.archivedBucket,e[50]=D):D=e[50];let T;e[51]!==N||e[52]!==D?(T=s.jsx("button",{type:"button",onClick:N,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:D}),e[51]=N,e[52]=D,e[53]=T):T=e[53];let M;e[54]!==P||e[55]!==T?(M=s.jsxs("div",{className:"flex items-center gap-2",children:[P,T]}),e[54]=P,e[55]=T,e[56]=M):M=e[56];let $;e[57]!==I||e[58]!==M?($=s.jsxs(Qs,{className:"w-full sm:items-center sm:justify-between",children:[I,M]}),e[57]=I,e[58]=M,e[59]=$):$=e[59];let F;e[60]!==m||e[61]!==f||e[62]!==$||e[63]!==y||e[64]!==v?(F=s.jsxs(m,{showCloseButton:f,className:y,children:[v,$]}),e[60]=m,e[61]=f,e[62]=$,e[63]=y,e[64]=v,e[65]=F):F=e[65];let V;return e[66]!==u||e[67]!==F||e[68]!==x||e[69]!==g?(V=s.jsx(u,{open:x,onOpenChange:g,children:F}),e[66]=u,e[67]=F,e[68]=x,e[69]=g,e[70]=V):V=e[70],V}function YD(t){const e=nt.c(57),{t:n}=ut(),{value:r,setValue:a,showDeletionDialog:i,setShowDeletionDialog:o,onConfirm:c}=t,d=r?.archivedBucket===!0,p=r?.sessionCount??0;let m;e[0]!==d||e[1]!==p||e[2]!==n?(m=n(d?p===1?"sessions.sidebar.dialogs.deleteSession.title":"sessions.sidebar.dialogs.deleteSessions.title":p===1?"sessions.sidebar.dialogs.archiveSession.title":"sessions.sidebar.dialogs.archiveSessions.title"),e[0]=d,e[1]=p,e[2]=n,e[3]=m):m=e[3];const u=m;let 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 y;e[8]!==a?(y=V=>{V||a(null)},e[8]=a,e[9]=y):y=e[9];let x;e[10]!==u?(x=s.jsx(Ss,{children:u}),e[10]=u,e[11]=x):x=e[11];let g;e[12]!==b?(g=s.jsx(Os,{children:b}),e[12]=b,e[13]=g):g=e[13];let w;e[14]!==x||e[15]!==g?(w=s.jsxs(Is,{children:[x,g]}),e[14]=x,e[15]=g,e[16]=w):w=e[16];let v;e[17]!==o||e[18]!==i?(v=()=>o(!i),e[17]=o,e[18]=i,e[19]=v):v=e[19];const S=!i;let A;e[20]!==i?(A=i?s.jsx(Ei,{className:"h-4 w-4"}):s.jsx(Ri,{className:"h-4 w-4 text-primary"}),e[20]=i,e[21]=A):A=e[21];let j;e[22]!==n?(j=n("sessions.sidebar.dialogs.neverAsk"),e[22]=n,e[23]=j):j=e[23];let C;e[24]!==j||e[25]!==v||e[26]!==S||e[27]!==A?(C=s.jsxs("button",{type:"button",onClick:v,className:"inline-flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":S,children:[A,j]}),e[24]=j,e[25]=v,e[26]=S,e[27]=A,e[28]=C):C=e[28];let I;e[29]!==a?(I=()=>a(null),e[29]=a,e[30]=I):I=e[30];let R;e[31]!==n?(R=n("sessions.sidebar.dialogs.cancel"),e[31]=n,e[32]=R):R=e[32];let k;e[33]!==I||e[34]!==R?(k=s.jsx("button",{type:"button",onClick:I,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:R}),e[33]=I,e[34]=R,e[35]=k):k=e[35];let P;e[36]!==c?(P=()=>{c()},e[36]=c,e[37]=P):P=e[37];let N;e[38]!==d||e[39]!==n?(N=n(d?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[38]=d,e[39]=n,e[40]=N):N=e[40];let D;e[41]!==P||e[42]!==N?(D=s.jsx("button",{type:"button",onClick:P,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]=P,e[42]=N,e[43]=D):D=e[43];let T;e[44]!==k||e[45]!==D?(T=s.jsxs("div",{className:"flex items-center gap-2",children:[k,D]}),e[44]=k,e[45]=D,e[46]=T):T=e[46];let M;e[47]!==C||e[48]!==T?(M=s.jsxs(Qs,{className:"w-full sm:items-center sm:justify-between",children:[C,T]}),e[47]=C,e[48]=T,e[49]=M):M=e[49];let $;e[50]!==M||e[51]!==w?($=s.jsxs(vs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[w,M]}),e[50]=M,e[51]=w,e[52]=$):$=e[52];let F;return e[53]!==f||e[54]!==$||e[55]!==y?(F=s.jsx(ws,{open:f,onOpenChange:y,children:$}),e[53]=f,e[54]=$,e[55]=y,e[56]=F):F=e[56],F}function XD(t){const e=nt.c(36),{t:n}=ut(),{value:r,setValue:a,onConfirm:i}=t,o=!!r;let c;e[0]!==a?(c=A=>{A||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(Ss,{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(Os,{children:m}),e[9]=m,e[10]=u):u=e[10];let h;e[11]!==p||e[12]!==u?(h=s.jsxs(Is,{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 y;e[18]!==b||e[19]!==f?(y=s.jsx("button",{type:"button",onClick:b,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:f}),e[18]=b,e[19]=f,e[20]=y):y=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]!==y?(w=s.jsxs(Qs,{children:[y,g]}),e[26]=g,e[27]=y,e[28]=w):w=e[28];let v;e[29]!==w||e[30]!==h?(v=s.jsxs(vs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[h,w]}),e[29]=w,e[30]=h,e[31]=v):v=e[31];let S;return e[32]!==o||e[33]!==c||e[34]!==v?(S=s.jsx(ws,{open:o,onOpenChange:c,children:v}),e[32]=o,e[33]=c,e[34]=v,e[35]=S):S=e[35],S}const ZD=t=>{const e=nt.c(46),{selectedCount:n,scopeKey:r,scopeFolders:a,archivedBucket:i,onMoveToFolder:o,onCreateFolderAndMove:c,onRemoveFromFolder:d,canRemoveFromFolder:p,onDelete:m,onDone:u}=t,{t:h}=ut(),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 y=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(zs,{children:[s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx(Bs,{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(zn,{className:"h-4 w-4"})})})}),s.jsx(Ct,{side:"top",sideOffset:4,children:s.jsx("p",{children:h("sessions.sidebar.bulkActions.moveToFolder")})})]}),s.jsxs(Vs,{align:"end",className:"min-w-[180px]",children:[a.length===0?s.jsx($t,{disabled:!0,className:"text-muted-foreground",children:h("sessions.sidebar.folders.none")}):a.map($=>s.jsx($t,{onClick:()=>o($.id),children:s.jsx("span",{className:"flex-1 truncate",children:$.name})},$.id)),s.jsx(En,{}),s.jsxs($t,{onClick:c,children:[s.jsx(_s,{className:"mr-1 h-4 w-4"}),h("sessions.sidebar.folders.newFolderEllipsis")]}),p?s.jsxs($t,{onClick:d,className:"text-destructive focus:text-destructive",children:[s.jsx(Ds,{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 v;e[16]===Symbol.for("react.memo_cache_sentinel")?(v=pe("inline-flex h-7 w-7 items-center justify-center rounded-md text-destructive hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50"),e[16]=v):v=e[16];let S;e[17]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsx(sn,{className:"h-4 w-4"}),e[17]=S):S=e[17];let A;e[18]!==y||e[19]!==m?(A=s.jsx(St,{asChild:!0,children:s.jsx("button",{type:"button",onClick:m,className:v,"aria-label":y,children:S})}),e[18]=y,e[19]=m,e[20]=A):A=e[20];let j;e[21]!==y?(j=s.jsx(Ct,{side:"top",sideOffset:4,children:s.jsx("p",{children:y})}),e[21]=y,e[22]=j):j=e[22];let C;e[23]!==A||e[24]!==j?(C=s.jsxs(kt,{children:[A,j]}),e[23]=A,e[24]=j,e[25]=C):C=e[25];let I;e[26]!==h?(I=h("sessions.sidebar.header.actions.exitSelection"),e[26]=h,e[27]=I):I=e[27];let R;e[28]===Symbol.for("react.memo_cache_sentinel")?(R=s.jsx(Ds,{className:"h-4 w-4"}),e[28]=R):R=e[28];let k;e[29]!==u||e[30]!==I?(k=s.jsx(St,{asChild:!0,children:s.jsx("button",{type:"button",onClick:u,className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":I,children:R})}),e[29]=u,e[30]=I,e[31]=k):k=e[31];let P;e[32]!==h?(P=h("sessions.sidebar.header.actions.exitSelection"),e[32]=h,e[33]=P):P=e[33];let N;e[34]!==P?(N=s.jsx(Ct,{side:"top",sideOffset:4,children:s.jsx("p",{children:P})}),e[34]=P,e[35]=N):N=e[35];let D;e[36]!==k||e[37]!==N?(D=s.jsxs(kt,{children:[k,N]}),e[36]=k,e[37]=N,e[38]=D):D=e[38];let T;e[39]!==D||e[40]!==w||e[41]!==C?(T=s.jsxs("div",{className:"ml-auto flex items-center gap-0.5",children:[w,C,D]}),e[39]=D,e[40]=w,e[41]=C,e[42]=T):T=e[42];let M;return e[43]!==T||e[44]!==g?(M=s.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-t border-border px-2.5 py-1.5",children:[g,T]}),e[43]=T,e[44]=g,e[45]=M):M=e[45],M},Xx="oc.sessions.activeNow",eT=2160*60*1e3,Zx=t=>!!t.parentID,em=t=>!!t.time?.archived,du=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},tT=t=>{try{const e=t.getItem(Xx);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[]}},uh=(t,e)=>{try{t.setItem(Xx,JSON.stringify(e))}catch{}},sT=(t,e,n=Date.now())=>{const r=n-eT;return t.filter(a=>{const i=e.get(a.sessionId);return i?em(i)?!1:du(i)>=r:!0})},nT=(t,e)=>!e||t.some(n=>n.sessionId===e)?t:[{sessionId:e},...t],eb=t=>[...t].sort((e,n)=>du(n)-du(e)),rT=(t,e)=>{const n=t.map(r=>e.get(r.sessionId)??null).filter(r=>!!r).filter(r=>!em(r)).filter(r=>!Zx(r));return eb(n)},aT=(t,e)=>{const n=t.filter(r=>{if(em(r)||Zx(r))return!1;const a=e[r.id];return a?.type==="busy"||a?.type==="retry"});return eb(n)},bl="oc.sessions.projectCollapse",mh="oc.sessions.groupOrder",ph="oc.sessions.groupCollapse",fh="oc.sessions.activeSessionByProject",wd="oc.sessions.expandedParents",hh="oc.sessions.pinned",iT=(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},oT=(t,e)=>{if(t.time?.archived)return!0;const n=ks(kl(t))?.toLowerCase();return!n||e.size===0?!0:e.has(n)},lT=5*6e4,gh=({mobileVariant:t=!1,onSessionSelected:e,allowReselect:n=!1,hideDirectoryControls:r=!1,showOnlyMainWorkspace:a=!1})=>{const{t:i}=ut(),[o,c]=l.useState(!1),[d,p]=l.useState(""),m=l.useRef(null),u=l.useRef(null),h=l.useRef(new Set),[b,f]=l.useState(null),[y,x]=l.useState(""),[g,w]=l.useState(null),[v,S]=l.useState(new Set),[A]=l.useState(()=>new Map),j=l.useMemo(()=>ba(),[]),[C,I]=l.useState(()=>tT(j)),[R,k]=l.useState(new Set),[P,N]=l.useState(new Map),[D,T]=l.useState(new Set),[M,$]=l.useState(!1),[F,V]=l.useState(!1),[O,L]=l.useState(null),[W,B]=l.useState(null),[ne,le]=l.useState(""),[ee,ae]=l.useState(null),[ge,te]=l.useState(null),[E,z]=l.useState(null),[J,H]=l.useState(()=>{try{const Me=ba().getItem(hh);if(!Me)return new Set;const xt=JSON.parse(Me);return new Set(Array.isArray(xt)?xt.filter(ot=>typeof ot=="string"):[])}catch{return new Set}}),[re,ce]=l.useState(()=>{try{const Me=ba().getItem(ph);if(!Me)return new Set;const xt=JSON.parse(Me);return new Set(Array.isArray(xt)?xt.filter(ot=>typeof ot=="string"):[])}catch{return new Set}}),[Ne,me]=l.useState(()=>{try{const Me=ba().getItem(mh);if(!Me)return new Map;const xt=JSON.parse(Me),ot=new Map;return Object.entries(xt).forEach(([Gt,Ce])=>{Array.isArray(Ce)&&ot.set(Gt,Ce.filter(qe=>typeof qe=="string"))}),ot}catch{return new Map}}),[we,_]=l.useState(()=>{try{const Me=ba().getItem(fh);if(!Me)return new Map;const xt=JSON.parse(Me),ot=new Map;return Object.entries(xt).forEach(([Gt,Ce])=>{typeof Ce=="string"&&Ce.length>0&&ot.set(Gt,Ce)}),ot}catch{return new Map}}),[ue,Q]=l.useState(new Map),oe=l.useRef(new Map),Z=l.useRef(0),Ie=Ws(Me=>Me.homeDirectory),Se=Ws(Me=>Me.currentDirectory),Y=Ws(Me=>Me.setDirectory),fe=Fs(Me=>Me.projects),ke=Fs(Me=>Me.activeProjectId),xe=Fs(Me=>Me.removeProject),he=Fs(Me=>Me.setActiveProjectIdOnly),Pe=Fs(Me=>Me.updateProjectMeta),Be=Fs(Me=>Me.reorderProjects),G=Te(Me=>Me.setActiveMainTab),be=Te(Me=>Me.openContextPanelTab),De=Te(Me=>Me.setSettingsDialogOpen),Ae=Te(Me=>Me.toggleHelpDialog),ve=Te(Me=>Me.setAboutDialogOpen),U=Te(Me=>Me.setSessionSwitcherOpen),de=Te(Me=>Me.setScheduledTasksDialogOpen),Re=Te(Me=>Me.toggleSidebar),Le=Te(Me=>Me.openMultiRunLauncher),se=Te(Me=>Me.notifyOnSubtasks),ie=Te(Me=>Me.showDeletionDialog),K=Te(Me=>Me.setShowDeletionDialog),_e=bc(d,120),He=l.useMemo(()=>_e.trim().toLowerCase(),[_e]),Ke=He.length>0,Ze=rr(Me=>Me.collapsedFolderIds),Xe=rr(Me=>Me.foldersMap),mt=rr(Me=>Me.getFoldersForScope),et=rr(Me=>Me.createFolder),ct=rr(Me=>Me.renameFolder),lt=rr(Me=>Me.deleteFolder),ye=rr(Me=>Me.addSessionToFolder),Ge=rr(Me=>Me.addSessionsToFolder),$e=rr(Me=>Me.removeSessionFromFolder),Ve=rr(Me=>Me.removeSessionsFromFolders),tt=rr(Me=>Me.toggleFolderCollapse),Qe=rr(Me=>Me.cleanupSessions),ze=rr(Me=>Me.getSessionFolderId);bP({isSessionSearchOpen:o,setIsSessionSearchOpen:c,sessionSearchInputRef:u,sessionSearchContainerRef:m});const ht=Ng(),_t=Dg(),Kt=ag(),Ut=ow(),jt=jo(Me=>Me.hasLoaded),Dt=jo(Me=>Me.activeSessions),ts=jo(Me=>Me.archivedSessions),it=Wt(Me=>Me.currentSessionId),Yt=Wt(Me=>!!Me.newSessionDraft?.open),Qt=Wt(Me=>Me.setCurrentSession),Xt=Wt(Me=>Me.updateSessionTitle),us=Wt(Me=>Me.shareSession),ms=Wt(Me=>Me.unshareSession),gs=Wt(Me=>Me.worktreeMetadata),ds=Wt(Me=>Me.availableWorktreesByProject),Ft=Wt(Me=>Me.openNewSessionDraft),Ue=Ya(jr(Me=>({checkForUpdates:Me.checkForUpdates,available:Me.available,runtimeType:Me.runtimeType,info:Me.info,downloading:Me.downloading,downloaded:Me.downloaded,progress:Me.progress,error:Me.error,downloadUpdate:Me.downloadUpdate,restartToUpdate:Me.restartToUpdate}))),Tt=l.useMemo(()=>iT(fe,ds),[ds,fe]),At=l.useMemo(()=>{const Me=new Map(Kt.map(Gt=>[Gt.id,Gt])),xt=Dt.map(Gt=>Me.get(Gt.id)??Gt),ot=new Set(xt.map(Gt=>Gt.id));return Kt.forEach(Gt=>{ot.has(Gt.id)||xt.push(Gt)}),xt.filter(Gt=>oT(Gt,Tt))},[Dt,Tt,Kt]),vt=l.useMemo(()=>Kt.map(Me=>{const xt=ks(Me.directory??null)??"";return`${Me.id}:${Me.title??""}:${Me.time?.archived?1:0}:${xt}`}).join("|"),[Kt]),Rt=l.useRef(Kt);l.useEffect(()=>{Rt.current=Kt},[vt,Kt]),l.useEffect(()=>{let Me=!1;const xt=async()=>{const ot=Fs.getState().projects;if(ot.length===0)return;const Gt=new Map,Ce=[];await Promise.all(ot.map(async qe=>{const dt=ks(qe.path);if(dt)try{if(!(pn.getState().directories.get(dt)?.isGitRepo??await Tr(()=>import("./modelPrefsAutoSave-BHV5Gay8.js").then(Ns=>Ns.eQ),__vite__mapDeps([2,0,1,3,4])).then(Ns=>Ns.checkIsGitRepository(dt))))return;const qt=await $d({id:qe.id,path:dt});if(Me||qt.length===0)return;Gt.set(dt,qt),Ce.push(...qt)}catch{}})),!Me&&Wt.setState({availableWorktrees:Ce,availableWorktreesByProject:Gt})};return Bd(Rt.current),xt(),()=>{Me=!0}},[Se,vt,fe]),l.useEffect(()=>{let Me=null;const xt=qx(ot=>{ot.type==="scheduled-task-ran"&&(Me&&clearTimeout(Me),Me=setTimeout(()=>{Bd(Rt.current)},500))});return()=>{Me&&clearTimeout(Me),xt()}},[]);const ns=l.useMemo(()=>kn(),[]),As=pc(),[ft,is]=l.useState(!1),es=l.useMemo(()=>yn(),[]),{isTablet:Ts}=un(),Ls=t||Ts,X=l.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),pt=!t&&!es&&!ns,wt=!t&&!es&&!pt,zt=ns&&X&&!ft||As?"pl-[5.5rem]":"pl-3",ss="app-region-no-drag inline-flex h-8 w-8 items-center justify-center rounded-md typography-ui-label font-medium text-foreground transition-colors hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:pointer-events-none disabled:opacity-50";l.useEffect(()=>{if(!ns||!X){is(!1);return}let Me=!1,xt=null;const ot=async()=>{try{const Ce=await dw();Me||is(Ce)}catch{Me||is(!1)}},Gt=async()=>{try{xt=uw(()=>{ot()})}catch{}};return ot(),Gt(),()=>{Me=!0,xt&&xt()}},[ns,X]);const os=l.useCallback(async Me=>{const xt=Me.target;xt.closest(".app-region-no-drag")||xt.closest("button, a, input, select, textarea")||Me.button===0&&ns&&await Mg()},[ns]),{buildGroupSearchText:Ps,filterSessionNodesForSearch:Ms,buildGroupedSessions:We}=xP({homeDirectory:Ie,worktreeMetadata:gs,pinnedSessionIds:J,gitBranches:ht,isVSCode:es}),{scheduleCollapsedProjectsPersist:gt}=wP({isVSCode:es,hasLoadedGlobalSessions:jt,safeStorage:j,keys:{sessionExpanded:wd,projectCollapse:bl,sessionPinned:hh,groupOrder:mh,projectActiveSession:fh,groupCollapse:ph},sessions:At,pinnedSessionIds:J,setPinnedSessionIds:H,groupOrderByProject:Ne,activeSessionByProject:we,collapsedGroups:re,setExpandedParents:S,setCollapsedProjects:k}),Mt=l.useCallback(Me=>{H(xt=>{const ot=new Set(xt);return ot.has(Me)?ot.delete(Me):ot.add(Me),ot})},[]),Et=l.useMemo(()=>[...At].sort((Me,xt)=>Oi(Me,xt,J)),[At,J]),as=l.useMemo(()=>new Map(Et.map((Me,xt)=>[Me.id,xt])),[Et]),st=l.useMemo(()=>{const Me=new Map;return Et.forEach(xt=>{const ot=xt.parentID;if(!ot)return;const Gt=Me.get(ot)??[];Gt.push(xt),Me.set(ot,Gt)}),Me.forEach(xt=>xt.sort((ot,Gt)=>Oi(ot,Gt,J))),Me},[Et,J]),Lt=s.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-ui-label font-semibold",children:i("sessions.sidebar.empty.noSessions.title")}),s.jsx("p",{className:"typography-meta mt-1",children:i("sessions.sidebar.empty.noSessions.description")})]}),ls=l.useMemo(()=>fe.find(Me=>Me.id===g)??null,[fe,g]),rs=l.useCallback(Me=>{g&&(Pe(g,Me),w(null))},[g,Pe]),Bt=l.useCallback(()=>{$(!0)},[]),xs=l.useCallback(()=>{const Me=Ya.getState();if(Me.available&&Me.info){V(!0);return}Ue.checkForUpdates().then(()=>{const{available:xt,error:ot}=Ya.getState();if(ot){q.error(i("sessions.sidebar.updateCheck.errorTitle"),{description:ot});return}if(!xt){q.success(i("sessions.sidebar.updateCheck.latestVersion"));return}V(!0)})},[i,Ue]),mn=l.useCallback(()=>{t&&U(!1),De(!0)},[t,U,De]),js=Ue.available&&(Ue.runtimeType==="desktop"||Ue.runtimeType==="web"),xn=Wt(Me=>Me.deleteSession),In=Wt(Me=>Me.deleteSessions),an=Wt(Me=>Me.archiveSession),An=Wt(Me=>Me.archiveSessions),{copiedSessionId:on,handleSessionSelect:ln,handleSessionDoubleClick:fn,handleSaveEdit:cr,handleCancelEdit:Vr,handleShareSession:Fe,handleCopyShareUrl:Nt,handleUnshareSession:Ht,handleDeleteSession:cs,confirmDeleteSession:Xs}=yP({activeProjectId:ke,currentDirectory:Se,currentSessionId:it,mobileVariant:t,allowReselect:n,onSessionSelected:e,isSessionSearchOpen:o,sessionSearchQuery:d,setSessionSearchQuery:p,setIsSessionSearchOpen:c,setActiveProjectIdOnly:he,setDirectory:Y,setActiveMainTab:G,setSessionSwitcherOpen:U,setCurrentSession:Qt,updateSessionTitle:Xt,shareSession:us,unshareSession:ms,deleteSession:xn,deleteSessions:In,archiveSession:an,archiveSessions:An,childrenMap:st,showDeletionDialog:ie,setDeleteSessionConfirm:ae,deleteSessionConfirm:ee,setEditingId:f,setEditTitle:x,editingId:b,editTitle:y}),Zs=l.useCallback(()=>{if(!ge)return;const{scopeKey:Me,folderId:xt}=ge;te(null),lt(Me,xt)},[ge,lt]),Gs=l.useCallback(()=>{Dr.requestDirectoryDialog()},[]);l.useEffect(()=>{if(!it)return;const xt=At.find(ot=>ot.id===it)?.parentID;xt&&S(ot=>{if(ot.has(xt))return ot;const Gt=new Set(ot);Gt.add(xt);try{j.setItem(wd,JSON.stringify(Array.from(Gt)))}catch{}return Gt})},[it,At,j]);const en=l.useCallback(Me=>{S(xt=>{const ot=new Set(xt);ot.has(Me)?ot.delete(Me):ot.add(Me);try{j.setItem(wd,JSON.stringify(Array.from(ot)))}catch{}return ot})},[j]),hn=l.useCallback((Me,xt)=>{if(!Me)return null;xt&&Ze.has(xt)&&tt(xt);const ot=et(Me,i("sessions.sidebar.folder.newFolderName"),xt);return B(ot.id),le(ot.name),ot},[Ze,tt,et,i]),vn=l.useCallback(Me=>{T(xt=>{const ot=new Set(xt);return ot.has(Me)?ot.delete(Me):ot.add(Me),ot})},[]),dr=l.useCallback(()=>{Z.current=Date.now()+150,k(()=>{const Me=new Set(fe.map(xt=>xt.id));try{j.setItem(bl,JSON.stringify(Array.from(Me)))}catch{}return es||gt(Me),Me})},[fe,es,j,gt]),Zr=l.useCallback(()=>{Z.current=Date.now()+150,k(()=>{const Me=new Set;try{j.setItem(bl,JSON.stringify([]))}catch{}return es||gt(Me),Me})},[es,j,gt]),ea=l.useCallback(Me=>{Z.current=Date.now()+150,k(xt=>{const ot=new Set(xt);ot.has(Me)?ot.delete(Me):ot.add(Me);try{j.setItem(bl,JSON.stringify(Array.from(ot)))}catch{}return es||gt(ot),ot})},[es,j,gt]),On=l.useMemo(()=>fe.map(Me=>({...Me,normalizedPath:ks(Me.path)})).filter(Me=>!!Me.normalizedPath),[fe]),Ln=l.useMemo(()=>On.map(Me=>Me.normalizedPath),[On]),{github:er}=Gn(),bn=Zn(Me=>Me.status),qn=Zn(Me=>Me.hasChecked),$n=lw(Ln),zr=gr(Me=>Me.ensureEntry),_r=gr(Me=>Me.setParams),Ia=gr(Me=>Me.refreshTargets);IP({normalizedProjects:On,gitRepoStatus:$n,setProjectRepoStatus:N,setProjectRootBranches:Q});const Aa=Wt(Me=>Me.isLoading);OP({isSessionsLoading:Aa,sessions:At,archivedSessions:ts,normalizedProjects:On,isVSCode:es,availableWorktreesByProject:ds,cleanupSessions:Qe});const{getSessionsForProject:ur,getArchivedSessionsForProject:tr}=TP({isVSCode:es,sessions:At,archivedSessions:ts,availableWorktreesByProject:ds});cP({normalizedProjects:On,sessions:At,archivedSessions:ts,availableWorktreesByProject:ds,isVSCode:es,isSessionsLoading:Aa,foldersMap:Xe,createFolder:et,addSessionToFolder:ye,cleanupSessions:Qe});const qs=l.useRef(!1);ke&&P.has(ke)&&(qs.current=!!P.get(ke));const{projectSections:Cn,groupSearchDataByGroup:mi,sectionsForRender:Er,searchMatchCount:da}=mP({normalizedProjects:On,getSessionsForProject:ur,getArchivedSessionsForProject:tr,availableWorktreesByProject:ds,projectRepoStatus:P,projectRootBranches:ue,lastRepoStatus:qs.current,buildGroupedSessions:We,hasSessionSearchQuery:Ke,normalizedSessionSearchQuery:He,filterSessionNodesForSearch:Ms,buildGroupSearchText:Ps,foldersMap:Xe}),pi=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")})]}),Qn=!0,{currentSessionDirectory:Pa}=fP({projectSections:Cn,activeProjectId:ke,activeSessionByProject:we,setActiveSessionByProject:_,currentSessionId:it,handleSessionSelect:ln,newSessionDraftOpen:Yt,mobileVariant:t,openNewSessionDraft:Ft,setActiveMainTab:G,setSessionSwitcherOpen:U,sessions:At,worktreeMetadata:gs}),{getOrderedGroups:to}=hP(Ne),fi=l.useRef(!1);l.useEffect(()=>{if(fi.current||Cn.length===0)return;const Me=Cn.flatMap(xt=>xt.groups.filter(ot=>ot.isArchivedBucket).map(ot=>`${xt.project.id}:${ot.id}`));Me.length>0&&ce(xt=>new Set([...xt,...Me])),fi.current=!0},[Cn]);const Da=l.useMemo(()=>{const Me=new Map,xt=new Map;return Cn.forEach(ot=>{const Gt=Pg(ot.project.label?.trim()||ii(ot.project.normalizedPath,Ie)||ot.project.normalizedPath);ot.groups.forEach(Ce=>{const qe=Ce.branch&&Ce.branch!==Gt?{projectLabel:Gt,branchLabel:Ce.branch}:{projectLabel:Gt,branchLabel:null},dt=bt=>{bt.forEach(Pt=>{const qt=ot.project.normalizedPath.length,Ns=xt.get(Pt.session.id)??-1;qt<Ns||(Me.set(Pt.session.id,{node:Pt,projectId:ot.project.id,groupDirectory:Ce.directory,secondaryMeta:qe}),xt.set(Pt.session.id,qt),Pt.children.length>0&&dt(Pt.children))})};dt(Ce.sessions)})}),Me},[Cn,Ie]),sr=Ha(Me=>Me.showRecentSection),Ee=l.useMemo(()=>sr?rT(C,new Map(At.map(Me=>[Me.id,Me]))).sort((Me,xt)=>Oi(Me,xt,J)):[],[C,J,At,sr]),Je=l.useMemo(()=>sr?aT(At,Ut):[],[Ut,At,sr]);l.useEffect(()=>{!sr||Je.length===0||I(Me=>{const xt=Je.reduce((ot,Gt)=>nT(ot,Gt.id),Me);return xt===Me?Me:(uh(j,xt),xt)})},[Je,j,sr]),l.useEffect(()=>{if(!sr)return;const Me=new Map;[...At,...ts].forEach(ot=>{Me.set(ot.id,ot)});const xt=sT(C,Me);xt.length===C.length&&xt.every((ot,Gt)=>ot.sessionId===C[Gt]?.sessionId)||(I(xt),uh(j,xt))},[C,ts,j,At,sr]);const Ye=l.useMemo(()=>{if(!sr)return[];const Me=xt=>{const ot=Da.get(xt.id),Gt=ks(xt.directory??null);return{node:ot?.node??{session:xt,children:[],worktree:null},projectId:ot?.projectId??null,groupDirectory:ot?.groupDirectory??Gt,secondaryMeta:ot?.secondaryMeta??null}};return[{key:"active-now",title:i("sessions.sidebar.activity.recentTitle"),items:Ee.map(Me)}]},[Ee,Da,sr,i]),at=l.useMemo(()=>new Set(Ee.map(Me=>Me.id)),[Ee]),It=l.useMemo(()=>[...at],[at]);CA({currentSessionId:it,sortedSessions:Et,recentSessionIds:It,ensureSessionRenderable:_t.ensureSessionRenderable});const Jt=l.useMemo(()=>{if(!es||Ke||at.size===0)return Er;const Me=xt=>xt.reduce((ot,Gt)=>{if(at.has(Gt.session.id))return ot;const Ce=Me(Gt.children);return Ce.length===Gt.children.length?(ot.push(Gt),ot):(ot.push({...Gt,children:Ce}),ot)},[]);return Er.map(xt=>({...xt,groups:xt.groups.map(ot=>({...ot,sessions:Me(ot.sessions)}))}))},[es,Ke,at,Er]),Js=l.useMemo(()=>{const Me=new Set;return Jt.forEach(xt=>{xt.groups.forEach(ot=>{const Gt=ks(ot.directory??null),Ce=ot.branch?.trim()||ht.get(Gt||"")?.trim();!Gt||!Ce||Me.add(Co(Gt,Ce))})}),[...Me]},[ht,Jt]),cn=x2(Js);l.useEffect(()=>{if(!qn||!bn?.connected||!er)return;const Me=[],xt=Date.now();if(Jt.forEach(Gt=>{R.has(Gt.project.id)||Gt.groups.forEach(Ce=>{const qe=ks(Ce.directory??null),dt=Ce.branch?.trim()||ht.get(qe||"")?.trim();if(!qe||!dt)return;const bt=Co(qe,dt),Pt=gr.getState().entries[bt],qt=!!Pt?.status?.pr,Ns=`${qe}::${dt}`,nn=Math.max(Pt?.lastRefreshAt??0,Pt?.lastDiscoveryPollAt??0),nr=!!(Pt?.isInitialStatusResolved&&!qt&&(!h.current.has(Ns)||xt-nn>=lT));(!Pt||!Pt.isInitialStatusResolved||nr)&&(nr&&h.current.add(Ns),Me.push({directory:qe,branch:dt}))})}),Me.length===0)return;const ot=new Map;Me.forEach(Gt=>{const Ce=Co(Gt.directory,Gt.branch,Gt.remoteName??null);ot.has(Ce)||ot.set(Ce,Gt)}),ot.forEach((Gt,Ce)=>{zr(Ce),_r(Ce,{directory:Gt.directory,branch:Gt.branch,remoteName:Gt.remoteName??null,canShow:!0,github:er,githubAuthChecked:qn,githubConnected:bn.connected})}),Ia([...ot.values()],{force:!0,silent:!0,markInitialResolved:!0})},[R,zr,er,qn,bn?.connected,ht,Ia,Jt,_r]);const qo=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",Un="h-4.5 w-4.5",Ta=VP({isDesktopShellRuntime:ns,projectSections:Cn,projectHeaderSentinelRefs:oe}),ua=l.useCallback((Me,xt=0,ot,Gt,Ce=!1,qe,dt="project")=>s.jsx(QD,{node:Me,depth:xt,groupDirectory:ot,projectId:Gt,archivedBucket:Ce,directoryStatus:A,currentSessionId:it,pinnedSessionIds:J,expandedParents:v,hasSessionSearchQuery:Ke,normalizedSessionSearchQuery:He,notifyOnSubtasks:se,editingId:b,setEditingId:f,editTitle:y,setEditTitle:x,handleSaveEdit:cr,handleCancelEdit:Vr,toggleParent:en,handleSessionSelect:ln,handleSessionDoubleClick:fn,togglePinnedSession:Mt,handleShareSession:Fe,copiedSessionId:on,handleCopyShareUrl:Nt,handleUnshareSession:Ht,openSidebarMenuKey:O,setOpenSidebarMenuKey:L,renamingFolderId:W,getFoldersForScope:mt,getSessionFolderId:ze,removeSessionFromFolder:$e,addSessionToFolder:ye,createFolderAndStartRename:hn,openContextPanelTab:be,handleDeleteSession:cs,mobileVariant:t,alwaysShowActions:Ls,renderSessionNode:ua,secondaryMeta:qe,renderContext:dt}),[A,it,J,v,Ke,He,se,b,f,y,x,cr,Vr,en,ln,fn,Mt,Fe,on,Nt,Ht,O,L,W,mt,ze,$e,ye,hn,be,cs,t,Ls]),hi=l.useCallback(Me=>{ce(xt=>{const ot=new Set(xt);return ot.has(Me)?ot.delete(Me):ot.add(Me),ot})},[]),Cc=l.useMemo(()=>{const Me=new Map;for(const[xt,ot]of cn)Me.set(xt,{visualState:ot.visualState,number:ot.number,url:ot.url,state:ot.prState,draft:ot.draft,title:ot.title,base:ot.base,head:ot.head,checks:ot.checks,canMerge:ot.canMerge,mergeableState:ot.mergeableState,repo:ot.repo});return Me},[cn]),so=l.useCallback((Me,xt,ot,Gt,Ce,qe)=>s.jsx(sD,{group:Me,groupKey:xt,projectId:ot,hideGroupLabel:Gt,compactBodyPadding:qe,hasSessionSearchQuery:Ke,normalizedSessionSearchQuery:He,groupSearchDataByGroup:mi,expandedSessionGroups:D,collapsedGroups:re,hideDirectoryControls:r,collapsedFolderIds:Ze,toggleFolderCollapse:tt,renameFolder:ct,deleteFolder:lt,showDeletionDialog:ie,setDeleteFolderConfirm:te,renderSessionNode:ua,currentSessionDirectory:Pa,projectRepoStatus:P,lastRepoStatus:qs.current,toggleGroupSessionLimit:vn,mobileVariant:t,alwaysShowActions:Ls,activeProjectId:ke,setActiveProjectIdOnly:he,setActiveMainTab:G,setSessionSwitcherOpen:U,openNewSessionDraft:Ft,addSessionToFolder:ye,createFolderAndStartRename:hn,renamingFolderId:W,renameFolderDraft:ne,setRenameFolderDraft:le,setRenamingFolderId:B,pinnedSessionIds:J,sessionOrderIndex:as,prVisualStateByDirectoryBranch:Cc,onToggleCollapsedGroup:hi,dragHandleProps:Ce}),[Ke,He,mi,D,re,r,Ze,tt,ct,lt,ie,ua,Pa,P,vn,t,Ls,ke,he,G,U,Ft,ye,hn,W,ne,J,as,Cc,hi]),gi=sr&&!Ke?s.jsx(bD,{sections:Ye,renderSessionNode:ua}):null,xi=!!(W||b||g),ma=hr(Me=>Me.enabled),dn=hr(Me=>Me.selectedIds),bi=hr(Me=>Me.scopeKey),yi=hr,Ic=l.useCallback(()=>{hr.getState().toggleMode()},[]),Ac=l.useCallback(()=>{hr.getState().disable()},[]),Ur=l.useMemo(()=>{if(dn.size===0||typeof document>"u")return!1;let Me=!1,xt=!1;for(const ot of dn){const Gt=document.querySelectorAll(`[data-session-row="${CSS.escape(ot)}"]`);for(const Ce of Gt)Ce.getAttribute("data-session-archived")==="1"?xt=!0:Me=!0}return xt&&!Me},[dn]),Tn=l.useMemo(()=>{if(bi)return bi;if(dn.size===0||typeof document>"u")return null;for(const Me of dn){const ot=document.querySelector(`[data-session-row="${CSS.escape(Me)}"]`)?.getAttribute("data-session-scope");if(ot&&ot.length>0)return ot}return null},[dn,bi]),Pc=l.useMemo(()=>Tn?Xe[Tn]??[]:[],[Xe,Tn]),Qo=l.useMemo(()=>{if(!Tn||dn.size===0)return!1;const Me=Xe[Tn]??[];for(const xt of Me)for(const ot of xt.sessionIds)if(dn.has(ot))return!0;return!1},[Xe,Tn,dn]),pa=l.useCallback(Me=>{!Tn||dn.size===0||Ge(Tn,Me,Array.from(dn))},[Ge,dn,Tn]),Jo=l.useCallback(()=>{if(!Tn||dn.size===0)return;const Me=hn(Tn);Me&&Ge(Tn,Me.id,Array.from(dn))},[Ge,hn,dn,Tn]),Yo=l.useCallback(()=>{!Tn||dn.size===0||Ve(Tn,Array.from(dn))},[Ve,dn,Tn]),Ma=l.useCallback(async()=>{const Me=Array.from(dn);if(Me.length!==0){if(Ur){const{deletedIds:xt,failedIds:ot}=await In(Me);xt.length>0&&q.success(xt.length===1?i("sessions.sidebar.bulkActions.deletedSingle",{count:xt.length}):i("sessions.sidebar.bulkActions.deletedPlural",{count:xt.length})),ot.length>0&&q.error(ot.length===1?i("sessions.sidebar.bulkActions.failedDeleteSingle",{count:ot.length}):i("sessions.sidebar.bulkActions.failedDeletePlural",{count:ot.length}))}else{const{archivedIds:xt,failedIds:ot}=await An(Me);xt.length>0&&q.success(xt.length===1?i("sessions.sidebar.bulkActions.archivedSingle",{count:xt.length}):i("sessions.sidebar.bulkActions.archivedPlural",{count:xt.length})),ot.length>0&&q.error(ot.length===1?i("sessions.sidebar.bulkActions.failedArchiveSingle",{count:ot.length}):i("sessions.sidebar.bulkActions.failedArchivePlural",{count:ot.length}))}hr.getState().clear()}},[An,Ur,In,dn,i]),no=l.useCallback(()=>{const Me=dn.size;if(Me!==0){if(!ie){Ma();return}z({sessionCount:Me,archivedBucket:Ur})}},[Ur,Ma,dn,ie]),Dc=l.useCallback(async()=>{z(null),await Ma()},[Ma]);l.useEffect(()=>{if(!ma)return;const Me=typeof navigator<"u"&&/Macintosh|Mac OS X/.test(navigator.userAgent||""),xt=ot=>{if(xi)return;const Gt=ot.target;if(Gt&&(Gt.tagName==="INPUT"||Gt.tagName==="TEXTAREA"||Gt.isContentEditable))return;const Ce=Me?ot.metaKey:ot.ctrlKey;if(ot.key==="Escape"){ot.preventDefault(),hr.getState().disable();return}if(Ce&&ot.key==="Backspace"){ot.preventDefault(),no();return}if(Ce&&(ot.key==="a"||ot.key==="A")){const qe=typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[];if(qe.length===0)return;ot.preventDefault();const bt=yi.getState().scopeKey??qe[0]?.getAttribute("data-session-scope")??null,Pt=Ns=>bt?Ns.getAttribute("data-session-scope")===bt:!0,qt=qe.filter(Pt).map(Ns=>Ns.getAttribute("data-session-row")).filter(Ns=>typeof Ns=="string"&&Ns.length>0);if(qt.length===0)return;yi.getState().replaceAll(qt,bt||null)}};return window.addEventListener("keydown",xt),()=>window.removeEventListener("keydown",xt)},[no,xi,yi,ma]);const Xo=l.useCallback(()=>{G("chat"),t&&U(!1),Ft()},[t,Ft,G,U]),Zo=l.useCallback(()=>{G("chat"),t&&U(!1),Le()},[t,Le,G,U]);return s.jsxs("div",{ref:m,className:pe("relative flex h-full flex-col text-foreground overflow-x-hidden",t?"":"bg-transparent"),children:[wt?s.jsx("div",{onMouseDown:os,className:pe("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(St,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Re,className:ss,"aria-label":i("sessions.sidebar.header.actions.closeSessions"),children:s.jsx(si,{className:"h-[18px] w-[18px]"})})}),s.jsx(Ct,{children:s.jsx("p",{children:i("sessions.sidebar.header.actions.closeSessions")})})]})}):null,s.jsx(mD,{hideDirectoryControls:r,handleOpenDirectoryDialog:Gs,handleNewSession:Xo,canOpenMultiRun:fe.length>0,openMultiRunLauncher:Zo,headerActionIconClass:Un,reserveHeaderActionsSpace:Qn,headerActionButtonClass:qo,isSessionSearchOpen:o,setIsSessionSearchOpen:c,sessionSearchInputRef:u,sessionSearchQuery:d,setSessionSearchQuery:p,hasSessionSearchQuery:Ke,searchMatchCount:da,collapseAllProjects:dr,expandAllProjects:Zr,openScheduledTasksDialog:()=>de(!0),selectionModeEnabled:ma,onToggleSelectionMode:Ic,showSidebarToggle:pt,onToggleSidebar:Re,avoidWindowControlsOverlay:As}),s.jsx(ID,{topContent:gi,sectionsForRender:Jt,projectSections:Cn,activeProjectId:ke,showOnlyMainWorkspace:a,hasSessionSearchQuery:Ke,emptyState:Lt,searchEmptyState:pi,renderGroupSessions:so,homeDirectory:Ie,collapsedProjects:R,hideDirectoryControls:r,projectRepoStatus:P,isDesktopShellRuntime:ns,stuckProjectHeaders:Ta,mobileVariant:t,alwaysShowActions:Ls,toggleProject:ea,setActiveProjectIdOnly:he,setActiveMainTab:G,setSessionSwitcherOpen:U,openNewSessionDraft:Ft,openNewWorktreeDialog:Bt,openProjectEditDialog:w,removeProject:xe,projectHeaderSentinelRefs:oe,reorderProjects:Be,getOrderedGroups:to,setGroupOrderByProject:me,openSidebarMenuKey:O,setOpenSidebarMenuKey:L,isInlineEditing:xi}),ma&&dn.size>0?s.jsx(ZD,{selectedCount:dn.size,scopeKey:Tn,scopeFolders:Pc,archivedBucket:Ur,onMoveToFolder:pa,onCreateFolderAndMove:Jo,onRemoveFromFolder:Yo,canRemoveFromFolder:Qo,onDelete:no,onDone:Ac}):null,s.jsx(vD,{onOpenSettings:mn,onOpenShortcuts:Ae,onOpenAbout:()=>ve(!0),onOpenUpdate:xs,showRuntimeButtons:!es,showUpdateButton:js}),s.jsx(ou,{open:F,onOpenChange:V,info:Ue.info,downloading:Ue.downloading,downloaded:Ue.downloaded,progress:Ue.progress,error:Ue.error,onDownload:Ue.downloadUpdate,onRestart:Ue.restartToUpdate,runtimeType:Ue.runtimeType}),ls?s.jsx(cw,{open:!!ls,onOpenChange:Me=>{Me||w(null)},projectId:ls.id,projectName:ls.label||ii(ls.path,Ie),projectPath:ls.path,initialIcon:ls.icon,initialColor:ls.color,initialIconBackground:ls.iconBackground,onSave:rs}):null,s.jsx(MA,{open:M,onOpenChange:$,onWorktreeCreated:(Me,xt)=>{if(G("chat"),t&&U(!1),xt?.sessionId){Qt(xt.sessionId);return}Ft({directoryOverride:Me})}}),s.jsx(oP,{}),s.jsx(JD,{value:ee,setValue:ae,showDeletionDialog:ie,setShowDeletionDialog:K,onConfirm:Xs}),s.jsx(XD,{value:ge,setValue:te,onConfirm:Zs}),s.jsx(YD,{value:E,setValue:z,showDeletionDialog:ie,setShowDeletionDialog:K,onConfirm:Dc})]})},cT=()=>{const t=nt.c(13),[e,n]=Oe.useState(!1);let r,a;t[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>{n(kn())},a=[],t[0]=r,t[1]=a):(r=t[0],a=t[1]),Oe.useEffect(r,a);let i;t[2]!==e?(i=async h=>e?await mw(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 pw():{success:!0},t[4]=e,t[5]=c):c=t[5];const d=c;let p;t[6]!==e?(p=async h=>e?await fw():{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},dT=t=>t==="/",oc=t=>t.replace(/\\/g,"/"),tm=t=>{if(!t||dT(t))return t;let e=t;for(;e.length>1&&e.endsWith("/");)e=e.slice(0,-1);return e},Bi=t=>t.endsWith("/"),uT=t=>{const e=t.trim();return!e||Bi(e)?e:`${e}/`},sm=t=>t.lastIndexOf("/"),tb=t=>{if(Bi(t))return t;const e=sm(t);return e<0?t:t.slice(0,e+1)},mT=t=>{const e=sm(t);return t.slice(e+1)},sb=t=>{const e=tm(t.trim());if(!e||e==="~"||e==="~/"||e==="/")return null;const n=sm(e);return n<0?null:e.startsWith("~/")&&n<=1?"~/":n===0?"/":`${e.slice(0,n)}/`},pT=t=>Bi(t)&&sb(t)!==null,fT=(t,e)=>`${tb(t)}${e}/`,ji=t=>{if(!t)return null;const e=tm(oc(t.trim()));return e?e.toLowerCase():null},xh=(t,e)=>{const n=t.trim();return n==="~"?e:n.startsWith("~/")?`${e}${n.slice(1)}`:n},hT=t=>typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?t.metaKey&&!t.ctrlKey:t.ctrlKey&&!t.metaKey,jd=t=>{if(!t)return;t.focus({preventScroll:!0});const e=t.value.length;t.setSelectionRange(e,e),t.scrollLeft=t.scrollWidth},gT=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 oc(e.home.trim())}}catch{}return Dn.getFilesystemHome().catch(()=>null)},xT=({open:t,onOpenChange:e})=>{const{t:n}=ut(),r=Ws(se=>se.homeDirectory),a=Fs(se=>se.projects),i=Fs(se=>se.addProject),o=ar(se=>se.profiles),c=ar(se=>se.globalIdentity),d=ar(se=>se.defaultGitIdentityId),p=ar(se=>se.loadProfiles),m=ar(se=>se.loadGlobalIdentity),u=ar(se=>se.loadDefaultGitIdentityId),h=xc(),{isDesktop:b,requestAccess:f,startAccessing:y}=cT(),{isMobile:x}=un(),g=l.useRef(null),w=l.useRef(null),v=l.useRef(new Map),[S,A]=l.useState(""),[j,C]=l.useState("~/"),[I,R]=l.useState([]),[k,P]=l.useState(!1),[N,D]=l.useState(!1),[T,M]=l.useState(0),[$,F]=l.useState(!1),[V,O]=l.useState(!1),[L,W]=l.useState(0),[B,ne]=l.useState(!1),[le,ee]=l.useState(""),[ae,ge]=l.useState(null),te=S||r,E=l.useMemo(()=>new Set(a.map(se=>ji(se.path)).filter(se=>!!se)),[a]);l.useEffect(()=>{if(!t)return;C("~/"),R([]),M(0),F(!1),O(!1),ne(!1),ee(""),ge(null),requestAnimationFrame(()=>jd(g.current));let se=!1;return(async()=>{const K=await gT();se||(A(K||r||""),requestAnimationFrame(()=>jd(g.current)))})(),()=>{se=!0}},[r,t]),l.useEffect(()=>{t&&(p(),m(),u())},[u,p,m,t]);const z=l.useMemo(()=>{const se=new Map;c&&se.set(c.id,c);for(const ie of o)se.set(ie.id,ie);return Array.from(se.values())},[o,c]);l.useEffect(()=>{if(!t||!B||ae!==null)return;const se=typeof d=="string"?d.trim():"";if(se&&z.some(K=>K.id===se)){ge(se);return}const ie=z.find(K=>K.authType==="ssh"||K.sshKey);ie&&ge(ie.id)},[z,d,B,t,ae]);const J=l.useMemo(()=>z.find(se=>se.id===ae)??null,[z,ae]),H=l.useMemo(()=>tb(j),[j]),re=l.useMemo(()=>Bi(j)?"":mT(j),[j]),ce=l.useMemo(()=>te?xh(H,te):"",[H,te]);l.useEffect(()=>{if(!t||!ce){R([]);return}let se=!1;return P(!0),D(!1),Dn.listLocalDirectory(ce).then(ie=>{if(se)return;D(!1);const K=ie.filter(_e=>_e.isDirectory).map(_e=>({name:_e.name,path:oc(_e.path)})).sort((_e,He)=>_e.name.localeCompare(He.name));R(K)}).catch(()=>{se||(R([]),D(!0))}).finally(()=>{se||P(!1)}),()=>{se=!0}},[ce,t]);const Ne=l.useMemo(()=>{const se=re.toLowerCase(),ie=h||re.startsWith(".");return I.filter(K=>K.name.toLowerCase().startsWith(se)&&(ie||!K.name.startsWith(".")))},[re,I,h]),me=l.useMemo(()=>{const se=[];pT(j)&&se.push({type:"up",value:"browse:up",name:"..",path:sb(j)});for(const ie of Ne){const K=ji(ie.path);se.push({type:"directory",value:`browse:${ie.path}`,name:ie.name,path:ie.path,disabled:!!(K&&E.has(K))})}return se},[E,Ne,j]);l.useEffect(()=>{M(0)},[j,me.length]);const we=l.useMemo(()=>te?tm(xh(j,te)):"",[te,j]),_=ji(we),ue=!!(_&&E.has(_)),Q=l.useMemo(()=>re?Ne.find(se=>se.name===re)??null:null,[re,Ne]),oe=!!(we&&!ue&&(Bi(j)&&N||!Bi(j)&&re.trim().length>0&&Q===null)),Z=!$&&!V&&!ue&&!!we,Ie=Z&&le.trim().length>0,Se=me[T]??null,Y=!!(Se&&(Se.type==="up"||Se.type==="directory"&&!Se.disabled)),fe=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?"⌘":"Ctrl",ke=n(ue?"directoryExplorerDialog.actions.alreadyAdded":B?$?"directoryExplorerDialog.actions.cloning":"directoryExplorerDialog.actions.cloneAndAdd":$?"directoryExplorerDialog.actions.adding":oe?"directoryExplorerDialog.actions.createAndAdd":"directoryExplorerDialog.actions.addProject");l.useLayoutEffect(()=>{const se=w.current;if(!se)return;const ie=()=>W(Math.ceil(se.getBoundingClientRect().width));if(ie(),typeof ResizeObserver>"u")return;const K=new ResizeObserver(ie);return K.observe(se),()=>K.disconnect()},[ke]),l.useLayoutEffect(()=>{const se=g.current;se&&(se.scrollLeft=se.scrollWidth)},[L,j]),l.useLayoutEffect(()=>{t&&jd(g.current)},[t]),l.useLayoutEffect(()=>{const se=me[T];se&&v.current.get(se.value)?.scrollIntoView({block:"nearest"})},[T,me]);const xe=l.useCallback(()=>{e(!1)},[e]),he=l.useCallback(async se=>{if(!se||$)return;const ie=ji(se);if(ie&&E.has(ie))return;let K=se;F(!0);try{const _e=!B&&oe&&ji(se)===ji(we);if(B){const Ke=le.trim();if(!Ke){q.error(n("directoryExplorerDialog.toast.cloneUrlRequired"));return}K=(await Dn.cloneRepository({remoteUrl:Ke,destinationPath:se,gitIdentityId:J?.id??null})).path}else _e&&await Dn.createDirectory(se,{allowOutsideWorkspace:!0});if(!i(K)){q.error(n("directoryExplorerDialog.toast.failedToAddProject"),{description:n("directoryExplorerDialog.toast.selectValidDirectoryPath")});return}xe()}catch(_e){q.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:_e instanceof Error?_e.message:n("directoryExplorerDialog.toast.unknownError")})}finally{F(!1)}},[i,E,le,xe,B,$,J?.id,oe,we,n]),Pe=l.useCallback(se=>{C(uT(se))},[]),Be=l.useCallback(se=>{C(fT(j,se.name))},[j]),G=l.useCallback(se=>{if(se){if(se.type==="up"){se.path&&Pe(se.path);return}se.disabled||Be(se)}},[Pe,Be]),be=l.useCallback(async()=>{if(!(!b||V)){O(!0);try{const se=await f(we);if(!se.success||!se.path){se.error&&se.error!=="Directory selection cancelled"&&q.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:se.error});return}const ie=await y(se.path);if(!ie.success){q.error(n("directoryExplorerDialog.toast.failedToOpenDirectory"),{description:ie.error||n("directoryExplorerDialog.toast.desktopCouldNotGrantAccess")});return}await he(se.path)}catch(se){q.error(n("directoryExplorerDialog.toast.failedToSelectDirectory"),{description:se instanceof Error?se.message:n("directoryExplorerDialog.toast.unknownError")})}finally{O(!1)}}},[he,b,V,f,y,n,we]),De=l.useCallback(se=>{if(se.key==="ArrowDown"){se.preventDefault(),M(ie=>Math.min(me.length-1,ie+1));return}if(se.key==="ArrowUp"){se.preventDefault(),M(ie=>Math.max(0,ie-1));return}if(se.key==="Enter"){if(se.preventDefault(),hT(se)){he(we);return}Y&&G(Se);return}se.key==="Backspace"&&j===""&&(se.preventDefault(),xe())},[G,he,xe,Y,Se,j,me.length,we]),Ae=s.jsxs("button",{type:"button",onClick:()=>Sl(!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(Ri,{className:"h-4 w-4 text-primary"}):s.jsx(Ei,{className:"h-4 w-4"}),n("directoryExplorerDialog.toggle.showHidden")]}),ve=s.jsxs("div",{className:"px-2.5 py-1.5",children:[B?s.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5",children:[s.jsx(Vt,{value:le,onChange:se=>ee(se.target.value),placeholder:n("directoryExplorerDialog.clone.remoteUrlPlaceholder"),className:"min-w-0 flex-1 border-border/60 bg-[var(--surface-elevated)] font-mono typography-ui-label shadow-none",spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off"}),s.jsx(tx,{activeProfile:J,identities:z,onSelect:se=>ge(se.id),isApplying:$,iconOnly:!0})]}):null,s.jsxs("div",{className:"relative",children:[s.jsx(Ca,{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(Vt,{ref:g,value:j,onChange:se=>C(oc(se.target.value)),onKeyDown:De,placeholder:n("directoryExplorerDialog.pathInput.placeholder"),className:"border-transparent bg-transparent pl-9 font-mono typography-ui-label shadow-none focus-visible:ring-0",style:!x&&L>0?{paddingRight:`${L+24}px`}:void 0,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off"}),x?null:s.jsx(je,{ref:w,variant:"outline",size:"xs",tabIndex:-1,className:"absolute right-1.5 top-1/2 h-7 -translate-y-1/2 gap-1 px-2 typography-meta",disabled:B?!Ie:!Z,onMouseDown:se=>se.preventDefault(),onClick:()=>{he(we)},title:ke,children:ke})]})]}),U=s.jsx("div",{className:"relative min-h-0 flex-1 overflow-hidden rounded-xl border border-border/60 bg-[var(--surface-elevated)] shadow-sm",children:s.jsxs("div",{className:"max-h-[min(28rem,58vh)] overflow-y-auto p-2",children:[s.jsx("div",{className:"px-2 pb-1 pt-0.5 typography-meta font-medium uppercase tracking-wide text-muted-foreground/80",children:n("directoryExplorerDialog.browse.directories")}),k?s.jsx("div",{className:"py-10 text-center typography-ui-label text-muted-foreground",children:n("directoryExplorerDialog.browse.loading")}):me.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:me.map((se,ie)=>{const K=ie===T;return s.jsxs("button",{ref:_e=>{_e?v.current.set(se.value,_e):v.current.delete(se.value)},type:"button",disabled:se.type==="directory"&&se.disabled,onMouseEnter:()=>M(ie),onMouseDown:_e=>_e.preventDefault(),onClick:()=>G(se),className:pe("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",K&&"bg-interactive-selection text-interactive-selection-foreground",!K&&"hover:bg-interactive-hover/50",se.type==="directory"&&se.disabled&&"cursor-not-allowed opacity-45 hover:bg-transparent"),children:[se.type==="up"?s.jsx(zi,{className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80"}):s.jsx(Th,{className:"h-4 w-4 flex-shrink-0 text-muted-foreground/80"}),s.jsx("span",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:se.name})}),se.type==="directory"&&se.disabled?s.jsx("span",{className:"rounded-full border border-border/60 px-2 py-0.5 typography-meta text-muted-foreground",children:n("directoryExplorerDialog.browse.addedBadge")}):null]},se.value)})})]})}),de=s.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3",children:[ve,U]}),Re=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(Cu,{className:"h-3.5 w-3.5"}),s.jsx(Cs,{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(pm,{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(pm,{className:"h-3.5 w-3.5"}),n("directoryExplorerDialog.footer.add")]})]}),Le=()=>s.jsxs(s.Fragment,{children:[x?null:Re,s.jsxs("div",{className:pe("flex w-full flex-row justify-end gap-2 sm:w-auto",x&&"justify-stretch"),children:[b?s.jsx(je,{variant:"ghost",size:"xs",onClick:be,disabled:$||V||B,children:n(V?"directoryExplorerDialog.actions.openingFinder":"directoryExplorerDialog.actions.openInFinder")}):null,s.jsx(je,{variant:"ghost",size:"xs",onClick:()=>ne(se=>!se),disabled:$||V,className:pe(x&&"flex-1"),children:n(B?"directoryExplorerDialog.actions.addLocalProject":"directoryExplorerDialog.actions.cloneRepository")}),x?s.jsx(je,{size:"xs",onClick:()=>{he(we)},disabled:B?!Ie:!Z,className:"flex-1",children:ke}):null]})]});return x?s.jsx(Ar,{open:t,onClose:xe,title:n("directoryExplorerDialog.title"),className:"h-[88dvh] max-h-[720px] max-w-full",contentMaxHeightClassName:"flex-1",footer:s.jsx("div",{className:"flex flex-col gap-2",children:Le()}),children:s.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-3",children:[s.jsx("div",{className:"flex justify-end",children:Ae}),de]})}):s.jsx(ws,{open:t,onOpenChange:e,children:s.jsxs(vs,{className:"flex w-full max-w-xl flex-col gap-0 overflow-hidden p-0 sm:max-h-[80vh]",onOpenAutoFocus:se=>se.preventDefault(),children:[s.jsx(Is,{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(Ss,{children:n("directoryExplorerDialog.title")}),s.jsx(Os,{className:"mt-2",children:n("directoryExplorerDialog.description")})]}),Ae]})}),s.jsx("div",{className:"min-h-0 flex-1 px-2 pb-0",children:de}),s.jsx(Qs,{className:"flex w-full flex-col gap-3 px-5 py-3 sm:flex-row sm:items-center sm:justify-between",children:Le()})]})})},Ba=t=>t?s.jsx("span",{className:"text-foreground/80 dark:text-foreground/70",children:t}):void 0,Or=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},bT=()=>{const{t}=ut(),[e,n]=l.useState(!1),[r,a]=l.useState(!1),[i,o]=l.useState(null),[c,d]=l.useState([]),[p,m]=l.useState(!1),[u,h]=l.useState(!1),[b,f]=l.useState(!1),[y,x]=l.useState(!1),[g,w]=l.useState(new Set),v=Wt(Z=>Z.getWorktreeMetadata),S=Wt(Z=>Z.newSessionDraft),A=Wt(Z=>Z.setNewSessionDraftTarget),j=Wt(Z=>Z.setDraftBootstrapPendingDirectory),C=hw,I=bw,R=Wt(Z=>Z.deleteSessions),k=Wt(Z=>Z.archiveSessions),P=Te(Z=>Z.showDeletionDialog),N=Te(Z=>Z.setShowDeletionDialog),D=Ws(Z=>Z.currentDirectory),T=Ws(Z=>Z.homeDirectory),M=Ws(Z=>Z.isHomeReady),$=Fs(Z=>Z.projects),F=Fs(Z=>Z.activeProjectId),{isMobile:V,isTablet:O,hasTouchInput:L}=un(),W=V||O||L,B=l.useMemo(()=>{const Ie=(F?$.find(Se=>Se.id===F)??null:null)?.path??D;return Or(Ie)},[F,D,$]),ne=l.useCallback(Z=>{const Se=Or(Z.projectDirectory)||B;return{id:($.find(fe=>Or(fe.path)===Se)??null)?.id??`path:${Se}`,path:Se}},[B,$]),le=y&&g.size>0,ee=l.useMemo(()=>{const Z=i?.worktree;return Z&&typeof Z.branch=="string"&&Z.branch.trim().length>0?!0:c.length>0&&c.every(({metadata:Ie})=>typeof Ie.branch=="string"&&Ie.branch.trim().length>0)},[i?.worktree,c]),ae=i?.mode==="worktree",ge=ae,te=b||!ae||!ee,E=b||!ae;l.useEffect(()=>{r||!M||$.length>0||(a(!0),n(!0))},[r,M,$.length]);const z=l.useCallback(Z=>{o({sessions:Z.sessions,dateLabel:Z.dateLabel,mode:Z.mode??"session",worktree:Z.worktree??null})},[]),J=l.useCallback(()=>{o(null),d([]),m(!1),h(!1),f(!1),x(!1),w(new Set)},[]),H=l.useCallback(async Z=>{if(Z.sessions.length===0)return;if(Z.sessions.length===1){const fe=Z.sessions[0];await C(fe.id)?q.success(t("sessions.sidebar.session.delete.success")):q.error(t("sessions.sidebar.session.delete.error"));return}const Ie=Z.sessions.map(fe=>fe.id),{deletedIds:Se,failedIds:Y}=await R(Ie);if(Se.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}):Z.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:Z.dateLabel}):void 0;q.success(Se.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:Se.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:Se.length}),{description:Ba(fe)})}Y.length>0&&q.error(Y.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:Y.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:Y.length}),{description:Ba(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))})},[C,R,t]);l.useEffect(()=>Dr.onDeleteRequest(Z=>{if(!P&&(Z.mode??"session")==="session"){H(Z);return}z(Z)}),[z,P,H]),l.useEffect(()=>Dr.onDirectoryRequest(()=>{n(!0)}),[]),l.useEffect(()=>{if(!i){d([]),m(!1),h(!1),x(!1),w(new Set);return}const Z=i.sessions.map(Y=>{const fe=v(Y.id);return fe?{session:Y,metadata:fe}:null}).filter(Y=>!!Y);d(Z),m(!1),x(!1),w(new Set);const Ie=new Map;if(i.worktree?.path&&Ie.set(Or(i.worktree.path),i.worktree),Z.forEach(({metadata:Y})=>{Y.path&&Ie.set(Or(Y.path),Y)}),Ie.size===0){x(!0);return}let Se=!1;return(async()=>{const Y=new Map,fe=new Set;await Promise.all(Array.from(Ie.entries()).map(async([ke,xe])=>{try{const he=await gw(xe.path);Y.set(ke,he),he?.isDirty&&fe.add(ke)}catch{xe.status&&(Y.set(ke,xe.status),xe.status.isDirty&&fe.add(ke))}})).catch(ke=>{console.warn("Failed to inspect worktree status before deletion:",ke)}),!Se&&(w(fe),x(!0),o(ke=>{if(!ke?.worktree?.path)return ke;const xe=Or(ke.worktree.path),he=Y.get(xe);if(!he)return ke;const Pe=ke.worktree.status;return Pe?.isDirty===he.isDirty&&Pe?.ahead===he.ahead&&Pe?.behind===he.behind&&Pe?.upstream===he.upstream?ke:{...ke,worktree:{...ke.worktree,status:he}}}),d(ke=>ke.map(xe=>{const he=Or(xe.metadata.path),Pe=Y.get(he);return Pe?{session:xe.session,metadata:{...xe.metadata,status:Pe}}:xe})))})(),()=>{Se=!0}},[i,v]),l.useEffect(()=>{ee||m(!1)},[ee]);const re=l.useCallback(async(Z,Ie)=>{const Se=p&&ee,Y=ne(Z),fe=Or(Z.path),ke=Or(Y.path);try{await xw(Y,Z,{deleteRemoteBranch:Se,deleteLocalBranch:Ie});const xe=Or(S?.directoryOverride);return S?.open&&fe&&xe===fe&&ke&&(j(null),A({projectId:Y.id,directoryOverride:ke},{force:!0})),Or(D)===fe&&ke&&Ws.getState().setDirectory(ke,{showOverlay:!1}),!0}catch(xe){return q.error(t("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle"),{description:Ba(xe instanceof Error?xe.message:t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),!1}},[ee,D,p,ne,S?.directoryOverride,S?.open,j,A,t]),ce=l.useCallback(async()=>{if(i){f(!0);try{const Z=ge,Ie=Z&&p,Se=Z&&u;if(i.sessions.length===0&&ae&&i.worktree){if(!await re(i.worktree,Se)){J();return}const ke=t(p&&ee?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.removed");q.success(t("sessions.sidebar.sessionDialogs.worktree.removedTitle"),{description:Ba(ke)}),J();return}if(i.sessions.length===1){const Y=i.sessions[0];if(!(ae?await I(Y.id):await C(Y.id,{archiveWorktree:!1,deleteRemoteBranch:Ie,deleteLocalBranch:Se}))){q.error(t(ae?"sessions.sidebar.session.archive.error":"sessions.sidebar.session.delete.error")),f(!1);return}const ke=!ae&&Z?t(Ie?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.attachedArchived"):void 0;q.success(t(ae?"sessions.sidebar.session.archive.success":"sessions.sidebar.session.delete.success"),{description:Ba(ke),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}else{const Y=i.sessions.map(xe=>xe.id);let fe=[],ke=[];if(ae){const xe=await k(Y);fe=xe.archivedIds,ke=xe.failedIds}else{const xe=await R(Y,{archiveWorktree:!1,deleteRemoteBranch:Ie,deleteLocalBranch:Se});fe=xe.deletedIds,ke=xe.failedIds}if(ae&&i.worktree&&ke.length===0&&await re(i.worktree,Se),fe.length>0){const xe=!ae&&Z?t(Ie?"sessions.sidebar.sessionDialogs.worktree.archivedAndRemoteRemoved":"sessions.sidebar.sessionDialogs.worktree.attachedArchivedPlural"):void 0,Pe=[ke.length>0?ae?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,xe].filter(Boolean).join(" ");q.success(ae?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:Ba(Pe||void 0),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}if(ke.length>0&&(q.error(ae?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:Ba(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),fe.length===0)){f(!1);return}}ae&&i.sessions.length===1&&i.worktree&&await re(i.worktree,Se),J()}finally{f(!1)}}},[i,p,u,C,R,I,k,J,ge,ae,ee,re,t]),Ne=i?.worktree??c[0]?.metadata??null,me=i?i.mode==="worktree"?i.sessions.length===0?t("sessions.sidebar.dialogs.worktreeDelete.descriptionNoLinked"):i.sessions.length===1?t("sessions.sidebar.dialogs.worktreeDelete.descriptionOneLinked",{count:i.sessions.length}):t("sessions.sidebar.dialogs.worktreeDelete.descriptionManyLinked",{count:i.sessions.length}):i.sessions.length===1?i.dateLabel?t("sessions.sidebar.dialogs.sessionDelete.descriptionOneWithDate",{dateLabel:i.dateLabel}):t("sessions.sidebar.dialogs.sessionDelete.descriptionOne"):i.dateLabel?t("sessions.sidebar.dialogs.sessionDelete.descriptionManyWithDate",{count:i.sessions.length,dateLabel:i.dateLabel}):t("sessions.sidebar.dialogs.sessionDelete.descriptionMany",{count:i.sessions.length}):"",we=i?s.jsxs("div",{className:pe(ae?"space-y-3":"space-y-2"),children:[i.sessions.length>0&&s.jsxs("div",{className:pe(ae?"rounded-lg bg-muted/30 p-3":"space-y-1.5 rounded-xl border border-border/40 bg-sidebar/60 p-3"),children:[ae&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-meta font-medium text-foreground",children:i.sessions.length===1?t("sessions.sidebar.sessionDialogs.linkedSessionSingle"):t("sessions.sidebar.sessionDialogs.linkedSessionPlural")}),s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:i.sessions.length})]}),s.jsxs("ul",{className:pe(ae?"mt-2 space-y-1":"space-y-0.5"),children:[i.sessions.slice(0,5).map(Z=>s.jsxs("li",{className:pe(ae?"flex items-center gap-2 rounded-md px-2.5 py-1.5 text-sm text-muted-foreground":"typography-micro text-muted-foreground/80"),children:[s.jsx("span",{className:pe(!ae&&"hidden"),children:"•"}),s.jsx("span",{className:"truncate",children:Z.title||t("sessions.sidebar.session.untitled")})]},Z.id)),i.sessions.length>5&&s.jsx("li",{className:pe(ae?"px-2.5 py-1 text-xs text-muted-foreground/70":"typography-micro text-muted-foreground/70"),children:t("sessions.sidebar.dialogs.sessionList.more",{count:i.sessions.length-5})})]})]}),ae?s.jsxs("div",{className:"space-y-2 rounded-lg bg-muted/30 p-3",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Ks,{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")}),Ne?.label?s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:Ne.label}):null]}),s.jsx("p",{className:"typography-micro text-muted-foreground/80 break-all",children:Ne?To(Ne.path,T):t("sessions.sidebar.sessionDialogs.worktree.pathUnavailable")}),le&&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,_=ae?ee?s.jsxs("button",{type:"button",onClick:()=>{te||m(Z=>!Z)},disabled:te,className:pe("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",te?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[p?s.jsx(Ri,{className:"size-4 text-primary"}):s.jsx(Ei,{className:"size-4"}),t("sessions.sidebar.sessionDialogs.actions.deleteRemoteBranch")]}):s.jsx("span",{className:"text-xs text-muted-foreground/70",children:t("sessions.sidebar.sessionDialogs.actions.remoteBranchInfoUnavailable")}):null,ue=ae?s.jsxs("button",{type:"button",onClick:()=>{E||h(Z=>!Z)},disabled:E,className:pe("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",E?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[u?s.jsx(Ri,{className:"size-4 text-primary"}):s.jsx(Ei,{className:"size-4"}),t("sessions.sidebar.sessionDialogs.actions.deleteLocalBranch")]}):null,Q=ae?s.jsxs("div",{className:"flex w-full items-center justify-between gap-3",children:[s.jsxs("div",{className:"flex flex-col items-start gap-1",children:[ue,_]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(je,{variant:"ghost",onClick:J,disabled:b,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(je,{variant:"destructive",onClick:ce,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(!P),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":!P,children:[P?s.jsx(Ei,{className:"size-4"}):s.jsx(Ri,{className:"size-4 text-primary"}),t("sessions.sidebar.dialogs.neverAsk")]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(je,{variant:"ghost",onClick:J,disabled:b,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(je,{variant:"destructive",onClick:ce,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")})]})]}),oe=ae?t("sessions.sidebar.sessionDialogs.actions.deleteWorktree"):i?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction");return s.jsxs(s.Fragment,{children:[W?s.jsx(Ar,{open:!!i,onClose:()=>{b||J()},title:oe,footer:s.jsx("div",{className:"flex justify-end gap-2",children:Q}),children:s.jsxs("div",{className:"space-y-2 pb-2",children:[me&&s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:me}),we]})}):s.jsx(ws,{open:!!i,onOpenChange:Z=>{if(!Z){if(b)return;J()}},children:s.jsxs(vs,{className:pe(ae?"max-w-xl max-h-[70vh] flex flex-col overflow-hidden gap-3":"max-w-[min(520px,100vw-2rem)] space-y-2 pb-2"),children:[s.jsxs(Is,{children:[s.jsxs(Ss,{className:pe(ae&&"flex items-center gap-2"),children:[ae&&s.jsx(sn,{className:"h-5 w-5"}),oe]}),me&&s.jsx(Os,{children:me})]}),s.jsx("div",{className:pe(ae&&"flex-1 min-h-0 overflow-y-auto space-y-2"),children:we}),s.jsx(Qs,{className:"mt-2 gap-2 pt-1 pb-1",children:Q})]})}),s.jsx(xT,{open:e,onOpenChange:n})]})},uu=t=>t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").substring(0,50),yT=(t,e)=>{const n=uu(t),r=uu(e);return`${n}-${r}`.substring(0,60)},bh=(t,e)=>`${t}/${e}`,vT=()=>{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=Ws.getState().currentDirectory??null;if(r&&r.trim().length>0){const a=r.replace(/\\/g,"/").replace(/\/+$/,"")||r;return{id:`path:${a}`,path:a}}return null},Nd=wr()(Xi(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=vT();if(!d)return t({error:"Select a project",isLoading:!1}),null;const p=d.path;if(!await vg(p))return t({error:"Not in a git repository",isLoading:!1}),null;const u=uu(n),h=await zo(p),b=await yw(p),f=[],y=c?.filter(j=>j.trim().length>0)??[],x=new Map;for(const j of a){const C=`${j.providerID}:${j.modelID}`;x.set(C,(x.get(C)||0)+1)}const g=new Map;for(const j of a){const C=`${j.providerID}:${j.modelID}`,I=x.get(C)||1,R=(g.get(C)||0)+1;g.set(C,R);const k=yT(j.providerID,j.modelID),P=I>1?bh(u,`${k}/${R}`):bh(u,k);try{const N=await vw(d,{preferredName:P,mode:"new",branchName:P,worktreeName:P,startRef:e.worktreeBaseBranch||"HEAD",setupCommands:y},{resolvedRootTrackingRemote:b}),D={...N,createdFromBranch:h,kind:"standard"},T=I>1?`${u}/${j.providerID}/${j.modelID}/${R}`:`${u}/${j.providerID}/${j.modelID}`,M=await Dn.withDirectory(N.path,()=>Dn.createSession({title:T}));Wt.getState().setWorktreeMetadata(M.id,D),f.push({sessionId:M.id,worktreePath:N.path,providerID:j.providerID,modelID:j.modelID,variant:j.variant})}catch(N){console.warn("[MultiRun] Failed to create session:",N)}}const w=c?.filter(j=>j.trim().length>0)??[];w.length>0&&wg(d,w).catch(()=>{console.warn("[MultiRun] Failed to save worktree setup commands")});const v=f.map(j=>j.sessionId),S=f[0]?.sessionId??null;if(v.length===0)return t({error:"Failed to create any sessions",isLoading:!1}),null;const A=o?.map(j=>({type:"file",mime:j.mime,filename:j.filename,url:j.url}));return(async()=>{try{await Promise.allSettled(f.map(async j=>{try{await Dn.withDirectory(j.worktreePath,()=>Dn.sendMessage({id:j.sessionId,providerID:j.providerID,modelID:j.modelID,variant:j.variant,text:r,agent:i,files:A}))}catch(C){console.warn("[MultiRun] Failed to start run:",C)}}))}catch(j){console.warn("[MultiRun] Failed to start runs:",j)}})(),t({isLoading:!1}),{groupSlug:u,sessionIds:v,firstSessionId:S}}catch(d){return t({error:d instanceof Error?d.message:"Failed to create Multi-Run",isLoading:!1}),null}},clearError:()=>{t({error:null})}}),{name:"multirun-store"})),nb="h-7",mu=()=>`${Date.now()}-${Math.random().toString(36).substring(2,9)}`,wT=new Intl.NumberFormat("en-US",{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}),jT=t=>{if(typeof t!="number"||Number.isNaN(t))return"";if(t===0)return"0";const e=wT.format(t);return e.endsWith(".0")?e.slice(0,-2):e},NT=t=>{const e=nt.c(12),{model:n,instanceIndex:r,totalSameModel:a,onRemove:i}=t,o=n.displayName||`${n.providerID}/${n.modelID}`,c=a>1?`${o} (${r})`:o;let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=pe("flex items-center gap-1.5 px-2 rounded-md bg-interactive-selection/20 border border-border/30",nb),e[0]=d):d=e[0];let p;e[1]!==n.providerID?(p=s.jsx(Bn,{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(Ds,{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},ST=({selectedModels:t,onAdd:e,onRemove:n,onUpdate:r,minModels:a,addButtonLabel:i,showChips:o=!0,maxModels:c,addButtonClassName:d})=>{const{t:p}=ut(),m=yt(W=>W.providers),u=yt(W=>W.modelsMetadata),{favoriteModelsList:h,recentModelsList:b}=dg(),[f,y]=l.useState(!1),[x,g]=l.useState(""),[w,v]=l.useState(0),[S,A]=l.useState(null),j=l.useRef(null),C=l.useRef(null),I=l.useRef(null),R=l.useRef([]),k=c===void 0||t.length<c,P=l.useMemo(()=>{const W=new Map;for(const B of t){const ne=`${B.providerID}:${B.modelID}`;W.set(ne,(W.get(ne)||0)+1)}return W},[t]),N=l.useCallback(W=>t.filter(ne=>ne.providerID===W.providerID&&ne.modelID===W.modelID).findIndex(ne=>ne.instanceId===W.instanceId)+1,[t]),D=(W,B)=>{const ne=`${W}/${B}`;return u.get(ne)},T=W=>{const B=W?.name||W?.id||"",ne=String(B);return ne.length>40?ne.substring(0,37)+"...":ne},M=l.useCallback((W,B)=>{if(!x.trim())return!0;const ne=x.toLowerCase();return W.toLowerCase().includes(ne)||B.toLowerCase().includes(ne)},[x]),$=l.useMemo(()=>h.filter(({model:W,providerID:B})=>{const le=m.find(ae=>ae.id===B)?.name||B,ee=T(W);return M(ee,le)}),[h,m,M]),F=l.useMemo(()=>b.filter(({model:W,providerID:B})=>{const le=m.find(ae=>ae.id===B)?.name||B,ee=T(W);return M(ee,le)}),[b,m,M]),V=l.useMemo(()=>m.map(W=>{const ne=(Array.isArray(W.models)?W.models:[]).filter(le=>{const ee=T(le);return M(ee,W.name||W.id||"")});return{...W,models:ne}}).filter(W=>W.models.length>0),[m,M]),O=$.length>0||F.length>0||V.length>0;l.useEffect(()=>{if(!f||!I.current)return;const W=I.current.getBoundingClientRect();let B=I.current.parentElement;for(;B&&!(B.getAttribute("role")==="dialog"||B.hasAttribute("data-scroll-shadow"));){const ee=getComputedStyle(B);if(ee.overflow==="auto"||ee.overflow==="hidden"||ee.overflowY==="auto"||ee.overflowY==="hidden")break;B=B.parentElement}const ne=B?B.getBoundingClientRect().top:0,le=W.top-ne-16;A(Math.max(150,Math.min(300,le)))},[f]),l.useEffect(()=>{f&&j.current&&j.current.focus()},[f]),l.useEffect(()=>{!k&&f&&(y(!1),g(""),v(0))},[k,f]),l.useEffect(()=>{if(!f)return;const W=B=>{C.current&&!C.current.contains(B.target)&&(y(!1),g(""),v(0))};return document.addEventListener("mousedown",W),()=>document.removeEventListener("mousedown",W)},[f]),l.useEffect(()=>{v(0)},[x]);const L=(W,B,ne,le,ee,ae)=>{const ge=`${B}:${ne}`,te=P.get(ge)||0,E=D(B,ne),z=jT(E?.limit?.context),J=le==="fav"||le==="recent";return s.jsxs("button",{ref:H=>{R.current[ee]=H},type:"button",disabled:!k,onClick:()=>{e({providerID:B,modelID:ne,displayName:W.name||ne,instanceId:mu()})},onMouseEnter:()=>v(ee),className:pe("w-full text-left px-2 py-1.5 rounded-md typography-meta transition-colors flex items-center gap-2",k&&(ae?"bg-interactive-selection":"hover:bg-interactive-hover/50"),!k&&"cursor-not-allowed opacity-60"),children:[s.jsxs("div",{className:"flex items-center gap-1.5 flex-1 min-w-0",children:[J&&s.jsx(Bn,{providerId:B,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"font-medium truncate",children:T(W)}),z&&s.jsx("span",{className:"typography-micro text-muted-foreground flex-shrink-0",children:z})]}),te>0&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex-shrink-0",children:["×",te]})]},`${le}-${ge}`)};return s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex flex-wrap gap-1.5 items-center",children:[s.jsxs("div",{className:"relative",ref:C,children:[s.jsxs(je,{ref:I,type:"button",variant:"outline",size:"sm",className:pe(nb,"!border-border/80 !bg-[var(--surface-subtle)] hover:!bg-[var(--interactive-hover)]/70",d),disabled:!k,onClick:()=>{y(!f)},children:[s.jsx(_s,{className:"h-3.5 w-3.5 mr-1"}),i??p("multirun.modelMultiSelect.actions.addModel")]}),f&&(()=>{const W=[];$.forEach(({model:ee,providerID:ae,modelID:ge})=>{W.push({model:ee,providerID:ae,modelID:ge,section:"fav"})}),F.forEach(({model:ee,providerID:ae,modelID:ge})=>{W.push({model:ee,providerID:ae,modelID:ge,section:"recent"})}),V.forEach(ee=>{ee.models.forEach(ae=>{W.push({model:ae,providerID:ee.id,modelID:ae.id,section:"provider"})})});const B=W.length,ne=ee=>{if(!ww(ee))if(ee.key==="ArrowDown"){ee.preventDefault(),ee.stopPropagation();const ae=(w+1)%Math.max(1,B);v(ae),setTimeout(()=>{R.current[ae]?.scrollIntoView({behavior:"smooth",block:"nearest"})},0)}else if(ee.key==="ArrowUp"){ee.preventDefault(),ee.stopPropagation();const ae=(w-1+Math.max(1,B))%Math.max(1,B);v(ae),setTimeout(()=>{R.current[ae]?.scrollIntoView({behavior:"smooth",block:"nearest"})},0)}else if(ee.key==="Enter"){ee.preventDefault(),ee.stopPropagation();const ae=W[w];ae&&k&&e({providerID:ae.providerID,modelID:ae.modelID,displayName:ae.model.name||ae.modelID,instanceId:mu()})}else ee.key==="Escape"&&(ee.preventDefault(),ee.stopPropagation(),y(!1),g(""),v(0))};let le=0;return s.jsxs("div",{className:"absolute bottom-full left-0 mb-1 z-50 w-[min(380px,calc(100vw-2rem))] max-w-[calc(100vw-2rem)] flex flex-col overflow-hidden rounded-xl border border-border/50 shadow-lg",style:{background:"linear-gradient(var(--surface-elevated),var(--surface-elevated)),linear-gradient(var(--surface-background),var(--surface-background))"},children:[s.jsx("div",{className:"p-2 border-b border-border/40",children:s.jsxs("div",{className:"relative",children:[s.jsx(Hn,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Vt,{ref:j,type:"text",placeholder:p("multirun.modelMultiSelect.search.placeholder"),value:x,onChange:ee=>g(ee.target.value),onKeyDown:ne,className:"h-8 pl-8 typography-meta"})]})}),s.jsx(Es,{outerClassName:"flex-1",style:{maxHeight:S?`${S}px`:"300px"},children:s.jsxs("div",{className:"p-1",children:[!O&&s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:p("multirun.modelMultiSelect.search.noResults")}),$.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"typography-micro font-semibold text-muted-foreground uppercase tracking-wider sticky top-0 z-10 -mx-1 flex items-center gap-2 border-b border-border/30 px-3 py-1.5 [background:linear-gradient(var(--surface-elevated),var(--surface-elevated)),linear-gradient(var(--surface-background),var(--surface-background))]",children:[s.jsx(po,{className:"h-4 w-4 text-primary"}),p("multirun.modelMultiSelect.sections.favorites")]}),$.map(({model:ee,providerID:ae,modelID:ge})=>{const te=le++;return L(ee,ae,ge,"fav",te,w===te)})]}),F.length>0&&s.jsxs(s.Fragment,{children:[$.length>0&&s.jsx("div",{className:"h-px bg-border/40 my-1"}),s.jsxs("div",{className:"typography-micro font-semibold text-muted-foreground uppercase tracking-wider sticky top-0 z-10 -mx-1 flex items-center gap-2 border-b border-border/30 px-3 py-1.5 [background:linear-gradient(var(--surface-elevated),var(--surface-elevated)),linear-gradient(var(--surface-background),var(--surface-background))]",children:[s.jsx(yu,{className:"h-4 w-4"}),p("multirun.modelMultiSelect.sections.recent")]}),F.map(({model:ee,providerID:ae,modelID:ge})=>{const te=le++;return L(ee,ae,ge,"recent",te,w===te)})]}),($.length>0||F.length>0)&&V.length>0&&s.jsx("div",{className:"h-px bg-border/40 my-1"}),V.map((ee,ae)=>s.jsxs(l.Fragment,{children:[ae>0&&s.jsx("div",{className:"h-px bg-border/40 my-1"}),s.jsxs("div",{className:"typography-micro font-semibold text-muted-foreground uppercase tracking-wider sticky top-0 z-10 -mx-1 flex items-center gap-2 border-b border-border/30 px-3 py-1.5 [background:linear-gradient(var(--surface-elevated),var(--surface-elevated)),linear-gradient(var(--surface-background),var(--surface-background))]",children:[s.jsx(Bn,{providerId:ee.id,className:"h-4 w-4 flex-shrink-0"}),ee.name]}),ee.models.map(ge=>{const te=le++;return L(ge,ee.id,ge.id,"provider",te,w===te)})]},ee.id))]})}),s.jsx("div",{className:"px-3 pt-1 pb-1.5 border-t border-border/40 typography-micro text-muted-foreground",children:p("multirun.modelMultiSelect.keyboard.hint")})]})})()]}),o&&t.length>0&&s.jsx("div",{className:"flex flex-col gap-2 w-full",children:t.map((W,B)=>{const ne=`${W.providerID}:${W.modelID}`,le=P.get(ne)||1,ee=N(W),ge=m.find(H=>H.id===W.providerID)?.models.find(H=>H.id===W.modelID),te=ge?.variants?Object.keys(ge.variants):[],E=te.length>0,z="__default__",J=W.variant??z;return s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(NT,{model:W,instanceIndex:ee,totalSameModel:le,onRemove:()=>n(B)}),E&&s.jsxs(ps,{value:J,onValueChange:H=>{if(!r)return;r(B,{...W,variant:H===z?void 0:H})},children:[s.jsxs(fs,{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(Ao,{className:pe("h-3.5 w-3.5 flex-shrink-0",J===z?"text-muted-foreground":"text-[color:var(--status-info)]")}),s.jsx(ys,{placeholder:p("multirun.modelMultiSelect.variant.placeholder")})]}),s.jsxs(hs,{fitContent:!0,children:[s.jsx(Ot,{value:z,className:"pr-2 [&>span:first-child]:hidden",children:p("multirun.modelMultiSelect.variant.default")}),te.map(H=>s.jsx(Ot,{value:H,className:"pr-2 [&>span:first-child]:hidden",children:H},H))]})]})]},W.instanceId)})})]}),a!==void 0&&t.length<a&&s.jsx("p",{className:"typography-micro text-muted-foreground",children:c!==void 0?p("multirun.modelMultiSelect.validation.minToMax",{min:a,max:c}):p("multirun.modelMultiSelect.validation.minOnly",{min:a})})]})},kT="oc:lastWorktreeSourceBranch";function rb(t){const e=nt.c(21),{git:n}=Gn(),r=Fu(t),a=Cg(t),i=pn(PT);let o;e[0]!==r?.all||e[1]!==t||e[2]!==i||e[3]!==n?(o=()=>{!t||!n||r?.all||i(t,n)},e[0]=r?.all,e[1]=t,e[2]=i,e[3]=n,e[4]=o):o=e[4];const c=r?.all;let d;e[5]!==t||e[6]!==i||e[7]!==n||e[8]!==c?(d=[t,n,c,i],e[5]=t,e[6]=i,e[7]=n,e[8]=c,e[9]=d):d=e[9],l.useEffect(o,d);let p;e:{if(!r?.all){let g;e[10]===Symbol.for("react.memo_cache_sentinel")?(g=[],e[10]=g):g=e[10],p=g;break e}let x;e[11]!==r.all?(x=r.all.filter(AT).sort(),e[11]=r.all,e[12]=x):x=e[12],p=x}const m=p;let u;e:{if(!r?.all){let g;e[13]===Symbol.for("react.memo_cache_sentinel")?(g=[],e[13]=g):g=e[13],u=g;break e}let x;e[14]!==r.all?(x=r.all.filter(IT).map(CT).sort(),e[14]=r.all,e[15]=x):x=e[15],u=x}const h=u;let b;e:{if(!t){b=null;break e}if(a){b=null;break e}if(!r){b=null;break e}b=!!r.all}const f=b;let y;return e[16]!==f||e[17]!==a||e[18]!==m||e[19]!==h?(y={localBranches:m,remoteBranches:h,isLoading:a,isGitRepository:f},e[16]=f,e[17]=a,e[18]=m,e[19]=h,e[20]=y):y=e[20],y}function CT(t){return t.replace(/^remotes\//,"")}function IT(t){return t.startsWith("remotes/")}function AT(t){return!t.startsWith("remotes/")}function PT(t){return t.fetchBranches}const DT=({directory:t,value:e,onChange:n,className:r,disabled:a,id:i})=>{const{t:o}=ut(),{localBranches:c,remoteBranches:d,isLoading:p,isGitRepository:m}=rb(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 zo(t).catch(()=>null):null,y=localStorage.getItem(kT);y&&u.includes(y)?n(y):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(ps,{value:e,onValueChange:n,disabled:h,children:[s.jsx(fs,{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(hs,{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(Vd,{children:[s.jsx(Om,{className:"font-semibold text-foreground",children:o("multiRun.branchSelector.groups.localBranches")}),c.map(b=>s.jsx(Ot,{value:b,className:"whitespace-normal break-all",children:b},b))]}),c.length>0&&d.length>0&&s.jsx(jw,{}),d.length>0&&s.jsxs(Vd,{children:[s.jsx(Om,{className:"font-semibold text-foreground",children:o("multiRun.branchSelector.groups.remoteBranches")}),d.map(b=>s.jsx(Ot,{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")})]})},TT=t=>{const e=nt.c(34),{value:n,onChange:r,className:a,disabled:i,id:o}=t,{t:c}=ut(),d=yt(MT),p=yt(RT),m=yt(ET);let u;e[0]!==d?(u=d(),e[0]=d,e[1]=u):u=e[1];const h=u;let b;e[2]!==h?(b=h.filter(FT),e[2]=h,e[3]=b):b=e[3];const f=b;let y,x;e[4]!==p?(y=()=>{p()},x=[p],e[4]=p,e[5]=y,e[6]=x):(y=e[5],x=e[6]),l.useEffect(y,x);let g,w;e[7]!==m||e[8]!==i||e[9]!==r||e[10]!==f||e[11]!==n?(g=()=>{if(i)return;const P=n.trim();if(P.length>0&&f.some(T=>T.name===P))return;const N=typeof m=="string"&&m.trim().length>0?m.trim():null;if(N&&f.some(T=>T.name===N)){r(N);return}const D=f[0]?.name;D&&r(D)},w=[m,i,r,f,n],e[7]=m,e[8]=i,e[9]=r,e[10]=f,e[11]=n,e[12]=g,e[13]=w):(g=e[12],w=e[13]),l.useEffect(g,w);const v=n.trim().length>0?n:void 0;let S;e[14]!==a?(S=pe("max-w-full typography-meta text-foreground !border-border/80 !bg-[var(--surface-subtle)] hover:!bg-[var(--interactive-hover)]/70 data-[popup-open]:!bg-[var(--interactive-active)]/70",a),e[14]=a,e[15]=S):S=e[15];let A;e[16]!==c?(A=c("multirun.agentSelector.placeholder"),e[16]=c,e[17]=A):A=e[17];let j;e[18]!==A?(j=s.jsx(ys,{placeholder:A}),e[18]=A,e[19]=j):j=e[19];let C;e[20]!==o||e[21]!==S||e[22]!==j?(C=s.jsx(fs,{id:o,size:"lg",className:S,children:j}),e[20]=o,e[21]=S,e[22]=j,e[23]=C):C=e[23];let I;e[24]!==f?(I=f.length>0&&s.jsx(Vd,{children:f.map(OT)}),e[24]=f,e[25]=I):I=e[25];let R;e[26]!==I?(R=s.jsx(hs,{fitContent:!0,children:I}),e[26]=I,e[27]=R):R=e[27];let k;return e[28]!==i||e[29]!==r||e[30]!==v||e[31]!==C||e[32]!==R?(k=s.jsxs(ps,{value:v,onValueChange:r,disabled:i,children:[C,R]}),e[28]=i,e[29]=r,e[30]=v,e[31]=C,e[32]=R,e[33]=k):k=e[33],k};function MT(t){return t.getVisibleAgents}function RT(t){return t.loadAgents}function ET(t){return t.currentAgentName}function FT(t){return t.mode!=="subagent"}function OT(t){return s.jsx(Ot,{value:t.name,className:"w-auto whitespace-nowrap",children:t.name},t.name)}const LT=10*1024*1024,Sd=5,yl=t=>{const e=nt.c(3),{children:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(St,{asChild:!0,children:s.jsx("button",{type:"button",tabIndex:-1,className:"inline-flex items-center justify-center text-muted-foreground/50 hover:text-muted-foreground transition-colors",children:s.jsx(Us,{className:"h-3.5 w-3.5"})})}),e[0]=r):r=e[0];let a;return e[1]!==n?(a=s.jsxs(kt,{children:[r,s.jsx(Ct,{side:"top",className:"max-w-[240px]",children:n})]}),e[1]=n,e[2]=a):a=e[2],a},Ni=t=>{const e=nt.c(9),{htmlFor:n,required:r,children:a,info:i}=t;let o;e[0]!==r?(o=r&&s.jsx("span",{className:"text-destructive ml-0.5",children:"*"}),e[0]=r,e[1]=o):o=e[1];let c;e[2]!==a||e[3]!==n||e[4]!==o?(c=s.jsxs("label",{htmlFor:n,className:"typography-meta font-medium text-foreground",children:[a,o]}),e[2]=a,e[3]=n,e[4]=o,e[5]=c):c=e[5];const d=i&&i;let p;return e[6]!==c||e[7]!==d?(p=s.jsxs("div",{className:"flex items-center gap-1.5",children:[c,d]}),e[6]=c,e[7]=d,e[8]=p):p=e[8],p},$T=({initialPrompt:t,onCreated:e,onCancel:n,isWindowed:r=!1})=>{const{t:a}=ut(),[i,o]=l.useState(""),[c,d]=l.useState(()=>t??""),[p,m]=l.useState([]),[u,h]=l.useState(""),[b,f]=l.useState([]),[y,x]=l.useState(!1),[g,w]=l.useState([]),[v,S]=l.useState(!1),[A,j]=l.useState(!1),[C,I]=l.useState(!1),[R,k]=l.useState(""),[P,N]=l.useState(!1),[D,T]=l.useState(""),M=l.useRef(null),$=l.useRef(null),F=l.useRef(null),V=l.useRef(null),O=Ws(se=>se.currentDirectory??null),L=Ws(se=>se.homeDirectory??null),W=l.useMemo(()=>{if(typeof window>"u")return null;const se=window.__VSCODE_CONFIG__?.workspaceFolder;return typeof se=="string"&&se.trim().length>0?se.trim():null},[]),B=Fs(se=>se.activeProjectId),ne=Fs(se=>se.setActiveProjectIdOnly),le=Fs(se=>se.projects),[ee,ae]=l.useState(()=>B??null);l.useEffect(()=>{if(B){ae(B);return}!ee&&le.length>0&&ae(le[0].id)},[B,le,ee]);const ge=l.useMemo(()=>ee?le.find(se=>se.id===ee)??null:null,[le,ee]),te=ge?.path??O,E=l.useCallback(se=>{ae(se),se!==B&&ne(se)},[B,ne]),{currentTheme:z}=Rr(),J=l.useCallback(se=>{const ie=se.label?.trim()||ii(se.path,L),K=Wo({id:se.id,iconImage:se.iconImage??null},{themeVariant:z.metadata.variant,iconColor:z.colors.surface.foreground}),_e=se.icon?vc[se.icon]:null,He=se.color?Ko[se.color]:void 0;return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[K?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:se.iconBackground?{backgroundColor:se.iconBackground}:void 0,children:s.jsx("img",{src:K,alt:"",className:"h-full w-full object-contain",draggable:!1})}):_e?s.jsx(_e,{className:"h-3.5 w-3.5 shrink-0",style:He?{color:He}:void 0}):s.jsx(zn,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:He?{color:He}:void 0}),s.jsx("span",{className:"truncate",children:ie})]})},[L,z.metadata.variant,z.colors.surface.foreground]),H=l.useMemo(()=>{if(ge?.path)return{id:ge.id,path:ge.path};const se=O??W;return se?{id:`path:${se}`,path:se}:null},[ge,O,W]),[re,ce]=l.useState(()=>typeof window>"u"?!1:kn()),Ne=l.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),me=pc();l.useEffect(()=>{typeof window>"u"||ce(kn())},[]);const we=l.useMemo(()=>{if(typeof window>"u")return null;const se=window.__OPENCHAMBER_MACOS_MAJOR__;if(typeof se=="number"&&Number.isFinite(se)&&se>0)return se;if(typeof navigator>"u")return null;const ie=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!ie)return null;const K=Number.parseInt(ie[1],10),_e=Number.parseInt(ie[2],10);return Number.isNaN(K)?null:K===10?_e:K},[]),_=l.useMemo(()=>re&&Ne||me?"pl-[5.5rem]":"pl-3",[re,Ne,me]),ue=l.useMemo(()=>!re||!Ne||we===null?"":we>=26?"h-12":we<=15?"h-14":"",[re,Ne,we]),Q=l.useCallback(async se=>{se.target.closest("button, a, input, select, textarea")||se.button===0&&re&&await Mg()},[re]);l.useEffect(()=>{if(!n)return;const se=ie=>{ie.key==="Escape"&&(ie.preventDefault(),ie.stopPropagation(),n())};return window.addEventListener("keydown",se,!0),()=>window.removeEventListener("keydown",se,!0)},[n]);const[oe,Z]=l.useState(""),{isLoading:Ie,isGitRepository:Se}=rb(te),Y=Nd(se=>se.createMultiRun),fe=Nd(se=>se.error),ke=Nd(se=>se.clearError);l.useEffect(()=>{typeof t=="string"&&t.trim().length>0&&d(se=>se.trim().length>0?se:t)},[t]),l.useEffect(()=>{if(!H)return;let se=!1;return j(!0),(async()=>{try{const ie=await Vu(H);se||w(ie)}catch{}finally{se||j(!1)}})(),()=>{se=!0}},[H]);const xe=se=>{p.length>=Sd||(m(ie=>[...ie,se]),ke())},he=se=>{m(ie=>ie.filter((K,_e)=>_e!==se)),ke()},Pe=l.useCallback((se,ie)=>{m(K=>K.map((_e,He)=>He===se?ie:_e))},[]),Be=async se=>{const ie=se.target.files;if(!ie)return;let K=0;for(let _e=0;_e<ie.length;_e++){const He=ie[_e];if(He.size>LT){q.error(a("multirun.launcher.toast.fileTooLarge",{fileName:He.name}));continue}try{const Ke=await new Promise((Xe,mt)=>{const et=new FileReader;et.onload=()=>Xe(et.result),et.onerror=mt,et.readAsDataURL(He)}),Ze={id:mu(),filename:He.name,mimeType:He.type||"application/octet-stream",size:He.size,dataUrl:Ke};f(Xe=>[...Xe,Ze]),K++}catch(Ke){console.error("File attach failed",Ke),q.error(a("multirun.launcher.toast.attachFailed",{fileName:He.name}))}}K>0&&q.success(K===1?a("multirun.launcher.toast.attachedSingle",{count:K}):a("multirun.launcher.toast.attachedPlural",{count:K})),M.current&&(M.current.value="")},G=se=>{f(ie=>ie.filter(K=>K.id!==se))},be=l.useCallback((se,ie)=>{if(se.startsWith("/")){const He=se.indexOf(" "),Ke=se.indexOf(`
125
- `),Ze=Math.min(He===-1?se.length:He,Ke===-1?se.length:Ke);if(ie<=Ze&&He===-1){T(se.substring(1,Ze)),N(!0),I(!1);return}}N(!1);const K=se.substring(0,ie),_e=K.lastIndexOf("@");if(_e!==-1){const He=_e>0?K[_e-1]:null,Ke=K.substring(_e+1);(!He||/\s/.test(He))&&!Ke.includes(" ")&&!Ke.includes(`
126
- `)?(k(Ke),I(!0)):I(!1);return}I(!1)},[]),De=l.useCallback(se=>{if(P&&V.current&&(se.key==="Enter"||se.key==="ArrowUp"||se.key==="ArrowDown"||se.key==="Escape"||se.key==="Tab")){se.preventDefault(),V.current.handleKeyDown(se.key);return}C&&F.current&&(se.key==="Enter"||se.key==="ArrowUp"||se.key==="ArrowDown"||se.key==="Escape"||se.key==="Tab")&&(se.preventDefault(),F.current.handleKeyDown(se.key))},[P,C]),Ae=l.useCallback(se=>{const K=$.current?.selectionStart??c.length,He=c.substring(0,K).lastIndexOf("@"),Ke=se.relativePath&&se.relativePath.trim().length>0?se.relativePath.trim():se.path||se.name,Ze=He!==-1?He:K,Xe=`${c.substring(0,Ze)}@${Ke} ${c.substring(K)}`,mt=Ze+Ke.length+2;d(Xe),I(!1),k(""),requestAnimationFrame(()=>{const et=$.current;et&&(et.selectionStart=mt,et.selectionEnd=mt,et.focus()),be(Xe,mt)})},[c,be]),ve=l.useCallback(se=>{const K=$.current?.selectionStart??c.length,He=c.substring(0,K).lastIndexOf("@"),Ke=He!==-1?He:K,Ze=`${c.substring(0,Ke)}@${se} ${c.substring(K)}`,Xe=Ke+se.length+2;d(Ze),I(!1),k(""),requestAnimationFrame(()=>{const mt=$.current;mt&&(mt.selectionStart=Xe,mt.selectionEnd=Xe,mt.focus()),be(Ze,Xe)})},[c,be]),U=l.useCallback(se=>{const ie=`/${se.name} `;d(ie),N(!1),T(""),requestAnimationFrame(()=>{const K=$.current;K&&(K.focus(),K.selectionStart=K.value.length,K.selectionEnd=K.value.length),be(ie,ie.length)})},[be]),de=async se=>{if(se.preventDefault(),!!c.trim()&&!(p.length<2)){x(!0),ke();try{ee&&ee!==B&&ne(ee);const ie=p.map(({instanceId:Ze,...Xe})=>Xe),K=b.map(Ze=>({mime:Ze.mimeType,filename:Ze.filename,url:Ze.dataUrl})),_e=g.filter(Ze=>Ze.trim().length>0),He={name:i.trim(),prompt:c.trim(),models:ie,agent:u||void 0,worktreeBaseBranch:oe,files:K.length>0?K:void 0,setupCommands:_e.length>0?_e:void 0},Ke=await Y(He);Ke&&(Ke.firstSessionId&&Wt.getState().setCurrentSession(Ke.firstSessionId),e?.())}finally{x(!1)}}},Re=!!(i.trim()&&c.trim()&&p.length>=2&&oe&&Se&&!Ie),Le=g.filter(se=>se.trim()).length;return s.jsxs("form",{onSubmit:de,className:"flex flex-col h-full bg-background",children:[r?null:s.jsxs("header",{onMouseDown:Q,className:pe("relative flex h-12 shrink-0 items-center justify-center border-b app-region-drag select-none",_,ue),style:{borderColor:"var(--interactive-border)"},children:[s.jsx("h1",{className:"typography-ui-label font-medium",children:a("multirun.launcher.title")}),n&&s.jsx("div",{className:"absolute right-0 flex items-center pr-3",children:s.jsxs(kt,{children:[s.jsx(St,{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(Ds,{className:"h-5 w-5"})})}),s.jsx(Ct,{children:s.jsx("p",{children:a("multirun.launcher.actions.closeEsc")})})]})})]}),s.jsx(Vo,{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(Ni,{htmlFor:"multirun-project",required:!0,children:a("multirun.launcher.project.label")}),le.length>0?s.jsxs(ps,{value:ee??void 0,onValueChange:E,children:[s.jsx(fs,{id:"multirun-project",size:"lg",className:"w-fit max-w-full",children:ge?s.jsx(ys,{children:J(ge)}):s.jsx(ys,{placeholder:a("multirun.launcher.project.placeholder")})}),s.jsx(hs,{fitContent:!0,children:le.map(se=>s.jsx(Ot,{value:se.id,className:"max-w-[24rem]",children:J(se)},se.id))})]}):s.jsx("p",{className:"typography-micro text-muted-foreground py-2",children:a("multirun.launcher.project.empty")})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Ni,{htmlFor:"group-name",required:!0,info:s.jsx(yl,{children:a("multirun.launcher.groupName.info")}),children:a("multirun.launcher.groupName.label")}),s.jsx(Vt,{id:"group-name",value:i,onChange:se=>o(se.target.value),placeholder:a("multirun.launcher.groupName.placeholder"),className:"typography-meta w-full",required:!0})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Ni,{htmlFor:"multirun-worktree-base-branch",info:s.jsx(yl,{children:a("multirun.launcher.baseBranch.info")}),children:a("multirun.launcher.baseBranch.label")}),s.jsx(DT,{directory:te,value:oe,onChange:Z,id:"multirun-worktree-base-branch"})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Ni,{htmlFor:"multirun-agent",info:s.jsx(yl,{children:a("multirun.launcher.agent.info")}),children:a("multirun.launcher.agent.label")}),s.jsx(TT,{value:u,onChange:h,id:"multirun-agent"})]})]}),s.jsxs(yr,{open:v,onOpenChange:S,children:[s.jsxs(Mr,{className:"w-full flex items-center gap-2 py-1.5 px-2 -mx-2 rounded-lg hover:bg-[var(--interactive-hover)]/50 transition-colors group",children:[s.jsx(Yh,{className:"h-3.5 w-3.5 text-muted-foreground/70"}),s.jsx("span",{className:"typography-meta font-medium text-muted-foreground group-hover:text-foreground transition-colors",children:a("multirun.launcher.setupCommands.label")}),Le>0&&s.jsx("span",{className:"inline-flex items-center justify-center h-4 min-w-4 px-1 rounded-full typography-micro font-medium",style:{backgroundColor:"var(--primary-base)",color:"var(--primary-foreground)",fontSize:"0.625rem",lineHeight:1},children:Le}),s.jsx(Cs,{className:pe("h-3.5 w-3.5 text-muted-foreground/50 transition-transform duration-200 ml-auto",v&&"rotate-180")})]}),s.jsx(vr,{children:s.jsx("div",{className:"pt-2 space-y-1.5",children:A?s.jsx("p",{className:"typography-meta text-muted-foreground/70 px-2",children:a("multirun.launcher.setupCommands.loading")}):s.jsxs(s.Fragment,{children:[g.map((se,ie)=>s.jsxs("div",{className:"flex gap-1.5",children:[s.jsx(Vt,{value:se,onChange:K=>{const _e=[...g];_e[ie]=K.target.value,w(_e)},placeholder:a("multirun.launcher.setupCommands.commandPlaceholder"),className:"h-8 flex-1 font-mono text-xs"}),s.jsx("button",{type:"button",onClick:()=>{const K=g.filter((_e,He)=>He!==ie);w(K)},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(Ds,{className:"h-3.5 w-3.5"})})]},`${se}-${ie}`)),s.jsxs("button",{type:"button",onClick:()=>w([...g,""]),className:"flex items-center gap-1 typography-meta text-muted-foreground hover:text-foreground transition-colors px-1",children:[s.jsx(_s,{className:"h-3 w-3"}),a("multirun.launcher.setupCommands.addCommand")]})]})})})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(Ni,{htmlFor:"prompt",required:!0,children:a("multirun.launcher.prompt.label")}),s.jsxs("div",{className:"relative",children:[s.jsx(Sn,{id:"prompt",ref:$,value:c,onChange:se=>{const ie=se.target.value;d(ie);const K=se.target.selectionStart??ie.length;be(ie,K)},onKeyDown:De,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}),P?s.jsx(Ig,{ref:V,searchQuery:D,onCommandSelect:U,onClose:()=>N(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,C?s.jsx(Ag,{ref:F,searchQuery:R,onFileSelect:Ae,onAgentSelect:ve,onClose:()=>I(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[s.jsx("input",{ref:M,type:"file",multiple:!0,className:"hidden",onChange:Be,accept:"*/*"}),s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>M.current?.click(),className:"inline-flex items-center gap-1 h-6 px-2 rounded-md typography-micro text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]/50 transition-colors",children:[s.jsx(lv,{className:"h-3 w-3"}),a("multirun.launcher.attachments.attach")]})}),s.jsx(Ct,{children:a("multirun.launcher.attachments.tooltip")})]}),b.map(se=>s.jsxs("div",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded-md typography-micro border",style:{backgroundColor:"var(--surface-elevated)",borderColor:"var(--interactive-border)"},children:[se.mimeType.startsWith("image/")?s.jsx(Jh,{className:"h-3 w-3 text-muted-foreground"}):s.jsx(qh,{className:"h-3 w-3 text-muted-foreground"}),s.jsx("span",{className:"truncate max-w-[100px]",title:se.filename,children:se.filename}),s.jsx("button",{type:"button",onClick:()=>G(se.id),className:"text-muted-foreground hover:text-destructive",children:s.jsx(Ds,{className:"h-3 w-3"})})]},se.id))]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(Ni,{required:!0,info:s.jsx(yl,{children:a("multirun.launcher.models.info",{max:Sd})}),children:a("multirun.launcher.models.label")}),s.jsx(ST,{selectedModels:p,onAdd:xe,onRemove:he,onUpdate:Pe,minModels:2,maxModels:Sd})]}),fe&&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:fe})]})})}),s.jsx("div",{className:"shrink-0 px-4 sm:px-6 py-3",children:s.jsxs("div",{className:"mx-auto w-full max-w-2xl flex items-center justify-end gap-2",children:[s.jsx(je,{type:"button",variant:"ghost",size:"sm",onClick:n,children:a("multirun.launcher.actions.cancel")}),s.jsx(je,{type:"submit",size:"sm",disabled:!Re||y,children:y?a("multirun.launcher.actions.creating"):s.jsx(s.Fragment,{children:a("multirun.launcher.actions.startWithModelCount",{count:p.length})})})]})})]})};class BT 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(Rg,{className:"w-full max-w-md",children:[s.jsx(Nw,{className:"text-center",children:s.jsxs(Sw,{className:"flex items-center justify-center gap-2 text-destructive",children:[s.jsx(cv,{className:"h-5 w-5"}),this.props.texts.title]})}),s.jsxs(kw,{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(je,{onClick:this.handleReset,variant:"outline",className:"flex-1",children:[s.jsx(Mn,{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 VT(t){const e=nt.c(22),{t:n}=ut();let r;e[0]!==n?(r=n("chat.errorBoundary.title"),e[0]=n,e[1]=r):r=e[1];let a;e[2]!==n?(a=n("chat.errorBoundary.description"),e[2]=n,e[3]=a):a=e[3];let i;e[4]!==n?(i=n("chat.errorBoundary.sessionLabel"),e[4]=n,e[5]=i):i=e[5];let o;e[6]!==n?(o=n("chat.errorBoundary.detailsSummary"),e[6]=n,e[7]=o):o=e[7];let c;e[8]!==n?(c=n("chat.errorBoundary.resetAction"),e[8]=n,e[9]=c):c=e[9];let d;e[10]!==n?(d=n("chat.errorBoundary.persistentHint"),e[10]=n,e[11]=d):d=e[11];let p;e[12]!==r||e[13]!==a||e[14]!==i||e[15]!==o||e[16]!==c||e[17]!==d?(p={title:r,description:a,sessionLabel:i,detailsSummary:o,resetAction:c,persistentHint:d},e[12]=r,e[13]=a,e[14]=i,e[15]=o,e[16]=c,e[17]=d,e[18]=p):p=e[18];let m;return e[19]!==t||e[20]!==p?(m=s.jsx(BT,{...t,texts:p}),e[19]=t,e[20]=p,e[21]=m):m=e[21],m}const pu=()=>{const t=nt.c(3),n=Wt(zT)||void 0;let r;t[0]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(Cw,{}),t[0]=r):r=t[0];let a;return t[1]!==n?(a=s.jsx(VT,{sessionId:n,children:r}),t[1]=n,t[2]=a):a=t[2],a};function zT(t){return t.currentSessionId}const _T=ca(()=>Tr(()=>Promise.resolve().then(()=>x3),void 0).then(t=>({default:t.PlanView}))),yh=ca(()=>Tr(()=>Promise.resolve().then(()=>Y2),void 0).then(t=>({default:t.GitView}))),UT=ca(()=>Tr(()=>Promise.resolve().then(()=>Bk),void 0).then(t=>({default:t.DiffView}))),vh=ca(()=>Tr(()=>import("./TerminalView-CSEtmbyD.js"),__vite__mapDeps([5,0,1,2,3,4,6])).then(t=>({default:t.TerminalView}))),WT=ca(()=>Tr(()=>Promise.resolve().then(()=>u3),void 0).then(t=>({default:t.FilesView}))),KT=ca(()=>Tr(()=>Promise.resolve().then(()=>II),void 0).then(t=>({default:t.SettingsView}))),HT=ca(()=>Tr(()=>import("./SettingsWindow-BPWLJy6K.js"),__vite__mapDeps([7,0,1,2,3,4,6])).then(t=>({default:t.SettingsWindow}))),GT=ca(()=>Tr(()=>import("./MultiRunWindow-C2H5hpiq.js"),__vite__mapDeps([8,0,1,2,3,4,6])).then(t=>({default:t.MultiRunWindow}))),vl=85,qT=250,QT=500,JT=400,YT=860,XT=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},ZT=()=>{const{t}=ut(),e=1140,n=1220,r=640,a=700,i=Te(te=>te.isSidebarOpen),o=Te(te=>te.isRightSidebarOpen),c=Te(te=>te.isBottomTerminalOpen),d=Te(te=>te.setRightSidebarOpen),p=Te(te=>te.setBottomTerminalOpen),m=Te(te=>te.activeMainTab),u=Te(te=>te.setIsMobile),h=Te(te=>te.isSessionSwitcherOpen),b=Te(te=>te.isSettingsDialogOpen),f=Te(te=>te.setSettingsDialogOpen),y=Te(te=>te.isMultiRunLauncherOpen),x=Te(te=>te.setMultiRunLauncherOpen),g=Te(te=>te.multiRunLauncherPrefillPrompt),{isMobile:w,isTablet:v}=un(),S=l.useMemo(()=>kn(),[]),A=Te(te=>te.sidebarWidth),j=Te(te=>te.rightSidebarWidth),[C,I]=l.useState(null),R=Xr()??"",k=l.useMemo(()=>XT(R),[R]),P=Te(te=>{if(!k)return!1;const E=te.contextPanelByDirectory[k],z=E?.tabs??[],J=z.find(H=>H.id===E?.activeTabId)??z[z.length-1];return!!(E?.isOpen&&J)}),N=Te(te=>te.setSidebarOpen),D=l.useRef(!1),T=l.useRef(!1),M=l.useRef(!1),[$,F]=l.useState(!1),V=l.useRef(!1),O=fm(0),L=Oe.useRef(0),W=fm(0),B=Oe.useRef(0);Oe.useEffect(()=>{w&&(L.current=window.innerWidth*(vl/100),B.current=window.innerWidth*(vl/100))},[w]),Oe.useEffect(()=>{if(!w)return;const te=$?0:-L.current;hm(O,te,{type:"spring",stiffness:400,damping:35,mass:.8})},[$,w,O]),Oe.useEffect(()=>{if(!w)return;V.current=o;const te=o?0:B.current;hm(W,te,{type:"spring",stiffness:400,damping:35,mass:.8})},[w,o,W]),Oe.useEffect(()=>{w&&F(h)},[h,w]),Oe.useEffect(()=>{!w||!b||(F(!1),h&&Te.getState().setSessionSwitcherOpen(!1),o&&d(!1))},[w,b,h,o,d]),Oe.useEffect(()=>{w&&(V.current=o)},[o,w]);const ne=Ya(te=>te.checkForUpdates);l.useEffect(()=>{let H=!1,re=null;const ce=me=>{const we=Math.round(me*1e3);return Math.max(3e5,Math.min(864e5,we))},Ne=me=>{H||(re=window.setTimeout(async()=>{const we=await ne(),_=typeof we=="number"&&Number.isFinite(we)?ce(we):36e5;Ne(_)},me))};return Ne(3e3),()=>{H=!0,re!==null&&window.clearTimeout(re)}},[ne]),l.useEffect(()=>{Te.getState().isMobile!==w&&u(w)},[w,u]),l.useEffect(()=>{if(typeof window>"u")return;let te;const E=()=>{te!==void 0&&window.clearTimeout(te),te=window.setTimeout(()=>{Te.getState().updateProportionalSidebarWidths()},150)};return window.addEventListener("resize",E),()=>{window.removeEventListener("resize",E),te!==void 0&&window.clearTimeout(te)}},[]),l.useEffect(()=>{if(P){Te.getState().isSidebarOpen&&(N(!1),M.current=!0);return}M.current&&(N(!0),M.current=!1)},[P,N]),l.useEffect(()=>{if(typeof window>"u")return;let te;const E=()=>{const J=Te.getState(),H=window.innerWidth,re=window.innerHeight,ce=H<e,Ne=H>=n;if(ce?J.isRightSidebarOpen&&(d(!1),D.current=!0):Ne&&D.current&&(d(!0),D.current=!1),!w&&!v){const me=re<r,we=re>=a;me?J.isBottomTerminalOpen&&(p(!1),T.current=!0):we&&T.current&&(p(!0),T.current=!1)}},z=()=>{te!==void 0&&window.clearTimeout(te),te=window.setTimeout(()=>{E()},100)};return E(),window.addEventListener("resize",z),()=>{window.removeEventListener("resize",z),te!==void 0&&window.clearTimeout(te)}},[w,v,p,d]),l.useEffect(()=>{if(typeof window>"u")return;const te=Te.subscribe((E,z)=>{const J=window.innerWidth,H=window.innerHeight,re=J>=n,ce=H>=a;E.isRightSidebarOpen!==z.isRightSidebarOpen&&re&&(D.current=!1),E.isBottomTerminalOpen!==z.isBottomTerminalOpen&&ce&&(T.current=!1)});return()=>{te()}},[w,v,p,d]);const le=l.useMemo(()=>{switch(m){case"plan":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(_T,{})});case"git":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(yh,{})});case"diff":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(UT,{})});case"terminal":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(vh,{})});case"files":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(WT,{})});default:return null}},[m]),ee=m==="chat",ae=l.useMemo(()=>Math.min(QT,Math.max(qT,A||Hd)),[A]),ge=l.useMemo(()=>Math.min(YT,Math.max(JT,j||Qg)),[j]);return s.jsx(ik,{children:s.jsxs("div",{"data-page-scroll-lock":"true",className:pe("main-content-safe-area h-[100dvh]",w?"flex flex-col":"flex","bg-background"),children:[s.jsx(AI,{}),s.jsx(hA,{}),s.jsx(yA,{}),s.jsx(bT,{}),w?s.jsxs(Iw,{value:{leftDrawerOpen:$,rightDrawerOpen:o,toggleLeftDrawer:()=>{o&&d(!1),F(!$)},toggleRightDrawer:()=>{$&&F(!1),d(!o)},leftDrawerX:O,rightDrawerX:W,leftDrawerWidth:L,rightDrawerWidth:B,setMobileLeftDrawerOpen:F,setRightSidebarOpen:d},children:[!b&&s.jsx(rp,{onToggleLeftDrawer:()=>{o&&d(!1),F(!$)},onToggleRightDrawer:()=>{$&&F(!1),d(!o)},leftDrawerOpen:$,rightDrawerOpen:o}),s.jsx(Ec.button,{type:"button",initial:!1,animate:{opacity:$||o?1:0,pointerEvents:$||o?"auto":"none"},className:"fixed left-0 right-0 bottom-0 top-[var(--oc-header-height,56px)] z-40 bg-black/50 cursor-default",onClick:()=>{F(!1),d(!1)},"aria-label":t("mainLayout.mobile.closeDrawerAria")}),s.jsx(Ec.aside,{drag:"x",dragElastic:.08,dragMomentum:!1,dragConstraints:{left:-(L.current||window.innerWidth*.85),right:0},style:{width:`${vl}%`,x:O},onDragEnd:(te,E)=>{const z=L.current||window.innerWidth*.85,J=z*.3,H=500,re=O.get(),ce=E.offset.x<-J||E.velocity.x<-H,Ne=E.offset.x>J||E.velocity.x>H;ce?(O.set(-z),F(!1)):Ne?(O.set(0),F(!0)):re>-z/2?O.set(0):O.set(-z)},className:pe("fixed left-0 top-[var(--oc-header-height,56px)] z-50 h-[calc(100%-var(--oc-header-height,56px))] bg-background","cursor-grab active:cursor-grabbing"),"aria-hidden":!$,children:s.jsx("div",{"data-page-scroll-lock":"true",className:"h-full overflow-hidden flex bg-[var(--surface-background)] shadow-none drawer-safe-area",style:{backgroundImage:"linear-gradient(var(--surface-muted), var(--surface-muted))"},children:s.jsx("div",{className:"flex-1 min-w-0 overflow-hidden flex flex-col","data-page-scroll-lock":"true",children:s.jsx(rn,{children:s.jsx(gh,{mobileVariant:!0})})})})}),s.jsx(Ec.aside,{drag:"x",dragElastic:.08,dragMomentum:!1,dragConstraints:{left:0,right:B.current||window.innerWidth*.85},style:{width:`${vl}%`,x:W},onDragEnd:(te,E)=>{const z=B.current||window.innerWidth*.85,J=z*.3,H=500,re=W.get(),ce=E.offset.x>J||E.velocity.x>H,Ne=E.offset.x<-J||E.velocity.x<-H;ce?(W.set(z),d(!1)):Ne?(W.set(0),d(!0)):re<z/2?W.set(0):W.set(z)},className:pe("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(rn,{children:s.jsx(l.Suspense,{fallback:null,children:s.jsx(yh,{})})})})}),s.jsx("div",{"data-page-scroll-lock":"true",className:pe("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:pe("absolute inset-0",!ee&&"invisible"),children:s.jsx(rn,{children:s.jsx(pu,{})})}),le&&s.jsx("div",{className:"absolute inset-0",children:s.jsx(rn,{children:le})}),y&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",children:s.jsx(rn,{children:s.jsx($T,{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(rn,{children:s.jsx(l.Suspense,{fallback:null,children:s.jsx(KT,{onClose:()=>f(!1)})})})})]}):s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"flex flex-1 overflow-hidden relative",children:s.jsxs("div",{className:pe("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:pe("pointer-events-none absolute top-0 z-0","bg-sidebar"),style:{left:`${ae}px`,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 100% 100%, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 100% 100%, transparent calc(10px - 1px), black 10px)"}}),s.jsx("div",{"aria-hidden":!0,className:pe("pointer-events-none absolute bottom-0 z-0","bg-sidebar"),style:{left:`${ae}px`,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 100% 0%, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 100% 0%, transparent calc(10px - 1px), black 10px)"}})]}):null,o?s.jsxs(s.Fragment,{children:[s.jsx("div",{"aria-hidden":!0,className:pe("pointer-events-none absolute top-0 z-0","bg-sidebar"),style:{right:`${ge}px`,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 0 100%, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 0 100%, transparent calc(10px - 1px), black 10px)"}}),s.jsx("div",{"aria-hidden":!0,className:pe("pointer-events-none absolute bottom-0 z-0","bg-sidebar"),style:{right:`${ge}px`,width:"10px",height:"10px",WebkitMaskImage:"radial-gradient(circle at 0 0, transparent calc(10px - 1px), black 10px)",maskImage:"radial-gradient(circle at 0 0, transparent calc(10px - 1px), black 10px)"}})]}):null,s.jsx(P0,{isOpen:i,isMobile:w,className:"border-0",children:s.jsx(gh,{})}),s.jsxs("div",{className:pe("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(rp,{desktopRightSidebarActionsHost:C}),s.jsx("div",{className:pe("flex flex-1 min-h-0 overflow-hidden",i||ee?"":"border-l border-border/50",o?"":"border-r border-border/50"),"data-page-scroll-lock":"true",children:s.jsxs("div",{className:"relative flex flex-1 min-h-0 min-w-0 overflow-hidden","data-page-scroll-lock":"true",children:[s.jsxs("main",{className:"flex-1 overflow-hidden bg-background relative","data-page-scroll-lock":"true",children:[s.jsx("div",{className:pe("absolute inset-0",!ee&&"invisible"),children:s.jsx(rn,{children:s.jsx(pu,{})})}),le&&s.jsx("div",{className:"absolute inset-0",children:s.jsx(rn,{children:le})})]}),s.jsx(t5,{})]})}),s.jsx(S0,{isOpen:c,isMobile:w,children:c?s.jsx(rn,{children:s.jsx(l.Suspense,{fallback:null,children:s.jsx(vh,{})})}):null})]}),s.jsx(D0,{isOpen:o,className:"border-0",onTopActionsHostChange:I,children:s.jsx(rn,{children:s.jsx(TS,{})})})]})}),s.jsx(l.Suspense,{fallback:null,children:s.jsx(HT,{open:b,onOpenChange:f})}),s.jsx(l.Suspense,{fallback:null,children:s.jsx(GT,{open:y,onOpenChange:x,initialPrompt:g})})]})]})})},e8=t=>{if(t<1e3)return`${Math.round(t)}ms`;const e=t/1e3;if(e<60)return`${e.toFixed(1)}s`;const n=Math.floor(e/60),r=Math.round(e%60);return`${n}m ${r}s`},fr=t=>{const e=nt.c(8),{label:n,value:r}=t;let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[0]=a):a=e[0];let i;e[1]!==n?(i=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:n}),e[1]=n,e[2]=i):i=e[2];let o;e[3]!==r?(o=s.jsx("div",{className:"typography-markdown font-semibold text-[var(--surface-foreground)]",children:r}),e[3]=r,e[4]=o):o=e[4];let c;return e[5]!==i||e[6]!==o?(c=s.jsxs("div",{className:"rounded-md p-2",style:a,children:[i,o]}),e[5]=i,e[6]=o,e[7]=c):c=e[7],c},wh=t=>{const e=nt.c(43),{title:n,snapshot:r,emptyLabel:a}=t,{t:i}=ut();let o;if(e[0]!==a||e[1]!==r.durationMs||e[2]!==r.entries||e[3]!==r.lastUpdatedAt||e[4]!==r.startedAt||e[5]!==i||e[6]!==n){const c=r.entries.slice(0,12);let d;e[8]!==r.entries?(d=r.entries.reduce(n8,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?e8(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 y;e[23]!==r.entries.length||e[24]!==f?(y=s.jsx(fr,{label:f,value:r.entries.length}),e[23]=r.entries.length,e[24]=f,e[25]=y):y=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(fr,{label:x,value:p}),e[28]=x,e[29]=p,e[30]=g):g=e[30];let w;e[31]!==i?(w=i("memoryDebugPanel.metric.lastUpdate"),e[31]=i,e[32]=w):w=e[32];let v;e[33]!==r.lastUpdatedAt||e[34]!==i?(v=r.lastUpdatedAt?i("memoryDebugPanel.common.live"):i("memoryDebugPanel.common.notAvailable"),e[33]=r.lastUpdatedAt,e[34]=i,e[35]=v):v=e[35];let S;e[36]!==w||e[37]!==v?(S=s.jsx(fr,{label:w,value:v}),e[36]=w,e[37]=v,e[38]=S):S=e[38];let A;e[39]!==g||e[40]!==S||e[41]!==y?(A=s.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[y,g,S]}),e[39]=g,e[40]=S,e[41]=y,e[42]=A):A=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,A,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(Es,{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},t8=t=>{const e=nt.c(101),{onClose:n}=t,{t:r}=ut(),[a,i]=l.useState("memory"),[o,c]=l.useState("idle"),d=Wt(r8),p=Tg(a8),m=_o(),u=bg(i8),h=gr(o8),[b,f]=l.useState(l8),[y,x]=l.useState(c8);let g;e[0]!==b.entries?(g=new Map,b.entries.forEach(Se=>{g.set(Se.metric,Se.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 v;e[4]!==g?(v=g.get("ui.message_list.render.streaming")??0,e[4]=g,e[5]=v):v=e[5];let S;e[6]!==g?(S=g.get("ui.chat_message.render")??0,e[6]=g,e[7]=S):S=e[7];let A;e[8]!==g?(A=g.get("ui.chat_message.render.streaming")??0,e[8]=g,e[9]=A):A=e[9];let j;e[10]!==g?(j=g.get("ui.chat_message.render.static_during_stream")??0,e[10]=g,e[11]=j):j=e[11];let C;e[12]!==g?(C=g.get("ui.chat_message.render.static_outside_active_turn_during_stream")??0,e[12]=g,e[13]=C):C=e[13];let I;e[14]!==w||e[15]!==v||e[16]!==S||e[17]!==A||e[18]!==j||e[19]!==C?(I={messageListRender:w,messageListRenderStreaming:v,chatMessageRender:S,chatMessageRenderStreaming:A,chatMessageRenderStaticDuringStream:j,chatMessageRenderStaticOutsideActiveTurnDuringStream:C},e[14]=w,e[15]=v,e[16]=S,e[17]=A,e[18]=j,e[19]=C,e[20]=I):I=e[20];const R=I;let k,P;e[21]===Symbol.for("react.memo_cache_sentinel")?(k=()=>{const Se=()=>{f(Cl()),x(Il())};Se();const Y=window.setInterval(Se,500);return()=>window.clearInterval(Y)},P=[],e[21]=k,e[22]=P):(k=e[21],P=e[22]),l.useEffect(k,P);let N,D;e[23]!==o?(N=()=>{if(o==="idle")return;const Se=window.setTimeout(()=>{c("idle")},1500);return()=>window.clearTimeout(Se)},D=[o],e[23]=o,e[24]=N,e[25]=D):(N=e[24],D=e[25]),l.useEffect(N,D);let T=0,M;if(e[26]!==u?(M=Object.keys(u),e[26]=u,e[27]=M):M=e[27],e[28]!==u||e[29]!==M||e[30]!==T){for(const Se of M)T=T+(u[Se]?.length??0);e[28]=u,e[29]=M,e[30]=T,e[31]=T}else T=e[31];const $=T;let F;if(e[32]!==d||e[33]!==u||e[34]!==p||e[35]!==m||e[36]!==r){let Se;e[38]!==d||e[39]!==u||e[40]!==p||e[41]!==r?(Se=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]=Se):Se=e[42],F=m.map(Se).sort(d8),e[32]=d,e[33]=u,e[34]=p,e[35]=m,e[36]=r,e[37]=F}else F=e[37];const V=F;let O;e[43]!==u?(O=Object.keys(u),e[43]=u,e[44]=O):O=e[44];const L=O.length;let W;e[45]===Symbol.for("react.memo_cache_sentinel")?(W=async()=>{try{const Se={generatedAt:new Date().toISOString(),ui:Cl(),vscode:Il()};await navigator.clipboard.writeText(JSON.stringify(Se,null,2)),c("copied")}catch{c("error")}},e[45]=W):W=e[45];const B=W;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 le;e[47]!==a?(le=a==="memory"?s.jsx(dv,{className:"h-4 w-4 text-[var(--surface-foreground)]"}):s.jsx(uv,{className:"h-4 w-4 text-[var(--surface-foreground)]"}),e[47]=a,e[48]=le):le=e[48];let ee;e[49]!==r?(ee=r("memoryDebugPanel.title"),e[49]=r,e[50]=ee):ee=e[50];let ae;e[51]!==ee?(ae=s.jsx("h3",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:ee}),e[51]=ee,e[52]=ae):ae=e[52];let ge;e[53]!==le||e[54]!==ae?(ge=s.jsxs("div",{className:"flex items-center gap-2",children:[le,ae]}),e[53]=le,e[54]=ae,e[55]=ge):ge=e[55];let te;e[56]!==a?(te=a==="streaming"?s.jsxs(s.Fragment,{children:[s.jsx(je,{size:"xs",variant:"ghost",onClick:B,children:s.jsx(br,{className:"h-3.5 w-3.5"})}),s.jsx(je,{size:"xs",variant:"ghost",onClick:()=>{Pw(),f(Cl()),x(Il())},children:s.jsx(Nn,{className:"h-3.5 w-3.5"})})]}):null,e[56]=a,e[57]=te):te=e[57];let E;e[58]!==n?(E=n?s.jsx(je,{size:"icon",variant:"ghost",className:"h-6 w-6",onClick:n,children:s.jsx(Ds,{className:"h-4 w-4"})}):null,e[58]=n,e[59]=E):E=e[59];let z;e[60]!==te||e[61]!==E?(z=s.jsxs("div",{className:"flex items-center gap-1",children:[te,E]}),e[60]=te,e[61]=E,e[62]=z):z=e[62];let J;e[63]!==ge||e[64]!==z?(J=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-2",children:[ge,z]}),e[63]=ge,e[64]=z,e[65]=J):J=e[65];let H;e[66]===Symbol.for("react.memo_cache_sentinel")?(H={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[66]=H):H=e[66];const re=a==="memory"?"secondary":"ghost";let ce;e[67]===Symbol.for("react.memo_cache_sentinel")?(ce=()=>i("memory"),e[67]=ce):ce=e[67];let Ne;e[68]!==r?(Ne=r("memoryDebugPanel.tabs.memory"),e[68]=r,e[69]=Ne):Ne=e[69];let me;e[70]!==re||e[71]!==Ne?(me=s.jsx(je,{size:"sm",variant:re,className:"flex-1",onClick:ce,children:Ne}),e[70]=re,e[71]=Ne,e[72]=me):me=e[72];const we=a==="streaming"?"secondary":"ghost";let _;e[73]===Symbol.for("react.memo_cache_sentinel")?(_=()=>i("streaming"),e[73]=_):_=e[73];let ue;e[74]!==r?(ue=r("memoryDebugPanel.tabs.streaming"),e[74]=r,e[75]=ue):ue=e[75];let Q;e[76]!==we||e[77]!==ue?(Q=s.jsx(je,{size:"sm",variant:we,className:"flex-1",onClick:_,children:ue}),e[76]=we,e[77]=ue,e[78]=Q):Q=e[78];let oe;e[79]!==me||e[80]!==Q?(oe=s.jsxs("div",{className:"mb-3 flex gap-1 rounded-md p-1",style:H,children:[me,Q]}),e[79]=me,e[80]=Q,e[81]=oe):oe=e[81];let Z;e[82]!==a||e[83]!==L||e[84]!==o||e[85]!==d||e[86]!==u||e[87]!==p||e[88]!==V||e[89]!==m||e[90]!==R||e[91]!==b||e[92]!==r||e[93]!==h||e[94]!==$||e[95]!==y?(Z=a==="memory"?s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"grid grid-cols-2 gap-2 typography-meta",children:[s.jsx(fr,{label:r("memoryDebugPanel.metric.totalMessages"),value:$}),s.jsx(fr,{label:r("memoryDebugPanel.metric.cachedSessions"),value:`${L} / ${Lm.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:Aw()})})]}),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:Lm.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(Es,{outerClassName:"max-h-48",className:"space-y-1 pr-1",children:V.map(Se=>s.jsxs("div",{className:"typography-meta flex items-center justify-between rounded p-1.5",style:{backgroundColor:Se.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:Se.title}),Se.isStreaming?s.jsx(sg,{className:"h-3 w-3 animate-pulse text-[var(--status-info)]"}):null,Se.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:Se.messageCount})}),Se.backgroundCount>0?s.jsxs("span",{className:"text-[var(--status-info)]",children:["+",Se.backgroundCount]}):null]})]},Se.id))})]}),s.jsx("div",{className:"flex gap-2 border-t border-[var(--interactive-border)] pt-2",children:s.jsxs(kt,{children:[s.jsx(St,{asChild:!0,children:s.jsx(je,{size:"sm",variant:"outline",className:"typography-meta",onClick:()=>{console.log("[DebugPanel] Session store state:",{sessions:m.map(u8),currentSessionId:d,cachedSessions:Object.keys(u),memoryStates:Object.fromEntries(p)})},children:r("memoryDebugPanel.actions.logState")})}),s.jsx(Ct,{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(je,{size:"xs",variant:"outline",onClick:B,children:r("memoryDebugPanel.actions.copyJson")})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[s.jsx(fr,{label:r("memoryDebugPanel.metric.uiMetrics"),value:b.entries.length}),s.jsx(fr,{label:r("memoryDebugPanel.metric.vscodeMetrics"),value:y.entries.length}),s.jsx(fr,{label:r("memoryDebugPanel.metric.messageListRenders"),value:R.messageListRender}),s.jsx(fr,{label:r("memoryDebugPanel.metric.messageListStreamRenders"),value:R.messageListRenderStreaming}),s.jsx(fr,{label:r("memoryDebugPanel.metric.chatMessageRenders"),value:R.chatMessageRender}),s.jsx(fr,{label:r("memoryDebugPanel.metric.chatMessageStreamRenders"),value:R.chatMessageRenderStreaming}),s.jsx(fr,{label:r("memoryDebugPanel.metric.chatMessageStaticDuringStream"),value:R.chatMessageRenderStaticDuringStream}),s.jsx(fr,{label:r("memoryDebugPanel.metric.chatMessageStaticOutsideActiveTurn"),value:R.chatMessageRenderStaticOutsideActiveTurnDuringStream})]}),s.jsx(wh,{title:r("memoryDebugPanel.section.uiStreamingMetrics"),snapshot:b,emptyLabel:r("memoryDebugPanel.section.noUiSamples")}),y.entries.length>0?s.jsx(wh,{title:r("memoryDebugPanel.section.vscodeBridgeMetrics"),snapshot:y,emptyLabel:r("memoryDebugPanel.section.noVscodeSamples")}):null]}),e[82]=a,e[83]=L,e[84]=o,e[85]=d,e[86]=u,e[87]=p,e[88]=V,e[89]=m,e[90]=R,e[91]=b,e[92]=r,e[93]=h,e[94]=$,e[95]=y,e[96]=Z):Z=e[96];let Ie;return e[97]!==J||e[98]!==oe||e[99]!==Z?(Ie=s.jsxs(Rg,{className:"fixed bottom-4 right-4 z-50 w-[28rem] p-4 shadow-none bottom-safe-area",style:ne,children:[J,oe,Z]}),e[97]=J,e[98]=oe,e[99]=Z,e[100]=Ie):Ie=e[100],Ie},s8=t8;function n8(t,e){return t+e.count}function r8(t){return t.currentSessionId}function a8(t){return t.sessionMemoryState}function i8(t){return t.message}function o8(t){return t.totalRequestCount}function l8(){return Cl()}function c8(){return Il()}function d8(t,e){return e.lastAccessed-t.lastAccessed}function u8(t){return{id:t.id,title:t.title}}const m8=()=>{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()??"":""},p8=async()=>{const t=m8()||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")},jh="openchamber:menu-action",kd="openchamber:check-for-updates",f8=t=>{const e=Wt(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=Ya(x=>x.checkForUpdates),{setThemeMode:u}=Rr(),h=l.useRef(!1),b=l.useCallback(()=>{h.current||(h.current=!0,m().then(()=>{const{available:x,error:g}=Ya.getState();if(g){q.error("Failed to check for updates",{description:g});return}x||q.success("You are on the latest version")}).finally(()=>{h.current=!1}))},[m]),f=l.useCallback(()=>{Dr.requestDirectoryDialog()},[]),y=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),Sg();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)||p8();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":{Dw().catch(()=>{q.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 v=w.detail;v&&y(v)},g=()=>{b()};return window.addEventListener(jh,x),window.addEventListener(kd,g),()=>{window.removeEventListener(jh,x),window.removeEventListener(kd,g)}},[y,b]),l.useEffect(()=>{if(typeof window>"u")return;const g=window.__TAURI__?.event?.listen;if(typeof g!="function")return;let w=null,v=null;return g("openchamber:menu-action",S=>{const A=S?.payload;typeof A=="string"&&y(A)}).then(S=>{w=S}).catch(()=>{}),g("openchamber:check-for-updates",()=>{window.dispatchEvent(new Event(kd))}).then(S=>{v=S}).catch(()=>{}),()=>{(async()=>{try{const A=w?.();A instanceof Promise&&await A}catch{}try{const A=v?.();A instanceof Promise&&await A}catch{}})()}},[y])},h8=["chat","git","diff","terminal","files"],g8=["settings","agents","commands","skills","providers","usage","git-identities"],Cr={SESSION:"session",TAB:"tab",SETTINGS:"settings",FILE:"file"};function Nh(t){const e=x8();return{sessionId:b8(e),tab:y8(e),settingsPath:v8(e),diffFile:w8(e)}}function x8(){if(typeof window>"u")return new URLSearchParams;try{return new URLSearchParams(window.location.search)}catch{return new URLSearchParams}}function b8(t){const e=t.get(Cr.SESSION);return!e||e.trim().length===0?null:e.trim()}function y8(t){const e=t.get(Cr.TAB);if(!e)return null;const n=e.toLowerCase().trim();return h8.includes(n)?n:null}function v8(t){const e=t.get(Cr.SETTINGS);if(!e)return null;const n=e.toLowerCase().trim();return n.length===0?null:n==="openchamber"||n==="general"||n==="preferences"?"home":(g8.includes(n),n)}function w8(t){const e=t.get(Cr.FILE);if(!e||e.trim().length===0)return null;try{return decodeURIComponent(e.trim())}catch{return e.trim()}}function Sh(){if(typeof window>"u")return!1;try{const t=new URLSearchParams(window.location.search);return t.has(Cr.SESSION)||t.has(Cr.TAB)||t.has(Cr.SETTINGS)||t.has(Cr.FILE)}catch{return!1}}const j8="chat";function ab(t){const e=new URLSearchParams;if(t.sessionId&&t.sessionId.trim().length>0&&e.set(Cr.SESSION,t.sessionId),t.isSettingsOpen){const n=t.settingsPath.trim().length>0?t.settingsPath:"home";return e.set(Cr.SETTINGS,n),e}return t.tab!==j8&&e.set(Cr.TAB,t.tab),t.tab==="diff"&&t.diffFile&&t.diffFile.trim().length>0&&e.set(Cr.FILE,t.diffFile),e}function N8(t,e){const n=typeof window<"u"?window.location.pathname:"/",r=t.toString();return r?`${n}?${r}`:n}function S8(t){if(typeof window>"u")return!0;try{const e=new URLSearchParams(window.location.search),n=ab(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 k8(t,e={}){if(!(typeof window>"u")&&!C8()&&!(!e.force&&S8(t)))try{const n=ab(t),r=N8(n);e.replace?window.history.replaceState({...window.history.state,route:t},"",r):window.history.pushState({route:t},"",r)}catch{}}function C8(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function I8(){return typeof window>"u"?!1:window.__VSCODE_CONFIG__!==void 0}function A8(){const t=l.useMemo(()=>I8(),[]),e=l.useRef(!1),n=l.useRef(!1),r=Wt(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=Wt.getState().currentSessionId;u.sessionId!==h&&await r(u.sessionId)}if(u.settingsPath){o(kx(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=Wt.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();k8(h,u)},[t,p]);l.useEffect(()=>{if(e.current||(e.current=!0,!Sh()))return;const u=Nh();(async()=>(await d(u),t||m({replace:!0})))()},[d,t,m]),l.useEffect(()=>{if(t)return;let u=Wt.getState().currentSessionId;return Wt.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,v=x.settingsPage!==b,S=x.pendingDiffFile!==f&&x.activeMainTab==="diff";u=x.activeMainTab,h=x.isSettingsDialogOpen,b=x.settingsPage,f=x.pendingDiffFile,(g||w||v||S)&&m()})},[t,m]),l.useEffect(()=>{if(typeof window>"u"||t)return;const u=()=>{const h=Nh();if(Sh())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 kh="pwa-install-toast-shown",P8=()=>{const t=nt.c(6),{browserTab:e}=$x(),{t:n}=ut(),r=l.useRef(n);let a,i;t[0]!==n?(a=()=>{r.current=n},i=[n],t[0]=n,t[1]=a,t[2]=i):(a=t[1],i=t[2]),l.useEffect(a,i);let o,c;t[3]!==e?(o=()=>{if(typeof window>"u"||!ja()||!e)return;let d=null,p=null;const m=()=>{p!==null&&(q.dismiss(p),p=null)},u=async()=>{if(!d)return;const f=d;d=null,m(),await f.prompt();const{outcome:y}=await f.userChoice;y==="accepted"&&q.success(r.current("pwa.installPrompt.started"))},h=f=>{const y=f;if(typeof y.prompt!="function")return;y.preventDefault(),d=y;const x=ng();x.getItem(kh)!=="true"&&p===null&&(x.setItem(kh,"true"),p=q.info(r.current("pwa.installPrompt.description"),{duration:1/0,action:{label:r.current("pwa.installPrompt.action"),onClick:()=>{u()}}}))},b=()=>{d=null,m(),q.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)},D8=["local","remote",null],T8=["ok","not-configured","unreachable","wrong-service","missing"];function ib(t){if(!t||typeof t!="object")return{valid:!1};const e=t,n=e.target,r=e.status;if(n!==null&&(typeof n!="string"||!D8.includes(n)))return{valid:!1};if(typeof r!="string"||!T8.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 Ch(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 M8(t){return t.isDesktopShell?t.bootOutcomeKnown?t.bootViewIsMain===!1?!0:t.isInitialized:!1:t.isInitialized}function R8(t){return t.isTauriShell&&!t.isDesktopLocalOriginActive}function Ih(){if(fu()!=="valid")return null;const e=window.__OPENCHAMBER_DESKTOP_BOOT_OUTCOME__,n=ib(e);return n.valid?n.outcome:null}function fu(){if(typeof window>"u")return"not-injected";const t=window.__OPENCHAMBER_DESKTOP_BOOT_OUTCOME__;return t==null?"not-injected":ib(t).valid?"valid":"malformed"}const E8=()=>{const t=nt.c(5),[e,n]=l.useState(F8),{isUpdating:r,message:a}=e;let i,o;if(t[0]===Symbol.for("react.memo_cache_sentinel")?(i=()=>Mw(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(Eg,{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 F8(){return Tw()}const O8=({open:t,onOpenChange:e})=>{const{t:n}=ut(),[r,a]=l.useState(null),[i,o]=l.useState(!1),[c,d]=l.useState(!1),[p,m]=l.useState(null),[u,h]=l.useState(!1),b=l.useCallback(async()=>{if(!i){o(!0),d(!1);try{if(!p){q.error(n("aboutDialog.toast.copyFailed"),{description:n("aboutDialog.toast.diagnosticsNotReady")});return}const y=await $m.copyTextToClipboard(p);y.ok?(d(!0),q.success(n("aboutDialog.toast.diagnosticsCopied"))):q.error(n("aboutDialog.toast.copyFailed"),{description:y.error})}catch(y){q.error(n("aboutDialog.toast.copyFailed")),console.error("Failed to copy diagnostics:",y)}finally{o(!1)}}},[p,i,n]);l.useEffect(()=>{if(!t)return;(async()=>{try{const x=await fetch("/api/system/info");if(x.ok){const g=await x.json();if(typeof g.openchamberVersion=="string"&&g.openchamberVersion.trim()){a(g.openchamberVersion);return}}}catch{}a(await Rw())})()},[t]),l.useEffect(()=>{if(!t){m(null),h(!1);return}let y=!1;return h(!0),$m.buildDiagnosticsReport().then(x=>{y||m(x)}).catch(x=>{y||(console.error("Failed to prepare diagnostics:",x),m(null))}).finally(()=>{y||h(!1)}),()=>{y=!0}},[t]);const f=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(Eg,{width:64,height:64}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("h2",{className:"text-lg font-semibold",children:"OpenChamber"}),f&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:n("aboutDialog.versionLabel",{version:f})})]}),s.jsxs("div",{className:"flex flex-col items-center gap-2 pt-2",children:[s.jsx("button",{onClick:b,disabled:i||u||!p,className:pe("typography-meta text-muted-foreground hover:text-foreground","underline-offset-2 hover:underline","disabled:opacity-50 disabled:cursor-not-allowed"),children:n(c?"aboutDialog.actions.diagnosticsCopied":u?"aboutDialog.actions.preparingDiagnostics":"aboutDialog.actions.copyDiagnostics")}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:n("aboutDialog.diagnosticsDescription")})]}),s.jsxs("div",{className:"flex items-center gap-4 pt-2",children:[s.jsxs("a",{href:"https://github.com/btriapitsyn/openchamber",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(wa,{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(Xh,{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(Ed,{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")})]})})})},Cd=(t,e)=>{const n=t.get(e);return typeof n!="string"?null:n.trim()||null},L8=(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},$8=()=>{const t=Pn(i=>i.completeAuth),[e,n]=l.useState("working"),[r,a]=l.useState("Completing MCP authorization...");return l.useEffect(()=>{if(typeof window>"u"){n("error"),a("Browser context unavailable.");return}const i=new URLSearchParams(window.location.search),o=Cd(i,"code"),c=Dx(i),d=Ju(i),p=Cd(i,"error"),m=Cd(i,"error_description");if(p){d&&fetch(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("error"),a(m??p);return}(async()=>{try{if(!o)throw new Error("Missing OAuth authorization code. Start authorization again from MCP Settings or paste the returned code into OpenChamber manually.");let u=c;if(!u&&d){const 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(L8(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(je,{type:"button",onClick:()=>{typeof window>"u"||window.location.replace("/")},children:"Return to OpenChamber"})})]})})},Ah=ca(()=>Tr(()=>import("./OnboardingScreen-B0qAcM9E.js"),__vite__mapDeps([9,0,1,2,3,4])).then(t=>({default:t.OnboardingScreen}))),B8=()=>{const t=nt.c(3),e=Te(K8),n=Te(H8);let r;return t[0]!==e||t[1]!==n?(r=s.jsx(O8,{open:e,onOpenChange:n}),t[0]=e,t[1]=n,t[2]=r):r=t[2],r},V8=t=>{const e=nt.c(21),{onRetry:n,isRetrying:r}=t,{t:a}=ut();let i;e[0]!==a?(i=a("startup.initRecovery.title"),e[0]=a,e[1]=i):i=e[1];let o;e[2]!==i?(o=s.jsx("h1",{className:"typography-title text-foreground",children:i}),e[2]=i,e[3]=o):o=e[3];let c;e[4]!==a?(c=a("startup.initRecovery.description"),e[4]=a,e[5]=c):c=e[5];let d;e[6]!==c?(d=s.jsx("p",{className:"typography-body text-muted-foreground",children:c}),e[6]=c,e[7]=d):d=e[7];let p;e[8]!==o||e[9]!==d?(p=s.jsxs("div",{className:"flex flex-col gap-2",children:[o,d]}),e[8]=o,e[9]=d,e[10]=p):p=e[10];let m;e[11]!==r||e[12]!==a?(m=a(r?"startup.initRecovery.retrying":"startup.initRecovery.retry"),e[11]=r,e[12]=a,e[13]=m):m=e[13];let u;e[14]!==r||e[15]!==n||e[16]!==m?(u=s.jsx(je,{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},z8=()=>{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}},_8=()=>typeof window>"u"?!1:window.location.pathname===Px,U8=t=>{const e=nt.c(7),{embeddedSessionChat:n,isVSCodeRuntime:r}=t,a=_o(),i=Wt(G8),o=Wt(q8);let c,d;return e[0]!==i||e[1]!==n||e[2]!==r||e[3]!==a||e[4]!==o?(c=()=>{!n||r||i!==n.sessionId&&a.some(p=>p.id===n.sessionId)&&o(n.sessionId)},d=[i,n,r,a,o],e[0]=i,e[1]=n,e[2]=r,e[3]=a,e[4]=o,e[5]=c,e[6]=d):(c=e[5],d=e[6]),l.useEffect(c,d),null};function W8({apis:t}){const e=yt(E=>E.initializeApp),n=yt(E=>E.isInitialized),r=yt(E=>E.isConnected),a=yt(E=>E.providers.length),i=yt(E=>E.agents.length),o=yt(E=>E.loadProviders),c=yt(E=>E.loadAgents),d=Wt(E=>E.error),p=Wt(E=>E.clearError),m=Ws(E=>E.currentDirectory),u=Ws(E=>E.setDirectory),h=Ws(E=>E.isSwitchingDirectory),[b,f]=l.useState(!1),y=Zn(E=>E.refreshStatus),[x,g]=l.useState(()=>t.runtime.isVSCode),[w,v]=l.useState(!0),[S,A]=l.useState(!1),[j,C]=l.useState(0),[I,R]=l.useState(!1),k=Te(E=>E.wideChatLayoutEnabled),P=Te(E=>E.mobileKeyboardMode),N=l.useMemo(()=>kn(),[]),D=Ru(E=>E.setPlanModeEnabled),[T,M]=l.useState(()=>fu()),[$,F]=l.useState(()=>{const E=Ih();return E!==null?Ch({isDesktopShell:!0,bootOutcome:E}):null}),V=l.useRef(!1),O=l.useMemo(()=>z8(),[]),L=!O||w,W=l.useMemo(()=>_8(),[]);l.useEffect(()=>(Bm(b),()=>{Bm(!1)}),[b]),l.useEffect(()=>{Ew(P)},[P]),l.useEffect(()=>{g(t.runtime.isVSCode)},[t.runtime.isVSCode]),l.useEffect(()=>(document.documentElement.classList.toggle("wide-chat-layout",k),()=>{document.documentElement.classList.remove("wide-chat-layout")}),[k]),l.useEffect(()=>(Vm(t),()=>Vm(null)),[t]),l.useEffect(()=>{O||y(t.github,{force:!0})},[t.github,O,y]),Fw();const B=T==="valid",ne=$?.screen==="main";l.useEffect(()=>{if(!M8({isDesktopShell:N,isInitialized:n,bootOutcomeKnown:B,bootViewIsMain:ne}))return;const E=setTimeout(()=>{const z=document.getElementById("initial-loading");z&&(z.classList.add("fade-out"),setTimeout(()=>{z.remove()},300))},150);return()=>clearTimeout(E)},[N,n,B,ne]),l.useEffect(()=>{if(!N||T!=="malformed")return;const E=document.getElementById("initial-loading");E&&(E.textContent="Desktop startup failed — please restart the app.")},[N,T]),l.useEffect(()=>{if(N)return;const E=setTimeout(()=>{const z=document.getElementById("initial-loading");z&&!n&&(z.classList.add("fade-out"),setTimeout(()=>{z.remove()},300))},5e3);return()=>clearTimeout(E)},[N,n]),l.useEffect(()=>{let E=!1;return(async()=>{const J=await fetch("/health",{method:"GET"}).catch(()=>null);if(!J||!J.ok||E)return;const H=await J.json().catch(()=>null);if(!H||E)return;const re=H.planModeExperimentalEnabled;D(re===!0||re===1||re==="1"||re==="true")})(),()=>{E=!0}},[D]),l.useEffect(()=>{x||e()},[e,x]),l.useEffect(()=>{if(x||n)return;let E=!0,z,J=0;const H=10,re=1e3,ce=async()=>{if(!E)return;if(J>=H){A(!0);return}const Ne=yt.getState();if(Ne.isInitialized){A(!1);return}J+=1,await Ne.initializeApp();const me=yt.getState();if(!E)return;if(me.isInitialized){A(!1);return}if(J>=H){A(!0);return}const we=Math.min(re*Math.pow(2,J-1),16e3);z=setTimeout(ce,we)};return z=setTimeout(ce,re),()=>{E=!1,z&&clearTimeout(z)}},[j,n,x]),l.useEffect(()=>{n&&A(!1)},[n]),l.useEffect(()=>{if(!S)return;const E=document.getElementById("initial-loading");E&&(E.classList.add("fade-out"),setTimeout(()=>{E.remove()},300))},[S]),l.useEffect(()=>{if(x||!r||a>0&&i>0)return;let E=!0,z=0;const J=15,H=async()=>{const ce=yt.getState();if(!(ce.providers.length>0&&ce.agents.length>0))try{ce.providers.length===0&&await o(),yt.getState().agents.length===0&&await c()}catch{}};H();const re=setInterval(()=>{if(E){if(++z>=J){clearInterval(re);return}H()}},2e3);return()=>{E=!1,clearInterval(re)}},[r,x,c,o,a,i]),l.useEffect(()=>{h||x||r&&Dn.setDirectory(m)},[m,h,r,x]),l.useEffect(()=>{if(!O||typeof window>"u")return;const E=H=>{const re=H?.visible===!0;v(re)},z=H=>{if(H.origin!==window.location.origin)return;const re=H.data;re?.type==="openchamber:embedded-visibility"&&E(re.payload)},J=window;return J.__openchamberSetEmbeddedVisibility=E,window.addEventListener("message",z),()=>{window.removeEventListener("message",z),J.__openchamberSetEmbeddedVisibility===E&&delete J.__openchamberSetEmbeddedVisibility}},[O]),l.useEffect(()=>{!O?.directory||x||m!==O.directory&&u(O.directory,{showOverlay:!1})},[m,O,x,u]),l.useEffect(()=>{if(!O||typeof window>"u")return;const E=z=>{z.storageArea===window.localStorage&&z.key==="ui-store"&&Te.persist.rehydrate()};return window.addEventListener("storage",E),()=>{window.removeEventListener("storage",E)}},[O]),l.useEffect(()=>{if(typeof window>"u")return;const E=z=>{const J=z.detail,H=typeof J?.sessionId=="string"?J.sessionId.trim():"";if(!H)return;const re=typeof J?.directory=="string"&&J.directory.trim().length>0?J.directory.trim():null;Te.getState().setActiveMainTab("chat"),Wt.getState().setCurrentSession(H,re)};return window.addEventListener("openchamber:open-session",E),()=>window.removeEventListener("openchamber:open-session",E)},[]),l.useEffect(()=>{if(typeof window>"u")return;const E=z=>{const J=z.detail,H=typeof J?.directory=="string"&&J.directory.trim().length>0?J.directory.trim():null,re=typeof J?.projectId=="string"&&J.projectId.trim().length>0?J.projectId.trim():null;Te.getState().setActiveMainTab("chat"),Te.getState().setSessionSwitcherOpen(!1),Wt.getState().openNewSessionDraft({selectedProjectId:re,directoryOverride:H,preserveDirectoryOverride:!!H})};return window.addEventListener("openchamber:open-draft-session",E),()=>window.removeEventListener("openchamber:open-draft-session",E)},[]),l.useEffect(()=>{if(typeof window>"u")return;const E=z=>{const J=z.detail,H=typeof J?.projectPath=="string"?J.projectPath.trim():"";if(!H)return;const re=Fs.getState(),ce=re.projects.find(Ne=>Ne.path===H);ce?re.setActiveProject(ce.id):re.addProject(H)};return window.addEventListener("openchamber:open-project",E),()=>window.removeEventListener("openchamber:open-project",E)},[]),l.useEffect(()=>{typeof window>"u"||!n||h||V.current||(V.current=!0,window.__openchamberAppReady=!0,window.dispatchEvent(new Event("openchamber:app-ready")))},[n,h]),Ow({enabled:L}),P8(),Lw(),A8();const le=l.useCallback(()=>{f(E=>!E)},[]);f8(le),l.useEffect(()=>{if(O)return;const E=z=>{Eu(z)&&z.shiftKey&&!z.altKey&&(z.code==="KeyD"||z.key.toLowerCase()==="d")&&(z.preventDefault(),f(H=>!H))};return window.addEventListener("keydown",E,!0),()=>window.removeEventListener("keydown",E,!0)},[O]),l.useEffect(()=>{O||d&&setTimeout(()=>p(),5e3)},[p,O,d]),l.useEffect(()=>{if(!N||T!=="not-injected")return;let E=!1,z=0;const J=200,H=2e3,re=50,ce=()=>{if(E)return;z++;const Ne=fu();if(Ne!=="not-injected"){if(E=!0,M(Ne),Ne==="valid"){const we=Ih();we&&F(Ch({isDesktopShell:!0,bootOutcome:we}))}return}const me=Math.min(J*Math.pow(1.1,z),H);if(z>=re){const we=document.getElementById("initial-loading");we&&!we.textContent?.includes("taking longer")&&(we.textContent="Desktop startup is taking longer than expected...")}window.setTimeout(ce,me)};return window.setTimeout(ce,J),()=>{E=!0}},[N,T]);const ee=l.useCallback(async()=>{if(R8({isTauriShell:ri(),isDesktopLocalOriginActive:oa()})){await jg();return}window.location.reload()},[]),ae=l.useCallback(async()=>{if(!I){A(!1),R(!0);try{await yt.getState().initializeApp()}finally{R(!1)}yt.getState().isInitialized||C(E=>E+1)}},[I]),ge=E=>{if(E.screen==="recovery")return E.variant};if(N&&$&&$.screen!=="main"){if($.screen==="chooser")return s.jsx(rn,{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(Ah,{mode:"first-launch",onCliAvailable:ee,onChooseRemote:()=>{}})})})});const E=ge($),z=$.screen==="recovery"&&"url"in $?$.url:void 0;return s.jsx(rn,{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(Ah,{mode:"recovery",recoveryVariant:E,recoveryHostUrl:z,recoveryHostLabel:void 0,onCliAvailable:ee})})})})}if(O)return s.jsx(rn,{children:s.jsx(zm,{sdk:Dn.getSdkClient(),directory:m||"",children:s.jsx(_m,{apis:t,children:s.jsx(Um,{delayDuration:300,skipDelayDuration:150,children:s.jsxs("div",{className:"h-full text-foreground bg-background",children:[s.jsx(U8,{embeddedSessionChat:O,isVSCodeRuntime:x}),s.jsx(Wm,{embeddedBackgroundWorkEnabled:L}),s.jsx(pu,{}),s.jsx(Km,{})]})})})})});if(W)return s.jsx(rn,{children:s.jsx($8,{})});if(S&&!n&&!x&&!O)return s.jsx(rn,{children:s.jsx(V8,{onRetry:()=>{ae()},isRetrying:I})});const te=!n&&!N;return s.jsx(rn,{children:s.jsx(zm,{sdk:Dn.getSdkClient(),directory:m||"",children:s.jsx(_m,{apis:t,children:s.jsx(aN,{children:s.jsx($w,{children:s.jsx(Um,{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(Wm,{embeddedBackgroundWorkEnabled:L}),s.jsx(ZT,{}),s.jsx(Km,{}),!te&&s.jsxs(s.Fragment,{children:[s.jsx(E8,{}),s.jsx(B8,{}),b&&s.jsx(s8,{onClose:()=>f(!1)})]})]})})})})})})})}function K8(t){return t.isAboutDialogOpen}function H8(t){return t.setAboutDialogOpen}function G8(t){return t.currentSessionId}function q8(t){return t.setCurrentSession}const Q8=typeof window<"u"&&window.__OPENCHAMBER_RUNTIME_APIS__||(()=>{throw new Error("Runtime APIs not provided for legacy UI entrypoint.")})();Bw();Vw().then(()=>{Promise.all([zw(),_w()]).catch(t=>{console.error("[main] settings init failed:",t)}),Uw(),Ww(),Kw()}).catch(t=>{console.error("[main] appearance init failed:",t)});const ob=document.getElementById("root");if(!ob)throw new Error("Root element not found");mv.createRoot(ob).render(s.jsx(Oe.StrictMode,{children:s.jsx(Hw,{children:s.jsx(Gw,{children:s.jsx(qw,{children:s.jsx(Qw,{children:s.jsx(W8,{apis:Q8})})})})})}));const rM=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"}));export{$T as M,Al as P,Br as S,bI as a,rM as m,gn as u};